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