Are there any libraries, pieces of code or suchlike that'll let me play ZX Spectrum .ay files in my XNA Game Studio games?
ZX Spectrum AY-3-8912 playback in XNA Game Studio
676 views Asked by Piku AtThere are 3 answers
If you want to code it yourself you need:
Zilog Z80A CPU emulator
not that easy to do but there are some free C/C++ sources for it. I use my own.
3 channel AY 8910/8912 PSG chip emulator
this is much more simple then the CPU. it is just tone generator but the documentation is not very good for it so you need to experiment a lot.
1 Bit digital Speaker emulation
*.AY files do not always use AY-chip for sound output. Some games combine AY and Build In speaker. I am not sure now if AY also do have supprot for covox or not ... But if yes then you need to include also 8/16 bit mono/stereo covox usually on some i8255 chip.
keyboard emulation
variable HW architecture support
*.AY files store music for more architectures ... there are differences between Sharp, Amstard CPC, ZX48, ZX128, clones ... Some have different crystal frequencies, some have different channel mixing to reproductors, and also the IO addresses can differ not to mention memory paging issues.
Sound output
This is target platform dependent and as I do not use XNA will not touch this subject (as it is already answered/accepted)
The AY player looks like this:
- first load the AY header
- detect target platform and configure your emulator to match it
- load the AY binary to target memory zones
- set the registers and start the emulation
So if you want to code AY player you will end up with writing Z80 emulator as *.AY files are programs not sound recordings. As many AY files uses speaker then you will need to properly emulate the contention model otherwise timing issues will occur which can be heard especially on Speaker...
To improve quality you can apply FIR filters to simulate the PWM-like controlling of speaker which many effects use.
You should convert .ay files to wav first. There is a program here to do that. It also comes with source code so someone who have some free time might help by creating a content importer & processor from it? :-)
If you need sound in XNA, and want XBOX 360 support you need to use the supported file formats. You are properbly better of by trying to convert the .ay files to a format that XNA natively support.
If you only want to support Windows, then search for a .NET Library that can play them, it will work in XNA on windows if it works in .NET.