我已簡單地程序來交換在PCM音頻端(2個通道,48kHz的,24位),但只有一個信道被正確地交換,第二個仍然是小端(我檢查生成輸出在CoolEdit 2000中)。任何人都可以給我一些指導,我的代碼中有什麼問題?交換端
inline int endian_swap(unsigned int x)
{
unsigned char c1, c2, c3, c4;
c1 = x & 255;
c2 = (x >> 8) & 255;
c3 = (x >> 16) & 255;
c4 = (x >> 24) & 255;
return ((int)c1 << 24) + ((int)c2 << 16) + ((int)c3 << 8) + c4;
}
int main()
{
FILE *fpIn, *fpOut;
short x;
fpIn = fopen("audio.pcm", "rb");
fpOut = fopen("out.pcm", "wb");
int test = sizeof(short);
int count = 0;
int swaped = 0;
while(fread(&x, sizeof(int), 1, fpIn) == 1)
{
swaped = endian_swap(x);
fwrite(&swaped, sizeof(int), 1, fpOut);
}
system("pause");
return 0;
}
此致敬禮!
'endian_swap()'如何實現? – sharptooth
對不起,我沒有在 – Luke
之前添加endian_swap()通過組合這兩個錯誤(由Oli Charlesworth和mtrw提到),我很驚訝任何一個頻道看起來都不錯。 –