When trying to play a sound via FMOD, I am getting the following error:
- This only happens when I load the sound from memory. When I load it from the file directly, it works fine. I verified that the memory buffer contains the same data as the file, by writing the byte array to a file and comparing the two with a show difference tool.
- It is an ogg file, just like all the rest of the sounds I am using. This is the only one that has this problem though.
- It works fine the first time the sound is played. Any subsequent attempt to play the sound generates this error.
int CFMODAudioPlayer::loadAudioFile(std::string audioname, char* buffer, int bufferSize)
{
FMOD::Sound* audioStream;
FMOD_CREATESOUNDEXINFO audioInfo;
memset(&audioInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
audioInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
audioInfo.length = static_cast<unsigned int>(bufferSize);
system_->setStreamBufferSize(65536, FMOD_TIMEUNIT_RAWBYTES);
FMODErrorCheck(system_->createStream(static_cast<const char*>(buffer), FMOD_OPENMEMORY, &audioInfo, &audioStream));
int id = sounds_.size();
audioNameIDMap_[audioname] = id;
sounds_.push_back(audioStream);
channels_.push_back(NULL);
return id;
}
And here is the code I am using to play the sound:
void CFMODAudioPlayer::playAudio(std::string audioname)
{
int index = audioNameIDMap_[audioname];
FMOD::Channel* channel;
FMODErrorCheck(system_->playSound(FMOD_CHANNEL_FREE, sounds_[index], false, &channel));
channels_[index] = channel;
}