2018-12-08 05:52:24 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2021-12-26 17:47:58 +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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2018-12-08 05:52:24 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-12-08 05:52:24 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GLK_SOUND_H
|
|
|
|
#define GLK_SOUND_H
|
|
|
|
|
|
|
|
#include "glk/glk_types.h"
|
|
|
|
#include "audio/audiostream.h"
|
2018-12-08 19:37:37 +00:00
|
|
|
#include "audio/mixer.h"
|
2018-12-08 05:52:24 +00:00
|
|
|
#include "common/array.h"
|
|
|
|
|
|
|
|
namespace Glk {
|
|
|
|
|
2019-11-25 04:30:37 +00:00
|
|
|
#define GLK_MAXVOLUME 0x10000
|
|
|
|
|
2018-12-08 05:52:24 +00:00
|
|
|
class Sounds;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the data for a playing sound
|
|
|
|
*/
|
2018-12-08 19:37:37 +00:00
|
|
|
class SoundChannel {
|
|
|
|
private:
|
2018-12-08 05:52:24 +00:00
|
|
|
Sounds *_owner;
|
2018-12-09 19:36:20 +00:00
|
|
|
uint _soundNum;
|
|
|
|
uint _notify;
|
2018-12-08 19:37:37 +00:00
|
|
|
Audio::SoundHandle _handle;
|
2019-11-25 04:30:37 +00:00
|
|
|
uint _defaultVolume;
|
2018-12-08 19:37:37 +00:00
|
|
|
public:
|
2018-12-09 19:36:20 +00:00
|
|
|
uint _rock;
|
2019-04-15 01:43:30 +00:00
|
|
|
gidispatch_rock_t _dispRock;
|
2018-12-08 19:37:37 +00:00
|
|
|
public:
|
2018-12-08 05:52:24 +00:00
|
|
|
/**
|
2018-12-08 19:37:37 +00:00
|
|
|
* Constructor
|
2018-12-08 05:52:24 +00:00
|
|
|
*/
|
2019-11-25 04:30:37 +00:00
|
|
|
SoundChannel(Sounds *owner, uint volume);
|
2018-12-08 05:52:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
~SoundChannel();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Play a sound
|
|
|
|
*/
|
2018-12-09 19:36:20 +00:00
|
|
|
uint play(uint soundNum, uint repeats = 1, uint notify = 0);
|
2018-12-08 19:37:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop playing sound
|
|
|
|
*/
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Poll for whether a playing sound was finished
|
|
|
|
*/
|
|
|
|
void poll();
|
2018-12-09 04:22:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the volume
|
|
|
|
* @param volume Volume from 0 (silence) to 0x10000 (full volume)
|
|
|
|
* @param duration Optional duration for a gradual volume change
|
|
|
|
* @param notify If non-zero, triggers a evtype_VolumeNotify when
|
|
|
|
* the volume change duration finishes
|
|
|
|
*/
|
|
|
|
void setVolume(uint volume, uint duration = 0, uint notify = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause playback
|
|
|
|
*/
|
|
|
|
void pause();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unpause playback
|
|
|
|
*/
|
|
|
|
void unpause();
|
2018-12-08 05:52:24 +00:00
|
|
|
};
|
|
|
|
typedef SoundChannel *schanid_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sound manager
|
|
|
|
*/
|
|
|
|
class Sounds {
|
2018-12-08 19:37:37 +00:00
|
|
|
friend class SoundChannel;
|
2018-12-08 05:52:24 +00:00
|
|
|
private:
|
|
|
|
Common::Array<schanid_t> _sounds;
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Remove a sound from the sounds list
|
|
|
|
*/
|
|
|
|
void removeSound(schanid_t snd);
|
|
|
|
public:
|
|
|
|
~Sounds();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new channel
|
|
|
|
*/
|
2019-11-25 04:30:37 +00:00
|
|
|
schanid_t create(uint rock = 0, uint volume = GLK_MAXVOLUME);
|
2018-12-08 05:52:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to iterate over the current list of sound channels
|
|
|
|
*/
|
2018-12-09 19:36:20 +00:00
|
|
|
schanid_t iterate(schanid_t chan, uint *rockptr = nullptr);
|
2018-12-08 19:37:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Poll for whether any playing sounds are finished
|
|
|
|
*/
|
|
|
|
void poll();
|
2018-12-08 05:52:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Glk
|
|
|
|
|
|
|
|
#endif
|