annotate libao2/ao_pcm.c @ 6026:16e33d66b813

added audio_out_format_bits to calc len alignment
author iive
date Thu, 09 May 2002 07:39:33 +0000
parents 7e082f42497a
children 2eec40929570
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
1 #include <stdio.h>
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
2 #include <stdlib.h>
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
3
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
4 #include "config.h"
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
5 #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
6 #include "afmt.h"
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
7 #include "audio_out.h"
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
8 #include "audio_out_internal.h"
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
9
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
10 static ao_info_t info =
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
11 {
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
12 "RAW PCM/WAVE file writer audio output",
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
13 "pcm",
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
14 "Atmosfear",
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
15 ""
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
16 };
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
17
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
18 LIBAO_EXTERN(pcm)
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
19
4914
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
20 extern int vo_pts;
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
21
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
22 char *ao_outputfilename = NULL;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
23 int ao_pcm_waveheader = 1;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
24
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
25 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
26 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
27 #define WAV_ID_FMT 0x20746d66 /* "fmt " */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
28 #define WAV_ID_DATA 0x61746164 /* "data" */
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
29 #define WAV_ID_PCM 0x0001
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 struct WaveHeader
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 unsigned long riff;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
34 unsigned long file_length;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
35 unsigned long wave;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
36 unsigned long fmt;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
37 unsigned long fmt_length;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
38 short fmt_tag;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
39 short channels;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
40 unsigned long sample_rate;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
41 unsigned long bytes_per_second;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
42 short block_align;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
43 short bits;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
44 unsigned long data;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
45 unsigned long data_length;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
46 };
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
47
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
48 /* init with default values */
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
49 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
50 le2me_32(WAV_ID_RIFF),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
51 le2me_32(0x00000000),
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_WAVE),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 le2me_32(WAV_ID_DATA),
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
62 le2me_32(0x00000000)
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
63 };
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
64
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
65 static FILE *fp = NULL;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
66
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
67 // to set/get/query special features/parameters
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
68 static int control(int cmd,int arg){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
69 return -1;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
70 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
71
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
72 // open & setup audio device
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
73 // return: 1=success 0=fail
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
74 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
75 int bits;
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
76 if(!ao_outputfilename) {
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
77 ao_outputfilename = (char *) malloc(sizeof(char) * 14);
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
78 strcpy(ao_outputfilename,
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
79 (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
80 }
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
81
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
82 /* 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
83 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
84 really be a switch to be correct in all cases */
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
85 if (format == AFMT_S16_BE) { bits = 16; }
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
86 else { bits = format; }
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
87
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
88 wavhdr.channels = le2me_16(channels);
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
89 wavhdr.sample_rate = le2me_32(rate);
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
90 wavhdr.bytes_per_second = rate * (bits / 8) * channels;
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
91 wavhdr.bytes_per_second = le2me_32(wavhdr.bytes_per_second);
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
92 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
93
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
94 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
95 "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
96 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
97 (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
98 printf("PCM: Info: fastest dumping is achieved with -vo null "
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
99 "-hardframedrop.\n"
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
100 "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
101 "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
102
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
103 fp = fopen(ao_outputfilename, "wb");
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
104
4914
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
105 ao_data.outburst = 65536;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
106
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
107
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
108 if(fp) {
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
109 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
110 fseek(fp, sizeof(wavhdr), SEEK_SET);
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
111 return 1;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
112 }
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
113 printf("PCM: Failed to open %s for writing!\n", ao_outputfilename);
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
114 return 0;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
115 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
116
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
117 // close audio device
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
118 static void uninit(){
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
119
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
120 if(ao_pcm_waveheader){ /* Write wave header */
4914
de4074ab4e5f good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
121 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
122 wavhdr.file_length = le2me_32(wavhdr.file_length);
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
123 fseek(fp, 0, SEEK_SET);
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
124 fwrite(&wavhdr,sizeof(wavhdr),1,fp);
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
125 }
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
126 fclose(fp);
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
127 free(ao_outputfilename);
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
128 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
129
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
130 // stop playing and empty buffers (for seeking/pause)
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
131 static void reset(){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
132
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
133 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
134
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
135 // stop playing, keep buffers (for pause)
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
136 static void audio_pause()
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
137 {
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
138 // for now, just call reset();
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
139 reset();
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
140 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
141
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
142 // resume playing, after audio_pause()
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
143 static void audio_resume()
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
144 {
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
145 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
146
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
147 // return: how many bytes can be played without blocking
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
148 static int get_space(){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
149
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
150 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
151 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
152 return ao_data.outburst;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
153 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
154
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
155 // plays 'len' bytes of 'data'
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
156 // it should round it down to outburst*n
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
157 // return: number of bytes played
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
158 static int play(void* data,int len,int flags){
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
159
5837
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
160 #ifdef WORDS_BIGENDIAN
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
161 register int i;
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
162 unsigned short *buffer = (unsigned short *) data;
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
163
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
164 if (wavhdr.bits == 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
165 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
166 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
167 }
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
168 }
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
169 /* FIXME: take care of cases with more than 8 bits here? */
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
170 #endif
7e082f42497a - Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents: 4914
diff changeset
171
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
172 //printf("PCM: Writing chunk!\n");
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
173 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
174
1112
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
175 if(ao_pcm_waveheader)
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
176 wavhdr.data_length += len;
b1cf1087ec33 Added support for writing wave files and specifying filename to write to.
atmosfear
parents: 1107
diff changeset
177
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
178 return len;
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
179 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
180
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
181 // return: delay in seconds between first and last sample in buffer
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
182 static float get_delay(){
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
183
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1113
diff changeset
184 return 0.0;
1107
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
185 }
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
186
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
187
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
188
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
189
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
190
9d764880d989 Added raw PCM writer ao driver.
atmosfear
parents:
diff changeset
191