update cspot

This commit is contained in:
philippe44
2022-11-17 14:06:00 -08:00
parent a81d0e0513
commit 7e5f27af12
137 changed files with 6046 additions and 836 deletions

View File

@@ -0,0 +1,19 @@
// Copyright (c) Kuba Szczodrzyński 2022-1-12.
#pragma once
#include "BaseCodec.h"
#include "aacdec.h"
class AACDecoder : public BaseCodec {
private:
HAACDecoder aac;
int16_t *pcmData;
AACFrameInfo frame = {};
public:
AACDecoder();
~AACDecoder();
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;
};

View File

@@ -0,0 +1,18 @@
// Copyright (c) Kuba Szczodrzyński 2022-1-12.
#pragma once
#include "BaseCodec.h"
#include "alac_wrapper.h"
class ALACDecoder : public BaseCodec {
private:
alac_codec_s* alacCodec;
int16_t *pcmData;
public:
ALACDecoder();
~ALACDecoder();
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;
};

View File

@@ -0,0 +1,23 @@
// Copyright (c) Kuba Szczodrzyński 2022-1-12.
#pragma once
#include "BaseCodec.h"
#include "BaseContainer.h"
#include <memory>
enum class AudioCodec {
UNKNOWN = 0,
AAC = 1,
MP3 = 2,
VORBIS = 3,
OPUS = 4,
FLAC = 5,
};
class AudioCodecs {
public:
static std::shared_ptr<BaseCodec> getCodec(AudioCodec type);
static std::shared_ptr<BaseCodec> getCodec(BaseContainer *container);
static void addCodec(AudioCodec type, const std::shared_ptr<BaseCodec> &codec);
};

View File

@@ -0,0 +1,39 @@
// Copyright (c) Kuba Szczodrzyński 2022-1-12.
#pragma once
#include "BaseContainer.h"
class BaseCodec {
public:
/**
* Setup the codec (sample rate, channel count, etc) using the specified container.
*/
virtual bool setup(BaseContainer *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(BaseContainer *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;
};

View File

@@ -0,0 +1,52 @@
#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>
#include <stdlib.h>
#include <memory>
#include "aacdec.h"
#include "mp3dec.h"
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();
}
#endif
#endif

View File

@@ -0,0 +1,19 @@
// Copyright (c) Kuba Szczodrzyński 2022-1-14.
#pragma once
#include "BaseCodec.h"
#include "mp3dec.h"
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;
uint8_t *decode(uint8_t *inData, uint32_t inLen, uint32_t &outLen) override;
};

View File

@@ -0,0 +1,19 @@
// Copyright (c) Kuba Szczodrzyński 2022-1-14.
#pragma once
#include "BaseCodec.h"
struct OpusDecoder;
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;
};

View File

@@ -0,0 +1,25 @@
// Copyright (c) Kuba Szczodrzyński 2022-1-14.
#pragma once
#include "BaseCodec.h"
#include "ivorbiscodec.h"
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(BaseContainer *container) override;
private:
void setPacket(uint8_t *inData, uint32_t inLen) const;
};