Reputation: 91
I am creating a project in witch I have to find the loudness of recorded sound.
No matter how many times I call getMaxAmplitude()
it always show 0 and by writing amplitudeDb
it always shows -infinity.
kindly help me thanks.
Here is my code.
record1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
record[0] = new MediaRecorder();
record[0].setAudioSource(MediaRecorder.AudioSource.MIC);
record[0].getMaxAmplitude();
record[0].setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
record[0].setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
record[0].setOutputFile(FilePath);
try {
record[0].prepare();
record[0].getMaxAmplitude();
} catch(IOException e) {
e.printStackTrace();
}
try {
record[0].start();
}
catch(Exception e) {
e.printStackTrace();
}
}
});
stop.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View v) {
try {
record[0].stop();
}
catch(Exception e) {
e.printStackTrace();
}
try {
int amp = record[0].getMaxAmplitude();
//String ampl = amp.toString();
int x = 1;
System.out.println("amp: " + amp);
System.out.println("hello");
//double amplitudeDb = 20 * Math.log10((double) Math.abs(amp));
ampli.setText("" + amp);
}
catch(Exception e) {
e.printStackTrace();
}
try {
record[0].release();
}
catch(Exception e) {
e.printStackTrace();
}
}
});
Upvotes: 1
Views: 238
Reputation: 91
finally i understands the logic of getMaxAmplitude() ijust have to write record[0].getMaxAmplitude() just before record[0].stop()
everything willbe okay then :)
Upvotes: 1