Files: ff356ac03b9201b62881c0c01ab0b732d81ebb2f / src / main.c
2889 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 | |
24 | HANDLE eventh; |
25 | |
26 | BOOL init( char *name ) |
27 | { |
28 | //MMRESULT result; |
29 | |
30 | wfx.nSamplesPerSec = 44100; |
31 | wfx.wBitsPerSample = 16; |
32 | wfx.nChannels = 2; |
33 | |
34 | wfx.cbSize = 0; |
35 | wfx.wFormatTag = WAVE_FORMAT_PCM; |
36 | wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels; |
37 | wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; |
38 | |
39 | constructor(); |
40 | |
41 | sang = loadSongFromFile(name); |
42 | resumePlay(); |
43 | if( !sang ) return FALSE; |
44 | |
45 | eventh = CreateEvent( |
46 | NULL, // default security attributes |
47 | TRUE, // manual-reset event |
48 | FALSE, // initial state is nonsignaled |
49 | TEXT("WriteEvent") // object name |
50 | ); |
51 | |
52 | if( waveOutOpen( &hWaveOut, WAVE_MAPPER, &wfx, (unsigned int)eventh, 0, CALLBACK_EVENT ) != MMSYSERR_NOERROR ) |
53 | { |
54 | printf( "Unable to open waveout\n" ); |
55 | return FALSE; |
56 | } |
57 | |
58 | return TRUE; |
59 | } |
60 | |
61 | void shut( void ) |
62 | { |
63 | //if( synSong ) free( synSong ); |
64 | if( hWaveOut != INVALID_HANDLE_VALUE ) waveOutClose( hWaveOut ); |
65 | } |
66 | |
67 | int main(int argc, char *argv[]) |
68 | { |
69 | WAVEHDR header[BUFFNUM]; |
70 | int nextbuf = 0; |
71 | //sigset_t base_mask, waiting_mask; |
72 | |
73 | printf( "Syntrax test player v0.000000001\n" ); |
74 | |
75 | if( argc < 2 ) |
76 | { |
77 | printf( "Usage: play_hvl <tune>\n" ); |
78 | return 0; |
79 | } |
80 | |
81 | if( init( argv[1] ) ) |
82 | { |
83 | int i; |
84 | |
85 | for ( i=0; i<BUFFNUM; i++ ){ |
86 | memset( &header[i], 0, sizeof( WAVEHDR ) ); |
87 | header[i].dwBufferLength = ((44100*2*2)/50); |
88 | header[i].lpData = (LPSTR)audiobuffer[i]; |
89 | } |
90 | |
91 | for ( i=0; i<BUFFNUM-1; i++ ){ |
92 | mixChunk(audiobuffer[nextbuf], 1024); |
93 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
94 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
95 | nextbuf = (nextbuf+1)%BUFFNUM; |
96 | } |
97 | |
98 | for(;;) |
99 | { |
100 | mixChunk(audiobuffer[nextbuf], 1024); |
101 | waveOutPrepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
102 | waveOutWrite( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ); |
103 | nextbuf = (nextbuf+1)%BUFFNUM; |
104 | |
105 | // Don't do this in your own player or plugin :-) |
106 | //while( waveOutUnprepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ) == WAVERR_STILLPLAYING ) ; |
107 | while( waveOutUnprepareHeader( hWaveOut, &header[nextbuf], sizeof( WAVEHDR ) ) == WAVERR_STILLPLAYING ){ |
108 | WaitForSingleObject(eventh, INFINITE); |
109 | } |
110 | ResetEvent(eventh); |
111 | } |
112 | |
113 | } |
114 | shut(); |
115 | |
116 | return 0; |
117 | } |
118 | |
119 |
Built with git-ssb-web