mirror of
https://github.com/storytold/RuntimeAudioImporter.git
synced 2026-10-09 00:09:48 +00:00
function to export soundwave to wav file
This commit is contained in:
+4
-10
@@ -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;
|
||||
|
||||
+1
-2
@@ -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:
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user