so I wanted to make an audio file of a ZX Spectrum program today as part of a gag for an event annoucement.
step one. you need a compiler. thanks to
@boriel@mastodon.social, there is ZX Basic that just works. it's awesome. you just do ../zxbc.py -f tap -a --BASIC jingle.bas and that's it.
step two. you need an emulator. yay—I thought—retroarch has libretro-fuse that's even packaged for Alpine. it worked strange, displayed a lot of weird stuff and looked too compilcated. so I resorted to JSSpeccy3, which runs in a browser. it was okay, but I got tired of switching between the compiler and my browser, uploading the file, checking it out, etc.
I gave retroarch one more shot, spent some time researching why on earth the audio was not working, even though the retroarch menus had it. one strace later it became clear that libretro-fuse does not use retroarch's sound system, but the ALSA sequencer. okay, modprobe snd_seq, done. now i can iterate much faster, by compiling my program and loading it into the emulator with a single command. neat!
step three. you need a way to convert your tape image to an audio file. the original FUSE emulator (not to be confused with FUSE-the-filesystem-in-userspace-thing! damn it, google) contains some utilities, and among them there is tape2wav, which does exactly what you need. to get tape2wav you just need to compile libspectrum, then fuse-utils. sources are available for both, it's really almost as simple as: ./configure && make && doas make install. alas, tape2wav won't build without a warning, if your system's libaudiofile is broken. Alpine's package seem to be exactly this, so I had to check out the original source code, figure out the exact way to build the thing, since READMEs were updated almost never it seems, and, finally I've built everything and had my tape2wav working.
step four. you may want to check that your audio file can be loaded into a ZX emulator. I thought the audio2tape program from the same fuse-utils suite would do exactly that. alas, it does not support the turbo-encoded tapes that it's sibling tape2wav produces, and there's no way to turn the turbo encoding off in the latter. the retroarch's libretro-fuse won't load wav files either, it just ignores them. so I thought to give the original fuse a shot. after doing apk add gtk+2.0-dev and having some pleasant nostalgic flashbacks, it compiled successfully, and — finally — i got my wav played and loaded.
step five. you may want to make the audio file sound like a real tape recording. for this I went to my studio computer, loaded the wav in Logic Pro, applied my favourite tape emulation, some compression, normalized the volume et voila.
soon the announcement will go live, and I'll show you the results.
nothing much, but a deep dive nontheless.