15 int size = (inNumChannels > 2)
16 ?
sizeof(ALACSpecificConfig) + kChannelAtomSize +
17 sizeof(ALACAudioChannelLayout)
18 :
sizeof(ALACSpecificConfig);
64 LOGI(
"DecoderALAC::setCodecConfig: %d", (
int)len);
66 int32_t rc =
dec.Init((
void*)data, len);
71 LOGI(
"ALAC Decoder Setup - SR: %d, Channels: %d, Bits: %d, Frame Size: %d",
72 (
int)
dec.mConfig.sampleRate, (
int)
dec.mConfig.numChannels,
73 (
int)
dec.mConfig.bitDepth, (
int)
dec.mConfig.frameLength);
93 size_t write(
const uint8_t* encodedFrame,
size_t encodedLen)
override {
94 LOGD(
"DecoderALAC::write: %d", (
int)encodedLen);
105 BitBufferInit(&
bits, (uint8_t*)encodedFrame, encodedLen);
108 uint32_t outNumSamples = 0;
111 dec.mConfig.numChannels, &outNumSamples);
114 LOGE(
"Decode failed with error: %d", status);
120 outNumSamples *
dec.mConfig.numChannels *
dec.mConfig.bitDepth / 8;
121 LOGI(
"DecoderALAC::write-pcm: %d", (
int)outputSize);
124 int open = outputSize;
127 int writeSize = std::min(1024, open);
130 if (writeSize != written) {
131 LOGE(
"write error: %d -> %d", (
int)outputSize, (
int)written);
134 processed += written;
139 operator bool() {
return true; }
157 ALACSpecificConfig tmp;
160 tmp.compatibleVersion = 0;
176 uint32_t uncompressedFrameSize =
184 uncompressedFrameSize + (uncompressedFrameSize / 2) + 64 + 50;
192 return dec.mConfig.frameLength *
dec.mConfig.numChannels *
193 dec.mConfig.bitDepth / 8;
198 config.frameLength = Swap32NtoB(config.frameLength);
199 config.maxRun = Swap16NtoB((uint16_t)config.maxRun);
200 config.maxFrameBytes = Swap32NtoB(config.maxFrameBytes);
201 config.avgBitRate = Swap32NtoB(config.avgBitRate);
202 config.sampleRate = Swap32NtoB(config.sampleRate);
223 LOGE(
"No output stream set");
238 uint32_t outputBufferSize = inputBufferSize * 2;
241 "ALAC Encoder: frame_size=%d, inputBuf=%d, outputBuf=%d, channels=%d, "
258 size_t write(
const uint8_t* data,
size_t len)
override {
260 LOGD(
"EncoderALAC::write: %d", (
int)len);
261 for (
int j = 0; j < len; j++) {
270 if (ioNumBytes != written) {
271 LOGE(
"write error: %d -> %d", (
int)ioNumBytes, (
int)written);
297 const char*
mime()
override {
return "audio/alac"; }
301 enc.SetFastMode(fast);
307 LOGE(
"Can't change frame size on started encoder")
329 AudioFormatDescription result;
330 memset(&result, 0,
sizeof(AudioFormatDescription));
332 result.mFormatID = kALACFormatLinearPCM;
333 result.mFormatFlags =
334 kALACFormatFlagIsSignedInteger |
335 kALACFormatFlagIsPacked;
337 result.mFramesPerPacket = 1;
346 AudioFormatDescription result;
347 memset(&result, 0,
sizeof(AudioFormatDescription));
349 result.mFormatID = kALACCodecFormat;
351 result.mBytesPerPacket = 0;
353 result.mBytesPerFrame = 0;
379 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