Question
C++ CPP 1. Suppose I want to play an audio file every three seconds (maybe some regular alarm). There are two ways to do this:
C++ CPP
1. Suppose I want to play an audio file every three seconds (maybe some regular alarm). There are two ways to do this:
Method A:
OnStartup() Play audio file Set timer for 3 seconds
OnTimer() Play audio file Set timer for 3 seconds
Method B:
OnStartup() starttime = timeGetTime() Play audio file nextaudiotime = 3 Set timer for nextaudiotime - (timeGetTime() - starttime)
OnTimer() Play audio file nextaudiotime += 3 Set timer for nextaudiotime - (timeGetTime() - starttime)
Assume the time to service a timer expiration averages 3 milliseconds and the time to start up an audio file averages 20 milliseconds. After one hour, how many times will method A and method B be expected to play the audio file. After one day, how many times will method A and method B be expected to play the audio file?
2. It's common that a multimedia presentation will have a characteristic called latency. Latency is a processing delay exhibited by the media. As an example, playing audio from a file may require a variable amount of time, depending on how busy the system is, how quickly the file can be accessed, and how much decompression is required. For this reason, most multimedia API's allow you to load the media, then play it. So, you can tell it to open an audio file in advance, then tell it to play the audio file. The time to start playing is generally very small in this case because the system has been able to prepare for it. Suppose play requires less than a millisecond, but open can require up to 1 second. Modify the algorithm from Method B above to play a different audio file every three seconds and ensure the audio is played on time (within 5 milliseconds will be acceptable).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started