Reputation: 175
So basically, I thought the formula for computing pcm file size went as follows:
fileSize(in bits) = samples_per_sec x seconds x number_of_channels
And it worked just fine for me since I was exclusively dealing with pcm files which had 8 bit depth. When I started to deal with 16 bit depth files, the formula didn't produce accurate results. Through some googling I found out that my aformentioned formula was wrong, actually you have to adhere to this one:
fileSize(in bits) = samples_per_sec x seconds x number_of_channel x bit_depth/8
It explains why I was getting correct results with the incorrect formula since, you know, 8 / 8 = 1.
The thing that I don't get is this: why do you have to divide bit depth by eight?
In order to get bits as a result of your calculations, you have to get them on the right side of your formula as well:
bits = samples/seconds x seconds x num_of_channels(dimensionless) x bits/sample = bits
which is fine. So, it should work without division by eight. But it doesn't. Where am I wrong?
Upvotes: 1
Views: 200
Reputation: 1832
In your notation style:
samples_per_sec x seconds x number_of_channels
is total number of samples
samples_per_sec x seconds x number_of_channel x bit_depth
is total number of bits
samples_per_sec x seconds x number_of_channel x bit_depth / 8
is total number of bytes
samples/seconds x seconds x num_of_channels(dimensionless) x bits/sample
is sample_rate x duration_in_seconds x num_of_channels x bit_depth
, which is again total number of bits
The main confusion is likely from bits and bytes. Audio sample size is typically described in bit depth not byte depth. File size / memory is described typically in bytes. To go from bits to bytes you simply divide by 8.
Upvotes: 2