Varying amplitude

Status
Not open for further replies.

cat

Active member
Code:
///////////////////////////////////
// copy the Design Tool code here
///////////////////////////////////

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine2;          //xy=585,367
AudioSynthWaveformSine   sine1;          //xy=606,308
AudioMixer4              mixer1;         //xy=794,343
AudioOutputI2S           i2s1;           //xy=981,350
AudioConnection          patchCord1(sine2, 0, mixer1, 1);
AudioConnection          patchCord2(sine1, 0, mixer1, 0);
AudioConnection          patchCord3(mixer1, 0, i2s1, 0);
AudioConnection          patchCord4(mixer1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=866,505
// GUItool: end automatically generated code

void setup() {
  Serial.begin(9600);
  AudioMemory(20);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.32);

  sine1.frequency(200);
  sine1.amplitude(0.5);
  sine2.frequency(200);
  sine2.amplitude(0.5);

}

float in, out = 0;

void loop() {

if (in > 6.283){in=0;}
else{in = in + 0.01;}
    out =  sin(in) *0.5 + 0.5 ;

    Serial.println(out);
//      sine1.amplitude(out); // why does my volume not vary when this or the next line are active?
      mixer1.gain(0, out);
      mixer1.gain(1, 0.0);
      mixer1.gain(2, 0.0);
      mixer1.gain(3, 0.0);

  delay(100);
}

All I'm trying to do is vary a sine waves volume over time, but I get no change in volume, I've also tried without the mixer, to no avail. What basic concept am I missing here!?
Serial monitor says I've a value varying between 0-1, at 0 it cuts out, is the float out of range?
Just using a Teensy3.2+shield at the moment.
 
I ran your sketch using audio adaptor kit on T3.2, and either works for me with ear buds and watching on scope. sine1.amplitude() gives louder (Vpp = 1.36v) at 1 than does mixer1.gain (Vpp = 0.72v).
 
Last edited:
I ran your sketch using audio shield on T3.2, and either works for me with ear buds and watching on scope. sine1.amplitude() gives louder (Vpp = 1.36v) at 1 than does mixer1.gain (Vpp = 0.72v).

Well, great it works, but damn it doesn't work for me!
Thanks for that, I'll go back to catching my head!
 
Thanks Paul,
I've gone back to basics and it is indeed working, (should always come back to a problem in the morning) I had a component hanging off a pwm pin thats used by the shield, I am a dumb ass!
Damn the audio design thing is great, unbelievably straight forward to use (especially as I use vvvv, a node based software, all the time)
 
Status
Not open for further replies.
Back
Top