• Please review our updated Terms and Rules here

Please help me to play high-quality audio on XT/286 machine

The crash has been fixed and also exits gracefully on keypress.
Here's it on the 4.77MHz PCjr that happens to have its PC Speaker output amplified via the monitor. Upon close listening there's a melody being played behind the "bank alarm" ringing:
 
@boggit @konc @deanimator @Chr$ @Chuck(G) and everyone else, thank you so much, guys, for all your effort!
I honestly hadn't expected so much help and support, but you were amazing!
It was also awesome to see your machines!

I apologize for what you had to go through listening to these noises!
You are right; they are not nice at all :LOL:

Regarding the program, few conclusions:
1. The approach is working in general
2. 4.77 Mhz is enough to run this kind of program
3. The sound is very quiet. I probably had to amplify the sample to peaks to make it scream before transforming into raw
4. Maybe the code is not fast enough, or because 8 KHz PIT update frequency is audible, we hear that high pitch beep in the background
5. Emulators are not able to simulate the real physical speaker behavior
6. I need to have real hardware if I plan to achieve any good results

To illustrate why I was so naively optimistic and what I dreamed of hearing on the real hardware, here is the same program running under DOSBox.
 

Attachments

  • sound2.mp4
    582.3 KB
Last edited:
There are lots of emulators with their own quirks. From my experience I have found MESS/MAME32 to be good enough to debug my DOS cassette tape interface (the tape modem is the same timer chip as the PC speaker, just a different channel). DOSBox is mainly an emulator to play DOS games on, it doesn't accurately simulate all software quirks of old hardware.
Here's an emulated 4.77MHz PCjr, as far as the sound goes I think it is fairly comparable to my video above and to Chr$' observations on his XT; only perhaps the bass frequencies are lost in the real hardware due to the puny speaker + the staccatto in my Junior above are, what I think, caused by an amplified bus noise.

Take a listen - faint emulated floppy noise (spindle and stepper) in the beginning, (loud) PC sound starts at the ninth second:
 
Last edited:
There are lots of emulators with their own quirks. From my experience I have found MESS/MAME32 to be good enough to debug my DOS cassette tape interface (the tape modem is the same timer chip as the PC speaker, just a different channel). DOSBox is mainly an emulator to play DOS games on, it doesn't accurately simulate all software quirks of old hardware.
Here's an emulated 4.77MHz PCjr, as far as the sound goes I think it is fairly comparable to my video above and to Chr$' observations on his XT; only perhaps the bass frequencies are lost in the real hardware due to the puny speaker + the staccatto in my Junior above are, what I think, caused by an amplified bus noise.

Take a listen - faint emulated floppy noise (spindle and stepper) in the beginning, (loud) PC sound starts at the ninth second:

For me, the emulator recording sounds a lot better.
If I compare your recording from your PCjr and the recording from the emulator, the difference is HUGE.

That's the main problem for me now because, on my end, this program in the emulator also sounds very good, but as we know, it sounds differently on the real PCjr and XT.
This means that when I hear something on an emulator, I cannot trust it, and it will sound significantly different on the hardware.
The staccato, as you nicely called it, ruins the whole experience, and there is no way for me to hear and fix it on an emulator because it is not audible there.
Recordings from boggit and konc do not seem to have staccato, but they are quiet and have high-pitched noise.
But we don't hear such problems on emulators. Unfortunately, the conclusion is the same: emulators have no trust.
Sigh... I need real hardware.
 
konc said:
If you can find a "real" speaker you could use something relatively modern and available I believe.

Even with a mainboard that has a small piezo speaker, we're talking about PWM here - the speaker output is usually open collector, and the speaker itself connected between +5V and /SPK. A NOT gate such as the 7404, 1 signal NPN with its emitter grounded, and a base resistor of around 100 ohms to the output of the NOT gate, that should be enough for him to connect regular 8-ohm magnetic speaker between the collector and say +12V of the PSU to get real loud sound. No investments in expensive technology needed.

As far as the 4.77MHz XT goes, the nicest PC speaker "digitized sound" I have heard from a DOS application, was from a French game called Space Racer. It plays its theme tune that's almost a minute long from two unsigned 8-bit mono samples, MUSIC0.SPL and MUSIC1.SPL (each 42K and 55K in size, respectively), sampled at around 10 kilohertz, by loading them to memory at once, and then playing predefined parts (i.e. not the whole sound file at once). There's some whine present even on the real hardware, but it's far from being ear-piercing, and a regular ole PC/XT is enough. Their executable (SPACE.EXE) is not packed or obfuscated so you could have a look at their timer ISR. You won't get more "Hi-Fi" than this, unless you go via the route of D/A converters, reinventing the sound card in the process. :)

 
Last edited:
Since most PCs had parallel ports back then, a common dodge was to make a simple R/2R DAC hooked off the port. Didn't interfere with printing, but did require a small external amplifier. Sound quality was significantly better than the simple PIT-based PWM.
 
Yes, but not necessarily very old and very expensive. If you can find a "real" speaker you could use something relatively modern and available I believe.
Yeah, but relatively modern would also mean faster, which removes the challenge of doing this for the oldest and slowest machines.
I'm not too concerned about price, but space is my problem. I don't have much space in the apartment or on my table for one more machine 😥
 
Even with a mainboard that has a small piezo speaker, we're talking about PWM here - the speaker output is usually open collector, and the speaker itself connected between +5V and /SPK. A NOT gate such as the 7404, 1 signal NPN with its emitter grounded, and a base resistor of around 100 ohms to the output of the NOT gate, that should be enough for him to connect regular 8-ohm magnetic speaker between the collector and say +12V of the PSU to get real loud sound. No investments in expensive technology needed.

As far as the 4.77MHz XT goes, the nicest PC speaker "digitized sound" I have heard from a DOS application, was from a French game called Space Racer. It plays its theme tune that's almost a minute long from two unsigned 8-bit mono samples, MUSIC0.SPL and MUSIC1.SPL (each 42K and 55K in size, respectively), sampled at around 10 kilohertz, by loading them to memory at once, and then playing predefined parts (i.e. not the whole sound file at once). There's some whine present even on the real hardware, but it's far from being ear-piercing, and a regular ole PC/XT is enough. Their executable (SPACE.EXE) is not packed or obfuscated so you could have a look at their timer ISR. You won't get more "Hi-Fi" than this, unless you go via the route of D/A converters, reinventing the sound card in the process. :)

Thanks! That's an interesting example of how people went above and beyond to get a quality sound while using minimal resources.
Indeed, it plays pieces of these two audio files. They have sampled PWM and an array of which samples to play and how long separately. Like in the modern world, MIDI data and instrument samples are stored separately and then played by some sequencer. Pretty cool!
Unfortunately, their ISRs are extremely simple, and they have no magic. Interestingly, they are switching between a few ISRs in real time and between pieces of samples, i.e., after every "instrument" note :unsure:
I will investigate this deeper.
Thanks for the cool app to play with!
 
As far as the 4.77MHz XT goes, the nicest PC speaker "digitized sound" I have heard from a DOS application, was from a French game called Space Racer.

This is indeed amazing, I'd hesitate to bet on pc speaker or low quality sound card synthesis. Thanks for sharing

Yeah, but relatively modern would also mean faster, which removes the challenge of doing this for the oldest and slowest machines.
I'm not too concerned about price, but space is my problem. I don't have much space in the apartment or on my table for one more machine 😥

I was thinking of a combined dev environment with emulators for speed adjustments and trials, and something modern but with a real speaker to be able to hear the outcome. But yeah if space is an issue I totally understand.
 
Last edited:
I gave it my try this evening: made an app to convert the 8-bit PCM into 1-bit PWM, shortening the datastream size eight times, and instead of programming the speaker channel 2 frequency in the timer ISR I just flip its enable flag accordingly. This yields loud sound, comparable with regular beeps, and having zero whine at a sampling rate of 14 kHz still usable on the stock 4.77MHz 8088. But it's not really usable for "music" unlike some wacky sound effects, because of the resulting distortion. Here's Bill Hanna's famous Tom and Jerry scream played on the PCjr... I think it's fitting. :)

 

Attachments

  • TOMJERRY.ZIP
    40 KB · Views: 3
I gave it my try this evening: made an app to convert the 8-bit PCM into 1-bit PWM, shortening the datastream size eight times, and instead of programming the speaker channel 2 frequency in the timer ISR I just flip its enable flag accordingly. This yields loud sound, comparable with regular beeps, and having zero whine at a sampling rate of 14 kHz still usable on the stock 4.77MHz 8088. But it's not really usable for "music" unlike some wacky sound effects, because of the resulting distortion. Here's Bill Hanna's famous Tom and Jerry scream played on the PCjr... I think it's fitting. :)


Love the code, especially the idea to feed the "precompiled" bitstream.
 
I gave it my try this evening: made an app to convert the 8-bit PCM into 1-bit PWM, shortening the datastream size eight times, and instead of programming the speaker channel 2 frequency in the timer ISR I just flip its enable flag accordingly. This yields loud sound, comparable with regular beeps, and having zero whine at a sampling rate of 14 kHz still usable on the stock 4.77MHz 8088. But it's not really usable for "music" unlike some wacky sound effects, because of the resulting distortion. Here's Bill Hanna's famous Tom and Jerry scream played on the PCjr... I think it's fitting. :)

Haha, this is hilarious! :LOL:
Sounds very loud, indeed and I love the simplicity of the code!
Nicely done!
 
If you guys still feeling adventurous and want to struggle a bit more with me, I'm offering you to try a new version :)
Sorry, but as usual, no working code or good-quality audio is guaranteed :LOL:

⚠️ The program exits on the ESC key only ⚠️

This is a 10 kHz version (instead of 8 kHz in the previous) with a different sound, Red Hot Chilli Peppers - "Californication" intro.
Hopefully, 10 kHz will reduce that annoying high-pitch noise we heard last time.

I've picked this specific song because it has primarily low frequencies that I assume PC speaker likes more (hopefully). I went through the sample in Audacity, manually smoothed some spikes, and then amplified the sample.

The whole code became very optimized and hackish.
This is the main ISR, for example:
Code:
new_int8:     
    lodsb

    or al,al
    jne not_end
    mov si,offset sample
    lodsb

not_end:
    out 42h,al

    mov al,20h
    out 20h,al
    iret

And this is the main loop :LOL:
Code:
wait_for_esc:
    or bl,bl
    je wait_for_esc

The program now also sets own handler for int 9 (keyboard), to detect keypresses instead of calling int 16h or other methods.

Please let me know if the program works at all.
It works and sounds pretty good on emulators, but I don't trust them anymore 😤

Thank you!
 

Attachments

  • SOUND4.zip
    31.2 KB · Views: 2
Yeah, it's better now. The only issue is that on a PCjr, the keyboard is handled differently so it won't react to any keypresses here, Escape included. I think you don't need to concern yourself about that since the Junior had been a blind development path, but if you want to, you can inspect the keyboard buffer in the BIOS Data Area (BDA), so e.g. if you use DS to process your sound in your ISR and you have ES free, set it to 0 before the sound starts and then inspect the keyboard buffer (32 bytes at address 41Eh, start and end offsets are 16-bit values at addresses 480h and 482h respectively). It's faster than calling the INT 16h interrupt to do a keypress check.

 
Yeah, it's better now.
Wow! It is really loud and even sounds pretty clear on the recording!
Does it really sound clear? Have there been any noises or distortions?

The only issue is that on a PCjr, the keyboard is handled differently so it won't react to any keypresses here, Escape included. I think you don't need to concern yourself about that since the Junior had been a blind development path, but if you want to, you can inspect the keyboard buffer in the BIOS Data Area (BDA), so e.g. if you use DS to process your sound in your ISR and you have ES free, set it to 0 before the sound starts and then inspect the keyboard buffer (32 bytes at address 41Eh, start and end offsets are 16-bit values at addresses 480h and 482h respectively). It's faster than calling the INT 16h interrupt to do a keypress check.
Nice! I'll check this. Thanks!
 
It's good enough with some background whine. You won't get the loudness of 1-bit PWM, then again, not the distortion either, which is what you don't want. Unless you're playing loud screams, wacky gunshot noises or Austrian painter's fits of rage. I have a video of that too, but I won't risk the banhammer here. :)

Note that the PCjr only has a small piezospeaker on the mainboard, so its sound is amplified via the monitor. How the piezospeaker sounds by itself can be heard in the last 2 seconds of the video when I turn the volume all the way down. A 5150 or XT has a 1/2-watt classic voice coil speaker, which is louder than a piezospeaker itself - but it's still not amplified unlike what's in the monitor of the PCjr. If you want to experiment I posted some details in my post above, on how to construct a simple "amplifier" (more precisely a switch) with 1 transistor and a 7404 gate, even if the mainboard has a small piezo speaker. But then again, you'll fall down the rabbit hole of reinventing a DAC or a whole sound card in the process. Have a look at the Covox Speech Thing or a Disney Sound Source. Printer port in, speaker sound out - and of better quality and loudness than what comes from the mainboard. I have actually used this circuit to diagnose a faulty parallel port card that failed to allocate an I/O address - by listening to "pops" in the speaker during BIOS POST.
 
Last edited:
Back in the day (late 80s) there were techniques, such as what you are working on, to incorporate speech/sound effects in PC games.


Basically it was 1 bit a2d and there were a number of techniques to try to smooth it out.....to little consequence...because...it's 1 bit a2d :) Still, if it was intelligible by comparative standards, novelty and small files meant that it was worthwhile...until better techniques (better hardware) came around. The same data could, and was, used, in C64 and apple ii. You just slammed it out the speaker bit - literal bit banging.

You could take 8 bit a2d and try your best to convert it to...1 bit. You can use an op amp comparator and adjust levels as it comes in...you can trim the files...but in the end, you are pushing that speaker cone back and forth..all or none. It is amazing that it can be as good as it is....but it is still as bad as it is :)

Here is an example with some source code if you are interested to see any differences in how you are sending it out the speaker.
 
He's actually doing eight bits here. On a PC the PIT has 3 channels: channel 0 for the IRQ0 timer, channel 1 for XT RAM refresh and channel 2 for the speaker and 5150 tape interface.
For digitized sound output through the speaker, you have two options basically: directly flip the "speaker enable" bit (PPI 8255A-5 Port B, reg. 61h, bit 0) in the clock ISR for either a constant duty cycle square wave for beeping, or 1-bit PWM (loud and distorted with no background whine). Or, instead, program the LSB of channel 2 of the PIT 8253-5 in the clock ISR with the sample byte (i.e. all eight bits) currently read. With this you get lower volume and some background whine, but better sound "fidelity".
For 1-bit conversion check out my software example above, it's simpler. My "Tom and Jerry" example is an example of the former, his improved SOUND4 is an example of the latter.
 
He's actually doing eight bits here. On a PC the PIT has 3 channels: channel 0 for the IRQ0 timer, channel 1 for XT RAM refresh and channel 2 for the speaker and 5150 tape interface.
For digitized sound output through the speaker, you have two options basically: directly flip the "speaker enable" in the clock ISR for 1-bit PWM (loud and distorted with no background whine), or program the LSB of channel 2 in the clock ISR with the sample byte (i.e. all eight bits) currently read. With this you get lower volume and some background whine, but better sound "fidelity".
For 1-bit conversion check out my software example above, it's simpler.
Not sure I am following your reference "He's actually doing eight bits here" - you realize the "he" in my post / source code example is me back in the late 80s - right?
 
Back
Top