2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2007-01-25 15:17:46 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SOUND_MODS_PAULA_H
|
|
|
|
#define SOUND_MODS_PAULA_H
|
|
|
|
|
|
|
|
#include "sound/audiostream.h"
|
|
|
|
#include "common/mutex.h"
|
|
|
|
|
|
|
|
namespace Audio {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emulation of the "Paula" Amiga music chip
|
|
|
|
* The interrupt frequency specifies the number of mixed wavesamples between
|
|
|
|
* calls of the interrupt method
|
|
|
|
*/
|
|
|
|
class Paula : public AudioStream {
|
|
|
|
public:
|
2007-01-26 11:47:26 +00:00
|
|
|
static const int NUM_VOICES = 4;
|
|
|
|
|
2007-01-25 15:17:46 +00:00
|
|
|
Paula(bool stereo = false, int rate = 44100, int interruptFreq = 0);
|
|
|
|
~Paula();
|
2007-02-18 21:46:40 +00:00
|
|
|
|
2007-01-25 15:17:46 +00:00
|
|
|
bool playing() const { return _playing; }
|
2007-05-19 12:06:51 +00:00
|
|
|
void setInterruptFreq(int freq) { _curInt = _intFreq = freq; }
|
2007-01-26 11:47:26 +00:00
|
|
|
void setPanning(byte voice, byte panning) {
|
|
|
|
assert(voice < NUM_VOICES);
|
|
|
|
_voice[voice].panning = panning;
|
2007-01-25 15:17:46 +00:00
|
|
|
}
|
|
|
|
void clearVoice(byte voice);
|
2007-01-26 11:47:26 +00:00
|
|
|
void clearVoices() { for (int i = 0; i < NUM_VOICES; ++i) clearVoice(i); }
|
2007-06-24 11:40:00 +00:00
|
|
|
void startPlay(void) { _playing = true; }
|
|
|
|
void stopPlay(void) { _playing = false; }
|
|
|
|
void pausePlay(bool pause) { _playing = !pause; }
|
2007-01-25 15:17:46 +00:00
|
|
|
|
|
|
|
// AudioStream API
|
|
|
|
int readBuffer(int16 *buffer, const int numSamples);
|
|
|
|
bool isStereo() const { return _stereo; }
|
|
|
|
bool endOfData() const { return _end; }
|
|
|
|
int getRate() const { return _rate; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct Channel {
|
2007-02-18 21:46:40 +00:00
|
|
|
const int8 *data;
|
|
|
|
const int8 *dataRepeat;
|
2007-01-25 15:17:46 +00:00
|
|
|
uint32 length;
|
|
|
|
uint32 lengthRepeat;
|
|
|
|
int16 period;
|
|
|
|
byte volume;
|
|
|
|
double offset;
|
|
|
|
byte panning; // For stereo mixing: 0 = far left, 255 = far right
|
2007-01-26 11:47:26 +00:00
|
|
|
} _voice[NUM_VOICES];
|
2007-01-25 15:17:46 +00:00
|
|
|
|
|
|
|
int _rate;
|
|
|
|
int _intFreq;
|
|
|
|
int _curInt;
|
|
|
|
bool _stereo;
|
|
|
|
bool _end;
|
|
|
|
bool _playing;
|
|
|
|
Common::Mutex _mutex;
|
|
|
|
|
|
|
|
void mix(int16 *&buf, int8 data, int voice) {
|
2007-01-26 11:47:26 +00:00
|
|
|
const int32 tmp = ((int32) data) * _voice[voice].volume;
|
2007-01-25 15:17:46 +00:00
|
|
|
if (_stereo) {
|
2007-01-26 11:47:26 +00:00
|
|
|
*buf++ += (tmp * (255 - _voice[voice].panning)) >> 7;
|
|
|
|
*buf++ += (tmp * (_voice[voice].panning)) >> 7;
|
2007-01-25 15:17:46 +00:00
|
|
|
} else
|
2007-01-26 11:47:26 +00:00
|
|
|
*buf++ += tmp;
|
2007-01-25 15:17:46 +00:00
|
|
|
}
|
2007-04-26 19:08:53 +00:00
|
|
|
virtual void interrupt(void) {}
|
2007-01-25 15:17:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Audio
|
|
|
|
|
|
|
|
#endif
|