Forums

how to make sounds with C++

Started by laserbeak43 August 29, 2007
hi,
how would i go about creating something that makes sound and sending
it to an output so i can hear it?
sorry for the very simple question, but what i want to do is learn how
to make sounds(as low-level as i could(could want to)) and send them
to an output, without the use of third-party libraries such as
portaudio, etc.

Portaudio is a good choice. If you can't use it because of license issues,

you can look up from its source code how it's done in different audio
environments (MME, ALSA, DirectSound, ASIO etc).
BTW, you didn't tell what platform you're planning to use.

If you reconsider portaudio, I happen to have one example on my web page:
http://www.elisanet.fi/mnentwig/webroot/looprecord/index.html

Others are included with the source.

On Aug 29, 4:53 am, "mnentwig" <mnent...@elisanet.fi> wrote:
> Portaudio is a good choice. >
i actualy have tried portaudio. and have made sounds with it using the examples. what i don't like about it is that there's so much going on. and finding my way through all of that source. it makes me feel disorganized and irritable :P i will look at your code though. i've started a google group for audio related dsp, and have posted some stuff i made last night out of frustration. here's the link http://groups.google.com/group/DSPStudyGroup/browse_thread/thread/e890b54c51509f7b it doesnt interface with anything though. all it does is print values to the console
> you can look up from its source code how it's done in different audio > environments (MME, ALSA, DirectSound, ASIO etc).
this seems like the best choice for me, but again, looking through all of those files gets bery nerve wrecking to me. if there's nothing simpler, i guess i'd have no choice though
> BTW, you didn't tell what platform you're planning to use. >
i use winxp and sometimes linux. i'm too much of a newb on linux to do anything really though. i spent most of my time in linux chatrooms trying to get things to work when i do use it.
> If you reconsider portaudio, I happen to have one example on my web page:http://www.elisanet.fi/mnentwig/webroot/looprecord/index.html > > Others are included with the source.
portaudio might be the one i work with in the future. i can see that happening, but it might be too much for me now.
Hello,

here is a (quite) compact example using plain direct sound.
http://cvs.savannah.nongnu.org/viewvc/fluidsynth/src/fluid_dsound.c?revision=1.10&root=fluid&view=markup
It's from "fluid synth" on http://savannah.nongnu.org.

Anyway, portaudio is really the faster way to make some noise on windows:

- Download and install msys and mingw from sourceforge. Use its shell as
command line.
- download and install the gcc package and 'make' utility
- download portaudio
- unpack it: gzip -dc pa_stable_v19_061121.tar.gz | tar -xvf  -
- ./configure
- make 
- (possibly make install)
- cd into test folder
- gcc patest_leftright.c -I../include -mwindows
../lib/.libs/libportaudio.a -lole32 -lwinmm -mwindows -mconsole
- ./a.exe and it starts to beep

Don't worry about most of the audio code being plain C (not C++).
ANSI C is alive and kicking. 

Cheers

Markus

On Aug 29, 7:12 am, laserbeak43 <laserbea...@gmail.com> wrote:
> hi, > how would i go about creating something that makes sound and sending > it to an output so i can hear it? > sorry for the very simple question, but what i want to do is learn how > to make sounds(as low-level as i could(could want to)) and send them > to an output, without the use of third-party libraries such as > portaudio, etc.
Why oh why would one EVER consider NOT going through third-party libs? portaudio is excellent for exactly what you describe. Moreover, it is crossplatform which means you will never have to dig into the gruel details of each platform (which takes A LOT of time). Also, its license will allow you to use it in commercial apps too... /Rob

laserbeak43 wrote:

> hi, > how would i go about creating something that makes sound and sending > it to an output so i can hear it?
RTFM
> sorry for the very simple question, but what i want to do is learn how > to make sounds(as low-level as i could(could want to)) and send them > to an output, without the use of third-party libraries such as > portaudio, etc.
MSDN has all of that. VLV
On Tue, 28 Aug 2007 22:12:01 -0700, laserbeak43 wrote:

> hi, > how would i go about creating something that makes sound and sending > it to an output so i can hear it? > sorry for the very simple question, but what i want to do is learn how > to make sounds(as low-level as i could(could want to)) and send them > to an output, without the use of third-party libraries such as > portaudio, etc.
To make sounds you need to make a waveform, then play it out. We're a good resource for the making the sounds, but to play them out you should look for audio drivers. Google around -- there are resources. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
On Aug 29, 9:07 pm, laserbeak43 <laserbea...@gmail.com> wrote:
> On Aug 29, 4:53 am, "mnentwig" <mnent...@elisanet.fi> wrote:> Portaudio is a good choice. > > i actualy have tried portaudio. and have made sounds with it using the > examples. > what i don't like about it is that there's so much going on. and > finding my way through all of that source. it makes me feel > disorganized and irritable :P
If you just have a problem with that particular library, you might try Simple DirectMedia Layer. It provides support for sound, video acceleration, and input devices across a number of platforms with bindings for almost any language you'd want to use. http://www.libsdl.org Might be worth a try if you just want an alternative library. Jason