8#include "codec-shine.h"
52 operator bool()
override {
return _shine !=
nullptr &&
_out !=
nullptr; }
55 if (!
_out)
return false;
58 LOGE(
"Unsupported bits per sample: %d. Only 16 is supported.",
64 LOGE(
"Unsupported number of channels: %d. Only 1 or 2 are supported.",
77 "Input is mono but Shine encoder is configured for stereo. "
78 "Forcing mono mode.");
85 "Failed to initialize Shine encoder with sample rate %d, channels "
91 "Shine encoder initialized with sample rate %d, channels %d, bitrate "
95 int samples_per_pass = shine_samples_per_pass(
_shine);
96 int buffer_size_bytes = samples_per_pass *
info.
channels *
sizeof(int16_t);
98 LOGE(
"Failed to resize PCM buffer to %d bytes", buffer_size_bytes);
117 size_t write(
const uint8_t* data,
size_t len)
override {
120 for (
int j = 0; j < len; j++) {
143 const char*
mime()
override {
return "audio/mpeg"; }
153 if (
_shine ==
nullptr ||
_out ==
nullptr)
return;
160 uint8_t* data = shine_flush(
_shine, &written);
161 if (written > 0 && data) {
175 uint8_t* mp3 = shine_encode_buffer_interleaved(
189 if (sr <= 12000)
return 32;
190 if (sr <= 22050)
return 64;
191 if (sr <= 32000)
return 128;
195 if (sr <= 12000 && req > 64)
return 64;
196 if (sr <= 22050 && req > 128)
return 128;
197 if (sr <= 32000 && req > 256)
return 256;
199 if (req > 320)
return 320;
202 const int table[] = {32, 40, 48, 56, 64, 80, 96,
203 112, 128, 160, 192, 224, 256, 320};
206 for (
int i = 0; i < 14; i++) {
207 if (req <= table[i]) {
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30