aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2003-03-18 21:46:44 +0000
committerMax Horn2003-03-18 21:46:44 +0000
commit80e3c23482fbcea15b545f001d983c7657263761 (patch)
tree81fd73cd151ccea0520a5713026084e24a8e22ba /sound
parent4cdfd9c2beae3de73a9ee19ae1db8609b8667e6c (diff)
downloadscummvm-rg350-80e3c23482fbcea15b545f001d983c7657263761.tar.gz
scummvm-rg350-80e3c23482fbcea15b545f001d983c7657263761.tar.bz2
scummvm-rg350-80e3c23482fbcea15b545f001d983c7657263761.zip
cleanup; add stopID method to stop a currently playing sound via its ID
svn-id: r6835
Diffstat (limited to 'sound')
-rw-r--r--sound/mixer.cpp57
-rw-r--r--sound/mixer.h20
2 files changed, 25 insertions, 52 deletions
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 3c013ea866..e518233c76 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -88,17 +88,6 @@ int SoundMixer::insertAt(PlayingSoundHandle *handle, int index, Channel *chan) {
return index;
}
-int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags) {
- for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
- if (_channels[i] == NULL) {
- return insertAt(handle, i, new ChannelRaw(this, sound, size, rate, flags, -1));
- }
- }
-
- warning("SoundMixer::out of mixer slots");
- return -1;
-}
-
int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id) {
for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
if (_channels[i] == NULL) {
@@ -217,6 +206,16 @@ void SoundMixer::stop(int index) {
_channels[index]->destroy();
}
+void SoundMixer::stopID(int id) {
+
+ for (int i = _beginSlots; i != NUM_CHANNELS; i++) {
+ if (_channels[i] != NULL && _channels[i]->_id == id) {
+ _channels[i]->destroy();
+ return;
+ }
+ }
+}
+
void SoundMixer::pause(bool paused) {
_paused = paused;
}
@@ -578,9 +577,7 @@ static int16 mixer_element_size[] = {
};
void SoundMixer::ChannelRaw::mix(int16 *data, uint len) {
- byte *s, *s_org = NULL;
- uint32 fp_pos;
- byte *end;
+ byte *s, *end;
if (_toBeDestroyed) {
realDestroy();
@@ -591,41 +588,15 @@ void SoundMixer::ChannelRaw::mix(int16 *data, uint len) {
len = _size;
_size -= len;
- /*
- * simple support for fread() reading of samples
- */
- if (_flags & FLAG_FILE) {
- /* determine how many samples to read from the file */
- uint num = len * _fpSpeed >> 16;
-
- s_org = (byte *)malloc(num);
- if (s_org == NULL)
- error("ChannelRaw::mix out of memory");
-
- uint num_read = ((File *)_ptr)->read(s_org, num);
- if (num - num_read != 0)
- memset(s_org + num_read, 0x80, num - num_read);
-
- s = s_org;
- fp_pos = 0;
- end = s_org + num;
- } else {
- s = (byte *)_ptr + _pos;
- fp_pos = _fpPos;
- end = (byte *)_ptr + _realSize;
- }
+ s = (byte *)_ptr + _pos;
+ end = (byte *)_ptr + _realSize;
const uint32 fp_speed = _fpSpeed;
const int16 *vol_tab = _mixer->_volumeTable;
- mixer_helper_table[_flags & 0x07] (data, &len, &s, &fp_pos, fp_speed, vol_tab, end, (_flags & FLAG_REVERSE_STEREO) ? true : false);
+ mixer_helper_table[_flags & 0x07] (data, &len, &s, &_fpPos, fp_speed, vol_tab, end, (_flags & FLAG_REVERSE_STEREO) ? true : false);
_pos = s - (byte *)_ptr;
- _fpPos = fp_pos;
-
- if (_flags & FLAG_FILE) {
- free(s_org);
- }
if (_size < 1) {
if (_flags & FLAG_LOOP) {
diff --git a/sound/mixer.h b/sound/mixer.h
index acf6e9e051..61ef5553a6 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -46,6 +46,7 @@ private:
public:
bool _toBeDestroyed;
int _id;
+ Channel() : _id(-1) {}
virtual void mix(int16 *data, uint len) = 0;
void destroy() {
_toBeDestroyed = true;
@@ -196,16 +197,14 @@ public:
// start playing a raw sound
enum {
// Do *NOT* change any of these flags without looking at the code in mixer.cpp
- FLAG_UNSIGNED = 1, // unsigned samples
- FLAG_STEREO = 2, // sound is in stereo
- FLAG_16BITS = 4, // sound is 16 bits wide
- FLAG_AUTOFREE = 8, // sound buffer is freed automagically at the end of playing
- FLAG_FILE = 16, // sound is a FILE * that's read from
- FLAG_REVERSE_STEREO = 32, // sound should be reverse stereo
- FLAG_LOOP = 64 // loop the audio
+ 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 playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id);
+ int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1);
int playStream(PlayingSoundHandle *handle, int index, void *sound, uint32 size, uint rate,
byte flags, int32 timeout = 3, int32 buffer_size = 2000000);
#ifdef USE_MAD
@@ -228,6 +227,9 @@ public:
/* stop playing a specific sound */
void stop(int index);
+ /* stop playing a specific sound */
+ void stopID(int id);
+
/* append to existing sound */
int append(int index, void * sound, uint32 size, uint rate, byte flags);