Exemplo n.º 1
0
		/**
		 * Calculates MFCC features for each frame.
		 *
		 * @param wav recording object
		 * @param options transform options
		 */
		public override void Process(WaveFile wav, TransformOptions options)
		{
			wavFilename = wav.GetFilename();
			
			int framesCount = wav.GetFramesCount();
			Array.Resize(ref featureArray, framesCount);
			
			if (m_indicator != null)
				m_indicator.Start(0, framesCount-1);
			
			int N = wav.GetSamplesPerFrameZP();
			UpdateFilters(wav.GetSampleFrequency(), N);
			
			//filters.DrawMelFiltersBank("melfilters.png");
			
			Complex[] frameSpectrum = new Complex[N];
			double[] filtersOutput = new double[Dtw.MELFILTERS];
			double[] frameMfcc = new double[m_paramsPerFrame];
			
			Transform transform = new Transform(options);
			
			// for each frame: FFT -> Mel filtration -> DCT
			for (int i = 0; i < framesCount; ++i)
			{
				transform.Fft(wav.frames[i], ref frameSpectrum);
				filters.ApplyAll(ref frameSpectrum, N, ref filtersOutput);
				transform.Dct(filtersOutput, ref frameMfcc);
				
				//featureArray[i] = frameMfcc;
				featureArray[i] = new double[frameMfcc.Length];
				frameMfcc.CopyTo(featureArray[i], 0);
				
				if (m_indicator != null)
					m_indicator.Progress(i);
			}
			
			if (m_indicator != null)
				m_indicator.Stop();
		}
Exemplo n.º 2
0
		/**
		 * Calculates power for each frame.
		 *
		 * @param wav recording object
		 * @param options transform options
		 */
		public override void Process(WaveFile wav, TransformOptions options)
		{
			wavFilename = wav.GetFilename();
			
			int framesCount = wav.GetFramesCount();
			Array.Resize(ref featureArray, framesCount);
			
			if (m_indicator != null)
				m_indicator.Start(0, framesCount-1);
			
			Transform transform = new Transform(options);
			for (int i = 0; i < framesCount; ++i)
			{
				List<double> @params = new List<double>();
				@params.Add(transform.FramePower(wav.frames[i]));
				featureArray[i] = @params.ToArray();
				
				if (m_indicator != null)
					m_indicator.Progress(i);
			}
			
			if (m_indicator != null)
				m_indicator.Stop();
		}