diff options
author | Max Horn | 2003-07-29 01:37:03 +0000 |
---|---|---|
committer | Max Horn | 2003-07-29 01:37:03 +0000 |
commit | 77eb28406227d041d7b5395540727b4af4ca2349 (patch) | |
tree | 96ad59bbc182d7e74e51335be1475d15d724e55c /sound | |
parent | 1be944755f1f089b5b000852a9fc34c8b5eea017 (diff) | |
download | scummvm-rg350-77eb28406227d041d7b5395540727b4af4ca2349.tar.gz scummvm-rg350-77eb28406227d041d7b5395540727b4af4ca2349.tar.bz2 scummvm-rg350-77eb28406227d041d7b5395540727b4af4ca2349.zip |
added VorbisInputStream
svn-id: r9271
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiostream.cpp | 99 | ||||
-rw-r--r-- | sound/audiostream.h | 26 | ||||
-rw-r--r-- | sound/rate.h | 2 |
3 files changed, 126 insertions, 1 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 130b4c9817..40e06eb429 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -22,6 +22,7 @@ #include "audiostream.h" #include "mixer.h" #include "common/engine.h" +#include "common/util.h" template<bool is16Bit, bool isUnsigned> @@ -153,6 +154,104 @@ void WrappedMemoryStream<stereo, is16Bit, isUnsigned>::append(const byte *data, #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 - #pragma mark --- Input stream factories --- #pragma mark - diff --git a/sound/audiostream.h b/sound/audiostream.h index fbe2f722de..c7c2614230 100644 --- a/sound/audiostream.h +++ b/sound/audiostream.h @@ -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 @@ -63,4 +66,27 @@ public: 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 diff --git a/sound/rate.h b/sound/rate.h index 2ac69cc411..d0ebf0ae05 100644 --- a/sound/rate.h +++ b/sound/rate.h @@ -94,7 +94,7 @@ public: }; 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); |