Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  Encode sound effects in a midi soundbank?  (Read 3126 times)
0 Members and 1 Guest are viewing this topic.
Offline doos

Senior Devvie


Medals: 2
Projects: 2


Here be random


« Posted 2013-01-12 00:17:13 »

I've been reading that midi has pretty high polyphony - 32-128, but I think the number of wavs you can play simultaneously is low in comparison.

I was wondering if anyone has ever thought of making a midi soundbank from the individual game sounds and using java midi so they could get a better polyphony? I think since jdk 7 having access to some open source soundbank formats, creating those might be easier?

I might have skipped a page in the "What is midi?" section.. I remember my old casio having different sounds attached to different keys for drums though I think some people put instruments on different channels just to make swapping instruments out easier.

Offline krasse
« Reply #1 - Posted 2013-01-12 07:37:59 »

I did that once and it worked pretty well.
I used the Gervill midi synthesizer source for manipulating the soundfonts but I would probably do it manually with Viena (yes with one 'n') if I ever do it again.

One thing to think of though: If you plan to use midi music together with sfxs the number of channels you can use for representing different sound sources shrink. It is max 16 channels if I don't remember it wrong.

Offline doos

Senior Devvie


Medals: 2
Projects: 2


Here be random


« Reply #2 - Posted 2013-01-12 10:41:49 »

I got a sample soundfont from:
http://www.hammersound.com/cgi-bin/soundlink.pl?action=view_category&category=Sound+Effects&ListStart=0&ListLength=15

And tested the concept with some random code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.Synthesizer;
import javax.swing.JButton;
import javax.swing.JFrame;

public class LoadSoundbank extends JFrame {
   private static final boolean DEBUG = true;

   public static JButton playButton = new JButton("play");


   public static void main(String[] args) throws MidiUnavailableException, InvalidMidiDataException, IOException {

      Synthesizer   synth = null;
      synth = MidiSystem.getSynthesizer();
      if (DEBUG) out("Synthesizer: " + synth);

      Soundbank soundbank = null;
      File file = new File("SFX_StarWars_weapons.SF2");
      System.out.println(file.exists());
      soundbank = MidiSystem.getSoundbank(file);
      if (DEBUG) out("Soundbank: " + soundbank);

      synth.open();
      if (DEBUG) out("Defaut soundbank: " + synth.getDefaultSoundbank());

      if (soundbank != null)
      {
         out("soundbank supported: " + synth.isSoundbankSupported(soundbank));
         boolean bInstrumentsLoaded = synth.loadAllInstruments(soundbank);
         if (DEBUG) out("Instruments loaded: " + bInstrumentsLoaded);
      }

      playButton.addActionListener(new PlayListener(synth));

      new LoadSoundbank();

   }


   private static void printUsageAndExit()
   {
      out("LoadSoundbank: usage:");
      out("java LoadSoundbank [<soundbankfilename>]");
      System.exit(1);
   }


   private static void out(String strMessage)
   {
      System.out.println(strMessage);
   }

   public LoadSoundbank (){

      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setLayout(new BorderLayout());
      add(playButton, BorderLayout.CENTER);
      pack();
      show();
   }

   private static class PlayListener implements ActionListener {

      int   nNoteNumber = (int)(80*Math.random());   // MIDI key number
      int   nVelocity = 100;   // MIDI note on velocity

      int   nDuration = 50;
     
      int channelNumber = 10;

      Synthesizer synth;

      public PlayListener(Synthesizer synth){
         this.synth = synth;
         channelNumber = 0;
      }

      @Override
      public void actionPerformed(ActionEvent arg0) {

         for (int i = 0;i < 50; i++){

            MidiChannel[]   channels = synth.getChannels();

            nNoteNumber = (int)(80*Math.random());

            //         nNoteNumber = 45;
           
            MidiChannel channel = channels[9];
           
//            channels[9].noteOn(nNoteNumber, nVelocity);
           
             int PAN_CONTROLLER = 10;
             
            // Pan to Center:
//            channel.controlChange(PAN_CONTROLLER, 64);

           
            if (i<25){
               // Pan hard left:
            channel.controlChange(PAN_CONTROLLER, 0);
            }
            else {
            // Pan hard right:
            channel.controlChange(PAN_CONTROLLER, 127);
            }

            // "Active stereo", Jimi-Hendrix-style
            // sweep from almost-full left to almost-full right:
//            for (int position = 8; position < 127; position += 8) {
//                channel.controlChange(PAN_CONTROLLER, position);
//                try {
//                    Thread.sleep(5);
//                } catch (InterruptedException e) {
//                }
//            }
           
           
            channels[channelNumber].setMono(false);
            channels[channelNumber].noteOn(nNoteNumber, nVelocity);


            /*
             *   Wait for the specified amount of time
             *   (the duration of the note).
             */

            try
            {
               Thread.sleep(nDuration);
            }
            catch (InterruptedException e)
            {
            }

            //         channels[channelNumber].noteOff(nNoteNumber);
         }


         /*
          *   Turn the note off.
          */


      }
   }
}



Problem now is how to get MY soundeffects into a sf2 file.. :/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline doos

Senior Devvie


Medals: 2
Projects: 2


Here be random


« Reply #3 - Posted 2013-01-12 11:04:20 »

Viena (yes with one 'n')

OH! thanks for the tip!
Offline krasse
« Reply #4 - Posted 2013-01-12 14:24:47 »

If you want to automate the soundfont construction, I have some code for you Smiley

It is taken out of its context but you can probably see how to use the Gervill soundfont-related classes for creating/manipulating sfx-soundfonts.

Offline doos

Senior Devvie


Medals: 2
Projects: 2


Here be random


« Reply #5 - Posted 2013-01-20 17:59:21 »

Thanks, I've bookmarked that to investigate later. I got Viena to encode some old sound effects, and I was interested that it did some pitch shifting to attach them to a range of keys.. Might be good for adding variety to sound effects, maybe?
Offline nsigma
« Reply #6 - Posted 2013-01-20 18:37:45 »

Remember, if you don't need pitching, that you can have drumkit soundfonts with 128 different sounds on one channel.  Unlike some synthesizers, Gervill is also meant to support drumkits on every MIDI channel.  As certain things (FX, panning, etc.) will be channel based, you could potentially load the same drumkit instrument on each channel, and rotate through them for each sound effect.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline krasse
« Reply #7 - Posted 2013-01-20 21:19:07 »

Some more ideas of things you can do with midi/gervill with sfxs:
* doppler shift with pitch bend
* positioning with balance
* attenuation with volume
* environment effects with chorus, reverb and lp filter freq/bandwidth

If you have a channel for each sound source and manage/prioritize these depending on context, it should be a pretty straightforward coding adventure Smiley

Gervill has also an implementation of key-based tuning, which you can use (see the demos). It also has a bunch of different chorus and reverb filters that you can change with some fancy midi messages.


Offline nsigma
« Reply #8 - Posted 2013-01-20 22:56:30 »

Btw, I extracted some of the effects from Gervill as part of the JAudioLib's AudioOps library, should you wish to use them on plain audio data. There's no release yet, but the source is at http://code.google.com/p/jaudiolibs/source/browse/?repo=audioops

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline nsigma
« Reply #9 - Posted 2013-04-06 17:22:24 »

Btw, I extracted some of the effects from Gervill as part of the JAudioLib's AudioOps library, should you wish to use them on plain audio data. There's no release yet, but the source is at http://code.google.com/p/jaudiolibs/source/browse/?repo=audioops

Just linking to this thread from elsewhere and noticed the link I posted is old.

All this code is now on GitHub (so fork away!  Wink ) - https://github.com/jaudiolibs/

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
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.

toopeicgaming1999 (57 views)
2014-11-26 15:22:04

toopeicgaming1999 (50 views)
2014-11-26 15:20:36

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (27 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
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!