Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Midi, SF2 and Synthesizer...  (Read 5561 times)
0 Members and 1 Guest are viewing this topic.
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Posted 2008-02-19 08:39:45 »

To make a short story long  Tongue There is all the story.

I was looking solution for the background music (mp3, ogg, midi...). But i was a bit disappointed by the quality of the midi sound.
Since it is possible to use "soundbank", i look for a new one (and tool to manage them). I find out a new sound bank but it was the same quality (the "delux" version...) and i never find anything on the file format or on tools for them  Huh
After some search, i find out that the most popular (and open) sound font (why did they call it sound bank in java  Undecided) is the SF2 (you can easily fond a lot of them  Grin). Then I try to create my own SoundBank class to use with current Midi API... not much luck. I down load the jdk source code to see how they deal with it... I didn't get it at all  Undecided (allmost all methods are "native" and I didn't find the C code)

"Hooo well, I will remake all in a 100% java code. It musn't be that difficult" (Dreaming dreaming  Grin)

So I get the file reference. I make a loader (only 60 parameters per sample  Shocked). I make a sequencer, a synthesizer, a mixer (the most basic one). First trys, a lovely silence. Second trys, i heard a magic noise. Third ones, the samples !!!  Smiley. Victory ! I play a midi file and i heard one of the most horrible (and hilarious) music ever  Tongue. I have make some amelioration on the mixer but i have still have lots of problem.

Loading sample :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
    ByteBuffer buff = ByteBuffer.allocate((int)size+1);
   
    if (buff == null) { throw(new JFMODException("Not enough memory")); }
   
    int position = 1;
    while (size >0)
    {
      int read = is.read(buff.array(),position,(int)size);
           
      size -= read;
      position += read;
    }
     
    memoryDump = buff.asShortBuffer();


There are signed 16 bit data. I'm not sur of the convertion byte -> short (it was working for me... until I try to use webstart and i have to change it (0->1 in position  Shocked)).

Attenuation :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static int centibelToPercent(int c)
 {
   c = toShort(c);
   
   if (c<0){ return 0; }
   
   double percent = DAHDSR.MAX_VOLUME / (Math.exp(c/200.0)/Math.log(10));
   
   return (int)percent;
 }

All attenuation are given in decibel (in centibel in fact). Is it the good formulat ? I didn't find a good way to apply it to the envelope

Pitch :
1  
2  
3  
4  
5  
double freq1 = freq[note];
int tone = sample.getRootKey()+sample.getTuneCoarse();
if (tone<0) { tone = 0; } else if (tone>128) { tone = 128; }
double freq2 = freq[tone]*(100.0+sample.getTuneFine())/100.0;
int step = (int)(65536*freq1/freq2*(float)sample.getRate()/(float)Mixer.RATE);


It work for some samples, and it didn't for some others... (there is the scaleTuning parameter to add to this, i'm not sure how to deal with it)

DAHDSR :
Delay, Attack, Hold, Decay, Sustain, Release (not less...)

I'm not sur : I play the delay,attack,hold, decay, sustain while the note is on. If the note turn off, i drop the envelope value from where it is to 0 in the release time. (it seems strange for a harp to have a 10s release  Huh). May be I should use a fixe step rather than a fixe time.

Delay :
When i start playing a instrument, there is a delay at the  begining (it seem to come from java sound). Any way to deal with it ? (it is not that important for a music)

I have made an organ to test the samples. (qsdfghjklm for notes, 1234567890 for octave)
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #1 - Posted 2008-02-20 07:59:07 »

Not mush reply (no wonder since it is very Midi/SF2 specific  Grin)

I think i have find out my mistake with the pich. The fine correction is in cents not in per cent and is not on the right frequence (i wonder if the "coarse" correction is on the right one... but i didn't come across right now)
1  
2  
3  
4  
5  
6  
7  
8  
9  
        double freq1 = freq[note];
        int tone = sample.getRootKey()+sample.getTuneCoarse();
        if (tone<0) { tone = 0; } else if (tone>128) { tone = 128; }
        double freq2 = freq[tone];
       
        double coef = freq1/freq2*Math.pow(cents,sample.getTuneFine());
        coef = coef*sample.getScaleTuning()/100.0 + (100.0-sample.getScaleTuning())/100.0;
               
        int step = (int)(65536*coef*(double)sample.getRate()/(double)Mixer.RATE);


For attenuation, the formulat seems to be good but it didn't seem good in the music (where did i do my mistake...)
And i still have the delay with the organ.

Tests : Organ, Midi Player

Next step, try to do the tremolo and the reverb effects.
Offline skinny boy

Junior Duke





« Reply #2 - Posted 2009-09-30 18:15:22 »

anyone tried out the demos???

i got the same mistake i got when trying to run the JOGL online demos

Application Error "Unable to launch Application"

on both of them

JOrgan Launch File details

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://www.bonbonchan.net/java/" href="jorgan.jnlp">
  <information>
    <title>JOrgan</title>
    <vendor>Bonbon-Chan</vendor>
    <description>Organ to test MIDI Synth</description>
  </information>
  <security>
   <all-permissions/>
  </security>

  <resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.5+" max-heap-size="128m"/>
    <jar href="JFMOD.jar" main="true" />
  </resources>
 
  <application-desc main-class="net.bonbonchan.jfmod.soundfont.JOrgan" />
</jnlp>


exception details

com.sun.deploy.net.FailedDownloadException: Unable to load resource: http://www.bonbonchan.net/java/JFMOD.jar
   at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
   at com.sun.javaws.LaunchDownload.downloadJarFiles(Unknown Source)
   at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
   at com.sun.javaws.Launcher.downloadResources(Unknown Source)
   at com.sun.javaws.Launcher.prepareLaunchFile(Unknown Source)
   at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
   at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
   at com.sun.javaws.Launcher.launch(Unknown Source)
   at com.sun.javaws.Main.launchApp(Unknown Source)
   at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
   at com.sun.javaws.Main$1.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


Wrapped Exception details

java.util.zip.ZipException: ZIP file must have at least one entry
   at java.util.zip.ZipOutputStream.finish(Unknown Source)
   at java.util.zip.DeflaterOutputStream.close(Unknown Source)
   at java.util.zip.ZipOutputStream.close(Unknown Source)
   at com.sun.deploy.net.HttpDownloadHelper.download(Unknown Source)
   at com.sun.deploy.cache.Cache.downloadResourceToTempFile(Unknown Source)
   at com.sun.deploy.cache.Cache.downloadResourceToCache(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
   at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
   at com.sun.javaws.LaunchDownload.downloadJarFiles(Unknown Source)
   at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
   at com.sun.javaws.Launcher.downloadResources(Unknown Source)
   at com.sun.javaws.Launcher.prepareLaunchFile(Unknown Source)
   at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
   at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
   at com.sun.javaws.Launcher.launch(Unknown Source)
   at com.sun.javaws.Main.launchApp(Unknown Source)
   at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
   at com.sun.javaws.Main$1.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


i dont think they are that helpfull for me to post the same details from the other demo
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #3 - Posted 2009-09-30 23:11:12 »

Street Fighter 2 is awesome. Carry on.

Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #4 - Posted 2009-10-02 06:57:56 »

Hmmm it's an one year old project  Smiley. I didn't work on it much, I tryed to fix it yesterday but I have some problem to upload file on my server  Undecided.

By the way, it has nothing to do with Street Fighter... I just hate when people use abbreviation for anything. It end up to have plenty of thing with the same abbreviation.
Offline skinny boy

Junior Duke





« Reply #5 - Posted 2009-10-03 12:16:00 »

i think he was just kidding, since i posted in a "dead" topic

anyway, you dont have to make it work just for me, i am new to the forum, so i scan it, looking for something interesting and then reading about it

so if you have abandoned the project, leave it
thank you either way
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #6 - Posted 2009-10-05 06:50:20 »

The project is dead until I get back to it (I don't know then but it will be in the next century  Wink). I just have to upload a file... but the exemple use a 4mb sound bank and my connection doesn't want me to upload it  Angry. I will try again in the week.
Offline skinny boy

Junior Duke





« Reply #7 - Posted 2009-10-05 11:13:11 »

ok then, thank you for your time
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #8 - Posted 2009-10-07 07:26:31 »

At last... it works  Tongue

As you can "see", there is several problems :
- latency in buffering process (from Java Sound)
- some bugs in the sequencer
- incomplet mixer (but it work not soo bad  Wink)
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!