1
/* ScummVM - Graphic Adventure Engine
3
* ScummVM is the legal property of its developers, whose names
4
* are too numerous to list here. Please refer to the COPYRIGHT
5
* file distributed with this source distribution.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
#ifndef SOUND_MODS_PAULA_H
27
#define SOUND_MODS_PAULA_H
29
#include "audio/audiostream.h"
30
#include "common/frac.h"
31
#include "common/mutex.h"
36
* Emulation of the "Paula" Amiga music chip
37
* The interrupt frequency specifies the number of mixed wavesamples between
38
* calls of the interrupt method
40
class Paula : public AudioStream {
42
static const int NUM_VOICES = 4;
44
kPalSystemClock = 7093790,
45
kNtscSystemClock = 7159090,
46
kPalCiaClock = kPalSystemClock / 10,
47
kNtscCiaClock = kNtscSystemClock / 10,
48
kPalPaulaClock = kPalSystemClock / 2,
49
kNtscPauleClock = kNtscSystemClock / 2
52
/* TODO: Document this */
54
uint int_off; // integral part of the offset
55
frac_t rem_off; // fractional part of the offset, at least 0 and less than 1
57
explicit Offset(int off = 0) : int_off(off), rem_off(0) {}
60
Paula(bool stereo = false, int rate = 44100, uint interruptFreq = 0);
63
bool playing() const { return _playing; }
64
void setTimerBaseValue( uint32 ticksPerSecond ) { _timerBase = ticksPerSecond; }
65
uint32 getTimerBaseValue() { return _timerBase; }
66
void setSingleInterrupt(uint sampleDelay) { assert(sampleDelay < _intFreq); _curInt = sampleDelay; }
67
void setSingleInterruptUnscaled(uint timerDelay) {
68
setSingleInterrupt((uint)(((double)timerDelay * getRate()) / _timerBase));
70
void setInterruptFreq(uint sampleDelay) { _intFreq = sampleDelay; _curInt = 0; }
71
void setInterruptFreqUnscaled(uint timerDelay) {
72
setInterruptFreq((uint)(((double)timerDelay * getRate()) / _timerBase));
74
void clearVoice(byte voice);
75
void clearVoices() { for (int i = 0; i < NUM_VOICES; ++i) clearVoice(i); }
76
void startPlay() { _playing = true; }
77
void stopPlay() { _playing = false; }
78
void pausePlay(bool pause) { _playing = !pause; }
81
int readBuffer(int16 *buffer, const int numSamples);
82
bool isStereo() const { return _stereo; }
83
bool endOfData() const { return _end; }
84
int getRate() const { return _rate; }
89
const int8 *dataRepeat;
95
byte panning; // For stereo mixing: 0 = far left, 255 = far right
100
Common::Mutex _mutex;
102
virtual void interrupt() = 0;
114
void setChannelPanning(byte channel, byte panning) {
115
assert(channel < NUM_VOICES);
116
_voice[channel].panning = panning;
119
void disableChannel(byte channel) {
120
assert(channel < NUM_VOICES);
121
_voice[channel].data = 0;
124
void enableChannel(byte channel) {
125
assert(channel < NUM_VOICES);
126
Channel &ch = _voice[channel];
127
ch.data = ch.dataRepeat;
128
ch.length = ch.lengthRepeat;
129
// actually first 2 bytes are dropped?
130
ch.offset = Offset(0);
131
// ch.period = ch.periodRepeat;
134
void setChannelPeriod(byte channel, int16 period) {
135
assert(channel < NUM_VOICES);
136
_voice[channel].period = period;
139
void setChannelVolume(byte channel, byte volume) {
140
assert(channel < NUM_VOICES);
141
_voice[channel].volume = volume;
144
void setChannelSampleStart(byte channel, const int8 *data) {
145
assert(channel < NUM_VOICES);
146
_voice[channel].dataRepeat = data;
149
void setChannelSampleLen(byte channel, uint32 length) {
150
assert(channel < NUM_VOICES);
151
assert(length < 32768/2);
152
_voice[channel].lengthRepeat = 2 * length;
155
void setChannelData(uint8 channel, const int8 *data, const int8 *dataRepeat, uint32 length, uint32 lengthRepeat, int32 offset = 0) {
156
assert(channel < NUM_VOICES);
158
Channel &ch = _voice[channel];
160
ch.dataRepeat = data;
161
ch.lengthRepeat = length;
162
enableChannel(channel);
163
ch.offset = Offset(offset);
165
ch.dataRepeat = dataRepeat;
166
ch.lengthRepeat = lengthRepeat;
169
void setChannelOffset(byte channel, Offset offset) {
170
assert(channel < NUM_VOICES);
171
_voice[channel].offset = offset;
174
Offset getChannelOffset(byte channel) {
175
assert(channel < NUM_VOICES);
176
return _voice[channel].offset;
179
int getChannelDmaCount(byte channel) {
180
assert(channel < NUM_VOICES);
181
return _voice[channel].dmaCount;
184
void setChannelDmaCount(byte channel, int dmaVal = 0) {
185
assert(channel < NUM_VOICES);
186
_voice[channel].dmaCount = dmaVal;
189
void setAudioFilter(bool enable) {
194
Channel _voice[NUM_VOICES];
198
const double _periodScale;
204
template<bool stereo>
205
int readBufferIntern(int16 *buffer, const int numSamples);
208
} // End of namespace Audio