SINCLAIR ZX81 Sound Digitizer | English

SINCLAIR ZX81 Sound Digitizer | English

Mar 18, 2023

A magyar verzió itt olvasható.

immagine

Introduction

I wrote the original source code of my now published program in 1986. I recently found it in one of the old spiral notebooks. I typed it but it didn't work because it has a lot of errors. Unfortunately, I could only find this assembly source, no hex code or BASIC loader anywhere. Maybe I have it on one of my tapes or another notebook. Anyway, I fixed it. Despite his poor, 1-bit mono skills, it was a miracle at the time.

immagine

A few years later, I designed and built a 2-bit audio digitizer for the C64. Its sound has become more beautiful, due to the double bit depth, i.e. more detailed sampling. I used it for several demos. I even wrote a sampler based DAW that was similar to the Amiga sampe method, only on 1 channel. Then I also built a 4-bit device (shown below), but it was only tested, nothing was made with it for a demo/game. However, 4 bit already resulted in much more detailed sampling, and thus the result was much clearer and more beautiful. But "the hand of fate" brought me an Amiga, and I built an 8-bit digitizer for it.

immagine My 4-bit digitizer built in 1991. Maybe I'll fix it up and use it for something. Or, I'll just write a post about it. 🙂

About digitization

"Digital signal processing (DSP) or digitization is the process of making a physical quantity processable in some way for a computer."
Wikipedia

This means that the sound, which we have already converted into an analog electronic signal, still needs to be converted into a form that the computer can process. Nowadays, this is done by sound cards, but back then they didn't exist, and most microcomputers only had chips capable of synthesizing sound.

In the figures below, the blue line symbolizes analog sound.
immagine

  • The 1-bit (red), i.e. LO/HI state gives a very rough result.

  • With 2 bits (yellow), we can already distinguish 4 signal levels. It can be seen that the result has been refined somewhat, it is starting to resemble the original.

  • Further doubling the number of bits, 4 bits (green) produces 16 signal levels, which mimics the analog signal quite well.


We used the latter solution on the C64 and other similar machines. They were considered very good in their time. This was surpassed only by the Amiga with its 8 bits (256 signal levels), which would almost be the blue line. As the technology got better and better, the demands got bigger, and 16 bits were introduced, which we still use in our everyday devices. E.g.: MP3 players, mobile phones, TVs, and also computer sound cards. Bits higher than this (24/32) are only used in studios.

Another important thing to know is the sampling rate (ie, samples per second or bits per second), which is usually given in kilohertz (kHz). Here too, the higher the value, the better the recording.

Implementation on the ZX81

The standard CD has a sampling rate of 44.1 kHz with 16-bit. Which means 88200 bytes are processed per second. This exceeds not only the RAM capacity, but also the CPU speed of most contemporary microcomputers. There is nothing to do, a compromise must be made. If we choose to record a maximum pitch of 3 kHz (which is enough for many audio materials), then 6 kHz sampling is required. This is 750 bytes per second with 1 bit, which is approx. 19 seconds means audio material in the 14 kB free space of the 16 kB RAM. I will write about the reason for choosing the 1-bit mode below. Since the number of bits is given, what we can change is the sampling frequency, the setting of which determines the length of the recorded sound, thus changing the "beauty" of the sound in inverse proportion. Of course of the recorded sound determines the recommended minimum sampling frequency.

immagine In the picture taken during the testing of the program, you can clearly see that in the case of a 1 kHz signal, it takes 3-4 samples in the zero state. This means that with this setting, the maximum frequency that can be processed flawlessly is the aforementioned 3-4 kHz. All we have to do is apply a 3 kHz LOW-PASS filter to the music to be digitized so that harmonics do not interfere with the process. This setting is also perfectly suited for human speech.

immagine Further measurements show that the 992 Hz signal after recording will be 1010 Hz during playback. This is actually a speedup of 0.018%, which is almost nothing, but let's be precise, this difference can be easily fixed. The discrepancy is due to the fact that the recording and playback instructions in the program are not the same. If we count the M cycle time of the instructions, a couple of NOP instructions solve it.

The program and its operation

The ZX81 was designed to be such a cheap little machine that no audio equipment, not even a beeper, was included. In addition, an easily programmable USER port, LPT port, or any parallel I/O port were not included. It does have an EXPANSION port, but it is a bit more complicated to put a digitizer on it, because it has to be connected to the bus with an I/O module. At the age of 17, this would have been a big task for me at the time, so the factory-built tape recorder connectors intended for storing and loading programs remain. This gave us the answer to why my digitizing program was only 1-bit.

immagine

  • The soul of the program is the instruction IN A,($FE) that reads the tape recorder port, and the instruction OUT ($FF) that writes it.

  • The [R/P]LOOP2 loop processes the 8 consecutive bits one by one, producing 1 byte.

  • The [R/P]LOOP1 cycle starts according to the set HL register and repeats the above cycle until the closing memory address.

  • The sampling rate is performed by the LD B,$16 / DJNZ $FE microcycle. The value loaded into register B determines the sampling rate. This is not a specific value, just a ratio.

  • NOPs and instructions that do not affect the program are only there because of the already mentioned exact synchronization.

Unfortunately, the ZX81 uses the tape output together with the video output (ULA chip), so a normal picture is not visible while the program is running, we can only see the striping proportional to the sound change.

Closing remarks and download

Of course, today this program can only function as an interesting or educational example. Although, the program was not very useful at that time either, because it is useless for games, and for playing music... well, yes. 🙂

If you want to play with it, you can find it here. A minimum 16 kB RAM module is required.

immagine

Thank you for your attention!

If you liked my writing and you invite me for a coffee, you will encourage me to write more similar interesting things for you.

Ti piace questo post?

Offri un caffè a NICKMANN Studio

Altro da NICKMANN Studio