Guitarix
valve.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 file is part of the Guitarix Audio Engine
22  *
23  *
24  * --------------------------------------------------------------------------
25  */
26 
27 #pragma once
28 
29 #ifndef SRC_HEADERS_VALVE_H_
30 #define SRC_HEADERS_VALVE_H_
31 
32 /****************************************************************
33  * 1-dimensional function tables for linear interpolation
34  *
35  * table1d and table1d_imp<size> must only differ in the last
36  * element, so that the typecast for tubetab below will work.
37  * Can't use inheritance because then C initializers will not
38  * work and initialization will be more awkward or less efficient.
39  */
40 
41 struct table1d { // 1-dimensional function table
42  float low;
43  float high;
44  float istep;
45  int size;
46  float data[];
47 };
48 
49 template <int tab_size>
50 struct table1d_imp {
51  float low;
52  float high;
53  float istep;
54  int size;
55  float data[tab_size];
56  operator table1d&() const { return *(table1d*)this; }
57 };
58 
59 /*
60  * data tables generated by tools/tube_transfer.py
61  */
62 #include "12ax7.cc"
63 #include "12AU7.cc"
64 #include "12AT7.cc"
65 #include "6V6.cc"
66 #include "6DJ8.cc"
67 #include "6C16.cc"
68 
69 enum {
83 };
84 
86  &static_cast<table1d&>(tubetable_12AX7[0]),
87  &static_cast<table1d&>(tubetable_12AX7[1]),
88  &static_cast<table1d&>(tubetable_6V6[0]),
89  &static_cast<table1d&>(tubetable_6V6[1]),
90  &static_cast<table1d&>(tubetable_12AU7[0]),
91  &static_cast<table1d&>(tubetable_12AU7[1]),
92  &static_cast<table1d&>(tubetable_6DJ8[0]),
93  &static_cast<table1d&>(tubetable_6DJ8[1]),
94  &static_cast<table1d&>(tubetable_12AT7[0]),
95  &static_cast<table1d&>(tubetable_12AT7[1]),
96  &static_cast<table1d&>(tubetable_6C16[0]),
97  &static_cast<table1d&>(tubetable_6C16[1]),
98 };
99 
100 /*
101  * definitions for ffunction(float Ftube(int,float), "valve.h", "");
102  * in gx_amp.dsp - gx_ampmodul.dsp
103  */
104 
105 static inline double Ftube(int table, double Vgk) {
106  const table1d& tab = *tubetab[table];
107  double f = (Vgk - tab.low) * tab.istep;
108  int i = static_cast<int>(f);
109  if (i < 0)
110  return tab.data[0];
111  if (i >= tab.size-1)
112  return tab.data[tab.size-1];
113  f -= i;
114  return tab.data[i]*(1-f) + tab.data[i+1]*f;
115 }
116 
117 #endif // SRC_HEADERS_VALVE_H_
table1d * tubetab[TUBE_TABLE_SIZE]
Definition: valve.h:85
float low
Definition: valve.h:51
float low
Definition: valve.h:42
Definition: valve.h:41
float high
Definition: valve.h:52
float high
Definition: valve.h:43
float istep
Definition: valve.h:53
float istep
Definition: valve.h:44
float data[]
Definition: valve.h:46
int size
Definition: valve.h:54
int size
Definition: valve.h:45