Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound API #15

Open
joskuijpers opened this issue May 6, 2014 · 5 comments
Open

Sound API #15

joskuijpers opened this issue May 6, 2014 · 5 comments
Labels

Comments

@joskuijpers
Copy link
Contributor

I wrote the Sound API in the sound module (sound.js). It is almost an exact copy of the Sphere 1.5 API but has a couple of differences:

  • Now using constructor instead of LoadSound, obviously.
  • Repeat, volume, pitch, pan and length are properties.
  • Volume and pan are now floats.
  • Added the boolean playing property.
  • Added the string path property.
    The same is true for SoundEffect.
  • Added stop function to the module: stopping all sound.
  • Added volume property to the module: master volume setting (for in config screens etc).

Now I think about adding an event for both: 'finished'. Especially useful for Sound, to play the next song of a playlist.
For better background music playlist stuff, we might want to add some other technique: something that calls a function to ask for the next song, when it thinks it needs it: just before the ending. and it then crossfades. Maybe some playlist module? Is this useful, or wished?

What about a exports.currentPlaying function/property that returns an array of all current playing sounds? It is just an array, so the sound.play() can add this to the array, and on stop or pause, it can remove itself from the array.

After that, I would like approval on the module 😄

@joskuijpers joskuijpers changed the title Sound API: quest Sound API May 6, 2014
@joskuijpers
Copy link
Contributor Author

So I added the "finished" event in my quick implementation, and using that event I implemented a Playlist class, fully in JavaScript 😃. It uses fs to read all files from a folder, and plays the first. When it is finished, it loads the second and plays that. I think we should have this event.

@FlyingJester
Copy link
Member

Something I added in the AudioBass plugin in TurboSphere, the ability to specify the number of repeats for a Sound and SoundEffect.
it's usually very simple in audio libraries to make a sound repeat a certain number of times, while doing so in script is much more complicated.

@joskuijpers
Copy link
Contributor Author

Thanks! I found that functionality in AVFoundation too (the framework I use for audio). I will add it.

On May 10, 2014, at 11:48 PM, Martin McDonough [email protected] wrote:

Something I added in the AudioBass plugin in TurboSphere, the ability to specify the number of repeats for a Sound and SoundEffect.
it's usually very simple in audio libraries to make a sound repeat a certain number of times, while doing so in script is much more complicated.


Reply to this email directly or view it on GitHub.

@FlyingJester
Copy link
Member

Another thing is that the separation of Sound and SoundEffect objects is more than just semantic. I'm not sure if this was the original intent, but working on TurboSphere they represent two different ways to play a sound.
The Sound object is a streamed sound, and the SoundEffect object is a sampled sound. This also codifies why only encoded sounds can be SoundEffects while Sounds can also hold Mod-style music or Midi files.

This also is why, in TurboSphere, Sounds cannot be played more than once, while SoundEffects can. Similarly, you can only post raw PCM or encoded data to a Sound to generate it on the fly.

Re the playlist, have you seen the playlist portion of RadLib? I haven't looked at it too closely, but seeing it in action in Hold The Line, it looks perfectly functional.

I would rather consider this kind of event more as a callback, rather than a true asynchronous event.

@joskuijpers
Copy link
Contributor Author

The distinction between Sound and SoundEffect you give sounds valid (pun intended). We can put restrictions on the capabilities of both classes and enforce those.
One being the simultaneous playing of multiple streams of 1 sound. You could ofcourse create two Sound objects...

What else?

RE Playlist: I can't find the 'playlist portion' in RadLib. Link?

RE Callbacks: I am not sure whether to put 'finished' on the event queue or call the function directly. I think keeping it all alike, so using only the event queue, might simplify things for users. But if you have a valid argument to directly call all the listeners...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants