git ssb

0+

kode54 / syntrax-c



Tree: 3aa8a437591202761828240a5064926d5acf6a6b

Files: 3aa8a437591202761828240a5064926d5acf6a6b / src / main.c

3159 bytesRaw
1
2
3#define WIN32_LEAN_AND_MEAN // for stripping windows.h include
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <signal.h>
8#include <stddef.h>
9
10#include <windows.h> // for mixer stream
11#include <mmsystem.h> // for mixer stream
12
13#include "syntrax\syntrax.h"
14
15#define BUFFNUM 8
16
17HWAVEOUT hWaveOut = INVALID_HANDLE_VALUE; /* Device handle */
18WAVEFORMATEX wfx;
19LPSTR audblock;
20char audiobuffer[BUFFNUM][((44100*2*2)/50)];
21
22Song *sang = NULL;
23Player *player = NULL;
24
25HANDLE eventh;
26
27void pressAny(void) {
28 printf("Clicky key, get continue!\n");
29 getchar();
30}
31
32BOOL 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
69void shut( void )
70{
71 //if( synSong ) free( synSong );
72 if( hWaveOut != INVALID_HANDLE_VALUE ) waveOutClose( hWaveOut );
73}
74
75int 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