19

What is the difference between sample rate and frame rate? I tried to check a song and found sample rate and frame rate using java.They have same value, It makes me confuse.

doesn't frame consist of many sample?

thank you

wendy0402
  • 495
  • 2
  • 5
  • 16

3 Answers3

25

read the documentation

Sample rate = number of samples / second

Frame = 1 sample from each channel (PCM)

Frame Size = Sample size * Channels

Frame Rate = frames / second.

For PCM the sample rate and the frame rate are the same since a frame consists of a a sample from each channel

msam
  • 4,259
  • 3
  • 19
  • 32
  • 2
    The sample rate is always the same as the frame rate for PCM. @greg-449 posted the correct answer – Peter Bagyinszki Jul 31 '15 at 23:08
  • gregs answer is the correct one. It is independent of channels for PCM Source code: http://book2s.com/java/src/package/javax/sound/sampled/audioformat.html – justinvf Mar 24 '17 at 16:53
  • @justinvf Both answers are the correct. The link you posted describes exactly what I wrote above: `For encodings like PCM, a frame consists of the set of samples for all channels at a given point in time, and so the size of a frame (in bytes) is always equal to the size of a sample (in bytes) times the number of channels`...`with some other sorts of encodings...the sample rate and sample size refer to the data after it is decoded into PCM, and so they are completely different from the frame rate and frame size` – msam Apr 05 '17 at 13:19
  • greg-449 is quoting documentation regarding the frame RATE while @msam is quoting the Java docs about the frame SIZE. – man910 Apr 18 '17 at 14:40
17

From: http://www.jsresources.org/faq_audio.html#frame_rate

For PCM, A-law and μ-law data, a frame is all data that belongs to one sampling intervall. This means that the frame rate is the same as the sample rate.

For compressed formats like Ogg Vorbis, mp3 and GSM 06.10, the situation is different. A frame is a block of data as it is output by the encoder. Often, these blocks contain the information for several sampling intervalls. For instance, a mp3 frame represents about 24 ms. So the frame rate is about 40 Hz. However, the sample rate of the original is preserved even inside the frames and is correctly restored after decoding.

greg-449
  • 109,219
  • 232
  • 102
  • 145
1

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.

  • 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` – iryndin Oct 24 '19 at 18:23