Sign in to follow this  

Audio Programming

This topic is 3296 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3296 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this