|
import jm.util.*;
|
During the reading of the audio file,
the Read class prints some feedback out to the terminal window. This
includes information about the file.
-------------------- Reading Audio File ---------------------
File 'Welcome.au' read in. Details:
Channels = 1, Samples per channel = 47492, Sample rate = 44100, Bit depth = 16
-------------------------------------------------------------
It should be noted that these methods are designed to enable
stand-alone manipulation of audio data and that many additional audio
features ion Java and jMusic allow for integration of event-based and
audio-based music making processes.
To access the audio samples, simply read from the float array data. For
example, addind a for-loop after the Read.audio() line can print out
all the sample values to the terminal window.
for (int i=0; i< data.length; i++) {
System.out.print(data[i] + " ");
}
In order to see a more visual (but still textual) display of the sample
data, replace the previous for-loop with this one, recompile and run.
for (int i=0; i< data.length; i+= 10) {
|
Saving samples as an audio file
The compliment to the Read class is the Write class, whose audio()
method will create an audio file from an array of floats. In the class
below, samples are read from one file and immediately written out to
another. Notice that the written file is of a different type to the
input file. So this program performs a simple file type conversion from
an AU to AIFF file.
import jm.util.*;
|
As a final code example in this section, we’ll manipulate the samples
before they are written. A simple change is to reverse the order of the
samples, thus playing the sound backwards.
import jm.util.*;
|
© 2004 Andrew Brown |
|
|
|
|
|