simpleaudiomanager playEffect distorted sound

simpleaudiomanager playEffect distorted sound
0.0 0


play backgrund music is fine but i have to preload any effect before it even plays and when it plays its all distorted.


The current version cocos2d-0.99.5-x-0.8.2 airplay module supports CocosDenshion fairly superficial - rather as a sample test. Sound effect of CocosDenshion will work fine now only for the “raw” sound files. For other types of audio files - for example wav - may require some extra effort …

Only as an example:

if we are using 16 bit mono wav with sample rate = 11025, you can edit the preload function for audio files as follows

    SimpleAudioEngine:: preloadEffect (const char * pszFilePath) 
        s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb");

        IwAssertMsg(GAME, fileHandle, ("Open file %s Failed. s3eFileError Code : %i", pszFilePath, s3eFileGetError()));

        g_SoundFileSize = s3eFileGetSize(fileHandle);
        g_SoundBuffer = (int16*)s3eMallocBase(g_SoundFileSize);
        memset(g_SoundBuffer, 0, g_SoundFileSize);

        // INSERT BEGIN//////////////////////////////////////////////////////////

        s3eSoundSetInt (S3E_SOUND_DEFAULT_FREQ, 11025);  // Set default freq for sound effect 
        s3eSoundSetInt (S3E_SOUND_VOLUME, 6);  // Set default volume for sound effect  
        s3eFileSeek (fileHandle, 44, S3E_FILESEEK_SET); // Maybe we need skip 44 byte (because wav file have header see )

        // INSERT END //////////////////////////////////////////////////////////

        s3eFileRead (g_SoundBuffer, g_SoundFileSize, 1, fileHandle);


As a follow-on from this, am I correct in saying that the simpleaudiomanager can’t handle multiple sound effects by default? For example, the code below, playEffect takes the sound file path as a parameter, but doesn’t seem to actually use it, it seems to use what’s in the buffer (the last preloaded sound). I’m attempting to debug why every object is making the same sound :slight_smile:

unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
int channel = s3eSoundGetFreeChannel();
s3eSoundChannelPlay(channel, g_SoundBuffer, g_SoundFileSize/2, 1, 0);


Yes - you’re right - for now do not supported multiple sound effects. But it’s pretty easy to do - you need just do preload sound effects to array of buffers and playing the effect as a buffer from an array of buffers.