Loading...
Searching...
No Matches
gx_convolver.h
Go to the documentation of this file.
/*
* Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
* Copyright (C) 2011 Pete Shorthose
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* --------------------------------------------------------------------------
*/
/* ------- This is the guitarix convolution Engine ------- */
#pragma once
#ifndef SRC_HEADERS_GX_CONVOLVER_H_
#define SRC_HEADERS_GX_CONVOLVER_H_
#ifndef GUITARIX_AS_PLUGIN
#include <zita-convolver.h>
#else
#include "zita-convolver.h"
#endif
#include <gxwmm/gainline.h>
#include <sndfile.hh>
namespace gx_engine {
/* GxConvolver */
class Audiofile {
public:
enum {
TYPE_OTHER,
TYPE_CAF,
TYPE_WAV,
TYPE_AIFF,
TYPE_AMB
};
enum {
FORM_OTHER,
FORM_16BIT,
FORM_24BIT,
FORM_32BIT,
FORM_FLOAT
};
enum {
ERR_NONE = 0,
ERR_MODE = -1,
ERR_TYPE = -2,
ERR_FORM = -3,
ERR_OPEN = -4,
ERR_SEEK = -5,
ERR_DATA = -6,
ERR_READ = -7,
ERR_WRITE = -8
};
Audiofile(void);
~Audiofile(void);
int type(void) const { return _type; }
int form(void) const { return _form; }
int rate(void) const { return _rate; }
int chan(void) const { return _chan; }
unsigned int size(void) const { return _size; }
int open_read(string name);
int close(void);
int seek(unsigned int posit);
int read(float *data, unsigned int frames);
private:
void reset(void);
SNDFILE *_sndfile;
int _type;
int _form;
int _rate;
int _chan;
unsigned int _size;
};
bool read_audio(const std::string& filename, unsigned int *audio_size, int *audio_chan,
int *audio_type, int *audio_form, int *audio_rate, float **buffer);
class GxConvolverBase: protected Convproc {
protected:
volatile bool ready;
bool sync;
void adjust_values(unsigned int audio_size, unsigned int& count, unsigned int& offset,
unsigned int& delay, unsigned int& ldelay, unsigned int& length,
unsigned int& size, unsigned int& bufsize);
unsigned int buffersize;
unsigned int samplerate;
GxConvolverBase(): ready(false), sync(false), buffersize(), samplerate() {}
~GxConvolverBase();
public:
inline void set_buffersize(unsigned int sz) { buffersize = sz; }
inline unsigned int get_buffersize() { return buffersize; }
inline void set_samplerate(unsigned int sr) { samplerate = sr; }
inline unsigned int get_samplerate() { return samplerate; }
bool checkstate();
using Convproc::state;
inline void set_not_runnable() { ready = false; }
inline bool is_runnable() { return ready; }
bool start(int policy, int priority);
using Convproc::stop_process;
inline void set_sync(bool val) { sync = val; }
};
class GxConvolver: public GxConvolverBase {
private:
gx_resample::StreamingResampler resamp;
bool read_sndfile(Audiofile& audio, int nchan, int samplerate, const float *gain,
unsigned int *delay, unsigned int offset, unsigned int length,
const Gainline& points);
public:
GxConvolver(): GxConvolverBase(), resamp() {}
bool configure(
string fname, float gain, float lgain,
unsigned int delay, unsigned int ldelay, unsigned int offset,
unsigned int length, unsigned int size, unsigned int bufsize,
const Gainline& gainline);
bool compute(int count, float* input1, float *input2, float *output1, float *output2);
bool configure(string fname, float gain, unsigned int delay, unsigned int offset,
unsigned int length, unsigned int size, unsigned int bufsize,
const Gainline& gainline);
bool compute(int count, float* input, float *output);
static void compute_interpolation(double& fct, double& gp, unsigned int& idx,
const Gainline& points, int offset);
};
inline void GxConvolver::compute_interpolation(
double& fct, double& gp, unsigned int& idx, const Gainline& points, int offset) {
fct = (points[idx+1].g-points[idx].g)/(20*(points[idx+1].i-points[idx].i));
gp = points[idx].g/20 + fct * (offset-points[idx].i);
idx++;
}
class GxSimpleConvolver: public GxConvolverBase {
private:
gx_resample::BufferResampler& resamp;
public:
GxSimpleConvolver(gx_resample::BufferResampler& resamp_)
: GxConvolverBase(), resamp(resamp_) {}
bool configure(int count, float *impresp, unsigned int imprate);
bool update(int count, float *impresp, unsigned int imprate);
bool compute(int count, float* input, float *output);
bool compute(int count, float* buffer) {
return is_runnable() ? compute(count, buffer, buffer) : true;
}
bool configure_stereo(int count, float *impresp, unsigned int imprate);
bool update_stereo(int count, float *impresp, unsigned int imprate);
bool compute_stereo(int count, float* input, float* input1, float *output, float *output1);
bool compute_stereo(int count, float* buffer, float* buffer1)
{
return is_runnable() ? compute_stereo(count, buffer, buffer1, buffer, buffer1) : true;
}
};
} /* end of gx_engine namespace */
#endif // SRC_HEADERS_GX_CONVOLVER_H_
gx_engine::Audiofile
Definition gx_convolver.h:41
gx_engine::Audiofile::open_read
int open_read(string name)
gx_engine::Audiofile::chan
int chan(void) const
Definition gx_convolver.h:78
gx_engine::Audiofile::_rate
int _rate
Definition gx_convolver.h:94
gx_engine::Audiofile::seek
int seek(unsigned int posit)
gx_engine::Audiofile::TYPE_AMB
@ TYPE_AMB
Definition gx_convolver.h:49
gx_engine::Audiofile::TYPE_AIFF
@ TYPE_AIFF
Definition gx_convolver.h:48
gx_engine::Audiofile::TYPE_OTHER
@ TYPE_OTHER
Definition gx_convolver.h:45
gx_engine::Audiofile::TYPE_WAV
@ TYPE_WAV
Definition gx_convolver.h:47
gx_engine::Audiofile::TYPE_CAF
@ TYPE_CAF
Definition gx_convolver.h:46
gx_engine::Audiofile::form
int form(void) const
Definition gx_convolver.h:76
gx_engine::Audiofile::size
unsigned int size(void) const
Definition gx_convolver.h:79
gx_engine::Audiofile::rate
int rate(void) const
Definition gx_convolver.h:77
gx_engine::Audiofile::reset
void reset(void)
gx_engine::Audiofile::Audiofile
Audiofile(void)
gx_engine::Audiofile::_form
int _form
Definition gx_convolver.h:93
gx_engine::Audiofile::~Audiofile
~Audiofile(void)
gx_engine::Audiofile::FORM_16BIT
@ FORM_16BIT
Definition gx_convolver.h:54
gx_engine::Audiofile::FORM_OTHER
@ FORM_OTHER
Definition gx_convolver.h:53
gx_engine::Audiofile::FORM_32BIT
@ FORM_32BIT
Definition gx_convolver.h:56
gx_engine::Audiofile::FORM_24BIT
@ FORM_24BIT
Definition gx_convolver.h:55
gx_engine::Audiofile::FORM_FLOAT
@ FORM_FLOAT
Definition gx_convolver.h:57
gx_engine::Audiofile::_sndfile
SNDFILE * _sndfile
Definition gx_convolver.h:91
gx_engine::Audiofile::_size
unsigned int _size
Definition gx_convolver.h:96
gx_engine::Audiofile::_chan
int _chan
Definition gx_convolver.h:95
gx_engine::Audiofile::ERR_TYPE
@ ERR_TYPE
Definition gx_convolver.h:63
gx_engine::Audiofile::ERR_FORM
@ ERR_FORM
Definition gx_convolver.h:64
gx_engine::Audiofile::ERR_DATA
@ ERR_DATA
Definition gx_convolver.h:67
gx_engine::Audiofile::ERR_SEEK
@ ERR_SEEK
Definition gx_convolver.h:66
gx_engine::Audiofile::ERR_READ
@ ERR_READ
Definition gx_convolver.h:68
gx_engine::Audiofile::ERR_OPEN
@ ERR_OPEN
Definition gx_convolver.h:65
gx_engine::Audiofile::ERR_MODE
@ ERR_MODE
Definition gx_convolver.h:62
gx_engine::Audiofile::ERR_NONE
@ ERR_NONE
Definition gx_convolver.h:61
gx_engine::Audiofile::ERR_WRITE
@ ERR_WRITE
Definition gx_convolver.h:69
gx_engine::Audiofile::type
int type(void) const
Definition gx_convolver.h:75
gx_engine::Audiofile::close
int close(void)
gx_engine::Audiofile::_type
int _type
Definition gx_convolver.h:92
gx_engine::Audiofile::read
int read(float *data, unsigned int frames)
gx_engine::GxConvolverBase::is_runnable
bool is_runnable()
Definition gx_convolver.h:121
gx_engine::GxConvolverBase::ready
volatile bool ready
Definition gx_convolver.h:104
gx_engine::GxConvolverBase::get_samplerate
unsigned int get_samplerate()
Definition gx_convolver.h:117
gx_engine::GxConvolverBase::GxConvolverBase
GxConvolverBase()
Definition gx_convolver.h:111
gx_engine::GxConvolverBase::set_not_runnable
void set_not_runnable()
Definition gx_convolver.h:120
gx_engine::GxConvolverBase::set_samplerate
void set_samplerate(unsigned int sr)
Definition gx_convolver.h:116
gx_engine::GxConvolverBase::get_buffersize
unsigned int get_buffersize()
Definition gx_convolver.h:115
gx_engine::GxConvolverBase::buffersize
unsigned int buffersize
Definition gx_convolver.h:109
gx_engine::GxConvolverBase::sync
bool sync
Definition gx_convolver.h:105
gx_engine::GxConvolverBase::~GxConvolverBase
~GxConvolverBase()
gx_engine::GxConvolverBase::adjust_values
void adjust_values(unsigned int audio_size, unsigned int &count, unsigned int &offset, unsigned int &delay, unsigned int &ldelay, unsigned int &length, unsigned int &size, unsigned int &bufsize)
gx_engine::GxConvolverBase::samplerate
unsigned int samplerate
Definition gx_convolver.h:110
gx_engine::GxConvolverBase::set_sync
void set_sync(bool val)
Definition gx_convolver.h:124
gx_engine::GxConvolverBase::checkstate
bool checkstate()
gx_engine::GxConvolverBase::start
bool start(int policy, int priority)
gx_engine::GxConvolverBase::set_buffersize
void set_buffersize(unsigned int sz)
Definition gx_convolver.h:114
gx_engine::GxConvolver::resamp
gx_resample::StreamingResampler resamp
Definition gx_convolver.h:129
gx_engine::GxConvolver::configure
bool configure(string fname, float gain, float lgain, unsigned int delay, unsigned int ldelay, unsigned int offset, unsigned int length, unsigned int size, unsigned int bufsize, const Gainline &gainline)
gx_engine::GxConvolver::compute
bool compute(int count, float *input, float *output)
gx_engine::GxConvolver::read_sndfile
bool read_sndfile(Audiofile &audio, int nchan, int samplerate, const float *gain, unsigned int *delay, unsigned int offset, unsigned int length, const Gainline &points)
gx_engine::GxConvolver::compute_interpolation
static void compute_interpolation(double &fct, double &gp, unsigned int &idx, const Gainline &points, int offset)
Definition gx_convolver.h:149
gx_engine::GxConvolver::compute
bool compute(int count, float *input1, float *input2, float *output1, float *output2)
gx_engine::GxConvolver::GxConvolver
GxConvolver()
Definition gx_convolver.h:134
gx_engine::GxConvolver::configure
bool configure(string fname, float gain, unsigned int delay, unsigned int offset, unsigned int length, unsigned int size, unsigned int bufsize, const Gainline &gainline)
gx_engine::GxSimpleConvolver::update_stereo
bool update_stereo(int count, float *impresp, unsigned int imprate)
gx_engine::GxSimpleConvolver::compute_stereo
bool compute_stereo(int count, float *input, float *input1, float *output, float *output1)
gx_engine::GxSimpleConvolver::configure_stereo
bool configure_stereo(int count, float *impresp, unsigned int imprate)
gx_engine::GxSimpleConvolver::compute
bool compute(int count, float *input, float *output)
gx_engine::GxSimpleConvolver::GxSimpleConvolver
GxSimpleConvolver(gx_resample::BufferResampler &resamp_)
Definition gx_convolver.h:161
gx_engine::GxSimpleConvolver::resamp
gx_resample::BufferResampler & resamp
Definition gx_convolver.h:159
gx_engine::GxSimpleConvolver::compute_stereo
bool compute_stereo(int count, float *buffer, float *buffer1)
Definition gx_convolver.h:173
gx_engine::GxSimpleConvolver::configure
bool configure(int count, float *impresp, unsigned int imprate)
gx_engine::GxSimpleConvolver::update
bool update(int count, float *impresp, unsigned int imprate)
gx_engine::GxSimpleConvolver::compute
bool compute(int count, float *buffer)
Definition gx_convolver.h:166
gx_resample::BufferResampler
Definition gx_resampler.h:49
gx_resample::StreamingResampler
Definition gx_resampler.h:54
gx_engine
Definition gx_convolver.h:37
gx_engine::read_audio
bool read_audio(const std::string &filename, unsigned int *audio_size, int *audio_chan, int *audio_type, int *audio_form, int *audio_rate, float **buffer)