OSDN Git Service

Sound の Length と Position をリファクタ。
authorくまかみ工房 <kumakamikoubou@gmail.com>
Wed, 16 Nov 2016 08:48:15 +0000 (17:48 +0900)
committerくまかみ工房 <kumakamikoubou@gmail.com>
Wed, 16 Nov 2016 08:48:41 +0000 (17:48 +0900)
FDK24/メディア/サウンド/WASAPI/Sound.cs
FDK24/メディア/サウンド/WASAPI/SoundTimer.cs

index 189a44e..d74cb37 100644 (file)
@@ -6,19 +6,42 @@ using CSCore;
 
 namespace FDK.メディア.サウンド.WASAPI
 {
-       public class Sound
+       public class Sound : IDisposable
        {
-               public long Length
+               public long 長さsample
                {
                        get { return this._SampleSource.Length; }
                }
 
-               public long Position
+               public double 長さsec
+               {
+                       get { return this.長さsample / ( this.WaveFormat.Channels * this.WaveFormat.SampleRate ); }
+               }
+
+               public long 位置sample
                {
                        get { return this._SampleSource.Position; }
                        set { this._SampleSource.Position = value; }
                }
 
+               public double 位置sec
+               {
+                       get
+                       {
+                               return this.位置sample / ( this.WaveFormat.Channels * this.WaveFormat.SampleRate );
+                       }
+                       set
+                       {
+                               long position = (long) ( value * this.WaveFormat.SampleRate * this.WaveFormat.Channels + 0.5 ); // +0.5 は四捨五入
+                               position -= ( position % this.WaveFormat.Channels );    // チャンネル数の倍数にする。
+
+                               if( ( 0 > position ) || ( this.長さsample <= position ) )
+                                       throw new ArgumentOutOfRangeException();
+
+                               this.位置sample = position;
+                       }
+               }
+                       
                public WaveFormat WaveFormat
                {
                        get { return this._SampleSource.WaveFormat; }
@@ -59,6 +82,8 @@ namespace FDK.メディア.サウンド.WASAPI
 
                public void Dispose()
                {
+                       this.Stop();
+
                        FDK.Utilities.解放する( ref this._SampleSource );
                        FDK.Utilities.解放する( ref this._WaveSource );
                        this._MixerRef = null;
index 24c2230..d6a1202 100644 (file)
@@ -22,7 +22,7 @@ namespace FDK.メディア.サウンド.WASAPI
                                int hr = 0;
 
                                long デバイス周波数 = 0;
-                               //デバイス周波数 = audioClock.Pu64Frequency;     --> たまにおかしくなるので、使わない。
+                               //デバイス周波数 = audioClock.Pu64Frequency; --> Native 系で統一するため、こちらは使わない。
                                audioClock.GetFrequencyNative( out デバイス周波数 );
 
                                long QPC周波数 = FDK.カウンタ.QPCTimer.周波数;