- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 KissFFT Library与 this 11 second 44kHz .wav sample file作为测试输入。
然而,当我处理窗口大小为 512 的文件时,我只得到 1 个输出值。这很奇怪,44kHz 的 11 秒 .wav 文件不应该给出 1 个值作为窗口大小为 512 的输出。像 16 这样的较小窗口会给我 5 个值,这仍然是一个低计数。
有人知道我做错了什么吗?
这是我的代码:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <math.h>
#include "kiss_fft.h"
#define WIN 512
int main()
{
char *music_file = "C:/MSin44W16-13.wav";
FILE *in;
char buf[WIN * 2];
int nfft = WIN, i, fx;
double intensity = 0;
kiss_fft_cfg cfg;
kiss_fft_cpx cx_in[WIN];
kiss_fft_cpx cx_out[WIN];
short *sh;
cfg = kiss_fft_alloc(nfft, 0, 0, 0);
in = fopen(music_file, "r");
if (!in) {
printf("unable to open file: %s\n", music_file);
perror("Error");
return 1;
}
fx = 0;
while (fread(buf, 1, WIN * 2, in))
{
for (i = 0;i<WIN;i++) {
sh = (short *)&buf[i * 2];
cx_in[i].r = (float) (((double)*sh) / 32768.0);
cx_in[i].i = 0.0;
}
kiss_fft(cfg, cx_in, cx_out);
//Display the value of a position
int position = 511;
intensity = sqrt(pow(cx_out[position].r, 2) + pow(cx_out[position].i, 2));
printf("%9.4f\n", intensity);
//Display all values
/*
for (i = 0;i<WIN;i++) {
//printf("Joe: cx_out[i].r:%f\n", cx_out[i].r);
//printf("Joe: cx_out[i].i:%f\n", cx_out[i].i);
intensity = sqrt(pow(cx_out[i].r,2) + pow(cx_out[i].i,2));
printf("%d - %9.4f\n", i, intensity);
}
*/
}
free(cfg);
scanf("%d");
return 0;
}
这是我得到的输出:
42.7577
这是更新后的代码版本,但我在编译时遇到错误:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <math.h>
#include "kiss_fft.h"
#include "sndfile.h"
#define WIN 512
int main()
{
char *music_file = "C:/voice.wav";
SNDFILE *infile;
SF_INFO sfinfo;
//int readcount;
short buf[WIN * 2];
int nfft = WIN;
double intensity = 0;
kiss_fft_cfg cfg;
kiss_fft_cpx cx_in[WIN];
kiss_fft_cpx cx_out[WIN];
short *sh;
cfg = kiss_fft_alloc(nfft, 0, 0, 0);
if (!( infile = sf_open(music_file, SFM_READ, &sfinfo) ))
{ /* Open failed so print an error message. */
printf("Not able to open input file %s.\n", "input.wav");
/* Print the error message fron libsndfile. */
sf_perror(NULL);
return 1;
}
while ((sf_read_short(infile, buf, WIN)))//fread(buf, 1, WIN * 2, in)
{
//system("cls");
for (int i = 0;i<WIN;i++) {
sh = (short *)&buf[i * 2];
cx_in[i].r = (float) (((double)*sh) / 32768.0);
cx_in[i].i = 0.0;
}
kiss_fft(cfg, cx_in, cx_out);
//Display the value of a position
int position = 511;
intensity = sqrt(pow(cx_out[position].r, 2) + pow(cx_out[position].i, 2));
printf("%9.4f\n", intensity);
//Display all values
/*
for (i = 0;i<WIN;i++) {
//printf("Joe: cx_out[i].r:%f\n", cx_out[i].r);
//printf("Joe: cx_out[i].i:%f\n", cx_out[i].i);
intensity = sqrt(pow(cx_out[i].r,2) + pow(cx_out[i].i,2));
printf("%d - %9.4f\n", i, intensity);
}
*/
}
sf_close(infile);
free(cfg);
int temp;
scanf_s("%d", &temp);
return 0;
}
我按照这篇文章中的步骤操作:
"error LNK2019: unresolved external symbol" error in Visual Studio 2010
我仍然遇到这些错误:
最佳答案
问题不是来自 KissFFT,而是因为您正在尝试读取以 ASCII 模式打开的 binary wave 文件:
in = fopen(music_file, "r");
当您稍后尝试使用 fread
读取数据时,您最终遇到了一个无效字符。在您的特定示例文件中,读取的第 215th 个字符是 Substitute Character (hex value 0x1A
) ,它被 C 运行时库解释为文件结束标记。相应地,fread
停止填充更多数据并最终返回 0(在 WIN
设置为 512 的第二次迭代中,稍后将 WIN
设置为 16)。
要解决这个问题,您应该以二进制方式打开文件:
in = fopen(music_file, "rb");
请注意,这将确保二进制数据按原样读入您的输入缓冲区,但不会为您解码 wave 文件头。要正确读取和解码波形文件并获取有意义的数据,您应该考虑使用音频库(例如 libsndfile 等等)。如果你必须推出自己的 wave 文件阅读器,你应该阅读 specifications和/或查看有关该主题的许多教程之一。
关于c - 在波形文件上使用 KissFFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35735803/
我正在尝试使用 KissFFT Library与 this 11 second 44kHz .wav sample file作为测试输入。 然而,当我处理窗口大小为 512 的文件时,我只得到 1 个
我在编译和链接“开箱即用”的 kissfft 库时遇到了新问题。我已经下载了 kissfft 库并将其解压缩到测试目录。进入目录并运行“make testall”后,我收到以下错误,看起来 std c
我在编译和链接“开箱即用”的 kissfft 库时遇到了新问题。我已经下载了 kissfft 库并将其解压缩到测试目录。进入目录并运行“make testall”后,我收到以下错误,看起来 std c
我想在真实的音频设备上应用 FFT 并从中计算峰值 这是我的代码.. N=8192 kiss_fft_cpx out[N/2 +1]; int len = fft->N / 2
我们已经编译了 KissFFT 库,它似乎运行良好,但我们不确定如何使用它来获取二维图像的频域。任何帮助都会很棒。 附言。我们在 After Effects SDK 中运行它。 最佳答案 我还没有将
尝试让 KissFFT 定点实现与 DSPIC 保持一致。问题是 Kiss 中的定点实现是真正的定点,但 dspic 在 40 位寄存器中进行乘法和求和,然后在舍入后向下移动到 16 位。 KissF
目前我正在开发 Tizen IDE。 我已经从麦克风读取输入数据并尝试对其应用 FFT...但每次我从 FFT 得到 nan 输出。 这是我的代码.. ShortBuffer *pBuffer1 =
我正在尝试在 Java 应用程序中原生使用 KissFFT,但输入信号的正向/反向没有按预期返回:信号幅度几乎不存在。如果我去掉比例因子(除以 2N),结果就是谐波噪声。谁能发现这个错误? 这是前向调
我正在通过包含 320 个样本的数据包中的套接字连接接收 PCM 数据。声音采样率为每秒 8000 个样本。我正在用它做这样的事情: int size = 160 * 2;//160; int isi
我在理解如何正确使用 KissFFT (1.2.9) 时遇到一些问题。我现在想要实现的是执行 FFT,然后立即执行 iFFT 以再次重建原始信号。下面的代码片段演示了我在做什么: void test(
我想在 C++ 项目中使用 kissFFT std::vector轻松处理任意长度的信号。为此,我编辑了 this SO answer来自 kissFFT 的作者。我换了 std::complex x
真正的逆 FFT 给我一个充满 NaN 而不是 floats 的数组。 kiss_fftri(conf,complex_array,output); complex_array 是正常的,我猜值没有问
我正在正确获取图像的 2d-fft,但没有从同一图像的 2d-fft 中得到 的倒数。 从同一图像的 2d-fft 获取逆的正确调用是什么??? // for 2d-fft. This I am ge
我正在尝试在 BeagleBone Black 上使用 KissFFT,运行 Debian 7.5 和 3.8 内核。当我尝试运行该程序时,该程序已编译,但显示错误 Real FFT optimiza
我有一个项目使用 FFTW 的 fftw_plan_dft_r2c_1d 和 fftw_plan_dft_c2r_1d,以及 fftw_execute。 KissFFT 中有哪些等效函数? 最佳答案
我正在使用 KissFFT 的真实函数来转换一些真实的音频信号。我很困惑,因为我输入了带有 nfft 样本的真实信号,但结果是 nfft/2+1 复杂 频率仓。 来自 KissFFT 的自述文件: 真
我是一名优秀的程序员,十分优秀!