@@ -182,17 +182,18 @@ class DecoderALAC : public AudioDecoder {
182
182
tmp.maxFrameBytes =
183
183
uncompressedFrameSize + (uncompressedFrameSize / 2 ) + 64 + 50 ;
184
184
185
- convert (tmp);
185
+ convertToNetworkFormat (tmp);
186
186
setCodecConfig (tmp);
187
187
}
188
188
189
+ // / Calculate the output buffer size based on the current configuration
189
190
int outputBufferSize () {
190
191
return dec.mConfig .frameLength * dec.mConfig .numChannels *
191
192
dec.mConfig .bitDepth / 8 ;
192
193
}
193
194
194
195
// / Convert to big endian so that we can use it in Init()
195
- void convert (ALACSpecificConfig& config) {
196
+ void convertToNetworkFormat (ALACSpecificConfig& config) {
196
197
config.frameLength = Swap32NtoB (config.frameLength );
197
198
config.maxRun = Swap16NtoB ((uint16_t )config.maxRun );
198
199
config.maxFrameBytes = Swap32NtoB (config.maxFrameBytes );
@@ -225,7 +226,7 @@ class EncoderALAC : public AudioEncoder {
225
226
input_format = getInputFormat ();
226
227
out_format = getOutputFormat ();
227
228
228
- // enc.SetFrameSize(out_format.mFramesPerPacket);
229
+ // Setup Encoder
229
230
enc.SetFrameSize (frame_size);
230
231
int rc = enc.InitializeEncoder (out_format);
231
232
@@ -259,11 +260,11 @@ class EncoderALAC : public AudioEncoder {
259
260
for (int j = 0 ; j < len; j++) {
260
261
in_buffer.write (data[j]);
261
262
if (in_buffer.isFull ()) {
262
- // provide max output buffer size
263
+ // provide available encoded data length
263
264
int32_t ioNumBytes = in_buffer.size ();
264
- int rc =
265
- enc.Encode (input_format, out_format, (uint8_t *)in_buffer.data (),
265
+ int rc = enc.Encode (input_format, out_format, (uint8_t *)in_buffer.data (),
266
266
out_buffer.data (), &ioNumBytes);
267
+ // Output encoded data
267
268
size_t written = p_print->write (out_buffer.data (), ioNumBytes);
268
269
if (ioNumBytes != written) {
269
270
LOGE (" write error: %d -> %d" , (int )ioNumBytes, (int )written);
@@ -274,18 +275,21 @@ class EncoderALAC : public AudioEncoder {
274
275
return len;
275
276
}
276
277
278
+ // / Provide the configuration of the encoder
277
279
ALACSpecificConfig config () {
278
280
enc.GetConfig (cfg);
279
281
return cfg;
280
282
}
281
283
284
+ // / Provide the magic coookie for the decoder
282
285
ALACBinaryConfig& binaryConfig () {
283
286
bin.setChannels (info.channels );
284
287
uint32_t size = bin.size ();
285
288
enc.GetMagicCookie (bin.data (), &size);
286
289
return bin;
287
290
}
288
291
292
+ // / Check if the encoder is ready to encode
289
293
operator bool () { return is_started && p_print != nullptr ; }
290
294
291
295
// / Mime type: returns audio/alac
@@ -336,7 +340,7 @@ class EncoderALAC : public AudioEncoder {
336
340
AudioFormatDescription result;
337
341
memset (&result, 0 , sizeof (AudioFormatDescription));
338
342
result.mSampleRate = info.sample_rate ;
339
- result.mFormatID = ' alac ' ;
343
+ result.mFormatID = kALACCodecFormat ;
340
344
result.mFormatFlags = getOutputFormatFlags (info.bits_per_sample ); // or 0 ?
341
345
result.mBytesPerPacket = 0 ; // Variable for compressed format
342
346
result.mFramesPerPacket = frame_size; // Common ALAC frame size
0 commit comments