Audio Library Mixer Gain bug?

Status
Not open for further replies.

i2sflew

Active member
Hi everyone,

synth.PNG
above you see my basic setup. I am trying to regulate amplitude by the mixer gain setting instead of the oscillators. However if the envelope has already started and the gain was 0.0 at the start and is altered it stays at zero. If it is at say 0.5, I start the envelope and adjust it to 1.0 the volume is at something like 0.75. Only after calling noteOn() again it's set to 1.0. It seems the setting is always proportional to the start setting or something.

Is this a bug, or am I overseeing anything?

Cheers
 
Hi everyone,

View attachment 23509
above you see my basic setup. I am trying to regulate amplitude by the mixer gain setting instead of the oscillators. However if the envelope has already started and the gain was 0.0 at the start and is altered it stays at zero. If it is at say 0.5, I start the envelope and adjust it to 1.0 the volume is at something like 0.75. Only after calling noteOn() again it's set to 1.0. It seems the setting is always proportional to the start setting or something.

Is this a bug, or am I overseeing anything?

Cheers

A bug is unlikely. Its used by many thousands of users. But of course, nothing is impossible.
Your information is not sufficiant...
The forum rules state "always post complete sourcecode"... so.. please make a *small* program, easy to read, and maybe we take a look.
 
Mixer gain settings take effect every 128 samples as the audio library updates. Maybe the problem you're seeing is on such a short time scale that you're noticing this 128 sample update time?

The mixer will clip to +1.0 and -1.0 maximum values if the inputs are too much. Maybe you're seeing clipping effects?

I'm having difficulty understanding your description. You've used the word "it" many times where I can not tell if "it" means the mixer or the envelope effect. A clearer description would be nice, but as Frank said, you really need to create a small program (not a large audio system) which demonstrates the bug. Please, make sure the code you post really does reproduce the problem when copied into a blank Arduino window and then uploaded to a Teensy.

If this really is a previously unknown bug, I really do want to fix it. But no investigation will even begin until a complete program is posted to reproduce the problem.
 
Sorry I have very little time to work on my project, so I'll try to setup another program which reproduces the problem when I have time.

I'll try with a better description:
I can alter the mixer gain by serial comms.
1.
- The gain is at 1.0, noteOn() is called, I can hear the appropriate volume on my speaker
- While the note is on I adjust the gain down and the volume goes down accordingly.
This is the good case

2.
- The gain is at 0.0, noteOn() is called, no Sound
- While the note is on I adjust the gain up but the volume does not follow.
- noteOff() is called, then noteOn() again is called and the volume is now at the set value

As I said, maybe I used the library incorrectly. I'll try to get back to you asap with a reproduction.
 
Normally I don't investigate until a complete program is posted, but this seemed so simple, so why not....

I drew this in the design tool.

sc.png

Here's the code I tried. It does the same noteOn & noteOff sequence, first with the gain set to 0.75, then with the gain at 0 and changed to 0.75 after 80ms. It also pulses 2 digital pins, so I can easily see when the code is running with my oscilloscope.

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

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=217,242
AudioMixer4              mixer1;         //xy=400,266
AudioEffectEnvelope      envelope1;      //xy=577,269
AudioOutputI2S           i2s1;           //xy=768,273
AudioConnection          patchCord1(sine1, 0, mixer1, 0);
AudioConnection          patchCord2(mixer1, envelope1);
AudioConnection          patchCord3(envelope1, 0, i2s1, 0);
AudioConnection          patchCord4(envelope1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=622,339
// GUItool: end automatically generated code


void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  AudioMemory(20);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.75);
  mixer1.gain(0, 0);
  mixer1.gain(1, 0);
  mixer1.gain(2, 0);
  mixer1.gain(3, 0);
  sine1.frequency(1000);
  sine1.amplitude(0.9);
}

void loop() {
  mixer1.gain(0, 0.75);  // first trial with gain at 0.75
  digitalWrite(3, HIGH);
  delay(50);             // pulse pin 3 before normal test (trigger oscillscope)
  digitalWrite(3, LOW);
  envelope1.noteOn();
  delay(160);
  envelope1.noteOff();
  delay(500);
  
  mixer1.gain(0, 0);     // second trial with gain starting at 0
  digitalWrite(4, HIGH);
  delay(50);             // pulse pin 4 before gain change test
  digitalWrite(4, LOW);
  envelope1.noteOn();
  delay(80);
  mixer1.gain(0, 0.75);  // set gain to 0.75 about 80ms after noteOn
  delay(80);
  envelope1.noteOff();
  delay(500);
}

This is the result I see on my scope.

file.png

It certainly seems to be working. The 2nd waveform indeed starts with nothing because the gain is 0, but then when the gain is set to 0.75, it looks exactly the same as the first waveform except the first 80ms are missing.

Here is the hardware setup on my workbench with the oscilloscope probes connected.

DSC_1319_web.jpg

Best I can conclude is this case does indeed work properly. If you still feel there is a bug here, obviously I can't reproduce it unless you post a complete program I can run here to observe the problem.
 
Thank you for setting this up, so far I couldn't write something like this for my own. Your code does show this works. This is pretty much what my main program is doing except with a lot of MIDI and Serial settings and other stuff. There must be something wrong with the rest of my code then, which has nothing to do with the mixer.

I was wondering if I was using it incorrectly like ahving to call update() for the mixer or envelope but your code doesn't do that either. I agree there is no indication here for a bug in the mixer or envelope!
 
Status
Not open for further replies.
Back
Top