37 namespace discord_core_internal {
46 jsonifier::string_view_base<uint8_t>
data{};
58 opus_encoder_destroy(other);
70 auto result = opus_encoder_ctl(
ptr.get(), OPUS_SET_SIGNAL(OPUS_SIGNAL_MUSIC));
71 if (result != OPUS_OK) {
72 throw dca_exception{
"Failed to set the opus signal type, reason: " + jsonifier::string{ opus_strerror(result) } };
76 result = opus_encoder_ctl(
ptr.get(), OPUS_SET_BITRATE(OPUS_BITRATE_MAX));
77 if (result != OPUS_OK) {
78 throw dca_exception{
"Failed to set the opus bitrate, reason: " + jsonifier::string{ opus_strerror(result) } };
86 DCA_INLINE encoder_return_data
encodeData(jsonifier::string_view_base<uint8_t> inputFrame) {
87 if (inputFrame.size() == 0) {
97 std::memcpy(
resampleVector.data(), inputFrame.data(), inputFrame.size());
98 uint64_t sampleCount = inputFrame.size() / 2 / 2;
101 throw dca_exception{
"Failed to encode the bitstream, reason: " + jsonifier::string{ opus_strerror(count) } };
104 encoder_return_data returnData{};
105 returnData.sampleCount = sampleCount;
111 unique_ptr<OpusEncoder, opus_encoder_deleter>
ptr{};
The main namespace for the forward-facing interfaces.
Structure to hold the encoded data and sample count returned by the encoder.
jsonifier::string_view_base< uint8_t > data
Encoded data.
uint64_t sampleCount
Number of audio samples in the input frame.
Deleter for OpusEncoder instances.
DCA_INLINE void operator()(OpusEncoder *other)
Operator to destroy an OpusEncoder instance.
Wrapper class for the opus audio encoder.
unique_ptr< OpusEncoder, opus_encoder_deleter > ptr
Unique pointer to OpusEncoder instance.
jsonifier::vector< opus_int16 > resampleVector
For properly copying the values without type-punning.
static constexpr uint64_t maxBufferSize
Maximum size of the encoded data buffer.
static constexpr int64_t sampleRate
Sample rate of the audio data.
DCA_INLINE opus_encoder_wrapper()
Constructor for opus_encoder_wrapper. initializes and configures the opus encoder.
static constexpr int64_t nChannels
Number of audio channels.
jsonifier::string_base< uint8_t > encodedData
Buffer for encoded audio data.
DCA_INLINE encoder_return_data encodeData(jsonifier::string_view_base< uint8_t > inputFrame)
Encode opus audio data.