30class VorbisDecoder :
public AudioDecoder {
49 const char *
mime()
override {
return "audio/vorbis"; }
61 vorbis_info_init(&
vi);
62 vorbis_comment_init(&
vc);
71 vorbis_block_clear(&
vb);
72 vorbis_dsp_clear(&
vd);
73 vorbis_comment_clear(&
vc);
74 vorbis_info_clear(&
vi);
90 size_t write(
const uint8_t *data,
size_t len)
override {
92 packet.packet = (
unsigned char *)data;
96 packet.granulepos = 0;
125 if (
vi.channels > 0 &&
vi.rate > 0) {
136 operator bool()
override {
return active; }
144 vorbis_dsp_state
vd{};
166 if (vorbis_synthesis_headerin(&
vi, &
vc, &packet) != 0) {
178 if (vorbis_synthesis_init(&
vd, &
vi) != 0) {
179 LOGE(
"vorbis_synthesis_init failed");
182 vorbis_block_init(&
vd, &
vb);
192 size_t total_written = 0;
193 if (vorbis_synthesis(&
vb, &packet) == 0) {
194 vorbis_synthesis_blockin(&
vd, &
vb);
195 float **
pcm =
nullptr;
196 int samples = vorbis_synthesis_pcmout(&
vd, &
pcm);
197 while (samples > 0 &&
pcm) {
206 vorbis_synthesis_read(&
vd, chunk);
207 samples = vorbis_synthesis_pcmout(&
vd, &
pcm);
210 return total_written;
221 for (
int i = 0; i < samples; ++i) {
222 for (
int ch = 0; ch < channels; ++ch) {
223 float val =
pcm[ch][i];
224 int16_t sample = (int16_t)(val * 32767.0f);
225 if (sample > 32767) sample = 32767;
226 if (sample < -32768) sample = -32768;
#define LOGE(...)
Definition AudioLoggerIDF.h:30
virtual size_t write(const uint8_t *data, size_t len)
Definition Arduino.h:120