summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-04-20 04:52:51 +0200
committerwm4 <wm4@nowhere>2013-02-06 23:04:12 +0100
commit94f72b1e59f93cdd310d9cb6bcaa4fa06c8c3f75 (patch)
tree01f0663735a21abc52f6dc894062c2708f8e8161
parent37c5c114af8b4747dfa0664bf967958baa9a1c91 (diff)
downloadmpv-94f72b1e59f93cdd310d9cb6bcaa4fa06c8c3f75.tar.bz2
mpv-94f72b1e59f93cdd310d9cb6bcaa4fa06c8c3f75.tar.xz
ao_dsound: support 6.1 and 7.1 channel configurations
Instead of doing the channel reordering manually, use the existing support in reorder_ch.c. Untested.
-rw-r--r--audio/out/ao_dsound.c73
1 files changed, 43 insertions, 30 deletions
diff --git a/audio/out/ao_dsound.c b/audio/out/ao_dsound.c
index 8d3124122c..ae6a6de324 100644
--- a/audio/out/ao_dsound.c
+++ b/audio/out/ao_dsound.c
@@ -32,9 +32,12 @@
#include <dsound.h>
#include <math.h>
+#include <libavutil/avutil.h>
+
#include "config.h"
#include "audio/format.h"
#include "ao.h"
+#include "audio/reorder_ch.h"
#include "audio_out_internal.h"
#include "core/mp_msg.h"
#include "osdep/timer.h"
@@ -104,10 +107,25 @@ typedef struct {
#endif
static const int channel_mask[] = {
- SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY,
- SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT,
- SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY,
- SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY
+ /* 1 */ SPEAKER_FRONT_CENTER,
+ /* 2 */ SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT,
+ /* 3 */ SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT
+ | SPEAKER_LOW_FREQUENCY,
+ /* 4 */ SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT
+ | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT,
+ /* 5 */ SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT
+ | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT
+ | SPEAKER_LOW_FREQUENCY,
+ /* 6 */ SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT
+ | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT
+ | SPEAKER_LOW_FREQUENCY,
+ /* 7 */ SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT
+ | SPEAKER_BACK_LEFT | SPEAKER_BACK_CENTER | SPEAKER_BACK_RIGHT
+ | SPEAKER_LOW_FREQUENCY,
+ /* 8 */ SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT
+ | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT
+ | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT
+ | SPEAKER_LOW_FREQUENCY,
};
static HINSTANCE hdsound_dll = NULL; ///handle to the dll
@@ -329,32 +347,27 @@ static int write_buffer(unsigned char *data, int len)
if (SUCCEEDED(res))
{
- if( (ao_data.channels == 6) && !AF_FORMAT_IS_AC3(ao_data.format) ) {
- // reorder channels while writing to pointers.
- // it's this easy because buffer size and len are always
- // aligned to multiples of channels*bytespersample
- // there's probably some room for speed improvements here
- const int chantable[6] = {0, 1, 4, 5, 2, 3}; // reorder "matrix"
- int i, j;
- int numsamp,sampsize;
-
- sampsize = af_fmt2bits(ao_data.format)>>3; // bytes per sample
- numsamp = dwBytes1 / (ao_data.channels * sampsize); // number of samples for each channel in this buffer
-
- for( i = 0; i < numsamp; i++ ) for( j = 0; j < ao_data.channels; j++ ) {
- memcpy((char*)lpvPtr1+(i*ao_data.channels*sampsize)+(chantable[j]*sampsize),data+(i*ao_data.channels*sampsize)+(j*sampsize),sampsize);
- }
-
- if (NULL != lpvPtr2 )
- {
- numsamp = dwBytes2 / (ao_data.channels * sampsize);
- for( i = 0; i < numsamp; i++ ) for( j = 0; j < ao_data.channels; j++ ) {
- memcpy((char*)lpvPtr2+(i*ao_data.channels*sampsize)+(chantable[j]*sampsize),data+dwBytes1+(i*ao_data.channels*sampsize)+(j*sampsize),sampsize);
- }
- }
+ if (!AF_FORMAT_IS_AC3(ao_data.format)) {
+ int sampsize = af_fmt2bits(ao_data.format) / 8;
+ reorder_channel_copy_nch(data,
+ AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
+ lpvPtr1,
+ AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
+ ao_data.channels,
+ dwBytes1 / sampsize,
+ sampsize);
+ if (lpvPtr2 != NULL)
+ reorder_channel_copy_nch(data + dwBytes1,
+ AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
+ lpvPtr2,
+ AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
+ ao_data.channels,
+ dwBytes2 / sampsize,
+ sampsize);
write_offset+=dwBytes1+dwBytes2;
- if(write_offset>=buffer_size)write_offset=dwBytes2;
+ if(write_offset>=buffer_size)
+ write_offset=dwBytes2;
} else {
// Write to pointers without reordering.
memcpy(lpvPtr1,data,dwBytes1);
@@ -432,7 +445,7 @@ static int init(int rate, int channels, int format, int flags)
DSBUFFERDESC dsbdesc;
//check if the channel count and format is supported in general
- if (channels > 6) {
+ if (channels > FF_ARRAY_ELEMS(channel_mask)) {
UninitDirectSound();
mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: 8 channel audio not yet supported\n");
return 0;
@@ -490,7 +503,7 @@ static int init(int rate, int channels, int format, int flags)
| DSBCAPS_CTRLVOLUME; /** volume control enabled */
if (channels > 2) {
- wformat.dwChannelMask = channel_mask[channels - 3];
+ wformat.dwChannelMask = channel_mask[channels - 1];
wformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
wformat.Samples.wValidBitsPerSample = wformat.Format.wBitsPerSample;
// Needed for 5.1 on emu101k - shit soundblaster