From 5a0bdc1e81f4bfbb8680c6f294672dc8d45fdde5 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sun, 17 May 2020 17:15:10 +0800 Subject: [PATCH] fix #89 --- cocos/audio/AudioCache.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cocos/audio/AudioCache.cpp b/cocos/audio/AudioCache.cpp index a22ab5f73d..e31cc6b96f 100644 --- a/cocos/audio/AudioCache.cpp +++ b/cocos/audio/AudioCache.cpp @@ -145,7 +145,11 @@ void AudioCache::readDataTask(unsigned int selfId) uint32_t remainingFrames = totalFrames; uint32_t adjustFrames = 0; - _format = channelCount > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; + if(bytesPerFrame > 1) + _format = channelCount > 1 ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16; // bits depth: 16bits + else + _format = channelCount > 1 ? AL_FORMAT_STEREO8 : AL_FORMAT_MONO8; // bits depth: 8bits + _sampleRate = (ALsizei)sampleRate; _duration = 1.0f * totalFrames / sampleRate; _totalFrames = totalFrames;