forked from teamnwah/openmw-tes3coop
Added stream capability to Audiere input
This commit is contained in:
parent
d763b9dbb6
commit
abee2689e3
4 changed files with 67 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include "input_audiere.h"
|
#include "input_audiere.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "../../stream/imp_client/audiere_file.h"
|
||||||
|
|
||||||
// Exception handling
|
// Exception handling
|
||||||
class Audiere_Exception : public std::exception
|
class Audiere_Exception : public std::exception
|
||||||
{
|
{
|
||||||
|
@ -25,14 +27,14 @@ using namespace Mangle::Sound;
|
||||||
|
|
||||||
AudiereInput::AudiereInput()
|
AudiereInput::AudiereInput()
|
||||||
{
|
{
|
||||||
canLoadStream = false;
|
canLoadStream = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputSource *AudiereInput::load(const std::string &file)
|
InputSource *AudiereInput::load(const std::string &file)
|
||||||
{ return new AudiereSource(file); }
|
{ return new AudiereSource(file); }
|
||||||
|
|
||||||
InputSource *AudiereInput::load(Stream::InputStream *input)
|
InputSource *AudiereInput::load(Stream::InputStream *input)
|
||||||
{ assert(0 && "not implemented yet"); }
|
{ return new AudiereSource(input); }
|
||||||
|
|
||||||
// --- InputSource ---
|
// --- InputSource ---
|
||||||
|
|
||||||
|
@ -45,6 +47,16 @@ AudiereSource::AudiereSource(const std::string &file)
|
||||||
buf = CreateSampleBuffer(sample);
|
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()
|
InputStream *AudiereSource::getStream()
|
||||||
{
|
{
|
||||||
return new AudiereStream(buf->openStream());
|
return new AudiereStream(buf->openStream());
|
||||||
|
|
|
@ -28,6 +28,7 @@ class AudiereSource : public InputSource
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudiereSource(const std::string &file);
|
AudiereSource(const std::string &file);
|
||||||
|
AudiereSource(Stream::InputStream *input);
|
||||||
InputStream *getStream();
|
InputStream *getStream();
|
||||||
void drop() { delete this; }
|
void drop() { delete this; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@ L_AUDIERE=-laudiere
|
||||||
ffmpeg_openal_test: ffmpeg_openal_test.cpp ../imp/input_ffmpeg.cpp ../imp/output_openal.cpp
|
ffmpeg_openal_test: ffmpeg_openal_test.cpp ../imp/input_ffmpeg.cpp ../imp/output_openal.cpp
|
||||||
$(GCC) $^ -o $@ $(L_FFMPEG) $(L_OPENAL)
|
$(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)
|
$(GCC) $^ -o $@ $(L_AUDIERE) $(L_OPENAL)
|
||||||
|
|
||||||
audiere_test: audiere_test.cpp ../imp/audiere_imp.cpp
|
audiere_test: audiere_test.cpp ../imp/audiere_imp.cpp
|
||||||
|
|
|
@ -1,20 +1,67 @@
|
||||||
// This file is included directly into the test programs
|
// This file is included directly into the test programs
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
using namespace std;
|
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;
|
Sound *snd = NULL;
|
||||||
Instance *s = NULL;
|
Instance *s = NULL;
|
||||||
|
|
||||||
try
|
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 = snd->getInstance(false, false);
|
||||||
s->play();
|
s->play();
|
||||||
|
|
||||||
|
@ -37,5 +84,6 @@ int main()
|
||||||
{
|
{
|
||||||
play("cow.wav");
|
play("cow.wav");
|
||||||
play("owl.ogg", true);
|
play("owl.ogg", true);
|
||||||
|
play("cow.wav", false, true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue