Пример #1
0
        static byte[] EncodeNGCDSP(byte[] soundData, int numSamples, short[][] coefs)
        {
            //Create ADPCM Data by frame
            var ms = new MemoryStream();

            using (var bw = new BinaryWriterX(ms, true))
                using (var br = new BinaryReaderX(new MemoryStream(soundData)))
                {
                    List <short> pcmBlock = null;
                    while (br.BaseStream.Position < br.BaseStream.Length)
                    {
                        //Set history values
                        if (pcmBlock != null)
                        {
                            var y = pcmBlock[14];
                            var n = pcmBlock[15];
                            pcmBlock = new List <short>();
                            pcmBlock.Add(y);
                            pcmBlock.Add(n);
                        }
                        else
                        {
                            pcmBlock = new List <short>();
                            pcmBlock.Add(0);
                            pcmBlock.Add(0);
                        }

                        //Get PCMBlock for frame
                        if (br.BaseStream.Length - br.BaseStream.Position < 28)
                        {
                            for (int i = 0; i < br.BaseStream.Length - br.BaseStream.Position; i += 2)
                            {
                                pcmBlock.Add(br.ReadInt16());
                            }
                            while (pcmBlock.Count() < 16)
                            {
                                pcmBlock.Add(0);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < 14; i++)
                            {
                                pcmBlock.Add(br.ReadInt16());
                            }
                        }

                        //Convert PCMBlock to ADPCM frame
                        var adpcm = NGCDSPEncoder.DSPEncodeFrame(pcmBlock.ToArray(), 14, coefs);
                        bw.Write(adpcm);
                    }
                }

            return(ms.ToArray());
        }
Пример #2
0
 static short[][] GetCoefs(byte[] soundData, int numSamples)
 {
     return(NGCDSPEncoder.DSPCorrelateCoefs(soundData, numSamples));
 }