echo("備忘録");

IT技術やプログラミング関連など、技術系の事を備忘録的にまとめています。

Managed DirectXを動かす その2

これの続きで、Managed DirectXが無事動いたので、DirectSoundで*.wavファイルを再生する処理を書いてみました。
再生だけなら、すごいシンプルなんですね。
(不要な処理が多いかもしれません。すいません。)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;

namespace Sample
{
    public partial class Form1 : Form
    {
        private Device dev;              // デバイス
        private SecondaryBuffer s_buf;   // セカンダリバッファ
           
        public Form1()
        {
            InitializeComponent();
        }

        // フォームロード時の処理
        private void Form1_Load(object sender, EventArgs e)
        {
            string path = @"C:\sample.wav";  // 再生する*.wavファイルのパス

      this.dev = new Device();
            this.dev.SetCooperativeLevel(this, CooperativeLevel.Priority);
            this.s_buf = new SecondaryBuffer(path, dev);
        }

        // 再生時の処理(「再生」ボタンクリックなど)
        private void button1_Click(object sender, EventArgs e)
        {     
            // 再生位置を一番最初に設定して、再生
            this.s_buf.SetCurrentPosition(0);
            this.s_buf.Play(0, BufferPlayFlags.Default);
        }

        // 停止時の処理(「停止」ボタンクリックなど)
        private void button2_Click(object sender, EventArgs e)
        {
            // デバイスとセカンダリバッファの破棄
            this.s_buf.Dispose();
            this.dev.Dispose();
        }
    }
}

さて、次はキャプチャですかね。