annotate libao2/ao_dsound.c @ 37185:917a3c4c2d39

lavf: fix AVSEEK_SIZE when STREAM_CTRL_GET_SIZE is not implemented. Would set the size to an uninitialized value before.
author reimar
date Wed, 17 Sep 2014 17:49:54 +0000
parents d61151719945
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
1 /*
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
2 * Windows DirectSound interface
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
3 *
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
4 * Copyright (c) 2004 Gabor Szecsi <deje@miki.hu>
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
5 *
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
6 * This file is part of MPlayer.
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
7 *
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
11 * (at your option) any later version.
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
12 *
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
16 * GNU General Public License for more details.
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
17 *
26743
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
18 * You should have received a copy of the GNU General Public License along
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
21 */
0f42fb42843c Use standard license headers with standard formatting.
diego
parents: 23458
diff changeset
22
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
23 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
24 \todo verify/extend multichannel support
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
25 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
26
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
27
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
28 #include <stdio.h>
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
29 #include <stdlib.h>
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
30 #include <windows.h>
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
31 #define DIRECTSOUND_VERSION 0x0600
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
32 #include <dsound.h>
16972
6a1eaca0e6c1 DirectSound's GetVolume and SetVolume use 100ths of decibels and range from -10,000 to 0.
joey
parents: 14947
diff changeset
33 #include <math.h>
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
34
14479
cae0dbeb44bb af_format.h needs config.h to be included first.
reimar
parents: 14398
diff changeset
35 #include "config.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14135
diff changeset
36 #include "libaf/af_format.h"
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
37 #include "audio_out.h"
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
38 #include "audio_out_internal.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13674
diff changeset
39 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13674
diff changeset
40 #include "libvo/fastmemcpy.h"
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
41 #include "osdep/timer.h"
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
42 #include "subopt-helper.h"
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
43
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
44
28823
9a5b8c2ed6de Make ao_info_t structs const.
reimar
parents: 28815
diff changeset
45 static const ao_info_t info =
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
46 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
47 "Windows DirectSound audio output",
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
48 "dsound",
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
49 "Gabor Szecsi <deje@miki.hu>",
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
50 ""
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
51 };
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
52
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
53 LIBAO_EXTERN(dsound)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
54
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
55 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
56 \todo use the definitions from the win32 api headers when they define these
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
57 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
58 #define WAVE_FORMAT_IEEE_FLOAT 0x0003
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
59 #define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
60 #define WAVE_FORMAT_EXTENSIBLE 0xFFFE
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
61
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
62 static const GUID KSDATAFORMAT_SUBTYPE_PCM = {0x1,0x0000,0x0010, {0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}};
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
63
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
64 #define SPEAKER_FRONT_LEFT 0x1
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
65 #define SPEAKER_FRONT_RIGHT 0x2
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
66 #define SPEAKER_FRONT_CENTER 0x4
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
67 #define SPEAKER_LOW_FREQUENCY 0x8
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
68 #define SPEAKER_BACK_LEFT 0x10
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
69 #define SPEAKER_BACK_RIGHT 0x20
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
70 #define SPEAKER_FRONT_LEFT_OF_CENTER 0x40
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
71 #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
72 #define SPEAKER_BACK_CENTER 0x100
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
73 #define SPEAKER_SIDE_LEFT 0x200
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
74 #define SPEAKER_SIDE_RIGHT 0x400
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
75 #define SPEAKER_TOP_CENTER 0x800
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
76 #define SPEAKER_TOP_FRONT_LEFT 0x1000
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
77 #define SPEAKER_TOP_FRONT_CENTER 0x2000
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
78 #define SPEAKER_TOP_FRONT_RIGHT 0x4000
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
79 #define SPEAKER_TOP_BACK_LEFT 0x8000
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
80 #define SPEAKER_TOP_BACK_CENTER 0x10000
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
81 #define SPEAKER_TOP_BACK_RIGHT 0x20000
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
82 #define SPEAKER_RESERVED 0x80000000
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
83
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
84 #ifndef _WAVEFORMATEXTENSIBLE_
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
85 typedef struct {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
86 WAVEFORMATEX Format;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
87 union {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
88 WORD wValidBitsPerSample; /* bits of precision */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
89 WORD wSamplesPerBlock; /* valid if wBitsPerSample==0 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
90 WORD wReserved; /* If neither applies, set to zero. */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
91 } Samples;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
92 DWORD dwChannelMask; /* which channels are */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
93 /* present in stream */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
94 GUID SubFormat;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
95 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
96 #endif
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
97
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
98 static const int channel_mask[] = {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
99 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_LOW_FREQUENCY,
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
100 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT,
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
101 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY,
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
102 SPEAKER_FRONT_LEFT | SPEAKER_FRONT_CENTER | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_LOW_FREQUENCY
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
103 };
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
104
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
105 static HINSTANCE hdsound_dll = NULL; ///handle to the dll
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
106 static LPDIRECTSOUND hds = NULL; ///direct sound object
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
107 static LPDIRECTSOUNDBUFFER hdspribuf = NULL; ///primary direct sound buffer
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
108 static LPDIRECTSOUNDBUFFER hdsbuf = NULL; ///secondary direct sound buffer (stream buffer)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
109 static int buffer_size = 0; ///size in bytes of the direct sound buffer
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
110 static int write_offset = 0; ///offset of the write cursor in the direct sound buffer
14555
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
111 static int min_free_space = 0; ///if the free space is below this value get_space() will return 0
14947
2f4f347bd5e4 get_space fix by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 14555
diff changeset
112 ///there will always be at least this amout of free space to prevent
2f4f347bd5e4 get_space fix by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 14555
diff changeset
113 ///get_space() from returning wrong values when buffer is 100% full.
2f4f347bd5e4 get_space fix by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 14555
diff changeset
114 ///will be replaced with nBlockAlign in init()
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
115 static int device_num = 0; ///wanted device number
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
116 static GUID device; ///guid of the device
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
117
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
118 /***************************************************************************************/
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
119
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
120 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
121 \brief output error message
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
122 \param err error code
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
123 \return string with the error message
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
124 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
125 static char * dserr2str(int err)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
126 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
127 switch (err) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
128 case DS_OK: return "DS_OK";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
129 case DS_NO_VIRTUALIZATION: return "DS_NO_VIRTUALIZATION";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
130 case DSERR_ALLOCATED: return "DS_NO_VIRTUALIZATION";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
131 case DSERR_CONTROLUNAVAIL: return "DSERR_CONTROLUNAVAIL";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
132 case DSERR_INVALIDPARAM: return "DSERR_INVALIDPARAM";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
133 case DSERR_INVALIDCALL: return "DSERR_INVALIDCALL";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
134 case DSERR_GENERIC: return "DSERR_GENERIC";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
135 case DSERR_PRIOLEVELNEEDED: return "DSERR_PRIOLEVELNEEDED";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
136 case DSERR_OUTOFMEMORY: return "DSERR_OUTOFMEMORY";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
137 case DSERR_BADFORMAT: return "DSERR_BADFORMAT";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
138 case DSERR_UNSUPPORTED: return "DSERR_UNSUPPORTED";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
139 case DSERR_NODRIVER: return "DSERR_NODRIVER";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
140 case DSERR_ALREADYINITIALIZED: return "DSERR_ALREADYINITIALIZED";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
141 case DSERR_NOAGGREGATION: return "DSERR_NOAGGREGATION";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
142 case DSERR_BUFFERLOST: return "DSERR_BUFFERLOST";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
143 case DSERR_OTHERAPPHASPRIO: return "DSERR_OTHERAPPHASPRIO";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
144 case DSERR_UNINITIALIZED: return "DSERR_UNINITIALIZED";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
145 case DSERR_NOINTERFACE: return "DSERR_NOINTERFACE";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
146 case DSERR_ACCESSDENIED: return "DSERR_ACCESSDENIED";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
147 default: return "unknown";
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
148 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
149 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
150
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
151 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
152 \brief uninitialize direct sound
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
153 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
154 static void UninitDirectSound(void)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
155 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
156 // finally release the DirectSound object
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
157 if (hds) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
158 IDirectSound_Release(hds);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
159 hds = NULL;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
160 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
161 // free DSOUND.DLL
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
162 if (hdsound_dll) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
163 FreeLibrary(hdsound_dll);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
164 hdsound_dll = NULL;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
165 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
166 mp_msg(MSGT_AO, MSGL_V, "ao_dsound: DirectSound uninitialized\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
167 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
168
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
169 /**
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
170 \brief print the commandline help
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
171 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16972
diff changeset
172 static void print_help(void)
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
173 {
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
174 mp_msg(MSGT_AO, MSGL_FATAL,
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
175 "\n-ao dsound commandline help:\n"
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
176 "Example: mplayer -ao dsound:device=1\n"
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
177 " sets 1st device\n"
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
178 "\nOptions:\n"
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
179 " device=<device-number>\n"
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
180 " Sets device number, use -v to get a list\n");
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
181 }
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
182
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
183
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
184 /**
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
185 \brief enumerate direct sound devices
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
186 \return TRUE to continue with the enumeration
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
187 */
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
188 static BOOL CALLBACK DirectSoundEnum(LPGUID guid,LPCSTR desc,LPCSTR module,LPVOID context)
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
189 {
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
190 int* device_index=context;
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
191 mp_msg(MSGT_AO, MSGL_V,"%i %s ",*device_index,desc);
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
192 if(device_num==*device_index){
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
193 mp_msg(MSGT_AO, MSGL_V,"<--");
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
194 if(guid){
23458
973e53dc7df5 Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents: 23457
diff changeset
195 memcpy(&device,guid,sizeof(GUID));
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
196 }
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
197 }
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
198 mp_msg(MSGT_AO, MSGL_V,"\n");
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
199 (*device_index)++;
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
200 return TRUE;
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
201 }
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
202
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
203
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
204 /**
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
205 \brief initilize direct sound
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
206 \return 0 if error, 1 if ok
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
207 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
208 static int InitDirectSound(void)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
209 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
210 DSCAPS dscaps;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
211
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
212 // initialize directsound
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
213 HRESULT (WINAPI *OurDirectSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
214 HRESULT (WINAPI *OurDirectSoundEnumerate)(LPDSENUMCALLBACKA, LPVOID);
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
215 int device_index=0;
29586
2eff450157cd The suboption parser now takes a const options list, so mark them all const.
reimar
parents: 29263
diff changeset
216 const opt_t subopts[] = {
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
217 {"device", OPT_ARG_INT, &device_num,NULL},
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
218 {NULL}
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
219 };
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
220 if (subopt_parse(ao_subdevice, subopts) != 0) {
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
221 print_help();
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
222 return 0;
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
223 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
224
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
225 hdsound_dll = LoadLibrary("DSOUND.DLL");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
226 if (hdsound_dll == NULL) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
227 mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot load DSOUND.DLL\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
228 return 0;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
229 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
230 OurDirectSoundCreate = (void*)GetProcAddress(hdsound_dll, "DirectSoundCreate");
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
231 OurDirectSoundEnumerate = (void*)GetProcAddress(hdsound_dll, "DirectSoundEnumerateA");
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
232
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
233 if (OurDirectSoundCreate == NULL || OurDirectSoundEnumerate == NULL) {
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
234 mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: GetProcAddress FAILED\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
235 FreeLibrary(hdsound_dll);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
236 return 0;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
237 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
238
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
239 // Enumerate all directsound devices
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
240 mp_msg(MSGT_AO, MSGL_V,"ao_dsound: Output Devices:\n");
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
241 OurDirectSoundEnumerate(DirectSoundEnum,&device_index);
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
242
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
243 // Create the direct sound object
14398
889b6b99b1b8 device selection support
faust3
parents: 14264
diff changeset
244 if FAILED(OurDirectSoundCreate((device_num)?&device:NULL, &hds, NULL )) {
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
245 mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot create a DirectSound device\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
246 FreeLibrary(hdsound_dll);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
247 return 0;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
248 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
249
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
250 /* Set DirectSound Cooperative level, ie what control we want over Windows
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
251 * sound device. In our case, DSSCL_EXCLUSIVE means that we can modify the
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
252 * settings of the primary buffer, but also that only the sound of our
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
253 * application will be hearable when it will have the focus.
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
254 * !!! (this is not really working as intended yet because to set the
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
255 * cooperative level you need the window handle of your application, and
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
256 * I don't know of any easy way to get it. Especially since we might play
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
257 * sound without any video, and so what window handle should we use ???
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
258 * The hack for now is to use the Desktop window handle - it seems to be
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
259 * working */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
260 if (IDirectSound_SetCooperativeLevel(hds, GetDesktopWindow(), DSSCL_EXCLUSIVE)) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
261 mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot set direct sound cooperative level\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
262 IDirectSound_Release(hds);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
263 FreeLibrary(hdsound_dll);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
264 return 0;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
265 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
266 mp_msg(MSGT_AO, MSGL_V, "ao_dsound: DirectSound initialized\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
267
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
268 memset(&dscaps, 0, sizeof(DSCAPS));
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
269 dscaps.dwSize = sizeof(DSCAPS);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
270 if (DS_OK == IDirectSound_GetCaps(hds, &dscaps)) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
271 if (dscaps.dwFlags & DSCAPS_EMULDRIVER) mp_msg(MSGT_AO, MSGL_V, "ao_dsound: DirectSound is emulated, waveOut may give better performance\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
272 } else {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
273 mp_msg(MSGT_AO, MSGL_V, "ao_dsound: cannot get device capabilities\n");
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
274 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
275
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
276 return 1;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
277 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
278
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
279 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
280 \brief destroy the direct sound buffer
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
281 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
282 static void DestroyBuffer(void)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
283 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
284 if (hdsbuf) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
285 IDirectSoundBuffer_Release(hdsbuf);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
286 hdsbuf = NULL;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
287 }
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
288 if (hdspribuf) {
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
289 IDirectSoundBuffer_Release(hdspribuf);
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
290 hdspribuf = NULL;
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
291 }
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
292 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
293
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
294 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
295 \brief fill sound buffer
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
296 \param data pointer to the sound data to copy
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
297 \param len length of the data to copy in bytes
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
298 \return number of copyed bytes
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
299 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
300 static int write_buffer(unsigned char *data, int len)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
301 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
302 HRESULT res;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
303 LPVOID lpvPtr1;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
304 DWORD dwBytes1;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
305 LPVOID lpvPtr2;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
306 DWORD dwBytes2;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
307
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
308 // Lock the buffer
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
309 res = IDirectSoundBuffer_Lock(hdsbuf,write_offset, len, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
310 // If the buffer was lost, restore and retry lock.
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
311 if (DSERR_BUFFERLOST == res)
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
312 {
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
313 IDirectSoundBuffer_Restore(hdsbuf);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
314 res = IDirectSoundBuffer_Lock(hdsbuf,write_offset, len, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
315 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
316
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
317
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
318 if (SUCCEEDED(res))
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
319 {
30240
1c55c7f6874b More uses of AF_FORMAT_IS_AC3
reimar
parents: 29826
diff changeset
320 if( (ao_data.channels == 6) && !AF_FORMAT_IS_AC3(ao_data.format) ) {
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
321 // reorder channels while writing to pointers.
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
322 // it's this easy because buffer size and len are always
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
323 // aligned to multiples of channels*bytespersample
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
324 // there's probably some room for speed improvements here
35472
5e4973f679cf Make lookup table static.
reimar
parents: 35471
diff changeset
325 static const int chantable[6] = {0, 1, 4, 5, 2, 3}; // reorder "matrix"
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
326 int i, j;
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
327 int numsamp,sampsize;
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
328
14249
8f59f661f317 hopefully final fix
alex
parents: 14245
diff changeset
329 sampsize = af_fmt2bits(ao_data.format)>>3; // bytes per sample
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
330 numsamp = dwBytes1 / (ao_data.channels * sampsize); // number of samples for each channel in this buffer
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
331
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
332 for( i = 0; i < numsamp; i++ ) for( j = 0; j < ao_data.channels; j++ ) {
23458
973e53dc7df5 Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents: 23457
diff changeset
333 memcpy(lpvPtr1+(i*ao_data.channels*sampsize)+(chantable[j]*sampsize),data+(i*ao_data.channels*sampsize)+(j*sampsize),sampsize);
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
334 }
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
335
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
336 if (NULL != lpvPtr2 )
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
337 {
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
338 numsamp = dwBytes2 / (ao_data.channels * sampsize);
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
339 for( i = 0; i < numsamp; i++ ) for( j = 0; j < ao_data.channels; j++ ) {
23458
973e53dc7df5 Do not use fast_memcpy for small size copy, esp. when the size is constant
reimar
parents: 23457
diff changeset
340 memcpy(lpvPtr2+(i*ao_data.channels*sampsize)+(chantable[j]*sampsize),data+dwBytes1+(i*ao_data.channels*sampsize)+(j*sampsize),sampsize);
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
341 }
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
342 }
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
343
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
344 write_offset+=dwBytes1+dwBytes2;
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
345 if(write_offset>=buffer_size)write_offset=dwBytes2;
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
346 } else {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
347 // Write to pointers without reordering.
23457
a124f3abc1ec Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents: 20250
diff changeset
348 fast_memcpy(lpvPtr1,data,dwBytes1);
a124f3abc1ec Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents: 20250
diff changeset
349 if (NULL != lpvPtr2 )fast_memcpy(lpvPtr2,data+dwBytes1,dwBytes2);
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
350 write_offset+=dwBytes1+dwBytes2;
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
351 if(write_offset>=buffer_size)write_offset=dwBytes2;
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
352 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
353
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
354 // Release the data back to DirectSound.
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
355 res = IDirectSoundBuffer_Unlock(hdsbuf,lpvPtr1,dwBytes1,lpvPtr2,dwBytes2);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
356 if (SUCCEEDED(res))
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
357 {
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
358 // Success.
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
359 DWORD status;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
360 IDirectSoundBuffer_GetStatus(hdsbuf, &status);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
361 if (!(status & DSBSTATUS_PLAYING)){
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
362 res = IDirectSoundBuffer_Play(hdsbuf, 0, 0, DSBPLAY_LOOPING);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
363 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
364 return dwBytes1+dwBytes2;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
365 }
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
366 }
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
367 // Lock, Unlock, or Restore failed.
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
368 return 0;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
369 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
370
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
371 /***************************************************************************************/
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
372
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
373 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
374 \brief handle control commands
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
375 \param cmd command
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
376 \param arg argument
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
377 \return CONTROL_OK or -1 in case the command can't be handled
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
378 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
379 static int control(int cmd, void *arg)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
380 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
381 DWORD volume;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
382 switch (cmd) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
383 case AOCONTROL_GET_VOLUME: {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
384 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
385 IDirectSoundBuffer_GetVolume(hdsbuf, &volume);
16972
6a1eaca0e6c1 DirectSound's GetVolume and SetVolume use 100ths of decibels and range from -10,000 to 0.
joey
parents: 14947
diff changeset
386 vol->left = vol->right = pow(10.0, (float)(volume+10000) / 5000.0);
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
387 //printf("ao_dsound: volume: %f\n",vol->left);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
388 return CONTROL_OK;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
389 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
390 case AOCONTROL_SET_VOLUME: {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
391 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
16972
6a1eaca0e6c1 DirectSound's GetVolume and SetVolume use 100ths of decibels and range from -10,000 to 0.
joey
parents: 14947
diff changeset
392 volume = (DWORD)(log10(vol->right) * 5000.0) - 10000;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
393 IDirectSoundBuffer_SetVolume(hdsbuf, volume);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
394 //printf("ao_dsound: volume: %f\n",vol->left);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
395 return CONTROL_OK;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
396 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
397 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
398 return -1;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
399 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
400
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
401 /**
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
402 \brief setup sound device
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
403 \param rate samplerate
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
404 \param channels number of channels
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
405 \param format format
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
406 \param flags unused
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
407 \return 1=success 0=fail
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
408 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
409 static int init(int rate, int channels, int format, int flags)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
410 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
411 int res;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
412
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
413 WAVEFORMATEXTENSIBLE wformat;
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
414 DSBUFFERDESC dsbpridesc;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
415 DSBUFFERDESC dsbdesc;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
416
35471
f2a11c8695a4 Move declarations to the top of the function.
reimar
parents: 35470
diff changeset
417 if (!InitDirectSound()) return 0;
f2a11c8695a4 Move declarations to the top of the function.
reimar
parents: 35470
diff changeset
418
29826
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29586
diff changeset
419 //check if the channel count and format is supported in general
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29586
diff changeset
420 if (channels > 6) {
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29586
diff changeset
421 UninitDirectSound();
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29586
diff changeset
422 mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: 8 channel audio not yet supported\n");
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29586
diff changeset
423 return 0;
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29586
diff changeset
424 }
30241
02b9c1a452e1 Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents: 30240
diff changeset
425
02b9c1a452e1 Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents: 30240
diff changeset
426 if (AF_FORMAT_IS_AC3(format))
02b9c1a452e1 Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents: 30240
diff changeset
427 format = AF_FORMAT_AC3_NE;
14135
234295985ccd disable all unknown formats in the windows aos
faust3
parents: 14123
diff changeset
428 switch(format){
30241
02b9c1a452e1 Add support for distinguishing between little- and big-endian SPDIF AC3
reimar
parents: 30240
diff changeset
429 case AF_FORMAT_AC3_NE:
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14135
diff changeset
430 case AF_FORMAT_S24_LE:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14135
diff changeset
431 case AF_FORMAT_S16_LE:
28815
ce24a9f06ccb The 8 bit per sample formats are unsigned on Windows, fixes playback with
reimar
parents: 26743
diff changeset
432 case AF_FORMAT_U8:
14135
234295985ccd disable all unknown formats in the windows aos
faust3
parents: 14123
diff changeset
433 break;
234295985ccd disable all unknown formats in the windows aos
faust3
parents: 14123
diff changeset
434 default:
14264
cb5fbade8a5c af_fmt2str_short
alex
parents: 14249
diff changeset
435 mp_msg(MSGT_AO, MSGL_V,"ao_dsound: format %s not supported defaulting to Signed 16-bit Little-Endian\n",af_fmt2str_short(format));
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14135
diff changeset
436 format=AF_FORMAT_S16_LE;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
437 }
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
438 //fill global ao_data
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
439 ao_data.channels = channels;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
440 ao_data.samplerate = rate;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
441 ao_data.format = format;
14249
8f59f661f317 hopefully final fix
alex
parents: 14245
diff changeset
442 ao_data.bps = channels * rate * (af_fmt2bits(format)>>3);
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
443 if(ao_data.buffersize==-1) ao_data.buffersize = ao_data.bps; // space for 1 sec
14264
cb5fbade8a5c af_fmt2str_short
alex
parents: 14249
diff changeset
444 mp_msg(MSGT_AO, MSGL_V,"ao_dsound: Samplerate:%iHz Channels:%i Format:%s\n", rate, channels, af_fmt2str_short(format));
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
445 mp_msg(MSGT_AO, MSGL_V,"ao_dsound: Buffersize:%d bytes (%d msec)\n", ao_data.buffersize, ao_data.buffersize / ao_data.bps * 1000);
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
446
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
447 //fill waveformatex
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
448 ZeroMemory(&wformat, sizeof(WAVEFORMATEXTENSIBLE));
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
449 wformat.Format.cbSize = (channels > 2) ? sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX) : 0;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
450 wformat.Format.nChannels = channels;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
451 wformat.Format.nSamplesPerSec = rate;
30240
1c55c7f6874b More uses of AF_FORMAT_IS_AC3
reimar
parents: 29826
diff changeset
452 if (AF_FORMAT_IS_AC3(format)) {
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
453 wformat.Format.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
454 wformat.Format.wBitsPerSample = 16;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
455 wformat.Format.nBlockAlign = 4;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
456 } else {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
457 wformat.Format.wFormatTag = (channels > 2) ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
14249
8f59f661f317 hopefully final fix
alex
parents: 14245
diff changeset
458 wformat.Format.wBitsPerSample = af_fmt2bits(format);
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
459 wformat.Format.nBlockAlign = wformat.Format.nChannels * (wformat.Format.wBitsPerSample >> 3);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
460 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
461
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
462 // fill in primary sound buffer descriptor
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
463 memset(&dsbpridesc, 0, sizeof(DSBUFFERDESC));
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
464 dsbpridesc.dwSize = sizeof(DSBUFFERDESC);
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
465 dsbpridesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
466 dsbpridesc.dwBufferBytes = 0;
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
467 dsbpridesc.lpwfxFormat = NULL;
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
468
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
469
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
470 // fill in the secondary sound buffer (=stream buffer) descriptor
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
471 memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
472 dsbdesc.dwSize = sizeof(DSBUFFERDESC);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
473 dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 /** Better position accuracy */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
474 | DSBCAPS_GLOBALFOCUS /** Allows background playing */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
475 | DSBCAPS_CTRLVOLUME; /** volume control enabled */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
476
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
477 if (channels > 2) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
478 wformat.dwChannelMask = channel_mask[channels - 3];
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
479 wformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
480 wformat.Samples.wValidBitsPerSample = wformat.Format.wBitsPerSample;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
481 // Needed for 5.1 on emu101k - shit soundblaster
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
482 dsbdesc.dwFlags |= DSBCAPS_LOCHARDWARE;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
483 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
484 wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec * wformat.Format.nBlockAlign;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
485
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
486 dsbdesc.dwBufferBytes = ao_data.buffersize;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
487 dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&wformat;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
488 buffer_size = dsbdesc.dwBufferBytes;
14555
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
489 write_offset = 0;
14947
2f4f347bd5e4 get_space fix by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 14555
diff changeset
490 min_free_space = wformat.Format.nBlockAlign;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
491 ao_data.outburst = wformat.Format.nBlockAlign * 512;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
492
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
493 // create primary buffer and set its format
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
494
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
495 res = IDirectSound_CreateSoundBuffer( hds, &dsbpridesc, &hdspribuf, NULL );
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
496 if ( res != DS_OK ) {
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
497 UninitDirectSound();
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
498 mp_msg(MSGT_AO, MSGL_ERR,"ao_dsound: cannot create primary buffer (%s)\n", dserr2str(res));
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
499 return 0;
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
500 }
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
501 res = IDirectSoundBuffer_SetFormat( hdspribuf, (WAVEFORMATEX *)&wformat );
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
502 if ( res != DS_OK ) mp_msg(MSGT_AO, MSGL_WARN,"ao_dsound: cannot set primary buffer format (%s), using standard setting (bad quality)", dserr2str(res));
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
503
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
504 mp_msg(MSGT_AO, MSGL_V, "ao_dsound: primary buffer created\n");
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
505
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
506 // now create the stream buffer
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
507
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
508 res = IDirectSound_CreateSoundBuffer(hds, &dsbdesc, &hdsbuf, NULL);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
509 if (res != DS_OK) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
510 if (dsbdesc.dwFlags & DSBCAPS_LOCHARDWARE) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
511 // Try without DSBCAPS_LOCHARDWARE
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
512 dsbdesc.dwFlags &= ~DSBCAPS_LOCHARDWARE;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
513 res = IDirectSound_CreateSoundBuffer(hds, &dsbdesc, &hdsbuf, NULL);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
514 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
515 if (res != DS_OK) {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
516 UninitDirectSound();
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
517 mp_msg(MSGT_AO, MSGL_ERR, "ao_dsound: cannot create secondary (stream)buffer (%s)\n", dserr2str(res));
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
518 return 0;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
519 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
520 }
13640
a7d080bc610f ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13460
diff changeset
521 mp_msg(MSGT_AO, MSGL_V, "ao_dsound: secondary (stream)buffer created\n");
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
522 return 1;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
523 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
524
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
525
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
526
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
527 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
528 \brief stop playing and empty buffers (for seeking/pause)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
529 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16972
diff changeset
530 static void reset(void)
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
531 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
532 IDirectSoundBuffer_Stop(hdsbuf);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
533 // reset directsound buffer
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
534 IDirectSoundBuffer_SetCurrentPosition(hdsbuf, 0);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
535 write_offset=0;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
536 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
537
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
538 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
539 \brief stop playing, keep buffers (for pause)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
540 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16972
diff changeset
541 static void audio_pause(void)
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
542 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
543 IDirectSoundBuffer_Stop(hdsbuf);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
544 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
545
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
546 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
547 \brief resume playing, after audio_pause()
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
548 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16972
diff changeset
549 static void audio_resume(void)
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
550 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
551 IDirectSoundBuffer_Play(hdsbuf, 0, 0, DSBPLAY_LOOPING);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
552 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
553
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
554 /**
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
555 \brief close audio device
14555
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
556 \param immed stop playback immediately
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
557 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
558 static void uninit(int immed)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
559 {
14555
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
560 if(immed)reset();
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
561 else{
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
562 DWORD status;
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
563 IDirectSoundBuffer_Play(hdsbuf, 0, 0, 0);
35469
539bfa51eb72 ao_dsound: Add a hack that avoid cutting of audio,
reimar
parents: 30612
diff changeset
564 // This should not be necessary, but a lot of drivers
539bfa51eb72 ao_dsound: Add a hack that avoid cutting of audio,
reimar
parents: 30612
diff changeset
565 // do not correctly report the status here, causing
539bfa51eb72 ao_dsound: Add a hack that avoid cutting of audio,
reimar
parents: 30612
diff changeset
566 // audio to be discarded. So we sleep approximately
539bfa51eb72 ao_dsound: Add a hack that avoid cutting of audio,
reimar
parents: 30612
diff changeset
567 // the right amount of time first.
539bfa51eb72 ao_dsound: Add a hack that avoid cutting of audio,
reimar
parents: 30612
diff changeset
568 usec_sleep(get_delay() * 1000 * 1000);
14555
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
569 while(!IDirectSoundBuffer_GetStatus(hdsbuf,&status) && (status&DSBSTATUS_PLAYING))
35470
116dbb38eac0 Reduce sleep time now that we will spend much less time in this loop.
reimar
parents: 35469
diff changeset
570 usec_sleep(5000);
14555
6fb9eca97d41 support immed flag, always initialize write_offset, min_free_space doesn't seem to be required anymore after Florian Dietrichs patches
faust3
parents: 14479
diff changeset
571 }
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
572 DestroyBuffer();
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
573 UninitDirectSound();
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
574 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
575
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
576 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
577 \brief find out how many bytes can be written into the audio buffer without
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
578 \return free space in bytes, has to return 0 if the buffer is almost full
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
579 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16972
diff changeset
580 static int get_space(void)
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
581 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
582 int space;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
583 DWORD play_offset;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
584 IDirectSoundBuffer_GetCurrentPosition(hdsbuf,&play_offset,NULL);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
585 space=buffer_size-(write_offset-play_offset);
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
586 // | | <-- const --> | | |
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
587 // buffer start play_cursor write_cursor write_offset buffer end
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
588 // play_cursor is the actual postion of the play cursor
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
589 // write_cursor is the position after which it is assumed to be save to write data
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
590 // write_offset is the postion where we actually write the data to
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
591 if(space > buffer_size)space -= buffer_size; // write_offset < play_offset
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
592 if(space < min_free_space)return 0;
14947
2f4f347bd5e4 get_space fix by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 14555
diff changeset
593 return space-min_free_space;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
594 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
595
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
596 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
597 \brief play 'len' bytes of 'data'
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
598 \param data pointer to the data to play
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
599 \param len size in bytes of the data buffer, gets rounded down to outburst*n
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
600 \param flags currently unused
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
601 \return number of played bytes
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
602 */
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
603 static int play(void* data, int len, int flags)
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
604 {
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
605 DWORD play_offset;
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
606 int space;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
607
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
608 // make sure we have enough space to write data
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
609 IDirectSoundBuffer_GetCurrentPosition(hdsbuf,&play_offset,NULL);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
610 space=buffer_size-(write_offset-play_offset);
13674
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
611 if(space > buffer_size)space -= buffer_size; // write_offset < play_offset
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
612 if(space < len) len = space;
b7322244e53c channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents: 13640
diff changeset
613
20250
7cfd3a04d537 Implement AOPLAY_FINAL_CHUNK support for dshow and win32 out.
reimar
parents: 19614
diff changeset
614 if (!(flags & AOPLAY_FINAL_CHUNK))
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
615 len = (len / ao_data.outburst) * ao_data.outburst;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
616 return write_buffer(data, len);
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
617 }
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
618
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
619 /**
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
620 \brief get the delay between the first and last sample in the buffer
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
621 \return delay in seconds
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
622 */
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 16972
diff changeset
623 static float get_delay(void)
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
624 {
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
625 DWORD play_offset;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
626 int space;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
627 IDirectSoundBuffer_GetCurrentPosition(hdsbuf,&play_offset,NULL);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28823
diff changeset
628 space=play_offset-write_offset;
13460
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
629 if(space <= 0)space += buffer_size;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
630 return (float)(buffer_size - space) / (float)ao_data.bps;
70d8f1975fc8 directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff changeset
631 }