0
0

Hello,

I’m trying to port my project from windows/ios to android. I am not able to create or play on any channel this way 0-31.

The below code works on ios and on windows so I’m not sure what would be the issue on android. Looking at revision.txt it says this is version 4.44.12.

Thanks for any help

[code:url6y0m9]
FMOD::Sound* newSfx =0;

FMOD_RESULT r = FMOD_OK;
unsigned long size =0;
unsigned char* pData = 0;
char* pData2 = 0;
FMOD_CREATESOUNDEXINFO exinfo;


pData = loadfiledata(path.c_str(), "rb", &size);
if(size > 0)
{
    pData2 = reinterpret_cast<char*>(pData);

    memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

    exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    exinfo.length = size;

    LOG("size of sound:%lu",size);
    r = system->createSound(pData2, FMOD_OPENMEMORY | FMOD_LOOP_OFF, &exinfo, &newSfx);
}
else
{
    LOG("File size is not bigger than 0. %s", path.c_str());

    r = FMOD_ERR_FILE_NOTFOUND;
}

if (r != FMOD_OK)
{
    LOG("[FMOD] %s, %s", FMOD_ErrorString(r), path.c_str());  //nothing gets logged here
}

for (int i=1;i<MaxChannels;i++) //MaxChannels == 32, 0 is reserved for background music
{
    FMOD::Channel* chn;
    FMOD_RESULT r = system->getChannel(i, &chn);
    if (r == FMOD_OK)
    {
        bool playing = false;
        r = chn->isPlaying(&playing);
        LOG("channel:%d playing:%d fmod:%d file: %s", i, (int)playing, (int)r, path.c_str());

        if ((r == FMOD_OK || r == FMOD_ERR_INVALID_HANDLE) && !playing)
        {

            r = system->playSound((FMOD_CHANNELINDEX)i, newSfx ,false, nullptr); //CRASHES HERE
            //have also tried
            //r = system->playSound((FMOD_CHANNELINDEX)i, newSfx ,false, &chn);
            //r = system->playSound(FMOD_CHANNEL_FREE, newSfx ,false, nullptr);
            //r = system->playSound(FMOD_CHANNEL_FREE, newSfx ,false, &chn);

            break;
        }
        LOG("sound played");

    }
}

[/code:url6y0m9]

  • You must to post comments
0
0

BTW .. here is the output I get

08-10 00:45:34.869: D/game debug info(6043): getting file data for: sfx/collectible.wav
08-10 00:45:34.869: D/game debug info(6043): size of sound:86127 <– correct
08-10 00:45:34.869: D/game debug info(6043): channel:1 playing:0 fmod:36 file: sfx/collectible.wav
08-10 00:45:34.869: A/libc(6043): Fatal signal 11 (SIGSEGV) at 0x00020113 (code=1)

  • You must to post comments
0
0

So

  • You must to post comments
0
0

So I changed the loop to the following and hard coded in the channel…
I also commented out the get channel and isPlaying calls..

[code:psnrxwob]
for (int i=1;i<MaxChannels;i++) //MaxChannels == 32
{
FMOD::Channel* chn;
//FMOD_RESULT r = system->getChannel(i, &chn);
if (r == FMOD_OK)
{
bool playing = false;
//r = chn->isPlaying(&playing);
LOG("channel:%d playing:%d fmod:%d file: %s", i, (int)playing, (int)r, path.c_str());

        if ((r == FMOD_OK || r == FMOD_ERR_INVALID_HANDLE) &amp;&amp; !playing)
        {

            r = system-&gt;playSound((FMOD_CHANNELINDEX)1, *sfx ,false, &amp;chn);
            break;
        }
        LOG(&quot;sound played&quot;);

    }
}

[/code:psnrxwob]

This allowed sounds to play but is not a good solution. Any thoughts on why the channel could be causing the problem?

Thanks

  • You must to post comments
0
0

So making one more change to null out the channel pointer before calling the play sound allowed the sound effects to function. I would like to know though if this causes a memory leak?

Thanks

[code:3rhxupaf]
for (int i=1;i<MaxChannels;i++)
{
FMOD::Channel* chn;
FMOD_RESULT r = system->getChannel(i, &chn);
if (r == FMOD_OK)
{
bool playing = false;
r = chn->isPlaying(&playing);
LOG("channel:%d playing:%d fmod:%d file: %s", i, (int)playing, (int)r, path.c_str());

        if ((r == FMOD_OK || r == FMOD_ERR_INVALID_HANDLE) &amp;&amp; !playing)
        {
            chn = nullptr;
            r = system-&gt;playSound((FMOD_CHANNELINDEX)i, *sfx ,false, &amp;chn);
            break;
        }
        LOG(&quot;sound played&quot;);

    }
}

[/code:3rhxupaf]

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.