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 - Sound stuff

Reply to topic
Author Message
  • Joined: 28 Sep 1999
  • Posts: 1197
Reply with quote
Sound stuff
Post Posted: Sat Dec 04, 1999 11:13 pm

Have any of you emulator author types found an SMS game that
makes use of both the PSG and FM sound chips at the same
time? The most I've seen is the PSG being muted while FM
sound is being played, but nothing in terms of actual
music or sound effects.

Also, can anyone explain how 'speech' is done via the PSG?
(as used in Gauntlet, Space Harrier, Sailer Moon GG) I have
a hunch it's some tricky business with the noise channel, or
just the volume being rapidly changed, but I really don't
have a clue about the specifics.
  View user's profile Send private message Visit poster's website
Limbs a Flyin'
  • Guest
Reply with quote
Post Posted: Sun Dec 05, 1999 4:38 am

Quote
> Also, can anyone explain how 'speech' is done via the PSG?
> (as used in Gauntlet, Space Harrier, Sailer Moon GG) I have
> a hunch it's some tricky business with the noise channel, or
> just the volume being rapidly changed, but I really don't
> have a clue about the specifics.

at a guess i would assume different games might do it differently, but if i had written such a routine it would

silence all the channels.
set one specific channel to a certain tone (i would set it to the lowest to keep that tone itself from being obvious to the listiner)
then change the volume on that channel at the right time ( would this be AM sound?)
effectivly changing the volume many times per frame (or whatever you want to measure time with) alters the strength of the output signal, and you get a messy psuedo DAC

so to emulate that would need your psg (or what ever) to log the incoming writes to it as well as the time offset when they occur, and then when you render the wave form you account for those changes. sounds logical enough
 
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Post Posted: Sun Dec 05, 1999 11:55 am
Quote
> Have any of you emulator author types found an SMS game that
> makes use of both the PSG and FM sound chips at the same
> time? The most I've seen is the PSG being muted while FM
> sound is being played, but nothing in terms of actual
> music or sound effects.

Popping in my mind, Alex Kidd the Lost Stars uses both. But probably all games needing voices do the same.

Quote
> Also, can anyone explain how 'speech' is done via the PSG?
> (as used in Gauntlet, Space Harrier, Sailer Moon GG) I have
> a hunch it's some tricky business with the noise channel, or
> just the volume being rapidly changed, but I really don't
> have a clue about the specifics.

It does nothing special than tweaking with the sound registers very quickly. Basically to get voices playing on an emulator you have to emulate the soundchip near perfectly, with wave synthesis and good synchronisation.
Wrapping the data to a PC Speaker or an adlib soundcard should work to "hear" the voice playing, but it will be far far from being good.
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 25 Oct 1999
  • Posts: 2029
  • Location: Monterey, California
Reply with quote
Post Posted: Sun Dec 05, 1999 6:49 pm

Quote
> at a guess i would assume different games might do it differently, but if i had written such a routine it would

> silence all the channels.
> set one specific channel to a certain tone (i would set it to the lowest to keep that tone itself from being obvious to the listiner)

Basically right. You can set a PSG channel to a frequency of zero, which means that the wave is locked in place at its highest (or lowest) position. Then you can 'write' the sound wave directly through the volume control.... with four bits of resolution. Of course the timing is up to you.

Quote
> then change the volume on that channel at the right time ( would this be AM sound?)

Yeah... or as it's more commonly known, PCM.

There were two common methods that I found for playing back samples on the SMS.

The older games (space harrier, alex kidd) used Pulse Width Modulation... the same method used to playback samples on the PC's built in speaker or various portable LCD ganes(with '1 bit' sound... i.e., the speaker can be high or low, no in between). Rather than converting (lets say) an 4 bit PCM wave to a 1 bit wave by simply rounding every sample up to maximum (1) or down to the minimum (0), which would sound horrible (try loading a sample in a sample editor like goldwave and amplyfying the sample by 1600% or something, to where the clipping would be intolerable)... a greater bit depth was simulated by altering the speaker output within the space of a single sample. I won't go into much detail about it, but suffice to say there's a lot of aliasing but the sound is recognizable.

The SMS games that used PWM playback did so by setting all three tone channels to zero frequency, and altering the volumes of all three channels in unison at regular timed intervals (using only maximum volume or minimum) . The use of all three channels was for extra loudness.

Later games (like the Williams Arcade Classics) used plain old 4-bit (unsigned) Pulse code modulation, and I'm really not sure why all the older games didn't also... I don't think PWM used any less cart space, and sure didn't sound better. These playback routines, like the PWM routines, set all three channels to zero frequency, and changed the volumes in unison at regular intervals... however, instead of all-on or all-off, the channel volumes were set to the amplitude for each sample (in this context I mean 'sample' as in a single amplitude measurement at one point in time during a recording). The sound was much, much cleaner, though a little bit faint.


Of course, there's no hardware timer in the SMS other than the vertical blank, and 60 samples/second is way to low for a recognizable sample playback (though it might function to make some odd synthesized sound effects in the low low frequency range). Horizontal Blank interrupts only occur regularly while the screen is drawn, not during the vblank, so they aren't a dependable timing mechanism.

So generally, during sample playback, the CPU just dedicated itself to playing the sample and doing nothing else... I've pulled a few sample playback routines out of the alex kidd and Williams Arcade Classics roms, and they just output the next sample to the volume controls, run a countdown loop, and jump to the next sample. They also disable interrupts. You'll recall most SMS games just freeze the onscreen action while playing a sample... two exceptions I can think of are Space Harrier (the Space Harrier falls to the ground as he screams) and the yet-undumped Shooting Gallery (a -very- scratchy 'Perfect!' sample when you play around without missing a target... and the music doesn't stop. I think there was a palette change during the playback also).


Here's an interesting bit of trivia... another game that does 4-bit PCM playback is Lemmings for SMS... and I discovered when I loaded the cart rom into a sample editor that the samples are stored in 8-bit SIGNED pcm! That's the same format that the amiga's sound chips used, and the game was originally developed for amiga. So, looking at the sample playback routine, I discovered that the sample player loads each 8-bit sample, flips it to unsigned, and shifts it down 4 bits before outputting it to the volume control. That's either very wasteful or very innovative (including a mini paula chip emulator right into an sms game).
  View user's profile Send private message Visit poster's website
Jose Manuel Delgado
  • Guest
Reply with quote
Post Posted: Sun Dec 05, 1999 8:37 pm
Hello :)

Quote
> Also, can anyone explain how 'speech' is done via the PSG?
> (as used in Gauntlet, Space Harrier, Sailer Moon GG) I have
> a hunch it's some tricky business with the noise channel, or
> just the volume being rapidly changed, but I really don't
> have a clue about the specifics.

Depends. Sonic1 GG uses both rapidly changes of frecuency and volume. Sonic and Tails 2 GG uses rapidly volume changes only. In next version of Calypso you can see how rapidly it is (over 3000-5000 in a 1/5 of second). This feature is disabled in the "oficial" version of the emulator, but i can enable if you want.

Saludos,

JMDM
 
Limbs a Flyin'
  • Guest
Reply with quote
Post Posted: Mon Dec 06, 1999 4:46 am

Quote
> > Have any of you emulator author types found an SMS game that
> > makes use of both the PSG and FM sound chips at the same
> > time? The most I've seen is the PSG being muted while FM
> > sound is being played, but nothing in terms of actual
> > music or sound effects.

> Popping in my mind, Alex Kidd the Lost Stars uses both. But probably all games needing voices do the same.

i think he means making use of the fm chip and psg at the same time, not alternating between the two. taking that into account i cant think of a single game that does that
 
  • Joined: 28 Sep 1999
  • Posts: 1197
Reply with quote
Post Posted: Mon Dec 06, 1999 9:41 pm

Quote
> The older games (space harrier, alex kidd) used Pulse Width Modulation... the same method used to playback samples on the PC's built in speaker or various portable LCD ganes(with '1 bit' sound... i.e., the speaker can be high or low, no in between). Rather than converting (lets say) an 4 bit PCM wave to a 1 bit wave by simply rounding every sample up to maximum (1) or down to the minimum (0), which would sound horrible (try loading a sample in a sample editor like goldwave and amplyfying the sample by 1600% or something, to where the clipping would be intolerable)... a greater bit depth was simulated by altering the speaker output within the space of a single sample. I won't go into much detail about it, but suffice to say there's a lot of aliasing but the sound is recognizable.

Doesn't sound like something that could be emulated easily,
I use the OPL-2 for PSG sound, and you can't reprogram it
very quickly. (or at least as quickly as the PSG is accessed
by the SMS for speech stuff)

Quote
> Later games (like the Williams Arcade Classics) used plain old 4-bit (unsigned) Pulse code modulation, and I'm really not sure why all the older games didn't also... I don't think PWM used any less cart space, and sure didn't sound better. These playback routines, like the PWM routines, set all three channels to zero frequency, and changed the volumes in unison at regular intervals... however, instead of all-on or all-off, the channel volumes were set to the amplitude for each sample (in this context I mean 'sample' as in a single amplitude measurement at one point in time during a recording). The sound was much, much cleaner, though a little bit faint.

Interesting; I bet I could monitor the PSG regs to see when the
frequecies are set to zero, and pipe the volume levels which would
be used for 4-bit PCM right out to the SB's DAC. Of course,
this would probably mess up music that has the frequency
zeroed as well, but it's worth trying.

Thanks for the in-depth explanations of how this stuff works!
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 25 Oct 1999
  • Posts: 2029
  • Location: Monterey, California
Reply with quote
Post Posted: Tue Dec 07, 1999 6:59 pm

Quote
> Doesn't sound like something that could be emulated easily,
> I use the OPL-2 for PSG sound, and you can't reprogram it
> very quickly. (or at least as quickly as the PSG is accessed
> by the SMS for speech stuff)

I've never programmed with the OPL2 directly... can it be programmed to play an unmodified square wave? I remember dos mastergear used OPL for PSG output (I think) and it never did sound right.



Quote
> Interesting; I bet I could monitor the PSG regs to see when the
> frequecies are set to zero, and pipe the volume levels which would
> be used for 4-bit PCM right out to the SB's DAC. Of course,
> this would probably mess up music that has the frequency
> zeroed as well, but it's worth trying.

What I'd do is log all the outputs to the sound registers in a given frame, noting along with the volume how many cycles had passed since the last change (I'd just code it into the output handler), and use that log to construct the portion of the audio wave to be played in that frame. You'd need to divise a constant which tells you how many CPU cycles correspond to a single audio sample in your playback stream (the constant would be based on the SMS's clock speed as well as theplayback rate). Thus, if the sample playback routine sets the volume to 5 and doesn't change it for 4000 z80 cycles, you'd write the audio buffer's equivelants to sample position '5' 4000/K times to the audio buffer.

This assumes a digital PSG emulator... which probably significantly mroe difficult than emulating with OPL...

The logging method is probably the only sensible way to do it, and I'd wager that's how Meka handles sample playback.. the problem with changing the opl volume whenever you encounter a volume change in the SMS program's code is that you probably aren't actually emulating one z80 cycle every 4 million somethingth of a second, but rather, emulating a block of z80 in a quick sucession, then jumping elsewhere in your emulator program to render grapohics, poll for input, etc...


Quote
> Thanks for the in-depth explanations of how this stuff works!

Yay! Appreciated in my own lifetime!
  View user's profile Send private message Visit poster's website
Ricardo Bittencourt
  • Guest
Reply with quote
Post Posted: Tue Dec 07, 1999 9:13 pm
Quote
> What I'd do is log all the outputs to the sound registers in a given frame, noting along with the volume how many cycles had passed since the last change (I'd just code it into the output handler), and use that log to construct the portion of the audio wave to be played in that frame. You'd need to divise a constant which tells you how many CPU cycles correspond to a single audio sample in your playback stream (the constant would be based on the SMS's clock speed as well as theplayback rate). Thus, if the sample playback routine sets the volume to 5 and doesn't change it for 4000 z80 cycles, you'd write the audio buffer's equivelants to sample position '5' 4000/K times to the audio buffer.

That's what BrSMS does and it sounds very well. Check out the source code of BrMSX if you want to see an full assembly implementation of that.

Ricardo Bittencourt
 
  • Joined: 12 Jul 1999
  • Posts: 891
Reply with quote
Hey Ricardo!
Post Posted: Wed Dec 08, 1999 10:04 am
Quote
> > What I'd do is log all the outputs to the sound registers in a given frame, noting along with the volume how many cycles had passed since the last change (I'd just code it into the output handler), and use that log to construct the portion of the audio wave to be played in that frame. You'd need to divise a constant which tells you how many CPU cycles correspond to a single audio sample in your playback stream (the constant would be based on the SMS's clock speed as well as theplayback rate). Thus, if the sample playback routine sets the volume to 5 and doesn't change it for 4000 z80 cycles, you'd write the audio buffer's equivelants to sample position '5' 4000/K times to the audio buffer.

> That's what BrSMS does and it sounds very well. Check out the source code of BrMSX if you want to see an full assembly implementation of that.

> Ricardo Bittencourt

Have you finished with BRSMS? Just wondering, as it still doesn't emulate sound on my computer. For referance, I have an ESS1788 soundcard.
~unfnknblvbl
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!