patternMinor
Why doesn't playing audio stop other tasks?
Viewed 0 times
playingwhystopaudiodoesntasksother
Problem
If processors can only execute one thing at a time, how come I can play music continuously and still be able to run other tasks?
I understand the interrupt system, but isn't it needed that CPU continuously process audio for it to not sound jittery/laggy?
I am asking about the underlying implementation, is this question related to multi-threading? How does a 1-core, 1-threaded CPU be able to achieve this multitasking?
I understand the interrupt system, but isn't it needed that CPU continuously process audio for it to not sound jittery/laggy?
I am asking about the underlying implementation, is this question related to multi-threading? How does a 1-core, 1-threaded CPU be able to achieve this multitasking?
Solution
Since the CPU works in fixed clock cycles, nothing is really continuous, only seems so because the discretization is sensitive enough.
Suppose your CPU clock rate is $1\text{GHz}=10^9Hz$. If the CPU only devotes one in $t$ clock cycles to processing audio (and utilizes the remaining clock cycles for unrelated tasks) then you have a delay of $\approx t\cdot 10^{-9}s$ between every "audio processing tasks" preformed by the cpu (for simplicity, we assume the cpu preforms this processing using only one clock cycle).
Lets say we allow a delay of $10^{-5}s$ (humans hear frequencies in the range of 20Hz to 20Khz, so the human hearing will not be sensitive to such delay), then we need to require $t<10^4$, so the CPU can handle simultaneously $10^4$ more tasks while keeping a delay of $10^{-5}s$.
Suppose your CPU clock rate is $1\text{GHz}=10^9Hz$. If the CPU only devotes one in $t$ clock cycles to processing audio (and utilizes the remaining clock cycles for unrelated tasks) then you have a delay of $\approx t\cdot 10^{-9}s$ between every "audio processing tasks" preformed by the cpu (for simplicity, we assume the cpu preforms this processing using only one clock cycle).
Lets say we allow a delay of $10^{-5}s$ (humans hear frequencies in the range of 20Hz to 20Khz, so the human hearing will not be sensitive to such delay), then we need to require $t<10^4$, so the CPU can handle simultaneously $10^4$ more tasks while keeping a delay of $10^{-5}s$.
Context
StackExchange Computer Science Q#76029, answer score: 9
Revisions (0)
No revisions yet.