git ssb

0+

kode54 / syntrax-c



Commit eb80f67bab69619271c4041b118e90e30b091c78

Updated main.c a bit.

anonymous authored on 1/3/2016, 5:57:34 PM
Christopher Snowhill committed on 6/13/2018, 12:10:58 AM
Parent: 9cd52ae87a9a085257d0b015fffe777f1f23973e

Files changed

src/main.cchanged
src/main.cView
@@ -13,20 +13,68 @@
1313
1414 #include "syntrax\syntrax.h"
1515
1616 #define BUFFNUM 8
17+#define RATE 44100
18+#define BUFFLEN ((RATE*2*2)/50)
1719
1820 HWAVEOUT hWaveOut = INVALID_HANDLE_VALUE; /* Device handle */
1921 WAVEFORMATEX wfx;
2022 LPSTR audblock;
21-char audiobuffer[BUFFNUM][((44100*2*2)/50)];
23+char audiobuffer[BUFFNUM][BUFFLEN];
2224
2325 Song *sang = NULL;
2426 Player *player = NULL;
2527 syntrax_info info;
28+int max_channels = 0;
2629
2730 HANDLE eventh;
2831
32+ /* Standard error macro for reporting API errors */
33+ #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
34+ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
35+
36+void cls( HANDLE hConsole )
37+{
38+ COORD coordScreen = { 0, 0 }; /* here's where we'll home the
39+ cursor */
40+ BOOL bSuccess;
41+ DWORD cCharsWritten;
42+ CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
43+ DWORD dwConSize; /* number of character cells in
44+ the current buffer */
45+
46+ /* get the number of character cells in the current buffer */
47+
48+ bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
49+ PERR( bSuccess, "GetConsoleScreenBufferInfo" );
50+ dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
51+
52+ /* fill the entire screen with blanks */
53+
54+ bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
55+ dwConSize, coordScreen, &cCharsWritten );
56+ PERR( bSuccess, "FillConsoleOutputCharacter" );
57+
58+ /* get the current text attribute */
59+
60+ bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
61+ PERR( bSuccess, "ConsoleScreenBufferInfo" );
62+
63+ /* now set the buffer's attributes accordingly */
64+
65+ bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
66+ dwConSize, coordScreen, &cCharsWritten );
67+ PERR( bSuccess, "FillConsoleOutputAttribute" );
68+
69+ /* put the cursor at (0, 0) */
70+
71+ bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
72+ PERR( bSuccess, "SetConsoleCursorPosition" );
73+return;
74+}
75+
76+
2977 void pressAny(void) {
3078 printf("Clicky key, get continue!\n");
3179 getchar();
3280 }
@@ -34,9 +82,9 @@
3482 BOOL init( char *name )
3583 {
3684 //MMRESULT result;
3785
38- wfx.nSamplesPerSec = 44100;
86+ wfx.nSamplesPerSec = RATE;
3987 wfx.wBitsPerSample = 16;
4088 wfx.nChannels = 2;
4189
4290 wfx.cbSize = 0;
@@ -46,9 +94,9 @@
4694
4795 sang = File_loadSong( name );
4896 if ( !sang ) return FALSE;
4997
50- player = playerCreate( 44100 );
98+ player = playerCreate( RATE );
5199 if( !player ) return FALSE;
52100
53101 if ( loadSong( player, sang ) < 0 ) return FALSE;
54102
@@ -76,12 +124,11 @@
76124
77125 void updateScreen(void)
78126 {
79127 playerGetInfo(player, &info);
80- //cls is expensive and I am lazy
81- //we can't put this in the loop
82- system("cls");
83- printf("Syntrax test player v0.0001 || %i/%i \n", info.selectedSubs+1, info.totalSubs);
128+ cls( GetStdHandle( STD_OUTPUT_HANDLE ));
129+ printf("Syntrax test player v0.0001 || %i/%i\n", info.selectedSubs+1, info.totalSubs);
130+ printf("\ro: %3u - r: %2u - c: %2u (%2u)\n", info.coarse, info.fine, info.channelsPlaying, info.channelsPlaying > max_channels ? max_channels = info.channelsPlaying : max_channels);
84131 printf("Title: %s\n", info.subsongName);
85132 }
86133
87134 int main(int argc, char *argv[])
@@ -107,20 +154,20 @@
107154 updateScreen();
108155
109156 for ( i=0; i<BUFFNUM; i++ ){
110157 memset( &header[i], 0, sizeof( WAVEHDR ) );
111- header[i].dwBufferLength = ((44100*2*2)/50);
158+ header[i].dwBufferLength = BUFFLEN;
112159 header[i].lpData = (LPSTR)audiobuffer[i];
113160 }
114161 for ( i=0; i<BUFFNUM-1; i++ ){
115- mixChunk(player, audiobuffer[nextbuf], 882);
162+ mixChunk(player, audiobuffer[nextbuf], BUFFLEN/4);
116163 waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) );
117164 waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) );
118165 nextbuf = (nextbuf+1)%BUFFNUM;
119166 }
120167 for(;;)
121168 {
122- mixChunk(player, audiobuffer[nextbuf], 882);
169+ mixChunk(player, audiobuffer[nextbuf], BUFFLEN/4);
123170 waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) );
124171 waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) );
125172 nextbuf = (nextbuf+1)%BUFFNUM;
126173
@@ -137,15 +184,17 @@
137184 --subnum;
138185 if (subnum < 0) subnum = info.totalSubs - 1;
139186
140187 if (info.selectedSubs != subnum) initSubsong(player, subnum);
188+ max_channels = 0;
141189 updateScreen();
142190 break;
143191 case 62: //F4, subtune++
144192 subnum = info.selectedSubs;
145193 subnum = ++subnum % info.totalSubs;
146194
147195 if (info.selectedSubs != subnum) initSubsong(player, subnum);
196+ max_channels = 0;
148197 updateScreen();
149198 break;
150199 case 72: //up arrow press
151200 break;
@@ -165,8 +214,9 @@
165214 case 'H': /* capital 'H' key press */ break;
166215 /* etc */
167216 }
168217 }
218+ updateScreen();
169219 WaitForSingleObject(eventh, INFINITE);
170220 }
171221 ResetEvent(eventh);
172222 }
@@ -178,6 +228,5 @@
178228 playerDestroy(player);
179229 File_freeSong(sang);
180230
181231 return 0;
182-}
183-
232+}

Built with git-ssb-web