你怎麼閱讀原始音頻文件
- 閱讀二進制模式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;
}
}
什麼區別你有看到? – LostBoy
不會'putc'寫一個'char',丟棄16位值的上半部分嗎? – simonc
@simonc你會寫什麼呢? –