Results 1 to 19 of 19

Thread: using WaveOutOpen with CALLBACK_THREAD option

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    using WaveOutOpen with CALLBACK_THREAD option

    Dear Trick,

    Can you provide me an example of using WaveOutOpen multimedia api using CALLBACK_THREAD option in the main thread like you have given for Signal Spectrum display using CALLBACK_WINDOW.

    regards,
    JSVenu

  2. #2
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: using WaveOutOpen with CALLBACK_THREAD option

    dear jsvenu:
    Why do you have so many questions?
    ha ha!
    Do not know what you are mainly engaged in work, the main development of what tools?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by xiaoyao View Post
    dear jsvenu:
    Why do you have so many questions?
    ha ha!
    Do not know what you are mainly engaged in work, the main development of what tools?
    Dear xiaoyao,

    I have idea of how to do this in unmanaged vc++ 6.0 win32 and MFC apps because they support message loop ,threading(including worker and user interface threads) directly.I wanted to do the same using vb6 by taking help from members of vbforums like Trick .I already tried and having some problems as you can see in http://www.vbforums.com/showthread.p...ignal-spectrum.

    regards,
    JSVenu
    Last edited by jsvenu; Feb 22nd, 2020 at 03:27 AM.

  4. #4

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by The trick View Post
    This is the example.
    Dear Trick,

    Thankyou for the example.

    I tried to extend the app to form based app and put two buttons Play and display msgbox.
    I made form as startup and call Main in Play button1 handler and display msgbox in display msgbox (button2) handler as follows:


    Code:
    Private Sub Command1_Click()
    Main
    End Sub
    
    Private Sub Command2_Click()
    MsgBox "in btn2" 'the playing sound stops when msgbox displayed
    End Sub
    I increased the play duration upto 1000 secs so that I can try to display msgbox when I play it by clicking on display msgbox (button2) as follows:
    Code:
        Loop While m_fPlayedSec < 1000
    When I click Play button the sound starts playing and then when I click on display msgbox (button2) we get msgbox displayed but the audio stops immediately.
    How to make the audio continue even when we click on display msgbox (button2) and terminate the application properly.


    regards,
    JSVenu
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: using WaveOutOpen with CALLBACK_THREAD option

    maybe you need play music in thread 2。
    click button to play,stop。
    when playing,if you click button about "msgbox now",music will play in background,It won't be interrupted Stop.

  7. #7

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by The trick View Post
    You can't show a modal box because it has it's own modal loop which doesn't know about your MM_WOM_DONE messages and just skips it.
    Dear Trick,

    But your signal spectrum which you are displaying using subclassing and CALLBACK_WINDOW continues playing audio even when I click on the new button1 handler to display a msgbox after clicking the play button which you can check in the attachment.

    I was asking for same using CALLBACK_THREAD option in waveoutopen api. Please clarify.

    regards,
    JSVenu
    Attached Files Attached Files

  9. #9

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by The trick View Post
    When you use the CALLBACK_WINDOW method DispatchMessage sends the message to the WindowProc.
    Dear Trick,

    With CALLBACK_THREAD option in WaveOutOpen api can we call DispatchMessage using SetWindowsHookEx and WH_GETMESSAGE and in the callbackgetmsgproc friend function (main Form member function) so that DispatchMessage sends the message to the WindowProc in the sample link below which I already posted so that audio continues without stopping.
    http://www.vbforums.com/attachment.p...9&d=1582277698

    regards,
    JSVenu
    Last edited by jsvenu; Feb 23rd, 2020 at 06:54 AM.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by jsvenu View Post
    Dear Trick,

    With CALLBACK_THREAD option in WaveOutOpen api can we call DispatchMessage using SetWindowsHookEx and WH_GETMESSAGE and in the callbackgetmsgproc friend function (main Form member function) so that DispatchMessage sends the message to the WindowProc in the sample link below which I already posted so that audio continues without stopping.
    http://www.vbforums.com/attachment.p...9&d=1582277698

    regards,
    JSVenu
    Dear Trick,

    I found the problem is with acquiring data and displaying it on the form when we hook main thread msg pump.

    In the callbackgetmsgproc function which is the hook function for main thread msg pump for receiving MM_WOM_DONE event when we use waveoutopen with CALLBACK_THREAD and SetWindowshookex with WH_GETMESSAGE we will be receiving the MM_WOM_DONE when this playing is going on pressing Play button and even when we click on button1 handler which displays msgbox.

    I had to modify the program by commenting acquiring data and displaying it on the form in the callbackgetmsgproc.
    Now we get the same audio acquired in first sample only and it is written and played continuously.
    Can you tell me how to make the program work as usual using this method of CALLBACK_THREAD in waveoutopen api.
    I am attaching the working code with this limitation which plays audio in main thread even with msgbox displayed.Please clarify.

    regards,
    JSVenu
    Attached Files Attached Files

  12. #12

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by The trick View Post
    Why hooks? I don't understand you. I gave you the 2 codes with CALLBACK_THREAD and CALLBACK_WINDOW. What's your end goal?
    Dear Trick,

    The code you gave using CALLBACK_THREAD does not route MM_WOM_DONE to the default msg pump when we try to display msgbox while playing.So like you used subclassing I had to use WH_GETMESSAGE hook which is used to get default message loop and route MM_WOM_DONE to it even when a msgbox is displayed while playing just like using subclassing with CALLBACK_WINDOW.In addition to this updating audio buffer and displaying has to be updated in this sample code with link http://www.vbforums.com/attachment.p...3&d=1582473415 like in the code you provided using CALLBACK_WINDOW.

    Using CALLBACK_THREAD I only know WH_GETMESSAGE hook to get default msg pump and catch MM_WOM_DONE while displaying msgbox and I have difficulty in acquiring audio data and updating display.If you know any other way to tackle msg pump you can help me as you already helped using subclassing and CALLBACK_WINDOW for which I am thankful to you.

    regards,
    JSVenu
    Last edited by jsvenu; Feb 24th, 2020 at 05:55 AM.

  14. #14

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by The trick View Post
    If you need a message box just use CALLBACK_WINDOW.
    Dear Trick,
    Ok I agree that here subclassing using CALLBACK_WINDOW is better than hooking with CALLBACK_THREAD in this example of playing audio and spectrum display.

    Suppose we start say 10 threads each of which have lot of processing loops when we click on command1 button
    instead of displaying a msgbox.

    1. Can you tell me how to maintain the same quality of audio and spectrum display continuously for the main thread when the 10 threads are started by clicking on command1 button after clicking on play button.
    How to make the main thread behave like it was behaving before without the 10 threads started.

    2.When we stop or pause play how to make the other threads work as they work without clicking on play button.
    Code attached.

    regards,
    JSVenu
    Attached Files Attached Files
    Last edited by jsvenu; Feb 24th, 2020 at 08:06 AM.

  16. #16
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,797

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Can you tell me how to maintain the same quality of audio and spectrum display continuously for the main thread when the 10 threads are started by clicking on command1 button after clicking on play button.
    How to make the main thread behave like it was behaving before without the 10 threads started.
    This is obliviously you shouldn't overload the thread which plays the audio. Alternatively you could use CALLBAC_FUNCTION mechanism but it isn't trivial.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by The trick View Post
    This is obliviously you shouldn't overload the thread which plays the audio. Alternatively you could use CALLBAC_FUNCTION mechanism but it isn't trivial.
    Dear Trick,

    Thankyou for the reply.
    In the main thread I will be playing audio.My intention is not to miss any MM_WOM_DONE event in main thread inspite of having other threads in an application which is generally the case in any practical situation so that loss of audio continuity won't be there.Please clarify.

    regards,
    JSVenu

  18. #18

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    356

    Re: using WaveOutOpen with CALLBACK_THREAD option

    Quote Originally Posted by The trick View Post
    Just increase the buffer size and you'll have more time to process the message.
    Dear Trick,

    Thankyou for the reply.

    Just to be more clear is it ReDim m_tBuffer(1) from InitPlayback form function which is defined and used as follows:

    Code:
    'frmMain(code)
    
    Private m_tBuffer()     As tBuffer
    
    
    Private Function InitPlayback() As Boolean
    
    
           ...
    
           ReDim m_tBuffer(1)
    
           ...
    
    End Function

    Here you used only one item in the m_tBuffer.
    So you mean we have to increase the count as follow:




    Code:
    Private Function InitPlayback() As Boolean
    
    
           ...
    
           ReDim m_tBuffer(count)
    
           ...
    
    End Function
    Generally what is the value of this count we have to take based on other threads for better performance.Please clarify.

    regards,
    JSVenu

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