@@ -42,12 +42,20 @@ class DecoderALAC : public AudioDecoder {
4242 }
4343
4444 // / we expect the write is called for a complete frame!
45- size_t write (const uint8_t * encodedFrame, size_t frameLength ) override {
46- LOGI (" write: %d" , (int )frameLength );
45+ size_t write (const uint8_t * encodedFrame, size_t len ) override {
46+ LOGI (" DecoderALAC:: write: %d" , (int )len );
4747 if (!is_init) {
4848 ALACSpecificConfig config = {};
49+ int frame_size = info.bits_per_sample / 8 * info.channels ;
4950 AudioInfo info = audioInfo ();
50- config.frameLength = frameLength;
51+ config.frameLength = len / frame_size; // frames per packet
52+ config.compatibleVersion = 0 ;
53+ config.pb = 40 ;
54+ config.mb = 10 ;
55+ config.kb = 14 ;
56+ config.maxRun = 255 ;
57+ config.maxFrameBytes = len;
58+ config.avgBitRate = 0 ; // not known
5159 config.bitDepth = info.bits_per_sample ;
5260 config.numChannels = info.channels ;
5361 config.sampleRate = info.sample_rate ;
@@ -61,7 +69,7 @@ class DecoderALAC : public AudioDecoder {
6169
6270 // Init bit buffer
6371 struct BitBuffer bits;
64- BitBufferInit (&bits, (uint8_t *)encodedFrame, frameLength);
72+ BitBufferInit (&bits, (uint8_t *)encodedFrame, dec. mConfig . frameLength );
6573
6674 // Decode
6775 uint32_t outNumSamples = 0 ;
@@ -81,7 +89,7 @@ class DecoderALAC : public AudioDecoder {
8189 if (outputSize != written) {
8290 LOGE (" write error: %d -> %d" , outputSize, written);
8391 }
84- return frameLength ;
92+ return len ;
8593 }
8694
8795 operator bool () { return true ; }
@@ -145,12 +153,12 @@ class EncoderALAC : public AudioEncoder {
145153
146154 // / Encode the audio samples into ALAC format
147155 size_t write (const uint8_t * data, size_t len) override {
148- LOGI (" write: %d" , (int )len);
149- int32_t ioNumBytes = len;
156+ LOGI (" EncoderALAC::write: %d" , (int )len);
150157 for (int j = 0 ; j < len; j++) {
151158 in_buffer.write (data[j]);
152159 if (in_buffer.isFull ()) {
153- int rc = enc.Encode (input_format, out_format, (uint8_t *)data,
160+ int32_t ioNumBytes = in_buffer.available ();
161+ int rc = enc.Encode (input_format, out_format, (uint8_t *)in_buffer.data (),
154162 out_buffer.data (), &ioNumBytes);
155163 size_t written = p_print->write (out_buffer.data (), ioNumBytes);
156164 if (ioNumBytes != written) {
0 commit comments