I can't figure out how the 3 "filters" have any mathematical reasoning behind them. They seem pretty random, like Ken Kutaragi just picked some random math equations out of a hat.
The first "filter" makes a little sense, since it practically a DPCM decoder, but why must the last sample be multiplied by 15/16?
The other 2 "filters" I can't make any sense out of them. If they are called "filters" what do they filter out and why?
psycopathicteen wrote:
The first "filter" makes a little sense, since it practically a DPCM decoder, but why must the last sample be multiplied by 15/16?
So that errors don't build up over time and become DC offsets. This is a fairly standard
leaky integrator.
Quote:
The other 2 "filters" I can't make any sense out of them. If they are called "filters" what do they filter out and why?
They're second-order resonant IIR filters. The filters are used to whiten the signal, in much the same way as the
"floors" in Vorbis. I haven't analyzed the filters to see their exact center point and Q value, but a good converter will end up picking the one whose frequency response most closely matches the spectral shape of the 16-sample block.
I guess there is some math behind it. Some really confusing complicated math that is over my head.
A good converter need not do that much. An acceptable but expensive converter can brute force every possible filter and scale value combination for the least mean square error compared to the input sample data.
One would need only to brute-force each of the four filters, as the peak of the prediction residues would give the scale that doesn't clip.
Good idea. Maybe somebody can work that into the decoder I wrote ages ago, or maybe there's a better one floating around now?
psycopathicteen wrote:
I guess there is some math behind it. Some really confusing complicated math that is over my head.
Well don't worry, you're not alone. I barely understand the S-DSP myself. I just think of it like the CRC32 seed value. I'm sure it has a significant and complicated history, so I just make sure to use the right magic number and move on.
I'd really enjoy a step-by-step walkthrough of the entire DSP, "this is what this does, this is why it does it, here are two audio samples to demonstrate the effect, here's a video and some pictures showing the effect."
It's amazing how humble blargg is, given that his DSP emulator is genius.
byuu wrote:
It's amazing how humble blargg is, given that his DSP emulator is genius.
I mostly took the genius existing work of previous people and refined it, as I've done with other things (NES APU for example). Most of my "genius" is hundreds of hours of hard work, rather than merely divine inspiration
psycopathicteen, the filters are pretty simple to understand at a high level. You've got a set of 4-bit PCM samples, which clearly won't sound good for some waveforms if they just generate a rough stair-step waveform. So you smooth it out. These filters use different smoothings. Why multiple ones? They make different shapes that fit the sample points, and presumably the BRR encoding tool tries each filter and uses the one that fits best.
Quote:
Good idea. Maybe somebody can work that into the decoder I wrote ages ago, or maybe there's a better one floating around now?
I did that about one year ago - I ported your encoder to java and improved it a little. Search "BRRTools" on romhacking.net to get it.
I asked you if I could use it so you should have remembered it.
Quote:
An acceptable but expensive converter can brute force every possible filter and scale value combination for the least mean square error compared to the input sample data.
What are you talking about ? It's freeware.
Quote:
Quote:
An acceptable but expensive converter can brute force every possible filter and scale value combination for the least mean square error compared to the input sample data.
What are you talking about ? It's freeware.
He may be referring to computational cost. Not that it matters much on a modern PC.
Yes, exactly, I was referring to computational cost.
The pseudocode still looks a hell of a lot computationally cheaper than, say, what LAME does for MP3 audio:
Code:
For each 16-sample block:
Try whitening it with each of four filters to produce "residue"
Pick the filter with the smallest peak residue
Determine the scale factor from this peak residue
For each sample in the block:
Whiten: Produce the residue
Scale: Divide by the scale factor
Dither: Optionally add random noise to break up patterns introduced by quantization
Quantize: Round the scaled residue to the nearest integer and store it
Rescale: Multiply the quantized residue by the scale factor
Reconstruct: Apply this filter to produce the current state
Pack the quantized residue into nibbles and write them
VAG on PS1/PS2 has a couple more filter options and 28-sample blocks, but otherwise it's the same thing.
Why run the whitening filter once, discard the results, and run it again? The prediction filters in BRR are based on the two previous samples of the
decoded data. If you quantize the already whitened data, the errors will compound.
My computer is having trouble running BRRtool. It keeps giving me ERROR: currupted file window.
Who cares if it is long to convert the samples, it's a one-time process in the development of a game. If you develop a game, just convert your .wav once and save them as .brr to include in your source. Even if you have a slow PC, it will probably not be this much of a problem.
Also I removed the unnecessary step to compute the root of the mean (I just compare means, which is equivalent) which should make things faster. You could also disable some of the filters if you want it to be faster - you don't have to leave all 4 enabled.
@psyco : are you using a valid .wav file ?
My computer doesn't know what file type to open with.
You're running the tool from the commandline with java, right?
This is what happens.
Quote:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Compaq_Owner.DAVID>"My Documents\[681]BRRTools\bin\brr
\BRREncoder.class"
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Documents and Sett
ings\Compaq_Owner/DAVID\My Documents\[681]BRRTools\bin\brr\BRREncoder/class
Caused by: java.lang.ClassNotFoundException: C:\Documents and Settings\Compaq_Ow
ner.DAVID\My Documents\[681]BRRTools\bin\brr\BRREncoder.class
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: C:\Documents and Settings\Compaq_Owner.DAVID\My D
ocuments\[681]BRRTools\bin\brr\BRREncoder.class. Program will exit.
C:\Documents and Settings\Compaq_Owner.DAVID>
Quote:
C:\snesdev\BRRTools>java -classpath bin brr.BRREncoder test.wav -l
Size of file to encode : 2000 samples.
Initial BRR block added
Done !
Filter 0 used on 111 blocks.
Filter 2 used on 2 blocks.
Filter 3 used on 12 blocks.
Psycho, you should install JRE (java runtime environment) on your machine (just google java runtime in google and you'll be able to download it easily), and then type "java" before the program, like mic shows. Yeah, java programs aren't directly executable without JRE (like how ROMs aren't executable without an emulator), but that is an easy way to make sure your programs will run on all OSes that have JRE (Windows, linux and mac OS all have JRE).
Java run-time environment. Oh, I downloaded just Java, not the run-time environment. I'll try that.
mic_ wrote:
Quote:
C:\snesdev\BRRTools>java -classpath bin brr.BRREncoder test.wav -l
Size of file to encode : 2000 samples.
Initial BRR block added
Done !
Filter 0 used on 111 blocks.
Filter 2 used on 2 blocks.
Filter 3 used on 12 blocks.
Poor filter 1 :(
I'll use you, filter 1 ;_;
LOL
It's weird filter 0 is used this much - usually it's the worst one and is the least used one. At least it was for samples I converted.
Quote:
It's weird filter 0 is used this much - usually it's the worst one and is the least used one. At least it was for samples I converted.
I used a square wave sample.
What folder should I put all this stuff in?
The JRE? Doesn't the installer suggest a directory for you? Like C:\Program Files\Sun\...
In my case, I can't even run it.
Quote:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
This requires Java 6. I can't do that... that requires a 64-bit Intel Mac to do so, if I recall my details correctly.
I use a PowerPC G5 running Mac OS X 10.4.11.