resample / upsample sound frames from 8Khz to 48Khz (Java/Android)

Related searches

The application that I am trying to develop for andriod, records frames at 48Khz (PCM 16bits & mono) and sends them to the network. Also, there is an incoming stream of audio at 8Khz. So, I receive 8Khz sampled frames and play them (my AudioTrack object is set to 8Khz), but when playing them, everything works but the latency is HUGE. It takes like around 3 seconds until you hear something.

I think that if I upsample the received frames from 8Khz to 48Khz and play them, there won't be such a huge playing latency. In fact when I record and play frames at the same rate, the latency is really low. The bad thing is that I am forced to do it this way: send to 48Khz and receive to 8Khz.

As explained before, I'm trying to upsample a sound frame (16bits PCM) from 8Khz to 48Khz. Does anybody know any routine/library/API in Java that does this???

I know the basics about upsampling a discreet signal, but I consider that to design and implement my own FIR filter and convolute it with the audio stream way too much. Also, it is over my knowledge.

So...does anybody can help me with this?? Does anybody know any library/routine in Java that I can use?? Any suggestions or alternatives??

A quick and dirty solution would be linear interpolation. Since you're always sampling up by a factor of six this is really easy to do:

It works somewhat like this (C-code, and untested, and I don't handle the last iteration properly, but it shows the idea I think).

void resample (short * output, short * input, int n)
  // output ought to be 6 times as large as input (48000/8000).

  int i;
  for (i=0; i<n-1; i++)
    output[i*6+0] = input[i]*6/6 + input[i+1]*0/6;
    output[i*6+1] = input[i]*5/6 + input[i+1]*1/6;
    output[i*6+2] = input[i]*4/6 + input[i+1]*2/6;
    output[i*6+3] = input[i]*3/6 + input[i+1]*3/6;
    output[i*6+4] = input[i]*2/6 + input[i+1]*4/6;
    output[i*6+5] = input[i]*1/6 + input[i+1]*5/6;

Linear interpolation won't give you great sound quality but it is cheap and fast. You can improve this using cubic interpolation if you want to.

If you want a fast and high quality resampling I suggest that you compile a c resampling library like libresample using the Android-NDK and call it from java using JNI. That will be a lot faster. Writing the JNI code is something most people shy away from, but it's quite easy.. The NDK has lots of examples for this.

Resample 8KHz audio sample rate to 44.1KHz using - android, Resample 8KHz audio sample rate to 44.1KHz using swr_convert[FFMPEG] - c++ . Anybody, has tried upsampling audio stream from 8K to 44.1K? I need to resample working with codec, and the flow I think is: Decode input video file( frame?) with audio samples at 48KHz, whereas the only sample rate that Android� For example, an MP3 file may be encoded at 44.1 kHz sample rate but needs to be played back on an Android device supporting 48 kHz audio internally. In that case, a resampler would be used to upsample the MP3 output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate used within the Android device.

Linear interpolation introduces artifacts. There is nice java library with high-quality resampling - JSSRC (

The code is now available on Github:

Upsampling von PCM-Audio-Proben in Android, Am einfachsten ist es, einfach jeden Wert zu kopieren und die Frequenz zu verdoppeln. Dies wird die Klangqualit�t nicht verbessern, aber auch nicht� Choose simple-ratio sampling rates such as 24 kHz (1:2) and 32 kHz (2:3) when playing back on a 48-kHz device, even though other sampling rates and ratios may be permitted through AudioTrack. Use upsampling rather than downsampling to change sample rates. Sampling rates can be changed on the fly.

I was unable to make most libraries work (,, They all have problems either in the resulting audio or just failed to convert from 48000Hz to 44100Hz (that's what I needed).

This one though works perfectly:

That's a big pure-Java library that works on Android (no javax.sound dependencies) and that is capable of many things, but if you just take the FilterKit, Resampler and SampelBuffers classes in package be.tarsos.dsp.resample, it works extremely well and is easy to use.

resample/upsample Soundframes von 8Khz bis 48Khz (Java/Android), Eine schnelle und schmutzige L�sung w�re eine lineare Interpolation. Da Sie immer um einen Faktor von sechs Sampling sind, ist dies wirklich einfach zu tun:. now ,i have a 8k pcm, if i apply this project to my pcm,i need resample 8khz to 48khz,what method of sampling i clould apply and make no effect on noise reduction?

The TarsosDPS library was too heavy for my needs, but I found out that the resampling tools were first published as a lighter 3-class library:

As for TarsosDPS no need of javax

Sampling audio | Android NDK, Best practices for sampling and resampling As of Android 5.0 (Lollipop), the audio resamplers are now entirely based on FIR filters In general, it is best to choose the sampling rate to fit the device, typically 44.1 kHz or 48 kHz. Use upsampling rather than downsampling to change sample rates Kotlin Java More. (for some reason the OMX.SEC.aac.dec always outputs 44100 Hz 2 channel audio if the original track is a 22050 Hz, and outputs 48000 Hz 2 channel audio if the original track is 24000 Hz.) The problem comes in when I try appending a 24000 Hz audio track after a 22050 Hz audio track.

Sample Rate Conversion, Resamplers are used in several places in Android. For example, an In that case, a resampler would be used to upsample the MP3 output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate used within the Android device. Java is a registered trademark of Oracle and/or its affiliates. I have encountered a bug in DirectShow .NET where I create a secondary buffer with a sample rate of 8khz, and upon playback, the sound plays back at approx. 8.1khz instead. Googling this, I discovered that I might be forced to upsample the 8khz audio myself to 48khz or 44.1khz depending on the soundcard in the PC.

Using deep convolutional neural networks to upsample audio signals such as speech or music. Code Paper We train neural networks to impute new time-domain samples in an audio signal; this is similar to the image super-resolution problem, where individual audio samples are analogous to pixels.

Most android devices have a "native" sample rate. For some devices it is 44.1kHz, but for most modern android devices it is 48kHz. This means all the other "supported" sample rates are actually derived (by re-sampling) from this native 48kHz sample rate.