Perforce JViews Charts Sample: Sound Player
Description
This sample shows how to handle real-time audio data. It is a simple sound player based on the Java Sound Technology. Audio data is read from an audio input stream and displayed in two charts, one for each channel.
How to Use the Sample
- Select an audio file to read by means of the button. The supported audio file formats depend on the Java Sound implementation used, but every implementations should at least provide support for AIFF, AU, WAV, and MIDI-based file formats TYPE 0, TYPE 1, and RMF.
- Pressto play the current selection.
- Press to stop the current session.
- Select the update rate of the charts using the combo box.
- Adjust the line gain level using the vertical slider.
How to Run the Sample as an Application
This sample can
be run as an application.
The installation directory contains
an executable JAR file,
sound.jar
,
that allows you to execute the sample with a double click from a
file browser. Note that if you are using Internet Explorer, you can
open the installation directory
and execute the JAR file from the browser. This
technique may not work in other Web browsers.
Alternatively, you
can run the sample application from the command line.
First check that the Ant utility is properly configured. If not, see the
instructions on how to configure Ant for Perforce JViews.
Then, go to the installation directory
of the sample and type:
ant run
Topics Covered
- Batching notification events.
- Use of cyclic data sets.
- Feeding data model from an external thread.
Detailed Description
This sample reads audio data from an audio input stream and displays it in two charts (one per audio channel) while playing the audio stream. The number of updates per second is set according to the combo box value.
An external thread extracts data from the audio input stream and writes it in the audio output line. At the same time, audio data is decoded into data points (one data point per audio frame) and added to the corresponding charts.
For best performance, two main features available in the Charts package are used:
-
Use of cyclic data sets
- A cyclic data set (instance of
IlvCyclicDataSet
) is a special data set where values are stored in a fixed-size buffer, meaning that when new values are added, the oldest values are removed if the buffer size is reached. This mechanism lets you handle a limited number of data points instead of a full set of points. -
Batching the notifications
- By default, each time a new data point is added to a data set, a
corresponding event (
DATA_ADDED
) is sent to all the listeners so that, for example, the renderers can update themselves. To avoid sending a notification for every new point added, a batch notification mechanism is available on allIlvAbstractDataSet
subclasses. When this mechanism is started, all the notification events are buffered by the data set until the batch session ends (callingendBatch()
). Then, only one notification event describing the buffered notifications is sent to the listener.
Installation Directory
The Sound Player sample is installed here.