안녕하세요 이제 막 어플리케이션 제작을 하는 초보자입니다..
지금 하려는게 파일을 녹음하고 그 파일을 불러와 fft 처리를 해서 일정 크기 이상의 소리를 표시하고 싶은데 들려주는 주파수와 계산상에 나오는 주파수가 달라서 여쭤봅니다... 아래 코드처럼 PCM 타입으로 AudioRecord로 녹음해서 저장되어 있는 파일을 불러와서 처리하는데 뭐가 잘못됐는지 잘 모르겠네요 ㅠㅠ
도와주시면 정말 감사하겠습니다!!
public class RecordAudio extends AsyncTask<Void, double[], Void> {
@Override
protected Void doInBackground(Void... params) {
//FileInputStream fis = null;
InputStream in = null;
BufferedInputStream bis = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] writeData = new byte[mBuffersize];
short[] buffer = new short[blockSize]; //blockSize = 256
double[] toTransform = new double[blockSize]; //blockSize = 256
//double[] dataRecord = new double[blockSize];
EditText editText = findViewById(R.id.editText_id);
mFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + editText.getText().toString() + ".pcm";
File file = new File(mFilePath);
try {
in = new FileInputStream(file);
bis = new BufferedInputStream(in);
int len = 0;
while ((len = bis.read(writeData)) >= 0) {
baos.write(writeData, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < blockSize; i++) {
buffer[i] = (short) writeData[i];
toTransform[i] = (double) buffer[i] / Short.MAX_VALUE;
}
transformer.ft(toTransform);
publishProgress(toTransform);
return null;
}
@Override
public void onProgressUpdate(double[]... toTransform) {
int count = 0;
for (int i = 0; i < toTransform[0].length; i++) {
int x = i;
double freq = (int) (x * 15.625);
//Log.d("toTransform", Double.toString(toTransform[0][i]));
if (toTransform[0][i] * 100 > 3.5) {
//Log.d("toTransform compare", Double.toString(toTransform[0][i]));
mFrequency1 = freq;
Log.d("mFrequency toTransform", String.valueOf(mFrequency1));
}
imageview.invalidate();
}
}