Advertisement

Programming music

Started by February 08, 2004 07:20 PM
5 comments, last by dodecahedron 20 years, 9 months ago
Suppose that you have a midi keyboard and sequencer and have arranged some songs with it. What''s the best way to get those songs to play as backround music for a game? I''m trying to work with Java, and I see basically two very simple, but not acceptable options: 1. take the audio output of the keyboard and sample the whole song into an enormous wav file. 2. convert the sequence into a MID file then arrange the song using the cheezy stock instruments on the soundcard. Option 1 is a memory hog and for option 2, the instruments on the soundcard synth are horrible. What would really be ideal is to sample parts of the song, then arrange and mix the samples. So, for instance, if the song is AABA form, we could sample the A-section then play the sample three times. That would save on memory. What I fear with this method is that I''m going to get bogged down in coding cause I''m going to be telling the computer things like "at 2434 milliseconds play A.wav on channel 1 and volume 2and at 5432 milliseconds play B.wav on channel 2 at volume 5" In other words, I would be spending a lot of time basically doing the arranging and mixing in Java. Maybe another idea would be to have all the samples and then use MIDI to arrange them into a song. As you may have guessed, I''m pretty inexperienced with the programming side of things, so I''d love a push in the right direction.
<< Suppose that you have a midi keyboard and sequencer and have arranged some songs with it. What''s the best way to get those songs to play as backround music for a game? >>

Good question, that''s what I wanna know. I found something which might work in Win32 with C/C++

MCIMIDI.c

Haven''t tried to compile this. Studying it to understand what it does. Uses mciSendCommand or some such function. Seems easier than DirectMusic if it works.

Don''t know if you can use mciSendCommand with Java

Phil P
Advertisement
Knowing little to nothing about programming, I''m wondering why not just convert the .wav file to a compressed format? I don''t know which formats are supported by Java, but .mp3 and .ogg come to mind. Mp3 has become licensed now, so if this project is going to be published, you''ll probably have to pay a fee, but .ogg is free to use. Both formats will reduce the file size to over 10% of the original without notable quality loss, and the conversion is done as simple as converting a jpeg to a gif - using a program like Cool Edit.

***
Looking for a music composer for your game? Go to my page to listen to samples of my orchestral pieces and find info on how to contact me.
***Symphonic Aria,specialising in music for games, multimedia productions and film. Listen to music samples on the website, www.symphonicaria.com.
You could also try adding samples to the music using ModPlug Tracker. I''m not sure how you''d get mod support in Java. There''s probably a libary around somewhere, try asking google.

For those that don''t know - mod is like MIDI, only the samples are embedded in the file - so almost 100% reliable sound output, with fairly low filesize.
Try JMusic. It''s an open source collection of libraries for Java that specialize in all areas of sound and music, and it''s really very good. I''ve only dealt with the MIDI side of it, but I''m pretty sure it supports wav and maybe mp3. Plus it also lets you synthesize your own sounds.
If I''m understanding my own forays into sound programming (which are rather basic at this point) then seperating the music into AABA form or what-have-you should prove the easiest solution. Simply load part A into the buffer twice, followed by B and then A. This is a pretty high-level overview of it but worrying about what millisecond to start playing what part will likely be the least of your problems.
Advertisement
If you specifically want it the way it sounds coming out of your keyboard, then you record the keyboard into your computer, and compress the file into mp3 or .ogg format.

This topic is closed to new replies.

Advertisement