이제 저는 하나의 오디오 신호 처리를하고 있으며, 전화기로 녹음 한 오디오 사운드 웨이브를 실시간으로 표시하려고합니다.짧은 []을 이중 []으로 변환하려면 어떻게해야합니까?
내 오디오 형식이 "ENCODING_PCM_16BIT"인 문제가 있습니다. 그렇다면 16 비트 short 데이터를 double 형식으로 어떻게 바꿀 수 있습니까?
여기 내 코드이지만 제대로 작동하지 않습니다. 아무도 내가이 문제를 해결하도록 도울 수 있습니까?
try {
AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, Sample_rate, Channel, Encording,
Buffersize);
DataOutputStream dos = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(MainActivity.file)));
short[] buffer = new short[Buffersize/2]; //870 double/ 2 = 435 double
System.out.println("The buffer size is " + Buffersize);
timer1();
audioRecord.startRecording(); // Start record
while (MainActivity.isrecord) {
int bufferReadResult = audioRecord.read(buffer, 0, buffer.length);
System.out.println("The buffer size is " + bufferReadResult);
for (int i = 0; i < bufferReadResult/2; i++) {
dos.writeShort(buffer[i]);
**tempraw[i] = (double)buffer[i];**
}
phase = DataProcess(tempraw);
}
audioRecord.stop(); // record stop
audioRecord.release();
audioRecord = null;
dos.close(); // Output stream close
dos = null;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
내가
감사합니다 "를 더블 [] tempraw"로 "[] 버퍼 짧은"에서 그 데이터를 넣고 싶다!
인터넷에서 일부 코드를 본 후에이 코드를 만들었습니다. 내가 그냥 더블 배열 int 배열처럼 더블
private static double shorttodouble(short[] a, int index) {
// TODO Auto-generated method stub
long l;
l = a[index + 0];
l &= 0xffff;
l |= ((long) a[index + 1] << 16);
l &= 0xffffffffl;
l |= ((long) a[index + 2] << 32);
l &= 0xffffffffffffl;
l |= ((long) a[index + 3] << 48);
l &= 0xffffffffffffffffl;
l |= ((long) a[index + 4] << 64);
return (double)l;
}
'...하지만이 일이 ... 제대로 아니다'정확히 무슨 제대로 작동하지 않는 이유는 무엇입니까? –
나는 짧은 [] 문자를 가지고 있으며 길이는 짧다. 그리고 짧은 네 자리마다 이중 값으로 변환됩니다. 그러나, 내 코드에서 사용되는 방식을 사용하면 단 두 개의 짧은 형식이 이중 형식으로 바뀝니다. 그건 맞지 않아. 나는 그것이 "짧은 [] 버퍼 = 새 짧은 [Buffersize/2], 이중 [] tempraw = 새로운 이중 [Buffersize/2/4]와 같은 초기화 짧은 배열 때문에 배운다. 그리고 일식은 "outofboundsexception"이라고 말합니다 – MarvinC
질문을 편집하고이 모든 것을 설명해야합니다. 먼저 알고리즘 설명과 구현 방법을 보여줍니다. 그런 다음 예외 세부 정보 (메시지, 스택 추적, 원본)를 게시합니다. 그런데 예외 메시지에 대해 Google에 시도해보십시오. 아마 당신은 스스로 알아낼 수 있습니다. –