I want to stream opus encoded audio data into the engine from C++. I found this class searching in the docs:
as well as the USoundWaveProcedural and UAudioComponent components:
I am not very familiar with the audio engine, or playing audio in the engine in general. I was wondering if there is a good pointer to decoding a specific audio format and playing it.
Thanks for any help!
Just in case somebody else comes across this question and wants to do it, here is the code I got working…
Apologies for not following UE4 coding standards:
// create opus header
TArray<uint8> l_header;
FMemoryWriter l_writer(l_header);
const char* OpusIdentifier = OPUS_ID_STRING;
l_writer.Serialize((void*)OpusIdentifier, FCStringAnsi::Strlen(OpusIdentifier) + 1);
uint16 l_sampleRate = 48000;
l_writer.Serialize(&l_sampleRate, sizeof(uint16));
uint32 l_trueSampleCount = 1; // don't think this matters reading OpusAudioInfo.cpp:ParseHeader?
l_writer.Serialize(&l_trueSampleCount, sizeof(uint32));
uint8 l_numChannels = 2;
l_writer.Serialize(&l_numChannels, sizeof(uint8));
uint16 l_numFrames = 1; // don't think this matters reading OpusAudioInfo.cpp:ParseHeader?
l_writer.Serialize(&l_numFrames, sizeof(uint16));
FSoundQualityInfo l_qualityInfo;
bool l_parseHeaderResult = m_opus.ParseHeader(l_header.GetData(), l_header.Num(), &l_qualityInfo);
bool l_createOpusDecoder = m_opus.CreateDecoder();
// Later on when you want to decode audio
AudioPacket l_packet = a_frame.GetData()[i];
TArray<uint8> l_data = l_packet.GetData();
TArray<uint8> l_outBuffer;
l_outBuffer.SetNum(480 * 2 * 2);
FDecodeResult l_result = m_opus.Decode(l_data.GetData(), l_data.Num(), l_outBuffer.GetData(), l_outBuffer.Num());
// Do whatever with decoded audio