【发布时间】:2020-09-30 08:56:08
【问题描述】:
我的代码只是复制标题,但不会在第二个循环中改变音量。
// TODO: Copy header from the input file to the output file
uint8_t header[HEADER_SIZE];
uint8_t* header_p=malloc(HEADER_SIZE * sizeof(uint8_t));
while(fread(&header_p,sizeof(header[HEADER_SIZE]),1,input))
{
fwrite(&header_p,sizeof(header[HEADER_SIZE]),1,output);
}
// TODO: Read samples from the input file and write updated data to the output file
int16_t buffer;
while(fread(&buffer,sizeof(buffer),1,input))
{
buffer =(int16_t)(buffer*factor);
fwrite(&buffer,sizeof(buffer),1,output);
}
【问题讨论】:
-
我不知道 .wav 文件的格式,但
malloc(sizeof(uint8_t))看起来分配的字节很少(一个字节)。 -
是的,我编辑了它,但没有任何改变,问题在于第二个循环。
-
1 在十六进制编辑器中打开输出文件并检查数据是否符合您的预期。 2 手工制作示例并检查外观和工作是否符合预期。
-
你确定这个 WAV 文件是每个样本 16 位的吗?以及为什么要定义大小为
HEADER_SIZE的静态数组,然后为相同大小执行malloc- 我没有看到任何修改。您可以使用header缓冲区而不是header_p。 -
您希望在一个文件中找到多少个
HEADER元素?您在第一个循环中读取/写入整个文件,直到剩余字节小于 1 个标头。