# How to get rid of click at the beginning of an Audiosample?

**URL:** https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864
**Category:** Libraries
**Created:** [May 3, 2019, 2:44am UTC](https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864 "2019-05-03T02:44:46Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [May 3, 2019, 2:44am UTC](https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864/1 "2019-05-03T02:44:46Z")

</div>

Hi. I noticed that audiosamples I play always have a click in the beginning, which is not a good quality for use. To demonstrate it, I play an inaudible 1hz sinewave below. Press d to play the wave and you hear the click on every press. Why does this happen and is there something I can do to remedy it?

```auto
import processing.sound.*;
AudioSample sample;

void setup(){
float[] r = new float[44100];
for ( int i = 0; i < 44100; i++){
  r[i] = sin((TWO_PI/(44100/1)) * i); //1Hz frequency
}
sample = new AudioSample(this, r, false, 44100);
}

void draw(){}

void keyPressed(){
  if (key == 'd' && !sample.isPlaying()){
    sample.play();
  }
}

void keyReleased(){
  if (key == 'd'){
    sample.stop();
  }
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 3, 2019, 6:14am UTC](https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864/2 "2019-05-03T06:14:06Z")

</div>

try my example with a little bit more show:

```auto
import processing.sound.*;
AudioSample sample;
FFT fft;
Waveform waveform;

int fftBands = 128;
int showfftBands = 10;
// Define how many samples of the Waveform you want to be able to read at once
int samples = 300;

int resolution = 50; // vals to make one sinus ( minimal 4 for triangle
float[] sinewave = new float[resolution];
int note = 440; //Hz

void setup() {
  size(300, 300);
  for (int i = 0; i < resolution; i++) sinewave[i] = sin(TWO_PI*i/resolution);
  sample = new AudioSample(this, sinewave, note * resolution);
  sample.amp(0.2);
  //sample.loop();

  fft = new FFT(this, fftBands);
  fft.input(sample);

  waveform = new Waveform(this, samples);
  waveform.input(sample);

  println("SFSampleRate= " + sample.sampleRate() + " Hz");
  println("SFSamples= " + sample.frames() + " samples");
  println("SFDuration= " + sample.duration() + " seconds");

  println("use: key [d] sound start / stop");
}

void draw() {
  background(200, 200, 0);
  fft.analyze();
  stroke(0, 200, 0);
  fill(0, 0, 200);
  float r_width = width/float(showfftBands);
  for (int i = 0; i < showfftBands; i++) rect( i*r_width, height, r_width, -fft.spectrum[i]*height);

  // Perform the analysis
  waveform.analyze();

  beginShape();
  noFill();
  stroke(200, 0, 0);
  for (int i = 0; i < samples; i++) {
    // Draw current data of the waveform
    // Each sample in the data array is between -1 and +1 
    vertex(
      map(i, 0, samples, 0, width), 
      map(waveform.data[i], -1, 1, 0, height)
      );
  }
  endShape();
}

void keyPressed() {
  if (key == 'd' && !sample.isPlaying() ) {
    sample.loop();
    sample.amp(0.2);
  }
}

void keyReleased() {
  if (key == 'd') {
    sample.amp(0.001);
    sample.stop();
  }
}

```

---

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [May 3, 2019, 12:59pm UTC](https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864/3 "2019-05-03T12:59:48Z")

</div>

Hi kll. I get “The class “Waveform” does not exist” unfortunately. Am I supposed to replace this with something else?

Edit: For now I just tried removing waveform and playing the sample and the click is still there.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 3, 2019, 2:08pm UTC](https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864/4 "2019-05-03T14:08:26Z")

</div>

this is processing 3.5.3 on a win 7 PC  
with the default processing SOUND lib  
and the waveform thing is from a ready example, also the FFT…

the rest i changed to stay close to your code

---

<div class="post-metadata">

### Author: ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)
#### Post date: [May 3, 2019, 3:30pm UTC](https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864/5 "2019-05-03T15:30:18Z")

</div>

Could you point me in the direction of the example for Waveform? Having trouble finding it.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 4, 2019, 12:05am UTC](https://discourse.processing.org/t/how-to-get-rid-of-click-at-the-beginning-of-an-audiosample/10864/6 "2019-05-04T00:05:39Z")

</div>

could you first confirm that you use Processing 3.5.3 and its IDE?  
and what computer / OS you use?

then try:  
/ File / Examples / Libraries / Sound / Analysis / AudioWaveform /

 ![SNAG-0104](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e2e5b537e9f592ca05a2d30e8daf36af00d92a53.jpeg)
