annotate libao2/ao_pcm.c @ 27420:917c93c652b0

Add VIDIX driver for SuperH Mobile VEU hardware block. Patch by Magnus Damm <magnus dot damm at gmail dot com>.
author ben
date Mon, 11 Aug 2008 23:10:03 +0000
parents c75d2f3cf4eb
children e45b08f2f5d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6237
2eec40929570 warning fixes (string.h is required for memset)
pl
parents: 5837
diff changeset
1 #include "config.h"
2eec40929570 warning fixes (string.h is required for memset)
pl
parents: 5837
diff changeset
2
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
3 #include <stdio.h>
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
4 #include <stdlib.h>
6237
2eec40929570 warning fixes (string.h is required for memset)
pl
parents: 5837
diff changeset
5 #include <string.h>
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
6
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 21250
diff changeset
7 #include "libavutil/common.h"
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
8 #include "mpbswap.h"
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
9 #include "subopt-helper.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
10 #include "libaf/af_format.h"
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
11 #include "libaf/reorder_ch.h"
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
12 #include "audio_out.h"
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
13 #include "audio_out_internal.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
14 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
15 #include "help_mp.h"
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
16
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
17
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
18 static ao_info_t info =
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
19 {
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
20 "RAW PCM/WAVE file writer audio output",
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
21 "pcm",
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
22 "Atmosfear",
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
23 ""
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
24 };
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
25
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
26 LIBAO_EXTERN(pcm)
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
27
4914
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
28 extern int vo_pts;
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
29
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
30 static char *ao_outputfilename = NULL;
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
31 static int ao_pcm_waveheader = 1;
18092
96fdfbad5b1a -ao pcm:fast suboption for faster-than-realtime dumping
reimar
parents: 17566
diff changeset
32 static int fast = 0;
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
33
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
34 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
35 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
36 #define WAV_ID_FMT 0x20746d66 /* "fmt " */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
37 #define WAV_ID_DATA 0x61746164 /* "data" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
38 #define WAV_ID_PCM 0x0001
26604
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
39 #define WAV_ID_FLOAT_PCM 0x0003
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
40
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
41 struct WaveHeader
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
42 {
11270
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
43 uint32_t riff;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
44 uint32_t file_length;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
45 uint32_t wave;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
46 uint32_t fmt;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
47 uint32_t fmt_length;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
48 uint16_t fmt_tag;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
49 uint16_t channels;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
50 uint32_t sample_rate;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
51 uint32_t bytes_per_second;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
52 uint16_t block_align;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
53 uint16_t bits;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
54 uint32_t data;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
55 uint32_t data_length;
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
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
58 /* init with default values */
21250
7b1ab00ef2eb le2me_32 is no longer a macro on PPC, and in general does not have to
reimar
parents: 18500
diff changeset
59 static struct WaveHeader wavhdr;
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
60
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
61 static FILE *fp = NULL;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
62
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
63 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 9277
diff changeset
64 static int control(int cmd,void *arg){
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
65 return -1;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
66 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
67
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
68 // open & setup audio device
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
69 // return: 1=success 0=fail
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
70 static int init(int rate,int channels,int format,int flags){
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
71 int bits;
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
72 opt_t subopts[] = {
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
73 {"waveheader", OPT_ARG_BOOL, &ao_pcm_waveheader, NULL},
14539
de08cc60fd7e use MSTRZ suboption type
reimar
parents: 14327
diff changeset
74 {"file", OPT_ARG_MSTRZ, &ao_outputfilename, NULL},
18092
96fdfbad5b1a -ao pcm:fast suboption for faster-than-realtime dumping
reimar
parents: 17566
diff changeset
75 {"fast", OPT_ARG_BOOL, &fast, NULL},
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
76 {NULL}
14300
8f1ab3da482c missing ;
faust3
parents: 14298
diff changeset
77 };
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
78 // set defaults
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
79 ao_pcm_waveheader = 1;
18488
b23c0e341e3e Move setting the output filename after the suboption parsing, otherwise it
diego
parents: 18092
diff changeset
80
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
81 if (subopt_parse(ao_subdevice, subopts) != 0) {
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
82 return 0;
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
83 }
18500
9533f21d3f7e Only set the default output filename when it was not passed on the command
diego
parents: 18488
diff changeset
84 if (!ao_outputfilename){
9533f21d3f7e Only set the default output filename when it was not passed on the command
diego
parents: 18488
diff changeset
85 ao_outputfilename =
9533f21d3f7e Only set the default output filename when it was not passed on the command
diego
parents: 18488
diff changeset
86 strdup(ao_pcm_waveheader?"audiodump.wav":"audiodump.pcm");
9533f21d3f7e Only set the default output filename when it was not passed on the command
diego
parents: 18488
diff changeset
87 }
18488
b23c0e341e3e Move setting the output filename after the suboption parsing, otherwise it
diego
parents: 18092
diff changeset
88
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
89 bits=8;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
90 switch(format){
26604
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
91 case AF_FORMAT_S32_BE:
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
92 format=AF_FORMAT_S32_LE;
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
93 case AF_FORMAT_S32_LE:
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
94 bits=32;
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
95 break;
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
96 case AF_FORMAT_FLOAT_BE:
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
97 format=AF_FORMAT_FLOAT_LE;
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
98 case AF_FORMAT_FLOAT_LE:
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
99 bits=32;
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
100 break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
101 case AF_FORMAT_S8:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
102 format=AF_FORMAT_U8;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
103 case AF_FORMAT_U8:
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
104 break;
25097
7a6a7f47109f Support dump AF_FORMAT_AC3 format.
ulion
parents: 21507
diff changeset
105 case AF_FORMAT_AC3:
7a6a7f47109f Support dump AF_FORMAT_AC3 format.
ulion
parents: 21507
diff changeset
106 bits=16;
7a6a7f47109f Support dump AF_FORMAT_AC3 format.
ulion
parents: 21507
diff changeset
107 break;
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
108 default:
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
109 format=AF_FORMAT_S16_LE;
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
110 bits=16;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
111 break;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
112 }
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
113
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
114 ao_data.outburst = 65536;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
115 ao_data.buffersize= 2*65536;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
116 ao_data.channels=channels;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
117 ao_data.samplerate=rate;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
118 ao_data.format=format;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
119 ao_data.bps=channels*rate*(bits/8);
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
120
21250
7b1ab00ef2eb le2me_32 is no longer a macro on PPC, and in general does not have to
reimar
parents: 18500
diff changeset
121 wavhdr.riff = le2me_32(WAV_ID_RIFF);
7b1ab00ef2eb le2me_32 is no longer a macro on PPC, and in general does not have to
reimar
parents: 18500
diff changeset
122 wavhdr.wave = le2me_32(WAV_ID_WAVE);
7b1ab00ef2eb le2me_32 is no longer a macro on PPC, and in general does not have to
reimar
parents: 18500
diff changeset
123 wavhdr.fmt = le2me_32(WAV_ID_FMT);
7b1ab00ef2eb le2me_32 is no longer a macro on PPC, and in general does not have to
reimar
parents: 18500
diff changeset
124 wavhdr.fmt_length = le2me_32(16);
26604
9946e4a6e457 Support 32 bit float and integer formats in ao_pcm.c
reimar
parents: 25315
diff changeset
125 wavhdr.fmt_tag = le2me_16(format == AF_FORMAT_FLOAT_LE ? WAV_ID_FLOAT_PCM : WAV_ID_PCM);
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
126 wavhdr.channels = le2me_16(ao_data.channels);
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
127 wavhdr.sample_rate = le2me_32(ao_data.samplerate);
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
128 wavhdr.bytes_per_second = le2me_32(ao_data.bps);
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
129 wavhdr.bits = le2me_16(bits);
16243
178b8b4a62c6 Set block_align in header, seems MatLab can not handle files without.
reimar
parents: 14539
diff changeset
130 wavhdr.block_align = le2me_16(ao_data.channels * (bits / 8));
9277
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
131
21250
7b1ab00ef2eb le2me_32 is no longer a macro on PPC, and in general does not have to
reimar
parents: 18500
diff changeset
132 wavhdr.data = le2me_32(WAV_ID_DATA);
9277
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
133 wavhdr.data_length=le2me_32(0x7ffff000);
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
134 wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8;
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
135
14264
cb5fbade8a5c af_fmt2str_short
alex
parents: 14245
diff changeset
136 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_FileInfo, ao_outputfilename,
cb5fbade8a5c af_fmt2str_short
alex
parents: 14245
diff changeset
137 (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate,
cb5fbade8a5c af_fmt2str_short
alex
parents: 14245
diff changeset
138 (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
139 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
140
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
141 fp = fopen(ao_outputfilename, "wb");
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
142 if(fp) {
9277
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
143 if(ao_pcm_waveheader){ /* Reserve space for wave header */
6501
827f08ddf044 Allow writing to pipe.
albeu
parents: 6237
diff changeset
144 fwrite(&wavhdr,sizeof(wavhdr),1,fp);
9277
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
145 wavhdr.file_length=wavhdr.data_length=0;
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
146 }
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
147 return 1;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
148 }
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
149 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_PCM_CantOpenOutputFile,
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
150 ao_outputfilename);
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
151 return 0;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
152 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
153
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
154 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 11270
diff changeset
155 static void uninit(int immed){
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
156
6501
827f08ddf044 Allow writing to pipe.
albeu
parents: 6237
diff changeset
157 if(ao_pcm_waveheader && fseek(fp, 0, SEEK_SET) == 0){ /* Write wave header */
4914
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
158 wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8;
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
159 wavhdr.file_length = le2me_32(wavhdr.file_length);
6762
8411ea0d9078 endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 6501
diff changeset
160 wavhdr.data_length = le2me_32(wavhdr.data_length);
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
161 fwrite(&wavhdr,sizeof(wavhdr),1,fp);
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
162 }
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
163 fclose(fp);
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
164 if (ao_outputfilename)
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
165 free(ao_outputfilename);
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
166 ao_outputfilename = NULL;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
167 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
168
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
169 // stop playing and empty buffers (for seeking/pause)
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 16243
diff changeset
170 static void reset(void){
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
171
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
172 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
173
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
174 // stop playing, keep buffers (for pause)
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 16243
diff changeset
175 static void audio_pause(void)
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
176 {
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
177 // for now, just call reset();
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
178 reset();
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
179 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
180
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
181 // resume playing, after audio_pause()
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 16243
diff changeset
182 static void audio_resume(void)
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
183 {
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
184 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
185
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
186 // return: how many bytes can be played without blocking
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 16243
diff changeset
187 static int get_space(void){
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
188
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
189 if(vo_pts)
18092
96fdfbad5b1a -ao pcm:fast suboption for faster-than-realtime dumping
reimar
parents: 17566
diff changeset
190 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
191 return ao_data.outburst;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
192 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
193
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
194 // plays 'len' bytes of 'data'
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
195 // it should round it down to outburst*n
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
196 // return: number of bytes played
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
197 static int play(void* data,int len,int flags){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
198
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
199 // let libaf to do the conversion...
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
200 #if 0
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
201 //#ifdef WORDS_BIGENDIAN
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
202 if (ao_data.format == AFMT_S16_LE) {
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
203 unsigned short *buffer = (unsigned short *) data;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
204 register int i;
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
205 for(i = 0; i < len/2; ++i) {
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
206 buffer[i] = le2me_16(buffer[i]);
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
207 }
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
208 }
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
209 #endif
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
210
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
211 if (ao_data.channels == 6 || ao_data.channels == 5) {
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
212 int frame_size = le2me_16(wavhdr.bits) / 8;
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
213 len -= len % (frame_size * ao_data.channels);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
214 reorder_channel_nch(data, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
215 AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
216 ao_data.channels,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
217 len / frame_size, frame_size);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
218 }
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 25097
diff changeset
219
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
220 //printf("PCM: Writing chunk!\n");
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
221 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
222
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
223 if(ao_pcm_waveheader)
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
224 wavhdr.data_length += len;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
225
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
226 return len;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
227 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
228
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
229 // 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
230 static float get_delay(void){
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
231
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
232 return 0.0;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
233 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
234
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
235
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
236
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
237
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
238
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
239