annotate ima4.c @ 2444:ec8ff6ea4af6

Independed compilation of SUBDIRS
author nick
date Wed, 24 Oct 2001 07:34:41 +0000
parents 311676805f20
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2399
35c767f8fea4 initial
alex
parents:
diff changeset
1 /*
35c767f8fea4 initial
alex
parents:
diff changeset
2 IMA4:1 audio codec from QuickTime4Linux library. (http://www.heroinewarrior.com/)
35c767f8fea4 initial
alex
parents:
diff changeset
3 */
35c767f8fea4 initial
alex
parents:
diff changeset
4
35c767f8fea4 initial
alex
parents:
diff changeset
5 #include "ima4.h"
35c767f8fea4 initial
alex
parents:
diff changeset
6
35c767f8fea4 initial
alex
parents:
diff changeset
7 static int quicktime_ima4_step[89] =
35c767f8fea4 initial
alex
parents:
diff changeset
8 {
35c767f8fea4 initial
alex
parents:
diff changeset
9 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
35c767f8fea4 initial
alex
parents:
diff changeset
10 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
35c767f8fea4 initial
alex
parents:
diff changeset
11 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
35c767f8fea4 initial
alex
parents:
diff changeset
12 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
35c767f8fea4 initial
alex
parents:
diff changeset
13 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
35c767f8fea4 initial
alex
parents:
diff changeset
14 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
35c767f8fea4 initial
alex
parents:
diff changeset
15 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
35c767f8fea4 initial
alex
parents:
diff changeset
16 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
35c767f8fea4 initial
alex
parents:
diff changeset
17 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
35c767f8fea4 initial
alex
parents:
diff changeset
18 };
35c767f8fea4 initial
alex
parents:
diff changeset
19
35c767f8fea4 initial
alex
parents:
diff changeset
20 static int quicktime_ima4_index[16] =
35c767f8fea4 initial
alex
parents:
diff changeset
21 {
35c767f8fea4 initial
alex
parents:
diff changeset
22 -1, -1, -1, -1, 2, 4, 6, 8,
35c767f8fea4 initial
alex
parents:
diff changeset
23 -1, -1, -1, -1, 2, 4, 6, 8
35c767f8fea4 initial
alex
parents:
diff changeset
24 };
35c767f8fea4 initial
alex
parents:
diff changeset
25
35c767f8fea4 initial
alex
parents:
diff changeset
26 /* ================================== private for ima4 */
35c767f8fea4 initial
alex
parents:
diff changeset
27
35c767f8fea4 initial
alex
parents:
diff changeset
28
35c767f8fea4 initial
alex
parents:
diff changeset
29 void ima4_decode_sample(int *predictor, int *nibble, int *index, int *step)
35c767f8fea4 initial
alex
parents:
diff changeset
30 {
35c767f8fea4 initial
alex
parents:
diff changeset
31 int difference, sign;
35c767f8fea4 initial
alex
parents:
diff changeset
32
35c767f8fea4 initial
alex
parents:
diff changeset
33 /* Get new index value */
35c767f8fea4 initial
alex
parents:
diff changeset
34 *index += quicktime_ima4_index[*nibble];
35c767f8fea4 initial
alex
parents:
diff changeset
35
35c767f8fea4 initial
alex
parents:
diff changeset
36 if(*index < 0) *index = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
37 else
35c767f8fea4 initial
alex
parents:
diff changeset
38 if(*index > 88) *index = 88;
35c767f8fea4 initial
alex
parents:
diff changeset
39
35c767f8fea4 initial
alex
parents:
diff changeset
40 /* Get sign and magnitude from *nibble */
35c767f8fea4 initial
alex
parents:
diff changeset
41 sign = *nibble & 8;
35c767f8fea4 initial
alex
parents:
diff changeset
42 *nibble = *nibble & 7;
35c767f8fea4 initial
alex
parents:
diff changeset
43
35c767f8fea4 initial
alex
parents:
diff changeset
44 /* Get difference */
35c767f8fea4 initial
alex
parents:
diff changeset
45 difference = *step >> 3;
35c767f8fea4 initial
alex
parents:
diff changeset
46 if(*nibble & 4) difference += *step;
35c767f8fea4 initial
alex
parents:
diff changeset
47 if(*nibble & 2) difference += *step >> 1;
35c767f8fea4 initial
alex
parents:
diff changeset
48 if(*nibble & 1) difference += *step >> 2;
35c767f8fea4 initial
alex
parents:
diff changeset
49
35c767f8fea4 initial
alex
parents:
diff changeset
50 /* Predict value */
35c767f8fea4 initial
alex
parents:
diff changeset
51 if(sign)
35c767f8fea4 initial
alex
parents:
diff changeset
52 *predictor -= difference;
35c767f8fea4 initial
alex
parents:
diff changeset
53 else
35c767f8fea4 initial
alex
parents:
diff changeset
54 *predictor += difference;
35c767f8fea4 initial
alex
parents:
diff changeset
55
35c767f8fea4 initial
alex
parents:
diff changeset
56 if(*predictor > 32767) *predictor = 32767;
35c767f8fea4 initial
alex
parents:
diff changeset
57 else
35c767f8fea4 initial
alex
parents:
diff changeset
58 if(*predictor < -32768) *predictor = -32768;
35c767f8fea4 initial
alex
parents:
diff changeset
59
35c767f8fea4 initial
alex
parents:
diff changeset
60 /* Update the step value */
35c767f8fea4 initial
alex
parents:
diff changeset
61 *step = quicktime_ima4_step[*index];
35c767f8fea4 initial
alex
parents:
diff changeset
62 }
35c767f8fea4 initial
alex
parents:
diff changeset
63
2420
311676805f20 ima4 mov audio support
arpi
parents: 2399
diff changeset
64 int ima4_decode_block(unsigned short *output, unsigned char *input, int maxlen)
2399
35c767f8fea4 initial
alex
parents:
diff changeset
65 {
35c767f8fea4 initial
alex
parents:
diff changeset
66 int predictor;
35c767f8fea4 initial
alex
parents:
diff changeset
67 int index;
35c767f8fea4 initial
alex
parents:
diff changeset
68 int step;
35c767f8fea4 initial
alex
parents:
diff changeset
69 int i, nibble, nibble_count, block_size;
35c767f8fea4 initial
alex
parents:
diff changeset
70 int olen = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
71 unsigned char *block_ptr;
2420
311676805f20 ima4 mov audio support
arpi
parents: 2399
diff changeset
72 unsigned char *input_end = input + IMA4_BLOCK_SIZE;
2399
35c767f8fea4 initial
alex
parents:
diff changeset
73 // quicktime_ima4_codec_t *codec = ((quicktime_codec_t*)atrack->codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
74
35c767f8fea4 initial
alex
parents:
diff changeset
75 /* Get the chunk header */
35c767f8fea4 initial
alex
parents:
diff changeset
76 predictor = *input++ << 8;
35c767f8fea4 initial
alex
parents:
diff changeset
77 predictor |= *input++;
35c767f8fea4 initial
alex
parents:
diff changeset
78
35c767f8fea4 initial
alex
parents:
diff changeset
79 index = predictor & 0x7f;
35c767f8fea4 initial
alex
parents:
diff changeset
80 if(index > 88) index = 88;
35c767f8fea4 initial
alex
parents:
diff changeset
81
35c767f8fea4 initial
alex
parents:
diff changeset
82 predictor &= 0xff80;
35c767f8fea4 initial
alex
parents:
diff changeset
83 if(predictor & 0x8000) predictor -= 0x10000;
35c767f8fea4 initial
alex
parents:
diff changeset
84 step = quicktime_ima4_step[index];
35c767f8fea4 initial
alex
parents:
diff changeset
85
35c767f8fea4 initial
alex
parents:
diff changeset
86 /* Read the input buffer sequentially, one nibble at a time */
35c767f8fea4 initial
alex
parents:
diff changeset
87 nibble_count = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
88 while(input < input_end)
35c767f8fea4 initial
alex
parents:
diff changeset
89 {
35c767f8fea4 initial
alex
parents:
diff changeset
90 nibble = nibble_count ? (*input++ >> 4) & 0x0f : *input & 0x0f;
35c767f8fea4 initial
alex
parents:
diff changeset
91
35c767f8fea4 initial
alex
parents:
diff changeset
92 ima4_decode_sample(&predictor, &nibble, &index, &step);
35c767f8fea4 initial
alex
parents:
diff changeset
93 if (olen+1 > maxlen)
35c767f8fea4 initial
alex
parents:
diff changeset
94 break;
35c767f8fea4 initial
alex
parents:
diff changeset
95 *output++ = predictor;
35c767f8fea4 initial
alex
parents:
diff changeset
96 olen++;
35c767f8fea4 initial
alex
parents:
diff changeset
97
35c767f8fea4 initial
alex
parents:
diff changeset
98 nibble_count ^= 1;
35c767f8fea4 initial
alex
parents:
diff changeset
99 }
35c767f8fea4 initial
alex
parents:
diff changeset
100 return(olen);
35c767f8fea4 initial
alex
parents:
diff changeset
101 }
35c767f8fea4 initial
alex
parents:
diff changeset
102
35c767f8fea4 initial
alex
parents:
diff changeset
103 #if 0
35c767f8fea4 initial
alex
parents:
diff changeset
104 void ima4_encode_sample(int *last_sample, int *last_index, int *nibble, int next_sample)
35c767f8fea4 initial
alex
parents:
diff changeset
105 {
35c767f8fea4 initial
alex
parents:
diff changeset
106 int difference, new_difference, mask, step;
35c767f8fea4 initial
alex
parents:
diff changeset
107
35c767f8fea4 initial
alex
parents:
diff changeset
108 difference = next_sample - *last_sample;
35c767f8fea4 initial
alex
parents:
diff changeset
109 *nibble = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
110 step = quicktime_ima4_step[*last_index];
35c767f8fea4 initial
alex
parents:
diff changeset
111 new_difference = step >> 3;
35c767f8fea4 initial
alex
parents:
diff changeset
112
35c767f8fea4 initial
alex
parents:
diff changeset
113 if(difference < 0)
35c767f8fea4 initial
alex
parents:
diff changeset
114 {
35c767f8fea4 initial
alex
parents:
diff changeset
115 *nibble = 8;
35c767f8fea4 initial
alex
parents:
diff changeset
116 difference = -difference;
35c767f8fea4 initial
alex
parents:
diff changeset
117 }
35c767f8fea4 initial
alex
parents:
diff changeset
118
35c767f8fea4 initial
alex
parents:
diff changeset
119 mask = 4;
35c767f8fea4 initial
alex
parents:
diff changeset
120 while(mask)
35c767f8fea4 initial
alex
parents:
diff changeset
121 {
35c767f8fea4 initial
alex
parents:
diff changeset
122 if(difference >= step)
35c767f8fea4 initial
alex
parents:
diff changeset
123 {
35c767f8fea4 initial
alex
parents:
diff changeset
124 *nibble |= mask;
35c767f8fea4 initial
alex
parents:
diff changeset
125 difference -= step;
35c767f8fea4 initial
alex
parents:
diff changeset
126 new_difference += step;
35c767f8fea4 initial
alex
parents:
diff changeset
127 }
35c767f8fea4 initial
alex
parents:
diff changeset
128
35c767f8fea4 initial
alex
parents:
diff changeset
129 step >>= 1;
35c767f8fea4 initial
alex
parents:
diff changeset
130 mask >>= 1;
35c767f8fea4 initial
alex
parents:
diff changeset
131 }
35c767f8fea4 initial
alex
parents:
diff changeset
132
35c767f8fea4 initial
alex
parents:
diff changeset
133 if(*nibble & 8)
35c767f8fea4 initial
alex
parents:
diff changeset
134 *last_sample -= new_difference;
35c767f8fea4 initial
alex
parents:
diff changeset
135 else
35c767f8fea4 initial
alex
parents:
diff changeset
136 *last_sample += new_difference;
35c767f8fea4 initial
alex
parents:
diff changeset
137
35c767f8fea4 initial
alex
parents:
diff changeset
138 if(*last_sample > 32767) *last_sample = 32767;
35c767f8fea4 initial
alex
parents:
diff changeset
139 else
35c767f8fea4 initial
alex
parents:
diff changeset
140 if(*last_sample < -32767) *last_sample = -32767;
35c767f8fea4 initial
alex
parents:
diff changeset
141
35c767f8fea4 initial
alex
parents:
diff changeset
142 *last_index += quicktime_ima4_index[*nibble];
35c767f8fea4 initial
alex
parents:
diff changeset
143
35c767f8fea4 initial
alex
parents:
diff changeset
144 if(*last_index < 0) *last_index = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
145 else
35c767f8fea4 initial
alex
parents:
diff changeset
146 if(*last_index > 88) *last_index= 88;
35c767f8fea4 initial
alex
parents:
diff changeset
147 }
35c767f8fea4 initial
alex
parents:
diff changeset
148
35c767f8fea4 initial
alex
parents:
diff changeset
149 #if 0
35c767f8fea4 initial
alex
parents:
diff changeset
150 void ima4_encode_block(quicktime_audio_map_t *atrack, unsigned char *output, int16_t *input, int step, int channel)
35c767f8fea4 initial
alex
parents:
diff changeset
151 {
35c767f8fea4 initial
alex
parents:
diff changeset
152 quicktime_ima4_codec_t *codec = ((quicktime_codec_t*)atrack->codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
153 int i, nibble_count = 0, nibble, header;
35c767f8fea4 initial
alex
parents:
diff changeset
154
35c767f8fea4 initial
alex
parents:
diff changeset
155 /* Get a fake starting sample */
35c767f8fea4 initial
alex
parents:
diff changeset
156 header = codec->last_samples[channel];
35c767f8fea4 initial
alex
parents:
diff changeset
157 /* Force rounding. */
35c767f8fea4 initial
alex
parents:
diff changeset
158 if(header < 0x7fc0) header += 0x40;
35c767f8fea4 initial
alex
parents:
diff changeset
159 if(header < 0) header += 0x10000;
35c767f8fea4 initial
alex
parents:
diff changeset
160 header &= 0xff80;
35c767f8fea4 initial
alex
parents:
diff changeset
161 *output++ = (header & 0xff00) >> 8;
35c767f8fea4 initial
alex
parents:
diff changeset
162 *output++ = (header & 0x80) + (codec->last_indexes[channel] & 0x7f);
35c767f8fea4 initial
alex
parents:
diff changeset
163
35c767f8fea4 initial
alex
parents:
diff changeset
164 for(i = 0; i < SAMPLES_PER_BLOCK; i++)
35c767f8fea4 initial
alex
parents:
diff changeset
165 {
35c767f8fea4 initial
alex
parents:
diff changeset
166 ima4_encode_sample(&(codec->last_samples[channel]),
35c767f8fea4 initial
alex
parents:
diff changeset
167 &(codec->last_indexes[channel]),
35c767f8fea4 initial
alex
parents:
diff changeset
168 &nibble,
35c767f8fea4 initial
alex
parents:
diff changeset
169 *input);
35c767f8fea4 initial
alex
parents:
diff changeset
170
35c767f8fea4 initial
alex
parents:
diff changeset
171 if(nibble_count)
35c767f8fea4 initial
alex
parents:
diff changeset
172 *output++ |= (nibble << 4);
35c767f8fea4 initial
alex
parents:
diff changeset
173 else
35c767f8fea4 initial
alex
parents:
diff changeset
174 *output = nibble;
35c767f8fea4 initial
alex
parents:
diff changeset
175
35c767f8fea4 initial
alex
parents:
diff changeset
176 input += step;
35c767f8fea4 initial
alex
parents:
diff changeset
177 nibble_count ^= 1;
35c767f8fea4 initial
alex
parents:
diff changeset
178 }
35c767f8fea4 initial
alex
parents:
diff changeset
179 }
35c767f8fea4 initial
alex
parents:
diff changeset
180 #endif
35c767f8fea4 initial
alex
parents:
diff changeset
181 /* Convert the number of samples in a chunk into the number of bytes in that */
35c767f8fea4 initial
alex
parents:
diff changeset
182 /* chunk. The number of samples in a chunk should end on a block boundary. */
35c767f8fea4 initial
alex
parents:
diff changeset
183 long ima4_samples_to_bytes(long samples, int channels)
35c767f8fea4 initial
alex
parents:
diff changeset
184 {
35c767f8fea4 initial
alex
parents:
diff changeset
185 long bytes = samples / SAMPLES_PER_BLOCK * BLOCK_SIZE * channels;
35c767f8fea4 initial
alex
parents:
diff changeset
186 return bytes;
35c767f8fea4 initial
alex
parents:
diff changeset
187 }
35c767f8fea4 initial
alex
parents:
diff changeset
188
35c767f8fea4 initial
alex
parents:
diff changeset
189 /* Decode the chunk into the work buffer */
35c767f8fea4 initial
alex
parents:
diff changeset
190 int ima4_decode_chunk(quicktime_t *file, int track, long chunk, int channel)
35c767f8fea4 initial
alex
parents:
diff changeset
191 {
35c767f8fea4 initial
alex
parents:
diff changeset
192 int result = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
193 int i, j;
35c767f8fea4 initial
alex
parents:
diff changeset
194 long chunk_samples, chunk_bytes;
35c767f8fea4 initial
alex
parents:
diff changeset
195 unsigned char *chunk_ptr, *block_ptr;
35c767f8fea4 initial
alex
parents:
diff changeset
196 quicktime_trak_t *trak = file->atracks[track].track;
35c767f8fea4 initial
alex
parents:
diff changeset
197 quicktime_ima4_codec_t *codec = ((quicktime_codec_t*)file->atracks[track].codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
198
35c767f8fea4 initial
alex
parents:
diff changeset
199 /* Get the byte count to read. */
35c767f8fea4 initial
alex
parents:
diff changeset
200 chunk_samples = quicktime_chunk_samples(trak, chunk);
35c767f8fea4 initial
alex
parents:
diff changeset
201 chunk_bytes = ima4_samples_to_bytes(chunk_samples, file->atracks[track].channels);
35c767f8fea4 initial
alex
parents:
diff changeset
202
35c767f8fea4 initial
alex
parents:
diff changeset
203 /* Get the buffer to read into. */
35c767f8fea4 initial
alex
parents:
diff changeset
204 if(codec->work_buffer && codec->work_size < chunk_samples)
35c767f8fea4 initial
alex
parents:
diff changeset
205 {
35c767f8fea4 initial
alex
parents:
diff changeset
206 free(codec->work_buffer);
35c767f8fea4 initial
alex
parents:
diff changeset
207 codec->work_buffer = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
208 }
35c767f8fea4 initial
alex
parents:
diff changeset
209
35c767f8fea4 initial
alex
parents:
diff changeset
210 if(!codec->work_buffer)
35c767f8fea4 initial
alex
parents:
diff changeset
211 {
35c767f8fea4 initial
alex
parents:
diff changeset
212 codec->work_size = chunk_samples;
35c767f8fea4 initial
alex
parents:
diff changeset
213 codec->work_buffer = malloc(sizeof(int16_t) * codec->work_size);
35c767f8fea4 initial
alex
parents:
diff changeset
214 }
35c767f8fea4 initial
alex
parents:
diff changeset
215
35c767f8fea4 initial
alex
parents:
diff changeset
216 if(codec->read_buffer && codec->read_size < chunk_bytes)
35c767f8fea4 initial
alex
parents:
diff changeset
217 {
35c767f8fea4 initial
alex
parents:
diff changeset
218 free(codec->read_buffer);
35c767f8fea4 initial
alex
parents:
diff changeset
219 codec->read_buffer = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
220 }
35c767f8fea4 initial
alex
parents:
diff changeset
221
35c767f8fea4 initial
alex
parents:
diff changeset
222 if(!codec->read_buffer)
35c767f8fea4 initial
alex
parents:
diff changeset
223 {
35c767f8fea4 initial
alex
parents:
diff changeset
224 codec->read_size = chunk_bytes;
35c767f8fea4 initial
alex
parents:
diff changeset
225 codec->read_buffer = malloc(codec->read_size);
35c767f8fea4 initial
alex
parents:
diff changeset
226 }
35c767f8fea4 initial
alex
parents:
diff changeset
227
35c767f8fea4 initial
alex
parents:
diff changeset
228 /* codec->work_size now holds the number of samples in the last chunk */
35c767f8fea4 initial
alex
parents:
diff changeset
229 /* codec->read_size now holds number of bytes in the last read buffer */
35c767f8fea4 initial
alex
parents:
diff changeset
230
35c767f8fea4 initial
alex
parents:
diff changeset
231 /* Read the entire chunk regardless of where the desired sample range starts. */
35c767f8fea4 initial
alex
parents:
diff changeset
232 result = quicktime_read_chunk(file, codec->read_buffer, track, chunk, 0, chunk_bytes);
35c767f8fea4 initial
alex
parents:
diff changeset
233
35c767f8fea4 initial
alex
parents:
diff changeset
234 /* Now decode the chunk, one block at a time, until the total samples in the chunk */
35c767f8fea4 initial
alex
parents:
diff changeset
235 /* is reached. */
35c767f8fea4 initial
alex
parents:
diff changeset
236
35c767f8fea4 initial
alex
parents:
diff changeset
237 if(!result)
35c767f8fea4 initial
alex
parents:
diff changeset
238 {
35c767f8fea4 initial
alex
parents:
diff changeset
239 block_ptr = codec->read_buffer;
35c767f8fea4 initial
alex
parents:
diff changeset
240 for(i = 0; i < chunk_samples; i += SAMPLES_PER_BLOCK)
35c767f8fea4 initial
alex
parents:
diff changeset
241 {
35c767f8fea4 initial
alex
parents:
diff changeset
242 for(j = 0; j < file->atracks[track].channels; j++)
35c767f8fea4 initial
alex
parents:
diff changeset
243 {
35c767f8fea4 initial
alex
parents:
diff changeset
244 if(j == channel)
35c767f8fea4 initial
alex
parents:
diff changeset
245 ima4_decode_block(&(file->atracks[track]), &(codec->work_buffer[i]), block_ptr);
35c767f8fea4 initial
alex
parents:
diff changeset
246
35c767f8fea4 initial
alex
parents:
diff changeset
247 block_ptr += BLOCK_SIZE;
35c767f8fea4 initial
alex
parents:
diff changeset
248 }
35c767f8fea4 initial
alex
parents:
diff changeset
249 }
35c767f8fea4 initial
alex
parents:
diff changeset
250 }
35c767f8fea4 initial
alex
parents:
diff changeset
251 codec->buffer_channel = channel;
35c767f8fea4 initial
alex
parents:
diff changeset
252 codec->chunk = chunk;
35c767f8fea4 initial
alex
parents:
diff changeset
253
35c767f8fea4 initial
alex
parents:
diff changeset
254 return result;
35c767f8fea4 initial
alex
parents:
diff changeset
255 }
35c767f8fea4 initial
alex
parents:
diff changeset
256
35c767f8fea4 initial
alex
parents:
diff changeset
257
35c767f8fea4 initial
alex
parents:
diff changeset
258 /* =================================== public for ima4 */
35c767f8fea4 initial
alex
parents:
diff changeset
259
35c767f8fea4 initial
alex
parents:
diff changeset
260 static int quicktime_delete_codec_ima4(quicktime_audio_map_t *atrack)
35c767f8fea4 initial
alex
parents:
diff changeset
261 {
35c767f8fea4 initial
alex
parents:
diff changeset
262 quicktime_ima4_codec_t *codec = ((quicktime_codec_t*)atrack->codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
263
35c767f8fea4 initial
alex
parents:
diff changeset
264 if(codec->work_buffer) free(codec->work_buffer);
35c767f8fea4 initial
alex
parents:
diff changeset
265 if(codec->read_buffer) free(codec->read_buffer);
35c767f8fea4 initial
alex
parents:
diff changeset
266 if(codec->last_samples) free(codec->last_samples);
35c767f8fea4 initial
alex
parents:
diff changeset
267 if(codec->last_indexes) free(codec->last_indexes);
35c767f8fea4 initial
alex
parents:
diff changeset
268 codec->last_samples = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
269 codec->last_indexes = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
270 codec->read_buffer = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
271 codec->work_buffer = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
272 codec->chunk = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
273 codec->buffer_channel = 0; /* Channel of work buffer */
35c767f8fea4 initial
alex
parents:
diff changeset
274 codec->work_size = 0; /* Size of work buffer */
35c767f8fea4 initial
alex
parents:
diff changeset
275 codec->read_size = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
276 free(codec);
35c767f8fea4 initial
alex
parents:
diff changeset
277 return 0;
35c767f8fea4 initial
alex
parents:
diff changeset
278 }
35c767f8fea4 initial
alex
parents:
diff changeset
279
35c767f8fea4 initial
alex
parents:
diff changeset
280 static int quicktime_decode_ima4(quicktime_t *file,
35c767f8fea4 initial
alex
parents:
diff changeset
281 int16_t *output_i,
35c767f8fea4 initial
alex
parents:
diff changeset
282 float *output_f,
35c767f8fea4 initial
alex
parents:
diff changeset
283 long samples,
35c767f8fea4 initial
alex
parents:
diff changeset
284 int track,
35c767f8fea4 initial
alex
parents:
diff changeset
285 int channel)
35c767f8fea4 initial
alex
parents:
diff changeset
286 {
35c767f8fea4 initial
alex
parents:
diff changeset
287 int result = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
288 longest chunk, chunk_sample, chunk_bytes, chunk_samples;
35c767f8fea4 initial
alex
parents:
diff changeset
289 longest i, chunk_start, chunk_end;
35c767f8fea4 initial
alex
parents:
diff changeset
290 quicktime_trak_t *trak = file->atracks[track].track;
35c767f8fea4 initial
alex
parents:
diff changeset
291 quicktime_ima4_codec_t *codec = ((quicktime_codec_t*)file->atracks[track].codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
292
35c767f8fea4 initial
alex
parents:
diff changeset
293 /* Get the first chunk with this routine and then increase the chunk number. */
35c767f8fea4 initial
alex
parents:
diff changeset
294 quicktime_chunk_of_sample(&chunk_sample, &chunk, trak, file->atracks[track].current_position);
35c767f8fea4 initial
alex
parents:
diff changeset
295
35c767f8fea4 initial
alex
parents:
diff changeset
296 /* Read chunks and extract ranges of samples until the output is full. */
35c767f8fea4 initial
alex
parents:
diff changeset
297 for(i = 0; i < samples && !result; )
35c767f8fea4 initial
alex
parents:
diff changeset
298 {
35c767f8fea4 initial
alex
parents:
diff changeset
299 /* Get chunk we're on. */
35c767f8fea4 initial
alex
parents:
diff changeset
300 chunk_samples = quicktime_chunk_samples(trak, chunk);
35c767f8fea4 initial
alex
parents:
diff changeset
301
35c767f8fea4 initial
alex
parents:
diff changeset
302 if(!codec->work_buffer ||
35c767f8fea4 initial
alex
parents:
diff changeset
303 codec->chunk != chunk ||
35c767f8fea4 initial
alex
parents:
diff changeset
304 codec->buffer_channel != channel)
35c767f8fea4 initial
alex
parents:
diff changeset
305 {
35c767f8fea4 initial
alex
parents:
diff changeset
306 /* read a new chunk if necessary */
35c767f8fea4 initial
alex
parents:
diff changeset
307 result = ima4_decode_chunk(file, track, chunk, channel);
35c767f8fea4 initial
alex
parents:
diff changeset
308 }
35c767f8fea4 initial
alex
parents:
diff changeset
309
35c767f8fea4 initial
alex
parents:
diff changeset
310 /* Get boundaries from the chunk */
35c767f8fea4 initial
alex
parents:
diff changeset
311 chunk_start = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
312 if(chunk_sample < file->atracks[track].current_position)
35c767f8fea4 initial
alex
parents:
diff changeset
313 chunk_start = file->atracks[track].current_position - chunk_sample;
35c767f8fea4 initial
alex
parents:
diff changeset
314
35c767f8fea4 initial
alex
parents:
diff changeset
315 chunk_end = chunk_samples;
35c767f8fea4 initial
alex
parents:
diff changeset
316 if(chunk_sample + chunk_end > file->atracks[track].current_position + samples)
35c767f8fea4 initial
alex
parents:
diff changeset
317 chunk_end = file->atracks[track].current_position + samples - chunk_sample;
35c767f8fea4 initial
alex
parents:
diff changeset
318
35c767f8fea4 initial
alex
parents:
diff changeset
319 /* Read from the chunk */
35c767f8fea4 initial
alex
parents:
diff changeset
320 if(output_i)
35c767f8fea4 initial
alex
parents:
diff changeset
321 {
35c767f8fea4 initial
alex
parents:
diff changeset
322 /*printf("decode_ima4 1 chunk %ld %ld-%ld output %ld\n", chunk, chunk_start + chunk_sample, chunk_end + chunk_sample, i); */
35c767f8fea4 initial
alex
parents:
diff changeset
323 while(chunk_start < chunk_end)
35c767f8fea4 initial
alex
parents:
diff changeset
324 {
35c767f8fea4 initial
alex
parents:
diff changeset
325 output_i[i++] = codec->work_buffer[chunk_start++];
35c767f8fea4 initial
alex
parents:
diff changeset
326 }
35c767f8fea4 initial
alex
parents:
diff changeset
327 /*printf("decode_ima4 2\n"); */
35c767f8fea4 initial
alex
parents:
diff changeset
328 }
35c767f8fea4 initial
alex
parents:
diff changeset
329 else
35c767f8fea4 initial
alex
parents:
diff changeset
330 if(output_f)
35c767f8fea4 initial
alex
parents:
diff changeset
331 {
35c767f8fea4 initial
alex
parents:
diff changeset
332 while(chunk_start < chunk_end)
35c767f8fea4 initial
alex
parents:
diff changeset
333 {
35c767f8fea4 initial
alex
parents:
diff changeset
334 output_f[i++] = (float)codec->work_buffer[chunk_start++] / 32767;
35c767f8fea4 initial
alex
parents:
diff changeset
335 }
35c767f8fea4 initial
alex
parents:
diff changeset
336 }
35c767f8fea4 initial
alex
parents:
diff changeset
337
35c767f8fea4 initial
alex
parents:
diff changeset
338 chunk++;
35c767f8fea4 initial
alex
parents:
diff changeset
339 chunk_sample += chunk_samples;
35c767f8fea4 initial
alex
parents:
diff changeset
340 }
35c767f8fea4 initial
alex
parents:
diff changeset
341
35c767f8fea4 initial
alex
parents:
diff changeset
342 return result;
35c767f8fea4 initial
alex
parents:
diff changeset
343 }
35c767f8fea4 initial
alex
parents:
diff changeset
344
35c767f8fea4 initial
alex
parents:
diff changeset
345 static int quicktime_encode_ima4(quicktime_t *file,
35c767f8fea4 initial
alex
parents:
diff changeset
346 int16_t **input_i,
35c767f8fea4 initial
alex
parents:
diff changeset
347 float **input_f,
35c767f8fea4 initial
alex
parents:
diff changeset
348 int track,
35c767f8fea4 initial
alex
parents:
diff changeset
349 long samples)
35c767f8fea4 initial
alex
parents:
diff changeset
350 {
35c767f8fea4 initial
alex
parents:
diff changeset
351 int result = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
352 longest i, j, step;
35c767f8fea4 initial
alex
parents:
diff changeset
353 longest chunk_bytes;
35c767f8fea4 initial
alex
parents:
diff changeset
354 longest overflow_start;
35c767f8fea4 initial
alex
parents:
diff changeset
355 longest offset;
35c767f8fea4 initial
alex
parents:
diff changeset
356 longest chunk_samples; /* Samples in the current chunk to be written */
35c767f8fea4 initial
alex
parents:
diff changeset
357 quicktime_audio_map_t *track_map = &(file->atracks[track]);
35c767f8fea4 initial
alex
parents:
diff changeset
358 quicktime_ima4_codec_t *codec = ((quicktime_codec_t*)track_map->codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
359 int16_t *input_ptr;
35c767f8fea4 initial
alex
parents:
diff changeset
360 unsigned char *output_ptr;
35c767f8fea4 initial
alex
parents:
diff changeset
361
35c767f8fea4 initial
alex
parents:
diff changeset
362 /* Get buffer sizes */
35c767f8fea4 initial
alex
parents:
diff changeset
363 if(codec->work_buffer && codec->work_size < (samples + codec->work_overflow + 1) * track_map->channels)
35c767f8fea4 initial
alex
parents:
diff changeset
364 {
35c767f8fea4 initial
alex
parents:
diff changeset
365 /* Create new buffer */
35c767f8fea4 initial
alex
parents:
diff changeset
366 longest new_size = (samples + codec->work_overflow + 1) * track_map->channels;
35c767f8fea4 initial
alex
parents:
diff changeset
367 int16_t *new_buffer = malloc(sizeof(int16_t) * new_size);
35c767f8fea4 initial
alex
parents:
diff changeset
368
35c767f8fea4 initial
alex
parents:
diff changeset
369 /* Copy overflow */
35c767f8fea4 initial
alex
parents:
diff changeset
370 for(i = 0; i < codec->work_overflow * track_map->channels; i++)
35c767f8fea4 initial
alex
parents:
diff changeset
371 new_buffer[i] = codec->work_buffer[i];
35c767f8fea4 initial
alex
parents:
diff changeset
372
35c767f8fea4 initial
alex
parents:
diff changeset
373 /* Swap pointers. */
35c767f8fea4 initial
alex
parents:
diff changeset
374 free(codec->work_buffer);
35c767f8fea4 initial
alex
parents:
diff changeset
375 codec->work_buffer = new_buffer;
35c767f8fea4 initial
alex
parents:
diff changeset
376 codec->work_size = new_size;
35c767f8fea4 initial
alex
parents:
diff changeset
377 }
35c767f8fea4 initial
alex
parents:
diff changeset
378 else
35c767f8fea4 initial
alex
parents:
diff changeset
379 if(!codec->work_buffer)
35c767f8fea4 initial
alex
parents:
diff changeset
380 {
35c767f8fea4 initial
alex
parents:
diff changeset
381 /* No buffer in the first place. */
35c767f8fea4 initial
alex
parents:
diff changeset
382 codec->work_size = (samples + codec->work_overflow) * track_map->channels;
35c767f8fea4 initial
alex
parents:
diff changeset
383 /* Make the allocation enough for at least the flush routine. */
35c767f8fea4 initial
alex
parents:
diff changeset
384 if(codec->work_size < SAMPLES_PER_BLOCK * track_map->channels)
35c767f8fea4 initial
alex
parents:
diff changeset
385 codec->work_size = SAMPLES_PER_BLOCK * track_map->channels;
35c767f8fea4 initial
alex
parents:
diff changeset
386 codec->work_buffer = malloc(sizeof(int16_t) * codec->work_size);
35c767f8fea4 initial
alex
parents:
diff changeset
387 }
35c767f8fea4 initial
alex
parents:
diff changeset
388
35c767f8fea4 initial
alex
parents:
diff changeset
389 /* Get output size */
35c767f8fea4 initial
alex
parents:
diff changeset
390 chunk_bytes = ima4_samples_to_bytes(samples + codec->work_overflow, track_map->channels);
35c767f8fea4 initial
alex
parents:
diff changeset
391 if(codec->read_buffer && codec->read_size < chunk_bytes)
35c767f8fea4 initial
alex
parents:
diff changeset
392 {
35c767f8fea4 initial
alex
parents:
diff changeset
393 free(codec->read_buffer);
35c767f8fea4 initial
alex
parents:
diff changeset
394 codec->read_buffer = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
395 }
35c767f8fea4 initial
alex
parents:
diff changeset
396
35c767f8fea4 initial
alex
parents:
diff changeset
397 if(!codec->read_buffer)
35c767f8fea4 initial
alex
parents:
diff changeset
398 {
35c767f8fea4 initial
alex
parents:
diff changeset
399 codec->read_buffer = malloc(chunk_bytes);
35c767f8fea4 initial
alex
parents:
diff changeset
400 codec->read_size = chunk_bytes;
35c767f8fea4 initial
alex
parents:
diff changeset
401 }
35c767f8fea4 initial
alex
parents:
diff changeset
402
35c767f8fea4 initial
alex
parents:
diff changeset
403 if(!codec->last_samples)
35c767f8fea4 initial
alex
parents:
diff changeset
404 {
35c767f8fea4 initial
alex
parents:
diff changeset
405 codec->last_samples = malloc(sizeof(int) * track_map->channels);
35c767f8fea4 initial
alex
parents:
diff changeset
406 for(i = 0; i < track_map->channels; i++)
35c767f8fea4 initial
alex
parents:
diff changeset
407 {
35c767f8fea4 initial
alex
parents:
diff changeset
408 codec->last_samples[i] = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
409 }
35c767f8fea4 initial
alex
parents:
diff changeset
410 }
35c767f8fea4 initial
alex
parents:
diff changeset
411
35c767f8fea4 initial
alex
parents:
diff changeset
412 if(!codec->last_indexes)
35c767f8fea4 initial
alex
parents:
diff changeset
413 {
35c767f8fea4 initial
alex
parents:
diff changeset
414 codec->last_indexes = malloc(sizeof(int) * track_map->channels);
35c767f8fea4 initial
alex
parents:
diff changeset
415 for(i = 0; i < track_map->channels; i++)
35c767f8fea4 initial
alex
parents:
diff changeset
416 {
35c767f8fea4 initial
alex
parents:
diff changeset
417 codec->last_indexes[i] = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
418 }
35c767f8fea4 initial
alex
parents:
diff changeset
419 }
35c767f8fea4 initial
alex
parents:
diff changeset
420
35c767f8fea4 initial
alex
parents:
diff changeset
421 /* Arm the input buffer after the last overflow */
35c767f8fea4 initial
alex
parents:
diff changeset
422 step = track_map->channels;
35c767f8fea4 initial
alex
parents:
diff changeset
423 for(j = 0; j < track_map->channels; j++)
35c767f8fea4 initial
alex
parents:
diff changeset
424 {
35c767f8fea4 initial
alex
parents:
diff changeset
425 input_ptr = codec->work_buffer + codec->work_overflow * track_map->channels + j;
35c767f8fea4 initial
alex
parents:
diff changeset
426
35c767f8fea4 initial
alex
parents:
diff changeset
427 if(input_i)
35c767f8fea4 initial
alex
parents:
diff changeset
428 {
35c767f8fea4 initial
alex
parents:
diff changeset
429 for(i = 0; i < samples; i++)
35c767f8fea4 initial
alex
parents:
diff changeset
430 {
35c767f8fea4 initial
alex
parents:
diff changeset
431 *input_ptr = input_i[j][i];
35c767f8fea4 initial
alex
parents:
diff changeset
432 input_ptr += step;
35c767f8fea4 initial
alex
parents:
diff changeset
433 }
35c767f8fea4 initial
alex
parents:
diff changeset
434 }
35c767f8fea4 initial
alex
parents:
diff changeset
435 else
35c767f8fea4 initial
alex
parents:
diff changeset
436 if(input_f)
35c767f8fea4 initial
alex
parents:
diff changeset
437 {
35c767f8fea4 initial
alex
parents:
diff changeset
438 for(i = 0; i < samples; i++)
35c767f8fea4 initial
alex
parents:
diff changeset
439 {
35c767f8fea4 initial
alex
parents:
diff changeset
440 *input_ptr = (int16_t)(input_f[j][i] * 32767);
35c767f8fea4 initial
alex
parents:
diff changeset
441 input_ptr += step;
35c767f8fea4 initial
alex
parents:
diff changeset
442 }
35c767f8fea4 initial
alex
parents:
diff changeset
443 }
35c767f8fea4 initial
alex
parents:
diff changeset
444 }
35c767f8fea4 initial
alex
parents:
diff changeset
445
35c767f8fea4 initial
alex
parents:
diff changeset
446 /* Encode from the input buffer to the read_buffer up to a multiple of */
35c767f8fea4 initial
alex
parents:
diff changeset
447 /* blocks. */
35c767f8fea4 initial
alex
parents:
diff changeset
448 input_ptr = codec->work_buffer;
35c767f8fea4 initial
alex
parents:
diff changeset
449 output_ptr = codec->read_buffer;
35c767f8fea4 initial
alex
parents:
diff changeset
450
35c767f8fea4 initial
alex
parents:
diff changeset
451 for(i = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
452 i + SAMPLES_PER_BLOCK <= samples + codec->work_overflow;
35c767f8fea4 initial
alex
parents:
diff changeset
453 i += SAMPLES_PER_BLOCK)
35c767f8fea4 initial
alex
parents:
diff changeset
454 {
35c767f8fea4 initial
alex
parents:
diff changeset
455 for(j = 0; j < track_map->channels; j++)
35c767f8fea4 initial
alex
parents:
diff changeset
456 {
35c767f8fea4 initial
alex
parents:
diff changeset
457 ima4_encode_block(track_map, output_ptr, input_ptr + j, track_map->channels, j);
35c767f8fea4 initial
alex
parents:
diff changeset
458
35c767f8fea4 initial
alex
parents:
diff changeset
459 output_ptr += BLOCK_SIZE;
35c767f8fea4 initial
alex
parents:
diff changeset
460 }
35c767f8fea4 initial
alex
parents:
diff changeset
461 input_ptr += SAMPLES_PER_BLOCK * track_map->channels;
35c767f8fea4 initial
alex
parents:
diff changeset
462 }
35c767f8fea4 initial
alex
parents:
diff changeset
463
35c767f8fea4 initial
alex
parents:
diff changeset
464 /* Write to disk */
35c767f8fea4 initial
alex
parents:
diff changeset
465 chunk_samples = (longest)((samples + codec->work_overflow) / SAMPLES_PER_BLOCK) * SAMPLES_PER_BLOCK;
35c767f8fea4 initial
alex
parents:
diff changeset
466
35c767f8fea4 initial
alex
parents:
diff changeset
467 /*printf("quicktime_encode_ima4 1 %ld\n", chunk_samples); */
35c767f8fea4 initial
alex
parents:
diff changeset
468 /* The block division may result in 0 samples getting encoded. */
35c767f8fea4 initial
alex
parents:
diff changeset
469 /* Don't write 0 samples. */
35c767f8fea4 initial
alex
parents:
diff changeset
470 if(chunk_samples)
35c767f8fea4 initial
alex
parents:
diff changeset
471 {
35c767f8fea4 initial
alex
parents:
diff changeset
472 offset = quicktime_position(file);
35c767f8fea4 initial
alex
parents:
diff changeset
473 result = quicktime_write_data(file, codec->read_buffer, chunk_bytes);
35c767f8fea4 initial
alex
parents:
diff changeset
474 if(result) result = 0; else result = 1; /* defeat fwrite's return */
35c767f8fea4 initial
alex
parents:
diff changeset
475 quicktime_update_tables(file,
35c767f8fea4 initial
alex
parents:
diff changeset
476 track_map->track,
35c767f8fea4 initial
alex
parents:
diff changeset
477 offset,
35c767f8fea4 initial
alex
parents:
diff changeset
478 track_map->current_chunk,
35c767f8fea4 initial
alex
parents:
diff changeset
479 track_map->current_position,
35c767f8fea4 initial
alex
parents:
diff changeset
480 chunk_samples,
35c767f8fea4 initial
alex
parents:
diff changeset
481 0);
35c767f8fea4 initial
alex
parents:
diff changeset
482 file->atracks[track].current_chunk++;
35c767f8fea4 initial
alex
parents:
diff changeset
483 }
35c767f8fea4 initial
alex
parents:
diff changeset
484
35c767f8fea4 initial
alex
parents:
diff changeset
485 /* Move the last overflow to the front */
35c767f8fea4 initial
alex
parents:
diff changeset
486 overflow_start = i;
35c767f8fea4 initial
alex
parents:
diff changeset
487 input_ptr = codec->work_buffer;
35c767f8fea4 initial
alex
parents:
diff changeset
488 for(i = overflow_start * track_map->channels ;
35c767f8fea4 initial
alex
parents:
diff changeset
489 i < (samples + codec->work_overflow) * track_map->channels;
35c767f8fea4 initial
alex
parents:
diff changeset
490 i++)
35c767f8fea4 initial
alex
parents:
diff changeset
491 {
35c767f8fea4 initial
alex
parents:
diff changeset
492 *input_ptr++ = codec->work_buffer[i];
35c767f8fea4 initial
alex
parents:
diff changeset
493 }
35c767f8fea4 initial
alex
parents:
diff changeset
494 codec->work_overflow = samples + codec->work_overflow - overflow_start;
35c767f8fea4 initial
alex
parents:
diff changeset
495
35c767f8fea4 initial
alex
parents:
diff changeset
496 return result;
35c767f8fea4 initial
alex
parents:
diff changeset
497 }
35c767f8fea4 initial
alex
parents:
diff changeset
498
35c767f8fea4 initial
alex
parents:
diff changeset
499 int quicktime_flush_ima4(quicktime_t *file, int track)
35c767f8fea4 initial
alex
parents:
diff changeset
500 {
35c767f8fea4 initial
alex
parents:
diff changeset
501 quicktime_audio_map_t *track_map = &(file->atracks[track]);
35c767f8fea4 initial
alex
parents:
diff changeset
502 quicktime_ima4_codec_t *codec = ((quicktime_codec_t*)track_map->codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
503 int result = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
504 int i;
35c767f8fea4 initial
alex
parents:
diff changeset
505
35c767f8fea4 initial
alex
parents:
diff changeset
506 /*printf("quicktime_flush_ima4 %ld\n", codec->work_overflow); */
35c767f8fea4 initial
alex
parents:
diff changeset
507 if(codec->work_overflow)
35c767f8fea4 initial
alex
parents:
diff changeset
508 {
35c767f8fea4 initial
alex
parents:
diff changeset
509 /* Zero out enough to get a block */
35c767f8fea4 initial
alex
parents:
diff changeset
510 i = codec->work_overflow * track_map->channels;
35c767f8fea4 initial
alex
parents:
diff changeset
511 while(i < SAMPLES_PER_BLOCK * track_map->channels)
35c767f8fea4 initial
alex
parents:
diff changeset
512 {
35c767f8fea4 initial
alex
parents:
diff changeset
513 codec->work_buffer[i++] = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
514 }
35c767f8fea4 initial
alex
parents:
diff changeset
515 codec->work_overflow = i / track_map->channels + 1;
35c767f8fea4 initial
alex
parents:
diff changeset
516 /* Write the work_overflow only. */
35c767f8fea4 initial
alex
parents:
diff changeset
517 result = quicktime_encode_ima4(file, 0, 0, track, 0);
35c767f8fea4 initial
alex
parents:
diff changeset
518 }
35c767f8fea4 initial
alex
parents:
diff changeset
519 return result;
35c767f8fea4 initial
alex
parents:
diff changeset
520 }
35c767f8fea4 initial
alex
parents:
diff changeset
521
35c767f8fea4 initial
alex
parents:
diff changeset
522 void quicktime_init_codec_ima4(quicktime_audio_map_t *atrack)
35c767f8fea4 initial
alex
parents:
diff changeset
523 {
35c767f8fea4 initial
alex
parents:
diff changeset
524 quicktime_ima4_codec_t *codec;
35c767f8fea4 initial
alex
parents:
diff changeset
525
35c767f8fea4 initial
alex
parents:
diff changeset
526 /* Init public items */
35c767f8fea4 initial
alex
parents:
diff changeset
527 ((quicktime_codec_t*)atrack->codec)->priv = calloc(1, sizeof(quicktime_ima4_codec_t));
35c767f8fea4 initial
alex
parents:
diff changeset
528 ((quicktime_codec_t*)atrack->codec)->delete_acodec = quicktime_delete_codec_ima4;
35c767f8fea4 initial
alex
parents:
diff changeset
529 ((quicktime_codec_t*)atrack->codec)->decode_video = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
530 ((quicktime_codec_t*)atrack->codec)->encode_video = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
531 ((quicktime_codec_t*)atrack->codec)->decode_audio = quicktime_decode_ima4;
35c767f8fea4 initial
alex
parents:
diff changeset
532 ((quicktime_codec_t*)atrack->codec)->encode_audio = quicktime_encode_ima4;
35c767f8fea4 initial
alex
parents:
diff changeset
533
35c767f8fea4 initial
alex
parents:
diff changeset
534 /* Init private items */
35c767f8fea4 initial
alex
parents:
diff changeset
535 codec = ((quicktime_codec_t*)atrack->codec)->priv;
35c767f8fea4 initial
alex
parents:
diff changeset
536 codec->work_buffer = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
537 codec->read_buffer = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
538 codec->chunk = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
539 codec->buffer_channel = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
540 codec->work_overflow = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
541 codec->work_size = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
542 codec->read_size = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
543 codec->last_samples = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
544 codec->last_indexes = 0;
35c767f8fea4 initial
alex
parents:
diff changeset
545 }
35c767f8fea4 initial
alex
parents:
diff changeset
546 #endif