Everything works as expected, except the following error log happens every time exiting the play session.
LogFMOD: Error: c:\jk\workspace\Build__2.2__Unreal_Win\core_api\src\fmod_systemi_thread.cpp(65) - assertion: 'mCrit[crit]' failed
LogFMOD: Error: c:\jk\workspace\Build__2.2__Unreal_Win\core_api\src\fmod_systemi_thread.cpp(138) - assertion: 'mCrit[crit]' failed
LogFMOD: Error: c:\jk\workspace\Build__2.2__Unreal_Win\core_api\src\fmod_systemi_thread.cpp(65) - assertion: 'mCrit[crit]' failed
LogFMOD: Error: c:\jk\workspace\Build__2.2__Unreal_Win\core_api\src\fmod_systemi_thread.cpp(138) - assertion: 'mCrit[crit]' failed
LogWorld: UWorld::CleanupWorld for FirstPersonExampleMap, bSessionEnded=true, bCleanupResources=true
Code:
// Fill out your copyright notice in the Description page of Project Settings.
#include "MultiSoundActor.h"
// Sets default values
AMultiSoundActor::AMultiSoundActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND* /*sound*/, void* data, unsigned int datalen)
{
static float t1 = 0, t2 = 0; // time
static float v1 = 0, v2 = 0; // velocity
signed short* stereo16bitbuffer = (signed short*)data;
for (unsigned int count = 0; count < (datalen >> 2); count++) // >>2 = 16bit stereo (4 bytes per sample)
{
*stereo16bitbuffer++ = (signed short)(FMath::Sin(t1) * 32767.0f); // left channel
*stereo16bitbuffer++ = (signed short)(FMath::Sin(t2) * 32767.0f); // right channel
t1 += 0.01f + v1;
t2 += 0.0142f + v2;
v1 += (float)(FMath::Sin(t1) * 0.002f);
v2 += (float)(FMath::Sin(t2) * 0.002f);
}
return FMOD_OK;
}
// Called when the game starts or when spawned
void AMultiSoundActor::BeginPlay()
{
Super::BeginPlay();
auto StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
FMOD::System* system = nullptr;
StudioSystem->getCoreSystem(&system);
FMOD_MODE mode = FMOD_OPENUSER | FMOD_LOOP_NORMAL;
FMOD_CREATESOUNDEXINFO exinfo;
void* extradriverdata = 0;
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); /* Required. */
exinfo.numchannels = 2; /* Number of channels in the sound. */
exinfo.defaultfrequency = 44100; /* Default playback rate of sound. */
exinfo.decodebuffersize = 44100; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */
exinfo.length = exinfo.defaultfrequency * exinfo.numchannels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
exinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Data format of sound. */
exinfo.pcmreadcallback = pcmreadcallback; /* User callback for reading. */
verifyfmod(system->createSound(0, mode, &exinfo, &sound));
verifyfmod(system->playSound(sound, 0, 0, &channel));
}
// Called every frame
void AMultiSoundActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AMultiSoundActor::EndPlay(EEndPlayReason::Type Why)
{
if (channel)
{
channel->stop();
}
if (sound)
{
sound->release();
}
}