Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: simple java playing sound using jsmfl please help .  (Read 6017 times)

0 Members and 1 Guest are viewing this topic.

wissamjackal

  • Newbie
  • *
  • Posts: 2
    • View Profile
simple java playing sound using jsmfl please help .
« 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

wissamjackal

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: simple java playing sound using jsmfl please help .
« Reply #1 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

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: simple java playing sound using jsmfl please help .
« Reply #2 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.
« Last Edit: May 22, 2013, 07:11:02 am by pdinklag »
JSFML - The Java binding to SFML.