ITASampleClock.h 2.2 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1 2 3 4 5
/*
* ----------------------------------------------------------------
*
*		ITA core libs
*		(c) Copyright Institute of Technical Acoustics (ITA)
6
*		RWTH Aachen University, Germany, 2015-2017
Jonas Stienen's avatar
Jonas Stienen committed
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 40 41 42 43 44 45 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
*
* ----------------------------------------------------------------
*				    ____  __________  _______
*				   //  / //__   ___/ //  _   |
*				  //  /    //  /    //  /_|  |
*				 //  /    //  /    //  ___   |
*				//__/    //__/    //__/   |__|
*
* ----------------------------------------------------------------
*
*/
// $Id: ITASampleClock.h 2900 2012-09-17 08:42:42Z fwefers $

#ifndef INCLUDE_WATCHER_ITA_SAMPLE_CLOCK
#define INCLUDE_WATCHER_ITA_SAMPLE_CLOCK

#include <ITAHPT.h>
#include <ITASamplerDefinition.h>


/**
 * Diese Klasse definiert eine Schnittstelle die es erlaubt
 * Zeitangaben eines ... in Sample-Indizes
 * eines Audio-Datenstroms umzurechnen und umgekehrt.
 */

class ITA_SAMPLER_API ITASampleClock
{
public:
	inline ITASampleClock( double dSamplerate, double dScale = 1.0 ) : m_dSamplerate( dSamplerate ), m_dScale( dScale ), m_ttRef( ITAHPT_now() ) {};
	inline virtual ~ITASampleClock() {};

	//! Skalierung [in Sekunden] zurckgeben
	inline double GetScale() { return m_dScale; };

	//! Zeitpunkt eines gewissen Samples setzen [Timerticks]
	inline void Adjust( int iSample, ITATimerTicks ttRef ) {
		// Timerticks bei Sample 0 berechnen
		m_ttRef = ttRef - toTimerTicks( (double) iSample / m_dSamplerate );
	};

	//! Sample-Index in Zeitmarke umrechnen
	inline double GetTimeForSample( int iSample ) {
		return (double) iSample / m_dSamplerate / m_dScale;
	};

	//! Zeitmarke in Sample-Index umrechnen
	inline int GetSampleForTime( double dTime ) {
		// Auf nchstgelegenen Wert runden
		return (int) ( dTime * m_dScale * m_dSamplerate );
	};

	//! Sample-Index in Timerticks umrechnen
	inline ITATimerTicks GetTicksForSample( int iSample ) {
		return m_ttRef + toTimerTicks( (double) iSample / m_dSamplerate );
	};

	//! Zeitmarke in Timerticks umrechnen
	inline ITATimerTicks GetTicksForTime( double dTime ) {
		return m_ttRef + toTimerTicks( dTime * m_dScale );
	};

protected:
	double m_dSamplerate;
	double m_dScale;
	ITATimerTicks m_ttRef;		// Reference: timer ticks at sample 0
};

#endif // INCLUDE_WATCHER_ITA_SAMPLE_CLOCK