15 int size = (inNumChannels > 2)
16 ?
sizeof(ALACSpecificConfig) + kChannelAtomSize +
17 sizeof(ALACAudioChannelLayout)
18 :
sizeof(ALACSpecificConfig);
50 const char*
mime()
override {
return "audio/alac"; }
66 LOGI(
"DecoderALAC::setCodecConfig: %d", (
int)len);
68 int32_t rc =
dec.Init((
void*)data, len);
73 LOGI(
"ALAC Decoder Setup - SR: %d, Channels: %d, Bits: %d, Frame Size: %d",
74 (
int)
dec.mConfig.sampleRate, (
int)
dec.mConfig.numChannels,
75 (
int)
dec.mConfig.bitDepth, (
int)
dec.mConfig.frameLength);
95 size_t write(
const uint8_t* encodedFrame,
size_t encodedLen)
override {
96 LOGD(
"DecoderALAC::write: %d", (
int)encodedLen);
107 BitBufferInit(&
bits, (uint8_t*)encodedFrame, encodedLen);
110 uint32_t outNumSamples = 0;
113 dec.mConfig.numChannels, &outNumSamples);
116 LOGE(
"Decode failed with error: %d", status);
122 outNumSamples *
dec.mConfig.numChannels *
dec.mConfig.bitDepth / 8;
123 LOGI(
"DecoderALAC::write-pcm: %d", (
int)outputSize);
126 int open = outputSize;
129 int writeSize = std::min(1024, open);
132 if (writeSize != written) {
133 LOGE(
"write error: %d -> %d", (
int)outputSize, (
int)written);
136 processed += written;
141 operator bool() {
return true; }
159 ALACSpecificConfig tmp;
162 tmp.compatibleVersion = 0;
178 uint32_t uncompressedFrameSize =
186 uncompressedFrameSize + (uncompressedFrameSize / 2) + 64 + 50;
194 return dec.mConfig.frameLength *
dec.mConfig.numChannels *
195 dec.mConfig.bitDepth / 8;
200 config.frameLength = Swap32NtoB(config.frameLength);
201 config.maxRun = Swap16NtoB((uint16_t)config.maxRun);
202 config.maxFrameBytes = Swap32NtoB(config.maxFrameBytes);
203 config.avgBitRate = Swap32NtoB(config.avgBitRate);
204 config.sampleRate = Swap32NtoB(config.sampleRate);
225 LOGE(
"No output stream set");
240 uint32_t outputBufferSize = inputBufferSize * 2;
243 "ALAC Encoder: frame_size=%d, inputBuf=%d, outputBuf=%d, channels=%d, "
260 size_t write(
const uint8_t* data,
size_t len)
override {
262 LOGD(
"EncoderALAC::write: %d", (
int)len);
263 for (
int j = 0; j < len; j++) {
272 if (ioNumBytes != written) {
273 LOGE(
"write error: %d -> %d", (
int)ioNumBytes, (
int)written);
299 const char*
mime()
override {
return "audio/alac"; }
303 enc.SetFastMode(fast);
309 LOGE(
"Can't change frame size on started encoder")
331 AudioFormatDescription result;
332 memset(&result, 0,
sizeof(AudioFormatDescription));
334 result.mFormatID = kALACFormatLinearPCM;
335 result.mFormatFlags =
336 kALACFormatFlagIsSignedInteger |
337 kALACFormatFlagIsPacked;
339 result.mFramesPerPacket = 1;
348 AudioFormatDescription result;
349 memset(&result, 0,
sizeof(AudioFormatDescription));
351 result.mFormatID = kALACCodecFormat;
353 result.mBytesPerPacket = 0;
355 result.mBytesPerFrame = 0;
381 LOGE(
"Unsupported bit depth: %d", bits);
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
virtual size_t write(const uint8_t *data, size_t len)
Definition Arduino.h:120