Search code examples
audioavaudiopcmbuffer

How can I to resize PCM audio sample buffer longer?


For example, I have 100 Byte PCM buffer and want to increase it to 300 Byte.

what i tried: asume original buffer was 9, 4, 1, 7, 5

  1. insert 0 - 9 0 0 4 0 0 1 0 0 7 0 0 5 0 0
  2. average - 9 7 5 4 3 2 1 3 5 7 7 6 5 5 5
  3. insert 0 in back - 9 4 1 7 5 0 0 0 0 0 0 0 0 0 0

They all had weird noise in result audio file.

How can I change length of buffer without effect sound? Is there any formula I can use?


Solution

  • Usually linear interpolation works. What is the bit-resolution of your PCM file? If it is 16 bits (pretty typical), you'll have to first convert two bytes into a single value before applying the interpolation, and then disassemble the values back to bytes. You will need to know the byte order, as it can be either little-endian or big-endian.

    EDIT: I should have added that the pitch will drop with this method of lengthening the file, unless the playback frame rate increases. To stretch out a sound in time without affecting its pitch is considerably more complicated.