From alsa-devel-owner@alsa.jcu.cz  Fri Aug  7 19:32:08 1998
Received: from cyphyn.219.org (nwhn-sh2-port148.snet.net [204.60.13.148])
	by marvin.jcu.cz (8.8.8/8.8.8) with ESMTP id TAA01087
	for <alsa-devel@alsa.jcu.cz>; Fri, 7 Aug 1998 19:31:52 +0200
Received: from cyphyn.219.org (localhost [127.0.0.1])
          by cyphyn.219.org (8.8.4/8.8.4) with SMTP
	  id NAA02187 for <alsa-devel@alsa.jcu.cz>; Fri, 7 Aug 1998 13:28:09 -0400
Message-ID: <35CB3928.6EC6AA37@geocities.com>
Date: Fri, 07 Aug 1998 13:28:08 -0400
From: Fred Floberg <emng@geocities.com>
MIME-Version: 1.0
To: alsa-devel@alsa.jcu.cz
Subject: Bug, Feature, or El Nino?
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

Hello All,

I'm very excited about the ALSA project! Very good work, Jaroslav!
Finally, full duplex audio for SB's under Linux! :-)

I'm in the process of porting a few applications over to ALSA in
order to take advantage of the full duplex features (csound has
primative support at this point. Next will be Linux Doom (BOOM).
And then Speak Freely - an Internet phone app).

In order to get a feel for the new API I wrote a small test program
which opens a stream in DUPLEX mode, reads and writes the audio
data from the mic to the speakers.

Everything works fine, until I access the mixer with amixer or
alsamixer while the test app is running. When I do that a delay
is introduced between audio input and audio output which remains
until the test app is restarted (i.e. audio stream is closed and
then opened again). The delay seems to be approximately 0.25 sec,
and is not affected by audio buffer/fragment size.

I'm including the set up portion of my test program below.
Am I doing something wrong? Is this delay a small bug?

System here is P166, Soundblaster 16, Linux kernel 2.0.33,
ALSA driver 0.2.0-pre3, ALSA lib 0.0.8


	#define B 256

        void *handle;

        unsigned int buf[B];
        void *bufptr = buf;

        int nbytes = B;
	int err = 0;

        snd_pcm_format_t fmt;
        snd_pcm_playback_params_t pp;

        if((err = snd_pcm_open(&handle, 0, 0, SND_PCM_OPEN_DUPLEX)) != 0){
                fprintf(stderr, "Opening audio device: %s\n", snd_strerror(err));
                exit(0);
        }

        fmt.format = SND_PCM_SFMT_S16_LE;
        fmt.channels = 1;
        fmt.rate = 44100;

        if(err = snd_pcm_record_format(handle, &fmt)){
                fprintf(stderr,"%s\n", snd_strerror(err));
                snd_pcm_close(handle);
                exit(0);
        }
        if(err = snd_pcm_playback_format(handle, &fmt)){
                fprintf(stderr,"%s\n", snd_strerror(err));
                snd_pcm_close(handle);
                exit(0);
        }

        pp.fragments_max = -1; /* Experimental trick taken from Aplay */
        pp.fragment_size = B;
        pp.fragments_room = 1;

        if((err = snd_pcm_playback_params(handle, &pp)) < 0){
                fprintf(stderr, "Error setting playback params: %s\n",
                                snd_strerror(err));
                snd_pcm_close(handle);
                exit(0);
        }

	while(1){ read from and write to handle }

Thanks,

Fred

