[+PLUS] Problem in accessing /dev/dsp

Santhosh Thottingal santhosh00 at gmail.com
Sat Jan 6 09:52:20 IST 2007


Got the solution..
see the below code

/* USE: gcc sndtest2.c -lasound to compile :-)*/
/* also insure alsa-lib and alsa-lib-devel are installed */
#include<stdio.h>
#include<alsa/asoundlib.h>
snd_output_t *output=NULL;
static char *device="default";  /* playback device */
unsigned char buffer[16000*16*300*2/8];
int main(int argc, char *argv[]){
int err;
int rfd;
unsigned int i;
snd_pcm_t *handle;
snd_pcm_sframes_t frames;
 rfd=open(argv[1], O_RDONLY);
    if((err=snd_pcm_open(&handle,device, SND_PCM_STREAM_PLAYBACK,0))<0){
        perror("Playback open error");
        exit(1);
    }

    if((err= snd_pcm_set_params(handle,
                                SND_PCM_FORMAT_S16_LE,
                                SND_PCM_ACCESS_RW_INTERLEAVED,
                                1,
                                16000,
                                1,
                                500000))<0){

              printf("Playback open error: %s\n", snd_strerror(err));
            exit(1);
    }
    while(1){
        read(rfd, buffer, sizeof(buffer));
    frames=snd_pcm_writei(handle,buffer,sizeof(buffer));
    if(frames<0){
           printf("snd_pcm_writei failed: %s\n", snd_strerror(err));
    break;

    }
    if(frames>0 && frames < (long)sizeof(buffer))
         printf("Short write (expected %li, wrote %li)\n",
(long)sizeof(buffer), frames);

    }
    snd_pcm_close(handle);

    return 0;

}

This will multiplex the /dev/dsp device and we can  any number of programs
that access /dev/dsp at the same time.


On 1/5/07, Santhosh Thottingal <santhosh00 at gmail.com> wrote:
>
> Thanks for your input...
> Killing the process does not seem to be a good choice.
> I got some sample code to play sound files using ALSA
> library(alsa/asoundlib.h from alsa-lib and alsa-lib-devel) from one friend.
> I will update you after trying it.
> Thanks,
> -santhosh
>
> On 1/5/07, Pramode C.E. <pramode_ce at yahoo.co.in> wrote:
>
> > >
> > >              The problem I am experiencing here is,
> > > if artsd (or any sound
> > > system) is holding this device I cannot use
> > > /dev/dsp. And I cannot guess the
> > > sound system running on the machine this program is
> > > going to run. If I kill
> >
> > I think there is something called `artsdsp' which
> > translates calls to /dev/dsp to arts api functions -
> > but that doesn't solve your problem. Maybe, the only
> > way out is to use something like `fuser', identify the
> > process using the sound device and kill it.
> >
> >
> >
> >
> > ====================
> > Pramode C.E
> > http://pramode.net
> > ====================
> >
> > Send free SMS to your Friends on Mobile from your Yahoo! Messenger.
> > Download Now! http://messenger.yahoo.com/download.php
> >
> >
> >
> > _______________________________________________
> > Palakkad Libre software Users Society Main Mailing List
> > "Adding freedom to common minds"
> >
> > PLUS-discuss at lists.sarovar.org
> > http://lists.sarovar.org/cgi-bin/mailman/listinfo/plus-discuss
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.sarovar.org/pipermail/plus-discuss/attachments/20070106/2591fd0d/attachment.xhtml


More information about the PLUS-discuss mailing list