mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-22 04:01:23 +00:00
cleanup; add stopID method to stop a currently playing sound via its ID
svn-id: r6835
This commit is contained in:
parent
4cdfd9c2be
commit
80e3c23482
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user