Reference+
Class Name
AudioSample
Description
This class allows you low-level access to an audio buffer to create, access, manipulate and play back sound samples. If you want to pre-load your audio sample with an audio file from disk you can do so using the {@link SoundFile} subclass.
Examples
import processing.sound.*; AudioSample sample; void setup() { size(640, 360); background(255); // Create an array and manually write a single sine wave oscillation into it. int resolution = 1000; float[] sinewave = new float[resolution]; for (int i = 0; i < resolution; i++) { sinewave[i] = sin(TWO_PI*i/resolution); } // Create the audiosample based on the data, set framerate to play 200 oscillations/second sample = new AudioSample(this, sinewave, 200 * resolution); // Play the sample in a loop (but don't make it too loud) sample.amp(0.2); sample.loop(); } void draw() { }
Constructors
AudioSample(parent, frames)
AudioSample(parent, frames, stereo)
AudioSample(parent, frames, stereo, frameRate)
AudioSample(parent, frames, frameRate)
AudioSample(parent, data)
AudioSample(parent, data, stereo)
AudioSample(parent, data, frameRate)
AudioSample(parent, data, stereo, frameRate)
Parameters
parent
(PApplet)
typically use "this"frames
(int)
the desired number of frames for this audiosamplestereo
(boolean)
whether to treat the audiosample as 2-channel (stereo) or not (default: ,<code>,false,</code>,)frameRate
(int)
the underlying frame rate of the sample (default: 44100)
Methods
amp()
Changes the amplitude/volume of the player.channels()
Returns the number of channels in the audiosample as an int (1 for mono, 2 for stereo).cue()
Cues the playhead to a fixed position in the audiosample.cueFrame()
Cues the playhead to a fixed position in the audiosample.duration()
Returns the duration of the audiosample in seconds.frames()
Returns the number of frames of the audiosample as an int.jump()
Jumps to a specific position in the audio sample.jumpFrame()
Jump to a specific position in the audiosample without interrupting playback.loop()
Starts the playback of the audiosample.play()
Starts the playback of the audiosample.playFor()
Starts the playback of the audiosample for the specified duration or to the end of the audiosample, whichever comes first.rate()
Set the relative playback rate of the audiosample.resize()
Resizes the underlying buffer of the audiosample to the given number of frames.sampleRate()
Returns the underlying sample rate of the audiosample.pan()
Pan the soundfile in a stereo panorama.set()
Set multiple parameters at once.stop()
Stops the playback.position()
Get current sound file playback position in seconds.positionFrame()
Get frame index of current sound file playback position.percent()
Get current sound file playback position in percent.pause()
Stop the playback of the sample, but cue it to the current position.read()
The underlying data of the audiosample can be read and written in several different.write()
The underlying data of the audiosample can be read and (over)written in several different ways.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.