Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to play a sound without interrupting other threads with in an MFC application?

How to play a sound without interrupting other threads with in an MFC application?

Scheduled Pinned Locked Moved C / C++ / MFC
c++csshelptutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kiran Satish
    wrote on last edited by
    #1

    I am wondering if anyone could help me figure out a way to reliably play a sound using 'PlaySound' function and not interrupting other threads in an application. I am currently playing a wav file loaded into a resource at a given point in time based on the events that happen in other threads in a real-time application. But whenever it plays, it is interrupting my other threads for a brief moment. Is there any other better way to do this? Here is my command

    PlaySound(MAKEINTRESOURCE(IDW_WAVE),AfxGetInstanceHandle(),SND_RESOURCE | SND_ASYNC);

    The duration of the sound is less than a second. thanks

    PKNT

    _ Michael HaephratiM 2 Replies Last reply
    0
    • K Kiran Satish

      I am wondering if anyone could help me figure out a way to reliably play a sound using 'PlaySound' function and not interrupting other threads in an application. I am currently playing a wav file loaded into a resource at a given point in time based on the events that happen in other threads in a real-time application. But whenever it plays, it is interrupting my other threads for a brief moment. Is there any other better way to do this? Here is my command

      PlaySound(MAKEINTRESOURCE(IDW_WAVE),AfxGetInstanceHandle(),SND_RESOURCE | SND_ASYNC);

      The duration of the sound is less than a second. thanks

      PKNT

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      The SND_ASYNC flag plays the sound without interrupting other threads. How do you measure that the other threads are interrupted? In which thread is the PlaySound function being called. Some info about how the threads are arranged in the application would help for better diagnosis.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++) (October 2009 - September 2013)

      Polymorphism in C

      K 1 Reply Last reply
      0
      • _ _Superman_

        The SND_ASYNC flag plays the sound without interrupting other threads. How do you measure that the other threads are interrupted? In which thread is the PlaySound function being called. Some info about how the threads are arranged in the application would help for better diagnosis.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        K Offline
        K Offline
        Kiran Satish
        wrote on last edited by
        #3

        I am using SND_ASYNC mainly to achieve that. But it still interrupts other threads. I am playing it in a separate thread that runs parallel to other threads and runs upon receiving an event or else waits indefinitely for the event to occur. I can tell that playing a sound effects other threads by looking at the frame that I grab continuously from a framegrabber, where I miss a part of the frame whenever I play the sound. All my threads run parallel and all the threads wait for a certain event to occur. I start all the threads when I run the application, but keep them waiting for certain events to occur. While couple of threads run most of the time, some threads only run when they receive certain event. thanks

        PKNT

        D 1 Reply Last reply
        0
        • K Kiran Satish

          I am using SND_ASYNC mainly to achieve that. But it still interrupts other threads. I am playing it in a separate thread that runs parallel to other threads and runs upon receiving an event or else waits indefinitely for the event to occur. I can tell that playing a sound effects other threads by looking at the frame that I grab continuously from a framegrabber, where I miss a part of the frame whenever I play the sound. All my threads run parallel and all the threads wait for a certain event to occur. I start all the threads when I run the application, but keep them waiting for certain events to occur. While couple of threads run most of the time, some threads only run when they receive certain event. thanks

          PKNT

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Kiran Satish wrote:

          I can tell that playing a sound effects other threads by looking at the frame that I grab continuously from a framegrabber, where I miss a part of the frame whenever I play the sound.

          Do you have a multi-core processor?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

          K 1 Reply Last reply
          0
          • D David Crow

            Kiran Satish wrote:

            I can tell that playing a sound effects other threads by looking at the frame that I grab continuously from a framegrabber, where I miss a part of the frame whenever I play the sound.

            Do you have a multi-core processor?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

            K Offline
            K Offline
            Kiran Satish
            wrote on last edited by
            #5

            Yes, its a dual Quad core Xeon Processor system.

            PKNT

            1 Reply Last reply
            0
            • K Kiran Satish

              I am wondering if anyone could help me figure out a way to reliably play a sound using 'PlaySound' function and not interrupting other threads in an application. I am currently playing a wav file loaded into a resource at a given point in time based on the events that happen in other threads in a real-time application. But whenever it plays, it is interrupting my other threads for a brief moment. Is there any other better way to do this? Here is my command

              PlaySound(MAKEINTRESOURCE(IDW_WAVE),AfxGetInstanceHandle(),SND_RESOURCE | SND_ASYNC);

              The duration of the sound is less than a second. thanks

              PKNT

              Michael HaephratiM Offline
              Michael HaephratiM Offline
              Michael Haephrati
              wrote on last edited by
              #6

              Start a new thread which will call PlaySound

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups