Mercurial > mplayer.hg
annotate libao2/ao_pcm.c @ 9233:ba7041fbcfda
ffmpeg's DV audio decoder added
author | arpi |
---|---|
date | Mon, 03 Feb 2003 00:20:46 +0000 |
parents | b639f4560740 |
children | d824f1a3c341 |
rev | line source |
---|---|
6237 | 1 #include "config.h" |
2 | |
1107 | 3 #include <stdio.h> |
4 #include <stdlib.h> | |
6237 | 5 #include <string.h> |
1107 | 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" |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
8 #include "afmt.h" |
1107 | 9 #include "audio_out.h" |
10 #include "audio_out_internal.h" | |
11 | |
12 static ao_info_t info = | |
13 { | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
14 "RAW PCM/WAVE file writer audio output", |
1107 | 15 "pcm", |
16 "Atmosfear", | |
17 "" | |
18 }; | |
19 | |
20 LIBAO_EXTERN(pcm) | |
21 | |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
22 extern int vo_pts; |
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
23 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
24 char *ao_outputfilename = NULL; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
25 int ao_pcm_waveheader = 1; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
26 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
27 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
28 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
29 #define WAV_ID_FMT 0x20746d66 /* "fmt " */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
30 #define WAV_ID_DATA 0x61746164 /* "data" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
31 #define WAV_ID_PCM 0x0001 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
32 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
33 struct WaveHeader |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
34 { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
35 unsigned long riff; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
36 unsigned long file_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
37 unsigned long wave; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
38 unsigned long fmt; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
39 unsigned long fmt_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
40 short fmt_tag; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
41 short channels; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
42 unsigned long sample_rate; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
43 unsigned long bytes_per_second; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
44 short block_align; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
45 short bits; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
46 unsigned long data; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
47 unsigned long data_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
48 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
49 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
50 /* init with default values */ |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
51 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
|
52 le2me_32(WAV_ID_RIFF), |
9026 | 53 /* 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 le2me_32(WAV_ID_DATA), |
9223
b639f4560740
temporary 'inifinte' length disabled (commit r1.13 reversed) due to user
arpi
parents:
9156
diff
changeset
|
65 0, //le2me_32(0x7ffff000) |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
66 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
67 |
1107 | 68 static FILE *fp = NULL; |
69 | |
70 // to set/get/query special features/parameters | |
71 static int control(int cmd,int arg){ | |
72 return -1; | |
73 } | |
74 | |
75 // open & setup audio device | |
76 // return: 1=success 0=fail | |
77 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
|
78 int bits; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
79 if(!ao_outputfilename) { |
9156
a75cab40c985
double free(), found by Olivier Galibert <galibert@pobox.com>
arpi
parents:
9026
diff
changeset
|
80 ao_outputfilename = strdup(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm"); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
81 } |
7658 | 82 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
83 /* 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
|
84 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
|
85 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
|
86 |
7658 | 87 bits=8; |
88 switch(format){ | |
89 case AFMT_S8: | |
90 format=AFMT_U8; | |
91 case AFMT_U8: | |
92 break; | |
93 default: | |
94 format=AFMT_S16_LE; | |
95 bits=16; | |
96 break; | |
97 } | |
98 | |
99 ao_data.outburst = 65536; | |
100 ao_data.buffersize= 2*65536; | |
101 ao_data.channels=channels; | |
102 ao_data.samplerate=rate; | |
103 ao_data.format=format; | |
104 ao_data.bps=channels*rate*(bits/8); | |
105 | |
106 wavhdr.channels = le2me_16(ao_data.channels); | |
107 wavhdr.sample_rate = le2me_32(ao_data.samplerate); | |
108 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
|
109 wavhdr.bits = le2me_16(bits); |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
110 |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
111 printf("PCM: File: %s (%s)\n" |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
112 "PCM: Samplerate: %iHz Channels: %s Format %s\n", |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
113 ao_outputfilename, (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
114 (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); |
6941
a16a68266408
-vc null is better than -hardframedrop -- hint by gabor <gabor@realtime.sk>
arpi
parents:
6762
diff
changeset
|
115 printf("PCM: Info: fastest dumping is achieved with -vc null -vo null\n" |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
116 "PCM: Info: to write WAVE files use -waveheader (default); " |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
117 "for RAW PCM -nowaveheader.\n"); |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
118 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
119 fp = fopen(ao_outputfilename, "wb"); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
120 if(fp) { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
121 if(ao_pcm_waveheader) /* Reserve space for wave header */ |
6501 | 122 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
123 return 1; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
124 } |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
125 printf("PCM: Failed to open %s for writing!\n", ao_outputfilename); |
1107 | 126 return 0; |
127 } | |
128 | |
129 // close audio device | |
130 static void uninit(){ | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
131 |
6501 | 132 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
|
133 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
|
134 wavhdr.file_length = le2me_32(wavhdr.file_length); |
6762 | 135 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
|
136 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
137 } |
1107 | 138 fclose(fp); |
139 } | |
140 | |
141 // stop playing and empty buffers (for seeking/pause) | |
142 static void reset(){ | |
143 | |
144 } | |
145 | |
146 // stop playing, keep buffers (for pause) | |
147 static void audio_pause() | |
148 { | |
149 // for now, just call reset(); | |
150 reset(); | |
151 } | |
152 | |
153 // resume playing, after audio_pause() | |
154 static void audio_resume() | |
155 { | |
156 } | |
157 | |
158 // return: how many bytes can be played without blocking | |
159 static int get_space(){ | |
160 | |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
161 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
|
162 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
|
163 return ao_data.outburst; |
1107 | 164 } |
165 | |
166 // plays 'len' bytes of 'data' | |
167 // it should round it down to outburst*n | |
168 // return: number of bytes played | |
169 static int play(void* data,int len,int flags){ | |
170 | |
7658 | 171 // let libaf to do the conversion... |
172 #if 0 | |
173 //#ifdef WORDS_BIGENDIAN | |
174 if (ao_data.format == AFMT_S16_LE) { | |
175 unsigned short *buffer = (unsigned short *) data; | |
176 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
|
177 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
|
178 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
|
179 } |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
180 } |
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
181 #endif |
7658 | 182 |
1107 | 183 //printf("PCM: Writing chunk!\n"); |
184 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
|
185 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
186 if(ao_pcm_waveheader) |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
187 wavhdr.data_length += len; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
188 |
1107 | 189 return len; |
190 } | |
191 | |
3095 | 192 // return: delay in seconds between first and last sample in buffer |
193 static float get_delay(){ | |
1107 | 194 |
3095 | 195 return 0.0; |
1107 | 196 } |
197 | |
198 | |
199 | |
200 | |
201 | |
202 |