Author Topic: [SoundSystemJPCT]Playing a sound with short interval  (Read 3577 times)

Offline P0jan

  • bit
  • Posts: 4
    • View Profile
[SoundSystemJPCT]Playing a sound with short interval
« on: September 19, 2013, 12:03:33 PM »
I have a source which I am trying to play two times with an interval of 500ms.

Code: newbielink:javascript:void(0); [nonactive]
Engine.soundPlayer.newSource("src00", new File("res/general/collect3.wav").toURL(), "wav", false);
Engine.soundPlayer.play("src00");

Thread.sleep(500);

Engine.soundPlayer.play("src00");

The second call to soundPlayer.play("src00") is suspended.
If I change the sleep to 1500ms, it will work fine.

Is there a way to change this?

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: [SoundSystemJPCT]Playing a sound with short interval
« Reply #1 on: September 19, 2013, 03:04:27 PM »
What do you mean by "is suspended"?  How long is the sample (less than 500 ms I presume?)
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline P0jan

  • bit
  • Posts: 4
    • View Profile
Re: [SoundSystemJPCT]Playing a sound with short interval
« Reply #2 on: September 20, 2013, 04:04:52 AM »
By "suspended" I mean that the sound is not played, the call to play() is ignored.
I think the sound is over 500ms, I can check when I get home.

In the current sound api I am using(which I am looking to replace with possibly this) allow me to play a sound multiple times without have to worry about a interval limitation. I hope I can achieve the same effect here.

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: [SoundSystemJPCT]Playing a sound with short interval
« Reply #3 on: September 20, 2013, 06:45:28 AM »
Well of it is over 500ms, then of course the call to play() is ignored since the source is already playing.  If your intention is to restart the source, call stop() then play().  If your intention is to play multiple instances of the sample simultaneously, then you will need to attach it to more than one source.  Easiest way to do that is to use quickPlay rather than play, so SoundSystem handles creation and management of the sources for you behind the scenes (so you don't have to worry about keeping track of multiple sources).
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline P0jan

  • bit
  • Posts: 4
    • View Profile
Re: [SoundSystemJPCT]Playing a sound with short interval
« Reply #4 on: September 20, 2013, 07:14:59 AM »
Yes, my intention is to play multiple instances of a sample simultaneously.

The reason I dont want to use quickPlay is because it is a performance killer, and having lags in a game is not a good idea. Afaik, quickPlay recreates the buffer everytime its called, which means it have to read the sound from the disk everytime it is called.

I dont see why calling play multiple times on the same sample should not work. The buffer is in memory. Why not reuse it in a different thread?

Anyway, thanks for the help!

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3495
  • Developer
    • View Profile
    • PaulsCode.Com
Re: [SoundSystemJPCT]Playing a sound with short interval
« Reply #5 on: September 20, 2013, 06:10:46 PM »
LOL quickPlay does not read the sample from disk every time you call it.  Only the first time.  You can also call loadSound ahead of time to avoid latency on the first call to quickPlay.  Filename / identifier is just how you refer to the sample once it is loaded.

You are mixing up the definition of sources and samples (I recommend reading the first chapter of the guide I wrote)  A source is merely information about where in 3D space to play a sample.  The sample only exists once.  To play a sample multiple times simultaneously, you need more than one source.  That's how the library is designed.  QuickPlay is written exactly for what you are doing, but you can maintain several sources and cycle through them too if you don't like how SoundSystem manages the sources.
« Last Edit: September 20, 2013, 06:16:44 PM by Paul »
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted