I am trying to record a race bike's sound and analyse the recorded audio with FFT and find the engines frequency. If i only whistle, everything works fine, i can see a clear graph which corresponds to my whistling low and high and so on. I create a heatmap with different colors for the different amplitudes i get from the FFT for frequency vs time. The Audio gets recorded like this:
private class RecordAudio extends AsyncTask<Void, float[], Void> {
@Override
protected Void doInBackground(Void... params) {
try {
int bufferSize = AudioRecord.getMinBufferSize(sampleRateMain,
channelConfiguration, audioEncoding);
AudioRecord audioRecord = new AudioRecord(
MediaRecorder.AudioSource.DEFAULT, sampleRateMain,
channelConfiguration, audioEncoding, bufferSize);
short[] buffer = new short[blockSize];
audioRecord.startRecording();
float[] audioData = new float[blockSize];
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String currentDateandTime = sdf.format(new Date());
BufferedWriter writer;
String pathtemp = Environment.getExternalStorageDirectory().getAbsolutePath();
String filename ="/"+currentDateandTime;
path = pathtemp +filename;
writer = new BufferedWriter (new FileWriter(path,false));
int i2=0;
while (started) {
if(i2==10){
datastructures tempdata = new datastructures();
i2=0;
audioRecord.read(buffer, 0, blockSize);
float sum = 0;
for (int i = 0; i < blockSize; i++) {
audioData[i] = (float) ( buffer[i]);
writer.write(audioData[i]+" ");
if (audioData[i] <= 0) {
audioData[i] = audioData[i] * (-1);
}
sum = sum + audioData[i];
}
writer.newLine();
tempdata.freqsum = sum;
mainData.add(tempdata);
}
i2++;
}
writer.close();
}
catch(IOException e){
e.printStackTrace();
}
audioRecord.stop();
} catch (Throwable t) {
Log.e(TAG, "Audio recording Failed");
}
return null;
}
}
So i am storing the audiodata on the sd-card. To reduce the data i loop through i2 and only record once in i2=0...10; In the next part of the app i let the user cut out a part of the audiodata and load only this part in a vector called trimmed. I then do a FFT of those frequencies. But it seems like there is only overdrive in the data.
Is it possible to trigger the automatic gain for the microphone while recording ?
How would i load the recorded and saved audiodata into Audacity ? (I tried different import setting for raw data but it doesnt seem to work) Here is an example file
I implemented a butterworth filter, if i got this right the filter should be applied before the FFT ?