Ok so finally I decided to test what I have been studying in audio processing and use it with C/C++ searched the web and finally figured out sox is pretty cool. It already has code to take care of most file operations. Cool I thought lets try to reuse some of the source files – tried and failed – ran into compiler and linker error 😦

But wait – as it turns out sox has a library which is pretty cool – hey and its easy to use (I could use it within few hours) – here are my notes from trying to use sox as a library both under linux and cygwin under windows XP (hey my laptop has XP and I wanted to watch TV while trying to compile the damn thing)

Trying to compile Sox for linux
Ran into couple of issues. The usage for libst.a as documented in libst.txt was as follows

ft_t st_open_input(const char *path, const st_signalinfo_t *info, const char *filetype);
Note :
path = “-” specifies date to be read from stdin
info = NULL header is checked to provide filetype
filetype = NULL then use header/file ext to figure out type

ft_t st_open_output(const char *path, const st_signalinfo_t *info,const char *filetype, const char *comment);

As it turns out in the latest library the open APIs have been changed to “st_open_read” and “st_open_write“.

Then I ran into some issues because the proper libraries were not getting compiled

libst.a(vorbis.o)(.text+0x99): In function `st_vorbisstartread’:
/home/users/v/vi/vivekkumar/sox/audio/src/vorbis.c:116: undefined reference to `ov_open_callbacks’
libst.a(vorbis.o)(.text+0xb7):/home/users/v/vi/vivekkumar/sox/audio/src/vorbis.c:124: undefined reference to `ov_info’
libst.a(vorbis.o)(.text+0xcb):/home/users/v/vi/vivekkumar/sox/audio/src/vorbis.c:125: undefined reference to `ov_comment’
/home/users/v/vi/vivekkumar/sox/audio/src/vorbis.c:376: undefined reference to vorbis_encode_init_vbr’

Using the following lines was finally able to compile everything
gcc -lm -lvorbisfile -lvorbisenc dummy.c -o dummy libst.a

Compiling Sox library with Cygwin

I later got a __assert linker error while trying to compile the dummy
project. Finally was able to google and figure out that it happens if
some object are compiled with -mno-cygwin and some without it. As it
turns out by default the sox project in cygwin is configured to compile
with “-mno-cygwin” option. Here is how

gcc -lm -mno-cygwin dummy.c -o dummy libst.a