Just realized I probably have made the amplitude too large for the PCM audio component in the above sample code. Would want to shift it up a couple of bits less (and sign extend) when aligning within the 32 bit word so as not to overdrive the output.
Of course this is possible to do. And I do think it's a very nice feature to add.
It won't be an AY-3-19010 though, so I will not include it in the official code.
Feel free to make a fork or hack or whatever you want to do!
Great, I am going to give it a try when I get a chance and see if it works and how it sounds. Thanks Ahle2.
Luckily I do not need true AY-3-8910 compliance as you can tell by the weird hacks I am planning here, but it should still make for a very handy sound engine with very low hub RAM usage once loaded. I like it.
So I soldered up a simple audio interface on my prop demo board and hacked about with the code today. I got some 8 bit WAV samples to play and mix in with the AY-3-8910 sound effects simultaneously and I am quite happy with the end result. Spin was not working quite right with a waitcnt (too slow) but worked okay once I added the extra output pin toggle at the sampling rate in the AY COG and got the spin code waiting on this before updating the sample.
In case anyone wants to do something similar, the code I provided above works okay, but it may be safer to also add these two sar instructions to reduce the modulation of the PCM source so as not to overload the accumulator with all four sources adding into it if that bothers you.
Also, to change the sampling rate to a value suitable for 44.1kHz and sub rate sources (I used 88.2kHz), you just need to change the following two parameters. This then keeps the AY waveform output thinking it has a 125kHz reference clock.
SAMPLE_RATE = [COLOR="#FF0000"]88_200 [/COLOR]' Sample rate of AYcog (125 kHz is maximum for an 80 Mhz propeller)
OSC_CORR = trunc([COLOR="#FF0000"]1.489 [/COLOR]* PSG_FREQ) ' Relative oscillator frequency
Yeah well I got it to go and I was able to mix in the PCM from an 8 bit wave file. Was a bit limited by the size of HUB ram so I was only able to put small snippets of low rate WAVs into memory so it wasn't a great test but I could hear it working. Now need to hack up some SD card interface to stream larger files from that for futher audio experiments.
But another thing I tried was to merge this in with Micah's S/PDIF object and see what happens when I play some demo AY music from your AYCog demonstration code digitally through the S/DPIF buffer to my amp. Even though I believe it is properly synchronized to the S/PDIF object at 44.1kHz it is sounding somewhat distorted when I feed it into my amp via TOSLINK (Logitech Z-5500D). I mostly hear it happen when two voices are playing the melody part simultaneously. Actually I quite liked some of the distortion effects it generated - parts of it sound a bit more like an electric guitar. :cool: It also doesn't seem to be as snappy to turn on/off sounds, I hear them almost bleed into one another. Single voice sounds okay as does Micah's test synth code here http://scanlime.org/2011/04/spdif-digital-audio-on-a-microcontroller/ . I checked the max modulation depth and it is 1/4 of the 16 bit range and I was not feeding any additional PCM sources - I'd reverted to original AYCog, so that should be fine. I'd checked the source was signed two's complement and I also shifted the samples down to a subset of the range and lowered playback volumes in the AYCog code and still didn't help. It also happens the same way when I slow down the music. What is weird is the existing analog outputs (which I still output too during playback) all sounds fine and that is all driven from the S/PDIF playback rate as well. So I am guessing it is sounding like this over the digital interface because of the rather harsh (square wave) modulation going straight into the amp's DAC without any low pass filtering unlike what probably happens on the analog inputs of my amp. Luckily I kept the volume down to be kind to the speakers. Once I get the SD card setup I want to try to playback a 16 bit wave directly to make sure my S/PDIF and amp setup are all good. Ultimately I want to be able to output both analog and digitally simultaneously if possible (just using 2 COGs, keeping 6 others free for video and my PS/2 interfaces). If the square waves sound harsh I might investigate other options (maybe sine table lookups). Once I get the digital interface up and running I could always generate better sounds that way from my external micro (think MOD files), but I would quite like to use the AYCog as well for a more retro sound.
So what exactly are you trying to achieve? External micro... mod playback.... retro sounds... video generation.... ps2 keyboard... This sounds interesting!
AYcog generates unsigned samples, so you will need to subtract 2^31 from the sample to convert it to signed.
Then it's very important that AYcog and the S/PDIF object are 100% synced and not 99.99999%. You will hear even the slightest diff.
Distortion fixed!! Was a stupid signed/unsigned error in the end. Once I subtracted 0x80000000 from the samples going to the SPDIF COG, the optical output now sounds just like the analog (but clearer). Excellent!
LOL, just read your last post after I wrote mine. Thanks anyway - you were indeed right. :thumb:
Well I am trying to put together a nice little retro platform just for fun to see what sort of performance I can achieve from the propeller for A/V. Right now on the propeller side I have a customized video driver working with 12 bit color and am adding audio to it as well as I/O devices. I guess a lot of people like using the prop standalone for these things but I am using it in a slightly different way as part of something else...more posts when I get further along.
One might be a little bit spoiled after using the SID 6581/8580(SIDcog) and thinking that all PSGs from the 80s are equally awesome.
A few things that you must know about the AY-3-8910 before continuing your endeavours:
* The envelope is nothing lika any envelope found anywhere else
* There's only ONE envelope shared amongst all channels
* You can't really have different "instruments" (without tricks) since the AY (normally) can only output pure square waves
* Most applications does not use the envelope because it is quirky and limited
* Most applications uses a software envelope instead (changing amplitude over time in sw)
* Some applications uses the envelope as an amplitude modulator to create waveforms other than square waves (not easy to do/understand, but VERY cool sounding results)
* You can apply noise to any square wave, but you have only got ONE shared noise generator
The AY-3-8910 is not even close to the SID when it comes to features and sound quality, but still some people managed to squeeze out pretty cool sounds with a lot of trickery. Have a listen to, http://www.youtube.com/watch?v=h5x1hWBexG8, it abuses the poor AY-3-8910 to the max. It sounds sooo cool.
While AYcog can emulate that tune pretty much perfectly, it still is hard (not impossible) to make a music play routine on the Propeller to achieve the same results.
Comments
It won't be an AY-3-19010 though, so I will not include it in the official code.
Feel free to make a fork or hack or whatever you want to do!
Luckily I do not need true AY-3-8910 compliance as you can tell by the weird hacks I am planning here, but it should still make for a very handy sound engine with very low hub RAM usage once loaded. I like it.
Cheers,
Roger.
In case anyone wants to do something similar, the code I provided above works okay, but it may be safer to also add these two sar instructions to reduce the modulation of the PCM source so as not to overload the accumulator with all four sources adding into it if that bothers you.
Also, to change the sampling rate to a value suitable for 44.1kHz and sub rate sources (I used 88.2kHz), you just need to change the following two parameters. This then keeps the AY waveform output thinking it has a 125kHz reference clock.
But another thing I tried was to merge this in with Micah's S/PDIF object and see what happens when I play some demo AY music from your AYCog demonstration code digitally through the S/DPIF buffer to my amp. Even though I believe it is properly synchronized to the S/PDIF object at 44.1kHz it is sounding somewhat distorted when I feed it into my amp via TOSLINK (Logitech Z-5500D). I mostly hear it happen when two voices are playing the melody part simultaneously. Actually I quite liked some of the distortion effects it generated - parts of it sound a bit more like an electric guitar. :cool: It also doesn't seem to be as snappy to turn on/off sounds, I hear them almost bleed into one another. Single voice sounds okay as does Micah's test synth code here http://scanlime.org/2011/04/spdif-digital-audio-on-a-microcontroller/ . I checked the max modulation depth and it is 1/4 of the 16 bit range and I was not feeding any additional PCM sources - I'd reverted to original AYCog, so that should be fine. I'd checked the source was signed two's complement and I also shifted the samples down to a subset of the range and lowered playback volumes in the AYCog code and still didn't help. It also happens the same way when I slow down the music. What is weird is the existing analog outputs (which I still output too during playback) all sounds fine and that is all driven from the S/PDIF playback rate as well. So I am guessing it is sounding like this over the digital interface because of the rather harsh (square wave) modulation going straight into the amp's DAC without any low pass filtering unlike what probably happens on the analog inputs of my amp. Luckily I kept the volume down to be kind to the speakers. Once I get the SD card setup I want to try to playback a 16 bit wave directly to make sure my S/PDIF and amp setup are all good. Ultimately I want to be able to output both analog and digitally simultaneously if possible (just using 2 COGs, keeping 6 others free for video and my PS/2 interfaces). If the square waves sound harsh I might investigate other options (maybe sine table lookups). Once I get the digital interface up and running I could always generate better sounds that way from my external micro (think MOD files), but I would quite like to use the AYCog as well for a more retro sound.
AYcog generates unsigned samples, so you will need to subtract 2^31 from the sample to convert it to signed.
Then it's very important that AYcog and the S/PDIF object are 100% synced and not 99.99999%. You will hear even the slightest diff.
/Johannes
Well I am trying to put together a nice little retro platform just for fun to see what sort of performance I can achieve from the propeller for A/V. Right now on the propeller side I have a customized video driver working with 12 bit color and am adding audio to it as well as I/O devices. I guess a lot of people like using the prop standalone for these things but I am using it in a slightly different way as part of something else...more posts when I get further along.
/Johannes
Could you post some examples of a few instruments using AYcog?
I'm having some trouble how to manipulate the envelope settings. A couple/three examples would be awesome.
Thanks
Jeff
A few things that you must know about the AY-3-8910 before continuing your endeavours:
* The envelope is nothing lika any envelope found anywhere else
* There's only ONE envelope shared amongst all channels
* You can't really have different "instruments" (without tricks) since the AY (normally) can only output pure square waves
* Most applications does not use the envelope because it is quirky and limited
* Most applications uses a software envelope instead (changing amplitude over time in sw)
* Some applications uses the envelope as an amplitude modulator to create waveforms other than square waves (not easy to do/understand, but VERY cool sounding results)
* You can apply noise to any square wave, but you have only got ONE shared noise generator
The AY-3-8910 is not even close to the SID when it comes to features and sound quality, but still some people managed to squeeze out pretty cool sounds with a lot of trickery. Have a listen to, http://www.youtube.com/watch?v=h5x1hWBexG8, it abuses the poor AY-3-8910 to the max. It sounds sooo cool.
While AYcog can emulate that tune pretty much perfectly, it still is hard (not impossible) to make a music play routine on the Propeller to achieve the same results.
Thanks for explaining why I was running into difficulty. AYcog just wasn't designed to do what I was trying to do. (Like the chip itself.)
Jeff