SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Sound.h
1 #pragma once
2 #include<Multimedia/SDX.h>
3 
4 namespace SDX
5 {
7 enum class PlayType
8 {
9 #ifdef DXLIB
10  Normal = DX_PLAYTYPE_NORMAL,
11  Back = DX_PLAYTYPE_BACK,
12  Loop = DX_PLAYTYPE_LOOP,
13 #elif defined(SDL)
14  Normal = 0,
15  Back = 0,
16  Loop = -1,
17 #endif
18 
19 };
20 
22 class Sound
24 {
25 private:
26  SoundHandle handle;
27 public:
28 
29  Sound(){}
30 
32  Sound(const char *ファイル名 , double 音量 = 1.0)
33  {
34  Load(ファイル名);
35  }
36 
38  int Load(const char *ファイル名 , double 音量 = 1.0)
39  {
40  #ifdef DXLIB
41  if(this->handle != NULL_HANDLE ) DxLib::DeleteSoundMem(handle);
42  DxLib::ChangeVolumeSoundMem(int(音量 * 255), this->handle);
43  return this->handle = DxLib::LoadSoundMem(ファイル名);
44  #elif defined(SDL)
45  handle = Mix_LoadWAV(ファイル名);
46  Mix_VolumeChunk(handle, int(音量 * 128));
47  return true;
48  #endif
49  }
50 
52  bool Release()
53  {
54  #ifdef DXLIB
55  return !DxLib::DeleteSoundMem(handle);
56  #elif defined(SDL)
57  Mix_FreeChunk(handle);
58  return true;
59  #endif
60  }
61 
63  SoundHandle GetHandle() const
64  {
65  return this->handle;
66  }
67 
69  bool Play(PlayType 再生方法 = PlayType::Back , bool 先頭から再生 = true) const
70  {
71  #ifdef DXLIB
72  return !DxLib::PlaySoundMem(this->handle, (int)再生方法, 先頭から再生);
73  #elif defined(SDL)
74  //Mix_HaltChannel(-1);
75  static int channel = 0;
76  Mix_PlayChannel(0, handle, (int)再生方法);
77  channel = (++channel) % 2;
78  return true;
79  #endif
80  }
81 
83  bool Check() const
84  {
85  #ifdef DXLIB
86  return !DxLib::CheckSoundMem(this->handle);
87  #elif defined(SDL)
88  return false;
89  #endif
90  }
91 
93  bool Stop()
94  {
95  #ifdef DXLIB
96  return !DxLib::StopSoundMem(this->handle);
97  #elif defined(SDL)
98  return false;
99  #endif
100  }
101 
103  bool SetPan(int 音声パン)
104  {
105  #ifdef DXLIB
106  return !DxLib::SetPanSoundMem(音声パン, this->handle);
107  #elif defined(SDL)
108  return false;
109  #endif
110  }
111 
113  bool SetVolume(double 音量)
114  {
115  #ifdef DXLIB
116  return !DxLib::ChangeVolumeSoundMem(int(音量 * 255), this->handle);
117  #elif defined(SDL)
118  Mix_VolumeChunk(handle, int(音量 * 128));
119  return false;
120  #endif
121  }
122 
124  bool SetFrequency(int 再生周波数)
126  {
127  #ifdef DXLIB
128  return !DxLib::SetFrequencySoundMem(再生周波数, this->handle);
129  #elif defined(SDL)
130  return false;
131  #endif
132  }
133 
135  bool SetLoopPos(int ループ位置)
136  {
137  #ifdef DXLIB
138  return !DxLib::SetLoopPosSoundMem(ループ位置, this->handle);
139  #elif defined(SDL)
140  return false;
141  #endif
142  }
143 
145  bool SetLoopSamplePos(int ループ周波数)
147  {
148  #ifdef DXLIB
149  return !DxLib::SetLoopSamplePosSoundMem(ループ周波数, this->handle);
150  #elif defined(SDL)
151  return false;
152  #endif
153  }
154 };
155 }
bool SetLoopSamplePos(int ループ周波数)
サンプリング周波数でループ位置を設定.
Definition: Sound.h:146
bool Play(PlayType 再生方法=PlayType::Back, bool 先頭から再生=true) const
音声ファイルを再生.
Definition: Sound.h:69
bool SetPan(int 音声パン)
音声パンを設定.
Definition: Sound.h:103
bool SetFrequency(int 再生周波数)
再生周波数を設定.
Definition: Sound.h:125
bool Check() const
再生中か判定.
Definition: Sound.h:83
Sound(const char *ファイル名, double 音量=1.0)
音声ファイルをメモリに読み込む.
Definition: Sound.h:32
SoundHandle GetHandle() const
ハンドルを取得.
Definition: Sound.h:63
int Load(const char *ファイル名, double 音量=1.0)
音声ファイルをメモリに読み込む.
Definition: Sound.h:38
bool SetVolume(double 音量)
音量を0~1.0の範囲で設定.
Definition: Sound.h:113
bool Release()
音声ファイルをメモリから開放.
Definition: Sound.h:52
bool SetLoopPos(int ループ位置)
ミリ秒単位でループ位置を設定.
Definition: Sound.h:135
bool Stop()
再生を停止.
Definition: Sound.h:93