I can play sounds?:O

Started by
9 comments, last by frazchaudhry 11 years, 9 months ago
I can play sounds in C++? How do I go about doing that? It doesnt matter if its how to play a little beep or a whole entire song but how do you do it??

~Saint Squireen
Advertisement

I can play sounds in C++? How do I go about doing that? It doesnt matter if its how to play a little beep or a whole entire song but how do you do it??


C++ doesn't support sounds, you need to use your OS API for that (or a third party API that your OS and/or drivers support)

For Windows you have some basic sound support in the Win32 API and better sound support with DirectX or OpenAL (OpenAL is also available on Mac and Linux)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
The easiest and most straight forward way is to use an external library. I've written my own .wav decoder once and it's rather nightmarish.

Now, which library depends on what exactly you want to do. If you want to analyse streams of bytes as the sound goes then some libraries are better suited for that. If you are simply looking for something that will let you read a specific file format then there's easier stuff you can use.

I'd recommend checking out SDL since it comes with image loading features, threading, sound, etc. It's a nice package that will get you up and running fast. Check this page out : http://lazyfoo.net/SDL_tutorials/lesson11/index.php

[size=1]I "surf" the web, literally.

You gonna need an external library.

Try Audiere or OpenAL
well if you just wanna play a little beep in C++ use the escape character "\a".

cout << "\a";

This will give u a nice little beep.

well if you just wanna play a little beep in C++ use the escape character "\a".

cout << "\a";

This will give u a nice little beep.

You can't possibly be serious.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

He/she is actual serious hahaha I literally just tried it out and it works!!!!! Wow, I would never have thought that!!

~Saint Squireen

[quote name='frazchaudhry' timestamp='1341775652' post='4956991']
well if you just wanna play a little beep in C++ use the escape character "\a".

cout << "\a";

This will give u a nice little beep.

You can't possibly be serious.
[/quote]

try it out then and see for yourself

[quote name='Bacterius' timestamp='1341778728' post='4957011']
[quote name='frazchaudhry' timestamp='1341775652' post='4956991']
well if you just wanna play a little beep in C++ use the escape character "\a".

cout << "\a";

This will give u a nice little beep.

You can't possibly be serious.
[/quote]

try it out then and see for yourself
[/quote]
I wasn't doubting you, I know this console escape produces a beep. It's just that it's hardly flexible enough to do anything resembling a song with it, and the OP is probably better off using actual API's. I didn't mean to offend smile.png

On topic, if you are interested in playing songs only, you might want to take a look at MIDI synthetizers, they are very nice to produce simple music and it's relatively easy to use. However in terms of simplicity, if you are under Windows, nothing beats the PlaySound function (in MMSystem, iirc) to play wave files, for instance. It's a start, at least.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

winmm.dll has Playsound().
Not terrific but maybe better than cout << "/a"
LOL

This topic is closed to new replies.

Advertisement