android中调用fft函数,J使用PCM数据在Android中转换FFT(JTransforms FFT in Android from PCM data)...
J使用PCM數據在Android中轉換FFT(JTransforms FFT in Android from PCM data)
我一直在玩這個游戲已經有一段時間了,我無法弄清楚我在這里要做的事情。
我正在將PCM音頻數據讀入一個audioData數組中:
recorder.read(audioData,0,bufferSize); //read the PCM audio data into the audioData array
我想使用Piotr Wendykier的JTransform庫,以便對我的PCM數據進行FFT預處理以獲得頻率。
import edu.emory.mathcs.jtransforms.fft.DoubleFFT_1D;
目前我有這個:
DoubleFFT_1D fft = new DoubleFFT_1D(1024); // 1024 is size of array
for (int i = 0; i < 1023; i++) {
a[i]= audioData[i];
if (audioData[i] != 0)
Log.v(TAG, "audiodata=" + audioData[i] + " fft= " + a[i]);
}
fft.complexForward(a);
我無法理解如何工作,有人可以給我一些建議嗎? 在這之后我需要進行任何計算嗎?
我確信我走了,任何事情將不勝感激!
本
I've been playing with this now for sometime, I cant work out what I am meant to be doing here.
I am reading in PCM audio data into an audioData array:
recorder.read(audioData,0,bufferSize); //read the PCM audio data into the audioData array
I want to use Piotr Wendykier's JTransform library in order to preform an FFT on my PCM data in order to obtain the frequency.
import edu.emory.mathcs.jtransforms.fft.DoubleFFT_1D;
At the moment I have this:
DoubleFFT_1D fft = new DoubleFFT_1D(1024); // 1024 is size of array
for (int i = 0; i < 1023; i++) {
a[i]= audioData[i];
if (audioData[i] != 0)
Log.v(TAG, "audiodata=" + audioData[i] + " fft= " + a[i]);
}
fft.complexForward(a);
I cant make sense of how to work this, can somebody give me some pointers? Will i have to perform any calculations after this?
I'm sure I'm way off, anything would be greatly appreciated!
Ben
原文:https://stackoverflow.com/questions/7649003
更新時間:2020-01-09 15:32
最滿意答案
如果您只是在輸入波形中查找單個正弦波音調的頻率,那么您需要找到幅度最大的FFT峰值,其中:
Magnitude = sqrt(re*re + im*im)
這個最大幅度峰值的指數i會告訴你你的正弦波的大概頻率:
Frequency = Fs * i / N
哪里:
Fs = sample rate (Hz)
i = index of peak
N = number of points in FFT (1024 in this case)
If you're just looking for the frequency of a single sinusoidal tone in the input waveform then you need to find the FFT peak with the largest magnitude, where:
Magnitude = sqrt(re*re + im*im)
The index i of this largest magnitude peak will tell you the approximate frequency of your sinusoid:
Frequency = Fs * i / N
where:
Fs = sample rate (Hz)
i = index of peak
N = number of points in FFT (1024 in this case)
2011-10-04
相關問答
你的輸入都是0。 short s = 32767;
double d = s/32768;
System.out.println("dividing a short yields a truncated result " + d);
d = (double) s / 32768;
System.out.println("casting to a double and then dividing yields " + d);
Your inputs are all 0. short s = 327
...
首先,您需要確保您獲得的結果正確轉換為float / double。 我不知道短[]版本是如何工作的,但是byte []版本只返回原始字節版本。 然后,該字節數組需要正確轉換為浮點數。 轉換代碼應該如下所示: double[] micBufferData = new double[];
final int bytesPerSample = 2; // As it is 16bit PCM
final double amplificat
...
您可以使用AudioTrack播放PCM數據! 也許是這樣的: int bufsize = AudioTrack.getMinBufferSize(44100,
AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT);
AudioTrack audio = new AudioTrack(AudioManager.STREAM_MUSIC,
...
我應該使用NDK來避免這種情況嗎? 不,你會得到與NDK相同的結果。 AudioRecord提供對原始PCM數據的訪問。 設備之間的差異發生,因為它們使用不同的音頻模塊。 這些模塊具有不同的硬件功能 (低通濾波器/靈敏度),您無法通過軟件禁用它們。 其背后的原因是這些功能可以降低噪音。 should i use NDK to avoid that? No, you will get the same results with the NDK. AudioRecord provides alread
...
您需要首先將字節數組轉換為適合您樣本的數組類型,然后反轉該數組。 例如,如果您的樣本是16位,那么您將要轉換為短數組。 或者,在16位情況下,您可以將數據保存為字節然后反向 - 但是以成對字節為單位。 public void reverse(byte[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
byte t
...
如果您只是在輸入波形中查找單個正弦波音調的頻率,那么您需要找到幅度最大的FFT峰值,其中: Magnitude = sqrt(re*re + im*im)
這個最大幅度峰值的指數i會告訴你你的正弦波的大概頻率: Frequency = Fs * i / N
哪里: Fs = sample rate (Hz)
i = index of peak
N = number of points in FFT (1024 in this case)
If you're just looking for
...
假設音頻是立體聲的,一旦你有兩個第一個字節的原始PCM對應左聲道音頻,兩個跟隨右聲道音頻,所以你可以將它們視為短路然后第一個短路代表左聲道和第二個正確的渠道。 因此,如果您想獲得左聲道數據,則必須使用輸入原始PCM進行循環并保存每一個短路。 喜歡這個: void demux(short in[], short left[], short right[], int len) {
for (int i=0; i
left[i] = in[i];
...
是的,它是原始PCM,您可以使用Android SDK掛接到PCM播放。 Yes it's raw PCM , you can hook into the PCM playback with the Android SDK.
來自android-ndk-r8b / docs / opensles / index.html PCM數據格式 PCM數據格式只能與緩沖區隊列一起使用。 所以SLDataFormat_PCM 不能像我假設的那樣與SLDataLocator_Address一起使用。 我可以使用緩沖區隊列執行我想要的操作,而不是像這樣使用一個大隊列 bufferqueueitf->Enqueue(bufferqueueitf,dataChunk,dataSize);
from android-ndk-r8b/do
...
你的問題是java中的短路是bigendian,但是如果從WAV文件中獲取數據,那么數據就是小端。 Your problem is that shorts in java are bigendian, but if you got your data from a WAV file the data is little endian.
總結
以上是生活随笔為你收集整理的android中调用fft函数,J使用PCM数据在Android中转换FFT(JTransforms FFT in Android from PCM data)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android端发送字符到Wed端,An
- 下一篇: android分钟倒计时,Android