2 using System.Collections.Generic;
3 using System.Diagnostics;
7 namespace FDK.メディア.サウンド.WASAPI
9 public class Sound : IDisposable
13 get { return this._SampleSource.Length; }
18 get { return this.長さsample / ( this.WaveFormat.Channels * this.WaveFormat.SampleRate ); }
23 get { return this._SampleSource.Position; }
24 set { this._SampleSource.Position = value; }
31 return this.位置sample / ( this.WaveFormat.Channels * this.WaveFormat.SampleRate );
35 long position = (long) ( value * this.WaveFormat.SampleRate * this.WaveFormat.Channels + 0.5 ); // +0.5 は四捨五入
36 position -= ( position % this.WaveFormat.Channels ); // チャンネル数の倍数にする。
38 if( ( 0 > position ) || ( this.長さsample <= position ) )
39 throw new ArgumentOutOfRangeException();
41 this.位置sample = position;
45 public WaveFormat WaveFormat
47 get { return this._SampleSource.WaveFormat; }
50 public CSCore.ISampleSource SampleSource
52 get { return this._SampleSource; }
56 /// 音量。0.0(無音)~1.0(原音)。
60 get { return this._Volume; }
63 if( ( 0.0f > value ) || ( 1.0f < value ) )
64 throw new ArgumentOutOfRangeException();
71 /// Sound の生成は、コンストラクタではなく Device.CreateSound() で行うこと。
72 /// (Device 内部で持っている Mixer への参照が必要なため。)
74 /// <param name="path">サウンドファイルパス</param>
75 /// <param name="mixer">使用する Mixer。</param>
76 internal Sound( string path, Mixer mixer )
78 this._MixerRef = new WeakReference<Mixer>( mixer );
79 this._WaveSource = new Decoder( path, mixer.WaveFormat );
80 this._SampleSource = this._WaveSource.ToSampleSource();
87 FDK.Utilities.解放する( ref this._SampleSource );
88 FDK.Utilities.解放する( ref this._WaveSource );
89 this._MixerRef = null;
95 if( this._MixerRef.TryGetTarget( out mixer ) )
96 mixer.AddSound( this );
102 if( this._MixerRef.TryGetTarget( out mixer ) )
103 mixer.RemoveSound( this );
106 private CSCore.IWaveSource _WaveSource = null;
107 private CSCore.ISampleSource _SampleSource = null;
108 private System.WeakReference<Mixer> _MixerRef = null;
109 private float _Volume = 1.0f;