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