Initial commit
This commit is contained in:
121
engines/icb/sound/direct_sound.cpp
Normal file
121
engines/icb/sound/direct_sound.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/icb/sound/direct_sound.h"
|
||||
#include "engines/icb/sound/music_manager.h"
|
||||
#include "engines/icb/sound/speech_manager.h"
|
||||
#include "engines/icb/sound/fx_manager.h"
|
||||
#include "engines/icb/sound.h"
|
||||
#include "engines/icb/icb.h"
|
||||
|
||||
#include "audio/mixer.h"
|
||||
|
||||
#include "common/system.h"
|
||||
#include "common/timer.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
MusicManager *g_theMusicManager = nullptr;
|
||||
SpeechManager *g_theSpeechManager = nullptr;
|
||||
FxManager *g_theFxManager = nullptr;
|
||||
bool8 g_TimerOn = TRUE8;
|
||||
|
||||
Common::TimerManager::TimerProc g_timer_id;
|
||||
|
||||
void SoundEngineTimer(void *ignored) {
|
||||
if (g_TimerOn) {
|
||||
UpdateSounds10Hz();
|
||||
Poll_Sound_Engine();
|
||||
}
|
||||
}
|
||||
|
||||
bool8 Init_Sound_Engine() {
|
||||
// Create a timer to poll the sound engine at 100 millisecond intervals
|
||||
g_system->getTimerManager()->installTimerProc(SoundEngineTimer, 100 * 1000, nullptr, "SoundEngineTimer");
|
||||
|
||||
// Initalize the other sections (ie music, fx and speech)
|
||||
g_theMusicManager = new MusicManager();
|
||||
g_theSpeechManager = new SpeechManager();
|
||||
g_theFxManager = new FxManager;
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
bool8 Close_Sound_Engine() {
|
||||
// Kill the sound engine timer
|
||||
g_system->getTimerManager()->removeTimerProc(g_timer_id);
|
||||
|
||||
// Destroy the fx manager
|
||||
if (g_theFxManager) {
|
||||
delete g_theFxManager;
|
||||
g_theFxManager = nullptr;
|
||||
}
|
||||
|
||||
// Destroy the music manager
|
||||
if (g_theMusicManager) {
|
||||
delete g_theMusicManager;
|
||||
g_theMusicManager = nullptr;
|
||||
}
|
||||
|
||||
// Destroy the speech manager
|
||||
if (g_theSpeechManager) {
|
||||
delete g_theSpeechManager;
|
||||
g_theSpeechManager = nullptr;
|
||||
}
|
||||
g_icb->_mixer->stopAll();
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
bool8 Poll_Sound_Engine() {
|
||||
// Refresh the music streams
|
||||
if (g_theMusicManager) {
|
||||
if (!g_theMusicManager->UpdateMusic()) {
|
||||
// Shutdown if we fail - not elegant but safe
|
||||
Close_Sound_Engine();
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh the speech streams
|
||||
if (g_theSpeechManager) {
|
||||
if (!g_theSpeechManager->UpdateSpeech()) {
|
||||
// Shutdown if we fail - not elegant but safe
|
||||
Close_Sound_Engine();
|
||||
}
|
||||
}
|
||||
|
||||
// Poll the sound fx manager
|
||||
if (g_theFxManager) {
|
||||
if (!g_theFxManager->Poll()) {
|
||||
// Shutdown if we fail - not elegant but safe
|
||||
Close_Sound_Engine();
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
} // End of namespace ICB
|
||||
53
engines/icb/sound/direct_sound.h
Normal file
53
engines/icb/sound/direct_sound.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ICB_DIRECT_SOUND_H__
|
||||
#define ICB_DIRECT_SOUND_H__
|
||||
|
||||
#include "engines/icb/common/px_common.h"
|
||||
#include "engines/icb/common/px_types.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
class MusicManager;
|
||||
class SpeechManager;
|
||||
class FxManager;
|
||||
|
||||
#define MAX_FX 24 // 16 Sound Effects channels
|
||||
|
||||
extern SpeechManager *g_theSpeechManager;
|
||||
extern FxManager *g_theFxManager;
|
||||
extern bool8 g_TimerOn;
|
||||
|
||||
bool8 Init_Sound_Engine(); // Setup the sound engine
|
||||
bool8 Close_Sound_Engine(); // Shutdown the sound engine
|
||||
|
||||
// This is called ten times a second on an internal timer
|
||||
bool8 Poll_Sound_Engine(); // Updates the sound engine
|
||||
|
||||
} // End of namespace ICB
|
||||
|
||||
#endif //__DIRECT_SOUND_H__
|
||||
312
engines/icb/sound/fx_manager.cpp
Normal file
312
engines/icb/sound/fx_manager.cpp
Normal file
@@ -0,0 +1,312 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/icb/sound/fx_manager.h"
|
||||
#include "engines/icb/p4.h"
|
||||
#include "engines/icb/res_man_pc.h"
|
||||
#include "engines/icb/sound/sound_common.h"
|
||||
#include "engines/icb/icb.h"
|
||||
#include "engines/icb/global_objects.h"
|
||||
|
||||
#include "common/textconsole.h"
|
||||
|
||||
#include "audio/decoders/wave.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
// externals
|
||||
extern _stub stub;
|
||||
|
||||
bool8 noSoundEngine = FALSE8;
|
||||
|
||||
// Nearest integer macro
|
||||
#define NEAREST_INT(X) (X) > 0.0 ? int((X) + 0.5) : int((X)-0.5)
|
||||
|
||||
FxManager::FxManager() {
|
||||
for (int32 id = 0; id < MAX_FX; id++) {
|
||||
memset(m_effects[id].name, 0, SAMPLE_NAME_LENGTH);
|
||||
m_effects[id].flags = Effect::EMPTY;
|
||||
m_effects[id].delay = 0;
|
||||
m_effects[id].looped = 0;
|
||||
m_effects[id].pitch = 0;
|
||||
m_effects[id].pan = 0;
|
||||
m_effects[id].volume = 0;
|
||||
m_effects[id]._stream = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FxManager::~FxManager() {
|
||||
// Remove any memory resident sounds
|
||||
UnregisterAll();
|
||||
}
|
||||
|
||||
bool8 FxManager::Poll() {
|
||||
if (noSoundEngine)
|
||||
return TRUE8;
|
||||
|
||||
// Update all buffers
|
||||
for (int32 id = 0; id < MAX_FX; id++) {
|
||||
switch (m_effects[id].flags) {
|
||||
// If it's playing check it hasn't finished
|
||||
case Effect::PLAYING:
|
||||
// Apply current settings
|
||||
if (g_icb->_mixer->isSoundHandleActive(m_effects[id]._handle)) {
|
||||
float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
|
||||
g_icb->_mixer->setChannelVolume(m_effects[id]._handle, m_effects[id].volume * volumeConversion);
|
||||
g_icb->_mixer->setChannelBalance(m_effects[id]._handle, m_effects[id].pan);
|
||||
|
||||
// FIXME correct pitch control
|
||||
//uint32 frequency = (m_effects[id].pitch * g_stub->cycle_speed) / 100;
|
||||
//m_effects[id].buffer->SetFrequency( frequency ) ;
|
||||
//alSourcef(m_effects[id].alStream.source, AL_PITCH, 1.0f);
|
||||
}
|
||||
|
||||
if (!g_icb->_mixer->isSoundHandleActive(m_effects[id]._handle)) {
|
||||
// Finished playing so ready to go again
|
||||
m_effects[id].flags = Effect::READY;
|
||||
}
|
||||
break;
|
||||
|
||||
// It's currently delayed
|
||||
case Effect::DELAYED:
|
||||
|
||||
m_effects[id].delay--;
|
||||
if (m_effects[id].delay != 0)
|
||||
break;
|
||||
// falls through
|
||||
|
||||
// It's waiting to play
|
||||
case Effect::QUEUED: {
|
||||
|
||||
// Apply current settings
|
||||
// FIXME correct pitch control
|
||||
//uint32 frequency = (m_effects[id].pitch * g_stub->cycle_speed) / 100;
|
||||
//m_effects[id].buffer->SetFrequency( frequency ) ;
|
||||
//alSourcef(m_effects[id].alStream.source, AL_PITCH, 1.0f);
|
||||
|
||||
// So play it
|
||||
float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
|
||||
g_icb->_mixer->playStream(Audio::Mixer::kSFXSoundType, &m_effects[id]._handle,
|
||||
makeLoopingAudioStream(m_effects[id]._stream, (m_effects[id].looped != 0) ? 0 : 1),
|
||||
-1, m_effects[id].volume * volumeConversion, m_effects[id].pan, DisposeAfterUse::NO);
|
||||
m_effects[id].flags = Effect::PLAYING;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
int32 FxManager::Register(const int32 id, const char *name, const int32 delay, uint32 byteOffsetInCluster) {
|
||||
if (noSoundEngine)
|
||||
return 0;
|
||||
|
||||
// Create the sound buffers
|
||||
if (!Load(id, name, byteOffsetInCluster)) {
|
||||
warning("sounds.txt: can't load \"%s\"", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Record the samples name so we know it is currently loaded in memory
|
||||
Common::strcpy_s(m_effects[id].name, name);
|
||||
|
||||
// Setup the delay if there is one
|
||||
m_effects[id].delay = delay;
|
||||
|
||||
if (delay)
|
||||
m_effects[id].flags = Effect::DELAYED;
|
||||
else
|
||||
m_effects[id].flags = Effect::READY;
|
||||
|
||||
// Ok were done
|
||||
return id;
|
||||
}
|
||||
|
||||
void FxManager::Unregister(int32 id) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
if (g_icb->_mixer->isSoundHandleActive(m_effects[id]._handle)) {
|
||||
g_icb->_mixer->stopHandle(m_effects[id]._handle);
|
||||
}
|
||||
|
||||
delete m_effects[id]._stream;
|
||||
m_effects[id]._stream = nullptr;
|
||||
|
||||
memset(m_effects[id].name, 0, SAMPLE_NAME_LENGTH);
|
||||
m_effects[id].flags = Effect::EMPTY;
|
||||
}
|
||||
|
||||
void FxManager::Play(int32 id) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
if (m_effects[id].flags == Effect::READY) {
|
||||
// Queue the sound to be played
|
||||
m_effects[id].flags = Effect::QUEUED;
|
||||
}
|
||||
}
|
||||
|
||||
void FxManager::SetVolume(int32 id, int32 vol) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
m_effects[id].volume = vol;
|
||||
}
|
||||
|
||||
void FxManager::SetPan(int32 id, int32 pan) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
m_effects[id].pan = pan;
|
||||
}
|
||||
|
||||
void FxManager::SetPitch(int32 id, int32 pitch) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
m_effects[id].pitch = pitch;
|
||||
}
|
||||
|
||||
void FxManager::Stop(int32 id) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
if (m_effects[id].flags == Effect::PLAYING) {
|
||||
// Halt playback and reset position
|
||||
g_icb->_mixer->stopHandle(m_effects[id]._handle);
|
||||
m_effects[id]._stream->rewind();
|
||||
m_effects[id].flags = Effect::READY;
|
||||
}
|
||||
}
|
||||
|
||||
void FxManager::StopAll() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
for (int32 id = 0; id < MAX_FX; id++) {
|
||||
if (m_effects[id].flags == Effect::PLAYING) {
|
||||
// Halt playback and reset position
|
||||
g_icb->_mixer->stopHandle(m_effects[id]._handle);
|
||||
m_effects[id]._stream->rewind();
|
||||
m_effects[id].flags = Effect::READY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FxManager::UnregisterAll() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
for (int32 id = 0; id < MAX_FX; id++) {
|
||||
Unregister(id);
|
||||
|
||||
delete m_effects[id]._stream;
|
||||
m_effects[id]._stream = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int32 FxManager::GetDefaultRate(const char *name, uint32 byteOffsetInCluster) {
|
||||
int32 rateToFind = 0;
|
||||
int32 id;
|
||||
|
||||
for (id = 0; id < MAX_FX; id++) {
|
||||
// Do we have this sample loaded in memory
|
||||
if (strcmp(m_effects[id].name, name) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (id == MAX_FX)
|
||||
rateToFind = GetDefaultRateByName(name, byteOffsetInCluster);
|
||||
else
|
||||
rateToFind = GetDefaultRateByID(id);
|
||||
|
||||
return rateToFind;
|
||||
}
|
||||
|
||||
int32 FxManager::GetDefaultRateByName(const char * /*name*/, uint32 byteOffsetInCluster) {
|
||||
_wavHeader header;
|
||||
|
||||
// Open the cluster file and seek to the start of the sample
|
||||
const char *clusterName = (const char *)pxVString("g\\samples.clu");
|
||||
|
||||
Common::SeekableReadStream *stream = openDiskFileForBinaryStreamRead(clusterName);
|
||||
if (!stream)
|
||||
return 0;
|
||||
|
||||
stream->seek(byteOffsetInCluster, SEEK_SET);
|
||||
|
||||
// Read in the wave header
|
||||
if (stream->read(&header, sizeof(_wavHeader)) != sizeof(_wavHeader)) {
|
||||
delete stream;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Close the file
|
||||
delete stream;
|
||||
|
||||
// Return the wavs sampling rate
|
||||
return (FROM_LE_32(header.samplesPerSec));
|
||||
}
|
||||
|
||||
bool8 FxManager::Load(int32 id, const char * /*name*/, uint32 byteOffsetInCluster) {
|
||||
_wavHeader header;
|
||||
uint32 length;
|
||||
int32 lengthInCycles;
|
||||
|
||||
// Open the cluster file and seek to the start of the sample
|
||||
const char *clusterName = (const char *)pxVString("g\\samples.clu");
|
||||
|
||||
Common::SeekableReadStream *stream = openDiskFileForBinaryStreamRead(clusterName);
|
||||
if (!stream)
|
||||
return FALSE8;
|
||||
|
||||
stream->seek(byteOffsetInCluster, SEEK_SET);
|
||||
|
||||
if (openWav(stream, header, length, byteOffsetInCluster, lengthInCycles) != TRUE8) {
|
||||
delete stream;
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
// Straighten out the block align. (someties it's per second and sometime per sample)
|
||||
if (FROM_LE_16(header.blockAlign) > 16)
|
||||
header.blockAlign = TO_LE_16((uint16)(FROM_LE_16(header.channels) * FROM_LE_16(header.bitsPerSample) / 8));
|
||||
|
||||
// Store buffer sampling rate for easy access later
|
||||
m_effects[id].rate = FROM_LE_32(header.samplesPerSec);
|
||||
m_effects[id]._stream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
|
||||
|
||||
if (m_effects[id].rate != 0)
|
||||
m_effects[id].length = 500 * length / m_effects[id].rate;
|
||||
else
|
||||
m_effects[id].length = 0;
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
} // End of namespace ICB
|
||||
108
engines/icb/sound/fx_manager.h
Normal file
108
engines/icb/sound/fx_manager.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ICB_FXMANAGER_H__INCLUDED_
|
||||
#define ICB_FXMANAGER_H__INCLUDED_
|
||||
|
||||
#include "engines/icb/sound/direct_sound.h"
|
||||
|
||||
#include "audio/audiostream.h"
|
||||
#include "audio/mixer.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
extern bool8 noSoundEngine;
|
||||
|
||||
#define SAMPLE_NAME_LENGTH 64
|
||||
|
||||
typedef struct Effect {
|
||||
enum FxFlags { EMPTY, DELAYED, QUEUED, PLAYING, READY };
|
||||
|
||||
char name[SAMPLE_NAME_LENGTH]; // Sample name
|
||||
int32 delay; // The delay until playing
|
||||
int32 looped; // Loop this effect
|
||||
|
||||
int32 pitch; // Sampling rate (Hz)
|
||||
int32 pan; // Pan (DirectSound scale)
|
||||
int32 volume; // Volume (DirectSound scale)
|
||||
|
||||
int32 rate; // Original buffer sample rate
|
||||
FxFlags flags; // Status of sample
|
||||
int32 length; // Length of sample in millisecs at base rate...
|
||||
Audio::SeekableAudioStream *_stream;
|
||||
Audio::SoundHandle _handle;
|
||||
} Effect;
|
||||
|
||||
class FxManager {
|
||||
private:
|
||||
Effect m_effects[MAX_FX];
|
||||
|
||||
public:
|
||||
FxManager();
|
||||
~FxManager();
|
||||
|
||||
public:
|
||||
// Register wavs and unregister (high level load and unload)
|
||||
int32 Register(const int32 id, const char *name, const int32 delay = 0, uint32 byteOffsetInCluster = 0);
|
||||
void Unregister(int32 id);
|
||||
void UnregisterAll();
|
||||
|
||||
// Called on a timer 10 times a second
|
||||
bool8 Poll();
|
||||
|
||||
// Pretty important really
|
||||
void Play(int32 id);
|
||||
void Stop(int32 id);
|
||||
|
||||
void StopAll(void);
|
||||
|
||||
// All realtime tweakers
|
||||
void SetVolume(int32 id, int32 vol);
|
||||
void SetPitch(int32 id, int32 pitch);
|
||||
|
||||
// A DirectSound buffer can support panning OR 3D position but not both
|
||||
// A parameter for Register() lets you decide which to support
|
||||
void SetPan(int32 id, int32 pan);
|
||||
|
||||
// Helpers and debug shat
|
||||
void SetLooping(int32 id, int32 loop = 1) { m_effects[id].looped = loop; }
|
||||
bool8 IsPlaying(int32 id) { return (m_effects[id].flags == Effect::PLAYING) ? TRUE8 : FALSE8; }
|
||||
|
||||
int32 GetDefaultRate(const char *name, uint32 byteOffsetInCluster = 0);
|
||||
|
||||
int32 GetDefaultLength(int32 id) { return m_effects[id].length; }
|
||||
|
||||
private:
|
||||
bool8 Load(int32 id, const char *name, uint32 byteOffsetInCluster = 0);
|
||||
|
||||
// Can get original sampling rate by channel or examine a wav file
|
||||
int32 GetDefaultRateByID(int32 id) { return m_effects[id].rate; }
|
||||
int32 GetDefaultRateByName(const char *name, uint32 byteOffsetInCluster = 0);
|
||||
};
|
||||
|
||||
} // End of namespace ICB
|
||||
|
||||
#endif
|
||||
258
engines/icb/sound/music_manager.cpp
Normal file
258
engines/icb/sound/music_manager.cpp
Normal file
@@ -0,0 +1,258 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/icb/sound/sound_common.h"
|
||||
#include "engines/icb/sound/music_manager.h"
|
||||
#include "engines/icb/sound/fx_manager.h"
|
||||
#include "engines/icb/res_man_pc.h"
|
||||
#include "engines/icb/sound.h"
|
||||
#include "engines/icb/p4.h"
|
||||
#include "engines/icb/icb.h"
|
||||
|
||||
#include "audio/decoders/wave.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
extern _stub stub;
|
||||
|
||||
MusicManager::MusicManager() {
|
||||
m_bufferLength = 0;
|
||||
m_wavByteOffsetInCluster = 0;
|
||||
m_wavDataSize = 0;
|
||||
|
||||
m_paused = FALSE8;
|
||||
m_lengthInCycles = 0;
|
||||
|
||||
m_identifier = 0;
|
||||
|
||||
m_fading = 0;
|
||||
m_adjustFadeVol = 0;
|
||||
|
||||
_audioStream = nullptr;
|
||||
}
|
||||
|
||||
MusicManager::~MusicManager() {
|
||||
KillBuffer();
|
||||
}
|
||||
|
||||
bool8 MusicManager::UpdateMusic() {
|
||||
if (noSoundEngine)
|
||||
return TRUE8;
|
||||
|
||||
// Don't do anything if we're paused or buffer invalid
|
||||
if (m_paused == FALSE8) {
|
||||
// Do fade out here
|
||||
|
||||
// Has music been stopped?
|
||||
if (m_adjustFadeVol != 0) {
|
||||
// Have we faded down
|
||||
if (m_fading == 0) {
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle))
|
||||
g_icb->_mixer->stopHandle(_handle);
|
||||
m_adjustFadeVol = 0;
|
||||
} else {
|
||||
AdjustVolume(m_adjustFadeVol * -1);
|
||||
m_fading--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
bool8 MusicManager::LoadMusic(const char *clusterName, uint32 byteOffsetToWav, int32 vol) {
|
||||
if (noSoundEngine)
|
||||
return FALSE8;
|
||||
|
||||
if (clusterName[0] == '\0')
|
||||
return FALSE8;
|
||||
|
||||
// Check to see if we have this piece of music already loaded
|
||||
if (m_identifier == byteOffsetToWav) {
|
||||
// Record & Set the volume
|
||||
SetVolume(vol);
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
// Stops and fills the buffer with silence
|
||||
KillBuffer();
|
||||
|
||||
// A new music file overrides paused status
|
||||
m_paused = FALSE8;
|
||||
|
||||
// Open the cluster file
|
||||
Common::SeekableReadStream *stream = openDiskFileForBinaryStreamRead(clusterName);
|
||||
if (stream == nullptr)
|
||||
return FALSE8;
|
||||
|
||||
// Need to seek to the correct position in the cluster
|
||||
stream->seek(byteOffsetToWav, SEEK_SET);
|
||||
|
||||
// Read in header information and make buffer
|
||||
if (!OpenMusic(stream)) {
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
// Record & Set the volume
|
||||
SetVolume(vol);
|
||||
|
||||
// As we're only dealing with one global music cluster, then this number
|
||||
// can be used safely to idenity all different music in the entire game
|
||||
m_identifier = byteOffsetToWav;
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
bool8 MusicManager::StartMusic(const char *clusterName, uint32 byteOffsetToWav, int32 vol) {
|
||||
warning("MusicManager::StartMusic");
|
||||
if (LoadMusic(clusterName, byteOffsetToWav, vol) == TRUE8) {
|
||||
// Regular playback
|
||||
m_adjustFadeVol = 0;
|
||||
|
||||
if (PlayMusic() == TRUE8)
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
bool8 MusicManager::PlayMusic() {
|
||||
if (noSoundEngine)
|
||||
return FALSE8;
|
||||
|
||||
// Regular playback
|
||||
m_adjustFadeVol = 0;
|
||||
|
||||
// Play the sound buffer
|
||||
float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
|
||||
g_icb->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_handle, _audioStream,
|
||||
-1, m_musicVol * volumeConversion, 0, DisposeAfterUse::YES);
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
void MusicManager::StopMusic() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
// Do nothing if we're already fading
|
||||
if (m_fading == 0 && IsPlaying()) {
|
||||
// Set the fade active
|
||||
m_fading = 10;
|
||||
m_adjustFadeVol = (int32)(GetMusicVolume() / m_fading) + 1;
|
||||
if (m_adjustFadeVol == 0)
|
||||
m_adjustFadeVol = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void MusicManager::SetMusicPausedStatus(bool8 p) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
if (p) {
|
||||
// Already paused
|
||||
if (!IsPlaying() && m_paused)
|
||||
return;
|
||||
|
||||
// Stop playback leaving cursors alone
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle))
|
||||
g_icb->_mixer->pauseHandle(_handle, true);
|
||||
|
||||
m_paused = TRUE8;
|
||||
} else {
|
||||
if (m_paused) {
|
||||
m_paused = FALSE8;
|
||||
|
||||
// Play from where we left off
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle))
|
||||
g_icb->_mixer->pauseHandle(_handle, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MusicManager::SetMusicVolume(int32 volume) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
SetVolume(volume);
|
||||
}
|
||||
|
||||
bool8 MusicManager::IsPlaying() {
|
||||
if (noSoundEngine)
|
||||
return FALSE8;
|
||||
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle))
|
||||
return TRUE8;
|
||||
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
void MusicManager::SetVolume(int32 volume) {
|
||||
// Store and set correct volume
|
||||
m_musicVol = volume;
|
||||
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle)) {
|
||||
float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
|
||||
g_icb->_mixer->setChannelVolume(_handle, volume * volumeConversion);
|
||||
}
|
||||
}
|
||||
|
||||
void MusicManager::AdjustVolume(int32 amount) {
|
||||
int32 musicVol = m_musicVol;
|
||||
musicVol += amount;
|
||||
if (musicVol > 127)
|
||||
musicVol = 127;
|
||||
if (musicVol < 0)
|
||||
musicVol = 0;
|
||||
m_musicVol = musicVol;
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle)) {
|
||||
float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
|
||||
g_icb->_mixer->setChannelVolume(_handle, musicVol * volumeConversion);
|
||||
}
|
||||
}
|
||||
|
||||
bool8 MusicManager::OpenMusic(Common::SeekableReadStream *stream) {
|
||||
_wavHeader header;
|
||||
|
||||
if (openWav(stream, header, m_wavDataSize, m_wavByteOffsetInCluster, m_lengthInCycles) == FALSE8) {
|
||||
delete stream;
|
||||
return FALSE8;
|
||||
}
|
||||
_audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
void MusicManager::KillBuffer() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle))
|
||||
g_icb->_mixer->stopHandle(_handle);
|
||||
|
||||
m_identifier = 0;
|
||||
}
|
||||
|
||||
} // End of namespace ICB
|
||||
87
engines/icb/sound/music_manager.h
Normal file
87
engines/icb/sound/music_manager.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ICB_MUSICMANAGER_H_INCLUDED_
|
||||
#define ICB_MUSICMANAGER_H_INCLUDED_
|
||||
|
||||
#include "engines/icb/common/px_common.h"
|
||||
#include "engines/icb/sound/direct_sound.h"
|
||||
|
||||
#include "common/stream.h"
|
||||
|
||||
#include "audio/audiostream.h"
|
||||
#include "audio/mixer.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
class MusicManager {
|
||||
private:
|
||||
Audio::AudioStream *_audioStream;
|
||||
Audio::SoundHandle _handle;
|
||||
|
||||
uint32 m_bufferLength; // Stores the length of the sound buffers in bytes
|
||||
int32 m_musicVol; // The volume the each stream was started at
|
||||
|
||||
uint32 m_wavByteOffsetInCluster;
|
||||
uint32 m_wavDataSize;
|
||||
|
||||
bool8 m_paused;
|
||||
int32 m_lengthInCycles; // Assumes 12 frames per second
|
||||
|
||||
int32 m_fading;
|
||||
int32 m_adjustFadeVol;
|
||||
|
||||
uint32 m_identifier; // Handle if you like of loaded music
|
||||
|
||||
public:
|
||||
MusicManager();
|
||||
~MusicManager();
|
||||
|
||||
bool8 UpdateMusic();
|
||||
|
||||
bool8 LoadMusic(const char *clusterName, uint32 byteOffsetToWav, int32 vol = 128);
|
||||
bool8 StartMusic(const char *clusterName, uint32 byteOffsetToWav, int32 vol = 128);
|
||||
bool8 PlayMusic();
|
||||
void StopMusic();
|
||||
void SetMusicPausedStatus(bool8 p = TRUE8);
|
||||
void SetMusicVolume(int32 volume);
|
||||
|
||||
bool8 IsPlaying();
|
||||
bool8 IsPaused() { return m_paused; }
|
||||
int32 GetLength() { return m_lengthInCycles; }
|
||||
|
||||
private:
|
||||
bool8 OpenMusic(Common::SeekableReadStream *stream);
|
||||
void KillBuffer();
|
||||
void SetVolume(int32 volume);
|
||||
void AdjustVolume(int32 amount);
|
||||
};
|
||||
|
||||
extern MusicManager *g_theMusicManager;
|
||||
|
||||
} // End of namespace ICB
|
||||
|
||||
#endif
|
||||
86
engines/icb/sound/sound_common.cpp
Normal file
86
engines/icb/sound/sound_common.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/icb/p4.h"
|
||||
#include "engines/icb/sound/direct_sound.h"
|
||||
#include "engines/icb/sound/sound_common.h"
|
||||
|
||||
#include "common/textconsole.h"
|
||||
#include "common/stream.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
// Common code between the three sound-managers
|
||||
bool8 openWav(Common::SeekableReadStream *stream, _wavHeader &header, uint32 &length, uint32 &byteOffsetInCluster, int32 &lengthInCycles) {
|
||||
|
||||
int32 pos = stream->pos();
|
||||
int32 bytesRead;
|
||||
char buff[1024];
|
||||
bool bMore = true;
|
||||
|
||||
// Read the wave header
|
||||
if (stream->read(&header, sizeof(_wavHeader)) != sizeof(_wavHeader))
|
||||
return FALSE8;
|
||||
|
||||
if (FROM_LE_16(header.formatTag) != 1) {
|
||||
warning("Only supports PCM uncompressed wav files");
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
// Find the start of the data
|
||||
do {
|
||||
int32 i = 0;
|
||||
bytesRead = stream->read(buff, 256);
|
||||
for (i = 0; i < (bytesRead - 3) && bMore; i++)
|
||||
bMore = READ_LE_U32(buff + i) != MKTAG('a', 't', 'a', 'd');
|
||||
|
||||
if (bMore)
|
||||
stream->seek(-3, SEEK_CUR);
|
||||
else
|
||||
stream->seek(i - bytesRead + 3, SEEK_CUR);
|
||||
|
||||
} while (bMore && bytesRead == 256);
|
||||
|
||||
if (bMore) // Can't find 'data' !
|
||||
return FALSE8;
|
||||
|
||||
// Find length of data
|
||||
length = stream->readUint32LE();
|
||||
if (stream->err())
|
||||
return FALSE8;
|
||||
|
||||
// Adjust this byte counter to represent the first data byte of the wav
|
||||
byteOffsetInCluster = (uint32)stream->pos();
|
||||
|
||||
// Expected number of cycles this sample reguires to completely playback
|
||||
lengthInCycles = (int32)ceil(((double)length / (double)FROM_LE_32(header.avgBytesPerSec)) * 12.0f * 1.215f);
|
||||
|
||||
stream->seek(pos);
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
} // End of namespace ICB
|
||||
56
engines/icb/sound/sound_common.h
Normal file
56
engines/icb/sound/sound_common.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ICB_SOUNDCOMMON_H__INCLUDED_
|
||||
#define ICB_SOUNDCOMMON_H__INCLUDED_
|
||||
|
||||
#include "engines/icb/sound/direct_sound.h"
|
||||
|
||||
#include "common/stream.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
typedef struct _wavHeader {
|
||||
char riff[4];
|
||||
uint32 fileLength;
|
||||
char wavID[4];
|
||||
char format[4];
|
||||
uint32 formatLen;
|
||||
uint16 formatTag;
|
||||
uint16 channels;
|
||||
uint32 samplesPerSec;
|
||||
uint32 avgBytesPerSec;
|
||||
uint16 blockAlign;
|
||||
uint16 bitsPerSample;
|
||||
|
||||
} _wavHeader;
|
||||
|
||||
// Common code between the three sound managers
|
||||
bool8 openWav(Common::SeekableReadStream *filePtr, _wavHeader &header, uint32 &length, uint32 &byteOffsetInCluster, int32 &lengthInCycles);
|
||||
|
||||
} // End of namespace ICB
|
||||
|
||||
#endif
|
||||
184
engines/icb/sound/speech_manager.cpp
Normal file
184
engines/icb/sound/speech_manager.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "engines/icb/sound/speech_manager.h"
|
||||
#include "engines/icb/sound/music_manager.h"
|
||||
#include "engines/icb/sound/fx_manager.h"
|
||||
#include "engines/icb/sound/direct_sound.h"
|
||||
#include "engines/icb/res_man_pc.h"
|
||||
#include "engines/icb/debug.h"
|
||||
#include "engines/icb/p4.h"
|
||||
#include "engines/icb/sound/sound_common.h"
|
||||
#include "engines/icb/icb.h"
|
||||
|
||||
#include "common/textconsole.h"
|
||||
|
||||
#include "audio/mixer.h"
|
||||
#include "audio/decoders/wave.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
SpeechManager::SpeechManager() {
|
||||
m_wavByteOffsetInCluster = 0;
|
||||
m_wavDataSize = 0;
|
||||
|
||||
m_paused = FALSE8;
|
||||
m_lengthInCycles = 0;
|
||||
m_speechVol = 0;
|
||||
|
||||
_audioStream = nullptr;
|
||||
}
|
||||
|
||||
SpeechManager::~SpeechManager() { KillBuffer(); }
|
||||
|
||||
bool8 SpeechManager::IsPlaying() {
|
||||
if (noSoundEngine)
|
||||
return FALSE8;
|
||||
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle)) {
|
||||
return TRUE8;
|
||||
}
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
bool8 SpeechManager::StartSpeech(const char *fileName, uint32 byteOffsetToWav, int32 vol) {
|
||||
if (noSoundEngine)
|
||||
return FALSE8;
|
||||
|
||||
if (fileName[0] == '\0')
|
||||
return FALSE8;
|
||||
|
||||
// Stops and fills the buffer with silence
|
||||
KillBuffer();
|
||||
|
||||
// A new speech file overrides paused status
|
||||
m_paused = FALSE8;
|
||||
|
||||
// Open the cluster file
|
||||
Common::SeekableReadStream *stream = openDiskFileForBinaryStreamRead(fileName);
|
||||
if (stream == nullptr)
|
||||
return FALSE8;
|
||||
|
||||
// Need to seek to the correct position in the cluster
|
||||
stream->seek(byteOffsetToWav, SEEK_SET);
|
||||
|
||||
// Read in header information and make buffer
|
||||
if (!OpenSpeech(stream)) {
|
||||
warning("SpeechManager::OpenStream(%s, header) failed", fileName);
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
|
||||
g_icb->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_handle, _audioStream,
|
||||
-1, vol * volumeConversion, 0, DisposeAfterUse::YES);
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
bool8 SpeechManager::UpdateSpeech() {
|
||||
if (noSoundEngine)
|
||||
return TRUE8;
|
||||
|
||||
// Don't do anything if we're paused or buffer invalid
|
||||
if (m_paused == FALSE8) {
|
||||
if (IsPlaying() == FALSE8)
|
||||
KillBuffer();
|
||||
}
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
void SpeechManager::StopSpeech() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
KillBuffer();
|
||||
}
|
||||
|
||||
void SpeechManager::PauseSpeech() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
if (m_paused || !IsPlaying())
|
||||
return;
|
||||
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle))
|
||||
g_icb->_mixer->pauseHandle(_handle, true);
|
||||
|
||||
m_paused = TRUE8;
|
||||
}
|
||||
|
||||
void SpeechManager::ResumeSpeech() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
if (m_paused) {
|
||||
m_paused = FALSE8;
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle)) {
|
||||
g_icb->_mixer->pauseHandle(_handle, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpeechManager::SetSpeechVolume(int32 volume) {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
|
||||
SetVolume(volume);
|
||||
}
|
||||
|
||||
void SpeechManager::SetVolume(int32 volume) {
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle)) {
|
||||
float volumeConversion = Audio::Mixer::kMaxChannelVolume / 128.0f;
|
||||
g_icb->_mixer->setChannelVolume(_handle, volume * volumeConversion);
|
||||
}
|
||||
}
|
||||
|
||||
bool8 SpeechManager::OpenSpeech(Common::SeekableReadStream *stream) {
|
||||
_wavHeader header;
|
||||
|
||||
// Get the length etc.
|
||||
if (openWav(stream, header, m_wavDataSize, m_wavByteOffsetInCluster, m_lengthInCycles) != TRUE8) {
|
||||
delete stream;
|
||||
return FALSE8;
|
||||
}
|
||||
|
||||
// _audioStream contains the latest Opened WAV, which should be played immediately after, and
|
||||
// thus cleaned by the mixer when done.
|
||||
_audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
|
||||
|
||||
return TRUE8;
|
||||
}
|
||||
|
||||
void SpeechManager::KillBuffer() {
|
||||
if (noSoundEngine)
|
||||
return;
|
||||
if (g_icb->_mixer->isSoundHandleActive(_handle))
|
||||
g_icb->_mixer->stopHandle(_handle);
|
||||
// No need to free _audioStream as it is auto-freed by the mixer.
|
||||
}
|
||||
|
||||
} // End of namespace ICB
|
||||
75
engines/icb/sound/speech_manager.h
Normal file
75
engines/icb/sound/speech_manager.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/* 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.
|
||||
*
|
||||
* Additional copyright for this file:
|
||||
* Copyright (C) 1999-2000 Revolution Software Ltd.
|
||||
* This code is based on source code created by Revolution Software,
|
||||
* used with permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ICB_SPEECHMANAGER_H_INCLUDED_
|
||||
#define ICB_SPEECHMANAGER_H_INCLUDED_
|
||||
|
||||
#include "engines/icb/common/px_common.h"
|
||||
#include "engines/icb/sound/direct_sound.h"
|
||||
|
||||
#include "common/stream.h"
|
||||
|
||||
#include "audio/audiostream.h"
|
||||
#include "audio/mixer.h"
|
||||
|
||||
namespace ICB {
|
||||
|
||||
class SpeechManager {
|
||||
private:
|
||||
Audio::AudioStream *_audioStream;
|
||||
Audio::SoundHandle _handle;
|
||||
int32 m_speechVol; // The volume the each stream was started at
|
||||
|
||||
uint32 m_wavByteOffsetInCluster;
|
||||
uint32 m_wavDataSize;
|
||||
|
||||
bool8 m_paused;
|
||||
int32 m_lengthInCycles; // Assumes 12 frames per second
|
||||
|
||||
public:
|
||||
SpeechManager();
|
||||
~SpeechManager();
|
||||
|
||||
bool8 UpdateSpeech();
|
||||
|
||||
bool8 StartSpeech(const char *fileName, uint32 byteOffsetToWav, int32 vol = 128);
|
||||
void StopSpeech();
|
||||
void PauseSpeech();
|
||||
void ResumeSpeech();
|
||||
void SetSpeechVolume(int32 volume);
|
||||
bool8 IsPlaying();
|
||||
bool8 IsPaused() { return m_paused; }
|
||||
int32 GetLength() { return m_lengthInCycles; }
|
||||
|
||||
private:
|
||||
bool8 OpenSpeech(Common::SeekableReadStream *stream);
|
||||
void KillBuffer();
|
||||
void SetVolume(int32 volume);
|
||||
};
|
||||
|
||||
} // End of namespace ICB
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user