Ejemplo n.º 1
0
        public virtual void Process(AudioRecord item, AudioInfo info)
        {
            //build amplitude envelope
            var s = Build(info.Samples);
            //resample
            var resampler = factory.CreateResampler();
            var resampled = resampler.Resample(s, info.Samples.BitRate * ((float)EnvelopeLength / info.Samples.Values.Length));

            //build packed array
            var envelope = new Envelope(resampled);
            //save into audio item
            item.Data.Add(envelope);
        }
Ejemplo n.º 2
0
        public void Process(AudioRecord item, AudioInfo info)
        {
            var tempogram = new Tempogram();

            var s = info.Samples;

            s = new EnvelopeProcessor(factory).Build(info.Samples, 32, false);
            var s2 = new Samples() { Values = new float[s.Values.Length], BitRate = s.BitRate };
            var intensity = 0;

            for (int i = 0; i < s.Values.Length - 1; i++)
            {
                var d = s.Values[i + 1] - s.Values[i];
                var dd = d > 0 ? d : 0;
                s.Values[i] = dd;
                s2.Values[i] = d;
                if (d > minAmplitudeChangeForIntensityRate)
                    intensity++;
            }
            s.Values[s.Values.Length - 1] = 0;
            s2.Values[s.Values.Length - 1] = 0;

            var time = s.Values.Length / s.BitRate;//time of sound

            var maxShift = (int)(s.Values.Length * (maxRithmDuration / time));

            var autoCorr1 = AutoCorr(s.Values, maxShift, 5);
            var autoCorr2 = AutoCorr(s2.Values, maxShift, 2);
            var l = (float)autoCorr1.Length;
            var k = Math.Log(2);
            var list1 = new List<KeyValuePair<float, float>>();
            var list2 = new List<KeyValuePair<float, float>>();
            for (int i = 0; i < l; i++)
            {
                var j = i / (float)l;
                j = (float)(Math.Log(j + 1) / k);
                list1.Add(new KeyValuePair<float, float>(j, autoCorr1[i]));

                var v = autoCorr2[i];
                list2.Add(new KeyValuePair<float, float>(j, v > 0 ? v : 0));
            }
            tempogram.LongTempogram.Build(list1);
            tempogram.ShortTempogram.Build(list2);

            tempogram.Intensity = (float)intensity / time;

            CalcTempo(tempogram);

            //save to audio item
            item.Data.Add(tempogram);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads data from db
        /// </summary>
        public ICollection<AudioRecord> Load()
        {
            Collection<AudioRecord> records = new Collection<AudioRecord>();
            if (File.Exists(Path))
                using (var fs = new FileStream(Path, FileMode.Open, FileAccess.Read))
                using (var zip = new GZipStream(fs, CompressionMode.Decompress, false))
                using (var br = new BinaryReader(zip, Encoding.UTF8))
                    try
                    {
                        var count = br.ReadInt32();
                        for (int i = 0; i < count; i++)
                        {
                            var item = new AudioRecord();
                            item.Load(br);
                            records.Add(item);
                        }
                    }
                    catch (EndOfStreamException) {/*end of stream*/}

            return records;
        }
Ejemplo n.º 4
0
        private void ScanPath(string path)
        {
            try
            {
                IEnumerable<string> audioIndexes = DataBase.Records.Select(r => r.FullPath);
                foreach (string filePath in DirectoryScanner.Scan(path, ApplicationConstants.SupportedAudioFileExtensions))
                {
                    if (!audioIndexes.Contains(filePath))
                    {
                        AudioRecord item = new AudioRecord()
                        {
                            FullPath = filePath
                        };

                        lock (DataBase.Records)
                        {
                            DataBase.Records.Add(item);
                        }
                        DataBase.IsChanged = true;
                    }
                }
            }
            catch (Exception e)
            {
                //TODO process possible exceptions
            }
        }