Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
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  
  Writing my own software audio mixer  (Read 6179 times)
0 Members and 1 Guest are viewing this topic.
Offline paulscode

Senior Devvie


Medals: 12


Staff Sergeant


« Posted 2010-08-23 01:06:27 »

Hello, all.  My next big project is to write my own software audio mixer, so that I can play multiple audio inputs on a single SourceDataLine.  I need to be able to do the following things with PCM audio data:

1) Mixing multiple inputs into one 2-channel (left/right) output, maintaining synchronization between the channels
2) Converting between (or mixing directly) various audio formats (different sample rates/sample sizes/channels)
3) Changing frequency (pitch)
4) Changing gain (volume) independently on each channel

I want to be able to do this in pure Java, completely programatically (i.e. no linking with 3rd-party libraries).  I'm looking for all tips, source code, tutorials, that kind of thing.  I am proficient in several programming languages, so references don't necessarily have to be written specifically for Java.

We love death.  The US loves life.  That is the difference between us.  -Osama bin Laden, mass murderer
Offline ShannonSmith
« Reply #1 - Posted 2010-08-23 15:41:36 »

All fairly trivial except for:

1) Low latency (tricky in Java but possible).
2) Converting between sample rates and changing frequency. Both of those are not trivial to get high quality results. There are a few pretty good sites for audio stuff, musicdsp.org has some good code examples also the dsp forum at  KVR is a good place to ask questions. Columbia uni has a very good mailing list on audio dsp that I tend to search with google
eg:
sample rate conversion site:music.columbia.edu
Offline nsigma
« Reply #2 - Posted 2010-08-23 17:05:25 »


Hello, all.  My next big project is to write my own software audio mixer, so that I can play multiple audio inputs on a single SourceDataLine.  I need to be able to do the following things with PCM audio data:

1) Mixing multiple inputs into one 2-channel (left/right) output, maintaining synchronization between the channels
2) Converting between (or mixing directly) various audio formats (different sample rates/sample sizes/channels)
3) Changing frequency (pitch)
4) Changing gain (volume) independently on each channel

I want to be able to do this in pure Java, completely programatically (i.e. no linking with 3rd-party libraries).  I'm looking for all tips, source code, tutorials, that kind of thing.  I am proficient in several programming languages, so references don't necessarily have to be written specifically for Java.

From my experience, I'd suggest using small, constant size floating-point buffers throughout your audio pipeline.  This is the method used by all the Java audio libraries I know of, including my own, and will make a lot of the mixing stuff a lot easier and reduce any problems with different sample sizes.  Sample rate conversion (and changing frequency) require interpolation between a source table and your destination buffer - I'd recommend going with some sort of pluggable interpolation strategy and starting with a basic linear interpolator - quite nasty but possibly good enough, and you can then plug in better alternatives later.

For mixing (and gain) and any other sort of control change, I'd also recommend linear interpolating values through your buffer period as it's easy to get nasty clicks otherwise.

For research, you might want to look at Beads http://www.beadsproject.net, Toot http://toot.org.uk/, JASS http://www.cs.ubc.ca/~kvdoel/jass/, and possibly RasmusDSP (by the guy who wrote Gervill) http://rasmusdsp.cvs.sourceforge.net/.  Only RasmusDSP has a licence open enough for you if I recall correctly, and it's incredibly complicated and all undocumented - not that I'm one to criticise!  Grin

I am planning on opening up some of the audio libraries under Praxis http://code.google.com/p/praxis as GPL w/CPE in the near future, but I know you don't like that licence!  Tongue  Feel free to look around the repo though - audio.ops, audio.servers and rapl are the 3 things to look under.  Just be warned it's a little untidy in there, and there may be dragons!  Smiley

All fairly trivial except for:
1) Low latency (tricky in Java but possible).

For low latency, worth having a look at this page http://frinika.wikispaces.com/JavaSoundAudioServer  I'm using a similar principle in Praxis, it's not that tricky, and it gives good results.  In fact, Frinika is worth a look for what's possible with Java audio.

Hope that's vaguely useful, and good luck with it.

Best wishes, Neil

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jono
« Reply #3 - Posted 2010-08-26 15:02:11 »

One approach to doing the pitch shifting is to use a phase vocoder. With this you can slow down/speed up a sound without changing the pitch. By resampling up or down respectively, you can then change the longer or shorter sounds into ones with the original duration but different pitch.

The quality of this might not be as good as you need, but since I had most of this lying around already I thought I'd put it together anyway. So here's a basic framework for a phase vocoder in Java. The code's all mine, and you're welcome to take any bits you want and chuck a BSD license or whatever on them.

Here is an example of an original sound, the same sound shortened, and the same sound extended.

Non-periodic sounds (noise) is where the phase vocoder tends to fail. Also, to handle low frequency sounds you will need to use a larger window size, which increases the processing overhead.
Offline paulscode

Senior Devvie


Medals: 12


Staff Sergeant


« Reply #4 - Posted 2010-08-26 21:07:14 »

Awesome, thank you very much for the code samples!  This will be very helpful.

We love death.  The US loves life.  That is the difference between us.  -Osama bin Laden, mass murderer
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.

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

SHC (22 views)
2014-11-25 05:53:45

Norakomi (19 views)
2014-11-25 05:26:43

Gibbo3771 (22 views)
2014-11-24 13:59:16

trollwarrior1 (36 views)
2014-11-22 06:13:56

xFryIx (74 views)
2014-11-13 06:34:49

digdugdiggy (52 views)
2014-11-12 15:11:50

digdugdiggy (46 views)
2014-11-12 15:10:15

digdugdiggy (41 views)
2014-11-12 15:09:33

kovacsa (68 views)
2014-11-07 13:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 16:35:00

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

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

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

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

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

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

List of Learning Resources
by SilverTiger
2014-07-31 10: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!