@@ -42,12 +42,20 @@ class DecoderALAC : public AudioDecoder {
42
42
}
43
43
44
44
// / 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 );
47
47
if (!is_init) {
48
48
ALACSpecificConfig config = {};
49
+ int frame_size = info.bits_per_sample / 8 * info.channels ;
49
50
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
51
59
config.bitDepth = info.bits_per_sample ;
52
60
config.numChannels = info.channels ;
53
61
config.sampleRate = info.sample_rate ;
@@ -61,7 +69,7 @@ class DecoderALAC : public AudioDecoder {
61
69
62
70
// Init bit buffer
63
71
struct BitBuffer bits;
64
- BitBufferInit (&bits, (uint8_t *)encodedFrame, frameLength);
72
+ BitBufferInit (&bits, (uint8_t *)encodedFrame, dec. mConfig . frameLength );
65
73
66
74
// Decode
67
75
uint32_t outNumSamples = 0 ;
@@ -81,7 +89,7 @@ class DecoderALAC : public AudioDecoder {
81
89
if (outputSize != written) {
82
90
LOGE (" write error: %d -> %d" , outputSize, written);
83
91
}
84
- return frameLength ;
92
+ return len ;
85
93
}
86
94
87
95
operator bool () { return true ; }
@@ -145,12 +153,12 @@ class EncoderALAC : public AudioEncoder {
145
153
146
154
// / Encode the audio samples into ALAC format
147
155
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);
150
157
for (int j = 0 ; j < len; j++) {
151
158
in_buffer.write (data[j]);
152
159
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 (),
154
162
out_buffer.data (), &ioNumBytes);
155
163
size_t written = p_print->write (out_buffer.data (), ioNumBytes);
156
164
if (ioNumBytes != written) {
0 commit comments