Help controlling Audio Library parameters with pots, without Audio Shield

Status
Not open for further replies.

pangolin

Member
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?

Code:
#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() {

Serial.begin(9600);
while(!Serial);                        // wait until serial window is open
Serial.print("ready...");
  
AudioMemory(100);
freeverb1.roomsize(0.7);
freeverb1.damping(0.2);
dac1.analogReference(INTERNAL);
}


void loop() {

room = (float)analogRead(A1)/ 1023.0;

Serial.print(room);

freeverb1.roomsize(room);

delay(25);

}
 
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.

Pete
 
Thanks that thread indeed leads to the answers.

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

Code:
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:

Code:
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 - https://forum.pjrc.com/attachment.php?attachmentid=11814&d=1508348274

Code:
value = adc->analogRead(readPin, ADC_1);   // readPin is any ADC1 compatible pin number
 
Status
Not open for further replies.
Back
Top