37 namespace discord_core_internal {
53 opus_decoder_destroy(other);
64 if (
data.size() < 23040) {
69 ptr.reset(opus_decoder_create(48000, 2, &error));
72 if (error != OPUS_OK) {
73 throw dca_exception{
"Failed to create the opus decoder, reason: " + jsonifier::string{ opus_strerror(error) } };
81 DCA_INLINE jsonifier::string_view_base<opus_int16>
decodeData(jsonifier::string_view_base<uint8_t> dataToDecode) {
82 const int32_t sampleCount = opus_decode(
ptr.get(), dataToDecode.data(),
static_cast<opus_int32
>(dataToDecode.size() & 0x7FFFFFFF),
data.data(), 5760, 0);
85 if (sampleCount > 0) {
86 return jsonifier::string_view_base<opus_int16>{
data.data(),
static_cast<uint64_t
>(sampleCount) * 2ULL };
88 throw dca_exception{
"Failed to decode a user's voice payload, reason: " + jsonifier::string{ opus_strerror(sampleCount) } };
93 unique_ptr<OpusDecoder, opus_decoder_deleter>
ptr{};
94 jsonifier::vector<opus_int16>
data{};
The main namespace for the forward-facing interfaces.
Deleter foropus_decoder instances.
DCA_INLINE void operator()(OpusDecoder *other)
Operator to destroy an OpusDecoder instance.
A wrapper class for the opus audio decoder.
jsonifier::vector< opus_int16 > data
Buffer for decoded audio samples.
DCA_INLINE jsonifier::string_view_base< opus_int16 > decodeData(jsonifier::string_view_base< uint8_t > dataToDecode)
Decode opus audio data.
unique_ptr< OpusDecoder, opus_decoder_deleter > ptr
Unique pointer to OpusDecoder instance.
DCA_INLINE opus_decoder_wrapper()
Constructor for opus_decoder_wrapper. initializes and configures the opus decoder.