How do I loop a sound?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Ali1077
Posts: 1
Joined: August 31st, 2020, 10:57 pm
Contact:

How do I loop a sound?

Post by Ali1077 » August 31st, 2020, 11:04 pm

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

albinopapa
Posts: 4266
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: How do I loop a sound?

Post by albinopapa » September 3rd, 2020, 4:17 pm

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 };
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4266
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: How do I loop a sound?

Post by albinopapa » September 3rd, 2020, 4:19 pm

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 ).
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply