cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.06k forks source link

SimpleAudioEngine fails to playback 32bit wav files #16607

Open hunterwilliams opened 8 years ago

hunterwilliams commented 8 years ago

Steps to Reproduce:

  1. Use any 32 bit .wav file
  2. SimpleAudioEngine::getInstance()->playEffect(filePath, false, 1, 0, 1);

The sound will not play. However converting with Audacity to a 16bit version works perfectly fine.

If I need to supply a test file let me know.

dumganhar commented 8 years ago

Could you upload a 32bit .wav for testing? Thanks.

hunterwilliams commented 8 years ago

I've put one in my dropbox. Not sure a great place to upload them.

https://dl.dropboxusercontent.com/u/16766619/punch.wav

dumganhar commented 8 years ago

@hunterwilliams , I could download the file you uploaded. Thank you.

dumganhar commented 8 years ago

@hunterwilliams , I tested, it's a bug of SimpleAudioEngine.

void* CDloadWaveAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei*    outSampleRate)
{
...
    if ((theFileFormat.mBitsPerChannel != 8) && (theFileFormat.mBitsPerChannel != 16)) { 
// GOTO HERE, SINCE mBitsPerChannel is 32.
        CDLOG(@"MyGetOpenALAudioData - Unsupported Format, must be 8 or 16 bit PCM\n"); goto Exit;
    }

I also tested with AudioEngine which uses openal to play audio. And it works ok. It's better to switch to AudioEngine which is more powerful. :)

hunterwilliams commented 8 years ago

Ah I didn't manage to see that pop in the logs. Maybe suggest a documentation mention unless I missed it :)