Uploaded some audio code to the Comprehensive C Archive Network (CCAN)

CCAN is the fledgling Comprehensive C Archive Network, the idea being that it is to C what the CPAN is to Perl. CCAN is only just beginning. Trying to do my part, I CCAN-ibalized some audio code from Word War vi to create two CCAN modules, ogg_to_pcm, and wwviaudio.

ogg_to_pcm is a very small function which relies on libvorbisfile and converts an ogg file into raw PCM data in memory. Libvorbisfile is cool, but figuring out how to use it is a matter of digging through code examples. I figured people could use a very simple piece of code that lets them say, “I have an ogg file — decode it and give me the PCM data.” Likewise, wwviaudio provides a lot of functions for real time playback and mixing of 16 bit 44100Hz mono PCM data using portaudio. Portaudio is cool, in that it isolates you from the audio hardware and drivers, and is cross platform, but to use it you kind of have to write your own audio engine and mixer. wwviaudio is a very simple and small audio engine and mixer on top of portaudio with a very easy to understand and use interface.

So, what does it take to CCANibalize a chunk of C code?

Well, first you should download the ccan tarball. Go to the CCAN download page and download the whole tarball and unpack it, cd in there, and “make”, “make tools”, and “make check”.

me@myhost ccan_demo]$ ls
ccan.tar.bz2
[me@myhost ccan_demo]$ tar xjf ccan.tar.bz2 
[me@myhost ccan_demo]$ ls
ccan  ccan.tar.bz2
[me@myhost ccan_demo]$ cd ccan
[me@myhost ccan]$ ls
ccan  config.h  Makefile  Makefile-ccan  tools
[me@myhost ccan]$ make
[...]
[me@myhost ccan]$ make tools
[...]
[me@myhost ccan]$ make check
[...]

Then, copy your code intor a directory in the ccan subdir…

[me@myhost ccan]$ ls
ccan                has_info_documentation.d  noerr.d
ccan_depends.d      has_main_header.d         no_info.d
ccanlint.d          has_tests.d               run_tests.d
config.h            idempotent.d              str_talloc.d
depends.d           inter-depends             talloc.d
doc_extract-core.d  libccan.a                 test-depends
doc_extract.d       Makefile                  tools
file_analysis.d     Makefile-ccan             trailing_whitespace.d
grab_file.d         namespacize.d
[me@myhost ccan]$ cd ccan
[me@myhost ccan]$ mkdir mycode
[me@myhost ccan]$ cd mycode
[me@myhost mycode]$ cp -r /somewhere/mycode .

You need to create a _info.c program in your directory which, when run, tells the ccan Makefile and tools what libraries and other ccan modules your code depends on. Take a look at the _info.c files of other ccan modules to get an idea what this _info.c looks like. Part of the _info.c is comments. Pay attention to these, and make yours just like the existing ones, as these comments are parsed and will end up on the ccan web page, and need to be in a particular format.

You should run ccanlint on your code.

[me@myhost ccan]$ tools/ccanlint/ccanlint -v -d ccan/wwviaudio

The first time you run it, it will ask you if you need a “test” directory and default test program. Answer y.

At this point, I have seen ccanlint fail, with permission denied. It creates the test directory, but fails to create run.c, though this doesn’t always happen. If it does happen, chmod 755 the test directory that it created, and run it again. It should then create a test/run.c program for your code

Then, run ccanlint again:

[me@myhost ccan]$ tools/ccanlint/ccanlint -v -d ccan/wwviaudio
Compulsory tests:
  No tests: OK
  No main header file: OK
  No _info.c file: OK

Normal tests:
  Documentation in _info.c: OK
  Headers are #ifndef/#define idempotent wrapped: OK
  Lines with unnecessary trailing whitespace: OK
Total score: 5/5
[me@myhost ccan]$ 

Add unit tests to the test/run.c program if you can. If you cannot figure out how to add any sensible unit tests, then when you submit your program you should omit the tests directory (don’t submit empty tests.) If you do, they’ll be cut out anyway, so not a big deal, either way.

ccanlint will likely complain about various things (particularly, trailing whitespace). Fix all those. At the moment, ccanlint is a bit rough around the edges and its messages can be cryptic, and decoding them may require you to dig into the ccanlint code itself. This should improve as time goes by. CCAN is a participating organization in this year’s 2009 Google Summer of Code and so this should leat to improvements to ccanlint in particular, and CCAN in general.

So… if you’ve got some great C code lying around that others might find useful, think about CCANibalizing it.

And if you are a C programmer, but don’t have any C code you can contribute, take a look at what’s there anyway, as there is some pretty neat stuff in there, and you’ll likely learn something, even if you don’t use any of the code. I know I did.

~ by scaryreasoner on April 10, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: