Discussion:
[music-dsp] resampling
Alex Dashevski
2018-07-19 18:15:51 UTC
Permalink
Hi,

I need to convert 48Khz to 8KHz on input and convert 8Khz to 48Khz on audio
on output.
Could you explain how to do it ?
I need to implement this on android(NDK).

Thanks,
Alex
Esteban Maestre
2018-07-19 18:28:05 UTC
Permalink
Hi Alex,


This is a good read:

https://ccrma.stanford.edu/~jos/resample/


Using Google, I found somebody who used the LGPL code available at
Julius' site:

https://github.com/intervigilium/libresample


Good luck!

Esteban
Post by Alex Dashevski
Hi,
I need to convert 48Khz to 8KHz on input and convert 8Khz to 48Khz on
audio on output.
Could you explain how to do it ?
I need to implement this on android(NDK).
Thanks,
Alex
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
--
Esteban Maestre
Computational Acoustic Modeling Lab
Department of Music Research, McGill University
http://ccrma.stanford.edu/~esteban
Alex Dashevski
2018-07-22 19:22:53 UTC
Permalink
Hi,
Could you explain how to use with LGPL ? I can't understand it.
Thanks,
Alex
Post by Esteban Maestre
Hi Alex,
https://ccrma.stanford.edu/~jos/resample/
Using Google, I found somebody who used the LGPL code available at Julius'
https://github.com/intervigilium/libresample
Good luck!
Esteban
Hi,
I need to convert 48Khz to 8KHz on input and convert 8Khz to 48Khz on
audio on output.
Could you explain how to do it ?
I need to implement this on android(NDK).
Thanks,
Alex
_______________________________________________
--
Esteban Maestre
Computational Acoustic Modeling Lab
Department of Music Research, McGill Universityhttp://ccrma.stanford.edu/~esteban
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Vladimir Pantelic
2018-07-22 19:28:33 UTC
Permalink
https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
Post by Alex Dashevski
Hi,
Could you explain how to use with LGPL ? I can't understand it.
Thanks,
Alex
Post by Esteban Maestre
Hi Alex,
https://ccrma.stanford.edu/~jos/resample/
Using Google, I found somebody who used the LGPL code available at
https://github.com/intervigilium/libresample
Good luck!
Esteban
Hi,
I need to convert 48Khz to 8KHz on input and convert 8Khz to 48Khz on
audio on output.
Could you explain how to do it ?
I need to implement this on android(NDK).
Thanks,
Alex
_______________________________________________
--
Esteban Maestre
Computational Acoustic Modeling Lab
Department of Music Research, McGill Universityhttp://ccrma.stanford.edu/~esteban
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Alex Dashevski
2018-07-22 19:47:21 UTC
Permalink
This is even more incomprehensible.
I'm looking for a simple example of code and explanation how to convert
signal of 48Khz freq samples to 8Kh ,do processing of signal and convert
8Khz to 48Khz freq samples.
Thanks,
Alex
Post by Vladimir Pantelic
https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
Post by Alex Dashevski
Hi,
Could you explain how to use with LGPL ? I can't understand it.
Thanks,
Alex
Post by Esteban Maestre
Hi Alex,
https://ccrma.stanford.edu/~jos/resample/
Using Google, I found somebody who used the LGPL code available at
https://github.com/intervigilium/libresample
Good luck!
Esteban
Hi,
I need to convert 48Khz to 8KHz on input and convert 8Khz to 48Khz on
audio on output.
Could you explain how to do it ?
I need to implement this on android(NDK).
Thanks,
Alex
_______________________________________________
--
Esteban Maestre
Computational Acoustic Modeling Lab
Department of Music Research, McGill Universityhttp://ccrma.stanford.edu/~esteban
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
jpff
2018-07-22 19:49:35 UTC
Permalink
Were you expecting real-time/time-critical resampling or offline?
Alex Dashevski
2018-07-22 19:55:40 UTC
Permalink
real time
Post by jpff
Were you expecting real-time/time-critical resampling or offline?
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Kjetil Matheussen
2018-07-22 20:22:34 UTC
Permalink
Maybe this will give you an idea:

48khz -> 8khz:
float get_output_sample(get_input_sample){
static int i=0;
static float sample;

if (i % 6 == 0)
sample = get_input_sample();

i++;

return sample;
}

8khz -> 48khz:
float get_output_sample(get_input_sample){
float ret = get_input_sample();

for(int i=1;i<6;i++)
get_input_sample();

return ret;
}

Not the best sound quality though.
Post by Alex Dashevski
real time
Post by jpff
Were you expecting real-time/time-critical resampling or offline?
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Alex Dashevski
2018-07-22 20:37:14 UTC
Permalink
where is low pass filter?
Post by Kjetil Matheussen
float get_output_sample(get_input_sample){
static int i=0;
static float sample;
if (i % 6 == 0)
sample = get_input_sample();
i++;
return sample;
}
float get_output_sample(get_input_sample){
float ret = get_input_sample();
for(int i=1;i<6;i++)
get_input_sample();
return ret;
}
Not the best sound quality though.
Post by Alex Dashevski
real time
Post by jpff
Were you expecting real-time/time-critical resampling or offline?
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Henrik G. Sundt
2018-07-23 01:08:00 UTC
Permalink
This solution, without using any low pass filters before and after the
desimation, will generate a lot of aliasing frequencies, Kjetil!

Here is another solution:
https://github.com/intervigilium/libresample/tree/master/jni/resample

Henrik
Post by Kjetil Matheussen
float get_output_sample(get_input_sample){
static int i=0;
static float sample;
if (i % 6 == 0)
sample = get_input_sample();
i++;
return sample;
}
float get_output_sample(get_input_sample){
float ret = get_input_sample();
for(int i=1;i<6;i++)
get_input_sample();
return ret;
}
Not the best sound quality though.
Post by Alex Dashevski
real time
Post by jpff
Were you expecting real-time/time-critical resampling or offline?
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp [1]
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp [1]
------
[1] https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Sound of L.A. Music and Audio
2018-07-23 04:30:43 UTC
Permalink
This code is also dangerous "LGPL" :-)

Seriously, I'm afraid this is also too much for him. Code is not really
good to explain solutions. I prefer the clarification and let people
code themselves.

Let's try it this way:

1. Apply an anti aliasing filter with an edge frequency of about 2..3kHz
and a stop frequency of not more than 4kHz to meet the 8kHz sampling
rate. Do not use only linear interpolation but CIC + FIR. For simple
approaches use an IIR. A nice filter was a 6x4 TAP FIR Filter and a 3kHz
edge.

2. Pick up every 6th sample to get 8kHz

3. Appreciate a dark sound without any "s", "t" ... :-)


To transform back to 48kHz

1. use a linear interpolation with a one stage CIC. Do not use the often
proposed filling with zeros. For simple solutions use the smaple 6 times.

2. Apply a short 12 TAP - FIR filter with an edge frequency of 16kHz
which has easy coefficients for 48kHz and reduces artifacts from the
linear interpolation.

3. This should maintain the 8kHz quality without new degradation

Jürgen
Post by Henrik G. Sundt
This solution, without using any low pass filters before and after the
desimation, will generate a lot of aliasing frequencies, Kjetil!
https://github.com/intervigilium/libresample/tree/master/jni/resample
Henrik
Kjetil Matheussen
2018-07-23 07:08:30 UTC
Permalink
Post by Henrik G. Sundt
This solution, without using any low pass filters before and after the
desimation, will generate a lot of aliasing frequencies, Kjetil!
No doubt. I did write "Not the best sound quality though." :-)
Alex didn't write about his knowledge level etc., so I just showed the
simplest resampler, in case it would be useful.
Kjetil Matheussen
2018-07-23 07:24:11 UTC
Permalink
Post by Henrik G. Sundt
This solution, without using any low pass filters before and after the
desimation, will generate a lot of aliasing frequencies, Kjetil!
https://github.com/intervigilium/libresample/tree/master/jni/resample
For linear interpolation, here is a version that's easier to read:

currReadPos = 2.0;
prevVal = 0.0;
nextVal = 0.0;

float getOutputSample(){
while(currReadPos > 1.0){
currReadPos-=1.0;
prevVal=nextVal;
nextVal=getInputSample();
}
float ret = prevVal + currReadPos * (nextVal-prevVal);
currReadPos += (input_samplerate / output_samplerate);

return ret;
}
Felix Homann
2018-07-23 11:31:36 UTC
Permalink
libsamplerate, aka Secret Rabbit Code, has been relicensed under a 2 clause
BSD license a while ago. Maybe you want to give it a try:

https://github.com/erikd/libsamplerate
Nigel Redmon
2018-07-23 16:25:16 UTC
Permalink
Some articles on my website: http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/ <http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/>, especially the 2010 articles, but the Amp Sim article might be a helpful overview.

48k -> 8k: Filter with a lowpass with cutoff below 4k; keep 1 sample, throw away 5, repeat.

8k -> 48k: Use 1 sample, follow it with 5 new samples of 0 value, repeat; filter with a lowpass filter with cutoff below 4k.

Nuances:

A linear phase FIR is a popular choice for the lowpass filter (odd length, Kaiser windowed sinc is a good choice). In downsampling, you don’t have to calculate the samples you intend to discard, and in upsampling, you don’t need to do the operations for added 0-valued samples.

You want the filter stop band (above 4k) to have suitable attenuation (Kaiser is nice for this, because you can specify it, trading off with transition sharpness).

Advance topic: You can optimize performance by doing it in two stages (3x, 2x). You win by noting that the first stage doesn’t have to be perfect, and long as the second stage cleans up after it.
Hi,
I need to convert 48Khz to 8KHz on input and convert 8Khz to 48Khz on audio on output.
Could you explain how to do it ?
I need to implement this on android(NDK).
Thanks,
Alex
Tom O'Hara
2018-07-24 05:56:30 UTC
Permalink
I've done many resamplers over the decades (48<->32, 24,16,8) and always
used FIRs for these reasons.

Tom
http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/,
especially the 2010 articles, but the Amp Sim article might be a
helpful overview.
48k -> 8k: Filter with a lowpass with cutoff below 4k; keep 1 sample, throw away 5, repeat.
8k -> 48k: Use 1 sample, follow it with 5 new samples of 0 value,
repeat; filter with a lowpass filter with cutoff below 4k.
A linear phase FIR is a popular choice for the lowpass filter (odd
length, Kaiser windowed sinc is a good choice). In downsampling, you
don’t have to calculate the samples you intend to discard, and in
upsampling, you don’t need to do the operations for added 0-valued
samples.
You want the filter stop band (above 4k) to have suitable attenuation
(Kaiser is nice for this, because you can specify it, trading off with
transition sharpness).
Advance topic: You can optimize performance by doing it in two stages
(3x, 2x). You win by noting that the first stage doesn’t have to be
perfect, and long as the second stage cleans up after it.
Alex Dashevski
2018-07-24 05:59:32 UTC
Permalink
Hi,
I need to do resampling on android.
Could you give me code on c/c++/Java?
Post by Tom O'Hara
I've done many resamplers over the decades (48<->32, 24,16,8) and always
used FIRs for these reasons.
Tom
http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/,
Post by Nigel Redmon
especially the 2010 articles, but the Amp Sim article might be a
helpful overview.
48k -> 8k: Filter with a lowpass with cutoff below 4k; keep 1 sample,
throw away 5, repeat.
8k -> 48k: Use 1 sample, follow it with 5 new samples of 0 value,
repeat; filter with a lowpass filter with cutoff below 4k.
A linear phase FIR is a popular choice for the lowpass filter (odd
length, Kaiser windowed sinc is a good choice). In downsampling, you
don’t have to calculate the samples you intend to discard, and in
upsampling, you don’t need to do the operations for added 0-valued
samples.
You want the filter stop band (above 4k) to have suitable attenuation
(Kaiser is nice for this, because you can specify it, trading off with
transition sharpness).
Advance topic: You can optimize performance by doing it in two stages
(3x, 2x). You win by noting that the first stage doesn’t have to be
perfect, and long as the second stage cleans up after it.
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
r***@web.de
2018-07-24 14:37:16 UTC
Permalink
_______________________________________________
dupswapdrop: music-dsp mailing list
music-***@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp
Tom O'Hara
2018-07-24 14:53:49 UTC
Permalink
Adding zeros is an advantage as then you don't need to calculate their
multiplication, as 0 x coefficient = 0

The filter order will be the same with zeros or repeated samples.

Tom
Hello Nigel
could you please say a word more to what you mean by "2x", "3x"?
Also I am again not sure why in this case, adding zeros is an
advantage. I had expected to just copy the samples to have less work
to do in filtering. I tested such things in MATLAB and found that
feeding zeros needs more filter TAPs to come to the same result.
Rolf
*Gesendet:* Montag, 23. Juli 2018 um 18:25 Uhr
*Betreff:* Re: [music-dsp] resampling
http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/,
especially the 2010 articles, but the Amp Sim article might be a
helpful overview.
48k -> 8k: Filter with a lowpass with cutoff below 4k; keep 1 sample, throw away 5, repeat.
8k -> 48k: Use 1 sample, follow it with 5 new samples of 0 value,
repeat; filter with a lowpass filter with cutoff below 4k.
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
Virus-free. www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Nigel Redmon
2018-07-24 16:36:00 UTC
Permalink
(Not sure why I didn’t receive Rolf’s email directly
)

Hi Rolf,

First, I should have pointed to this newer series of articles (of mine), not old ones, earlier in this thread. You’ll get a detailed explanation of why zeroes (and as Alex points out, the zeros can be handled efficiently so it’s a good thing anyway):

http://www.earlevel.com/main/tag/sampling-theory-series/?order=ASC <http://www.earlevel.com/main/tag/sampling-theory-series/?order=ASC>

Nigel
Adding zeros is an advantage as then you don't need to calculate their multiplication, as 0 x coefficient = 0
The filter order will be the same with zeros or repeated samples.
Tom
Hello Nigel
could you please say a word more to what you mean by "2x", "3x"?
Also I am again not sure why in this case, adding zeros is an advantage. I had expected to just copy the samples to have less work to do in filtering. I tested such things in MATLAB and found that feeding zeros needs more filter TAPs to come to the same result.
Rolf
Gesendet: Montag, 23. Juli 2018 um 18:25 Uhr
Betreff: Re: [music-dsp] resampling
Some articles on my website: http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/ <http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/>, especially the 2010 articles, but the Amp Sim article might be a helpful overview.
48k -> 8k: Filter with a lowpass with cutoff below 4k; keep 1 sample, throw away 5, repeat.
8k -> 48k: Use 1 sample, follow it with 5 new samples of 0 value, repeat; filter with a lowpass filter with cutoff below 4k.
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> Virus-free. www.avg.com <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> <x-msg://18/#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp <https://lists.columbia.edu/mailman/listinfo/music-dsp>
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
Nigel Redmon
2018-07-24 18:08:42 UTC
Permalink
Oops, meant “as Tom points out
”
Post by Nigel Redmon
(Not sure why I didn’t receive Rolf’s email directly
)
Hi Rolf,
http://www.earlevel.com/main/tag/sampling-theory-series/?order=ASC <http://www.earlevel.com/main/tag/sampling-theory-series/?order=ASC>
Nigel
Adding zeros is an advantage as then you don't need to calculate their multiplication, as 0 x coefficient = 0
The filter order will be the same with zeros or repeated samples.
Tom
Hello Nigel
could you please say a word more to what you mean by "2x", "3x"?
Also I am again not sure why in this case, adding zeros is an advantage. I had expected to just copy the samples to have less work to do in filtering. I tested such things in MATLAB and found that feeding zeros needs more filter TAPs to come to the same result.
Rolf
Gesendet: Montag, 23. Juli 2018 um 18:25 Uhr
Betreff: Re: [music-dsp] resampling
Some articles on my website: http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/ <http://www.earlevel.com/main/category/digital-audio/sample-rate-conversion/>, especially the 2010 articles, but the Amp Sim article might be a helpful overview.
48k -> 8k: Filter with a lowpass with cutoff below 4k; keep 1 sample, throw away 5, repeat.
8k -> 48k: Use 1 sample, follow it with 5 new samples of 0 value, repeat; filter with a lowpass filter with cutoff below 4k.
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> Virus-free. www.avg.com <http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> <x-msg://18/#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp <https://lists.columbia.edu/mailman/listinfo/music-dsp>
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
_______________________________________________
dupswapdrop: music-dsp mailing list
https://lists.columbia.edu/mailman/listinfo/music-dsp
r***@web.de
2018-07-26 00:27:50 UTC
Permalink
_______________________________________________
dupswapdrop: music-dsp mailing list
music-***@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp
Tom O'Hara
2018-07-26 05:54:45 UTC
Permalink
Regarding Tom's remark:  Using the copied samples also requires no
additional multiplcation since the value is already stored and in use (?)
No, they require multiplication and addition as, while the samples are
the same, each coefficient is different.  A zero x coefficient = zero,
so no need to multiply or add.

Tom

Loading...