annotate libao2/ao_pcm.c @ 15157:c9a7876a9046

Nits suggested by The Wanderer
author gpoirier
date Thu, 14 Apr 2005 10:53:04 +0000
parents de08cc60fd7e
children 178b8b4a62c6
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
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
7 #include "bswap.h"
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
8 #include "subopt-helper.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
9 #include "libaf/af_format.h"
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
10 #include "audio_out.h"
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
11 #include "audio_out_internal.h"
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
12 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 13383
diff changeset
13 #include "help_mp.h"
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
14
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
15
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
16 static ao_info_t info =
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
17 {
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
18 "RAW PCM/WAVE file writer audio output",
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
19 "pcm",
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
20 "Atmosfear",
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
21 ""
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
22 };
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
23
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
24 LIBAO_EXTERN(pcm)
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
25
4914
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
26 extern int vo_pts;
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
27
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
28 static char *ao_outputfilename = NULL;
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
29 static int ao_pcm_waveheader = 1;
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
30
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
31 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
32 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
33 #define WAV_ID_FMT 0x20746d66 /* "fmt " */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
34 #define WAV_ID_DATA 0x61746164 /* "data" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
35 #define WAV_ID_PCM 0x0001
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
36
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
37 struct WaveHeader
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
38 {
11270
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
39 uint32_t riff;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
40 uint32_t file_length;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
41 uint32_t wave;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
42 uint32_t fmt;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
43 uint32_t fmt_length;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
44 uint16_t fmt_tag;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
45 uint16_t channels;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
46 uint32_t sample_rate;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
47 uint32_t bytes_per_second;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
48 uint16_t block_align;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
49 uint16_t bits;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
50 uint32_t data;
8ba8ec1293e7 64bit types fix by a unkown mandrake 64bit expert
attila
parents: 10077
diff changeset
51 uint32_t data_length;
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
52 };
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
53
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
54 /* init with default values */
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
55 static struct WaveHeader wavhdr = {
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
56 le2me_32(WAV_ID_RIFF),
9026
ccbfff7debf8 When the file is not finished to be written,
arpi
parents: 8060
diff changeset
57 /* same conventions than in sox/wav.c/wavwritehdr() */
9223
b639f4560740 temporary 'inifinte' length disabled (commit r1.13 reversed) due to user
arpi
parents: 9156
diff changeset
58 0, //le2me_32(0x7ffff024),
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
59 le2me_32(WAV_ID_WAVE),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
60 le2me_32(WAV_ID_FMT),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
61 le2me_32(16),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
62 le2me_16(WAV_ID_PCM),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
63 le2me_16(2),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
64 le2me_32(44100),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
65 le2me_32(192000),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
66 le2me_16(4),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
67 le2me_16(16),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
68 le2me_32(WAV_ID_DATA),
9223
b639f4560740 temporary 'inifinte' length disabled (commit r1.13 reversed) due to user
arpi
parents: 9156
diff changeset
69 0, //le2me_32(0x7ffff000)
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
70 };
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
71
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
72 static FILE *fp = NULL;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
73
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
74 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 9277
diff changeset
75 static int control(int cmd,void *arg){
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
76 return -1;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
77 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
78
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
79 // open & setup audio device
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
80 // return: 1=success 0=fail
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
81 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
82 int bits;
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
83 opt_t subopts[] = {
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
84 {"waveheader", OPT_ARG_BOOL, &ao_pcm_waveheader, NULL},
14539
de08cc60fd7e use MSTRZ suboption type
reimar
parents: 14327
diff changeset
85 {"file", OPT_ARG_MSTRZ, &ao_outputfilename, NULL},
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
86 {NULL}
14300
8f1ab3da482c missing ;
faust3
parents: 14298
diff changeset
87 };
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
88 // set defaults
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
89 ao_pcm_waveheader = 1;
14539
de08cc60fd7e use MSTRZ suboption type
reimar
parents: 14327
diff changeset
90 ao_outputfilename =
de08cc60fd7e use MSTRZ suboption type
reimar
parents: 14327
diff changeset
91 strdup((ao_pcm_waveheader)?"audiodump.wav":"audiodump.pcm");
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
92 if (subopt_parse(ao_subdevice, subopts) != 0) {
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
93 return 0;
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
94 }
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
95
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
96 /* bits is only equal to format if (format == 8) or (format == 16);
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
97 this means that the following "if" is a kludge and should
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
98 really be a switch to be correct in all cases */
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
99
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
100 bits=8;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
101 switch(format){
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
102 case AF_FORMAT_S8:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
103 format=AF_FORMAT_U8;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
104 case AF_FORMAT_U8:
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
105 break;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
106 default:
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
107 format=AF_FORMAT_S16_LE;
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
108 bits=16;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
109 break;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
110 }
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
111
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
112 ao_data.outburst = 65536;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
113 ao_data.buffersize= 2*65536;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
114 ao_data.channels=channels;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
115 ao_data.samplerate=rate;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
116 ao_data.format=format;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
117 ao_data.bps=channels*rate*(bits/8);
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
118
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
119 wavhdr.channels = le2me_16(ao_data.channels);
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
120 wavhdr.sample_rate = le2me_32(ao_data.samplerate);
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
121 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
122 wavhdr.bits = le2me_16(bits);
9277
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
123
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
124 wavhdr.data_length=le2me_32(0x7ffff000);
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
125 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
126
14264
cb5fbade8a5c af_fmt2str_short
alex
parents: 14245
diff changeset
127 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_FileInfo, ao_outputfilename,
cb5fbade8a5c af_fmt2str_short
alex
parents: 14245
diff changeset
128 (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate,
cb5fbade8a5c af_fmt2str_short
alex
parents: 14245
diff changeset
129 (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
130 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
131
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
132 fp = fopen(ao_outputfilename, "wb");
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
133 if(fp) {
9277
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
134 if(ao_pcm_waveheader){ /* Reserve space for wave header */
6501
827f08ddf044 Allow writing to pipe.
albeu
parents: 6237
diff changeset
135 fwrite(&wavhdr,sizeof(wavhdr),1,fp);
9277
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
136 wavhdr.file_length=wavhdr.data_length=0;
d824f1a3c341 The "initialize wav header with infinite lenght" broke the
arpi
parents: 9223
diff changeset
137 }
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
138 return 1;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
139 }
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
140 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_PCM_CantOpenOutputFile,
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
141 ao_outputfilename);
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
142 return 0;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
143 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
144
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
145 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 11270
diff changeset
146 static void uninit(int immed){
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
147
6501
827f08ddf044 Allow writing to pipe.
albeu
parents: 6237
diff changeset
148 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
149 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
150 wavhdr.file_length = le2me_32(wavhdr.file_length);
6762
8411ea0d9078 endianess fix by Colin Leroy <colin@colino.net>
arpi
parents: 6501
diff changeset
151 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
152 fwrite(&wavhdr,sizeof(wavhdr),1,fp);
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
153 }
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
154 fclose(fp);
14298
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
155 if (ao_outputfilename)
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
156 free(ao_outputfilename);
3c818342a02b Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents: 14264
diff changeset
157 ao_outputfilename = NULL;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
158 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
159
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
160 // stop playing and empty buffers (for seeking/pause)
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
161 static void reset(){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
162
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
163 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
164
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
165 // stop playing, keep buffers (for pause)
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
166 static void audio_pause()
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
167 {
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
168 // for now, just call reset();
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
169 reset();
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
170 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
171
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
172 // resume playing, after audio_pause()
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
173 static void audio_resume()
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
174 {
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
175 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
176
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
177 // return: how many bytes can be played without blocking
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
178 static int get_space(){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
179
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
180 if(vo_pts)
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
181 return ao_data.pts < vo_pts ? ao_data.outburst : 0;
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
182 return ao_data.outburst;
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 // plays 'len' bytes of 'data'
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
186 // it should round it down to outburst*n
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
187 // return: number of bytes played
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
188 static int play(void* data,int len,int flags){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
189
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
190 // let libaf to do the conversion...
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
191 #if 0
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
192 //#ifdef WORDS_BIGENDIAN
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
193 if (ao_data.format == AFMT_S16_LE) {
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
194 unsigned short *buffer = (unsigned short *) data;
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
195 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
196 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
197 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
198 }
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
199 }
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
200 #endif
7658
65037d309de3 updated for libaf rules
arpi
parents: 6941
diff changeset
201
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
202 //printf("PCM: Writing chunk!\n");
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
203 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
204
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
205 if(ao_pcm_waveheader)
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
206 wavhdr.data_length += len;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
207
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
208 return len;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
209 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
210
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
211 // return: delay in seconds between first and last sample in buffer
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
212 static float get_delay(){
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
213
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
214 return 0.0;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
215 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
216
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
217
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
218
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
219
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
220
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
221