예제 #1
0
        public static Wav CreateWav(byte[] rawData)
        {
            var wav = new Wav()
            {
                _ChunkId       = SubArray(rawData, 0, 4),
                _ChunkSize     = SubArray(rawData, 4, 4),
                _Format        = SubArray(rawData, 8, 4),
                _Subchunk1Id   = SubArray(rawData, 12, 4),
                _Subchunk1Size = SubArray(rawData, 16, 4),
                _AudioFormat   = SubArray(rawData, 20, 2),
                _NumChannels   = SubArray(rawData, 22, 2),
                _SampleRate    = SubArray(rawData, 24, 4),
                _ByteRate      = SubArray(rawData, 28, 4),
                _BlockAlign    = SubArray(rawData, 32, 2),
                _BitsPerSample = SubArray(rawData, 34, 2),
                _Subchunk2Id   = SubArray(rawData, 36, 4),
                _Subchunk2Size = SubArray(rawData, 40, 4),
                _Data          = SubArray(rawData, 44, rawData.Length - 44),
                _RawData       = rawData,
            };

            if (wav.NumChannels > 1)
            {
                wav = GetDualChannel();
            }

            if (ValidateWav(wav))
            {
                return(wav);
            }
            else
            {
                throw new FormatException("File not in correct WAV format.");
            }
        }
예제 #2
0
        private static bool ValidateWav(Wav wav)
        {
            bool result = true;

            if (wav.ChunkId != "RIFF")
            {
                result = false;
            }
            if (wav.Format != "WAVE")
            {
                result = false;
            }
            if (wav.Subchunk1Id != "fmt ")
            {
                result = false;
            }
            if (wav.Subchunk2Id != "data")
            {
                result = false;
            }
            if (wav.ChunkId != "RIFF")
            {
                result = false;
            }

            return(result);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var data = ReadBytes(@"E:\dev_files\Yamaha-V50-Synbass-1-C2.wav");

            var wav = Wav.CreateWav(data);

            var ChunkId       = wav.ChunkId;
            var ChunkSize     = wav.ChunkSize;
            var Format        = wav.Format;
            var Subchunk1Id   = wav.Subchunk1Id;
            var Subchunk1Size = wav.Subchunk1Size;
            var AudioFormat   = wav.AudioFormat;
            var NumChannels   = wav.NumChannels;
            var SampleRate    = wav.SampleRate;
            var ByteRate      = wav.ByteRate;
            var BlockAlign    = wav.BlockAlign;
            var BitsPerSample = wav.BitsPerSample;
            var Subchunk2Id   = wav.Subchunk2Id;
            var Subchunk2Size = wav.Subchunk2Size;

            string str_chunkId   = GetBytesAsString(wav._ChunkId);
            string str_chunkSize = GetBytesAsString(wav._ChunkSize);
            string str_format    = GetBytesAsString(wav._Format);
            string str_sub1Id    = GetBytesAsString(wav._Subchunk1Id);
            string str_sub1Size  = GetBytesAsString(wav._Subchunk1Size);
            string str_audioForm = GetBytesAsString(wav._AudioFormat);
            string str_numChan   = GetBytesAsString(wav._NumChannels);
            string str_sRate     = GetBytesAsString(wav._SampleRate);
            string str_bRate     = GetBytesAsString(wav._ByteRate);
            string str_align     = GetBytesAsString(wav._BlockAlign);
            string str_bps       = GetBytesAsString(wav._BitsPerSample);
            string str_sub2Id    = GetBytesAsString(wav._Subchunk2Id);
            string str_sub2Size  = GetBytesAsString(wav._Subchunk2Size);
            string str_data      = GetBytesAsString(wav._RawData);

            Console.WriteLine(
                $"ChunkId       : {ChunkId}\t:: {str_chunkId}\n" +
                $"ChunkSize     : {ChunkSize}\t:: {str_chunkSize}\n" +
                $"Format        : {Format}\t:: {str_format}\n" +
                $"Subchunk1Id   : {Subchunk1Id}\t:: {str_sub1Id}\n" +
                $"Subchunk1Size : {Subchunk1Size}\t:: {str_sub1Size}\n" +
                $"AudioFormat   : {AudioFormat}\t:: {str_audioForm}\n" +
                $"NumChannels   : {NumChannels}\t:: {str_numChan}\n" +
                $"SampleRate    : {SampleRate}\t:: {str_sRate}\n" +
                $"ByteRate      : {ByteRate}\t:: {str_bRate}\n" +
                $"BlockAlign    : {BlockAlign}\t:: {str_align}\n" +
                $"BitsPerSample : {BitsPerSample}\t:: {str_bps}\n" +
                $"Subchunk2Id   : {Subchunk2Id}\t:: {str_sub2Id}\n" +
                $"Subchunk2Size : {Subchunk2Size}\t:: {str_sub2Size}\n\n" +
                $"Raw Data      : {str_data.Substring(0, 254)}...");
        }
예제 #4
0
        private static Wav GetDualChannel(Wav wav)
        {
            var data       = wav.Data;
            var dataLength = data.Length;

            var leftSample = true;
            var left       = new byte[dataLength / 2];
            var right      = new byte[dataLength / 2];

            for (int i = 0; i < dataLength; i += 4)
            {
            }

            return(wav);
        }