JSSRCResampler Example

92 views
Skip to first unread message

Dugald Morrow

unread,
Apr 24, 2013, 3:13:06 AM4/24/13
to js...@googlegroups.com
Hi,

Can anyone provide an example of how to use JSSRCResampler? I have a wav file encoded in 8kbps and I need to re-sample it as a 48kbps, PCM wav file. I'd like an example showing how I use JSSRCResampler to create the re-sampled wav file.


Thanks

Maksim Khadkevich

unread,
Apr 24, 2013, 4:11:28 AM4/24/13
to js...@googlegroups.com
You can find examples in  "src/java/test" directory. If you want upsample from 8kHz to 48kHz, the solution is

int outSamplingRate = 48000;  
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(inFilePath));
AudioFormat sourceFormat = audioInputStream.getFormat();
AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                        outSamplingRate,
                        sourceFormat.getSampleSizeInBits(),
                        sourceFormat.getChannels(),
                        sourceFormat.getFrameSize(),
                        sourceFormat.getFrameRate(),
                        sourceFormat.isBigEndian());

AudioInputStream inputStream = AudioSystem.getAudioInputStream(targetFormat, audioInputStream);
AudioSystem.write(inputStream, AudioFileFormat.Type.WAVE, new File(outFilePath, outSamplingRate)));

Maksim Khadkevich

unread,
Apr 24, 2013, 4:34:02 AM4/24/13
to js...@googlegroups.com
When you add jssrc library in classpath, there is com.jssrc.resample.JSSRCSampleRateConversionProvider service defined in META-INF. It has a priority over default audio format converter, which uses linear interpolation (introduces aliasing).


On Wednesday, April 24, 2013 10:11:28 AM UTC+2, Maksim Khadkevich wrote:
You can find examples in  "src/java/test" directory. If you want upsample from 8kHz to 48kHz, the solution is

int outSamplingRate = 48000;  
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(inFilePath));
AudioFormat sourceFormat = audioInputStream.getFormat();
AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                        outSamplingRate,
                        sourceFormat.getSampleSizeInBits()
                        sourceFormat.getChannels(),
                        sourceFormat.getFrameSize(),
                        sourceFormat.getFrameRate(),
                        sourceFormat.isBigEndian());

AudioInputStream inputStream = AudioSystem.getAudioInputStream(targetFormat, audioInputStream);
AudioSystem.write(inputStream, AudioFileFormat.Type.WAVE, new File(outFilePath, outSamplingRate)));

Dugald Morrow

unread,
Apr 24, 2013, 4:35:34 AM4/24/13
to js...@googlegroups.com
Hi Maksim,

Thanks for the explanation.

Regards,
Dugald


--
You received this message because you are subscribed to a topic in the Google Groups "JSSRC" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jssrc/crSSdWaAH9A/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to jssrc+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages