4

I have a need to convert audio samples from 11025 and 22050 to 44100; I'm looking for the fastest and best sounding conversion routine. I require that the answer be given in pure Java, without the need for external routines or libraries. The source is an array of short values representing left and right channels, interleaved like so LRLRLRLR
I've heard that gaussian transformation is the best, but it is a cpu killer.

Update
To add more detail, I would like a mix between best and fastest. The answer would give great sounding audio suitable for near real-time communication.
Update 2
I'm looking for some short code examples for this one, should be ez points for you audio guru's

RzR
  • 3,068
  • 29
  • 26
Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131
  • I think the formula that I need is on this page but I'm not a math-guy. Any math-geeks out there feel like commenting? http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Tech/Chapter07/genDists.html – Paul Gregoire Sep 14 '10 at 18:09
  • 7
    You will have to make a choice between fastest or best. The *fastest* solution would be something like just duplicating samples, while for *best* you can imagine *any* amount of computation, possibly even an AI that understands whats heard and knows how it should sound :) You can not possibly require both at the same time. A reasonable constraint (like suitable for realtime) would probably get your more answers. If you're set for a specific algorytm, change your question title to reflect that. – Durandal Oct 10 '10 at 23:01

2 Answers2

1

Well, it is hard to resample it slow enough so that it is not realtime :-) One of the best & still fast solutions is to do forward FFT, and then do reverse FFT with any sample rate you need.

You may implement this on your own, or copy & paste any FFT implementation.

This might work like 100x realtime or faster, not sure you need 1000x faster (in this case you can go for linear or bicubic interpolation) :-)

BarsMonster
  • 6,483
  • 2
  • 34
  • 47
1

you can (ultimately) just use a fir after filling every other sample with 0s - you're upsampling by 2 or 4. this will be plenty fast for realtime. audio quality will be fine for most applications.

justin
  • 104,054
  • 14
  • 179
  • 226
  • I'm not sure, but filling every other sample with a zero would probably sound *very odd*... It should probably duplicate the values. – Frank Oct 16 '10 at 03:26
  • Even after applying a FIR (http://en.wikipedia.org/wiki/Finite_impulse_response) filter to the embedded zeroes, wouldn't that still sound odd? – Roland Illig Oct 17 '10 at 00:22
  • @Frank and Roland Illing you may not realize that duplicating the samples (assuming a signal upsampled by an integer which has been zero-filled) could be achieved perfectly with a very simple fir: all values=1, length=upsampling amount (2 or 4 in this case). in practice, it's better to use a longer window function (e.g., sinc or Hamming). the filter fills the gaps, and serves as an interpolator. which function is 'best' depends on the signal, and the characteristics you want (or don't). – justin Oct 19 '10 at 06:47