O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

384
|
Chapter 10, Audio
#75 Build an Audio Waveform Display
HACK
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
simulator.
Example 10-7 is the complete code for the
WaveformPanelContainer.
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);
singleChannelWaveformPanels.add(waveformPanel);
add(createChannelDisplay(waveformPanel, t));
}
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required