Skip to content
Snippets Groups Projects
Select Git revision
  • 95e87de7411476f5f9dbd90bcc7cdf029f58fc1c
  • master default protected
  • develop protected
  • ITASampler_v2024a
  • VA_v2023b
  • VA_v2023a
  • VA_v2022a
  • before_cmake_rework
  • v2021.a
  • v2020.a
  • v2019.a
  • v2018.b
  • v2018.a
  • v2017.d
  • v2017.c
  • v2017.b
  • v2017.a
  • v2016.a
18 results

ITASampleClock.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ITASampleClock.h 2.20 KiB
    /*
    * ----------------------------------------------------------------
    *
    *		ITA core libs
    *		(c) Copyright Institute of Technical Acoustics (ITA)
    *		RWTH Aachen University, Germany, 2015-2017
    *
    * ----------------------------------------------------------------
    *				    ____  __________  _______
    *				   //  / //__   ___/ //  _   |
    *				  //  /    //  /    //  /_|  |
    *				 //  /    //  /    //  ___   |
    *				//__/    //__/    //__/   |__|
    *
    * ----------------------------------------------------------------
    *
    */
    // $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