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);
|
FMemory::Free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool URuntimeAudioImporterLibrary::ExportSoundWaveToFile(USoundWave* SoundWaveToExport, FString PathToExport, bool Faster)
|
bool URuntimeAudioImporterLibrary::ExportSoundWaveToFile(USoundWave* SoundWaveToExport, FString PathToExport)
|
||||||
{
|
{
|
||||||
uint8* PCMData = SoundWaveToExport->RawPCMData;
|
uint8* PCMData = SoundWaveToExport->RawPCMData;
|
||||||
size_t PCMDataSize = SoundWaveToExport->RawPCMDataSize;
|
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;
|
drwav_uint64 framesToWrite = PCMDataSize / sizeof(DR_WAVE_FORMAT_PCM) / SoundWaveToExport->NumChannels;
|
||||||
|
|
||||||
if (Faster) {
|
ChannelCount = SoundWaveToExport->NumChannels;
|
||||||
ChannelCount = SoundWaveToExport->NumChannels;
|
SampleRate = FGenericPlatformMath::RoundToInt((framesToWrite / (float)SoundWaveToExport->GetDuration() * ChannelCount));
|
||||||
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();
|
|
||||||
}
|
|
||||||
drwav wavEncode;
|
drwav wavEncode;
|
||||||
|
|
||||||
drwav_data_format format;
|
drwav_data_format format;
|
||||||
|
|||||||
+1
-2
@@ -106,12 +106,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param SoundWaveToExport SoundWave object need to be exported
|
* @param SoundWaveToExport SoundWave object need to be exported
|
||||||
* @param PathToExport Path where to save audio file
|
* @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
|
* @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.
|
* @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")
|
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:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user