FaceAccess/Record/OpusCodec.h
2024-06-18 14:27:48 +08:00

39 lines
766 B
C++

#ifndef __OPUSENCODER_H__
#define __OPUSENCODER_H__
#include "opus/opus.h"
#include <string>
#include <vector>
namespace Opus {
class Packet {
public:
uint8_t *data = nullptr;
uint32_t byteSize = 0;
};
class Encoder {
public:
~Encoder();
bool open(int32_t samplerate, int32_t channels, uint32_t sampleSize);
void close();
const Packet encode(const int16_t *pcm, int32_t framesize);
private:
OpusEncoder *m_encoder = nullptr;
std::vector<uint8_t> m_buffer;
};
class Decoder {
public:
bool open(int32_t samplerate, int32_t channels);
int32_t decode(const uint8_t *data, int32_t dataSize, int16_t *pcm, int32_t pcmBuffer);
private:
OpusDecoder *m_decoder = nullptr;
};
} // namespace Opus
#endif // __OPUSENCODER_H__