[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.16,1.17 audiostream.h,1.12,1.13 mixer.cpp,1.90,1.91 mixer.h,1.37,1.38 rate.h,1.10,1.11
Max Horn
fingolfin at users.sourceforge.net
Fri Aug 1 05:50:08 CEST 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv10957
Modified Files:
audiostream.cpp audiostream.h mixer.cpp mixer.h rate.h
Log Message:
implemented raw sound looping; some debug output enabled temporarily
Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- audiostream.cpp 31 Jul 2003 19:32:38 -0000 1.16
+++ audiostream.cpp 1 Aug 2003 12:49:24 -0000 1.17
@@ -40,7 +40,7 @@
template<bool stereo, bool is16Bit, bool isUnsigned>
-class LinearMemoryStream : public AudioInputStream {
+class LinearMemoryStream : public LinearAudioInputStream {
protected:
const byte *_ptr;
const byte *_end;
@@ -58,11 +58,17 @@
return val;
}
bool eof() const {
- return _end <= _ptr;
+ return _ptr >= _end;
}
bool isStereo() const {
return stereo;
}
+ void reset(const byte *data, uint32 len) {
+ _ptr = data;
+ _end = data + len;
+ if (stereo) // Stereo requires even sized data
+ assert(len % 2 == 0);
+ }
};
@@ -413,7 +419,7 @@
template<bool stereo>
-static AudioInputStream *makeLinearInputStream(const byte *ptr, uint32 len, bool is16Bit, bool isUnsigned) {
+static LinearAudioInputStream *makeLinearInputStream(const byte *ptr, uint32 len, bool is16Bit, bool isUnsigned) {
if (isUnsigned) {
if (is16Bit)
return new LinearMemoryStream<stereo, true, true>(ptr, len);
@@ -444,7 +450,7 @@
}
-AudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len) {
+LinearAudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len) {
const bool is16Bit = (_flags & SoundMixer::FLAG_16BITS) != 0;
const bool isUnsigned = (_flags & SoundMixer::FLAG_UNSIGNED) != 0;
if (_flags & SoundMixer::FLAG_STEREO) {
Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- audiostream.h 1 Aug 2003 12:19:52 -0000 1.12
+++ audiostream.h 1 Aug 2003 12:49:24 -0000 1.13
@@ -53,6 +53,11 @@
virtual bool eof() const = 0;
};
+class LinearAudioInputStream : public AudioInputStream {
+public:
+ virtual void reset(const byte *data, uint32 len) = 0;
+};
+
class WrappedAudioInputStream : public AudioInputStream {
public:
virtual void append(const byte *data, uint32 len) = 0;
@@ -118,7 +123,7 @@
-AudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len);
+LinearAudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len);
WrappedAudioInputStream *makeWrappedInputStream(byte _flags, uint32 len);
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- mixer.cpp 31 Jul 2003 20:28:11 -0000 1.90
+++ mixer.cpp 1 Aug 2003 12:49:24 -0000 1.91
@@ -67,19 +67,19 @@
byte _flags;
#ifdef SOX_HACK
RateConverter *_converter;
- AudioInputStream *_input;
+ LinearAudioInputStream *_input;
#else
uint32 _pos;
uint32 _size;
uint32 _fpSpeed;
uint32 _fpPos;
uint32 _realSize, _rate;
+#endif
byte *_loop_ptr;
uint32 _loop_size;
-#endif
public:
- ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id);
+ ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, uint32 loopStart, uint32 loopEnd);
~ChannelRaw();
void mix(int16 *data, uint len);
@@ -272,7 +272,7 @@
return index;
}
-int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id) {
+int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, uint32 loopStart, uint32 loopEnd) {
StackLock lock(_mutex);
// Prevent duplicate sounds
@@ -282,7 +282,7 @@
return -1;
}
- return insertChannel(handle, new ChannelRaw(this, handle, sound, size, rate, flags, id));
+ return insertChannel(handle, new ChannelRaw(this, handle, sound, size, rate, flags, id, loopStart, loopEnd));
}
#ifdef USE_MAD
@@ -651,7 +651,7 @@
#endif
/* RAW mixer */
-ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id)
+ChannelRaw::ChannelRaw(SoundMixer *mixer, PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id, uint32 loopStart, uint32 loopEnd)
: Channel(mixer, handle) {
_id = id;
_ptr = (byte *)sound;
@@ -665,6 +665,23 @@
// Get a rate converter instance
_converter = makeRateConverter(rate, mixer->getOutputRate(), _input->isStereo());
+ printf(" data has %d bits and is %s\n",
+ ((flags & SoundMixer::FLAG_16BITS) ? 16 : 8),
+ ((flags & SoundMixer::FLAG_UNSIGNED) ? "unsigned" : "signed"));
+
+ if (flags & SoundMixer::FLAG_LOOP) {
+ if (loopEnd == 0) {
+ _loop_ptr = _ptr;
+ _loop_size = size;
+ } else {
+ assert(loopStart < loopEnd && loopEnd <= size);
+ _loop_ptr = _ptr + loopStart;
+ _loop_size = loopEnd - loopStart;
+ }
+ } else {
+ _loop_ptr = 0;
+ _loop_size = 0;
+ }
#else
_pos = 0;
_fpPos = 0;
@@ -705,9 +722,13 @@
if (_input->eof()) {
// TODO: call drain method
- // TODO: Looping
- destroy();
- return;
+ // Loop if requested
+ if (_loop_ptr) {
+ _input->reset(_loop_ptr, _loop_size);
+ } else {
+ destroy();
+ return;
+ }
}
const int volume = _mixer->getVolume();
@@ -756,6 +777,9 @@
// Get a rate converter instance
_converter = makeRateConverter(rate, mixer->getOutputRate(), _input->isStereo());
+ printf(" data has %d bits and is %s\n",
+ ((flags & SoundMixer::FLAG_16BITS) ? 16 : 8),
+ ((flags & SoundMixer::FLAG_UNSIGNED) ? "unsigned" : "signed"));
#else
_flags = flags;
_bufferSize = buffer_size;
Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- mixer.h 1 Aug 2003 12:19:53 -0000 1.37
+++ mixer.h 1 Aug 2003 12:49:24 -0000 1.38
@@ -82,7 +82,8 @@
~SoundMixer();
// start playing a raw sound
- int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id = -1);
+ int playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags,
+ int id = -1, uint32 loopStart = 0, uint32 loopEnd = 0);
#ifdef USE_MAD
int playMP3(PlayingSoundHandle *handle, File *file, uint32 size);
int playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration);
Index: rate.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/rate.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- rate.h 1 Aug 2003 12:19:53 -0000 1.10
+++ rate.h 1 Aug 2003 12:49:24 -0000 1.11
@@ -94,7 +94,7 @@
};
static inline RateConverter *makeRateConverter(st_rate_t inrate, st_rate_t outrate, bool stereo) {
-// printf("makeRateConverter: inrate %d, outrate %d\n", inrate, outrate);
+printf("makeRateConverter: inrate %d, outrate %d, %s\n", inrate, outrate, (stereo ? "stereo" : "mono"));
if (inrate != outrate) {
return new LinearRateConverter(inrate, outrate);
//return new ResampleRateConverter(inrate, outrate, 1);
More information about the Scummvm-git-logs
mailing list