All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Peters <epeters@graphics.cs.uni-sb.de>
To: alsa-devel@lists.sourceforge.net
Subject: Starting the device manually
Date: Mon, 24 Jul 2006 11:37:56 +0200	[thread overview]
Message-ID: <44C494F4.6050301@graphics.cs.uni-sb.de> (raw)

Dear all,

I'm a bit confused by the alsa documentation. I want to fill up a buffer
of a alsa device with snd_pcm_writei and then if the buffer is full, I
want to be able to start the playback manually. By looking to the
documentation, I found the method snd_pcm_sw_params_set_start_threshold.
In some other messages on this list there was the hint to set this
threshhold larger than the max_buffer_size and then the device shouldn't
start automatically. So I've done. But unfortunately the playback starts
again automatically. Here are the lines of code, I'm setting the
buffer_size and period_size and the start threshhold:

/* determine the buffer size */
if (buffer_time == 0 && buffer_frames == 0) {
   if( snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, 0)
< 0) {
     return -1;
   }
   if (buffer_time > 500000) {
     buffer_time = 500000;
   }
}

/* calculating the period size depending on the buffer size */
if (period_time == 0 && period_frames == 0) {
   if (buffer_time > 0) {
     period_time = buffer_time / 4;
   } else {
     period_frames = buffer_frames / 4;
   }
}

/* setting the period size according to the buffer size */
if (period_time > 0) {
   if (snd_pcm_hw_params_set_period_time_near(pcm_handle, hwparams,
&period_time, 0) < 0) {
     return -1;
   }
} else {
   if ( snd_pcm_hw_params_set_period_size_near(pcm_handle, hwparams,
&period_frames, 0) < 0) {
     return -1;
   }
}

/* setting the buffer size */
if (buffer_time > 0) {
   if (snd_pcm_hw_params_set_buffer_time_near(pcm_handle, hwparams,
&buffer_time, 0) < 0) {
     return -1;
   }
} else {
   if ( snd_pcm_hw_params_set_buffer_size_near(pcm_handle, hwparams,
&buffer_frames) < 0) {
     return -1;
   }
}

/* calculating the number of frames of a buffer and a period */
buffer_frames = buffer_time * sample_rate;
period_frames = period_time * sample_rate;


/* setting the start threshhold in frames */
int err = 0;
/*Init swparams */
if ((err = snd_pcm_sw_params_malloc (&swparams)) < 0) {
   return -1;
}

if ((err = snd_pcm_sw_params_current(pcm_handle, swparams)) < 0) {
   return -1;
}

if ((err = snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams,
2*buffer_frames)) < 0) {
   return FAILURE;
}

err = snd_pcm_sw_params(pcm_handle, swparams);
if (err < 0) {
   return -1;
}

Here are some specifications of the system I'm using:

- SuSE 9.3 with all updates and patches
- ALSA version 1.0.9a
- sound board Audigy 4 PRO [SB0380]
- chip SigmaTel STAC9750,51

Now some questions:
- Where is the failure in my implementation?
- I think, if I don't call snd_pcm_start there should be no output if
the start threshold is larger than the max_buffer_size. Is this correct?
- Is it possible that the starting behaviour depends on the hardware I'm
using?
- Do you have other hints so I can start my playback manually on a
timepoint I want?

Best regards,
Eric


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

             reply	other threads:[~2006-07-24  9:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-24  9:37 Eric Peters [this message]
2006-07-24 11:05 ` Starting the device manually Clemens Ladisch
2006-07-24 11:40   ` Eric Peters
2006-08-04 16:44     ` Clemens Ladisch
2006-07-24 15:35 ` James Courtier-Dutton
2006-07-25  6:20   ` Eric Peters
2006-07-24 15:37 ` James Courtier-Dutton

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=44C494F4.6050301@graphics.cs.uni-sb.de \
    --to=epeters@graphics.cs.uni-sb.de \
    --cc=alsa-devel@lists.sourceforge.net \
    /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.