473,757 Members | 10,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sound programming

Hello

I've got interested in learning some basic sound programming bits in
C... mainly I want to know how to go about accessing the sound devices -
reading from them mainly - in windows and linux... I'd kind of like to be
able to do it without a whole bunch of extra garbage added in there - by
this I mean that I know in windows there are a million sound programming
packages that make the whole process "easier" - there are also a few in
linux but I think the raw stuff I'm interested in understanding is a bit
more simple in linux b/c of the way devices work in it.

So if anyone can point me at a place to start - maybe some really raw
source code for linux and windows - I would really appreciate it.

Thanks!

Jul 7 '08 #1
4 4594
"kid joe" <sp******@spamt rap.invalidwrot e in message
I've got interested in learning some basic sound programming bits in
C... mainly I want to know how to go about accessing the sound devices -
reading from them mainly - in windows and linux... I'd kind of like to be
able to do it without a whole bunch of extra garbage added in there - by
this I mean that I know in windows there are a million sound programming
packages that make the whole process "easier" - there are also a few in
linux but I think the raw stuff I'm interested in understanding is a bit
more simple in linux b/c of the way devices work in it.

So if anyone can point me at a place to start - maybe some really raw
source code for linux and windows - I would really appreciate it.
It is rather more involved than you think.

The problem is that audio devices need to be fed a continuous stream of raw
bits, whilst generally you want the processor to spend most of its time
dealing with the rest of the program, like moving space invaders about the
screen.

So unless you want to do difficult multi-tasking programming at the device
level, you need a certain layer of abstraction. the question then becomes
"which one?". For space invaders you can probably get away with an interface
that says "play sound". It puts a bleep or an explosion into the audio
queue, return scontro, to you almost immediately, and a millesecond or so
later you'll hear the sound on the speakers.
For a more advanced use of audio, this isn't sufficient. You'll want to be
able to cancel jobs, to submit long sequences instead of tiny clips, to
change the volume, to stream sound in from a backing store, maybe to
synthesise samples on the fly.

So it becomes difficult to know what level of abstration to use. Too low and
you're doing messy parallel programming, too high and you're calling Midi
instruments and the like when you just want to say "play this".

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jul 7 '08 #2

"Malcolm McLean" <re*******@btin ternet.comwrote in message
news:e8******** *************** *******@bt.com. ..
"kid joe" <sp******@spamt rap.invalidwrot e in message
>I've got interested in learning some basic sound programming bits in
C... mainly I want to know how to go about accessing the sound devices -
reading from them mainly - in windows and linux... I'd kind of like to be
able to do it without a whole bunch of extra garbage added in there - by
this I mean that I know in windows there are a million sound programming
packages that make the whole process "easier" - there are also a few in
linux but I think the raw stuff I'm interested in understanding is a bit
more simple in linux b/c of the way devices work in it.

So if anyone can point me at a place to start - maybe some really raw
source code for linux and windows - I would really appreciate it.
It is rather more involved than you think.

The problem is that audio devices need to be fed a continuous stream of
raw bits, whilst generally you want the processor to spend most of its
time dealing with the rest of the program, like moving space invaders
about the screen.
yes, and sadly, getting this write without blocking the app (or causing
annoying auditory artifacts) is a little harder than it may seem (or at
least for single-threaded apps).
So unless you want to do difficult multi-tasking programming at the device
level, you need a certain layer of abstraction. the question then becomes
"which one?". For space invaders you can probably get away with an
interface that says "play sound". It puts a bleep or an explosion into the
audio queue, return scontro, to you almost immediately, and a millesecond
or so later you'll hear the sound on the speakers.
For a more advanced use of audio, this isn't sufficient. You'll want to be
able to cancel jobs, to submit long sequences instead of tiny clips, to
change the volume, to stream sound in from a backing store, maybe to
synthesise samples on the fly.

So it becomes difficult to know what level of abstration to use. Too low
and you're doing messy parallel programming, too high and you're calling
Midi instruments and the like when you just want to say "play this".
a generally workable approach I had found was to implement a mixer, which
created temporary "mix streams". these streams basically just provided a
means for the mixer to demand a certain number of samples. the streams
themselves had a various info (current origin, spatial velocity, ...)
allowing for effects like doppler shifting (as well as just the "things are
quieter when far away" effect).

these were typically structs making use of callbacks.

playing a sound typically involved creating a stream with the right
properties (handled automatically by various "play a sound") functions, the
stream typically automatically destroying itself when done.

the interface also worked fairly well with playing audio from videos, and
from songs in the form of mp3s (typically, sound effects are just buffered
into ram, but songs are better streamed since they can take a decent-sized
chunk of memory to store).

whatever else can be played so long as the right callbacks could be
provided.
note: callbacks may be passed a chunk of "user data" (as well as a stream
id), which is another useful trick here, and is put in the struct when
creating the stream. this is usually a pointer holding whatever it is the
stream-specific functions feel is important (GTK does similar...).
also note:
as an interesting effect of having doppler shifting and other effects, not
all of the streams may be strictly temporally in-sync, since moving away
from a stream causes it to be played slower and moving towards it makes it
play faster (I make sounds just "cut out" near mach-1, since otherwise there
are annoying zero-division issues).

a related trick was to add a delay calculated from the distance of the sound
from the camera, such that, say, a distant explosion will take a little
while for the sound to hit (first we see the explosion, and then the sound
hits a short time later).

note that as an effect of the geometry: when one is far away from an audio
source they are out of sync with it (temporally and possibly also in terms
of rate), but as they move closer the sync is regained, such that upon
reaching the source it is playing more or less in realtime (and other
sources they were nearby originally have moved out of sync).

....

one notable lacking effect though is echo-modeling (or dealing with sounds
being otherwise blocked or distorted by geometry), since this is
computationally expensive (an "echo effect", "dampen effect", ... being much
cheaper).

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jul 8 '08 #3
kid joe wrote:
Hello

I've got interested in learning some basic sound programming bits in
C... mainly I want to know how to go about accessing the sound devices -
reading from them mainly - in windows and linux... I'd kind of like to be
able to do it without a whole bunch of extra garbage added in there - by
this I mean that I know in windows there are a million sound programming
packages that make the whole process "easier" - there are also a few in
linux but I think the raw stuff I'm interested in understanding is a bit
more simple in linux b/c of the way devices work in it.

So if anyone can point me at a place to start - maybe some really raw
source code for linux and windows - I would really appreciate it.

Thanks!
Sound programming in C is involved and highly system dependent. A cross
platform helper library would _be_ "a bunch of garbage added in there", and
would not (nessescarily) reflect the way the sound hardware works in
practice.

The least crufty library I know of only does sound output --
http://xiph.org/ao/

If you are interested in sound synthesis or analysis I would recommend Chuck
instead -- http://chuck.cs.princeton.edu/

Of course, there is always Pure Data (http://puredata.info/) or its
commercial sibling, Max/MSP (http://www.cycling74.com/)

-Sigmund
Jul 8 '08 #4
"kid joe" <sp******@spamt rap.invalidwrot e in message
news:pa******** *************** *****@spamtrap. invalid...
Hello

I've got interested in learning some basic sound programming bits in
C... mainly I want to know how to go about accessing the sound devices -
reading from them mainly - in windows and linux... I'd kind of like to be
able to do it without a whole bunch of extra garbage added in there - by
this I mean that I know in windows there are a million sound programming
packages that make the whole process "easier" - there are also a few in
linux but I think the raw stuff I'm interested in understanding is a bit
more simple in linux b/c of the way devices work in it.

So if anyone can point me at a place to start - maybe some really raw
source code for linux and windows - I would really appreciate it.
http://sourceforge.net/search/index....de=0&limit=100
** Posted from http://www.teranews.com **
Jul 9 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
7414
by: David Saum | last post by:
I am modifying some VB6 code I found online for computing the spectra of sound card data http://fullspectrum.com/deeth/programming/vb.html#Spect in order to build a receiver to detect Gamma Ray Bursts (GRB). http://www.infiltec.com/SID-GRB@home The original code allows for sampling rates from 11.025 - 44.1khz, and that works OK, but I need to sample my Audigy2 sound card at 48 or preferably 96khz in order to look at signals around...
1
4115
by: Mathias Goldau | last post by:
Hi, Can someone tell me where I find some material (e.g. a compiler with graphics.h and conio.h (for free)) related to graphic programming BGI-like, and sound programming (not PC-speaker). The platform doesn't matter. My problem: I want to port a simple programm for TurboPascal 7.0 to C/C++, that uses functions like: putPixel(...), because TP doesn't offer Soundblaster support, and I thought in C/C++ this would be easier/possible. Am I...
4
3481
by: Robert Gravereaux | last post by:
I'm putting together a C# .Net forms project on win2k. The application requires some sort of horn sound. I've never implemented any audio in .Net, so I'm not sure how best to accomplish this. It's an application that works with a wireless barcode scanner, in a warehouse environment. The user could be potentially 20 or 30 ft. from the PC. If the user scans something improperly, the app should sound a 'horn' to notify the user. I'm trying...
4
1749
by: inkexit | last post by:
I'd like to know how many sounds I can play at once using the average pc. of course, average is rather vague. let's say, 1 gigahertz, 256 mb ram, and a 16 bit 44.1 khz sound card. the complete sample library I will be playing back samples from is about 30 MBs total, the individual samples are about 50 KB. if I construct a program from scratch using C to play these sounds, how many could be sounded concurrently?
17
2008
by: Ben | last post by:
How do I add sound so that it plays automatically when the page is loaded? My search turned up some references to <bgsound>, but it was described as a Microsoft-designed tag. I prefer to stick to non-properietary standards. Also, is there a sound format that most browsers can play natively, without a plug-in? The sound is 5-seconds, voice-only.
2
7870
by: positivebalance41m | last post by:
I have been searching how to do sound capture (record audio input) in VB.NET for days now. I find some references to "winmm.dll" calls, but they give VB5 or VB6 examples which won't code convert upgrade to VB.NET without warnings errors that I can understand how to fix. There's some ActiveX and OCX's floating around, some free some not, but in all cases they don't explain or give me access to the raw PCM data in some kind of familiar...
3
1629
by: mariolino | last post by:
i have created a little WaveTable Ocillator, a sinusoid. How can i send it to Sound Card for play? I NEED INFO ON SOUND SYNTHESIS AND SOUND PROGRAMMING IN C/C++. THANKS. by MARIOLINO
0
2450
by: Mark | last post by:
How can I set up JRE to use a particular sound device on Linux? I mean for existing java applications - I do not want to do sound API programming. I came across the sound.properties file, but I do not know what I do have to enter in order to use a particular ALSA device, or if this is possible at all. Mark
2
1124
by: =?Utf-8?B?bWF0dA==?= | last post by:
Recently when I try to watch any TV channel thru Media Center, I hear a ringing/beeping type sound, instead of the regular audio. I only hear this sound when trying to watch live TV. My recorded TV shows sounds just fine and my other applications audio sound fine as well. I can't think of anything I've changed recently to have caused this sound issue. Any suggestions would be greatly appreciated, thanks.
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.