Fmod is used as audio library on our engine, and is used at windows version of our game.
I’m trying to continue a port of it on the jni version of the engine, to replace current usage of Android audio library.
Our engine have a FileManager that handles files in both platforms and loads files into memory, in order to use zip containters on android, so I use FMOD_OPENMEMORY | FMOD_CREATESAMPLE or FMOD_OPENMEMORY | FMOD_CREATECOMPRESSEDSAMPLE | FMOD_CREATESTREAM depending the audio sample type (music or effects).
All that is ok, and managed to get it working on windows as it shoud work on android, but on Adroid I get the error:
SystemI::createSound : Info has invalid cbsize = 148. Must be set to sizeof(FMOD_CREATESOUNDEXINFO)
I debugged, and tried a lot of things, disabling some optimizations, the value 148 for cbsize is the right one for windows and works without problem.
the relevant snippet of code:
bool FMAudioSample::LoadSampleFromFileInMemory(
AudioWeakPtr audio,
void* pBuffer,
const unsigned int bufferLength,
const Audio::SAMPLE_TYPE type)
{
try
{
Audio* pAudio = audio.lock().get();
m_system = boost::any_cast<FMOD::System*>(pAudio->GetAudioContext());
}
catch (const boost::bad_any_cast&)
{
std::stringstream ss;
ss << "FMAudioSample::LoadSampleFromFileInMemory: Invalid fmod system";
m_logger.Log(ss.str(), Platform::FileLogger::ERROR);
return false;
}
FMOD_CREATESOUNDEXINFO audioInfo;
// Clear the structure to avoid thrash
// it could have a constructor
memset(&audioInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
audioInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
audioInfo.length = static_cast<unsigned int>(bufferLength);
// Open file from memory and create uncompressed sample, doing it on the fly will cause
// some delay.
FMOD_MODE mode = FMOD_OPENMEMORY | FMOD_CREATESAMPLE;
// if is streamable type, use CREATECOMPRESSEDSAMPLE and add FMOD_CREATESTREAM flag to mode
// 'cause it is music and uncompress it in memory will use a lot of resources
// avoids a big if to call createStream function, wich by the docs, do the same.
// we cant use FMOD_OPENMEMORY_POINT and need to let fmod duplicate it because it allocates
// extra bytes on the buffer on compressed files, for mixing and other stuff.
if (FMAudioContext::IsStreamable(type))
FMOD_MODE mode = FMOD_OPENMEMORY | FMOD_CREATECOMPRESSEDSAMPLE | FMOD_CREATESTREAM;
const FMOD_RESULT result = m_system->createSound(static_cast<char*>(pBuffer), mode, &audioInfo, &m_sound);
if (FMOD_ERRCHECK(result, m_logger))
return false;
m_logger.Log(m_fileName + " file loaded", Platform::FileLogger::INFO);
return true;
}