Mercurial > mplayer.hg
annotate libao2/ao_pcm.c @ 2374:eb6f70125851
largefileization
author | arpi |
---|---|
date | Mon, 22 Oct 2001 17:08:24 +0000 |
parents | d92e19f1ae71 |
children | 981a9e5118ce |
rev | line source |
---|---|
1107 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "audio_out.h" | |
5 #include "audio_out_internal.h" | |
6 | |
7 static ao_info_t info = | |
8 { | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
9 "RAW PCM/WAVE file writer audio output", |
1107 | 10 "pcm", |
11 "Atmosfear", | |
12 "" | |
13 }; | |
14 | |
15 LIBAO_EXTERN(pcm) | |
16 | |
17 // there are some globals: | |
18 // ao_samplerate | |
19 // ao_channels | |
20 // ao_format | |
21 // ao_bps | |
22 // ao_outburst | |
23 // ao_buffersize | |
24 | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
25 char *ao_outputfilename = NULL; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
26 int ao_pcm_waveheader = 1; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
27 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
28 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
29 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
30 #define WAV_ID_FMT 0x20746d66 /* "fmt " */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
31 #define WAV_ID_DATA 0x61746164 /* "data" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
32 #define WAV_ID_PCM 0x0001 |
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 struct WaveHeader |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
35 { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
36 unsigned long riff; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
37 unsigned long file_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
38 unsigned long wave; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
39 unsigned long fmt; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
40 unsigned long fmt_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
41 short fmt_tag; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
42 short channels; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
43 unsigned long sample_rate; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
44 unsigned long bytes_per_second; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
45 short block_align; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
46 short bits; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
47 unsigned long data; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
48 unsigned long data_length; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
49 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
50 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
51 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
52 static struct WaveHeader wavhdr = { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
53 WAV_ID_RIFF, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
54 0x00000000, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
55 WAV_ID_WAVE, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
56 WAV_ID_FMT, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
57 16, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
58 WAV_ID_PCM, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
59 2, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
60 44100, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
61 192000, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
62 4, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
63 16, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
64 WAV_ID_DATA, |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
65 0x00000000 |
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){ | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
78 if(!ao_outputfilename) { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
79 ao_outputfilename = (char *) malloc(sizeof(char) * 14); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
80 strcpy(ao_outputfilename,(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm")); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
81 } |
1107 | 82 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
83 wavhdr.channels = channels; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
84 wavhdr.sample_rate = rate; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
85 wavhdr.bytes_per_second = rate * (format / 8) * channels; |
1113 | 86 wavhdr.bits = format; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
87 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
88 printf("PCM: File: %s (%s) Samplerate: %iHz Channels: %s Format %s\n", ao_outputfilename, (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format)); |
1107 | 89 printf("PCM: Info - fastest dumping is achieved with -vo null -hardframedrop.\n"); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
90 printf("PCM: Info - to write WAVE files use -waveheader (default), for RAW PCM -nowaveheader.\n"); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
91 fp = fopen(ao_outputfilename, "wb"); |
1107 | 92 |
93 ao_outburst = 4096; | |
94 | |
95 | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
96 if(fp) { |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
97 if(ao_pcm_waveheader) /* Reserve space for wave header */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
98 fseek(fp, sizeof(wavhdr), SEEK_SET); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
99 return 1; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
100 } |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
101 printf("PCM: Failed to open %s for writing!\n", ao_outputfilename); |
1107 | 102 return 0; |
103 } | |
104 | |
105 // close audio device | |
106 static void uninit(){ | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
107 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
108 if(ao_pcm_waveheader){ /* Write wave header */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
109 wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
110 fseek(fp, 0, SEEK_SET); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
111 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
112 } |
1107 | 113 fclose(fp); |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
114 free(ao_outputfilename); |
1107 | 115 } |
116 | |
117 // stop playing and empty buffers (for seeking/pause) | |
118 static void reset(){ | |
119 | |
120 } | |
121 | |
122 // stop playing, keep buffers (for pause) | |
123 static void audio_pause() | |
124 { | |
125 // for now, just call reset(); | |
126 reset(); | |
127 } | |
128 | |
129 // resume playing, after audio_pause() | |
130 static void audio_resume() | |
131 { | |
132 } | |
133 | |
134 // return: how many bytes can be played without blocking | |
135 static int get_space(){ | |
136 | |
137 return ao_outburst; | |
138 } | |
139 | |
140 // plays 'len' bytes of 'data' | |
141 // it should round it down to outburst*n | |
142 // return: number of bytes played | |
143 static int play(void* data,int len,int flags){ | |
144 | |
145 //printf("PCM: Writing chunk!\n"); | |
146 fwrite(data,len,1,fp); | |
147 | |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
148 if(ao_pcm_waveheader) |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
149 wavhdr.data_length += len; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
150 |
1107 | 151 return len; |
152 } | |
153 | |
154 // return: how many unplayed bytes are in the buffer | |
155 static int get_delay(){ | |
156 | |
157 return 0; | |
158 } | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 |