Sending bits out of the audio port?

Hi.i'm using windows 7(32 bit). code block compiler.
OK. i have to get the binary code of a file out of the audio port(headphones).

for e.g. if the bin code of file sond.dat is 01000110001111....(so on )
then there should be sound in audio port for every 1 and silence for every 0.

I know that's crazy but that's my wee project.

AND yes by audio port I mean headphones port and not the cpu's internal speaker's that can be beeped with beep() or sound() commands.
I want the sound card to do that.

what function should i use to produce the sound?
Last edited on
I guess you could use OpenAL, Win32 probably has some sound routines as well, and then there's DirectSound (which, IIRC, isn't maintained anymore though). But you'd actually have to compose the sound yourself, you won't find

al_do_what_i_want_with_this_bitstream_please

anywhere.
Right. There isn't really such a thing as "sound on" and "sound off" as far as the audio hardware is concerned. It streams a PCM wave. It's up to you to construct a wave which is silent at times and audible at times, if that's what you want.

I would start with streaming something simple, like a basic sine wave. Then work on stopping/starting it at certain times.


I can help with the audio wave construction, but not with working with OpenAL. I haven't used OpenAL directly in years.
I'm working on a software synthesizer, so I do know a few things about the type of project you're interested in. Your project really isn't that crazy if I understand it correctly.

I'd suggest looking into PortAudio for your audio output. If you don't need things like 3D positioning and just want a no-nonsense cross-platform sound output interface, PortAudio is a good choice. I've had very good experiences with the latest version.

You'll need to decide what kind of sound you'd like to output. I can post algorithms for somewhat unoptimized triangle, square, and sawtooth waves if you'd like. A sine would be the simplest because if you're not too concerned about performance (though those sines are pretty cheap if you have just a couple of them), there's a sine function in the standard library, under <cmath>.

As for reading your file... I'll let you deal with learning how to mask the bits yourself. :)

Good luck!
-Albatross
Last edited on
I found a YouTube video that seems to solve your problem. The link (for the video) is:
http://www.youtube.com/watch?v=_DG9z6YOzgg
and the link (for the source code from the video) is:
http://bisqwit.iki.fi/jutut/kuvat/programming_examples/s3mplayer.pdf
which can be found in the description.

Tell me if this helps (as I am relatively new to C++).
Hi Disch and Albatross. I know that i can write a wave as: P= A*sin(w*t+k) or p= a*e^(-kt) or something like that. But how do I get the audio port to deliver it?

@Albatross:Can we deliver all the waveforms or only sine waves through the audio port?. If we can , then please tell me how to do it.

I know how to read the bits off a file. all u gotta do is read bools from it one by one. The thing i'm concerned about is getting the sound.
Isn't there any simple function in c++ that allows u to output sound through audio port?
Last edited on
Topic archived. No new replies allowed.