aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorPaweł Kołodziejski2004-04-25 18:43:46 +0000
committerPaweł Kołodziejski2004-04-25 18:43:46 +0000
commit43979c90122e2baaf365046d232b8d4b5245d8c4 (patch)
tree9a1a8608fd872ac27091ed1d8bc6ab1bc437b6fe /sound
parentcc5fb7fc58283512a344dc1f49698e1426788602 (diff)
downloadscummvm-rg350-43979c90122e2baaf365046d232b8d4b5245d8c4.tar.gz
scummvm-rg350-43979c90122e2baaf365046d232b8d4b5245d8c4.tar.bz2
scummvm-rg350-43979c90122e2baaf365046d232b8d4b5245d8c4.zip
delete CustomProcInputStream and add getFreeSpace for appendable audiostream
svn-id: r13629
Diffstat (limited to 'sound')
-rw-r--r--sound/audiostream.cpp44
-rw-r--r--sound/audiostream.h26
2 files changed, 16 insertions, 54 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp
index 0c31a65f0e..02889fc714 100644
--- a/sound/audiostream.cpp
+++ b/sound/audiostream.cpp
@@ -214,6 +214,7 @@ public:
void append(const byte *data, uint32 len);
void finish() { _finalized = true; }
+ uint32 getFreeSpace();
};
@@ -298,6 +299,20 @@ void AppendableMemoryStream<stereo, is16Bit, isUnsigned>::append(const byte *dat
}
}
+template<bool stereo, bool is16Bit, bool isUnsigned>
+uint32 AppendableMemoryStream<stereo, is16Bit, isUnsigned>::getFreeSpace() {
+ uint32 free;
+
+ if (_pos <= _end) {
+ uint32 free_from_end = _bufferEnd - _end;
+ uint32 free_to_pos = _pos - _bufferStart;
+ free = free_from_end + free_to_pos;
+ } else {
+ free = _pos - _end;
+ }
+
+ return free;
+}
#pragma mark -
#pragma mark --- Procedural stream ---
@@ -336,35 +351,6 @@ public:
};
#endif
-CustomProcInputStream::CustomProcInputStream(int rate, byte flags, CustomInputProc proc, void *refCon) {
- _refCon = refCon;
- _refStream = this;
- _rate = rate;
- _proc = proc;
- _finished = false;
- _isStereo = (flags & SoundMixer::FLAG_STEREO) != 0;
- _is16Bit = (flags & SoundMixer::FLAG_16BITS) != 0;
- _isUnsigned = (flags & SoundMixer::FLAG_UNSIGNED) != 0;
- assert(!(flags & SoundMixer::FLAG_LITTLE_ENDIAN));
- assert(!(flags & SoundMixer::FLAG_AUTOFREE));
-}
-
-int CustomProcInputStream::readBuffer(int16 *buffer, const int numSamples) {
- int numBytes = numSamples;
- numBytes *= (_is16Bit ? 2 : 1);
- byte *tmpBuffer = (byte *)malloc(numBytes);
- int gotSamples = (_proc)(_refCon, _refStream, tmpBuffer, numBytes) / (_is16Bit ? 2 : 1);
-
- const byte *ptr = tmpBuffer;
- for (int samples = 0; samples < gotSamples; samples++) {
- *buffer++ = READSAMPLE(_is16Bit, _isUnsigned, ptr);
- ptr += (_is16Bit ? 2 : 1);
- }
-
- free(tmpBuffer);
- return gotSamples;
-}
-
#pragma mark -
#pragma mark --- Input stream factories ---
#pragma mark -
diff --git a/sound/audiostream.h b/sound/audiostream.h
index 5e6c41fdfc..2dbc1ae81c 100644
--- a/sound/audiostream.h
+++ b/sound/audiostream.h
@@ -93,6 +93,7 @@ class AppendableAudioStream : public AudioStream {
public:
virtual void append(const byte *data, uint32 len) = 0;
virtual void finish() = 0;
+ virtual uint32 getFreeSpace() = 0;
};
class ZeroInputStream : public AudioStream {
@@ -113,31 +114,6 @@ public:
int getRate() const { return -1; }
};
-class CustomProcInputStream : public AudioStream {
-public:
- typedef int (*CustomInputProc)(void *refCon, CustomProcInputStream *stream, byte *data, uint len);
-
-private:
- bool _isStereo;
- bool _is16Bit;
- bool _isUnsigned;
- int _rate;
- CustomInputProc _proc;
- CustomProcInputStream *_refStream;
- void *_refCon;
- bool _finished;
-
-public:
-
- CustomProcInputStream(int rate, byte flags, CustomInputProc proc, void *refCon);
-
- int readBuffer(int16 *buffer, const int numSamples);
- bool isStereo() const { return _isStereo; }
- bool endOfData() const { return _finished; }
- void finish() { _finished = true; }
- int getRate() const { return _rate; }
-};
-
AudioStream *makeLinearInputStream(int rate, byte _flags, const byte *ptr, uint32 len, uint loopOffset, uint loopLen);
AppendableAudioStream *makeAppendableAudioStream(int rate, byte _flags, uint32 len);