ITAAudioSample.h 4.44 KB
Newer Older
1 2 3 4 5
/*
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
6
 *		RWTH Aachen University, Germany, 2015-2018
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */

#ifndef INCLUDE_WATCHER_ITA_AUDIO_SAMPLE
#define INCLUDE_WATCHER_ITA_AUDIO_SAMPLE

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

#include <string>

28
//! Multi-channel audio sample with single precision floating point quantization
29
/**
30
  * An audio sample is basically an ITASampleFrame with a given sampling rate.
31 32 33 34 35 36
  */
class ITA_BASE_API CITAAudioSample : public ITASampleFrame
{
public:
	//! Create empty audio sample
	/**
37 38 39
	  * Creates an uninitialized audio sample with given a sampling rate, only.
	  *
	  * @note Requires initialization or load to be used, otherwise methods will throw ITAException.
40 41
	  */
	CITAAudioSample( const float fSampleRate = 44100.0f );
42 43 44
	
	//! Create audio sample from file
	/**
45 46 47 48 49
	  * Will load audio sample from file and adopts number of channels and sample rate.
	  *
	  * @param[in] sFilePath Path to audio file
	  *
	  * @note Will raise ITAException on error.
50 51
	  */
	CITAAudioSample( const std::string& sFilePath );
52 53 54 55 56 57 58 59

	//! 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
	  */
60
	explicit CITAAudioSample( const int iNumChannels, const int iLengthSamples, const float fSampleRate, const bool bZeroInit = true );
61 62 63

	//! Copy constructor as pointer
	/**
64
	 * @param[in] pSource Pointer to source audio sample
65 66 67 68 69
	 */
	CITAAudioSample( const CITAAudioSample* pSource );

	//! Copy constructor as reference
	/**
70
	  * @param[in] pbSource Reference to source audio sample
71 72 73 74 75 76
	  */
	CITAAudioSample( const CITAAudioSample& sbSource );

	virtual inline ~CITAAudioSample() {};

	//! Sampling frequency of audio sample
77 78 79 80
	/**
	  * @return Sampling rate of audio sample
	  *
	  */
81 82 83 84 85 86 87 88 89 90 91 92 93
	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 );

94 95 96 97 98 99 100 101
	//! Read from sample buffer with sample rate conversion, if necessary
	/**
	  * Reads audio samples from sample frame and converts to internal sample rate, if given source sample rate is mismatching.
	  *
	  * @param[in] sfSource Source sample frame
	  * @param[in] fSourceSampleRate Sample rate of source sample frame
	  *
	  */
102 103
	void Load( const ITASampleFrame& sfSource, const float fSourceSampleRate );

104 105 106 107 108 109
	//! Read from other audio sample with sample rate conversion, if necessary
	/**
	  * Reads audio samples from sample frame and converts to internal sample rate, if given source sample rate is mismatching.
	  *
	  * @param[in] oSource Source audio sample
	  */
110 111
	void Load( const CITAAudioSample& oSource );

112 113 114 115 116 117 118 119 120
	//! Load audio sample from file and adopt it's sample rate
	/**
	  * Will load audio sample from file and adopts number of channels and sample rate.
	  *
	  * @param[in] sFilePath Path to audio file
	  *
	  * @note Will raise ITAException on error.
	  * @sa LoadWithSampleRateConversion()
	  */
121 122
	void Load( const std::string& sFilePath );

123 124 125 126 127 128 129 130
	//! Load audio sample from file and convert sample rate to internal sample rate, if necessary
	/**
	  * Will load audio sample from file and adopts number of channels but not sample rate. Converts audio samples into internal sampling rate if mismatched.
	  *
	  * @param[in] sFilePath Path to audio file
	  *
	  * @note Will raise ITAException on error.
	  */
131
	void LoadWithSampleRateConversion( const std::string& sFilePath );
132 133 134 135 136 137 138 139 140 141 142 143 144

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