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

你可能感兴趣的:(javax.sound.sampled.AudioFormat.java)