![[INTEL NAVIGATION HEADER]](../../../../../../DESIGN/PIX/HEADER.GIF)
Intel Spatial
Audio for Java* Package Tutorial
Lesson 7:
Streaming
This applet creates random tunes using an
octave worth of tones and a streaming sound
source to play them.Use the "New Tune"
button to generate a new tune, or the
"Replay" button to hear the last one
again.
Here is the source
for the applet Streaming.
|
Goal: This lesson
covers the use of streaming media in the Intel Spatial
Audio for Java* package. The package provides support for
streaming sound sources and streaming listeners.
The Streaming Sound
Source
The applet generates its tune by
filling up a buffer with data for a random note, then
submitting that buffer to the streaming sound source
using the submitBuffer() method. When you submit
a buffer, you can specify an argument to an event which
will be signaled when the audio renderer is finished with
the buffer. In this way, you can re-use the buffers
rather than allocate more and more memory.
This applet uses four steps to
accomplish the streaming:
1. Create the buffers and
the data. The data for seven different notes and a
rest are stored in byte arrays -- byte dataRest,
byte dataA[], etc. We only use three instances
of the BufferHolder class, though. The idea is to
submit all three to the streaming sound source, then
catch the event indicating that the audio renderer is
done with each buffer, set the data to the next
value, and resubmit it. When we create each
BufferHolder, we specify the argument to the
completion event. The Event.id will be SoundSource.BUFFER_EVENT.
We must also specify the AWT Component which will be
the target of the event; in an applet, you can often
pass this.
buffer1 = new BufferHolder(dataRest, (Object)"event1", null, this);
2. Remove any buffers from
the streaming sound source's playback queue:
streamingSoundSource.flush();
3. Start up the sound
source. We create a method called playNextNote()
in which we set the data variable of a BufferHolder
to the byte array representing the next note and
submit the buffer to the streaming sound source. Then
we call this method once on each of the three
BufferHolders.
b.data = getCurrentNote();
streamingSoundSource.submitBuffer(b);
4. Keep playing until the
tune is done (15 notes). We use the applet's handleEvent()
method to catch the BUFFER_EVENTS. When we
receive one, we know that the audio renderer is
finished with the data, so we set the BufferHolder's data
variable to the byte buffer representing the
next note and submit the buffer again.
public boolean handleEvent(Event evt) {
switch(evt.id) {
case SoundSource.BUFFER_EVENT:
if (evt.arg == "event1") {
playNextNote(buffer1);
return true;
}
if (evt.arg == "event2") {
playNextNote(buffer2);
return true;
}
if (evt.arg == "event3") {
playNextNote(buffer3);
return true;
}
} // switch
...
}
The Streaming Listener
While a direct listener sends
the data data generated by the audio renderer directly to
the audio output device (usually headphones or speakers),
the streaming listener receives buffers of data via its requestBuffer()
method. Please refer to the documentation in the User's
Guide for details and a
simple usage model.
This page was last updated on Feb
11th, 1997.
Legal Stuff
|