Originally posted by uxmkt
View Post
And later tricking my AdLib through volume modulation, too. (Didn't have the necessary pieces to solder my own Covox Speechthing-like parallel port DAC like the cool kids. Eventually I got a Sound Blaster at Christmas later on)
But all in all, playing PCM is relatively straight forward, and PWM is too. (Specially on a device where the speaker is more or less directly connector to the output of a timer. It's pretty low-level doing crazy things with it did entirely make sense).
The magic in Linux comes from managing the precise timing to achieve it.
(No DMA at all + Single pulse trigger on the PC Speaker = so you must manually trigger a pulse for every sample. It's easy to achieve in a single task environment like DOS (use a timer IRQ on AT+ class computers, or count your cycles on older PC). It a much more involved feat in a multi-tasking multi-user environment, where you also need to keep all the other tasks into consideration.
Composite sine synthesis of MIDI is an entirely different can of worm. You aren't playing straight PCM, but you need to correctly extract your formant from the sound (Fourrier transform + lots of clean-ups upstream of the playing) and you're playing it over a channel that is very high-level: you aren't directly driving anything, you're passing very abstract messages (to the instrument(s) listenning on channel CC: please select instrument number XX from your bank, and then please play note YY, with velocity ZZ).
The PC Speaker equivalent would be trying to play PCM samples... while doing it using exclusively Music Macros Language (e.g.: MS-BASIC's PLAY command).
(Which BTW could perhaps be achieved but not on stock music macro. You'd need a fair amount of PEEKing and POKEing (and IN/OUTing) to change the frequency of the interrupt handler used by the BASIC's MML player, remove sanity checks in the MML interpreter so you could send arbitrarily short durations, probably tweak both timers even further, and use a very beefy computer so the whole MML macro routine can run at the high frequency required by PWM).
(And if you think about it, those PEEK/POKE/IN/OUT commands/functions in the above speculation are BASIC's equivalent to MIDI's SYSEX).
Leave a comment: