Jack2 1.9.7

JackResampler.h

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 "types.h"
00025 #include "JackError.h"
00026 
00027 namespace Jack
00028 {
00029 
00030 #define DEFAULT_RB_SIZE 32768
00031 #define DEFAULT_ADAPTATIVE_SIZE 2048
00032 
00033 inline float Range(float min, float max, float val)
00034 {
00035     return (val < min) ? min : ((val > max) ? max : val);
00036 }
00037 
00042 class JackResampler
00043 {
00044 
00045     protected:
00046 
00047         jack_ringbuffer_t* fRingBuffer;
00048         double fRatio;
00049         unsigned int fRingBufferSize;
00050 
00051     public:
00052 
00053         JackResampler();
00054         virtual ~JackResampler();
00055 
00056         virtual void Reset(unsigned int new_size);
00057 
00058         virtual unsigned int ReadResample(jack_default_audio_sample_t* buffer, unsigned int frames);
00059         virtual unsigned int WriteResample(jack_default_audio_sample_t* buffer, unsigned int frames);
00060 
00061         virtual unsigned int Read(jack_default_audio_sample_t* buffer, unsigned int frames);
00062         virtual unsigned int Write(jack_default_audio_sample_t* buffer, unsigned int frames);
00063 
00064         virtual unsigned int ReadSpace();
00065         virtual unsigned int WriteSpace();
00066 
00067         unsigned int GetError()
00068         {
00069             return (jack_ringbuffer_read_space(fRingBuffer) / sizeof(float)) - (fRingBufferSize / 2);
00070         }
00071 
00072         void SetRatio(double ratio)
00073         {
00074             fRatio = Range(0.25, 4.0, ratio);
00075         }
00076 
00077         double GetRatio()
00078         {
00079             return fRatio;
00080         }
00081 
00082     };
00083 }
00084 
00085 #endif