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 GLK_SOUND_H 24 #define GLK_SOUND_H 25 26 #include "glk/glk_types.h" 27 #include "audio/audiostream.h" 28 #include "audio/mixer.h" 29 #include "common/array.h" 30 31 namespace Glk { 32 33 #define GLK_MAXVOLUME 0x10000 34 35 class Sounds; 36 37 /** 38 * Holds the data for a playing sound 39 */ 40 class SoundChannel { 41 private: 42 Sounds *_owner; 43 uint _soundNum; 44 uint _notify; 45 Audio::SoundHandle _handle; 46 uint _defaultVolume; 47 public: 48 uint _rock; 49 gidispatch_rock_t _dispRock; 50 public: 51 /** 52 * Constructor 53 */ 54 SoundChannel(Sounds *owner, uint volume); 55 56 /** 57 * Destructor 58 */ 59 ~SoundChannel(); 60 61 /** 62 * Play a sound 63 */ 64 uint play(uint soundNum, uint repeats = 1, uint notify = 0); 65 66 /** 67 * Stop playing sound 68 */ 69 void stop(); 70 71 /** 72 * Poll for whether a playing sound was finished 73 */ 74 void poll(); 75 76 /** 77 * Change the volume 78 * @param volume Volume from 0 (silence) to 0x10000 (full volume) 79 * @param duration Optional duration for a gradual volume change 80 * @param notify If non-zero, triggers a evtype_VolumeNotify when 81 * the volume change duration finishes 82 */ 83 void setVolume(uint volume, uint duration = 0, uint notify = 0); 84 85 /** 86 * Pause playback 87 */ 88 void pause(); 89 90 /** 91 * Unpause playback 92 */ 93 void unpause(); 94 }; 95 typedef SoundChannel *schanid_t; 96 97 /** 98 * Sound manager 99 */ 100 class Sounds { 101 friend class SoundChannel; 102 private: 103 Common::Array<schanid_t> _sounds; 104 private: 105 /** 106 * Remove a sound from the sounds list 107 */ 108 void removeSound(schanid_t snd); 109 public: 110 ~Sounds(); 111 112 /** 113 * Create a new channel 114 */ 115 schanid_t create(uint rock = 0, uint volume = GLK_MAXVOLUME); 116 117 /** 118 * Used to iterate over the current list of sound channels 119 */ 120 schanid_t iterate(schanid_t chan, uint *rockptr = nullptr); 121 122 /** 123 * Poll for whether any playing sounds are finished 124 */ 125 void poll(); 126 }; 127 128 } // End of namespace Glk 129 130 #endif 131