function to export soundwave to wav file

This commit is contained in:
Respirant
2021-01-10 17:52:30 +03:00
parent b761ae46dd
commit 6165fe1740
2 changed files with 5 additions and 12 deletions
@@ -77,7 +77,7 @@ void unreal_free(void* p, void* pUserData)
FMemory::Free(p);
}
bool URuntimeAudioImporterLibrary::ExportSoundWaveToFile(USoundWave* SoundWaveToExport, FString PathToExport, bool Faster)
bool URuntimeAudioImporterLibrary::ExportSoundWaveToFile(USoundWave* SoundWaveToExport, FString PathToExport)
{
uint8* PCMData = SoundWaveToExport->RawPCMData;
size_t PCMDataSize = SoundWaveToExport->RawPCMDataSize;
@@ -93,15 +93,9 @@ bool URuntimeAudioImporterLibrary::ExportSoundWaveToFile(USoundWave* SoundWaveTo
drwav_uint64 framesToWrite = PCMDataSize / sizeof(DR_WAVE_FORMAT_PCM) / SoundWaveToExport->NumChannels;
if (Faster) {
ChannelCount = SoundWaveToExport->NumChannels;
SampleRate = FGenericPlatformMath::RoundToInt((framesToWrite / (float)SoundWaveToExport->GetDuration() * ChannelCount));
}
else {
TArray<uint8> NeedlessPCMData; //Needless PCMData array, but without it, it is not possible to get SampleRate
SoundWaveToExport->GetImportedSoundWaveData(*&NeedlessPCMData, *&SampleRate, *&ChannelCount);
NeedlessPCMData.Empty();
}
ChannelCount = SoundWaveToExport->NumChannels;
SampleRate = FGenericPlatformMath::RoundToInt((framesToWrite / (float)SoundWaveToExport->GetDuration() * ChannelCount));
drwav wavEncode;
drwav_data_format format;
@@ -106,12 +106,11 @@ public:
*
* @param SoundWaveToExport SoundWave object need to be exported
* @param PathToExport Path where to save audio file
* @param Faster Get SampleRate faster. Less clear, but fast. The difference is very insignificant, True is recommended
* @return Whether the save was successfull or not
* @warning It is very important that USoundWave should not used by the engine so that it can be read from physical memory.
*/
UFUNCTION(BlueprintCallable, meta = (Keywords = "Exporter, Export, Save, Runtime, WAV"), Category = "RuntimeAudioImporter")
static bool ExportSoundWaveToFile(USoundWave * SoundWaveToExport, FString PathToExport, bool Faster = true);
static bool ExportSoundWaveToFile(USoundWave * SoundWaveToExport, FString PathToExport);
private:
/**