first commit
This commit is contained in:
47
include/framework/audio/audio_io.h
Normal file
47
include/framework/audio/audio_io.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __AUDIOIO__
|
||||
#define __AUDIOIO__
|
||||
|
||||
|
||||
#include "audio/stream_interface.h"
|
||||
#include "audio/stream_factory.h"
|
||||
#include "audio/sample_interface.h"
|
||||
#include "audio/sample_factory.h"
|
||||
#include "memory/singleton.h"
|
||||
#include "container/nlist.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
/*
|
||||
@short Audio factory.
|
||||
@author Emmanuel Julien (ejulien@owloh.com)
|
||||
*/
|
||||
class AudioIO : public Singleton <AudioIO>
|
||||
{
|
||||
AutoList <IAudioStreamFactory *> stream_factories;
|
||||
AutoList <ISampleFactory *> sample_factories;
|
||||
|
||||
public:
|
||||
|
||||
/// Register a stream codec.
|
||||
void RegisterStreamFactory(IAudioStreamFactory *);
|
||||
/// Register a sample codec.
|
||||
void RegisterSampleFactory(ISampleFactory *);
|
||||
|
||||
/// Open stream.
|
||||
IAudioStream *OpenStream(const char *path, const char *format = 0);
|
||||
/// Load a sample.
|
||||
ISample *LoadSample(const char *path, const char *format = 0);
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __AUDIOIO__
|
||||
|
||||
32
include/framework/audio/sample_factory.h
Normal file
32
include/framework/audio/sample_factory.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __ISAMPLEFACTORY__
|
||||
#define __ISAMPLEFACTORY__
|
||||
|
||||
|
||||
namespace GS {
|
||||
struct ISample;
|
||||
|
||||
/*
|
||||
@short Sample I/O codec interface.
|
||||
@author Emmanuel Julien (ejulien@owloh.com)
|
||||
*/
|
||||
struct ISampleFactory
|
||||
{
|
||||
/// Get the codec name.
|
||||
virtual const char *GetName() = 0;
|
||||
/// Load a sample.
|
||||
virtual ISample *Load(const char *path) = 0;
|
||||
|
||||
virtual ~ISampleFactory() {}
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __ISAMPLEFACTORY__
|
||||
|
||||
46
include/framework/audio/sample_format.h
Normal file
46
include/framework/audio/sample_format.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NSAMPLEFORMAT__
|
||||
#define __NSAMPLEFORMAT__
|
||||
|
||||
|
||||
#include "ntypes.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
/*!
|
||||
@short Sample format.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct SampleFormat
|
||||
{
|
||||
enum Format
|
||||
{
|
||||
Format_PCM = 0,
|
||||
#if __PLATFORM_NINTENDO_WII__
|
||||
Format_Wii_ADPCM
|
||||
#endif
|
||||
};
|
||||
|
||||
Format format;
|
||||
uint channels;
|
||||
|
||||
uint frequency;
|
||||
uchar resolution;
|
||||
|
||||
/// Get the PCM data memory footprint a given number of samples in this format.
|
||||
uint GetPCMDataSize(uint sample_count) const
|
||||
{ return (sample_count * channels * resolution) / 8; }
|
||||
|
||||
SampleFormat(Format _format = Format_PCM, uint _channels = 2, uint _frequency = 48000, uchar _bit_per_sample = 16) : format(_format), channels(_channels), frequency(_frequency), resolution(_bit_per_sample) {}
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NSAMPLEFORMAT__
|
||||
37
include/framework/audio/sample_interface.h
Normal file
37
include/framework/audio/sample_interface.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __ISAMPLE__
|
||||
#define __ISAMPLE__
|
||||
|
||||
|
||||
#include "audio/sample_format.h"
|
||||
#include "time/ntime.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
/*!
|
||||
@short Sample base interface.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct ISample
|
||||
{
|
||||
/// Return the format identifier (eg. "WAV").
|
||||
virtual const char *GetFormat() = 0;
|
||||
|
||||
/// Get sample format.
|
||||
virtual bool GetSampleFormat(SampleFormat &) const = 0;
|
||||
/// Get sample duration.
|
||||
virtual Time GetDuration() const = 0;
|
||||
|
||||
virtual ~ISample() {}
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __ISAMPLE__
|
||||
34
include/framework/audio/sample_stream_factory.h
Normal file
34
include/framework/audio/sample_stream_factory.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __SAMPLESTREAMFACTORY__
|
||||
#define __SAMPLESTREAMFACTORY__
|
||||
|
||||
|
||||
#include "audio/sample_interface.h"
|
||||
#include "audio/sample_factory.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
struct ISample;
|
||||
|
||||
/*!
|
||||
@short Sample stream factory
|
||||
This codec can decode any supported audio stream to a WAV sample.
|
||||
@author Emmanuel Julien (ejulien@owloh.com)
|
||||
*/
|
||||
struct SampleStreamFactory : public ISampleFactory
|
||||
{
|
||||
/// Get the codec name.
|
||||
virtual const char *GetName() { return "Stream"; }
|
||||
/// Load a sample.
|
||||
virtual ISample *Load(const char *path);
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __SAMPLESTREAMFACTORY__
|
||||
60
include/framework/audio/sample_wav.h
Normal file
60
include/framework/audio/sample_wav.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __SAMPLEWAV__
|
||||
#define __SAMPLEWAV__
|
||||
|
||||
|
||||
#include "audio/sample_interface.h"
|
||||
#include "time/ntime.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
/*!
|
||||
@short WAV sample.
|
||||
@author Emmanuel Julien (ejulien@owloh.com)
|
||||
*/
|
||||
class SampleWav : public ISample
|
||||
{
|
||||
friend struct SampleWavFactory;
|
||||
|
||||
protected:
|
||||
|
||||
SampleFormat format;
|
||||
|
||||
uint sample_count;
|
||||
Array <char> pcm_data;
|
||||
|
||||
public:
|
||||
|
||||
/// Return the sample count.
|
||||
uint GetSampleCount() const { return sample_count; }
|
||||
/// Return the PCM data.
|
||||
void *GetPCMData() const { return pcm_data.c_ptr(); }
|
||||
/// Return the PCM data size.
|
||||
uint GetPCMDataSize() const;
|
||||
|
||||
/// Set PCM data, the data array content will be transfered to the sample.
|
||||
void Set(Array <char> &data, uint sample_count, const SampleFormat &);
|
||||
/// Allocate PCM samples for a given format.
|
||||
char *AllocAs(uint sample_count, const SampleFormat &);
|
||||
|
||||
/// Return the sample format identifier (eg. "WAV").
|
||||
virtual const char *GetFormat() { return "WAV"; }
|
||||
|
||||
/// Get the sample format.
|
||||
virtual bool GetSampleFormat(SampleFormat &) const;
|
||||
/// Get sample duration.
|
||||
virtual Time GetDuration() const;
|
||||
|
||||
SampleWav() : sample_count(0) {}
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __SAMPLEWAV__
|
||||
29
include/framework/audio/sample_wav_factory.h
Normal file
29
include/framework/audio/sample_wav_factory.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __SAMPLEWAVCODEC__
|
||||
#define __SAMPLEWAVCODEC__
|
||||
|
||||
|
||||
#include "audio/sample_factory.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
struct ISample;
|
||||
|
||||
/// Sample WAV codec
|
||||
struct SampleWavFactory : public ISampleFactory
|
||||
{
|
||||
/// Get the codec name.
|
||||
virtual const char *GetName() { return "WAV"; }
|
||||
/// Load a sample.
|
||||
virtual ISample *Load(const char *path);
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __SAMPLEWAVCODEC__
|
||||
31
include/framework/audio/stream_factory.h
Normal file
31
include/framework/audio/stream_factory.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __ISTREAMFACTORY__
|
||||
#define __ISTREAMFACTORY__
|
||||
|
||||
|
||||
namespace GS {
|
||||
struct IAudioStream;
|
||||
|
||||
/*
|
||||
@short Stream factory interface.
|
||||
@author Emmanuel Julien (ejulien@owloh.com)
|
||||
*/
|
||||
struct IAudioStreamFactory
|
||||
{
|
||||
/// Get factory name.
|
||||
virtual const char *GetName() = 0;
|
||||
/// Open a stream.
|
||||
virtual IAudioStream *Open(const char *path) = 0;
|
||||
|
||||
virtual ~IAudioStreamFactory() {}
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __ISTREAMFACTORY__
|
||||
42
include/framework/audio/stream_interface.h
Normal file
42
include/framework/audio/stream_interface.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __AUDIOSTREAMINTERFACE__
|
||||
#define __AUDIOSTREAMINTERFACE__
|
||||
|
||||
|
||||
#include "audio/sample_format.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
/*
|
||||
@short Audio stream interface.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
struct IAudioStream
|
||||
{
|
||||
SampleFormat format;
|
||||
|
||||
/// Return the stream data format (eg. "OGG").
|
||||
virtual const char *GetFormat() = 0;
|
||||
|
||||
virtual bool Seek(int t_ms = 0) = 0;
|
||||
virtual bool IsEOF() const = 0;
|
||||
|
||||
virtual size_t GetPCM(void *) = 0;
|
||||
virtual size_t GetPCMBufferSize() const = 0;
|
||||
|
||||
virtual bool Open(const char *uri) = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual ~IAudioStream() {}
|
||||
};
|
||||
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __AUDIOSTREAMINTERFACE__
|
||||
Reference in New Issue
Block a user