Results 1 to 20 of 20

Thread: [VB6] - Signal spectrum

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,687

    [VB6] - Signal spectrum

    Hello everyone!
    This project contains the sound signals generator with the spectrum visualizer. The list of signals contains the following forms:

    1. White noise;
    2. Pink noise;
    3. Brown/Red noise;
    4. Blue noise;
    5. Violet noise;
    6. Sine modulation by low frequency;
    7. Square wave (odd harmonics with 6db/oct attenuation);
    8. Saw wave (odd/even harmonics with 6db/oct attenuation);
    9. Triangle wave (odd harmonics with 12db/oct attenuation);
    10. Signal with only even harmonics;
    11. Complex FM modulation;
    12. AM modulation.


    The spectrum visualizer supports resolutions up to 32768 points and averaging. The discrete complex FFT (Fast Fourier Transform) is used to visualize the spectrum. This procedure is optimized to processing a real signal using the even/odd decomposition in frequency domain which allows to performs the transformation of 2 real signals as single complex signal. The further synthesis of the spectrum is based on shifting in time domain and corresponding frequency domain rotation. The comments in the code describes everything in details.



    Best Regards,
    The trick.
    Attached Files Attached Files

  2. #2
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by The trick View Post
    Hello everyone!
    This project contains the sound signals generator with the spectrum visualizer. The list of signals contains the following forms:

    1. White noise;
    2. Pink noise;
    3. Brown/Red noise;
    4. Blue noise;
    5. Violet noise;
    6. Sine modulation by low frequency;
    7. Square wave (odd harmonics with 6db/oct attenuation);
    8. Saw wave (odd/even harmonics with 6db/oct attenuation);
    9. Triangle wave (odd harmonics with 12db/oct attenuation);
    10. Signal with only even harmonics;
    11. Complex FM modulation;
    12. AM modulation.


    The spectrum visualizer supports resolutions up to 32768 points and averaging. The discrete complex FFT (Fast Fourier Transform) is used to visualize the spectrum. This procedure is optimized to processing a real signal using the even/odd decomposition in frequency domain which allows to performs the transformation of 2 real signals as single complex signal. The further synthesis of the spectrum is based on shifting in time domain and corresponding frequency domain rotation. The comments in the code describes everything in details.



    Best Regards,
    The trick.
    Dear Trick,

    Thankyou for the nice program.
    You please tell me how you are able to display graph continuously on the user control of the form without using new thread and the display continues even when I drag the form.

    regards,
    JSVenu

  3. #3

  4. #4
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by The trick View Post
    Everything is displayed in the main thread. We get the callback notification from the driver like you could get from a timer control.
    Dear Trick,

    Thankyou for the clarification.

    regards,
    JSVenu

  5. #5
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Dear Trick,
    If we have other processing loops also running in the same main thread we can use doevents in the loops for making the main thread responsive to driver notifications.Here how to make the application not to miss driver notifications.
    Suppose we create new threads how to make main thread be responsive to driver notifications without missing them and manage all threads in a responsive way.Please clarify.

    regards,
    JSVenu

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,901

    Re: [VB6] - Signal spectrum

    Stop hacking each thread with unrelated questions about threading.
    This is just a sample for something completely different!

  7. #7
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by Arnoutdv View Post
    Stop hacking each thread with unrelated questions about threading.
    This is just a sample for something completely different!
    Dear Arnoutdv,

    I understand this is a sample related to dsp signals.
    I was asking this question so that the same can be used in practical situation where we have GUI displaying
    graphs,receiving driver notifications etc simultaneously in different threads in a responsive way without missing
    like in audio driver notifications missing some may make audio not understandable since continuity may be lost.

    regards,
    JSVenu

  8. #8
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by The trick View Post
    Hello everyone!
    This project contains the sound signals generator with the spectrum visualizer. The list of signals contains the following forms:

    1. White noise;
    2. Pink noise;
    3. Brown/Red noise;
    4. Blue noise;
    5. Violet noise;
    6. Sine modulation by low frequency;
    7. Square wave (odd harmonics with 6db/oct attenuation);
    8. Saw wave (odd/even harmonics with 6db/oct attenuation);
    9. Triangle wave (odd harmonics with 12db/oct attenuation);
    10. Signal with only even harmonics;
    11. Complex FM modulation;
    12. AM modulation.


    The spectrum visualizer supports resolutions up to 32768 points and averaging. The discrete complex FFT (Fast Fourier Transform) is used to visualize the spectrum. This procedure is optimized to processing a real signal using the even/odd decomposition in frequency domain which allows to performs the transformation of 2 real signals as single complex signal. The further synthesis of the spectrum is based on shifting in time domain and corresponding frequency domain rotation. The comments in the code describes everything in details.



    Best Regards,
    The trick.
    Dear Trick,

    When we use waveOutOpen with CALLBACK_THREAD option how can we catch MM_WOM_DONE event in the forms default message loop if we use this option instead of subclassing the form using CALLBACK_WINDOW in waveOutOpen as you did here.

    There are other options in waveOutOpen like CALLBACK_FUNCTION,CALLBACK_EVENT etc.Which one is better to use.Please clarify.

    regards,
    JSVenu
    Last edited by jsvenu; Feb 13th, 2020 at 08:13 PM.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,687

    Re: [VB6] - Signal spectrum

    When we use waveOutOpen with CALLBACK_THREAD option how can we catch MM_WOM_DONE event in the forms default message loop if we use this option instead of subclassing the form using CALLBACK_WINDOW in waveOutOpen as you did here.
    In this case you need to create a Message-Pumping loop to extract the message from the message queue.

    There are other options in waveOutOpen like CALLBACK_FUNCTION,CALLBACK_EVENT etc.Which one is better to use.Please clarify.
    If you use the CALLBACK_FUNCTION mechanism it's called from a different thread and it requires the thread initialization. You could use my module for this scenario.
    If you use the CALLBACK_EVENT mechanism you should test an event (which you specified when open the device). You can use this class for this reason.

    If you want to simplify the development of the sound processing you could use the special class which is quite safe to debugging. To simplify code i don't use it here (i don't afraid subclassing ).

  10. #10
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    In this case you need to create a Message-Pumping loop to extract the message from the message queue.
    Dear Trick,

    Where exactly in code we have to put msg pump.

    regards,
    JSVenu

  11. #11

  12. #12

  13. #13
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by The trick View Post
    When you need to play a sound.
    Dear Trick,

    Just as default windowproc is not visible you made it accessible thru form window subclassing using setwindowlong and in that windowproc you were catching the MM_WOM_DONE.

    I was asking same but with default invisible windows thread message loop by accessing it and in which I can catch the MM_WOM_DONE and proceed as in windowproc when we use waveOutOpen with CALLBACK_THREAD option .

    regards,
    JSVenu

  14. #14
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by The trick
    When you need to play a sound.

    Dear Trick,

    We specify 4th parameter (dwCallback) as App.ThreadID as follows:

    Private Const CALLBACK_THREAD As Long = &H20000

    lErr = waveOutOpen(m_hWaveOut, WAVE_MAPPER, tFormat, App.ThreadID, 0, CALLBACK_THREAD)

    When we put message pump in play button as follows:

    Code:
    Private Sub cmdPlay_Click()
            while getmessage(...)
    
               'catch MM_WOM_DONE
                ...
             wend
               ...
    End Sub
    and in this msg pump we catch MM_WOM_DONE.


    But when we want to stop play it is not possible since the main thread is busy and the click on the same play button doesn't work.Please clarify.

    regards,
    JSVenu
    Last edited by jsvenu; Feb 15th, 2020 at 02:38 AM.

  15. #15
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by jsvenu View Post
    Dear Trick,

    We specify 4th parameter (dwCallback) as App.ThreadID as follows:

    Private Const CALLBACK_THREAD As Long = &H20000

    lErr = waveOutOpen(m_hWaveOut, WAVE_MAPPER, tFormat, App.ThreadID, 0, CALLBACK_THREAD)

    When we put message pump in play button as follows:

    Code:
    Private Sub cmdPlay_Click()
            while getmessage(...)
    
               'catch MM_WOM_DONE
                ...
             wend
               ...
    End Sub
    and in this msg pump we catch MM_WOM_DONE.


    But when we want to stop play it is not possible since the main thread is busy and the click on the same play button doesn't work.Please clarify.

    regards,
    JSVenu

    Dear Trick,

    Can you provide me a way to use the following code

    Code:
    hHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMsgProc, 0, hThreadToHook)

    instead of

    Code:
    m_pfnPrevProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)
    in InitSubclassing


    where GetMsgProc is defined as

    Code:
    Public Function GetMsgProc(ByVal uCode As Long _
        , ByVal wParam As Long _
        , ByRef lParam As MSG) As Long
        If uCode = 0 Then
            If wParam = PM_REMOVE Then
            
            
             Dim tHeader As WAVEHDR
        Dim lIndex  As Long
        
        Select Case lParam.message
        Case MM_WOM_DONE
            
            memcpy tHeader, ByVal lParam, Len(tHeader)
            
            ' // Search for free buffer
            For lIndex = 0 To UBound(m_tBuffer)
                If m_tBuffer(lIndex).tHeader.lpData = tHeader.lpData Then Exit For
            Next
            
            NeedNewData m_tBuffer(lIndex).bData()
            
            waveOutWrite m_hWaveOut, m_tBuffer(lIndex).tHeader, Len(m_tBuffer(lIndex).tHeader)
            
         Case Else
            GetMsgProc = CallNextHookEx(hHook, uCode, wParam, lParam)
        End Select
           
            End If
        
    End If
        
    End Sub
    and use UnhookWindowsHookEx in UninitializeSubclassing as follows:

    Code:
    Private Sub UninitializeSubclassing()
        
     
       If bHooked Then
            UnhookWindowsHookEx hHook
            bHooked = False
        End If
        
    End Sub
    so that I can hook to default message loop and use the following code in InitPlayback

    Code:
    lErr = waveOutOpen(m_hWaveOut, WAVE_MAPPER, tFormat, App.ThreadID, 0, CALLBACK_THREAD)
    regards,
    JSVenu

  16. #16
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by jsvenu View Post
    Dear Trick,

    Can you provide me a way to use the following code

    Code:
    hHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMsgProc, 0, hThreadToHook)

    instead of

    Code:
    m_pfnPrevProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)
    in InitSubclassing


    where GetMsgProc is defined as

    Code:
    Public Function GetMsgProc(ByVal uCode As Long _
        , ByVal wParam As Long _
        , ByRef lParam As MSG) As Long
        If uCode = 0 Then
            If wParam = PM_REMOVE Then
            
            
             Dim tHeader As WAVEHDR
        Dim lIndex  As Long
        
        Select Case lParam.message
        Case MM_WOM_DONE
            
            memcpy tHeader, ByVal lParam, Len(tHeader)
            
            ' // Search for free buffer
            For lIndex = 0 To UBound(m_tBuffer)
                If m_tBuffer(lIndex).tHeader.lpData = tHeader.lpData Then Exit For
            Next
            
            NeedNewData m_tBuffer(lIndex).bData()
            
            waveOutWrite m_hWaveOut, m_tBuffer(lIndex).tHeader, Len(m_tBuffer(lIndex).tHeader)
            
         Case Else
            GetMsgProc = CallNextHookEx(hHook, uCode, wParam, lParam)
        End Select
           
            End If
        
    End If
        
    End Sub
    and use UnhookWindowsHookEx in UninitializeSubclassing as follows:

    Code:
    Private Sub UninitializeSubclassing()
        
     
       If bHooked Then
            UnhookWindowsHookEx hHook
            bHooked = False
        End If
        
    End Sub
    so that I can hook to default message loop and use the following code in InitPlayback

    Code:
    lErr = waveOutOpen(m_hWaveOut, WAVE_MAPPER, tFormat, App.ThreadID, 0, CALLBACK_THREAD)
    regards,
    JSVenu
    Dear Trick,

    I am sending the project code using waveOutOpen(m_hWaveOut, WAVE_MAPPER, tFormat, App.ThreadID, 0, CALLBACK_THREAD) as attachment.
    When we compile and run the code I am getting the Play button disabled.Please clarify how to make the Play button enabled and make the code work properly.

    regards,
    JSVenu
    Attached Files Attached Files

  17. #17
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Dear Trick,

    Actually I am getting compile error when I try to use UDT(MSG struture) as parameter to a class sub.
    Can you tell me how to give UDT as parameter to a class sub without using typelibrary.If you can tell me how to do this I think the problem is solved in the above code http://www.vbforums.com/attachment.p...7&d=1581857502 already sent to you.Please clarify.

    regards,
    JSVenu

  18. #18
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by jsvenu View Post
    Dear Trick,

    Actually I am getting compile error when I try to use UDT(MSG struture) as parameter to a class sub.
    Can you tell me how to give UDT as parameter to a class sub without using typelibrary.If you can tell me how to do this I think the problem is solved in the above code http://www.vbforums.com/attachment.p...7&d=1581857502 already sent to you.Please clarify.

    regards,
    JSVenu
    Dear Trick,

    I got the compile error solved by making the Form function as Friend function.Now the form function is able to take MSG structure as parameter.But when I run the application and click play button one sample is drawn and then it is crashing.When I run in IDE I am getting the following error in msgbox when I click play button after one sample is displayed in usercontrol.

    Runtime error 16
    Expression too complex


    at the following code in usercontrol refresh method:


    Code:
      ' // Draw spectrum
        Do While lPixelIndex < UserControl.ScaleWidth - tOffset.fX
    I had to click End button in msgbox to exit the application.

    Please clarify.Code attached.

    regards,
    JSVenu
    Attached Files Attached Files

  19. #19

  20. #20
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: [VB6] - Signal spectrum

    Quote Originally Posted by The trick View Post
    jsvenu, if you want to solve some threading scenario with the sound please create a new thread in the main forum.
    Dear Trick,

    Ok. I started a new thread for this at http://www.vbforums.com/showthread.p...21#post5454621

    regards,
    JSVenu

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width