Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Question Regarding Simple ALSA Stereo Output
@ 2004-06-23 13:57 Bill Kapralos
  2004-06-23 14:45 ` Clemens Ladisch
  2004-06-23 15:44 ` James Courtier-Dutton
  0 siblings, 2 replies; 8+ messages in thread
From: Bill Kapralos @ 2004-06-23 13:57 UTC (permalink / raw)
  To: alsa-devel

Hello

I am failry new to Linux programming and recently started using the ALSA
API for some software I am writing involving the output of sound to a apir
of headphones. Using (and slightly modifying) a simple example found on
the ALSA web site (Matthias Nagorni, "ALSA 0.9.0 Howto") I am able to
open the auduio port and send data to it however,  I am having some
difficulty with the output of stereo data.  In particular, I am
initializing the device for interleaved output (e.g.
SND_PCM_ACCESS_RW_INTERLEAVED) and specifying two channels (at 16 bit
little endian format).  I then have some stereo data (which I "create"
which is in interleaved format (e.g. first word (2-byte sample) is for the
left channel, second for the right channel, third for the left etc... but
when i do send this data to the audio device (using the "writei" function,
I do not get the desired result.  It appears as if it is simply outputting
the data assuming one channel e.g. the same signal is heard in both the
left and right ear even when I have deliberately made the signals
different (e.g. introduced a considerable delay to one channel etc.).
Furthermore, when I explicitly set all left channel samples to "0" and the
right channel samples to "non-zero", no sound is heard at all - it seems
as if only the left channel data is being output which is of course all
zero.  In contrast, if i set all the right channel samples to zero and the
left channel samples to non-zero, the sound is heard.

I am really confused with this problem! It appears as if I cannot control
what is sent to the left/right channel! Am i completely overlooking
something here? I am really puzzled by what I initially thought of as a
trivial matter!!!

Any help would be greatly appreciated! Thank You in advance!

Please reply to: billkATcs.yorku.ca (of course replace "AT" with "@".

Regards,


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

* Re: Question Regarding Simple ALSA Stereo Output
  2004-06-23 13:57 Question Regarding Simple ALSA Stereo Output Bill Kapralos
@ 2004-06-23 14:45 ` Clemens Ladisch
  2004-06-23 15:04   ` Bill Kapralos
  2004-06-23 15:44 ` James Courtier-Dutton
  1 sibling, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2004-06-23 14:45 UTC (permalink / raw)
  To: Bill Kapralos; +Cc: alsa-devel

Bill Kapralos wrote:
> It appears as if it is simply outputting the data assuming one
> channel e.g. the same signal is heard in both the left and right
> ear even when I have deliberately made the signals different (e.g.
> introduced a considerable delay to one channel etc.). Furthermore,
> when I explicitly set all left channel samples to "0" and the
> right channel samples to "non-zero", no sound is heard at all - it
> seems as if only the left channel data is being output which is of
> course all zero.  In contrast, if i set all the right channel
> samples to zero and the left channel samples to non-zero, the
> sound is heard.

Does the function snd_pcm_hw_params_set_channels() return an error?

What is output when you add the following code after the call to
snd_pcm_hw_params():

	snd_output_t *out;
	...
	snd_output_stdio_attach(&out, stdout, 0);
	snd_pcm_dump_hw_setup(pcm, out);
	snd_output_close(out);

What hardware do you use?


Regards,
Clemens




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

* Re: Question Regarding Simple ALSA Stereo Output
  2004-06-23 14:45 ` Clemens Ladisch
@ 2004-06-23 15:04   ` Bill Kapralos
  2004-06-23 15:18     ` Clemens Ladisch
  2004-06-23 16:50     ` James Courtier-Dutton
  0 siblings, 2 replies; 8+ messages in thread
From: Bill Kapralos @ 2004-06-23 15:04 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

Hi Clemens

Thanks for the prompt response!

Should have mentioned this in the original email however I am using an SGI
"box" wit dual Pentium III processors running SuSe Linux with a
(VT82C686 ACER AC97 Audio Controller).  The card does support stereo and I
can successfully set the number of channels to two (using
snd_pcm_hw_params_set_channels() ).  After adding the code you suggested,
the following was output:

 stream       : PLAYBACK
 access       : RW_INTERLEAVED
 format       : S16_LE
 subformat    : STD
 channels     : 2
 rate         : 44100
 exact rate   : 44100 (44100/1)
 msbits       : 16
 buffer_size  : 20480
 period_size  : 2048
 period_time  : 46438
 tick_time    : 10000

Once again, thanks for the response!

Regards,

================================================

On Wed, 23 Jun 2004, Clemens Ladisch wrote:

> Bill Kapralos wrote:
> > It appears as if it is simply outputting the data assuming one
> > channel e.g. the same signal is heard in both the left and right
> > ear even when I have deliberately made the signals different (e.g.
> > introduced a considerable delay to one channel etc.). Furthermore,
> > when I explicitly set all left channel samples to "0" and the
> > right channel samples to "non-zero", no sound is heard at all - it
> > seems as if only the left channel data is being output which is of
> > course all zero.  In contrast, if i set all the right channel
> > samples to zero and the left channel samples to non-zero, the
> > sound is heard.
>
> Does the function snd_pcm_hw_params_set_channels() return an error?
>
> What is output when you add the following code after the call to
> snd_pcm_hw_params():
>
> 	snd_output_t *out;
> 	...
> 	snd_output_stdio_attach(&out, stdout, 0);
> 	snd_pcm_dump_hw_setup(pcm, out);
> 	snd_output_close(out);
>
> What hardware do you use?
>
>
> Regards,
> Clemens
>
>
>


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

* Re: Question Regarding Simple ALSA Stereo Output
  2004-06-23 15:04   ` Bill Kapralos
@ 2004-06-23 15:18     ` Clemens Ladisch
  2004-06-23 16:50     ` James Courtier-Dutton
  1 sibling, 0 replies; 8+ messages in thread
From: Clemens Ladisch @ 2004-06-23 15:18 UTC (permalink / raw)
  To: Bill Kapralos; +Cc: alsa-devel

Bill Kapralos wrote:
> The card does support stereo and I can successfully set the number
> of channels to two (using snd_pcm_hw_params_set_channels() ).
> After adding the code you suggested, the following was output:
> ...
>  channels     : 2

Looks as if there's nothing wrong with your program.

> I am using an SGI "box" wit dual Pentium III processors running
> SuSe Linux with a (VT82C686 ACER AC97 Audio Controller).

Probably the AC'97 codec is configured for mono output.  What codec do
you have?  (see second line at top of alsamixer screen)  What are the
mixer settings?  (see /etc/asound.state after running "alsactl store")


Regards,
Clemens




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

* Re: Question Regarding Simple ALSA Stereo Output
  2004-06-23 13:57 Question Regarding Simple ALSA Stereo Output Bill Kapralos
  2004-06-23 14:45 ` Clemens Ladisch
@ 2004-06-23 15:44 ` James Courtier-Dutton
  1 sibling, 0 replies; 8+ messages in thread
From: James Courtier-Dutton @ 2004-06-23 15:44 UTC (permalink / raw)
  To: Bill Kapralos; +Cc: alsa-devel

Bill Kapralos wrote:
> Hello
> 
> I am failry new to Linux programming and recently started using the ALSA
> API for some software I am writing involving the output of sound to a apir
> of headphones. Using (and slightly modifying) a simple example found on
> the ALSA web site (Matthias Nagorni, "ALSA 0.9.0 Howto") I am able to
> open the auduio port and send data to it however,  I am having some
> difficulty with the output of stereo data.  In particular, I am
> initializing the device for interleaved output (e.g.
> SND_PCM_ACCESS_RW_INTERLEAVED) and specifying two channels (at 16 bit
> little endian format).  I then have some stereo data (which I "create"
> which is in interleaved format (e.g. first word (2-byte sample) is for the
> left channel, second for the right channel, third for the left etc... but
> when i do send this data to the audio device (using the "writei" function,
> I do not get the desired result.  It appears as if it is simply outputting
> the data assuming one channel e.g. the same signal is heard in both the
> left and right ear even when I have deliberately made the signals
> different (e.g. introduced a considerable delay to one channel etc.).
> Furthermore, when I explicitly set all left channel samples to "0" and the
> right channel samples to "non-zero", no sound is heard at all - it seems
> as if only the left channel data is being output which is of course all
> zero.  In contrast, if i set all the right channel samples to zero and the
> left channel samples to non-zero, the sound is heard.
> 
> I am really confused with this problem! It appears as if I cannot control
> what is sent to the left/right channel! Am i completely overlooking
> something here? I am really puzzled by what I initially thought of as a
> trivial matter!!!
> 
> Any help would be greatly appreciated! Thank You in advance!
> 
> Please reply to: billkATcs.yorku.ca (of course replace "AT" with "@".
> 
> Regards,
> 
> 

Please post your code to a url so we can look at it.
Alternatively, look at the sample code in
./alsa-lib/test/pcm.c
or
./alsa-utils/speaker-test/speaker-test.c

Cheers
James


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

* Re: Question Regarding Simple ALSA Stereo Output
       [not found] <Pine.GSO.4.58.0406231129100.6839@blue.cs.yorku.ca>
@ 2004-06-23 16:10 ` Clemens Ladisch
  0 siblings, 0 replies; 8+ messages in thread
From: Clemens Ladisch @ 2004-06-23 16:10 UTC (permalink / raw)
  To: Bill Kapralos; +Cc: alsa-devel

Bill Kapralos wrote:
>                 name 'Master Playback Switch'
>                 value true
>                 name 'Master Playback Volume'
>                 value.0 63
>                 value.1 63
>                 name 'Headphone Playback Switch'
>                 value true
>                 name 'Headphone Playback Volume'
>                 value.0 31
>                 value.1 31

Looks OK.

>                 name 'Master Mono Playback Switch'
>                 value true
>                 name 'Master Mono Playback Volume'
>                 value 31

Try muting this.

>  Chip: Analog Devices AD1881

This chip has some funky features to allow different sample rates for
left and right channels.  Please show the contents of
/proc/asound/card0/codec97#0/ac97#0-0+regs.


Regards,
Clemens




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

* Re: Question Regarding Simple ALSA Stereo Output
  2004-06-23 15:04   ` Bill Kapralos
  2004-06-23 15:18     ` Clemens Ladisch
@ 2004-06-23 16:50     ` James Courtier-Dutton
  1 sibling, 0 replies; 8+ messages in thread
From: James Courtier-Dutton @ 2004-06-23 16:50 UTC (permalink / raw)
  To: Bill Kapralos; +Cc: Clemens Ladisch, alsa-devel

Bill Kapralos wrote:
> Hi Clemens
> 
> Thanks for the prompt response!
> 
> Should have mentioned this in the original email however I am using an SGI
> "box" wit dual Pentium III processors running SuSe Linux with a
> (VT82C686 ACER AC97 Audio Controller).  The card does support stereo and I
> can successfully set the number of channels to two (using
> snd_pcm_hw_params_set_channels() ).  After adding the code you suggested,
> the following was output:
> 
>  stream       : PLAYBACK
>  access       : RW_INTERLEAVED
>  format       : S16_LE
>  subformat    : STD
>  channels     : 2
>  rate         : 44100
>  exact rate   : 44100 (44100/1)
>  msbits       : 16
>  buffer_size  : 20480
>  period_size  : 2048
>  period_time  : 46438
>  tick_time    : 10000
> 
> Once again, thanks for the response!
> 
> Regards,
> 
> ================================================
> 
> On Wed, 23 Jun 2004, Clemens Ladisch wrote:
> 
> 
>>Bill Kapralos wrote:
>>
>>>It appears as if it is simply outputting the data assuming one
>>>channel e.g. the same signal is heard in both the left and right
>>>ear even when I have deliberately made the signals different (e.g.
>>>introduced a considerable delay to one channel etc.). Furthermore,
>>>when I explicitly set all left channel samples to "0" and the
>>>right channel samples to "non-zero", no sound is heard at all - it
>>>seems as if only the left channel data is being output which is of
>>>course all zero.  In contrast, if i set all the right channel
>>>samples to zero and the left channel samples to non-zero, the
>>>sound is heard.
>>
>>Does the function snd_pcm_hw_params_set_channels() return an error?
>>
>>What is output when you add the following code after the call to
>>snd_pcm_hw_params():
>>
>>	snd_output_t *out;
>>	...
>>	snd_output_stdio_attach(&out, stdout, 0);
>>	snd_pcm_dump_hw_setup(pcm, out);
>>	snd_output_close(out);
>>
>>What hardware do you use?
>>
>>
>>Regards,
>>Clemens
>>
>>

Which device name are you opening?
Try using "plug:front" as the device name in snd_pcm_open()

James




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

* Re: Question Regarding Simple ALSA Stereo Output
       [not found] <E1Bd8zp-00028B-03@sc8-sf-list2.sourceforge.net>
@ 2004-06-23 22:11 ` Tom Watson
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Watson @ 2004-06-23 22:11 UTC (permalink / raw)
  To: alsa-devel

James Courtier-Dutton <James@superbug.demon.co.uk> Wrote:
<<<deletia>>>

> Alternatively, look at the sample code in
> ../alsa-lib/test/pcm.c
> or
> ../alsa-utils/speaker-test/speaker-test.c

> Cheers
> James

While I have seen .../test/pcm.c I have not seen 'speaker-test.c'.  A
quick 'find' did not yield it either.  Is this something new??

Inquiring minds.......

I think it would be welcome in any event to be part of the ALSA tree.



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


	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com

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

end of thread, other threads:[~2004-06-23 22:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-23 13:57 Question Regarding Simple ALSA Stereo Output Bill Kapralos
2004-06-23 14:45 ` Clemens Ladisch
2004-06-23 15:04   ` Bill Kapralos
2004-06-23 15:18     ` Clemens Ladisch
2004-06-23 16:50     ` James Courtier-Dutton
2004-06-23 15:44 ` James Courtier-Dutton
     [not found] <Pine.GSO.4.58.0406231129100.6839@blue.cs.yorku.ca>
2004-06-23 16:10 ` Clemens Ladisch
     [not found] <E1Bd8zp-00028B-03@sc8-sf-list2.sourceforge.net>
2004-06-23 22:11 ` Tom Watson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox