• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Sound API

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
{
try
{
// Locate the default synthesizer
Synthesizer synth = MidiSystem.getSynthesizer();
// Open the synthesizer
synth.open();
// 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
synth.loadAllInstruments(bank);
// 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];
break;
}
}
if (seashore == null)
{
System.out.println("Can't find the beach");
System.exit(0);
}
// 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
channels[1].programChange(seashorePatch.getBank(),
seashorePatch.getProgram());
channels[2].programChange(seashorePatch.getBank(),
seashorePatch.getProgram());
channels[3].programChange(seashorePatch.getBank(),
seashorePatch.getProgram());
// 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);
Thread.sleep(3500);
channels[2].noteOn(32, 127);
Thread.sleep(1500);
channels[3].noteOn(32, 127);
// Wait forever
for (;
{
try { Thread.sleep(999999999); } catch (Exception ignore) {}
}
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}

Thanks in advance
Indira.
 
This tiny ad is guaranteed to be gluten free.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic