From d335bce62df47217546639b8816f8203f0137d37 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 3 Jan 2004 00:33:14 +0000 Subject: added makeVOCStream() (convenience function) svn-id: r12094 --- sound/voc.cpp | 38 ++++++++++++++++++++++++++++---------- sound/voc.h | 4 ++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/sound/voc.cpp b/sound/voc.cpp index af8b1c4a0a..f3d3d1319a 100644 --- a/sound/voc.cpp +++ b/sound/voc.cpp @@ -23,9 +23,24 @@ #include "stdafx.h" #include "common/util.h" #include "common/file.h" + +#include "sound/audiostream.h" +#include "sound/mixer.h" #include "sound/voc.h" +int getSampleRateFromVOCRate(int vocSR) { + if (vocSR == 0xa5 || vocSR == 0xa6 || vocSR == 0x83) { + return 11025; + } else if (vocSR == 0xd2 || vocSR == 0xd3) { + return 22050; + } else { + int sr = 1000000L / (256L - vocSR); + warning("inexact sample rate used: %i (0x%x)", sr, vocSR); + return sr; + } +} + byte *readVOCFromMemory(byte *ptr, int &size, int &rate, int &loops) { assert(memcmp(ptr, "Creative Voice File\x1A", 20) == 0); @@ -137,14 +152,17 @@ byte *loadVOCFile(File *file, int &size, int &rate) { return data; } -int getSampleRateFromVOCRate(int vocSR) { - if (vocSR == 0xa5 || vocSR == 0xa6 || vocSR == 0x83) { - return 11025; - } else if (vocSR == 0xd2 || vocSR == 0xd3) { - return 22050; - } else { - int sr = 1000000L / (256L - vocSR); - warning("inexact sample rate used: %i (0x%x)", sr, vocSR); - return sr; - } +AudioInputStream *makeVOCStream(byte *ptr) { + int size, rate, loops; + byte *data = readVOCFromMemory(ptr, size, rate, loops); + + return makeLinearInputStream(rate, SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_UNSIGNED, data, size, 0, 0); } + +AudioInputStream *makeVOCStream(File *file) { + int size, rate; + byte *data = loadVOCFile(file, size, rate); + + return makeLinearInputStream(rate, SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_UNSIGNED, data, size, 0, 0); +} + diff --git a/sound/voc.h b/sound/voc.h index 4eb44006b0..fd9da916e5 100644 --- a/sound/voc.h +++ b/sound/voc.h @@ -26,6 +26,7 @@ #include "stdafx.h" #include "common/scummsys.h" +class AudioInputStream; class File; #if !defined(__GNUC__) @@ -59,4 +60,7 @@ extern int getSampleRateFromVOCRate(int vocSR); extern byte *readVOCFromMemory(byte *ptr, int &size, int &rate, int &loops); extern byte *loadVOCFile(File *file, int &size, int &rate); +AudioInputStream *makeVOCStream(byte *ptr); +AudioInputStream *makeVOCStream(File *file); + #endif -- cgit v1.2.3