Files
faumaray cf48f2f350 New arch
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-11 15:06:50 +03:00

43 lines
1.1 KiB
C++

#pragma once
// Converts Echoion's internal PCM (192 kHz stereo S16, delivered in 20 ms
// chunks) into TeamSpeak-ready Opus frames: resample to 48 kHz stereo, then
// Opus-encode in exact 20 ms (960 samples/ch) frames. A small PCM ring absorbs
// the resampler's priming latency so every emitted frame is exactly 960/ch.
#include <cstdint>
#include <span>
#include <vector>
struct SwrContext;
struct OpusEncoder;
namespace Echoion::Standalone
{
class AudioEncoder
{
public:
// inRate defaults to Echoion's 192 kHz internal pipeline.
explicit AudioEncoder(int bitrate = 96000, int inRate = 192000);
~AudioEncoder();
AudioEncoder(const AudioEncoder&) = delete;
AudioEncoder& operator=(const AudioEncoder&) = delete;
// Feed one chunk of interleaved stereo S16 at inRate. Returns zero or
// more complete Opus frames (each a 20 ms packet).
std::vector<std::vector<uint8_t>>
encode(std::span<const short> interleaved);
private:
SwrContext* swr_ = nullptr;
OpusEncoder* enc_ = nullptr;
int inRate_ = 192000;
std::vector<short> pcm_; // resampled 48 kHz interleaved stereo
};
} // namespace Echoion::Standalone