mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-22 04:01:23 +00:00
Generalize the sound archive framework to be able to open new formats
svn-id: r50519
This commit is contained in:
parent
764aa1a125
commit
c7f6a5b286
@ -123,8 +123,8 @@ int DraciEngine::init() {
|
||||
_itemImagesArchive = new BArchive(itemImagesPath);
|
||||
_stringsArchive = new BArchive(stringsPath);
|
||||
|
||||
_soundsArchive = new SoundArchive(soundsPath, kSoundsFrequency);
|
||||
_dubbingArchive = new SoundArchive(dubbingPath, kDubbingFrequency);
|
||||
_soundsArchive = new LegacySoundArchive(soundsPath, kSoundsFrequency);
|
||||
_dubbingArchive = new LegacySoundArchive(dubbingPath, kDubbingFrequency);
|
||||
_sound = new Sound(_mixer);
|
||||
|
||||
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
|
||||
|
@ -332,7 +332,7 @@ void Game::handleOrdinaryLoop(int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
int Game::inventoryPositionFromMouse() {
|
||||
int Game::inventoryPositionFromMouse() const {
|
||||
const int column = CLIP(scummvm_lround(
|
||||
(_vm->_mouse->getPosX() - kInventoryX + kInventoryItemWidth / 2.) /
|
||||
kInventoryItemWidth) - 1, 0L, (long) kInventoryColumns - 1);
|
||||
|
@ -335,7 +335,7 @@ public:
|
||||
private:
|
||||
void updateOrdinaryCursor();
|
||||
void updateInventoryCursor();
|
||||
int inventoryPositionFromMouse();
|
||||
int inventoryPositionFromMouse() const;
|
||||
void handleOrdinaryLoop(int x, int y);
|
||||
void handleInventoryLoop();
|
||||
void handleDialogueLoop();
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
namespace Draci {
|
||||
|
||||
void SoundArchive::openArchive(const Common::String &path) {
|
||||
void LegacySoundArchive::openArchive(const Common::String &path) {
|
||||
// Close previously opened archive (if any)
|
||||
closeArchive();
|
||||
|
||||
@ -103,12 +103,12 @@ void SoundArchive::openArchive(const Common::String &path) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SoundArchive close method
|
||||
* @brief LegacySoundArchive close method
|
||||
*
|
||||
* Closes the currently opened archive. It can be called explicitly to
|
||||
* free up memory.
|
||||
*/
|
||||
void SoundArchive::closeArchive() {
|
||||
void LegacySoundArchive::closeArchive() {
|
||||
clearCache();
|
||||
delete _f;
|
||||
_f = NULL;
|
||||
@ -123,7 +123,7 @@ void SoundArchive::closeArchive() {
|
||||
* Clears the cache of the open files inside the archive without closing it.
|
||||
* If the files are subsequently accessed, they are read from the disk.
|
||||
*/
|
||||
void SoundArchive::clearCache() {
|
||||
void LegacySoundArchive::clearCache() {
|
||||
// Delete all cached data
|
||||
for (uint i = 0; i < _sampleCount; ++i) {
|
||||
_samples[i].close();
|
||||
@ -137,7 +137,7 @@ void SoundArchive::clearCache() {
|
||||
*
|
||||
* Loads individual samples from an archive to memory on demand.
|
||||
*/
|
||||
SoundSample *SoundArchive::getSample(int i, uint freq) {
|
||||
SoundSample *LegacySoundArchive::getSample(int i, uint freq) {
|
||||
// Check whether requested file exists
|
||||
if (i < 0 || i >= (int) _sampleCount) {
|
||||
return NULL;
|
||||
|
@ -47,28 +47,61 @@ struct SoundSample {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* An abstract wrapper around archives of sound samples or dubbing.
|
||||
*/
|
||||
class SoundArchive {
|
||||
public:
|
||||
SoundArchive(const Common::String &path, uint defaultFreq) :
|
||||
SoundArchive() { }
|
||||
virtual ~SoundArchive() { }
|
||||
|
||||
/**
|
||||
* Returns the number of sound samples in the archive. Zero means that
|
||||
* a fake empty archive has been opened and the caller may consider
|
||||
* opening a different one, for example with compressed music.
|
||||
*/
|
||||
virtual uint size() const = 0;
|
||||
|
||||
/**
|
||||
* Checks whether there is an archive opened. Should be called before reading
|
||||
* from the archive to check whether opening of the archive has succeeded.
|
||||
*/
|
||||
virtual bool isOpen() const = 0;
|
||||
|
||||
/**
|
||||
* Removes cached samples from memory.
|
||||
*/
|
||||
virtual void clearCache() = 0;
|
||||
|
||||
/**
|
||||
* Caches a given sample into memory and returns a pointer into it. We
|
||||
* own the pointer. If freq is nonzero, then the sample is played at a
|
||||
* different frequency (only used for uncompressed samples).
|
||||
*/
|
||||
virtual SoundSample *getSample(int i, uint freq) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads CD.SAM (with dubbing) and CD2.SAM (with sound samples) from the
|
||||
* original game.
|
||||
*/
|
||||
class LegacySoundArchive : public SoundArchive {
|
||||
public:
|
||||
LegacySoundArchive(const Common::String &path, uint defaultFreq) :
|
||||
_path(), _samples(NULL), _sampleCount(0), _defaultFreq(defaultFreq), _opened(false), _f(NULL) {
|
||||
openArchive(path);
|
||||
}
|
||||
|
||||
~SoundArchive() { closeArchive(); }
|
||||
virtual ~LegacySoundArchive() { closeArchive(); }
|
||||
|
||||
void closeArchive();
|
||||
void openArchive(const Common::String &path);
|
||||
uint size() const { return _sampleCount; }
|
||||
|
||||
/**
|
||||
* Checks whether there is an archive opened. Should be called before reading
|
||||
* from the archive to check whether openArchive() succeeded.
|
||||
*/
|
||||
bool isOpen() const { return _opened; }
|
||||
virtual uint size() const { return _sampleCount; }
|
||||
virtual bool isOpen() const { return _opened; }
|
||||
|
||||
void clearCache();
|
||||
|
||||
SoundSample *getSample(int i, uint freq);
|
||||
virtual void clearCache();
|
||||
virtual SoundSample *getSample(int i, uint freq);
|
||||
|
||||
private:
|
||||
Common::String _path; ///< Path to file
|
||||
|
Loading…
x
Reference in New Issue
Block a user