javax.sound.sampled.AudioFormat.java


Viewing the Java Code javax.sound.sampled.AudioFormat.java line 252:

frameSize 

    ((sampleSizeInBits + 7) / 8) * channels

When is Different to http://soundfile.sapp.org/doc/WaveFormat/

BlockAlign == NumChannels * BitsPerSample/8

I can't understand Why use + 7.

 

加上7再除以8是为了防止sampleSizeInBits不能被8整除以保证返回的整数大于等于1。

Frame size is in bytes. Let's say channels=2. So, for sampleSizeInBits=8 or 16 we still will have frameSize=2 or 4 bytes,

as it should be. +7 is neglected as we have integer division here. +7 starts playing role when sampleSizeInBits is not multiple to 8.

E.g. sampleSizeInBits=10. So, for sampleSizeInBits=10 and channels=2 frameSize=((12+7)/8)*2=(19/8)*2=4. Briefly, +7 takes

into account cases when sampleSizeInBits is not multiple to 8 to have correct number of bytes for frameSize


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM