コード例 #1
0
ファイル: AmplitudeAnalyzer.cs プロジェクト: kattex/nztronix
        /// <summary>
        /// Trims noise off of the front of the given sound data.
        /// </summary>
        /// 
        /// <remarks>
        /// This is also the first method call in the pipeline, so calling this
        /// method will continue the pipeline, cutting out the desired chunks and
        /// returning all the way back with them.
        /// </remarks>
        /// 
        /// <param name="data">The data to trim.</param>
        private List<SoundData> TrimNoise(SoundData.SoundEnumerator ie)
        {
            List<SoundData> chunks = new List<SoundData>();
              float average = 0;
              int count = 0;

              ie.MoveNext();

              do {
            Int16 level = ie.Current, abs = Math.Abs(level);

            // Eat a little first to even out the average, then start checking.
            if (count >= AVERAGE_COUNT) {
              if (abs > 5 * average && IsLeader(ie)) {
            chunks.Add(RipChunk(ie, average));
              }
            }

            // Don't let data or spikes screw up our noise muffler.
            if (count < AVERAGE_COUNT || !(abs > 5 * average)) {
              average = (average * count + abs) / ++count;
            } else {
              count++;
            }

              } while (ie.MoveNext());

              return chunks;
        }