This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Class

AudioSample

Name

read()

Examples
import processing.sound.*;
AudioSample sample;

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

  // Create a new audiosample
  sample = new AudioSample(this, 100000, 22050);

  // Read some data from it (the following calls are just for demonstration,
  // a freshly initiated audiosample actually contains nothing but zeros)

  // Read the very first frame:
  float frame = sample.read(0);

  // Read the entire sample
  float[] sampleContent = new float[100000];
  sample.read(sampleContent);

  // Read only a part of the sample data
  float[] subSample = new float[50000];
  // Read 500000 frames, starting at frame 30000
  sample.read(30000, subSample, 0, 50000);
}      

void draw() {
}
Description The underlying data of the audiosample can be read and written in several different ways: the method taking a single float array `data` gets the current sample data and write it into the given array. The array has to be able to store as many floats as there are frames in this sample. It is also possible to only read parts of the sample data using the method with four arguments, which allows you to specify the index of the first frame to read, the position in the array to write it to, as well as how many frames to copy over into the array in total. Finally, the method taking a single integer argument `index` returns the value of the single audio frame of the sample at this index as a float.
Syntax
.read(data)
.read(startFrame, data, startIndex, numFrames)
.read(index)
Parameters
data float[]: the target array that the read data is written to
startFrame int: the index of the first frame of the audiosample that should be read
startIndex int: the position in the array where the first read frame should be written to (typically 0)
numFrames int: the number of frames that should be read (can't be greater than data.length - startIndex)
index int: the index of the single frame of the audiosample that should be read and returned as a float
Returnsvoid or float
Updated on January 21, 2019 10:05:15am EST

Creative Commons License