[alsa-devel] ALSA C++ API
Lasse Kärkkäinen
tronic+8nhy at trn.iki.fi
Tue Sep 18 22:19:10 CEST 2007
Even though I got no replies to my original announcement, here is a
new version that wraps hw and sw params completely, has a macro for
checking ALSA C function return values (throws alsa::error) and uses
different naming style (similar to the C++ standard library). It is
better documented now, too.
The code is now largely generated with macros, so it isn't very readable
anymore :/
Next I'll be trying to figure out how the PCM API itself should be
wrapped, for C++ style callbacks, etc. I am using the test/pcm.c program
for my tests. Does it use good style for error recovery, etc? Mine will
base on it, so this is important.
Example of use (a port of what test/pcm.c does using a few separate
functions and 140 lines of code):
alsa::pcm handle(device);
unsigned int rrate = rate;
alsa::hw_config(handle)
.rate_resample(resample)
.set(transfer_methods[method].access)
.set(format)
.channels(channels)
.rate_near(rrate)
.buffer_time_near(buffer_time)
.get_buffer_size(buffer_size)
.period_time_near(period_time)
.get_period_size(period_size)
.commit();
if (rate != rrate) {
std::cout << "Requested rate " << rate << " Hz, got " <<
rrate << " Hz" << std::endl;
rate = rrate;
}
alsa::sw_config(handle)
.start_threshold((buffer_size / period_size) * period_size)
.avail_min(period_size)
.xfer_align(1)
.commit();
I'd prefer to use the Boost libraries (boost::function,
boost::noncopyable, etc), but I am afraid that a dependency on them
might be problematic. What do you think?
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: alsa.hpp
Url: http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20070918/650cb036/attachment-0001.bat
More information about the Alsa-devel
mailing list