ScummVM API documentation
sound.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on original Hugo Trilogy source code
24  *
25  * Copyright (c) 1989-1995 David P. Gray
26  *
27  */
28 
29 #ifndef HUGO_SOUND_H
30 #define HUGO_SOUND_H
31 
32 #include "audio/mixer.h"
33 #include "audio/midiplayer.h"
34 
35 namespace Audio {
36 class PCSpeaker;
37 }
38 
39 namespace Hugo {
40 
41 class MidiPlayer : public Audio::MidiPlayer {
42 public:
43  MidiPlayer();
44 
45  void pause(bool p);
46  void play(uint8 *stream, uint16 size);
47 
48  // The following line prevents compiler warnings about hiding the pause()
49  // method from the parent class.
50  // FIXME: Maybe the pause(bool p) method should be removed and the
51  // pause/resume methods of the parent class be used instead?
52  void pause() override { Audio::MidiPlayer::pause(); }
53 
54  uint32 getBaseTempo();
55 
56  // Overload Audio::MidiPlayer method
57  void sendToChannel(byte channel, uint32 b) override;
58  void onTimer() override;
59 
60 private:
61  bool _paused;
62 };
63 
64 class SoundHandler {
65 public:
67  ~SoundHandler();
68 
69  static const int kHugoCNT = 1190000;
70 
71  int8 _pcspkrTimer; // Timer (ticks) for note being played
72  int8 _pcspkrOctave; // Current octave 1..7
73  int8 _pcspkrNoteDuration; // Current length of note (ticks)
74 
75  const char *_DOSSongPtr;
76  const char *_DOSIntroSong;
77 
78  void toggleMusic();
79  void toggleSound();
80  void setMusicVolume();
81  static void loopPlayer(void *refCon);
82  void pcspkr_player();
83  void playMusic(int16 tune);
84  void playSound(int16 sound, const byte priority);
85  void initSound();
86  void syncVolume();
87  void checkMusic();
88  void loadIntroSong(Common::ReadStream &in);
89  void initPcspkrPlayer();
90 protected:
91  byte _curPriority; // Priority of currently playing sound
92 
93 private:
94  HugoEngine *_vm;
95  Audio::SoundHandle _soundHandle;
96  MidiPlayer *_midiPlayer;
97  Audio::PCSpeaker *_speakerStream;
98  Audio::SoundHandle _speakerHandle;
99 
100  void stopSound();
101  void stopMusic();
102  void playMIDI(SoundPtr seqPtr, uint16 size);
103 };
104 
105 } // End of namespace Hugo
106 
107 #endif //HUGO_SOUND_H
Definition: midiplayer.h:63
Definition: console.h:27
Definition: mixer.h:49
Definition: sound.h:41
Definition: stream.h:385
Definition: hugo.h:210
Definition: sound.h:64
Definition: pcspk.h:31
Definition: system.h:38