Skip to content

Null pointer error when attaching Env (amplitude envelope) to SoundFile #97

@trackme518

Description

@trackme518

Hi,
I am getting null pointer error when trying to attach SoundFile to amplitude envelope Env:

import processing.sound.*;
SoundFile soundfile;
Env env; 

// Times and levels for the ASR envelope
float attackTime = 0.001;
float sustainTime = 0.01;
float sustainLevel = 1.0;
float releaseTime = 0.2;

void setup() {
  size(640, 360);
  background(0);

  // Create triangle wave and start it
  soundfile = new SoundFile(this, dataPath("zvonkohra.wav") );
  //soundfile.loop(); //does not matter - I am getting null pointer regardless
  soundfile.amp(1.0);
  // Create the envelope 
  //env = new Env(this);
}

void mousePressed(){
    soundfile.play();
    env.play(soundfile, attackTime, sustainTime, sustainLevel, releaseTime); // NULL POINTER ERROR HERE
    println("file play");
}

void draw() { 
} 

With AudioSample it works...so once again method that would return AudioSample from SoundFile would come in handy. What about creating a new function that would return it so we don't have to modify play return type?

import processing.sound.*;
SoundFile soundfile;
Env env;
AudioSample sample;
// Times and levels for the ASR envelope
float attackTime = 0.001;
float sustainTime = 0.1;
float sustainLevel = 1.0;
float releaseTime = 0.5;

void setup() {
  size(640, 360);
  background(0);

  // Create triangle wave and start it
  soundfile = new SoundFile(this, dataPath("zvonkohra.wav") );
  //soundfile.loop();
  soundfile.amp(1.0);

  float[] bufferData = new float[soundfile.frames()];
  for (int i = 0; i < soundfile.frames(); i++) {
    bufferData[i] = soundfile.read(i, 0);
    //float right = soundfile.read(i, 1);
  }

  sample = new AudioSample(this, bufferData);
  // Create the envelope
  env = new Env(this);
}

void mousePressed() {
  sample.play();
  env.play(sample, attackTime, sustainTime, sustainLevel, releaseTime); // NULL POINTER ERROR
  println("file play");
}

void draw() {
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions