All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Scott Merritt" <alsauser@pragmasoft.com>
To: alsa-devel@alsa-project.org
Subject: SALSA: snd_pcm_avail_update
Date: Thu, 13 Sep 2007 18:55:55 -0400	[thread overview]
Message-ID: <20070913185555.35445b93.alsauser@pragmasoft.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 466 bytes --]

Using salsa-lib-0.0.11, cross-compiling to ARM ...

Despite my best efforts, snd_pcm_avail_update is always returning
"broken pipe".  I have checked the pcm_state of the Capture Handle
just before snd_pcm_avail_update and it is "RUNNING'.  But immediately
after snd_pcm_avail_update it always returns "XRUN".  Furthermore,
this same sequence seems to work properly with the standard ALSA-Lib.

Test program is attached.  Any suggestions appreciated.

Thanks, Scott.

[-- Attachment #2: salsatest.c --]
[-- Type: application/octet-stream, Size: 4573 bytes --]

	#include <stdio.h>
	#include <stdlib.h>
	#include <errno.h>
	#include <poll.h>

	#include <asoundlib.h>

typedef unsigned long int Word32;
typedef signed long int Int32;
const Int32 MaxInt32Value = 0x7FFFFFFF;

	snd_pcm_t *CapHndl;
	snd_pcm_t *PbHndl;

	short buf[100000];

#define AlsaCodec "hw:0"

const snd_pcm_access_t AccessMode = SND_PCM_ACCESS_MMAP_INTERLEAVED;
const snd_pcm_format_t SampleFormat = SND_PCM_FORMAT_S16_LE;
const unsigned int SampleRate = 16000;  // 16kHz Audio sampling

// A transfer size of 640 samples per period (= 25 fragments per second)
// seems like a good compromise between efficiency and latency.
const snd_pcm_uframes_t PeriodSize = 640;  // 25 fragments per second

void Panic (char* Msg) {
   fprintf (stderr, "Panic: %s\n", Msg);
   exit (1);
}  // end Panic

//-------------------------------------------------------------------------
// *** LEVEL 2 ***

void SetUpHwParams (snd_pcm_t* Handle, Word32 BfrPeriods) {
   snd_pcm_hw_params_t* HwParams;
   snd_pcm_uframes_t BfrSize = BfrPeriods * PeriodSize;
   if (snd_pcm_hw_params_malloc (&HwParams) < 0)
      Panic ("SetUpHwParams: Unable to allocate HwParam structure");
   if (snd_pcm_hw_params_any (Handle, HwParams) < 0)
      Panic ("SetUpHwParams: Unable to initialize HwParam structure");
   if (snd_pcm_hw_params_set_access (Handle, HwParams, AccessMode) < 0)
      Panic ("SetUpHwParams: Unable to set access mode");
   if (snd_pcm_hw_params_set_format (Handle, HwParams, SampleFormat) < 0)
      Panic ("SetUpHwParams: Unable to set sample format");
   if (snd_pcm_hw_params_set_channels (Handle, HwParams, 2) < 0)
      Panic ("SetUpHwParams: Unable to set number of channels");
   if (snd_pcm_hw_params_set_rate (Handle, HwParams, SampleRate, 0) < 0)
      Panic ("SetUpHwParams: Unable to set sample rate");
   if (snd_pcm_hw_params_set_buffer_size (Handle, HwParams, BfrSize) < 0)
      Panic ("SetUpHwParams: Unable to set buffer size");
   if (snd_pcm_hw_params_set_period_size (
         Handle, HwParams, PeriodSize, 0) < 0)
      Panic ("SetUpHwParams: Unable to set period size");
   if (snd_pcm_hw_params (Handle, HwParams) < 0)
      Panic ("SetUpHwParams: Unable to write HwParams to device");
   snd_pcm_hw_params_free (HwParams);  // free HwParams structure
}  // end SetUpHwParams

void SetUpSwParams (snd_pcm_t* Handle) {
   snd_pcm_sw_params_t* SwParams;
   if (snd_pcm_sw_params_malloc (&SwParams) < 0)
      Panic ("SetUpSwParams: Unable to allocate SwParam structure");
   if (snd_pcm_sw_params_current (Handle, SwParams) < 0)
      Panic ("SetUpSwParams: Unable to retrieve current SwParams");
   if (snd_pcm_sw_params_set_start_threshold (
         Handle, SwParams, MaxInt32Value) < 0)  // use manual start/stop
      Panic ("SetUpSwParams: Unable to set (maximal) start threshold");
   if (snd_pcm_sw_params_set_avail_min (Handle, SwParams, PeriodSize) < 0)
      Panic ("SetUpSwParams: Unable to set notification threshold");
   if (snd_pcm_sw_params_set_xfer_align (Handle, SwParams, PeriodSize) < 0)
      Panic ("SetUpSwParams: Unable to set transfer alignment");
   if (snd_pcm_sw_params (Handle, SwParams) < 0)
      Panic ("SetUpSwParams: Unable to write SwParams to device");
   snd_pcm_sw_params_free (SwParams);  // free SwParams structure
}  // end SetUpSwParams

//***************************************************************
// *** LEVEL 1 ***

main (int argc, char *argv[]) {
   snd_pcm_sframes_t FramesAvail;

   if (snd_pcm_open (&CapHndl,
         AlsaCodec, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK) < 0)
      Panic ("??? Unable to open PCM Capture Stream");
   if (snd_pcm_open (&PbHndl,
         AlsaCodec, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0)
      Panic ("??? Unable to open PCM Playback Stream");

   SetUpHwParams (CapHndl, 50);  SetUpHwParams (PbHndl, 50);
   SetUpSwParams (CapHndl);  SetUpSwParams (PbHndl);

   // Prepare operations may not be required ...
   if (snd_pcm_prepare (CapHndl) < 0)
      Panic ("??? Unable to prepare PCM Capture Stream");
//   if (snd_pcm_prepare (PbHndl) < 0)
//      Panic ("??? Unable to prepare PCM Playback Stream");

   if (snd_pcm_start(CapHndl) < 0)
      Panic ("??? Unable to start PCM Capture Stream");

   if ((FramesAvail = snd_pcm_avail_update (CapHndl)) < 0) {
      fprintf (stderr, "pcm_avail_update failed (%s)\n", snd_strerror (FramesAvail)); 
//      Panic ("PCM Capture frames not available");
      }      

   fprintf (stderr, "Frames Avail are %d\n", FramesAvail);

   snd_pcm_close (CapHndl);  snd_pcm_close (PbHndl);
   exit (0);
}  // end main


[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

             reply	other threads:[~2007-09-13 22:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-13 22:55 J. Scott Merritt [this message]
2007-09-14 16:26 ` SALSA: snd_pcm_avail_update J. Scott Merritt

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=20070913185555.35445b93.alsauser@pragmasoft.com \
    --to=alsauser@pragmasoft.com \
    --cc=alsa-devel@alsa-project.org \
    /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.