houtson
Well-known member
I'm using AudioEffectWaveshaper with Teensy3.6 and the Audio Board in an audio effect project. I'm running low on memory so want to move the waveshape arrays to flash rather than RAM.
To do this I'm using const float array []. While this seems to work the complier doesn't like it with 'warning: invalid conversion from 'const float*' to 'float*' [-fpermissive]'.
I use VSCode with PlatformIO, if I try to compile in Arduino then it fails completely (with similar error).
I've included a simple example below that cycles a sine wave through a couple of different waveshapers.
My question is : is there a better way to store wave shape arrays in flash that avoids the compiler warnings/errors? Cheers, Paul
To do this I'm using const float array []. While this seems to work the complier doesn't like it with 'warning: invalid conversion from 'const float*' to 'float*' [-fpermissive]'.
I use VSCode with PlatformIO, if I try to compile in Arduino then it fails completely (with similar error).
I've included a simple example below that cycles a sine wave through a couple of different waveshapers.
My question is : is there a better way to store wave shape arrays in flash that avoids the compiler warnings/errors? Cheers, Paul
Code:
#include <Audio.h>
AudioSynthWaveform waveform;
AudioEffectWaveshaper waveshape1;
AudioOutputI2S i2s2;
AudioConnection patchCord1(waveform, 0, waveshape1, 0);
AudioConnection patchCord2(waveshape1, 0, i2s2, 0);
AudioConnection patchCord3(waveshape1, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1;
const float wave_shape_flat[2] = {
-1.0,
1.0
};
const float wave_shape_chebyshev_3rd [257] =
{
-1.0,-0.9375,-0.8671875,-0.796875,-0.734375,-0.671875,-0.609375,-0.546875,-0.484375,-0.4296875,-0.375,-0.3203125,
-0.265625,-0.2109375,-0.15625,-0.109375,-0.0546875,-0.0078125,0.0390625,0.078125,0.125,0.1640625,0.2109375,0.25,
0.2890625,0.328125,0.359375,0.3984375,0.4296875,0.46875,0.5,0.53125,0.5546875,0.5859375,0.6171875,0.640625,0.6640625,
0.6953125,0.71875,0.734375,0.7578125,0.78125,0.796875,0.8203125,0.8359375,0.8515625,0.8671875,0.8828125,0.890625,
0.90625,0.921875,0.9296875,0.9375,0.953125,0.9609375,0.96875,0.96875,0.9765625,0.984375,0.984375,0.9921875,0.9921875,
0.9921875,0.9921875,0.9921875,0.9921875,0.9921875,0.9921875,0.9921875,0.984375,0.984375,0.9765625,0.9765625,0.96875,
0.9609375,0.953125,0.9453125,0.9375,0.9296875,0.921875,0.90625,0.8984375,0.890625,0.875,0.8671875,0.8515625,0.8359375,
0.828125,0.8125,0.796875,0.78125,0.765625,0.75,0.734375,0.71875,0.703125,0.6796875,0.6640625,0.6484375,0.6328125,0.609375,
0.59375,0.5703125,0.5546875,0.53125,0.515625,0.4921875,0.46875,0.453125,0.4296875,0.40625,0.3828125,0.359375,0.34375,0.3203125,
0.296875,0.2734375,0.25,0.2265625,0.203125,0.1796875,0.15625,0.1328125,0.109375,0.0859375,0.0625,0.0390625,0.015625,0,
-0.0234375,-0.046875,-0.0703125,-0.09375,-0.1171875,-0.140625,-0.1640625,-0.1875,-0.2109375,-0.234375,-0.2578125,-0.28125,
-0.3046875,-0.328125,-0.3515625,-0.3671875,-0.390625,-0.4140625,-0.4375,-0.4609375,-0.4765625,-0.5,-0.5234375,-0.5390625,
-0.5625,-0.578125,-0.6015625,-0.6171875,-0.640625,-0.65625,-0.671875,-0.6875,-0.7109375,-0.7265625,-0.7421875,-0.7578125,
-0.7734375,-0.7890625,-0.8046875,-0.8203125,-0.8359375,-0.84375,-0.859375,-0.875,-0.8828125,-0.8984375,-0.90625,-0.9140625,
-0.9296875,-0.9375,-0.9453125,-0.953125,-0.9609375,-0.96875,-0.9765625,-0.984375,-0.984375,-0.9921875,-0.9921875,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-0.9921875,-0.9921875,-0.984375,-0.9765625,-0.9765625,-0.96875,-0.9609375,-0.9453125,-0.9375,-0.9296875,-0.9140625,
-0.8984375,-0.890625,-0.875,-0.859375,-0.84375,-0.828125,-0.8046875,-0.7890625,-0.765625,-0.7421875,-0.7265625,-0.703125,
-0.671875,-0.6484375,-0.625,-0.59375,-0.5625,-0.5390625,-0.5078125,-0.4765625,-0.4375,-0.40625,-0.3671875,-0.3359375,-0.296875,
-0.2578125,-0.21875,-0.171875,-0.1328125,-0.0859375,-0.046875,0,0.046875,0.1015625,0.1484375,0.203125,0.2578125,0.3125,0.3671875,
0.421875,0.4765625,0.5390625,0.6015625,0.6640625,0.7265625,0.7890625,0.859375,0.9296875,0.9996875
};
const float wave_shape_chebyshev_6th [257] =
{
0.490693441,0.270855938,0.072669375,-0.104991361,-0.263216483,-0.403061926,-0.525549963,-0.631669818,-0.722378276,
-0.79860028,-0.861229534,-0.911129093,-0.949131951,-0.976041622,-0.992632719,-0.999651527,-0.997816569,-0.987819169,
-0.970324009,-0.945969683,-0.915369243,-0.879110741,-0.837757768,-0.791849987,-0.741903658,-0.688412162,-0.631846518,
-0.572655896,-0.511268125,-0.448090193,-0.383508747,-0.317890586,-0.251583144,-0.184914977,-0.118196241,-0.05171916,
0.014241505,0.079427988,0.143599071,0.206529621,0.268010148,0.327846365,0.385858743,0.441882084,0.495765094,0.547369957,
0.59657192,0.643258879,0.687330973,0.728700181,0.767289925,0.803034675,0.835879566,0.86578001,0.892701325,0.916618355,
0.93751511,0.955384399,0.970227472,0.982053671,0.990880081,0.996731184,0.999638529,0.999640393,0.996781454,0.991112473,
0.982689972,0.971575925,0.957837447,0.941546494,0.922779566,0.90161741,0.87814474,0.852449947,0.824624828,0.794764306,
0.762966172,0.729330814,0.693960964,0.656961444,0.61843892,0.578501658,0.537259286,0.494822565,0.451303155,0.406813401,
0.361466108,0.315374332,0.268651175,0.221409575,0.173762116,0.125820832,0.077697021,0.029501059,-0.018657772,-0.066671461,
-0.114433432,-0.161838711,-0.208784079,-0.255168227,-0.300891902,-0.345858051,-0.389971958,-0.433141375,-0.475276652,
-0.516290858,-0.556099899,-0.594622629,-0.63178096,-0.667499963,-0.701707965,-0.734336644,-0.765321112,-0.794600003,
-0.822115545,-0.847813638,-0.871643916,-0.893559814,-0.913518623,-0.931481545,-0.947413734,-0.961284349,-0.973066581,
-0.982737693,-0.990279043,-0.99567611,-0.998918508,-1,-0.998918508,-0.99567611,-0.990279043,-0.982737693,-0.973066581,
-0.961284349,-0.947413734,-0.931481545,-0.913518623,-0.893559814,-0.871643916,-0.847813638,-0.822115545,-0.794600003,
-0.765321112,-0.734336644,-0.701707965,-0.667499963,-0.63178096,-0.594622629,-0.556099899,-0.516290858,-0.475276652,
-0.433141375,-0.389971958,-0.345858051,-0.300891902,-0.255168227,-0.208784079,-0.161838711,-0.114433432,-0.066671461,
-0.018657772,0.029501059,0.077697021,0.125820832,0.173762116,0.221409575,0.268651175,0.315374332,0.361466108,0.406813401,
0.451303155,0.494822565,0.537259286,0.578501658,0.61843892,0.656961444,0.693960964,0.729330814,0.762966172,0.794764306,
0.824624828,0.852449947,0.87814474,0.90161741,0.922779566,0.941546494,0.957837447,0.971575925,0.982689972,0.991112473,
0.996781454,0.999640393,0.999638529,0.996731184,0.990880081,0.982053671,0.970227472,0.955384399,0.93751511,0.916618355,
0.892701325,0.86578001,0.835879566,0.803034675,0.767289925,0.728700181,0.687330973,0.643258879,0.59657192,0.547369957,
0.495765094,0.441882084,0.385858743,0.327846365,0.268010148,0.206529621,0.143599071,0.079427988,0.014241505,-0.05171916,
-0.118196241,-0.184914977,-0.251583144,-0.317890586,-0.383508747,-0.448090193,-0.511268125,-0.572655896,-0.631846518,
-0.688412162,-0.741903658,-0.791849987,-0.837757768,-0.879110741,-0.915369243,-0.945969683,-0.970324009,-0.987819169,
-0.997816569,-0.999651527,-0.992632719,-0.976041622,-0.949131951,-0.911129093,-0.861229534,-0.79860028,-0.722378276,
-0.631669818,-0.525549963,-0.403061926,-0.263216483,-0.104991361,0.072669375,0.270855938,0.490693441,0.733342528,1
};
void setup() {
Serial.begin(9600);
AudioMemory(40);
waveform.begin(1.0, 200.0, WAVEFORM_SINE);
}
void loop() {
waveshape1.shape(wave_shape_flat, 2);
delay (500);
waveshape1.shape(wave_shape_chebyshev_3rd, 257);
delay(500);
waveshape1.shape(wave_shape_chebyshev_6th, 257);
delay(500);
}