我应该从getFft看到什么样的输出? [英] What kind of output should I see from getFft?

查看:160
本文介绍了我应该从getFft看到什么样的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我的工作创造一个Android音频可视化应用程序。问题是,我所得到的形成方法getFft()没有什么谷歌表示,它应该产生摇摆。我跟踪源$ C ​​$ C一路回C ++,但我不是用C足够熟悉++或FFT真正明白发生了什么。

Alright, so I am working on creating an Android audio visualization app. The problem is, what I get form the method getFft() doesn't jive with what google says it should produce. I traced the source code all the way back to C++, but I am not familiar enough with C++ or FFT to actually understand what is happening.

我会尝试,包括在这里所需要的一切:

I will try and include everything needed here:

<一个href=\"http://www.google.com/$c$csearch/p?hl=en#uX1GffpyOZk/media/java/android/media/audiofx/Visualizer.java\"相对=nofollow> (Java)的Visualizer.getFft(字节[] FFT)

 /**
 * Returns a frequency capture of currently playing audio content. The capture is a 8-bit
 * magnitude FFT. Note that the size of the FFT is half of the specified capture size but both
 * sides of the spectrum are returned yielding in a number of bytes equal to the capture size.
 * {@see #getCaptureSize()}.
 * <p>This method must be called when the Visualizer is enabled.
 * @param fft array of bytes where the FFT should be returned
 * @return {@link #SUCCESS} in case of success,
 * {@link #ERROR_NO_MEMORY}, {@link #ERROR_INVALID_OPERATION} or {@link #ERROR_DEAD_OBJECT}
 * in case of failure.
 * @throws IllegalStateException
 */
public int getFft(byte[] fft)
throws IllegalStateException {
    synchronized (mStateLock) {
        if (mState != STATE_ENABLED) {
            throw(new IllegalStateException("getFft() called in wrong state: "+mState));
        }
        return native_getFft(fft);
    }
}

(C ++ )Visualizer.getFft(uint8_t有* FFT)

status_t Visualizer::getFft(uint8_t *fft)
{
if (fft == NULL) {
    return BAD_VALUE;
}
if (mCaptureSize == 0) {
    return NO_INIT;
}

status_t status = NO_ERROR;
if (mEnabled) {
    uint8_t buf[mCaptureSize];
    status = getWaveForm(buf);
    if (status == NO_ERROR) {
        status = doFft(fft, buf);
    }
} else {
    memset(fft, 0, mCaptureSize);
}
return status;
}

(C ++ )Visualizer.doFft(uint8_t有* FFT,uint8_t有*波形)

status_t Visualizer::doFft(uint8_t *fft, uint8_t *waveform)
{
int32_t workspace[mCaptureSize >> 1];
int32_t nonzero = 0;

for (uint32_t i = 0; i < mCaptureSize; i += 2) {
    workspace[i >> 1] = (waveform[i] ^ 0x80) << 23;
    workspace[i >> 1] |= (waveform[i + 1] ^ 0x80) << 7;
    nonzero |= workspace[i >> 1];
}

if (nonzero) {
    fixed_fft_real(mCaptureSize >> 1, workspace);
}

for (uint32_t i = 0; i < mCaptureSize; i += 2) {
    fft[i] = workspace[i >> 1] >> 23;
    fft[i + 1] = workspace[i >> 1] >> 7;
}

return NO_ERROR;
}

(C ++ )fixedfft.fixed_fft_real(INT N,int32_t * v)

void fixed_fft_real(int n, int32_t *v)
{
int scale = LOG_FFT_SIZE, m = n >> 1, i;

fixed_fft(n, v);
for (i = 1; i <= n; i <<= 1, --scale);
v[0] = mult(~v[0], 0x80008000);
v[m] = half(v[m]);

for (i = 1; i < n >> 1; ++i) {
    int32_t x = half(v[i]);
    int32_t z = half(v[n - i]);
    int32_t y = z - (x ^ 0xFFFF);
    x = half(x + (z ^ 0xFFFF));
    y = mult(y, twiddle[i << scale]);
    v[i] = x - y;
    v[n - i] = (x + y) ^ 0xFFFF;
}
}

(C ++ )fixedfft.fixed_fft(INT N,int32_t * v)

void fixed_fft(int n, int32_t *v)
{
int scale = LOG_FFT_SIZE, i, p, r;

for (r = 0, i = 1; i < n; ++i) {
    for (p = n; !(p & r); p >>= 1, r ^= p);
    if (i < r) {
        int32_t t = v[i];
        v[i] = v[r];
        v[r] = t;
    }
}

for (p = 1; p < n; p <<= 1) {
    --scale;

    for (i = 0; i < n; i += p << 1) {
        int32_t x = half(v[i]);
        int32_t y = half(v[i + p]);
        v[i] = x + y;
        v[i + p] = x - y;
    }

    for (r = 1; r < p; ++r) {
        int32_t w = MAX_FFT_SIZE / 4 - (r << scale);
        i = w >> 31;
        w = twiddle[(w ^ i) - i] ^ (i << 16);
        for (i = r; i < n; i += p << 1) {
            int32_t x = half(v[i]);
            int32_t y = mult(w, v[i + p]);
            v[i] = x - y;
            v[i + p] = x + y;
        }
    }
}
}

如果您通过所有的成功了,你是真棒!所以我的问题是,当我调用Java方法getFft()我结束了负值,如果返回的数组是为了重新present幅度应该不存在。所以我的问题是,什么,我需要做的,使阵列重新present幅度?

If you made it through all that, you are awesome! So my issue, is when I call the java method getFft() I end up with negative values, which shouldn't exist if the returned array is meant to represent magnitude. So my question is, what do I need to do to make the array represent magnitude?

编辑:看来我的数据,实际上可能是傅里叶系数。我被戳各地的网络,发现这个。小程序启动功能FFT显示系数的重新绘制presentation,这是当我从图表的getFft数据会发生什么活脱()。因此,新的问题:这是我的数据是什么?如果是这样,我怎么从系数到它的频谱分析?

It appears my data may actually be the Fourier coefficients. I was poking around the web and found this. The applet "Start Function FFT" displays a graphed representation of coefficients and it is a spitting image of what happens when I graph the data from getFft(). So new question: Is this what my data is? and if so, how do I go from the coefficients to a spectral analysis of it?

推荐答案

这是FFT不只是生​​产规模;它产生相以及(输出每个样品是复数)。如果你想要的大小,那么你需要明确地计算它为每个输出样本,如重*重+ IM * IM ,其中重新即时消息均为复数的实部和虚部,分别为。

An FFT doesn't just produce magnitude; it produces phase as well (the output for each sample is a complex number). If you want magnitude, then you need to explicitly calculate it for each output sample, as re*re + im*im, where re and im are the real and imaginary components of each complex number, respectively.


不幸的是,我不能看到你的code在您使用复数工作在任何地方,因此,或许还需要一些重写。

更新

如果我猜的话(在code一眼之后),我会说,真正的成分是在偶数索引和奇数组分在奇数索引。因此,要获得大小,你需要做的是这样的:

If I had to guess (after glancing at the code), I'd say that real components were at even indices, and odd components were at odd indices. So to get magnitudes, you'd need to do something like:

uint32_t mag[N/2];
for (int i = 0; i < N/2; i++)
{
    mag[i] = fft[2*i]*fft[2*i] + fft[2*i+1]*fft[2*i+1];
}

这篇关于我应该从getFft看到什么样的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆