►index

     スポンサーサイト

    --------

    上記の広告は1ヶ月以上更新のないブログに表示されています。
    新しい記事を書く事で広告が消せます。

     VB.NET Mci Api による録音クラス

    2013-05-26

    mciSendString Apiを使ったWaveファイルへの録音クラスです。(^^)b

    Public Class MciRecorder

        Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _

               (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _

                ByVal uReturnLength As UInt32, ByVal hwndCallback As Integer) As Integer

     

        Private _SampleRate As Int32 = 44100

        Public Property SampleRate() As Int32

            Get

                Return _SampleRate

            End Get

            Set(ByVal value As Int32)

                _SampleRate = value

            End Set

        End Property

     

        Private _BitperSample As Int32 = 16

        Public Property BitperSample() As Int32

            Get

                Return _BitperSample

            End Get

            Set(ByVal value As Int32)

                _BitperSample = value

            End Set

        End Property

     

        Private _Channels As Int16 = 1

        Public Property Channels() As Int16

            Get

                Return _Channels

            End Get

            Set(ByVal value As Int16)

                _Channels = value

            End Set

        End Property

     

        Private _PathWaveFile As String = "~temp.wav"

        Public Property PathWaveFile() As String

            Get

                Return _PathWaveFile

            End Get

            Set(ByVal value As String)

                _PathWaveFile = value

            End Set

        End Property

     

     

     

        Sub Start()

            Dim CommandString As String

            Dim BytesPerSec As Integer

            Dim BlockAlignment As Integer

     

            BytesPerSec = (BitperSample * Channels * SampleRate) / 8

            BlockAlignment = (BitperSample * Channels) / 8

     

            CommandString = "set file time format milliseconds channels " & Channels & " "

            CommandString &= "samplespersec " & SampleRate & " "

            CommandString &= "bytespersec " & BytesPerSec & " "

            CommandString &= "alignment " & BlockAlignment & " "

            CommandString &= "bitspersample " & BitperSample

     

            mciSendString("open new type waveaudio alias file", "", 0, 0)

            mciSendString(CommandString, "", 0, 0)

            mciSendString("record file", "", 0, 0) '録音開始

     

        End Sub

     

        Sub [Stop]()

            mciSendString("stop file", "", 0, 0) '録音停止

            mciSendString("save file """ & _PathWaveFile & """", "", 0, 0) '保存

            mciSendString("close file", "", 0, 0) '閉じる

        End Sub

     

    End Class

     


    トラックバック

    コメントの投稿

    非公開コメント

    PR
    上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。