All of lore.kernel.org
 help / color / mirror / Atom feed
* SALSA: snd_pcm_avail_update
@ 2007-09-13 22:55 J. Scott Merritt
  2007-09-14 16:26 ` J. Scott Merritt
  0 siblings, 1 reply; 2+ messages in thread
From: J. Scott Merritt @ 2007-09-13 22:55 UTC (permalink / raw)
  To: alsa-devel

[-- 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

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

* Re: SALSA: snd_pcm_avail_update
  2007-09-13 22:55 SALSA: snd_pcm_avail_update J. Scott Merritt
@ 2007-09-14 16:26 ` J. Scott Merritt
  0 siblings, 0 replies; 2+ messages in thread
From: J. Scott Merritt @ 2007-09-14 16:26 UTC (permalink / raw)
  To: alsa-devel

On Thu, 13 Sep 2007 18:55:55 -0400
"J. Scott Merritt" <alsauser@pragmasoft.com> wrote:

> 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.
> 

After further investigation ... it appears that snd_pcm_open() in
salsa-lib-0.0.11:pcm.c is not properly recording/initializing the
pcm->stream field.

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

end of thread, other threads:[~2007-09-14 16:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-13 22:55 SALSA: snd_pcm_avail_update J. Scott Merritt
2007-09-14 16:26 ` J. Scott Merritt

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.