Files: 3aa8a437591202761828240a5064926d5acf6a6b / src / main.c
3159 bytesRaw
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | HWAVEOUT hWaveOut = INVALID_HANDLE_VALUE; /* Device handle */ |
18 | WAVEFORMATEX wfx; |
19 | LPSTR audblock; |
20 | char audiobuffer[BUFFNUM][((44100*2*2)/50)]; |
21 | |
22 | Song *sang = NULL; |
23 | Player *player = NULL; |
24 | |
25 | HANDLE eventh; |
26 | |
27 | void pressAny(void) { |
28 | printf("Clicky key, get continue!\n"); |
29 | getchar(); |
30 | } |
31 | |
32 | BOOL init( char *name ) |
33 | { |
34 | //MMRESULT result; |
35 | |
36 | wfx.nSamplesPerSec = 44100; |
37 | wfx.wBitsPerSample = 16; |
38 | wfx.nChannels = 2; |
39 | |
40 | wfx.cbSize = 0; |
41 | wfx.wFormatTag = WAVE_FORMAT_PCM; |
42 | wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels; |
43 | wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; |
44 | |
45 | sang = File_loadSong( name ); |
46 | if ( !sang ) return FALSE; |
47 | |
48 | player = playerCreate( 44100 ); |
49 | if( !player ) return FALSE; |
50 | |
51 | if ( loadSong( player, sang ) < 0 ) return FALSE; |
52 | |
53 | eventh = CreateEvent( |
54 | NULL, // default security attributes |
55 | TRUE, // manual-reset event |
56 | FALSE, // initial state is nonsignaled |
57 | TEXT("WriteEvent") // object name |
58 | ); |
59 | |
60 | if( waveOutOpen( &hWaveOut, WAVE_MAPPER, &wfx, (unsigned int)eventh, 0, CALLBACK_EVENT ) != MMSYSERR_NOERROR ) |
61 | { |
62 | printf( "Unable to open waveout\n" ); |
63 | return FALSE; |
64 | } |
65 | |
66 | return TRUE; |
67 | } |
68 | |
69 | void shut( void ) |
70 | { |
71 | //if( synSong ) free( synSong ); |
72 | if( hWaveOut != INVALID_HANDLE_VALUE ) waveOutClose( hWaveOut ); |
73 | } |
74 | |
75 | int main(int argc, char *argv[]) |
76 | { |
77 | WAVEHDR header[BUFFNUM]; |
78 | int nextbuf = 0; |
79 | //sigset_t base_mask, waiting_mask; |
80 | |
81 | printf( "Syntrax test player v0.000000001\n" ); |
82 | |
83 | if( argc < 2 ) |
84 | { |
85 | printf( "Usage: syntrax-c <tune.jxs>\n" ); |
86 | return 0; |
87 | } |
88 | |
89 | if( init( argv[1] ) ) |
90 | { |
91 | int i; |
92 | |
93 | for ( i=0; i<BUFFNUM; i++ ){ |
94 | memset( &header[i], 0, sizeof( WAVEHDR ) ); |
95 | header[i].dwBufferLength = ((44100*2*2)/50); |
96 | header[i].lpData = (LPSTR)audiobuffer[i]; |
97 | } |
98 | for ( i=0; i<BUFFNUM-1; i++ ){ |
99 | mixChunk(player, audiobuffer[nextbuf], 44100/50); |
100 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
101 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
102 | nextbuf = (nextbuf+1)%BUFFNUM; |
103 | } |
104 | |
105 | for(;;) |
106 | { |
107 | mixChunk(player, audiobuffer[nextbuf], 44100/50); |
108 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
109 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
110 | nextbuf = (nextbuf+1)%BUFFNUM; |
111 | |
112 | // Don't do this in your own player or plugin :-) |
113 | //while( waveOutUnprepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ) == WAVERR_STILLPLAYING ) ; |
114 | while( waveOutUnprepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ) == WAVERR_STILLPLAYING ){ |
115 | WaitForSingleObject(eventh, INFINITE); |
116 | } |
117 | ResetEvent(eventh); |
118 | } |
119 | |
120 | } |
121 | playerDestroy(player); |
122 | File_freeSong(sang); |
123 | |
124 | return 0; |
125 | } |
126 | |
127 |
Built with git-ssb-web