|
|
|
@ -6,19 +6,21 @@
|
|
|
|
|
namespace Mangle {
|
|
|
|
|
namespace Sound {
|
|
|
|
|
|
|
|
|
|
/// A sample source reading directly from a memory buffer
|
|
|
|
|
class MemorySource : public SampleSource
|
|
|
|
|
/// A class for reading raw samples directly from a stream.
|
|
|
|
|
class Stream2Samples : public SampleSource
|
|
|
|
|
{
|
|
|
|
|
char *buf;
|
|
|
|
|
size_t len;
|
|
|
|
|
size_t pos;
|
|
|
|
|
|
|
|
|
|
int32_t rate, channels, bits;
|
|
|
|
|
Stream::StreamPtr inp;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
MemorySource(void *_buf, size_t _len, int32_t _rate, int32_t _channels, int32_t _bits)
|
|
|
|
|
: len(_len), pos(0), rate(_rate), channels(_channels), bits(_bits)
|
|
|
|
|
{ buf = (char*)_buf; }
|
|
|
|
|
Stream2Samples(Stream::StreamPtr _inp, int32_t _rate, int32_t _channels, int32_t _bits)
|
|
|
|
|
: inp(_inp), rate(_rate), channels(_channels), bits(_bits)
|
|
|
|
|
{
|
|
|
|
|
isSeekable = inp->isSeekable;
|
|
|
|
|
hasPosition = inp->hasPosition;
|
|
|
|
|
hasSize = inp->hasSize;
|
|
|
|
|
hasPtr = inp->hasPtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the sample rate, number of channels, and bits per
|
|
|
|
|
/// sample. NULL parameters are ignored.
|
|
|
|
@ -29,20 +31,16 @@ class MemorySource : public SampleSource
|
|
|
|
|
if(_bits) *_bits = bits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool eof() const { return pos == len; }
|
|
|
|
|
|
|
|
|
|
size_t read(void *out, size_t count)
|
|
|
|
|
{
|
|
|
|
|
assert(len >= pos);
|
|
|
|
|
|
|
|
|
|
if(count > (len-pos))
|
|
|
|
|
count = len-pos;
|
|
|
|
|
|
|
|
|
|
if(count) memcpy(out, buf+pos, count);
|
|
|
|
|
pos += count;
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
{ return inp->read(out, count); }
|
|
|
|
|
|
|
|
|
|
void seek(size_t pos) { inp->seek(pos); }
|
|
|
|
|
size_t tell() const { return inp->tell(); }
|
|
|
|
|
size_t size() const { return inp->size(); }
|
|
|
|
|
bool eof() const { return inp->eof(); }
|
|
|
|
|
void *getPtr() const { return inp->getPtr(); }
|
|
|
|
|
void *getPtr(size_t size) const { return inp->getPtr(size); }
|
|
|
|
|
void *getPtr(size_t pos, size_t size) const { return inp->getPtr(pos, size); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}} // namespaces
|
|
|
|
|