Commit eb80f67bab69619271c4041b118e90e30b091c78
Updated main.c a bit.
anonymous authored on 1/3/2016, 5:57:34 PMChristopher Snowhill committed on 6/13/2018, 12:10:58 AM
Parent: 9cd52ae87a9a085257d0b015fffe777f1f23973e
Files changed
src/main.c | changed |
src/main.c | ||
---|---|---|
@@ -13,20 +13,68 @@ | ||
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | 16 | |
17 | + | |
18 | + | |
17 | 19 | |
18 | 20 | HWAVEOUT hWaveOut = INVALID_HANDLE_VALUE; /* Device handle */ |
19 | 21 | WAVEFORMATEX wfx; |
20 | 22 | LPSTR audblock; |
21 | -char audiobuffer[BUFFNUM][((44100*2*2)/50)]; | |
23 | +char audiobuffer[BUFFNUM][BUFFLEN]; | |
22 | 24 | |
23 | 25 | Song *sang = NULL; |
24 | 26 | Player *player = NULL; |
25 | 27 | syntrax_info info; |
28 | +int max_channels = 0; | |
26 | 29 | |
27 | 30 | HANDLE eventh; |
28 | 31 | |
32 | + /* Standard error macro for reporting API errors */ | |
33 | + | |
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 | + | |
29 | 77 | void pressAny(void) { |
30 | 78 | printf("Clicky key, get continue!\n"); |
31 | 79 | getchar(); |
32 | 80 | } |
@@ -34,9 +82,9 @@ | ||
34 | 82 | BOOL init( char *name ) |
35 | 83 | { |
36 | 84 | //MMRESULT result; |
37 | 85 | |
38 | - wfx.nSamplesPerSec = 44100; | |
86 | + wfx.nSamplesPerSec = RATE; | |
39 | 87 | wfx.wBitsPerSample = 16; |
40 | 88 | wfx.nChannels = 2; |
41 | 89 | |
42 | 90 | wfx.cbSize = 0; |
@@ -46,9 +94,9 @@ | ||
46 | 94 | |
47 | 95 | sang = File_loadSong( name ); |
48 | 96 | if ( !sang ) return FALSE; |
49 | 97 | |
50 | - player = playerCreate( 44100 ); | |
98 | + player = playerCreate( RATE ); | |
51 | 99 | if( !player ) return FALSE; |
52 | 100 | |
53 | 101 | if ( loadSong( player, sang ) < 0 ) return FALSE; |
54 | 102 | |
@@ -76,12 +124,11 @@ | ||
76 | 124 | |
77 | 125 | void updateScreen(void) |
78 | 126 | { |
79 | 127 | 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); | |
84 | 131 | printf("Title: %s\n", info.subsongName); |
85 | 132 | } |
86 | 133 | |
87 | 134 | int main(int argc, char *argv[]) |
@@ -107,20 +154,20 @@ | ||
107 | 154 | updateScreen(); |
108 | 155 | |
109 | 156 | for ( i=0; i<BUFFNUM; i++ ){ |
110 | 157 | memset( &header[i], 0, sizeof( WAVEHDR ) ); |
111 | - header[i].dwBufferLength = ((44100*2*2)/50); | |
158 | + header[i].dwBufferLength = BUFFLEN; | |
112 | 159 | header[i].lpData = (LPSTR)audiobuffer[i]; |
113 | 160 | } |
114 | 161 | for ( i=0; i<BUFFNUM-1; i++ ){ |
115 | - mixChunk(player, audiobuffer[nextbuf], 882); | |
162 | + mixChunk(player, audiobuffer[nextbuf], BUFFLEN/4); | |
116 | 163 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
117 | 164 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
118 | 165 | nextbuf = (nextbuf+1)%BUFFNUM; |
119 | 166 | } |
120 | 167 | for(;;) |
121 | 168 | { |
122 | - mixChunk(player, audiobuffer[nextbuf], 882); | |
169 | + mixChunk(player, audiobuffer[nextbuf], BUFFLEN/4); | |
123 | 170 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
124 | 171 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
125 | 172 | nextbuf = (nextbuf+1)%BUFFNUM; |
126 | 173 | |
@@ -137,15 +184,17 @@ | ||
137 | 184 | --subnum; |
138 | 185 | if (subnum < 0) subnum = info.totalSubs - 1; |
139 | 186 | |
140 | 187 | if (info.selectedSubs != subnum) initSubsong(player, subnum); |
188 | + max_channels = 0; | |
141 | 189 | updateScreen(); |
142 | 190 | break; |
143 | 191 | case 62: //F4, subtune++ |
144 | 192 | subnum = info.selectedSubs; |
145 | 193 | subnum = ++subnum % info.totalSubs; |
146 | 194 | |
147 | 195 | if (info.selectedSubs != subnum) initSubsong(player, subnum); |
196 | + max_channels = 0; | |
148 | 197 | updateScreen(); |
149 | 198 | break; |
150 | 199 | case 72: //up arrow press |
151 | 200 | break; |
@@ -165,8 +214,9 @@ | ||
165 | 214 | case 'H': /* capital 'H' key press */ break; |
166 | 215 | /* etc */ |
167 | 216 | } |
168 | 217 | } |
218 | + updateScreen(); | |
169 | 219 | WaitForSingleObject(eventh, INFINITE); |
170 | 220 | } |
171 | 221 | ResetEvent(eventh); |
172 | 222 | } |
@@ -178,6 +228,5 @@ | ||
178 | 228 | playerDestroy(player); |
179 | 229 | File_freeSong(sang); |
180 | 230 | |
181 | 231 | return 0; |
182 | -} | |
183 | - | |
232 | +} |
Built with git-ssb-web