aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2004-01-03 00:33:14 +0000
committerMax Horn2004-01-03 00:33:14 +0000
commitd335bce62df47217546639b8816f8203f0137d37 (patch)
treea5f361352111c9b20856e7ab1a5963cbe37d37de
parent8bd9ce2949ca7e607da2aa18d3af7cd8e8d25a09 (diff)
downloadscummvm-rg350-d335bce62df47217546639b8816f8203f0137d37.tar.gz
scummvm-rg350-d335bce62df47217546639b8816f8203f0137d37.tar.bz2
scummvm-rg350-d335bce62df47217546639b8816f8203f0137d37.zip
added makeVOCStream() (convenience function)
svn-id: r12094
-rw-r--r--sound/voc.cpp38
-rw-r--r--sound/voc.h4
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