Skip to content

stuttering / noise when using amp(float volume) continously #98

Description

@trackme518

Hi,
I am getting noticeable glitches / noise when using amp(float volume) continuously. Example with custom Envelope function - code below. Tested on Linux Mint.

import processing.sound.*;
AmpplitudeEnvelope env;
Track track;

void setup() {
  frameRate(1000);
  JSONObject json = new JSONObject();
  json.setFloat("attack", 0.8);
  json.setFloat("sustain", 0.9);
  json.setFloat("release", 1.2);
  json.setFloat("level", 0.8);

  track = new Track( new SoundFile(this, "zvonkohra.wav") );
  track.sample.loop();

  env = new AmpplitudeEnvelope(json);
}

void draw() {
  env.update();
}

void mousePressed() {
  env.reset();
}


class Track {
  SoundFile sample;
  Track(SoundFile fil) {
    sample =  fil;
  }
}
//custom envelopes class - i want to operate on existing samples + let them play
class AmpplitudeEnvelope {
  float attack; //in seconds
  float sustain;
  float release;
  float level;//between 0-1
  Track audiotrack = null; //reference to existing track with SoundFile object
  long started = 0;//when we start attack
  int state = 0;//0=attack,1=sustain,2=release,3=ended
  float amplitude = 0.0;

  AmpplitudeEnvelope(JSONObject json) {
    this.attack = json.getFloat("attack");
    this.sustain = json.getFloat("sustain");
    this.release = json.getFloat("release");
    this.level = json.getFloat("level");
    this.audiotrack = track;

  }

  void reset() {
    started = millis();
    amplitude = 0.0; //start silent
    println("envelope triggered");
  }

  void update() {

    float delta = (millis()-started)/1000.0;
    //println(delta);
    if ( delta<attack) { //attack
      state = 0;
      amplitude = map( delta, 0, attack, 0, level);//where we are at current curve for volume change
    } else if ( delta>attack && delta<attack+sustain) { //sustain
      state = 1;
      amplitude = level;
    } else if ( delta>attack+sustain && delta<attack+sustain+release ) { //release
      state = 2;
      amplitude = map( (delta-attack-sustain), 0, release, level, 0);//where we are at current curve for volume change
    } else if ( delta>attack+sustain+release ) {
      state = 3; //finished
      amplitude = 0.0;
    }
    //----
    if (this.audiotrack!=null) {
      if ( this.audiotrack.sample != null) {
        this.audiotrack.sample.amp(amplitude);
        //println(this.amplitude);
      }
    }
    //----
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions