96000HZ audio impliementation code submission.

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

-_pentium5.1_-
Lurker
Posts: 110
Joined: Sat Sep 04, 2004 7:55 pm
Location: USA

Post by -_pentium5.1_- »

Sorry for reviving this thread. My misguided desire to see a 96kHz sound output in ZSNES was based on a couple of major misconceptions about SNES sound:
1. I thought that the 32kHz sample-rate "limit" only applied to BRR-decoded samples, not FM-synthesized tones. I forgot that the SNES's entire sound output is combined into one 32kHz PCM stream.
2. I thought that Gaussian interpolation or noise might be able to take advantage of a higher sample rate to slightly increase high-frequency response without sounding too different from the real SNES.
I made mistake #1 because my mind was poisoned by too much NES emulation, and I made mistake #2 because I was thinking about a certain PCM interpolation setting in kode54's VBA build.
This signature intentionally contains no text other than this sentence.
kode54
Zealot
Posts: 1140
Joined: Wed Jul 28, 2004 3:31 am
Contact:

Post by kode54 »

The PCM interpolation filters I added to VBA are not designed to increase high-frequency content, because usually, the only high frequency content present is aliasing. The purpose of the filters is to eliminate that aliasing by interpolating missing samples. libresample / band-limited interpolation is probably the highest quality thing I could cram in there, other than perhaps a decent polyphase resampler, but this was quick and easy.

Most of the time, you will not find games to be playing samples at much higher than the Nyquist frequency, that is, half of 32000Hz. It is unlikely that interpolation will yield any more high frequency content there, besides aliasing.

Several of the tracks from Final Fantasy 6, on the other hand, do use some medium to high frequency samples, such as 2.06 Spinach Rag, and 2.20 Another World Of Beasts. The affected notes will begin to distort audibly with simple linear interpolation, while the correct filter will prevent that from happening at the 32000Hz output rate. Resampling and mixing at a higher rate may actually yield real high frequency content in this case, and perhaps it may only serve to annoy your dog.

Mixing at rates other than 32000Hz also requires interpolating the envelopes, and also throws out the possibility of correct echo emulation. (As the reverb actually buffers in a block of the APU RAM, which would have to vary in size relative to the requested size and the emulated sample rate. Of course nothing is known to depend on there being any sample data cycling around in the echo buffer, so that's not too big of a problem.) Since most emulators already do this, the point is moot.


You're welcome to load up SNESAmp and test this, but I don't know if you'll be getting the samples mixed and envelopes processed/interpolated to the rate you choose, or if you'll be getting the 32000Hz output resampled, since I think it supports both now. Or maybe it switched over to resampling the output. I'm so confused. :[
-_pentium5.1_-
Lurker
Posts: 110
Joined: Sat Sep 04, 2004 7:55 pm
Location: USA

Post by -_pentium5.1_- »

Okay, um... I'm not a complete idiot about audio signal processing, but (relatively speaking) I really don't know that much about the inner workings of the SNES. I should have given the same explanation for both of my "misconceptions": My mind has been poisoned by too much NES emulation.
This signature intentionally contains no text other than this sentence.
Bahamut_ZERO_Clue

Post by Bahamut_ZERO_Clue »

Throwing away a Sound card that doesn't work sounds reasonable but I'm kinda stuck as I have a Laptop with Integrated Realtek HD ALC880(D) audio. It's really good for what it does however but upgrading to a Audigy2 NX is not an option and it's very impractical for me to nix one audio chipset for another that will be doing no better work than the other.
SteveSnake
Rookie
Posts: 11
Joined: Thu Mar 02, 2006 8:41 pm

Post by SteveSnake »

Bahamut_ZERO_939 wrote:I have a Laptop with Integrated Realtek HD ALC880(D) audio.
Well, according to Realtek themselves, that hardware:
Supports 44.1K/48K/96K/192kHz DAC sample rate
Not being rude but I still can't really see why you need 96K.
DOLLS (J) [!]
ZNES Developer
Posts: 215
Joined: Mon Aug 02, 2004 11:22 pm

Post by DOLLS (J) [!] »

SteveSnake wrote:Not being rude but I still can't really see why you need 96K.
Perhaps it doesn't support 32 KHz and he wants the most accurate sound he can get (3x 32 KHz)?
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

Quick googling of "Creative and Upsampling"
http://www.google.com/search?hl=en&q=Cr ... gle+Search

I really doubt supporting 96KHz will do anything useful except for adding noise that wasn't there in the first place for no particular reason... but whatever I guess.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

Have you tried listening to the music from Front Mission 2: Gun Hazard in SNESAmp? There is a huge difference between 32kHz-to 48 and 32-to-96kHz,especially when using Cubic interpolation and Stereo HQ,although there is benefit with Gaussian interpolation as well.
The GH music is very rich in high frquencies.
I've used Otachan's ASIO_out (www.otachan.com) plugin for Winamp and an Audigy2 for testing.ASIO4ALL (www.asio4all.com) driver,and SNESAmp set to 32bit/96kHz.

Also,it can be very noticeable in any soundtrack,if you set the pitch to +12 semitones up.

Sounds more like PSX-quality than SNES-quality.

But it's more to do with getting the Audigy2 to operate at 24/96 to get the best and most linear frequency response from the card,while avoiding the double-resampling at 48kHz that the crappy Creative drivers do.
Bypassing DirectSound with the ASIO driver eliminates this Creative driver crap to a great extent.But ASIO can work at 48kHz at 16bit or 96kHz at 24bit (although ASIO4ALL can support any other samplerate like (16000,24000,32000,44100,48000,96000,192000) at 16,24 or 32bit.
(and,yes,I know the Audigy2 convertors can output only 18bit sound in reality,not 24bit as advertised)

Hmmm...as I think of it,why hasn't anybody thought of implementing ASIO output in any emulator? ASIO gives much lower latencies and gives the most direct sound possible.Also these drivers are more high-performance than DirectSound - less CPU needed.
And,there's this driver ASIO4ALL that's free,easy to use and works on any consumer soundcard,pro soundcard and onboard audio.
Last edited by kick on Sun Mar 05, 2006 11:06 pm, edited 2 times in total.
Aerdan
Winter Knight
Posts: 467
Joined: Mon Aug 16, 2004 10:16 pm
Contact:

Post by Aerdan »

If you're not using Gaussian interpolation, go away, no one cares. I don't *care* how 'good' it might sound; it's not what the SNES used, so it's irrelevant to getting ZSNES to output 96kHz.
tetsuo55
Regular
Posts: 307
Joined: Sat Mar 04, 2006 3:17 pm

Post by tetsuo55 »

Aerdan wrote:If you're not using Gaussian interpolation, go away, no one cares. I don't *care* how 'good' it might sound; it's not what the SNES used, so it's irrelevant to getting ZSNES to output 96kHz.
personally i dont agree

i do prefer the options for either Exactly like the original snes or the option for enhanced sound/graphics
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

tetsuo55 wrote:
Aerdan wrote:If you're not using Gaussian interpolation, go away, no one cares. I don't *care* how 'good' it might sound; it's not what the SNES used, so it's irrelevant to getting ZSNES to output 96kHz.
personally i dont agree

i do prefer the options for either Exactly like the original snes or the option for enhanced sound/graphics
I'm just not going to give a nice diplomatic explaination because it's been said many times. Devs will ignore you when you say any of the audio filters and higher frequency (other than Gaussian) have bugs/differences in them simply because it was never intended. You can choose to like these filters or not.
Last edited by Deathlike2 on Mon Mar 06, 2006 12:00 am, edited 1 time in total.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
Bahamut_ZERO_Clue

Post by Bahamut_ZERO_Clue »

We have so many requests for video resolutions but why is audio so taboo? Nobody whined about getting 32bpp Windowed modes. Nobody complained about high-resolution modes like 1024x768 and higher when they were added. There were no complaints about porting ZSnes to Windows from a DOS port.

Update:

ASM continues to elude me, if it were C/C++ it might be clearer but this is the first time I've worked with 24bit audio and trying to use it with WaveOut through the PCM (I'm really used to dealing with native DirectSound). Even the neccessary audio processing settings in dspproc.asm aren't making sense. I need some details on how the settings are calculated against audio output, range, buffer lengths, and bit depths.
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

Bahamut_ZERO_939 wrote:We have so many requests for video resolutions but why is audio so taboo? Nobody whined about getting 32bpp Windowed modes. Nobody complained about high-resolution modes like 1024x768 and higher when they were added. There were no complaints about porting ZSnes to Windows from a DOS port.
Dude, it's a different set of issues altogether.

For video resolutions, I'm still wondering where that command line option is available for those people that care get satisfied. Video resolutions are particular to the the system (particularly of the laptop variety). There is generally a negative impact when using non-native resolution.

There's a simple reason why there is a Windows port.. because coding for DOS is very much a pain in the ass and you will have to adhere to those limitations. (I'd love to see power being wasted from a dual core system in DOS... if it even runs.) Plus, add the fact that everyone is not planning to stay in the stonage Win9x era forever.

There is probably some reason why the audio filters get more flak than the video filters do. It probably has to do with the state of ZSNES and the complex nature of emulating sound (moreso than the video). Sound reproduction is very subjective.. whereas a bug in the video rendering is visible (tangible) and easier to point out.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
Reznor007
Lurker
Posts: 118
Joined: Fri Jul 30, 2004 8:11 am
Contact:

Post by Reznor007 »

Deathlike2 wrote:For video resolutions, I'm still wondering where that command line option is available for those people that care get satisfied. Video resolutions are particular to the the system (particularly of the laptop variety). There is generally a negative impact when using non-native resolution.
This falls into the exact same category as you mentioned. Running a LCD at non-native resolution makes it look bad...running sound at a non-native frequency makes it sound bad.
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

Reznor007 wrote:
Deathlike2 wrote:For video resolutions, I'm still wondering where that command line option is available for those people that care get satisfied. Video resolutions are particular to the the system (particularly of the laptop variety). There is generally a negative impact when using non-native resolution.
This falls into the exact same category as you mentioned. Running a LCD at non-native resolution makes it look bad...running sound at a non-native frequency makes it sound bad.
ZSNES already allows 44Khz and 48Khz though.. and those are generally native for most sound cards even the integrated audio crap.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
Reznor007
Lurker
Posts: 118
Joined: Fri Jul 30, 2004 8:11 am
Contact:

Post by Reznor007 »

If you have your system set to output 96KHz then running 48KHz would be resampled.

It's like saying 1280x960 shouldn't be supported because 640x480 is an even multiple of it.
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

Reznor007 wrote:If you have your system set to output 96KHz then running 48KHz would be resampled.

It's like saying 1280x960 shouldn't be supported because 640x480 is an even multiple of it.
I think it's more to it that just that. I'll leave it at that.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

It's like saying 1280x960 shouldn't be supported because 640x480 is an even multiple of it.
If you're 20 feet away from the monitor, you wouldn't be able to tell the difference, which is what the situation is like with your ears. Unlike with your eyes, you can't get "closer" with your ears (getting physically closer is like making something brighter for your eyes).
Reznor007
Lurker
Posts: 118
Joined: Fri Jul 30, 2004 8:11 am
Contact:

Post by Reznor007 »

blargg wrote:
It's like saying 1280x960 shouldn't be supported because 640x480 is an even multiple of it.
If you're 20 feet away from the monitor, you wouldn't be able to tell the difference, which is what the situation is like with your ears. Unlike with your eyes, you can't get "closer" with your ears (getting physically closer is like making something brighter for your eyes).
What I was getting at is that 1280x960 was added to avoid LCD resampling because it adds artifacts. Audio resampling falls into the same category. Some people have audio systems good enough to tell the difference.
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

Reznor007 wrote:
blargg wrote:
It's like saying 1280x960 shouldn't be supported because 640x480 is an even multiple of it.
If you're 20 feet away from the monitor, you wouldn't be able to tell the difference, which is what the situation is like with your ears. Unlike with your eyes, you can't get "closer" with your ears (getting physically closer is like making something brighter for your eyes).
What I was getting at is that 1280x960 was added to avoid LCD resampling because it adds artifacts. Audio resampling falls into the same category. Some people have audio systems good enough to tell the difference.
I don't have a problem with adding options.. sometimes it is bad to have too many.

Most sound cards allow the sampling I've mentioned.. there's really no reason to add more. No sound card requires 96Khz sampling.. but that's also like saying you are not required to use a resolution higher than the highest res the SNES uses. Then again, I'm willing to bet someone will ask for 24-bit/192KHz options..

At least with custom resolutions, you don't have to worry about resolution requests.. but there's no way that I know of that you can have custom sampling rates. If you get all these options.. will they actually have a benefit? I really doubt it.

The other real issue is emulation accuracy and those that say using some other audio filter and higher sampling rates will reproduce "better sounds" as noted by some of the other posters... I finally understood this issue.. after thinking some of the audio filters/higher sampling rates improved the the natural sound... that's probably why the devs aren't as interested in adding more sampling rates.
Last edited by Deathlike2 on Mon Mar 06, 2006 3:34 am, edited 2 times in total.
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

Audio resampling falls into the same category. Some people have audio systems good enough to tell the difference.
The audio system may reproduce the higher frequencies, but I was referring to your ears. Hence my example of being 20 feet away from the monitor where you wouldn't be able to tell the difference between 1280x960 and 640x480. Looks like it's time to bust out the Monster cables! :)
Deathlike2
ZSNES Developer
ZSNES Developer
Posts: 6747
Joined: Tue Dec 28, 2004 6:47 am

Post by Deathlike2 »

blargg wrote:
Audio resampling falls into the same category. Some people have audio systems good enough to tell the difference.
The audio system may reproduce the higher frequencies, but I was referring to your ears. Hence my example of being 20 feet away from the monitor where you wouldn't be able to tell the difference between 1280x960 and 640x480. Looks like it's time to bust out the Monster cables! :)
Ah.. that's why parents tell you not to get close to the TV... :wink:
Continuing [url=http://slickproductions.org/forum/index.php?board=13.0]FF4[/url] Research...
Reznor007
Lurker
Posts: 118
Joined: Fri Jul 30, 2004 8:11 am
Contact:

Post by Reznor007 »

blargg wrote:
Audio resampling falls into the same category. Some people have audio systems good enough to tell the difference.
The audio system may reproduce the higher frequencies, but I was referring to your ears. Hence my example of being 20 feet away from the monitor where you wouldn't be able to tell the difference between 1280x960 and 640x480. Looks like it's time to bust out the Monster cables! :)
It's not just the high frequencies that are the problem. kmixer can introduce audible distortion resampling from 44.1KHz to 48KHz. Adding 96KHz simply lets users leave their system set to 96KHz without having to have resampling or manually switching the card to 48KHz every time.
kick
Trooper
Posts: 550
Joined: Wed Mar 01, 2006 8:47 pm

Post by kick »

The 96000Hz samplerate option is NOT to make the sound better or any different than what the SNES can do.It is more to preserve the sound and get it as CLOSE to the SNES as possible,for users of Audigy (10k2)-based cards.

The Audigy2 can operate at 48 or 96kHz (192kHz is useless marketing crap)

When operating at 48kHz,the Audigy2 resamples the data twice,even if it's at 48kHz,it passes through the Audigy DSP and also add to this the slight degradation from the kMixer in WinXP.

While at 96kHz,the Audigy2 cards feature a special chip (p16v) intended for 96kHz and above streams. The sound bypasses the DSP,the resampling and the kMixer has no effect.The p16v outputs it as 24-bit/96kHz at the output with no audible degradation,so you get the "real thing".
You also get the full 16-bits of sound in this case,instead of 15 1/2 before.

With SBLive! and Audigy 1cards,it's easy - you only need to change the Creative drivers with kX Project drivers and use 48kHz.

With the Audigy2,ZS and 4 Pro,you need 96kHz samplerate with whatever driver.

That's why.

On the other hand,the X-Fi series of cards have a very high-quality resampler,similar in quality to SSRC-HQ built-in,so they can support any sample rate with no audible defects.
Last edited by kick on Mon Mar 06, 2006 5:58 am, edited 6 times in total.
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

It's not just the high frequencies that are the problem. kmixer can introduce audible distortion resampling from 44.1KHz to 48KHz.
OK, that makes sense. It's like that on Mac OS Classic; the Sound Manager's resampler uses simple linear interpolation so if you want better, your code has to do the resampling. It's odd that a sound card wouldn't be made so that 44.1 kHz streams sounded decent in Windows. I take it that ZSNES can't just generate sound at either 44.1 kHz or 48 kHz internally, thus working with most sound cards?
Post Reply