diff --git a/sound/imp/input_audiere.cpp b/sound/imp/input_audiere.cpp index 624b2050b..b7a38ffd1 100644 --- a/sound/imp/input_audiere.cpp +++ b/sound/imp/input_audiere.cpp @@ -1,6 +1,8 @@ #include "input_audiere.h" #include +#include "../../stream/imp_client/audiere_file.h" + // Exception handling class Audiere_Exception : public std::exception { @@ -25,14 +27,14 @@ using namespace Mangle::Sound; AudiereInput::AudiereInput() { - canLoadStream = false; + canLoadStream = true; } InputSource *AudiereInput::load(const std::string &file) { return new AudiereSource(file); } InputSource *AudiereInput::load(Stream::InputStream *input) -{ assert(0 && "not implemented yet"); } +{ return new AudiereSource(input); } // --- InputSource --- @@ -45,6 +47,16 @@ AudiereSource::AudiereSource(const std::string &file) buf = CreateSampleBuffer(sample); } +AudiereSource::AudiereSource(Stream::InputStream *input) +{ + SampleSourcePtr sample = OpenSampleSource + (new Stream::AudiereFile(input)); + if(!sample) + fail("Couldn't load stream"); + + buf = CreateSampleBuffer(sample); +} + InputStream *AudiereSource::getStream() { return new AudiereStream(buf->openStream()); diff --git a/sound/imp/input_audiere.h b/sound/imp/input_audiere.h index 344c07735..4bc42cbc6 100644 --- a/sound/imp/input_audiere.h +++ b/sound/imp/input_audiere.h @@ -28,6 +28,7 @@ class AudiereSource : public InputSource public: AudiereSource(const std::string &file); + AudiereSource(Stream::InputStream *input); InputStream *getStream(); void drop() { delete this; } }; diff --git a/sound/tests/Makefile b/sound/tests/Makefile index 22da35432..5d38b4d1d 100644 --- a/sound/tests/Makefile +++ b/sound/tests/Makefile @@ -9,7 +9,7 @@ L_AUDIERE=-laudiere ffmpeg_openal_test: ffmpeg_openal_test.cpp ../imp/input_ffmpeg.cpp ../imp/output_openal.cpp $(GCC) $^ -o $@ $(L_FFMPEG) $(L_OPENAL) -openal_audiere_test: openal_audiere_test.cpp ../imp/input_audiere.cpp ../imp/output_openal.cpp +openal_audiere_test: openal_audiere_test.cpp ../imp/input_audiere.cpp ../imp/output_openal.cpp ../../stream/imp_client/audiere_file.cpp $(GCC) $^ -o $@ $(L_AUDIERE) $(L_OPENAL) audiere_test: audiere_test.cpp ../imp/audiere_imp.cpp diff --git a/sound/tests/common.cpp b/sound/tests/common.cpp index 78dbce5b2..28c470536 100644 --- a/sound/tests/common.cpp +++ b/sound/tests/common.cpp @@ -1,20 +1,67 @@ // This file is included directly into the test programs #include +#include #include using namespace std; -void play(const char* name, bool music=false) +class TestStream : public Mangle::Stream::InputStream { - cout << "Playing " << name << "\n"; + ifstream io; + +public: + + TestStream(const char* name) + { + io.open(name, ios::binary); + isSeekable = true; + hasPosition = true; + hasSize = false; + } + + size_t read(void* buf, size_t len) + { + io.read((char*)buf, len); + return io.gcount(); + } + + void seek(size_t pos) + { + io.seekg(pos); + } + + size_t tell() const + { return ((TestStream*)this)->io.tellg(); } + + size_t size() const + { return 0; } + + bool eof() const + { return io.eof(); } +}; + +void play(const char* name, bool music=false, bool stream=false) +{ + // Only load streams if the backend supports it + if(stream && !mg.canLoadStream) + return; + + cout << "Playing " << name; + if(stream) cout << " (from stream)"; + cout << "\n"; Sound *snd = NULL; Instance *s = NULL; try { - snd = mg.load(name, music); + if(stream) + snd = mg.load(new TestStream(name), music); + else + snd = mg.load(name, music); + + s = snd->getInstance(false, false); s->play(); @@ -37,5 +84,6 @@ int main() { play("cow.wav"); play("owl.ogg", true); + play("cow.wav", false, true); return 0; }