Login
Back to forumReply to this topicGo to last reply

Posted By

SukkoPera
on 2023-11-16
02:29:40
 SoundX - An AdLib card on your C16/+4!

Here's finally the last audio thing I've been working on: it's an adaptation of the C64 SFX Sound Expander for the x264 series.

While it didn't enjoy much success when it was released on the C64, since it was not that much superior to the built-in SID (if superior at all...), it would have certainly been muuuuch more successful if it had been targeted at our beloved machines. In fact, it is basically the equivalent of an AdLib card, an audio board for the PCs of the time, based on the YM3526 chip from Yamaha (also known as OPL), which is exponentially better than the TED as a sound chip, with the following features (thanks Wikipedia):

9 channels of sound, each made of two oscillators or 6 channels with 5 percussion instruments

For the whole channel:
Main frequency (10 bits)
Octave (3 bits)
Note on/off
Synthesis mode (FM or just additive)
Feedback (0–7, the modulator modulating itself)

For each one of the two oscillators:
Frequency multiply (can be set to 1⁄2, 1 to 10, 12 or 15)
Waveform (Sine)
Volume (0–63, logarithmic)
Attack, decay, sustain, release (4 bits each, logarithmic)
Tremolo (on or off)
Vibrato (on or off)
Sustain (on or off)
Envelope scaling per key (on or off)
Volume scaling per key (0–3)

There are also a few parameters that can be set for the whole chip:
Vibrato depth
Tremolo depth
Percussion mode (uses 3 channels to provide 5 percussion sounds)
Composite sine mode (see Sinewave synthesis)

The board can even use the slightly more modern YM3812 (OPL-II): among its newly-added features is the ability to pick between four waveforms for each individual oscillator. In addition to the original sine wave, three modified waveforms can be produced: half-sine waves (where the negative part of the sine is muted), absolute-sine waves (where the negative part is inverted), and pseudo-sawtooth waves (quarter sine waves upward only with silent sections in between).

While this is all very interesting, the original board could be bought together with a piano-like keyboard and some demo software. Such keyboard is not easy to find these days, so it was pointless to replicate the interface for it and I rather decided to build upon my experience with the Plus4MIDI project from Chizman, by adding a real MIDI I/O interface. This means the +4 will be able to receive data from a General MIDI keyboard or to play it, through a standard DIN-5 MIDI interface.

This all makes sense because the YM3812 chip, its companion DAC (YM3014B) and a standard ACIA chip (for the MIDI part) can all be bought supercheap on AliExpress & similar sites, making this board very affordable to build for everyone. Let's say 15-20€?

On the programming side I diverged a bit from the SFX Sound Expander and rather followed the AdLib style: the board only uses two addresses for the audio part: $FDE4 and $FDE5. The former is for writing the number of the YM register to be modified while the latter is for the value. The former address can also be read and it will return the YM status register, which is only useful for the detection of the board or if you want to make use of the YM internal timers. BTW, any AdLib tutorials (like this one) should be 100% applicable to this board just as well, except for the addresses. The MIDI section is handled through a classic ACIA (6551) chip, occupying addresses $FDE0/1/2/3 (these are partly used by Solder's MIDI interface, that's why I chose them). Addresses can still be changed if someone convinces me to happy.

Now, it should be apparent that no software for this card exists yet, so how could I test it? Master @Csabo supported me and quickly hacked together a tech demo which plays a few songs from the original AdLib Card Demo:



He also wrote a MIDI decoder that allows "playing the TED" through a General MIDI keyboard:



To test the MIDI output, I hacked Chizman's MIDI OUT stuff so that it would play through this board:



(Please ignore the Plus4MIDI board you see in the videos, it is only acting as Classic MIDI <-> MIDI over USB converter.)

So thanks a lot to Master Csabo and Chizman (unbeknownst) for the help! Also thanks to kinmami for help with the HW design.

Of course, to make complete sense, this project needs support from the actual programmers! So people, please make games for the board! Or programs, demos, whatever! I think a nice first step would be to port the original SFX Sounds Expander software: I can't say for sure, but I'm guessing this shouldn't be too much of an effort, plus I can help with the tech details and can explain how to make the MIDI decoder. Csabo will also release his programs together with the sources, which means a good part is already made!

As usual, I will make the full project public ASAP and will also offer PCBs to anybody who wants one, just ask!

So who's volunteering? wink



Posted By

George
on 2023-11-16
07:59:16
 Re: SoundX - An AdLib card on your C16/+4!

Really fascinating stuff! Adlib with Midi like an Atari St. Impressive demos!
Congrats to the team.

Maybe this will become a standard on the plus/4 because components are easy and cheap to get.

If you also add a cheap 3d/2d accelarator solution maybe with hardware sprites on the board, that could be a reference hardware expansion board for future game projects.

Posted By

BSZ
on 2023-11-16
09:14:03
 Re: SoundX - An AdLib card on your C16/+4!

Hm... Interesting project! happy

Important info: I really like the sound of OPL(2)! happy

Unfortunately, it was often bad used in the past for PC use. It was typically used to play MIDI, not in very good quality. Because of this, users have bad memories of the AdLib sound card. But the musics made especially for it sounds very good! I used to plan to make one for plus/4, but just for fun. I didn't think of it as a product, for the following reasons:

- The chip has more than 200 (!) registers! As you write above, these can be set through a "hole". Before writing each register, the register number must be set separately.
- The chip is "slow". Wait a while after setting the register number, then wait again after setting the register value. While these times are not very long (~3-4 µSec + ~24 µSec), they are still very noticeable even at CBM CPU speeds.
- Playing a single sound means setting about 10 registers. This is compounded by the above waits.

Don't have to update all registers every time, but it still takes a lot of CPU time to play any complex music. In my opinion, I can think of using OPL(2) (in an 8-bit environment) is to have a dedicated (co-)processor to handle the chip. (This is typically how it was done in the past.) However, this makes the hardware overly complicated. happy I think that's one of the reasons why OPL didn't become a huge success on C64 either. (Or is it? grin )

I still think so: You can make music programs, but using this chip in games/demos is not very rewarding: it takes CPU time away from effects/other tasks. Regardless, I'm curious what other people think about this! As I said at the beginning, I really like the sound of the OPL2, maybe it will spark the imagination of some people here. grin

Edit: For those of you who don't know what the AdLib sounds like:

Shelter - The author is unknown for me, does anyone recognise him?
En Lille Test - MSK / Vibrants
The Alibi - JCH / Vibrants
Gone... - JCH / Vibrants

If there is familiar music among them, it is no coincidence! grin


Posted By

SukkoPera
on 2023-11-16
12:53:07
 Re: SoundX - An AdLib card on your C16/+4!

Well, this is not a "product", in the sense that it is not something I plan to sell to make me rich. It will be just another open project that anyone can build on their own. It's one more weapon for x264 musicians that I just hope gets widely adopted as it's cheap to make and it sounds muuuuch better than the TED. It's also not a SID (even though I think I've seen a sort of "SID emulator" somewhere) which feels somewhat out of place on x264 machines. The YM never got too popular on the C64 or on other 8-bit computers, so it could be "our thing"!

It's true that the YM has a lot of registers (254, I think) but that is because it supports 9 channels, so most registers are replicated per each channel. Of course there is no need to use all the channels, the chip already sounds great with just a few voices happy.

I think you only need to setup 10 registers at the beginning, then you should be able to keep making sounds by changing just a few every frame.

It's also true that the chip is slow (one should wait 3.3 ms after every "register number" write and 23ms after every "register value" write). Someone made some tests to check if these could be reduced and if I understand correctly, some clever programming could reduce the impact of such delays, since the C64 (which they used) is not a superfast machine to start with (so it takes time to execute its instructions, you don't necessarily have to waste time through NOPs).

It sure will require some smart programming techniques, but if no-one tries, no-one will find the final answer happy.

Posted By

MMS
on 2023-11-16
17:34:37
 Re: SoundX - An AdLib card on your C16/+4!

Wow, the next great project, I really like it!

Well, adding aMIDI out port makes this my favourite card... Adlib had a very nice and distincive sound, if programmed well.
https://www.youtube.com/watch?v=ylOlyd7c_tQ

You may know I have a theory, that C64 Sound Expander originally created for Plus/4, but due to it's problems on the market they modified the Expander to fit to the C64. Just watch out the charcoal black housing! It had no sense on C64, but would have been a great success on Plus/4, especially with the Sound in/out signals on Memory expansion (it requires an additional cable on C64 to mix it to the C64 SID audio). I suppose those musics on my link have their own format we can also play...

The MIDI out feature: it is visible that the 6551 JUST able to follow the MIDI speed, and with more than 10 channles it slows donw, but that's OK, it is just 19.2kBaud. It sounds great, and only with 4-6 channels and Yamaha XG it could be perfect. I just need a little more money to realize those ideas grin

Anyhow, I am in. I will order this PCB as soon as available on PCBWay (as I remember your usual way, I like them). How to program the OPL/OPL2... Frankly speaking, even Hermit's TED music editor is too complex for me grin

Posted By

SukkoPera
on 2023-11-16
18:22:33
 Re: SoundX - An AdLib card on your C16/+4!

Nope, the MIDI interface on this board is standard, 31250 bps. It's only the demo program that was written for 19200, I only hacked it to change the addresses and thus it still "stutters", but now it could be rewritten to take advantage of the full speed. The Plus4MIDI board in the video is acting as a standard MIDI converter, only relaying messages between two standard interfaces. If I had a MIDI keyboard with the DIN-5 connector I could have connected it straight to the board, but unfortunately I don't have it (here grin).

"My usual way" also includes releasing the full design files and offering boards, I'll be happy to send some over happy.

Posted By

Frenetic
on 2023-11-18
05:47:45
 Re: SoundX - An AdLib card on your C16/+4!

Great work!

Let me just add that there is already Adlib/OPL sound for the C16/Plus/4 since quite some time: the Sidekick264 provides one wink

However, the addresses are $FDE2 etc (I ported a simple Adlib-player as an example). Maybe it makes sense to make the addresses between the two coherent?

Posted By

SukkoPera
on 2023-11-19
08:23:14
 Re: SoundX - An AdLib card on your C16/+4!

Wow, I didn't know the SideKick also had this feature! Guess it would have saved me some work! angel

Yes, of course we'd better decide on a single address, and it would be great if OPL support was also included in YAPE and/or VICE at that same address. @Gaia, got any plans for the Christmas holidays? grin

I initially used $FDE2 too, as Solder's I/O Map indicated $FDE0/1 were used by his MIDI interface and I was planning to use the same addresses for my MIDI implementation, so having the OPL next to those was an obvious choice. But I had overlooked the fact that the ACIA has four registers and thus it needs 4 addresses, so I moved the OPL forward.

The easy solutions I see are:
1. I move the OPL back to $FDE2/3 and the MIDI to 4/5/6/7, which could make sense because my MIDI implementation is now clearly not the same as Solder's (which only required two addresses, unfortunately nobody seems to own this interface these days).
2. You move the OPL to $FDE4/5.

Since there's basically no software around that uses the OPL (yet! wink), I think both solutions are feasible, it's up to us to choose. Let me know your opinion happy.

Posted By

Frenetic
on 2023-11-19
10:50:53
 Re: SoundX - An AdLib card on your C16/+4!

Yes, I need to talk to my advertising department wink

Theoretically I'd only have to change this single line of code: "cfgEmulateOPL2 = 0xfde2;" wink (plus recompile the included example program)

If you have a few days, I'd make sure that what I said above is true and check -- but first I'd need to set up my C16 again happy

Posted By

MMS
on 2023-11-19
11:38:07
 Re: SoundX - An AdLib card on your C16/+4!

@Sukkopera: sorry to misunderstood the symptoms, it sounded like a 19.2kBaud MIDI implementation happy Sorry I was wrong. I knew that the 6551 could work on a higher speed with the help of faster external clock crystal, but I did not expect such a good solution happy

@Frenetic : one and half year ago I planned to buy the SideKick just because of this feature, but at that time it was not possible to buy the required Raspberry from the local shops. I learned there was a major chip crysis. Without Raspberry it was no use to order the Sidekick, and after that a lot of things changed in my life and I lost major capital in crypto business too sad rest is history, hopefully soon I will recover from all these issues.

Posted By

SukkoPera
on 2023-12-23
06:16:34
 Re: SoundX - An AdLib card on your C16/+4!

@MMS: No worries, I should have pointed it out from the beginning. And anyway you are right, the demo is still written for 19200 bps but data is actually moving faster, that's why I have the scope in the video: you can't see it, but it's decoding the serial data and that's the proof that the communication is happening at 31250 bps.

@Frenetic: OK, but I think we also need to make sure that we use the same addresses in the same way happy. In my case:
- Writing to $FDE4 -> Register number
- Writing to $FDE5 -> Register value
- Reading $FDE4 -> Returns status byte

In particular, you might be using $FDE6 (currently $FDE4 for you) for the status read, if you followed the SFX Sound Expander decoding scheme. I think we can avoid wasting one address happy.

UPDATE 23/12
I must admit that I was expecting a bit more enthusiasm about this project, but anyway... It has now been released.

Thanks a lot to @Csabo for his help.

Enjoy, and Merry Christmas!

Posted By

MMS
on 2023-12-23
07:30:05
 Re: SoundX - An AdLib card on your C16/+4!

@Sukkopera: the enthusiasm is here, but winter (= Christmas + presents) is coming, not to mention my other PCBWay orders happy

I will be definitely one of the owners in the near future, thank you for your great work.
It is wonderful, that we could have the OPL music (and even MIDI out!) that defined the music of the PC gaming for a decade.

Posted By

SukkoPera
on 2023-12-23
13:39:18
 Re: SoundX - An AdLib card on your C16/+4!

Yep, I'll send you one of these, too. You'd better start looking for a YM3812,YM3014B and 6551 on AliExpress wink.

Posted By

MMS
on 2023-12-23
15:59:44
 Re: SoundX - An AdLib card on your C16/+4!

@Sukkopera you are very kind! Thank you for the hint, I will start to check them.

BTW I recently saw some very nice "smart" soldering iron TS100 on PCBWay, considering to buy one instead of my ancient Weller, as I cannot prevent to test my soldering skills happy

Posted By

SukkoPera
on 2023-12-23
16:12:54
 Re: SoundX - An AdLib card on your C16/+4!

I'm pretty sure any Weller, even an old one, is better than any modern Chinese stuff.

You don't need any fancy tools, easy soldering is always one of my design goals. As long as it has a decent tip (not a particularly small one) and it can reach 330-350°C, it's more than enough (hint: use leaded solder). I do 99.999% of my soldering (yes, even SMD stuff down to 0603) with the original tip that came with my Hakko.

Posted By

MMS
on 2023-12-23
16:30:06
 Re: SoundX - An AdLib card on your C16/+4!

Thanks for the hint. So before any further investment I will try my old stuff.

I agree with you, my last soldering experience was with lead-free, and it was pretty hard to create a good contact.
So last time I ordered again leaded soldering wire, but I had no chance to try it out (yet).



Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2024