Menu

File input/output

farski
2014-04-17
2014-11-16
  • farski

    farski - 2014-04-17

    As I had mentioned in my other thread, I'm switching an app over from SoX proper to soxr to reduce the dependencies. SoX was pretty straight forward in terms of how it handled actually writing out a full-fledged WAV file with the resampled data. It seems like soxr, at least from the examples I've seen and the little bit of work I've done so far, isn't really set up to create a WAV file. I think I'm ending up with raw PCM data in a file the way I'm doing things right now.

    Is there an out-of-the-box way of getting a WAV file with soxr? Or even just some standard way of taking the resulting data and wrapping it up as a WAV?

    The resampling is an optional step that only gets run under certain conditions in this app, and then next step (encoding to MP2) is dependent on starting with a WAV or AIFF; adding support for raw PCM data would be a real bummer at this point.

     
  • robs

    robs - 2014-04-23

    I'm afraid not: soxr is just the resampler (for apps that have already got their I/O sorted through other means).

     
  • farski

    farski - 2014-04-23

    Does that mean on the other end I should not be opening WAV files directly? Do I need to get the PCM data out of the WAV myself before running it through soxr?

     
  • robs

    robs - 2014-04-23

    Yes, here's a bit from the README file on this:

    The resampler is currently available either as part of libsox (the audio
    file-format and effect library), or stand-alone as libsoxr (this package).
    The interfaces to libsox and libsoxr are slightly different, with that of
    libsoxr designed specifically for resampling. An application requiring
    support for other effects, or for reading-from or writing-to audio files or
    devices, should use libsox (or other libraries such as libsndfile or
    libavformat).

     
  • farski

    farski - 2014-04-24

    Ok, thanks. It's not clear to me yet whether it would be more work to try and get libsox working in this application, or wrapping soxr with file i/o is more trouble than it's worth. For now I'm at least going to try to stick with soxr because the footprint is smaller and I already have it available and working.

    If you don't mind indulging me for a moment, I think I have made some progress in terms of reading and writing the files with libsndfile, and processing the audio with soxr. It's not work quite right, though, as the audio I end up with is pretty messed up (just quick stutters).

    My main hangup is how the various buffers and lengths for sndfile and soxr match up.
    https://gist.github.com/farski/797259df04356ee25560

    I think I'm good up until line 39. I would really appreciate even a quick glance at how I'm processing the audio to see if you notice any glaring errors

     
  • robs

    robs - 2014-04-26

    I think it's a mismatch between shorts and floats: either use sndfile read float, or tell soxr_create to expect shorts using the soxr_io_spec_t parameter.

     
  • farski

    farski - 2014-09-07

    I've finally had some more time to spend working on this. I actually made some good progress getting the the inputs/outputs of sndfile and soxr to match up. I can run a 48kHz file through and get back a 44.1 file just like I would expect.

    That version of the code was having trouble with a number of other formats, though, which wasn't surprising since I wasn't explicitly handling different formats.

    I felt like I had a better understanding of how this all works, so I kind of went back to the drawing board. I took a lot of what is in example 2 and added the channel support from example 3 and added handling for the different formats libsnd supports and swapped the stdin/out stuff with file io.

    I'm having a problem where I get an EXC_BAD_ACCESS error at soxr_process every time, though. All the values I pass in are what I would expect when it gets called, so I'm at a loss as to what might be causing the issue.

    Any ideas?

    https://gist.github.com/farski/1feeae5de63313a96894

     

    Last edit: farski 2014-09-07
  • farski

    farski - 2014-11-16

    Finally tracked down the issue causing the crash. I was mistakenly using the split types rather than interleaved types.

     

Log in to post a comment.