OggVorbisAudioFormat problem


I am having a problem with OggVorbisAudioformat…
I read an ogg file(48kz,stereo,16 bits per channel) using juce::AudioFormatReader
and then write it to a (wav/ogg) file using juce::AudioFormatWriter.I find that the audio is distorted and noisy.

Heres my sourcecode…

void ReadFromOggWriteToWav(juce::String inputFilePath, juce::String outputFilePath)
//reading .ogg file
juce::FileInputStream *inputstream = juce::File(inputFilePath).createInputStream();
juce::AudioFormat *format = new juce::OggVorbisAudioFormat();
juce::AudioFormatReader *audioReader = format->createReaderFor(inputstream, true);

int64 lengthSamples = audioReader->lengthInSamples;

int *x[2];
x[0] = new int[lengthSamples];
x[1] = new int[lengthSamples];

memset(x[0], 0, lengthSamples*4);
memset(x[1], 0, lengthSamples*4);

//reading all the samples
audioReader->read((int**)x, 0, lengthSamples);	

//writing to .wav file
juce::AudioFormat *format1 = new juce::WavAudioFormat();
juce::AudioFormatWriter *audioWriter = format1->createWriterFor(juce::File(outputFilePath).createOutputStream(), audioReader->sampleRate, audioReader->numChannels, audioReader->bitsPerSample, 0, 0);

//writing all the samples
audioWriter->write((const int **)x, lengthSamples);

delete audioWriter;
delete audioReader;	


Please give me a solution to this problem…

Thanks in Advance

you’re probably mixing up 32-bit floats with 32-bit ints.

There’s a much more sensible way to do this anyway - see AudioFormatWriter::writeFromAudioReader()