Skip to content

#define MOZZI_AUDIO_RATE 65536 not compatible with Oscil on some platform #313

@tomcombriat

Description

@tomcombriat

Setting Mozzi's audio rate to 65536 is not officially supported, but more and more people are using this rate these days as it can be seen in the forum and some of the issues/PR published here.

After the typo fixed in #306 , it seems that setting the rate that high leads to an error, at least on some platforms.

Test sketch

#include <MozziConfigValues.h>
#define MOZZI_AUDIO_RATE 65536
#include <Mozzi.h>

#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator

// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, MOZZI_AUDIO_RATE> aSin(SIN2048_DATA);


void setup(){
  startMozzi(); // start with default control rate of 64
}


void updateControl(){}

AudioOutput updateAudio(){
  return MonoOutput::from16Bit(0);
}

void loop(){
  audioHook(); // required here
}

Error message

/tmp/.arduinoIDE-unsaved2025621-60578-87yq4x.3gpop/Control_Gain/Control_Gain.ino:9:43: error: narrowing conversion of '65536' from 'int' to 'short unsigned int' [-Wnarrowing]
    9 | Oscil <SIN2048_NUM_CELLS, MOZZI_AUDIO_RATE> aSin(SIN2048_DATA);
      |                                           ^
/tmp/.arduinoIDE-unsaved2025621-60578-87yq4x.3gpop/Control_Gain/Control_Gain.ino:9:50: error: invalid conversion from 'const int8_t*' {aka 'const signed char*'} to 'int' [-fpermissive]
    9 | Oscil <SIN2048_NUM_CELLS, MOZZI_AUDIO_RATE> aSin(SIN2048_DATA);
      |                                                  ^~~~~~~~~~~~
      |                                                  |
      |                                                  const int8_t* {aka const signed char*}

Platform tested

Platform Compiles Run
RP2040 No No
ESP32 No No
AVR Yes ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions