[SPAM] RE: [Speex-dev] Encoding audio sampled at 44.1 khz?

Peter Mosedal Laursen dmu615 at vejlehs.dk
Thu Mar 22 20:38:46 PDT 2007


Hi David,

Thank you very much for your reply. Since I need to resample the audio in the program itself, I decided to try out the resampling API in speex.

But now, I have another problem. The resampled sound is very much distorted and clicks appear quite often. (I have attached the source code I used for testing it below).

The test data I had was a file sampled at 44100 hz stereo, 16 bits and that is currently the only file I tested it with.

What am I doing wrong in the below code?

I look forward to any replies.

Best regards,


-- Code --

/* Compiler: Visual Studio 2005 Express

OS: Windows XP Pro SP 2

Program used to play back the output file: GoldWave


#include <speex/speex_resampler.h>

#include <stdio.h>

//#pragma comment(lib, "libspeex_test.lib")

#define ReadSize 16384

int main(int argc, char* argv[]) {

// First of all, declare the resampler state

SpeexResamplerState* State = speex_resampler_init(2, 44100, 22050, 5);

short in[ReadSize];

short out[ReadSize];

FILE* fin = fopen(argv[1], "rb");

FILE* fout = fopen(argv[2], "wb");

unsigned InLength = ReadSize, OutLength = ReadSize;;


while (1) {

// Read in the short data

fread(&in, sizeof(short), ReadSize, fin);

if (feof(fin)) break;

speex_resampler_process_interleaved_int(State, in, &InLength, out, &OutLength);

fwrite(&out, sizeof(short), OutLength, fout);






-- Code --

From: David Hogan [mailto:david.hogan at freshtel.net]
Sent: Thu 22/03/2007 22:29
To: Peter Mosedal Laursen; speex-dev at lists.xiph.org
Subject: [SPAM] RE: [Speex-dev] Encoding audio sampled at 44.1 khz?

Hi Peter,

Have you considered resampling the raw 44.1kHz stereo source files using
a program such as http://audacity.sourceforge.net/, say to 16kHz mono or
32kHz mono, and then using the wideband or ultrawideband speex modes to
encode the result?

Alternatively, if you want to programmatically do the resampling
yourself, you could try the new resampling API in the svn head of speex,
or the GPL library 'Secret Rabit Code'.

Hope this helps,
David Hogan

> -----Original Message-----
> From: speex-dev-bounces at xiph.org
> [mailto:speex-dev-bounces at xiph.org] On Behalf Of Peter Mosedal Laursen
> Sent: Thursday, 22 March 2007 6:13 AM
> To: speex-dev at lists.xiph.org
> Subject: [Speex-dev] Encoding audio sampled at 44.1 khz?
> Hi everyone,
> I recently began using libspeex 1.2 Beta 1 on Windows using
> MS Visual C++. I have gotten a decoder and an encoder to work
> fine from the excellent sample code posted at the website.
> But I face a problem. I am working on using Speex in a
> program to play and create audio books encoded using Speex
> (currently testing it only; for these tests, I do not use Ogg
> to save the encoded frames, even though the data is saved to
> a disk). Some of the files I have are files encoded at 44100
> samples per second stereo. This is not music, but audio books
> recorded from CDs.
> Is it possible to encode those data using Speex? The files I
> tested with ended up taking larger amounts of space than the
> original files.
> If it is not possible, I should be very glad if someone could
> show me how to resample my audio at a lower sampling
> frequency or point me to a place where I might learn of such
> things. (I am very much a beginner when it comes to
> programming with audio data).
> I look forward to hearing from you.
> Best regards,
> Peter.
> _______________________________________________
> Speex-dev mailing list
> Speex-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev

More information about the Speex-dev mailing list