All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Watson <sdc695@yahoo.com>
To: Carlo Wood <carlo@alinoe.com>, tsw@johana.com
Cc: alsa development <alsa-devel@lists.sourceforge.net>
Subject: Re: I thought it would simple....
Date: Wed, 23 Jul 2003 22:03:25 -0700 (PDT)	[thread overview]
Message-ID: <20030724050325.3325.qmail@web21501.mail.yahoo.com> (raw)
In-Reply-To: <20030723110750.GA2492@alinoe.com>

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

OK, here is more data.  The enclosed files are:
1) The "minimal playback program" described in the original message,
modified to clear the buffer, and do the "dump" of the parameters.  The
buffer size is lengthened a bit (maybe this makes a difference??)
2) The output of 'strace' on the program, it stops at the 'poll'
instruction (broken out with a ^c at the terminal).
3) A cut/pasted copy of the output sent to the terminal.  In
particular, it has the output from "snd_pcm_dump" which ought to help a
bit.

The source was compiled with 'cc simple.c -lasound -o simple'.
It was executed with './simple surround40'.

I think I'm doing everything OK, and if I solve this goodie (on the
simple program), I suspect tha I can solve the problem with my program.

P.S.  The sound card is a Turtle Beach Santa Cruz.  It can handle the 4
channel things OK (I used 'aplay' very nicely!!)

While the C++ program is nice, I'm not really into that.  It seemed to
work OK (as given).  My program is C, thus the enclosed files.

Maybe there is a solution out there.

Thanks to all.  ALSA is the way of the future!!

--- Carlo Wood <carlo@alinoe.com> wrote:
> I found that a better example for playback is
> the 'pcm.c' file that you can find on the alsa site.
> It contains many ways to deliver the data (a nice
> sine) to your soundcard.  Playing with the parameters
> gives some insight (more than reading the overall poor
> documentation imho :().
> 
<<<deletia>>>
> On Tue, Jul 22, 2003 at 11:54:49PM -0700, Tom Watson wrote:
> > I am attempting to write a "simple" audio playback program.  Well,
> I
> > thought it would be, but...
> > Somehow (thru strace) the 'snd_pcm_writei' call goes and eventually
> > does a system 'poll' call, but it doesn't return indicating that a
> > write is OK to do.
> > I've used similar parameters in 'aplay' and I see that it works.
> > 
> > The basis of the program I'm writing is the one described in _A
> > Tutorial on Using the ALSA API_
> > (http://equalarea.com/paul/alsa-audio.html), section entitled "A
> > Minimal Playback Program".
> > 
> > One thing I've noted:  Some of the data printed out by
> "snd_pcm_dump"
> > is different between my program and 'aplay'.  I suspect that there
> is a
> > clue somewhere, but what is the "magic"??
> > 
> > If necessary, I can provide the 'strace' or the output from
> > 'snd_pcm_dump', but in the interest of brevity...
> > 
> > Any "great clue" would be appreciated.
<<<deletia of C++ program...>>>

=====
-- 
Tom Watson
tsw@johana.com

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alsa/asoundlib.h>
#define CHAN 4
#define BSIZ 4096	/* Number of frames */
main (int argc, char *argv[])
{
int i;
int err;
short buf[CHAN * BSIZ];
snd_pcm_t *playback_handle;
snd_pcm_hw_params_t *hw_params;
snd_output_t *log;              /* For the log goodie */

/* Just set it to something empty */
memset (buf, 0, sizeof(buf));
if ((err = snd_pcm_open (&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
	fprintf (stderr, "cannot open audio device %s (%s)\n", 
	 argv[1], 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 (playback_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 (playback_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 (playback_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 (playback_handle, hw_params, 44100, 0)) < 0) {
	fprintf (stderr, "cannot set sample rate (%s)\n",
	 snd_strerror (err));
	exit (1);
	}

if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, CHAN)) < 0) {
	fprintf (stderr, "cannot set channel count (%s)\n",
	 snd_strerror (err));
	exit (1);
	}

if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
	fprintf (stderr, "cannot set parameters (%s)\n",
	 snd_strerror (err));
	exit (1);
	}
err = snd_output_stdio_attach(&log, stderr, 0);
if (err < 0)
	{
	fprintf (stderr, "Can\'t do stdio attach (%d)\n", err);
	exit (1);
	}
snd_pcm_dump (playback_handle, log);
      
/* snd_pcm_hw_params_free (hw_params); */

if ((err = snd_pcm_prepare (playback_handle)) < 0) {
	fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
	 snd_strerror (err));
	exit (1);
	}

for (i = 0; i < 10; ++i) {
	if ((err = snd_pcm_writei (playback_handle, buf, BSIZ)) != BSIZ) {
		fprintf (stderr, "write to audio interface failed (%s)\n",
			 snd_strerror (err));
		exit (1);
		}
	}

snd_pcm_close (playback_handle);
exit (0);
}


[-- Attachment #3: simple.tr --]
[-- Type: application/x-troff, Size: 26330 bytes --]

[-- Attachment #4: simple.sout --]
[-- Type: application/octet-stream, Size: 1682 bytes --]

Multi PCM

Channel bindings:
0: slave 0, channel 0
1: slave 0, channel 1
2: slave 1, channel 0
3: slave 1, channel 1

Its setup is:
stream       : PLAYBACK
access       : RW_INTERLEAVED
format       : S16_LE
subformat    : STD
channels     : 4
rate         : 44100
exact rate   : 44100 (44100/1)
msbits       : 16
buffer_size  : 8192
period_size  : 8
period_time  : 181
tick_time    : 10000
tstamp_mode  : NONE
period_step  : 1
sleep_min    : 0
avail_min    : 8
xfer_align   : 8
start_threshold  : 1
stop_threshold   : 8192
silence_threshold: 0
silence_size : 0
boundary     : 1073741824

Slave #0: Hardware PCM card 0 'Sound Fusion CS46xx' device 0 subdevice 0

Its setup is:
stream       : PLAYBACK
access       : MMAP_INTERLEAVED
format       : S16_LE
subformat    : STD
channels     : 2
rate         : 44100
exact rate   : 44100 (44100/1)
msbits       : 16
buffer_size  : 8192
period_size  : 8
period_time  : 181
tick_time    : 10000
tstamp_mode  : NONE
period_step  : 1
sleep_min    : 0
avail_min    : 8
xfer_align   : 8
start_threshold  : 1
stop_threshold   : 8192
silence_threshold: 0
silence_size : 0
boundary     : 1073741824

Slave #1: Hardware PCM card 0 'Sound Fusion CS46xx' device 1 subdevice 0

Its setup is:
stream       : PLAYBACK
access       : MMAP_INTERLEAVED
format       : S16_LE
subformat    : STD
channels     : 2
rate         : 44100
exact rate   : 44100 (44100/1)
msbits       : 16
buffer_size  : 8192
period_size  : 8
period_time  : 181
tick_time    : 10000
tstamp_mode  : NONE
period_step  : 1
sleep_min    : 0
avail_min    : 8
xfer_align   : 8
start_threshold  : 1
stop_threshold   : 8192
silence_threshold: 0
silence_size : 0
boundary     : 1073741824

  reply	other threads:[~2003-07-24  5:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-23  6:54 I thought it would simple Tom Watson
2003-07-23 11:07 ` Carlo Wood
2003-07-24  5:03   ` Tom Watson [this message]
2003-07-24 13:48     ` Takashi Iwai
2003-08-11 21:30       ` Tom Watson

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=20030724050325.3325.qmail@web21501.mail.yahoo.com \
    --to=sdc695@yahoo.com \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=carlo@alinoe.com \
    --cc=tsw@johana.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.