Mercurial > hg > forks > pwpunix
annotate pwplib/snd-w32.c @ 17:c60e531d19cd
Some misc. cleanups and minor warning removals.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 22 May 2010 20:32:49 +0300 |
parents | acb5694e93d9 |
children | b9d679965320 |
rev | line source |
---|---|
0 | 1 #include "config.h" |
2 | |
3 #ifdef DRIVE_WIN32 | |
4 | |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 #include <malloc.h> | |
9 | |
10 #include <windows.h> | |
11 | |
12 #define TIMERHZ 72 | |
13 | |
14 #include "pwplib.h" | |
15 | |
16 #define NUMBUFS 2 | |
17 | |
18 #define HARDBUFSIZE 65536 | |
19 | |
20 struct | |
21 { | |
22 int buffersize; | |
23 HWAVEOUT outHandle; | |
24 WAVEHDR waveHdr[NUMBUFS]; | |
25 char *bufData[NUMBUFS]; | |
26 int currbuf; | |
27 int bufferptr; | |
28 int letsgo; | |
29 } | |
30 pwp_w32snd; | |
31 | |
32 extern void gb_sound(int,int,int,int); | |
33 | |
34 void win32snd_fill() | |
35 { | |
36 while(pwp_w32snd.bufferptr<(HARDBUFSIZE-pwp_w32snd.buffersize)) | |
37 { | |
38 pwplib.player(); | |
39 | |
40 gb_genwave(pwp_w32snd.bufData[pwp_w32snd.currbuf] + | |
41 pwp_w32snd.bufferptr, | |
42 pwp_w32snd.buffersize); | |
43 | |
44 pwp_w32snd.bufferptr += pwp_w32snd.buffersize; | |
45 } | |
46 pwp_w32snd.waveHdr[pwp_w32snd.currbuf].lpData = | |
47 pwp_w32snd.bufData[pwp_w32snd.currbuf]; | |
48 pwp_w32snd.waveHdr[pwp_w32snd.currbuf].dwBufferLength = | |
49 pwp_w32snd.bufferptr; | |
50 | |
51 pwp_w32snd.bufferptr=0; | |
52 | |
53 waveOutPrepareHeader( | |
54 pwp_w32snd.outHandle, | |
55 &pwp_w32snd.waveHdr[pwp_w32snd.currbuf], | |
56 sizeof(WAVEHDR)); | |
57 | |
58 waveOutWrite( | |
59 pwp_w32snd.outHandle, | |
60 &pwp_w32snd.waveHdr[pwp_w32snd.currbuf], | |
61 sizeof(WAVEHDR)); | |
62 | |
63 pwp_w32snd.currbuf=(pwp_w32snd.currbuf+1)%NUMBUFS; | |
64 } | |
65 | |
66 static void CALLBACK win32snd_callback(HWAVEOUT hwo,UINT uMsg, | |
67 DWORD dwParam0, DWORD dwParam1, DWORD dwParam2) | |
68 { | |
69 if(pwp_w32snd.letsgo==0) return; | |
70 | |
71 /* | |
72 if(pwp_w32snd.waveHdr[pwp_w32snd.currbuf].dwFlags&WHDR_PREPARED) | |
73 waveOutUnprepareHeader( | |
74 pwp_w32snd.outHandle, | |
75 &pwp_w32snd.waveHdr[pwp_w32snd.currbuf], | |
76 sizeof(WAVEHDR)); | |
77 */ | |
78 win32snd_fill(); | |
79 } | |
80 | |
81 void win32snd_restore() | |
82 { | |
83 } | |
84 | |
85 void win32snd_start() | |
86 { | |
87 if(pwp_w32snd.letsgo==0) | |
88 { | |
89 {int i=0; | |
90 for(;i<NUMBUFS;i++) win32snd_fill(); | |
91 } | |
92 | |
93 pwp_w32snd.letsgo++; | |
94 } | |
95 } | |
96 | |
97 int win32snd_init() | |
98 { | |
99 HANDLE bufHandle,waveHdrHandle; | |
100 WAVEFORMATEX waveFormat; | |
101 | |
102 /************/ | |
103 | |
104 /* try: 8000/8/1, 11025/8/1, 11025/16/1, 22050/16/1, 22050/16/2, | |
105 44100/16/2 */ | |
106 | |
107 waveFormat.wFormatTag = WAVE_FORMAT_PCM; | |
108 waveFormat.nChannels = 1; | |
109 waveFormat.nSamplesPerSec = 22050; | |
110 waveFormat.wBitsPerSample = 8; | |
111 waveFormat.nBlockAlign = | |
112 waveFormat.nChannels * (waveFormat.wBitsPerSample/8); | |
113 waveFormat.nAvgBytesPerSec = | |
114 waveFormat.nSamplesPerSec * waveFormat.nBlockAlign; | |
115 waveFormat.cbSize = 0; | |
116 | |
117 pwp_w32snd.letsgo=0; | |
118 | |
119 {int i=0;for(;i<NUMBUFS;i++) | |
120 pwp_w32snd.bufData[i] = malloc(HARDBUFSIZE); | |
121 } | |
122 | |
123 pwplib.sound=gb_sound; | |
124 gb_init(waveFormat.nAvgBytesPerSec); | |
125 | |
126 pwp_w32snd.buffersize = waveFormat.nAvgBytesPerSec/TIMERHZ; | |
127 pwp_w32snd.currbuf=0; | |
128 pwp_w32snd.bufferptr = 0; | |
129 | |
130 {int r = waveOutOpen(&pwp_w32snd.outHandle,WAVE_MAPPER,&waveFormat, | |
131 (DWORD)win32snd_callback,0, | |
132 CALLBACK_FUNCTION); | |
133 if(r) { printf("ERROR\n"); } | |
134 } | |
135 | |
17
c60e531d19cd
Some misc. cleanups and minor warning removals.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
136 pwplib_regdestr(win32snd_restore); |
0 | 137 |
138 // pwp_w32snd.buffersize = waveFormat.nAvgBytesPerSec/TIMERHZ; | |
139 | |
140 pwplib.loopflush = win32snd_start; | |
141 | |
142 return 1; | |
143 } | |
144 | |
145 #endif | |
146 |