annotate libao2/ao_win32.c @ 13247:933b45ad31d5

Removal of -jpeg commandline option. It's replaced by an options parser in the module itself. Instead of mplayer -vo jpeg -jpeg options one now has to use mplayer -vo jpeg:options.
author ivo
date Sat, 04 Sep 2004 22:59:33 +0000
parents 5b9c594dc6e9
children 83c5f9888576
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
12151
75fdb659f5bf round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents: 12146
diff changeset
3 * Copyright (c) 2002 - 2004 Sascha Sommer <saschasommer@freenet.de>.
7913
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"
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
31 #include "osdep/timer.h"
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
32
12699
02efc0619f61 10l WAVE_FORMAT_DOLBY_AC3_SPDIF needs to be defined first, patch by Gianluigi Tiesi <sherpya at netfarm.it>
faust3
parents: 12684
diff changeset
33 #define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
34 #define WAVE_FORMAT_EXTENSIBLE 0xFFFE
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
35
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
36 static const GUID KSDATAFORMAT_SUBTYPE_PCM = {
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
37 0x1,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
38 };
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
39
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
40 typedef struct {
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
41 WAVEFORMATEX Format;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
42 union {
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
43 WORD wValidBitsPerSample;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
44 WORD wSamplesPerBlock;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
45 WORD wReserved;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
46 } Samples;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
47 DWORD dwChannelMask;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
48 GUID SubFormat;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
49 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
50
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
51 #define SPEAKER_FRONT_LEFT 0x1
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
52 #define SPEAKER_FRONT_RIGHT 0x2
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
53 #define SPEAKER_FRONT_CENTER 0x4
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
54 #define SPEAKER_LOW_FREQUENCY 0x8
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
55 #define SPEAKER_BACK_LEFT 0x10
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
56 #define SPEAKER_BACK_RIGHT 0x20
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
57 #define SPEAKER_FRONT_LEFT_OF_CENTER 0x40
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
58 #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
59 #define SPEAKER_BACK_CENTER 0x100
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
60 #define SPEAKER_SIDE_LEFT 0x200
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
61 #define SPEAKER_SIDE_RIGHT 0x400
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
62 #define SPEAKER_TOP_CENTER 0x800
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
63 #define SPEAKER_TOP_FRONT_LEFT 0x1000
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
64 #define SPEAKER_TOP_FRONT_CENTER 0x2000
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
65 #define SPEAKER_TOP_FRONT_RIGHT 0x4000
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
66 #define SPEAKER_TOP_BACK_LEFT 0x8000
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
67 #define SPEAKER_TOP_BACK_CENTER 0x10000
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
68 #define SPEAKER_TOP_BACK_RIGHT 0x20000
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
69
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
70 static const int channel_mask[] = {
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
71 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY,
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
72 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY,
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
73 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_CENTER | SPEAKER_LOW_FREQUENCY,
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
74 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
75 };
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
76
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
77
12699
02efc0619f61 10l WAVE_FORMAT_DOLBY_AC3_SPDIF needs to be defined first, patch by Gianluigi Tiesi <sherpya at netfarm.it>
faust3
parents: 12684
diff changeset
78
12155
deb95ac21f14 restore original ringbuffer constants as the current values are causing heavy stutter here, especially noticable after moving the video window
faust3
parents: 12151
diff changeset
79 #define SAMPLESIZE 1024
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
80 #define BUFFER_SIZE 4096
12155
deb95ac21f14 restore original ringbuffer constants as the current values are causing heavy stutter here, especially noticable after moving the video window
faust3
parents: 12151
diff changeset
81 #define BUFFER_COUNT 16
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
82
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
83
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
84 static WAVEHDR* waveBlocks; //pointer to our ringbuffer memory
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
85 static HWAVEOUT hWaveOut; //handle to the waveout device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
86 static unsigned int buf_write=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
87 static unsigned int buf_write_pos=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
88 static int full_buffers=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
89 static int buffered_bytes=0;
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 static ao_info_t info =
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
93 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
94 "Windows waveOut audio output",
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
95 "win32",
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
96 "Sascha Sommer <saschasommer@freenet.de>",
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
97 ""
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
98 };
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
99
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
100 LIBAO_EXTERN(win32)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
101
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
102 static void CALLBACK waveOutProc(HWAVEOUT hWaveOut,UINT uMsg,DWORD dwInstance,
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
103 DWORD dwParam1,DWORD dwParam2)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
104 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
105 if(uMsg != WOM_DONE)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
106 return;
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
107 if (full_buffers) {
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
108 buffered_bytes-=BUFFER_SIZE;
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
109 --full_buffers;
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
110 } else {
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
111 buffered_bytes=0;
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
112 }
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
113 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
114
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
115 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 9589
diff changeset
116 static int control(int cmd,void *arg)
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
117 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
118 DWORD volume;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
119 switch (cmd)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
120 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
121 case AOCONTROL_GET_VOLUME:
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
122 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
123 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
124 waveOutGetVolume(hWaveOut,&volume);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
125 vol->left = (float)(LOWORD(volume)/655.35);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
126 vol->right = (float)(HIWORD(volume)/655.35);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
127 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
128 return CONTROL_OK;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
129 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
130 case AOCONTROL_SET_VOLUME:
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
131 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
132 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
133 volume = MAKELONG(vol->left*655.35,vol->right*655.35);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
134 waveOutSetVolume(hWaveOut,volume);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
135 return CONTROL_OK;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
136 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
137 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
138 return -1;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
139 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
140
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
141 // open & setup audio device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
142 // return: 1=success 0=fail
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
143 static int init(int rate,int channels,int format,int flags)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
144 {
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
145 WAVEFORMATEXTENSIBLE wformat;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
146 DWORD totalBufferSize = (BUFFER_SIZE + sizeof(WAVEHDR)) * BUFFER_COUNT;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
147 MMRESULT result;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
148 unsigned char* buffer;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
149 int i;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
150
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
151 //fill global ao_data
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
152 ao_data.channels=channels;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
153 ao_data.samplerate=rate;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
154 ao_data.format=format;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
155 ao_data.bps=channels*rate;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
156 if(format != AFMT_U8 && format != AFMT_S8)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
157 ao_data.bps*=2;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
158 if(ao_data.buffersize==-1)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
159 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
160 ao_data.buffersize=audio_out_format_bits(format)/8;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
161 ao_data.buffersize*= channels;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
162 ao_data.buffersize*= SAMPLESIZE;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
163 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
164 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
165 mp_msg(MSGT_AO, MSGL_V,"ao_win32: Buffersize:%d\n",ao_data.buffersize);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
166
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
167 //fill waveformatex
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
168 ZeroMemory( &wformat, sizeof(WAVEFORMATEXTENSIBLE));
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
169 wformat.Format.cbSize = (channels>2)?sizeof(WAVEFORMATEXTENSIBLE):0;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
170 wformat.Format.nChannels = channels;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
171 wformat.Format.nSamplesPerSec = rate;
12684
47598beff93a ac3 passthrough, initial patch by Gianluigi Tiesi <sherpya at netfarm.it>
faust3
parents: 12155
diff changeset
172 if(format == AFMT_AC3)
47598beff93a ac3 passthrough, initial patch by Gianluigi Tiesi <sherpya at netfarm.it>
faust3
parents: 12155
diff changeset
173 {
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
174 wformat.Format.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
175 wformat.Format.wBitsPerSample = 16;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
176 wformat.Format.nBlockAlign = 4;
12684
47598beff93a ac3 passthrough, initial patch by Gianluigi Tiesi <sherpya at netfarm.it>
faust3
parents: 12155
diff changeset
177 }
47598beff93a ac3 passthrough, initial patch by Gianluigi Tiesi <sherpya at netfarm.it>
faust3
parents: 12155
diff changeset
178 else
47598beff93a ac3 passthrough, initial patch by Gianluigi Tiesi <sherpya at netfarm.it>
faust3
parents: 12155
diff changeset
179 {
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
180 wformat.Format.wFormatTag = (channels>2)?WAVE_FORMAT_EXTENSIBLE:WAVE_FORMAT_PCM;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
181 wformat.Format.wBitsPerSample = audio_out_format_bits(format);
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
182 wformat.Format.nBlockAlign = wformat.Format.nChannels * (wformat.Format.wBitsPerSample >> 3);
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
183 }
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
184 if(channels>2)
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
185 {
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
186 wformat.dwChannelMask = channel_mask[channels-3];
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
187 wformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
188 wformat.Samples.wValidBitsPerSample=audio_out_format_bits(format);
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
189 }
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
190
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
191 wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec * wformat.Format.nBlockAlign;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
192
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
193 //open sound device
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
194 //WAVE_MAPPER always points to the default wave device on the system
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
195 result = waveOutOpen(&hWaveOut,WAVE_MAPPER,(WAVEFORMATEX*)&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION|WAVE_FORMAT_DIRECT);
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
196 if(result == WAVERR_BADFORMAT)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
197 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
198 mp_msg(MSGT_AO, MSGL_ERR,"ao_win32: format not supported switching to default\n");
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
199 ao_data.channels = wformat.Format.nChannels = 2;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
200 ao_data.samplerate = wformat.Format.nSamplesPerSec = 44100;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
201 ao_data.format = AFMT_S16_LE;
13017
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
202 ao_data.bps=ao_data.channels * ao_data.samplerate*2;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
203 wformat.Format.wBitsPerSample=16;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
204 wformat.Format.wFormatTag=WAVE_FORMAT_PCM;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
205 wformat.Format.nBlockAlign = wformat.Format.nChannels * (wformat.Format.wBitsPerSample >> 3);
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
206 wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec * wformat.Format.nBlockAlign;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
207 ao_data.buffersize=(wformat.Format.wBitsPerSample>>3)*wformat.Format.nChannels*SAMPLESIZE;
5b9c594dc6e9 untested multichannel support
faust3
parents: 12795
diff changeset
208 result = waveOutOpen(&hWaveOut,WAVE_MAPPER,(WAVEFORMATEX*)&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION);
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
209 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
210 if(result != MMSYSERR_NOERROR)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
211 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
212 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
213 return 0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
214 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
215 //allocate buffer memory as one big block
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
216 buffer = malloc(totalBufferSize);
9589
1823fdaffa73 fix -loop problem
faust3
parents: 8657
diff changeset
217 memset(buffer,0x0,totalBufferSize);
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
218 //and setup pointers to each buffer
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
219 waveBlocks = (WAVEHDR*)buffer;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
220 buffer += sizeof(WAVEHDR) * BUFFER_COUNT;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
221 for(i = 0; i < BUFFER_COUNT; i++) {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
222 waveBlocks[i].lpData = buffer;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
223 buffer += BUFFER_SIZE;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
224 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
225
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
226 return 1;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
227 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
228
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
229 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 12093
diff changeset
230 static void uninit(int immed)
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
231 {
12146
aaea699d0a67 support immed flag
faust3
parents: 12145
diff changeset
232 if(!immed)while(buffered_bytes > 0)usec_sleep(50000);
aaea699d0a67 support immed flag
faust3
parents: 12145
diff changeset
233 else buffered_bytes=0;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
234 waveOutReset(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
235 waveOutClose(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
236 mp_msg(MSGT_AO, MSGL_V,"waveOut device closed\n");
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
237 free(waveBlocks);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
238 mp_msg(MSGT_AO, MSGL_V,"buffer memory freed\n");
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
239 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
240
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
241 // stop playing and empty buffers (for seeking/pause)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
242 static void reset()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
243 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
244 waveOutReset(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
245 buf_write=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
246 buf_write_pos=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
247 full_buffers=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
248 buffered_bytes=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
249 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
250
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
251 // stop playing, keep buffers (for pause)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
252 static void audio_pause()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
253 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
254 waveOutPause(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
255 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
256
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
257 // resume playing, after audio_pause()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
258 static void audio_resume()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
259 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
260 waveOutRestart(hWaveOut);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
261 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
262
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
263 // return: how many bytes can be played without blocking
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
264 static int get_space()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
265 {
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
266 return BUFFER_COUNT*BUFFER_SIZE - buffered_bytes;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
267 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
268
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
269 //writes data into buffer, based on ringbuffer code in ao_sdl.c
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
270 static int write_waveOutBuffer(unsigned char* data,int len){
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
271 WAVEHDR* current;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
272 int len2=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
273 int x;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
274 while(len>0){
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
275 current = &waveBlocks[buf_write];
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
276 if(buffered_bytes==BUFFER_COUNT*BUFFER_SIZE) break;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
277 //unprepare the header if it is prepared
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
278 if(current->dwFlags & WHDR_PREPARED)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
279 waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
280 x=BUFFER_SIZE-buf_write_pos;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
281 if(x>len) x=len;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
282 memcpy(current->lpData+buf_write_pos,data+len2,x);
12151
75fdb659f5bf round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents: 12146
diff changeset
283 if(buf_write_pos==0)full_buffers++;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
284 len2+=x; len-=x;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
285 buffered_bytes+=x; buf_write_pos+=x;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
286 //prepare header and write data to device
12093
f54d02f6ddbf let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents: 11511
diff changeset
287 current->dwBufferLength = buf_write_pos;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
288 waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
289 waveOutWrite(hWaveOut, current, sizeof(WAVEHDR));
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
290
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
291 if(buf_write_pos>=BUFFER_SIZE){ //buffer is full find next
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
292 // block is full, find next!
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
293 buf_write=(buf_write+1)%BUFFER_COUNT;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
294 buf_write_pos=0;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
295 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
296 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
297 return len2;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
298 }
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
299
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
300 // plays 'len' bytes of 'data'
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
301 // it should round it down to outburst*n
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
302 // return: number of bytes played
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
303 static int play(void* data,int len,int flags)
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
304 {
12151
75fdb659f5bf round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents: 12146
diff changeset
305 len = (len/ao_data.outburst)*ao_data.outburst;
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
306 return write_waveOutBuffer(data,len);
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
307 }
10106
b5b7b2f4f069 10l remove unused global
faust3
parents: 9633
diff changeset
308
7913
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
309 // return: delay in seconds between first and last sample in buffer
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
310 static float get_delay()
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
311 {
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
312 return (float)(buffered_bytes + ao_data.buffersize)/(float)ao_data.bps;
61060cbe44fb new windows waveout audio driver
faust3
parents:
diff changeset
313 }