Files
Webcam/include/framework/audio/audio_io.cpp

53 lines
1.6 KiB
C++

/* -----------------------------------------------------------------------------
GSFramework
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */
#include "audio/audio_io.h"
#include "filesystem/filesystem.h"
#include "platform.h"
#include "log/log.h"
using namespace GS;
template<> AudioIO *Singleton <AudioIO> ::i = NULL;
//------------------------------------------------------------------------------
void AudioIO::RegisterStreamFactory(IAudioStreamFactory *f)
{ stream_factories.Add(f); }
void AudioIO::RegisterSampleFactory(ISampleFactory *f)
{ sample_factories.Add(f); }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
ISample *AudioIO::LoadSample(const char *path, const char *format)
{
String fmt(format);
if (Platform::Get().io->Exists(path))
ListForeachPtr(ISampleFactory *, codec, sample_factories)
if (ISample *sample = codec->Load(path))
{
if (!fmt || (fmt == sample->GetFormat()))
return sample;
_safe_delete(sample);
}
return NULL;
}
IAudioStream *AudioIO::OpenStream(const char *path, const char *format)
{
String fmt(format);
if (Platform::Get().io->Exists(path))
ListForeachPtr(IAudioStreamFactory *, codec, stream_factories)
if (IAudioStream *stream = codec->Open(path))
{
if (!fmt || (fmt == stream->GetFormat()))
return stream;
_safe_delete(stream);
}
return NULL;
}
//------------------------------------------------------------------------------