Beispiel #1
0
        /// <summary>
        /// 8 bites mono hangfájl beolvasására szolgál.
        /// </summary>
        public static byte[] Rgsample8bit(string fpat, int?ofreqSample = null)
        {
            var wave = new WavInFile(fpat);

            if (ofreqSample != null && wave.GetSampleRate() != ofreqSample)
            {
                throw new Exception("nem " + ofreqSample.Value + "Hz-es");
            }
            if (wave.GetNumChannels() != 1)
            {
                throw new Exception("nem mono");
            }
            if (wave.GetNumBits() != 8)
            {
                throw new Exception("nem 8 bites");
            }

            var n = wave.GetNumSamples();

            var rgsample = new byte[n];

            wave.Read(rgsample, n);
            Debug.Assert(wave.Eof());
            wave.Dispose();
            return(rgsample);
        }
Beispiel #2
0
        public static short[][] Rgsample16bit(string fpat, int?ofreq = null, int?occhannel = null)
        {
            var wave = new WavInFile(fpat);

            if (wave.GetNumBits() != 16)
            {
                throw new Exception("nem 16 bites");
            }
            if (ofreq != null && wave.GetSampleRate() != ofreq)
            {
                throw new Exception("nem " + ofreq + " frekvenciájú");
            }
            if (occhannel != null && wave.GetNumChannels() != occhannel)
            {
                throw new Exception("nem " + occhannel + " csatornás");
            }

            var n        = wave.GetNumSamples();
            var cchannel = wave.GetNumChannels();
            var rgsample = new short[n * cchannel];

            wave.Read(rgsample, rgsample.Length);
            Debug.Assert(wave.Eof());
            var rgrgsample = new short[cchannel][];

            for (int ichannel = 0; ichannel < cchannel; ichannel++)
            {
                rgrgsample[ichannel] = new short[n];
            }

            for (var isample = 0; isample < n; isample++)
            {
                for (int ichannel = 0; ichannel < cchannel; ichannel++)
                {
                    rgrgsample[ichannel][isample] = rgsample[isample * cchannel + ichannel];
                }
            }

            wave.Dispose();
            return(rgrgsample);
        }