Files: efff0d5be49e438aefc3460617744c5e1dd1be61 / src / main.c
5022 bytesRaw
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | HWAVEOUT hWaveOut = INVALID_HANDLE_VALUE; /* Device handle */ |
19 | WAVEFORMATEX wfx; |
20 | LPSTR audblock; |
21 | char audiobuffer[BUFFNUM][((44100*2*2)/50)]; |
22 | |
23 | Song *sang = NULL; |
24 | Player *player = NULL; |
25 | syntrax_info info; |
26 | |
27 | HANDLE eventh; |
28 | |
29 | void pressAny(void) { |
30 | printf("Clicky key, get continue!\n"); |
31 | getchar(); |
32 | } |
33 | |
34 | BOOL init( char *name ) |
35 | { |
36 | //MMRESULT result; |
37 | |
38 | wfx.nSamplesPerSec = 44100; |
39 | wfx.wBitsPerSample = 16; |
40 | wfx.nChannels = 2; |
41 | |
42 | wfx.cbSize = 0; |
43 | wfx.wFormatTag = WAVE_FORMAT_PCM; |
44 | wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels; |
45 | wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; |
46 | |
47 | sang = File_loadSong( name ); |
48 | if ( !sang ) return FALSE; |
49 | |
50 | player = playerCreate( 44100 ); |
51 | if( !player ) return FALSE; |
52 | |
53 | if ( loadSong( player, sang ) < 0 ) return FALSE; |
54 | |
55 | eventh = CreateEvent( |
56 | NULL, // default security attributes |
57 | TRUE, // manual-reset event |
58 | FALSE, // initial state is nonsignaled |
59 | TEXT("WriteEvent") // object name |
60 | ); |
61 | |
62 | if( waveOutOpen( &hWaveOut, WAVE_MAPPER, &wfx, (unsigned int)eventh, 0, CALLBACK_EVENT ) != MMSYSERR_NOERROR ) |
63 | { |
64 | printf( "Unable to open waveout\n" ); |
65 | return FALSE; |
66 | } |
67 | |
68 | return TRUE; |
69 | } |
70 | |
71 | void shut( void ) |
72 | { |
73 | //if( synSong ) free( synSong ); |
74 | if( hWaveOut != INVALID_HANDLE_VALUE ) waveOutClose( hWaveOut ); |
75 | } |
76 | |
77 | void updateScreen(void) |
78 | { |
79 | 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); |
84 | printf("Title: %s\n", info.subsongName); |
85 | } |
86 | |
87 | int main(int argc, char *argv[]) |
88 | { |
89 | WAVEHDR header[BUFFNUM]; |
90 | int nextbuf = 0; |
91 | //sigset_t base_mask, waiting_mask; |
92 | |
93 | if( argc < 2 ) |
94 | { |
95 | printf( "Usage: syntrax-c <tune.jxs>\n" ); |
96 | printf( "[ and ] keys change subtune.\n" ); |
97 | printf( "\n" ); |
98 | system("pause"); |
99 | return 0; |
100 | } |
101 | |
102 | if( init( argv[1] ) ) |
103 | { |
104 | int i; |
105 | updateScreen(); |
106 | |
107 | for ( i=0; i<BUFFNUM; i++ ){ |
108 | memset( &header[i], 0, sizeof( WAVEHDR ) ); |
109 | header[i].dwBufferLength = ((44100*2*2)/50); |
110 | header[i].lpData = (LPSTR)audiobuffer[i]; |
111 | } |
112 | for ( i=0; i<BUFFNUM-1; i++ ){ |
113 | mixChunk(player, audiobuffer[nextbuf], 882); |
114 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
115 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
116 | nextbuf = (nextbuf+1)%BUFFNUM; |
117 | } |
118 | for(;;) |
119 | { |
120 | mixChunk(player, audiobuffer[nextbuf], 882); |
121 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
122 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
123 | nextbuf = (nextbuf+1)%BUFFNUM; |
124 | |
125 | // Don't do this in your own player or plugin :-) |
126 | //while( waveOutUnprepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ) == WAVERR_STILLPLAYING ) ; |
127 | while( waveOutUnprepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ) == WAVERR_STILLPLAYING ){ |
128 | if (_kbhit()) { |
129 | int subnum; |
130 | switch (_getch()) { |
131 | case 0: /* introduces an extended key */ |
132 | case 227: /* this also happens on Win32 (I think) */ |
133 | switch (_getch()) { /* read the extended key code */ |
134 | case 72: /* up arrow press */ |
135 | break; |
136 | case 75: /* left arrow press */ |
137 | break; |
138 | case 77: /* right arrow press */ |
139 | break; |
140 | case 80: /* down arrow press */ |
141 | break; |
142 | /* etc */ |
143 | } |
144 | break; |
145 | case '[': |
146 | subnum = info.selectedSubs; |
147 | --subnum; |
148 | if (subnum < 0) subnum = info.totalSubs - 1; |
149 | |
150 | if (info.selectedSubs != subnum) initSubsong(player, subnum); |
151 | updateScreen(); |
152 | break; |
153 | case ']': |
154 | subnum = info.selectedSubs; |
155 | subnum = ++subnum % info.totalSubs; |
156 | |
157 | if (info.selectedSubs != subnum) initSubsong(player, subnum); |
158 | updateScreen(); |
159 | break; |
160 | |
161 | case 'H': /* capital 'H' key press */ break; |
162 | /* etc */ |
163 | } |
164 | } |
165 | WaitForSingleObject(eventh, INFINITE); |
166 | } |
167 | ResetEvent(eventh); |
168 | } |
169 | |
170 | } |
171 | playerDestroy(player); |
172 | File_freeSong(sang); |
173 | |
174 | return 0; |
175 | } |
176 | |
177 |
Built with git-ssb-web