- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚开始用 C 语言编程。我正在尝试编写一段代码,能够分析 wav 音频文件中的值并将它们写入数组 buf[num_samples]
; num_samples
通过读取音频文件头中包含的信息来定义(它被定义为 uint32_t
变量,因为音频文件可能包含大量样本)。我找到了这段代码:
uint16_t buf[num_samples];
// Open WAV file with FFmpeg and read raw samples via the pipe.
FILE *pipe = popen("ffmpeg -i 45s.wav -f s16le -ac 1 -", "r");
// check on the pipe work
if ((pipe = popen("ffmpeg -i 45s.wav -f s16le -ac 1 -", "r"))==NULL) {
perror("ERROR\n");
}
fread(buf, 2, num_samples, pipe);
pclose(pipe);
其中 fread()
的第二个参数是 2(指字节),因为我使用的是与参数 Bit_per_sample = 16
配合使用的记录器.
但是存在问题,实际上数组中充满了“不合逻辑的值”:我期望代表波形的值(或多或少它们应该属于区间 [-20,000; 32,767]
)。
为了验证数组的正确填充,我添加了一个带有 %d
的 printf的buf[i]
在 i=0
的循环中至i=num_samples-1
。下面是我从输出中获得的一些值:
64947 65002 65046 65080 65110 65150 65188 65236
65264 65306 65338 65378 65434 65472 65517 8
81 128 168 206 241 268 306 322
424 458 497 520 543 566 586 622
676 699 728 745 765 796 825 840
917 950 970 996 1018 1040 1064 1072
1106 1128
有人可以帮助我或给我一些有用的建议吗?
预先感谢您,希望我没有浪费您的时间。
最佳答案
您的类型错误,您使用 uint16_t
作为无符号类型,并期望有符号值在 [-20,000; 之间32,767]
。
将 buf 声明为 int16_t buf[num_samples];
,因此缓冲区被声明为 2 个(有符号)字节的元素。
另外,打开并检查管道使用情况
FILE *pipe;
if ((pipe = popen("ffmpeg -i 45s.wav -f s16le -ac 1 -", "r"))==NULL) {
perror("ERROR\n");
exit(1);
}
关于c - 使用 fread() 填充数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45840865/
我有以下代码: int main() { char* pedal[20]; char* pedal2[20]; for (int i = 0; i < 20; i++)
我想用 in.wav 文件中的数据填充 hdr (结构)变量,并且我想复制 in 的前 64 个字节。 wav 文件转换为另一个文件 (out.wav)。 但是!当第二次使用fread()时,它开始从
我有一个由 1and1 托管的网站 - 他们没用!由于某种原因,他们提供的备份脚本不再有效,他们无法为我提供答案!所以我想我会自己写,这是我的代码: if (file_exists('backup
我正在尝试从文件中读取并将其复制到另一个文件。我正在网上查看一些代码,我似乎注意到有些人以这种方式声明 fread: fread (buffer, 1, 1000, src) 一些这样 fread (
当我是“男人的恐惧”时,我得到了: RETURN VALUE fread() and fwrite() return the number of items successfully read or
从文件中读取整数值时,覆盖率检查给出以下错误 调用函数“fread”会污染参数“readval” //coverity note: Calling function "fread" taints ar
为了更清楚地说明这一点,我将放置代码示例: $file = fopen('filename.ext', 'rb'); // Assume $pos has been declared // metho
尝试转换此 matlab 代码: fid = fopen([fpath, '/file.bin'],'rb'); content = fread(fid, 11,'single'); 我当前的尝试如下
假设我有: FILE* fp = fopen("myfile.bin", "r"); char something[30]; fread(something,sizeof(char)*30,1,fp)
fwrite 一个整数取决于字节序,但是有没有一种方法可以将一个整数 0x00000004 写入一个文件,这样无论它运行在什么机器上,它都可以始终被读取为 0x00000004。 一个想法是始终按照特
所以我尝试将此类 Matlab 代码转换为 C++: ss = 'file.mask' fp = fopen(ss, 'rb'); sx = fread(fp, 1, 'int32') sy = f
使用 C,可以使用函数 fread 来读取以 null 结尾的字符串吗? 我必须读取一个以 ip 开头的文件,该文件是 4 个无符号字符,后跟一个描述空终止字符串数的整数。之后,我需要读取字符串,直到
> fread('col1,col2\n') Empty data.table (0 rows) of 2 cols: col1,col2 > fread('col1,col2\n5,4') c
我正在尝试使用 data.table 将文件读入 R/fread .一些字段有前导零,我只想将数据作为字符读取并手动修复它们。但是我不知道如何将其传达给 fread .我正在尝试这个,它像往常一样分配
fread来自 data.table包一般可以在读取文件时自动确定列分隔符( sep )。 例如,这里fread自动检测 |作为列分隔符: library(data.table) fread(past
使用 fread,如何读取包含行名和列名的 CSV 文件。 我尝试了以下操作,但它没有正确读取行和列名称。 csv 文件看起来像(其中 C1、C2、C3 是列名,r1、r2、r3 是行名) input
我遇到了这样的文件: COL1 COL2 COL3 weqw asrg qerhqetjw weweg ethweth
我正在尝试使用 fread 读取表格。 txt 文件具有如下所示的文本: "No","Comment","Type" "0","he said:"wonderful|"","A" "1","Pr/ "
我正在尝试使用从 Apple 移动性报告生成的 csv,可以找到 here . 现在一切正常,我能够按预期获得 .csv,它看起来像这样的文字: csvtxt <- "geo_type,region,
我在 data.table (1.8.8, R 3.0.1) 中使用 fread 试图读取非常大的文件。 有问题的文件有 313 行和约 660 万列数字数据行,文件大小约为 12GB。这是具有 51
我是一名优秀的程序员,十分优秀!