Skip to main content
gamedev.net
🔒 Locked

Audio Programming

Started by RanHam335 Dec 3, 2008 at 5:33 AM 1 replies 800+ views
Original Post
RanHam335
RanHam335
I want to create a program that will create a square wave and output it through the computers audio port. I want to do this in C++ but I have no idea how to even generate the tone out through the audio port. I understand the square wave formulas but is it even possible to broadcast it out of the computers audio port using c++? Thanks Randall
cignox1
cignox1
A possibility could be using fast fourier transformate to convert from a function domain to another (i.e. you set the amplitudes at different frequencies, and it transforms them in a standard wave. Once I did the inverse process to take the mic input, transform it to a set of frequencies amplitudes and find the peak. I did this for a 'guitar tuner' tool.

When you have your sample, then it is easy to play it using one of the api available (openAL for example)

For the FFT you might want to use the FFTW library...
eq
eq
If you'd like to output your signal as you create it (dynamic tone generation) you'll need to use an audio API.
Under windows there are several options:
DirectSound (depreciated in Vista).
XACT (Vista)
..etc..

I'm no expert but I managed to put together an audio library for my game using DirectSound.
It supports streaming (generated) audio and mixing it as regular samples (2d/3d etc).
I did a simple test where the cursors X position was the frequency of a sine wave and the Y position was the amplitude, was quite fun to create audio using the mouse like that...

Also there's a challenge if you'd like it to be "very realtime" since the method I used uses small buffers (typically around 50 ms) for playback and this introduces latency.

Edit: Oh, forgot to mention Fmod which is very nice IMO, if you can afford the license or doing non-profit work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.