1 /* ScummVM - Graphic Adventure Engine
2  *
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.
6  *
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.
11  *
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.
16  *
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.
20  *
21  */
22 
23 #ifndef SCUMM_PLAYERS_PLAYER_V2_H
24 #define SCUMM_PLAYERS_PLAYER_V2_H
25 
26 #include "scumm/players/player_v2base.h"
27 
28 namespace Scumm {
29 
30 /**
31  * Scumm V2 PC-Speaker MIDI driver.
32  * This simulates the pc speaker sound, which is driven  by the 8253 (square
33  * wave generator) and a low-band filter.
34  */
35 class Player_V2 : public Player_V2Base {
36 public:
37 	Player_V2(ScummEngine *scumm, Audio::Mixer *mixer, bool pcjr);
38 	~Player_V2() override;
39 
40 	// MusicEngine API
41 	void setMusicVolume(int vol) override;
42 	void startSound(int sound) override;
43 	void stopSound(int sound) override;
44 	void stopAllSounds() override;
45 //	virtual int  getMusicTimer();
46 	int  getSoundStatus(int sound) const override;
47 
48 	// AudioStream API
49 	int readBuffer(int16 *buffer, const int numSamples) override;
50 
51 protected:
52 	unsigned int _update_step;
53 	unsigned int _decay;
54 	int _level;
55 	unsigned int _RNG;
56 	unsigned int _volumetable[16];
57 
58 	int _timer_count[4];
59 	int _timer_output;
60 
61 protected:
62 	virtual void generateSpkSamples(int16 *data, uint len);
63 	virtual void generatePCjrSamples(int16 *data, uint len);
64 
65 	void lowPassFilter(int16 *data, uint len);
66 	void squareGenerator(int channel, int freq, int vol,
67 						int noiseFeedback, int16 *sample, uint len);
68 };
69 
70 } // End of namespace Scumm
71 
72 #endif
73