From: Enno Fennema <ennofennema@tele2.nl>
To: Daniel Sanz <daniellsanz2@gmail.com>
Cc: alsa-devel@alsa-project.org, Trent Piepho <tpiepho@gmail.com>,
Clemens Ladisch <clemens@ladisch.de>
Subject: Re: snd_pcm_wait function (really snd_pcm_draiin)
Date: Fri, 16 Nov 2012 17:27:07 +0100 [thread overview]
Message-ID: <50A6695B.6080202@tele2.nl> (raw)
In-Reply-To: <CAHU0+dTL=rc6gMc49cWiUL3rL2_92myqYrReCUbK3hVy4BB=DA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 688 bytes --]
On 11/16/12 11:41, Daniel Sanz wrote:
> Thanks, Trent, I've been playing a bit with snd_pcm_drain,
> snd_pcm_writei, blocking mode, non-blocking mode, etc. but even if I
> ...
I wanted to play a short sound and release the pcm. It works with a
non-block drain as Clemens suggested.
I noticed using gettimeofday() around drain() that it takes a bit over 2
seconds. Rather long for a sound that only takes 0.1 sec.
Not draining aand a usleep() for 0.1 sec plays the full time and
releases the cpm quicker. As you see in attached example I don't bother
with periods either.
Not exactly your question but I have given up on drainage for my current
application.
Regards,
Enno Fennema
[-- Attachment #2: drain.c --]
[-- Type: text/x-csrc, Size: 865 bytes --]
#include <alsa/asoundlib.h>
#include <math.h>
int main(int argc, char** argv) {
int err, i, n;
snd_pcm_t *handle;
int16_t buffer[500];
for( i = 0; i < 500; i++ ) { // put 500 samples in buffer
double omega = (double)(i % 50) * 2.0 * M_PI / 50;
buffer[i] = sin(omega) * 2500;
}
snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
snd_pcm_set_params(handle, SND_PCM_FORMAT_S16,
SND_PCM_ACCESS_RW_INTERLEAVED,
1, 22000, 0, 50000 );
snd_pcm_start(handle);
n = 2200;
while( n > 500 ) {
err = snd_pcm_writei(handle, buffer, 500);
if( err < 0 )
printf("Error %d : %s\n", err, snd_strerror(err));
n -= err;
}
err = snd_pcm_writei(handle, buffer, n);
#if 0
snd_pcm_nonblock(handle, 0); // ** 1 - nonblock; 0 - Do block
snd_pcm_drain(handle);
#else
usleep(100000);
#endif
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
next prev parent reply other threads:[~2012-11-16 16:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-12 7:23 snd_pcm_wait function Enno Fennema
2012-11-12 7:36 ` Clemens Ladisch
2012-11-12 20:57 ` Trent Piepho
2012-11-13 0:15 ` Daniel Sanz
2012-11-13 4:45 ` Trent Piepho
2012-11-16 10:41 ` Daniel Sanz
2012-11-16 16:27 ` Enno Fennema [this message]
2012-11-16 19:10 ` snd_pcm_wait function (really snd_pcm_draiin) David Henningsson
2012-11-19 11:10 ` Daniel Sanz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50A6695B.6080202@tele2.nl \
--to=ennofennema@tele2.nl \
--cc=alsa-devel@alsa-project.org \
--cc=clemens@ladisch.de \
--cc=daniellsanz2@gmail.com \
--cc=tpiepho@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.