FaceAccess/Record/FFmpegResample.h

32 lines
785 B
C
Raw Normal View History

2024-06-18 14:27:48 +08:00
#ifndef __FFMPEGRESAMPLE_H__
#define __FFMPEGRESAMPLE_H__
#include <array>
#include <cstdint>
#include <fstream>
struct SwrContext;
class FFmpegResample {
public:
class Frame {
public:
uint8_t *data = nullptr;
int32_t byteSize = 0;
};
~FFmpegResample();
void initialize(int32_t sampleRateIn, int32_t channelIn, int32_t sampleRateOut, int32_t channelOut,int32_t period);
Frame resample(const uint8_t *pcm, int32_t size);
private:
SwrContext *m_swrContext = nullptr;
uint8_t *m_buffer;
std::array<uint8_t, 48 * 20 * 2 * 2> buffer;
int32_t m_sampleRateOut = 48000;
int32_t m_channelOut = 2;
int32_t m_sampleRateIn = 16000;
int32_t m_channelIn = 1;
int32_t m_period = 20; // ms
};
#endif // __FFMPEGRESAMPLE_H__