SDXFrameWork  0.13
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Public Member Functions | Static Public Member Functions | List of all members
SDX::Sound Class Reference

効果音用音声を表すクラス. More...

#include <Sound.h>

Public Member Functions

 Sound (const char *ファイル名, double 音量=1.0)
 音声ファイルをメモリに読み込む. More...
 
bool Load (const char *ファイル名, double 音量=1.0)
 音声ファイルをメモリに読み込む. More...
 
bool Release ()
 音声ファイルをメモリから開放. More...
 
Mix_Chunk * GetHandle () const
 ハンドルを取得. More...
 
bool Play () const
 音声ファイルを再生. More...
 
bool SetVolume (double 音量)
 音量を0~1.0の範囲で設定. More...
 
double GetVolume ()
 音量を取得. More...
 
void SetPanning (double 左パン=1.0, double 右パン=1.0)
 音声パンを設定. More...
 
void Set3DEffect (double 距離=-1, double 角度=0)
 3D音声再生効果を付ける. More...
 

Static Public Member Functions

static void SetMainVolume (double 音量)
 全体の音量を0~1.0の範囲で設定. More...
 

Detailed Description

効果音用音声を表すクラス.

//Copyright © 2014 SDXFramework
//[License]GNU Affero General Public License, version 3
//[Contact]http://sourceforge.jp/projects/dxframework/
//ライブラリの初期化等を行う
#include <SDXFramework.h>
bool SampleSound()
{
using namespace SDX;
System::Initialise("sample", 640, 480);//ウィンドウタイトルを指定して、初期化する
Sound seA("data/se_maoudamashii_onepoint14.wav");
Sound seB("data/se_maoudamashii_onepoint15.wav");
Sound *nowSE = &seA;
double distance = 0.0;
double angle = 0.0;
while (System::Update())//ウィンドウの更新や、入力の更新等を行う
{
Drawing::String({ 10, 10 }, Color::White, "AとBでSEの種類変更\nZXで音量変更、RLでパン設定、カーソルキーで3D効果");
Drawing::String({ 10, 50 }, Color::White, { "音量 = ", nowSE->GetVolume(),"\n角度 = ",angle,"\n距離 = " , distance });
//AとBで再生対象変更
if (Input::key.A.on)
{
nowSE = &seA;
nowSE->Play();
}
if (Input::key.B.on)
{
nowSE = &seB;
nowSE->Play();
}
//ZとXで音量変更
if (Input::key.Z.on)
{
nowSE->SetVolume(nowSE->GetVolume() - 0.1);
nowSE->Play();
}
if (Input::key.X.on)
{
nowSE->Set3DEffect();
nowSE->SetVolume(nowSE->GetVolume() + 0.1);
nowSE->Play();
}
//RとLでパニング
if (Input::key.R.on)
{
nowSE->Set3DEffect();
nowSE->SetPanning(0.5, 1.0);
nowSE->Play();
nowSE->SetPanning();
}
if (Input::key.L.on)
{
nowSE->Set3DEffect();
nowSE->SetPanning(1.0, 0.5);
nowSE->Play();
nowSE->SetPanning();
}
//上下左右カーソルで3D効果
if (Input::key.Left.on)
{
angle -= 0.1;
nowSE->Set3DEffect(distance, angle);
nowSE->Play();
}
if (Input::key.Right.on)
{
angle += 0.1;
nowSE->Set3DEffect(distance, angle);
nowSE->Play();
}
if (Input::key.Up.on)
{
distance += 0.1;
if (distance >= 1){ distance = 1; }
nowSE->Set3DEffect(distance,angle);
nowSE->Play();
}
if (Input::key.Down.on)
{
distance -= 0.1;
if (distance <= 0){ distance = 0; }
nowSE->Set3DEffect(distance, angle);
nowSE->Play();
}
if (Input::key.Return.on){ break;}//Enterで終了
}
System::End();//ライブラリの終了処理を行う
return true;
}
Todo:
同時に複数の効果音を鳴らす場合の挙動に不安

Constructor & Destructor Documentation

SDX::Sound::Sound ( const char *  ファイル名,
double  音量 = 1.0 
)
inline

音声ファイルをメモリに読み込む.

Member Function Documentation

bool SDX::Sound::Load ( const char *  ファイル名,
double  音量 = 1.0 
)
inline

音声ファイルをメモリに読み込む.

bool SDX::Sound::Release ( )
inline

音声ファイルをメモリから開放.

Mix_Chunk* SDX::Sound::GetHandle ( ) const
inline

ハンドルを取得.

bool SDX::Sound::Play ( ) const
inline

音声ファイルを再生.

bool SDX::Sound::SetVolume ( double  音量)
inline

音量を0~1.0の範囲で設定.

double SDX::Sound::GetVolume ( )
inline

音量を取得.

void SDX::Sound::SetPanning ( double  左パン = 1.0,
double  右パン = 1.0 
)
inline

音声パンを設定.

スピーカー左右の音量を変える、0.0~1.0

void SDX::Sound::Set3DEffect ( double  距離 = -1,
double  角度 = 0 
)
inline

3D音声再生効果を付ける.

距離は[近]0~1.0[遠]、角度は[正面]0[左]-PAI/2[右]PAI/2で指定 距離を0以下にすると無効になる SetPanよりこっちが優先される

Todo:
距離指定がバグってる?
static void SDX::Sound::SetMainVolume ( double  音量)
inlinestatic

全体の音量を0~1.0の範囲で設定.

一度もこの関数を使用していない場合は最大音量