1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 21:49:55 +00:00

Added stream capability to Audiere input

This commit is contained in:
Nicolay Korslund 2009-12-26 14:49:43 +01:00
parent d763b9dbb6
commit abee2689e3
4 changed files with 67 additions and 6 deletions

View file

@ -1,6 +1,8 @@
#include "input_audiere.h"
#include <assert.h>
#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());

View file

@ -28,6 +28,7 @@ class AudiereSource : public InputSource
public:
AudiereSource(const std::string &file);
AudiereSource(Stream::InputStream *input);
InputStream *getStream();
void drop() { delete this; }
};

View file

@ -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

View file

@ -1,20 +1,67 @@
// This file is included directly into the test programs
#include <iostream>
#include <fstream>
#include <exception>
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
{
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;
}