mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
QDENGINE: Simplified wave loading code
This commit is contained in:
4 files changed
+12
-113
No files matched your search
@@ -39,12 +39,10 @@ qdSound::qdSound() : _volume(255) {
|
||||
}
|
||||
|
||||
qdSound::~qdSound() {
|
||||
_sound.free_data();
|
||||
}
|
||||
|
||||
bool qdSound::free_resource() {
|
||||
toggle_resource_status(false);
|
||||
_sound.free_data();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ mpegPlayer::~mpegPlayer() {
|
||||
}
|
||||
|
||||
bool mpegPlayer::play(const Common::Path file, bool loop, int vol) {
|
||||
bool isOGG = file.baseName().hasSuffix(".ogg");
|
||||
bool isOGG = file.baseName().hasSuffixIgnoreCase(".ogg");
|
||||
|
||||
debugC(1, kDebugSound, "mpegPlayer::play(%s, %d, %d)", file.toString().c_str(), loop, vol);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "audio/audiostream.h"
|
||||
#include "audio/decoders/raw.h"
|
||||
#include "audio/decoders/wave.h"
|
||||
#include "common/debug.h"
|
||||
@@ -32,41 +33,9 @@
|
||||
|
||||
namespace QDEngine {
|
||||
|
||||
wavSound::wavSound() : _data(NULL) {
|
||||
_data_length = 0;
|
||||
_bits_per_sample = 0;
|
||||
_channels = 0;
|
||||
_samples_per_sec = 0;
|
||||
}
|
||||
wavSound::wavSound() {}
|
||||
|
||||
wavSound::~wavSound() {
|
||||
free_data();
|
||||
}
|
||||
|
||||
bool wavSound::init(int data_len, int bits, int chn, int samples) {
|
||||
free_data();
|
||||
|
||||
_data_length = data_len;
|
||||
_data = new char[_data_length];
|
||||
|
||||
_channels = chn;
|
||||
_bits_per_sample = bits;
|
||||
_samples_per_sec = samples;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wavSound::free_data() {
|
||||
if (_data) {
|
||||
delete [] _data;
|
||||
_data = NULL;
|
||||
}
|
||||
|
||||
_data_length = 0;
|
||||
_bits_per_sample = 0;
|
||||
_channels = 0;
|
||||
_samples_per_sec = 0;
|
||||
}
|
||||
wavSound::~wavSound() {}
|
||||
|
||||
bool wavSound::wav_file_load(const Common::Path fpath) {
|
||||
debugC(3, kDebugSound, "[%d] Loading Wav: %s", g_system->getMillis(), transCyrillic(fpath.toString()));
|
||||
@@ -79,37 +48,13 @@ bool wavSound::wav_file_load(const Common::Path fpath) {
|
||||
|
||||
Common::SeekableReadStream *stream;
|
||||
|
||||
if (_fname.baseName().hasSuffixIgnoreCase(".ogg")) {
|
||||
}
|
||||
|
||||
if (qdFileManager::instance().open_file(&stream, fpath.toString().c_str(), false)) {
|
||||
int size, rate;
|
||||
byte flags;
|
||||
uint16 type;
|
||||
int blockAlign;
|
||||
|
||||
if (!Audio::loadWAVFromStream(*stream, size, rate, flags, &type, &blockAlign)) {
|
||||
warning("Error loading wav file header: '%s", transCyrillic(fpath.toString()));
|
||||
delete stream;
|
||||
return false;
|
||||
}
|
||||
|
||||
int bits;
|
||||
if (flags & Audio::FLAG_UNSIGNED)
|
||||
bits = 8;
|
||||
else if (flags & Audio::FLAG_16BITS)
|
||||
bits = 16;
|
||||
else if (flags & Audio::FLAG_24BITS)
|
||||
bits = 24;
|
||||
else
|
||||
bits = 8;
|
||||
|
||||
int channels = 1;
|
||||
if (flags & Audio::FLAG_STEREO)
|
||||
channels = 2;
|
||||
|
||||
init(size, bits, channels, rate);
|
||||
|
||||
stream->seek(0);
|
||||
|
||||
_audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::NO);
|
||||
|
||||
_length = (float)_audioStream->getLength().msecs() / 1000.0;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -34,39 +34,8 @@ public:
|
||||
wavSound();
|
||||
~wavSound();
|
||||
|
||||
const char *data() const {
|
||||
return _data;
|
||||
}
|
||||
int data_length() const {
|
||||
return _data_length;
|
||||
}
|
||||
int bits_per_sample() const {
|
||||
return _bits_per_sample;
|
||||
}
|
||||
int channels() const {
|
||||
return _channels;
|
||||
}
|
||||
int samples_per_sec() const {
|
||||
return _samples_per_sec;
|
||||
}
|
||||
|
||||
bool init(int data_len, int bits, int chn, int samples);
|
||||
void free_data();
|
||||
|
||||
//! Возвращает true, если звук валиден (т.е. параметры допустимые).
|
||||
bool is_valid() const {
|
||||
if (_bits_per_sample != 8 && _bits_per_sample != 16) return false;
|
||||
if (_channels != 1 && _channels != 2) return false;
|
||||
if (!_samples_per_sec) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Возвращает длительность звука в секундах.
|
||||
float length() const {
|
||||
if (!is_valid()) return 0.0f;
|
||||
return float(_data_length / _channels / (_bits_per_sample >> 3)) / float(_samples_per_sec);
|
||||
}
|
||||
//! Returns sound length in seconds
|
||||
float length() const { return _length; }
|
||||
|
||||
bool wav_file_load(const Common::Path fname);
|
||||
|
||||
@@ -74,20 +43,7 @@ public:
|
||||
Common::Path _fname;
|
||||
|
||||
private:
|
||||
|
||||
//! Данные.
|
||||
char *_data;
|
||||
//! Длина данных.
|
||||
int _data_length;
|
||||
//! Количество бит на сэмпл (8/16).
|
||||
int _bits_per_sample;
|
||||
//! Количество каналов (1/2 - моно/стерео).
|
||||
int _channels;
|
||||
//! Частота дискретизации - количество сэмплов в секунду.
|
||||
/**
|
||||
Значения: 8.0, 11.025, 22.05, 44.1 x1000 Hz.
|
||||
*/
|
||||
int _samples_per_sec;
|
||||
float _length = 0.0;
|
||||
};
|
||||
|
||||
} // namespace QDEngine
|
||||
|
||||
Reference in new issue
Block a user