Its possible and PWM controlled DAC is the answer. All you need is single digital pin output and fast enough I/O hooked up to non linear load (like Speaker, or capacitance or RC filter) ...
This can be used to play PCM samples (among other things)...
set PWM base frequency high enough
the frequency should be higher than human can hear otherwise you would hear a high pitch sound in the background. However if CPU I/O is not fast enough you just use lower one. For example telephony uses sounds up to ~4KHz so PWM with 8KHz is enough to produce telephony quality sound (its enough for "recognizable" human language even if voice is up to 12KHz).
PWM -> DAC
each period of PWM transfers some energy to the speaker. For AC coupled loads The amount is highest with ratio 1:1 (50% is L and 50% is H). The further you are from this the lower energy is transfered. This is sort of DAC.
PCM
PCM is analog variable sampled (by ADC) as digital numbers (for DAC) that reproduces the original analog variable (up to a point). So we can sample sound in form of PCM (like *.wav files) and play it with PWM on Speaker.
When you put all this into SW 1bit digital Speaker you will need:
2 * f_sound * n_volumes = f_IO
where f_sound
is the max frequency of sound produced (samplerate/2), n_volumes is the number of different sound volumes produceable and f_IO is required frequency of I/O to produce this sound.
If we think about ZX then we need in inner most loop something like this (highly unoptimized):
l2: ...
ld a,0 ; 7T
out (254),a ;11T
ld bc,(adr_L) ;20T
l0: djnz l0 ;17/12T
ld a,255 ; 7T
out (254),a ;11T
ld bc,(adr_H) ;20T
l1: djnz l1 ;17/12T
jp l2 ;14T
summing up to ~104T per PWM period. If we consider 4 volumes, another ~50T for sound fetching or generating and 4MHz CPU then:
f_sound = 4000000/(2*4*(104 + 50))
f_sound = ~3.2 KHz
which is more or less like the telephony quality sound. So yes it was possible to have such sound on old 8bit computers. The code is just my pure attempt I wrote just now and can be optimized a lot more so I imagine you could go even to 8KHz after optimizations made...
I created similar PCM sample player on my ZX ages ago where the sound was sampled by ADC hooked to 8255 of my ZX clone (Didaktik Gama 89) and then could be played latter on internal Speaker. It was capable of storing just a few seconds (IIRC ~15sec) into memory but it worked. Sorry I do not remember the samplerate I was able to achieve but it was higher than 4KHz.
However this technique requires a lot of CPU time that prohibits other stuff like gfx, game logic etc to be done at the same time unless other HW capabilities are exploited. For example on PC there is the PIT i8253 that can make part of the stuff for you ...
On top of all this you can achieve also polyphony. With volume control its easy you just sum up the 2 or more channels together with saturation.
However its possible to do it also without the volume control (the 1bit sound video from youtube you linked use this technique). Its done by combining the 1bit digital signals together.
For more info see: