Mercurial > mplayer.hg
annotate libao2/ao_pcm.c @ 32061:dcdcbe7f6713
Move video_time_usage / vout_time_usage extern var declarations to mpcommon.h.
author | diego |
---|---|
date | Sat, 11 Sep 2010 11:33:07 +0000 |
parents | a3890036b137 |
children | dd75bae40633 |
rev | line source |
---|---|
28343 | 1 /* |
2 * PCM audio output driver | |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
20 | |
6237 | 21 #include "config.h" |
22 | |
1107 | 23 #include <stdio.h> |
24 #include <stdlib.h> | |
6237 | 25 #include <string.h> |
1107 | 26 |
21372 | 27 #include "libavutil/common.h" |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21372
diff
changeset
|
28 #include "mpbswap.h" |
14298
3c818342a02b
Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents:
14264
diff
changeset
|
29 #include "subopt-helper.h" |
14245 | 30 #include "libaf/af_format.h" |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
25097
diff
changeset
|
31 #include "libaf/reorder_ch.h" |
31997
a3890036b137
Add proper include instead of declaring the vo_pts variable extern.
diego
parents:
31620
diff
changeset
|
32 #include "libvo/video_out.h" |
1107 | 33 #include "audio_out.h" |
34 #include "audio_out_internal.h" | |
14123 | 35 #include "mp_msg.h" |
36 #include "help_mp.h" | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
37 |
29269
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
38 #ifdef __MINGW32__ |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
39 // for GetFileType to detect pipes |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
40 #include <windows.h> |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
41 #endif |
1107 | 42 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
43 static const ao_info_t info = |
1107 | 44 { |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
45 "RAW PCM/WAVE file writer audio output", |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
46 "pcm", |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
47 "Atmosfear", |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
48 "" |
1107 | 49 }; |
50 | |
51 LIBAO_EXTERN(pcm) | |
52 | |
14298
3c818342a02b
Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents:
14264
diff
changeset
|
53 static char *ao_outputfilename = NULL; |
3c818342a02b
Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents:
14264
diff
changeset
|
54 static int ao_pcm_waveheader = 1; |
18092
96fdfbad5b1a
-ao pcm:fast suboption for faster-than-realtime dumping
reimar
parents:
17566
diff
changeset
|
55 static int fast = 0; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
56 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
57 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
58 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
59 #define WAV_ID_FMT 0x20746d66 /* "fmt " */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
60 #define WAV_ID_DATA 0x61746164 /* "data" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
61 #define WAV_ID_PCM 0x0001 |
26604
9946e4a6e457
Support 32 bit float and integer formats in ao_pcm.c
reimar
parents:
25315
diff
changeset
|
62 #define WAV_ID_FLOAT_PCM 0x0003 |
30666
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
63 #define WAV_ID_FORMAT_EXTENSIBLE 0xfffe |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
64 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
65 /* init with default values */ |
29002
b7367b035fdd
Add forgotten "static" to new data_length variable in ao_pcm
reimar
parents:
29001
diff
changeset
|
66 static uint64_t data_length; |
30666
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
67 static FILE *fp = NULL; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
68 |
30666
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
69 |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
70 static void fput16le(uint16_t val, FILE *fp) { |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
71 uint8_t bytes[2] = {val, val >> 8}; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
72 fwrite(bytes, 1, 2, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
73 } |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
74 |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
75 static void fput32le(uint32_t val, FILE *fp) { |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
76 uint8_t bytes[4] = {val, val >> 8, val >> 16, val >> 24}; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
77 fwrite(bytes, 1, 4, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
78 } |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
79 |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
80 static void write_wave_header(FILE *fp, uint64_t data_length) { |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
81 int use_waveex = (ao_data.channels >= 5 && ao_data.channels <= 8); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
82 uint16_t fmt = (ao_data.format == AF_FORMAT_FLOAT_LE) ? WAV_ID_FLOAT_PCM : WAV_ID_PCM; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
83 uint32_t fmt_chunk_size = use_waveex ? 40 : 16; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
84 int bits = af_fmt2bits(ao_data.format); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
85 |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
86 // Master RIFF chunk |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
87 fput32le(WAV_ID_RIFF, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
88 // RIFF chunk size: 'WAVE' + 'fmt ' + 4 + fmt_chunk_size + data chunk hdr (8) + data length |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
89 fput32le(12 + fmt_chunk_size + 8 + data_length, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
90 fput32le(WAV_ID_WAVE, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
91 |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
92 // Format chunk |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
93 fput32le(WAV_ID_FMT, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
94 fput32le(fmt_chunk_size, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
95 fput16le(use_waveex ? WAV_ID_FORMAT_EXTENSIBLE : fmt, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
96 fput16le(ao_data.channels, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
97 fput32le(ao_data.samplerate, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
98 fput32le(ao_data.bps, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
99 fput16le(ao_data.channels * (bits / 8), fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
100 fput16le(bits, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
101 |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
102 if (use_waveex) { |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
103 // Extension chunk |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
104 fput16le(22, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
105 fput16le(bits, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
106 switch (ao_data.channels) { |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
107 case 5: |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
108 fput32le(0x0607, fp); // L R C Lb Rb |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
109 break; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
110 case 6: |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
111 fput32le(0x060f, fp); // L R C Lb Rb LFE |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
112 break; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
113 case 7: |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
114 fput32le(0x0727, fp); // L R C Cb Ls Rs LFE |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
115 break; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
116 case 8: |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
117 fput32le(0x063f, fp); // L R C Lb Rb Ls Rs LFE |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
118 break; |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
119 } |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
120 // 2 bytes format + 14 bytes guid |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
121 fput32le(fmt, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
122 fput32le(0x00100000, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
123 fput32le(0xAA000080, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
124 fput32le(0x719B3800, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
125 } |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
126 |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
127 // Data chunk |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
128 fput32le(WAV_ID_DATA, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
129 fput32le(data_length, fp); |
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
130 } |
1107 | 131 |
132 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9277
diff
changeset
|
133 static int control(int cmd,void *arg){ |
1107 | 134 return -1; |
135 } | |
136 | |
137 // open & setup audio device | |
138 // return: 1=success 0=fail | |
139 static int init(int rate,int channels,int format,int flags){ | |
29586
2eff450157cd
The suboption parser now takes a const options list, so mark them all const.
reimar
parents:
29401
diff
changeset
|
140 const opt_t subopts[] = { |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
141 {"waveheader", OPT_ARG_BOOL, &ao_pcm_waveheader, NULL}, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
142 {"file", OPT_ARG_MSTRZ, &ao_outputfilename, NULL}, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
143 {"fast", OPT_ARG_BOOL, &fast, NULL}, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
144 {NULL} |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
145 }; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
146 // set defaults |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
147 ao_pcm_waveheader = 1; |
18488
b23c0e341e3e
Move setting the output filename after the suboption parsing, otherwise it
diego
parents:
18092
diff
changeset
|
148 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
149 if (subopt_parse(ao_subdevice, subopts) != 0) { |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
150 return 0; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
151 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
152 if (!ao_outputfilename){ |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
153 ao_outputfilename = |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
154 strdup(ao_pcm_waveheader?"audiodump.wav":"audiodump.pcm"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
155 } |
18488
b23c0e341e3e
Move setting the output filename after the suboption parsing, otherwise it
diego
parents:
18092
diff
changeset
|
156 |
30358 | 157 if (ao_pcm_waveheader) |
158 { | |
159 // WAV files must have one of the following formats | |
160 | |
161 switch(format){ | |
162 case AF_FORMAT_U8: | |
163 case AF_FORMAT_S16_LE: | |
164 case AF_FORMAT_S24_LE: | |
165 case AF_FORMAT_S32_LE: | |
166 case AF_FORMAT_FLOAT_LE: | |
167 case AF_FORMAT_AC3_BE: | |
168 case AF_FORMAT_AC3_LE: | |
169 break; | |
170 default: | |
171 format = AF_FORMAT_S16_LE; | |
172 break; | |
173 } | |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
174 } |
7658 | 175 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
176 ao_data.outburst = 65536; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
177 ao_data.buffersize= 2*65536; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
178 ao_data.channels=channels; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
179 ao_data.samplerate=rate; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
180 ao_data.format=format; |
30666
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
181 ao_data.bps=channels*rate*(af_fmt2bits(format)/8); |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
182 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
183 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_FileInfo, ao_outputfilename, |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
184 (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
185 (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format)); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
186 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_HintInfo); |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
187 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
188 fp = fopen(ao_outputfilename, "wb"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
189 if(fp) { |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
190 if(ao_pcm_waveheader){ /* Reserve space for wave header */ |
30666
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
191 write_wave_header(fp, 0x7ffff000); |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
192 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
193 return 1; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
194 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
195 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_PCM_CantOpenOutputFile, |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
196 ao_outputfilename); |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
197 return 0; |
1107 | 198 } |
199 | |
200 // close audio device | |
12145 | 201 static void uninit(int immed){ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
202 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
203 if(ao_pcm_waveheader){ /* Rewrite wave header */ |
29269
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
204 int broken_seek = 0; |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
205 #ifdef __MINGW32__ |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
206 // Windows, in its usual idiocy "emulates" seeks on pipes so it always looks |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
207 // like they work. So we have to detect them brute-force. |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
208 broken_seek = GetFileType((HANDLE)_get_osfhandle(_fileno(fp))) != FILE_TYPE_DISK; |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
209 #endif |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
210 if (broken_seek || fseek(fp, 0, SEEK_SET) != 0) |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
211 mp_msg(MSGT_AO, MSGL_ERR, "Could not seek to start, WAV size headers not updated!\n"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
212 else { |
31132
f5478d5be47e
Change WAV header updating in ao_pcm to allow to up to almost 4GB size.
reimar
parents:
30666
diff
changeset
|
213 if (data_length > 0xfffff000) { |
f5478d5be47e
Change WAV header updating in ao_pcm to allow to up to almost 4GB size.
reimar
parents:
30666
diff
changeset
|
214 mp_msg(MSGT_AO, MSGL_ERR, "File larger than allowed for WAV files, may play truncated!\n"); |
f5478d5be47e
Change WAV header updating in ao_pcm to allow to up to almost 4GB size.
reimar
parents:
30666
diff
changeset
|
215 data_length = 0xfffff000; |
f5478d5be47e
Change WAV header updating in ao_pcm to allow to up to almost 4GB size.
reimar
parents:
30666
diff
changeset
|
216 } |
30666
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
217 write_wave_header(fp, data_length); |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
218 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
219 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
220 fclose(fp); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
221 if (ao_outputfilename) |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
222 free(ao_outputfilename); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
223 ao_outputfilename = NULL; |
1107 | 224 } |
225 | |
226 // stop playing and empty buffers (for seeking/pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
227 static void reset(void){ |
1107 | 228 |
229 } | |
230 | |
231 // stop playing, keep buffers (for pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
232 static void audio_pause(void) |
1107 | 233 { |
234 // for now, just call reset(); | |
235 reset(); | |
236 } | |
237 | |
238 // resume playing, after audio_pause() | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
239 static void audio_resume(void) |
1107 | 240 { |
241 } | |
242 | |
243 // return: how many bytes can be played without blocking | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
244 static int get_space(void){ |
1107 | 245 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
246 if(vo_pts) |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
247 return ao_data.pts < vo_pts + fast * 30000 ? ao_data.outburst : 0; |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
248 return ao_data.outburst; |
1107 | 249 } |
250 | |
251 // plays 'len' bytes of 'data' | |
252 // it should round it down to outburst*n | |
253 // return: number of bytes played | |
254 static int play(void* data,int len,int flags){ | |
255 | |
29826 | 256 if (ao_data.channels == 5 || ao_data.channels == 6 || ao_data.channels == 8) { |
30666
b20827f16dd0
Output WAVE_FORMAT_EXTENSIBLE extension in wave header when waveheader
tack
parents:
30633
diff
changeset
|
257 int frame_size = af_fmt2bits(ao_data.format) / 8; |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
258 len -= len % (frame_size * ao_data.channels); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
259 reorder_channel_nch(data, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
260 AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
261 ao_data.channels, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
262 len / frame_size, frame_size); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
263 } |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
25097
diff
changeset
|
264 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
265 //printf("PCM: Writing chunk!\n"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
266 fwrite(data,len,1,fp); |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
267 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
268 if(ao_pcm_waveheader) |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
269 data_length += len; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
270 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
271 return len; |
1107 | 272 } |
273 | |
3095 | 274 // return: delay in seconds between first and last sample in buffer |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
275 static float get_delay(void){ |
1107 | 276 |
3095 | 277 return 0.0; |
1107 | 278 } |