Author Topic: Batman sample player  (Read 372 times)

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Batman sample player
« on: March 30, 2012, 07:09:46 AM »

www.pcedev.net/pce_audio/batman_app/batman_sampleplayer.zip

 Rummaging through some stuff, found this. Forgot I had this. Up/down to select sample #, button I (or II) plays the current sample/instrument.

 A little background on it: It's just the bass guitar samples of Batman on the PCE. There are quite a few others (like drumkits and orchestra hit), but these are special. Every once in a while I rummage/trace through sound engines of PCE games (mostly hucards). Almost all games use the sample channel method to play a few short samples and usually drumkit type stuff. Maybe a sound effect or two (like the 'bark' sample in Air Zonk). And then other games use no samples at all. But this game was different. There are 25 'notes' to the bass guitar sound (ranging two octaves). Each note/tone has two parts. There's an attack part, and then there's a loop part. This isn't uncommon, as sample based synth uses this technique. But cool thing about this, is that there is no 'release' part of the sample (to trail of in sound) like you normally have on sample based synth. The loop part would be used for 'hold' (holding the sound). And even then, a bass guitar sample for such setups usually don't even have loop points for base guitar samples (there really isn't a need for it if you have the whole sample).

 So anyway, the sample is divided into the attack part and the loop part. The release part/phase of the instrument is made up of a simple volume fade on key release (channel volume). This has a nice effect in that the sample bit depth on the PCE is only 5 bits per channel. But that's 5bits per volume level. The human ear isn't perceptive of 'noise' on loud audio. The quantization noise of 5bits is really only heard on the lower amplitude parts of a sample. The bass guitar sample has a nice strong/loud attack phase. And the loop part of the sample is loud too. If the release part was done as a recorded sample, it would more noticeable noise increase as the sample trails off in volume. That's where the channel volume comes in. What's normally 5bit sample depth gets expanded into a range of near 10bit sample depth. You don't need to do this 'per' sample or sync it per sample. You just envelope the volume at a low 60hz or slower. It's a bit difficult to explain, but it's very similar to 'range compression' (where a block of samples has a multiplier definition to set the range for that block of samples).

 The output is nice and clean and high res sounding. Not that the PCE can't do some bass guitars type modeling with its normal channel, but there are limitations to what it can do. Sound synth theory says that one important and most complex parts of an instrument is the attack phase. Even LA synth (linear arithmetic) cheats by 'mixing' in an attack sample with the modeled instrument sound ( not that the PCE sound chip is anywhere near that level to be worrying about that). And so benefits of this is that the 'cycle' part is higher res than the pce's normal wavebuffer, the attack phase can be fairly complex, and but the cpu resource requirement is low. One trade off is sample storage. 25 samples took about 16k of rom. Not bad at all. The other trade off is that there is no pitch sliding (obviously) - at least in the Batman sound engine version. Not a problem for a bass guitar per se, but if you wanted some other 'synth' type sounds (or final fantasy string instruments) - then the process needs some additional modification (and thus some more cpu resource). I didn't have any plans to take it to that level. I just thought it was pretty clever what they did and pretty unique to PCE sound engines.

 The assembled rom is in the zip along with the source (thought I doubt anyone will use it). I don't recommend using Ootake to test it out. Ootake still has DDA problems (it's gotten better but it's still overly noise than it really is due to some weird artifacting of the emulator itself).

ccovell

  • Hero Member
  • *****
  • Posts: 2245
Re: Batman sample player
« Reply #1 on: March 30, 2012, 01:51:03 PM »
I've tried this out before when you first released it, and it was pretty cool.

So, one question about the PCE's volume controls:  Do the multiple volume controls of the PCE really add together and assist each other?  There's so much noise leakage in the whole PCE audio hardware I can't believe it anyway.  Mute any channel using any of the controls and you can still hear the waveform playing quietly... so doesn't this interference cut out the "lower bits" of the theoretical 10-bit volume envelope?

The model that supposedly works on the PCE is this:

<[{(Channel 5 bit sample data) x 5 bit Channel Volume} x 4 bit Channel Balance] x 4 bit Global Balance> = 18 bits of volume control!

Doesn't sound likely.

What the Paula sound hardware on the Amiga does is more likely: While the Amiga has 8-bit sample hardware, it also has a 6-bit (64 level) volume control.  That does not add up to 14-bits, technically as there is no 64-level DAC in the Amiga.  Instead, the Paula hardware suppresses (mutes) a single (8-bit) sample every certain number of clock ticks (28800 ticks per second, going by my lousy memory).  If the volume is 63, all samples pass through at the specified frequency.  If the volume is lower-- 62, for example-- then one out of every 64 samples is suppressed, and so on.  This has the audible effect of a gradual volume fade.  HOWEVER, listen to a sample on the Amiga at a very low volume and the sample sounds scratchy due to the Paula "dropping" samples to get this low volume effect.

I'd bet the PCE does it the same way, going by the way it sounds...

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Batman sample player
« Reply #2 on: March 30, 2012, 04:20:29 PM »
Quote
<[{(Channel 5 bit sample data) x 5 bit Channel Volume} x 4 bit Channel Balance] x 4 bit Global Balance> = 18 bits of volume control!

The formula is this:

left = 0x1f - (global.left*2) +  0x1f - (chan.left*2) + 0x1f - (chan.mono)
right = 0x1f - (global.right*2) +  0x1f - (chan.right*2) + 0x1f - (chan.mono)

Left and right saturate at 0x1f (they don't clip).

 From there,
Code: [Select]
left_out=log_tabe[left]*current.sample and same for the right.

 They accumulate, not multiply. It works out since the channel volume steps are logarithmic. So there's only one real volume control per each channel left and right side, so you gain nothing as far as increased depth/step output if you try to mix mono and pan volume settings. Most games use mono volume for the envelope volume and channel pan as the master volume for it. Makes it convenient even if you're not gaining additional resolution in attenuation.

Quote
What the Paula sound hardware on the Amiga does is more likely: While the Amiga has 8-bit sample hardware, it also has a 6-bit (64 level) volume control.  That does not add up to 14-bits, technically as there is no 64-level DAC in the Amiga.  Instead, the Paula hardware suppresses (mutes) a single (8-bit) sample every certain number of clock ticks (28800 ticks per second, going by my lousy memory).  If the volume is 63, all samples pass through at the specified frequency.  If the volume is lower-- 62, for example-- then one out of every 64 samples is suppressed, and so on.  This has the audible effect of a gradual volume fade.  HOWEVER, listen to a sample on the Amiga at a very low volume and the sample sounds scratchy due to the Paula "dropping" samples to get this low volume effect.

I'd bet the PCE does it the same way, going by the way it sounds...

 I've never heard that. Are you sure? The discussions I've had with a few amiga coders was that the volume control in some Amigas didn't have a linear reduction across the full range (the accuracy of the dacs wasn't meant for that exploit) and so the 14bit audio you got with the paired channel (AM mode) was really only 10bits usable. But that it varied from Amiga version to version (within models).

 If the PCE did that, I would have probably notice that. If you suppress a waveform down to just 1 sample output of 32, and played it at a low rate - it wouldn't sound scratchy. It'd sound completely wrong altogether. For what it's worth, I looked at the PCE audio on the scope before it hit the amp (at its full 3.58mhz output from the chip) and I didn't see anything like that. I was specifically looking for PWM or such on the DAC output too. That and I've done a ton of recordings to the PCE from the real units over the years (some for myself and some for tests for Ryphecha and other emulation authors). I didn't notice any anomalies in the low and very low volume range. Matter of fact, when I did the paired channel 10bit DAC output tests, I used pan volume to raise and lower the volume of the sample output. I didn't notice anything weird there either. I know at some point, the lower of the paired channel will saturate to 0 level (or leak level) - but the upper channel volume is so low by then that it's not even noticeable.

I know some of Genesis and Megadrives have anomalies in the DAC output for really low volume output. A weird stepping effect (spritesmind had it documented in a thread). But since you mentioned it, I'll keep any eye out for it when I do recording tests again from the real system.

Quote
Mute any channel using any of the controls and you can still hear the waveform playing quietly... so doesn't this interference cut out the "lower bits" of the theoretical 10-bit volume envelope?

 I don't see how one is related to the other. Unless you're referring to the noise. I was referring to noise via quantization at low bit depths. The artifacts of low bit depth, if you will. I wasn't referring to the 10bit DAC paired output trick, if that's what you mean. That trick works pretty good on the real hardware, but this is completely different.

 I've also noticed the audio leak too. But IIRC, it was only when chan pan was set to 00 and mono was set high. I don't think I got audio leak at with $80 and $ff settings. But even if it were so, that would just make volume setting of 0 the lowest instead of 'off'. I usually turn my channels off by stopping the waveform pointer.

(edit: had to add code tags)
« Last Edit: March 30, 2012, 04:25:29 PM by Bonknuts »

ccovell

  • Hero Member
  • *****
  • Posts: 2245
Re: Batman sample player
« Reply #3 on: March 30, 2012, 07:38:12 PM »
I've never heard that. Are you sure? The discussions I've had with a few amiga coders...
...I was specifically looking for PWM or such on the DAC output too...


Yes, I guess PWM is the correct term. The Turbo's still a mystery to me what with it being logarithmic, but anyway...

Paula...  Linky: http://blog.kebby.org/?p=11

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Batman sample player
« Reply #4 on: April 02, 2012, 08:20:05 AM »
I've never heard that. Are you sure? The discussions I've had with a few amiga coders...
...I was specifically looking for PWM or such on the DAC output too...


Yes, I guess PWM is the correct term. The Turbo's still a mystery to me what with it being logarithmic, but anyway...

Paula...  Linky: http://blog.kebby.org/?p=11


 Ohhh. PWM. Ok. The way I read your description, it sounded much different.