Skip to content

Commit 086d051

Browse files
committed
CodecALAC comments
1 parent a93af20 commit 086d051

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/AudioTools/AudioCodecs/CodecALAC.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,18 @@ class DecoderALAC : public AudioDecoder {
182182
tmp.maxFrameBytes =
183183
uncompressedFrameSize + (uncompressedFrameSize / 2) + 64 + 50;
184184

185-
convert(tmp);
185+
convertToNetworkFormat(tmp);
186186
setCodecConfig(tmp);
187187
}
188188

189+
/// Calculate the output buffer size based on the current configuration
189190
int outputBufferSize() {
190191
return dec.mConfig.frameLength * dec.mConfig.numChannels *
191192
dec.mConfig.bitDepth / 8;
192193
}
193194

194195
/// Convert to big endian so that we can use it in Init()
195-
void convert(ALACSpecificConfig& config) {
196+
void convertToNetworkFormat(ALACSpecificConfig& config) {
196197
config.frameLength = Swap32NtoB(config.frameLength);
197198
config.maxRun = Swap16NtoB((uint16_t)config.maxRun);
198199
config.maxFrameBytes = Swap32NtoB(config.maxFrameBytes);
@@ -225,7 +226,7 @@ class EncoderALAC : public AudioEncoder {
225226
input_format = getInputFormat();
226227
out_format = getOutputFormat();
227228

228-
// enc.SetFrameSize(out_format.mFramesPerPacket);
229+
// Setup Encoder
229230
enc.SetFrameSize(frame_size);
230231
int rc = enc.InitializeEncoder(out_format);
231232

@@ -259,11 +260,11 @@ class EncoderALAC : public AudioEncoder {
259260
for (int j = 0; j < len; j++) {
260261
in_buffer.write(data[j]);
261262
if (in_buffer.isFull()) {
262-
// provide max output buffer size
263+
// provide available encoded data length
263264
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(),
266266
out_buffer.data(), &ioNumBytes);
267+
// Output encoded data
267268
size_t written = p_print->write(out_buffer.data(), ioNumBytes);
268269
if (ioNumBytes != written) {
269270
LOGE("write error: %d -> %d", (int)ioNumBytes, (int)written);
@@ -274,18 +275,21 @@ class EncoderALAC : public AudioEncoder {
274275
return len;
275276
}
276277

278+
/// Provide the configuration of the encoder
277279
ALACSpecificConfig config() {
278280
enc.GetConfig(cfg);
279281
return cfg;
280282
}
281283

284+
/// Provide the magic coookie for the decoder
282285
ALACBinaryConfig& binaryConfig() {
283286
bin.setChannels(info.channels);
284287
uint32_t size = bin.size();
285288
enc.GetMagicCookie(bin.data(), &size);
286289
return bin;
287290
}
288291

292+
/// Check if the encoder is ready to encode
289293
operator bool() { return is_started && p_print != nullptr; }
290294

291295
/// Mime type: returns audio/alac
@@ -336,7 +340,7 @@ class EncoderALAC : public AudioEncoder {
336340
AudioFormatDescription result;
337341
memset(&result, 0, sizeof(AudioFormatDescription));
338342
result.mSampleRate = info.sample_rate;
339-
result.mFormatID = 'alac';
343+
result.mFormatID = kALACCodecFormat;
340344
result.mFormatFlags = getOutputFormatFlags(info.bits_per_sample); // or 0 ?
341345
result.mBytesPerPacket = 0; // Variable for compressed format
342346
result.mFramesPerPacket = frame_size; // Common ALAC frame size

0 commit comments

Comments
 (0)