ScummVM API documentation
player_mac.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 #ifndef SCUMM_PLAYERS_PLAYER_MAC_H
23 #define SCUMM_PLAYERS_PLAYER_MAC_H
24 
25 #include "common/scummsys.h"
26 #include "common/util.h"
27 #include "common/mutex.h"
28 #include "scumm/music.h"
29 #include "audio/audiostream.h"
30 #include "audio/mixer.h"
31 
32 #define RES_SND MKTAG('s', 'n', 'd', ' ')
33 
34 class Mixer;
35 
36 namespace Scumm {
37 
38 class ScummEngine;
39 
43 class Player_Mac : public Audio::AudioStream, public MusicEngine {
44 public:
45  Player_Mac(ScummEngine *scumm, Audio::Mixer *mixer, int numberOfChannels, int channelMask, bool fadeNoteEnds);
46  ~Player_Mac() override;
47 
48  void init(const Common::Path &instrumentFile);
49 
50  // MusicEngine API
51  void setMusicVolume(int vol) override;
52  void startSound(int sound) override;
53  void stopSound(int sound) override;
54  void stopAllSounds() override;
55  int getMusicTimer() override;
56  int getSoundStatus(int sound) const override;
57 
58  // AudioStream API
59  int readBuffer(int16 *buffer, const int numSamples) override;
60  bool isStereo() const override { return false; }
61  bool endOfData() const override { return false; }
62  int getRate() const override { return _sampleRate; }
63 
64  void saveLoadWithSerializer(Common::Serializer &ser) override;
65 
66 private:
67  Common::Mutex _mutex;
68  Audio::Mixer *const _mixer;
69  Audio::SoundHandle _soundHandle;
70  uint32 _sampleRate;
71  int _soundPlaying;
72 
73  void stopAllSounds_Internal();
74 
75  struct Instrument {
76  byte *_data;
77  uint32 _size;
78  uint32 _rate;
79  uint32 _loopStart;
80  uint32 _loopEnd;
81  byte _baseFreq;
82 
83  uint _pos;
84  uint _subPos;
85 
86  void newNote() {
87  _pos = 0;
88  _subPos = 0;
89  }
90 
91  void generateSamples(int16 *data, int pitchModifier, int volume, int numSamples, int remainingSamplesOnNote, bool fadeNoteEnds);
92  };
93  friend void syncWithSerializer(Common::Serializer &, Instrument &);
94 
95  int _pitchTable[128];
96  int _numberOfChannels;
97  int _channelMask;
98  bool _fadeNoteEnds;
99 
100  virtual bool loadMusic(const byte *ptr) { return false; }
101  virtual bool getNextNote(int ch, uint32 &samples, int &pitchModifier, byte &velocity) { return false; }
102 
103 protected:
104  struct Channel {
105  virtual ~Channel() {}
106 
107  Instrument _instrument;
108  bool _looped;
109  uint32 _length;
110  const byte *_data;
111 
112  uint _pos;
113  int _pitchModifier;
114  byte _velocity;
115  uint32 _remaining;
116 
117  bool _notesLeft;
118 
119  bool loadInstrument(Common::SeekableReadStream *stream);
120  };
121  friend void syncWithSerializer(Common::Serializer &, Channel &);
122 
123  ScummEngine *const _vm;
124  Common::Path _instrumentFile;
125  Channel *_channel;
126 
127  uint32 _lastVersionBeforeSaveFormatChange;
128 
129  uint32 durationToSamples(uint16 duration);
130  int noteToPitchModifier(byte note, Instrument *instrument);
131  void overrideChannelMask(int newMask);
132 };
133 
134 } // End of namespace Scumm
135 
136 #endif
void stopSound(int sound) override
Definition: player_mac.h:43
Definition: path.h:52
void setMusicVolume(int vol) override
Definition: music.h:40
Definition: stream.h:745
int getRate() const override
Definition: player_mac.h:62
Definition: serializer.h:79
Definition: scumm.h:518
int getMusicTimer() override
Definition: mixer.h:49
void stopAllSounds() override
Definition: mixer.h:59
int readBuffer(int16 *buffer, const int numSamples) override
Definition: mutex.h:67
Definition: audiostream.h:50
void startSound(int sound) override
Definition: player_mac.h:104
bool isStereo() const override
Definition: player_mac.h:60
void saveLoadWithSerializer(Common::Serializer &ser) override
bool endOfData() const override
Definition: player_mac.h:61
Definition: actor.h:30
int getSoundStatus(int sound) const override