updated codes to today CMCore/CMPlatform
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include<hgl/io/InputStream.h>
|
||||
// #include<hgl/HAC.H>
|
||||
#include<hgl/type/ObjectBuffer.h>
|
||||
//#include<hgl/type/ObjectBuffer.h>
|
||||
#include<hgl/audio/AudioFileType.h>
|
||||
|
||||
namespace hgl
|
||||
@@ -30,7 +30,7 @@ namespace hgl
|
||||
|
||||
AudioBuffer(void *,int,AudioFileType); ///<本类构造函数
|
||||
AudioBuffer(InputStream *,int,AudioFileType); ///<本类构造函数
|
||||
AudioBuffer(const os_char *filename=0,AudioFileType=aftNone); ///<本类构造函数
|
||||
AudioBuffer(const os_char *filename=0,AudioFileType=AudioFileType::None); ///<本类构造函数
|
||||
// AudioBuffer(HAC *,const os_char *,AudioFileType=aftNone); ///<本类构造函数
|
||||
virtual ~AudioBuffer(); ///<本类析构函数
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace hgl
|
||||
|
||||
bool Load(void *,int,AudioFileType); ///<从内存中加载音频数据
|
||||
bool Load(InputStream *,int,AudioFileType); ///<从流中加载音频数据
|
||||
bool Load(const os_char *,AudioFileType=aftNone); ///<从文件中加载音频数据
|
||||
bool Load(const os_char *,AudioFileType=AudioFileType::None); ///<从文件中加载音频数据
|
||||
// bool Load(HAC *,const os_char *,AudioFileType=aftNone); ///<从HAC包的文件中加载音频数据
|
||||
|
||||
void Clear(); ///<清除数据
|
||||
|
@@ -2,20 +2,21 @@
|
||||
#define HGL_AUDIO_FILE_TYPE_INCLUDE
|
||||
|
||||
#include<hgl/platform/Platform.h>
|
||||
#include<hgl/TypeFunc.h>
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
* 音频文件格式
|
||||
*/
|
||||
enum AudioFileType
|
||||
enum class AudioFileType
|
||||
{
|
||||
aftNone=0, ///<起始定义,如使用表示自动根据扩展名识别
|
||||
None=0, ///<起始定义,如使用表示自动根据扩展名识别
|
||||
|
||||
aftWAV, ///<Wav音波文件
|
||||
aftVorbis, ///<Vorbis OGG文件
|
||||
aftOpus, ///<Opus OGG文件
|
||||
Wav, ///<Wav音波文件
|
||||
Vorbis, ///<Vorbis OGG文件
|
||||
Opus, ///<Opus OGG文件
|
||||
|
||||
aftEnd
|
||||
ENUM_CLASS_RANGE(Wav,Opus)
|
||||
};//enum AudioFileType
|
||||
|
||||
AudioFileType CheckAudioExtName(const os_char *ext_name);
|
||||
|
@@ -1,82 +0,0 @@
|
||||
protected:
|
||||
|
||||
ALbyte *audio_data;
|
||||
int audio_data_size;
|
||||
|
||||
void *audio_ptr; ///<音频数据指针
|
||||
|
||||
char *audio_buffer;
|
||||
int audio_buffer_size;
|
||||
uint audio_buffer_count; ///<播放数据计数
|
||||
|
||||
AudioPlugInInterface *decode;
|
||||
|
||||
ALenum format; ///<音频数据格式
|
||||
ALsizei rate; ///<音频数据采样率
|
||||
|
||||
struct
|
||||
{
|
||||
bool open;
|
||||
uint64 time;
|
||||
float gap;
|
||||
|
||||
struct
|
||||
{
|
||||
float gain;
|
||||
double time;
|
||||
}start,end;
|
||||
}auto_gain; ///<自动增益
|
||||
|
||||
bool ReadData(ALuint);
|
||||
bool UpdateBuffer();
|
||||
void ClearBuffer();
|
||||
|
||||
bool Playback();
|
||||
|
||||
bool IsExitDelete()const override{return false;}
|
||||
bool Execute() override;
|
||||
|
||||
void InitPrivate();
|
||||
bool Load(AudioFileType);
|
||||
|
||||
protected:
|
||||
|
||||
volatile bool loop;
|
||||
volatile PlayState ps;
|
||||
|
||||
AudioSource audiosource;
|
||||
ALuint source;
|
||||
ALuint buffer[3];
|
||||
double time;
|
||||
double wait_time;
|
||||
|
||||
double gain;
|
||||
|
||||
double start_time;
|
||||
|
||||
double fade_in_time;
|
||||
double fade_out_time;
|
||||
|
||||
bool GetLoop();
|
||||
void SetLoop(bool);
|
||||
|
||||
public:
|
||||
|
||||
uint GetIndex(){return audiosource.index;}
|
||||
double GetTime(){return time;}
|
||||
PlayState GetPlayState(){return ps;}
|
||||
int GetSourceState(){return audiosource.GetState();}
|
||||
float GetMinGain(){return audiosource.GetMinGain();}
|
||||
float GetMaxGain(){return audiosource.GetMaxGain();}
|
||||
|
||||
float GetPitch(){return audiosource.pitch;}
|
||||
void SetPitch(float val){audiosource.SetPitch(val);}
|
||||
|
||||
float GetGain(){return audiosource.gain;}
|
||||
void SetGain(float val){audiosource.SetGain(val);}
|
||||
|
||||
float GetConeGain(){return audiosource.cone_gain;}
|
||||
void SetConeGain(float val){audiosource.SetConeGain(val);}
|
||||
|
||||
float GetRolloffFactor(){return audiosource.rolloff_factor;}
|
||||
void SetRolloffFactor(float rf){audiosource.SetRolloffFactor(rf);}
|
@@ -6,7 +6,7 @@
|
||||
#include<hgl/thread/ThreadMutex.h>
|
||||
#include<hgl/audio/OpenAL.h>
|
||||
#include<hgl/audio/AudioSource.h>
|
||||
#include<hgl/algorithm/VectorMath.h>
|
||||
#include<hgl/math/Math.h>
|
||||
using namespace openal;
|
||||
namespace hgl
|
||||
{
|
||||
@@ -17,6 +17,14 @@ namespace hgl
|
||||
|
||||
struct AudioPlugInInterface;
|
||||
|
||||
enum class PlayState //播放器状态
|
||||
{
|
||||
None=0,
|
||||
Play,
|
||||
Pause,
|
||||
Exit
|
||||
};
|
||||
|
||||
/**
|
||||
* 使用AudioPlayer创建的音频播放器类,一般用于背景音乐等独占的音频处理。
|
||||
* 这个音频播放器将使用一个单独的线程,在播放器被删除时线程也会被关闭。
|
||||
@@ -25,35 +33,91 @@ namespace hgl
|
||||
{
|
||||
ThreadMutex lock;
|
||||
|
||||
public:
|
||||
protected:
|
||||
|
||||
enum PlayState //播放器状态
|
||||
ALbyte *audio_data;
|
||||
int audio_data_size;
|
||||
|
||||
void *audio_ptr; ///<音频数据指针
|
||||
|
||||
char *audio_buffer;
|
||||
int audio_buffer_size;
|
||||
uint audio_buffer_count; ///<播放数据计数
|
||||
|
||||
AudioPlugInInterface *decode;
|
||||
|
||||
ALenum format; ///<音频数据格式
|
||||
ALsizei rate; ///<音频数据采样率
|
||||
|
||||
struct
|
||||
{
|
||||
psNone=0,
|
||||
psPlay,
|
||||
psPause,
|
||||
psExit
|
||||
};
|
||||
bool open;
|
||||
uint64 time;
|
||||
float gap;
|
||||
|
||||
#include<hgl/audio/AudioPlayer.Attrib.h>
|
||||
struct
|
||||
{
|
||||
float gain;
|
||||
double time;
|
||||
}start,end;
|
||||
}auto_gain; ///<自动增益
|
||||
|
||||
bool ReadData(ALuint);
|
||||
bool UpdateBuffer();
|
||||
void ClearBuffer();
|
||||
|
||||
bool Playback();
|
||||
|
||||
bool IsExitDelete()const override{return false;}
|
||||
bool Execute() override;
|
||||
|
||||
void InitPrivate();
|
||||
bool Load(AudioFileType);
|
||||
|
||||
protected:
|
||||
|
||||
volatile bool loop;
|
||||
volatile PlayState ps;
|
||||
|
||||
AudioSource audiosource;
|
||||
ALuint source;
|
||||
ALuint buffer[3];
|
||||
double total_time;
|
||||
double wait_time;
|
||||
|
||||
double gain;
|
||||
|
||||
double start_time;
|
||||
|
||||
double fade_in_time;
|
||||
double fade_out_time;
|
||||
|
||||
public: //属性
|
||||
|
||||
Property<uint> Index; ///<音源索引
|
||||
Property<double> Time; ///<音频总时间
|
||||
uint GetIndex()const{return audiosource.index;} ///<获取音源索引
|
||||
|
||||
Property<PlayState> State; ///<播放器状态
|
||||
Property<int> SourceState; ///<音源状态
|
||||
Property<float> MinGain; ///<最小增益
|
||||
Property<float> MaxGain; ///<最大增益
|
||||
double GetTotalTime()const{return total_time;} ///<获取音频总时长
|
||||
|
||||
Property<bool> Loop; ///<是否循环播放虚拟变量
|
||||
PlayState GetPlayState()const{return ps;} ///<获取播放器状态
|
||||
|
||||
Property<float> Pitch; ///<播放频率
|
||||
Property<float> Gain; ///<音量增益幅度
|
||||
Property<float> ConeGain; ///<
|
||||
int GetSourceState()const{return audiosource.GetState();} ///<获取音源索引
|
||||
|
||||
Property<float> RolloffFactor; ///<
|
||||
bool IsLoop(); ///<是否循环播放
|
||||
void SetLoop(bool); ///<设置循环播放
|
||||
|
||||
float GetGain()const{return audiosource.gain;} ///<获取音量增益
|
||||
float GetMinGain()const{return audiosource.GetMinGain();} ///<获取音量最小增益
|
||||
float GetMaxGain()const{return audiosource.GetMaxGain();} ///<获取音量最大增益
|
||||
float GetConeGain()const{return audiosource.cone_gain;} ///<获取音量锥形增益
|
||||
|
||||
void SetGain(float val){audiosource.SetGain(val);} ///<设置音量增益
|
||||
void SetConeGain(float val){audiosource.SetConeGain(val);} ///<设置音量锥形增益
|
||||
|
||||
float GetPitch()const{return audiosource.pitch;} ///<获取播放频率
|
||||
void SetPitch(float val){audiosource.SetPitch(val);} ///<设置播放频率
|
||||
|
||||
float GetRolloffFactor()const{return audiosource.rolloff_factor;} ///<获取Rolloff因子
|
||||
void SetRolloffFactor(float f){audiosource.SetRolloffFactor(f);} ///<设置Rolloff因子
|
||||
|
||||
public: //属性方法
|
||||
|
||||
@@ -76,13 +140,13 @@ namespace hgl
|
||||
|
||||
AudioPlayer();
|
||||
AudioPlayer(io::InputStream *,int,AudioFileType);
|
||||
AudioPlayer(const os_char *,AudioFileType=aftNone);
|
||||
// AudioPlayer(HAC *,const os_char *,AudioFileType=aftNone);
|
||||
AudioPlayer(const os_char *,AudioFileType=AudioFileType::None);
|
||||
// AudioPlayer(HAC *,const os_char *,AudioFileType=AudioFileType::None);
|
||||
virtual ~AudioPlayer();
|
||||
|
||||
virtual bool Load(io::InputStream *,int,AudioFileType); ///<从流中加载一个音频文件
|
||||
virtual bool Load(const os_char *,AudioFileType=aftNone); ///<加载一个音频文件
|
||||
// virtual bool Load(HAC *,const os_char *,AudioFileType=aftNone); ///<从HAC包中加载一个音频文件
|
||||
virtual bool Load(const os_char *,AudioFileType=AudioFileType::None); ///<加载一个音频文件
|
||||
// virtual bool Load(HAC *,const os_char *,AudioFileType=AudioFileType::None); ///<从HAC包中加载一个音频文件
|
||||
|
||||
virtual void Play(bool=true); ///<播放音频
|
||||
virtual void Stop(); ///<停止播放
|
||||
@@ -93,7 +157,7 @@ namespace hgl
|
||||
virtual double GetPlayTime(); ///<取得已播放时间(单位秒)
|
||||
virtual void SetFadeTime(double,double); ///<设置淡入淡出时间
|
||||
|
||||
virtual void AutoGain(float,double); ///<自动音量
|
||||
virtual void AutoGain(float,double,const double cur_time); ///<自动音量
|
||||
};//class AudioPlayer
|
||||
}//namespace hgl
|
||||
#endif//HGL_AUDIO_PLAYER_INCLUDE
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef HGL_AUDIO_SCENE_INCLUDE
|
||||
#define HGL_AUDIO_SCENE_INCLUDE
|
||||
|
||||
#include<hgl/algorithm/VectorMath.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/type/Pool.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/audio/ConeAngle.h>
|
||||
@@ -119,7 +119,7 @@ namespace hgl
|
||||
AudioListener *listener; ///<收聽者
|
||||
|
||||
ObjectPool<AudioSource> source_pool; ///<音源数据池
|
||||
Set<AudioSourceItem *> source_list; ///<音源列表
|
||||
SortedSets<AudioSourceItem *> source_list; ///<音源列表
|
||||
|
||||
protected:
|
||||
|
||||
|
@@ -1,67 +0,0 @@
|
||||
friend class AudioPlayer;
|
||||
|
||||
private:
|
||||
|
||||
void InitPrivate();
|
||||
|
||||
AudioBuffer *Buffer;
|
||||
|
||||
protected:
|
||||
|
||||
uint index;
|
||||
|
||||
bool pause;
|
||||
|
||||
bool loop;
|
||||
float pitch;
|
||||
float gain;
|
||||
float cone_gain;
|
||||
Vector3f position;
|
||||
Vector3f velocity;
|
||||
Vector3f direction;
|
||||
float ref_dist,max_dist;
|
||||
uint distance_model;
|
||||
float rolloff_factor;
|
||||
ConeAngle angle;
|
||||
|
||||
float doppler_factor;
|
||||
float doppler_velocity;
|
||||
|
||||
public:
|
||||
|
||||
uint GetIndex()const{return index;}
|
||||
|
||||
double GetCurTime();
|
||||
void SetCurTime(const double &);
|
||||
|
||||
int GetState();
|
||||
float GetMinGain();
|
||||
float GetMaxGain();
|
||||
|
||||
const bool GetLoop()const{return loop;}
|
||||
|
||||
const float GetPitch()const{return pitch;}
|
||||
const float GetGain()const{return gain;}
|
||||
const float GetConeGain()const{return cone_gain;}
|
||||
|
||||
const uint GetDistanceModel()const{return distance_model;}
|
||||
const float GetRolloffFactor()const{return rolloff_factor;}
|
||||
|
||||
const void GetDistance(float &rd,float &md)const
|
||||
{
|
||||
rd=ref_dist;
|
||||
md=max_dist;
|
||||
}
|
||||
|
||||
void GetDoppler(float &factor,float &velocity)
|
||||
{
|
||||
factor=doppler_factor;
|
||||
velocity=doppler_velocity;
|
||||
}
|
||||
|
||||
virtual void SetLoop(bool);
|
||||
void SetPitch(float);
|
||||
void SetGain(float);
|
||||
void SetConeGain(float);
|
||||
void SetDistanceModel(uint);
|
||||
void SetRolloffFactor(float);
|
@@ -3,6 +3,8 @@
|
||||
|
||||
#include<hgl/audio/ConeAngle.h>
|
||||
#include<hgl/audio/AudioBuffer.h>
|
||||
#include<hgl/al/al.h>
|
||||
#include<hgl/math/Math.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
@@ -13,41 +15,95 @@ namespace hgl
|
||||
*/
|
||||
class AudioSource ///音频源类
|
||||
{
|
||||
#include<hgl/audio/AudioSource.Attrib.h>
|
||||
friend class AudioPlayer;
|
||||
|
||||
private:
|
||||
|
||||
void InitPrivate();
|
||||
|
||||
AudioBuffer *Buffer;
|
||||
|
||||
protected:
|
||||
|
||||
uint index;
|
||||
|
||||
bool pause;
|
||||
|
||||
bool loop;
|
||||
float pitch;
|
||||
float gain;
|
||||
float cone_gain;
|
||||
Vector3f position;
|
||||
Vector3f velocity;
|
||||
Vector3f direction;
|
||||
float ref_dist,max_dist;
|
||||
uint distance_model;
|
||||
float rolloff_factor;
|
||||
ConeAngle angle;
|
||||
|
||||
float doppler_factor;
|
||||
float doppler_velocity;
|
||||
|
||||
public: //属性
|
||||
|
||||
Property<uint> Index;
|
||||
uint GetIndex()const{return index;} ///<获取当前音源索引
|
||||
int GetState()const; ///<获取当前音源状态
|
||||
|
||||
Property<double> CurTime; ///<当前播放到的时间
|
||||
const bool IsNone ()const{return GetState()==AL_NONE; }
|
||||
const bool IsStopped ()const{return GetState()==AL_STOPPED;}
|
||||
const bool IsPaused ()const{return GetState()==AL_PAUSED;}
|
||||
const bool IsPlaying ()const{return GetState()==AL_PLAYING;}
|
||||
|
||||
Property<int> State; ///<音源状态
|
||||
Property<float> MinGain; ///<最小增益
|
||||
Property<float> MaxGain; ///<最大增益
|
||||
double GetCurTime()const; ///<获取当前播放到的时间
|
||||
void SetCurTime(const double &); ///<设置当前播放时间
|
||||
|
||||
Property<bool> Loop; ///<是否循环播放虚拟变量
|
||||
float GetMinGain()const; ///<获取最小增益
|
||||
float GetMaxGain()const; ///<获取最大增益
|
||||
|
||||
Property<float> Pitch; ///<播放频率
|
||||
Property<float> Gain; ///<音量增益幅度
|
||||
Property<float> ConeGain; ///<音源锥增益
|
||||
const bool IsLoop()const{return loop;} ///<是否循环播放
|
||||
virtual void SetLoop(bool); ///<设置是否循环播放
|
||||
|
||||
Property<uint> DistanceModel; ///<距离衰减模型(默认钳位倒数距离模型)
|
||||
Property<float> RolloffFactor; ///<音源衰减因(>=0,默认1.0)
|
||||
const float GetPitch()const{return pitch;} ///<获取播放频率
|
||||
void SetPitch(float); ///<设置播放频率
|
||||
|
||||
public: //属性方法
|
||||
const float GetGain()const{return gain;} ///<获取音量增益幅度
|
||||
void SetGain(float); ///<设置音量增益幅度
|
||||
const float GetConeGain()const{return cone_gain;} ///<获取锥形音量增益幅度
|
||||
void SetConeGain(float); ///<设置锥形音量增益幅度
|
||||
|
||||
const Vector3f &GetPosition(){return position;}
|
||||
const Vector3f &GetVelocity(){return velocity;}
|
||||
const Vector3f &GetDirection(){return direction;}
|
||||
const ConeAngle &GetAngle(){return angle;}
|
||||
const uint GetDistanceModel()const{return distance_model;} ///<获取音量距离衰减模型
|
||||
void SetDistanceModel(uint); ///<设置音量距离衰减模型
|
||||
|
||||
void SetPosition(const Vector3f &);
|
||||
void SetVelocity(const Vector3f &);
|
||||
void SetDirection(const Vector3f &);
|
||||
void SetDistance(const float &ref_distance,const float &max_distance);
|
||||
void SetConeAngle(const ConeAngle &);
|
||||
void SetDopplerFactor(const float &); ///<设置多普勒效果强度
|
||||
void SetDopplerVelocity(const float &); ///<设置多普勒速度
|
||||
const float GetRolloffFactor()const{return rolloff_factor;} ///<获取音量衰减因子
|
||||
void SetRolloffFactor(float); ///<设置音量衰减因子(>=0,默认1.0)
|
||||
|
||||
void GetDoppler(float &factor,float &velocity)const ///<获取多普勒强度和速度
|
||||
{
|
||||
factor=doppler_factor;
|
||||
velocity=doppler_velocity;
|
||||
}
|
||||
|
||||
void SetDopplerFactor(const float &); ///<设置多普勒效果强度
|
||||
void SetDopplerVelocity(const float &); ///<设置多普勒速度
|
||||
|
||||
const void GetDistance(float &rd,float &md)const ///<获取音源距离范围
|
||||
{
|
||||
rd=ref_dist;
|
||||
md=max_dist;
|
||||
}
|
||||
void SetDistance(const float &ref_distance,const float &max_distance); ///<设置音源距离范围
|
||||
|
||||
const Vector3f &GetPosition()const{return position;} ///<获取音源位置
|
||||
void SetPosition(const Vector3f &); ///<设置音源位置
|
||||
|
||||
const Vector3f &GetVelocity()const{return velocity;} ///<获取速度
|
||||
void SetVelocity(const Vector3f &); ///<设置速度
|
||||
|
||||
const Vector3f &GetDirection()const{return direction;} ///<获取发声方向
|
||||
void SetDirection(const Vector3f &); ///<设置发声方向
|
||||
|
||||
const ConeAngle &GetAngle()const{return angle;} ///<获取发声锥形角度
|
||||
void SetConeAngle(const ConeAngle &); ///<设置发声锥形角度
|
||||
|
||||
public: //方法
|
||||
|
||||
@@ -65,8 +121,8 @@ namespace hgl
|
||||
virtual bool Create(); ///<创建音源
|
||||
virtual void Close(); ///<关闭音源
|
||||
|
||||
bool Link(AudioBuffer *); ///<绑定一个音频缓冲区
|
||||
void Unlink(); ///<解除绑定
|
||||
bool Link(AudioBuffer *); ///<绑定一个音频缓冲区
|
||||
void Unlink(); ///<解除绑定
|
||||
};//class AudioSource
|
||||
}//namespace hgl
|
||||
#endif//HGL_AUDIO_SOURCE_INCLUDE
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef HGL_LISTENER_INCLUDE
|
||||
#define HGL_LISTENER_INCLUDE
|
||||
|
||||
#include<hgl/algorithm/VectorMath.h>
|
||||
#include<hgl/math/math.h>
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
|
Reference in New Issue
Block a user