Hello Community,
I'm newbie in Linux and want to write an application to play audiodata from a buffer.
I startes to write a Test Application using the example I found im web.
http://home.roadrunner.com/~jgglatt/tech/linuxapi.htm
Code:
#include <stdio.h>
#include <string.h>
#include <alsa/asoundlib.h>
int main(int argc, char **argv)
{
register int err;
int cardNum;
// Start with first card
cardNum = -1;
for (;;){
snd_ctl_t *cardHandle;
if ((err = snd_card_next(&cardNum)) < 0){
printf("Can't get the next card number: %s\n", snd_strerror(err));
break;
}
if (cardNum < 0) break;
// Open this card's control interface. We specify only the card number -- not
// any device nor sub-device too
{
char str[64];
sprintf(str, "hw:%i", cardNum);
if ((err = snd_ctl_open(&cardHandle, str, 0)) < 0){
printf("Can't open card %i: %s\n", cardNum, snd_strerror(err));
continue;
}
}
{
snd_ctl_card_info_t *cardInfo;
// We need to get a snd_ctl_card_info_t. Just alloc it on the stack
snd_ctl_card_info_alloca(&cardInfo);
// Tell ALSA to fill in our snd_ctl_card_info_t with info about this card
if ((err = snd_ctl_card_info(cardHandle, cardInfo)) < 0)
printf("Can't get info for card %i: %s\n", cardNum, snd_strerror(err));
else
printf("Card %i = %s\n", cardNum, snd_ctl_card_info_get_name(cardInfo));
}
// Close the card's control interface after we're done with it
snd_ctl_close(cardHandle);
}
// ALSA allocates some mem to load its config file when we call some of the
// above functions. Now that we're done getting the info, let's tell ALSA
// to unload the info and free up that mem
snd_config_update_free_global();
}
if I compile it I get a lot of errors:
main.cpp:16: Error:undefined reference to `snd_card_next'
main.cpp:17: undefined reference to `snd_strerror'
main.cpp:26: undefined reference to `snd_ctl_open'
main.cpp:27: undefined reference to `snd_strerror'
main.cpp:36: undefined reference to `snd_ctl_card_info_sizeof'
main.cpp:39: undefined reference to `snd_ctl_card_info'
main.cpp:40: undefined reference to `snd_strerror'
main.cpp:42: undefined reference to `snd_ctl_card_info_get_name'
main.cpp:46: undefined reference to `snd_ctl_close'
main.cpp:51: undefined reference to `snd_config_update_free_global'
I also include <alsa/controls.h> . but I am not able to compile the code :-(
.
thanks for your help.
Martin