Previous page: Daily Crap 2010-01-24
Next page: Daily Crap 2010-02-06


Daily Crap 2010-02-02

  1. When I save an FLV file from YouTube and export its audio as WAV with VLC, there's usually a lot of clipping. Even if you export as floats (so that the clipped data is still there), when you load the file in Audacity, Audacity will hard clip at [-1, 1]. To get around this, I wrote a short C program using libsndfile to scale the raw float data.

    #include <stdio.h>
    #include <stdlib.h>
    #include <sndfile.h>
    
    int
    main(int argc, char *argv[])
    {
      SF_INFO infoIn, infoOut;
      SNDFILE *wavIn, *wavOut;
      int i;
      float frame[2 /* max channels */];
    
      infoIn.format = 0; /* auto-detect */
      wavIn = sf_open("beat.wav", SFM_READ, &infoIn);
      if(!wavIn) {
        printf("couldn't open beat.wav\n");
        return 1;
      }
    
      printf("input channels: %d\n", infoIn.channels);
    
      infoOut.samplerate = infoIn.samplerate;
      infoOut.channels = infoIn.channels;
      infoOut.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
      wavOut = sf_open("beat-out.wav", SFM_WRITE, &infoOut);
      if(!wavOut) {
        printf("couldn't open beat-out.wav\n");
        return 1;
      }
    
      while(sf_read_float(wavIn, frame, infoIn.channels) > 0) {
        for(i = 0; i < infoIn.channels; i++)
          frame[i] *= 0.3;
        sf_write_float(wavOut, frame, infoIn.channels);
      }
    
      printf("done\n");
    
      sf_close(wavOut);
      sf_close(wavIn);
    
      return 0;
    }

Comments

Click here to view the comments on this post.