Diễn Đàn Tin Học

Hiển thị kết quả từ 1 đến 4 / 4
  1. #1
    Tham gia
    16-07-2002
    Location
    none
    Bài viết
    15
    Like
    0
    Thanked 0 Times in 0 Posts

    Nói nhỏ nè ! Xin các cao thủ khắp mọi miền giúp đỡ

    Cho tôi được hỏi các bạn về một vấn đề, làm thế nào để đo được sóng âm thanh. Tôi thấy hiện nay các phần mềm nghe nhạc hiện đại như Jet-Audio hay Winamp đều có các Sound Visualation như Spectrum, Sound Level hay Sound Oscillscope. Không biết họ dùng kỹ thuật gì để làm được điều đó. Có bạn nào "siêu đẳng" về VB xin hãy giúp tôi nhé. Xin được cảm ơn rất nhiều.

    Teppi
    Quote Quote

  2. #2
    Tham gia
    17-07-2002
    Location
    Hà Nội
    Bài viết
    696
    Like
    0
    Thanked 8 Times in 7 Posts
    Sóng âm khí phát ra sound card phải là dạng thức RAW, bạn chỉ cần chặn luồng dữ liệu này lại rùi view nó ra sao cho co dãn hợp lý một tẹo, màu mè một tý là xong ngay. Nếu lười có thể tìm vài cái source plugin của WinAmp xem xét.

  3. #3
    Tham gia
    16-07-2002
    Location
    none
    Bài viết
    15
    Like
    0
    Thanked 0 Times in 0 Posts
    Cám ơn bạn.

    Tớ đã đo được xung của âm thanh phát ra bằng file mp3 hay wav, nhưng hiện tại lại đang bí về việc vẽ ra một oscilloscope bằng Picturebox. Giá trị xung nằm trong khoảng từ 0 tới 32767. Bạn có thể nghiên cứu cho tớ việc này không. Tớ thật sự không giỏi trong việc tính toán đại số. Tớ chỉ có năng lực trong việc tính toán nhị phân. Dưới đây là mã nguồn. Nó chạy được nhưng không được đẹp như cái Oscilloscope của Winamp, trông buồn cười lắm.

    Dim hmixer As Long ' mixer handle
    Dim inputVolCtrl As MIXERCONTROL ' waveout volume control
    Dim outputVolCtrl As MIXERCONTROL ' microphone volume control
    Dim rc As Long ' return code
    Dim ok As Boolean ' boolean return code

    Dim mxcd As MIXERCONTROLDETAILS ' control info
    Dim vol As MIXERCONTROLDETAILS_SIGNED ' control's signed value
    Dim volume As Long ' volume value
    Dim volHmem As Long ' handle to volume memory
    Dim PicX As Integer
    Dim PicY As Integer
    Dim NewX As Integer
    Dim NewY As Integer
    Dim OldX As Integer
    Dim OldY As Integer
    Dim Started As Boolean
    Dim i As Integer
    Dim h As Integer
    Dim X As Integer

    Private Sub Form_Load()

    Me.ScaleMode = vbTwips
    Me.Caption = "Graphical volume meter"
    Timer1.Interval = 50
    Timer1.Enabled = True

    ' Open the mixer specified by DEVICEID
    rc = mixerOpen(hmixer, DEVICEID, 0, 0, 0)

    If ((MMSYSERR_NOERROR <> rc)) Then
    MsgBox "Couldn't open the mixer."
    Exit Sub
    End If

    ' Get the output volume meter
    ok = GetControl(hmixer, MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, MIXERCONTROL_CONTROLTYPE_PEAKMETER, outputVolCtrl)

    If (ok = True) Then
    ProgressBar2.Min = 0
    ProgressBar2.Max = outputVolCtrl.lMaximum
    Else
    ProgressBar2.Enabled = False
    MsgBox "Couldn't get waveout meter"
    End If

    ' Initialize mixercontrol structure
    mxcd.cbStruct = Len(mxcd)
    volHmem = GlobalAlloc(&H0, Len(volume)) ' Allocate a buffer for the volume value
    mxcd.paDetails = GlobalLock(volHmem)
    mxcd.cbDetails = Len(volume)
    mxcd.cChannels = 1
    PicX = 0
    PicY = 1950
    NewX = 0
    NewY = 1950
    Started = False

    End Sub

    Private Sub Timer1_Timer()

    On Error Resume Next
    Pic1.Cls
    ' Get the current output level
    If (ProgressBar2.Enabled = True) Then
    mxcd.dwControlID = outputVolCtrl.dwControlID
    mxcd.item = outputVolCtrl.cMultipleItems
    rc = mixerGetControlDetails(hmixer, mxcd, MIXER_GETCONTROLDETAILSF_VALUE)
    CopyStructFromPtr volume, mxcd.paDetails, Len(volume)

    If (volume < 0) Then volume = -volume
    ProgressBar2.Value = volume 'Cuong do xung am thanh
    Label1.Caption = CStr(volume)
    'Rối ở đoạn chương trình này
    'Left channel
    For i = 0 To 499 Step 1
    h = ((volume + 32768) / 65535 * Pic1.ScaleHeight)
    X = (Pic1.ScaleWidth * i * 2) / 1000
    If i = 0 Then Pic1.PSet (0, h)
    Pic1.Line -(X, h), QBColor(10)
    Next
    'right channel
    For i = 1 To 499 Step 2
    h = ((volume + 32768) / 65535 * Pic1.ScaleHeight)
    X = (Pic1.ScaleWidth * i) / 500
    If i = 1 Then Pic1.PSet (0, h)
    Pic1.Line -(X, h), QBColor(10)
    Next

    'Dim Val As Long
    'Val = Int(ProgressBar2.Value * (100 / ProgressBar2.Max))
    '
    'PicY = 1950 - (1950 * (Val / 100))
    '
    'If (PicX + 40) < 3730 Then
    'PicX = PicX + 40
    'Else
    'Pic1.Cls
    'PicX = 0
    'Started = False
    'End If
    '
    'Pic1.Circle (PicX, PicY), 1, RGB(0, 0, 0)
    '
    'OldX = NewX
    'OldY = NewY
    'NewX = PicX
    'NewY = PicY
    'If Started = True Then
    'Pic1.PSet (NewX, NewY), QBColor(10)
    'Pic1.Line -(NewX, NewY), QBColor(10)
    'Else
    'Started = True
    'End If
    '
    End If
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    GlobalFree volHmem
    End Sub

  4. #4
    Tham gia
    13-07-2008
    Bài viết
    55
    Like
    0
    Thanked 0 Times in 0 Posts
    Anh Teppi ơi giúp em với. Em thấy anh vẽ đồ thị dạng sóng âm thanh như vậy là trình VB của anh cao lắm cho em hỏi chút:
    Em cần vẽ đồ thị dữ liệu nhận về từ cổng com (Vì em đang lập trình giao tiếp máy tính với PLC, PLC sau 1s nó gửi lên một số nguyên)mà không biết vẽ thế nào anh xem có code hay cách làm gì không bảo em với nhé em đang cần gấp lắm vì đồ án em sắp bảo vệ rồi.
    cảm ơn anh nhiều nhé.Nếu được anh gửi vào mail cho em nhé:
    xuanvudk2@gmail.com

Bookmarks

Quy định

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •