News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_e-dredon

Building an 8-Bit (emulated) PSG/FM Sound Expander

Started by e-dredon, 17:45, 23 June 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

e-dredon

Hi guys.

Fist of all, this is my first post here, I hope I won't break any board policy. If ever, please don't shoot the pianist ;p

IT's been a few months now I'm thinking on how to improve the audio capabilities of the Amstrad CPC. One of the biggest limitation of the machine in my point is the AY-3-8912 sound chip. I tried different software tricks to overcome the hardware limitations (SID voices is a great one but I had a short talk with Targhan. He doesn't show much motivation to implement this tech into Arkos Tracker as it's not really usable on machines without DMA. I'm talking from times to times with ZiK about DMA tracker for the CPC+. Few musicians like Cube! made wonderful chiptunes using MaxYMizer on the Atari-ST. I can't wait to put my hands on it :)
Then I discovered the PlayCity audio expansion. It sadly never really got popular even though it's supported by some emulators (Java CPC Desktop, ...) AND Arkos Tracker. The board is no longer produced (the cost would be below 10$ today). I suppose we can consider a 9 voices polyphony is a descent alternative to duty cycles, sine waveforms and filters.
Abalore and TotO will actually add a second AY chip in the cartridge version of Alcon 2020 (the Slapfight remake for Amstrad CPC classic). I love the idea. Some ATARI or Nintendo games cartridges actually expand the hardware of those gaming consoles. Sadly the cartridge port of the Amstrad CPC+ (GX-4000/6128+) are designed for ROM DATA storage only so we can't go this way for TNZS. It would require both a cartridge plus a dedicated piece of hardware on the 8bit parallel expansion port. The physical game edition would be horribly expensive.

So I think now that building a new audio expansion board with PlayCity compatibility, but that could go a bit beyond would be nice. YMZ-294 chips (pin compatible with the AY-3-8912) and those silly CPLDs are getting a bit difficult to source those days. Thus I'm a musician, not a skilful programmer. Dealing with CPLDs takes a lot of time as you need to make the software. :/ Also, sound chips like the SID became insanely expensive partly because the 8-bit music community loves it and this chip doesn't get really old nicely. That's why we saw some retrodev projects like SwinSID. They worked on a software emulation for the STM32 MCUs on a pin compatible board.

So I decided to start building something with the Espressif ESP-32 that I'm using for many other projects. It packs lots of CPU power that's just fine for Audio chips emulation. I was focused only on the AY emulation at the beginning as I wanted to work with Arkos Tracker. DefleMask actually supports multiples sound chips but the DMF module format is not well documented and probably not suitable for my project.

Wouldn't it be great if we had an 8-Bit audio expander that support those chips we love AND a better polyphony like some NES APU hardware add-on do ? Not only it would be designed for our beloved CPC machines but for other 8-bit computers as well.

May I introduce you to the Raptor 8-Bit Audio Expander Project. At first I did some experiments with the ESP as a standalone player (well got to start somewhere do we?), then I had to think about the connection with the computer. This is a where the USiFAC Serial Interface had me rethink the whole thing from scratch and do a MAJOR update to my initial design.

Using the Parallel 8-bit interface or a Serial interface on top both have pros and cons :

Pros:
The expander is much more versatile and could be used in combination with many different retro computers (ZX spectrum, Amstrad CPC classic/+, Thomson TO, Accorn BBC, ...).
Cons:
As far as I understood, the USiFAC / Expander design would need a bit more CPU resources. Streaming PCM Sound directly to the emulated AY is not only a bit awkward, it would be really tricky even the serial BUS can transmit data in theory much faster the default 115200bps (it can go up to 915000bps). PCM sound would have to be sent to the ESP PS-RAM first then played. Might sound a bit like cheating to some hardware conservatives...

I didn't want to open a talk here before I knew a bit better where I was going.
Here are the current specifications of the hardware I'm working on (mostly an AI-Thinker audio DevKit with a small customization)

Built-in and add-on parts :
ESP32-A1S ESP32 module with a built-in AC101 I2S audio codec, onboard 8Mbit of PS-RAM
1x Micro SD card reader (up to 64GB)
1x CP2102 USB to TTL
2x Micro USB connectors (1 DATA communication port and 1 charging port)
1x JST connector for LiPO batteries 3,7v
1x TP4056 LiPO charge controller (supports up to 1Amp but is set to 500mA only on the board)
1x Line In (Jack routed to the AC101 audio codec)
2x analog microphones (routed to the AC101 audio codec)
2x NS4150 audio amplifiers
2x JST speaker ports (can be converted to RCA or a more fancy autolock speaker wire socket)
1x Line out (Jack) up to 4Ω 3W for headsets or speakers
1x JTAG Port (clocked @ 20Mhz)
0,98" OLED white monochrome 128x64 I2C display (SSD1306).
6 control buttons (compatible with standard keycaps) + 2 system buttons

Target Features list :
- Line In : Can be used as a digitizer up to 24-bit @ 44.1Khz stereo
- Line-in pass-through mode. Connect the line out audio jack of your CPC, set the volume rocker to the minimum and enjoy the mix of the internal AY and the expander emulated audio chips
- The interface allows to set your own BT device ID.
- Connect it to a retro computer through a high speed serial interface.
- Built-in support for the Amstrad CPC - USiFAC (Serial Interface)
- Connect the expander to any modern computer with USB and use it over the serial interface (Arkos Tracker 2.0.0.a8 new feature).
- USB-MIDI mode. Use the expander as an 8-Bit 16 channels synthesizer for live performances.
- Mix different audio chips at the same time
- Setup the device with the Functions key and the display.
- Enjoy some basic DSP sound processing and a FFT (real time frequency analyzer).
- Firmware OTA updates

Supported audio chips :
1, Emulated PSG
- AY-3-891x @ 1Mhz (CPC) 3Mhz (ZX Spectrum), YM-2149F (Atari-ST)
- SID 6581 / 8580 (C64/128/D)
- NES APU with N163, VRC6/7
- Pokey (Atari XL)
2, Emulated PSG/FM chips
- YM2612 (Megadrive)
- YM2151 (Arcade, X68000, ...)
- FME-7 extensions for the NES APU (I don't have the proper code yet)

What currently works :
- AD2P/APT-X low latency (about 12ms) audio stream to Bluetooth 4,1+ receivers/headsets/speakers
- 1 emulated AY audio chip on core 0 or 1
- 1 emulated SID 8580 or 6581 on core 0

What's not supported yet but on serious WIP at the moment :
- USB-MIDI device : connect your Raptor to a MIDI keyboard through the USB-midi interface to your master keyboard with no additional USB-MIDI adapter.

Known issues & limitations :
- It took me some time to find the right hexport that had to be initialized to enable the Line-In and set it to pass through mode. The doc is quite unclear. Sadly Line-in / pass through OR JTAG, you need to make a choice [EDIT] (use DIP SWITCH N°4-5)[/EDIT]. So it won't be possible to mix the audio from the CPC line out with the Raptor audio output when used as a serial device as I was planing to abuse the JTAG @ 20Mhz to use it as a high speed serial interface with the USiFAC. Thus I had some issues communicating over 10Mhz with my JTAG noname programmer (I also own an official ST-Link but it's locked to ST-Microelectronics devices only). I don't know if it's an ESP-IDF bug or if my JTAG programmer is not happy with custom baud rates.
I can still use the RX/TX serial interface of the ESP-32, but I will be stuck to 115200bps. I need to check if it would be fast enough to stream the 2 two YM registers from the CPC (PlayCity compatibility mode). It surely wouldn't be enough for an hybrid mode (SID/AY or AY/NES APU etc...) as SID dumps usually takes A LOT OF DATA.
- When using the JTAG port with with the USiFAC, connect only TX, RX and GND, BEWARE you don't connect the +5V from the CPC. The board fully operates at +3,3V (power supply and signals. You would get some instant magick smoke,
- SID 8580/6581 on core 1 randomly hangs the ESP core. It might be an interrupt issue
- Using a Bluetooth headset/speaker while the device is in MIDI-USB mode for live performances, is no way... 25ms + 2x10ms of delay already ruins the whole thing and there are few other source of delay to consider. A very good article describes the problem here: http://www.jonnor.com/2017/04/optimizing-arduino-midi-controller-latency/. I'll dig it further later.

Next hardware upgrades WIP
- The micro USB that is routed to the CP2102 and ESP32 will be replaced with an USB-C connector
- Overcharge protection ICs will be added to the TP4056 charging circuit.
- The NS4150 class D mono amplifiers might be replaced by the much better PAM8610 Stereo Class D amplifier (2x15W) with overload/overheat protection. No need to go crazy with a TPA3110 like 30W amplifier (keep in mind the device can be powered with a LiPO battery)
The 5 function micro switch will be re-arranged into a matrix with different values resistors to save few I/O on the ESP-32. Two of the buttons will be replaced by a rotary encoder with click button or a 3D analog thumb stick (like on the SONY PSP) to make navigation in the UI much easier and faster
The Raptor 8-Bit Audio Expander is not meant to display lots of stuff at the moment. But ,96" is really small for me. The SSD1306 might be upgraded with a SH1106 1,3" OLED display. I'd like to keep some I/O for other features rather than a 320x200 SPI ILI9341 2,8" or 3,5" fat boy (eventually 16 chained WS2812/APA102 RGB LEDS to display the activity on each of the 16 channels.

Side notes :
I wanted to switch the AC101 for a better audio codec at first (I previously used a PCM5102 DAC, then an ES8374 as this audio codec also has a line-in and is supported by the official ESP-ADF without any driver patch like for the AC101) so I could keep up with the latest version of the ESP-ADF, but it came that the AC101 is actually quite good.
Thanks to the Espressif ESP-IDF / ESP-ADF framework Espressif ToolChain / Eclipse IDE, I finally got rid of this @!# Arduino IDE but I'd like to use some Arduino libraries (DSP/FFT analyser, USB-MIDI, RealTimeClock, etc...). it seems there is a way to do it.


Before I'll sink in a lot of code and spend the very little amount of free time I have on this project for the next 2 years, I'd like to know if you would be interested with the concept as an end user, or retro game developer, musician, ...
As I already said on my introduction post after I registered on this board I'm a terrible programmer. A actually use some opensource software and the Ai Thinker is based on the Espressif Open Hardware design, and will remain as is. This is a fan project, not a commercial one.

Sorry for this very long post and thanks to the braves who did read everything ;)

Cheers,

TotO

Hello !

Using expansion on CPC was not something natural. When I made the demonstration about the CTC-AY in 2013 at the ReSeT #10 event, I think that peoples was shared about the interest to have game cartridges, programmable raster interruptions and extra audio channels... So, without software (except the demo), no hardware. :)

Minds change and peoples have started since one or two years to considerate expansions like ROM or PlayCity into their développements. Thank you about Arkos Tracker 2 that can comfort developers in this way... Taking account about extra "AY" channels to be able to play at less Music & Sfx without denaturing how sound the CPC.

Contrary to what you have said, there is no sourcing problem to got those parts (LambdaMikel said me that three years ago too), they are enough cheap and finally does the job. So yes, it is a simple solution for Alcon 2020 to offer "fromage et désert" without the aspect "usine à gaz" as you can understand.

If your goal is to offer a board to replay music from others computer, it is funny but I can already do that on my PC or with a Pi.
Those all-in-one projects always make me skeptical because we don't really know what is the expansion of what... The board or the CPC?

By the way, it is an interesting project (I love the 80/90s music audio chips), like the LambdaSpeak project was too. So have fun with it!
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

VintageAdvantage

#2
Love the idea, and second what ToTO said. Let me add my perspective:

       
  • CPC community is not very open to anything else than AY
  • LambdaSpeak (Amdrum and HiQuality PCM Player) was sold ~ 30 copies
  • Speak&SID (SID for the CPC) was sold ~ 15 copies
  • PlayCity was sold > 100+ copies
  • LOVE the YM sound, and would be great to have it on the CPC!
  • Firmware for such a mega multi soundchip emulation project will probably be quite a nightmare, good luck with that!
  • Getting people to use / write software for it other than you might be challenging, too
  • If you get people like Arkos Tracker developers then this solves the problem
  • Still, some people will say the don't care for better PCM or sound, they only want AY and 4-bit AY PCM... so that is that  ;)
  • Mostly, it matters WHO is building, not WHAT is being built in CPC community
  • PlayCity shows you can have a hugely successful project if you position it right, and make the right community connections. This is key to any hardware project for CPC.
Anyhow, would love to see this project, good luck!!

VintageAdvantage

#3
QuoteWhat currently works :
- AD2P-APT-X low latency (about 12ms) audio stream to Bluetooth 4,1+ receivers/headsets/speakers
- 1 emulated AY audio chip on core 0 or 1
- 1 emulated SID 8580 or 6581 on core 0
Would LOVE to see a demo of this. YouTube video? Is this SwinSID? Can you share a link to the sources? What are you using for AY-3-8910(2) ? One of the Github projects?



TotO

I like the music you made on AT2 ! (may be Link's Awakening was played a bit too slow)
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Gryzor

Would love one even if very few games supported it... sounds lovely, but also quite complex and challenging!

How are you going to use the SSD1306 on it?

abalore

Quote from: VintageAdvantage on 01:02, 24 June 20

       
  • Mostly, it matters WHO is building, not WHAT is being built in CPC community
That is not what I perceive in the community. I first reached this forum when I developed M4FE, not long ago, and later to announce Alcon2020, and both projects had a great reception. M4FE is widely used by M4 board owners and Alcon2020 seems to generate some expectation. Maybe the interest of the projects is a key parameter. That's something hard to evaluate by the project's creator, because obviously for you the interest is high, but maybe your enthusiasm is not shared by anyone else.

Gryzor

Yeah, that comment was way off base I think. Many people have arrived at the scene and built something, and people rushed to support them even though they didn't know these persons before. Way off base.

TotO

I have not seen the edit on his post... Sure, I agree with you. As previously explain, my original project failed because peoples was not interrested, that all. I have listen them and adapted my work on CPC expansions for their needs.
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

e-dredon

Quote from: VintageAdvantage on 02:44, 24 June 20
Would LOVE to see a demo of this. YouTube video? Is this SwinSID? Can you share a link to the sources? What are you using for AY-3-8910(2) ? One of the Github projects?

Hello.
Well... Thanks for sharing your personal experience and sales DATA. The Speak&SID / Sonique Sound Board actually inspired me when I started to think about a solution to my AY frustrations ;) That being said, you might have misunderstood a few things :

The Raptor is not a fork of the SwinSID code. For now I'm using LibSID directly inherited from SwinSID, I previously tried a ReSID port for STM32/Teensy MCUs, but every code snippets I've seen so far only replay SID register dumps (.dmp). This method uses significantly less CPU than LibSID as you don't need to emulate the 6502 as well but it's not gonna work well in my case as I'd like to use the emulated chips as a midi synthesizer. I think LibSID is more what I'm looking for.

This project is a personal challenge. I don't currently have a funding campaign, and no one I should justify myself to.
I opened this discussion as a preliminary talk to the further developments I will do if I can feel that people are really interested and might even contribute. I think the post is clear enough. I don't get what made you think I'm close to a release. So the repository will come on time when I have something relevant to show. I already spent lots of time to make the songs with Arkos Tracker. It was a part of my learning process with Arkos Tracker 2. Targhan has been very kind and nice with me since we started to talk and didn't flame me with my super n00bish questions. He got some of my .AKS

Talking with enthusiastic and/or sceptical is fine. But as I already said, I have only little free time to work on personal projects, so I guess you can understand I'm not willing to waste some with rude and toxic talks that just ruins one's motivation. If no one likes it, then it's fine, I'll just go my way alone and probably never talk about this project again in public.

And about my post edits. I'm visually impaired. I'm editing posts usually to correct misspellings or rephrase something that looks unclear when I'm reading it again after posting. And it's been a while I didn't have to deal with bbcode, sorry ;) I added photos of the custom Ai Thinker-A1S. The genuine board cost around 12$ (I can down to 6$ with batch purchases). The custom board was ordered from JLCPCB. I wanted to test their pick'n'place bot. It took 3 shipping to get it to work properly. With the black 2 layers PCB everything placed except the A1S and the through hole (pin headers, microphones and JST connectors) the total cost is about 18$ ;)

Code references :
AY-3-8910 Emulator for ARM
https://github.com/ESPboy-edu/ESPboy_PT3Play
ay_emu.h

SID Emulator for ESP32
https://github.com/possan/csid-esp32/tree/master/main
LibSid.h

NES/POKEY sound chips emulators are from this projects. I didn't take a look yet at the SMS
https://github.com/rossumur/esp_8_bit


NES ApU with VRC6/7/N166 extensions
nofrendo (nes/famicom)
mmc5_snd.h
mmc5_snd.c
fds_snd.c
fds_snd.h
vrcvisnd.h
vrcvisnd.c

Pokey Sound Chip Emulator
Atari800XL emulator
libatari800_sound.c
libatari800_sound.h
pokey.c
pokey.h
pokeysnd.c
pokeysnd.h

The YM2151 is from MAME
https://github.com/mamedev/mame/tree/master/src/devices/sound
ym2151.cpp
ym2151.h
ym2151.txt

Regards,

VintageAdvantage


eto

I didn't see this post earlier... I love the idea!    Where can I buy it? ;-)

Especially an add-on which is optional is great. If I understand correctly, the YM would still be usable, so games could use it for e.g. sound effects and use the add-on for some great in game music or additional/other effects. As long as an extension doesn't change the soul of the CPC, why not adding new features - and it's called extension bus for a reason ;-)

One thing to consider would be, that the extension needs to also be supported by emulators. I wouldn't start developing on real hardware any more.

Powered by SMFPacks Menu Editor Mod