2 using System.Collections.Generic;
\r
4 using System.Diagnostics;
\r
7 using SlimDX.DirectSound;
\r
11 public class CSound管理 : IDisposable
\r
15 public static int nバッファの数 = 0x20;
\r
16 public static int nキープする再生済みバッファの数 = (nバッファの数 / 3);
\r
17 public static int nバッファサイズ = 0x1000;
\r
18 public static int n最大オンメモリ可能サイズ = 0x300000;
\r
23 // public DirectSound Device { get; private set; }
\r
24 private DirectSound Device;
\r
25 private void setDevice( DirectSound Device_ )
\r
29 public DirectSound getDevice()
\r
38 if( this.listSound == null )
\r
42 return this.listSound.Count;
\r
49 public CSound管理( IntPtr hWnd )
\r
53 this.Device = new SlimDX.DirectSound.DirectSound();
\r
54 Trace.TraceInformation( "MaxHardwareMixing: AllBuffers={0}, StaticBuffers={1}, StreamingBuffers={2}", new object[] { this.Device.Capabilities.MaxHardwareMixingAllBuffers, this.Device.Capabilities.MaxHardwareMixingStaticBuffers, this.Device.Capabilities.MaxHardwareMixingStreamingBuffers } );
\r
55 Trace.TraceInformation( "FreeHardwareMixing: AllBuffers={0}, StaticBuffers={1}, StreamingBuffers={2}", new object[] { this.Device.Capabilities.FreeHardwareMixingAllBuffers, this.Device.Capabilities.FreeHardwareMixingStaticBuffers, this.Device.Capabilities.FreeHardwareMixingStreamingBuffers } );
\r
56 Trace.TraceInformation( "FreeHardwareMemory: {0}", new object[] { this.Device.Capabilities.FreeHardwareMemory } );
\r
57 Trace.TraceInformation( "MaxContiguousFreeHardwareMemoryBytes: {0}", new object[] { this.Device.Capabilities.MaxContiguousFreeHardwareMemoryBytes } );
\r
58 Trace.TraceInformation( "SecondarySampleRate: {0} - {1} Hz", new object[] { this.Device.Capabilities.MinSecondarySampleRate, this.Device.Capabilities.MaxSecondarySampleRate } );
\r
59 Trace.TraceInformation( "PlayCpuOverheadSoftwareBuffers: {0}", new object[] { this.Device.Capabilities.PlayCpuOverheadSoftwareBuffers } );
\r
60 Trace.TraceInformation( "PrimaryBuffers: {0}", new object[] { this.Device.Capabilities.PrimaryBuffers } );
\r
61 Trace.TraceInformation( "Primary 8Bit:{0}, 16Bit:{1}, Mono:{2}, Stereo:{3}", new object[] { this.Device.Capabilities.Primary8Bit ? "supported" : "not supported", this.Device.Capabilities.Primary16Bit ? "supported" : "not supported", this.Device.Capabilities.PrimaryMono ? "supported" : "not supported", this.Device.Capabilities.PrimaryStereo ? "supported" : "not supported" } );
\r
62 Trace.TraceInformation( "Secondary 8Bit:{0}, 16Bit:{1}, Mono:{2}, Stereo:{3}", new object[] { this.Device.Capabilities.Secondary8Bit ? "supported" : "not supported", this.Device.Capabilities.Secondary16Bit ? "supported" : "not supported", this.Device.Capabilities.SecondaryMono ? "supported" : "not supported", this.Device.Capabilities.SecondaryStereo ? "supported" : "not supported" } );
\r
63 Trace.TraceInformation( "TotalHardwareMemory: {0}", new object[] { this.Device.Capabilities.TotalHardwareMemory } );
\r
64 Trace.TraceInformation( "UnlockTransferRateHardwareBuffers: {0}", new object[] { this.Device.Capabilities.UnlockTransferRateHardwareBuffers } );
\r
66 catch( DirectSoundException exception )
\r
68 Trace.TraceError( exception.Message );
\r
69 Trace.TraceError( "DirectSound デバイスの作成に失敗しました。" );
\r
75 this.Device.SetCooperativeLevel( hWnd, CooperativeLevel.Priority );
\r
76 Trace.TraceInformation( " DirectSound デバイスの協調レベルを Priority に設定しました。" );
\r
78 catch( DirectSoundException )
\r
82 this.Device.SetCooperativeLevel( hWnd, CooperativeLevel.Normal );
\r
83 Trace.TraceInformation( " DirectSound デバイスの協調レベルを Normal に設定しました。" );
\r
85 catch( DirectSoundException )
\r
88 Trace.TraceError( " DirectSound デバイスの協調レベルの設定に失敗しました。" );
\r
96 public CSound tサウンドを生成する( string strファイル名 )
\r
98 if( string.IsNullOrEmpty( strファイル名 ) || !File.Exists( strファイル名 ) )
\r
99 throw new ArgumentException( "ファイル名が無効です。" );
\r
101 CSound item = null;
\r
102 // if( ( ( ( item = this.tネイティブOggVorbisの場合( strファイル名 ) ) == null ) && ( ( item = this.tネイティブXAの場合( strファイル名 ) ) == null ) ) && ( ( ( item = this.tネイティブmp3の場合( strファイル名 ) ) == null ) && ( ( item = this.tRIFF_WAVEの場合( strファイル名 ) ) == null ) ) )
\r
103 if ( (item = this.tCheckAndDecode(strファイル名)) == null)
\r
104 throw new Exception( "OggVorbis, mp3, XA, RIFF ACM のいずれでもデコードに失敗しました。" );
\r
106 item.setDevice( ref this.Device );
\r
107 tサウンドを登録する( item );
\r
111 public void tサウンドを登録する( CSound sound )
\r
113 lock ( this.obj排他用 )
\r
115 this.listSound.Add( sound );
\r
119 public void t再生中の処理をする( object o ) // #26122 2011.9.1 yyagi; delegate経由の呼び出し用
\r
123 public void t再生中の処理をする()
\r
125 lock( this.obj排他用 )
\r
127 foreach( CSound sound in this.listSound )
\r
129 if( sound.b再生中 && sound.bストリーム再生する )
\r
131 sound.t再生中の処理をする();
\r
136 public void tサウンドを破棄する( CSound sound )
\r
138 lock( this.obj排他用 )
\r
140 if( sound != null )
\r
143 this.listSound.Remove( sound );
\r
148 #region [ IDisposable 実装 ]
\r
149 //-----------------
\r
150 public void Dispose()
\r
152 if( !this.bDisposed )
\r
154 foreach( CSound sound in this.listSound )
\r
158 this.listSound.Clear();
\r
159 if( this.Device != null )
\r
161 this.Device.Dispose();
\r
162 this.Device = null;
\r
165 this.bDisposed = true;
\r
168 //-----------------
\r
174 #region [ private ]
\r
175 //-----------------
\r
176 private object obj排他用 = new object();
\r
177 private bool bDisposed = false;
\r
178 private List<CSound> listSound = new List<CSound>();
\r
181 private CSound tCheckAndDecode(string strFilename)
\r
183 int nDecodedPCMsize;
\r
186 CSound csound = new CSoundOggVorbis();
\r
187 nDecodedPCMsize = csound.tデコード後のサイズを調べる(strFilename, out nHandle);
\r
188 if (nDecodedPCMsize < 0)
\r
191 csound = new CSoundXA();
\r
192 nDecodedPCMsize = csound.tデコード後のサイズを調べる(strFilename, out nHandle);
\r
193 if (nDecodedPCMsize < 0)
\r
196 csound = new CSoundRiffWave();
\r
197 nDecodedPCMsize = csound.tデコード後のサイズを調べる(strFilename, out nHandle);
\r
198 if (nDecodedPCMsize < 0)
\r
201 csound = new CSoundMp3();
\r
202 nDecodedPCMsize = csound.tデコード後のサイズを調べる(strFilename, out nHandle);
\r
203 if (nDecodedPCMsize < 0) {
\r
210 if (nDecodedPCMsize < n最大オンメモリ可能サイズ)
\r
212 csound.tオンメモリ方式で作成する(this.Device, strFilename, nHandle);
\r
216 csound.tストリーム方式で作成する(this.Device, strFilename, nHandle);
\r