游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2141|回复: 0

??????1.2.8???

[复制链接]

50

主题

69

帖子

69

积分

注册会员

Rank: 2

积分
69
发表于 2010-4-27 14:41:00 | 显示全部楼层 |阅读模式
??????1.2.8????????1.1.2??
????????????:
1.????????
2.? xm,mod,it,s3m???
3.?????????

???????(API)????:
1.?? ogg,mp3,wav,xm,it,s3m,mod??
2.???????????
3.?3d??
4.????,????

?????????????,??????????!
?????????????????????????(???????????fmod?????????)

????????OpenAL??

???????win32??gcc??
??? codeblock,devc++

??????(API)?????:
/*!==========================================================================
* ???????????:
*     1.??pdf???,????
*     2.????????????
*     3.??midi????
*     4.??aiff,acc,ape,flac?????(????)
*     5.???????
*     6.??????
*     7.???OpenAL?????
*     8.????,??,???????
*     9.????????
*     10.????
****************************************************************************/
??????1.4.2????:
/*!==========================================================================
* 1.4.2????????
*     ??PDF????
*     ?midi???????
*     ??????
*     ????????????OpenAL?????
*     ?????????????(aiff,au,flac,ape,acc...)(??????????!)
****************************************************************************/

????????(API) sdk
????:
c++?????
a/lib???? (?????a??lib??)
dll??-audio.dll??
OpenAL????

???????:
//! ????3d??????????????????????????
//! ??????????,????????,???????
//! ???????????????????
//! ??:?API?????????!
//! websize:www.gaimo.net
//! email:ccsdu2009@sohu.com
//! telephone:+86-028-67607663,
//!           +86-028-67607665

//! ???? list.
/*!==========================================================================
*  2010.01.22 ??:1.0.0
*     ????:??wav,ogg,mp3??
*              ?????????
*              ?????????
*     ?????????OpenAL??     
****************************************************************************/
/*!==========================================================================
*  2010.03.20 ??:1.1.0
*     ????:?3d??,?????
*     ?????????OpenAL??     
****************************************************************************/
/*!==========================================================================
*  2010.05.05 ??:1.2.8
*     ????:?????????(????wav??)
*     ????:it,s3m,xm,mod4????????
*     ???????
*     ?????????OpenAL??     
****************************************************************************/
/*!==========================================================================
* 1.4.0 ????????
*     ??PDF????
*     ?midi???????
*     ??????
*     ????????????OpenAL?????
*     ?????????????(aiff,au,flac,ape,acc)(??????????!)
****************************************************************************/
#ifndef AUDIODEVICE_HPP
#define AUDIODEVICE_HPP

////////////////////////////////////////////////////////////
/// ?????
////////////////////////////////////////////////////////////
#include <string>

#ifdef G_ENGINE
  #error ??????????????!
#endif

#if defined(_WIN32) || (defined(__WIN32__)) || defined(WIN32)
   #define G_WIN32  
#endif  

#ifndef __cplusplus
    #  error ???c++???
#endif

#ifndef G_CALL
#  ifdef G_WIN32
#    define G_CALL __stdcall
#  else
#    define G_CALL __stdcall
#  endif
#endif

#if !defined(G_DLL_API) && defined(G_WIN32)
    #if defined(BUILDING_DLL)
        #define G_DLL_API __declspec(dllexport)
    #else
        #define G_DLL_API __declspec(dllimport)
    #endif
#endif

#define G_FUNC(ret) extern "C" G_DLL_API ret

#ifndef NULL
#define NULL 0
#endif

typedef unsigned char  uchar8;
typedef unsigned int   uint;
typedef unsigned char  uint8;
typedef signed   short int16;
typedef unsigned short uint16;
typedef signed   int   int32;
typedef std::string    engine_string;

namespace core
{
         
////////////////////////////////////////////////////////////
/// ?????????
////////////////////////////////////////////////////////////     
class RefCount
{
public:
    ////////////////////////////////////////////////////////////
    /// ????????
    ////////////////////////////////////////////////////////////
    RefCount(): refcnt(1),auto_del(true){}

    ////////////////////////////////////////////////////////////
    /// ????????
    ////////////////////////////////////////////////////////////
    virtual ~RefCount(){}
   
    ////////////////////////////////////////////////////////////
    /// ???????
    ////////////////////////////////////////////////////////////   
    void SetAutoDel(bool able = true){auto_del = able;}
   
    ////////////////////////////////////////////////////////////
    /// ??????????
    ////////////////////////////////////////////////////////////
    const bool GetAutoDel()const{return auto_del;}
   
    ////////////////////////////////////////////////////////////
    /// ????????
    ////////////////////////////////////////////////////////////
    void Grab()const{++refcnt;};

    ////////////////////////////////////////////////////////////
    /// ????????
    ////////////////////////////////////////////////////////////
    bool Drop() const
    {
        //!ASSERT(refcnt>0 && "bad refcnt number!");

        --refcnt;
        if (refcnt == 0 && auto_del == true)
        {
            delete this;
            return true;
        }

        return false;
    }

    ////////////////////////////////////////////////////////////
    /// ??????
    ////////////////////////////////////////////////////////////
    int GetRefCnt()const{return refcnt;};

private:
    mutable int  refcnt;
    bool    auto_del;
};

////////////////////////////////////////////////////////
/// ?? RefPtr???????????
/// ?????????RefCount???
////////////////////////////////////////////////////////
template<class T>
class RefPtr
{
public:
    RefPtr(T* object = NULL)
    {
        this->object = object;
        if(this->object)
           object->Grab();
    }
   
    RefPtr(const RefPtr<T>& other)
    {
        object = NULL;
        *this = other;
    }
   
    ~RefPtr()
    {
        if(object)
           object->Drop();
        object = NULL;
    }

    RefPtr<T>& operator=(const RefPtr<T>& other)
    {
        if (other)
           other->Grab();
        if (object)
           object->Drop();
        object = other.get();
        return *this;
    }
   
    RefPtr& operator=(T* other)
    {
        if (other)
            other->Grab();
         if (object)
            object->Drop();
        object = other;
        return *this;
    }
   
    void swap(RefPtr<T>& other)
    {
        T* tmp = other.get();
        other = object;
        object = tmp;
    }
   
    void reset(T* other){*this = other;}
   
    T* get() const {return object;}
   
    T* operator->() const
    {   
        //!ASSERT(object && "bad object ptr");
        return object;
    }
   
    T& operator*() const
    {   
        //!ASSERT(object && "bad object ptr");
        return *object;
    }
   
    bool operator<(const RefPtr<T>& other) const
    {   
        return object < other.get();
    }
  
    ////////////////////////////////////////////////////////
    /// ????????
    ////////////////////////////////////////////////////////
    operator bool() const {return object != NULL;}

protected:
    T*   object;
};

namespace math
{
         
template<class T>
struct Vector3
{
    T x,y,z;
    Vector3():x(0),y(0),z(0){}  
};

}

typedef math::Vector3<float> Vector3f;

/////////////////////////////////////////////////////////
//! ????????
/////////////////////////////////////////////////////////
enum AudioFileType
{
    AUDIOFILE_TYPE_WAV = 0,
    AUDIOFILE_TYPE_OGG,
    AUDIOFILE_TYPE_MP3,
    AUDIOFILE_TYPE_XM,
    AUDIOFILE_TYPE_IT,
    AUDIOFILE_TYPE_MOD,
    AUDIOFILE_TYPE_S3M,
    AUDIOFILE_TYPE_AU,
    AUDIOFILE_TYPE_AIFF,
    AUDIOFILE_TYPE_WMA,
    AUDIOFILE_TYPE_AAC,
    AUDIOFILE_TYPE_APE,
    AUDIOFILE_TYPE_MIDI
};

/////////////////////////////////////////////////////////
//! ????????????
/////////////////////////////////////////////////////////
enum AudioFormat
{
    AUDIO_8BIT_MONO = 0,
    AUDIO_8BIT_STEREO,
    ADUIO_16BIT_MONO,
    AUDIO_16BIT_STEREO
};

//! ????????
const float AUDIO_SPACE_VELOCITY = 343.0f;

//! ?????????
const float AUDIO_DOPPLER_FACTOR = 1.0f;

////////////////////////////////////////////////////////////
/// ????????
////////////////////////////////////////////////////////////
class AudioListener : public RefCount
{
public:
    /////////////////////////////////////////////////////////
    //! ??,??????
    /////////////////////////////////////////////////////////
    AudioListener(){}
    virtual ~AudioListener(){}

    /////////////////////////////////////////////////////////
    //! ??,????????????
    /////////////////////////////////////////////////////////
    virtual void SetPosition(const Vector3f &pos) = 0;
    virtual Vector3f GetPosition()const = 0;
   
    /////////////////////////////////////////////////////////
    //! ?????????
    /////////////////////////////////////////////////////////
    virtual void SetDirection(const Vector3f& dir) = 0;
    virtual Vector3f GetDirection()const = 0;
   
    /////////////////////////////////////////////////////////
    //! ???????????(????????OpenGL????0,1,0)
    /////////////////////////////////////////////////////////
    virtual void SetUpVector(const Vector3f &updir) = 0;
    virtual Vector3f GetUpVector()const = 0;
   
    /////////////////////////////////////////////////////////
    //! ?????????
    /////////////////////////////////////////////////////////
    virtual void SetVelocity(const Vector3f &vel) = 0;
    virtual Vector3f GetVelocity()const = 0;        

    /////////////////////////////////////////////////////////
    //! ????????? (0.0f,1.0f)
    /////////////////////////////////////////////////////////        
    virtual void SetGlobalVolume(float volume) = 0;
    virtual float GetGlobalVolume()const = 0;
   
    /////////////////////////////////////////////////////////
    //! ??,????????
    /////////////////////////////////////////////////////////        
    virtual void  SetMetersPerUnit(float meters) = 0;
    virtual float GetMetersPerUnit(void) const = 0;     
   
    /////////////////////////////////////////////////////////
    //! ????
    /////////////////////////////////////////////////////////      
    virtual void Move(const Vector3f& position) = 0;   
};

/////////////////////////////////////////////////////////
//! ???????????
/////////////////////////////////////////////////////////
class AudioSource : public RefCount
{
public:
    /////////////////////////////////////////////////////////
    //! ??,?????
    /////////////////////////////////////////////////////////
    AudioSource(){}
    virtual ~AudioSource(){}
   
    /////////////////////////////////////////////////////////
    //! ????????,?
    /////////////////////////////////////////////////////////
    virtual bool Play(const engine_string& audiofile, bool loop) = 0;

    /////////////////////////////////////////////////////////
    //! ??????
    /////////////////////////////////////////////////////////
    virtual bool Stop() = 0;

    /////////////////////////////////////////////////////////
    //! ??????
    /////////////////////////////////////////////////////////
    virtual bool Pause() = 0;

    /////////////////////////////////////////////////////////
    //! ????????
    /////////////////////////////////////////////////////////
    virtual bool IsPlay()const = 0;
    virtual bool IsPause()const = 0;
    virtual bool IsStop()const = 0;
   
    /////////////////////////////////////////////////////////
    //! ??,?????? [0.0f,1.0f]
    /////////////////////////////////////////////////////////
    virtual void  SetVolume(float gain) = 0;
    virtual float GetVolume()const = 0;  
    virtual void  SetMaxVolume(float gain) = 0;
    virtual float GetMinVolume()const = 0;
    virtual void  SetMinVolume(float gain) = 0;
    virtual float GetMaxVolume()const = 0;   

    /////////////////////////////////////////////////////////
    /// ??, ??????(x,y,z)
    /////////////////////////////////////////////////////////
    virtual Vector3f GetSourcePosition()const = 0;
    virtual void SetSourcePosition(const Vector3f& position) = 0;
   
    /////////////////////////////////////////////////////////
    /// ??, ??????(x,y,z)
    /////////////////////////////////////////////////////////
    virtual Vector3f GetSourceDirection()const = 0 ;
    virtual void SetSourceDirection(const Vector3f& direction) = 0;   

    /////////////////////////////////////////////////////////
    /// ??, ??????
    /////////////////////////////////////////////////////////
    virtual Vector3f GetSourceVelocity()const = 0;
    virtual void SetSourceVelocity(const Vector3f& vel) = 0;

    /////////////////////////////////////////////////////////
    /// ??, ??????,??????
    /////////////////////////////////////////////////////////
    virtual void SetMaxDistance(float distance) = 0;
    virtual void GetMaxDistance(float &distance)= 0;
    virtual void SetMinDistance(float distance) = 0;
    virtual void GetMinDistance(float &distance)= 0;
   
    /////////////////////////////////////////////////////////
    /// ??, ???????[0.0,1.0]
    /////////////////////////////////////////////////////////
    virtual void  SetRolloffFactor(float factor) = 0;
    virtual float GetRolloffFactor()const=0;

    /////////////////////////////////////////////////////////
    /// ??, ???????(pitch????50%?????1?????)(0,+inf)
    /////////////////////////////////////////////////////////
    virtual void  SetPitch(float pitch) = 0;
    virtual float GetPitch()const = 0;
   
    /////////////////////////////////////////////////////////
    /// ????????????????
    /////////////////////////////////////////////////////////   
    virtual void  Move(const Vector3f &newpos) = 0;
   
    /////////////////////////////////////////////////////////
    /// ??, ?????(??,??,???)
    /////////////////////////////////////////////////////////
    virtual void SetAudioCone(float innerangle, float outerangle, float outergain) = 0;
    virtual void GetAudioCone(float &innerangle, float &outerangle, float &outergain) = 0;
   
    /////////////////////////////////////////////////////////
    /// ??, ?????????
    /////////////////////////////////////////////////////////   
    virtual void SetDopplerVelocity(const Vector3f& dvelocity) = 0;
    virtual Vector3f GetDopplerVelocity()const = 0;   
    virtual void SetDopplerStrength(float strength) = 0;           
    virtual float GetDopplerStrength()const = 0;
   
    /////////////////////////////////////////////////////////
    /// ??, ?????????????(0-+inf)
    /////////////////////////////////////////////////////////   
    virtual void SetStrength(float strength) = 0;            
    virtual float GetStrength()const = 0;
            
    /////////////////////////////////////////////////////////
    /// ??????,????????
    /////////////////////////////////////////////////////////
    virtual void SetAmbient(bool ambient) = 0;
    virtual bool IsAmbient() = 0;

    /////////////////////////////////////////////////////////
    /// ?????????????,?????????
    /////////////////////////////////////////////////////////
    virtual void SetRelative(bool relative) = 0;
    virtual bool IsRelative() = 0;

    /////////////////////////////////////////////////////////
    /// ?? Reverb?([0,1.0])
    /////////////////////////////////////////////////////////
    virtual bool SetReverbScale(float scale) = 0;
    /////////////////////////////////////////////////////////
    /// ?? Reverb?([0,1.0])
    /////////////////////////////////////////////////////////
    virtual bool SetReverbDelay(float delay) = 0;
   
public:   
    /////////////////////////////////////////////////////////
    /// ?????????
    /////////////////////////////////////////////////////////
    virtual bool AttachLowPassFiler(float gain = 1.2f, float gainhf = 0.6f) = 0;   
   
    /////////////////////////////////////////////////////////
    /// ??????
    /////////////////////////////////////////////////////////   
    virtual bool AttachAuxiliaryEffect() = 0;         
};

////////////////////////////////////////////////////////////
/// ?????????
////////////////////////////////////////////////////////////
class AudioCapture : public RefCount
{
public:
    /////////////////////////////////////////////////////////
    //! ??,??????
    /////////////////////////////////////////////////////////      
    AudioCapture(){}
    virtual ~AudioCapture(){}
   
    /////////////////////////////////////////////////////////
    //! ??,????????
    /////////////////////////////////////////////////////////     
    virtual void CaptureAudio() = 0;   
    virtual void CaptureStop() = 0;   
};

/////////////////////////////////////////////////////////
//! ????????
/////////////////////////////////////////////////////////
class AudioDevice : public RefCount
{
public:
    /////////////////////////////////////////////////////////
    //! ??,??????
    /////////////////////////////////////////////////////////
    AudioDevice(){}
    virtual ~AudioDevice(){}
   
    /////////////////////////////////////////////////////////
    //! ???,??????
    /////////////////////////////////////////////////////////      
    virtual bool Init(const  engine_string &devicename,
                      uint16 eax_effect_num,
                      uint16   output_freq) = 0;
    virtual bool Deinit() = 0;        
    /////////////////////////////////////////////////////////
    //! ?????????
    /////////////////////////////////////////////////////////
    virtual engine_string GetVerson() const = 0;

    /////////////////////////////////////////////////////////
    //! ????????
    /////////////////////////////////////////////////////////
    virtual engine_string GetMaker() const = 0;

    /////////////////////////////////////////////////////////
    //! ???????????????????
    /////////////////////////////////////////////////////////
    virtual bool IsSupport(const AudioFileType& type)const = 0;

    /////////////////////////////////////////////////////////
    //! ????????(?????255???)
    /////////////////////////////////////////////////////////
    virtual RefPtr<AudioSource>  GetAudioSource()const = 0;

    /////////////////////////////////////////////////////////
    //! ??????
    /////////////////////////////////////////////////////////
    virtual RefPtr<AudioListener> GetAudioListener()const = 0;
   
    /////////////////////////////////////////////////////////
    //! ??????????(???????)(??????wav??)(????)
    /////////////////////////////////////////////////////////     
    virtual RefPtr<AudioCapture> GetAudioCapture(const engine_string& name = "capture")const = 0;     
   
    /////////////////////////////////////////////////////////
    //! ??????????
    /////////////////////////////////////////////////////////
    virtual uint16 GetAudioDeviceNumber() = 0;  
    virtual engine_string GetDeviceByIndex(uint8 index) = 0;  
   
    /////////////////////////////////////////////////////////
    //! ???????
    /////////////////////////////////////////////////////////   
    virtual engine_string GetDefaultDeviceName()const = 0;   
};

/////////////////////////////////////////////////////////
//! ??????????
/////////////////////////////////////////////////////////
G_FUNC(RefPtr<AudioDevice>) GetAudioDevice();

}

#endif
//! maker:ccsdu2004

????dll???????? GetAudioDevice()

?????(API)
??????????3?:
1.http://www.libcode.cn/show.php?sid=85
2.http://www.pudn.com/downloads246/sourcecode/windows/multimedia/detail1145892.html
3.http://download.csdn.net/source/2290755
?????????????!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-10-15 01:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表