scummvm/engines/tony/sound.h

543 lines
17 KiB
C
Raw Normal View History

/* 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
2012-05-14 07:43:50 +02:00
/*
* This code is based on original Tony Tough source code
*
* Copyright (c) 1997-2003 Nayma Software
*/
#ifndef TONY_SOUND_H
#define TONY_SOUND_H
#include "audio/mixer.h"
#include "common/file.h"
#include "tony/gfxcore.h"
#include "tony/loc.h"
#include "tony/utils.h"
namespace Audio {
class RewindableAudioStream;
}
namespace Tony {
class FPSTREAM;
class FPSFX;
enum CODECS {
FPCODEC_RAW,
FPCODEC_ADPCM
};
/****************************************************************************\
*****************************************************************************
* class FPSound
* -------------
* Description: Sound driver per Falling Pumpkins
*****************************************************************************
\****************************************************************************/
class FPSOUND {
private:
bool bSoundSupported;
2012-05-21 23:53:13 +02:00
/****************************************************************************\
2012-06-12 00:07:50 +02:00
* Methods
2012-05-21 23:53:13 +02:00
\****************************************************************************/
public:
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: FPSOUND::FPSOUND();
*
2012-06-12 00:07:50 +02:00
* Description: Default constructor. Initializes the attributes
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
FPSOUND();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: FPSOUND::~FPSOUND();
*
2012-06-12 00:07:50 +02:00
* Description: Deinitialize the object, free memory
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
~FPSOUND();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
2012-06-09 18:35:08 -04:00
* Function: bool FPSOUND::Init();
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Description: Initializes the objects, and prepare everything required to
* create streams and sound effects.
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Return: True if everything is OK, False otherwise.
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-06-09 18:35:08 -04:00
bool Init();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool CreateStream(FPSTREAM** lplpStream);
*
2012-06-12 00:07:50 +02:00
* Description: Allocates an object of type FPSTREAM, and return its
* pointer after it has been initialized.
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Input: FPSTREAM** lplpStream Will contain the pointer of the
* object
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Return: True is everything i OK, False otherwise
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Note: The use of functions like CreateStream () and CreateSfx ()
* are due to the fact that the class constructors and
* FPSTREAM FPSFX require that DirectSound is already initialized.
* In this way, you avoid the bugs that would be created if an
* object type is declared FPSTREAM FPSFX or global
* (or anyway before initializing DirectSound).
2012-05-21 23:53:13 +02:00
\****************************************************************************/
bool CreateStream(FPSTREAM **lplpStream);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool CreateSfx(FPSFX** lplpSfx);
*
2012-06-12 00:07:50 +02:00
* Description: Allocates an object of type FPSFX and returns a pointer
* pointing to it
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Input: FPSFX** lplpSfx Will contain the pointer of the
* object
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Return: True is everything i OK, False otherwise
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Note: See notes about CreateStream()
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
bool CreateSfx(FPSFX **lplpSfx);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void SetMasterVolume(int dwVolume);
*
2012-06-12 00:07:50 +02:00
* Description: Set main volume
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Input: int dwVolume Volume to be set (0-63)
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
void SetMasterVolume(int dwVolume);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void GetMasterVolume(LPINT lpdwVolume);
*
2012-06-12 00:07:50 +02:00
* Description: Get main volume
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Input: LPINT lpdwVolume This variable will contain the
* current volume (0-63)
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
void GetMasterVolume(int *lpdwVolume);
};
class FPSFX {
2012-05-21 23:53:13 +02:00
/****************************************************************************\
2012-06-12 00:07:50 +02:00
* Attributes
2012-05-21 23:53:13 +02:00
\****************************************************************************/
private:
2012-06-12 00:07:50 +02:00
bool bSoundSupported; // True if the sound is active
bool bFileLoaded; // True is a file is opened
bool bLoop; // True is sound effect should loop
int lastVolume;
bool bIsVoice;
bool bPaused;
2012-06-12 11:35:27 -04:00
Audio::AudioStream *_loopStream;
Audio::RewindableAudioStream *_rewindableStream;
Audio::SoundHandle _handle;
2012-05-21 23:53:13 +02:00
public:
uint32 hEndOfBuffer;
private:
2012-05-21 23:53:13 +02:00
/****************************************************************************\
2012-06-12 00:07:50 +02:00
* Methods
2012-05-21 23:53:13 +02:00
\****************************************************************************/
public:
/**
* Check process for whether sounds have finished playing
*/
static void soundCheckProcess(CORO_PARAM, const void *param);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
2012-06-09 18:35:08 -04:00
* Function: FPSFX(bool bSoundOn);
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Description: Default constructor. *DO NOT* declare the object directly,
* create it though FPSOUND::CreateSfx() instead
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-06-09 18:35:08 -04:00
FPSFX(bool bSoundOn);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: ~FPSFX();
*
2012-06-12 00:07:50 +02:00
* Description: Default destructor. It also stops the sound effect that
* may be running, and free the memory used.
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
~FPSFX();
/****************************************************************************\
*
* Function: Release();
*
2012-06-12 00:07:50 +02:00
* Description: Releases the memory object. Must be called when the object
* is no longer useful and **ONLY** when the object was created
* with the FPSOUND :: CreateStream ().
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Note: Any object pointers are no longer valid after this call.
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-05-21 23:53:13 +02:00
void Release();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool LoadFile(char *lpszFileName, uint32 dwCodec=FPCODEC_RAW);
*
2012-06-12 00:07:50 +02:00
* Description: Opens a file and load sound effect
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Input: char *lpszFile SFX filename
* uint32 dwCodec CODEC to be used to decompress
* the sound samples
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Return: True if everything is OK, False otherwise
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
bool LoadFile(const char *lpszFileName, uint32 dwCodec = FPCODEC_RAW);
bool loadWave(Common::SeekableReadStream *stream);
bool LoadVoiceFromVDB(Common::File &vdbFP);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool Play();
*
2012-06-12 00:07:50 +02:00
* Description: Play the loaded FX.
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Return: True if everything is OK, False otherwise
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-05-21 23:53:13 +02:00
bool Play();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool Stop();
*
2012-06-12 00:07:50 +02:00
* Description: Stop a FX
2012-05-21 23:53:13 +02:00
*
2012-06-12 00:07:50 +02:00
* Return: True if everything is OK, False otherwise
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-05-21 23:53:13 +02:00
bool Stop();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void Pause(bool bPause);
*
2012-06-12 00:07:50 +02:00
* Description: Pause a FX
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-05-21 23:53:13 +02:00
void Pause(bool bPause);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool SetLoop(bool bLoop);
*
* Description: Enables or disables SFX loop
2012-05-21 23:53:13 +02:00
*
* Input: bool bLoop True to activate the loop, else False
2012-05-21 23:53:13 +02:00
*
* Note: The loop must be activated before the SFX starts to play,
* else the effect will only be noticable next time the SFX is
* played
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-05-21 23:53:13 +02:00
void SetLoop(bool bLoop);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void SetVolume(int dwVolume);
*
* Description: Set SFX Volume
2012-05-21 23:53:13 +02:00
*
* Input: int dwVolume Volume to set (0-63)
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-05-21 23:53:13 +02:00
void SetVolume(int dwVolume);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void GetVolume(int * lpdwVolume);
*
* Description: Get SFX volume
2012-05-21 23:53:13 +02:00
*
* Input: int * lpdwVolume Will contain the current volume
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-05-21 23:53:13 +02:00
void GetVolume(int *lpdwVolume);
/**
* Returns true if the sound has finished playing
*/
bool endOfBuffer() const;
};
class FPSTREAM {
2012-05-21 23:53:13 +02:00
/****************************************************************************\
* Attributes
2012-05-21 23:53:13 +02:00
\****************************************************************************/
private:
2012-05-21 23:53:13 +02:00
/*
HWND hwnd;
LPDIRECTSOUND lpDS;
LPDIRECTSOUNDBUFFER lpDSBuffer; // DirectSound circular buffer
LPDIRECTSOUNDNOTIFY lpDSNotify; // Notify hotspots in the buffer
2012-05-21 23:53:13 +02:00
*/
byte *lpTempBuffer; // Temporary buffer use for decompression
uint32 dwBufferSize; // Buffer size (bytes)
uint32 dwSize; // Stream size (bytes)
uint32 dwCodec; // CODEC used
HANDLE hThreadEnd; // Event used to close thread
Common::File _file; // File handle used for the stream
HANDLE hPlayThread; // Handle of the Play thread
HANDLE hHot1, hHot2, hHot3; // Events set by DirectSoundNotify
HANDLE hPlayThread_PlayFast;
HANDLE hPlayThread_PlayNormal;
bool bSoundSupported; // True if the sound is active
bool bFileLoaded; // True if the file is open
bool bLoop; // True if the stream should loop
bool bDoFadeOut; // True if fade out is required
bool bSyncExit;
bool bPaused;
int lastVolume;
FPSTREAM *SyncToPlay;
// DSBPOSITIONNOTIFY dspnHot[3];
bool CreateBuffer(int nBufSize);
public:
bool bIsPlaying; // True if the stream is playing
private:
static void PlayThread(FPSTREAM *This);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
* Methods
2012-05-21 23:53:13 +02:00
\****************************************************************************/
public:
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
2012-06-09 18:35:08 -04:00
* Function: FPSTREAM(bool bSoundOn);
2012-05-21 23:53:13 +02:00
*
* Description: Default contractor. *DO NOT* declare the object directly: use
* FPSOUND::CreateStream() indtead
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
2012-06-09 18:35:08 -04:00
FPSTREAM(bool bSoundOn);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: ~FPSTREAM();
*
* Description: Destructor by default. Stops the playing stream (if any) and
* frees the memory used by them
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
~FPSTREAM();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: Release();
*
* Description: Releases memory used by object. Must be used when the object
* is no longer used. *ONLY*<EFBFBD>for objects created by
* FPSOUND::CreateStream().
2012-05-21 23:53:13 +02:00
*
* Note: Object pointers are no longer valid after this call.
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
void Release();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool LoadFile(char *lpszFileName, uint32 dwCodec=FPCODEC_RAW);
*
* Description: Open a file for a stream.
2012-05-21 23:53:13 +02:00
*
* Input: char *lpszFile Filename to be opened
* uint32 dwCodec CODEC to be used to decompress
* sound samples
2012-05-21 23:53:13 +02:00
*
* Return: True if everything is OK, False otherwise
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
bool LoadFile(const char *lpszFileName, uint32 dwCodec = FPCODEC_RAW, int nSync = 2000);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: UnloadFile();
*
* Description: Close a file stream (if opened). This function must be
* called to free the memory used by the stream
2012-05-21 23:53:13 +02:00
*
* Return: Just to be sure, the destructor of this class calls
* UnloadFile() if it has not been mentioned explicitly
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
bool UnloadFile();
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool Play();
*
* Description: Play the loaded stream.
2012-05-21 23:53:13 +02:00
*
* Return: True if everything is OK, False otherwise
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
bool Play();
void PlayFast(void);
void Prefetch(void);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool Stop();
*
* Description: Stops the play of the stream.
2012-05-21 23:53:13 +02:00
*
* Return: True if everything is OK, False otherwise
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
bool Stop(bool bSync = false);
2012-05-21 23:53:13 +02:00
void WaitForSync(FPSTREAM *toplay);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void Pause(bool bPause);
*
* Description: Pause sound effect
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
void Pause(bool bPause);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: bool SetLoop(bool bLoop);
*
* Description: Enable of disable stream loop
2012-05-21 23:53:13 +02:00
*
* Input: bool bLoop True to enable loop, false otherwise
2012-05-21 23:53:13 +02:00
*
* Note: The loop must be activated BEFORE you play back the stream.
* Any changes made during play will not have 'effect until
* the stream is not stopped, and then comes back into play.
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
void SetLoop(bool bLoop);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void SetVolume(int dwVolume);
*
* Description: Change stream colume
2012-05-21 23:53:13 +02:00
*
* Input: int dwVolume Volume to be set (0-63)
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
void SetVolume(int dwVolume);
2012-05-21 23:53:13 +02:00
/****************************************************************************\
*
* Function: void GetVolume(LPINT lpdwVolume);
*
* Description: Get stream volume
2012-05-21 23:53:13 +02:00
*
* Input: LPINT lpdwVolume Will contain the current stream volume
2012-05-21 23:53:13 +02:00
*
\****************************************************************************/
void GetVolume(int *lpdwVolume);
};
} // End of namespace Tony
#endif