Blog

SoLoud on SpecNext

July 21st, 2024 (permalink)

I pushed a new update to the SoLoud repository a couple days ago, after years of absence. What I uploaded was a SoLoud console, with 8000+ lines of generated code. What it means that, if you have C code like..

SoLoud::Soloud soloud;
SoLoud::Wav sample;
soloud.init();
sample.load("pew_pew.wav");
soloud.play(sample);

..then, you can achieve the same through the console by:

SoLoud console 202002
Type "help" for help, "quit" to quit
♫> s soloud create
♫> w wav create
♫> 0 soloud init s
♫> 0 wav load w "pew_pew.wav"
♫> 0 soloud play s w

The console commands are parsed and sent through the 'c' api. The commands follow the format of destination variable, object, function, and zero to however many parameters are required.

Since it follows the 'c' api, the first parameter is typically a created object.

The console is super easy to crash. Just use a wrong handle as the object, for example. Everything is casted through a void pointer.

So what's the point? Well... the Spectrum Next has a Raspberry Pi Zero on it, which is not used for much. Early on I had the idea to just drop SoLoud in there, but it didn't feel right. I mean, when you have this retro-plus 8 bit machine, you don't expect it to play several mp3 streams through a reverb filter...

I've been requested to try it out nevertheless, so the first step was to ponder what kind of program it would be, and the console makes most sense.

Next up is the hurdle to compile it to the nextpi. As it happens, I went through a lot of that last year so I have most of the pieces.

What I didn't mention was the compile command line(s). Since it's been a while that would have been annoying to re-research.

I rebuilt the frankensteinian setup I used last time - Raspberry Pi Zero connected to an USB hub with a USB ethernet adapter which is connected to the laptop, raspi is also taking power from the laptop USB; raspi's mini-hdmi goes to a monitor and an USB keyboard is also connected to the hub so I can log in to the NextPi so it can tell me the IP address I can ssh to from the laptop. (After I know the IP I can take out about half of this config).

And looking at command history, I have this:

g++ nextgpio.cpp RtMidi.cpp nextpimidi.cpp -Os -lpthread -D__LINUX_ALSA__ -lasound -s

The console won't need GPIO. In fact, I want to leave the GPIO alone so audio output works. I also won't need RtMidi, for that matter, but I will need ALSA. Uh, which means I'll also need to plug in some USB audio device so I can test if this works at all without having to send the binary to the Next.

To prep, I gathered all the sources and headers I needed in a single directory (the ALSA sink, all audio sources, all headers, and the console sources). I scp'd these to the pi, and compiled:

g++ *.cpp *.c -Os -lpthread -D__LINUX_ALSA__ -lasound -s -DWITH_ALSA

The __LINUX_ALSA__ bit is probably just for RtMidi, but it doesn't hurt to have it there.

Executing this took a very long time. And failed due to some wrong include paths, which is not surprising given that I had flattened everything to a single directory. I had to edit a bunch of files to remove relative paths, after which it... failed when linking. I stubbed the openmpt calls (it's not like I was going to compile openmpt anyway) and to my surprise it built. To a 607204 byte binary. Which is rather huge, but then, there's a lot of stuff in there.

It also ran, but since I had not bothered to plug in an audio device I couldn't say if it plays or not at the time.

I then scp'd the binary out of the raspi, copied it over to my other PC on an usb stick (they're on different networks... don't ask), nextsynced the binary to the next, used .pisend to copy the binary over to the pi.

Next I hit .term and the following sequence:

SUP> chmod 777 nextpi-soloud
SUP> ./nextpi-soloud
Soloud console SOLOUD_VERSION
type "help" for help, "quit" to quit
> s soloud create
> 0 soloud init s
> p speech create
> p speech settext p "hello from spec next"
> 0 soloud play s p

soloud-nextpi.ogg

Audio through nextpi

Don't mind the noise floor.. I probably have a ground loop or two. Anyway, I did try a couple different audio sources and it seems to be working fine.

The nextpi-soloud binary I used can be downloaded here. For more info about SoLoud, point your browser this way, with the sources to it here on github.

I haven't stressed SoLoud on the zero, so I don't know how many mp3 files you can decode at the same time, but consider this: we're talking about decoding several mp3 files at the same time. On a retro platform. You now have great power, so handle it with great responsibility.

MMXXIV

July 21st, 2024 (permalink)

I think this must be a record for my late start of blogging in a year.

Let's start with the new year demo, released almost 8 months ago already..

What can I say.. the start of the year was pretty stressful, largely for reasons I'm not allowed to talk about. Since then, I've bicycled around 1000 km, and found that doing physical things helps with stress. It's just generally super boring. And you don't even lose weight. You just get hungrier. Cycling is not as boring, though, and I've learned a lot about my local surroundings as I've criss-crossed all sorts of paths.

One thing I haven't apparently mentioned in this blog (but you can see the links around), I set up a Ko-Fi shop. As a finn it's illegal for me to ask for donations (which also rules out stuff like kickstarter), but nothing stops me from selling services. At a quick glance what I'm offering may seem like a joke, but they're all serious offers, and in the past I've had (mostly) happy customers for every single item I'm listing.

The prices I'm listing are really low-balling the actual value. I'll adjust the prices if there's too much interest.

One update from a post from last year:

So I modded my 3d printer a bit. Only a bit. The Ikea Lack-table enclosure is the obvious bit, with LED strip lighting, concrete slab to reduce vibrations, two filament dryer/feeders on top, raspberry pi with OctoPrint somewhere below along with two buckets, one for PLA and other for PETG waste. Less obvious are a few smaller prints that do cable management and other tidyings-up.

I ran the printer basically nonstop for a couple of months, but now I only print when I have a need for something. Most of the early prints were for playing with the printer and/or modding it. The enclosure clearly lifts the temperature over ambient which may help with the print stability, but in all honestly the primary reason for it is to look nice.

As for look ahead.. I have a few ideas about what I want to blog about (that don't fit in a toot), and I have one rather experimental project for the ZX Spectrum Next cooking, so unless something happens, you should find a few more blog posts here this year.