New audio engine design

65 views
Skip to first unread message

Xiaoming Zhang

unread,
Jul 28, 2014, 4:45:54 AM7/28/14
to cocos2d-js-devel
There is a pull request for new audio api design https://github.com/cocos2d/cocos2d-x/pull/7602.
Fell free to comment it.
Any suggestion is appreciated.

Best Regards
Minggo




Nite Luo

unread,
Jul 28, 2014, 5:16:35 PM7/28/14
to cocos2d-...@googlegroups.com

Like sprite, we just let user create sprite with image and don’t have to deal with texture id, maybe we should do the same here, It’s much easier to manage.

how to play multiple sound, it’s up to developer to decide how they want to use that.

auto img = sprite::create("image.png");
addChild(img);

auto sound1 = sound::create("sound1.mp3");
sound1->play();

auto sound2 = sound::create("sound2.mp3");
sound2->play();

// I want to stop sound1 and play sound1 from the start again
sound1->play();

Compare to

int sound1 = audio::play2d("sound1.mp3");
audio::stop(sound1);

int sound2 = audio::play2d("sound2.mp3");
audio::stop(sound2);

//I want to start sound1 and play sound1 from the start again
audio::stop(sound1);
sound1 = audio::play2d("sound1.mp3");

In fact libGDX, flash, Unity, you can all create sound and use something like sound->play()
http://answers.unity3d.com/questions/12546/playing-audio-clip.html

http://www.gamefromscratch.com/post/2013/11/19/LibGDX-Tutorial-8-Audio.aspx

Xiaoming Zhang

unread,
Jul 28, 2014, 9:59:56 PM7/28/14
to Nite Luo, cocos2d-...@googlegroups.com
The codes of libgdx is that 

long id = mp3Sound.loop();
Timer.schedule(new Task(){
   @Override
   public void run(){
      mp3Sound.stop(id);
      }
   }, 5.0f);
Why it should use id to stop the audio, why not just mp3Sound.stop()?
So i think the mp3Sound is not the audio itself, it is a manager class to handle mp3 files.

long id = wavSound.play();
wavSound.setPitch(id,0.5f);
Why it needs to use id to setPitch?
Why not use  wavSound.setPitch(0.5f)?


Best Regards
Minggo




--
You received this message because you are subscribed to the Google Groups "cocos2d JS development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocos2d-js-dev...@googlegroups.com.
To post to this group, send email to cocos2d-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

NiTe Luo

unread,
Jul 28, 2014, 10:11:16 PM7/28/14
to Xiaoming Zhang, cocos2d-...@googlegroups.com
I wouldn’t say they’re manager class to handle mp3 files, check out the init code
Sound wavSound = Gdx.audio.newSound(Gdx.files.internal("data/wav.wav"));
Sound oggSound = Gdx.audio.newSound(Gdx.files.internal("data/ogg.ogg"));
Sound mp3Sound = Gdx.audio.newSound(Gdx.files.internal("data/mp3.mp3"));

I think the reason for that is it will let you play the same sound multiple times(sound instancing). if you call wavSound.stop it will stop all the sound instance. It’s actually a really good way, I think we could learn from them.

There is the doc

-Nite

Xiaoming Zhang

unread,
Jul 28, 2014, 10:17:19 PM7/28/14
to NiTe Luo, cocos2d-...@googlegroups.com
Oh, yep.
It seems it is has the benefit of unity implementation and our implementation.
We will discuss it and modify the API.

Best Regards
Minggo



Reply all
Reply to author
Forward
0 new messages