annotate libao2/ao_win32.c @ 11268:c367751bd7cb

10! someone please tell me how subs ever worked with mkv
author attila
date Sun, 26 Oct 2003 12:28:45 +0000
parents b5b7b2f4f069
children 6e580b901205
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
1 /******************************************************************************
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
2 * ao_win32.c: Windows waveOut interface for MPlayer
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
3 * Copyright (c) 2002 Sascha Sommer <saschasommer@freenet.de>.
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
4 *
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
8 * (at your option) any later version.
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
9 *
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
13 * GNU General Public License for more details.
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
14 *
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
18 *
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
19 *****************************************************************************/
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
20
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
21 #include <stdio.h>
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
22 #include <stdlib.h>
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
23 #include <windows.h>
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
24 #include <mmsystem.h>
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
25
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
26 #include "afmt.h"
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
27 #include "audio_out.h"
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
28 #include "audio_out_internal.h"
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
29 #include "../mp_msg.h"
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
30 #include "../libvo/fastmemcpy.h"
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
31
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
32 #define SAMPLESIZE 1024
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
33 #define BUFFER_SIZE 4096
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
34 #define BUFFER_COUNT 16
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
35
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
36
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
37 static WAVEHDR* waveBlocks; //pointer to our ringbuffer memory
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
38 static HWAVEOUT hWaveOut; //handle to the waveout device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
39 static DWORD restoredvolume; //saves the volume to restore after playing
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
40 static unsigned int buf_write=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
41 static unsigned int buf_write_pos=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
42 static int full_buffers=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
43 static int buffered_bytes=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
44
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
45
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
46 static ao_info_t info =
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
47 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
48 "Windows waveOut audio output",
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
49 "win32",
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
50 "Sascha Sommer <saschasommer@freenet.de>",
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
51 ""
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
52 };
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
53
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
54 LIBAO_EXTERN(win32)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
55
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
56 static void CALLBACK waveOutProc(HWAVEOUT hWaveOut,UINT uMsg,DWORD dwInstance,
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
57 DWORD dwParam1,DWORD dwParam2)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
58 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
59 if(uMsg != WOM_DONE)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
60 return;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
61 if(full_buffers==0) return; //no more data buffered!
8657
37b083f196d7 10l fixes sync?
faust3
parents: 7913
diff changeset
62 buffered_bytes-=BUFFER_SIZE;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
63 --full_buffers;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
64 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
65
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
66 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 9589
diff changeset
67 static int control(int cmd,void *arg)
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
68 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
69 DWORD volume;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
70 switch (cmd)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
71 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
72 case AOCONTROL_GET_VOLUME:
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
73 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
74 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
75 waveOutGetVolume(hWaveOut,&volume);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
76 vol->left = (float)(LOWORD(volume)/655.35);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
77 vol->right = (float)(HIWORD(volume)/655.35);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
78 mp_msg(MSGT_AO, MSGL_DBG2,"ao_win32: volume left:%f volume right:%f\n",vol->left,vol->right);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
79 return CONTROL_OK;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
80 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
81 case AOCONTROL_SET_VOLUME:
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
82 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
83 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
84 volume = MAKELONG(vol->left*655.35,vol->right*655.35);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
85 waveOutSetVolume(hWaveOut,volume);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
86 return CONTROL_OK;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
87 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
88 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
89 return -1;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
90 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
91
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
92 // open & setup audio device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
93 // return: 1=success 0=fail
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
94 static int init(int rate,int channels,int format,int flags)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
95 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
96 WAVEFORMATEX wformat;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
97 DWORD totalBufferSize = (BUFFER_SIZE + sizeof(WAVEHDR)) * BUFFER_COUNT;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
98 MMRESULT result;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
99 unsigned char* buffer;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
100 int i;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
101
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
102 //fill global ao_data
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
103 ao_data.channels=channels;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
104 ao_data.samplerate=rate;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
105 ao_data.format=format;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
106 ao_data.bps=channels*rate;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
107 if(format != AFMT_U8 && format != AFMT_S8)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
108 ao_data.bps*=2;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
109 if(ao_data.buffersize==-1)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
110 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
111 ao_data.buffersize=audio_out_format_bits(format)/8;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
112 ao_data.buffersize*= channels;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
113 ao_data.buffersize*= SAMPLESIZE;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
114 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
115 mp_msg(MSGT_AO, MSGL_V,"ao_win32: Samplerate:%iHz Channels:%i Format:%s\n",rate, channels, audio_out_format_name(format));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
116 mp_msg(MSGT_AO, MSGL_V,"ao_win32: Buffersize:%d\n",ao_data.buffersize);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
117
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
118 //fill waveformatex
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
119 ZeroMemory( &wformat, sizeof(WAVEFORMATEX));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
120 wformat.cbSize = 0; /* size of _extra_ info */
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
121 wformat.wFormatTag = WAVE_FORMAT_PCM;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
122 wformat.nChannels = channels;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
123 wformat.nSamplesPerSec = rate;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
124 wformat.wBitsPerSample = audio_out_format_bits(format);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
125 wformat.nBlockAlign = wformat.nChannels * (wformat.wBitsPerSample >> 3);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
126 wformat.nAvgBytesPerSec = wformat.nSamplesPerSec * wformat.nBlockAlign;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
127
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
128 //open sound device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
129 //WAVE_MAPPER always points to the default wave device on the system
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
130 result = waveOutOpen(&hWaveOut,WAVE_MAPPER,&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
131 if(result == WAVERR_BADFORMAT)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
132 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
133 mp_msg(MSGT_AO, MSGL_ERR,"ao_win32: format not supported switching to default\n");
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
134 ao_data.channels = wformat.nChannels = 2;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
135 ao_data.samplerate = wformat.nSamplesPerSec = 44100;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
136 ao_data.format = AFMT_S16_LE;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
137 ao_data.bps=ao_data.channels * ao_data.samplerate;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
138 ao_data.buffersize=wformat.wBitsPerSample=16;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
139 wformat.nBlockAlign = wformat.nChannels * (wformat.wBitsPerSample >> 3);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
140 wformat.nAvgBytesPerSec = wformat.nSamplesPerSec * wformat.nBlockAlign;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
141 ao_data.buffersize/=8;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
142 ao_data.buffersize*= ao_data.channels;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
143 ao_data.buffersize*= SAMPLESIZE;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
144 result = waveOutOpen(&hWaveOut,WAVE_MAPPER,&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
145 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
146 if(result != MMSYSERR_NOERROR)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
147 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
148 mp_msg(MSGT_AO, MSGL_ERR,"ao_win32: unable to open wave mapper device\n");
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
149 return 0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
150 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
151 //save volume
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
152 waveOutGetVolume(hWaveOut,&restoredvolume);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
153 //allocate buffer memory as one big block
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
154 buffer = malloc(totalBufferSize);
9589
1823fdaffa73 fix -loop problem
faust3
parents: 8657
diff changeset
155 memset(buffer,0x0,totalBufferSize);
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
156 //and setup pointers to each buffer
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
157 waveBlocks = (WAVEHDR*)buffer;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
158 buffer += sizeof(WAVEHDR) * BUFFER_COUNT;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
159 for(i = 0; i < BUFFER_COUNT; i++) {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
160 waveBlocks[i].dwBufferLength = BUFFER_SIZE;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
161 waveBlocks[i].lpData = buffer;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
162 buffer += BUFFER_SIZE;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
163 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
164
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
165 return 1;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
166 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
167
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
168 // close audio device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
169 static void uninit()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
170 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
171 waveOutSetVolume(hWaveOut,restoredvolume); //restore volume
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
172 waveOutReset(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
173 waveOutClose(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
174 mp_msg(MSGT_AO, MSGL_V,"waveOut device closed\n");
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
175 full_buffers=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
176 free(waveBlocks);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
177 mp_msg(MSGT_AO, MSGL_V,"buffer memory freed\n");
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
178 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
179
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
180 // stop playing and empty buffers (for seeking/pause)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
181 static void reset()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
182 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
183 waveOutReset(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
184 buf_write=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
185 buf_write_pos=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
186 full_buffers=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
187 buffered_bytes=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
188 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
189
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
190 // stop playing, keep buffers (for pause)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
191 static void audio_pause()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
192 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
193 waveOutPause(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
194 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
195
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
196 // resume playing, after audio_pause()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
197 static void audio_resume()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
198 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
199 waveOutRestart(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
200 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
201
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
202 // return: how many bytes can be played without blocking
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
203 static int get_space()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
204 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
205 return (BUFFER_COUNT-full_buffers)*BUFFER_SIZE - buf_write_pos;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
206 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
207
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
208 //writes data into buffer, based on ringbuffer code in ao_sdl.c
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
209 static int write_waveOutBuffer(unsigned char* data,int len){
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
210 WAVEHDR* current;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
211 int len2=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
212 int x;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
213 while(len>0){
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
214 current = &waveBlocks[buf_write];
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
215 if(full_buffers==BUFFER_COUNT) break;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
216 //unprepare the header if it is prepared
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
217 if(current->dwFlags & WHDR_PREPARED)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
218 waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
219 x=BUFFER_SIZE-buf_write_pos;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
220 if(x>len) x=len;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
221 memcpy(current->lpData+buf_write_pos,data+len2,x);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
222 len2+=x; len-=x;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
223 buffered_bytes+=x; buf_write_pos+=x;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
224 //prepare header and write data to device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
225 waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
226 waveOutWrite(hWaveOut, current, sizeof(WAVEHDR));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
227
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
228 if(buf_write_pos>=BUFFER_SIZE){ //buffer is full find next
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
229 // block is full, find next!
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
230 buf_write=(buf_write+1)%BUFFER_COUNT;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
231 ++full_buffers;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
232 buf_write_pos=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
233 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
234 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
235 return len2;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
236 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
237
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
238 // plays 'len' bytes of 'data'
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
239 // it should round it down to outburst*n
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
240 // return: number of bytes played
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
241 static int play(void* data,int len,int flags)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
242 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
243 return write_waveOutBuffer(data,len);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
244 }
10106
b5b7b2f4f069 10l remove unused global
faust3
parents: 9633
diff changeset
245
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
246 // return: delay in seconds between first and last sample in buffer
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
247 static float get_delay()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
248 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
249 return (float)(buffered_bytes + ao_data.buffersize)/(float)ao_data.bps;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
250 }