From: Torsten Mohr <tmohr@s.netic.de>
To: Jaroslav Kysela <perex@suse.cz>
Cc: alsa-devel@lists.sourceforge.net
Subject: Re: Docu:: Alsa Audio API:: A minimal capture program
Date: Mon, 9 Feb 2004 01:18:59 +0100 [thread overview]
Message-ID: <200402090119.00259.tmohr@s.netic.de> (raw)
In-Reply-To: <Pine.LNX.4.58.0401311456180.1876@pnote.perex-int.cz>
[-- Attachment #1: Type: text/plain, Size: 668 bytes --]
Hi,
> > thanks for that hint.
> >
> > But sadly, the attached program doesn't work, though
> > i set stop_threshold to 0. I didn't find any functions
>
> This is wrong. You need to set this value to sw_params->boundary or
> greater value to eliminate the stop detection, otherwise with zero,
> the stream is immediately stopped.
thanks again.
But this doesn't seem to be the problem, the attached file is
basically the example "minimal capture program" with the
suggested additions.
The program fails badly. It would be so very great if somebody
had a hint for me on that one. I tried to find the source of
the problem, but i didn't succeed.
Thanks,
Torsten.
[-- Attachment #2: sound.c --]
[-- Type: text/x-csrc, Size: 3809 bytes --]
#define _GNU_SOURCE
#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <alsa/asoundlib.h>
#include <sys/signal.h>
//#include "sound.h"
//#include "settings.h"
#ifndef SAMPLES
#define SAMPLES 2048
#endif
#define QWE fprintf(stderr, "File %s, Line %i\n", __FILE__, __LINE__)
int periodsize = 4096;
int rate = 44100;
int i;
int err;
unsigned char* data;
snd_pcm_t *capture_handle;
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
snd_pcm_uframes_t boundary;
unsigned char* sound_get_data(void) {
return data;
}
int sound_init2(void) {
if ((err = snd_pcm_open (&capture_handle, "plughw:0,0", SND_PCM_STREAM_CAPTURE, 0)) < 0) {
fprintf (stderr, "cannot open audio device plughw:0,0 (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0) {
fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
fprintf (stderr, "cannot set access type (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
fprintf (stderr, "cannot set sample format (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &rate, 0)) < 0) {
fprintf (stderr, "cannot set sample rate (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, 2)) < 0) {
fprintf (stderr, "cannot set channel count (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
fprintf (stderr, "cannot set parameters (%s)\n",
snd_strerror (err));
exit (1);
}
snd_pcm_hw_params_free (hw_params);
if ((err = snd_pcm_sw_params_malloc (&sw_params)) < 0) {
fprintf (stderr, "cannot allocate software parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_sw_params_current (capture_handle, sw_params)) < 0) {
fprintf (stderr, "cannot initialize software parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_sw_params_get_boundary (sw_params, &boundary)) < 0) {
fprintf (stderr, "cannot set access type (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_sw_params_set_stop_threshold (capture_handle, sw_params, boundary)) < 0) {
fprintf (stderr, "cannot set access type (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_sw_params (capture_handle, sw_params)) < 0) {
fprintf (stderr, "cannot set sw-parameters (%s)\n",
snd_strerror (err));
exit (1);
} // */
snd_pcm_sw_params_free (sw_params);
if ((err = snd_pcm_prepare (capture_handle)) < 0) {
fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
snd_strerror (err));
exit (1);
}
}
int sound_init(void) {
data = (unsigned char *)calloc(SAMPLES*4, 0);
sound_init2();
}
void sound_capture(void) {
QWE;
if ((err = snd_pcm_readi (capture_handle, data, periodsize)) != periodsize) {
fprintf (stderr, "read from audio interface failed (%s)\n",
snd_strerror (err));
exit (1);
}
QWE;
}
int main(int argc, char** argv) {
sound_init();
sound_capture();
sound_capture();
sleep(1);
sound_capture();
sound_capture();
QWE;
snd_pcm_drop(capture_handle);
QWE;
// snd_pcm_drain(capture_handle);
QWE;
snd_pcm_close(capture_handle);
QWE;
return 0;
} // */
next prev parent reply other threads:[~2004-02-09 0:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-27 21:40 Docu:: Alsa Audio API:: A minimal capture program Torsten Mohr
2004-01-28 15:18 ` Clemens Ladisch
2004-01-28 22:38 ` Torsten Mohr
2004-01-31 13:57 ` Jaroslav Kysela
2004-02-09 0:18 ` Torsten Mohr [this message]
2004-02-09 7:48 ` Jaroslav Kysela
2004-02-09 17:18 ` Torsten Mohr
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=200402090119.00259.tmohr@s.netic.de \
--to=tmohr@s.netic.de \
--cc=alsa-devel@lists.sourceforge.net \
--cc=perex@suse.cz \
/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.