Chapter 10, Audio
#75 Build an Audio Waveform Display
Create a Container
Now that you have the waveform painting under control, you need to cre-
ate a container called
WaveformPanelContainer for SingleWaveformPanels in
order to show multi-channel audio. Figure 10-6 shows the waveform in the
Example 10-7 is the complete code for the
AudioInfo is a helper class that contains references to the loaded audio sam-
ples and the current channel.
Figure 10-6. Multi-channel (stereo) audio in the simulator for this hack
Example 10-7. Testing out the waveform display
public class WaveformPanelContainer extends JPanel {
private ArrayList singleChannelWaveformPanels = new ArrayList( );
private AudioInfo audioInfo = null;
public WaveformPanelContainer( ) {
setLayout(new GridLayout(0,1));
public void setAudioToDisplay(AudioInputStream audioInputStream){
singleChannelWaveformPanels = new ArrayList( );
audioInfo = new AudioInfo(audioInputStream);
for (int t=0; t<audioInfo.getNumberOfChannels( ); t++){
SingleWaveformPanel waveformPanel
= new SingleWaveformPanel(audioInfo, t);
add(createChannelDisplay(waveformPanel, t));

Get Swing Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.