[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.106,1.107 mixer.h,1.38,1.39 rate.h,1.16,1.17 resample.cpp,1.7,1.8
Max Horn
fingolfin at users.sourceforge.net
Tue Aug 5 16:04:13 CEST 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv15943
Modified Files:
mixer.cpp mixer.h rate.h resample.cpp
Log Message:
some cleanup; added Channel::getVolume, once somebody tells me what exactly is needed, I can add per-channel volume, and also per-channel panning
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- mixer.cpp 5 Aug 2003 21:46:56 -0000 1.106
+++ mixer.cpp 5 Aug 2003 23:03:42 -0000 1.107
@@ -28,6 +28,15 @@
#include "sound/mixer.h"
#include "sound/rate.h"
+
+#pragma mark -
+#pragma mark --- Channel classes ---
+#pragma mark -
+
+
+/**
+ * Channels used by the sound mixer.
+ */
class Channel {
protected:
SoundMixer *_mixer;
@@ -36,35 +45,17 @@
AudioInputStream *_input;
public:
int _id;
+
Channel(SoundMixer *mixer, PlayingSoundHandle *handle)
: _mixer(mixer), _handle(handle), _converter(0), _input(0), _id(-1) {
assert(mixer);
}
- virtual ~Channel() {
- delete _converter;
- delete _input;
- if (_handle)
- *_handle = 0;
- }
-
- /* len indicates the number of sample *pairs*. So a value of
- 10 means that the buffer contains twice 10 sample, each
- 16 bits, for a total of 40 bytes.
- */
- virtual void mix(int16 *data, uint len) {
- assert(_input);
- assert(_converter);
-
- if (_input->eos()) {
- // TODO: call drain method
- destroy();
- return;
- }
-
- const int volume = isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume();
- _converter->flow(*_input, data, len, volume);
- }
+ virtual ~Channel();
void destroy();
+ virtual void mix(int16 *data, uint len);
+ virtual int getVolume() const {
+ return isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume();
+ }
virtual bool isMusicChannel() const = 0;
};
@@ -107,16 +98,13 @@
ChannelVorbis(SoundMixer *mixer, PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track);
bool isMusicChannel() const { return _is_cd_track; }
};
-#endif
+#endif // USE_VORBIS
+#pragma mark -
+#pragma mark --- SoundMixer ---
+#pragma mark -
-void Channel::destroy() {
- for (int i = 0; i != SoundMixer::NUM_CHANNELS; i++)
- if (_mixer->_channels[i] == this)
- _mixer->_channels[i] = 0;
- delete this;
-}
SoundMixer::SoundMixer() {
_syst = 0;
@@ -265,12 +253,11 @@
}
bool SoundMixer::bindToSystem(OSystem *syst) {
- uint rate = (uint) syst->property(OSystem::PROP_GET_SAMPLE_RATE, 0);
- _outputRate = rate;
_syst = syst;
_mutex = _syst->create_mutex();
+ _outputRate = (uint) syst->property(OSystem::PROP_GET_SAMPLE_RATE, 0);
- if (rate == 0)
+ if (_outputRate == 0)
error("OSystem returned invalid sample rate");
return syst->set_sound_proc(mixCallback, this, OSystem::SOUND_16BIT);
@@ -365,6 +352,41 @@
}
+#pragma mark -
+#pragma mark --- Channel implementations ---
+#pragma mark -
+
+
+Channel::~Channel() {
+ delete _converter;
+ delete _input;
+ if (_handle)
+ *_handle = 0;
+}
+
+void Channel::destroy() {
+ for (int i = 0; i != SoundMixer::NUM_CHANNELS; i++)
+ if (_mixer->_channels[i] == this)
+ _mixer->_channels[i] = 0;
+ delete this;
+}
+
+
+/* len indicates the number of sample *pairs*. So a value of
+ 10 means that the buffer contains twice 10 sample, each
+ 16 bits, for a total of 40 bytes.
+ */
+void Channel::mix(int16 *data, uint len) {
+ assert(_input);
+ if (_input->eos()) {
+ // TODO: call drain method
+ destroy();
+ } else {
+ assert(_converter);
+ _converter->flow(*_input, data, len, getVolume());
+ }
+}
+
/* RAW mixer */
ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, uint32 loopStart, uint32 loopEnd)
: Channel(mixer, handle) {
@@ -418,8 +440,6 @@
void ChannelStream::mix(int16 *data, uint len) {
assert(_input);
- assert(_converter);
-
if (_input->eos()) {
// TODO: call drain method
@@ -431,13 +451,11 @@
if (_finished) {
destroy();
}
-
return;
}
- const int volume = _mixer->getVolume(); // FIXME: Shouldn't this be music volume instead??
-// const int volume = isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume();
- _converter->flow(*_input, data, len, volume);
+ assert(_converter);
+ _converter->flow(*_input, data, len, getVolume());
}
#ifdef USE_MAD
Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- mixer.h 1 Aug 2003 12:49:24 -0000 1.38
+++ mixer.h 5 Aug 2003 23:03:42 -0000 1.39
@@ -20,8 +20,8 @@
*
*/
-#ifndef MIXER_H
-#define MIXER_H
+#ifndef SOUND_MIXER_H
+#define SOUND_MIXER_H
#include "stdafx.h"
#if defined(HAVE_CONFIG_H)
Index: rate.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/rate.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- rate.h 5 Aug 2003 00:29:37 -0000 1.16
+++ rate.h 5 Aug 2003 23:03:42 -0000 1.17
@@ -35,11 +35,6 @@
typedef uint32 st_size_t;
typedef uint32 st_rate_t;
-typedef struct {
- byte priv[1024];
-} eff_struct;
-typedef eff_struct *eff_t;
-
/* Minimum and maximum values a sample can hold. */
#define ST_SAMPLE_MAX 0x7fffL
#define ST_SAMPLE_MIN (-ST_SAMPLE_MAX - 1L)
Index: resample.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/resample.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- resample.cpp 5 Aug 2003 00:29:37 -0000 1.7
+++ resample.cpp 5 Aug 2003 23:03:42 -0000 1.8
@@ -58,6 +58,11 @@
/* resample includes */
#include "resample.h"
+typedef struct {
+ byte priv[1024];
+} eff_struct;
+typedef eff_struct *eff_t;
+
/* this Float MUST match that in filter.c */
#define Float double/*float*/
More information about the Scummvm-git-logs
mailing list