Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Help controlling Audio Library parameters with pots, without Audio Shield

  1. #1
    Junior Member
    Join Date
    May 2020

    Help controlling Audio Library parameters with pots, without Audio Shield

    The Freeverb based sketch below works fine with nothing in the loop(), but I get silence if I try to control the room size parameter in this manner.

    The line "(float)analogRead(A1)/ 1023.0;" is from the Freeverb example in the IDE. The sketch produces sound without this line.

    When there is no sound, nothing prints to the monitor for the variable 'room'. If i comment out the offending line above, I get 0.7 repeatedly, what 'room' was initialized as.

    Can someone explain this please?

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    // GUItool: begin automatically generated code
    AudioInputAnalog         adc1;           //xy=416,313
    AudioEffectFreeverb      freeverb1;      //xy=708,316
    AudioOutputAnalog        dac1;           //xy=976,301
    AudioConnection          patchCord1(adc1, freeverb1);
    AudioConnection          patchCord2(freeverb1, dac1);
    // GUItool: end automatically generated code
    float room = 0.7;
    void setup() {
    while(!Serial);                        // wait until serial window is open
    void loop() {
    room = (float)analogRead(A1)/ 1023.0;

  2. #2
    I may be wrong here but according to the source of free verb: roomsize is stored in a variable "n" which is passed into a "sat16" from dspinst.h. This object is only defined once during object initialization on line 75. You would have to update "sat16" every time there is a new room size value.

  3. #3
    Senior Member
    Join Date
    Nov 2012
    sat16 is just a macro which is defined to call a function which ultimately compiles into a single DSP assembler instruction (ssat).
    The notes for adc input in the audio design tool have this to say:
    analogRead() must not be used, because AudioInputAnalog is regularly accessing the ADC hardware. If both access the hardware at the same moment, analogRead() can end up waiting forever, which effectively crashes your program.
    So if you want to change the room parameter you'll have to find some other way.


  4. #4
    Thanks Pete, nice catch.

    Maybe check out this older thread of someone who was having a similar issue Pangolin?

  5. #5
    Junior Member
    Join Date
    May 2020
    Thanks that thread indeed leads to the answers.

    McIvan's code posted there needed a couple of updates to run. Namely this section:

    adc->setAveraging(8, ADC_1); // set number of averages
    adc->setResolution(12, ADC_1); // set bits of resolution
    adc->setConversionSpeed(ADC_VERY_LOW_SPEED, ADC_1); // change the conversion speed
    adc->setSamplingSpeed(ADC_VERY_LOW_SPEED, ADC_1); // change the sampling speed

    should be changed to:

    adc->adc1->setAveraging(8); // set number of averages
    adc->adc1->setResolution(12); // set bits of resolution
    adc->adc1->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED); // change the conversion speed
    adc->adc1->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_LOW_SPEED); // change the sampling speed
    and then this line will get ADC readings when used in the loop, as long you use ADC1. See ADC1 pins here -

    value = adc->analogRead(readPin, ADC_1);   // readPin is any ADC1 compatible pin number

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts