03-22-2015 10:20 AM
03-22-2015 01:52 PM
03-23-2015 07:06 AM
03-23-2015 11:42 AM
m_sSoundInfo = { 0 };
m_sSoundInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
m_sSoundInfo.suggestedsoundtype = FMOD_SOUND_TYPE_RAW;
m_sSoundInfo.channelorder = FMOD_CHANNELORDER_WAVEFORMAT; // important!
m_sSoundInfo.channelmask = FMOD_CHANNELMASK_5POINT1_REARS;
m_sSoundInfo.numchannels = formatNew->nChannels;
m_sSoundInfo.defaultfrequency = formatNew->nSamplesPerSec;
m_sSoundInfo.format = FMOD_SOUND_FORMAT_PCM24;
FMOD_RESULT result = FMOD::System_Create(&m_FMODSystem); // Create the main system object.
if (FMOD_OK != result) {
LOGF(WARNING, "Create FMOD Main System FAILED(%d)", result);
return(E_FAIL);
}
int iSampleRate(DEFAULT_FMOD_SAMPLERATE);
result = m_FMODSystem->getSoftwareFormat(&iSampleRate, nullptr, nullptr);
if (FMOD_OK == result) {
m_iFMODSampleRate = iSampleRate;
LOGF(INFO, "FMOD Mixer SampleRate: %dHz", iSampleRate);
}
else {
LOGF(WARNING, "FMOD getSoftwareFormat FAILED(%d)", result);
return(E_FAIL);
}
unsigned int bufferSize(0);
result = m_FMODSystem->getDSPBufferSize(&bufferSize, nullptr);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD getDSPBufferSize FAILED(%d)", result);
return(E_FAIL);
}
if (!OSP_FMOD_Initialize(iSampleRate, bufferSize))
{
LOGF(WARNING, "OSP_FMOD_Initialize FAILED");
return(E_FAIL);
}
if (!OSP_FMOD_SetSimpleBoxRoomParameters(5.0f, 2.1f, 3.7f,
0.75f, 0.65f, 0.55f, 0.25f, 0.65f, 0.65f))
{
LOGF(WARNING, "OSP_FMOD_SetSimpleBoxRoomParameters FAILED");
return(E_FAIL);
}
m_FMODSystem->setSoftwareFormat(m_iFMODSampleRate, FMOD_SPEAKERMODE_STEREO, 0); // FMOD_SPEAKERMODE_STEREO Final Format Used (Headphones)
result = m_FMODSystem->init(32, FMOD_INIT_NORMAL/*FMOD_INIT_STREAM_FROM_UPDATE | FMOD_INIT_THREAD_UNSAFE*/, 0);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD Init FAILED(%d)", result);
return(false);
}
result = m_FMODSystem->loadPlugin(m_szOSPAudioPlugin, &m_hOSPAudio);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD Load Plugin OSP FAILED(%d)", result);
return(false);
}
result = m_FMODSystem->createDSPByPlugin(m_hOSPAudio, &m_dspOSP);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD Create DSP OSP FAILED(%d)", result);
return(false);
}
/*FMOD_ADVANCEDSETTINGS sAdvanced = { 0 };
sAdvanced.cbSize = sizeof(FMOD_ADVANCEDSETTINGS);
sAdvanced.resamplerMethod = FMOD_DSP_RESAMPLER_SPLINE;
sAdvanced.maxPCMCodecs = 1;
sAdvanced.HRTFMinAngle = 180.0f;
sAdvanced.HRTFMaxAngle = 360.0f;
sAdvanced.HRTFFreq = 4000.0f;
result = m_FMODSystem->setAdvancedSettings(&sAdvanced); // Initialize FMOD.
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD setAdvancedSettings FAILED(%d)", result);
return(false);
}*/
result = m_FMODSystem->getMasterChannelGroup(&m_channelgroup);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD getMasterChannelGroup FAILED(%d)", result);
return(false);
}
result = m_channelgroup->setPaused(true);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD setPaused FAILED(%d)", result);
return(false);
}
result = m_channelgroup->setVolume(0.9f);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD setVolume FAILED(%d)", result);
return(false);
}
// Plugin OSP
result = m_channelgroup->addDSP(1, m_dspOSP);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD addDSP OSP FAILED(%d)", result);
return(false);
}
__declspec(restrict)FMOD::Channel * const FMODFilterManager::queueNextSound(CMediaBufferSampleWrapper const* const __restrict pSample, FMOD::Channel* const __restrict prevChannel, FMOD::Sound ** const __restrict curSoundSlot)
{
FMOD_RESULT result;
DWORD dwLength(0);
FMOD::Channel * __restrict newChannel;
char const* __restrict pBuffer(nullptr);
pSample->GetBufferAndLength(&pBuffer, &dwLength);
FMOD_CREATESOUNDEXINFO soundInfoCurLength(m_sSoundInfo);
soundInfoCurLength.length = dwLength;
result = m_FMODSystem->createSound(pBuffer, FMOD_OPENMEMORY_POINT | FMOD_OPENRAW | FMOD_IGNORETAGS | FMOD_LOWMEM | FMOD_UNIQUE, &soundInfoCurLength, curSoundSlot);
if (FMOD_OK != result)
return(nullptr);
result = m_FMODSystem->playSound(*curSoundSlot, m_channelgroup, true, &newChannel);
if (FMOD_OK != result)
return(nullptr);
if (nullptr == prevChannel)
{
result = PrimeFMODStream(&prevChannel, &soundInfoCurLength);
if (FMOD_OK != result) {
LOGF(WARNING, "PrimeFMODStream FAILED(%d)", result);
return(nullptr);
}
}
/* We want all channels to be sent as 5.1 instead of very end of DSP //
FMOD::DSP *channel_dsp_head;
result = newChannel->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &channel_dsp_head);
if (FMOD_OK != result)
return(nullptr);
result = channel_dsp_head->setChannelFormat(FMOD_CHANNELMASK_5POINT1_REARS, 6, FMOD_SPEAKERMODE_5POINT1);
if (FMOD_OK != result)
return(nullptr);
result = newChannel->setMixLevelsOutput(1.0f, 1.0f, 1.0f, 1.1f, 1.0f, 1.0f, 1.0f, 1.0f);
if (FMOD_OK != result)
return(nullptr);*/
unsigned long long startdelay = 0;
unsigned int soundlength = 0;
float soundfrequency;
FMOD::Sound * __restrict playingsound;
//Get the start time of the playing channel.
result = prevChannel->getDelay(&startdelay, 0);
if (FMOD_OK != result)
return(nullptr);
//Grab the length of the playing sound, and its frequency, so we can caluate where to place the new sound on the time line.
result = prevChannel->getCurrentSound(&playingsound);
if (FMOD_OK != result)
return(nullptr);
result = playingsound->getLength(&soundlength, FMOD_TIMEUNIT_PCM);
if (FMOD_OK != result)
return(nullptr);
result = prevChannel->getFrequency(&soundfrequency);
if (FMOD_OK != result)
return(nullptr);
//Now calculate the length of the sound in 'output samples'.
//Ie if a 44khz sound is 22050 samples long, and the output rate is 48khz, then we want to delay by 24000 output samples.
soundlength = (unsigned int)((float)soundlength / soundfrequency * (float)m_iFMODSampleRate);
startdelay += soundlength; // Add output rate adjusted sound length, to the clock value of the sound that is currently playing*/
result = newChannel->setDelay(startdelay, 0); // Set the delay of the new sound to the end of the old sound
if (FMOD_OK != result)
return(nullptr);
/*unsigned long long tDelayStart = (pSample->GetStartTime() / 10000) * (m_iSampleRate / 1000);
result = newChannel->setDelay(m_ulStartDelay + tDelayStart, 0); // Set the delay of the new sound to the end of the old sound
if (FMOD_OK != result)
return(nullptr);*/
result = newChannel->setPaused(false);
if (FMOD_OK != result)
return(nullptr);
return(newChannel);
}
03-24-2015 04:03 PM
FMOD_RESULT result = FMOD::System_Create(&m_FMODSystem); // Create the main system object.
if (FMOD_OK != result) {
LOGF(WARNING, "Create FMOD Main System FAILED(%d)", result);
return(E_FAIL);
}
int iSampleRate(DEFAULT_FMOD_SAMPLERATE);
result = m_FMODSystem->getSoftwareFormat(&iSampleRate, nullptr, nullptr);
if (FMOD_OK == result) {
m_iFMODSampleRate = iSampleRate;
LOGF(INFO, "FMOD Mixer SampleRate: %dHz", iSampleRate);
}
else {
LOGF(WARNING, "FMOD getSoftwareFormat FAILED(%d)", result);
return(E_FAIL);
}
unsigned int bufferSize(0);
result = m_FMODSystem->getDSPBufferSize(&bufferSize, nullptr);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD getDSPBufferSize FAILED(%d)", result);
return(E_FAIL);
}
if (!OSP_FMOD_Initialize(iSampleRate, bufferSize))
{
LOGF(WARNING, "OSP_FMOD_Initialize FAILED");
return(E_FAIL);
}
if (!OSP_FMOD_SetSimpleBoxRoomParameters(5.0f, 2.1f, 3.7f,
0.75f, 0.65f, 0.55f, 0.25f, 0.65f, 0.65f))
{
LOGF(WARNING, "OSP_FMOD_SetSimpleBoxRoomParameters FAILED");
return(E_FAIL);
}
m_FMODSystem->setSoftwareFormat(m_iFMODSampleRate, FMOD_SPEAKERMODE_STEREO, 0); // FMOD_SPEAKERMODE_STEREO Final Format Used (Headphones)
result = m_FMODSystem->init(32, FMOD_INIT_NORMAL, 0);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD Init FAILED(%d)", result);
return(false);
}
result = m_FMODSystem->loadPlugin(m_szOSPAudioPlugin, &m_hOSPAudio);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD Load Plugin OSP FAILED(%d)", result);
return(false);
}
__declspec(restrict)FMOD::Channel * const FMODFilterManager::queueNextSound(CMediaBufferSampleWrapper const* const __restrict pSample, FMOD::Channel* const __restrict prevChannel, FMOD::Sound ** const __restrict curSoundSlot)
{
FMOD_RESULT result;
DWORD dwLength(0);
FMOD::Channel * __restrict newChannel;
char const* __restrict pBuffer(nullptr);
pSample->GetBufferAndLength(&pBuffer, &dwLength);
FMOD_CREATESOUNDEXINFO soundInfoCurLength(m_sSoundInfo);
soundInfoCurLength.length = dwLength;
result = m_FMODSystem->createSound(pBuffer, FMOD_OPENMEMORY_POINT | FMOD_OPENRAW | FMOD_IGNORETAGS | FMOD_LOWMEM | FMOD_UNIQUE, &soundInfoCurLength, curSoundSlot);
if (FMOD_OK != result)
return(nullptr);
result = m_FMODSystem->playSound(*curSoundSlot, m_channelgroup, true, &newChannel);
if (FMOD_OK != result)
return(nullptr);
if (nullptr == prevChannel)
{
result = PrimeFMODStream(&prevChannel, &soundInfoCurLength);
if (FMOD_OK != result) {
LOGF(WARNING, "PrimeFMODStream FAILED(%d)", result);
return(nullptr);
}
}
/* We want all channels to be sent as 5.1 instead of very end of DSP //
FMOD::DSP *channel_dsp_head;
result = newChannel->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &channel_dsp_head);
if (FMOD_OK != result)
return(nullptr);
unsigned long long startdelay = 0;
unsigned int soundlength = 0;
float soundfrequency;
FMOD::Sound * __restrict playingsound;
//Get the start time of the playing channel.
result = prevChannel->getDelay(&startdelay, 0);
if (FMOD_OK != result)
return(nullptr);
//Grab the length of the playing sound, and its frequency, so we can caluate where to place the new sound on the time line.
result = prevChannel->getCurrentSound(&playingsound);
if (FMOD_OK != result)
return(nullptr);
result = playingsound->getLength(&soundlength, FMOD_TIMEUNIT_PCM);
if (FMOD_OK != result)
return(nullptr);
result = prevChannel->getFrequency(&soundfrequency);
if (FMOD_OK != result)
return(nullptr);
//Now calculate the length of the sound in 'output samples'.
//Ie if a 44khz sound is 22050 samples long, and the output rate is 48khz, then we want to delay by 24000 output samples.
soundlength = (unsigned int)((float)soundlength / soundfrequency * (float)m_iFMODSampleRate);
startdelay += soundlength; // Add output rate adjusted sound length, to the clock value of the sound that is currently playing*/
result = newChannel->setDelay(startdelay, 0); // Set the delay of the new sound to the end of the old sound
if (FMOD_OK != result)
return(nullptr);
/*unsigned long long tDelayStart = (pSample->GetStartTime() / 10000) * (m_iSampleRate / 1000);
result = newChannel->setDelay(m_ulStartDelay + tDelayStart, 0); // Set the delay of the new sound to the end of the old sound
if (FMOD_OK != result)
return(nullptr);*/
// Plugin OSP
result = m_FMODSystem->createDSPByPlugin(m_hOSPAudio, &m_dspOSP);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD Create DSP OSP FAILED(%d)", result);
return(false);
}
result = m_channelgroup->addDSP(1, m_dspOSP);
if (FMOD_OK != result) {
LOGF(WARNING, "FMOD addDSP OSP FAILED(%d)", result);
return(false);
}
result = newChannel->setPaused(false);
if (FMOD_OK != result)
return(nullptr);
return(newChannel);
}
03-26-2015 08:56 AM
03-31-2015 06:51 PM
04-03-2015 12:56 PM
"PeterStirling" wrote:
The input should be mono, and the output will be stereo. I just tested this on a channel group and it works correctly as long as the input is mono. If the input is stereo it sounds incorrect (but doesn't crash). We can down-mix to mono internally to support stereo input but there is no benefit over mono input. Can you try setting it up with mono input (or just calling DSP::setChannelFormat(0, 1, FMOD_SPEAKERMODE_MONO), and see if that works? If it's still crashing can you post your updated code?
04-13-2015 05:25 PM