Beispiel #1
0
        private void CalculateTimeLength(WavHeader WavHeader)
        {
            int BPS = WavHeader.SampleRate * WavHeader.Channels * WavHeader.BlockAlign;

            _timeLength = (WavHeader.DataSize / BPS) * 1000;
        }
Beispiel #2
0
        private void DivideEachChannel(WavHeader WavHeader, byte[] waveRawData)
        {
            if (WavHeader.BitDepth < 16 && WavHeader.BitDepth > 32)
            {
                throw new ArgumentOutOfRangeException();
            }

            int bytePerChannel  = WavHeader.DataSize / WavHeader.Channels;
            int dataLengthPerCH = bytePerChannel / (WavHeader.BitDepth / 8);

            _waveData = new double[WavHeader.Channels, dataLengthPerCH];

            int   index;
            Int16 LowByte16;
            Int16 HighByte16;
            Int32 LowByte;
            Int32 MidByte;
            Int32 HighByte;
            Int32 LLByte32;
            Int32 MLByte32;
            Int32 MHByte32;
            Int32 HHByte32;

            switch (WavHeader.BitDepth)
            {
            case 16:
                for (_channelOrder = 0; _channelOrder < WavHeader.Channels; _channelOrder++)
                {
                    index = 0;
                    for (int byteCnt = _channelOrder * 2; byteCnt < _wavRawData.Length; byteCnt += WavHeader.BlockAlign)
                    {
                        LowByte16  = _wavRawData[byteCnt];
                        HighByte16 = (Int16)(_wavRawData[byteCnt + 1] << 8);
                        _waveData[_channelOrder, index]  = (HighByte16 | LowByte16);
                        _waveData[_channelOrder, index] /= 0x8000; // Normalize
                        index++;
                    }
                }
                break;

            case 24:
                for (_channelOrder = 0; _channelOrder < WavHeader.Channels; _channelOrder++)
                {
                    index = 0;
                    for (int byteCnt = _channelOrder * 3; byteCnt < _wavRawData.Length; byteCnt += WavHeader.BlockAlign)
                    {
                        LowByte  = _wavRawData[byteCnt];
                        MidByte  = _wavRawData[byteCnt + 1] << 8;
                        HighByte = _wavRawData[byteCnt + 2] << 16;
                        _waveData[_channelOrder, index] = (HighByte | MidByte | LowByte);
                        if (_waveData[_channelOrder, index] > 0x800000) // Sign check
                        {
                            _waveData[_channelOrder, index] -= 0x1000000;
                        }
                        _waveData[_channelOrder, index] /= 0x800000; // Normalize
                        index++;
                    }
                }
                break;

            case 32: // experimental
                for (_channelOrder = 0; _channelOrder < WavHeader.Channels; _channelOrder++)
                {
                    index = 0;
                    for (int byteCnt = _channelOrder * 4; byteCnt < _wavRawData.Length; byteCnt += WavHeader.BlockAlign)
                    {
                        LLByte32 = _wavRawData[byteCnt];
                        MLByte32 = _wavRawData[byteCnt + 1] << 8;
                        MHByte32 = _wavRawData[byteCnt + 2] << 16;
                        HHByte32 = _wavRawData[byteCnt + 3] << 24;
                        _waveData[_channelOrder, index] = (HHByte32 | MHByte32 | MLByte32 | LLByte32);
                        //_waveData[_channelOrder, index] /= 0x80000000; // Normalize
                        index++;
                    }
                }

                break;

            default:
                throw new InvalidDataException();
            }
        }