Strange compiling problem (assertion "Balloc succeeded" failed: file "/data/jenkins/w
Hi,
I am working on a new oscillator class for Teensy. The complete code can be cloned via git from here.
While writing some code for precalculating values I tried to run it on a Teensy-3.6. This is the code (can also be found at https://codeberg.org/dcoredump/Synth_Sine_Partial/src/branch/main/examples/Pre_Calculate_Partials/Pre_Calculate_Partials.ino:
... and got a assertion "Balloc succeeded" failed: file "/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/stdlib/mprec.c", line 783
Shown on the serial console is:
This error seems to be inside Synth_Sine_Partial/src/synth_sine_partial.cpp line 177, but I cannot see any problem here:
I "rewrote" the test code from above to use with gcc-11.3.0 from my development system (see files at utils folder) and after
everything runs fine.
I am a little bit confused and after searching a long time I cannot find any problem. Is this a compiler problem in the Teensy-toolchain or am I doing something completely wrong?
TIA, Holger
Hi,
I am working on a new oscillator class for Teensy. The complete code can be cloned via git from here.
While writing some code for precalculating values I tried to run it on a Teensy-3.6. This is the code (can also be found at https://codeberg.org/dcoredump/Synth_Sine_Partial/src/branch/main/examples/Pre_Calculate_Partials/Pre_Calculate_Partials.ino:
Code:
#include <Arduino.h>
#include <Audio.h>
#include "synth_sine_partial.h"
#define USE_MAX_PARTIALS 30
AudioSynthSineSquare* square;
AudioSynthSineTriangle* triangle;
AudioSynthSineSawtooth* sawtooth;
AudioSynthSineSquareFast* square_fast;
AudioSynthSineTriangleFast* triangle_fast;
AudioSynthSineSawtoothFast* sawtooth_fast;
void setup() {
char label[32];
uint16_t i=0;
Serial.begin(115200);
Serial.printf("<START>\n");
// Square
square = new AudioSynthSineSquare(USE_MAX_PARTIALS);
square->amplitude(1.0);
square->begin();
for (float dc = 0.1; dc <= 1.0; dc += 0.01) {
snprintf(label, sizeof(label), "square");
square->set_duty_cycle(dc);
square->show_partials_compact(label,i);
i++;
}
// Triangle
triangle = new AudioSynthSineTriangle(USE_MAX_PARTIALS);
triangle->amplitude(1.0);
triangle->begin();
snprintf(label, sizeof(label), "triangle");
triangle->show_partials_compact(label);
// Sawtooth
sawtooth = new AudioSynthSineSawtooth(USE_MAX_PARTIALS);
sawtooth->amplitude(1.0);
sawtooth->begin();
snprintf(label, sizeof(label), "sawtooth");
sawtooth->show_partials_compact(label);
// Square Fast
i=0;
square_fast = new AudioSynthSineSquareFast(USE_MAX_PARTIALS);
square_fast->amplitude(1.0);
square_fast->begin();
for (float dc = 0.1; dc <= 1.0; dc += 0.01) {
snprintf(label, sizeof(label), "square_fast");
square_fast->set_duty_cycle(dc);
square_fast->show_partials_compact(label,i);
i++;
}
// Triangle Fast
triangle_fast = new AudioSynthSineTriangleFast(USE_MAX_PARTIALS);
triangle_fast->amplitude(1.0);
triangle_fast->begin();
snprintf(label, sizeof(label), "triangle_fast");
triangle_fast->show_partials_compact(label);
// Sawtooth Fast
sawtooth_fast = new AudioSynthSineSawtoothFast(USE_MAX_PARTIALS);
sawtooth_fast->amplitude(1.0);
sawtooth_fast->begin();
snprintf(label, sizeof(label), "sawtooth_fast");
sawtooth_fast->show_partials_compact(label);
Serial.printf("<END>\n");
}
void loop() {
}
... and got a assertion "Balloc succeeded" failed: file "/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/stdlib/mprec.c", line 783
Shown on the serial console is:
Code:
<START>
//
// Precalculated coefficients for square with 29 partials
//
const float square_a[0][USE_PARTIALS+1] = {
#if USE_PARTIALS > 0
assertion "Balloc succeeded" failed: file "/data/jenkins/workspace/GNU-toolchain/arm-11/src/newlib-cygwin/newlib/libc/stdlib/mprec.c", line 783
This error seems to be inside Synth_Sine_Partial/src/synth_sine_partial.cpp line 177, but I cannot see any problem here:
Code:
...
PRINTF("//\n// Precalculated coefficients for %s with %d partials\n//\n",label, _max_partials-1);
if(subindex >= 0)
PRINTF("const float %s_a[%d][USE_PARTIALS+1] = {\n",label, subindex);
else
PRINTF("const float %s_a[USE_PARTIALS+1] = {\n",label);
for(uint8_t i=0;i<=_max_partials;i++)
{
if(fabs(_a[i]) <= 0.00001)
_a[i]=0.0;
if(i<_max_partials)
{
PRINTF("#if USE_PARTIALS > %d\n",i);
PRINTF("\t%+2.15f, // a[%d]\n",_a[i],i); // <======================
PRINTF("#endif\n");
}
else
PRINTF("};\n");
}
...
I "rewrote" the test code from above to use with gcc-11.3.0 from my development system (see files at utils folder) and after
Code:
make && ./precalculate_partials
I am a little bit confused and after searching a long time I cannot find any problem. Is this a compiler problem in the Teensy-toolchain or am I doing something completely wrong?
TIA, Holger