0

I need some amount of songs to be played at the same time (simulteneously). My code is:

#define SIZE 9

FMOD_SYSTEM *gSystem = 0;
FMOD_CHANNEL *gChannel[SIZE];
FMOD_SOUND *gSound[SIZE];
const char *tracks[SIZE];

FMOD_RESULT result = FMOD_OK;
result = FMOD_System_Create(&gSystem);
result = FMOD_System_Init(gSystem, 1024, FMOD_INIT_NORMAL, 0);

FMOD_MODE soundParams = FMOD_SOFTWARE | FMOD_2D | FMOD_LOOP_OFF | FMOD_CREATESTREAM
                | FMOD_ACCURATETIME;

for (int i = 0; i < tracksSize; i++)
    result = FMOD_System_CreateSound(gSystem, tracks[i], soundParams, 0, &gSound[i]);

for (int i=0; i<tracksSize; i++) {
    result = FMOD_System_PlaySound(gSystem, FMOD_CHANNEL_FREE, gSound[i], true, &gChannel[i]);

    FMOD_Channel_SetMode(gChannel[i], FMOD_LOOP_NORMAL);
    FMOD_Channel_SetLoopCount(gChannel[i], -1);
    FMOD_Channel_SetPaused(gChannel[i], false);
}

But songs play intermittently. Help me, please.

voha
  • 42
  • 8

1 Answers1

0

I don't see anything immediately wrong with your code, it appears you are creating and playing 9 streams of audio. My concern would be the CPU cost of playing 9 streams on an Android (mobile) device. If you are using a complex compression format such as MP3 you are probably saturating the CPU. You can check this by using System::getCPUUsage(), take a look at the 'total' CPU value, is it over or near 100%? If so, that will be your problem.

The solution would be to choose either less channels playing simultaneously, or a less CPU intensive compression format such as ADPCM.

Mathew Block
  • 1,613
  • 1
  • 10
  • 9
  • Thank you, Mathew! I have run the application on Galaxy S4, and audio plays much better, but time to time it plays intermittently. – voha Aug 14 '13 at 16:06