I suspected that I could somehow get some music out of the SimH PDP-8 simulator for a while now, if I could only make it run real time and toggle a GPIO pin fast enough say, on a Raspberry Pi. That may still be doable in the future, but I also had a suspicion that I could generate music not in real time.
I finally got around to trying out my idea last night. A few lines were added to pdp8_cpu.c to spit out the elapsed instruction cycles every time a CAF instruction is executed, the default "noise" instruction in the MUSIC.PA program. That's all I did to the simulator. I then ran MUSIC with a given .MU file and watched as many integers are spit out onto the screen. These were copied and pasted into a new text file and saved. The rest of it is in a single C program that I cobbled together. It reads in this new text file and generates a series of pulses as an array of floats. Each interval is about 1.93 microseconds, which I calculated to be the average number of pulses for the music program to be "in tune" with A=440 Hz, plus or minus. This value is subject to change, particularly as the notes get higher in frequency, but only by perhaps 6% or so from my experiments. One detail to note is that per the recommendation of the MUSIC.PA manual, these pulses are extended to roughly 6 microseconds, or three time intervals in my program. This array of floats is then downsampled use libsamplerate to 44.1 kHz (from 1/1.93 microseconds, or roughly 520 kHz) and output to a canonical WAV file, 16-bit single channel. What do you know, it worked! Here's a sample: https://www.youtube.com/watch?v=_urDcyluX9c My code can be found here, for those interested: https://github.com/drovak/music Presumably, this technique could be used to generate music from any given computer simulator. Thanks, Kyle