http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sound - Adlib/SB/PC Speaker



>From: Lionel Pinkhard <lionelp@worldonline.co.za>
>Reply-To: gameprogrammer@gameprogrammer.com
>To: gameprogrammer@gameprogrammer.com
>Subject: Re: Sound - Adlib/SB/PC Speaker
>Date: Tue, 01 Jan 1980 05:19:17 +0000 (UTC)
>
>Hi,
>
>Yes, I was aware of that, however, what should I do if I want to make a
>quick sound, like for a game? Instead of playing a whole sound file? I
>know most modern games use sound files to store their sounds anyway, but
>what is the simplest form of a sound in Linux? (Or is this it?)

If you want to use the soundcard, Yes, writing some data to /dev/audio is 
the simplest way. (All IO is simple under linux)

>
>Thanks for that info! I'll definitely check it out!
>
>Sure, no problem, I've done it under Dos, just a little practise on driver
>programming, and I'll have it running under Linux, thanks for the idea!
>:-) But would this just be simply turning the speaker on and off rapidly,
>or would I use the PIT chip or something?

I'm afraid I don't know what the PIT chip is - I have also programmed the 
PC-speaker under DOS, but I can't remember exactly how it is done.  All I 
remember is that it uses digital waves at different freqs to generate 
vibrations, rather than doing a proper D-to-A conversion.

>No sorry, I was a little confused there, I just meant to play sound
>directly from the program instead of from an audio file, but now that I
>think of it, wouldn't it be possible (it seems anyway) to have a piece of
>audio code in your program, and then send it to /dev/audio?

Yes.

>But my main
>concern is: What would the format of this be? I mean, what do I send to
>make a sound? A simple example would be appreciated!

What you send to make a sound is the raw digital input for a codec. Your 
going to have to experiment and see what you get.  Try writing long blocks 
(like 1K) of every number from 0x0 to 0xFFFF and see what it sounds like. 
something like:

fd = open("/dev/audio");

for (short i=0; i < 0xFFFF; i++)
	for( short j=0; j< 1024; j++
		write( fd, &i, sizeof(i) );

DISCLAIMER: the above is pseudo-code

should do the trick.  If your really interested, the only way to be sure is 
to look at other ppl's code, and there is plenty of other ppl's code 
available for linux.  Of course, also be aware that while the above should 
work with 16 bit cards, you might need to use a larger data type or an array 
for better hardware - but I don't know, maybe drivers deal with that 
automatically, i've never _really_ gotten into sound.

For user space code to examine, check out XMMS - although it could be a 
nightmare to cut through all the UI stuff and find the backend code that 
does all the work.

- Ben

>
>Ciao,
>
>Lionel

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.

=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html