1 /* 2 * Copyright 2000-2006 Ingo Weinhold <ingo_weinhold@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT licensce. 4 */ 5 #ifndef AUDIO_RESAMPLER_H 6 #define AUDIO_RESAMPLER_H 7 8 9 /*! This AudioReader does both resampling an audio source to a different 10 sample rate and rescaling the time, e.g. it is possible to convert the 11 source data from 41.1 KHz to 96 KHz played backward twice as fast 12 (time scale = -2). 13 */ 14 15 16 #include "AudioReader.h" 17 18 19 class AudioResampler : public AudioReader { 20 public: 21 AudioResampler(); 22 AudioResampler(AudioReader* source, 23 float frameRate, float timeScale = 1.0); 24 virtual ~AudioResampler(); 25 26 virtual bigtime_t InitialLatency() const; 27 virtual status_t Read(void* buffer, int64 pos, int64 frames); 28 29 virtual status_t InitCheck() const; 30 31 void SetSource(AudioReader* source); 32 void SetFrameRate(float frameRate); 33 void SetTimeScale(float timeScale); 34 35 AudioReader* Source() const; 36 float FrameRate() const; 37 float TimeScale() const; 38 39 void SetInOffset(int64 offset); 40 int64 InOffset() const; 41 42 int64 ConvertFromSource(int64 pos) const; 43 int64 ConvertToSource(int64 pos) const; 44 45 private: 46 status_t _ReadLinear(void* buffer, int64 pos, 47 int64 frames); 48 49 private: 50 AudioReader* fSource; 51 float fTimeScale; // speed 52 int64 fInOffset; 53 }; 54 55 #endif // AUDIO_RESAMPLER_H 56