scummvm/sound/mixer.h

156 lines
4.0 KiB
C
Raw Normal View History

/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001-2003 The ScummVM project
*
* 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 2
* of the License, or (at your option) any later version.
* 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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#ifndef MIXER_H
#define MIXER_H
2003-05-18 13:39:02 +00:00
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#ifdef USE_MAD
#include <mad.h>
#endif
#ifdef USE_VORBIS
#include <vorbis/vorbisfile.h>
#endif
#include "stdafx.h"
#include "common/scummsys.h"
#include "common/system.h"
2003-06-15 01:56:47 +00:00
typedef uint32 PlayingSoundHandle;
2002-08-24 15:31:37 +00:00
class Channel;
class File;
2003-06-21 19:52:12 +00:00
class SoundMixer;
// TODO: class Channel should really be declared non-public, inside mixer.cpp
// However, right now Sound::updateMP3CD directly calls soundFinished. That
// should be changed, by adding proper API abstraction to SoundMixer for
// MP3/Vorbis "CD" playback.
2003-06-15 01:56:47 +00:00
class Channel {
2003-06-21 19:52:12 +00:00
protected:
SoundMixer *_mixer;
2003-06-15 01:56:47 +00:00
public:
bool _toBeDestroyed;
int _id;
2003-06-21 19:52:12 +00:00
Channel() : _mixer(0), _toBeDestroyed(false), _id(-1) {}
2003-06-15 01:56:47 +00:00
virtual void mix(int16 *data, uint len) = 0;
void destroy() {
_toBeDestroyed = true;
}
virtual void realDestroy() = 0;
virtual bool soundFinished();
};
2003-06-15 01:56:47 +00:00
class SoundMixer {
public:
typedef void PremixProc (void *param, int16 *data, uint len);
2003-06-15 01:56:47 +00:00
enum {
NUM_CHANNELS = 16
};
2003-06-15 01:56:47 +00:00
private:
2003-03-06 18:30:44 +00:00
static void onGenerateSamples(void *s, byte *samples, int len);
2003-03-06 18:30:44 +00:00
OSystem *_syst;
void *_mutex;
2002-07-07 18:04:03 +00:00
2003-06-15 01:56:47 +00:00
void *_premixParam;
PremixProc *_premixProc;
PlayingSoundHandle *_handles[NUM_CHANNELS];
public:
2002-08-24 15:31:37 +00:00
uint _outputRate;
2003-03-06 18:30:44 +00:00
int16 *_volumeTable;
2002-08-24 15:31:37 +00:00
int _musicVolume;
bool _paused;
2003-03-06 18:30:44 +00:00
Channel *_channels[NUM_CHANNELS];
2003-06-15 01:56:47 +00:00
public:
SoundMixer();
~SoundMixer();
2002-12-25 00:36:04 +00:00
// start playing a raw sound
enum {
2002-12-25 00:36:04 +00:00
// Do *NOT* change any of these flags without looking at the code in mixer.cpp
FLAG_UNSIGNED = 1 << 0, // unsigned samples
FLAG_STEREO = 1 << 1, // sound is in stereo
FLAG_16BITS = 1 << 2, // sound is 16 bits wide
FLAG_AUTOFREE = 1 << 3, // sound buffer is freed automagically at the end of playing
FLAG_REVERSE_STEREO = 1 << 4, // sound should be reverse stereo
FLAG_LOOP = 1 << 5 // loop the audio
};
int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1);
int playStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size);
#ifdef USE_MAD
2003-03-06 18:30:44 +00:00
int playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
int playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration);
#endif
#ifdef USE_VORBIS
2003-03-06 18:30:44 +00:00
int playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track);
#endif
2003-06-15 01:56:47 +00:00
/** Premix procedure, useful when using fmopl adlib */
2002-08-24 15:31:37 +00:00
void setupPremix(void * param, PremixProc * proc);
2003-06-15 01:56:47 +00:00
/** mix */
2002-08-24 15:31:37 +00:00
void mix(int16 * buf, uint len);
2003-06-15 01:56:47 +00:00
/** stop all currently playing sounds */
2002-08-24 15:31:37 +00:00
void stopAll();
2003-06-15 01:56:47 +00:00
/** stop playing a specific sound */
void stop(int index);
2003-06-15 01:56:47 +00:00
/** stop playing a specific sound */
void stopID(int id);
2003-06-15 01:56:47 +00:00
/** append to existing sound */
int append(int index, void * sound, uint32 size);
2003-06-15 01:56:47 +00:00
/** is any channel active? */
2002-08-24 15:31:37 +00:00
bool hasActiveChannel();
2003-06-15 01:56:47 +00:00
/** bind to the OSystem object => mixer will be
* invoked automatically when samples need
* to be generated */
2002-08-24 15:31:37 +00:00
bool bindToSystem(OSystem *syst);
2003-06-15 01:56:47 +00:00
/** set the volume, 0-256 */
2002-08-24 15:31:37 +00:00
void setVolume(int volume);
void setMusicVolume(int volume);
2003-06-15 01:56:47 +00:00
/** pause - unpause */
void pause(bool paused);
private:
int insertAt(PlayingSoundHandle *handle, int index, Channel *chan);
};
#endif