From alsa-user-owner@alsa.jcu.cz  Mon Sep 21 23:16:50 1998
Received: from entry.jcu.cz (IDENT:perex@entry.jcu.cz [160.217.1.111])
	by marvin.jcu.cz (8.9.1a/8.9.1) with SMTP id XAA24202;
	Mon, 21 Sep 1998 23:14:14 +0200
Date: Mon, 21 Sep 1998 23:14:14 +0200 (MET DST)
From: Jaroslav Kysela <perex@jcu.cz>
To: harryrat@kawo1.rwth-aachen.de
cc: alsa-user@jcu.cz
Subject: Re: pcm programming
In-Reply-To: <Pine.LNX.3.96.980921121530.3556B-100000@gambit.kawo1.rwth-aachen.de>
Message-ID: <Pine.LNX.3.96.980921231050.31752E-100000@entry.jcu.cz>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Reply-To: alsa-user@alsa.jcu.cz
Sender: alsa-user-owner@alsa.jcu.cz
Precedence: list

On Mon, 21 Sep 1998 harryrat@kawo1.rwth-aachen.de wrote:

> Sorry to post again my question, but I'm stuck and won't make it on my own:
> 
> ok, my very first sound program shall record something from the microphone
> and then play the contence of the record buffer.
> 
> record and playback device are the same...
> According to ALSA doc it is possible to open a device once in both
> directions...
> 
> here's the important piece of code:
> 
> readbuffer = (char *)malloc( 80000 );
> printf("%d\n", snd_pcm_read(pcmRecordHandle, readbuffer, 80000));
> snd_pcm_close(pcmRecordHandle);
> sleep(5);
> printf("-->%d\n", snd_pcm_write(pcmPlaybackHandle, readbuffer, 80000));
> snd_pcm_close(pcmPlaybackHandle);
> 
> in this version it works, sound is recorded and played back after the 5
> sec pause...
> 
> BUT: if I don't close the record handle before playback, no sound
> is played, silence...
> 
> readbuffer = (char *)malloc( 80000 );
> printf("%d\n", snd_pcm_read(pcmRecordHandle, readbuffer, 80000));
> sleep(5);
> printf("-->%d\n", snd_pcm_write(pcmPlaybackHandle, readbuffer, 80000));
> snd_pcm_close(pcmRecordHandle);
> snd_pcm_close(pcmPlaybackHandle);
> 
> both operations (read/write) are (according to return values) successfull, 
> complete buffer is used...initialisation of direction (not shown)
> seems also be ok, no errors...
> 
> Card is a GUS PNP, (so sound module is snd-interwave)
> 
> Any ideas what I am doin wrong ?

Code looks good.. You can also look to alsa-lib/test/pcm.c code which is
on CVS... This code work for me (tested with GUS PnP, too).. Or send me
directly your code...

> Do I always have to close one direction in order to be able to use the
> other ?

No, ALSA should support both methods correctly..

						Jaroslav

-----
Jaroslav Kysela <perex@jcu.cz>
Academic Computer Centre, University of South Bohemia
Branisovska 31, C. Budejovice, CZ-370 05 Czech Republic



