你怎么
- 以二进制模式读取 16 位立体声原始音频文件
- 将其值转换为右侧和左侧的整数。
- 将这些整数保存回一个新的 16 位立体声原始音频文件。
最后两个文件应该是相同的,用我的代码,它们不是。为什么?
我的代码:
char ergebnis[80];
sprintf(ergebnis,"%s.neu.raw",Datei);
FILE* ausgabe = fopen(ergebnis, "wb");
FILE* f = fopen(Datei, "rb");
if (f == NULL)
return;
int i = -1;
int r1 = 0;
int r2 = 0;
int l1 = 0;
int l2 = 0;
int l = 0;
int r = 0;
while((getc(f))!=EOF)
{
i++;
if (i == 0)
r1 = (unsigned)fgetc(f);
if (i == 1)
{
r2 = (unsigned)fgetc(f);
r = r1 | r2 << 8;
}
if (i == 2)
l1 = (unsigned)fgetc(f);
if (i == 3)
{
l2 = (unsigned)fgetc(f);
l = l1 | l2 << 8;
putc(r,ausgabe);
putc(l,ausgabe);
i = -1;
}
}
fclose(f);
fclose(ausgabe);
exit(-1);
编辑:解决了
int wo = 0;
while(wo !=EOF)
{
wo = getc(f);
i++;
if (i == 0)
r1 = (unsigned)wo;
if (i == 1)
{
r2 = (unsigned)wo;
r = (r2<<8)+r1; //r1 | r2 << 8;
}
if (i == 2)
l1 = (unsigned)wo;
if (i == 3)
{
l2 = (unsigned)wo;
l = (l2<<8)+l1; //l1 | l2 << 8;
putc((char) ( r & 0xff),ausgabe);
putc((char) ((r >> 8) & 0xff),ausgabe);
putc((char) ( l & 0xff),ausgabe);
putc((char) ((l >> 8) & 0xff),ausgabe);
i = -1;
}
}