【发布时间】:2009-03-24 13:36:03
【问题描述】:
这是我的尝试。关于更好的解决方案的任何提示?:
// for loop to convert 32 to 16 bits
uint32_t i;
int32_t * samps32 = (int32_t *)&(inIQbuffer[0]);
int16_t * samps16 = (int16_t *)&(outIQbuffer[0]);
for( i = 0; i < ( num_samples * 2/* because each sample is two int32 s*/ ); i++ ) {
overflowCount += ( abs(samps32[i]) & 0xFFFF8000 ) ? 1 : 0;
samps16[i] = (int16_t)samps32[i];
}
// Only report error every 4096 accumulated overflows
if( ( overflowCount & 0x1FFF ) > 4096 ) {
printf( "ERROR: Overflow has occured while scaling from 32 "
"bit to 16 bit samples %d times",
overflowCount );
}
这是实际检查溢出的部分:
overflowCount += ( abs(samps32[i]) & 0xFFFF8000 ) ? 1 : 0;
【问题讨论】:
-
我们正在将 int32_t 转换为 int16_t。
-
只想提一下:“根据您的编辑 (stackoverflow.com/revisions/677427/list),您几乎使我的整个帖子无效。感谢您在问题中未提及您的编辑。”
-
因为您的编辑令人困惑且无益而被否决。
-
Phresnel 你在我编辑问题时做出了回答。
标签: c performance optimization embedded