2003-05-26 22:03:04 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2001-2006 The ScummVM project
|
2003-05-26 22:03:04 +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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-05-26 22:03:04 +00:00
|
|
|
*
|
2006-02-11 09:55:41 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-05-26 22:03:04 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLAYER_V2_H
|
|
|
|
#define PLAYER_V2_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/mutex.h"
|
2003-09-07 16:16:19 +00:00
|
|
|
#include "scumm/music.h"
|
2004-11-27 16:12:11 +00:00
|
|
|
#include "sound/audiostream.h"
|
2003-06-15 01:00:43 +00:00
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
namespace Audio {
|
|
|
|
class Mixer;
|
|
|
|
}
|
2003-10-03 18:33:57 +00:00
|
|
|
|
|
|
|
namespace Scumm {
|
|
|
|
|
|
|
|
class ScummEngine;
|
|
|
|
|
2006-07-09 13:01:15 +00:00
|
|
|
#if defined(START_PACK_STRUCTS)
|
|
|
|
#pragma START_PACK_STRUCTS
|
2005-07-30 21:11:48 +00:00
|
|
|
#endif
|
2003-05-26 22:03:04 +00:00
|
|
|
|
|
|
|
struct channel_data {
|
|
|
|
uint16 time_left; // 00
|
|
|
|
uint16 next_cmd; // 02
|
|
|
|
uint16 base_freq; // 04
|
|
|
|
uint16 freq_delta; // 06
|
|
|
|
uint16 freq; // 08
|
|
|
|
uint16 volume; // 10
|
|
|
|
uint16 volume_delta; // 12
|
|
|
|
uint16 tempo; // 14
|
|
|
|
uint16 inter_note_pause; // 16
|
|
|
|
uint16 transpose; // 18
|
|
|
|
uint16 note_length; // 20
|
|
|
|
uint16 hull_curve; // 22
|
|
|
|
uint16 hull_offset; // 24
|
|
|
|
uint16 hull_counter; // 26
|
|
|
|
uint16 freqmod_table; // 28
|
|
|
|
uint16 freqmod_offset; // 30
|
|
|
|
uint16 freqmod_incr; // 32
|
|
|
|
uint16 freqmod_multiplier; // 34
|
|
|
|
uint16 freqmod_modulo; // 36
|
2003-06-01 16:42:29 +00:00
|
|
|
uint16 unknown[4]; // 38 - 44
|
|
|
|
uint16 music_timer; // 46
|
2003-05-26 22:03:04 +00:00
|
|
|
uint16 music_script_nr; // 48
|
2006-07-21 21:25:17 +00:00
|
|
|
};
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2006-07-09 13:01:15 +00:00
|
|
|
#if defined(END_PACK_STRUCTS)
|
|
|
|
#pragma END_PACK_STRUCTS
|
2003-06-15 01:00:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-10-03 23:34:06 +00:00
|
|
|
/**
|
2003-10-05 17:32:38 +00:00
|
|
|
* Scumm V2 PC-Speaker MIDI driver.
|
|
|
|
* This simulates the pc speaker sound, which is driven by the 8253 (square
|
|
|
|
* wave generator) and a low-band filter.
|
2003-10-03 23:34:06 +00:00
|
|
|
*/
|
2006-04-29 22:33:31 +00:00
|
|
|
class Player_V2 : public Audio::AudioStream, public MusicEngine {
|
2003-05-26 22:03:04 +00:00
|
|
|
public:
|
2003-10-05 17:32:38 +00:00
|
|
|
Player_V2(ScummEngine *scumm, bool pcjr);
|
2003-08-14 02:28:19 +00:00
|
|
|
virtual ~Player_V2();
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2004-11-28 21:24:02 +00:00
|
|
|
virtual void setMusicVolume(int vol);
|
2003-10-03 13:44:12 +00:00
|
|
|
virtual void startSound(int sound);
|
|
|
|
virtual void stopSound(int sound);
|
2003-08-14 02:28:19 +00:00
|
|
|
virtual void stopAllSounds();
|
|
|
|
virtual int getMusicTimer() const;
|
2003-10-03 13:44:12 +00:00
|
|
|
virtual int getSoundStatus(int sound) const;
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2004-11-27 16:18:50 +00:00
|
|
|
// AudioStream API
|
2004-11-27 16:12:11 +00:00
|
|
|
int readBuffer(int16 *buffer, const int numSamples) {
|
|
|
|
do_mix(buffer, numSamples / 2);
|
|
|
|
return numSamples;
|
|
|
|
}
|
|
|
|
bool isStereo() const { return true; }
|
|
|
|
bool endOfData() const { return false; }
|
|
|
|
int getRate() const { return _sample_rate; }
|
|
|
|
|
2003-08-14 02:28:19 +00:00
|
|
|
protected:
|
2003-06-27 00:10:17 +00:00
|
|
|
bool _isV3Game;
|
2005-05-10 23:48:48 +00:00
|
|
|
Audio::Mixer *_mixer;
|
2004-01-08 20:37:26 +00:00
|
|
|
ScummEngine *_vm;
|
2003-05-31 16:54:46 +00:00
|
|
|
|
|
|
|
bool _pcjr;
|
2003-06-06 21:56:37 +00:00
|
|
|
int _header_len;
|
2003-05-31 16:54:46 +00:00
|
|
|
|
2003-08-05 17:52:47 +00:00
|
|
|
uint32 _sample_rate;
|
|
|
|
uint32 _next_tick;
|
|
|
|
uint32 _tick_len;
|
2003-05-31 16:54:46 +00:00
|
|
|
unsigned int _update_step;
|
|
|
|
unsigned int _decay;
|
2003-09-30 17:10:03 +00:00
|
|
|
int _level;
|
2003-05-31 16:54:46 +00:00
|
|
|
unsigned int _RNG;
|
|
|
|
unsigned int _volumetable[16];
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2003-05-31 16:54:46 +00:00
|
|
|
int _timer_count[4];
|
|
|
|
int _timer_output;
|
|
|
|
|
2003-08-14 19:41:40 +00:00
|
|
|
int _current_nr;
|
|
|
|
byte *_current_data;
|
|
|
|
int _next_nr;
|
|
|
|
byte *_next_data;
|
|
|
|
byte *_retaddr;
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2003-09-19 14:43:57 +00:00
|
|
|
private:
|
2003-10-03 23:34:06 +00:00
|
|
|
union ChannelInfo {
|
|
|
|
channel_data d;
|
|
|
|
uint16 array[sizeof(channel_data)/2];
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-09-19 14:43:57 +00:00
|
|
|
int _music_timer;
|
|
|
|
int _music_timer_ctr;
|
|
|
|
int _ticks_per_music_timer;
|
|
|
|
|
|
|
|
const uint16 *_freqs_table;
|
|
|
|
|
2005-01-28 22:05:51 +00:00
|
|
|
Common::Mutex _mutex;
|
2003-09-19 14:43:57 +00:00
|
|
|
ChannelInfo _channels[5];
|
|
|
|
|
|
|
|
protected:
|
2005-01-10 22:06:49 +00:00
|
|
|
void mutex_up();
|
|
|
|
void mutex_down();
|
2003-05-31 16:54:46 +00:00
|
|
|
|
2003-09-19 14:43:57 +00:00
|
|
|
virtual void nextTick();
|
2003-08-14 02:28:19 +00:00
|
|
|
virtual void clear_channel(int i);
|
|
|
|
virtual void chainSound(int nr, byte *data);
|
|
|
|
virtual void chainNextSound();
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2003-09-19 14:43:57 +00:00
|
|
|
virtual void generateSpkSamples(int16 *data, uint len);
|
|
|
|
virtual void generatePCjrSamples(int16 *data, uint len);
|
2003-05-31 16:54:46 +00:00
|
|
|
|
2003-08-05 17:52:47 +00:00
|
|
|
void lowPassFilter(int16 *data, uint len);
|
2003-05-31 16:54:46 +00:00
|
|
|
void squareGenerator(int channel, int freq, int vol,
|
2003-11-08 21:59:32 +00:00
|
|
|
int noiseFeedback, int16 *sample, uint len);
|
|
|
|
|
2003-09-19 14:43:57 +00:00
|
|
|
private:
|
|
|
|
void do_mix(int16 *buf, uint len);
|
|
|
|
|
|
|
|
void set_pcjr(bool pcjr);
|
|
|
|
void execute_cmd(ChannelInfo *channel);
|
|
|
|
void next_freqs(ChannelInfo *channel);
|
2003-05-26 22:03:04 +00:00
|
|
|
};
|
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
} // End of namespace Scumm
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
#endif
|