3 #include "AudioTools/AudioCodecs/CodecOpus.h"
4 #include "AudioTools/AudioCodecs/ContainerOgg.h"
10 char signature[8] = {
'O',
'p',
'u',
's',
'H',
'e',
'a',
'd'};
12 uint8_t channelCount = 0;
13 uint16_t preSkip = 3840;
14 uint32_t sampleRate = 0;
15 int16_t outputGain = 0;
16 uint8_t channelMappingFamily = 0;
21 char signature[8] = {
'O',
'p',
'u',
's',
'T',
'a',
'g',
's'};
22 uint32_t vendorStringLength = 8;
23 char vendor[8] =
"Arduino";
24 uint32_t userCommentListLength = 0;
42 out.setDecoder(p_codec);
50 OggContainerDecoder::begin();
51 return dec.begin(settings);
54 bool begin()
override {
56 OggContainerDecoder::begin();
62 OggContainerDecoder::end();
70 virtual void beginOfSegment(ogg_packet *op)
override {
72 if (op->packet ==
nullptr)
return;
73 if (strncmp(
"OpusHead", (
char *)op->packet, 8) == 0) {
74 memmove(&header, (
char *)op->packet,
sizeof(header));
76 info.sample_rate = header.sampleRate;
77 info.channels = header.channelCount;
78 info.bits_per_sample = 16;
81 }
else if (strncmp(
"OpusTags", (
char *)op->packet, 8) == 0) {
91 OpusOggCommentHeader comment;
94 bool writeHeader()
override {
100 oh.packet = (uint8_t *)&header;
101 oh.bytes =
sizeof(header);
103 oh.packetno = packetno++;
106 if (!writePacket(oh)) {
108 LOGE(
"writePacket-header");
112 oh1.packet = (uint8_t *)&comment;
113 oh1.bytes =
sizeof(comment);
115 oh1.packetno = packetno++;
118 if (!writePacket(oh1, OGGZ_FLUSH_AFTER)) {
120 LOGE(
"writePacket-header1");
145 const char *
mime()
override {
return "audio/ogg;codecs=opus"; }