Page 1 of 1

How do I loop a sound?

Posted: August 31st, 2020, 11:04 pm
by Ali1077
How do I loop playing a sound like a background music I want to put in chili's framework.

I used Sound.h and Sound.cpp

Re: How do I loop a sound?

Posted: September 3rd, 2020, 4:17 pm
by albinopapa
When you create a sound, the constructors have parameters that define where a sound should start and where it should end and enable looping.

Sound( const std::wstring& fileName,float loopStart,float loopEnd )

If you want to loop a sound that is 20 seconds or only 20 seconds of the sound
Sound bg_music = Sound{ L"music.wav", 0.f, 20.f };

Re: How do I loop a sound?

Posted: September 3rd, 2020, 4:19 pm
by albinopapa
make sure to use floats to get the loop in seconds, otherwise if you use ints they'll be converted to unsigned int and you'll be looping in samples ( 0 - 20 samples which wouldn't be more than a blip ).