This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sound API  RSS feed

Indira Devi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I have got the follg code which when compiled gives the error
"Expected Instrument[] but founf javax.sound.midi.Instrument[]"
at the line
Instrument instrs[] = synth.getLoadedInstruments();

Can anyone please help me in this regard?
import javax.sound.midi.*;
public class Waves
public static void main(String[] args)
// Locate the default synthesizer
Synthesizer synth = MidiSystem.getSynthesizer();
// Open the synthesizer;
// Get the available Midi channels - there are usually 16
MidiChannel channels[] = synth.getChannels();
// Get the synth's soundbank where all the sounds are stored
Soundbank bank = synth.getDefaultSoundbank();
// Load all the available instruments
// Get a list of the available instruments
Instrument instrs[] = synth.getLoadedInstruments();
Instrument seashore = null;
// Loop through the instruments
for (int i=0; i < instrs.length; i++)
// Stop when you find the seashore
if (instrs[i].getName().equals("Seashore"))
seashore = instrs[i];
if (seashore == null)
System.out.println("Can't find the beach");
// Get the information describing the Seashore instrument - the
// patch contains the soundbank and program number
Patch seashorePatch = seashore.getPatch();
// Set 5 channels to use the Seashore instrument
// Start the Seashore note on 3 different channels. By waiting a short
// time before starting the next note, you get a much more continuous sound
channels[1].noteOn(32, 127);
channels[2].noteOn(32, 127);
channels[3].noteOn(32, 127);
// Wait forever
for (;
try { Thread.sleep(999999999); } catch (Exception ignore) {}
catch (Exception exc)

Thanks in advance
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!