This project has moved. For the latest updates, please go here.

Problem with conversion Gsm->Pcm

Sep 16, 2010 at 1:16 PM

I can't convert GSM to PCM format properly.

The output data contains only noise and process has finish without any exception.  The same code used for ALAW->PCM convertion works fine. From the other side, I've implemented ACM conversion from GSM->PCM using native c++ (with the same PCM/GSM parameters) and all there work great.

As you can see bellow I process raw audio data:

 

 

FileStream inFileStream = new FileStream(@"D:\gsm.raw", FileMode.Open);
var inFormat = new WaveFormatGsm610(8000, 1);

XWaveStream gsmStr = new XWaveStream(inFormat, inFileStream);


var transFormat = AcmStream.SuggestPcmFormat(gsmStr.WaveFormat); //PCM, 8000kHz 16bit, mono


var outStream = new WaveFormatConversionStream(transFormat, gsmStr);

var buff = new byte[outStream.Length];
outStream.Read(buff, 0, buff.Length);

var outFileStream = new FileStream(@"d:\out.raw", FileMode.Create);
outFileStream.Write(buff, 0, buff.Length);
outFileStream.Dispose();
inFileStream.Dispose();


and helper classes:

[StructLayout(LayoutKind.Sequential, Pack = 2)] public class WaveFormatGsm610 : WaveFormat { /// <summary> /// samplerate /// </summary> protected short samplesPerBlock; public short SamplesPerBlock { get { return samplesPerBlock; } } WaveFormatGsm610() : this(8000, 1) { } public WaveFormatGsm610(int sampleRate, int channels) : base() { this.waveFormatTag = WaveFormatEncoding.Gsm610; this.sampleRate = sampleRate; this.channels = (short)channels; this.bitsPerSample = (short)0; this.extraSize = 2; this.blockAlign = 65; this.averageBytesPerSecond = 1625; this.samplesPerBlock = 320; } }


    class XWaveStream : WaveStream
    {
        private WaveFormat format;
        Stream str;
        public XWaveStream(WaveFormat fmt, Stream str)
        {
            format = fmt;
            this.str = str;
        }


        public override WaveFormat WaveFormat
        {
            get { return format; }
        }

        public override long Length
        {
            get { return str.Length; }
        }

        public override long Position
        {
            get
            {
                return str.Position;
            }
            set
            {
                str.Position = value;
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return str.Read(buffer, offset, count);
        }
    }


Any ideas?

 

Sep 20, 2010 at 8:54 AM

I tried to decode ETSI GSM 06.10 stream which is not compatibile with Microsof GSM encoding :)