Bonjour,
Je travail en ce moment sur un système embarqué, et dans le cadre d'un projet, je dois faire communiquer par voix deux systèmes embarqués entre eux.
Dans un premier temps je cherchais donc à tester tout simplement le son sur un système, qui contient la version 2.6.24 de linux.
Je me suis inspirer de quelques utilitaires que l'on trouve dans l'architecture Alsa et voici ce que ça donne en codes ces quelques lignes :
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/ioctl.h>
//#include <linux/time.h>
#include <asm/byteorder.h>
#include <sound/asound.h>
main()
{
int i,j,t;
FILE *fp;
int ret;
int f;
int ver;
struct snd_pcm_info info;
struct snd_pcm_channel_info c_info;
struct snd_pcm_status state;
struct snd_pcm_hw_params hwp;
struct snd_pcm_sw_params swp;
int version=0;
memset (&info,0,sizeof(info));
memset (&c_info,0,sizeof(c_info));
memset (&state,0,sizeof(state));
memset (&hwp, 0, sizeof(hwp));
memset (&swp, 0, sizeof(swp));
f=open("/dev/snd/pcmC0D0p", O_RDWR|O_NONBLOCK);
if (f>=0) {
printf("device open with File descriptor f=%d\n", f);
#if 1
ret=ioctl(f, SNDRV_PCM_IOCTL_PVERSION, &version);
if (ret==0)
printf("IOCTL_PVERSION version is %d\n",version);
else
printf ("ioctl ret=%d errno=%d %s\n",ret, errno,strerror(errno));
#endif
#if 1
ret=ioctl(f, SNDRV_PCM_IOCTL_INFO, &info);
if (ret==0)
printf("IOCTL_INFO device is %d subdevice=%d card=%d name=%s\n",info.device,info.subdevice,info.card,info.name);
else
printf ("ioctl ret=%d errno=%d %s\n",ret, errno,strerror(errno));
#endif
#if 0
ret=ioctl(f, SNDRV_PCM_IOCTL_CHANNEL_INFO, &c_info);
if (ret==0)
printf("IOCTL_INFO Channel is %d first=%d step=%d\n",c_info.channel,c_info.first,c_info.step);
else
printf ("ioctl ret=%d errno=%d %s\n",ret, errno,strerror(errno));
#endif
#if 0
ret=ioctl(f, SNDRV_PCM_IOCTL_STATUS, &state);
if (ret==0)
printf("IOCTL_STATUS State is %d\n",state.state);
else
printf ("IOCTL_STATUS ret=%d errno=%d %s\n",ret, errno,strerror(errno));
#endif
#if 1
ret=ioctl(f, SNDRV_PCM_IOCTL_HW_PARAMS, &hwp);
if (ret==0)
printf("IOCTL_HW_PARAMS flags is %d\n",hwp.flags);
else
printf ("IOCTL_HW_PARAMS ret=%d errno=%d %s\n",ret, errno,strerror(errno));
#endif
ret=ioctl(f, SNDRV_PCM_IOCTL_SW_PARAMS, &swp);
if (ret==0)
printf("IOCTL_SW_PARAMS mode is %d\n",swp.tstamp_mode);
else
printf ("IOCTL_SW_PARAMS ret=%d errno=%d %s\n",ret, errno,strerror(errno));
ret=ioctl(f, SNDRV_PCM_IOCTL_START);
if (ret==0)
printf("IOCTL_ Start is OK\n");
else
printf ("IOCTL_START ret=%d errno=%d %s\n",ret, errno,strerror(errno));
for (i=0; i<1;i++) {
for (j=1;j<25;j++) {
t=0;
ret=read(f,&t,1);
// ret=putc(j,fp);
printf("ret=%d t=%d errno=%d",ret,t,errno);
ret=write(f,&j,1);
if (ret==EOF)
printf("ERREUR %d %s ",errno,strerror(errno));
}
}
}
else
printf("ERROR OPENNING FILE\n");
résultat à la compilation :
[root@eseco-ivan bouhara]# ./a.out
device open with File descriptor f=3
IOCTL_PVERSION version is 131080
IOCTL_INFO device is 0 subdevice=0 card=0 name=SiS SI7012
IOCTL_HW_PARAMS ret=-1 errno=22 Invalid argument
IOCTL_SW_PARAMS ret=-1 errno=77 File descriptor in bad state
IOCTL_START ret=-1 errno=77 File descriptor in bad state
ret=-1 t=0 errno=22ERREUR 77 File descriptor in bad state ret=-1 t=0 errno=22ERREUR...
Est-il possible de piloter la carte son sans passer par des interfaces multimédias ?
Peut-on envoyer un son directement sur les speakers(avec un /dev/..par exemple) ?
J'ai tout essayer pour éviter d'avoir à télécherger des packages mais il semble qu'il ne soit pas possible de faire sans pour un simple test son sur un Linux embarqué ...