untested multichannel support

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13018 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
faust3 2004-08-14 10:03:26 +00:00
parent caa21c891c
commit 40a0c7778d
1 changed files with 74 additions and 24 deletions

View File

@ -31,6 +31,50 @@
#include "osdep/timer.h" #include "osdep/timer.h"
#define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092 #define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092
#define WAVE_FORMAT_EXTENSIBLE 0xFFFE
static const GUID KSDATAFORMAT_SUBTYPE_PCM = {
0x1,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}
};
typedef struct {
WAVEFORMATEX Format;
union {
WORD wValidBitsPerSample;
WORD wSamplesPerBlock;
WORD wReserved;
} Samples;
DWORD dwChannelMask;
GUID SubFormat;
} WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
#define SPEAKER_FRONT_LEFT 0x1
#define SPEAKER_FRONT_RIGHT 0x2
#define SPEAKER_FRONT_CENTER 0x4
#define SPEAKER_LOW_FREQUENCY 0x8
#define SPEAKER_BACK_LEFT 0x10
#define SPEAKER_BACK_RIGHT 0x20
#define SPEAKER_FRONT_LEFT_OF_CENTER 0x40
#define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80
#define SPEAKER_BACK_CENTER 0x100
#define SPEAKER_SIDE_LEFT 0x200
#define SPEAKER_SIDE_RIGHT 0x400
#define SPEAKER_TOP_CENTER 0x800
#define SPEAKER_TOP_FRONT_LEFT 0x1000
#define SPEAKER_TOP_FRONT_CENTER 0x2000
#define SPEAKER_TOP_FRONT_RIGHT 0x4000
#define SPEAKER_TOP_BACK_LEFT 0x8000
#define SPEAKER_TOP_BACK_CENTER 0x10000
#define SPEAKER_TOP_BACK_RIGHT 0x20000
static const int channel_mask[] = {
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY,
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY,
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_CENTER | SPEAKER_LOW_FREQUENCY,
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY
};
#define SAMPLESIZE 1024 #define SAMPLESIZE 1024
#define BUFFER_SIZE 4096 #define BUFFER_SIZE 4096
@ -98,7 +142,7 @@ static int control(int cmd,void *arg)
// return: 1=success 0=fail // return: 1=success 0=fail
static int init(int rate,int channels,int format,int flags) static int init(int rate,int channels,int format,int flags)
{ {
WAVEFORMATEX wformat; WAVEFORMATEXTENSIBLE wformat;
DWORD totalBufferSize = (BUFFER_SIZE + sizeof(WAVEHDR)) * BUFFER_COUNT; DWORD totalBufferSize = (BUFFER_SIZE + sizeof(WAVEHDR)) * BUFFER_COUNT;
MMRESULT result; MMRESULT result;
unsigned char* buffer; unsigned char* buffer;
@ -121,41 +165,47 @@ static int init(int rate,int channels,int format,int flags)
mp_msg(MSGT_AO, MSGL_V,"ao_win32: Buffersize:%d\n",ao_data.buffersize); mp_msg(MSGT_AO, MSGL_V,"ao_win32: Buffersize:%d\n",ao_data.buffersize);
//fill waveformatex //fill waveformatex
ZeroMemory( &wformat, sizeof(WAVEFORMATEX)); ZeroMemory( &wformat, sizeof(WAVEFORMATEXTENSIBLE));
wformat.cbSize = 0; /* size of _extra_ info */ wformat.Format.cbSize = (channels>2)?sizeof(WAVEFORMATEXTENSIBLE):0;
wformat.nChannels = channels; wformat.Format.nChannels = channels;
wformat.nSamplesPerSec = rate; wformat.Format.nSamplesPerSec = rate;
if(format == AFMT_AC3) if(format == AFMT_AC3)
{ {
wformat.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF; wformat.Format.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF;
wformat.wBitsPerSample = 16; wformat.Format.wBitsPerSample = 16;
wformat.nBlockAlign = 4; wformat.Format.nBlockAlign = 4;
} }
else else
{ {
wformat.wFormatTag = WAVE_FORMAT_PCM; wformat.Format.wFormatTag = (channels>2)?WAVE_FORMAT_EXTENSIBLE:WAVE_FORMAT_PCM;
wformat.wBitsPerSample = audio_out_format_bits(format); wformat.Format.wBitsPerSample = audio_out_format_bits(format);
wformat.nBlockAlign = wformat.nChannels * (wformat.wBitsPerSample >> 3); wformat.Format.nBlockAlign = wformat.Format.nChannels * (wformat.Format.wBitsPerSample >> 3);
} }
wformat.nAvgBytesPerSec = wformat.nSamplesPerSec * wformat.nBlockAlign; if(channels>2)
{
wformat.dwChannelMask = channel_mask[channels-3];
wformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
wformat.Samples.wValidBitsPerSample=audio_out_format_bits(format);
}
wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec * wformat.Format.nBlockAlign;
//open sound device //open sound device
//WAVE_MAPPER always points to the default wave device on the system //WAVE_MAPPER always points to the default wave device on the system
result = waveOutOpen(&hWaveOut,WAVE_MAPPER,&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION); result = waveOutOpen(&hWaveOut,WAVE_MAPPER,(WAVEFORMATEX*)&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION|WAVE_FORMAT_DIRECT);
if(result == WAVERR_BADFORMAT) if(result == WAVERR_BADFORMAT)
{ {
mp_msg(MSGT_AO, MSGL_ERR,"ao_win32: format not supported switching to default\n"); mp_msg(MSGT_AO, MSGL_ERR,"ao_win32: format not supported switching to default\n");
ao_data.channels = wformat.nChannels = 2; ao_data.channels = wformat.Format.nChannels = 2;
ao_data.samplerate = wformat.nSamplesPerSec = 44100; ao_data.samplerate = wformat.Format.nSamplesPerSec = 44100;
ao_data.format = AFMT_S16_LE; ao_data.format = AFMT_S16_LE;
ao_data.bps=ao_data.channels * ao_data.samplerate*2; ao_data.bps=ao_data.channels * ao_data.samplerate*2;
ao_data.buffersize=wformat.wBitsPerSample=16; wformat.Format.wBitsPerSample=16;
wformat.nBlockAlign = wformat.nChannels * (wformat.wBitsPerSample >> 3); wformat.Format.wFormatTag=WAVE_FORMAT_PCM;
wformat.nAvgBytesPerSec = wformat.nSamplesPerSec * wformat.nBlockAlign; wformat.Format.nBlockAlign = wformat.Format.nChannels * (wformat.Format.wBitsPerSample >> 3);
ao_data.buffersize/=8; wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec * wformat.Format.nBlockAlign;
ao_data.buffersize*= ao_data.channels; ao_data.buffersize=(wformat.Format.wBitsPerSample>>3)*wformat.Format.nChannels*SAMPLESIZE;
ao_data.buffersize*= SAMPLESIZE; result = waveOutOpen(&hWaveOut,WAVE_MAPPER,(WAVEFORMATEX*)&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION);
result = waveOutOpen(&hWaveOut,WAVE_MAPPER,&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION);
} }
if(result != MMSYSERR_NOERROR) if(result != MMSYSERR_NOERROR)
{ {