Search code examples
audioaudio-recordingsampling

Create audio file from samples of amplitude


If I have a text file of sample amplitudes (0-26522), how can I create a playable audio file from them?

I have a vague recollection of tinkering with .pcm files and 8-bit samples way back in the nineties.

Is there any software to automatically create an audio file (PCM or other format) from my samples? I found SoX, but I even after looking at the documentation I can't figure out if it can do what I want, and if so how...


Solution

  • GUI audio workstation called Audacity that lets you do this

    File -> Import -> Raw Data

    Encoding:   Signed 16-bit PCM    // even though your ints are unsigned it still works
    Byte order:  little endian
    Channels     1 channel mono
    

    then just hit Import

    to confirm this works, in a text editor I just did a ( cut N paste followed by select all paste,paste,paste,paste ) of below list of ints about 10 times to generate several thousand ints in a vertical column ... this is my toy input file ... after above Import just save by doing

    File -> Export Audio

    where you choose which output format ( mp3, aac, PCM, ...) once I did this the output mp3 is playable ... using my toy input file I did hear a sine tone

    3
    305
    20294
    11029
    585
    3
    305
    20294
    11029
    585
    3
    305
    20294
    11029
    585