Mercurial > mplayer.hg
annotate libao2/ao_dsound.c @ 13854:b6b3d96a5c16
Sync
1.800: have each XviD's option flag have its (no)counterpart
1.799: vo_gl should work fine with -fixed-vo
+ some French fixes
author | gpoirier |
---|---|
date | Tue, 02 Nov 2004 17:26:24 +0000 |
parents | b7322244e53c |
children | a92101a7eb49 |
rev | line source |
---|---|
13460
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
1 /****************************************************************************** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
2 * ao_dsound.c: Windows DirectSound interface for MPlayer |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
3 * 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
|
4 * |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
6 * 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
|
7 * 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
|
8 * (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
|
9 * |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
11 * 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
|
12 * 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
|
13 * 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
|
14 * |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
18 * |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
19 *****************************************************************************/ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
20 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
21 \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
|
22 */ |
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 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
25 #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
|
26 #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
|
27 #include <windows.h> |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
28 #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
|
29 #include <dsound.h> |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
30 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
31 #include "afmt.h" |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
32 #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
|
33 #include "audio_out_internal.h" |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
34 #include "../mp_msg.h" |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
35 #include "../libvo/fastmemcpy.h" |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
36 #include "osdep/timer.h" |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
37 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
38 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
39 static ao_info_t info = |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
40 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
41 "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
|
42 "dsound", |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
43 "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
|
44 "" |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
45 }; |
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 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
|
48 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
49 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
50 \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
|
51 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
52 #if 1 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
53 #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
|
54 #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
|
55 #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
|
56 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
57 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
|
58 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
59 #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
|
60 #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
|
61 #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
|
62 #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
|
63 #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
|
64 #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
|
65 #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
|
66 #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
|
67 #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
|
68 #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
|
69 #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
|
70 #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
|
71 #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
|
72 #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
|
73 #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
|
74 #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
|
75 #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
|
76 #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
|
77 #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
|
78 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
79 #define DSSPEAKER_HEADPHONE 0x00000001 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
80 #define DSSPEAKER_MONO 0x00000002 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
81 #define DSSPEAKER_QUAD 0x00000003 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
82 #define DSSPEAKER_STEREO 0x00000004 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
83 #define DSSPEAKER_SURROUND 0x00000005 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
84 #define DSSPEAKER_5POINT1 0x00000006 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
85 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
86 #ifndef _WAVEFORMATEXTENSIBLE_ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
87 typedef struct { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
88 WAVEFORMATEX Format; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
89 union { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 } Samples; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
94 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
|
95 /* 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
|
96 GUID SubFormat; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
97 } WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
98 #endif |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
99 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
100 #endif |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
101 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 }; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
108 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
109 static HINSTANCE hdsound_dll = NULL; ///handle to the dll |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
110 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
|
111 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
|
112 static LPDIRECTSOUNDBUFFER hdsbuf = NULL; ///secondary direct sound buffer (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
|
113 static int buffer_size = 0; ///size in bytes of 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
|
114 static int write_offset = 0; ///offset of the write cursor in 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
|
115 static int min_free_space = 4096; ///if the free space is below this value get_space() will return 0 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
116 |
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 \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
|
121 \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
|
122 \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
|
123 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
124 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
|
125 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
126 switch (err) { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 } |
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 \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
|
152 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
153 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
|
154 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
155 // 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
|
156 if (hds) { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
157 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
|
158 hds = NULL; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
159 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
160 // 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
|
161 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
|
162 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
|
163 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
|
164 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
165 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
|
166 } |
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 \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
|
170 \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
|
171 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
172 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
|
173 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
174 DSCAPS dscaps; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
175 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
176 // initialize directsound |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
177 HRESULT (WINAPI *OurDirectSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 return 0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
182 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
183 OurDirectSoundCreate = (void*)GetProcAddress(hdsound_dll, "DirectSoundCreate"); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
184 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
185 if (OurDirectSoundCreate == NULL) { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
186 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
|
187 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
|
188 return 0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
189 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
190 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
191 // Create the direct sound object |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
192 if FAILED(OurDirectSoundCreate(NULL, &hds, NULL )) { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
193 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
|
194 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
|
195 return 0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
196 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
197 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
198 /* 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
|
199 * 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
|
200 * 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
|
201 * 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
|
202 * !!! (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
|
203 * 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
|
204 * 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
|
205 * 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
|
206 * 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
|
207 * working */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 return 0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
213 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
214 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
|
215 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 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
|
220 } else { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
221 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
|
222 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
223 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
224 return 1; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
225 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
226 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
227 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
228 \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
|
229 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
230 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
|
231 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
232 if (hdsbuf) { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
233 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
|
234 hdsbuf = NULL; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
235 } |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
236 if (hdspribuf) { |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
237 IDirectSoundBuffer_Release(hdspribuf); |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
238 hdspribuf = NULL; |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
239 } |
13460
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
240 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
241 |
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 \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
|
244 \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
|
245 \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
|
246 \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
|
247 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
248 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
|
249 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
250 HRESULT res; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
251 LPVOID lpvPtr1; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
252 DWORD dwBytes1; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
253 LPVOID lpvPtr2; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
254 DWORD dwBytes2; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
255 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
256 // Lock the buffer |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
257 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
|
258 // If the buffer was lost, restore and retry lock. |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
259 if (DSERR_BUFFERLOST == res) |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
260 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
261 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
|
262 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
|
263 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
264 |
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 if (SUCCEEDED(res)) |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
267 { |
13674
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
268 if( (ao_data.channels == 6) && (ao_data.format!=AFMT_AC3) ) { |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
269 // reorder channels while writing to pointers. |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
270 // 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
|
271 // aligned to multiples of channels*bytespersample |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
272 // there's probably some room for speed improvements here |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
273 const int chantable[6] = {0, 1, 4, 5, 2, 3}; // reorder "matrix" |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
274 int i, j; |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
275 int numsamp,sampsize; |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
276 |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
277 sampsize = audio_out_format_bits(ao_data.format)>>3; // bytes per sample |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
278 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
|
279 |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
280 for( i = 0; i < numsamp; i++ ) for( j = 0; j < ao_data.channels; j++ ) { |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
281 memcpy(lpvPtr1+(i*ao_data.channels*sampsize)+(chantable[j]*sampsize),data+(i*ao_data.channels*sampsize)+(j*sampsize),sampsize); |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
282 } |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
283 |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
284 if (NULL != lpvPtr2 ) |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
285 { |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
286 numsamp = dwBytes2 / (ao_data.channels * sampsize); |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
287 for( i = 0; i < numsamp; i++ ) for( j = 0; j < ao_data.channels; j++ ) { |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
288 memcpy(lpvPtr2+(i*ao_data.channels*sampsize)+(chantable[j]*sampsize),data+dwBytes1+(i*ao_data.channels*sampsize)+(j*sampsize),sampsize); |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
289 } |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
290 } |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
291 |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
292 write_offset+=dwBytes1+dwBytes2; |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
293 if(write_offset>=buffer_size)write_offset=dwBytes2; |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
294 } else { |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
295 // Write to pointers without reordering. |
13460
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
296 memcpy(lpvPtr1,data,dwBytes1); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
297 if (NULL != lpvPtr2 )memcpy(lpvPtr2,data+dwBytes1,dwBytes2); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
298 write_offset+=dwBytes1+dwBytes2; |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
299 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
|
300 } |
13460
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 // Release the data back to DirectSound. |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
303 res = IDirectSoundBuffer_Unlock(hdsbuf,lpvPtr1,dwBytes1,lpvPtr2,dwBytes2); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
304 if (SUCCEEDED(res)) |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
305 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
306 // Success. |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
307 DWORD status; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
308 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
|
309 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
|
310 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
|
311 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
312 return dwBytes1+dwBytes2; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
313 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
314 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
315 // Lock, Unlock, or Restore failed. |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
316 return 0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
317 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
318 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
319 /***************************************************************************************/ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
320 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
321 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
322 \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
|
323 \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
|
324 \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
|
325 \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
|
326 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
327 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
|
328 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
329 DWORD volume; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
330 switch (cmd) { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
331 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
|
332 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
|
333 IDirectSoundBuffer_GetVolume(hdsbuf, &volume); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
334 vol->left = vol->right = (float)(volume+10000) / 100.0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
335 //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
|
336 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
|
337 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
338 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
|
339 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
|
340 volume = (vol->right * 100.0)-10000; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
341 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
|
342 //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
|
343 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
|
344 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
345 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
346 return -1; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
347 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
348 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
349 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
350 \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
|
351 \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
|
352 \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
|
353 \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
|
354 \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
|
355 \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
|
356 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
357 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
|
358 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
359 int res; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
360 if (!InitDirectSound()) return 0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
361 |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
362 // ok, now create the buffers |
13460
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
363 WAVEFORMATEXTENSIBLE wformat; |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
364 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
|
365 DSBUFFERDESC dsbdesc; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
366 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
367 //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
|
368 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
|
369 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
|
370 ao_data.format = format; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
371 ao_data.bps = channels * rate * (audio_out_format_bits(format)>>3); |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
372 if(ao_data.buffersize==-1) ao_data.buffersize = ao_data.bps; // space for 1 sec |
13460
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
373 mp_msg(MSGT_AO, MSGL_V,"ao_dsound: Samplerate:%iHz Channels:%i Format:%s\n", rate, channels, audio_out_format_name(format)); |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
374 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
|
375 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
376 //fill waveformatex |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
377 ZeroMemory(&wformat, sizeof(WAVEFORMATEXTENSIBLE)); |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
378 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
|
379 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
|
380 wformat.Format.nSamplesPerSec = rate; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
381 if (format == AFMT_AC3) { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 } else { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
386 wformat.Format.wFormatTag = (channels > 2) ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
387 wformat.Format.wBitsPerSample = audio_out_format_bits(format); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
388 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
|
389 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
390 |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
391 // fill in primary sound buffer descriptor |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
392 memset(&dsbpridesc, 0, sizeof(DSBUFFERDESC)); |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
393 dsbpridesc.dwSize = sizeof(DSBUFFERDESC); |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
394 dsbpridesc.dwFlags = DSBCAPS_PRIMARYBUFFER; |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
395 dsbpridesc.dwBufferBytes = 0; |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
396 dsbpridesc.lpwfxFormat = NULL; |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
397 |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
398 |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
399 // 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
|
400 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
|
401 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
|
402 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
|
403 | 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
|
404 | 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
|
405 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
406 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
|
407 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
|
408 wformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
409 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
|
410 // 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
|
411 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
|
412 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
413 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
|
414 |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
415 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
|
416 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
|
417 buffer_size = dsbdesc.dwBufferBytes; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
418 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
|
419 |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
420 // create primary buffer and set its format |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
421 |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
422 res = IDirectSound_CreateSoundBuffer( hds, &dsbpridesc, &hdspribuf, NULL ); |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
423 if ( res != DS_OK ) { |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
424 UninitDirectSound(); |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
425 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
|
426 return 0; |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
427 } |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
428 res = IDirectSoundBuffer_SetFormat( hdspribuf, (WAVEFORMATEX *)&wformat ); |
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
429 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
|
430 |
13674
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
431 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
|
432 |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
433 // 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
|
434 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
435 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
|
436 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
|
437 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
|
438 // 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
|
439 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
|
440 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
|
441 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
442 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
|
443 UninitDirectSound(); |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
444 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
|
445 return 0; |
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 } |
13640
a7d080bc610f
ao dsound improvements patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13460
diff
changeset
|
448 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
|
449 return 1; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
450 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
451 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
452 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
453 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
454 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
455 \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
|
456 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
457 static void reset() |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
458 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
459 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
|
460 // 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
|
461 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
|
462 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
|
463 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
464 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
465 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
466 \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
|
467 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
468 static void audio_pause() |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
469 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
470 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
|
471 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
472 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
473 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
474 \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
|
475 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
476 static void audio_resume() |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
477 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
478 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
|
479 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
480 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
481 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
482 \brief close audio device |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
483 \param immed stop playback immediately, currently not supported |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
484 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
485 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
|
486 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
487 reset(); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
488 DestroyBuffer(); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
489 UninitDirectSound(); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
490 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
491 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
492 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
493 \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
|
494 \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
|
495 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
496 static int get_space() |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
497 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
498 int space; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
499 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
|
500 IDirectSoundBuffer_GetCurrentPosition(hdsbuf,&play_offset,NULL); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
501 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
|
502 // | | <-- const --> | | | |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
503 // 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
|
504 // 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
|
505 // 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
|
506 // 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
|
507 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
|
508 if(space < min_free_space)return 0; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
509 return space; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
510 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
511 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
512 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
513 \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
|
514 \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
|
515 \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
|
516 \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
|
517 \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
|
518 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
519 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
|
520 { |
13674
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
521 DWORD play_offset; |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
522 int space; |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
523 |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
524 // 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
|
525 IDirectSoundBuffer_GetCurrentPosition(hdsbuf,&play_offset,NULL); |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
526 space=buffer_size-(write_offset-play_offset); |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
527 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
|
528 if(space < len) len = space; |
b7322244e53c
channel reorder patch by Florian Dietrich <flodt8 at yahoo.de>
faust3
parents:
13640
diff
changeset
|
529 |
13460
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
530 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
|
531 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
|
532 } |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
533 |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
534 /** |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
535 \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
|
536 \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
|
537 */ |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
538 static float get_delay() |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
539 { |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
540 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
|
541 int space; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
542 IDirectSoundBuffer_GetCurrentPosition(hdsbuf,&play_offset,NULL); |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
543 space=play_offset-write_offset; |
70d8f1975fc8
directsound audio output plugin, patch by Gabor Szecsi <deje at miki.hu> some minor modifications by me
faust3
parents:
diff
changeset
|
544 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
|
545 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
|
546 } |