Background music (loop)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Lagoni
Posts: 3
Joined: June 17th, 2015, 7:11 pm

Background music (loop)

Post by Lagoni » June 18th, 2015, 9:29 pm

Okay where to begin.
Hello.
I am admittedly a newbie at c++ (still learning basic c), but i started making a game in the updated framework that includes sound.
First off i looked at Chili's example, and i can get those sounds to work just fine, and include them in my own game.
My problems start now:

I read through the sound.cpp, and gathered that the files should be in 44.1k 16bit Stereo PCM Wave format.
so i went online to convert my mp3. I got it to be 44.1k 16 bit stereo wave format.
it doesn't seem to be good enough though, as when i try to play it, it just comes out as a short distorted burst, then stops.
I tested the sound file in Chili's poop game example as well (and i did include it in the Chili DirectX Framework folder). I just put it instead of the tinkle sound when you eat the disc.
So my first question is:
Does anyone know how to convert (or extract or compress?) to PCM?
I think that's the reason it doesn't play correctly.

Secondly.
I want to have background music, but i don't know how to loop.
i searched online, and found this line of code:

PlaySound("music.wav", NULL, SND_FILENAME|SND_LOOP|SND_ASYNC);

the music file is underlined with red, and when i hover over it says:

(const char[14])"music.wav"
Error: argument of type "const char *" is incompatible with parameter of type "LPCWSTR"

second question:
Is this just because the framework does not have this function built in, or do i have to declare something somewhere?

third question:
Is there a file size limit in the framework? Because the one i want to use is 9.446 KB

I'm sorry for the long post.
I didn't feel like it was necessary to upload the source code, since that is not the problem.

Thanks in advance.
-Lagoni

superstar1998
Posts: 52
Joined: March 10th, 2015, 7:51 pm
Location: Romania
Contact:

Re: Background music (loop)

Post by superstar1998 » June 20th, 2015, 5:13 am

First of all, if the PlaySound is not underlined with red, the function should be ok.
Secondly, try putting an L in front of the name, like this :
L''music.wav''
Not sure if this will work as i haven't tested this function myself.
There should be no size limit, so your file will work.
“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”

– Martin Golding

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Background music (loop)

Post by chili » June 20th, 2015, 3:36 pm

The code for loading wavs is based on code from rastertek, and it seems to be picky in what .wav files it wants to load. The format of the wav files varies a bit from wav editor application to application, so wavs from some sources will not work properly. I use Sony Soundforge and have never had a problem (as long as the rate/bits/channels are correct). Just try saving the file in different editors until you find one that works. Or you can try and figure out where the loading code is puking. If you do, let me know ;)

The other stuff is as superstar has said.
Chili

Post Reply