Community
cancel
Showing results for 
Search instead for 
Did you mean: 
MAboh
Novice
1,731 Views

ALSA library in C language in intel edison using gcc compiler

Jump to solution

Hello all,

Now I decided to run a sample ALSA program on the intel edison using vi editor and gcc compiler through a putty terminal, because I spent a long time trying to use the eclipse and cygwin to run that simple program and I could not.

I could not run the program on the edison because of the line "# include "

My question is, is there already an ALSA library on the edison processor (My edison has yocto 2.1 installed form the intel edison website) ?

If no, how to install it to the edison processor ?

And if yes, what is its path ? so that I can include it in the C code.

Thanks in advance

0 Kudos
1 Solution
Pablo_M_Intel
Employee
211 Views

Hi Abohegab,

There are some ALSA packages in the Edison image. But you might have to download some others from the AlexT repo. Did you already configured your base-feeds.conf file? This is to be able to download packages from the repo.

If you haven't, I would suggest you to check this link http://alextgalileo.altervista.org/edison-package-repo-configuration-instructions.html http://alextgalileo.altervista.org/edison-package-repo-configuration-instructions.html, these are the instructions to configure your Edison. Once you're done with that, you can check the available packages in his repo.

Could you please share the code that you're using so we can help you?

Regards,

PabloM_Intel

View solution in original post

5 Replies
Pablo_M_Intel
Employee
212 Views

Hi Abohegab,

There are some ALSA packages in the Edison image. But you might have to download some others from the AlexT repo. Did you already configured your base-feeds.conf file? This is to be able to download packages from the repo.

If you haven't, I would suggest you to check this link http://alextgalileo.altervista.org/edison-package-repo-configuration-instructions.html http://alextgalileo.altervista.org/edison-package-repo-configuration-instructions.html, these are the instructions to configure your Edison. Once you're done with that, you can check the available packages in his repo.

Could you please share the code that you're using so we can help you?

Regards,

PabloM_Intel

View solution in original post

MAboh
Novice
211 Views

Thanks alot Mr Pablo,the problem was installing the ALSA package.

Now I have another problem if someone can help me, because I had the following problem also when I was programming on eclipse:

The error message is "undefined refrence" for a pointer called playback_handle

This is the simple ALSA program that I'm trying to run:

# include

# include

# include

main (int argc, char *argv[])

{

int i;

int err;

short buf[128];

snd_pcm_t *playback_handle;

snd_pcm_hw_params_t *hw_params;

if ((err = snd_pcm_open (&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0) {

fprintf (stderr, "cannot open audio device %s (%s)\n",

argv[1],

snd_strerror (err));

exit (1);

}

if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {

fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",

snd_strerror (err));

exit (1);

}

if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {

fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",

snd_strerror (err));

exit (1);

}

if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {

fprintf (stderr, "cannot set access type (%s)\n",

snd_strerror (err));

exit (1);

}

if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {

fprintf (stderr, "cannot set sample format (%s)\n",

snd_strerror (err));

exit (1);

}

if ((err = snd_pcm_hw_params_set_rate_near (playback_handle, hw_params, 44100, 0)) < 0) {

fprintf (stderr, "cannot set sample rate (%s)\n",

snd_strerror (err));

exit (1);

}

if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, 2)) < 0) {

fprintf (stderr, "cannot set channel count (%s)\n",

snd_strerror (err));

exit (1);

}

if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {

fprintf (stderr, "cannot set parameters (%s)\n",

snd_strerror (err));

exit (1);

}

snd_pcm_hw_params_free (hw_params);

if ((err = snd_pcm_prepare (playback_handle)) < 0) {

fprintf (stderr, "cannot prepare audio interface for use (%s)\n",

snd_strerror (err));

exit (1);

}

for (i = 0; i < 10; ++i) {

if ((err = snd_pcm_writei (playback_handle, buf, 128)) != 128) {

fprintf (stderr, "write to audio interface failed (%s)\n",

snd_strerror (err));

exit (1);

}

}

snd_pcm_close (playback_handle);

exit (0);

}

And this is the error I get:

/tmp/cc9SZYqA.o: In function `main':

ear02.c:(.text+0x2c): undefined reference to `snd_pcm_open'

ear02.c:(.text+0x43): undefined reference to `snd_strerror'

ear02.c:(.text+0x7e): undefined reference to `snd_pcm_hw_params_malloc'

ear02.c:(.text+0x95): undefined reference to `snd_strerror'

ear02.c:(.text+0xd1): undefined reference to `snd_pcm_hw_params_any'

ear02.c:(.text+0xe8): undefined reference to `snd_strerror'

ear02.c:(.text+0x126): undefined reference to `snd_pcm_hw_params_set_access'

ear02.c:(.text+0x13d): undefined reference to `snd_strerror'

ear02.c:(.text+0x17b): undefined reference to `snd_pcm_hw_params_set_format'

ear02.c:(.text+0x192): undefined reference to `snd_strerror'

ear02.c:(.text+0x1d7): undefined reference to `snd_pcm_hw_params_set_rate_near'

ear02.c:(.text+0x1ee): undefined reference to `snd_strerror'

ear02.c:(.text+0x22c): undefined reference to `snd_pcm_hw_params_set_channels'

ear02.c:(.text+0x243): undefined reference to `snd_strerror'

ear02.c:(.text+0x27f): undefined reference to `snd_pcm_hw_params'

ear02.c:(.text+0x296): undefined reference to `snd_strerror'

ear02.c:(.text+0x2cb): undefined reference to `snd_pcm_hw_params_free'

ear02.c:(.text+0x2dd): undefined reference to `snd_pcm_prepare'

ear02.c:(.text+0x2f4): undefined reference to `snd_strerror'

ear02.c:(.text+0x33e): undefined reference to `snd_pcm_writei'

ear02.c:(.text+0x358): undefined reference to `snd_strerror'

ear02.c:(.text+0x396): undefined reference to `snd_pcm_close'

collect2: error: ld returned 1 exit status

 

I read a similar problem and the solution was to add the library name in a file called '.pro' but I don't know where is that file.

I also included all the alsa libraries inside that simple program but the same error "undefined refrence" is shown.

If anyone could help, that will be appreciable.

Thanks in advance. 

MAboh
Novice
211 Views

I knew the solution. it is to include the lasound library while compiling:

root@***# gcc ***.c -lasound

Pablo_M_Intel
Employee
211 Views

Hi Abohegab,

Were you able to make it work? I didn't quite understand your last post so I'm not sure.

Regards,

PabloM_Intel

MAboh
Novice
211 Views

Hello PabloM,

Yes, I am able to make it work. Thanks alot for your help.

Best wishes,

Abohegab

Reply