Exemplo n.º 1
0
        static void Decode()
        {
            Decoder dec = new Decoder();
            Format  fmt = dec.ReadHeader(xa);

            dec.WriteRiffHeader(wav);

            byte[] buf_xa =
                new byte[fmt.BlockSizeXa * fmt.Blocks];
            short[] buf_pcm =
                new short[fmt.DataLengthPcm / sizeof(short)];
            long pcm_block;

            if (xa.Read(buf_xa, 0, buf_xa.Length) != buf_xa.Length)
            {
                throw new IOException("Unexpected end of file.");
            }

            int blocks = dec.Decode(buf_xa, buf_pcm,
                                    out pcm_block);

            Assert(blocks == fmt.Blocks);
            Assert(pcm_block == fmt.DataLengthPcm);

            fmt.WritePcm(wav, buf_pcm, pcm_block);
        }
Exemplo n.º 2
0
        static void Decode()
        {
            Decoder dec = new Decoder();
            Format  fmt = dec.ReadHeader(xa);

            dec.WriteRiffHeader(wav);

            byte[]  buf_xa  = new byte[fmt.BlockSizeXa];
            short[] buf_pcm = new short[fmt.BlockSamples];
            long    pcm_block;

            while (fmt.Blocks > 0)
            {
                if (xa.Read(buf_xa, 0, buf_xa.Length) !=
                    buf_xa.Length)
                {
                    throw new IOException(
                              "Unexpected end of file.");
                }

                int blocks = dec.Decode(buf_xa, buf_pcm,
                                        out pcm_block);
                Assert(blocks == 1);
                Assert(pcm_block > 0);

                fmt.WritePcm(wav, buf_pcm, pcm_block);
                fmt.DataLengthPcm -= pcm_block;
                fmt.Blocks--;
            }

            Assert(fmt.DataLengthPcm == 0);
        }