
 ReSample (c) 1996 by MLF/SLI
 


 What does ReSample do?

Well, it takes a Scream Tracker 3.x samplefile and resamples it at a 
different rate.
This is especially useful if you have this fabulous 4-channel S3M and
desperatly want to enter it in the Assembly 4-channel compotition. Now you
just have one problem. Assembly Orginizing only accepts them in MOD format.
The only problem you have is that your samples aren't sampled at 8363 Hz and
therefore ST3 can't properly convert your S3M into a MOD. That's where
ReSample comes in. You just take your samples and resample them to 8363 Hz!
And Boom - you're 300 dollars richer.
Then there's something else. Imagine you have this really cool sample at
44.1 kHz. There's just a slight hitch - it's bigger than 64000 bytes and ST3
won't load the whole sample! Just take ReSample and use the maximize option.


 How to use ReSample

There's nothing to it, really. Just type in the following:

  ReSample <filename> [samplerate]

<filename> is obligatory and signifies the sample that you wish to be
  resampled. The file has to be in 8bit mono ST3 sampleformat.
[samplerate] is the samplerate at which the sample should be resampled. If
  no samplerate is specified, ReSample defaults to 8363 Hz - the standard for
  MOD files. Samplerate may range from 1 to 2^31, although not all those
  samplerates are feasable. ST3's upper limmit is 2^16 = 65535. Rates below
  4 kHz shouldn't be considered. But go ahead and try and see what happens.
  Instead of the samplerate, you can specify MAX, which maximizes the size
  of the sample to 64000 bytes. The samplerate is adjusted automatically.


 Technical Information

ReSample takes the sample and interpolates it with a cubic spline. Then it
takes samples at intervals corresponding to the new samplerate to produce
the new sample. There probably are better and less memory-intensive methods
for interpolation, but I just did cubic splines at University and I wanted
to see how good the interpolation actually works. I'm quite impressed with
the results.
A cubic spline basically takes many 3rd degree polynomials (between every
two samples one) and overlays them over the sample so that the actual
function values at the sample points coinside with the original sample.
Also, the first and second derivitives of neighboring cubic polynomials
are identical at the overlapping point.
For more information about Spline-Interpolation see any textbook on numerical
methods for first year students.


 Source Code

I included the source code of ReSample in this package. Okay, okay, so I'm
not Tran or Michael Abrash. But I hope that the code will help you some,
if you're interested.
ReSample was written in pure C (no asm this time around). Don't be fooled
by the CPP extention - the compiler just defaulted to that extention and I
was to lazy to change it.
I used Borland C++ 3.1, but the source should be runnable on any PC-based
C-compiler.
EMS.HPP contains the EMS functions and wasn't written by me. Big thanks go
out to Terry Dettmann and Jim Kyle, the authors of the "DOS Programmer's
Reference" (2nd Edition). The functions only use C-calls, which makes them
quite slow, but I wasn't in the mood to convert them to assembler, mostly
because I didn't want to go on a bug-hunt.
I had to use EMS, because the spline-interpolation is so memory-intensive.
I have to store as many 4-byte float variables as there are samples in the
original sample. Then I need 2 equally sized arrays for temporary variables.
The original sample is also stored in EMS.
This blows the EMS-requirement up to 13 times the original sample-size.
Needless to say that I could not have done it with 640k base memory.
I'm not storing the new sample in EMS, since it's maximum size is 64000
bytes. But, you might say, what happens, if the new improved Scream Tracker 4
comes out and samples of unlimited length are allowed. Well, if that happens,
I'll release the new improved ReSample v4.00, satisfied?
All this talk about EMS, you'll think, why didn't he just use a DOS-extender,
maybe pmode, written by the aforementioned Tran? Because I don't have any
experience with protected mode programming and wouldn't know how to go about
using a DOS-extender, okay!?


 Known Bugs

Sometimes, the resampled file has some white noise added at the end of the
sample. And sometimes there's a slight bump in the sample near the beginning.
The former phenomenon occurs quite often. The latter occurs dominantly in
samples with a high samplerate. The problem doesn't lay in the interpolation
algorythm. It has to be something in the S3I header definition, or in the
almighty ST3 itself for that matter. If I resample and then convert the 
sample to raw format with Jesus Villena's CONVERT v1.4B and then load that
raw sample into ST3 neither of the aforementioned problems occur. I'd be
grateful for any help on fixing this rather sinewy bug.
Short loops aren't always converted perfectly, especially when the sample is
upsampled slightly. That is because the original LoopBegin and LoopEnd don't
exactly coincide with discrete samples in the new sample. But this isn't
exactly a bug, it's more like a feature (hello, Microsoft).
It happens that the spine overshoots the limits of the 8 bit sample, 
i.e. values of less than 0 or more than 255 are assumed. What I should have
done is reduce the overall volume slightly. What I did instead, was truncate
the exceeding values. You don't really hear it, but I may nevertheless
change this in the future.


 Copyright Notice

Nothing to say here, just use ReSample at your own risk. Otherwise do what
you like with it; rape the source-code, add something, remove something,
whatever. Please just mention where the original came from, i.e. from me.
It would also be nice, if you mentioned me in any song in which you use
resampled samples.


 Contacting the Author

If, for any reason, you want to contact me, please do so. Even a postcard,
just saying hello is welcome. It might even spur me on to release future
versions of ReSample or even release something totally different. I've been
meaning to start coding on a Demo for ages now - somehow, I'm just not
getting around to it...
Well, enough crap, here's my address:

  SnailMail:
  Michael Flegel
  Am Ehrenmal 2
  21516 Schulendorf
  Germany

  email:
  flegel@physnet.uni-hamburg.de

  WWW:
  http://www.physnet.uni-hamburg.de/home/vms/flegel

Oh yeah, please tell everybody about that web-site, if you will :-)


 Other SLI Products

As I've said, I've meaning to code a demo, but so far it's just not meant
to be. But my brother has released some excellent music under the SLI-label.
Check out the web-site for his latest releases.


 Greets

I know it's lame, but I just feel that I have to greet some people. Skip
these if you don't expect yourself to be on them.

  Apocalypse aka Erwin Sterne
  ax aka Alexis Iglauer
  Richard Franklin
  Defier/Penumbra aka John Hankinson
  Justin Benade
  Merlyn aka Tony Abbott
  Tony Thuy/AMD
  Eartoaster/Consubstantiality aka Henning Glawe
  Jinx!/Hybrid aka Jan Eric Hoffmann

  PSI/Future Crew, for writing a truly great music file editor

  Carl Geiger, our lecturer, for teaching me about cubic splines

  Tran, the greatest underground-coder
  Michael Abrash, the greatest overground(?)-coder
  Terry Dettmann and Jim Kyle, the authors of 'The Bible'
  Jesus Villena, the author of CONVERT


 Closing Words

I feel the need to say something in closing, I just don't know what.
So why don't I just leave it at that and say good-bye.

  MLF, May 12, 1996



 Version history

  v0.00
  The basic program, no EMS support yet, maximum samplesize:  10k

  v0.05
  Eliminated any redundant memory storage, maximum samplesize:  50k

  v0.10
  Added EMS support, maximum samplesize:  EMSsize/13

  v0.11
  Removed a few bugs, now releases EMS after abnormal exit

  v0.12
  Added check for SCRS in sample header

  v0.12
  Removed some minor bugs, first public release
