问题是:我必须更改 WAVE 文件的 header ,准确地说,我必须更改 ChunkSize 和 SubChunk2Size。问题是这些值使用 4 个字节,但似乎使用 fwrite 我覆盖了 8 个字节:
原文:
RIFFđ WAVEfmt
编辑:
RIFF(} } fmt
代码:
FILE *nova;
nova=fopen ( "nova.wav", "wb" );
fseek ( nova, 4, SEEK_SET );
fwrite ( &brojacC,4,1,nova );
fseek ( zvuk, 44, SEEK_SET );
fwrite ( &brojacCS2,4,1,nova );
在编辑文件中 WAVE
被覆盖。出了点问题,因为我从第 4 个字节开始写了 4 个字节,而 WAVE
从第 8 个字节开始。
我希望我至少说清楚了一点。这可以通过其他方式完成吗?
最佳答案
好吧,根据我的 man fopen
输出:
r Open text file for reading. The stream is positioned at the
beginning of the file.
r+ Open for reading and writing. The stream is positioned at the
beginning of the file.
w Truncate file to zero length or create text file for writing.
The stream is positioned at the beginning of the file.
w+ Open for reading and writing. The file is created if it does
not exist, otherwise it is truncated. The stream is positioned
at the beginning of the file.
a Open for appending (writing at end of file). The file is cre‐
ated if it does not exist. The stream is positioned at the end
of the file.
a+ Open for reading and appending (writing at end of file). The
file is created if it does not exist. The initial file position
for reading is at the beginning of the file, but output is
always appended to the end of the file.
话虽如此,我肯定会选择fopen("nova.wav", "r+b")
,因为w
似乎会截断文件,并且你在写之前读,而 a
附加到文件的末尾,你想重写文件的一部分。
关于C:编辑二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8874550/