Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[2664] Midi Synthesis in Java

Last post 04-07-2006 10:20 PM by spulka. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [2664] Midi Synthesis in Java

    This thread is for discussions of Midi Synthesis in Java.

    • Post Points: 30
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 09-05-2002 3:20 PM In reply to

    noteOff

    You need noteOff messages to close the note, otherwise it is strictly analogous to holding down the piano key after the note has rung out.

    MIDI has no concept of the sound having finished, that is a case for the synthesizer to deal with. A clever synthesizer may send the noteOff for you but you cannot rely on that. Try using a Sweep Pad or Seashore sound to appreciate the need for noteOff. MIDI itself does not know why these are different to the standard piano on patch 1. Synthesizers send noteOff messages when you take your finger off the key. The response to this will depend on the ADSR envelope of the sound. Also, the General MIDI specification requires drum notes to have a length of 1/32nd note (I think), and you will need noteOffs to achieve this.

    You will find when writing a more complex piece that if you do not use noteOff messages to close the noteOn you have opened, you will fill the synthesizer and no more noteOn's will sound until you send some noteOffs.

    If you are planning to program for MIDI, it will be worth your while investigating the MIDI 1.0 Specification. You will find out useful things like the fact that Velocity (how hard you strike the note) can only range from 0 to 127, and that Midi messages are organised in unsigned bytes. Java uses signed bytes so you will also need to compensate for this.

    hope this helps
    • Post Points: 0
  • 09-08-2002 10:57 AM In reply to

    • Michael H
    • Top 50 Contributor
    • Joined on 01-19-2002
    • Guru
    • Points 1,995
    From what I had read of the Java MIDI package documentation,
    I guess I didn't understand that noteOff is as important as it is.

    There are about 3 noteOff methods that I've found so far:

    allNotesOff()      // turns off all the notes
    noteOff(int notenumber)    // turns off the specific note.
    noteOff(int notenumber, int velocity)   // what is velocity for when you're
    // turning the note off?

    wow, thanks for all that info
    I haven't read the MIDI spec.

    This tutorial, I think I mean't it to be about
    of how to generate simple tones, not playing
    music.

    Sound is always the hardest thing for me to do on any platform.
    So far the only 2 platforms I can do simple sound effects with are:
    16bit DOS assembly
    Java

    thanks again for all that info,
    maybe I'll go further with MIDI.

    - Mike H
    • Post Points: 0
  • 09-08-2002 4:56 PM In reply to

    More MIDI

    I'm actually in the middle of coding a Java MIDI app on a contract, and to be honest, I haven't used the noteOn and noteOff methods, I have been building Sequences using ShortMessages and MetaMessages. It's a bit more involved and requires you to know a bit more about MIDI, but as long as you put JMF2.1 or above into your classpath, its pretty good, and I've had no problem with timing yet, which was always going to be tricky in Java's loosely scheduled environment. You will definitely notice the difference without JMF 2.1. But it's pretty rewarding when it works!

    have fun.
    Leon
    • Post Points: 0
  • 09-08-2002 8:32 PM In reply to

    • Michael H
    • Top 50 Contributor
    • Joined on 01-19-2002
    • Guru
    • Points 1,995
    I may or may not try Sequencing, it depends if I find a tutorial on it.

    The reason I wrote this tutorial on Synthesizing is because I wanted to do it but was unable to find a tutorial. I figured out all that's in this document from reading the online java documentation of package java.sound.midi .

    So there probably are plenty of errors in the article, including some silly mistakes and typos which'll be fixed when I have some time on my hands.

    I wrote this basically so that the typical guy can pick it up make his speakers something a little more than useless hardware in a Java program and can do more than Toolkit.getDefaultToolkit().beep().

    writing programing articles is one of my favorite things to do next to programing itself.

    You seem like a knowledgable Java guy. You should help get some Java content on DeveloperFusion as there is currently a lack. I have an upcoming
    Swing tutorial, but that and this one I believe are the only Java articles.

    Any thoughts,

    - Mike H

    -------------------------
    - "I need a life... No make that a better one..."
    - "I hate writing, and yet I write programing articles.. wierd..."
    - Me

    • Post Points: 0
  • 09-09-2002 11:52 AM In reply to

    Writing

    Thanks, I might just do that. I found your article on a search for Java MIDI example code so I haven't been through the site yet. I do c# and ASP primarily but I really love Java (and I'm Sun Certified ), so I may well try to explain the things I've learnt doing this project here. I always quite fancied tutorials and teaching, and, as you have no doubt already found, information on the Java MIDI subject is pretty thin on the ground. It'll be nice to do something to change that when I finally get some free time! I shall have to check out how to submit tutes. Watch this space
    L
    • Post Points: 0
  • 01-28-2004 12:17 AM In reply to

    • Turtle
    • Not Ranked
    • Joined on 01-28-2004
    • New Member
    • Points 5

    How do I record

    Hi

    I have successfully synthesized note using midi/java. now I want to save a particular sequence as a midi file and also retrieve the sequence when needed... How do I do that????

    Thanking You

    Turtle
    • Post Points: 0
  • 08-18-2004 1:51 PM In reply to

    complete bare bones example

    Below is the complete code to play a scale.


    import java.util.*;
    import javax.sound.midi.*;

    class SoundTest
    {
       public static void main(String[] args) {
           try {
               Synthesizer synth = MidiSystem.getSynthesizer();
               synth.open();
           
               final MidiChannel[] mc    = synth.getChannels();
               Instrument[]        instr = synth.getDefaultSoundbank().getInstruments();
               synth.loadInstrument(instr[76]);  // Bottle Blow
               for (int i = 0; i < 120; ++i) {
                   try {
                       Thread.sleep(100);
                   } catch (InterruptedException e) {}
                   mc[4].noteOn(i,200);
               }
           } catch (MidiUnavailableException e) {}
       }
    }

    • Post Points: 0
  • 04-07-2006 10:20 PM In reply to

    • spulka
    • Not Ranked
    • Joined on 04-07-2006
    • Czech Republic
    • New Member
    • Points 5

    Re: [2664] Midi Synthesis in Java

    I am writing a simple program; the user will select instrument (from a drop-down menu), pitch and delay for the tone, and press the Play button. I understand playing sounds. But i don't understand, which of the 16 channels should I select. When calling the Synthesiser.loadInstrument(Instrument i), method, I don't tell the Synthesiser to which channel should it load the specified Instrument. So I don't know, where the Instrument is loaded.

    • Post Points: 5
Page 1 of 1 (9 items)