SimpleAudioEngine iPhone implementation

Please correct me if I’m wrong but it seems the implementation for iphone SimpleAudioEngine is missing. I’ve found ./CocosDenshion/uphone and ./CocosDenshion/win32. I

I’m sorry. SimpleAudioEngine on iphone & android hasn’t been implemented yet. We had to upgrade to 0.99.5 first.
You can briefly use CocosDenshion in cocos2d-iphone.org with a simple c++ wrapper now.
The CocosDenshion on iphone may come out at Feb.2011

OK, integration of the original cocos2d iphone CocosDenshion into cocos2d-x project was really easy. In case anybody needs a simple cpp wrapper around obj c CocosDenshion - please contact me.

wow, It seems that you have successfully use the c++ wrapper!
Could you kindly commit this source on github to share with everyone in this community? Many guys are waiting for this. Thanks a lot!

I’m not sure this code should be committed to cocos2d-x (in fact I’m sure it shouldn’t). What I dd is:

  1. Added all .h and.m cocos2d-iphone CocosDenshion files into the project

  2. Added AVFoundation.framework, AudioToolbox.framework and OpenAL.framework frameworks

  3. Implemented TinyAudioEngine that covers all my current requirements
    I’m still waiting for the “real” cocos-2d CocosDenshion :slight_smile:

    // TinyAudioEngine.h
    #pragma once
    class TinyAudioEngine
    {
    public:
    static void playBackgroundMusic(const char* filePath, bool loop = false);
    static void stopBackgroundMusic(bool releaseData = false);
    static void setBackgroundMusicVolume(int volume);

     static int playEffect(const char* filePath);
         static void stopEffect(int soundId);
     static void setEffectsVolume(int volume);
    

    };

    // TinyAudioEngine.mm
    #include “TinyAudioEngine.h”
    #import “SimpleAudioEngine.h”

    void TinyAudioEngine::playBackgroundMusic(const char* filePath, bool loop /= false/)
    {
    [[SimpleAudioEngine sharedEngine] playBackgroundMusic:[NSString stringWithUTF8String:filePath] loop:loop];
    }

    void TinyAudioEngine::stopBackgroundMusic(bool releaseData /= false/)
    {
    [[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
    }

    void TinyAudioEngine::setBackgroundMusicVolume(int volume)
    {
    [[SimpleAudioEngine sharedEngine] setBackgroundMusicVolume:volume];
    }

    int TinyAudioEngine::playEffect(const char* filePath)
    {
    return [[SimpleAudioEngine sharedEngine] playEffect:[NSString stringWithUTF8String:filePath]];
    }

    void TinyAudioEngine::stopEffect(int soundId)
    {
    [[SimpleAudioEngine sharedEngine] stopEffect:soundId];
    }

    void TinyAudioEngine::setEffectsVolume(int volume)
    {
    [[SimpleAudioEngine sharedEngine] setEffectsVolume:volume];
    }

    // TinyAudioEngine.cpp
    #ifdef _WINDOWS

    #include “TinyAudioEngine.h”
    #nclude “SimpleAudioEngine.h”

    void TinyAudioEngine::playBackgroundMusic(const char* filePath, bool loop /= false/)
    {
    SimpleAudioEngine::getSharedEngine()->playBackgroundMusic(filePath, loop);
    }

    void TinyAudioEngine::stopBackgroundMusic(bool releaseData = false)
    {
    SimpleAudioEngine::getSharedEngine()->stopBackgroundMusic(releaseData);
    }

    void TinyAudioEngine::setBackgroundMusicVolume(int volume)
    {
    SimpleAudioEngine::getSharedEngine()->setBackgroundMusicVolume(volume);
    }

    int TinyAudioEngine::playEffect(const char* filePath)
    {
    return SimpleAudioEngine::getSharedEngine()->playEffect(filePath);
    }

    void TinyAudioEngine::stopEffect(int soundId)
    {
    SimpleAudioEngine::getSharedEngine()->stopEffect(soundId);
    }

    void TinyAudioEngine::setEffectsVolume(int volume)
    {
    SimpleAudioEngine::getSharedEngine()->setEffectsVolume(volume);
    }

    #endif

Great! You give out a good idea. Just adding c++ wrapper for SimpleAudioEngine only, instead of the wrapper for 3 layers intefaces of entire CocosDenshion.

In fact we may implement a “real” c++ CocosDenshion, because there’re third party OpenAL implement on android-ndk now!
Take a look at this
http://pielot.org/2010/12/14/openal-on-android/