Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TSOUND_INCLUDED
Toshihiro Shimizu 890ddd
#define TSOUND_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tsmartpointer.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tthreadmessage.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TSOUND_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace TSound
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
typedef UCHAR Channel;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
const int MONO = 0;
Toshihiro Shimizu 890ddd
const int LEFT = 0;
Toshihiro Shimizu 890ddd
const int RIGHT = LEFT + 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=========================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TSoundTrack;
Toshihiro Shimizu 890ddd
class TSoundTransform;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
template class DVAPI TSmartPointerT<tsoundtrack>;</tsoundtrack>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef TSmartPointerT<tsoundtrack> TSoundTrackP;</tsoundtrack>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The class TSoundTrackFormat contains the main features of a TSoundTrack as:
Toshihiro Shimizu 890ddd
  sample rate, bit per sample, number of channels and signed or unsigned sample
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class DVAPI TSoundTrackFormat
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TUINT32 m_sampleRate; // frequenza di campionamento
Toshihiro Shimizu 890ddd
	int m_bitPerSample;   // numero di bit per campione
Toshihiro Shimizu 890ddd
	int m_channelCount;   // numero di canali
Toshihiro Shimizu 890ddd
	bool m_signedSample;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSoundTrackFormat(
Toshihiro Shimizu 890ddd
		TUINT32 sampleRate = 0,
Toshihiro Shimizu 890ddd
		int bitPerSample = 0,
Toshihiro Shimizu 890ddd
		int channelCount = 0,
Toshihiro Shimizu 890ddd
		bool signedSample = true)
Toshihiro Shimizu 890ddd
		: m_sampleRate(sampleRate), m_bitPerSample(bitPerSample), m_channelCount(channelCount), m_signedSample(signedSample) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~TSoundTrackFormat() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator==(const TSoundTrackFormat &rhs);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool operator!=(const TSoundTrackFormat &rhs);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
//! \include sound_ex.cpp
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The class TSoundTrack contains all features about a sound track
Toshihiro Shimizu 890ddd
  and gives all methods to access to these informations
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class DVAPI TSoundTrack : public TSmartObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	DECLARE_CLASS_CODE
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TUINT32 m_sampleRate; // frequenza di campionamento
Toshihiro Shimizu 890ddd
	int m_sampleSize;	 // numero di byte per campione
Toshihiro Shimizu 890ddd
	int m_bitPerSample;   // numero di bit per campione
Toshihiro Shimizu 890ddd
	TINT32 m_sampleCount; // numero di campioni
Toshihiro Shimizu 890ddd
	int m_channelCount;   // numero di canali
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSoundTrack *m_parent; // nel caso di sotto-traccie
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	UCHAR *m_buffer;
Toshihiro Shimizu 890ddd
	bool m_bufferOwner;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSoundTrack();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSoundTrack(
Toshihiro Shimizu 890ddd
		TUINT32 sampleRate, int bitPerSample,
Toshihiro Shimizu 890ddd
		int channelCount, int sampleSize, TINT32 sampleCount, bool isSampleSigned);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSoundTrack(
Toshihiro Shimizu 890ddd
		TUINT32 sampleRate, int bitPerSample,
Toshihiro Shimizu 890ddd
		int channelCount, int sampleSize, TINT32 sampleCount,
Toshihiro Shimizu 890ddd
		UCHAR *buffer, TSoundTrack *parent);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Create a new soundtrack according to the sample rate, bits per sample, number 
Toshihiro Shimizu 890ddd
  of channels and number of samples specified as inputs.
Toshihiro Shimizu 890ddd
  signedSample must be true for tracks whose samples are signed
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	static TSoundTrackP create(
Toshihiro Shimizu 890ddd
		TUINT32 sampleRate, int bitPerSample,
Toshihiro Shimizu 890ddd
		int channelCount, TINT32 sampleCount,
Toshihiro Shimizu 890ddd
		bool signedSample = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static TSoundTrackP create(
Toshihiro Shimizu 890ddd
		TUINT32 sampleRate, int bitPerSample,
Toshihiro Shimizu 890ddd
		int channelCount, TINT32 sampleCount, void *buffer,
Toshihiro Shimizu 890ddd
		bool signedSample = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Create a new soundtrack according to the format and number of samples 
Toshihiro Shimizu 890ddd
  specified as inputs
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	static TSoundTrackP create(const TSoundTrackFormat &format, TINT32 sampleCount);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static TSoundTrackP create(const TSoundTrackFormat &format, TINT32 sampleCount, void *buffer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~TSoundTrack();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Converts from seconds to samples according to the soundtrack sample rate
Toshihiro Shimizu 890ddd
	TINT32 secondsToSamples(double sec) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Converts from samples to seconds according to the soundtrack sample rate
Toshihiro Shimizu 890ddd
	double samplesToSeconds(TINT32 smp) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TUINT32 getSampleRate() const { return m_sampleRate; }
Toshihiro Shimizu 890ddd
	int getSampleSize() const { return m_sampleSize; }
Toshihiro Shimizu 890ddd
	int getChannelCount() const { return m_channelCount; }
Toshihiro Shimizu 890ddd
	int getBitPerSample() const { return m_bitPerSample; }
Toshihiro Shimizu 890ddd
	TINT32 getSampleCount() const { return m_sampleCount; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the duration of the soundtrack in seconds.
Toshihiro Shimizu 890ddd
	double getDuration() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns true if the samples of the soundtrack are signed, false otherwise
Toshihiro Shimizu 890ddd
	virtual bool isSampleSigned() const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack format
Toshihiro Shimizu 890ddd
	TSoundTrackFormat getFormat() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns a pointer to the samples buffer.
Toshihiro Shimizu 890ddd
	const UCHAR *getRawData() const { return m_buffer; };
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setSampleRate(TUINT32 sampleRate) { m_sampleRate = sampleRate; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Clones the soundtrack
Toshihiro Shimizu 890ddd
	virtual TSoundTrackP clone() const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns a soundtrack that contains just the cloned channel
Toshihiro Shimizu 890ddd
	virtual TSoundTrackP clone(TSound::Channel chan) const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns a subtrack for the range [s0, s1], s0 and s1 are samples
Toshihiro Shimizu 890ddd
	virtual TSoundTrackP extract(TINT32 s0, TINT32 s1) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns a subtrack for the range [t0, t1], t0 and t1 are seconds
Toshihiro Shimizu 890ddd
	TSoundTrackP extract(double t0, double t1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Copies the all samples of the source soundtrack 
Toshihiro Shimizu 890ddd
  to the object, starting from dst_s0.
Toshihiro Shimizu 890ddd
  dst_s0 is expressed in samples.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	virtual void copy(const TSoundTrackP &src, TINT32 dst_s0) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Copies the all samples of the source soundtrack 
Toshihiro Shimizu 890ddd
  to the object, starting from dst_t0.
Toshihiro Shimizu 890ddd
  dst_t0 is expressed in seconds.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void copy(const TSoundTrackP &src, double dst_t0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Blanks the soundtrack in the given range
Toshihiro Shimizu 890ddd
	virtual void blank(TINT32 s0, TINT32 s1) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! 
Toshihiro Shimizu 890ddd
  Blanks the soundtrack in the given range. Range is expressed in seconds.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void blank(double t0, double t1);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*! 
Toshihiro Shimizu 890ddd
  Returns a new soundtrack obtained applying the given sound tranform 
Toshihiro Shimizu 890ddd
  to the soundtrack
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	virtual TSoundTrackP apply(TSoundTransform *) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure value for the given sample and channel: range [-1,1]
Toshihiro Shimizu 890ddd
	virtual double getPressure(TINT32 sample, TSound::Channel chan) const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure value for the given time and channel
Toshihiro Shimizu 890ddd
	double getPressure(double second, TSound::Channel chan) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure max and min values in the given sample range and channel
Toshihiro Shimizu 890ddd
	virtual void getMinMaxPressure(
Toshihiro Shimizu 890ddd
		TINT32 s0, TINT32 s1, TSound::Channel chan,
Toshihiro Shimizu 890ddd
		double &min, double &max) const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Returns the soundtrack pressure min and max values in the given range and channel.
Toshihiro Shimizu 890ddd
  Range in seconds
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void getMinMaxPressure(
Toshihiro Shimizu 890ddd
		double t0, double t1, TSound::Channel chan,
Toshihiro Shimizu 890ddd
		double &min, double &max) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure min and max values for the given channel
Toshihiro Shimizu 890ddd
	void getMinMaxPressure(TSound::Channel chan, double &min, double &max) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure max value in the given sample range and channel
Toshihiro Shimizu 890ddd
	virtual double getMaxPressure(TINT32 s0, TINT32 s1, TSound::Channel chan) const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Returns the soundtrack pressure min value in the given range and channel.
Toshihiro Shimizu 890ddd
  Range in seconds
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	double getMaxPressure(double t0, double t1, TSound::Channel chan) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure max value for the given channel
Toshihiro Shimizu 890ddd
	double getMaxPressure(TSound::Channel chan) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure max value in the given sample range and channel
Toshihiro Shimizu 890ddd
	virtual double getMinPressure(TINT32 s0, TINT32 s1, TSound::Channel chan) const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Returns the soundtrack pressure mix value in the given sample range and channel
Toshihiro Shimizu 890ddd
  Range in seconds
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	double getMinPressure(double t0, double t1, TSound::Channel chan) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the soundtrack pressure min value for the given channel
Toshihiro Shimizu 890ddd
	double getMinPressure(TSound::Channel chan) const;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TSoundDeviceException : public TException
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum Type {
Toshihiro Shimizu 890ddd
		FailedInit, // fallimento del costruttore
Toshihiro Shimizu 890ddd
		UnableOpenDevice,
Toshihiro Shimizu 890ddd
		UnableCloseDevice,
Toshihiro Shimizu 890ddd
		UnablePrepare,	 // non puo' preparare i blocchi per play o rec
Toshihiro Shimizu 890ddd
		UnsupportedFormat, // formato non supportato
Toshihiro Shimizu 890ddd
		UnableSetDevice,   // non puo' impostare il device richiesto
Toshihiro Shimizu 890ddd
		UnableVolume,	  // non puo' leggere o scrivere il valore del volume
Toshihiro Shimizu 890ddd
		NoMixer,		   // assenza del dispositivo per regolare il volume
Toshihiro Shimizu 890ddd
		Busy			   // indica che il dispositivo gia' sta facendo
Toshihiro Shimizu 890ddd
						   // un play od una registrazione
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSoundDeviceException(Type type, const string &msg)
Toshihiro Shimizu 890ddd
		: TException(msg), m_type(type) {}
Toshihiro Shimizu 890ddd
	TSoundDeviceException(Type type, const wstring &msg)
Toshihiro Shimizu 890ddd
		: TException(msg), m_type(type) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Type getType()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_type;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	Type m_type;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// forward declaration
Toshihiro Shimizu 890ddd
class TSoundInputDeviceImp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! \include sndInDev_ex.cpp
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The class TSoundInputDevice permits the recording of a new sound track
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class DVAPI TSoundInputDevice
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSoundInputDeviceImp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum Source {
Toshihiro Shimizu 890ddd
		Mic = 0,
Toshihiro Shimizu 890ddd
		LineIn,
Toshihiro Shimizu 890ddd
		DigitalIn,
Toshihiro Shimizu 890ddd
		CdAudio
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TSoundInputDevice();
Toshihiro Shimizu 890ddd
	~TSoundInputDevice();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    Returns true if on the machine there is an audio card installed correctly
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	static bool installed();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Returns the best format supported near the given parameters
Toshihiro Shimizu 890ddd
	TSoundTrackFormat getPreferredFormat(TUINT32 sampleRate, int channelCount, int bitPerSample);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Returns the best format supported near the given format
Toshihiro Shimizu 890ddd
	TSoundTrackFormat getPreferredFormat(const TSoundTrackFormat &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Returns true if is possible to change volume setting on current input interface
Toshihiro Shimizu 890ddd
	bool supportsVolume();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Starts the recording of a soundtrack with the given format from the given source.
Toshihiro Shimizu 890ddd
	void record(const TSoundTrackFormat &format, Source devtype = Mic);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
  Starts the recording over the soundtrack st from the given source.
Toshihiro Shimizu 890ddd
  If not stopped before, recording ends when the whole soundtrack has been
Toshihiro Shimizu 890ddd
  overwritten.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void record(const TSoundTrackP &st, Source src = Mic);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Stops the recording and returns the result of recording.
Toshihiro Shimizu 890ddd
	TSoundTrackP stop();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Return the current value of the volume
Toshihiro Shimizu 890ddd
	double getVolume();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of the volume
Toshihiro Shimizu 890ddd
	bool setVolume(double value);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns true if and only if the device is recording
Toshihiro Shimizu 890ddd
	bool isRecording();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The class TSoundOutputDeviceListener permits to notify to other object
Toshihiro Shimizu 890ddd
  if a playback is completed. Use it as base class that needs to know if
Toshihiro Shimizu 890ddd
  a playback is ended
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TSoundOutputDeviceListener
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual ~TSoundOutputDeviceListener(){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void onPlayCompleted() = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TSoundOutputDeviceImp;
Toshihiro Shimizu 890ddd
//! \include sndOutDev_ex.cpp
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The class TSoundOutputDevice permits the playback of a sound track
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
class DVAPI TSoundOutputDevice
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TSoundOutputDeviceImp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TSoundOutputDevice();
Toshihiro Shimizu 890ddd
	~TSoundOutputDevice();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!
Toshihiro Shimizu 890ddd
    Returns true if on the machine there is an audio card installed correctly
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	static bool installed();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Returns the best format supported near the given parameters
Toshihiro Shimizu 890ddd
	TSoundTrackFormat getPreferredFormat(TUINT32 sampleRate, int channelCount, int bitPerSample);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Returns the best format supported near the given format
Toshihiro Shimizu 890ddd
	TSoundTrackFormat getPreferredFormat(const TSoundTrackFormat &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isFormatSupported(const TSoundTrackFormat &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef MACOSX
Toshihiro Shimizu 890ddd
	//! Returns true if is possible to change volume setting on current input interface
Toshihiro Shimizu 890ddd
	bool supportsVolume();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns the current value of the volume [0,1]
Toshihiro Shimizu 890ddd
	double getVolume();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Set the value of volume , between [0,1]
Toshihiro Shimizu 890ddd
	bool setVolume(double value);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Open the device according to the features of soundtrack
Toshihiro Shimizu 890ddd
	bool open(const TSoundTrackP &st);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Playback of the sndtrack in the request sample range
Toshihiro Shimizu 890ddd
	void play(const TSoundTrackP &st, TINT32 s0, TINT32 s1, bool loop = false, bool scrubbing = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Close in the right mode the device
Toshihiro Shimizu 890ddd
	bool close();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!Playback of the sndtrack in the request time range.
Toshihiro Shimizu 890ddd
     The loop argument permits to set the looping status of player
Toshihiro Shimizu 890ddd
     The scrubbing permits to an application to set the mode for the 
Toshihiro Shimizu 890ddd
     interaction between sound and mouse
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	void play(const TSoundTrackP &st,
Toshihiro Shimizu 890ddd
			  double t0,
Toshihiro Shimizu 890ddd
			  double t1,
Toshihiro Shimizu 890ddd
			  bool loop = false,
Toshihiro Shimizu 890ddd
			  bool scrubbing = false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		play(st, st->secondsToSamples(t0), st->secondsToSamples(t1), loop, scrubbing);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Stop the playback of one or more soundtracks
Toshihiro Shimizu 890ddd
	void stop();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns if the device is busy with a playback
Toshihiro Shimizu 890ddd
	bool isPlaying() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef MACOSX
Toshihiro Shimizu 890ddd
	//!Return true if the playback of all soundtracks is ended.
Toshihiro Shimizu 890ddd
	bool isAllQueuedItemsPlayed();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Returns if the status of player is in looping
Toshihiro Shimizu 890ddd
	bool isLooping();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Permits to change the looping status of player
Toshihiro Shimizu 890ddd
	void setLooping(bool loop);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void attach(TSoundOutputDeviceListener *listener);
Toshihiro Shimizu 890ddd
	void detach(TSoundOutputDeviceListener *listener);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif