Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Homebrew ROM showing PCM with 2 squares

Reply to topic
Author Message
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Homebrew ROM showing PCM with 2 squares
Post Posted: Sat Sep 12, 2009 5:26 pm
I spent a few hours tonight putting together a small (no pun intended) ROM which tries to output some 16000hz wave files. It works fairly well, except for some "noise" I am finding hard to get rid of, likely related to the non linear distribution of the SMS channels. . It uses two square channels and some preprocessing to get it into a SMS format that is adequate. 3 Squares might help get rid of some of the noise, but I found that small delays between each square channel adds its own distortions.

Scott from SMS Power Radio did the intro for it.
retrobilly.zip (348.3 KB)

  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14982
  • Location: London
Reply with quote
Post Posted: Sun Sep 13, 2009 7:53 am
Are you using different values on the two channels to get better fidelity? Unfortunately there's still lousy coverage at the bottom of the wave.

Are you filtering out frequencies above 16kHz to avoid aliasing? (Resampling in a good wave editor ought to do that.) Are you normalising to 100% (or more)? Are you applying a compression filter? These might make it sound better. There's a lot of theory to learn about sound processing, I think; I know little enough to know how little I know.

Is it supposed glitch out before looping?
  View user's profile Send private message Visit poster's website
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Post Posted: Sun Sep 13, 2009 8:26 am
Maxim wrote
Are you using different values on the two channels to get better fidelity? Unfortunately there's still lousy coverage at the bottom of the wave.

Are you filtering out frequencies above 16kHz to avoid aliasing? (Resampling in a good wave editor ought to do that.) Are you normalising to 100% (or more)? Are you applying a compression filter? These might make it sound better. There's a lot of theory to learn about sound processing, I think; I know little enough to know how little I know.

Is it supposed glitch out before looping?


Yeah I'm using cooledit, so it's fairly good at resampling. The 16000hz wave it produces sounds very nice, at least compared to my demo. Although it does sound better in RetroCopy likely because I used the same amplifications (taken from your doc). There is probably a bug somewhere causing the majority of the noise.

Soon I'll have my testing environment for the real system so it will be easier to determine a few things from it. And yeah there is a glitch when it loops, it's basically outputting the code before it loops back to the sound.

I was thinking of emulating a hardware device which allows sample playback on one or two channels by using BUSREQ to hold the Z80 off the bus for 6 cycles or so every ~160 cycles. This way you wouldn't have to chain the CPU to the PSG and could have sampled music or sound effects in games. It's a fairly cheap way of improving the output whilst leaving the majority of the CPU to do game tasks. It's also more efficient to use only 6 cycles or so to do it compared to 24 at the minimum.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14982
  • Location: London
Reply with quote
Post Posted: Sun Sep 13, 2009 10:54 am
How do you get the samples into the device? Will addressing the PSG at its maximum rate confuse it? Why not wire in a SPC from a SNES, for example, and a mixer for the output?

If you're using both channels to get interpolated values then you may switch, for example, from 15+1 to 8+8 (made-up example) and you have to go through either 15+8 or 8+1 in the middle, albeit not for long. That'd give you a noise problem if it wasn't fast enough to be filtered. Avoiding this might be tricky.

Does it sound better with one channel?
  View user's profile Send private message Visit poster's website
  • Joined: 26 Aug 2008
  • Posts: 292
  • Location: Australia
Reply with quote
Post Posted: Sun Sep 13, 2009 1:33 pm
Maxim wrote
How do you get the samples into the device? Will addressing the PSG at its maximum rate confuse it? Why not wire in a SPC from a SNES, for example, and a mixer for the output?


Because if you go too extreme it's no longer the SMS. The way I see any hardware addon at this point is it's valid if it helps to extend the existing capabilities. Because we have the "power of god" so to speak to put a device a 1000 times better than the Z80 on the SMS these days doesn't necessarily mean it's good.

A way to hold the Z80 busreq and forcefeed the existing PSG seems to me like a good way to fully utilize the existing hardware and would be a fairly simple addon to do. Same with the VDP eventually but that is a bit more complicated, the PSG device just needs to output at regular intervals with a single byte for each channel.

It would simply read values from cartridge areas that the user specifies, since the Z80 is held it can have full control over the cart data too. Basically you'd need a 32bit register to specify where in the cart it grabs samples from, how many samples to grab, should it loop, etc. You could have quite a decent audio with a single channel at say 8khz producing some looped music, another channel doing drums/other instruments, and the other channels doing sound fx.

Maxim wrote
If you're using both channels to get interpolated values then you may switch, for example, from 15+1 to 8+8 (made-up example) and you have to go through either 15+8 or 8+1 in the middle, albeit not for long. That'd give you a noise problem if it wasn't fast enough to be filtered. Avoiding this might be tricky.

Does it sound better with one channel?


It sounds less noisy with one channel, but less quality if that makes sense. Originally I was doing an "out 7f, a" doing a few calcs then outputting "a" again, which was less than a 44100 sample but compared to two consecutive "out c" it was worse.

It's hard to hear the noise in RetroCopy but very audible in other emulators, so I would say it's something to do with the amplification values and probably a bug or two somewhere in there. It's very likely there is a bug because I get things I'm not expecting with some changes I make. I'm going to have to do a developer build of RetroCopy for myself because the existing debuggers aren't really up scratch for the stuff I want to do and slow me down quite a bit. I like rapid testing with small changes and it's quite hard to do it atm without wasting too much time.
  View user's profile Send private message Visit poster's website
  • Joined: 12 Nov 2005
  • Posts: 54
Reply with quote
Post Posted: Thu Feb 25, 2010 3:16 pm
Sorry to bump an old topic, but I just fixed the links from a posting a couple of years back where I posted some code for converting samples into PSG writes. There are also example VGM files of the samples.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Oct 2009
  • Posts: 138
Reply with quote
Post Posted: Fri Feb 26, 2010 3:17 pm
Sounds better than my attempt Blargg, at least the voices sound more loud and don't seem to have the same distortions. Did you do any song samples?
  View user's profile Send private message Visit poster's website
  • Joined: 12 Nov 2005
  • Posts: 54
Reply with quote
Post Posted: Fri Feb 26, 2010 6:11 pm
How about The Picard Song in stereo? Enjoy (2.7 MB):

The_Picard_Song.vgz (mirror in case the first doesn't work)

It's at 11 kHz and only uses two squares, so it's somewhat quiet. (OK, I think I worked out all the little bugs in the VGM encoding, argh)
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 742
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Sat Feb 27, 2010 11:48 am
lol.. that's still awesome.
  View user's profile Send private message
  • Joined: 10 Oct 1999
  • Posts: 211
  • Location: Lebanon, New Hampshire, USA
Reply with quote
Post Posted: Sun Feb 28, 2010 12:32 pm
The stereo is... well, quite hypnotic.
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!