Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Music player process

I was reading a book which says that a processor with single core and no hyper-threading can process only one process at a time, so a doubt arises that when we do so many operations on a PC and also some background processes are always there then why not music player stops in between for short while. I know the CPU is pretty fast but still music player usually plays music in continuance without any small break ( that is observable ). Can anyone clarify this behavior?

like image 672
Akashdeep Saluja Avatar asked Sep 07 '12 14:09

Akashdeep Saluja


People also ask

What is the function of music player?

They are portable digital music players that play music as audio files, such as MP3. In addition, most of these devices allow to store video, pictures, and to receive radio and TV programs (podcasting). Earphones and external speakers are the typical output devices delivering sound to the listener.

How does a digital music player work?

It has an input (probably a USB docking lead that hooks it up to your computer), a memory (either a small hard drive or a flash memory that can store MP3 files), a processor (something that can read the MP3 files and turn them back into music), and an output (a socket where you plug in your headphones).


1 Answers

1) A single-core CPU without hyperthreading can, as you say, only run one process at a time. Multiple processes are handled by context-switching, that is the CPU will run one process and then switch to the next process and the next and then back to the first process and so on. The frequency of how often a certain process is scheduled is dependent on lots of different factors, where process priority is one. (Back in the days it was often needed to run WinAmp with elevated priority to avoid glitches etc. Nowadays this is not needed as the CPU is a lot faster).

2) So, with this in mind, how come it still sounds great and without glitches?

When processing audio the CPU feeds the sound device with samples by putting them either in a hardware buffer on the sound card or in the RAM. The sound processor does not get its data directly from the CPU, instead it reads the samples from one of these two buffers. As long as we have samples in the buffer we are good, even though the CPU is off doing something else.

The details about the hardware buffer size is different on different sound cards. Some (older) sound cards does not have a sound buffer at all, and here the RAM comes into play instead.

Running out of samples is called buffer underrun. Even on modern computers this can happen, for example if you start a heavy process while running your audio player the CPU may not be able to switch back in time and we can clearly hear glitches and gaps in the sound feed.

like image 54
Avada Kedavra Avatar answered Sep 30 '22 02:09

Avada Kedavra