applied platformio structure

This commit is contained in:
2026-03-13 17:03:22 +00:00
parent c5233cf15c
commit db7d90e736
3510 changed files with 691878 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#pragma once
#include <stdint.h> // for uint8_t, uint32_t, int16_t
#include <vector>
#include "BaseCodec.h" // for BaseCodec
#include "pvmp4audiodecoder_api.h" // for tPVMP4AudioDecoderExternal
namespace bell {
class AudioContainer;
class AACDecoder : public BaseCodec {
private:
tPVMP4AudioDecoderExternal* aacDecoder;
std::vector<uint8_t> inputBuffer;
std::vector<int16_t> outputBuffer;
void* pMem;
bool firstFrame = true;
int getDecodedStreamType();
public:
AACDecoder();
~AACDecoder();
bool setup(uint32_t sampleRate, uint8_t channelCount,
uint8_t bitDepth) override;
bool setup(AudioContainer* container) override;
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
};
} // namespace bell

View File

@@ -0,0 +1,17 @@
#pragma once
#include <memory> // for shared_ptr
#include "AudioContainer.h" // for AudioContainer
#include "BaseCodec.h" // for BaseCodec
#include "CodecType.h" // for AudioCodec
namespace bell {
class AudioCodecs {
public:
static std::shared_ptr<BaseCodec> getCodec(AudioCodec type);
static std::shared_ptr<BaseCodec> getCodec(AudioContainer* container);
static void addCodec(AudioCodec type,
const std::shared_ptr<BaseCodec>& codec);
};
} // namespace bell

View File

@@ -0,0 +1,50 @@
#pragma once
#include <stdint.h> // for uint32_t, uint8_t
namespace bell {
class AudioContainer;
class BaseCodec {
private:
uint32_t lastSampleLen, availableBytes;
public:
uint32_t sampleRate = 44100;
uint8_t channelCount = 2;
uint8_t bitDepth = 16;
/**
* Setup the codec (sample rate, channel count, etc) using the specified container.
*/
virtual bool setup(AudioContainer* container);
/**
* Setup the codec manually, using the provided values.
*/
virtual bool setup(uint32_t sampleRate, uint8_t channelCount,
uint8_t bitDepth) = 0;
/**
* Decode the given sample.
*
* @param [in] inData encoded data. Should allow nullptr, in which case nullptr should be returned.
* @param [in] inLen size of inData, in bytes
* @param [out] outLen size of output PCM data, in bytes
* @return pointer to decoded raw PCM audio data, allocated inside the codec object; nullptr on failure
*/
virtual uint8_t* decode(uint8_t* inData, uint32_t& inLen,
uint32_t& outLen) = 0;
/**
* Read a single sample from the container, decode it, and return the result.
*
* @param [in] container media container to read the sample from (the container's codec must match this instance)
* @param [out] outLen size of output PCM data, in bytes
* @return pointer to decoded raw PCM audio data, allocated inside the codec object; nullptr on failure
*/
uint8_t* decode(AudioContainer* container, uint32_t& outLen);
/**
* Last error that occurred, this is a codec-specific value.
* This may be set by a codec upon decoding failure.
*/
int lastErrno = -1;
};
} // namespace bell

View File

@@ -0,0 +1,13 @@
#pragma once
namespace bell {
enum class AudioCodec {
UNKNOWN = 0,
AAC = 1,
MP3 = 2,
VORBIS = 3,
OPUS = 4,
FLAC = 5,
};
}

View File

@@ -0,0 +1,44 @@
#ifndef BELL_DISABLE_CODECS
#ifndef DECODER_GLOBALS_H
#define DECODER_GLOBALS_H
#define AAC_READBUF_SIZE (4 * AAC_MAINBUF_SIZE * AAC_MAX_NCHANS)
#define MP3_READBUF_SIZE (2 * 1024);
#include <stdio.h> // for NULL
// #include "aacdec.h" // for AACFreeDecoder, AACInitDecoder, HAACDecoder
#include "mp3dec.h" // for MP3FreeDecoder, MP3InitDecoder, HMP3Decoder
namespace bell {
class DecodersInstance {
public:
DecodersInstance(){};
~DecodersInstance() {
MP3FreeDecoder(mp3Decoder);
// AACFreeDecoder(aacDecoder);
};
// HAACDecoder aacDecoder = NULL;
HMP3Decoder mp3Decoder = NULL;
void ensureAAC() {
// if (aacDecoder == NULL) {
// aacDecoder = AACInitDecoder();
// }
}
void ensureMP3() {
if (mp3Decoder == NULL) {
mp3Decoder = MP3InitDecoder();
}
}
};
extern bell::DecodersInstance* decodersInstance;
void createDecoders();
} // namespace bell
#endif
#endif

View File

@@ -0,0 +1,26 @@
#pragma once
#include <stdint.h> // for uint8_t, uint32_t, int16_t
#include "BaseCodec.h" // for BaseCodec
#include "mp3dec.h" // for HMP3Decoder, MP3FrameInfo
namespace bell {
class AudioContainer;
class MP3Decoder : public BaseCodec {
private:
HMP3Decoder mp3;
int16_t* pcmData;
MP3FrameInfo frame = {};
public:
MP3Decoder();
~MP3Decoder();
bool setup(uint32_t sampleRate, uint8_t channelCount,
uint8_t bitDepth) override;
bool setup(AudioContainer* container) override;
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
};
} // namespace bell

View File

@@ -0,0 +1,22 @@
#pragma once
#include <stdint.h> // for uint8_t, uint32_t, int16_t
#include "BaseCodec.h" // for BaseCodec
struct OpusDecoder;
namespace bell {
class OPUSDecoder : public BaseCodec {
private:
OpusDecoder* opus;
int16_t* pcmData;
public:
OPUSDecoder();
~OPUSDecoder();
bool setup(uint32_t sampleRate, uint8_t channelCount,
uint8_t bitDepth) override;
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
};
} // namespace bell

View File

@@ -0,0 +1,31 @@
#pragma once
#include <stdint.h> // for uint8_t, uint32_t, int16_t
#include "BaseCodec.h" // for BaseCodec
#include "ivorbiscodec.h" // for vorbis_comment, vorbis_dsp_state, vorbis_info
#include "ogg.h" // for ogg_packet
namespace bell {
class AudioContainer;
class VorbisDecoder : public BaseCodec {
private:
vorbis_info* vi = nullptr;
vorbis_comment* vc = nullptr;
vorbis_dsp_state* vd = nullptr;
ogg_packet op = {};
int16_t* pcmData;
public:
VorbisDecoder();
~VorbisDecoder();
bool setup(uint32_t sampleRate, uint8_t channelCount,
uint8_t bitDepth) override;
uint8_t* decode(uint8_t* inData, uint32_t& inLen, uint32_t& outLen) override;
bool setup(AudioContainer* container) override;
private:
void setPacket(uint8_t* inData, uint32_t inLen) const;
};
} // namespace bell