我已简单地程序来交换在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提到),我很惊讶任何一个频道看起来都不错。 –