void USbinTTSComponent::ReadWaveForPC(FString path, TArray<uint8> &RawSamples, USoundWave *&SoundWave)
{
TArray<uint8> FileSamples;
if (!FFileHelper::LoadFileToArray(FileSamples, *path))
{
UE_LOG(LogTemp, Warning, TEXT(“—LoadFileToArray Error—”));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT(“LoadFileToArray Error”));
return;
}
FWaveModInfo WaveInfo;
FString ErrorMessage;
if (WaveInfo.ReadWaveInfo(FileSamples.GetData(), FileSamples.Num(), &ErrorMessage))
{
USoundWave* Sound = NewObject<USoundWave>(USoundWave::StaticClass());
// Compressed data is now out of date.
Sound->InvalidateCompressedData();
// If we're a multi-channel file, we're going to spoof the behavior of the SoundSurroundFactory
int32 ChannelCount = (int32)*WaveInfo.pChannels;
check(ChannelCount > 0);
int32 SizeOfSample = (*WaveInfo.pBitsPerSample) / 8;
int32 NumSamples = WaveInfo.SampleDataSize / SizeOfSample;
int32 NumFrames = NumSamples / ChannelCount;
Sound->RawData.Lock(LOCK_READ_WRITE);
void *LockedData = Sound->RawData.Realloc(FileSamples.Num() );
FMemory::Memcpy(LockedData, FileSamples.GetData(), FileSamples.Num());
Sound->RawData.Unlock();
Sound->Duration = (float)NumFrames / *WaveInfo.pSamplesPerSec;
Sound->SetSampleRate(*WaveInfo.pSamplesPerSec);
Sound->NumChannels = ChannelCount;
Sound->TotalSamples = *WaveInfo.pSamplesPerSec * Sound->Duration;
SoundWave = Sound;
RawSamples = FileSamples;
}
else
{
SoundWave = nullptr;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("--- ReadWaveInfo Error ---"));
UE_LOG(LogTemp, Warning, TEXT("--- ReadWaveInfo Error:>> %s"), *ErrorMessage);
}
}
// This is my code , How to fill another buffer?