All of lore.kernel.org
 help / color / mirror / Atom feed
* [alsa-dev]Question regarding period/buffer and error handling
@ 2004-05-28  1:34 Cournapeau David
  2004-05-28  7:02 ` Måns Rullgård
  2004-05-28 15:52 ` Clemens Ladisch
  0 siblings, 2 replies; 6+ messages in thread
From: Cournapeau David @ 2004-05-28  1:34 UTC (permalink / raw)
  To: ALSA LIST

Hi there,

    For my research, I need to use audio with matlab under linux, and 
sound support of matlab is kind of... well, crappy (basically, it is 
opening the /dev/audio file and write to it; on my computer, it doesn't 
seem to work). That's why I am thinking about using a wrapper to alsa.
    Thanks to some tutorials (by the way, thanks for your tutorial, 
Paul), I managed to play sound with matlab and alsa, but I would like my 
wrapper to be full proof against errors. Basically, here is my method :

    - parse the input arguments, convert from matlab representation to 
'normal C' representation (that is, vectors of double for samples).
    - To see if any soundcard is present, I am using 
snd_card_next(card), with card value to -1.
    - I allocate memory for a snd_pcm_hw_params_t structure, open a pcm 
device in NON_BLOCK_MODE, set the mode to blocking mode, set the format 
(16 bits LE), sampling rate, interleaved format and number of channels
    - I write to the pcm device using writei.

    My first problem is with writei: I cut my audio input in blocks of a 
small size before sending them to writei( blocks are 1024 frames long, 
for example), and depending of the sampling rate, writei doesn't write 
the whole block. For example, at 44100 Hz, if the block is 1024 frames 
long, only the 940 first frames are written. I think this problem is 
related to period size and so on, but I don't really understand the 
differences between period and buffer. Where can I find some 
informations about that ?
    My second problem is related to snd_card_next: If the card value 
returned by snd_card_next is different from -1, does that always mean 
than a alsa audio device is present on the system ? Is it the best 
method to probe a soundcard with alsa support?
    My third problem is related to the error handling: right now, with 
some hack, my wrapper works. But if I stop the wrapper with ctl+C, the 
pcm device is not closed properly, which means I cannot use the pcm 
device again (except by closing matlab and launching it again....). Is 
there a way to close the pcm device before opening it ? ( I first 
thought about catching the ctrl+C 'signal' from matlab in my wrapper, to 
exit cleanly, but for now, I didn't find any way to do it).

    Thank you,

    David


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [alsa-dev]Question regarding period/buffer and error handling
  2004-05-28  1:34 [alsa-dev]Question regarding period/buffer and error handling Cournapeau David
@ 2004-05-28  7:02 ` Måns Rullgård
  2004-05-28  8:00   ` Question " Cournapeau David
  2004-05-28 15:52 ` Clemens Ladisch
  1 sibling, 1 reply; 6+ messages in thread
From: Måns Rullgård @ 2004-05-28  7:02 UTC (permalink / raw)
  To: alsa-devel

Cournapeau David <cournape@atr.jp> writes:

> Hi there,
>
>     For my research, I need to use audio with matlab under linux, and
>     sound support of matlab is kind of... well, crappy (basically, it
>     is opening the /dev/audio file and write to it; on my computer, it
>     doesn't seem to work). That's why I am thinking about using a
>     wrapper to alsa.

If you are playing fairly short pieces of sound you might be able to
use this function I wrote some time ago:

function playsnd(y,fs,bits)

wf = tempname;
ws = warning;
warning off
wavwrite(y, fs, bits, wf);
warning ws
wf = [wf '.wav'];
[s,o] = unix(sprintf('aplay %s', wf));
delete(wf);


-- 
Måns Rullgård
mru@kth.se



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question regarding period/buffer and error handling
  2004-05-28  7:02 ` Måns Rullgård
@ 2004-05-28  8:00   ` Cournapeau David
  2004-05-28  8:22     ` Måns Rullgård
  0 siblings, 1 reply; 6+ messages in thread
From: Cournapeau David @ 2004-05-28  8:00 UTC (permalink / raw)
  To: alsa-devel

Måns Rullgård wrote:

>
>If you are playing fairly short pieces of sound you might be able to
>use this function I wrote some time ago:
>
>function playsnd(y,fs,bits)
>
>wf = tempname;
>ws = warning;
>warning off
>wavwrite(y, fs, bits, wf);
>warning ws
>wf = [wf '.wav'];
>[s,o] = unix(sprintf('aplay %s', wf));
>delete(wf);
>
>
>  
>
Well, I precisely want to avoid writing to a temporary file :)

But right now, my function seems to work, I just used UNIX signals to 
close cleanly the audio device, it was much simpler than what I thought 
at first.

Cheers,

David


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id66&op=click

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question regarding period/buffer and error handling
  2004-05-28  8:00   ` Question " Cournapeau David
@ 2004-05-28  8:22     ` Måns Rullgård
  0 siblings, 0 replies; 6+ messages in thread
From: Måns Rullgård @ 2004-05-28  8:22 UTC (permalink / raw)
  To: alsa-devel

Cournapeau David <cournape@atr.jp> writes:

> Måns Rullgård wrote:
>
>>
>>If you are playing fairly short pieces of sound you might be able to
>>use this function I wrote some time ago:
>>
>>function playsnd(y,fs,bits)
>>
>>wf = tempname;
>>ws = warning;
>>warning off
>>wavwrite(y, fs, bits, wf);
>>warning ws
>>wf = [wf '.wav'];
>>[s,o] = unix(sprintf('aplay %s', wf));
>>delete(wf);
>>
> Well, I precisely want to avoid writing to a temporary file :)

If the files are small they will probably never hit the physical
disk.  Of course, your sounds might be longer than that.

-- 
Måns Rullgård
mru@kth.se



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question regarding period/buffer and error handling
  2004-05-28  1:34 [alsa-dev]Question regarding period/buffer and error handling Cournapeau David
  2004-05-28  7:02 ` Måns Rullgård
@ 2004-05-28 15:52 ` Clemens Ladisch
  2004-05-31  1:04   ` Cournapeau David
  1 sibling, 1 reply; 6+ messages in thread
From: Clemens Ladisch @ 2004-05-28 15:52 UTC (permalink / raw)
  To: Cournapeau David; +Cc: ALSA LIST

Cournapeau David wrote:
>     My second problem is related to snd_card_next: If the card value
> returned by snd_card_next is different from -1, does that always mean
> than a alsa audio device is present on the system ?

It means that same kind of device with an ALSA driver is present.
This does not mean that you'll be able to play PCM data to it.  And
there may be software devices available.

> Is it the best method to probe a soundcard with alsa support?

snd_card_next() and snd_ctl_pcm_next_device() will give you a list of
hardware devices only.

Usually, you should use the device named "default" and let the user
allow to specify another device name.


HTH
Clemens




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question regarding period/buffer and error handling
  2004-05-28 15:52 ` Clemens Ladisch
@ 2004-05-31  1:04   ` Cournapeau David
  0 siblings, 0 replies; 6+ messages in thread
From: Cournapeau David @ 2004-05-31  1:04 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: ALSA LIST

Clemens Ladisch wrote:

>Cournapeau David wrote:
>  
>
>>    My second problem is related to snd_card_next: If the card value
>>returned by snd_card_next is different from -1, does that always mean
>>than a alsa audio device is present on the system ?
>>    
>>
>
>It means that same kind of device with an ALSA driver is present.
>This does not mean that you'll be able to play PCM data to it.  And
>there may be software devices available.
>
>  
>
>>Is it the best method to probe a soundcard with alsa support?
>>    
>>
>
>snd_card_next() and snd_ctl_pcm_next_device() will give you a list of
>hardware devices only.
>
>Usually, you should use the device named "default" and let the user
>allow to specify another device name.
>
>  
>
Ok, that's what I thought reading the different sources I checked, 
concerning the device name. But I am still a bit confused how to probe a 
soundcard to play a pcm stream to it: what  should I do after having 
found an hardware device with snd_card_next ?

Is there always a "default" name ? Or is it user dependant ?

cheers,

David


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-05-31  1:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-28  1:34 [alsa-dev]Question regarding period/buffer and error handling Cournapeau David
2004-05-28  7:02 ` Måns Rullgård
2004-05-28  8:00   ` Question " Cournapeau David
2004-05-28  8:22     ` Måns Rullgård
2004-05-28 15:52 ` Clemens Ladisch
2004-05-31  1:04   ` Cournapeau David

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.