Android Open Source - renderScriptFFT Mel Math






From Project

Back to project page renderScriptFFT.

License

The source code is released under:

Copyright (c) 2013 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided...

If you think the Android project renderScriptFFT listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.android.rs.utils;
/*from www  . j a  va2s  .  c om*/
import org.apache.commons.math3.linear.DefaultRealMatrixPreservingVisitor;
import org.apache.commons.math3.linear.MatrixUtils;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.util.FastMath;

public class MelMath {
  private final static double k = 1000.0/FastMath.log(1.0 + 1000.0 / 700.0);
  
  private MelMath(){}
    
  public static RealMatrix doubleAllExceptDCandNyquist(RealMatrix v, final RealMatrix c, final double mn, final double n, final double fn2){
    final RealMatrix out = MatrixUtils.createRealMatrix(v.getRowDimension(), v.getColumnDimension());
        DefaultRealMatrixPreservingVisitor mv = new DefaultRealMatrixPreservingVisitor(){
      @Override
      public void visit(int row, int col, double vval) {
        final double cval =  c.getEntry(row, col);
        if (cval + mn > 0 & (cval + mn < n - fn2)){
                out.setEntry(row, col, vval*2.0);
              } else {
                out.setEntry(row, col, vval);
              }
              
      }
        };
        
        v.walkInOptimizedOrder(mv);
    return out;  
  }
  
  public static RealMatrix frq2mel(RealMatrix frq){
    final RealMatrix mel = MatrixUtils.createRealMatrix(frq.getRowDimension(), frq.getColumnDimension());
        DefaultRealMatrixPreservingVisitor mv = new DefaultRealMatrixPreservingVisitor(){
      @Override
      public void visit(int row, int col, double curFrq) {
              final double aF = FastMath.abs(curFrq);
              mel.setEntry(row, col, FastMath.signum(curFrq)*Math.log(1.0+aF/700.0)*k);
      }
        };
        
        frq.walkInOptimizedOrder(mv);
    return mel;  
  }
  
  public static RealMatrix mel2frq(RealMatrix mel){  
    final RealMatrix frq = MatrixUtils.createRealMatrix(mel.getRowDimension(), mel.getColumnDimension());
    DefaultRealMatrixPreservingVisitor mv = new DefaultRealMatrixPreservingVisitor(){
      @Override
      public void visit(int row, int col, double curMel) {
              final double aM = FastMath.abs(curMel);
              frq.setEntry(row, col, 700.0 * FastMath.signum(curMel) * (Math.exp( aM/k ) - 1.0));
      }
        };
        
        mel.walkInOptimizedOrder(mv);
    return frq;  
  }
}




Java Source Code List

com.android.rs.MainActivity.java
com.android.rs.Mel_Test_MicroBench.java
com.android.rs.Mel_Test_Microphone.java
com.android.rs.Mel_Test.java
com.android.rs.mel.DCT.java
com.android.rs.mel.HammingFilter.java
com.android.rs.mel.MelFilterbank.java
com.android.rs.utils.ArrayConversion.java
com.android.rs.utils.MatrixMath.java
com.android.rs.utils.MelMath.java