All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.musicg.experiment.test.Test1 Maven / Gradle / Ivy

Go to download

Musicg is a lightweight audio analysis library, written in Java, with the purpose of extracting both high level and low level audio features.

The newest version!
package com.musicg.experiment.test;

import com.musicg.graphic.GraphicRender;
import com.musicg.math.rank.ArrayRankDouble;
import com.musicg.math.statistics.SpectralCentroid;
import com.musicg.math.statistics.StandardDeviation;
import com.musicg.pitch.PitchHandler;
import com.musicg.wave.Wave;
import com.musicg.wave.extension.Spectrogram;

public class Test1 {

	public static void main(String[] args) {		
		
		String filename = "audio_work/lala.wav";

		// create a wave object
		Wave wave = new Wave(filename);

		// TimeDomainRepresentations
		int fftSampleSize=1024;
		int overlapFactor=1;
		Spectrogram spectrogram=new Spectrogram(wave,fftSampleSize,overlapFactor);
		
		int fps=spectrogram.getFramesPerSecond();
		double unitFrequency=spectrogram.getUnitFrequency();

		// set boundary
		int highPass=100;
		int lowerBoundary=(int)(highPass/unitFrequency);
		int lowPass=4000;
		int upperBoundary=(int)(lowPass/unitFrequency);
		// end set boundary
		
		double[][] spectrogramData=spectrogram.getNormalizedSpectrogramData();
		double[][] absoluteSpectrogramData=spectrogram.getAbsoluteSpectrogramData();
		double[][] boundedSpectrogramData=new double[spectrogramData.length][];
		
		SpectralCentroid sc=new SpectralCentroid();
		StandardDeviation sd=new StandardDeviation();		
		ArrayRankDouble arrayRankDouble=new ArrayRankDouble();
		
		// zrc
		short[] amps=wave.getSampleAmplitudes();
		int numFrame=amps.length/1024;
		double[] zcrs=new double[numFrame];
		
		for (int i=0; i=0 && temp[j+1]<0) || (temp[j]<0 && temp[j+1]>=0)){
					numZC++;
				}
			}	
			
			zcrs[i]=numZC;
		}
		
		// end zcr
		
		for (int i=0; i=nthValue){
						robustFrequencies[count++]=b*unitFrequency;
						if (count>=numRobust){
							break;
						}
					}
				}
				
				double passIntensity=1000;
				double intensity=0;
				for (int i=0; ipassIntensity && maxFrequency>passFrequency){				
					double p=ph.getHarmonicProbability(robustFrequencies);				
					System.out.print(" P: "+p);
				}
			}
			System.out.print(" zcr:"+zcrs[frame]);
			System.out.println();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy