From 8d4e8adef3bc2f51d0cd64038bc7dca46d7dd402 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 10 Mar 2007 17:39:27 +0000 Subject: Let the mixer worry about converting mono to stereo. svn-id: r26065 --- engines/sky/music/adlibmusic.cpp | 25 ++++++++++--------------- engines/sky/music/adlibmusic.h | 7 ++----- 2 files changed, 12 insertions(+), 20 deletions(-) (limited to 'engines') diff --git a/engines/sky/music/adlibmusic.cpp b/engines/sky/music/adlibmusic.cpp index 36c962af5a..aa5d9ee51f 100644 --- a/engines/sky/music/adlibmusic.cpp +++ b/engines/sky/music/adlibmusic.cpp @@ -47,38 +47,33 @@ AdlibMusic::~AdlibMusic(void) { _mixer->stopHandle(_soundHandle); } -void AdlibMusic::premixerCall(int16 *data, uint len) { +int AdlibMusic::readBuffer(int16 *data, const int numSamples) { if (_musicData == NULL) { // no music loaded - memset(data, 0, 2 * len * sizeof(int16)); + memset(data, 0, numSamples * sizeof(int16)); } else if ((_currentMusic == 0) || (_numberOfChannels == 0)) { // music loaded but not played as of yet - memset(data, 0, 2 * len * sizeof(int16)); + memset(data, 0, numSamples * sizeof(int16)); // poll anyways as pollMusic() can activate the music pollMusic(); - _nextMusicPoll = _sampleRate/50; + _nextMusicPoll = _sampleRate / 50; } else { uint32 render; - int16 *origData = data; - uint origLen = len; - while (len) { - render = (len > _nextMusicPoll) ? (_nextMusicPoll) : (len); - len -= render; + int remaining = numSamples; + while (remaining) { + render = (remaining > _nextMusicPoll) ? (_nextMusicPoll) : (remaining); + remaining -= render; _nextMusicPoll -= render; YM3812UpdateOne(_opl, data, render); data += render; if (_nextMusicPoll == 0) { pollMusic(); - _nextMusicPoll = _sampleRate/50; + _nextMusicPoll = _sampleRate / 50; } } - - // Convert mono data to stereo - for (int i = (origLen - 1); i >= 0; i--) { - origData[2 * i] = origData[2 * i + 1] = origData[i]; - } } + return numSamples; } void AdlibMusic::setupPointers(void) { diff --git a/engines/sky/music/adlibmusic.h b/engines/sky/music/adlibmusic.h index b50157c3b5..ee98229b61 100644 --- a/engines/sky/music/adlibmusic.h +++ b/engines/sky/music/adlibmusic.h @@ -36,11 +36,8 @@ public: ~AdlibMusic(void); // AudioStream API - int readBuffer(int16 *buffer, const int numSamples) { - premixerCall(buffer, numSamples / 2); - return numSamples; - } - bool isStereo() const { return true; } + int readBuffer(int16 *buffer, const int numSamples); + bool isStereo() const { return false; } bool endOfData() const { return false; } int getRate() const { return _sampleRate; } -- cgit v1.2.3