Stereo - Strange error compilation depending if a function was define before updateAudio() - Problem with preprocessor ?

Open
#193 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
arduino, cpp
Domain
embedded-iot

Research direction

Start with the minimal sketch in the issue and compare compilation with callback_updateEncodeurRotatif() before and after updateAudio(). Inspect mozzi_config.h and the AudioOutput.h include path, then verify that stereo compilation succeeds regardless of the callback's position while the mono case remains working.

Written by the indexing model from the issue text.

Description

Hello,

I got a really strange problem using the stereo mode on a pico using pt_8211 as output (I did not test on other platforms).

The problem

My code is using a rotary encoder and mozzi and looks like that (minimal code example, I remove a max of things) :

//********************************************************************
// 2023 Djevahirdjian Léo
//
// Bug Stereo - Minimal Code
//
//********************************************************************

//********************************************************************
//     DEFINITIONS - Interface
//********************************************************************
// Rotary encoder
# define ROT_PIN0 6
# define ROT_PIN1 7
#include <RotaryEncoder.h>
RotaryEncoder *interface_encodeurRotatif = nullptr ;

//  Definition of the function called when rottary encoder is used.
// THIS MAKE THE COMPILATION FAILS
void callback_updateEncodeurRotatif(){
  interface_encodeurRotatif->tick() ;
}

//********************************************************************
//     DEFINITIONS - Mozzi
//********************************************************************
#include <MozziGuts.h>
#include <AudioOutput.h>
// Template oscillateur
#include <Oscil.h>
// Chargement des tables pour oscillateurs
#include <tables/saw2048_int8.h>
#include <tables/sin2048_int8.h>

Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> Oscillateur_Scie1(SAW2048_DATA) ;
Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> Oscillateur_Scie2(SAW2048_DATA) ;

int CH1_frequence = 440 ;
int CH2_frequence = 220 ;

void updateControl() {
  Oscillateur_Scie1.setFreq(CH1_frequence) ;
  Oscillateur_Scie2.setFreq(CH2_frequence) ;
}

// Fonction de génération de la sortie
AudioOutput_t updateAudio() {
  return StereoOutput::fromNBit(9, Oscillateur_Scie1.next(), Oscillateur_Scie2.next()) ;
}


//********************************************************************
//     COEUR n°0 - Mozzi
//********************************************************************
void setup() {
}

void loop() {
}

//********************************************************************
//     COEUR n°1 - Interface
//********************************************************************
void setup1(void) {
}

void loop1(){
}

These return an error "Compilation error: 'StereoOutput' does not name a type".

Try 1 - Switch to Mono

Switching to Mono mode in mozzi_config.h, and replacing

return StereoOutput::fromNBit(9, Oscillateur_Scie1.next(), Oscillateur_Scie2.next()) ;
```c++

to

```c++
return MonoOutput::fromNBit(9, Oscillateur_Scie1.next()) ;

-> the compilation work. The problem seems linked to the stereo mode.

Try 2 - Find the disturbing element

I was able to find what make a mess but I don't uderstant why ^^. Moving the function definition of callback_updateEncodeurRotatif() after updateAudio and the sketch is compiled witout error :

//********************************************************************
// 2023 Djevahirdjian Léo
//
// Bug Stereo - Minimal Code
//
//********************************************************************

//********************************************************************
//     DEFINITIONS - Interface
//********************************************************************
// Rotary encoder
# define ROT_PIN0 6
# define ROT_PIN1 7
#include <RotaryEncoder.h>
RotaryEncoder *interface_encodeurRotatif = nullptr ;

//********************************************************************
//     DEFINITIONS - Mozzi
//********************************************************************
#include <MozziGuts.h>
#include <AudioOutput.h>
// Template oscillateur
#include <Oscil.h>
// Chargement des tables pour oscillateurs
#include <tables/saw2048_int8.h>
#include <tables/sin2048_int8.h>

Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> Oscillateur_Scie1(SAW2048_DATA) ;
Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> Oscillateur_Scie2(SAW2048_DATA) ;

int CH1_frequence = 440 ;
int CH2_frequence = 220 ;

void updateControl() {
  Oscillateur_Scie1.setFreq(CH1_frequence) ;
  Oscillateur_Scie2.setFreq(CH2_frequence) ;
}

// Fonction de génération de la sortie
AudioOutput_t updateAudio() {
  return StereoOutput::fromNBit(9, Oscillateur_Scie1.next(), Oscillateur_Scie2.next()) ;
}

// AFTER -> MAKE THE COMPILE WORKS IN STEREO
void callback_updateEncodeurRotatif(){
  interface_encodeurRotatif->tick() ;
}


//********************************************************************
//     COEUR n°0 - Mozzi
//********************************************************************
void setup() {
}

void loop() {
}

//********************************************************************
//     COEUR n°1 - Interface
//********************************************************************
void setup1(void) {
}

void loop1(){
}

Conclusion

I don't have a clue what happen, it's really strange... I don't know if that is a clue that something wrong is happening with stereo mode... Hope that can help.

Thanks for your good work :-)

Leo

Dominant language
C
Stars
1.3k
Forks
204
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sensorium/Mozzi

All issues in sensorium/Mozzi

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.