Guitarix
gx_convolver.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3 * Copyright (C) 2011 Pete Shorthose
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * --------------------------------------------------------------------------
19 */
20
21/* ------- This is the guitarix convolution Engine ------- */
22
23#pragma once
24
25#ifndef SRC_HEADERS_GX_CONVOLVER_H_
26#define SRC_HEADERS_GX_CONVOLVER_H_
27
28#include <zita-convolver.h>
29#include <gxwmm/gainline.h>
30
31#include <sndfile.hh>
32
33namespace gx_engine {
34
35/* GxConvolver */
36
37class Audiofile {
38public:
39
40 enum {
46 };
47
48 enum {
54 };
55
56 enum {
65 ERR_WRITE = -8
66 };
67
68 Audiofile(void);
70
71 int type(void) const { return _type; }
72 int form(void) const { return _form; }
73 int rate(void) const { return _rate; }
74 int chan(void) const { return _chan; }
75 unsigned int size(void) const { return _size; }
76
77 int open_read(string name);
78 int close(void);
79
80 int seek(unsigned int posit);
81 int read(float *data, unsigned int frames);
82
83private:
84
85 void reset(void);
86
87 SNDFILE *_sndfile;
88 int _type;
89 int _form;
90 int _rate;
91 int _chan;
92 unsigned int _size;
93};
94
95bool read_audio(const std::string& filename, unsigned int *audio_size, int *audio_chan,
96 int *audio_type, int *audio_form, int *audio_rate, float **buffer);
97
98class GxConvolverBase: protected Convproc {
99protected:
100 volatile bool ready;
101 bool sync;
102 void adjust_values(unsigned int audio_size, unsigned int& count, unsigned int& offset,
103 unsigned int& delay, unsigned int& ldelay, unsigned int& length,
104 unsigned int& size, unsigned int& bufsize);
105 unsigned int buffersize;
106 unsigned int samplerate;
107 GxConvolverBase(): ready(false), sync(false), buffersize(), samplerate() {}
109public:
110 inline void set_buffersize(unsigned int sz) { buffersize = sz; }
111 inline unsigned int get_buffersize() { return buffersize; }
112 inline void set_samplerate(unsigned int sr) { samplerate = sr; }
113 inline unsigned int get_samplerate() { return samplerate; }
115 using Convproc::state;
116 inline void set_not_runnable() { ready = false; }
117 inline bool is_runnable() { return ready; }
118 bool start(int policy, int priority);
119 using Convproc::stop_process;
120 inline void set_sync(bool val) { sync = val; }
121};
122
124private:
126 bool read_sndfile(Audiofile& audio, int nchan, int samplerate, const float *gain,
127 unsigned int *delay, unsigned int offset, unsigned int length,
128 const Gainline& points);
129public:
132 string fname, float gain, float lgain,
133 unsigned int delay, unsigned int ldelay, unsigned int offset,
134 unsigned int length, unsigned int size, unsigned int bufsize,
135 const Gainline& gainline);
136 bool compute(int count, float* input1, float *input2, float *output1, float *output2);
137 bool configure(string fname, float gain, unsigned int delay, unsigned int offset,
138 unsigned int length, unsigned int size, unsigned int bufsize,
139 const Gainline& gainline);
140 bool compute(int count, float* input, float *output);
141 static void compute_interpolation(double& fct, double& gp, unsigned int& idx,
142 const Gainline& points, int offset);
143};
144
146 double& fct, double& gp, unsigned int& idx, const Gainline& points, int offset) {
147 fct = (points[idx+1].g-points[idx].g)/(20*(points[idx+1].i-points[idx].i));
148 gp = points[idx].g/20 + fct * (offset-points[idx].i);
149 idx++;
150}
151
152
154private:
156public:
158 : GxConvolverBase(), resamp(resamp_) {}
159 bool configure(int count, float *impresp, unsigned int imprate);
160 bool update(int count, float *impresp, unsigned int imprate);
161 bool compute(int count, float* input, float *output);
162 bool compute(int count, float* buffer) {
163 return is_runnable() ? compute(count, buffer, buffer) : true;
164 }
165
166 bool configure_stereo(int count, float *impresp, unsigned int imprate);
167 bool update_stereo(int count, float *impresp, unsigned int imprate);
168 bool compute_stereo(int count, float* input, float* input1, float *output, float *output1);
169 bool compute_stereo(int count, float* buffer, float* buffer1)
170 {
171 return is_runnable() ? compute_stereo(count, buffer, buffer1, buffer, buffer1) : true;
172 }
173};
174
175} /* end of gx_engine namespace */
176#endif // SRC_HEADERS_GX_CONVOLVER_H_
int open_read(string name)
int chan(void) const
Definition: gx_convolver.h:74
int seek(unsigned int posit)
int form(void) const
Definition: gx_convolver.h:72
unsigned int size(void) const
Definition: gx_convolver.h:75
int rate(void) const
Definition: gx_convolver.h:73
unsigned int _size
Definition: gx_convolver.h:92
int type(void) const
Definition: gx_convolver.h:71
int read(float *data, unsigned int frames)
unsigned int get_samplerate()
Definition: gx_convolver.h:113
void set_samplerate(unsigned int sr)
Definition: gx_convolver.h:112
unsigned int get_buffersize()
Definition: gx_convolver.h:111
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)
bool start(int policy, int priority)
void set_buffersize(unsigned int sz)
Definition: gx_convolver.h:110
gx_resample::StreamingResampler resamp
Definition: gx_convolver.h:125
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 *input, float *output)
bool read_sndfile(Audiofile &audio, int nchan, int samplerate, const float *gain, unsigned int *delay, unsigned int offset, unsigned int length, const Gainline &points)
static void compute_interpolation(double &fct, double &gp, unsigned int &idx, const Gainline &points, int offset)
Definition: gx_convolver.h:145
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 update_stereo(int count, float *impresp, unsigned int imprate)
bool compute_stereo(int count, float *input, float *input1, float *output, float *output1)
bool configure_stereo(int count, float *impresp, unsigned int imprate)
bool compute(int count, float *input, float *output)
GxSimpleConvolver(gx_resample::BufferResampler &resamp_)
Definition: gx_convolver.h:157
gx_resample::BufferResampler & resamp
Definition: gx_convolver.h:155
bool compute_stereo(int count, float *buffer, float *buffer1)
Definition: gx_convolver.h:169
bool configure(int count, float *impresp, unsigned int imprate)
bool update(int count, float *impresp, unsigned int imprate)
bool compute(int count, float *buffer)
Definition: gx_convolver.h:162
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)