+
+ /// <summary>
+ /// サウンドファイルの実体への参照数。
+ /// </summary>
+ /// <remarks>0の時にCSound()を作ると実体を生成し、1以上の時はClone()する。開放の時も同様で、2以上の時は実体を開放せず、1の時に実体を開放する。</remarks>
+ /// <remarks>DirectSound時のみ使用する。</remarks>
+ private static Dictionary<string, int> dicWavFileRefCounter;
+ private static Dictionary<string, CSound> dicCSoundWavInstance;
+
+ public CSound tGetCSoundWavInstance(string fullPathName)
+ {
+ if (dicCSoundWavInstance.ContainsKey(fullPathName))
+ {
+//Debug.WriteLine("dic instance hit" + Path.GetFileName(fullPathName));
+ return dicCSoundWavInstance[fullPathName];
+ }
+ else
+ {
+//Debug.WriteLine("dic instance fail" + Path.GetFileName(fullPathName));
+ return null;
+ }
+ }
+ public bool tSetCSoundWavInstance(string fullPathName, CSound cs)
+ {
+ if (dicCSoundWavInstance.ContainsKey(fullPathName))
+ {
+//Debug.WriteLine("dic instance already set" + Path.GetFileName(fullPathName));
+
+ throw new ArgumentException("tSetCSoundWavInstance(" + fullPathName + "): 既に登録されています。");
+ return false;
+ }
+ else
+ {
+//Debug.WriteLine("dic instance add" + Path.GetFileName(fullPathName));
+ dicCSoundWavInstance.Add(fullPathName, cs);
+ return true;
+ }
+ }
+
+ public static int tGetWavFileRefCounter(string fullPathName)
+ {
+ if (dicWavFileRefCounter.ContainsKey(fullPathName))
+ {
+//Debug.WriteLine("dic ref counter = " +dicWavFileRefCounter[fullPathName] + " (" + Path.GetFileName(fullPathName) + ")" );
+ return dicWavFileRefCounter[fullPathName];
+ }
+ else
+ {
+//Debug.WriteLine("dic ref counter = 0 (" + Path.GetFileName(fullPathName) + ")" );
+ return 0;
+ }
+ }
+
+ public static int tIncrementWavFileRefCounter(string fullPathName)
+ {
+ if (dicWavFileRefCounter.ContainsKey(fullPathName))
+ {
+//Debug.WriteLine("dic incremented counter = " + tGetWavFileRefCounter(fullPathName) + "+1 (" + Path.GetFileName(fullPathName) + ")" );
+ return ++dicWavFileRefCounter[fullPathName];
+ }
+ else
+ {
+//Debug.WriteLine("dic incremented counter = 1 (" + Path.GetFileName(fullPathName) + ")" );
+ dicWavFileRefCounter.Add(fullPathName, 1);
+ return 1;
+ }
+ }
+
+ public static int tDecrementWavFileRefCounter(string fullPathName)
+ {
+ if (dicWavFileRefCounter.ContainsKey(fullPathName))
+ {
+//Debug.WriteLine("dic decremented counter = " + tGetWavFileRefCounter(fullPathName) + "-1 (" + Path.GetFileName(fullPathName) + ")" );
+ int value = --dicWavFileRefCounter[fullPathName];
+ if (value == 0)
+ {
+ dicWavFileRefCounter.Remove(fullPathName);
+ dicCSoundWavInstance.Remove(fullPathName);
+ }
+ else if (value < 0)
+ {
+ throw new Exception("tDecrementWavFileRefCounter(" + fullPathName + "): カウンタが負の値です。(" + value.ToString() + ")" );
+ }
+ return value;
+ }
+ else
+ {
+ //Debug.WriteLine("dic dec counter = null (" + Path.GetFileName(fullPathName) + ")" );
+ //throw new ArgumentException("tDecrementWavFileRefCounter(" + fullPathName + "): 引数に相当するサウンドファイルが登録されていません。");
+ return 0;
+ }
+ }
+
+ public static void tClearWavFileRefCounter()
+ {
+ dicWavFileRefCounter.Clear();
+ dicCSoundWavInstance.Clear();
+ }
+