Guitarix
Loading...
Searching...
No Matches
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#ifndef GUITARIX_AS_PLUGIN
29#include <zita-convolver.h>
30#else
31#include "zita-convolver.h"
32#endif
33#include <gxwmm/gainline.h>
34
35#include <sndfile.hh>
36
37namespace gx_engine {
38
39/* GxConvolver */
40
41class Audiofile {
42public:
43
44 enum {
50 };
51
52 enum {
58 };
59
60 enum {
69 ERR_WRITE = -8
70 };
71
72 Audiofile(void);
74
75 int type(void) const { return _type; }
76 int form(void) const { return _form; }
77 int rate(void) const { return _rate; }
78 int chan(void) const { return _chan; }
79 unsigned int size(void) const { return _size; }
80
81 int open_read(string name);
82 int close(void);
83
84 int seek(unsigned int posit);
85 int read(float *data, unsigned int frames);
86
87private:
88
89 void reset(void);
90
91 SNDFILE *_sndfile;
92 int _type;
93 int _form;
94 int _rate;
95 int _chan;
96 unsigned int _size;
97};
98
99bool read_audio(const std::string& filename, unsigned int *audio_size, int *audio_chan,
100 int *audio_type, int *audio_form, int *audio_rate, float **buffer);
101
102class GxConvolverBase: protected Convproc {
103protected:
104 volatile bool ready;
105 bool sync;
106 void adjust_values(unsigned int audio_size, unsigned int& count, unsigned int& offset,
107 unsigned int& delay, unsigned int& ldelay, unsigned int& length,
108 unsigned int& size, unsigned int& bufsize);
109 unsigned int buffersize;
110 unsigned int samplerate;
111 GxConvolverBase(): ready(false), sync(false), buffersize(), samplerate() {}
113public:
114 inline void set_buffersize(unsigned int sz) { buffersize = sz; }
115 inline unsigned int get_buffersize() { return buffersize; }
116 inline void set_samplerate(unsigned int sr) { samplerate = sr; }
117 inline unsigned int get_samplerate() { return samplerate; }
119 using Convproc::state;
120 inline void set_not_runnable() { ready = false; }
121 inline bool is_runnable() { return ready; }
122 bool start(int policy, int priority);
123 using Convproc::stop_process;
124 inline void set_sync(bool val) { sync = val; }
125};
126
128private:
130 bool read_sndfile(Audiofile& audio, int nchan, int samplerate, const float *gain,
131 unsigned int *delay, unsigned int offset, unsigned int length,
132 const Gainline& points);
133public:
136 string fname, float gain, float lgain,
137 unsigned int delay, unsigned int ldelay, unsigned int offset,
138 unsigned int length, unsigned int size, unsigned int bufsize,
139 const Gainline& gainline);
140 bool compute(int count, float* input1, float *input2, float *output1, float *output2);
141 bool configure(string fname, float gain, unsigned int delay, unsigned int offset,
142 unsigned int length, unsigned int size, unsigned int bufsize,
143 const Gainline& gainline);
144 bool compute(int count, float* input, float *output);
145 static void compute_interpolation(double& fct, double& gp, unsigned int& idx,
146 const Gainline& points, int offset);
147};
148
150 double& fct, double& gp, unsigned int& idx, const Gainline& points, int offset) {
151 fct = (points[idx+1].g-points[idx].g)/(20*(points[idx+1].i-points[idx].i));
152 gp = points[idx].g/20 + fct * (offset-points[idx].i);
153 idx++;
154}
155
156
158private:
160public:
163 bool configure(int count, float *impresp, unsigned int imprate);
164 bool update(int count, float *impresp, unsigned int imprate);
165 bool compute(int count, float* input, float *output);
166 bool compute(int count, float* buffer) {
167 return is_runnable() ? compute(count, buffer, buffer) : true;
168 }
169
170 bool configure_stereo(int count, float *impresp, unsigned int imprate);
171 bool update_stereo(int count, float *impresp, unsigned int imprate);
172 bool compute_stereo(int count, float* input, float* input1, float *output, float *output1);
173 bool compute_stereo(int count, float* buffer, float* buffer1)
174 {
175 return is_runnable() ? compute_stereo(count, buffer, buffer1, buffer, buffer1) : true;
176 }
177};
178
179} /* end of gx_engine namespace */
180#endif // SRC_HEADERS_GX_CONVOLVER_H_
int open_read(string name)
int chan(void) const
int seek(unsigned int posit)
int form(void) const
unsigned int size(void) const
int rate(void) const
int type(void) const
int read(float *data, unsigned int frames)
unsigned int get_samplerate()
void set_samplerate(unsigned int sr)
unsigned int get_buffersize()
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)
gx_resample::StreamingResampler 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 *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)
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_)
gx_resample::BufferResampler & resamp
bool compute_stereo(int count, float *buffer, float *buffer1)
bool configure(int count, float *impresp, unsigned int imprate)
bool update(int count, float *impresp, unsigned int imprate)
bool compute(int count, float *buffer)
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)