Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trackme518 opened this issue Dec 27, 2023 · 1 comment
Open

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

trackme518 opened this issue Dec 27, 2023 · 1 comment
Labels
Linux/Raspberry Pi more info needed Further information is requested

Comments

@trackme518
Copy link

trackme518 commented Dec 27, 2023

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);
      }
    }
    //----
  }
}

@kevinstadler
Copy link
Collaborator

I wonder if this is issue is specific to Linux Mint? I just tried your sketch on MacOS and it sounds perfectly fine. I think it should also be possible to call the built-in Env envelope functionality on a looping SoundFile, I wonder if that would make a difference for performance/stuttering.

@kevinstadler kevinstadler added more info needed Further information is requested Linux/Raspberry Pi labels Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux/Raspberry Pi more info needed Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants