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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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).
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
I'm afraid not: soxr is just the resampler (for apps that have already got their I/O sorted through other means).
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?
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).
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
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.
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
Finally tracked down the issue causing the crash. I was mistakenly using the split types rather than interleaved types.