2010-06-03 18:13:27 +00:00
|
|
|
#include "audiere_source.hpp"
|
2009-12-28 16:15:52 +00:00
|
|
|
|
2010-06-03 18:13:27 +00:00
|
|
|
#include "../../stream/clients/audiere_file.hpp"
|
|
|
|
#include "../../tools/str_exception.hpp"
|
2009-12-28 16:15:52 +00:00
|
|
|
|
2010-01-01 17:42:35 +00:00
|
|
|
using namespace Mangle::Stream;
|
|
|
|
|
2009-12-28 16:15:52 +00:00
|
|
|
static void fail(const std::string &msg)
|
2010-01-02 12:06:37 +00:00
|
|
|
{ throw str_exception("Audiere exception: " + msg); }
|
2009-12-28 16:15:52 +00:00
|
|
|
|
|
|
|
using namespace audiere;
|
|
|
|
using namespace Mangle::Sound;
|
|
|
|
|
|
|
|
// --- SampleSource ---
|
|
|
|
|
|
|
|
void AudiereSource::getInfo(int32_t *rate, int32_t *channels, int32_t *bits)
|
|
|
|
{
|
|
|
|
SampleFormat fmt;
|
|
|
|
sample->getFormat(*channels, *rate, fmt);
|
2009-12-30 11:36:35 +00:00
|
|
|
if(bits)
|
|
|
|
{
|
|
|
|
if(fmt == SF_U8)
|
|
|
|
*bits = 8;
|
|
|
|
else if(fmt == SF_S16)
|
|
|
|
*bits = 16;
|
|
|
|
else assert(0);
|
|
|
|
}
|
2009-12-28 16:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- Constructors ---
|
|
|
|
|
|
|
|
AudiereSource::AudiereSource(const std::string &file)
|
|
|
|
{
|
|
|
|
sample = OpenSampleSource(file.c_str());
|
|
|
|
|
|
|
|
if(!sample)
|
|
|
|
fail("Couldn't load file " + file);
|
|
|
|
|
2010-08-16 12:13:13 +00:00
|
|
|
doSetup();
|
2009-12-28 16:15:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-01 17:42:35 +00:00
|
|
|
AudiereSource::AudiereSource(StreamPtr input)
|
2009-12-28 16:15:52 +00:00
|
|
|
{
|
|
|
|
// Use our Stream::AudiereFile implementation to convert a Mangle
|
|
|
|
// 'Stream' to an Audiere 'File'
|
2010-01-01 17:42:35 +00:00
|
|
|
sample = OpenSampleSource(new AudiereFile(input));
|
2009-12-28 16:15:52 +00:00
|
|
|
if(!sample)
|
|
|
|
fail("Couldn't load stream");
|
|
|
|
|
2010-08-16 12:13:13 +00:00
|
|
|
doSetup();
|
2009-12-28 16:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudiereSource::AudiereSource(audiere::SampleSourcePtr src)
|
|
|
|
: sample(src)
|
2010-08-16 12:13:13 +00:00
|
|
|
{ assert(sample); doSetup(); }
|
2009-12-28 16:15:52 +00:00
|
|
|
|
|
|
|
// Common function called from all constructors
|
2010-08-16 12:13:13 +00:00
|
|
|
void AudiereSource::doSetup()
|
2009-12-28 16:15:52 +00:00
|
|
|
{
|
|
|
|
assert(sample);
|
|
|
|
|
|
|
|
SampleFormat fmt;
|
|
|
|
int channels, rate;
|
|
|
|
sample->getFormat(channels, rate, fmt);
|
|
|
|
|
2010-08-16 12:13:13 +00:00
|
|
|
// Calculate the size of one frame, and pass it to SampleReader.
|
|
|
|
setup(GetSampleSize(fmt) * channels);
|
2009-12-30 11:36:35 +00:00
|
|
|
|
|
|
|
isSeekable = sample->isSeekable();
|
|
|
|
hasPosition = true;
|
|
|
|
hasSize = true;
|
2009-12-28 16:15:52 +00:00
|
|
|
}
|