Search code examples
c++audiowavsamplingpcm

Converting audio samples into an audible file format


I've been trying to convert a huge amount of data (about 900 MB) to an audible file format for a few days now. I've been given a .dat file containing 900 millions floating-point samples (one per line) representing 90 seconds of music at 10 MHz.

I downsampled to 40 KHz but now I don't know how I could possibly listen to the audio hidden in those bytes. I'm writing a C++ program in a Linux environment but if any one knows how to accomplish this task using Matlab, Octave, Python, Audacity, MPlayer or any other tool, please come forth and speak :) Contributions in any amount are greatly appreciated.

    head -n 5 ~/input.dat
    -2.4167
    -7.5322e-016
    -0.2283
     0.13581
    -0.51926

Solution

  • Target your sample rate to 44100 hz (or 48000, 22050, 11025, or 8000 hz)

    Convert your audio samples to 16-bit signed integers (-32768 to +32767).

    Follow the instructions on WAV file synthesis here: WAV File Synthesis From Scratch - C