Loading a .wav file into memory

Hello

Apologies for posting this - it’s probably a simple question but my online search has failed (although even just a pointer to anywhere I could read about this online would be massively helpful).

So, I’m wanting to load a .wav (or any audio format file) and use the data to draw with.

This link mentions that I can use my audio file as a subclass of the sample audio but I’m just not sure how to do this: (Reference / Processing.org)

This is my current code (without any attempt at where to create the subclass) - I’m just not sure what to do. I basically want to add my ‘noLoop’ into the set up so that my audio file (and resulting visual) is only displayed / created once (as I ultimately want to save the visual out as a PDF) and the way I’m currently doing it means that if I add my ‘noLoop’ then I get a flat line for the current visual…

Thank you for any help!

Becky

import processing.sound.*;

SoundFile file;
Waveform waveform;

int intValue = 200;

public void setup() {
noLoop();
size(640, 360);
background(255);

// Load a soundfile from the /data folder of the sketch and play it back
file = new SoundFile(this, “pigeon_01.wav”);
file.play();

waveform = new Waveform(this, intValue);
waveform.input(file);

println(file.frames());
}

public void draw() {
stroke(0);
strokeWeight(2);
noFill();

waveform.analyze();

beginShape();
for(int i = 0; i < intValue; i++)
{
vertex(
map(i, 0, intValue, 0, 640),
map(waveform.data[i], -1, 1, 0, 300)
);
}
endShape();
}