My code is like this
FMOD::System_Create(&s_system);
s_system->setSoftwareFormat(44100, FMOD_SPEAKERMODE_STEREO, 0);
s_system->init(16, FMOD_INIT_NORMAL, nullptr);
...
void AudioManager::loadSound(Sound* sound, Sound::Info* info, U8* data) {
FMOD_CREATESOUNDEXINFO exinfo;
std::memset(&exinfo, 0, sizeof(exinfo));
exinfo.cbsize = sizeof(exinfo);
exinfo.length = info->dataSize;
exinfo.numchannels = info->numChannels;
exinfo.defaultfrequency = info->sampleRate;
if (info->format == Format::PCM16) {
exinfo.format = FMOD_SOUND_FORMAT_PCM16;
exinfo.suggestedsoundtype = FMOD_SOUND_TYPE_RAW;
s_system->createSound((char*)data, FMOD_LOWMEM | FMOD_CREATESAMPLE | FMOD_OPENMEMORY_POINT | FMOD_OPENRAW, &exinfo, (FMOD::Sound**)&sound->m_sound);
}
}
void Sound::load(U8* data, U32 dataSize) {
Info info;
info.format = Format::PCM16;
info.dataSize = dataSize;
info.numChannels = 1;
info.sampleRate = 22050;
int inc = (info.format == Format::PCM16) * info.numChannels * 2;
m_data = resourceManager().alloc(dataSize + inc); // U8* m_data;
std::memcpy(m_data, data, dataSize);
if (inc)
std::memset(m_data + dataSize, 0x7f, inc);
// std::memset(m_data + dataSize, 0, inc); // fix
audioManager().loadSound(this, &info, m_data);
}
I’m using the latest Low level API 1.0.9 for MacOS.
When I play short PCM16 sound with 22050 sample rate, I hear click at the end. To fix this I add zero bytes to the end of data. Is it normal behaviour?
EDIT:
I add zeroes not to the end, but after it to fix clicking. Please see the code above.