[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.h,1.9,1.10 audiostream.cpp,1.6,1.7 rate.h,1.8,1.9
Max Horn
fingolfin at users.sourceforge.net
Mon Jul 28 18:38:02 CEST 2003
Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv16779
Modified Files:
audiostream.h audiostream.cpp rate.h
Log Message:
added VorbisInputStream
Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- audiostream.h 28 Jul 2003 18:01:56 -0000 1.9
+++ audiostream.h 29 Jul 2003 01:37:02 -0000 1.10
@@ -24,6 +24,9 @@
#include "scummsys.h"
#include <assert.h>
+#ifdef USE_VORBIS
+#include <vorbis/vorbisfile.h>
+#endif
// TODO:
// * maybe make readIntern return 16.16 or 24.8 fixed point values
@@ -62,5 +65,28 @@
AudioInputStream *makeLinearInputStream(byte _flags, const byte *ptr, uint32 len);
WrappedAudioInputStream *makeWrappedInputStream(byte _flags, uint32 len);
+
+
+
+#ifdef USE_VORBIS
+class VorbisInputStream : public AudioInputStream {
+ OggVorbis_File *_ov_file;
+ int _end_pos;
+ bool _eof_flag;
+ int _channels;
+ int16 _buffer[4096];
+ int16 *_pos;
+
+ void refill();
+public:
+ // TODO
+ VorbisInputStream(OggVorbis_File *file, int duration);
+ int16 read();
+ int size() const;
+ bool isStereo() const { return _channels >= 2; }
+};
+#endif
+
+
#endif
Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- audiostream.cpp 28 Jul 2003 18:01:56 -0000 1.6
+++ audiostream.cpp 29 Jul 2003 01:37:02 -0000 1.7
@@ -22,6 +22,7 @@
#include "audiostream.h"
#include "mixer.h"
#include "common/engine.h"
+#include "common/util.h"
template<bool is16Bit, bool isUnsigned>
@@ -150,6 +151,104 @@
_end += len;
}
}
+
+
+#pragma mark -
+#pragma mark --- MP3 (MAD) stream ---
+#pragma mark -
+
+
+#ifdef USE_MAD
+class MP3InputStream : public AudioInputStream {
+ struct mad_stream _stream;
+ struct mad_frame _frame;
+ struct mad_synth _synth;
+ uint32 _posInFrame;
+public:
+ // TODO
+};
+#endif
+
+
+#pragma mark -
+#pragma mark --- Ogg Vorbis stream ---
+#pragma mark -
+
+
+#ifdef USE_VORBIS
+
+#ifdef CHUNKSIZE
+#define VORBIS_TREMOR
+#endif
+
+
+VorbisInputStream::VorbisInputStream(OggVorbis_File *file, int duration)
+ : _ov_file(file) {
+ _pos = _buffer + ARRAYSIZE(_buffer);
+ _channels = ov_info(_ov_file, -1)->channels;
+
+ if (duration)
+ _end_pos = ov_pcm_tell(_ov_file) + duration;
+ else
+ _end_pos = ov_pcm_total(_ov_file, -1);
+
+ _eof_flag = false;
+}
+
+int16 VorbisInputStream::read() {
+ if (_pos >= _buffer + ARRAYSIZE(_buffer)) {
+ refill();
+ }
+ return *_pos++;
+}
+
+int VorbisInputStream::size() const {
+ if (_eof_flag)
+ return 0;
+ return _end_pos - ov_pcm_tell(_ov_file);
+}
+
+void VorbisInputStream::refill() {
+ // Read the samples
+ uint len_left = sizeof(_buffer);
+ char *read_pos = (char *)_buffer;
+
+ while (len_left > 0) {
+ long result = ov_read(_ov_file, read_pos, len_left,
+#ifndef VORBIS_TREMOR
+#ifdef SCUMM_BIG_ENDIAN
+ 1,
+#else
+ 0,
+#endif
+ 2, // 16 bit
+ 1, // signed
+#endif
+ NULL);
+ if (result == 0) {
+ _eof_flag = true;
+ memset(read_pos, 0, len_left);
+ break;
+ } else if (result == OV_HOLE) {
+ // Possibly recoverable, just warn about it
+ warning("Corrupted data in Vorbis file");
+ } else if (result < 0) {
+ debug(1, "Decode error %d in Vorbis file", result);
+ // Don't delete it yet, that causes problems in
+ // the CD player emulation code.
+ _eof_flag = true;
+ memset(read_pos, 0, len_left);
+ break;
+ } else {
+ len_left -= result;
+ read_pos += result;
+ }
+ }
+
+ _pos = _buffer;
+}
+
+#endif
#pragma mark -
Index: rate.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/rate.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rate.h 29 Jul 2003 01:36:10 -0000 1.8
+++ rate.h 29 Jul 2003 01:37:03 -0000 1.9
@@ -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\n", inrate, outrate);
if (inrate != outrate) {
return new LinearRateConverter(inrate, outrate);
//return new ResampleRateConverter(inrate, outrate, 1);
More information about the Scummvm-git-logs
mailing list