SFML community forums

Bindings - other languages => Java => Topic started by: wissamjackal on May 22, 2013, 01:04:32 am

Title: simple java playing sound using jsmfl please help .
Post by: wissamjackal on May 22, 2013, 01:04:32 am
hi there , i'm a beginner with jsmfl and i tried to play wav file using it , please need a simple code to how play the wav file using jsmfl .

additional help you may give me a way to double the sample rate of the original wav file so that would speed up the wav and reduce the duration of it .

waiting for replay .... sorry for my bad English


all regards wissam jackal
Title: Re: simple java playing sound using jsmfl please help .
Post by: wissamjackal on May 22, 2013, 01:09:52 am
well it worked after adding while loop , is there another way
and please if you can help me solve the other problem (increasing the speed depending on sample rate change like double it ).

all regards
Title: Re: simple java playing sound using jsmfl please help .
Post by: pdinklag on May 22, 2013, 07:09:06 am
Here's the wiki page for loading and playing sounds in JSFML:
https://github.com/pdinklag/JSFML/wiki/SoundBuffers-and-Sounds

In order to play a sound properly, it needs to be kept in memory, so yes, you would need to somehow wait until it finished playing. If your program doesn't wait, it will terminate before the sound is done playing, and thus it will be garbage-collected and interrupted.

If you have a window with a main loop, that should be no problem generally. If you, for some reason, want a program that only plays a sound, a simple call of Thread.sleep might do the trick just as well.

I suppose you use the Sound class for playing your sound? In that case, instead of tampering with the sample rate (which would require you to implement your own stream class), you can simply modify the sound's pitch (https://github.com/pdinklag/JSFML/wiki/SoundBuffers-and-Sounds#volume-and-pitch). The effect should be exactly what you are looking for.