Exemplo n.º 1
0
        /// <summary>
        /// Create a block data from audio data. Default length 512 bytes, 256 samples.
        /// </summary>
        /// <param name="channel">Channel audio data</param>
        /// <returns>Block data</returns>
        static byte[][] CreateBlocks(byte[] channel, int blockSize, int waveType)
        {
            List <Byte[]> blocks = new List <Byte[]>();

            if (waveType == 2)
            {
                return(Compression_ADPCM.CompressBlock(channel, blockSize));
            }

            int nBlocks         = channel.Length / blockSize;
            int lastBlockLength = channel.Length % blockSize;

            Byte[] block = new Byte[blockSize];
            for (int i = 0; i < nBlocks; i++)
            {
                block = new Byte[blockSize];
                Array.Copy(channel, i * blockSize, block, 0, blockSize);
                if (waveType == 0)
                {
                    block = PCM.PCM16ToPCM8(block);
                }

                blocks.Add(block);
            }

            block = new Byte[lastBlockLength];
            Array.Copy(channel, nBlocks * blockSize, block, 0, lastBlockLength);
            if (waveType == 0)
            {
                block = PCM.PCM16ToPCM8(block);
            }
            blocks.Add(block);

            return(blocks.ToArray());
        }
Exemplo n.º 2
0
        public static sSWAV ConvertToSWAV(sWAV wav, int waveType, int volume = 150)
        {
            sSWAV swav = new sSWAV();

            swav.header.type   = "SWAV".ToCharArray();
            swav.header.magic  = 0x0100FEFF;
            swav.header.nSize  = 0x10;
            swav.header.nBlock = 0x01;

            swav.data.type             = "DATA".ToCharArray();
            swav.data.info.nWaveType   = (byte)waveType;
            swav.data.info.bLoop       = 1;
            swav.data.info.nSampleRate = (ushort)wav.wave.fmt.sampleRate;
            swav.data.info.nTime       = (ushort)(1.6756991e+7 / wav.wave.fmt.sampleRate);
            swav.data.info.nLoopOffset = 0x01;

            if (wav.wave.fmt.numChannels > 1)
            {
                wav.wave.data.data = WAV.ConvertToMono(wav.wave.data.data, wav.wave.fmt.numChannels, wav.wave.fmt.bitsPerSample);
            }

            //wav.wave.data.data = ChangeVolume(wav.wave.data.data, volume, wav.wave.fmt.bitsPerSample);
            if (waveType == 0)
            {
                swav.data.data = PCM.PCM16ToPCM8(wav.wave.data.data);
            }
            else if (waveType == 2)
            {
                List <byte> temp = new List <byte>();
                temp.AddRange(new Byte[] { 0x00, 0x00, 0x00, 0x00 });
                temp.AddRange(Compression_ADPCM.Compress(wav.wave.data.data));
                swav.data.data = temp.ToArray();
            }
            else
            {
                swav.data.data = wav.wave.data.data;
            }

            swav.data.nSize            = (uint)swav.data.data.Length + 0x0A;
            swav.data.info.nNonLoopLen = (uint)swav.data.data.Length;
            swav.header.nFileSize      = swav.data.nSize + swav.header.nSize;

            return(swav);
        }