gtreshchev / RuntimeAudioImporter

Runtime Audio Importer plugin for Unreal Engine. Importing audio of various formats at runtime.
MIT License
308 stars 67 forks source link

Convert TArray<float> to other format #50

Closed imloama closed 10 months ago

imloama commented 10 months ago

Hi, i need some help. listen on OnPopulateAudioData callback, and got TArray format data, the default parameters is "Number of channels: 2, sample rate: 48000", I'm working with a SDK, it wants sample rate is Int16,16000, data format is " ERuntimeRAWAudioFormat::Int16", "Number of channels“ is 1 how to make is works, thanks。

gtreshchev commented 10 months ago

You can refer to this documentation page: https://github.com/gtreshchev/RuntimeAudioImporter/wiki/8.-Exporting-Audio

If your SDK requires RAW (PCM) audio data in Int16 format, with a sample rate of 16000 and a single channel, you can achieve this by using the ExportSoundWaveToRAWBuffer function. Specify the RAWFormat as Int16, and use the OverrideOptions structure to set SampleRate to 16000 and NumOfChannels to 1. Once the export process is complete, the function will return an array of bytes (TArray<uint8>) containing the exported audio data. You can then import this audio data into your SDK as needed.

gtreshchev commented 10 months ago

Regarding the OnPopulateAudioData delegate, it broadcasts the populated audio data in a 32-bit floating-point format, contained within a TArray<float>, which is more convenient and suitable for certain use cases.

imloama commented 10 months ago

Thanks for reply. ExportSoundWaveToRAWBuffer works fine.

But I do not want to call StopCapture method,So I would like to use OnPopulateAudioData delegate. According the document (https://github.com/gtreshchev/RuntimeAudioImporter/wiki/6.-Sound-Wave-Properties)[https://github.com/gtreshchev/RuntimeAudioImporter/wiki/6.-Sound-Wave-Properties], call the methods ResameSoundWave and MixSoundWaveChannel before StartCapture, donot works for OnPopulateAudioData. I don't know why, maybe it's a bug of my SDK.

I tried to copy ExportSoundWaveToRAWBuffer codes to convert the data of TArray<float> receiving from OnPopulateAudioData to TArray<uint8>, it works.