Jack2 1.9.6
|
00001 /* 00002 Copyright (C) 2008 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #ifndef __JackResampler__ 00021 #define __JackResampler__ 00022 00023 #include "ringbuffer.h" 00024 #include "JackError.h" 00025 00026 namespace Jack 00027 { 00028 00029 #define DEFAULT_RB_SIZE 32768 00030 #define DEFAULT_ADAPTATIVE_SIZE 2048 00031 00032 inline float Range(float min, float max, float val) 00033 { 00034 return (val < min) ? min : ((val > max) ? max : val); 00035 } 00036 00041 class JackResampler 00042 { 00043 00044 protected: 00045 00046 jack_ringbuffer_t* fRingBuffer; 00047 double fRatio; 00048 unsigned int fRingBufferSize; 00049 00050 public: 00051 00052 JackResampler(); 00053 virtual ~JackResampler(); 00054 00055 virtual void Reset(unsigned int new_size); 00056 00057 virtual unsigned int ReadResample(float* buffer, unsigned int frames); 00058 virtual unsigned int WriteResample(float* buffer, unsigned int frames); 00059 00060 virtual unsigned int Read(float* buffer, unsigned int frames); 00061 virtual unsigned int Write(float* buffer, unsigned int frames); 00062 00063 virtual unsigned int ReadSpace(); 00064 virtual unsigned int WriteSpace(); 00065 00066 unsigned int GetError() 00067 { 00068 return (jack_ringbuffer_read_space(fRingBuffer) / sizeof(float)) - (fRingBufferSize / 2); 00069 } 00070 00071 void SetRatio(double ratio) 00072 { 00073 fRatio = Range(0.25, 4.0, ratio); 00074 } 00075 00076 double GetRatio() 00077 { 00078 return fRatio; 00079 } 00080 00081 }; 00082 } 00083 00084 #endif