13
13
#include " AudioCodecs/AudioEncoded.h"
14
14
#include " lc3.h"
15
15
16
- /* *
16
+ /* *
17
17
* @defgroup c lc3
18
18
* @ingroup codecs
19
- * @brief LC3 Codec
20
- **/
21
-
19
+ * @brief LC3 Codec
20
+ **/
22
21
23
22
namespace audio_tools {
24
23
@@ -43,12 +42,13 @@ class LC3Decoder : public AudioDecoder {
43
42
this ->input_byte_count = inputByteCount;
44
43
}
45
44
46
- LC3Decoder (int dt_us = LC3_DEFAULT_DT_US, uint16_t inputByteCount = DEFAULT_BYTE_COUNT) {
45
+ LC3Decoder (int dt_us = LC3_DEFAULT_DT_US,
46
+ uint16_t inputByteCount = DEFAULT_BYTE_COUNT) {
47
47
this ->dt_us = dt_us;
48
48
this ->input_byte_count = inputByteCount;
49
49
info.sample_rate = 32000 ;
50
50
info.bits_per_sample = 16 ;
51
- info.channels = 2 ;
51
+ info.channels = 1 ;
52
52
}
53
53
54
54
virtual AudioInfo audioInfo () { return info; }
@@ -60,6 +60,8 @@ class LC3Decoder : public AudioDecoder {
60
60
61
61
virtual void begin () {
62
62
TRACEI ();
63
+
64
+ // Return the number of PCM samples in a frame
63
65
num_frames = lc3_frame_samples (dt_us, info.sample_rate );
64
66
dec_size = lc3_decoder_size (dt_us, info.sample_rate );
65
67
@@ -71,12 +73,13 @@ class LC3Decoder : public AudioDecoder {
71
73
LOGI (" dec_size: %d" , dec_size);
72
74
73
75
if (!checkValues ()) {
76
+ LOGE (" Invalid Parameters" );
74
77
return ;
75
78
}
76
79
77
80
// setup memory
78
81
input_buffer.resize (input_byte_count);
79
- output_buffer.resize (num_frames* 2 );
82
+ output_buffer.resize (num_frames * 2 );
80
83
lc3_decoder_memory.resize (dec_size);
81
84
82
85
// setup decoder
@@ -133,8 +136,6 @@ class LC3Decoder : public AudioDecoder {
133
136
134
137
protected:
135
138
Print *p_print = nullptr ;
136
- AudioInfo info;
137
- AudioInfoDependent *p_notify = nullptr ;
138
139
lc3_decoder_t lc3_decoder = nullptr ;
139
140
lc3_pcm_format pcm_format;
140
141
Vector<uint8_t > lc3_decoder_memory;
@@ -163,6 +164,10 @@ class LC3Decoder : public AudioDecoder {
163
164
return false ;
164
165
}
165
166
167
+ if (info.channels !=1 ){
168
+ LOGE (" channels: %d" , info.channels );
169
+ }
170
+
166
171
if (num_frames == -1 ) {
167
172
LOGE (" num_frames could not be determined - using m" );
168
173
return false ;
@@ -197,11 +202,12 @@ class LC3Decoder : public AudioDecoder {
197
202
*/
198
203
class LC3Encoder : public AudioEncoder {
199
204
public:
200
- LC3Encoder (int dt_us = LC3_DEFAULT_DT_US, uint16_t outputByteCount = DEFAULT_BYTE_COUNT) {
205
+ LC3Encoder (int dt_us = LC3_DEFAULT_DT_US,
206
+ uint16_t outputByteCount = DEFAULT_BYTE_COUNT) {
201
207
this ->dt_us = dt_us;
202
208
info.sample_rate = 32000 ;
203
209
info.bits_per_sample = 16 ;
204
- info.channels = 2 ;
210
+ info.channels = 1 ;
205
211
output_byte_count = outputByteCount;
206
212
}
207
213
@@ -212,6 +218,7 @@ class LC3Encoder : public AudioEncoder {
212
218
213
219
void begin () {
214
220
TRACEI ();
221
+
215
222
unsigned enc_size = lc3_encoder_size (dt_us, info.sample_rate );
216
223
num_frames = lc3_frame_samples (dt_us, info.sample_rate );
217
224
@@ -232,8 +239,8 @@ class LC3Encoder : public AudioEncoder {
232
239
output_buffer.resize (output_byte_count);
233
240
234
241
// setup encoder
235
- lc3_encoder =
236
- lc3_setup_encoder (dt_us, info. sample_rate , 0 , lc3_encoder_memory.data ());
242
+ lc3_encoder = lc3_setup_encoder (dt_us, info. sample_rate , 0 ,
243
+ lc3_encoder_memory.data ());
237
244
238
245
input_pos = 0 ;
239
246
active = true ;
@@ -260,8 +267,9 @@ class LC3Encoder : public AudioEncoder {
260
267
for (int j = 0 ; j < in_size; j++) {
261
268
input_buffer[input_pos++] = p_ptr8[j];
262
269
if (input_pos >= num_frames * 2 ) {
263
- if (lc3_encode (lc3_encoder, pcm_format, (const int16_t *)input_buffer.data (),
264
- 1 , output_buffer.size (), output_buffer.data ()) != 0 ) {
270
+ if (lc3_encode (lc3_encoder, pcm_format,
271
+ (const int16_t *)input_buffer.data (), 1 ,
272
+ output_buffer.size (), output_buffer.data ()) != 0 ) {
265
273
LOGE (" lc3_encode" );
266
274
}
267
275
@@ -307,6 +315,10 @@ class LC3Encoder : public AudioEncoder {
307
315
return false ;
308
316
}
309
317
318
+ if (info.channels !=1 ){
319
+ LOGE (" channels: %d" , info.channels );
320
+ }
321
+
310
322
if (num_frames == -1 ) {
311
323
LOGE (" Invalid num_frames" );
312
324
return false ;
0 commit comments