0

苹果提供的auriotouch 2示例代码如何获取频率值。谁能帮我这个。我也想得到计算这个频率的时间。提前致谢。我已经尝试了这么多,但是如何从中获取频率值?

    [_audioRecorder stop];

NSLog(@"error :%@", [self OSStatusToStr:[self open:[self path]]]);

UInt32 N = 4096;
UInt32   log2n = 32 - CountLeadingZeroes(N - 1);
UInt32    n = 1 << log2n;
UInt32    stride = 1;
UInt32    nOver2 = n / 2;
DSPSplitComplex A;

FFTSetup setupReal ;

//    printf("1D real FFT of length log2 ( %d ) = %d\n\n", n, log2n);

/* Allocate memory for the input operands and check its availability,
 * use the vector version to get 16-byte alignment. */

A.realp = (float *) malloc(nOver2 * sizeof(float));
A.imagp = (float *) malloc(nOver2 * sizeof(float));
float   *  originalReal = (float *) malloc(n * sizeof(float));
float   *  obtainedReal = (float *) malloc(n * sizeof(float));

if (originalReal == NULL || A.realp == NULL || A.imagp == NULL) {
    printf("\nmalloc failed to allocate memory for  the real FFT"
           "section of the sample.\n");
    exit(0);
}

/* Generate an input signal in the real domain. */
for (int i = 0; i < n; i++){

    originalReal[i] = (float) (i + 1);
}

/* Look at the real signal as an interleaved complex vector  by
 * casting it.  Then call the transformation function vDSP_ctoz to
 * get a split complex vector, which for a real signal, divides into
 * an even-odd configuration. */

vDSP_ctoz((COMPLEX *) originalReal, 2, &A, 1, nOver2);

/* Set up the required memory for the FFT routines and check  its
 * availability. */

setupReal = vDSP_create_fftsetup(log2n, FFT_RADIX2);

if (setupReal == NULL) {

    printf("\nFFT_Setup failed to allocate enough memory  for"
           "the real FFT.\n");

    exit(0);
}

/* Carry out a Forward and Inverse FFT transform. */
vDSP_fft_zrip(setupReal, &A, stride, log2n, FFT_FORWARD);
vDSP_fft_zrip(setupReal, &A, stride, log2n, FFT_INVERSE);

/* Verify correctness of the results, but first scale it by  2n. */
  Float32  scale = (float) 1.0 / (2 * n);
vDSP_vsmul(A.realp, 1, &scale, A.realp, 1, nOver2);
vDSP_vsmul(A.imagp, 1, &scale, A.imagp, 1, nOver2);

/* The output signal is now in a split real form.  Use the  function
 * vDSP_ztoc to get a split real vector. */
vDSP_ztoc(&A, 1, (COMPLEX *) obtainedReal, 2, nOver2);
4

0 回答 0