Results 1 to 3 of 3
Thread: Java Sound
- 08-19-2011, 12:18 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
Java Sound
hey
so I'm trying to make a program that can play sounds with different notes and instruments and stuff using javax.sound.midi. long story.
anyway, have set this up in eclipse but no matter what I change the instrument loaded into the synth to, it only plays the same piano.
changing channels changes the instrument but there's only 16 in that and the instruments array says its length is 411... where have the others gone/how do i access them?
help would be much appreciated. not total java noob but have never used sound and there is little to go on online.
ta
Java Code:import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.sound.midi.*; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; /** * @author Terry * */ public class Note { MidiChannel[] mc = null; /** * @return */ public Note(){ try { Synthesizer synth = MidiSystem.getSynthesizer(); synth.open(); //synth.loadAllInstruments(MidiSystem.getSoundbank(new File("C:\\Program Files\\Java\\jre6\\lib\\audio\\" + //"soundbank.gm"))); //System.out.println(syn.isSoundbankSupported(MidiSystem.getSoundbank(new File("C:\\Program Files\\Java\\jre7\\lib\\audio\\" + //"soundbank.gm")))); mc = synth.getChannels(); //changing the soundbank gives different instruments?/my one is shit Instrument[] instr = synth.getDefaultSoundbank().getInstruments(); //System.out.println("\n\nSOUNDBANK\n"+syn.getDefaultSoundbank().getDescription()); //System.out.println("\n\nINSTRUMENTS\n"+instr.length); //for(int i=0;i<instr.length;i++) //System.out.println(i+" "+instr[i].getName()); //supposed to change instrument, but doesnt synth.loadInstrument(instr[85]); System.out.println(instr[85].getName()); JFrame frame = new JFrame("Sound1"); JPanel pane = new JPanel(); JButton button1 = new JButton("Click me!"); frame.getContentPane().add(pane); pane.add(button1); frame.pack(); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.show(); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //changing index changes the instrument version //changing first is note pitch, second is how hard it is hit mc[5].noteOn(60,600); //change the wait to alter note duration try {Thread.sleep(1000);} catch (InterruptedException e1) {e1.printStackTrace();} //pull off to stop note mc[5].noteOff(60,600); } }); } catch (Exception e) {e.printStackTrace();} } /** * @param args */ public static void main(String[] args) { new Note(); } }
- 08-19-2011, 12:58 PM #2
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
fixed
Java Code:mc[5].programChange(instr[200].getPatch().getProgram());
- 08-19-2011, 12:58 PM #3
May be useful or at least relevant://changing the soundbank gives different instruments?/my one is shit
https://forums.oracle.com/forums/thr...89625�
db
Similar Threads
-
Sound In java
By chetoos in forum New To JavaReplies: 2Last Post: 06-28-2011, 05:59 PM -
Problems with sound in java and USB sound card
By marblecatdog in forum New To JavaReplies: 1Last Post: 04-19-2011, 12:02 PM -
java sound
By nikkka in forum New To JavaReplies: 11Last Post: 04-10-2011, 02:54 PM -
Calibration of Sound in Java
By satishrah@gmail.com in forum Advanced JavaReplies: 4Last Post: 02-12-2009, 01:44 PM -
Sound in applet Java
By toby in forum Java AppletsReplies: 1Last Post: 08-07-2007, 05:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks