/// <summary> /// Computes a Scms model from the MFCC representation of a song. /// </summary> /// <param name="mfcc">Comirva.Audio.Util.Maths.Matrix mfcc</param> /// <returns></returns> public static Scms GetScmsNoInverse(Comirva.Audio.Util.Maths.Matrix mfccs, string name) { DbgTimer t = new DbgTimer(); t.Start(); Comirva.Audio.Util.Maths.Matrix mean = mfccs.Mean(2); #if DEBUG if (Analyzer.DEBUG_INFO_VERBOSE) { if (Analyzer.DEBUG_OUTPUT_TEXT) { mean.WriteText(name + "_mean.txt"); } mean.DrawMatrixGraph(name + "_mean.png"); } #endif // Covariance Comirva.Audio.Util.Maths.Matrix covarMatrix = mfccs.Cov(mean); #if DEBUG if (Analyzer.DEBUG_INFO_VERBOSE) { if (Analyzer.DEBUG_OUTPUT_TEXT) { covarMatrix.WriteText(name + "_covariance.txt"); } covarMatrix.DrawMatrixGraph(name + "_covariance.png"); } #endif Comirva.Audio.Util.Maths.Matrix covarMatrixInv = new Comirva.Audio.Util.Maths.Matrix(covarMatrix.Rows, covarMatrix.Columns); // Store the Mean, Covariance, Inverse Covariance in an optimal format. int dim = mean.Rows; Scms s = new Scms(dim); int l = 0; for (int i = 0; i < dim; i++) { s.mean[i] = (float)mean.MatrixData[i][0]; for (int j = i; j < dim; j++) { s.cov[l] = (float)covarMatrix.MatrixData[i][j]; s.icov[l] = (float)covarMatrixInv.MatrixData[i][j]; l++; } } Dbg.WriteLine("GetScmsNoInverse - Execution Time: {0} ms", t.Stop().TotalMilliseconds); return(s); }
public AudioFeature Calculate(double[] input) { //pack the mfccs into a pointlist double[][] mfccCoefficients = mfcc.Process(input); //check if element 0 exists if(mfccCoefficients.Length == 0) throw new ArgumentException("The input stream is to short to process;"); //create mfcc matrix Matrix mfccs = new Matrix(mfccCoefficients); #if DEBUG mfccs.WriteText("mfccdata-mandelellis.txt"); mfccs.DrawMatrixGraph("mfccdata-mandelellis.png"); #endif // compute mean //Matrix mean = mfccs.Mean(1).Transpose(); Matrix mean = mfccs.Mean(2); #if DEBUG mean.WriteText("mean-mandelellis.txt"); mean.DrawMatrixGraph("mean-mandelellis.png"); #endif // create covariance matrix Matrix covarMatrix = mfccs.Cov(); #if DEBUG covarMatrix.WriteText("covariance-mandelellis.txt"); covarMatrix.DrawMatrixGraph("covariance-mandelellis.png"); #endif // Inverse Covariance Matrix covarMatrixInv; try { //covarMatrixInv = covarMatrix.Inverse(); covarMatrixInv = covarMatrix.InverseGausJordan(); } catch (Exception) { Console.Error.WriteLine("Mandel Ellis Extraction Failed!"); return null; } #if DEBUG covarMatrixInv.WriteText("inverse_covariance-mandelellis.txt"); covarMatrixInv.DrawMatrixGraph("inverse_covariance-mandelellis.png"); #endif MandelEllis.GmmMe gmmMe = new MandelEllis.GmmMe(mean, covarMatrix, covarMatrixInv); MandelEllis mandelEllis = new MandelEllis(gmmMe); return mandelEllis; }
/// <summary> /// Computes a Scms model from the MFCC representation of a song. /// </summary> /// <param name="mfcc">Comirva.Audio.Util.Maths.Matrix mfcc</param> /// <returns></returns> public static Scms GetScms(Comirva.Audio.Util.Maths.Matrix mfccs, string name) { DbgTimer t = new DbgTimer(); t.Start(); Comirva.Audio.Util.Maths.Matrix mean = mfccs.Mean(2); #if DEBUG if (Analyzer.DEBUG_INFO_VERBOSE) { if (Analyzer.DEBUG_OUTPUT_TEXT) { mean.WriteText(name + "_mean.txt"); } mean.DrawMatrixGraph(name + "_mean.png"); } #endif // Covariance Comirva.Audio.Util.Maths.Matrix covarMatrix = mfccs.Cov(mean); #if DEBUG if (Analyzer.DEBUG_INFO_VERBOSE) { if (Analyzer.DEBUG_OUTPUT_TEXT) { covarMatrix.WriteText(name + "_covariance.txt"); } covarMatrix.DrawMatrixGraph(name + "_covariance.png"); } #endif // Inverse Covariance Comirva.Audio.Util.Maths.Matrix covarMatrixInv; try { covarMatrixInv = covarMatrix.InverseGausJordan(); } catch (Exception) { Dbg.WriteLine("MatrixSingularException - Scms failed!"); return(null); } #if DEBUG if (Analyzer.DEBUG_INFO_VERBOSE) { if (Analyzer.DEBUG_OUTPUT_TEXT) { covarMatrixInv.WriteAscii(name + "_inverse_covariance.ascii"); } covarMatrixInv.DrawMatrixGraph(name + "_inverse_covariance.png"); } #endif // Store the Mean, Covariance, Inverse Covariance in an optimal format. int dim = mean.Rows; Scms s = new Scms(dim); int l = 0; for (int i = 0; i < dim; i++) { s.mean[i] = (float)mean.MatrixData[i][0]; for (int j = i; j < dim; j++) { s.cov[l] = (float)covarMatrix.MatrixData[i][j]; s.icov[l] = (float)covarMatrixInv.MatrixData[i][j]; l++; } } Dbg.WriteLine("Compute Scms - Execution Time: {0} ms", t.Stop().TotalMilliseconds); return(s); }