So, this seems to work. But, is it the right way to do it?
This is my header file, tables.h:
#ifndef CANTO_TABLES_H
#define CANTO_TABLES_H
// Sinewave table
extern const int8_t sinCalc[];
// Squarewave table
extern const int8_t sqrCalc[];
// Formant table
extern const int8_t formantTable[][7];
// Vowel indices
extern const int8_t vowels[];
// Sample-rate reduction divisor table
extern const int8_t srateTable[];
#include "tables.c"
#endif
and an excerpt from tables.c:
const int8_t sinCalc[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,2,2,3,3,4,5,6,7,8,10,12,14,17,20,24,
0,4,4,5,6,7,9,11,13,15,18,22,26,31,37,45,
0,5,6,7,8,10,12,14,17,20,24,28,34,41,49,58,
0,5,6,7,9,10,12,15,18,21,26,31,37,44,53,63,
0,5,6,7,8,10,12,14,17,20,24,28,34,41,49,58,
0,4,4,5,6,7,9,11,13,15,18,22,26,31,37,45,
0,2,2,3,3,4,5,6,7,8,10,12,14,17,20,24,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,-2,-2,-3,-3,-4,-5,-6,-7,-8,-10,-12,-14,-17,-20,-24,
0,-4,-4,-5,-6,-7,-9,-11,-13,-15,-18,-22,-26,-31,-37,-45,
0,-5,-6,-7,-8,-10,-12,-14,-17,-20,-24,-28,-34,-41,-49,-58,
0,-5,-6,-7,-9,-10,-12,-15,-18,-21,-26,-31,-37,-44,-53,-63,
0,-5,-6,-7,-8,-10,-12,-14,-17,-20,-24,-28,-34,-41,-49,-58,
0,-4,-4,-5,-6,-7,-9,-11,-13,-15,-18,-22,-26,-31,-37,-45,
0,-2,-2,-3,-3,-4,-5,-6,-7,-8,-10,-12,-14,-17,-20,-24
};
However, having read a little about the evils of global variables in the past (and I understand declaring a variable as 'extern' makes it global), I have a feeling this is the wrong way to do thing.
I have two goals in putting the the tables in an external file:
- So that I can use them in multiple objects
- So that if I do the above, the same variables will not be declared multiple times, if I use more than one instance of the objects that use the external file.
I don't know if this method fulfils either of these criteria.
Incidentally, if I can do the same thing with a single, rather than 2 files, that might be cool.
Any advice gratefully accepted.
a|x