How to play a sound without interrupting other threads with in an MFC application?
-
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
-
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
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 thePlaySound
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.
-
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 thePlaySound
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.
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
-
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
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
-
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
Yes, its a dual Quad core Xeon Processor system.
PKNT
-
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
Start a new thread which will call PlaySound