ITAAudioSample.h 3.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
 *		RWTH Aachen University, Germany, 2015-2017
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef INCLUDE_WATCHER_ITA_AUDIO_SAMPLE
#define INCLUDE_WATCHER_ITA_AUDIO_SAMPLE

// ITABase
#include <ITABaseDefinitions.h>
#include <ITASampleFrame.h>

#include <string>

//! Multi-channel audio sample with floating point quantization
/**
  * ITASampleFrame with a sampling rate. Also converts from other sampling rates.
  */
class ITA_BASE_API CITAAudioSample : public ITASampleFrame
{
public:
	//! Create empty audio sample
	/**
	  * Requires initialization or load to be used, otherwise methods will throw ITAException.
	  */
	CITAAudioSample( const float fSampleRate = 44100.0f );
40 41 42 43 44 45
	
	//! Create audio sample from file
	/**
	  * Requires initialization or load to be used, otherwise methods will throw ITAException.
	  */
	CITAAudioSample( const std::string& sFilePath );
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

	//! Create (empty) audio sample with given parameters
	/**
	  * @param[in] iNumChannels	   Number of channels
	  * @param[in] iLengthSamples	   Number of new samples
	  * @param[in] fSampleRate Sampling rate of audio sample
	  * @param[in] bZeroInit	   Init with zeros
	  */
	explicit CITAAudioSample( const int iChannels, const int iLength, const float fSampleRate, const bool bZeroInit = true );

	//! Copy constructor as pointer
	/**
	 * \param pSource Pointer to source audio sample
	 */
	CITAAudioSample( const CITAAudioSample* pSource );

	//! Copy constructor as reference
	/**
	  * \param pbSource Reference to source audio sample
	  */
	CITAAudioSample( const CITAAudioSample& sbSource );

	virtual inline ~CITAAudioSample() {};

	//! Sampling frequency of audio sample
	float GetSampleRate() const;
	
	//! Initialize
	/**
	  * (Re-)Initialize an audio sample
	  *
	  * @param[in] iNumChannels	   Number of channels
	  * @param[in] iLengthSamples	   Number of new samples
	  * @param[in] fSampleRate Sampling rate of audio sample
	  * @param[in] bZeroInit	   Init with zeros
	  */
	void Init( const int iNumChannels, const int iLengthSamples, const float fSampleRate, const bool bZeroInit = true );

	//! Read from sample buffer with sample rate conversion
	void Load( const ITASampleFrame& sfSource, const float fSourceSampleRate );

	//! Read from other audio sample with sample rate conversion
	void Load( const CITAAudioSample& oSource );

	//! Load audio sample from file and inherit it's sample rate
	void Load( const std::string& sFilePath );

	//! Load audio sample from file and convert sample rate, if necessary
	void LoadWithSampleTypeConversion( const std::string& sFilePath );

96 97 98
	//! Load audio sample from file and convert sample rate, if necessary
	void LoadWithSampleTypeConversion( const CITAAudioSample& asSource );

99 100 101 102 103 104 105 106 107 108 109 110
private:

	//! Disable this Init method from sample buffer
	void Init( int, int, bool );

	//! Disable load without sample rate
	void Load( const std::string&, const double& );

	float m_fSampleRate; //!< Sampling rate
};

#endif // INCLUDE_WATCHER_ITA_AUDIO_SAMPLE