How does the sound card process different incoming audio signals before outputting to the same speaker simultaneously?
I'm just going to start with a brief blurb about what a sound card does. The soundcard can store, mix, process and buffer sound. Only the analog input(if present) and non digital outputs share the same "type" of signal as the speaker receives. The connection to the CPU as well as any fiber optic or HDMI inputs or outputs are all digital, and are capable of transmitting much more data than is required for a single audio signal. The slowest PCI Express standard is capable of 250 MB/s and a single channel of CD quality audio only uses 705.6 Kbps, so one PCI express lane without overhead can keep up with roughly 2.8 million CD quality audio signals, so getting information to and from the card is no problem.
A program executes a code, after many steps in binary/transistor level finally the audio is sent from the CPU to the soundcard in digital domain. The sound card then processes this incoming information to analog signal and amplifies and outputs to a speaker.
The programs running on the computer determine what audio signals must play and when. Data representing audio signals must be brought from slow storage and kept in memory.
All of the signals meant to play at once must be processed and mixed, which can be done by the CPU or the sound card. Almost all soundcards are capable of mixing a large number of channels, but the better and newer a soundcard is the more likely it can perform significant amounts of processing, things like converting to directional audio, echo or room effects and normalization to take processing load off the CPU and/or provide a better quality experience. To mix two audio signals, they must be converted to compatible format(if stored compressed), the amplitude of the signals at each point in time can be summed(literally added together) and then normalized(volume adjusted because doing this doubles effective amplitude). You have to either have headroom(storage space and ability to process larger numbers than the original signals contained) or normalize before summing, which could reduce signal resolution if not done correctly.
Knowing that the CPU is a serial processor, how come we can still hear several different sounds from the speaker as they are distinct. Somehow the soundcard does not mix simultaneous incoming audio data. And most confusingly imagine one executes three programs where all outputs different audio. But at the end there is one single current passes through the speaker.
Once the audio has been processed and mixed, it is still in digital form and as the soundcard produces the actual output (1 digital signal per output channel), it wouldn't be efficient to design the soundcard to produce this output at precisely the correct rate, so it's put in a buffer at whatever rate it is produced. The output is then converted to analog from the buffer at the correct rate and that output is what goes to the headphone jack on your computer.
What is that current composed of? Is that the addition of three different waveforms? If so are they added in soundcard or before? Is sound card parallel processing and adding them at the end?
The current is composed of moving electrons. Yes, the waveforms are literally added(Any number can be simultaneously mixed btw, so you can use (Signal1+Signal2+Signal3+Signal4+Signal5)/5 = OutputSignal rather than adding them together 2 at a time.), and this can be done by the cpu or the soundcard. It could be the application, the operating system, or the soundcard doing the processing.
I'm just going to add an example to put it together. You have a first person shooter game running, an MP3 player playing music connected to the aux input jack and several other programs running that provide audible notifications. You have 5.1 channel speakers attached to your computer.
The MP3 player provides audio to an ADC in the soundcard, which converts the signal to digital and feeds it to the audio driver, which provides a volume adjustment, and may also split the 2 channel audio into 5.1 channel audio(to make it play on all 5.1 speakers instead of just front left and front right), at which point the signal is ready to be output. The CPU can either perform the volume adjustment and splitting itself or provide the soundcard with parameters instead.
Each of the programs using audible notifications will provide a volume adjustment, may split the audio into multiple channels if it comes from a mono file, and pass it to the audio driver, which might provide a second volume adjustment and/or split it into 5.1 channel audio, at which point the signal is ready to be output. Again, the CPU can either perform the processing functions or pass it off to the soundcard.
Finally you have your FPS shooter game running, and it's running in native 5.1 channel mode. At any given point in time we'll say it's playing an average of 15 different sounds, ambients, grey noise, running engines, footsteps, gunshots and echoes or some such. Because all of these are sounds stored in normalized wave files, once the sound has been loaded in memory, you can't simply send it to the soundcard at the correct time because direction and distance must be taken into account, so directional sounds must have their volume modified based on distance and be split into the correct channels to be played on the correct speakers. All of these sounds must be mixed, which again may be done by the CPU or the soundcard. Finally the data may undergo a volume adjustment. This application(gaming), in particular, can amount to a considerable workload, and having the soundcard perform these tasks rather than the cpu is beneficial. At this point the signal from the game is ready to be output.
Now we have three audio streams from different programs, which, again, must be mixed, normalized, and the master volume adjustment performed. Each of these audio streams may be 2 channel or 5.1 channel. If neither the operating system or soundcard is instructed to split the 2 channel into 5.1 channel, two channel is mixed with the front left and front right speakers.
Once all of this is done, you have 6 signals being output to their own DAC, each of which consists of a mixture of many.