|
??????1.4.2??
1.????win7,xp,vista
2.????c++
3.?????vc6.0,vc7.1,vc8,vc9,devc++,codeblock
4.??????flac,aiff,wav,it,mod,s3m,xm,ogg,mp3
5.????:???????
6.???????????
?????????????:????
????:
1.??????????
???alpha??,betha?????
2.????xbox,iphone?
?????.?????????
3.?????midi?
??????
4.????Python????
??????
5.??????????????
??????(??????)
6.?????????
???,?????????
7.?????????
???????
8.????????,???????????
??????????????
0.???????
3??
10.????????????log???
??????
11.????????????????
??????
12.??????????????
????
13.??????
???????
14.?????????:ccsdu2004@yahoo.com.cn??
????:
1.vc?? ??????vc6.0,vc7.1,vc8,vc9:
http://www.pudn.com/downloads258/sourcecode/game/detail1192191.html
http://download.csdn.net/source/2403577
2.gcc?? ??????devc++,codeblock
http://www.pudn.com/downloads258/sourcecode/multimedia/audio/detail1192125.html
http://ccsdu2004.download.csdn.net/
???????:
//! ????3d???????????????????????
//! ??????????,????????,???????
//! ???????????????????
//! websize:www.gaimo.net
//! email:ccsdu2004@yahoo.com.cn
//! telephone:+86-028-67607663,
//! fax: +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.2 alpha??????(?????)
* 1.????:xp,vista,win7
* 2.?????vc6,vc7,vc9,codeblock,devc++
* 3.??pdf??????
* 4.???aiff,flac,midi???????
* 5.?????????
****************************************************************************/
/*!==========================================================================
* 1.5.0????
* 1.????:???C#,Python,Lua,??????
* 2.????:???Linux???
* 3.????????
* 4.????(??????)
* 5.???????APE,WMA???
****************************************************************************/
/*!==========================================================================
* ??????????
* 1.???????(?mac,xbox,unix)
* 2.???????(C#,Python,Dephi,???,)
* 3.??OpenAL????
* 4.????????
****************************************************************************/
/*!==========================================================================
* ??????????????
* 1.??????,?????????????????????????
****************************************************************************/
#ifndef GAIMO_AUDIODEVICE_HPP
#define GAIMO_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
{
--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{return object;}
T& operator*() const{return *object;}
bool operator<(const RefPtr<T>& other)const{return object < other.get();}
operator bool() const {return object != NULL;}
protected:
T* object;
};
/////////////////////////////////////////////////////////
//! ????????
/////////////////////////////////////////////////////////
enum AUDIO_FILE_TYPE
{
//! WAV????
AUDIO_FILE_TYPE_WAV = 0, //! ??
//! OGG????
AUDIO_FILE_TYPE_OGG, //! ??
//! MP3????
AUDIO_FILE_TYPE_MP3, //! ??
//! XM,IT,MOD,S3M??
AUDIO_FILE_TYPE_XM, //! ??
AUDIO_FILE_TYPE_IT, //! ??
AUDIO_FILE_TYPE_MOD, //! ??
AUDIO_FILE_TYPE_S3M, //! ??
//! AU??
AUDIO_FILE_TYPE_AU,
//! AIFF??
AUDIO_FILE_TYPE_AIFF, //! ??
//! ??WMA??
AUDIO_FILE_TYPE_WMA,
//! APE????
AUDIO_FILE_TYPE_APE,
//! MIDI????
AUDIO_FILE_TYPE_MIDI,
//! FLAC????
AUDIO_FILE_TYPE_FLAC, //! ??
//! ??????
AUDIO_FILE_TYPE_NULL
};
////////////////////////////////////////////////////////////
/// ??????????
////////////////////////////////////////////////////////////
enum AUDIO_DISTANCE_MODE
{
AUDIO_DISTANCE_MODEL = 0,
AUDIO_INVERSE_DISTANCE,
AUDIO_INVERSE_DISTANCE_CLAMPED,
AUDIO_LINEAR_DISTANCE,
AUDIO_LINEAR_DISTANCE_CLAMPED,
AUDIO_EXPONENT_DISTANCE,
AUDIO_EXPONENT_DISTANCE_CLAMPED,
AUDIO_DISTANCE_MODE_NULL
};
/////////////////////////////////////////////////////////
//! ??????
/////////////////////////////////////////////////////////
enum AUDIO_EFFECT_TYPE
{
AUDIO_EFFECT_TYPE_REVERB = 0,
AUDIO_EFFECT_TYPE_EFXREVERB,
AUDIO_EFFECT_TYPE_CHORUS,
AUDIO_EFFECT_TYPE_DISTORTION,
AUDIO_EFFECT_TYPE_ECHO,
AUDIO_EFFECT_TYPE_FLANGER,
AUDIO_EFFECT_TYPE_FREQUENCY_SHIFTER,
AUDIO_EFFECT_TYPE_VOCAL_MORPHER,
AUDIO_EFFECT_TYPE_PITCH_SHIFTER,
AUDIO_EFFECT_TYPE_RING_MODULATOR,
AUDIO_EFFECT_TYPE_AUTOWAH,
AUDIO_EFFECT_TYPE_COMPRESSOR,
AUDIO_EFFECT_TYPE_EQUALIZER,
AUDIO_EFFECT_TYPE_COUNT,
AUDIO_EFFECT_TYPE_NULL
};
/////////////////////////////////////////////////////////
//! ?????????
/////////////////////////////////////////////////////////
enum AUDIO_FILTER_TYPE
{
AUDIO_FILTER_TYPE_LOWPASS,
AUDIO_FILTER_TYPE_HIGHPASS,
AUDIO_FILTER_TYPE_BANDPASS,
AUDIO_FILTER_TYPE_COUNT,
AUDIO_FILTER_TYPE_NULL
};
//! ????????
const float AUDIO_SPACE_VELOCITY = 343.0f;
//! ?????????
const float AUDIO_DOPPLER_FACTOR = 1.0f;
/////////////////////////////////////////////////////////
/// ????????
/////////////////////////////////////////////////////////
class AudioObject : public RefCount
{
public:
/////////////////////////////////////////////////////
//! ??,????????
/////////////////////////////////////////////////////
virtual void SetPosition(float x,float y,float z) = 0;
virtual void GetPosition(float &x,float &y,float &z) = 0;
/////////////////////////////////////////////////////
//! ??,????????
/////////////////////////////////////////////////////
virtual void SetDirection(float dirx,float diry,float dirz) = 0;
virtual void GetDirection(float &dirx,float &diry,float &dirz) = 0;
/////////////////////////////////////////////////////
//! ??,????????
/////////////////////////////////////////////////////
virtual void SetVelocity(float velx,float vely,float velz) = 0;
virtual void GetVelocity(float &velx,float &vely,float &velz) = 0;
////////////////////////////////////////////////////
//! ??????(????????????)
////////////////////////////////////////////////////
virtual void Move(float offsetx,float offsety,float offsetz) = 0;
};
/////////////////////////////////////////////////////////
/// ?????????
/////////////////////////////////////////////////////////
class AudioFilter : public RefCount
{
public:
////////////////////////////////////////////////////////
//! ??,?????????[0,1]
////////////////////////////////////////////////////////
virtual bool SetVolume(const float& volume) = 0;
virtual float GetVolume()const = 0;
////////////////////////////////////////////////////////
//! ??,??????
////////////////////////////////////////////////////////
virtual bool SetLowVolume(const float &volume) = 0;
virtual float GetLowVolume()const = 0;
////////////////////////////////////////////////////////
//! ??,???????
////////////////////////////////////////////////////////
virtual bool SetHighVolume(const float &volume) = 0;
virtual float GetHighVolume() const = 0;
////////////////////////////////////////////////////////
//! ?????????
////////////////////////////////////////////////////////
virtual bool IsValid() const = 0;
};
/////////////////////////////////////////////////////////
/// ????????
/////////////////////////////////////////////////////////
class AudioListener : public AudioObject
{
public:
/////////////////////////////////////////////////////
//! ??,??????(0.0f,1.0f)
/////////////////////////////////////////////////////
virtual void SetGlobalVolume(float volume) = 0;
virtual float GetGlobalVolume()const = 0;
};
////////////////////////////////////////////////////////
//! ???????????
////////////////////////////////////////////////////////
class AudioSource : public AudioObject
{
public:
////////////////////////////////////////////////////
//! ????????(2D??)
////////////////////////////////////////////////////
virtual bool Play(const engine_string& audiofile,bool loop = false) = 0;
////////////////////////////////////////////////////
//! ????????(3D??)(??:??????,??????,??????,????,????)
////////////////////////////////////////////////////
virtual bool Play(const engine_string& audiofile,bool loop,float mindist,float maxdist,float strength = 0.3f) = 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;
///////////////////////////////////////////////////
/// ??,??????,??????(??3D????)
///////////////////////////////////////////////////
virtual void SetMaxDistance(float distance) = 0;
virtual void GetMaxDistance(float &distance)= 0;
virtual void SetMinDistance(float distance) = 0;
virtual void GetMinDistance(float &distance)= 0;
///////////////////////////////////////////////////
/// ??,?????(??,??,???)(??3D????)
///////////////////////////////////////////////////
virtual void SetAudioCone(float innerangle,float outerangle,float outergain) = 0;
virtual void GetAudioCone(float &innerangle,float &outerangle,float &outergain) = 0;
};
//////////////////////////////////////////////////////
/// ?????????
//////////////////////////////////////////////////////
class AudioCapture : public RefCount
{
public:
//////////////////////////////////////////////////
//! ??,????????
//////////////////////////////////////////////////
virtual void CaptureAudio() = 0;
virtual void CaptureStop() = 0;
};
//////////////////////////////////////////////////////
//! ????????
//////////////////////////////////////////////////////
class AudioDevice : public RefCount
{
public:
/////////////////////////////////////////////////
//! ?????????
/////////////////////////////////////////////////
virtual engine_string GetVerson() const = 0;
/////////////////////////////////////////////////
//! ????????
/////////////////////////////////////////////////
virtual engine_string GetMaker() const = 0;
/////////////////////////////////////////////////
//! ???????????????????
/////////////////////////////////////////////////
virtual bool IsSupport(const AUDIO_FILE_TYPE& type)const = 0;
/////////////////////////////////////////////////
//! ????????(?????255???)
/////////////////////////////////////////////////
virtual RefPtr<AudioSource> GetAudioSource()const = 0;
/////////////////////////////////////////////////
//! ??????(????)(??:??)
/////////////////////////////////////////////////
virtual RefPtr<AudioListener> GetAudioListener(float x,float y,float z)= 0;
/////////////////////////////////////////////////
//! ??????????(???????)(??????wav??)(????)
/////////////////////////////////////////////////
virtual RefPtr<AudioCapture> GetAudioCapture(const engine_string& name = "capture")const = 0;
/////////////////////////////////////////////////
//! ??,????????
/////////////////////////////////////////////////
virtual void SetMetersPerUnit(float meters) = 0;
virtual float GetMetersPerUnit(void) const = 0;
/////////////////////////////////////////////////
//! ????????????????
/////////////////////////////////////////////////
virtual int GetMaxEffectMuber()const = 0;
/////////////////////////////////////////////////
//! ???????(???1.0f,343.3)
/////////////////////////////////////////////////
virtual void SetDoppler(float factor,float vel) = 0;
/////////////////////////////////////////////////
//! ??????????
/////////////////////////////////////////////////
virtual void SetDistanceModel(const AUDIO_DISTANCE_MODE &model) = 0;
};
/////////////////////////////////////////////////////
//! ??????????????????(????????NULL)
/////////////////////////////////////////////////////
G_FUNC(AudioDevice*) InitAudioDevice();
/////////////////////////////////////////////////////
//! ????????(??????)
/////////////////////////////////////////////////////
G_FUNC(void) TerminateAudioDevice();
}
#endif
//! maker:ccsdu2004
??4??demo??:
1.
/*!==========================================================================
*
* ??????(GaiMo Game Engine)
*
* ???? (C) 2009-2009 ??????????? ??????
* Copyright (C) ???????????. All Rights Reserved.
*
* ??????,??? http://www.gaimo.net
****************************************************************************/
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <AudioDevice.hpp>
int main()
{
std::cout<<"??????????!"<<std::endl;
//! ??????????????
core::AudioDevice *device = core::InitAudioDevice();
//! ??????
core::RefPtr<core::AudioSource> source = device->GetAudioSource();
//! ????????
std::cout<<"play:"<<source-> lay("..\\audio//?????.aif",true)<<std::endl;
while(getche() != 'q');
core::TerminateAudioDevice();
system("pause");
return EXIT_SUCCESS;
}
2.
/*!==========================================================================
*
* ??????(GaiMo Game Engine)
*
* ???? (C) 2009-2009 ??????????? ??????
* Copyright (C) ???????????. All Rights Reserved.
*
* ??????,??? http://www.gaimo.net
****************************************************************************/
#include <AudioDevice.hpp>
#include <conio.h>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define MAX_DST 10
#define MAX_POS 20
int main()
{
std::cout<<"??????????!"<<std::endl;
core::AudioDevice *device = core::InitAudioDevice(); ;
//! ??????
core::RefPtr<core::AudioSource> source = device->GetAudioSource();
std::cout<<"play:"<<source->Play("..\\audio//??.wav",true,0,MAX_DST)<<std::endl;
float itr = 0;
while(1)
{
float x = MAX_POS * cosf(itr);
float z = MAX_POS * cosf(itr);
source->Move(x,0,z);
itr+= 0.0001*0.017453293f;
}
core::TerminateAudioDevice();
system("pause");
return EXIT_SUCCESS;
}
3.
#include <AudioDevice.hpp>
#include <iostream>
#include <conio.h>
#include <windows.h>
#define CAPTURE_TIME 30000
int main()
{
std::cout<<"??????????!"<<std::endl;
//! ??????????????
core::AudioDevice *device = core::InitAudioDevice();
//! ??????
core::RefPtr<core::AudioSource> source = device->GetAudioSource();
//! ????????
core::RefPtr<core::AudioCapture> capture = device->GetAudioCapture("capture");
//! ????????
std::cout<<"play:"<<source->Play("..\\audio//glance.xm",true)<<std::endl;
capture->CaptureAudio();
unsigned long time = timeGetTime();
while(1)
{
if(timeGetTime() - time > CAPTURE_TIME)
break;
}
capture->CaptureStop();
core::TerminateAudioDevice();
return 1;
}
4.
/*!==========================================================================
*
* ??????(GaiMo Game Engine)
*
* ???? (C) 2009-2009 ??????????? ??????
* Copyright (C) ???????????. All Rights Reserved.
*
* ??????,??? http://www.gaimo.net
****************************************************************************/
#include <iostream>
#include <conio.h>
#include <AudioDevice.hpp>
char* mp3 = "..\\audio//DarinPeerless.mp3";
char* ogg = "..\\audio//GetOut.ogg";
char* xm = "..\\audio//Azure.xm";
char* s3m = "..\\audio//Friday.s3m";
char* mod = "..\\audio//Gimme the beat boys.mod";
char* aiff = "..\\audio//?????.aif";
char* flac = "..\\audio//duck.flac";
short flag = 0;
int main()
{
std::cout<<"??????????!"<<std::endl;
//! ??????????????
core::AudioDevice *device = core::InitAudioDevice();
std::cout<<"??0??mp3"<<std::endl;
std::cout<<"??1??ogg"<<std::endl;
std::cout<<"??2??xm"<<std::endl;
std::cout<<"??3??s3m"<<std::endl;
std::cout<<"??4??mod"<<std::endl;
std::cout<<"??5??aiff"<<std::endl;
std::cout<<"??6??flac"<<std::endl;
std::cin >> flag;
std::cout << std::endl;
//! ??????
core::RefPtr<core::AudioSource> source = device->GetAudioSource();
source->SetVolume(1.0f);
//! ????????
if(flag == 0)
std::cout<<"play:"<<source->Play(mp3,true)<<std::endl;
else if(flag == 1)
std::cout<<"play:"<<source->Play(ogg,true)<<std::endl;
else if(flag == 2)
std::cout<<"play:"<<source->Play(xm,true)<<std::endl;
else if(flag == 3)
std::cout<<"play:"<<source->Play(s3m,true)<<std::endl;
else if(flag == 4)
std::cout<<"play:"<<source->Play(mod,true)<<std::endl;
else if(flag == 5)
std::cout<<"play:"<<source->Play(aiff,true)<<std::endl;
else if(flag == 6)
std::cout<<"play:"<<source->Play(flac,true)<<std::endl;
while(getche() != 'q');
core::TerminateAudioDevice();
system("pause");
return EXIT_SUCCESS;
}
|
|