public override IEnumerator IeUpdate()
 {
     while (true)
     {
         if (KeyControl.GiveKey(DX.KEY_INPUT_0) == 1)
         {
             if (m.IsPlaySound())
             {
                 m.StopSound();
             }
             else
             {
                 m.ContinueSound();
             }
         }
         if (KeyControl.GiveKey(DX.KEY_INPUT_1) >= 1)
         {
             int pan = m.PanVal;
             m.ChangePan(pan - 3);
         }
         if (KeyControl.GiveKey(DX.KEY_INPUT_2) >= 1)
         {
             int pan = m.PanVal;
             m.ChangePan(pan + 3);
         }
         if (KeyControl.GiveKey(DX.KEY_INPUT_3) >= 1)
         {
             float vol = m.Volume;
             m.ChangeVolume(vol - 3);
         }
         if (KeyControl.GiveKey(DX.KEY_INPUT_4) >= 1)
         {
             float vol = m.Volume;
             m.ChangeVolume(vol + 3);
         }
         if (KeyControl.GiveKey(DX.KEY_INPUT_5) >= 1)
         {
             m3.PlaySound();
         }
         yield return(0);
     }
 }
Ejemplo n.º 2
0
    public override IEnumerator IeUpdate()
    {
        // http://dxlib.o.oo7.jp/cgi/patiobbs/patio.cgi?mode=past&no=1800
        int OutputSampleNum = 0;

        while (true)
        {
            // プレイヤーに再生されずにストックされている波形サンプルの数が
            // 0.1秒分以下になっていたら BGM.wav の全波形サンプルをプレイヤーに出力していない限りループの中に入る
            while (DX.GetStockDataLengthSoftSoundPlayer(SoftSoundPlayerHandle) < Math.Min(StackLength, 4410) && OutputSampleNum < SoftSoundSampleNum)
            {
                // サウンドデータハンドルを介してプレイヤーに出力していない波形サンプルを取得
                for (int i = 0; i < StackLength; i++)
                {
                    DX.ReadSoftSoundData(SoftSoundHandle, OutputSampleNum + i, out Wave[i], out Wave2[i]);
                }

                // ダミー / 0波を作る
                for (int i = 0; i < Wave.Length; i++)
                {
                    ZeroWave[i] = 0;
                }

                // エンターキーを押している間だけ,音データを加工する
                if (KeyControl.GiveKey(DX.KEY_INPUT_SPACE) > 0)
                {
                    // 本当はここにフィルターの処理を入れる
                    for (int i = 0; i < StackLength; i++)
                    {
                        // 適当に左右バランスいじってみる
                        // Wave[i] = (int)((double)Wave[i] * 0.05);
                        // Wave2[i] = (int)((double)Wave2[i] * 0.95);

                        // 適当にsin波を放り込んでみる
                        // (波が不連続になっちゃってるんだろうねぇ…)
                        int    fs   = 44100; // サンプリング周波数
                        int    freq = 440;   // 周波数(ラー♪)
                        double d    = 2 * Math.PI * freq * i / fs;
                        Wave[i]  = (int)(Math.Sin(d) * 32768);
                        Wave2[i] = (int)(Math.Sin(d) * 32768);
                        Wave2[i] = 0;
                    }
                }

                // Waveに対して(左側スピーカ)
                // FFTによりフーリエ変換を行う
                // bitsize : ビット数でサイズを指定。( BufferSizeは2の何乗であるか)
                // Wave2 : 虚数領域。(普通は0を設定)
                int[] a = Wave;
                FFT(Wave, ZeroWave, out ParamList, out ParamList2, bitsize);

                // 適当にフィルターを噛ませます
                // (適当なハイパスフィルタ)
                for (int i = 0; i < ParamList.Length / 2; i++)
                {
                    ParamList[i]  /= 2;
                    ParamList2[i] /= 2;
                }

                // IFFTで逆フーリエ変換を行う
                IFFT(ParamList, ParamList2, out Wave, out WaveIm, bitsize, Wave.Length);
                int[] b = Wave;
                int[] c = a;


                // Wave2に対して(右側スピーカ)
                // FFTによりフーリエ変換を行う
                // bitsize : ビット数でサイズを指定。( BufferSizeは2の何乗であるか)
                // Wave2 : 虚数領域。(普通は0を設定)
                FFT(Wave2, ZeroWave, out ParamList, out ParamList2, bitsize);

                // 適当にフィルターを噛ませます
                // (適当なハイパスフィルタ)
                for (int i = 0; i < ParamList.Length / 2; i++)
                {
                    ParamList[i]  = 0;
                    ParamList2[i] = 0;
                }

                // IFFTで逆フーリエ変換を行う
                IFFT(ParamList, ParamList2, out Wave2, out WaveIm, bitsize, Wave.Length);

                // 取得した波形サンプルをプレイヤーに出力
                for (int i = 0; i < StackLength; i++)
                {
                    DX.AddOneDataSoftSoundPlayer(SoftSoundPlayerHandle, Wave[i], Wave2[i]);
                }

                // プレイヤーに出力したサンプルの数をインクリメント
                OutputSampleNum += StackLength;
            }

            // まだプレイヤーの再生処理を開始していなかったら開始する
            if (DX.CheckStartSoftSoundPlayer(SoftSoundPlayerHandle) == DX.FALSE)
            {
                DX.StartSoftSoundPlayer(SoftSoundPlayerHandle);
            }

            // BGM.wav の全ての波形サンプルをプレイヤーに出力していて、
            // 且つプレイヤーが無音データを再生し始めていたら BGM.wav の再生が終了したということなのでループを抜ける
            if (OutputSampleNum == SoftSoundSampleNum && DX.CheckSoftSoundPlayerNoneData(SoftSoundPlayerHandle) == DX.TRUE)
            {
                break;
            }

            yield return(0);
        }

        yield break;
    }