shithub: dumb

Download patch

ref: fb758de4fe3e5dcfa9f98bf65ff1be72ed9c678f
parent: ad75b32881b5ad9f87a60545058fdbd3bdb885c5
parent: 8430c5c81ff15468b38a542b1e27ba19c2e72768
author: dmitrykos <dmitrykos@neutroncode.com>
date: Thu Dec 14 15:48:03 EST 2017

Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	dumb/src/it/itrender.c
#	src/helpers/resampler.c

diff: cannot open b/cmake-scripts//null: file does not exist: 'b/cmake-scripts//null' diff: cannot open a/dumb/cmake/cmake-scripts//null: file does not exist: 'a/dumb/cmake/cmake-scripts//null' diff: cannot open a/dumb/cmake//null: file does not exist: 'a/dumb/cmake//null' diff: cannot open a/dumb/examples//null: file does not exist: 'a/dumb/examples//null' diff: cannot open a/dumb/include/internal//null: file does not exist: 'a/dumb/include/internal//null' diff: cannot open a/dumb/include//null: file does not exist: 'a/dumb/include//null' diff: cannot open a/dumb/prj/dumb//null: file does not exist: 'a/dumb/prj/dumb//null' diff: cannot open a/dumb/prj//null: file does not exist: 'a/dumb/prj//null' diff: cannot open a/dumb/src/core//null: file does not exist: 'a/dumb/src/core//null' diff: cannot open a/dumb/src/helpers//null: file does not exist: 'a/dumb/src/helpers//null' diff: cannot open a/dumb/src/it//null: file does not exist: 'a/dumb/src/it//null' diff: cannot open a/dumb/src//null: file does not exist: 'a/dumb/src//null' diff: cannot open a/dumb/vc6/dumb//null: file does not exist: 'a/dumb/vc6/dumb//null' diff: cannot open a/dumb/vc6//null: file does not exist: 'a/dumb/vc6//null' diff: cannot open a/dumb//null: file does not exist: 'a/dumb//null' diff: cannot open b/examples//null: file does not exist: 'b/examples//null' diff: cannot open b/include/internal//null: file does not exist: 'b/include/internal//null' diff: cannot open b/include//null: file does not exist: 'b/include//null' diff: cannot open b/src/allegro//null: file does not exist: 'b/src/allegro//null' diff: cannot open b/src/core//null: file does not exist: 'b/src/core//null' diff: cannot open b/src/helpers//null: file does not exist: 'b/src/helpers//null' diff: cannot open b/src/it//null: file does not exist: 'b/src/it//null' diff: cannot open b/src//null: file does not exist: 'b/src//null' diff: cannot open b/vc6/dumb//null: file does not exist: 'b/vc6/dumb//null' diff: cannot open b/vc6//null: file does not exist: 'b/vc6//null'
--- /dev/null
+++ b/.clang-format
@@ -1,0 +1,3 @@
+BasedOnStyle: LLVM
+IndentWidth: 4
+SortIncludes: false
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
-### CMake template
+
+# Cmake files
 CMakeCache.txt
 CMakeFiles
 CMakeScripts
@@ -5,7 +6,7 @@
 Makefile
 cmake_install.cmake
 install_manifest.txt
-### C template
+
 # Object files
 *.o
 *.ko
--- /dev/null
+++ b/CHANGELOG.md
@@ -1,0 +1,596 @@
+```
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * CHANGELOG.md - Release notes for DUMB.             / / \  \
+ *                                                   | <  /   \_
+ *                                                   |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+ ```
+
+# DUMB Changelog
+
+## v2.0.2, released 9 October 2017
+
+* Amended order scanner to also look for blank type patterns that would
+  cause problems with the renderer.
+* Changed all format readers to check order scanner for errors and return
+  them to the caller.
+* Changed all credits references to the correct name, now that it's more
+  widely known.
+
+## v2.0.1, released 9 October 2017
+
+* #66, Can't Use DUMB_OFF_T_CUSTOM to Fix Static Assertion On 32-Bit System
+* #69, Make LFS-checks work with MinGW.org-MinGW
+* #70, Fix internal getnc to return dumb_ssize_t
+* #71, PSM Playback Has Garbled Sound
+* Documentation updates
+* More fuzz testing revealed places where order counts were allowed
+  to be extremely high, blowing out the memory requested for the
+  timekeeping arrays. This has been severely limited now to throw errors
+  on load.
+* Added some considerations to a porting document.
+
+## v2.0.0, released 26 September 2017
+
+* Memory leak and bug fixes
+* Audio playback quality improvements for STM
+* Added support for FEST MOD files
+* Default resampling quality is now cubic
+* Allegro 4 support
+* New dumbplay, dumbout examples
+* Multiple cmake fixes
+* Deprecated `duh_render()`, use `duh_render_float()` and `duh_render_int()`
+* Removed API deprecated since 0.9.3, see the
+    [DUMB 0.9.3 deprecation reference](http://dumb.sourceforge.net/index.php?page=docs&doc=deprec)
+
+## v1.0.0, released 17 January 2015
+
+* Support newer compilers
+* Better audio playback quality
+* More supported formats
+* SSE optimizations support
+* CMake support
+* New resamplers
+* Seek support
+* Fixes, cleanups, speedups.
+
+## v0.9.3, released 7 August 2005
+
+Hello! Welcome to a long-awaited-or-probably-just-given-up-on-by-everybody
+release! New to this release are lower memory usage, faster mixing loops,
+loading of text fields in the module files, and faster load functions for
+projects that don't need to seek within the module or know its length.
+Additionally, Chad Austin has contributed a dumb2wav tool for converting
+modules to .wav files and updated the Visual Studio 6 project files to
+compile all the examples as well as the library. Users of Unix-like systems
+will be pleased to know that on Chad's suggestion I have made the build
+system cope with variables such as $HOME or ${HOME} in the prefix.
+
+Chad has also contributed an Autotools build system, but neither of us
+recommends its use. The Autotools are an evil black box, we haven't quite
+managed to get it right, and goodness help you if it happens not to work for
+you. The files are available in a separate download if you absolutely need
+them. Notice that that download is almost twice as large as the rest of DUMB!
+
+Maybe we'll do SCons next time.
+
+Thanks to Chad for all his work. Chad is the author of Audiere, a portable
+sound library which has started using DUMB for its module playback! Wahoo!
+
+   http://audiere.sf.net/
+
+There are three main optimisations that went into the mixing loops.
+
+First, I downloaded ModPlugXMMS and had a peek at the mixing code, which is
+Public Domain. It uses look-up tables for the cubic mixing. I pinched the
+idea, and that sped DUMB's cubic (best quality) resamplers up by a factor of
+two or three.
+
+Secondly, the samples loaded from the file are now kept in 8-bit or 16-bit
+format, whereas previously they were being converted to 24-bit-in-32-bit on
+loading. This means the samples occupy a half or a quarter of the memory they
+used to occupy. It also had the side-effect of speeding up the mixing loops,
+but it meant I had to duplicate the resampling code. (It is all done with
+macros in the source code, but it becomes two copies on the binary level.)
+
+Secondly, stereo samples and stereo mixing buffers are now kept in
+interleaved format, where previously the two channels were done separately to
+keep the code simpler. This change has made the library quite a bit bigger,
+but has made the code run almost twice as fast for stereo output (tested for
+modules whose samples are mostly mono)!
+
+DUMB is now as fast as ModPlugXMMS on my system.
+
+Some people have also commented that DUMB seems to take a long time loading
+files. This is because immediately upon loading the file it runs the playback
+engine over it up as far as the point of first loop, taking snapshots at 30-
+second intervals to be used as references for fast seeking and finally
+storing the playback time. Of course, most games don't need this. You can now
+skip it by calling the _quick versions of the dumb_load_*(), dumb_read_*() or
+dumb_register_dat_*() functions. Should you need the data later, you can call
+dumb_it_do_initial_runthrough() to calculate it. Please note that this cannot
+currently be done safely from a concurrent thread while the music is playing.
+
+As mentioned, DUMB loads the text fields in module files now. You can
+retrieve the song title with duh_get_tag(). Sample names and file names and
+instrument names and filenames, and the song message for IT files, are
+available with a call to duh_get_it_sigdata() and various dumb_it_sd_*()
+functions. Please note that text fields added as extensions by ModPlug
+Tracker are not supported.
+
+DUMB's timing is ever so slightly more accurate. This is hardly noticeable,
+but it has meant that the length computed will increase very slightly.
+
+There are many small playback fixes in this release:
+
+* The Lxx effect in XM files (set envelope position) is now supported.
+
+* Pattern looping is now correct for XM files. Bizarrely, an ordinary pattern
+  loop whose start point isn't the first row seems to cause the next pattern
+  to start at the row corresponding to the loop start point. That must have
+  been a headache for people creating XM files! Nevertheless, DUMB now
+  emulates this behaviour. If you have an XM file that was written in a
+  tracker other than Fast Tracker II and breaks in DUMB, you can get around
+  it by putting a D00 effect (break to row 0) right at the end of the pattern
+  containing the loop.
+
+* XM pattern looping can be infinite. DUMB should detect this and call the
+  loop callback when it happens. Specifically, it has a loop counter for each
+  channel, so each time it sets or decrements that counter, it remembers the
+  loop end point for that channel. When the loop terminates, the loop end
+  point is reset to 0. If the loop end point ever decreases during a loop,
+  the loop callback is called. If anyone manages to get around this check and
+  prevent DUMB from calling the callback, please let me know and send me an
+  illustrative XM file!
+
+* For IT files, notes are now removed from channels if they have faded out,
+  even if they are still in the foreground. After this has happened, a row
+  with a note and Gxx (tone portamento) specified will cause a new note to
+  start playing, which is what Impulse Tracker does in this scenario.
+  (Normally, Gxx prevents the new note from playing and instead causes the
+  old note to start sliding towards the new note.)
+
+* If a tone portamento command occurred when no note was playing, the effect
+  value wasn't stored. This has been fixed. Thanks to Maim from #trax on
+  EFnet for discovering this bug.
+
+* DUMB now treats the parameter to the undocumented XM key off effect Kxx as
+  a delay, consistent with Fast Tracker II's behaviour. It has also been made
+  not to clear the note, so a subsequent volume command will restore it, as
+  in Fast Tracker II.
+
+* DUMB used to process the first row when you created the
+  DUMB_IT_SIGRENDERER. This happened before you had a chance to install any
+  callbacks. If an F00 effect occurred on the first row, the music would stop
+  immediately and the xm_speed_zero callback would be called if it were
+  present. Unfortunately, it wasn't present, and the algorithm for
+  calculating the length subsequently went into an endless loop while waiting
+  for it. Worse still, the same algorithm accumulated data for fast seeking,
+  and never stopped, so it pretty quickly consumed all the resources. DUMB
+  will now not process the first row until you first request some samples,
+  provided you pass zero for pos. Of course, any MOD or XM file with F00 in
+  the very first row won't do much anyway, but such files won't crash the
+  library now.
+
+* There was a subtle bug that affected a few XM files. For instruments with
+  no associated samples, the array mapping notes to samples is uninitialised.
+  This became a problem if such instruments were then used, which does happen
+  sometimes. On many systems, memory is initialised to zero when first given
+  to a program (for security reasons), so the problem didn't come up most of
+  the time. However, on platforms like DOS where memory isn't initialised, or
+  in programs that reuse memory later on (this includes the XMMS plug-in with
+  which I discovered the bug), a rogue note would occasionally play. This has
+  now been fixed.
+
+* DUMB's envelope handling for IT files was subtly wrong. Upon note off, it
+  stopped obeying the sustain loop points one tick too early. Notes were
+  often shorter than they should have been, and in pathological cases a whole
+  extra iteration of the sustain loop section might have been skipped. The
+  envelope code has now been rewritten. Thanks go to Allefant for Valgrinding
+  the new code!
+
+Finally, there were two build problems in the last version, which were fixed
+in the download marked with -fixed. They are of course correct in this
+version. For the record:
+
+* The make/config.bat file, responsible for generating make/config.txt, wrote
+  a crucial line to the wrong place, causing it to be left out of the file.
+  As a result, the makefile would fail to install everything for Allegro
+  users, and enter infinite recursion for other users. This applied to people
+  using DJGPP and MinGW.
+
+* DUMB's Makefile was supposed to install the example programs on Unix-based
+  platforms, but it wasn't doing. The fix was to edit Makefile and change the
+  one occurrence of $COMSPEC to $(COMSPEC).
+
+That's it! I hope you enjoy this long-awaited-or-probably-just-given-up-on-
+by-everybody release of DUMB!
+
+
+## v0.9.2, released 2 April 2003
+
+Yes, there really has been a release. This is not a day-late April fools'
+joke.
+
+DUMB's full name has changed! The old "Dedicated Universal Music
+Bastardisation" was rather silly, and not much more than a forced attempt at
+finding words beginning with D, U, M and B. I spent weeks and weeks browsing
+dictionaries and hopelessly asking others for bright ideas, until the
+brilliant Chris "Kitty Cat" Robinson came up with "Dynamic". I decided to
+keep the U as Universal, since a DUH struct can hold digital music in any
+format. Now all that remained was the B, but it didn't take me long to come
+up with Bibliotheque, which, despite looking French, is indeed considered an
+English word by Oxford English Dictionary Online, to which my university has
+a subscription. So there you have it - the name now makes sense.
+
+The two most significant additions to the project would have to be the new
+thread safety (with an important restriction, detailed in docs/dumb.txt), and
+the new build system. The silly 'makeall' and 'makecore' scripts are gone. If
+you are a GCC user, all you need do now is run 'make' and 'make install', as
+for other projects. You don't even have to run a 'fix' script any more! There
+are some caveats, which are covered in readme.txt. If you use Microsoft
+Visual C++ 6, you no longer need to obtain GCC and GNU Make - there is a
+project file just for you.
+
+Huge thanks go to Steve Terry for testing on Windows XP - about five times -
+and to lillo for testing on BeOS and Mac OS X. Thanks also to X-G for testing
+on a Windows system that has consistently posed problems for DUMB's old
+makefiles.
+
+There was a bug whereby al_poll_duh() would sometimes cause the music to
+resume playing if you called it after al_pause_duh(). Whether this was DUMB's
+fault for misusing Allegro's API, or a bug in Allegro, is unclear, but this
+release makes it work.
+
+In one of my projects, I found that my AL_DUH_PLAYER stopped playing when
+there were lots of other sound effects. In order to fix this, I programmed
+DUMB to set the priority of the stream's voice to 255, the maximum. I also
+added al_duh_set_priority(), so you can set the priority yourself if you need
+to.
+
+The resampling code has undergone a transformation. The bad news is that the
+linear average code is no longer in use. The good news is that where DUMB's
+resamplers used to require three extra samples' worth of memory to be
+allocated and initialised, it now copes with just the sample data. And it
+does a very good job at bouncing off loop points and otherwise hurtling
+around the sample. The resampling code is considerably more complicated, but
+the code that uses the resamplers is considerably simpler - and if you
+noticed a slight click in some bidirectionally looping samples, you'll be
+pleased to know that that click is gone!
+
+I have also devoted some effort to optimisation. It seemed hopeless for a
+while, but then I actually figured out a way of making it faster AND more
+accurate at the same time! DUMB is now quite a bit faster than it was, and it
+mixes not with 16-bit precision, but with 24-bit precision. (It used 32-bit
+integers all along, but the difference is that it now makes use of 256 times
+as much of the integer's range.)
+
+There have been the usual improvements to playback. The last release occurred
+rather too soon after I had fixed the XM effect memories; EAx and EBx, fine
+volume ramps, had been neglected. These are now handled properly.
+
+In previous versions of DUMB, muted channels in IT were actually played with
+surround sound panning (where the right-hand channel is inverted). This has
+been fixed, so muted channels will really be muted now.
+
+There were also some subtle problems with the way DUMB handled New Note
+Actions for IT files. It turned out that, in all releases of DUMB so far,
+pitch, filter and panning envelopes and sample vibrato were not being
+processed for any note that was forced into the background by a new note on
+the same channel! This only affected IT files. Not only has this been fixed,
+but envelope interpolation is much more accurate. Long trailing envelope-
+driven fade-outs sound a lot better now!
+
+Since panning and filter envelopes are more precise, extra fields have been
+added to the DUMB_IT_CHANNEL_STATE struct, used by
+dumb_it_sr_get_channel_state(). These fields hold the 'decimal' parts of the
+pan and filter cut-off. See dumb.txt for details.
+
+Mxx (set channel volume) now correctly only modifies the last note played on
+the channel, not any previous notes that have been forced into the background
+by New Note Actions, and filter effect processing is now closer to what
+Impulse Tracker does.
+
+The XM loader was slightly flawed and could crash on files containing samples
+with out-of-range loop points. One such file was given to me. This has been
+fixed.
+
+Finally, the legal stuff. Julien Cugniere has been added to the list of
+copyright owners. He deserves it, for all the work he did on the XM support!
+And the licence has been changed. You are no longer required to include a
+link to DUMB in a project that uses DUMB; the reasons for this relaxation are
+explained in licence.txt. However, the request is still there ...
+
+As usual, enjoy!
+
+
+## v0.9.1, released 19 December 2002
+
+Hi again! Lots to say this time, so I shall cut right to the chase.
+
+DUMB now supports Impulse Tracker's low-pass resonant filters! Huge thanks go
+to Jeffrey Lim, author of Impulse Tracker, for giving me what information he
+still had regarding the algorithm; to cut a long story short, modifying
+ModPlug Tracker's source code (which is in the Public Domain) led to an
+algorithm whose output matched Impulse Tracker's perfectly.
+
+Please note that ModPlug Tracker's filters as they stand do not match Impulse
+Tracker's, and I have no interest in supporting ModPlug Tracker's variant
+(especially not the integer rounding problems). Please see docs/modplug.txt,
+new in this release, for details.
+
+Thanks also go to Fatso Huuskonen for motivating me to add filter support,
+and providing me with several great IT files to test it with!
+
+The other important feature added for this release is click removal. Up until
+now, DUMB has generated clicks when cutting notes, starting samples in the
+middle, and so on. This version of DUMB will remove any such clicks. Note
+that DUMB does not use volume ramps to accomplish this; the algorithm will
+not take the bite out of the music!
+
+In other news, DUMB now supports sample vibrato for IT files, and instrument
+vibrato for XM files. A slight bug in New Note Action handling for IT files
+has been fixed; Note Fade will not break the sustain loops of the sample and
+envelope, as it did before. Tremor handling (Ixy) had a strange bug in it,
+which has been fixed.
+
+Support for XM files has been greatly enhanced. The XM envelope handling new
+in the last release contained a huge bug, resulting in notes seeming not to
+stop when they should; this has been fixed. Some XM files crashed DUMB, while
+others failed to load; these problems have been solved. Effect memories now
+work properly for XM and MOD files, to the best of my knowledge. Some other
+differences between IT and XM have been accounted for, most notably the
+Retrigger Note effects, Rxy and E9x.
+
+DUMB's sound quality and accuracy are not the only areas that have been
+enhanced. The API has been expanded, at last. You can now detect when a
+module loops, or make it play through just once. You can ask DUMB to inform
+you every time it generates some samples; this is useful for visualisation.
+For IT files, you can intercept the MIDI messages generated by Zxx macros,
+enabling you to synchronise your game with the music to some extent. (There
+is no such method for XM, S3M or MOD files yet; sorry. Also note that the
+function will be called before you actually hear the sound; I cannot improve
+this until DUMB has its own sound drivers, which won't be for a while.) You
+can query the current order and row. Finally, operations like changing the
+speed and tempo are now possible, and you can query the playback state on
+each channel.
+
+Some parts of DUMB's API have been deprecated. Simple programs that use
+Allegro will be unaffected, but if you get some compiler warnings or errors,
+please review docs/deprec.txt. This file explains why those parts of the API
+were deprecated, and tells you how to adapt your code; the changes you need
+to make are straightforward. Sorry for the inconvenience.
+
+For various reasons, I have made DUMB's makefiles use different compiler
+flags depending on your GCC version (unless you are using MSVC). There is no
+elegant way of getting the makefiles to detect when GCC is upgraded. If you
+upgrade GCC, you should execute 'make clean' in order to make DUMB detect the
+GCC version again. Otherwise you may get some annoying error messages. (It is
+wise to do this in any case, so that all the object files are built with the
+same GCC version.)
+
+DUMB's example players have been unified into a single player called
+'dumbplay'. The player has been enhanced to display messages when the music
+loops, and when XM and MOD files freeze (effect F00; more information on this
+in docs/howto.txt).
+
+Finally, as noted on DUMB's website, the release notes from the last release
+were inaccurate. It has been verified that DUMBOGG v0.5 does still work with
+that release, and still works with this release. The esoteric DUMBOGG v0.6
+has not been created yet, since DUMBOGG v0.5 still works.
+
+Please scroll down and read through the indented paragraphs in the notes for
+the last release; they are relevant for this release too.
+
+That's all folks! Until next time.
+
+
+## v0.9, released 16 October 2002
+
+MOD support is here! DUMB now supports all four of the common module formats.
+As usual, there have also been some improvements to the way modules are
+played back. Most notably, handling of tone portamento in IT files has been
+improved a lot, and XM envelopes are now processed correctly.
+
+The other major change is that DUMB now does a dummy run through each module
+on loading. It stores the playback state at thirty-second intervals. It stops
+when the module first loops, and then stores the playback time. This results
+in a slightly longer load time and a greater memory overhead, but seeking is
+faster (to any point before the module first loops) and the length is
+calculated! duh_get_length() will return this and is now documented in
+docs/howto.txt and docs/dumb.txt.
+
+DUMB's build process has been changed to use 'mingw' wherever it used
+'mingw32' before; some directories have been renamed, and the 'fix' command
+you had to run for MinGW has been changed from 'fix mingw32' to 'fix mingw'.
+
+Last time, I directed you to scroll down and read the notes from a past
+release, but ignore this point, and that point applies to something else, and
+so on. Did anyone do so? Well, if you're reading this at all, you probably
+did. Nevertheless, this time I shall be much less confusing and restate any
+relevant information. So the least you can do is read it!
+
+- If your program ever aborts with exit code 37 while loading an IT file,
+  PLEASE LET ME KNOW! The IT file in question has a stereo compressed sample
+  in it, and the format is unspecified for this case (Impulse Tracker itself
+  doesn't use stereo samples at all). I will need the IT file in question,
+  and any information you can give me about how the IT file was created (e.g.
+  what program). (If you don't get to see an exit code, let me know anyway.)
+
+- If your program ever outputs a line resembling "Inst 01 Env: 0,64 8,32
+  15,48" to stderr while loading an IT file, PLEASE LET ME KNOW! You have an
+  old IT file (saved by an Impulse Tracker version older than 2.00), and
+  support for such files is STILL untested.
+
+- Not all parts of DUMB's API are documented yet. You will find some
+  functions in dumb.h which are not listed in docs/dumb.txt; the reason is
+  that these functions still need work and will probably change. If you
+  really, really want to use them, talk to me first (IRC EFnet #dumb is a
+  good place for this; see readme.txt for details on using IRC). I intend to
+  finalise and document the whole of DUMB's API for Version 1.0.
+
+There have been some changes to the naming conventions in DUMB's undocumented
+API. DUMBOGG v0.5 will not work with this and subsequent releases of DUMB;
+please upgrade to DUMBOGG v0.6. These changes should not break anything in
+your own code, since you didn't use those parts of the API, did you ;)
+
+There is still a great deal of work to be done before DUMB's API can be
+finalised, and thus it will be a while before DUMB v1.0 comes out. It should
+be worth the wait. In the meantime, there will be 0.9.x releases with
+additional functionality, improved playback, and possibly support for some
+extra file formats.
+
+Finally I should like to offer an apology; there is a strong possibility that
+some of DUMB's official API will change in the near future. There will not be
+any drastic changes, and the corresponding changes to your source code will
+be simple enough. If I didn't make these changes, DUMB's API would start to
+become limited, or messy, or both, so it's for the better. I apologise in
+advance for this.
+
+Now scroll down and read the notes for the first r... oh wait, we already did
+that. I guess that's it then. You can stop reading now.
+
+Right after you've read this.
+
+And this.
+
+Off you go.
+
+Bye.
+
+
+## v0.8.1, released 11 August 2002
+
+This is a minor release that fixes a few bugs. One of these bugs, however,
+was pretty serious. dumb_register_dat_xm() was never coded! It was prototyped
+in aldumb.h, so code would compile, but there would be an unresolved symbol
+at the linking stage. This has been fixed.
+
+Platforms other than Unix did not have a working 'make veryclean' target;
+this has been fixed. In addition, the makefiles now use 'xcopy' instead of
+'copy', since on some systems GNU Make seems to have trouble calling commands
+built in to the shell.
+
+Contrary to the errata that was on the DUMB website, the makeall.sh and
+makecore.sh scripts actually DID install in /usr. This has now been
+corrected, and regardless of whether you use these scripts or call make
+directly, the files will now be installed to /usr/local by default.
+
+The XM loader used to treat stereo samples as mono samples with the data for
+the right channel positioned after the data for the left channel. This
+generally resulted in an unwanted echo effect. This has been fixed.
+
+When playing XM files, specifying an invalid instrument would cause an old
+note on that channel to come back (roughly speaking). Fast Tracker 2 does not
+exhibit this behaviour. This has been fixed.
+
+The GCC makefiles used -mpentium, which is deprecated in gcc 3.x. This was
+generating warnings, and has now been fixed.
+
+In XM files, the length of a sample is stored in bytes. DUMB was assuming
+that the length of a 16-bit sample would be even. I had two XM files where
+this was not the case, and DUMB was unable to load them. This has been fixed.
+
+In order to accommodate the extra part of the version number,
+DUMB_REVISION_VERSION has been added. DUMB_VERSION has also been added in
+order to facilitate checking if the version of DUMB installed is sufficient.
+See docs/dumb.txt for details.
+
+As a last-minute fix, the XM "Break to row" effect is now loaded properly. It
+was necessary to convert from binary-coded decimal to hexadecimal (those who
+have experience with Fast Tracker 2 will know what I mean). In short, this
+means the effect will now work properly when breaking to row 10 or greater.
+
+DUMB v0.8 had faulty release date constants; DUMB_MONTH and DUMB_DAY were
+swapped! For this reason, DUMB_DATE should not be compared against any date
+in 2002. This note has been added to docs/dumb.txt and also to dumb.h.
+
+Please scroll to the end and read the release notes for the first version,
+DUMB v0.7. Most of them apply equally to this release. However, the
+non-portable code was rewritten for DUMB v0.8, so that point does not apply.
+The point about length not being calculated also applies to XM files.
+
+Enjoy :)
+
+
+## v0.8, released 14 June 2002
+
+Welcome to the second release of DUMB!
+
+In addition to these notes, please read below the release notes for the
+previous version, DUMB v0.7. Most of them apply equally to this release.
+However, the non-portable code has been rewritten; DUMB should now port to
+big-endian platforms.
+
+The main improvement in this release of DUMB is the support for XM files.
+Enormous thanks go to Julien Cugniere for working on this while I had to
+revise for my exams!
+
+There was a mistake in the makefiles in the last release. The debugging
+Allegro interface library was mistakenly named libaldmbd.a instead of
+libaldmd.a, meaning you had to compile with -laldmbd, contrary to what the
+docs said. Apologies to everyone who lost sleep trying to work out what was
+wrong! The reason for using libaldmd.a is to maintain compatibility with
+plain DOS, where filenames are limited to eight characters (plus a three-
+letter extension). The makefiles have now been changed to match the
+information in the docs, so you may have to alter your project files
+accordingly.
+
+The example programs were faulty, and crashed on Windows if they were unable
+to load the file. It was also difficult to work out how to exit them (you had
+to click the taskbar button that didn't have a window, then press a key).
+They have been improved in both these respects.
+
+I have now added a docs/faq.txt file (Frequently Asked Questions), which is
+based on problems and misconceptions people have had with the first release.
+Please refer to it before contacting me with problems.
+
+Thanks to networm for touching up the Unix makefile and writing the
+instructions on using it.
+
+Incidentally, today (Friday 14 June) is the Robinson College May Ball at
+Cambridge Uni. God knows why it's called a May Ball if it's in June. I'm not
+going myself (72 GBP, and I'd have to wear a suit, ugh), but with all the
+noise outside I shall enjoy pumping up the speakers tonight!
+
+
+## DUMB v0.7, released 2 March 2002
+
+This is the first release of DUMB, and parts of the library are not
+crystallised. Don't let this put you off! Provided you don't try to use any
+features that aren't documented in docs/dumb.txt, the library should be rock
+solid and you should be able to upgrade more or less without problems.
+
+Here are some notes on this release:
+
+- There is some non-portable code in this release of DUMB. It is likely that
+  the library will fail to load IT files with compressed samples on
+  big-endian machines such as the Apple Macintosh.
+
+- If your program ever aborts with exit code 37 while loading an IT file,
+  PLEASE LET ME KNOW! The IT file in question has a stereo compressed sample
+  in it, and the format is unspecified for this case (Impulse Tracker itself
+  doesn't use stereo samples at all). I will need the IT file in question,
+  and any information you can give me about how the IT file was created (e.g.
+  what program). (If you don't get to see an exit code, let me know anyway.)
+
+- If your program ever outputs a line resembling "Inst 01 Env: 0,64 8,32
+  15,48" to stderr while loading an IT file, PLEASE LET ME KNOW! You have an
+  old IT file (saved by an Impulse Tracker version older than 2.00), and
+  support for such files is untested.
+
+- The length of IT and S3M files is not currently calculated. It is just set
+  to ten minutes.
--- /dev/null
+++ b/CMakeLists.txt
@@ -1,0 +1,234 @@
+cmake_minimum_required(VERSION 3.1)
+project(libdumb C)
+include(GNUInstallDirs)
+include(CheckCCompilerFlag)
+
+# Bump major (== soversion) on API breakages
+set(DUMB_VERSION_MAJOR 2)
+set(DUMB_VERSION_MINOR 0)
+set(DUMB_VERSION ${DUMB_VERSION_MAJOR}.${DUMB_VERSION_MINOR})
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-scripts)
+
+option(BUILD_EXAMPLES "Build example binaries" ON)
+option(BUILD_ALLEGRO4 "Build Allegro4 support" ON)
+option(USE_SSE "Use SSE instructions" ON)
+
+function(check_and_add_c_compiler_flag flag flag_variable_to_add_to)
+    string(TOUPPER "${flag}" check_name)
+    string(MAKE_C_IDENTIFIER "CC_HAS${check_name}" check_name)
+    check_c_compiler_flag("${flag}" "${check_name}")
+    if(${check_name})
+        set(${flag_variable_to_add_to} "${flag} ${${flag_variable_to_add_to}}" PARENT_SCOPE)
+    endif()
+endfunction()
+
+check_and_add_c_compiler_flag("-Wno-unused-variable" CMAKE_C_FLAGS)
+check_and_add_c_compiler_flag("-Wno-unused-but-set-variable" CMAKE_C_FLAGS)
+check_and_add_c_compiler_flag("-Wall" CMAKE_C_FLAGS)
+add_definitions("-D_FILE_OFFSET_BITS=64")
+add_definitions("-DDUMB_DECLARE_DEPRECATED")
+
+set(CMAKE_C_FLAGS_DEBUG "-DDEBUGMODE=1 -D_DEBUG")
+check_and_add_c_compiler_flag("-ggdb" CMAKE_C_FLAGS_DEBUG)
+check_and_add_c_compiler_flag("-Zi" CMAKE_C_FLAGS_DEBUG)
+
+set(CMAKE_C_FLAGS_RELEASE "-ffast-math -O2 -DNDEBUG")
+
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-ffast-math -O2 -DNDEBUG")
+check_and_add_c_compiler_flag("-g" CMAKE_C_FLAGS_RELWITHDEBINFO)
+check_and_add_c_compiler_flag("-Zi" CMAKE_C_FLAGS_RELWITHDEBINFO)
+
+set(CMAKE_C_FLAGS_MINSIZEREL "-ffast-math -Os -DNDEBUG")
+
+if(USE_SSE)
+    check_c_compiler_flag("-msse" "CC_HAS_MSSE")
+    if(CC_HAS_MSSE)
+        message(STATUS "Compiling with SSE support")
+        set(CMAKE_C_FLAGS "-msse ${CMAKE_C_FLAGS}")
+        add_definitions("-D_USE_SSE")
+    else()
+        message(STATUS "Compiling without SSE support")
+    endif()
+endif()
+
+link_directories(${CMAKE_CURRENT_BINARY_DIR})
+include_directories(include/)
+
+if(BUILD_EXAMPLES)
+    find_package(argtable2)
+    find_package(SDL2)
+else()
+    message(STATUS "Not building examples")
+endif()
+
+if(BUILD_ALLEGRO4)
+    find_package(Allegro4)
+else()
+    message(STATUS "Not building Allegro 4 support")
+endif()
+
+SET(SOURCES
+    src/core/unload.c
+    src/core/rendsig.c
+    src/core/rendduh.c
+    src/core/register.c
+    src/core/readduh.c
+    src/core/rawsig.c
+    src/core/makeduh.c
+    src/core/loadduh.c
+    src/core/dumbfile.c
+    src/core/duhtag.c
+    src/core/duhlen.c
+    src/core/atexit.c
+    src/helpers/stdfile.c
+    src/helpers/silence.c
+    src/helpers/sampbuf.c
+    src/helpers/riff.c
+    src/helpers/resample.c
+    src/helpers/memfile.c
+    src/helpers/clickrem.c
+    src/helpers/barray.c
+    src/helpers/tarray.c
+    src/it/xmeffect.c
+    src/it/readxm2.c
+    src/it/readxm.c
+    src/it/readstm2.c
+    src/it/readstm.c
+    src/it/reads3m2.c
+    src/it/reads3m.c
+    src/it/readriff.c
+    src/it/readptm.c
+    src/it/readpsm.c
+    src/it/readoldpsm.c
+    src/it/readokt2.c
+    src/it/readokt.c
+    src/it/readmtm.c
+    src/it/readmod2.c
+    src/it/readmod.c
+    src/it/readdsmf.c
+    src/it/readasy.c
+    src/it/readamf2.c
+    src/it/readamf.c
+    src/it/readam.c
+    src/it/read6692.c
+    src/it/read669.c
+    src/it/ptmeffect.c
+    src/it/loadxm2.c
+    src/it/loadxm.c
+    src/it/loadstm2.c
+    src/it/loadstm.c
+    src/it/loads3m2.c
+    src/it/loads3m.c
+    src/it/loadriff2.c
+    src/it/loadriff.c
+    src/it/loadptm2.c
+    src/it/loadptm.c
+    src/it/loadpsm2.c
+    src/it/loadpsm.c
+    src/it/loadoldpsm2.c
+    src/it/loadoldpsm.c
+    src/it/loadokt2.c
+    src/it/loadokt.c
+    src/it/loadmtm2.c
+    src/it/loadmtm.c
+    src/it/loadmod2.c
+    src/it/loadmod.c
+    src/it/loadasy2.c
+    src/it/loadasy.c
+    src/it/loadamf2.c
+    src/it/loadamf.c
+    src/it/load6692.c
+    src/it/load669.c
+    src/it/itunload.c
+    src/it/itrender.c
+    src/it/itread2.c
+    src/it/itread.c
+    src/it/itorder.c
+    src/it/itmisc.c
+    src/it/itload2.c
+    src/it/itload.c
+    src/it/readany.c
+    src/it/loadany2.c
+    src/it/loadany.c
+    src/it/readany2.c
+    src/helpers/resampler.c
+    src/helpers/lpc.c
+)
+
+set(INSTALL_HEADERS
+    include/dumb.h
+)
+
+set(ALLEGRO_SOURCES
+    src/allegro/alplay.c
+    src/allegro/datitq.c
+    src/allegro/dats3m.c
+    src/allegro/datxm.c
+    src/allegro/datduh.c
+    src/allegro/datmod.c
+    src/allegro/dats3mq.c
+    src/allegro/datxmq.c
+    src/allegro/datit.c
+    src/allegro/datmodq.c
+    src/allegro/datunld.c
+    src/allegro/packfile.c
+)
+
+
+set(PKG_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/dumb.pc")
+
+configure_file(
+    "${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.in"
+    ${PKG_CONFIG_FILE}
+    @ONLY
+)
+
+add_library(dumb ${SOURCES})
+set_target_properties(dumb PROPERTIES DEBUG_POSTFIX d)
+set_target_properties(dumb PROPERTIES VERSION ${DUMB_VERSION})
+set_target_properties(dumb PROPERTIES SOVERSION ${DUMB_VERSION_MAJOR})
+
+if(BUILD_ALLEGRO4)
+    add_library(aldmb ${ALLEGRO_SOURCES})
+    set_target_properties(aldmb PROPERTIES DEBUG_POSTFIX d)
+    set_target_properties(aldmb PROPERTIES VERSION ${DUMB_VERSION})
+    set_target_properties(aldmb PROPERTIES SOVERSION ${DUMB_VERSION_MAJOR})
+    list(APPEND DUMB_TARGETS aldmb)
+    list(APPEND INSTALL_HEADERS include/aldumb.h)
+    target_include_directories(aldmb PUBLIC ${ALLEGRO_INCLUDE_DIR})
+    target_link_libraries(aldmb ${ALLEGRO_LIBRARIES} dumb)
+endif()
+
+if(BUILD_EXAMPLES)
+    add_executable(dumbout examples/dumbout.c)
+    add_executable(dumbplay examples/dumbplay.c)
+    set_property(TARGET dumbout PROPERTY C_STANDARD 99)
+    set_property(TARGET dumbplay PROPERTY C_STANDARD 99)
+    if(MINGW)
+        target_link_libraries(dumbplay mingw32)
+    endif()
+
+    target_include_directories(dumbout PRIVATE ${ARGTABLE2_INCLUDE_DIR})
+    target_link_libraries(dumbout ${ARGTABLE2_LIBRARY} m dumb)
+
+    target_include_directories(dumbplay PRIVATE ${ARGTABLE2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR})
+    target_link_libraries(dumbplay ${ARGTABLE2_LIBRARY} ${SDL2_LIBRARY} dumb)
+
+    list(APPEND DUMB_TARGETS "dumbout" "dumbplay")
+endif()
+
+# Make sure the dylib install name path is set on OSX so you can include dumb in app bundles
+IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+    set_target_properties(dumb PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR})
+ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+
+target_link_libraries(dumb m)
+
+install(FILES ${PKG_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+install(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+install(TARGETS dumb ${DUMB_TARGETS}
+    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
--- /dev/null
+++ b/COMPILING.md
@@ -1,0 +1,35 @@
+# Compiling
+
+## 1. CMake
+
+### 1.1. Example
+
+In libdumb project root, run:
+```
+mkdir -p build
+cd build
+cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_ALLEGRO4:BOOL=ON ..
+make
+make install
+```
+
+### 1.2. Steps
+
+1. Create a new temporary build directory and cd into it
+2. Run libdumb cmake file with cmake (eg. `cmake -DCMAKE_INSTALL_PREFIX=/install/dir -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE=Release path/to/dumb/cmake/dir`).
+3. Run make (eg. just `make` or `mingw32-make` or something).
+4. If needed, run make install.
+
+### 1.3. Flags
+
+* `CMAKE_INSTALL_PREFIX` sets the installation path prefix.
+* `CMAKE_BUILD_TYPE` chooses the build type: `Release`, `Debug`, `RelWithDebInfo`, or `MinSizeRel`. Debug libraries will be named `libdumbd`, release libraries `libdumb`. Default is `Release`.
+* `BUILD_SHARED_LIBS` selects whether cmake should build a dynamic (`ON`) or static (`OFF`) library. Default is `OFF`.
+* `BUILD_ALLEGRO4` enables (`ON`) or disables (`OFF`) the optional Allegro 4 support. This requires Allegro 4 installed on the system. Default is `ON`.
+* `BUILD_EXAMPLES` selects example binaries. These example binaries require argtable2 and SDL2 libraries. Default is `ON`.
+* `USE_SSE` enables or disables SSE support. Default is `ON`.
+* You may also need to tell cmake what kind of makefiles to create with the "-G" flag. Eg. for MSYS one would say something like `cmake -G "MSYS Makefiles" .`.
+
+## 2. Visual Studio
+
+TODO
--- /dev/null
+++ b/DUMBFILE_SYSTEM.md
@@ -1,0 +1,226 @@
+Specification of DUMBFILE_SYSTEM
+================================
+
+DUMB is designed filesystem-agnostic, even though the C standard library
+already defines an abstraction over files on a disk. This is useful because
+Allegro 4 and 5 define their own abstractions.
+
+To register your own filesystem abstraction with DUMB, you must create an
+instance of struct `DUMBFILE_SYSTEM`, fill in your own function pointers
+according to the specification below, and call `register_dumbfile_system` on
+your instance.
+
+The header `dumb.h` defines `DUMBFILE_SYSTEM` as a struct of function pointers:
+
+```
+typedef struct DUMBFILE_SYSTEM
+{
+    void *(*open)(const char *filename);
+    int (*skip)(void *f, dumb_off_t n);
+    int (*getc)(void *f);
+    dumb_ssize_t (*getnc)(char *ptr, size_t n, void *f);
+    void (*close)(void *f);
+    int (*seek)(void *f, dumb_off_t n);
+    dumb_off_t (*get_size)(void *f);
+}
+DUMBFILE_SYSTEM;
+```
+
+Here, `dumb_off_t` is a signed integer at least 64 bits wide, it is intended
+to measure file offsets. The return type `dumb_ssize_t` is a signed integer
+exactly as wide as `size_t`, it is intended to store either a `size_t` or a
+negative error code. Both `dumb_*_t` are defined in `dumb.h`.
+
+The function pointers `skip` and `getnc` are optional, i.e., you may set
+some of these to `NULL` in your struct instance. DUMB will then try to
+mimick the missing functions' behavior by calling your `getc` several times.
+If DUMB is built with debugging flags, it will assert that all other
+functions are not `NULL`. In release mode, DUMB will silently fail.
+
+Your non-`NULL` function pointers must conform to the following specification.
+
+
+
+open
+----
+
+```
+void *(*open)(const char *filename);
+```
+
+Open a file for reading.
+
+Arguments:
+
+* `const char *filename`: A normal filename as understood by the operating
+    system. Will be opened for reading.
+
+Returns as `void *`:
+
+* the address of a file handle on successfully opening the file.
+    DUMB will pass this file handle as argument to other functions of
+    the `DUMBFILE_SYSTEM`.
+
+* `NULL` on error during opening the file.
+
+Each file has a *position* internally managed by DUMB. A newly opened file
+has a position of 0. Other functions from the `DUMBFILE_SYSTEM` can move
+this position around.
+
+DUMB allocates memory for the successfully opened file, and will store opaque
+information in that memory, e.g., the DUMB-internal file position. This memory
+be freed when DUMB calls `close` on the file's handle. The memory is separate
+from your own filesystem implementation: You are responsible for supplying the
+data, and DUMB is responsible for storing anything about interpreting that
+data.
+
+
+
+skip
+----
+
+```
+int (*skip)(void *f, dumb_off_t n);
+```
+
+Advance the position in the file.
+
+Arguments:
+
+* `void *f`: A file handle that `open` returned. Guaranteed non-`NULL`.
+
+* `dumb_off_t n`: Number of bytes to advance in the file. DUMB will only
+call this with `n >= 0`. For `n < 0`, the behavior of `skip` is undefined.
+
+Returns as `int`:
+
+* `0` on successfully skipping ahead by `n` bytes.
+
+* `-1` on error.
+
+It is legal to set `skip = NULL` in a `DUMBFILE_SYSTEM`. DUMB will then call
+`getc` a total of `n` times to skip ahead in a file. For speed, it is
+advisable to supply a proper `skip` implementation.
+
+
+
+getc
+----
+
+```
+int (*getc)(void *f);
+```
+
+Read a byte from the file.
+
+Arguments:
+
+* `void *f`: A file handle that `open` returned. Guaranteed non-`NULL`.
+
+Returns as `int`:
+
+* the value of the byte read, on successfully reading one byte.
+
+* `-1` on error.
+
+After a succesful read, DUMB will treat the file as advanced by one byte.
+
+
+
+getnc
+-----
+
+```
+dumb_ssize_t (*getnc)(char *ptr, size_t n, void *f);
+```
+
+Read up to the given number of bytes from the file into a given buffer.
+
+* `char *ptr`: The start of a buffer provided by DUMB.
+
+* `size_t n`: The length of the number of bytes to be read.
+
+* `void *f`: A file handle that `open` returned. Guaranteed non-`NULL`.
+
+Returns as `dumb_ssize_t`:
+
+* the number of bytes successfully read, if it was possible to read at least
+one byte.
+
+* `-1` on error, when it was not possible to read even a single byte.
+
+This function shall bytes from the file `f` and store them in sequence in the
+buffer beginning at `ptr`. It shall read fewer than `n` bytes if end of file
+is encountered before `n` bytes could have been read, otherwise it should read
+`n` bytes.
+
+It is legal to set `skip = NULL` in a `DUMBFILE_SYSTEM`. DUMB will then call
+`getc` a total of `n` times and store the results in its buffer.
+
+
+
+close
+-----
+
+```
+void (*close)(void *f);
+```
+
+Closes a file that has been opened before with `open`.
+
+Arguments:
+
+* `void *f`: A file handle that `open` returned. Guaranteed non-`NULL`.
+
+DUMB will deallocate the memory that it used to interpret the file. You are
+free to treat your resource however you would like: You may deallocate it, or
+keep it around for other things. For example, Allegro 5's implementation
+of `close` takes a void pointer and does nothing with it at all.
+
+
+
+seek
+----
+
+```
+int (*seek)(void *f, dumb_off_t n);
+```
+
+Jump to an arbitrary position in the file.
+
+Arguments:
+
+* `void *f`: A file handle that `open` returned. Guaranteed non-`NULL`.
+
+* `dumb_off_t n`: The position in the file, relative to the beginning.
+    There is no guarantee whether `n >= 0`.
+
+Returns as `int`:
+
+* `0` on successfully seeking in the file.
+
+* `-1` on error.
+
+DUMB will modify its internal position of the file accordingly.
+
+A value of `n < 0` shall set the file into an erroneous state from which no
+bytes can be read.
+
+
+
+get_size
+--------
+
+```
+dumb_off_t (*get_size)(void *f);
+```
+
+Get the length in bytes, i.e., the position after the final byte, of a file.
+
+Arguments:
+
+* `void *f`: A file handle that `open` returned. Guaranteed non-`NULL`.
+
+Returns as `dumb_off_t`:
+
+* the length of the file in bytes.
--- /dev/null
+++ b/LICENSE
@@ -1,0 +1,87 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * licence.txt - Conditions for use of DUMB.          / / \  \
+ *                                                   | <  /   \_
+ * If you do not agree to these terms, please        |  \/ /\   /
+ * do not use DUMB.                                   \_  /  > /
+ *                                                      | \ / /
+ * Information in [brackets] is provided to aid         |  ' /
+ * interpretation of the licence.                        \__/
+ */
+
+
+Dynamic Universal Music Bibliotheque, Version 0.9.3
+
+Copyright (C) 2001-2005 Ben Davis, Robert J Ohannessian and Julien Cugniere
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event shall the authors be held liable for any damages arising from the
+use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim
+   that you wrote the original software. If you use this software in a
+   product, you are requested to acknowledge its use in the product
+   documentation, along with details on where to get an unmodified version of
+   this software, but this is not a strict requirement.
+
+   [Note that the above point asks for a link to DUMB, not just a mention.
+   Googling for DUMB doesn't help much! The URL is "http://dumb.sf.net/".]
+
+   [The link was originally strictly required. This was changed for two
+   reasons. Firstly, if many projects request an acknowledgement, the list of
+   acknowledgements can become quite unmanageable. Secondly, DUMB was placing
+   a restriction on the code using it, preventing people from using the GNU
+   General Public Licence which disallows any such restrictions. See
+   http://www.gnu.org/philosophy/bsd.html for more information on this
+   subject. However, if DUMB plays a significant part in your project, we do
+   urge you to acknowledge its use.]
+
+2. Altered source versions must be plainly marked as such, and must not be
+   misrepresented as being the original software.
+
+3. This notice may not be removed from or altered in any source distribution.
+
+4. If you are using the Program in someone else's bedroom on any Monday at
+   3:05 pm, you are not allowed to modify the Program for ten minutes. [This
+   clause provided by Inphernic; every licence should contain at least one
+   clause, the reasoning behind which is far from obvious.]
+
+5. Users who wish to use DUMB for the specific purpose of playing music are
+   required to feed their dog on every full moon (if deemed appropriate).
+   [This clause provided by Allefant, who couldn't remember what Inphernic's
+   clause was.]
+
+6. No clause in this licence shall prevent this software from being depended
+   upon by a product licensed under the GNU General Public Licence. If such a
+   clause is deemed to exist, Debian, then it shall be respected in spirit as
+   far as possible and all other clauses shall continue to apply in full
+   force.
+
+8. Take the number stated as introducing this clause. Multiply it by two,
+   then subtract four. Now insert a '+' between the two digits and evaluate
+   the resulting sum. Call the result 'x'. If you have not yet concluded that
+   every numbered clause in this licence whose ordinal number is strictly
+   greater than 'x' (with the exception of the present clause) is null and
+   void, Debian, then you are hereby informed that laughter is good for one's
+   health and you are warmly suggested to do it. By the way, Clauses 4, 5 and
+   6 are null and void. Incidentally, I like Kubuntu. The work you guys do is
+   awesome. (Lawyers, on the other hand ...)
+
+We regret that we cannot provide any warranty, not even the implied warranty
+of merchantability or fitness for a particular purpose.
+
+Some files generated or copied by automake, autoconf and friends are
+available in an extra download. These fall under separate licences but are
+all free to distribute. Please check their licences as necessary.
--- /dev/null
+++ b/README.md
@@ -1,0 +1,96 @@
+# Dynamic Universal Music Bibliotheque (libdumb)
+
+     _______         ____    __         ___    ___
+    \    _  \       \    /  \  /       \   \  /   /       '   '  '
+     |  | \  \       |  |    ||         |   \/   |         .      .
+     |  |  |  |      |  |    ||         ||\  /|  |
+     |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+     |  |  |  |      |  |    ||         ||    |  |         .      .
+     |  |_/  /        \  \__//          ||    |  |
+    /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+                                                         /  \
+                                                        / .  \
+                                                       / / \  \
+                                                      | <  /   \_
+                                                      |  \/ /\   /
+                                                       \_  /  > /
+                                                         | \ / /
+                                                         |  ' /
+                                                          \__/
+
+
+
+## Introduction
+
+DUMB is a module audio renderer library. It reads module files and
+outputs audio that can be dumped to the actual audio playback library.
+
+This is a fork of the original dumb (http://dumb.sf.net/) by Ben Davis.
+
+## Features
+
+- Supports playback of the following module formats. The tracker software or
+  library the format is known for is given in parentheses. This does not mean
+  that DUMB does not support files created by other trackers provided that they
+  output files in one of those formats.
+
+   * IT (Impulse Tracker)
+   * XM (Fasttracker II)
+   * MOD (Ultimate SoundTracker, ProTracker)
+   * STM (Scream Tracker)
+   * S3M (Scream Tracker 3)
+   * 669 (Composer 669)
+   * AMF Asylum Music Format
+   * AMF Digital Sound and Music Interface Advanced Music Format
+   * DSM Digital Sound Interface Kit module format
+   * MTM (MultiTracker)
+   * OKT (Oktalyzer)
+   * PSM (Protracker Studio)
+     Both the older PSM16 and the newer PSM format is supported.
+   * PTM (PolyTracker)
+   * RIFF AM/AMFF (Galaxy Music System internal format)
+
+- Audio generated can be used in any way; DUMB does not necessarily send it
+  straight to a sound output system
+
+- Portable
+
+- Faithful to the original trackers, especially IT; if it plays a module
+  wrongly, it is considered a bug
+
+- Accurate support for low-pass resonant filters for IT files
+
+- Very accurate timing and pitching; completely deterministic playback
+
+- Click removal
+
+- Six resampling quality settings: aliasing, aliasing with bandwidth limiting,
+  linear interpolation, linear interpolation with bandwidth limiting, cubic
+  interpolation, and a compile-time-configurable fast sinc resampler
+
+- Number of samples playing at once can be limited to reduce processor usage,
+  but samples will come back in when other louder ones stop
+
+- Option to take longer loading but seek fast to any point before the music
+  first loops (seeking time increases beyond this point)
+
+- All notes will be present and correct even if a module's playback is started
+  in the middle
+
+- Optional Allegro 4 or Allegro 5 integration support
+
+- Facility to embed music files in other files (e.g. Allegro datafiles)
+
+
+## Installation
+
+Currently you need to compile libdumb yourself. For more details, please see
+the file [COMPILING.md](COMPILING.md).
+
+## License
+
+See [LICENSE](LICENSE) for license details.
+
+## Contributing
+
+Bugs, feature requests and patches can be submitted at https://github.com/kode54/dumb/.
--- /dev/null
+++ b/UPDATING_YOUR_PROJECTS.md
@@ -1,0 +1,16 @@
+# Updating your projects
+
+## Transition from 0.9.3 to 2.0.0 and beyond
+
+### The Basics
+
+* Build your DUMB-using project with warnings that show function pointer mismatches. Treat these warnings extremely carefully, most of them imply porting work.
+* `DUMBFILE_SYSTEM` needs 7 pointers instead of 5, and the signatures have changed. Look in include/dumb.h for a quick overview, and in DUMBFILE_SYSTEM.md for a more complete spec. Notable changes include seeking support, file length reporting, and using 64-bit safe seek offsets and file sizes.
+* Some functions return `dumb_off_t` instead of `long`. Most of that is backwards compatible unless you have function pointers to these.
+
+### Shortcomings of the 2.0 API
+
+* `DUH.length` is `dumb_off_t`, but this is not the clearest type. It's good that this is 64-bit, but it doesn't measure disk file offsets. `length` measures the total time of the DUH in 65536-ths of a second, where a DUH is a format-agnostic abstraction of a tracked song.
+* A sigrenderer is like a slider, or iterator, that moves along a DUH and decodes the music. The *position* of a sigrenderer is stored in `pos`, and this is exposed in the API as `long`. It should ideally have the same type as `DUH.length`.
+
+What's the worst impact of these shortcomings? If your `long` is 32-bit (should only happen on Windows when targeting 32-bit processors), your `pos` might be broken 2^15 seconds into a song, which is about 9 hours. It's really minimal impact, and this bug was already in DUMB 0.9.3. As of DUMB 2.0.0, this is even less of an impact, since the newer timekeeping arrays will automatically keep the `pos` within the actual detected length of a song, dropping back down to 0 again if it loops completely, or slightly higher if the loop is partway into the song. It's not perfect, but at least I tried, right?
--- /dev/null
+++ b/cmake-scripts/FindAllegro4.cmake
@@ -1,0 +1,41 @@
+# - Find allegro
+# Find the native ALLEGRO includes and library
+#
+# ALLEGRO_INCLUDE_DIR - where to find allegro.h, etc.
+# ALLEGRO_LIBRARIES - List of libraries when using allegro.
+# ALLEGRO_FOUND - True if allegro found.
+
+FIND_PATH(ALLEGRO_INCLUDE_DIR allegro.h
+/usr/local/include
+/usr/include
+$ENV{MINGDIR}/include
+)
+
+if(UNIX AND NOT CYGWIN)
+    exec_program(allegro-config ARGS --libs OUTPUT_VARIABLE ALLEGRO_LIBRARY)
+else(UNIX AND NOT CYGWIN)
+    SET(ALLEGRO_NAMES alleg alleglib alleg41 alleg42 allegdll)
+    FIND_LIBRARY(ALLEGRO_LIBRARY
+        NAMES ${ALLEGRO_NAMES}
+        PATHS /usr/lib /usr/local/lib $ENV{MINGDIR}/lib)
+endif(UNIX AND NOT CYGWIN)
+
+IF (ALLEGRO_INCLUDE_DIR AND ALLEGRO_LIBRARY)
+    SET(ALLEGRO_FOUND TRUE)
+    SET( ALLEGRO_LIBRARIES ${ALLEGRO_LIBRARY} )
+ELSE (ALLEGRO_INCLUDE_DIR AND ALLEGRO_LIBRARY)
+    SET(ALLEGRO_FOUND FALSE)
+    SET( ALLEGRO_LIBRARIES )
+ENDIF (ALLEGRO_INCLUDE_DIR AND ALLEGRO_LIBRARY)
+
+IF (ALLEGRO_FOUND)
+    MESSAGE(STATUS "Found Allegro: ${ALLEGRO_LIBRARY}")
+ELSE (ALLEGRO_FOUND)
+    MESSAGE(STATUS "Looked for Allegro libraries named ${ALLEGRO_NAMES}.")
+    MESSAGE(FATAL_ERROR "Could NOT find Allegro library")
+ENDIF (ALLEGRO_FOUND)
+
+MARK_AS_ADVANCED(
+ALLEGRO_LIBRARY
+ALLEGRO_INCLUDE_DIR
+)
--- /dev/null
+++ b/cmake-scripts/FindSDL2.cmake
@@ -1,0 +1,42 @@
+
+FIND_PACKAGE(Threads)
+
+SET(SDL2_SEARCH_PATHS
+    /usr/local/
+    /usr/
+)
+
+FIND_PATH(SDL2_INCLUDE_DIR SDL2/SDL.h
+    HINTS
+    PATH_SUFFIXES include
+    PATHS ${SDL2_SEARCH_PATHS}
+)
+
+FIND_LIBRARY(SDL2_LIBRARY
+    NAMES SDL2
+    HINTS
+    PATH_SUFFIXES lib64 lib
+    PATHS ${SDL2_SEARCH_PATHS}
+)
+
+IF(MINGW)
+    FIND_LIBRARY(SDL2MAIN_LIBRARY
+        NAMES SDL2main
+        HINTS
+        PATH_SUFFIXES lib64 lib
+        PATHS ${SDL2_SEARCH_PATHS}
+    )
+ELSE()
+    SET(SDL2MAIN_LIBRARY "")
+ENDIF()
+
+IF(SDL2_INCLUDE_DIR AND SDL2_LIBRARY)
+   SET(SDL2_FOUND TRUE)
+ENDIF (SDL2_INCLUDE_DIR AND SDL2_LIBRARY)
+
+IF(SDL2_FOUND)
+    SET(SDL2_LIBRARY ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
+    MESSAGE(STATUS "Found SDL2: ${SDL2_LIBRARY}")
+ELSE(SDL2_FOUND)
+    MESSAGE(WARNING "Could not find SDL2")
+ENDIF(SDL2_FOUND)
\ No newline at end of file
--- /dev/null
+++ b/cmake-scripts/Findargtable2.cmake
@@ -1,0 +1,27 @@
+SET(ARGTABLE2_SEARCH_PATHS
+        /usr/local
+        /usr
+        /opt
+)
+
+FIND_PATH(ARGTABLE2_INCLUDE_DIR argtable2.h
+        HINTS
+        PATH_SUFFIXES include
+        PATHS ${ARGTABLE2_SEARCH_PATHS}
+)
+FIND_LIBRARY(ARGTABLE2_LIBRARY argtable2
+        HINTS
+        PATH_SUFFIXES lib64 lib
+        PATHS ${ARGTABLE2_SEARCH_PATHS}
+)
+
+if(ARGTABLE2_INCLUDE_DIR AND ARGTABLE2_LIBRARY)
+    set(ARGTABLE2_FOUND TRUE)
+endif(ARGTABLE2_INCLUDE_DIR AND ARGTABLE2_LIBRARY)
+
+
+if(ARGTABLE2_FOUND)
+    message(STATUS "Found Argtable2: ${ARGTABLE2_LIBRARY}")
+else(ARGTABLE2_FOUND)
+    message(WARNING "Could not find Argtable2")
+endif(ARGTABLE2_FOUND)
\ No newline at end of file
--- a/dumb/cmake/CMakeLists.txt
+++ /dev/null
@@ -1,149 +1,0 @@
-cmake_minimum_required(VERSION 3.1)
-project(libdumb C)
-
-set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-scripts)
-
-option(BUILD_EXAMPLES "Build example binaries" ON)
-
-set(CMAKE_C_FLAGS "-Wall -DDUMB_DECLARE_DEPRECATED -D_USE_SSE -msse -Wno-unused-variable -Wno-unused-but-set-variable")
-set(CMAKE_C_FLAGS_DEBUG "-ggdb -DDEBUGMODE=1 -D_DEBUG")
-set(CMAKE_C_FLAGS_RELEASE "-ffast-math -O2 -DNDEBUG")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-ffast-math -g -O2 -DNDEBUG")
-set(CMAKE_C_FLAGS_MINSIZEREL "-ffast-math -Os -DNDEBUG")
-
-link_directories(${CMAKE_CURRENT_BINARY_DIR})
-include_directories(../include/)
-
-if(BUILD_EXAMPLES)
-    find_package(argtable2)
-    find_package(SDL2)
-else()
-    message(STATUS "Not building examples")
-endif()
-
-SET(SOURCES
-    ../src/core/unload.c
-    ../src/core/rendsig.c
-    ../src/core/rendduh.c
-    ../src/core/register.c
-    ../src/core/readduh.c
-    ../src/core/rawsig.c
-    ../src/core/makeduh.c
-    ../src/core/loadduh.c
-    ../src/core/dumbfile.c
-    ../src/core/duhtag.c
-    ../src/core/duhlen.c
-    ../src/core/atexit.c
-    ../src/helpers/stdfile.c
-    ../src/helpers/silence.c
-    ../src/helpers/sampbuf.c
-    ../src/helpers/riff.c
-    ../src/helpers/resample.c
-    ../src/helpers/memfile.c
-    ../src/helpers/clickrem.c
-    ../src/helpers/barray.c
-    ../src/helpers/tarray.c
-    ../src/it/xmeffect.c
-    ../src/it/readxm2.c
-    ../src/it/readxm.c
-    ../src/it/readstm2.c
-    ../src/it/readstm.c
-    ../src/it/reads3m2.c
-    ../src/it/reads3m.c
-    ../src/it/readriff.c
-    ../src/it/readptm.c
-    ../src/it/readpsm.c
-    ../src/it/readoldpsm.c
-    ../src/it/readokt2.c
-    ../src/it/readokt.c
-    ../src/it/readmtm.c
-    ../src/it/readmod2.c
-    ../src/it/readmod.c
-    ../src/it/readdsmf.c
-    ../src/it/readasy.c
-    ../src/it/readamf2.c
-    ../src/it/readamf.c
-    ../src/it/readam.c
-    ../src/it/read6692.c
-    ../src/it/read669.c
-    ../src/it/ptmeffect.c
-    ../src/it/loadxm2.c
-    ../src/it/loadxm.c
-    ../src/it/loadstm2.c
-    ../src/it/loadstm.c
-    ../src/it/loads3m2.c
-    ../src/it/loads3m.c
-    ../src/it/loadriff2.c
-    ../src/it/loadriff.c
-    ../src/it/loadptm2.c
-    ../src/it/loadptm.c
-    ../src/it/loadpsm2.c
-    ../src/it/loadpsm.c
-    ../src/it/loadoldpsm2.c
-    ../src/it/loadoldpsm.c
-    ../src/it/loadokt2.c
-    ../src/it/loadokt.c
-    ../src/it/loadmtm2.c
-    ../src/it/loadmtm.c
-    ../src/it/loadmod2.c
-    ../src/it/loadmod.c
-    ../src/it/loadasy2.c
-    ../src/it/loadasy.c
-    ../src/it/loadamf2.c
-    ../src/it/loadamf.c
-    ../src/it/load6692.c
-    ../src/it/load669.c
-    ../src/it/itunload.c
-    ../src/it/itrender.c
-    ../src/it/itread2.c
-    ../src/it/itread.c
-    ../src/it/itorder.c
-    ../src/it/itmisc.c
-    ../src/it/itload2.c
-    ../src/it/itload.c
-    ../src/it/readany.c
-    ../src/it/loadany2.c
-    ../src/it/loadany.c
-    ../src/it/readany2.c
-    ../src/helpers/resampler.c
-    ../src/helpers/lpc.c
-)
-
-set(INSTALL_HEADERS
-    ../include/dumb.h
-)
-
-add_library(dumb ${SOURCES})
-set_target_properties(dumb PROPERTIES DEBUG_POSTFIX d)
-
-set(EXAMPLE_TARGETS "")
-
-if(BUILD_EXAMPLES)
-    add_executable(dumbout ../examples/dumbout.c)
-    add_executable(dumbplay ../examples/dumbplay.c)
-    set_property(TARGET dumbout PROPERTY C_STANDARD 99)
-    set_property(TARGET dumbplay PROPERTY C_STANDARD 99)
-    if(MINGW)
-        target_link_libraries(dumbplay mingw32)
-    endif()
-
-    target_link_libraries(dumbout ${ARGTABLE2_LIBRARY} m dumb)
-    target_link_libraries(dumbplay ${ARGTABLE2_LIBRARY} ${SDL2_LIBRARY} dumb)
-
-    include_directories(${ARGTABLE2_INCLUDE_DIR} ${SDL2_INCLUDE_DIR} "../examples/")
-    set(EXAMPLE_TARGETS ${EXAMPLE_TARGETS} "dumbout" "dumbplay")
-endif()
-
-# Make sure the dylib install name path is set on OSX so you can include dumb in app bundles
-IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
-    set_target_properties(dumb PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
-ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
-
-target_link_libraries(dumb m)
-
-INSTALL(FILES ${INSTALL_HEADERS} DESTINATION include/)
-INSTALL(TARGETS dumb ${EXAMPLE_TARGETS}
-    RUNTIME DESTINATION bin
-    LIBRARY DESTINATION lib${LIB_SUFFIX}
-    ARCHIVE DESTINATION lib${LIB_SUFFIX}
-)
--- a/dumb/cmake/cmake-scripts/FindSDL2.cmake
+++ /dev/null
@@ -1,42 +1,0 @@
-
-FIND_PACKAGE(Threads)
-
-SET(SDL2_SEARCH_PATHS
-    /usr/local/
-    /usr/
-)
-
-FIND_PATH(SDL2_INCLUDE_DIR SDL2/SDL.h
-    HINTS
-    PATH_SUFFIXES include
-    PATHS ${SDL2_SEARCH_PATHS}
-)
-
-FIND_LIBRARY(SDL2_LIBRARY
-    NAMES SDL2
-    HINTS
-    PATH_SUFFIXES lib64 lib
-    PATHS ${SDL2_SEARCH_PATHS}
-)
-
-IF(MINGW)
-    FIND_LIBRARY(SDL2MAIN_LIBRARY
-        NAMES SDL2main
-        HINTS
-        PATH_SUFFIXES lib64 lib
-        PATHS ${SDL2_SEARCH_PATHS}
-    )
-ELSE()
-    SET(SDL2MAIN_LIBRARY "")
-ENDIF()
-
-IF(SDL2_INCLUDE_DIR AND SDL2_LIBRARY)
-   SET(SDL2_FOUND TRUE)
-ENDIF (SDL2_INCLUDE_DIR AND SDL2_LIBRARY)
-
-IF(SDL2_FOUND)
-    SET(SDL2_LIBRARY ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
-    MESSAGE(STATUS "Found SDL2: ${SDL2_LIBRARY}")
-ELSE(SDL2_FOUND)
-    MESSAGE(WARNING "Could not find SDL2")
-ENDIF(SDL2_FOUND)
\ No newline at end of file
--- a/dumb/cmake/cmake-scripts/Findargtable2.cmake
+++ /dev/null
@@ -1,27 +1,0 @@
-SET(ARGTABLE2_SEARCH_PATHS
-        /usr/local
-        /usr
-        /opt
-)
-
-FIND_PATH(ARGTABLE2_INCLUDE_DIR argtable2.h
-        HINTS
-        PATH_SUFFIXES include
-        PATHS ${ARGTABLE2_SEARCH_PATHS}
-)
-FIND_LIBRARY(ARGTABLE2_LIBRARY argtable2
-        HINTS
-        PATH_SUFFIXES lib64 lib
-        PATHS ${ARGTABLE2_SEARCH_PATHS}
-)
-
-if(ARGTABLE2_INCLUDE_DIR AND ARGTABLE2_LIBRARY)
-    set(ARGTABLE2_FOUND TRUE)
-endif(ARGTABLE2_INCLUDE_DIR AND ARGTABLE2_LIBRARY)
-
-
-if(ARGTABLE2_FOUND)
-    message(STATUS "Found Argtable2: ${ARGTABLE2_LIBRARY}")
-else(ARGTABLE2_FOUND)
-    message(WARNING "Could not find Argtable2")
-endif(ARGTABLE2_FOUND)
\ No newline at end of file
--- a/dumb/cmake/readme.txt
+++ /dev/null
@@ -1,31 +1,0 @@
-Howto build libdumb with cmake
-==============================
-
-A quick example
----------------
-
-In libdumb cmake directory (dumb/cmake/), run:
-```
-mkdir -p build
-cd build
-cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS:BOOL=ON ..
-make
-make install
-```
-
-Steps
------
-
-1. Create a new temporary build directory and cd into it
-2. Run libdumb cmake file with cmake (eg. `cmake -DCMAKE_INSTALL_PREFIX=/install/dir -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE=Release path/to/dumb/cmake/dir`).
-3. Run make (eg. just `make` or `mingw32-make` or something).
-4. If needed, run make install.
-
-Flags
------
-
-* CMAKE_INSTALL_PREFIX sets the installation path prefix
-* CMAKE_BUILD_TYPE sets the build type (eg. Release, Debug, RelWithDebInfo, MinSizeRel). Debug libraries will be named libdumbd, release libraries libdumb.
-* BUILD_SHARED_LIBS selects whether cmake should build dynamic or static library. On by default. (On=shared, OFF=static)
-* BUILD_EXAMPLES selects example binaries. Note that example binaries require argtable2 and SDL2 libraries. On by default.
-* You may also need to tell cmake what kind of makefiles to create with the "-G" flag. Eg. for MSYS one would say something like `cmake -G "MSYS Makefiles" .`.
--- a/dumb/examples/dumbout.c
+++ /dev/null
@@ -1,275 +1,0 @@
-#include <argtable2.h>
-#include <dumb.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-#include <math.h>
-
-static const int endian_test = 1;
-#define is_bigendian() ((*(char*)&endian_test) == 0)
-
-enum ENDIANNESS {
-    DUMB_LITTLE_ENDIAN = 0,
-    DUMB_BIG_ENDIAN
-};
-
-typedef struct {
-    DUH_SIGRENDERER *renderer;
-    DUH *src;
-    FILE *dst;
-    float delta;
-    int bufsize;
-    bool is_stdout;
-} streamer_t;
-
-typedef struct {
-    int bits;
-    int endianness;
-    int is_unsigned;
-    int freq;
-    int quality;
-    int n_channels;
-    float volume;
-    float delay;
-    const char *input;
-    char *output;
-} settings_t;
-
-
-int main(int argc, char *argv[]) {
-    int retcode = 1;
-    int nerrors = 0;
-    streamer_t streamer;
-    settings_t settings;
-    memset(&streamer, 0, sizeof(streamer_t));
-    memset(&settings, 0, sizeof(settings_t));
-
-    // Defaults
-    settings.freq = 44100;
-    settings.n_channels = 2;
-    settings.bits = 16;
-    settings.endianness = DUMB_LITTLE_ENDIAN;
-    settings.is_unsigned = false;
-    settings.volume = 1.0f;
-    settings.delay = 0.0f;
-    settings.quality = DUMB_RQ_CUBIC;
-
-    // commandline argument parser options
-    struct arg_lit *arg_help = arg_lit0("h", "help", "print this help and exits");
-    struct arg_dbl *arg_delay = arg_dbl0("d", "delay", "<delay>", "sets the initial delay in seconds (0.0 to 64.0, default 0.0)");
-    struct arg_dbl *arg_volume = arg_dbl0("v", "volume", "<volume", "sets the output volume (-8.0 to +8.0, default 1.0)");
-    struct arg_int *arg_samplerate = arg_int0("s", "samplerate", "<freq>", "sets the sampling rate (default 44100)");
-    struct arg_int *arg_quality = arg_int0("r", "quality", "<quality>", "specify the resampling quality to use");
-    struct arg_lit *arg_mono = arg_lit0("m", "mono", "generate mono output instead of stereo");
-    struct arg_lit *arg_bigendian = arg_lit0("b", "bigendian", "generate big-endian data instead of little-endian");
-    struct arg_lit *arg_eight = arg_lit0("8", "eight", "generate 8-bit instead of 16-bit");
-    struct arg_lit *arg_unsigned = arg_lit0("u", "unsigned", "generate unsigned output instead of signed");
-    struct arg_file *arg_output = arg_file0("o", "output", "<file>", "output file");
-    struct arg_file *arg_input = arg_file1(NULL, NULL, "<file>", "input module file");
-    struct arg_end *arg_fend = arg_end(20);
-    void* argtable[] = {arg_help, arg_input, arg_output, arg_delay, arg_volume, arg_samplerate, arg_quality,
-                        arg_mono, arg_bigendian, arg_eight, arg_unsigned, arg_fend};
-    const char* progname = "dumbout";
-
-    // Make sure everything got allocated
-    if(arg_nullcheck(argtable) != 0) {
-        fprintf(stderr, "%s: insufficient memory\n", progname);
-        goto exit_0;
-    }
-
-    // Parse inputs
-    nerrors = arg_parse(argc, argv, argtable);
-
-    // Handle help
-    if(arg_help->count > 0) {
-        fprintf(stderr, "Usage: %s", progname);
-        arg_print_syntax(stderr, argtable, "\n");
-        fprintf(stderr, "\nArguments:\n");
-        arg_print_glossary(stderr, argtable, "%-25s %s\n");
-        goto exit_0;
-    }
-
-    // Handle errors
-    if(nerrors > 0) {
-        arg_print_errors(stderr, arg_fend, progname);
-        fprintf(stderr, "Try '%s --help' for more information.\n", progname);
-        goto exit_0;
-    }
-
-    // Get input and output filenames
-    settings.input = arg_input->filename[0];
-    if(arg_output->count > 0) {
-        settings.output = malloc(strlen(arg_output->filename[0])+1);
-        strcpy(settings.output, arg_output->filename[0]);
-    } else {
-        settings.output = malloc(strlen(arg_output->basename[0])+5);
-        sprintf(settings.output, "%s%s", arg_output->basename[0], ".pcm");
-    }
-
-    // Handle the switch options
-    if(arg_bigendian->count > 0) { settings.endianness = DUMB_BIG_ENDIAN; }
-    if(arg_eight->count > 0) { settings.bits = 8; }
-    if(arg_unsigned->count > 0) { settings.is_unsigned = true; }
-    if(arg_mono->count > 0) { settings.n_channels = 1; }
-
-    if(arg_delay->count > 0) {
-        settings.delay = arg_delay->dval[0];
-        if(settings.delay < 0.0f || settings.delay >= 64.0f) {
-            fprintf(stderr, "Initial delay must be between 0.0f and 64.0f.\n");
-            goto exit_0;
-        }
-    }
-
-    if(arg_volume->count > 0) {
-        settings.volume = arg_volume->dval[0];
-        if(settings.volume < -8.0f || settings.volume > 8.0f) {
-            fprintf(stderr, "Volume must be between -8.0f and 8.0f.\n");
-            goto exit_0;
-        }
-    }
-
-    if(arg_samplerate->count > 0) {
-        settings.freq = arg_samplerate->ival[0];
-        if(settings.freq < 1 || settings.freq > 96000) {
-            fprintf(stderr, "Sampling rate must be between 1 and 96000.\n");
-            goto exit_0;
-        }
-    }
-
-    if(arg_quality->count > 0) {
-        settings.quality = arg_quality->ival[0];
-        if(settings.quality < 0 || settings.quality >= DUMB_RQ_N_LEVELS) {
-            fprintf(stderr, "Quality must be between %d and %d.\n", 0, DUMB_RQ_N_LEVELS-1);
-            goto exit_0;
-        }
-    }
-
-    // dumb settings stuff
-    dumb_register_stdfiles();
-
-    // Load source
-    streamer.src = dumb_load_any(settings.input, 0, 0);
-    if(!streamer.src) {
-        fprintf(stderr, "Unable to load file %s for playback!\n", settings.input);
-        goto exit_0;
-    }
-
-    // Set up playback
-    streamer.renderer = duh_start_sigrenderer(streamer.src, 0, settings.n_channels, 0);
-    streamer.delta = 65536.0f / settings.freq;
-    streamer.bufsize = 4096 * (settings.bits / 8) * settings.n_channels;
-
-    // Stop producing samples on module end
-    DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(streamer.renderer);
-    dumb_it_set_loop_callback(itsr, &dumb_it_callback_terminate, NULL);
-    dumb_it_set_xm_speed_zero_callback(itsr, &dumb_it_callback_terminate, NULL);
-    dumb_it_set_resampling_quality(itsr, settings.quality);
-
-    // Open output
-    if(strcmp(settings.output, "-") == 0) {
-        streamer.dst = stdout;
-        streamer.is_stdout = true;
-    } else {
-        streamer.dst = fopen(settings.output, "wb");
-        streamer.is_stdout = false;
-        if(!streamer.dst) {
-            fprintf(stderr, "Could not open output file %s!", settings.output);
-            goto exit_1;
-        }
-    }
-
-    bool run = true;
-    char *buffer = malloc(streamer.bufsize);
-    int read_samples;
-    int read_bytes;
-
-    // If output endianness is different than machine endianness, and output is 16 bits, reorder bytes.
-    int switch_endianness = ((is_bigendian() && settings.endianness == DUMB_LITTLE_ENDIAN) ||
-                            (!is_bigendian() && settings.endianness == DUMB_BIG_ENDIAN));
-
-    // Write the initial delay to the file if one was requested.
-    long d = ((long)floor(settings.delay * settings.freq + 0.5f)) * settings.n_channels * (settings.bits / 8);
-    if(d) {
-        // Fill the buffer with silence. Remember to take into account endianness
-        if(settings.is_unsigned) {
-            if(settings.bits == 16) {
-                if(settings.endianness == DUMB_BIG_ENDIAN) {
-                    // Unsigned 16bits big endian
-                    for(int i = 0; i < streamer.bufsize; i += 2) {
-                        buffer[i  ] = (char)0x80;
-                        buffer[i+1] = (char)0x00;
-                    }
-                } else {
-                    // Unsigned 16bits little endian
-                    for(int i = 0; i < streamer.bufsize; i += 2) {
-                        buffer[i  ] = (char)0x00;
-                        buffer[i+1] = (char)0x80;
-                    }
-                }
-            } else {
-                // Unsigned 8 bits
-                memset(buffer, 0x80, streamer.bufsize);
-            }
-        } else {
-            // Signed
-            memset(buffer, 0, streamer.bufsize);
-        }
-
-        while(d >= streamer.bufsize) {
-            fwrite(buffer, 1, streamer.bufsize, streamer.dst);
-            d -= streamer.bufsize;
-        }
-        if(d) {
-            fwrite(buffer, 1, d, streamer.dst);
-        }
-    }
-
-    // Loop until we have nothing to loop through. Dumb will stop giving out bytes when the file is done.
-    while(run) {
-        read_samples = duh_render(streamer.renderer,
-                                  settings.bits,
-                                  (int)settings.is_unsigned,
-                                  settings.volume,
-                                  streamer.delta,
-                                  4096, buffer);
-        read_bytes = read_samples * (settings.bits / 8) * settings.n_channels;
-
-        // switch endianness if required
-        if(switch_endianness && settings.bits == 16) {
-            char tmp;
-            for(int i = 0; i < read_bytes / 2; i++) {
-                tmp = buffer[i*2+0];
-                buffer[i*2+0] = buffer[i*2+1];
-                buffer[i*2+1] = tmp;
-            }
-        }
-
-        // Write to output stream and flush if it happens to be stdout
-        fwrite(buffer, 1, read_bytes, streamer.dst);
-        if(streamer.is_stdout) {
-            fflush(streamer.dst);
-        }
-        run = (read_samples > 0);
-    }
-    free(buffer);
-
-    // We made it this far without crashing, so let's just exit with no error :)
-    retcode = 0;
-
-    if(!streamer.is_stdout && streamer.dst) {
-        fclose(streamer.dst);
-    }
-
-exit_1:
-    if(streamer.renderer) {
-        duh_end_sigrenderer(streamer.renderer);
-    }
-    if(streamer.src) {
-        unload_duh(streamer.src);
-    }
-
-exit_0:
-    free(settings.output);
-    arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0]));
-    return retcode;
-}
--- a/dumb/examples/dumbplay.c
+++ /dev/null
@@ -1,284 +1,0 @@
-#include <argtable2.h>
-#include <dumb.h>
-#include <stdint.h>
-#include <string.h>
-#include <signal.h>
-#include <stdbool.h>
-#include <SDL2/SDL.h>
-
-// How many samples we should handle per callback call
-#define SAMPLES 8192
-
-// How many chars wide the progress bar is
-#define PROGRESSBAR_LENGTH 25
-
-typedef struct {
-    // Library contexts
-    DUH_SIGRENDERER *renderer;
-    DUH *src;
-    SDL_AudioDeviceID dev;
-
-    // Runtime vars
-    float delta;
-    int spos;  // Samples read
-    int ssize;  // Total samples available
-    int sbytes;  // bytes per sample
-    bool ended;
-
-    // Config switches
-    int bits;
-    int freq;
-    int quality;
-    int n_channels;
-    bool no_progress;
-    float volume;
-    const char *input;
-} streamer_t;
-
-// Set to true if SIGTERM or SIGINT is caught
-static bool stop_signal = false;
-
-// Simple signal handler function
-static void sig_fn(int signo) {
-    stop_signal = true;
-}
-
-// This is called from SDL2, and should read data from a source and hand it over to SDL2 via the stream buffer.
-void stream_audio(void* userdata, Uint8* stream, int len) {
-    streamer_t *streamer = (streamer_t*)userdata;
-
-    // Read samples from libdumb save them to the SDL buffer. Note that we are reading SAMPLES, not bytes!
-    int r_samples = len / streamer->sbytes;
-    int got = duh_render(streamer->renderer, streamer->bits, 0, streamer->volume, streamer->delta, r_samples, stream);
-    if(got == 0) {
-        streamer->ended = true;
-    }
-
-    // Get current position from libdumb for the playback display. If we get position that is 0, it probably
-    // means that the song ended and duh_sigrenderer_get_position points to the start of the file.
-    streamer->spos = duh_sigrenderer_get_position(streamer->renderer);
-    if(streamer->spos == 0) {
-        streamer->spos = streamer->ssize;
-    }
-}
-
-// Simply formats timestamp to string
-void format_ms(int ticks) {
-    int total_seconds = ticks / 1000;
-    int hours = 0;
-    int minutes = 0;
-    int seconds = 0;
-
-    // Calculate hours, minutes and seconds
-    if(total_seconds > 3600) {
-        hours = total_seconds / 3600;
-        total_seconds = total_seconds % 3600;
-    }
-    if(total_seconds > 60) {
-        minutes = total_seconds / 60;
-        total_seconds = total_seconds % 60;
-    }
-    seconds = total_seconds;
-
-    // If necessary, show hours. Otherwise only minutes and seconds.
-    if(hours > 0) {
-        printf("%02d:%02d:%02d", hours, minutes, seconds);
-    } else {
-        printf("%02d:%02d", minutes, seconds);
-    }
-}
-
-// Shows progressbar and time played
-void show_progress(int width, float progress, int ticks) {
-    int d = progress * width;
-    printf("%3d%% [", (int)(progress*100));
-    for(int x = 0; x < d; x++) {
-        printf("=");
-    }
-    for(int x = 0; x < (width-d); x++) {
-        printf(" ");
-    }
-    printf("] ");
-    format_ms(ticks);
-    printf("\r");
-    fflush(stdout);
-}
-
-int main(int argc, char *argv[]) {
-    int retcode = 1;
-    int nerrors = 0;
-    streamer_t streamer;
-    memset(&streamer, 0, sizeof(streamer_t));
-
-    // Signal handlers
-    signal(SIGINT, sig_fn);
-    signal(SIGTERM, sig_fn);    
-
-    // Initialize SDL2
-    if(SDL_Init(SDL_INIT_AUDIO) != 0) {
-        fprintf(stderr, "%s\n", SDL_GetError());
-        return 1;
-    }
-
-    // Defaults
-    streamer.freq = 44100;
-    streamer.n_channels = 2;
-    streamer.bits = 16;
-    streamer.volume = 1.0f;
-    streamer.quality = DUMB_RQ_CUBIC;
-
-    // commandline argument parser options
-    struct arg_lit *arg_help = arg_lit0("h", "help", "print this help and exits");
-    struct arg_dbl *arg_volume = arg_dbl0("v", "volume", "<volume", "sets the output volume (-8.0 to +8.0, default 1.0)");
-    struct arg_int *arg_samplerate = arg_int0("s", "samplerate", "<freq>", "sets the sampling rate (default 44100)");
-    struct arg_int *arg_quality = arg_int0("r", "quality", "<quality>", "specify the resampling quality to use");
-    struct arg_lit *arg_mono = arg_lit0("m", "mono", "generate mono output instead of stereo");
-    struct arg_lit *arg_eight = arg_lit0("8", "eight", "generate 8-bit instead of 16-bit");
-    struct arg_lit *arg_noprogress = arg_lit0("n", "noprogress", "hide progress bar");
-    struct arg_file *arg_output = arg_file0("o", "output", "<file>", "output file");
-    struct arg_file *arg_input = arg_file1(NULL, NULL, "<file>", "input module file");
-    struct arg_end *arg_fend = arg_end(20);
-    void* argtable[] = {arg_help, arg_input, arg_volume, arg_samplerate, arg_quality, arg_mono, arg_eight, arg_noprogress, arg_fend};
-    const char* progname = "dumbplay";
-
-    // Make sure everything got allocated
-    if(arg_nullcheck(argtable) != 0) {
-        fprintf(stderr, "%s: insufficient memory\n", progname);
-        goto exit_0;
-    }
-
-    // Parse inputs
-    nerrors = arg_parse(argc, argv, argtable);
-
-    // Handle help
-    if(arg_help->count > 0) {
-        fprintf(stderr, "Usage: %s", progname);
-        arg_print_syntax(stderr, argtable, "\n");
-        fprintf(stderr, "\nArguments:\n");
-        arg_print_glossary(stderr, argtable, "%-25s %s\n");
-        goto exit_0;
-    }
-
-    // Handle libargtable errors
-    if(nerrors > 0) {
-        arg_print_errors(stderr, arg_fend, progname);
-        fprintf(stderr, "Try '%s --help' for more information.\n", progname);
-        goto exit_0;
-    }
-
-    // Handle the switch options
-    streamer.input = arg_input->filename[0];
-    if(arg_eight->count > 0) { streamer.bits = 8; }
-    if(arg_mono->count > 0) { streamer.n_channels = 1; }
-    if(arg_noprogress->count > 0) { streamer.no_progress = true; }
-
-    if(arg_volume->count > 0) {
-        streamer.volume = arg_volume->dval[0];
-        if(streamer.volume < -8.0f || streamer.volume > 8.0f) {
-            fprintf(stderr, "Volume must be between -8.0f and 8.0f.\n");
-            goto exit_0;
-        }
-    }
-
-    if(arg_samplerate->count > 0) {
-        streamer.freq = arg_samplerate->ival[0];
-        if(streamer.freq < 1 || streamer.freq > 96000) {
-            fprintf(stderr, "Sampling rate must be between 1 and 96000.\n");
-            goto exit_0;
-        }
-    }
-
-    if(arg_quality->count > 0) {
-        streamer.quality = arg_quality->ival[0];
-        if(streamer.quality < 0 || streamer.quality >= DUMB_RQ_N_LEVELS) {
-            fprintf(stderr, "Quality must be between %d and %d.\n", 0, DUMB_RQ_N_LEVELS-1);
-            goto exit_0;
-        }
-    }
-
-    // Load source file.
-    dumb_register_stdfiles();
-    streamer.src = dumb_load_any(streamer.input, 0, 0);
-    if(!streamer.src) {
-        fprintf(stderr, "Unable to load file %s for playback!\n", streamer.input);
-        goto exit_0;
-    }
-
-    // Set up playback
-    streamer.renderer = duh_start_sigrenderer(streamer.src, 0, streamer.n_channels, 0);
-    streamer.delta = 65536.0f / streamer.freq;
-    streamer.sbytes = (streamer.bits / 8) * streamer.n_channels;
-    streamer.ssize = duh_get_length(streamer.src);
-
-    // Stop producing samples on module end
-    DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(streamer.renderer);
-    dumb_it_set_loop_callback(itsr, &dumb_it_callback_terminate, NULL);
-    dumb_it_set_xm_speed_zero_callback(itsr, &dumb_it_callback_terminate, NULL);
-    dumb_it_set_resampling_quality(itsr, streamer.quality);
-
-    // Set up the SDL2 format we want for playback.
-    SDL_AudioSpec want;
-    SDL_zero(want);
-    want.freq = streamer.freq;
-    want.format = (streamer.bits == 16) ? AUDIO_S16 : AUDIO_S8;
-    want.channels = streamer.n_channels;
-    want.samples = SAMPLES;
-    want.callback = stream_audio;
-    want.userdata = &streamer;
-
-    // Find SDL2 audio device, and request the format we just set up.
-    // SDL2 will tell us what we got in the "have" struct.
-    SDL_AudioSpec have;
-    streamer.dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
-    if(streamer.dev == 0) {
-        fprintf(stderr, "%s\n", SDL_GetError());
-        goto exit_1;
-    }
-
-    // Make sure we got the format we wanted. If not, stop here.
-    if(have.format != want.format) {
-        fprintf(stderr, "Could not get correct playback format.\n");
-        goto exit_2;
-    }
-
-    // Play file
-    SDL_PauseAudioDevice(streamer.dev, 0);
-
-    // Show initial state of the progress bar (if it is enabled)
-    int time_start = SDL_GetTicks();
-    float seek = 0.0f;
-    int ms_played = 0;
-    if(!streamer.no_progress) {
-        show_progress(PROGRESSBAR_LENGTH, seek, ms_played);
-    }
-
-    // Loop while dumb is still giving data. Update progressbar if enabled.
-    while(!stop_signal && !streamer.ended) {
-        if(!streamer.no_progress) {
-            seek = ((float)streamer.spos) / ((float)streamer.ssize);
-            ms_played = SDL_GetTicks() - time_start;
-            show_progress(PROGRESSBAR_LENGTH, seek, ms_played);
-        }
-        SDL_Delay(100);
-    }
-
-    // We made it this far without crashing, so let's just exit with no error :)
-    retcode = 0;
-
-    // Free up resources and exit.
-exit_2:
-    SDL_CloseAudioDevice(streamer.dev);
-
-exit_1:
-    if(streamer.renderer) {
-        duh_end_sigrenderer(streamer.renderer);
-    }
-    if(streamer.src) {
-        unload_duh(streamer.src);
-    }
-
-exit_0:
-    arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0]));
-    SDL_Quit();
-    return retcode;
-}
--- a/dumb/include/dumb.h
+++ /dev/null
@@ -1,824 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * dumb.h - The user header file for DUMB.            / / \  \
- *                                                   | <  /   \_
- * Include this file in any of your files in         |  \/ /\   /
- * which you wish to use the DUMB functions           \_  /  > /
- * and variables.                                       | \ / /
- *                                                      |  ' /
- * Allegro users, you will probably want aldumb.h.       \__/
- */
-
-#ifndef DUMB_H
-#define DUMB_H
-
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#ifdef _DEBUG
-#ifdef _MSC_VER
-#define _CRTDBG_MAP_ALLOC
-#include <crtdbg.h>
-#endif
-#endif
-
-#ifdef __cplusplus
-	extern "C" {
-#endif
-
-
-#define DUMB_MAJOR_VERSION    1
-#define DUMB_MINOR_VERSION    0
-#define DUMB_REVISION_VERSION 0
-
-#define DUMB_VERSION (DUMB_MAJOR_VERSION*10000 + DUMB_MINOR_VERSION*100 + DUMB_REVISION_VERSION)
-
-#define DUMB_VERSION_STR "1.0.0"
-
-#define DUMB_NAME "DUMB v" DUMB_VERSION_STR
-
-#define DUMB_YEAR  2015
-#define DUMB_MONTH 1
-#define DUMB_DAY   17
-
-#define DUMB_YEAR_STR2  "15"
-#define DUMB_YEAR_STR4  "2015"
-#define DUMB_MONTH_STR1 "1"
-#define DUMB_DAY_STR1   "17"
-
-#if DUMB_MONTH < 10
-#define DUMB_MONTH_STR2 "0" DUMB_MONTH_STR1
-#else
-#define DUMB_MONTH_STR2 DUMB_MONTH_STR1
-#endif
-
-#if DUMB_DAY < 10
-#define DUMB_DAY_STR2 "0" DUMB_DAY_STR1
-#else
-#define DUMB_DAY_STR2 DUMB_DAY_STR1
-#endif
-
-
-/* WARNING: The month and day were inadvertently swapped in the v0.8 release.
- *          Please do not compare this constant against any date in 2002. In
- *          any case, DUMB_VERSION is probably more useful for this purpose.
- */
-#define DUMB_DATE (DUMB_YEAR*10000 + DUMB_MONTH*100 + DUMB_DAY)
-
-#define DUMB_DATE_STR DUMB_DAY_STR1 "." DUMB_MONTH_STR1 "." DUMB_YEAR_STR4
-
-
-#undef MIN
-#undef MAX
-#undef MID
-
-#define MIN(x,y)   (((x) < (y)) ? (x) : (y))
-#define MAX(x,y)   (((x) > (y)) ? (x) : (y))
-#define MID(x,y,z) MAX((x), MIN((y), (z)))
-
-#undef ABS
-#define ABS(x) (((x) >= 0) ? (x) : (-(x)))
-
-
-#ifdef DEBUGMODE
-
-#ifndef ASSERT
-#include <assert.h>
-#define ASSERT(n) assert(n)
-#endif
-#ifndef TRACE
-// it would be nice if this did actually trace ...
-#define TRACE 1 ? (void)0 : (void)printf
-#endif
-
-#else
-
-#ifndef ASSERT
-#define ASSERT(n)
-#endif
-#ifndef TRACE
-#define TRACE 1 ? (void)0 : (void)printf
-#endif
-
-#endif
-
-
-#define DUMB_ID(a,b,c,d) (((unsigned int)(a) << 24) | \
-                          ((unsigned int)(b) << 16) | \
-                          ((unsigned int)(c) <<  8) | \
-                          ((unsigned int)(d)      ))
-
-
-
-#ifndef LONG_LONG
-#if defined __GNUC__ || defined __INTEL_COMPILER || defined __MWERKS__
-#define LONG_LONG long long
-#elif defined _MSC_VER || defined __WATCOMC__
-#define LONG_LONG __int64
-#elif defined __sgi
-#define LONG_LONG long long
-#else
-#error 64-bit integer type unknown
-#endif
-#endif
-
-#if __GNUC__ * 100 + __GNUC_MINOR__ >= 301 /* GCC 3.1+ */
-#ifndef DUMB_DECLARE_DEPRECATED
-#define DUMB_DECLARE_DEPRECATED
-#endif
-#define DUMB_DEPRECATED __attribute__((__deprecated__))
-#else
-#define DUMB_DEPRECATED
-#endif
-
-
-/* Basic Sample Type. Normal range is -0x800000 to 0x7FFFFF. */
-
-typedef int sample_t;
-
-
-/* Library Clean-up Management */
-
-int dumb_atexit(void (*proc)(void));
-
-void dumb_exit(void);
-
-
-/* File Input Functions */
-
-typedef struct DUMBFILE_SYSTEM
-{
-	void *(*open)(const char *filename);
-	int (*skip)(void *f, long n);
-	int (*getc)(void *f);
-	long (*getnc)(char *ptr, long n, void *f);
-	void (*close)(void *f);
-    int (*seek)(void *f, long n);
-    long (*get_size)(void *f);
-}
-DUMBFILE_SYSTEM;
-
-typedef struct DUMBFILE DUMBFILE;
-
-void register_dumbfile_system(const DUMBFILE_SYSTEM *dfs);
-
-DUMBFILE *dumbfile_open(const char *filename);
-DUMBFILE *dumbfile_open_ex(void *file, const DUMBFILE_SYSTEM *dfs);
-
-long dumbfile_pos(DUMBFILE *f);
-int dumbfile_skip(DUMBFILE *f, long n);
-
-#define DFS_SEEK_SET 0
-#define DFS_SEEK_CUR 1
-#define DFS_SEEK_END 2
-
-int dumbfile_seek(DUMBFILE *f, long n, int origin);
-
-long dumbfile_get_size(DUMBFILE *f);
-
-int dumbfile_getc(DUMBFILE *f);
-
-int dumbfile_igetw(DUMBFILE *f);
-int dumbfile_mgetw(DUMBFILE *f);
-
-long dumbfile_igetl(DUMBFILE *f);
-long dumbfile_mgetl(DUMBFILE *f);
-
-unsigned long dumbfile_cgetul(DUMBFILE *f);
-signed long dumbfile_cgetsl(DUMBFILE *f);
-
-long dumbfile_getnc(char *ptr, long n, DUMBFILE *f);
-
-int dumbfile_error(DUMBFILE *f);
-int dumbfile_close(DUMBFILE *f);
-
-
-/* stdio File Input Module */
-
-void dumb_register_stdfiles(void);
-
-DUMBFILE *dumbfile_open_stdfile(FILE *p);
-
-
-/* Memory File Input Module */
-
-DUMBFILE *dumbfile_open_memory(const char *data, long size);
-
-
-/* DUH Management */
-
-typedef struct DUH DUH;
-
-#define DUH_SIGNATURE DUMB_ID('D','U','H','!')
-
-void unload_duh(DUH *duh);
-
-DUH *load_duh(const char *filename);
-DUH *read_duh(DUMBFILE *f);
-
-long duh_get_length(DUH *duh);
-
-const char *duh_get_tag(DUH *duh, const char *key);
-int duh_get_tag_iterator_size(DUH *duh);
-int duh_get_tag_iterator_get(DUH *duh, const char **key, const char **tag, int i);
-
-/* Signal Rendering Functions */
-
-typedef struct DUH_SIGRENDERER DUH_SIGRENDERER;
-
-DUH_SIGRENDERER *duh_start_sigrenderer(DUH *duh, int sig, int n_channels, long pos);
-
-#ifdef DUMB_DECLARE_DEPRECATED
-typedef void (*DUH_SIGRENDERER_CALLBACK)(void *data, sample_t **samples, int n_channels, long length);
-/* This is deprecated, but is not marked as such because GCC tends to
- * complain spuriously when the typedef is used later. See comments below.
- */
-
-void duh_sigrenderer_set_callback(
-	DUH_SIGRENDERER *sigrenderer,
-	DUH_SIGRENDERER_CALLBACK callback, void *data
-) DUMB_DEPRECATED;
-/* The 'callback' argument's type has changed for const-correctness. See the
- * DUH_SIGRENDERER_CALLBACK definition just above. Also note that the samples
- * in the buffer are now 256 times as large; the normal range is -0x800000 to
- * 0x7FFFFF. The function has been renamed partly because its functionality
- * has changed slightly and partly so that its name is more meaningful. The
- * new one is duh_sigrenderer_set_analyser_callback(), and the typedef for
- * the function pointer has also changed, from DUH_SIGRENDERER_CALLBACK to
- * DUH_SIGRENDERER_ANALYSER_CALLBACK. (If you wanted to use this callback to
- * apply a DSP effect, don't worry; there is a better way of doing this. It
- * is undocumented, so contact me and I shall try to help. Contact details
- * are in readme.txt.)
- */
-
-typedef void (*DUH_SIGRENDERER_ANALYSER_CALLBACK)(void *data, const sample_t *const *samples, int n_channels, long length);
-/* This is deprecated, but is not marked as such because GCC tends to
- * complain spuriously when the typedef is used later. See comments below.
- */
-
-void duh_sigrenderer_set_analyser_callback(
-	DUH_SIGRENDERER *sigrenderer,
-	DUH_SIGRENDERER_ANALYSER_CALLBACK callback, void *data
-) DUMB_DEPRECATED;
-/* This is deprecated because the meaning of the 'samples' parameter in the
- * callback needed to change. For stereo applications, the array used to be
- * indexed with samples[channel][pos]. It is now indexed with
- * samples[0][pos*2+channel]. Mono sample data are still indexed with
- * samples[0][pos]. The array is still 2D because samples will probably only
- * ever be interleaved in twos. In order to fix your code, adapt it to the
- * new sample layout and then call
- * duh_sigrenderer_set_sample_analyser_callback below instead of this
- * function.
- */
-#endif
-
-typedef void (*DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK)(void *data, const sample_t *const *samples, int n_channels, long length);
-
-void duh_sigrenderer_set_sample_analyser_callback(
-	DUH_SIGRENDERER *sigrenderer,
-	DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK callback, void *data
-);
-
-int duh_sigrenderer_get_n_channels(DUH_SIGRENDERER *sigrenderer);
-long duh_sigrenderer_get_position(DUH_SIGRENDERER *sigrenderer);
-
-void duh_sigrenderer_set_sigparam(DUH_SIGRENDERER *sigrenderer, unsigned char id, long value);
-
-#ifdef DUMB_DECLARE_DEPRECATED
-long duh_sigrenderer_get_samples(
-	DUH_SIGRENDERER *sigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-) DUMB_DEPRECATED;
-/* The sample format has changed, so if you were using this function,
- * you should switch to duh_sigrenderer_generate_samples() and change
- * how you interpret the samples array. See the comments for
- * duh_sigrenderer_set_analyser_callback().
- */
-#endif
-
-long duh_sigrenderer_generate_samples(
-	DUH_SIGRENDERER *sigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-);
-
-void duh_sigrenderer_get_current_sample(DUH_SIGRENDERER *sigrenderer, float volume, sample_t *samples);
-
-void duh_end_sigrenderer(DUH_SIGRENDERER *sigrenderer);
-
-
-/* DUH Rendering Functions */
-
-/* For packed integers: 8, 16, 24-bit wide. 
- * Intermediary buffer sig_samples must be freed with destroy_sample_buffer()
- * in the end of the rendering loop.
- */
-long duh_render_int(
-	DUH_SIGRENDERER *sigrenderer,
-	sample_t ***sig_samples,
-	long *sig_samples_size,
-	int bits, int unsign,
-	float volume, float delta,
-	long size, void *sptr
-);
-
-/* For floats: 32, 64-bit wide.
- * Intermediary buffer sig_samples must be freed with destroy_sample_buffer()
- * in the end of the rendering loop.
- */
-long duh_render_float(
-	DUH_SIGRENDERER *sigrenderer,
-	sample_t ***sig_samples,
-	long *sig_samples_size,
-	int bits,
-	float volume, float delta,
-	long size, void *sptr
-);
-
-#ifdef DUMB_DECLARE_DEPRECATED
-
-long duh_render(
-	DUH_SIGRENDERER *sigrenderer,
-	int bits, int unsign,
-	float volume, float delta,
-	long size, void *sptr
-) DUMB_DEPRECATED;
-
-long duh_render_signal(
-	DUH_SIGRENDERER *sigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-) DUMB_DEPRECATED;
-/* Please use duh_sigrenderer_generate_samples(), and see the
- * comments for the deprecated duh_sigrenderer_get_samples() too.
- */
-
-typedef DUH_SIGRENDERER DUH_RENDERER DUMB_DEPRECATED;
-/* Please use DUH_SIGRENDERER instead of DUH_RENDERER. */
-
-DUH_SIGRENDERER *duh_start_renderer(DUH *duh, int n_channels, long pos) DUMB_DEPRECATED;
-/* Please use duh_start_sigrenderer() instead. Pass 0 for 'sig'. */
-
-int duh_renderer_get_n_channels(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
-long duh_renderer_get_position(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
-/* Please use the duh_sigrenderer_*() equivalents of these two functions. */
-
-void duh_end_renderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
-/* Please use duh_end_sigrenderer() instead. */
-
-DUH_SIGRENDERER *duh_renderer_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer) DUMB_DEPRECATED;
-DUH_SIGRENDERER *duh_renderer_get_sigrenderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
-DUH_SIGRENDERER *duh_renderer_decompose_to_sigrenderer(DUH_SIGRENDERER *dr) DUMB_DEPRECATED;
-/* These functions have become no-ops that just return the parameter.
- * So, for instance, replace
- *   duh_renderer_encapsulate_sigrenderer(my_sigrenderer)
- * with
- *   my_sigrenderer
- */
-
-#endif
-
-
-/* Impulse Tracker Support */
-
-extern int dumb_it_max_to_mix;
-
-typedef struct DUMB_IT_SIGDATA DUMB_IT_SIGDATA;
-typedef struct DUMB_IT_SIGRENDERER DUMB_IT_SIGRENDERER;
-
-DUMB_IT_SIGDATA *duh_get_it_sigdata(DUH *duh);
-DUH_SIGRENDERER *duh_encapsulate_it_sigrenderer(DUMB_IT_SIGRENDERER *it_sigrenderer, int n_channels, long pos);
-DUMB_IT_SIGRENDERER *duh_get_it_sigrenderer(DUH_SIGRENDERER *sigrenderer);
-
-int dumb_it_trim_silent_patterns(DUH * duh);
-
-typedef int (*dumb_scan_callback)(void *, int, long);
-int dumb_it_scan_for_playable_orders(DUMB_IT_SIGDATA *sigdata, dumb_scan_callback callback, void * callback_data);
-
-DUH_SIGRENDERER *dumb_it_start_at_order(DUH *duh, int n_channels, int startorder);
-
-enum
-{
-    DUMB_IT_RAMP_NONE = 0,
-    DUMB_IT_RAMP_ONOFF_ONLY = 1,
-    DUMB_IT_RAMP_FULL = 2
-};
-
-void dumb_it_set_ramp_style(DUMB_IT_SIGRENDERER * sigrenderer, int ramp_style);
-
-void dumb_it_set_loop_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data);
-void dumb_it_set_xm_speed_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data);
-void dumb_it_set_midi_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data, int channel, unsigned char midi_byte), void *data);
-void dumb_it_set_global_volume_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data);
-
-int dumb_it_callback_terminate(void *data);
-int dumb_it_callback_midi_block(void *data, int channel, unsigned char midi_byte);
-
-/* dumb_*_mod*: restrict_ |= 1-Don't read 15 sample files / 2-Use old pattern counting method */
-
-DUH *dumb_load_it(const char *filename);
-DUH *dumb_load_xm(const char *filename);
-DUH *dumb_load_s3m(const char *filename);
-DUH *dumb_load_stm(const char *filename);
-DUH *dumb_load_mod(const char *filename, int restrict_);
-DUH *dumb_load_ptm(const char *filename);
-DUH *dumb_load_669(const char *filename);
-DUH *dumb_load_psm(const char *filename, int subsong);
-DUH *dumb_load_old_psm(const char * filename);
-DUH *dumb_load_mtm(const char *filename);
-DUH *dumb_load_riff(const char *filename);
-DUH *dumb_load_asy(const char *filename);
-DUH *dumb_load_amf(const char *filename);
-DUH *dumb_load_okt(const char *filename);
-
-DUH *dumb_read_it(DUMBFILE *f);
-DUH *dumb_read_xm(DUMBFILE *f);
-DUH *dumb_read_s3m(DUMBFILE *f);
-DUH *dumb_read_stm(DUMBFILE *f);
-DUH *dumb_read_mod(DUMBFILE *f, int restrict_);
-DUH *dumb_read_ptm(DUMBFILE *f);
-DUH *dumb_read_669(DUMBFILE *f);
-DUH *dumb_read_psm(DUMBFILE *f, int subsong);
-DUH *dumb_read_old_psm(DUMBFILE *f);
-DUH *dumb_read_mtm(DUMBFILE *f);
-DUH *dumb_read_riff(DUMBFILE *f);
-DUH *dumb_read_asy(DUMBFILE *f);
-DUH *dumb_read_amf(DUMBFILE *f);
-DUH *dumb_read_okt(DUMBFILE *f);
-
-DUH *dumb_load_it_quick(const char *filename);
-DUH *dumb_load_xm_quick(const char *filename);
-DUH *dumb_load_s3m_quick(const char *filename);
-DUH *dumb_load_stm_quick(const char *filename);
-DUH *dumb_load_mod_quick(const char *filename, int restrict_);
-DUH *dumb_load_ptm_quick(const char *filename);
-DUH *dumb_load_669_quick(const char *filename);
-DUH *dumb_load_psm_quick(const char *filename, int subsong);
-DUH *dumb_load_old_psm_quick(const char * filename);
-DUH *dumb_load_mtm_quick(const char *filename);
-DUH *dumb_load_riff_quick(const char *filename);
-DUH *dumb_load_asy_quick(const char *filename);
-DUH *dumb_load_amf_quick(const char *filename);
-DUH *dumb_load_okt_quick(const char *filename);
-
-DUH *dumb_read_it_quick(DUMBFILE *f);
-DUH *dumb_read_xm_quick(DUMBFILE *f);
-DUH *dumb_read_s3m_quick(DUMBFILE *f);
-DUH *dumb_read_stm_quick(DUMBFILE *f);
-DUH *dumb_read_mod_quick(DUMBFILE *f, int restrict_);
-DUH *dumb_read_ptm_quick(DUMBFILE *f);
-DUH *dumb_read_669_quick(DUMBFILE *f);
-DUH *dumb_read_psm_quick(DUMBFILE *f, int subsong);
-DUH *dumb_read_old_psm_quick(DUMBFILE *f);
-DUH *dumb_read_mtm_quick(DUMBFILE *f);
-DUH *dumb_read_riff_quick(DUMBFILE *f);
-DUH *dumb_read_asy_quick(DUMBFILE *f);
-DUH *dumb_read_amf_quick(DUMBFILE *f);
-DUH *dumb_read_okt_quick(DUMBFILE *f);
-
-DUH *dumb_read_any_quick(DUMBFILE *f, int restrict_, int subsong);
-DUH *dumb_read_any(DUMBFILE *f, int restrict_, int subsong);
-
-DUH *dumb_load_any_quick(const char *filename, int restrict_, int subsong);
-DUH *dumb_load_any(const char *filename, int restrict_, int subsong);
-
-long dumb_it_build_checkpoints(DUMB_IT_SIGDATA *sigdata, int startorder);
-void dumb_it_do_initial_runthrough(DUH *duh);
-
-int dumb_get_psm_subsong_count(DUMBFILE *f);
-
-const unsigned char *dumb_it_sd_get_song_message(DUMB_IT_SIGDATA *sd);
-
-int dumb_it_sd_get_n_orders(DUMB_IT_SIGDATA *sd);
-int dumb_it_sd_get_n_samples(DUMB_IT_SIGDATA *sd);
-int dumb_it_sd_get_n_instruments(DUMB_IT_SIGDATA *sd);
-
-const unsigned char *dumb_it_sd_get_sample_name(DUMB_IT_SIGDATA *sd, int i);
-const unsigned char *dumb_it_sd_get_sample_filename(DUMB_IT_SIGDATA *sd, int i);
-const unsigned char *dumb_it_sd_get_instrument_name(DUMB_IT_SIGDATA *sd, int i);
-const unsigned char *dumb_it_sd_get_instrument_filename(DUMB_IT_SIGDATA *sd, int i);
-
-int dumb_it_sd_get_initial_global_volume(DUMB_IT_SIGDATA *sd);
-void dumb_it_sd_set_initial_global_volume(DUMB_IT_SIGDATA *sd, int gv);
-
-int dumb_it_sd_get_mixing_volume(DUMB_IT_SIGDATA *sd);
-void dumb_it_sd_set_mixing_volume(DUMB_IT_SIGDATA *sd, int mv);
-
-int dumb_it_sd_get_initial_speed(DUMB_IT_SIGDATA *sd);
-void dumb_it_sd_set_initial_speed(DUMB_IT_SIGDATA *sd, int speed);
-
-int dumb_it_sd_get_initial_tempo(DUMB_IT_SIGDATA *sd);
-void dumb_it_sd_set_initial_tempo(DUMB_IT_SIGDATA *sd, int tempo);
-
-int dumb_it_sd_get_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel);
-void dumb_it_sd_set_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel, int volume);
-
-int dumb_it_sr_get_current_order(DUMB_IT_SIGRENDERER *sr);
-int dumb_it_sr_get_current_row(DUMB_IT_SIGRENDERER *sr);
-
-int dumb_it_sr_get_global_volume(DUMB_IT_SIGRENDERER *sr);
-void dumb_it_sr_set_global_volume(DUMB_IT_SIGRENDERER *sr, int gv);
-
-int dumb_it_sr_get_tempo(DUMB_IT_SIGRENDERER *sr);
-void dumb_it_sr_set_tempo(DUMB_IT_SIGRENDERER *sr, int tempo);
-
-int dumb_it_sr_get_speed(DUMB_IT_SIGRENDERER *sr);
-void dumb_it_sr_set_speed(DUMB_IT_SIGRENDERER *sr, int speed);
-
-#define DUMB_IT_N_CHANNELS 64
-#define DUMB_IT_N_NNA_CHANNELS 192
-#define DUMB_IT_TOTAL_CHANNELS (DUMB_IT_N_CHANNELS + DUMB_IT_N_NNA_CHANNELS)
-
-/* Channels passed to any of these functions are 0-based */
-int dumb_it_sr_get_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel);
-void dumb_it_sr_set_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel, int volume);
-
-int dumb_it_sr_get_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel);
-void dumb_it_sr_set_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel, int muted);
-
-typedef struct DUMB_IT_CHANNEL_STATE DUMB_IT_CHANNEL_STATE;
-
-struct DUMB_IT_CHANNEL_STATE
-{
-	int channel; /* 0-based; meaningful for NNA channels */
-	int sample; /* 1-based; 0 if nothing playing, then other fields undef */
-	int freq; /* in Hz */
-	float volume; /* 1.0 maximum; affected by ALL factors, inc. mixing vol */
-	unsigned char pan; /* 0-64, 100 for surround */
-	signed char subpan; /* use (pan + subpan/256.0f) or ((pan<<8)+subpan) */
-	unsigned char filter_cutoff;    /* 0-127    cutoff=127 AND resonance=0 */
-	unsigned char filter_subcutoff; /* 0-255      -> no filters (subcutoff */
-	unsigned char filter_resonance; /* 0-127        always 0 in this case) */
-	/* subcutoff only changes from zero if filter envelopes are in use. The
-	 * calculation (filter_cutoff + filter_subcutoff/256.0f) gives a more
-	 * accurate filter cutoff measurement as a float. It would often be more
-	 * useful to use a scaled int such as ((cutoff<<8) + subcutoff).
-	 */
-};
-
-/* Values of 64 or more will access NNA channels here. */
-void dumb_it_sr_get_channel_state(DUMB_IT_SIGRENDERER *sr, int channel, DUMB_IT_CHANNEL_STATE *state);
-
-
-/* Signal Design Helper Values */
-
-/* Use pow(DUMB_SEMITONE_BASE, n) to get the 'delta' value to transpose up by
- * n semitones. To transpose down, use negative n.
- */
-#define DUMB_SEMITONE_BASE 1.059463094359295309843105314939748495817
-
-/* Use pow(DUMB_QUARTERTONE_BASE, n) to get the 'delta' value to transpose up
- * by n quartertones. To transpose down, use negative n.
- */
-#define DUMB_QUARTERTONE_BASE 1.029302236643492074463779317738953977823
-
-/* Use pow(DUMB_PITCH_BASE, n) to get the 'delta' value to transpose up by n
- * units. In this case, 256 units represent one semitone; 3072 units
- * represent one octave. These units are used by the sequence signal (SEQU).
- */
-#define DUMB_PITCH_BASE 1.000225659305069791926712241547647863626
-
-
-/* Signal Design Function Types */
-
-typedef void sigdata_t;
-typedef void sigrenderer_t;
-
-typedef sigdata_t *(*DUH_LOAD_SIGDATA)(DUH *duh, DUMBFILE *file);
-
-typedef sigrenderer_t *(*DUH_START_SIGRENDERER)(
-	DUH *duh,
-	sigdata_t *sigdata,
-	int n_channels,
-	long pos
-);
-
-typedef void (*DUH_SIGRENDERER_SET_SIGPARAM)(
-	sigrenderer_t *sigrenderer,
-	unsigned char id, long value
-);
-
-typedef long (*DUH_SIGRENDERER_GENERATE_SAMPLES)(
-	sigrenderer_t *sigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-);
-
-typedef void (*DUH_SIGRENDERER_GET_CURRENT_SAMPLE)(
-	sigrenderer_t *sigrenderer,
-	float volume,
-	sample_t *samples
-);
-
-typedef long (*DUH_SIGRENDERER_GET_POSITION)(
-	sigrenderer_t *sigrenderer
-);
-
-typedef void (*DUH_END_SIGRENDERER)(sigrenderer_t *sigrenderer);
-
-typedef void (*DUH_UNLOAD_SIGDATA)(sigdata_t *sigdata);
-
-
-/* Signal Design Function Registration */
-
-typedef struct DUH_SIGTYPE_DESC
-{
-	long type;
-	DUH_LOAD_SIGDATA                   load_sigdata;
-	DUH_START_SIGRENDERER              start_sigrenderer;
-	DUH_SIGRENDERER_SET_SIGPARAM       sigrenderer_set_sigparam;
-	DUH_SIGRENDERER_GENERATE_SAMPLES   sigrenderer_generate_samples;
-	DUH_SIGRENDERER_GET_CURRENT_SAMPLE sigrenderer_get_current_sample;
-	DUH_SIGRENDERER_GET_POSITION       sigrenderer_get_position;
-	DUH_END_SIGRENDERER                end_sigrenderer;
-	DUH_UNLOAD_SIGDATA                 unload_sigdata;
-}
-DUH_SIGTYPE_DESC;
-
-void dumb_register_sigtype(DUH_SIGTYPE_DESC *desc);
-
-int duh_add_signal(DUH *duh, DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata);
-
-
-// Decide where to put these functions; new heading?
-
-sigdata_t *duh_get_raw_sigdata(DUH *duh, int sig, long type);
-
-DUH_SIGRENDERER *duh_encapsulate_raw_sigrenderer(sigrenderer_t *vsigrenderer, DUH_SIGTYPE_DESC *desc, int n_channels, long pos);
-sigrenderer_t *duh_get_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer, long type);
-
-
-/* Standard Signal Types */
-
-//void dumb_register_sigtype_sample(void);
-
-
-/* Sample Buffer Allocation Helpers */
-
-#ifdef DUMB_DECLARE_DEPRECATED
-sample_t **create_sample_buffer(int n_channels, long length) DUMB_DEPRECATED;
-/* DUMB has been changed to interleave stereo samples. Use
- * allocate_sample_buffer() instead, and see the comments for
- * duh_sigrenderer_set_analyser_callback().
- */
-#endif
-sample_t **allocate_sample_buffer(int n_channels, long length);
-void destroy_sample_buffer(sample_t **samples);
-
-
-/* Silencing Helper */
-
-void dumb_silence(sample_t *samples, long length);
-
-
-/* Click Removal Helpers */
-
-typedef struct DUMB_CLICK_REMOVER DUMB_CLICK_REMOVER;
-
-DUMB_CLICK_REMOVER *dumb_create_click_remover(void);
-void dumb_record_click(DUMB_CLICK_REMOVER *cr, long pos, sample_t step);
-void dumb_remove_clicks(DUMB_CLICK_REMOVER *cr, sample_t *samples, long length, int step, float halflife);
-sample_t dumb_click_remover_get_offset(DUMB_CLICK_REMOVER *cr);
-void dumb_destroy_click_remover(DUMB_CLICK_REMOVER *cr);
-
-DUMB_CLICK_REMOVER **dumb_create_click_remover_array(int n);
-void dumb_record_click_array(int n, DUMB_CLICK_REMOVER **cr, long pos, sample_t *step);
-void dumb_record_click_negative_array(int n, DUMB_CLICK_REMOVER **cr, long pos, sample_t *step);
-void dumb_remove_clicks_array(int n, DUMB_CLICK_REMOVER **cr, sample_t **samples, long length, float halflife);
-void dumb_click_remover_get_offset_array(int n, DUMB_CLICK_REMOVER **cr, sample_t *offset);
-void dumb_destroy_click_remover_array(int n, DUMB_CLICK_REMOVER **cr);
-
-
-/* Resampling Helpers */
-
-#define DUMB_RQ_ALIASING 0
-#define DUMB_RQ_BLEP     1
-#define DUMB_RQ_LINEAR   2
-#define DUMB_RQ_BLAM     3
-#define DUMB_RQ_CUBIC    4
-#define DUMB_RQ_FIR      5
-#define DUMB_RQ_N_LEVELS 6
-
-extern int dumb_resampling_quality; /* This specifies the default */
-void dumb_it_set_resampling_quality(DUMB_IT_SIGRENDERER * sigrenderer, int quality); /* This overrides it */
-
-typedef struct DUMB_RESAMPLER DUMB_RESAMPLER;
-
-typedef struct DUMB_VOLUME_RAMP_INFO DUMB_VOLUME_RAMP_INFO;
-
-typedef void (*DUMB_RESAMPLE_PICKUP)(DUMB_RESAMPLER *resampler, void *data);
-
-struct DUMB_RESAMPLER
-{
-	void *src;
-	long pos;
-	int subpos;
-	long start, end;
-	int dir;
-	DUMB_RESAMPLE_PICKUP pickup;
-	void *pickup_data;
-	int quality;
-	/* Everything below this point is internal: do not use. */
-	union {
-		sample_t x24[3*2];
-		short x16[3*2];
-		signed char x8[3*2];
-	} x;
-	int overshot;
-    double fir_resampler_ratio;
-    void* fir_resampler[2];
-};
-
-struct DUMB_VOLUME_RAMP_INFO
-{
-	float volume;
-	float delta;
-	float target;
-	float mix;
-    unsigned char declick_stage;
-};
-
-void dumb_reset_resampler(DUMB_RESAMPLER *resampler, sample_t *src, int src_channels, long pos, long start, long end, int quality);
-DUMB_RESAMPLER *dumb_start_resampler(sample_t *src, int src_channels, long pos, long start, long end, int quality);
-long dumb_resample_1_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume, float delta);
-long dumb_resample_1_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_2_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_2_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-void dumb_resample_get_current_sample_1_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
-void dumb_resample_get_current_sample_1_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_2_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_2_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_end_resampler(DUMB_RESAMPLER *resampler);
-
-void dumb_reset_resampler_16(DUMB_RESAMPLER *resampler, short *src, int src_channels, long pos, long start, long end, int quality);
-DUMB_RESAMPLER *dumb_start_resampler_16(short *src, int src_channels, long pos, long start, long end, int quality);
-long dumb_resample_16_1_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume, float delta);
-long dumb_resample_16_1_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_16_2_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_16_2_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-void dumb_resample_get_current_sample_16_1_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
-void dumb_resample_get_current_sample_16_1_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_16_2_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_16_2_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_end_resampler_16(DUMB_RESAMPLER *resampler);
-
-void dumb_reset_resampler_8(DUMB_RESAMPLER *resampler, signed char *src, int src_channels, long pos, long start, long end, int quality);
-DUMB_RESAMPLER *dumb_start_resampler_8(signed char *src, int src_channels, long pos, long start, long end, int quality);
-long dumb_resample_8_1_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume, float delta);
-long dumb_resample_8_1_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_8_2_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_8_2_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-void dumb_resample_get_current_sample_8_1_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
-void dumb_resample_get_current_sample_8_1_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_8_2_1(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_8_2_2(DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_end_resampler_8(DUMB_RESAMPLER *resampler);
-
-void dumb_reset_resampler_n(int n, DUMB_RESAMPLER *resampler, void *src, int src_channels, long pos, long start, long end, int quality);
-DUMB_RESAMPLER *dumb_start_resampler_n(int n, void *src, int src_channels, long pos, long start, long end, int quality);
-long dumb_resample_n_1_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume, float delta);
-long dumb_resample_n_1_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_n_2_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-long dumb_resample_n_2_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta);
-void dumb_resample_get_current_sample_n_1_1(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst);
-void dumb_resample_get_current_sample_n_1_2(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_n_2_1(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_resample_get_current_sample_n_2_2(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst);
-void dumb_end_resampler_n(int n, DUMB_RESAMPLER *resampler);
-
-/* This sets the default panning separation for hard panned formats,
-   or for formats with default panning information. This must be set
-   before using any readers or loaders, and is not really thread safe. */
-
-extern int dumb_it_default_panning_separation; /* in percent, default 25 */
-
-/* DUH Construction */
-
-DUH *make_duh(
-	long length,
-	int n_tags,
-	const char *const tag[][2],
-	int n_signals,
-	DUH_SIGTYPE_DESC *desc[],
-	sigdata_t *sigdata[]
-);
-
-void duh_set_length(DUH *duh, long length);
-
-
-#ifdef __cplusplus
-	}
-#endif
-
-
-#endif /* DUMB_H */
--- a/dumb/include/internal/aldumb.h
+++ /dev/null
@@ -1,27 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * internal/aldumb.h - The internal header file       / / \  \
- *                     for DUMB with Allegro.        | <  /   \_
- *                                                   |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#ifndef INTERNAL_ALDUMB_H
-#define INTERNAL_ALDUMB_H
-
-
-void _dat_unload_duh(void *duh);
-
-
-#endif /* INTERNAL_DUMB_H */
--- a/dumb/include/internal/barray.h
+++ /dev/null
@@ -1,43 +1,0 @@
-#ifndef _B_ARRAY_H_
-#define _B_ARRAY_H_
-
-#include <stdlib.h>
-
-#ifdef BARRAY_DECORATE
-#undef PASTE
-#undef EVALUATE
-#define PASTE(a,b) a ## b
-#define EVALUATE(a,b) PASTE(a,b)
-#define bit_array_create EVALUATE(BARRAY_DECORATE,_bit_array_create)
-#define bit_array_destroy EVALUATE(BARRAY_DECORATE,_bit_array_destroy)
-#define bit_array_dup EVALUATE(BARRAY_DECORATE,_bit_array_dup)
-#define bit_array_reset EVALUATE(BARRAY_DECORATE,_bit_array_reset)
-#define bit_array_set EVALUATE(BARRAY_DECORATE,_bit_array_set)
-#define bit_array_set_range EVALUATE(BARRAY_DECORATE,_bit_array_set_range)
-#define bit_array_test EVALUATE(BARRAY_DECORATE,_bit_array_test)
-#define bit_array_test_range EVALUATE(BARRAY_DECORATE,_bit_array_test_range)
-#define bit_array_clear EVALUATE(BARRAY_DECORATE,_bit_array_clear)
-#define bit_array_clear_range EVALUATE(BARRAY_DECORATE,_bit_array_clear_range)
-#define bit_array_merge EVALUATE(BARRAY_DECORATE,_bit_array_merge)
-#define bit_array_mask EVALUATE(BARRAY_DECORATE,_bit_array_mask)
-#endif
-
-void * bit_array_create(size_t size);
-void bit_array_destroy(void * array);
-void * bit_array_dup(void * array);
-
-void bit_array_reset(void * array);
-
-void bit_array_set(void * array, size_t bit);
-void bit_array_set_range(void * array, size_t bit, size_t count);
-
-int bit_array_test(void * array, size_t bit);
-int bit_array_test_range(void * array, size_t bit, size_t count);
-
-void bit_array_clear(void * array, size_t bit);
-void bit_array_clear_range(void * array, size_t bit, size_t count);
-
-void bit_array_merge(void * array, void * source, size_t offset);
-void bit_array_mask(void * array, void * source, size_t offset);
-
-#endif
--- a/dumb/include/internal/dumb.h
+++ /dev/null
@@ -1,61 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * internal/dumb.h - DUMB's internal declarations.    / / \  \
- *                                                   | <  /   \_
- * This header file provides access to the           |  \/ /\   /
- * internal structure of DUMB, and is liable          \_  /  > /
- * to change, mutate or cease to exist at any           | \ / /
- * moment. Include it at your own peril.                |  ' /
- *                                                       \__/
- * ...
- *
- * Seriously. You don't need access to anything in this file. All right, you
- * probably do actually. But if you use it, you will be relying on a specific
- * version of DUMB, so please check DUMB_VERSION defined in dumb.h. Please
- * contact the authors so that we can provide a public API for what you need.
- */
-
-#ifndef INTERNAL_DUMB_H
-#define INTERNAL_DUMB_H
-
-
-typedef struct DUH_SIGTYPE_DESC_LINK
-{
-	struct DUH_SIGTYPE_DESC_LINK *next;
-	DUH_SIGTYPE_DESC *desc;
-}
-DUH_SIGTYPE_DESC_LINK;
-
-
-typedef struct DUH_SIGNAL
-{
-	sigdata_t *sigdata;
-	DUH_SIGTYPE_DESC *desc;
-}
-DUH_SIGNAL;
-
-
-struct DUH
-{
-	long length;
-
-	int n_tags;
-	char *(*tag)[2];
-
-	int n_signals;
-	DUH_SIGNAL **signal;
-};
-
-
-DUH_SIGTYPE_DESC *_dumb_get_sigtype_desc(long type);
-
-
-#endif /* INTERNAL_DUMB_H */
--- a/dumb/include/internal/dumbfile.h
+++ /dev/null
@@ -1,13 +1,0 @@
-#ifndef DUMBFILE_H
-#define DUMBFILE_H
-
-#include "../dumb.h"
-
-struct DUMBFILE
-{
-    const DUMBFILE_SYSTEM *dfs;
-    void *file;
-    long pos;
-};
-
-#endif // DUMBFILE_H
--- a/dumb/include/internal/fir_resampler.h
+++ /dev/null
@@ -1,18 +1,0 @@
-#ifndef _FIR_RESAMPLER_H_
-#define _FIR_RESAMPLER_H_
-
-void fir_init();
-
-void * fir_resampler_create();
-void fir_resampler_delete(void *);
-void * fir_resampler_dup(void *);
-
-int fir_resampler_get_free_count(void *);
-void fir_resampler_write_sample(void *, short sample);
-void fir_resampler_set_rate( void *, double new_factor );
-int fir_resampler_ready(void *);
-void fir_resampler_clear(void *);
-int fir_resampler_get_sample(void *);
-void fir_resampler_remove_sample(void *);
-
-#endif
--- a/dumb/include/internal/it.h
+++ /dev/null
@@ -1,926 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * internal/it.h - Internal stuff for IT playback     / / \  \
- *                 and MOD/XM/S3M conversion.        | <  /   \_
- *                                                   |  \/ /\   /
- * This header file provides access to the            \_  /  > /
- * internal structure of DUMB, and is liable            | \ / /
- * to change, mutate or cease to exist at any           |  ' /
- * moment. Include it at your own peril.                 \__/
- *
- * ...
- *
- * Seriously. You don't need access to anything in this file. All right, you
- * probably do actually. But if you use it, you will be relying on a specific
- * version of DUMB, so please check DUMB_VERSION defined in dumb.h. Please
- * contact the authors so that we can provide a public API for what you need.
- */
-
-#ifndef INTERNAL_IT_H
-#define INTERNAL_IT_H
-
-
-#define BIT_ARRAY_BULLSHIT
-
-#include <stddef.h>
-
-#include "barray.h"
-#include "tarray.h"
-
-
-/** TO DO: THINK ABOUT THE FOLLOWING:
-
-sigdata->flags & IT_COMPATIBLE_GXX
-
-                Bit 5: On = Link Effect G's memory with Effect E/F. Also
-                            Gxx with an instrument present will cause the
-                            envelopes to be retriggered. If you change a
-                            sample on a row with Gxx, it'll adjust the
-                            frequency of the current note according to:
-
-                              NewFrequency = OldFrequency * NewC5 / OldC5;
-*/
-
-
-
-/* These #defines are TEMPORARY. They are used to write alternative code to
- * handle ambiguities in the format specification. The correct code in each
- * case will be determined most likely by experimentation.
- */
-//#define STEREO_SAMPLES_COUNT_AS_TWO
-#define INVALID_ORDERS_END_SONG
-#define SUSTAIN_LOOP_OVERRIDES_NORMAL_LOOP
-#define VOLUME_OUT_OF_RANGE_SETS_MAXIMUM
-
-
-
-#define SIGTYPE_IT DUMB_ID('I', 'T', ' ', ' ')
-
-#define IT_SIGNATURE            DUMB_ID('I', 'M', 'P', 'M')
-#define IT_INSTRUMENT_SIGNATURE DUMB_ID('I', 'M', 'P', 'I')
-#define IT_SAMPLE_SIGNATURE     DUMB_ID('I', 'M', 'P', 'S')
-
-// olivier sux
-#define IT_MPTX_SIGNATURE       DUMB_ID('X', 'T', 'P', 'M')
-#define IT_INSM_SIGNATURE       DUMB_ID('M', 'S', 'N', 'I')
-
-
-/* This is divided by the tempo times 256 to get the interval between ticks.
- */
-#define TICK_TIME_DIVIDEND (65536 * 5 * 128)
-
-
-
-/* I'm not going to try to explain this, because I didn't derive it very
- * formally ;)
- */
-/* #define AMIGA_DIVISOR ((float)(4.0 * 14317056.0)) */
-/* I believe the following one to be more accurate. */
-//#define AMIGA_DIVISOR ((float)(8.0 * 7159090.5))
-#define AMIGA_CLOCK 3546895
-#define AMIGA_DIVISOR ((float)(16.0 * AMIGA_CLOCK))
-
-
-
-typedef struct IT_MIDI IT_MIDI;
-typedef struct IT_FILTER_STATE IT_FILTER_STATE;
-typedef struct IT_ENVELOPE IT_ENVELOPE;
-typedef struct IT_INSTRUMENT IT_INSTRUMENT;
-typedef struct IT_SAMPLE IT_SAMPLE;
-typedef struct IT_ENTRY IT_ENTRY;
-typedef struct IT_PATTERN IT_PATTERN;
-typedef struct IT_PLAYING_ENVELOPE IT_PLAYING_ENVELOPE;
-typedef struct IT_PLAYING IT_PLAYING;
-typedef struct IT_CHANNEL IT_CHANNEL;
-typedef struct IT_CHECKPOINT IT_CHECKPOINT;
-typedef struct IT_CALLBACKS IT_CALLBACKS;
-
-
-
-struct IT_MIDI
-{
-	unsigned char SFmacro[16][16]; // read these from 0x120
-	unsigned char SFmacrolen[16];
-	unsigned short SFmacroz[16]; /* Bitfield; bit 0 set = z in first position */
-	unsigned char Zmacro[128][16]; // read these from 0x320
-	unsigned char Zmacrolen[128];
-};
-
-
-
-struct IT_FILTER_STATE
-{
-	sample_t currsample, prevsample;
-};
-
-
-
-#define IT_ENVELOPE_ON                1
-#define IT_ENVELOPE_LOOP_ON           2
-#define IT_ENVELOPE_SUSTAIN_LOOP      4
-#define IT_ENVELOPE_CARRY             8
-#define IT_ENVELOPE_PITCH_IS_FILTER 128
-
-struct IT_ENVELOPE
-{
-	unsigned char flags;
-	unsigned char n_nodes;
-	unsigned char loop_start;
-	unsigned char loop_end;
-	unsigned char sus_loop_start;
-	unsigned char sus_loop_end;
-	signed char node_y[25];
-	unsigned short node_t[25];
-};
-
-
-
-#define NNA_NOTE_CUT      0
-#define NNA_NOTE_CONTINUE 1
-#define NNA_NOTE_OFF      2
-#define NNA_NOTE_FADE     3
-
-#define DCT_OFF        0
-#define DCT_NOTE       1
-#define DCT_SAMPLE     2
-#define DCT_INSTRUMENT 3
-
-#define DCA_NOTE_CUT  0
-#define DCA_NOTE_OFF  1
-#define DCA_NOTE_FADE 2
-
-struct IT_INSTRUMENT
-{
-	unsigned char name[27];
-	unsigned char filename[14];
-
-	int fadeout;
-
-	IT_ENVELOPE volume_envelope;
-	IT_ENVELOPE pan_envelope;
-	IT_ENVELOPE pitch_envelope;
-
-	unsigned char new_note_action;
-	unsigned char dup_check_type;
-	unsigned char dup_check_action;
-	signed char pp_separation;
-	unsigned char pp_centre;
-	unsigned char global_volume;
-	unsigned char default_pan;
-	unsigned char random_volume;
-	unsigned char random_pan;
-
-	unsigned char filter_cutoff;
-	unsigned char filter_resonance;
-
-	unsigned char map_note[120];
-	unsigned short map_sample[120];
-
-	//int output;
-};
-
-
-
-#define IT_SAMPLE_EXISTS              1
-#define IT_SAMPLE_16BIT               2
-#define IT_SAMPLE_STEREO              4
-#define IT_SAMPLE_LOOP               16
-#define IT_SAMPLE_SUS_LOOP           32
-#define IT_SAMPLE_PINGPONG_LOOP      64
-#define IT_SAMPLE_PINGPONG_SUS_LOOP 128
-
-#define IT_VIBRATO_SINE      0
-#define IT_VIBRATO_SAWTOOTH  1
-#define IT_VIBRATO_SQUARE    2
-#define IT_VIBRATO_RANDOM    3
-#define IT_VIBRATO_XM_SQUARE 4
-#define IT_VIBRATO_RAMP_DOWN 5
-#define IT_VIBRATO_RAMP_UP   6
-
-struct IT_SAMPLE
-{
-	unsigned char name[35];
-	unsigned char filename[15];
-	unsigned char flags;
-	unsigned char global_volume;
-	unsigned char default_volume;
-	unsigned char default_pan;
-	/* default_pan:
-	 *   0-255 for XM
-	 *   ignored for MOD
-	 *   otherwise, 0-64, and add 128 to enable
-	 */
-
-	long length;
-	long loop_start;
-	long loop_end;
-	long C5_speed;
-	long sus_loop_start;
-	long sus_loop_end;
-
-	unsigned char vibrato_speed;
-	unsigned char vibrato_depth;
-	unsigned char vibrato_rate;
-	unsigned char vibrato_waveform;
-
-	signed short   finetune;
-
-	void *data;
-
-	int max_resampling_quality;
-};
-
-
-
-#define IT_ENTRY_NOTE       1
-#define IT_ENTRY_INSTRUMENT 2
-#define IT_ENTRY_VOLPAN     4
-#define IT_ENTRY_EFFECT     8
-
-#define IT_SET_END_ROW(entry) ((entry)->channel = 255)
-#define IT_IS_END_ROW(entry) ((entry)->channel >= DUMB_IT_N_CHANNELS)
-
-#define IT_NOTE_OFF 255
-#define IT_NOTE_CUT 254
-
-#define IT_ENVELOPE_SHIFT 8
-
-#define IT_SURROUND 100
-#define IT_IS_SURROUND(pan) ((pan) > 64)
-#define IT_IS_SURROUND_SHIFTED(pan) ((pan) > 64 << IT_ENVELOPE_SHIFT)
-
-#define IT_SET_SPEED              1
-#define IT_JUMP_TO_ORDER          2
-#define IT_BREAK_TO_ROW           3
-#define IT_VOLUME_SLIDE           4
-#define IT_PORTAMENTO_DOWN        5
-#define IT_PORTAMENTO_UP          6
-#define IT_TONE_PORTAMENTO        7
-#define IT_VIBRATO                8
-#define IT_TREMOR                 9
-#define IT_ARPEGGIO              10
-#define IT_VOLSLIDE_VIBRATO      11
-#define IT_VOLSLIDE_TONEPORTA    12
-#define IT_SET_CHANNEL_VOLUME    13
-#define IT_CHANNEL_VOLUME_SLIDE  14
-#define IT_SET_SAMPLE_OFFSET     15
-#define IT_PANNING_SLIDE         16
-#define IT_RETRIGGER_NOTE        17
-#define IT_TREMOLO               18
-#define IT_S                     19
-#define IT_SET_SONG_TEMPO        20
-#define IT_FINE_VIBRATO          21
-#define IT_SET_GLOBAL_VOLUME     22
-#define IT_GLOBAL_VOLUME_SLIDE   23
-#define IT_SET_PANNING           24
-#define IT_PANBRELLO             25
-#define IT_MIDI_MACRO            26 //see MIDI.TXT
-
-/* Some effects needed for XM compatibility */
-#define IT_XM_PORTAMENTO_DOWN       27
-#define IT_XM_PORTAMENTO_UP         28
-#define IT_XM_FINE_VOLSLIDE_DOWN    29
-#define IT_XM_FINE_VOLSLIDE_UP      30
-#define IT_XM_RETRIGGER_NOTE        31
-#define IT_XM_KEY_OFF               32
-#define IT_XM_SET_ENVELOPE_POSITION 33
-
-/* More effects needed for PTM compatibility */
-#define IT_PTM_NOTE_SLIDE_DOWN        34
-#define IT_PTM_NOTE_SLIDE_UP          35
-#define IT_PTM_NOTE_SLIDE_DOWN_RETRIG 36
-#define IT_PTM_NOTE_SLIDE_UP_RETRIG   37
-
-/* More effects needed for OKT compatibility */
-#define IT_OKT_NOTE_SLIDE_DOWN        38
-#define IT_OKT_NOTE_SLIDE_DOWN_ROW    39
-#define IT_OKT_NOTE_SLIDE_UP          40
-#define IT_OKT_NOTE_SLIDE_UP_ROW      41
-#define IT_OKT_ARPEGGIO_3             42
-#define IT_OKT_ARPEGGIO_4             43
-#define IT_OKT_ARPEGGIO_5             44
-#define IT_OKT_VOLUME_SLIDE_DOWN      45
-#define IT_OKT_VOLUME_SLIDE_UP        46
-
-#define IT_N_EFFECTS                  47
-
-/* These represent the top nibble of the command value. */
-#define IT_S_SET_FILTER              0 /* Greyed out in IT... */
-#define IT_S_SET_GLISSANDO_CONTROL   1 /* Greyed out in IT... */
-#define IT_S_FINETUNE                2 /* Greyed out in IT... */
-#define IT_S_SET_VIBRATO_WAVEFORM    3
-#define IT_S_SET_TREMOLO_WAVEFORM    4
-#define IT_S_SET_PANBRELLO_WAVEFORM  5
-#define IT_S_FINE_PATTERN_DELAY      6
-#define IT_S7                        7
-#define IT_S_SET_PAN                 8
-#define IT_S_SET_SURROUND_SOUND      9
-#define IT_S_SET_HIGH_OFFSET        10
-#define IT_S_PATTERN_LOOP           11
-#define IT_S_DELAYED_NOTE_CUT       12
-#define IT_S_NOTE_DELAY             13
-#define IT_S_PATTERN_DELAY          14
-#define IT_S_SET_MIDI_MACRO         15
-
-/*
-S0x Set filter
-S1x Set glissando control
-S2x Set finetune
-
-
-S3x Set vibrato waveform to type x
-S4x Set tremelo waveform to type x
-S5x Set panbrello waveform to type x
-  Waveforms for commands S3x, S4x and S5x:
-    0: Sine wave
-    1: Ramp down
-    2: Square wave
-    3: Random wave
-S6x Pattern delay for x ticks
-S70 Past note cut
-S71 Past note off
-S72 Past note fade
-S73 Set NNA to note cut
-S74 Set NNA to continue
-S75 Set NNA to note off
-S76 Set NNA to note fade
-S77 Turn off volume envelope
-S78 Turn on volume envelope
-S79 Turn off panning envelope
-S7A Turn on panning envelope
-S7B Turn off pitch envelope
-S7C Turn on pitch envelope
-S8x Set panning position
-S91 Set surround sound
-SAy Set high value of sample offset yxx00h
-SB0 Set loopback point
-SBx Loop x times to loopback point
-SCx Note cut after x ticks
-SDx Note delay for x ticks
-SEx Pattern delay for x rows
-SFx Set parameterised MIDI Macro
-*/
-
-struct IT_ENTRY
-{
-	unsigned char channel; /* End of row if channel >= DUMB_IT_N_CHANNELS */
-	unsigned char mask;
-	unsigned char note;
-	unsigned char instrument;
-	unsigned char volpan;
-	unsigned char effect;
-	unsigned char effectvalue;
-};
-
-
-
-struct IT_PATTERN
-{
-	int n_rows;
-	int n_entries;
-	IT_ENTRY *entry;
-};
-
-
-
-#define IT_STEREO            1
-#define IT_USE_INSTRUMENTS   4
-#define IT_LINEAR_SLIDES     8 /* If not set, use Amiga slides */
-#define IT_OLD_EFFECTS      16
-#define IT_COMPATIBLE_GXX   32
-
-/* Make sure IT_WAS_AN_XM and IT_WAS_A_MOD aren't set accidentally */
-#define IT_REAL_FLAGS       63
-
-#define IT_WAS_AN_XM        64 /* Set for both XMs and MODs */
-#define IT_WAS_A_MOD       128
-
-#define IT_WAS_AN_S3M      256
-
-#define IT_WAS_A_PTM       512
-
-#define IT_WAS_A_669      1024
-
-#define IT_WAS_AN_OKT     2048
-
-#define IT_WAS_AN_STM     4096
-
-#define IT_WAS_PROCESSED  8192 /* Will be set the first time a sigdata passes through a sigrenderer */
-
-#define IT_ORDER_END  255
-#define IT_ORDER_SKIP 254
-
-struct DUMB_IT_SIGDATA
-{
-	unsigned char name[65];
-
-	unsigned char *song_message;
-
-	int n_orders;
-	int n_instruments;
-	int n_samples;
-	int n_patterns;
-	int n_pchannels;
-
-	int flags;
-
-	int global_volume;
-	int mixing_volume;
-	int speed;
-	int tempo;
-	int pan_separation;
-
-	unsigned char channel_pan[DUMB_IT_N_CHANNELS];
-	unsigned char channel_volume[DUMB_IT_N_CHANNELS];
-
-	unsigned char *order;
-	unsigned char restart_position; /* for XM compatiblity */
-
-	IT_INSTRUMENT *instrument;
-	IT_SAMPLE *sample;
-	IT_PATTERN *pattern;
-
-	IT_MIDI *midi;
-
-	IT_CHECKPOINT *checkpoint;
-};
-
-
-
-struct IT_PLAYING_ENVELOPE
-{
-	int next_node;
-	int tick;
-	int value;
-};
-
-
-
-#define IT_PLAYING_BACKGROUND 1
-#define IT_PLAYING_SUSTAINOFF 2
-#define IT_PLAYING_FADING     4
-#define IT_PLAYING_DEAD       8
-#define IT_PLAYING_REVERSE    16
-
-struct IT_PLAYING
-{
-	int flags;
-
-	int resampling_quality;
-
-	IT_CHANNEL *channel;
-	IT_SAMPLE *sample;
-	IT_INSTRUMENT *instrument;
-	IT_INSTRUMENT *env_instrument;
-
-	unsigned short sampnum;
-	unsigned char instnum;
-
-	unsigned char declick_stage;
-
-	float float_volume[2];
-	float ramp_volume[2];
-	float ramp_delta[2];
-
-	unsigned char channel_volume;
-
-	unsigned char volume;
-	unsigned short pan;
-
-	signed char volume_offset, panning_offset;
-
-	unsigned char note;
-
-	unsigned char enabled_envelopes;
-
-	unsigned char filter_cutoff;
-	unsigned char filter_resonance;
-
-	unsigned short true_filter_cutoff;   /* These incorporate the filter envelope, and will not */
-	unsigned char true_filter_resonance; /* be changed if they would be set to 127<<8 and 0.    */
-
-	unsigned char vibrato_speed;
-	unsigned char vibrato_depth;
-	unsigned char vibrato_n; /* May be specified twice: volpan & effect. */
-	unsigned char vibrato_time;
-	unsigned char vibrato_waveform;
-
-	unsigned char tremolo_speed;
-	unsigned char tremolo_depth;
-	unsigned char tremolo_time;
-	unsigned char tremolo_waveform;
-
-	unsigned char panbrello_speed;
-	unsigned char panbrello_depth;
-	unsigned char panbrello_time;
-	unsigned char panbrello_waveform;
-	signed char panbrello_random;
-
-	unsigned char sample_vibrato_time;
-	unsigned char sample_vibrato_waveform;
-	int sample_vibrato_depth; /* Starts at rate?0:depth, increases by rate */
-
-	int slide;
-	float delta;
-	int finetune;
-
-	IT_PLAYING_ENVELOPE volume_envelope;
-	IT_PLAYING_ENVELOPE pan_envelope;
-	IT_PLAYING_ENVELOPE pitch_envelope;
-
-	int fadeoutcount;
-
-	IT_FILTER_STATE filter_state[2]; /* Left and right */
-
-	DUMB_RESAMPLER resampler;
-
-	/* time_lost is used to emulate Impulse Tracker's sample looping
-	 * characteristics. When time_lost is added to pos, the result represents
-	 * the position in the theoretical version of the sample where all loops
-	 * have been expanded. If this is stored, the resampling helpers will
-	 * safely convert it for use with new loop boundaries. The situation is
-	 * slightly more complicated if dir == -1 when the change takes place; we
-	 * must reflect pos off the loop end point and set dir to 1 before
-	 * proceeding.
-	 */
-	long time_lost;
-
-	//int output;
-};
-
-
-
-#define IT_CHANNEL_MUTED 1
-
-#define IT_ENV_VOLUME  1
-#define IT_ENV_PANNING 2
-#define IT_ENV_PITCH   4
-
-struct IT_CHANNEL
-{
-	int flags;
-
-	unsigned char volume;
-	signed char volslide;
-	signed char xm_volslide;
-	signed char panslide;
-
-	/* xm_volslide is used for volume slides done in the volume column in an
-	 * XM file, since it seems the volume column slide is applied first,
-	 * followed by clamping, followed by the effects column slide. IT does
-	 * not exhibit this behaviour, so xm_volslide is maintained at zero.
-	 */
-
-	unsigned char pan;
-	unsigned short truepan;
-
-	unsigned char channelvolume;
-	signed char channelvolslide;
-
-	unsigned char instrument;
-	unsigned char note;
-
-	unsigned char SFmacro;
-
-	unsigned char filter_cutoff;
-	unsigned char filter_resonance;
-
-	unsigned char key_off_count;
-	unsigned char note_cut_count;
-	unsigned char note_delay_count;
-	IT_ENTRY *note_delay_entry;
-
-	unsigned char new_note_action;
-
-	unsigned char const* arpeggio_table;
-	signed char arpeggio_offsets[3];
-
-	int arpeggio_shift;
-	unsigned char retrig;
-	unsigned char xm_retrig;
-	int retrig_tick;
-
-	unsigned char tremor;
-	unsigned char tremor_time; /* Bit 6 set if note on; bit 7 set if tremor active. */
-
-	unsigned char vibrato_waveform;
-	unsigned char tremolo_waveform;
-	unsigned char panbrello_waveform;
-
-	int portamento;
-	int toneporta;
-	int toneslide;
-	unsigned char toneslide_tick, last_toneslide_tick, ptm_toneslide, ptm_last_toneslide, okt_toneslide;
-	unsigned char destnote;
-	unsigned char toneslide_retrig;
-
-	unsigned char glissando;
-
-	/** WARNING - for neatness, should one or both of these be in the IT_PLAYING struct? */
-	unsigned short sample;
-	unsigned char truenote;
-
-	unsigned char midi_state;
-
-	signed char lastvolslide;
-	unsigned char lastDKL;
-	unsigned char lastEF; /* Doubles as last portamento up for XM files */
-	unsigned char lastG;
-	unsigned char lastHspeed;
-	unsigned char lastHdepth;
-	unsigned char lastRspeed;
-	unsigned char lastRdepth;
-	unsigned char lastYspeed;
-	unsigned char lastYdepth;
-	unsigned char lastI;
-	unsigned char lastJ; /* Doubles as last portamento down for XM files */
-	unsigned char lastN;
-	unsigned char lastO;
-	unsigned char high_offset;
-	unsigned char lastP;
-	unsigned char lastQ;
-	unsigned char lastS;
-	unsigned char pat_loop_row;
-	unsigned char pat_loop_count;
-	unsigned char pat_loop_end_row; /* Used to catch infinite pattern loops */
-	unsigned char lastW;
-
-	unsigned char xm_lastE1;
-	unsigned char xm_lastE2;
-	unsigned char xm_lastEA;
-	unsigned char xm_lastEB;
-	unsigned char xm_lastX1;
-	unsigned char xm_lastX2;
-
-	unsigned char inv_loop_delay;
-	unsigned char inv_loop_speed;
-	int inv_loop_offset;
-
-	IT_PLAYING *playing;
-
-#ifdef BIT_ARRAY_BULLSHIT
-	void * played_patjump;
-	int played_patjump_order;
-#endif
-
-	//int output;
-};
-
-
-
-struct DUMB_IT_SIGRENDERER
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	int n_channels;
-
-	int resampling_quality;
-
-	unsigned char globalvolume;
-	signed char globalvolslide;
-
-	int tempo;
-	signed char temposlide;
-
-	IT_CHANNEL channel[DUMB_IT_N_CHANNELS];
-
-	IT_PLAYING *playing[DUMB_IT_N_NNA_CHANNELS];
-
-	int tick;
-	int speed;
-	int rowcount;
-
-	int order; /* Set to -1 if the song is terminated by a callback. */
-	int row;
-	int processorder;
-	int processrow;
-	int breakrow;
-
-	int restart_position;
-
-	int n_rows;
-
-	IT_ENTRY *entry_start;
-	IT_ENTRY *entry;
-	IT_ENTRY *entry_end;
-
-	long time_left; /* Time before the next tick is processed */
-	int sub_time_left;
-
-	DUMB_CLICK_REMOVER **click_remover;
-
-	IT_CALLBACKS *callbacks;
-
-#ifdef BIT_ARRAY_BULLSHIT
-	/* bit array, which rows are played, only checked by pattern break or loop commands */
-	void * played;
-
-	/*
-	   Loop indicator for internal processes, may also be useful for external processes 
-	   0 - Not looped
-	   1 - Looped
-	  -1 - Continued past loop
-	 */
-	int looped;
-
-	/*
-	   Kept until looped
-	*/
-	LONG_LONG time_played;
-
-	void * row_timekeeper;
-#endif
-
-	long gvz_time;
-	int gvz_sub_time;
-
-    int ramp_style;
-    
-	//int max_output;
-};
-
-
-
-struct IT_CHECKPOINT
-{
-	IT_CHECKPOINT *next;
-	long time;
-	DUMB_IT_SIGRENDERER *sigrenderer;
-};
-
-
-
-struct IT_CALLBACKS
-{
-	int (*loop)(void *data);
-	void *loop_data;
-	/* Return 1 to prevent looping; the music will terminate abruptly. If you
-	 * want to make the music stop but allow samples to fade (beware, as they
-	 * might not fade at all!), use dumb_it_sr_set_speed() and set the speed
-	 * to 0. Note that xm_speed_zero() will not be called if you set the
-	 * speed manually, and also that this will work for IT and S3M files even
-	 * though the music can't stop in this way by itself.
-	 */
-
-	int (*xm_speed_zero)(void *data);
-	void *xm_speed_zero_data;
-	/* Return 1 to terminate the mod, without letting samples fade. */
-
-	int (*midi)(void *data, int channel, unsigned char byte);
-	void *midi_data;
-	/* Return 1 to prevent DUMB from subsequently interpreting the MIDI bytes
-	 * itself. In other words, return 1 if the Zxx macros in an IT file are
-	 * controlling filters and shouldn't be.
-	 */
-
-	int (*global_volume_zero)(void *data);
-	void *global_volume_zero_data;
-	/* Return 1 to terminate the module when global volume is set to zero. */
-};
-
-
-
-void _dumb_it_end_sigrenderer(sigrenderer_t *sigrenderer);
-void _dumb_it_unload_sigdata(sigdata_t *vsigdata);
-
-extern DUH_SIGTYPE_DESC _dumb_sigtype_it;
-
-
-
-#define XM_APPREGIO                0
-#define XM_PORTAMENTO_UP           1
-#define XM_PORTAMENTO_DOWN         2
-#define XM_TONE_PORTAMENTO         3
-#define XM_VIBRATO                 4
-#define XM_VOLSLIDE_TONEPORTA      5
-#define XM_VOLSLIDE_VIBRATO        6
-#define XM_TREMOLO                 7
-#define XM_SET_PANNING             8
-#define XM_SAMPLE_OFFSET           9
-#define XM_VOLUME_SLIDE            10 /* A */
-#define XM_POSITION_JUMP           11 /* B */
-#define XM_SET_CHANNEL_VOLUME      12 /* C */
-#define XM_PATTERN_BREAK           13 /* D */
-#define XM_E                       14 /* E */
-#define XM_SET_TEMPO_BPM           15 /* F */
-#define XM_SET_GLOBAL_VOLUME       16 /* G */
-#define XM_GLOBAL_VOLUME_SLIDE     17 /* H */
-#define XM_KEY_OFF                 20 /* K (undocumented) */
-#define XM_SET_ENVELOPE_POSITION   21 /* L */
-#define XM_PANNING_SLIDE           25 /* P */
-#define XM_MULTI_RETRIG            27 /* R */
-#define XM_TREMOR                  29 /* T */
-#define XM_X                       33 /* X */
-#define XM_N_EFFECTS               (10+26)
-
-#define XM_E_SET_FILTER            0x0
-#define XM_E_FINE_PORTA_UP         0x1
-#define XM_E_FINE_PORTA_DOWN       0x2
-#define XM_E_SET_GLISSANDO_CONTROL 0x3
-#define XM_E_SET_VIBRATO_CONTROL   0x4
-#define XM_E_SET_FINETUNE          0x5
-#define XM_E_SET_LOOP              0x6
-#define XM_E_SET_TREMOLO_CONTROL   0x7
-#define XM_E_SET_PANNING           0x8
-#define XM_E_RETRIG_NOTE           0x9
-#define XM_E_FINE_VOLSLIDE_UP      0xA
-#define XM_E_FINE_VOLSLIDE_DOWN    0xB
-#define XM_E_NOTE_CUT              0xC
-#define XM_E_NOTE_DELAY            0xD
-#define XM_E_PATTERN_DELAY         0xE
-#define XM_E_SET_MIDI_MACRO        0xF
-
-#define XM_X_EXTRAFINE_PORTA_UP    1
-#define XM_X_EXTRAFINE_PORTA_DOWN  2
-
-/* To make my life a bit simpler during conversion, effect E:xy is converted
- * to effect number EBASE+x:y. The same applies to effect X, and IT's S. That
- * way, these effects can be manipulated like regular effects.
- */
-#define EBASE              (XM_N_EFFECTS)
-#define XBASE              (EBASE+16)
-#define SBASE              (IT_N_EFFECTS)
-
-#define EFFECT_VALUE(x, y) (((x)<<4)|(y))
-#define HIGH(v)            ((v)>>4)
-#define LOW(v)             ((v)&0x0F)
-#define SET_HIGH(v, x)     v = (((x)<<4)|((v)&0x0F))
-#define SET_LOW(v, y)      v = (((v)&0xF0)|(y))
-#define BCD_TO_NORMAL(v)   (HIGH(v)*10+LOW(v))
-
-
-
-#if 0
-unsigned char **_dumb_malloc2(int w, int h);
-void _dumb_free2(unsigned char **line);
-#endif
-
-void _dumb_it_xm_convert_effect(int effect, int value, IT_ENTRY *entry, int mod);
-int _dumb_it_fix_invalid_orders(DUMB_IT_SIGDATA *sigdata);
-
-
-#define PTM_APPREGIO                0
-#define PTM_PORTAMENTO_UP           1
-#define PTM_PORTAMENTO_DOWN         2
-#define PTM_TONE_PORTAMENTO         3
-#define PTM_VIBRATO                 4
-#define PTM_VOLSLIDE_TONEPORTA      5
-#define PTM_VOLSLIDE_VIBRATO        6
-#define PTM_TREMOLO                 7
-#define PTM_SAMPLE_OFFSET           9
-#define PTM_VOLUME_SLIDE            10 /* A */
-#define PTM_POSITION_JUMP           11 /* B */
-#define PTM_SET_CHANNEL_VOLUME      12 /* C */
-#define PTM_PATTERN_BREAK           13 /* D */
-#define PTM_E                       14 /* E */
-#define PTM_SET_TEMPO_BPM           15 /* F */
-#define PTM_SET_GLOBAL_VOLUME       16 /* G */
-#define PTM_RETRIGGER               17 /* H */
-#define PTM_FINE_VIBRATO            18 /* I */
-#define PTM_NOTE_SLIDE_UP           19 /* J */
-#define PTM_NOTE_SLIDE_DOWN         20 /* K */
-#define PTM_NOTE_SLIDE_UP_RETRIG    21 /* L */
-#define PTM_NOTE_SLIDE_DOWN_RETRIG  22 /* M */
-#define PTM_N_EFFECTS               23
-
-#define PTM_E_FINE_PORTA_DOWN       0x1
-#define PTM_E_FINE_PORTA_UP         0x2
-#define PTM_E_SET_VIBRATO_CONTROL   0x4
-#define PTM_E_SET_FINETUNE          0x5
-#define PTM_E_SET_LOOP              0x6
-#define PTM_E_SET_TREMOLO_CONTROL   0x7
-#define PTM_E_SET_PANNING           0x8
-#define PTM_E_RETRIG_NOTE           0x9
-#define PTM_E_FINE_VOLSLIDE_UP      0xA
-#define PTM_E_FINE_VOLSLIDE_DOWN    0xB
-#define PTM_E_NOTE_CUT              0xC
-#define PTM_E_NOTE_DELAY            0xD
-#define PTM_E_PATTERN_DELAY         0xE
-
-/* To make my life a bit simpler during conversion, effect E:xy is converted
- * to effect number EBASE+x:y. The same applies to effect X, and IT's S. That
- * way, these effects can be manipulated like regular effects.
- */
-#define PTM_EBASE              (PTM_N_EFFECTS)
-
-void _dumb_it_ptm_convert_effect(int effect, int value, IT_ENTRY *entry);
-
-long _dumb_it_read_sample_data_adpcm4(IT_SAMPLE *sample, DUMBFILE *f);
-
-void _dumb_it_interleave_stereo_sample(IT_SAMPLE *sample);
-
-/* Calling either of these is optional */
-void _dumb_init_cubic();
-#ifdef _USE_SSE
-void _dumb_init_sse();
-#endif
-
-#endif /* INTERNAL_IT_H */
--- a/dumb/include/internal/lpc.h
+++ /dev/null
@@ -1,24 +1,0 @@
-/********************************************************************
- *                                                                  *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
- *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
- * by the Xiph.Org Foundation http://www.xiph.org/                  *
- *                                                                  *
- ********************************************************************
-
-  function: LPC low level routines
-  last mod: $Id: lpc.h 16037 2009-05-26 21:10:58Z xiphmont $
-
- ********************************************************************/
-
-#ifndef _V_LPC_H_
-#define _V_LPC_H_
-
-struct DUMB_IT_SIGDATA;
-extern void dumb_it_add_lpc(struct DUMB_IT_SIGDATA *sigdata);
-
-#endif
--- a/dumb/include/internal/resampler.h
+++ /dev/null
@@ -1,60 +1,0 @@
-#ifndef _RESAMPLER_H_
-#define _RESAMPLER_H_
-
-// Ugglay
-#ifdef RESAMPLER_DECORATE
-#undef PASTE
-#undef EVALUATE
-#define PASTE(a,b) a ## b
-#define EVALUATE(a,b) PASTE(a,b)
-#define resampler_init EVALUATE(RESAMPLER_DECORATE,_resampler_init)
-#define resampler_create EVALUATE(RESAMPLER_DECORATE,_resampler_create)
-#define resampler_delete EVALUATE(RESAMPLER_DECORATE,_resampler_delete)
-#define resampler_dup EVALUATE(RESAMPLER_DECORATE,_resampler_dup)
-#define resampler_dup_inplace EVALUATE(RESAMPLER_DECORATE,_resampler_dup_inplace)
-#define resampler_set_quality EVALUATE(RESAMPLER_DECORATE,_resampler_set_quality)
-#define resampler_get_free_count EVALUATE(RESAMPLER_DECORATE,_resampler_get_free_count)
-#define resampler_write_sample EVALUATE(RESAMPLER_DECORATE,_resampler_write_sample)
-#define resampler_write_sample_fixed EVALUATE(RESAMPLER_DECORATE,_resampler_write_sample_fixed)
-#define resampler_set_rate EVALUATE(RESAMPLER_DECORATE,_resampler_set_rate)
-#define resampler_ready EVALUATE(RESAMPLER_DECORATE,_resampler_ready)
-#define resampler_clear EVALUATE(RESAMPLER_DECORATE,_resampler_clear)
-#define resampler_get_sample_count EVALUATE(RESAMPLER_DECORATE,_resampler_get_sample_count)
-#define resampler_get_sample EVALUATE(RESAMPLER_DECORATE,_resampler_get_sample)
-#define resampler_get_sample_float EVALUATE(RESAMPLER_DECORATE,_resampler_get_sample_float)
-#define resampler_remove_sample EVALUATE(RESAMPLER_DECORATE,_resampler_remove_sample)
-#endif
-
-void resampler_init(void);
-
-void * resampler_create(void);
-void resampler_delete(void *);
-void * resampler_dup(const void *);
-void resampler_dup_inplace(void *, const void *);
-
-enum
-{
-    RESAMPLER_QUALITY_MIN = 0,
-    RESAMPLER_QUALITY_ZOH = 0,
-    RESAMPLER_QUALITY_BLEP = 1,
-    RESAMPLER_QUALITY_LINEAR = 2,
-    RESAMPLER_QUALITY_BLAM = 3,
-    RESAMPLER_QUALITY_CUBIC = 4,
-    RESAMPLER_QUALITY_SINC = 5,
-    RESAMPLER_QUALITY_MAX = 5
-};
-
-void resampler_set_quality(void *, int quality);
-
-int resampler_get_free_count(void *);
-void resampler_write_sample(void *, short sample);
-void resampler_write_sample_fixed(void *, int sample, unsigned char depth);
-void resampler_set_rate( void *, double new_factor );
-int resampler_ready(void *);
-void resampler_clear(void *);
-int resampler_get_sample_count(void *);
-int resampler_get_sample(void *);
-float resampler_get_sample_float(void *);
-void resampler_remove_sample(void *, int decay);
-
-#endif
--- a/dumb/include/internal/riff.h
+++ /dev/null
@@ -1,24 +1,0 @@
-#ifndef RIFF_H
-#define RIFF_H
-
-struct riff;
-
-struct riff_chunk
-{
-	unsigned type;
-    long offset;
-	unsigned size;
-    struct riff * nested;
-};
-
-struct riff
-{
-	unsigned type;
-	unsigned chunk_count;
-	struct riff_chunk * chunks;
-};
-
-struct riff * riff_parse( DUMBFILE * f, long offset, long size, unsigned proper );
-void riff_free( struct riff * );
-
-#endif
--- a/dumb/include/internal/stack_alloc.h
+++ /dev/null
@@ -1,113 +1,0 @@
-/* Copyright (C) 2002 Jean-Marc Valin */
-/**
-   @file stack_alloc.h
-   @brief Temporary memory allocation on stack
-*/
-/*
-   Redistribution and use in source and binary forms, with or without
-   modification, are permitted provided that the following conditions
-   are met:
-
-   - Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-
-   - Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-   - Neither the name of the Xiph.org Foundation nor the names of its
-   contributors may be used to endorse or promote products derived from
-   this software without specific prior written permission.
-
-   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
-   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef STACK_ALLOC_H
-#define STACK_ALLOC_H
-
-#ifdef WIN32
-# include <malloc.h>
-#else
-# ifdef HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  include <stdlib.h>
-# endif
-#endif
-
-/**
- * @def ALIGN(stack, size)
- *
- * Aligns the stack to a 'size' boundary
- *
- * @param stack Stack
- * @param size  New size boundary
- */
-
-/**
- * @def PUSH(stack, size, type)
- *
- * Allocates 'size' elements of type 'type' on the stack
- *
- * @param stack Stack
- * @param size  Number of elements
- * @param type  Type of element
- */
-
-/**
- * @def VARDECL(var)
- *
- * Declare variable on stack
- *
- * @param var Variable to declare
- */
-
-/**
- * @def ALLOC(var, size, type)
- *
- * Allocate 'size' elements of 'type' on stack
- *
- * @param var  Name of variable to allocate
- * @param size Number of elements
- * @param type Type of element
- */
-
-#ifdef ENABLE_VALGRIND
-
-#include <valgrind/memcheck.h>
-
-#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
-
-#define PUSH(stack, size, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(type)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type))),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
-
-#else
-
-#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
-
-#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
-
-#endif
-
-#if defined(VAR_ARRAYS)
-#define VARDECL(var)
-#define ALLOC(var, size, type) type var[size]
-#elif defined(USE_ALLOCA)
-#define VARDECL(var) var
-#define ALLOC(var, size, type) var = alloca(sizeof(type)*(size))
-#else
-#define VARDECL(var) var
-#define ALLOC(var, size, type) var = PUSH(stack, size, type)
-#endif
-
-
-#endif
--- a/dumb/include/internal/tarray.h
+++ /dev/null
@@ -1,31 +1,0 @@
-#ifndef _T_ARRAY_H_
-#define _T_ARRAY_H_
-
-#include <stdlib.h>
-
-#ifndef LONG_LONG
-#if defined __GNUC__ || defined __INTEL_COMPILER || defined __MWERKS__
-#define LONG_LONG long long
-#elif defined _MSC_VER || defined __WATCOMC__
-#define LONG_LONG __int64
-#elif defined __sgi
-#define LONG_LONG long long
-#else
-#error 64-bit integer type unknown
-#endif
-#endif
-
-void * timekeeping_array_create(size_t size);
-void timekeeping_array_destroy(void * array);
-void * timekeeping_array_dup(void * array);
-
-void timekeeping_array_reset(void * array, size_t loop_start);
-
-void timekeeping_array_push(void * array, size_t index, LONG_LONG time);
-void timekeeping_array_bump(void * array, size_t index);
-
-unsigned int timekeeping_array_get_count(void * array, size_t index);
-
-LONG_LONG timekeeping_array_get_item(void * array, size_t index);
-
-#endif
--- a/dumb/licence.txt
+++ /dev/null
@@ -1,87 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * licence.txt - Conditions for use of DUMB.          / / \  \
- *                                                   | <  /   \_
- * If you do not agree to these terms, please        |  \/ /\   /
- * do not use DUMB.                                   \_  /  > /
- *                                                      | \ / /
- * Information in [brackets] is provided to aid         |  ' /
- * interpretation of the licence.                        \__/
- */
-
-
-Dynamic Universal Music Bibliotheque, Version 0.9.3
-
-Copyright (C) 2001-2005 Ben Davis, Robert J Ohannessian and Julien Cugniere
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event shall the authors be held liable for any damages arising from the
-use of this software.
-
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely, subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim
-   that you wrote the original software. If you use this software in a
-   product, you are requested to acknowledge its use in the product
-   documentation, along with details on where to get an unmodified version of
-   this software, but this is not a strict requirement.
-
-   [Note that the above point asks for a link to DUMB, not just a mention.
-   Googling for DUMB doesn't help much! The URL is "http://dumb.sf.net/".]
-
-   [The link was originally strictly required. This was changed for two
-   reasons. Firstly, if many projects request an acknowledgement, the list of
-   acknowledgements can become quite unmanageable. Secondly, DUMB was placing
-   a restriction on the code using it, preventing people from using the GNU
-   General Public Licence which disallows any such restrictions. See
-   http://www.gnu.org/philosophy/bsd.html for more information on this
-   subject. However, if DUMB plays a significant part in your project, we do
-   urge you to acknowledge its use.]
-
-2. Altered source versions must be plainly marked as such, and must not be
-   misrepresented as being the original software.
-
-3. This notice may not be removed from or altered in any source distribution.
-
-4. If you are using the Program in someone else's bedroom on any Monday at
-   3:05 pm, you are not allowed to modify the Program for ten minutes. [This
-   clause provided by Inphernic; every licence should contain at least one
-   clause, the reasoning behind which is far from obvious.]
-
-5. Users who wish to use DUMB for the specific purpose of playing music are
-   required to feed their dog on every full moon (if deemed appropriate).
-   [This clause provided by Allefant, who couldn't remember what Inphernic's
-   clause was.]
-
-6. No clause in this licence shall prevent this software from being depended
-   upon by a product licensed under the GNU General Public Licence. If such a
-   clause is deemed to exist, Debian, then it shall be respected in spirit as
-   far as possible and all other clauses shall continue to apply in full
-   force.
-
-8. Take the number stated as introducing this clause. Multiply it by two,
-   then subtract four. Now insert a '+' between the two digits and evaluate
-   the resulting sum. Call the result 'x'. If you have not yet concluded that
-   every numbered clause in this licence whose ordinal number is strictly
-   greater than 'x' (with the exception of the present clause) is null and
-   void, Debian, then you are hereby informed that laughter is good for one's
-   health and you are warmly suggested to do it. By the way, Clauses 4, 5 and
-   6 are null and void. Incidentally, I like Kubuntu. The work you guys do is
-   awesome. (Lawyers, on the other hand ...)
-
-We regret that we cannot provide any warranty, not even the implied warranty
-of merchantability or fitness for a particular purpose.
-
-Some files generated or copied by automake, autoconf and friends are
-available in an extra download. These fall under separate licences but are
-all free to distribute. Please check their licences as necessary.
--- a/dumb/prj/.gitignore
+++ /dev/null
@@ -1,3 +1,0 @@
-dumb-build-Desktop-Release
-dumb-build-Desktop-Debug
-*.user
--- a/dumb/prj/dumb/dumb.pro
+++ /dev/null
@@ -1,130 +1,0 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator 2012-12-22T16:33:53
-#
-#-------------------------------------------------
-
-QT       -= core gui
-
-TARGET = dumb
-TEMPLATE = lib
-CONFIG += staticlib
-
-DEFINES += _USE_SSE
-
-INCLUDEPATH += ../../include
-
-QMAKE_CFLAGS += -msse
-
-SOURCES += \
-    ../../src/core/unload.c \
-    ../../src/core/rendsig.c \
-    ../../src/core/rendduh.c \
-    ../../src/core/register.c \
-    ../../src/core/readduh.c \
-    ../../src/core/rawsig.c \
-    ../../src/core/makeduh.c \
-    ../../src/core/loadduh.c \
-    ../../src/core/dumbfile.c \
-    ../../src/core/duhtag.c \
-    ../../src/core/duhlen.c \
-    ../../src/core/atexit.c \
-    ../../src/helpers/stdfile.c \
-    ../../src/helpers/silence.c \
-    ../../src/helpers/sampbuf.c \
-    ../../src/helpers/riff.c \
-    ../../src/helpers/resample.c \
-    ../../src/helpers/memfile.c \
-    ../../src/helpers/clickrem.c \
-    ../../src/helpers/barray.c \
-    ../../src/helpers/tarray.c \
-    ../../src/it/xmeffect.c \
-    ../../src/it/readxm2.c \
-    ../../src/it/readxm.c \
-    ../../src/it/readstm2.c \
-    ../../src/it/readstm.c \
-    ../../src/it/reads3m2.c \
-    ../../src/it/reads3m.c \
-    ../../src/it/readriff.c \
-    ../../src/it/readptm.c \
-    ../../src/it/readpsm.c \
-    ../../src/it/readoldpsm.c \
-    ../../src/it/readokt2.c \
-    ../../src/it/readokt.c \
-    ../../src/it/readmtm.c \
-    ../../src/it/readmod2.c \
-    ../../src/it/readmod.c \
-    ../../src/it/readdsmf.c \
-    ../../src/it/readasy.c \
-    ../../src/it/readamf2.c \
-    ../../src/it/readamf.c \
-    ../../src/it/readam.c \
-    ../../src/it/read6692.c \
-    ../../src/it/read669.c \
-    ../../src/it/ptmeffect.c \
-    ../../src/it/loadxm2.c \
-    ../../src/it/loadxm.c \
-    ../../src/it/loadstm2.c \
-    ../../src/it/loadstm.c \
-    ../../src/it/loads3m2.c \
-    ../../src/it/loads3m.c \
-    ../../src/it/loadriff2.c \
-    ../../src/it/loadriff.c \
-    ../../src/it/loadptm2.c \
-    ../../src/it/loadptm.c \
-    ../../src/it/loadpsm2.c \
-    ../../src/it/loadpsm.c \
-    ../../src/it/loadoldpsm2.c \
-    ../../src/it/loadoldpsm.c \
-    ../../src/it/loadokt2.c \
-    ../../src/it/loadokt.c \
-    ../../src/it/loadmtm2.c \
-    ../../src/it/loadmtm.c \
-    ../../src/it/loadmod2.c \
-    ../../src/it/loadmod.c \
-    ../../src/it/loadasy2.c \
-    ../../src/it/loadasy.c \
-    ../../src/it/loadamf2.c \
-    ../../src/it/loadamf.c \
-    ../../src/it/load6692.c \
-    ../../src/it/load669.c \
-    ../../src/it/itunload.c \
-    ../../src/it/itrender.c \
-    ../../src/it/itread2.c \
-    ../../src/it/itread.c \
-    ../../src/it/itorder.c \
-    ../../src/it/itmisc.c \
-    ../../src/it/itload2.c \
-    ../../src/it/itload.c \
-    ../../src/it/readany.c \
-    ../../src/it/loadany2.c \
-    ../../src/it/loadany.c \
-    ../../src/it/readany2.c \
-    ../../src/helpers/sinc_resampler.c \
-    ../../src/helpers/lpc.c
-
-HEADERS += \
-    ../../include/dumb.h \
-    ../../include/internal/riff.h \
-    ../../include/internal/it.h \
-    ../../include/internal/dumb.h \
-    ../../include/internal/barray.h \
-    ../../include/internal/tarray.h \
-    ../../include/internal/aldumb.h \
-    ../../include/internal/sinc_resampler.h \
-    ../../include/internal/stack_alloc.h \
-    ../../include/internal/lpc.h \
-    ../../include/internal/dumbfile.h
-unix:!symbian {
-    maemo5 {
-        target.path = /opt/usr/lib
-    } else {
-        target.path = /usr/lib
-    }
-    INSTALLS += target
-}
-
-OTHER_FILES += \
-    ../../src/helpers/resample.inc \
-    ../../src/helpers/resamp3.inc \
-    ../../src/helpers/resamp2.inc
--- a/dumb/readme.txt
+++ /dev/null
@@ -1,541 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readme.txt - General information on DUMB.          / / \  \
- *                                                   | <  /   \_
- *                                                   |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-
-********************
-*** Introduction ***
-********************
-
-
-Thank you for downloading DUMB v0.9.3! You should have the following
-documentation:
-
-   readme.txt    - This file
-   licence.txt   - Conditions for the use of this software
-   release.txt   - Release notes and changes for this and past releases
-   docs/
-     howto.txt   - Step-by-step instructions on adding DUMB to your project
-     faq.txt     - Frequently asked questions and answers to them
-     dumb.txt    - DUMB library reference
-     deprec.txt  - Information about deprecated parts of the API
-     ptr.txt     - Quick introduction to pointers for those who need it
-     fnptr.txt   - Explanation of function pointers for those who need it
-     modplug.txt - Our official position regarding ModPlug Tracker
-
-This file will help you get DUMB set up. If you have not yet done so, please
-read licence.txt and release.txt before proceeding. After you've got DUMB set
-up, please refer to the files in the docs/ directory at your convenience. I
-recommend you start with howto.txt.
-
-
-****************
-*** Features ***
-****************
-
-
-Here is the statutory feature list:
-
-- Freeware
-
-- Supports playback of IT, XM, S3M and MOD files
-
-- Faithful to the original trackers, especially IT; if it plays your module
-  wrongly, please tell me so I can fix the bug! (But please don't complain
-  about differences between DUMB and ModPlug Tracker; see docs/modplug.txt)
-
-- Accurate support for low-pass resonant filters for IT files
-
-- Very accurate timing and pitching; completely deterministic playback
-
-- Click removal
-
-- Facility to embed music files in other files (e.g. Allegro datafiles)
-
-- Three resampling quality settings: aliasing, linear interpolation and cubic
-  interpolation
-
-- Number of samples playing at once can be limited to reduce processor usage,
-  but samples will come back in when other louder ones stop
-
-- All notes will be present and correct even if you start a piece of music in
-  the middle
-
-- Option to take longer loading but seek fast to any point before the music
-  first loops (seeking time increases beyond this point)
-
-- Audio generated can be used in any way; DUMB does not necessarily send it
-  straight to a sound output system
-
-- Can be used with Allegro, can be used without (if you'd like to help make
-  DUMB more approachable to people who aren't using Allegro, please contact
-  me)
-
-- Makefile provided for DJGPP, MinGW, Linux, BeOS and Mac OS X
-
-- Project files provided for MSVC 6
-
-- Autotools-based configure script available as a separate download for
-  masochists
-
-- Code should port anywhere that has a 32-bit C compiler; instructions on
-  compiling it manually are available further down
-
-
-*********************
-*** What you need ***
-*********************
-
-
-To use DUMB, you need a 32-bit C compiler (GCC and MSVC are fine). If you
-have Allegro, DUMB can integrate with its audio streams and datafiles, making
-your life easier. If you do not wish to use Allegro, you will have to do some
-work to get music playing back. The 'dumbplay' example program requires
-Allegro.
-
-   Allegro - http://alleg.sf.net/
-
-
-**********************************************
-*** How to set DUMB up with DJGPP or MinGW ***
-**********************************************
-
-
-You should have got the .zip version. If for some reason you got the .tar.gz
-version instead, you may have to convert make/config.bat to DOS text file
-format. WinZip does this automatically by default. Otherwise, loading it into
-MS EDIT and saving it again should do the trick (but do not do this to the
-Makefiles as it destroys tabs). You will have to do the same for any files
-you want to view in Windows Notepad. If you have problems, just go and
-download the .zip instead.
-
-Make sure you preserved the directory structure when you extracted DUMB from
-the archive. Most unzipping programs will do this by default, but pkunzip
-requires you to pass -d. If not, please delete DUMB and extract it again
-properly.
-
-If you are using Windows, open an MS-DOS Prompt or a Windows Command Line.
-Change to the directory into which you unzipped DUMB.
-
-If you are using MinGW (and you haven't renamed 'mingw32-make'), type:
-
-   mingw32-make
-
-Otherwise, type the following:
-
-   make
-
-DUMB will ask you whether you wish to compile for DJGPP or MinGW. Then it
-will ask you whether you want support for Allegro. (You have to have made and
-installed Allegro's optimised library for this to work.) Finally, it will
-compile optimised and debugging builds of DUMB, along with the example
-programs. When it has finished, run one of the following to install the
-libraries:
-
-   make install
-   mingw32-make install
-
-All done! If you ever need the configuration again (e.g. if you compiled for
-DJGPP before and you want to compile for MinGW now), run one of the
-following:
-
-   make config
-   mingw32-make config
-
-See the comments in the Makefile for other targets.
-
-Note: the Makefile will only work properly if you have COMSPEC or ComSpec set
-to point to command.com or cmd.exe. If you set it to point to a Unix-style
-shell, the Makefile won't work.
-
-Please let me know if you have any trouble.
-
-As an alternative, MSYS users may attempt to use the configure script,
-available in dumb-0.9.3-autotools.tar.gz. This has been found to work without
-Allegro, and is untested with Allegro. I should appreciate feedback from
-anyone else who tries this. I do not recommend its use, partly because it
-creates dynamically linked libraries and I don't know how to stop it from
-doing that (see the section on compiling DUMB manually), and partly because
-autotools are plain evil.
-
-Scroll down for information on the example programs. Refer to docs/howto.txt
-when you are ready to start programming with DUMB. If you use DUMB in a game,
-let me know - I might decide to place a link to your game on DUMB's website!
-
-
-******************************************************
-*** How to set DUMB up with Microsoft Visual C++ 6 ***
-******************************************************
-
-
-If you have a newer version of Microsoft Visual C++ or Visual Something that
-supports C++, please try these instructions and let me know if it works.
-
-You should have got the .zip version. If for some reason you got the .tar.gz
-version instead, you may have to convert some files to DOS text file format.
-WinZip does this automatically by default. Otherwise, loading such files into
-MS EDIT and saving them again should do the trick. You will have to do this
-for any files you want to view in Windows Notepad. If you have problems, just
-go and download the .zip instead.
-
-Make sure you preserved the directory structure when you extracted DUMB from
-the archive. Most unzipping programs will do this by default, but pkunzip
-requires you to pass -d. If not, please delete DUMB and extract it again
-properly.
-
-DUMB comes with a workspace Microsoft Visual C++ 6, containing projects for
-the DUMB core, the Allegro interface library and each of the examples. The
-first thing you might want to do is load the workspace up and have a look
-around. You will find it in the dumb\vc6 directory under the name dumb.dsw.
-Note that the aldumb and dumbplay projects require Allegro, so they won't
-work if you don't have Allegro. Nevertheless, dumbplay is the best-commented
-of the examples, so do have a look.
-
-When you are ready to add DUMB to your project, follow these instructions:
-
-1. Open your project in VC++.
-2. Select Project|Insert Project into Workspace...
-3. Navigate to the dumb\vc6\dumb directory and select dumb.dsp.
-   Alternatively, if you know that you are statically linking with a library
-   that uses the statically linked multithreaded runtime (/MT), you may wish
-   to select dumb_static.dsp in the dumb_static subdirectory instead.
-4. Select Build|Set Active Configuration..., and reselect one of your
-   project's configurations.
-5. Select Project|Dependencies... and ensure your project is dependent on
-   DUMB.
-6. Select Project|Settings..., Settings for: All Configurations, C/C++ tab,
-   Preprocessor category. Add the DUMB include directory to the Additional
-   Include Directories box.
-7. Ensure that for all the projects in the workspace (or more likely just all
-   the projects in a particular dependency chain) the run-time libraries are
-   the same. That's in Project|Settings, C/C++ tab, Code generation category,
-   Use run-time library dropdown. The settings for Release and Debug are
-   separate, so you'll have to change them one at a time. Exactly which run-
-   time library you use will depend on what you need; it doesn't appear that
-   DUMB has any particular requirements, so set it to whatever you're using
-   now. (It will have to be /MD, the multithreaded DLL library, if you are
-   statically linking with Allegro. If you are dynamically linking with
-   Allegro than it doesn't matter.)
-8. If you are using Allegro, do some or all of the above for the aldumb.dsp
-   project in the aldumb directory too.
-
-Good thing you only have to do all that once ... or twice ...
-
-If you have the Intel compiler installed, it will - well, should - be used to
-compile DUMB. The only setting I [Tom Seddon] added is /QxiM. This allows the
-compiler to use PPro and MMX instructions, and so when compiling with Intel
-the resultant EXE will require a Pentium II or greater. I don't think this is
-unreasonable. After all, it is 2003 :)
-
-[Note from Ben: the Intel compiler is evil! It makes AMD processors look bad!
-Patch it or boycott it or something!]
-
-If you don't have the Intel compiler, VC will compile DUMB as normal.
-
-This project file and these instructions were provided by Tom Seddon (I hope
-I got his name right; I had to guess it from his e-mail address!). Chad
-Austin has since changed the project files around, and I've just attempted to
-hack them to incorporate new source files. I've also tried to update the
-instructions using guesswork and some knowledge of Visual J++ (you heard me).
-The instructions and the project files are to this day untested by me. If you
-have problems, check the download page at http://dumb.sf.net/ to see if they
-are addressed; failing that, direct queries to me and I'll try to figure them
-out.
-
-If you have any comments at all on how the VC6 projects are laid out, or how
-the instructions could be improved, I should be really grateful to hear them.
-I am a perfectionist, after all. :)
-
-Scroll down for information on the example programs. When you are ready to
-start using DUMB, refer to docs/howto.txt. If you use DUMB in a game, let me
-know - I might decide to place a link to your game on DUMB's website!
-
-
-******************************************************
-*** How to set DUMB up on Linux, BeOS and Mac OS X ***
-******************************************************
-
-
-You should have got the .tar.gz version. If for some reason you got the .zip
-version instead, you may have to strip all characters with ASCII code 13 from
-some of the text files. If you have problems, just go and download the
-.tar.gz instead.
-
-You have two options. There is a Makefile which should cope with most
-systems. The first option is to use this default Makefile, and the procedure
-is explained below. The second option is to download
-dumb-0.9.3-autotools.tar.gz, extract it over the installation, run
-./configure and use the generated Makefile. Users who choose to do this are
-left to their own devices but advised to read the information at the end of
-this section. I strongly recommend the first option.
-
-If you are not using the configure script, the procedure is as follows.
-
-First, run the following command as a normal user:
-
-   make
-
-You will be asked whether you want Allegro support. Then, unless you are on
-BeOS, you will be asked where you'd like DUMB to install its headers,
-libraries and examples (which will go in the include/, lib/ and bin/
-subdirectories of the prefix you specify). BeOS has fixed locations for these
-files. You may use shell variables here, e.g. $HOME or ${HOME}, but ~ will
-not work. Once you have specified these pieces of information, the optimised
-and debugging builds of DUMB will be compiled, along with the examples. When
-it has finished, you can install them with:
-
-   make install
-
-You may need to be root for this to work. It depends on the prefix you chose.
-
-Note: the Makefile will only work if COMSPEC and ComSpec are both undefined.
-If either of these is defined, the Makefile will try to build for a Windows
-system, and will fail.
-
-Please let me know if you have any trouble.
-
-Scroll down for information on the example programs. Refer to docs/howto.txt
-when you are ready to start programming with DUMB. If you use DUMB in a game,
-let me know - I might decide to place a link to your game on DUMB's website!
-
-Important information for users of the configure script follows.
-
-The Makefile generated by the configure script creates dynamically linked
-libraries, and I don't know how to stop it from doing so. See the section
-below on building DUMB manually for why I recommend linking DUMB statically.
-However, if you choose to use the configure script, note the following.
-
-The default Makefile is a copy of Makefile.rdy (short for 'ready'), and it
-must exist with the name Makefile.rdy in order to work. The configure script
-will overwrite Makefile, so if you want the default Makefile back, just run:
-
-   cp Makefile.rdy Makefile
-
-Do not use a symlink, as that would result in Makefile.rdy getting
-overwritten next time the configure script is run!
-
-You can also access the usual build system by passing '-f Makefile.rdy' to
-Make.
-
-
-********************************************************
-*** How to build DUMB manually if nothing else works ***
-********************************************************
-
-
-Those porting to platforms without floating point support should be aware
-that DUMB does use floating point operations but not in the inner loops. They
-are used for volume and note pitch calculations, and they are used when
-initialising the filter algorithm for given cut-off and resonance values.
-Please let me know if this is a problem for you. If there is enough demand, I
-may be able to eliminate one or both of these cases.
-
-All of the library source code may be found in the src/ subdirectory. There
-are headers in the include/ subdirectory, and src/helpers/resample.c also
-#includes some .inc files in its own directory.
-
-There are four subdirectories under src/. For projects not using Allegro, you
-will need all the files in src/core/, src/helpers/ and src/it/. If you are
-using Allegro, you will want the src/allegro/ subdirectory too. For
-consistency with the other build systems, the contents of src/allegro/ should
-be compiled into a separate library.
-
-I recommend static-linking DUMB, since the version information is done via
-macros and the API has a tendency to change. If you static-link, then once
-your program is in binary form, you can be sure that changes to the installed
-version of DUMB won't cause it to malfuction. It is my fault that the API has
-been so unstable. Sorry!
-
-Compile each .c file separately. As mentioned above, you will need to specify
-two places to look for #include files: the include/ directory and the source
-file's own directory. You will also need to define the symbol
-DUMB_DECLARE_DEPRECATED on the command line.
-
-Do not compile the .inc files separately.
-
-You may need to edit dumb.h and add your own definition for LONG_LONG. It
-should be a 64-bit integer. If you do this, please see if you can add a check
-for your compiler so that it still works with other compilers.
-
-DUMB has two build modes. If you define the symbol DEBUGMODE, some checks for
-programmer error will be incorporated into the library. Otherwise it will be
-built without any such checks. (DUMB will however always thoroughly check the
-validity of files it is loading. If you ever find a module file that crashes
-DUMB, please let me know!)
-
-I recommend building two versions of the library, one with DEBUGMODE defined
-and debugging information included, and the other with compiler optimisation
-enabled. If you can install DUMB system-wide so that your projects, and other
-people's, can simply #include <dumb.h> or <aldumb.h> and link with libraries
-by simple name with no path, then that is ideal.
-
-If you successfully port DUMB to a new platform, please let me know!
-
-
-****************************
-*** The example programs ***
-****************************
-
-
-Three example programs are provided. On DOS and Windows, you can find them in
-the examples subdirectory. On other systems they will be installed system-
-wide.
-
-dumbplay
-   This program will only be built if you have Allegro. Pass it the filename
-   of an IT, XM, S3M or MOD file, and it will play it. It's not a polished
-   player with real-time threading or anything - so don't complain about it
-   stuttering while you use other programs - but it does show DUMB's fidelity
-   nicely. You can control the playback quality by editing dumb.ini, which
-   must be in the current working directory. (This is a flaw for systems
-   where the program is installed system-wide, but it is non-fatal.) Have a
-   look at the examples/dumb.ini file for further information.
-
-dumbout
-   This program does not need Allegro. You can use it to stream an IT, XM,
-   S3M or MOD file to raw PCM. This can be used as input to an encoder like
-   oggenc (with appropriate command-line options), or it can be sent to a
-   .pcm file which can be read by any respectable waveform editor. This
-   program is also convenient for timing DUMB. Compare the time it takes to
-   render a module with the module's playing time! dumbout doesn't try to
-   read any configuration file; the options are set on the command line.
-
-dumb2wav
-   This program is much the same as dumbout, but it writes a .wav file with
-   the appropriate header. Thanks go to Chad Austin for this useful tool.
-
-
-*********************************************
-*** Downloading music or writing your own ***
-*********************************************
-
-
-If you would like to compose your own music modules, then this section should
-help get you started.
-
-The best programs for the job are the trackers that pioneered the file
-formats:
-
-   Impulse Tracker - IT files - http://www.lim.com.au/ImpulseTracker/
-   Fast Tracker II - XM files - http://www.fasttracker2.com/
-   Scream Tracker 3 - S3M files - No official site known, please use Google
-
-MOD files come from the Amiga; I do not know what PC tracker to recommend for
-editing these. If you know of one, let me know! In the meantime, I would
-recommend using a more advanced file format. However, don't convert your
-existing MODs just for the sake of it.
-
-Fast Tracker II is Shareware. It offers a very flashy interface and has a
-game embedded, but the IT file format is more powerful and better defined. By
-all means try them both and see which you prefer; it is largely a matter of
-taste (and, in some cases, religion). Impulse Tracker and Scream Tracker 3
-are Freeware, although you can donate to Impulse Tracker and receive a
-slightly upgraded version. DUMB is likely to be at its best with IT files.
-
-These editors are DOS programs. Users of DOS-incapable operating systems may
-like to try ModPlug Tracker, but should read docs/modplug.txt before using it
-for any serious work. If you use a different operating system, or if you know
-of any module editors for Windows that are more faithful to the original
-trackers' playback, please give me some links so I can put them here!
-
-   ModPlug Tracker - http://www.modplug.com/
-
-If you have an x86 Linux system with VGA-compatible hardware (which covers
-all PC graphics cards I've ever seen), you should be able to get Impulse
-Tracker running with DOSEMU. You will have to give it access to the VGA ports
-and run it in a true console, as it will not work with the X-based VGA
-emulation. I personally added the SB16 emulation to DOSEMU, so you can even
-use filters! However, it corrupts samples alarmingly often when saving on my
-system - probably a DOSEMU issue. If you set this up, I am curious to know
-whether it works for you.
-
-   DOSEMU - http://www.dosemu.org/
-
-BEWARE OF WINAMP! Although it's excellent for MP3s, it is notorious for being
-one of the worst module players in existence; very many modules play wrongly
-with it. There are plug-ins available to improve Winamp's module support, for
-example WSP.
-
-   Winamp - http://www.winamp.com/
-   WSP - http://www.spytech.cz/index.php?sec=demo
-
-(There is a Winamp plug-in that uses DUMB, but it is unreliable. If anyone
-would like to work on it, please get in touch.)
-
-While I am at it I should also point out that Winamp is notorious for
-containing security flaws. Install it at your own risk, and if it is your
-work computer, check with your boss first!
-
-Samples and instruments are the building blocks of music modules. You can
-download samples at
-
-   http://www.tump.net/
-
-If you would like to download module files composed by other people, check
-the following sites:
-
-   http://www.modarchive.com/
-   http://www.scene.org/
-   http://www.tump.net/
-   http://www.homemusic.cc/main.php
-   http://www.modplug.com/
-
-Once again, if you know of more sites where samples or module files are
-available for download, please let me know.
-
-If you wish to use someone's music in your game, please respect the
-composer's wishes. In general, you should ask the composer. Music that has
-been placed in the Public Domain can be used by anyone for anything, but it
-wouldn't do any harm to ask anyway if you know who the author is. In many
-cases the author will be thrilled, so don't hesitate!
-
-A note about converting modules from one format to another, or converting
-from MIDI: don't do it, unless you are a musician and are prepared to go
-through the file and make sure everything sounds the way it should! The
-module formats are all slightly different, and MIDI is very different;
-converting from one format to another will usually do some damage.
-
-Instead, it is recommended that you allow DUMB to interpret the original file
-as it sees fit. DUMB may make mistakes (it does a lot of conversion on
-loading), but future versions of DUMB will be able to rectify these mistakes.
-On the other hand, if you convert the file, the damage is permanent.
-
-
-***********************
-*** Contact details ***
-***********************
-
-
-If you have trouble with DUMB, or want to contact me for any other reason, my
-e-mail address is given below. Please do get in touch, even if I appear to
-have disappeared!
-
-If you wish to chat online about something, perhaps on IRC, that can most
-likely be arranged. Send me an e-mail.
-
-
-******************
-*** Conclusion ***
-******************
-
-
-This is the conclusion.
-
-
-Ben Davis
-entheh@users.sf.net
--- a/dumb/release.txt
+++ /dev/null
@@ -1,561 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * release.txt - Release notes for DUMB.              / / \  \
- *                                                   | <  /   \_
- *                                                   |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-
-*******************************************
-*** DUMB v0.9.3, released 7 August 2005 ***
-*******************************************
-
-Hello! Welcome to a long-awaited-or-probably-just-given-up-on-by-everybody
-release! New to this release are lower memory usage, faster mixing loops,
-loading of text fields in the module files, and faster load functions for
-projects that don't need to seek within the module or know its length.
-Additionally, Chad Austin has contributed a dumb2wav tool for converting
-modules to .wav files and updated the Visual Studio 6 project files to
-compile all the examples as well as the library. Users of Unix-like systems
-will be pleased to know that on Chad's suggestion I have made the build
-system cope with variables such as $HOME or ${HOME} in the prefix.
-
-Chad has also contributed an Autotools build system, but neither of us
-recommends its use. The Autotools are an evil black box, we haven't quite
-managed to get it right, and goodness help you if it happens not to work for
-you. The files are available in a separate download if you absolutely need
-them. Notice that that download is almost twice as large as the rest of DUMB!
-
-Maybe we'll do SCons next time.
-
-Thanks to Chad for all his work. Chad is the author of Audiere, a portable
-sound library which has started using DUMB for its module playback! Wahoo!
-
-   http://audiere.sf.net/
-
-There are three main optimisations that went into the mixing loops.
-
-First, I downloaded ModPlugXMMS and had a peek at the mixing code, which is
-Public Domain. It uses look-up tables for the cubic mixing. I pinched the
-idea, and that sped DUMB's cubic (best quality) resamplers up by a factor of
-two or three.
-
-Secondly, the samples loaded from the file are now kept in 8-bit or 16-bit
-format, whereas previously they were being converted to 24-bit-in-32-bit on
-loading. This means the samples occupy a half or a quarter of the memory they
-used to occupy. It also had the side-effect of speeding up the mixing loops,
-but it meant I had to duplicate the resampling code. (It is all done with
-macros in the source code, but it becomes two copies on the binary level.)
-
-Secondly, stereo samples and stereo mixing buffers are now kept in
-interleaved format, where previously the two channels were done separately to
-keep the code simpler. This change has made the library quite a bit bigger,
-but has made the code run almost twice as fast for stereo output (tested for
-modules whose samples are mostly mono)!
-
-DUMB is now as fast as ModPlugXMMS on my system.
-
-Some people have also commented that DUMB seems to take a long time loading
-files. This is because immediately upon loading the file it runs the playback
-engine over it up as far as the point of first loop, taking snapshots at 30-
-second intervals to be used as references for fast seeking and finally
-storing the playback time. Of course, most games don't need this. You can now
-skip it by calling the _quick versions of the dumb_load_*(), dumb_read_*() or
-dumb_register_dat_*() functions. Should you need the data later, you can call
-dumb_it_do_initial_runthrough() to calculate it. Please note that this cannot
-currently be done safely from a concurrent thread while the music is playing.
-
-As mentioned, DUMB loads the text fields in module files now. You can
-retrieve the song title with duh_get_tag(). Sample names and file names and
-instrument names and filenames, and the song message for IT files, are
-available with a call to duh_get_it_sigdata() and various dumb_it_sd_*()
-functions. Please note that text fields added as extensions by ModPlug
-Tracker are not supported.
-
-DUMB's timing is ever so slightly more accurate. This is hardly noticeable,
-but it has meant that the length computed will increase very slightly.
-
-There are many small playback fixes in this release:
-
-* The Lxx effect in XM files (set envelope position) is now supported.
-
-* Pattern looping is now correct for XM files. Bizarrely, an ordinary pattern
-  loop whose start point isn't the first row seems to cause the next pattern
-  to start at the row corresponding to the loop start point. That must have
-  been a headache for people creating XM files! Nevertheless, DUMB now
-  emulates this behaviour. If you have an XM file that was written in a
-  tracker other than Fast Tracker II and breaks in DUMB, you can get around
-  it by putting a D00 effect (break to row 0) right at the end of the pattern
-  containing the loop.
-
-* XM pattern looping can be infinite. DUMB should detect this and call the
-  loop callback when it happens. Specifically, it has a loop counter for each
-  channel, so each time it sets or decrements that counter, it remembers the
-  loop end point for that channel. When the loop terminates, the loop end
-  point is reset to 0. If the loop end point ever decreases during a loop,
-  the loop callback is called. If anyone manages to get around this check and
-  prevent DUMB from calling the callback, please let me know and send me an
-  illustrative XM file!
-
-* For IT files, notes are now removed from channels if they have faded out,
-  even if they are still in the foreground. After this has happened, a row
-  with a note and Gxx (tone portamento) specified will cause a new note to
-  start playing, which is what Impulse Tracker does in this scenario.
-  (Normally, Gxx prevents the new note from playing and instead causes the
-  old note to start sliding towards the new note.)
-
-* If a tone portamento command occurred when no note was playing, the effect
-  value wasn't stored. This has been fixed. Thanks to Maim from #trax on
-  EFnet for discovering this bug.
-
-* DUMB now treats the parameter to the undocumented XM key off effect Kxx as
-  a delay, consistent with Fast Tracker II's behaviour. It has also been made
-  not to clear the note, so a subsequent volume command will restore it, as
-  in Fast Tracker II.
-
-* DUMB used to process the first row when you created the
-  DUMB_IT_SIGRENDERER. This happened before you had a chance to install any
-  callbacks. If an F00 effect occurred on the first row, the music would stop
-  immediately and the xm_speed_zero callback would be called if it were
-  present. Unfortunately, it wasn't present, and the algorithm for
-  calculating the length subsequently went into an endless loop while waiting
-  for it. Worse still, the same algorithm accumulated data for fast seeking,
-  and never stopped, so it pretty quickly consumed all the resources. DUMB
-  will now not process the first row until you first request some samples,
-  provided you pass zero for pos. Of course, any MOD or XM file with F00 in
-  the very first row won't do much anyway, but such files won't crash the
-  library now.
-
-* There was a subtle bug that affected a few XM files. For instruments with
-  no associated samples, the array mapping notes to samples is uninitialised.
-  This became a problem if such instruments were then used, which does happen
-  sometimes. On many systems, memory is initialised to zero when first given
-  to a program (for security reasons), so the problem didn't come up most of
-  the time. However, on platforms like DOS where memory isn't initialised, or
-  in programs that reuse memory later on (this includes the XMMS plug-in with
-  which I discovered the bug), a rogue note would occasionally play. This has
-  now been fixed.
-
-* DUMB's envelope handling for IT files was subtly wrong. Upon note off, it
-  stopped obeying the sustain loop points one tick too early. Notes were
-  often shorter than they should have been, and in pathological cases a whole
-  extra iteration of the sustain loop section might have been skipped. The
-  envelope code has now been rewritten. Thanks go to Allefant for Valgrinding
-  the new code!
-
-Finally, there were two build problems in the last version, which were fixed
-in the download marked with -fixed. They are of course correct in this
-version. For the record:
-
-* The make/config.bat file, responsible for generating make/config.txt, wrote
-  a crucial line to the wrong place, causing it to be left out of the file.
-  As a result, the makefile would fail to install everything for Allegro
-  users, and enter infinite recursion for other users. This applied to people
-  using DJGPP and MinGW.
-
-* DUMB's Makefile was supposed to install the example programs on Unix-based
-  platforms, but it wasn't doing. The fix was to edit Makefile and change the
-  one occurrence of $COMSPEC to $(COMSPEC).
-
-That's it! I hope you enjoy this long-awaited-or-probably-just-given-up-on-
-by-everybody release of DUMB!
-
-
-******************************************
-*** DUMB v0.9.2, released 2 April 2003 ***
-******************************************
-
-Yes, there really has been a release. This is not a day-late April fools'
-joke.
-
-DUMB's full name has changed! The old "Dedicated Universal Music
-Bastardisation" was rather silly, and not much more than a forced attempt at
-finding words beginning with D, U, M and B. I spent weeks and weeks browsing
-dictionaries and hopelessly asking others for bright ideas, until the
-brilliant Chris "Kitty Cat" Robinson came up with "Dynamic". I decided to
-keep the U as Universal, since a DUH struct can hold digital music in any
-format. Now all that remained was the B, but it didn't take me long to come
-up with Bibliotheque, which, despite looking French, is indeed considered an
-English word by Oxford English Dictionary Online, to which my university has
-a subscription. So there you have it - the name now makes sense.
-
-The two most significant additions to the project would have to be the new
-thread safety (with an important restriction, detailed in docs/dumb.txt), and
-the new build system. The silly 'makeall' and 'makecore' scripts are gone. If
-you are a GCC user, all you need do now is run 'make' and 'make install', as
-for other projects. You don't even have to run a 'fix' script any more! There
-are some caveats, which are covered in readme.txt. If you use Microsoft
-Visual C++ 6, you no longer need to obtain GCC and GNU Make - there is a
-project file just for you.
-
-Huge thanks go to Steve Terry for testing on Windows XP - about five times -
-and to lillo for testing on BeOS and Mac OS X. Thanks also to X-G for testing
-on a Windows system that has consistently posed problems for DUMB's old
-makefiles.
-
-There was a bug whereby al_poll_duh() would sometimes cause the music to
-resume playing if you called it after al_pause_duh(). Whether this was DUMB's
-fault for misusing Allegro's API, or a bug in Allegro, is unclear, but this
-release makes it work.
-
-In one of my projects, I found that my AL_DUH_PLAYER stopped playing when
-there were lots of other sound effects. In order to fix this, I programmed
-DUMB to set the priority of the stream's voice to 255, the maximum. I also
-added al_duh_set_priority(), so you can set the priority yourself if you need
-to.
-
-The resampling code has undergone a transformation. The bad news is that the
-linear average code is no longer in use. The good news is that where DUMB's
-resamplers used to require three extra samples' worth of memory to be
-allocated and initialised, it now copes with just the sample data. And it
-does a very good job at bouncing off loop points and otherwise hurtling
-around the sample. The resampling code is considerably more complicated, but
-the code that uses the resamplers is considerably simpler - and if you
-noticed a slight click in some bidirectionally looping samples, you'll be
-pleased to know that that click is gone!
-
-I have also devoted some effort to optimisation. It seemed hopeless for a
-while, but then I actually figured out a way of making it faster AND more
-accurate at the same time! DUMB is now quite a bit faster than it was, and it
-mixes not with 16-bit precision, but with 24-bit precision. (It used 32-bit
-integers all along, but the difference is that it now makes use of 256 times
-as much of the integer's range.)
-
-There have been the usual improvements to playback. The last release occurred
-rather too soon after I had fixed the XM effect memories; EAx and EBx, fine
-volume ramps, had been neglected. These are now handled properly.
-
-In previous versions of DUMB, muted channels in IT were actually played with
-surround sound panning (where the right-hand channel is inverted). This has
-been fixed, so muted channels will really be muted now.
-
-There were also some subtle problems with the way DUMB handled New Note
-Actions for IT files. It turned out that, in all releases of DUMB so far,
-pitch, filter and panning envelopes and sample vibrato were not being
-processed for any note that was forced into the background by a new note on
-the same channel! This only affected IT files. Not only has this been fixed,
-but envelope interpolation is much more accurate. Long trailing envelope-
-driven fade-outs sound a lot better now!
-
-Since panning and filter envelopes are more precise, extra fields have been
-added to the DUMB_IT_CHANNEL_STATE struct, used by
-dumb_it_sr_get_channel_state(). These fields hold the 'decimal' parts of the
-pan and filter cut-off. See dumb.txt for details.
-
-Mxx (set channel volume) now correctly only modifies the last note played on
-the channel, not any previous notes that have been forced into the background
-by New Note Actions, and filter effect processing is now closer to what
-Impulse Tracker does.
-
-The XM loader was slightly flawed and could crash on files containing samples
-with out-of-range loop points. One such file was given to me. This has been
-fixed.
-
-Finally, the legal stuff. Julien Cugniere has been added to the list of
-copyright owners. He deserves it, for all the work he did on the XM support!
-And the licence has been changed. You are no longer required to include a
-link to DUMB in a project that uses DUMB; the reasons for this relaxation are
-explained in licence.txt. However, the request is still there ...
-
-As usual, enjoy!
-
-
-**********************************************
-*** DUMB v0.9.1, released 19 December 2002 ***
-**********************************************
-
-Hi again! Lots to say this time, so I shall cut right to the chase.
-
-DUMB now supports Impulse Tracker's low-pass resonant filters! Huge thanks go
-to Jeffrey Lim, author of Impulse Tracker, for giving me what information he
-still had regarding the algorithm; to cut a long story short, modifying
-ModPlug Tracker's source code (which is in the Public Domain) led to an
-algorithm whose output matched Impulse Tracker's perfectly.
-
-Please note that ModPlug Tracker's filters as they stand do not match Impulse
-Tracker's, and I have no interest in supporting ModPlug Tracker's variant
-(especially not the integer rounding problems). Please see docs/modplug.txt,
-new in this release, for details.
-
-Thanks also go to Fatso Huuskonen for motivating me to add filter support,
-and providing me with several great IT files to test it with!
-
-The other important feature added for this release is click removal. Up until
-now, DUMB has generated clicks when cutting notes, starting samples in the
-middle, and so on. This version of DUMB will remove any such clicks. Note
-that DUMB does not use volume ramps to accomplish this; the algorithm will
-not take the bite out of the music!
-
-In other news, DUMB now supports sample vibrato for IT files, and instrument
-vibrato for XM files. A slight bug in New Note Action handling for IT files
-has been fixed; Note Fade will not break the sustain loops of the sample and
-envelope, as it did before. Tremor handling (Ixy) had a strange bug in it,
-which has been fixed.
-
-Support for XM files has been greatly enhanced. The XM envelope handling new
-in the last release contained a huge bug, resulting in notes seeming not to
-stop when they should; this has been fixed. Some XM files crashed DUMB, while
-others failed to load; these problems have been solved. Effect memories now
-work properly for XM and MOD files, to the best of my knowledge. Some other
-differences between IT and XM have been accounted for, most notably the
-Retrigger Note effects, Rxy and E9x.
-
-DUMB's sound quality and accuracy are not the only areas that have been
-enhanced. The API has been expanded, at last. You can now detect when a
-module loops, or make it play through just once. You can ask DUMB to inform
-you every time it generates some samples; this is useful for visualisation.
-For IT files, you can intercept the MIDI messages generated by Zxx macros,
-enabling you to synchronise your game with the music to some extent. (There
-is no such method for XM, S3M or MOD files yet; sorry. Also note that the
-function will be called before you actually hear the sound; I cannot improve
-this until DUMB has its own sound drivers, which won't be for a while.) You
-can query the current order and row. Finally, operations like changing the
-speed and tempo are now possible, and you can query the playback state on
-each channel.
-
-Some parts of DUMB's API have been deprecated. Simple programs that use
-Allegro will be unaffected, but if you get some compiler warnings or errors,
-please review docs/deprec.txt. This file explains why those parts of the API
-were deprecated, and tells you how to adapt your code; the changes you need
-to make are straightforward. Sorry for the inconvenience.
-
-For various reasons, I have made DUMB's makefiles use different compiler
-flags depending on your GCC version (unless you are using MSVC). There is no
-elegant way of getting the makefiles to detect when GCC is upgraded. If you
-upgrade GCC, you should execute 'make clean' in order to make DUMB detect the
-GCC version again. Otherwise you may get some annoying error messages. (It is
-wise to do this in any case, so that all the object files are built with the
-same GCC version.)
-
-DUMB's example players have been unified into a single player called
-'dumbplay'. The player has been enhanced to display messages when the music
-loops, and when XM and MOD files freeze (effect F00; more information on this
-in docs/howto.txt).
-
-Finally, as noted on DUMB's website, the release notes from the last release
-were inaccurate. It has been verified that DUMBOGG v0.5 does still work with
-that release, and still works with this release. The esoteric DUMBOGG v0.6
-has not been created yet, since DUMBOGG v0.5 still works.
-
-Please scroll down and read through the indented paragraphs in the notes for
-the last release; they are relevant for this release too.
-
-That's all folks! Until next time.
-
-
-*******************************************
-*** DUMB v0.9, released 16 October 2002 ***
-*******************************************
-
-MOD support is here! DUMB now supports all four of the common module formats.
-As usual, there have also been some improvements to the way modules are
-played back. Most notably, handling of tone portamento in IT files has been
-improved a lot, and XM envelopes are now processed correctly.
-
-The other major change is that DUMB now does a dummy run through each module
-on loading. It stores the playback state at thirty-second intervals. It stops
-when the module first loops, and then stores the playback time. This results
-in a slightly longer load time and a greater memory overhead, but seeking is
-faster (to any point before the module first loops) and the length is
-calculated! duh_get_length() will return this and is now documented in
-docs/howto.txt and docs/dumb.txt.
-
-DUMB's build process has been changed to use 'mingw' wherever it used
-'mingw32' before; some directories have been renamed, and the 'fix' command
-you had to run for MinGW has been changed from 'fix mingw32' to 'fix mingw'.
-
-Last time, I directed you to scroll down and read the notes from a past
-release, but ignore this point, and that point applies to something else, and
-so on. Did anyone do so? Well, if you're reading this at all, you probably
-did. Nevertheless, this time I shall be much less confusing and restate any
-relevant information. So the least you can do is read it!
-
-- If your program ever aborts with exit code 37 while loading an IT file,
-  PLEASE LET ME KNOW! The IT file in question has a stereo compressed sample
-  in it, and the format is unspecified for this case (Impulse Tracker itself
-  doesn't use stereo samples at all). I will need the IT file in question,
-  and any information you can give me about how the IT file was created (e.g.
-  what program). (If you don't get to see an exit code, let me know anyway.)
-
-- If your program ever outputs a line resembling "Inst 01 Env: 0,64 8,32
-  15,48" to stderr while loading an IT file, PLEASE LET ME KNOW! You have an
-  old IT file (saved by an Impulse Tracker version older than 2.00), and
-  support for such files is STILL untested.
-
-- Not all parts of DUMB's API are documented yet. You will find some
-  functions in dumb.h which are not listed in docs/dumb.txt; the reason is
-  that these functions still need work and will probably change. If you
-  really, really want to use them, talk to me first (IRC EFnet #dumb is a
-  good place for this; see readme.txt for details on using IRC). I intend to
-  finalise and document the whole of DUMB's API for Version 1.0.
-
-There have been some changes to the naming conventions in DUMB's undocumented
-API. DUMBOGG v0.5 will not work with this and subsequent releases of DUMB;
-please upgrade to DUMBOGG v0.6. These changes should not break anything in
-your own code, since you didn't use those parts of the API, did you ;)
-
-There is still a great deal of work to be done before DUMB's API can be
-finalised, and thus it will be a while before DUMB v1.0 comes out. It should
-be worth the wait. In the meantime, there will be 0.9.x releases with
-additional functionality, improved playback, and possibly support for some
-extra file formats.
-
-Finally I should like to offer an apology; there is a strong possibility that
-some of DUMB's official API will change in the near future. There will not be
-any drastic changes, and the corresponding changes to your source code will
-be simple enough. If I didn't make these changes, DUMB's API would start to
-become limited, or messy, or both, so it's for the better. I apologise in
-advance for this.
-
-Now scroll down and read the notes for the first r... oh wait, we already did
-that. I guess that's it then. You can stop reading now.
-
-Right after you've read this.
-
-And this.
-
-Off you go.
-
-Bye.
-
-
-********************************************
-*** DUMB v0.8.1, released 11 August 2002 ***
-********************************************
-
-This is a minor release that fixes a few bugs. One of these bugs, however,
-was pretty serious. dumb_register_dat_xm() was never coded! It was prototyped
-in aldumb.h, so code would compile, but there would be an unresolved symbol
-at the linking stage. This has been fixed.
-
-Platforms other than Unix did not have a working 'make veryclean' target;
-this has been fixed. In addition, the makefiles now use 'xcopy' instead of
-'copy', since on some systems GNU Make seems to have trouble calling commands
-built in to the shell.
-
-Contrary to the errata that was on the DUMB website, the makeall.sh and
-makecore.sh scripts actually DID install in /usr. This has now been
-corrected, and regardless of whether you use these scripts or call make
-directly, the files will now be installed to /usr/local by default.
-
-The XM loader used to treat stereo samples as mono samples with the data for
-the right channel positioned after the data for the left channel. This
-generally resulted in an unwanted echo effect. This has been fixed.
-
-When playing XM files, specifying an invalid instrument would cause an old
-note on that channel to come back (roughly speaking). Fast Tracker 2 does not
-exhibit this behaviour. This has been fixed.
-
-The GCC makefiles used -mpentium, which is deprecated in gcc 3.x. This was
-generating warnings, and has now been fixed.
-
-In XM files, the length of a sample is stored in bytes. DUMB was assuming
-that the length of a 16-bit sample would be even. I had two XM files where
-this was not the case, and DUMB was unable to load them. This has been fixed.
-
-In order to accommodate the extra part of the version number,
-DUMB_REVISION_VERSION has been added. DUMB_VERSION has also been added in
-order to facilitate checking if the version of DUMB installed is sufficient.
-See docs/dumb.txt for details.
-
-As a last-minute fix, the XM "Break to row" effect is now loaded properly. It
-was necessary to convert from binary-coded decimal to hexadecimal (those who
-have experience with Fast Tracker 2 will know what I mean). In short, this
-means the effect will now work properly when breaking to row 10 or greater.
-
-DUMB v0.8 had faulty release date constants; DUMB_MONTH and DUMB_DAY were
-swapped! For this reason, DUMB_DATE should not be compared against any date
-in 2002. This note has been added to docs/dumb.txt and also to dumb.h.
-
-Please scroll to the end and read the release notes for the first version,
-DUMB v0.7. Most of them apply equally to this release. However, the
-non-portable code was rewritten for DUMB v0.8, so that point does not apply.
-The point about length not being calculated also applies to XM files.
-
-Enjoy :)
-
-
-****************************************
-*** DUMB v0.8, released 14 June 2002 ***
-****************************************
-
-Welcome to the second release of DUMB!
-
-In addition to these notes, please read below the release notes for the
-previous version, DUMB v0.7. Most of them apply equally to this release.
-However, the non-portable code has been rewritten; DUMB should now port to
-big-endian platforms.
-
-The main improvement in this release of DUMB is the support for XM files.
-Enormous thanks go to Julien Cugniere for working on this while I had to
-revise for my exams!
-
-There was a mistake in the makefiles in the last release. The debugging
-Allegro interface library was mistakenly named libaldmbd.a instead of
-libaldmd.a, meaning you had to compile with -laldmbd, contrary to what the
-docs said. Apologies to everyone who lost sleep trying to work out what was
-wrong! The reason for using libaldmd.a is to maintain compatibility with
-plain DOS, where filenames are limited to eight characters (plus a three-
-letter extension). The makefiles have now been changed to match the
-information in the docs, so you may have to alter your project files
-accordingly.
-
-The example programs were faulty, and crashed on Windows if they were unable
-to load the file. It was also difficult to work out how to exit them (you had
-to click the taskbar button that didn't have a window, then press a key).
-They have been improved in both these respects.
-
-I have now added a docs/faq.txt file (Frequently Asked Questions), which is
-based on problems and misconceptions people have had with the first release.
-Please refer to it before contacting me with problems.
-
-Thanks to networm for touching up the Unix makefile and writing the
-instructions on using it.
-
-Incidentally, today (Friday 14 June) is the Robinson College May Ball at
-Cambridge Uni. God knows why it's called a May Ball if it's in June. I'm not
-going myself (72 GBP, and I'd have to wear a suit, ugh), but with all the
-noise outside I shall enjoy pumping up the speakers tonight!
-
-
-****************************************
-*** DUMB v0.7, released 2 March 2002 ***
-****************************************
-
-This is the first release of DUMB, and parts of the library are not
-crystallised. Don't let this put you off! Provided you don't try to use any
-features that aren't documented in docs/dumb.txt, the library should be rock
-solid and you should be able to upgrade more or less without problems.
-
-Here are some notes on this release:
-
-- There is some non-portable code in this release of DUMB. It is likely that
-  the library will fail to load IT files with compressed samples on
-  big-endian machines such as the Apple Macintosh.
-
-- If your program ever aborts with exit code 37 while loading an IT file,
-  PLEASE LET ME KNOW! The IT file in question has a stereo compressed sample
-  in it, and the format is unspecified for this case (Impulse Tracker itself
-  doesn't use stereo samples at all). I will need the IT file in question,
-  and any information you can give me about how the IT file was created (e.g.
-  what program). (If you don't get to see an exit code, let me know anyway.)
-
-- If your program ever outputs a line resembling "Inst 01 Env: 0,64 8,32
-  15,48" to stderr while loading an IT file, PLEASE LET ME KNOW! You have an
-  old IT file (saved by an Impulse Tracker version older than 2.00), and
-  support for such files is untested.
-
-- The length of IT and S3M files is not currently calculated. It is just set
-  to ten minutes.
--- a/dumb/src/core/atexit.c
+++ /dev/null
@@ -1,71 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * atexit.c - Library Clean-up Management.            / / \  \
- *                                                   | <  /   \_
- * By entheh.                                        |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-typedef struct DUMB_ATEXIT_PROC
-{
-	struct DUMB_ATEXIT_PROC *next;
-	void (*proc)(void);
-}
-DUMB_ATEXIT_PROC;
-
-
-
-static DUMB_ATEXIT_PROC *dumb_atexit_proc = NULL;
-
-
-
-int dumb_atexit(void (*proc)(void))
-{
-	DUMB_ATEXIT_PROC *dap = dumb_atexit_proc;
-
-	while (dap) {
-		if (dap->proc == proc) return 0;
-		dap = dap->next;
-	}
-
-	dap = malloc(sizeof(*dap));
-
-	if (!dap)
-		return -1;
-
-	dap->next = dumb_atexit_proc;
-	dap->proc = proc;
-	dumb_atexit_proc = dap;
-
-	return 0;
-}
-
-
-
-void dumb_exit(void)
-{
-	while (dumb_atexit_proc) {
-		DUMB_ATEXIT_PROC *next = dumb_atexit_proc->next;
-		(*dumb_atexit_proc->proc)();
-		free(dumb_atexit_proc);
-		dumb_atexit_proc = next;
-	}
-}
--- a/dumb/src/core/duhlen.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * duhlen.c - Functions to set and return the         / / \  \
- *            length of a DUH.                       | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- * Note that the length of a DUH is a constant          |  ' /
- * stored in the DUH struct and in the DUH disk          \__/
- * format. It will be calculated on loading for
- * other formats in which the length is not explicitly stored. Also note that
- * it does not necessarily correspond to the length of time for which the DUH
- * will generate samples. Rather it represents a suitable point for a player
- * such as Winamp to stop, and in any good DUH it will allow for any final
- * flourish to fade out and be appreciated.
- */
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-long duh_get_length(DUH *duh)
-{
-	return duh ? duh->length : 0;
-}
-
-
-
-void duh_set_length(DUH *duh, long length)
-{
-	if (duh)
-		duh->length = length;
-}
--- a/dumb/src/core/duhtag.c
+++ /dev/null
@@ -1,58 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * duhtag.c - Function to return the tags stored      / / \  \
- *            in a DUH struct (typically author      | <  /   \_
- *            information).                          |  \/ /\   /
- *                                                    \_  /  > /
- * By entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-const char *duh_get_tag(DUH *duh, const char *key)
-{
-	int i;
-	ASSERT(key);
-	if (!duh || !duh->tag) return NULL;
-
-	for (i = 0; i < duh->n_tags; i++)
-		if (strcmp(key, duh->tag[i][0]) == 0)
-			return duh->tag[i][1];
-
-	return NULL;
-}
-
-
-
-int duh_get_tag_iterator_size(DUH *duh)
-{
-	return (duh && duh->tag ? duh->n_tags : 0);
-}
-
-
-int duh_get_tag_iterator_get(DUH *duh, const char **key, const char **tag, int i)
-{
-	ASSERT(key);
-	ASSERT(tag);
-	if (!duh || !duh->tag || i >= duh->n_tags) return -1;
-
-	*key = duh->tag[i][0];
-	*tag = duh->tag[i][1];
-
-	return 0;
-}
--- a/dumb/src/core/dumbfile.c
+++ /dev/null
@@ -1,418 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * dumbfile.c - Hookable, strictly sequential         / / \  \
- *              file input functions.                | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-
-
-
-static const DUMBFILE_SYSTEM *the_dfs = NULL;
-
-
-
-void register_dumbfile_system(const DUMBFILE_SYSTEM *dfs)
-{
-	ASSERT(dfs);
-	ASSERT(dfs->open);
-	ASSERT(dfs->getc);
-	ASSERT(dfs->close);
-    ASSERT(dfs->seek);
-    ASSERT(dfs->get_size);
-	the_dfs = dfs;
-}
-
-
-
-#include "internal/dumbfile.h"
-
-
-
-DUMBFILE *dumbfile_open(const char *filename)
-{
-	DUMBFILE *f;
-
-	ASSERT(the_dfs);
-
-	f = (DUMBFILE *) malloc(sizeof(*f));
-
-	if (!f)
-		return NULL;
-
-	f->dfs = the_dfs;
-
-	f->file = (*the_dfs->open)(filename);
-
-	if (!f->file) {
-		free(f);
-		return NULL;
-	}
-
-	f->pos = 0;
-
-	return f;
-}
-
-
-
-DUMBFILE *dumbfile_open_ex(void *file, const DUMBFILE_SYSTEM *dfs)
-{
-	DUMBFILE *f;
-
-	ASSERT(dfs);
-	ASSERT(dfs->getc);
-	ASSERT(file);
-
-	f = (DUMBFILE *) malloc(sizeof(*f));
-
-	if (!f) {
-		if (dfs->close)
-			(*dfs->close)(file);
-		return NULL;
-	}
-
-	f->dfs = dfs;
-	f->file = file;
-
-	f->pos = 0;
-
-	return f;
-}
-
-
-
-long dumbfile_pos(DUMBFILE *f)
-{
-	ASSERT(f);
-
-	return f->pos;
-}
-
-
-
-int dumbfile_skip(DUMBFILE *f, long n)
-{
-	int rv;
-
-	ASSERT(f);
-	ASSERT(n >= 0);
-
-	if (f->pos < 0)
-		return -1;
-
-	f->pos += n;
-
-	if (f->dfs->skip) {
-		rv = (*f->dfs->skip)(f->file, n);
-		if (rv) {
-			f->pos = -1;
-			return rv;
-		}
-	} else {
-		while (n) {
-			rv = (*f->dfs->getc)(f->file);
-			if (rv < 0) {
-				f->pos = -1;
-				return rv;
-			}
-			n--;
-		}
-	}
-
-	return 0;
-}
-
-
-
-int dumbfile_getc(DUMBFILE *f)
-{
-	int rv;
-
-	ASSERT(f);
-
-	if (f->pos < 0)
-		return -1;
-
-	rv = (*f->dfs->getc)(f->file);
-
-	if (rv < 0) {
-		f->pos = -1;
-		return rv;
-	}
-
-	f->pos++;
-
-	return rv;
-}
-
-
-
-int dumbfile_igetw(DUMBFILE *f)
-{
-	int l, h;
-
-	ASSERT(f);
-
-	if (f->pos < 0)
-		return -1;
-
-	l = (*f->dfs->getc)(f->file);
-	if (l < 0) {
-		f->pos = -1;
-		return l;
-	}
-
-	h = (*f->dfs->getc)(f->file);
-	if (h < 0) {
-		f->pos = -1;
-		return h;
-	}
-
-	f->pos += 2;
-
-	return l | (h << 8);
-}
-
-
-
-int dumbfile_mgetw(DUMBFILE *f)
-{
-	int l, h;
-
-	ASSERT(f);
-
-	if (f->pos < 0)
-		return -1;
-
-	h = (*f->dfs->getc)(f->file);
-	if (h < 0) {
-		f->pos = -1;
-		return h;
-	}
-
-	l = (*f->dfs->getc)(f->file);
-	if (l < 0) {
-		f->pos = -1;
-		return l;
-	}
-
-	f->pos += 2;
-
-	return l | (h << 8);
-}
-
-
-
-long dumbfile_igetl(DUMBFILE *f)
-{
-	unsigned long rv, b;
-
-	ASSERT(f);
-
-	if (f->pos < 0)
-		return -1;
-
-	rv = (*f->dfs->getc)(f->file);
-	if ((signed long)rv < 0) {
-		f->pos = -1;
-		return rv;
-	}
-
-	b = (*f->dfs->getc)(f->file);
-	if ((signed long)b < 0) {
-		f->pos = -1;
-		return b;
-	}
-	rv |= b << 8;
-
-	b = (*f->dfs->getc)(f->file);
-	if ((signed long)b < 0) {
-		f->pos = -1;
-		return b;
-	}
-	rv |= b << 16;
-
-	b = (*f->dfs->getc)(f->file);
-	if ((signed long)b < 0) {
-		f->pos = -1;
-		return b;
-	}
-	rv |= b << 24;
-
-	f->pos += 4;
-
-	return rv;
-}
-
-
-
-long dumbfile_mgetl(DUMBFILE *f)
-{
-	unsigned long rv, b;
-
-	ASSERT(f);
-
-	if (f->pos < 0)
-		return -1;
-
-	rv = (*f->dfs->getc)(f->file);
-	if ((signed long)rv < 0) {
-		f->pos = -1;
-		return rv;
-	}
-	rv <<= 24;
-
-	b = (*f->dfs->getc)(f->file);
-	if ((signed long)b < 0) {
-		f->pos = -1;
-		return b;
-	}
-	rv |= b << 16;
-
-	b = (*f->dfs->getc)(f->file);
-	if ((signed long)b < 0) {
-		f->pos = -1;
-		return b;
-	}
-	rv |= b << 8;
-
-	b = (*f->dfs->getc)(f->file);
-	if ((signed long)b < 0) {
-		f->pos = -1;
-		return b;
-	}
-	rv |= b;
-
-	f->pos += 4;
-
-	return rv;
-}
-
-
-
-unsigned long dumbfile_cgetul(DUMBFILE *f)
-{
-	unsigned long rv = 0;
-	int v;
-
-	do {
-		v = dumbfile_getc(f);
-
-		if (v < 0)
-			return v;
-
-		rv <<= 7;
-		rv |= v & 0x7F;
-	} while (v & 0x80);
-
-	return rv;
-}
-
-
-
-signed long dumbfile_cgetsl(DUMBFILE *f)
-{
-	unsigned long rv = dumbfile_cgetul(f);
-
-	if (f->pos < 0)
-		return rv;
-
-	return (rv >> 1) | (rv << 31);
-}
-
-
-
-long dumbfile_getnc(char *ptr, long n, DUMBFILE *f)
-{
-	long rv;
-
-	ASSERT(f);
-	ASSERT(n >= 0);
-
-	if (f->pos < 0)
-		return -1;
-
-	if (f->dfs->getnc) {
-		rv = (*f->dfs->getnc)(ptr, n, f->file);
-		if (rv < n) {
-			f->pos = -1;
-			return MAX(rv, 0);
-		}
-	} else {
-		for (rv = 0; rv < n; rv++) {
-			int c = (*f->dfs->getc)(f->file);
-			if (c < 0) {
-				f->pos = -1;
-				return rv;
-			}
-			*ptr++ = c;
-		}
-	}
-
-	f->pos += rv;
-
-	return rv;
-}
-
-
-
-int dumbfile_seek(DUMBFILE *f, long n, int origin)
-{
-    switch ( origin )
-    {
-    case DFS_SEEK_CUR: n += f->pos; break;
-    case DFS_SEEK_END: n += (*f->dfs->get_size)(f->file); break;
-    }
-    f->pos = n;
-    return (*f->dfs->seek)(f->file, n);
-}
-
-
-
-long dumbfile_get_size(DUMBFILE *f)
-{
-    return (*f->dfs->get_size)(f->file);
-}
-
-
-
-int dumbfile_error(DUMBFILE *f)
-{
-	ASSERT(f);
-
-	return f->pos < 0;
-}
-
-
-
-int dumbfile_close(DUMBFILE *f)
-{
-	int rv;
-
-	ASSERT(f);
-
-	rv = f->pos < 0;
-
-	if (f->dfs->close)
-		(*f->dfs->close)(f->file);
-
-	free(f);
-
-	return rv;
-}
--- a/dumb/src/core/loadduh.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadduh.c - Code to read a DUH from a file,        / / \  \
- *             opening and closing the file for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-/* load_duh(): loads a .duh file, returning a pointer to a DUH struct.
- * When you have finished with it, you must pass the pointer to unload_duh()
- * so that the memory can be freed.
- */
-DUH *load_duh(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = read_duh(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/core/makeduh.c
+++ /dev/null
@@ -1,151 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * makeduh.c - Function to construct a DUH from       / / \  \
- *             its components.                       | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-static DUH_SIGNAL *make_signal(DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata)
-{
-	DUH_SIGNAL *signal;
-
-	ASSERT((desc->start_sigrenderer && desc->end_sigrenderer) || (!desc->start_sigrenderer && !desc->end_sigrenderer));
-	ASSERT(desc->sigrenderer_generate_samples && desc->sigrenderer_get_current_sample);
-
-	signal = malloc(sizeof(*signal));
-
-	if (!signal) {
-		if (desc->unload_sigdata)
-			if (sigdata)
-				(*desc->unload_sigdata)(sigdata);
-		return NULL;
-	}
-
-	signal->desc = desc;
-	signal->sigdata = sigdata;
-
-	return signal;
-}
-
-
-
-DUH *make_duh(
-	long length,
-	int n_tags,
-	const char *const tags[][2],
-	int n_signals,
-	DUH_SIGTYPE_DESC *desc[],
-	sigdata_t *sigdata[]
-)
-{
-	DUH *duh = malloc(sizeof(*duh));
-	int i;
-	int fail;
-
-	if (duh) {
-		duh->n_signals = n_signals;
-
-		duh->signal = malloc(n_signals * sizeof(*duh->signal));
-
-		if (!duh->signal) {
-			free(duh);
-			duh = NULL;
-		}
-	}
-
-	if (!duh) {
-		for (i = 0; i < n_signals; i++)
-			if (desc[i]->unload_sigdata)
-				if (sigdata[i])
-					(*desc[i]->unload_sigdata)(sigdata[i]);
-		return NULL;
-	}
-
-	duh->n_tags = 0;
-	duh->tag = NULL;
-
-	fail = 0;
-
-	for (i = 0; i < n_signals; i++) {
-		duh->signal[i] = make_signal(desc[i], sigdata[i]);
-		if (!duh->signal[i])
-			fail = 1;
-	}
-
-	if (fail) {
-		unload_duh(duh);
-		return NULL;
-	}
-
-	duh->length = length;
-
-	{
-		int mem = n_tags * 2; /* account for NUL terminators here */
-		char *ptr;
-
-		for (i = 0; i < n_tags; i++)
-			mem += strlen(tags[i][0]) + strlen(tags[i][1]);
-
-		if (mem <= 0) return duh;
-
-		duh->tag = malloc(n_tags * sizeof(*duh->tag));
-		if (!duh->tag) return duh;
-		duh->tag[0][0] = malloc(mem);
-		if (!duh->tag[0][0]) {
-			free(duh->tag);
-			duh->tag = NULL;
-			return duh;
-		}
-		duh->n_tags = n_tags;
-		ptr = duh->tag[0][0];
-		for (i = 0; i < n_tags; i++) {
-			duh->tag[i][0] = ptr;
-			strcpy(ptr, tags[i][0]);
-			ptr += strlen(tags[i][0]) + 1;
-			duh->tag[i][1] = ptr;
-			strcpy(ptr, tags[i][1]);
-			ptr += strlen(tags[i][1]) + 1;
-		}
-	}
-
-	return duh;
-}
-
-int duh_add_signal(DUH *duh, DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata)
-{
-	DUH_SIGNAL **signal;
-
-	if ( !duh || !desc || !sigdata ) return -1;
-
-	signal = ( DUH_SIGNAL ** ) realloc( duh->signal, ( duh->n_signals + 1 ) * sizeof( *duh->signal ) );
-	if ( !signal ) return -1;
-	duh->signal = signal;
-
-	memmove( signal + 1, signal, duh->n_signals * sizeof( *signal ) );
-	duh->n_signals++;
-
-	signal[ 0 ] = make_signal( desc, sigdata );
-	if ( !signal[ 0 ] ) return -1;
-
-	return 0;
-}
--- a/dumb/src/core/rawsig.c
+++ /dev/null
@@ -1,58 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * rawsig.c - Function to retrieve raw signal         / / \  \
- *            data from a DUH provided you know      | <  /   \_
- *            what type of signal it is.             |  \/ /\   /
- *                                                    \_  /  > /
- * By entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-/* You have to specify the type of sigdata, proving you know what to do with
- * the pointer. If you get it wrong, you can expect NULL back.
- */
-sigdata_t *duh_get_raw_sigdata(DUH *duh, int sig, long type)
-{
-	int i;
-	DUH_SIGNAL *signal;
-
-	if (!duh) return NULL;
-
-	if ( sig >= 0 )
-	{
-		if ((unsigned int)sig >= (unsigned int)duh->n_signals) return NULL;
-
-		signal = duh->signal[sig];
-
-		if (signal && signal->desc->type == type)
-			return signal->sigdata;
-	}
-	else
-	{
-		for ( i = 0; i < duh->n_signals; i++ )
-		{
-			signal = duh->signal[i];
-
-			if (signal && signal->desc->type == type)
-				return signal->sigdata;
-		}
-	}
-
-	return NULL;
-}
--- a/dumb/src/core/readduh.c
+++ /dev/null
@@ -1,107 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readduh.c - Code to read a DUH from an open        / / \  \
- *             file.                                 | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-static DUH_SIGNAL *read_signal(DUH *duh, DUMBFILE *f)
-{
-	DUH_SIGNAL *signal;
-	long type;
-
-	signal = malloc(sizeof(*signal));
-
-	if (!signal)
-		return NULL;
-
-	type = dumbfile_mgetl(f);
-	if (dumbfile_error(f)) {
-		free(signal);
-		return NULL;
-	}
-
-	signal->desc = _dumb_get_sigtype_desc(type);
-	if (!signal->desc) {
-		free(signal);
-		return NULL;
-	}
-
-	if (signal->desc->load_sigdata) {
-		signal->sigdata = (*signal->desc->load_sigdata)(duh, f);
-		if (!signal->sigdata) {
-			free(signal);
-			return NULL;
-		}
-	} else
-		signal->sigdata = NULL;
-
-	return signal;
-}
-
-
-
-/* read_duh(): reads a DUH from an already open DUMBFILE, and returns its
- * pointer, or null on error. The file is not closed.
- */
-DUH *read_duh(DUMBFILE *f)
-{
-	DUH *duh;
-	int i;
-
-	if (dumbfile_mgetl(f) != DUH_SIGNATURE)
-		return NULL;
-
-	duh = malloc(sizeof(*duh));
-	if (!duh)
-		return NULL;
-
-	duh->length = dumbfile_igetl(f);
-	if (dumbfile_error(f) || duh->length <= 0) {
-		free(duh);
-		return NULL;
-	}
-
-	duh->n_signals = dumbfile_igetl(f);
-	if (dumbfile_error(f) || duh->n_signals <= 0) {
-		free(duh);
-		return NULL;
-	}
-
-	duh->signal = malloc(sizeof(*duh->signal) * duh->n_signals);
-	if (!duh->signal) {
-		free(duh);
-		return NULL;
-	}
-
-	for (i = 0; i < duh->n_signals; i++)
-		duh->signal[i] = NULL;
-
-	for (i = 0; i < duh->n_signals; i++) {
-		if (!(duh->signal[i] = read_signal(duh, f))) {
-			unload_duh(duh);
-			return NULL;
-		}
-	}
-
-	return duh;
-}
--- a/dumb/src/core/register.c
+++ /dev/null
@@ -1,104 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * register.c - Signal type registration.             / / \  \
- *                                                   | <  /   \_
- * By entheh.                                        |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-static DUH_SIGTYPE_DESC_LINK *sigtype_desc = NULL;
-static DUH_SIGTYPE_DESC_LINK **sigtype_desc_tail = &sigtype_desc;
-
-
-
-/* destroy_sigtypes(): frees all memory allocated while registering signal
- * types. This function is set up to be called by dumb_exit().
- */
-static void destroy_sigtypes(void)
-{
-	DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc, *next;
-	sigtype_desc = NULL;
-	sigtype_desc_tail = &sigtype_desc;
-
-	while (desc_link) {
-		next = desc_link->next;
-		free(desc_link);
-		desc_link = next;
-	}
-}
-
-
-
-/* dumb_register_sigtype(): registers a new signal type with DUMB. The signal
- * type is identified by a four-character string (e.g. "WAVE"), which you can
- * encode using the the DUMB_ID() macro (e.g. DUMB_ID('W','A','V','E')). The
- * signal's behaviour is defined by four functions, whose pointers you pass
- * here. See the documentation for details.
- *
- * If a DUH tries to use a signal that has not been registered using this
- * function, then the library will fail to load the DUH.
- */
-void dumb_register_sigtype(DUH_SIGTYPE_DESC *desc)
-{
-	DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc;
-
-	ASSERT((desc->load_sigdata && desc->unload_sigdata) || (!desc->load_sigdata && !desc->unload_sigdata));
-	ASSERT((desc->start_sigrenderer && desc->end_sigrenderer) || (!desc->start_sigrenderer && !desc->end_sigrenderer));
-	ASSERT(desc->sigrenderer_generate_samples && desc->sigrenderer_get_current_sample);
-
-	if (desc_link) {
-		do {
-			if (desc_link->desc->type == desc->type) {
-				desc_link->desc = desc;
-				return;
-			}
-			desc_link = desc_link->next;
-		} while (desc_link);
-	} else
-		dumb_atexit(&destroy_sigtypes);
-
-	desc_link = *sigtype_desc_tail = malloc(sizeof(DUH_SIGTYPE_DESC_LINK));
-
-	if (!desc_link)
-		return;
-
-	desc_link->next = NULL;
-	sigtype_desc_tail = &desc_link->next;
-
-	desc_link->desc = desc;
-}
-
-
-
-/* _dumb_get_sigtype_desc(): searches the registered functions for a signal
- * type matching the parameter. If such a sigtype is found, it returns a
- * pointer to a sigtype descriptor containing the necessary functions to
- * manage the signal. If none is found, it returns NULL.
- */
-DUH_SIGTYPE_DESC *_dumb_get_sigtype_desc(long type)
-{
-	DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc;
-
-	while (desc_link && desc_link->desc->type != type)
-		desc_link = desc_link->next;
-
-	return desc_link ? desc_link->desc : NULL;
-}
--- a/dumb/src/core/rendduh.c
+++ /dev/null
@@ -1,331 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * rendduh.c - Functions for rendering a DUH into     / / \  \
- *             an end-user sample format.            | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <limits.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-/* On the x86, we can use some tricks to speed stuff up */
-#if (defined _MSC_VER) || (defined __DJGPP__) || (defined __MINGW__)
-// Can't we detect Linux and other x86 platforms here? :/
-
-#define FAST_MID(var, min, max) {                  \
-	var -= (min);                                  \
-	var &= (~var) >> (sizeof(var) * CHAR_BIT - 1); \
-	var += (min);                                  \
-	var -= (max);                                  \
-	var &= var >> (sizeof(var) * CHAR_BIT - 1);    \
-	var += (max);                                  \
-}
-
-#define CONVERT8(src, pos, signconv) {       \
-	signed int f = (src + 0x8000) >> 16;     \
-	FAST_MID(f, -128, 127);                  \
-	((char*)sptr)[pos] = (char)f ^ signconv; \
-}
-
-#define CONVERT16(src, pos, signconv) {          \
-	signed int f = (src + 0x80) >> 8;            \
-	FAST_MID(f, -32768, 32767);                  \
-	((short*)sptr)[pos] = (short)(f ^ signconv); \
-}
-
-#else
-
-#define CONVERT8(src, pos, signconv)		  \
-{											  \
-	signed int f = (src + 0x8000) >> 16;	  \
-	f = MID(-128, f, 127);					  \
-	((char *)sptr)[pos] = (char)f ^ signconv; \
-}
-
-
-
-#define CONVERT16(src, pos, signconv)			  \
-{												  \
-	signed int f = (src + 0x80) >> 8;			  \
-	f = MID(-32768, f, 32767);					  \
-	((short *)sptr)[pos] = (short)(f ^ signconv); \
-}
-
-#endif
-
-#define CONVERT24(src, pos) {                         \
-	signed int f = src;			                      \
-	f = MID(-8388608, f, 8388607);				      \
-	((unsigned char*)sptr)[pos  ] = (f)       & 0xFF; \
-	((unsigned char*)sptr)[pos+1] = (f >> 8)  & 0xFF; \
-	((unsigned char*)sptr)[pos+2] = (f >> 16) & 0xFF; \
-}
-
-#define CONVERT32F(src, pos) {                                     \
-	((float*)sptr)[pos] = (float)((signed int)src) * (1.0f/(float)(0xffffff/2+1)); \
-}
-
-#define CONVERT64F(src, pos) {                                     \
-	((double*)sptr)[pos] = (double)((signed int)src) * (1.0/(double)(0xffffff/2+1)); \
-}
-
-
-/* DEPRECATED */
-DUH_SIGRENDERER *duh_start_renderer(DUH *duh, int n_channels, long pos)
-{
-	return duh_start_sigrenderer(duh, 0, n_channels, pos);
-}
-
-
-/* DEPRECATED */
-long duh_render(
-	DUH_SIGRENDERER *sigrenderer,
-	int bits, int unsign,
-	float volume, float delta,
-	long size, void *sptr
-)
-{
-	long n;
-
-	sample_t **sampptr;
-
-	int n_channels;
-
-	ASSERT(bits == 8 || bits == 16);
-	ASSERT(sptr);
-
-	if (!sigrenderer)
-		return 0;
-
-	n_channels = duh_sigrenderer_get_n_channels(sigrenderer);
-
-	ASSERT(n_channels > 0);
-	/* This restriction will be removed when need be. At the moment, tightly
-	 * optimised loops exist for exactly one or two channels.
-	 */
-	ASSERT(n_channels <= 2);
-
-	sampptr = allocate_sample_buffer(n_channels, size);
-
-	if (!sampptr)
-		return 0;
-
-	dumb_silence(sampptr[0], n_channels * size);
-
-	size = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, sampptr);
-
-	if (bits == 16) {
-		int signconv = unsign ? 0x8000 : 0x0000;
-
-		for (n = 0; n < size * n_channels; n++) {
-			CONVERT16(sampptr[0][n], n, signconv);
-		}
-	} else {
-		char signconv = unsign ? 0x80 : 0x00;
-
-		for (n = 0; n < size * n_channels; n++) {
-			CONVERT8(sampptr[0][n], n, signconv);
-		}
-	}
-
-	destroy_sample_buffer(sampptr);
-
-	return size;
-}
-
-
-long duh_render_int(
-	DUH_SIGRENDERER *sigrenderer,
-	sample_t ***sig_samples,
-	long *sig_samples_size,
-	int bits, int unsign,
-	float volume, float delta,
-	long size, void *sptr
-)
-{
-	long n;
-
-	sample_t **sampptr;
-
-	int n_channels;
-
-	ASSERT(bits == 8 || bits == 16 || bits == 24);
-	ASSERT(sptr);
-	ASSERT(sig_samples);
-	ASSERT(sig_samples_size);
-
-	if (!sigrenderer)
-		return 0;
-
-	n_channels = duh_sigrenderer_get_n_channels(sigrenderer);
-
-	ASSERT(n_channels > 0);
-	/* This restriction will be removed when need be. At the moment, tightly
-	 * optimised loops exist for exactly one or two channels.
-	 */
-	ASSERT(n_channels <= 2);
-
-	if ((*sig_samples == NULL) || (*sig_samples_size != size))
-	{
-		destroy_sample_buffer(*sig_samples);
-		*sig_samples = allocate_sample_buffer(n_channels, size);
-		*sig_samples_size = size;
-	}
-	sampptr = *sig_samples;
-
-	if (!sampptr)
-		return 0;
-
-	dumb_silence(sampptr[0], n_channels * size);
-
-	size = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, sampptr);
-
-	if (bits == 24) {
-		long i = 0;
-		ASSERT(unsign == 0);
-		
-		for (n = 0; n < size * n_channels; n++, i += 3) {
-			CONVERT24(sampptr[0][n], i);
-		}
-	} else
-	if (bits == 16) {
-		int signconv = unsign ? 0x8000 : 0x0000;
-
-		for (n = 0; n < size * n_channels; n++) {
-			CONVERT16(sampptr[0][n], n, signconv);
-		}
-	} else {
-		char signconv = unsign ? 0x80 : 0x00;
-
-		for (n = 0; n < size * n_channels; n++) {
-			CONVERT8(sampptr[0][n], n, signconv);
-		}
-	}
-
-	return size;
-}
-
-
-long duh_render_float(
-	DUH_SIGRENDERER *sigrenderer,
-	sample_t ***sig_samples,
-	long *sig_samples_size,
-	int bits,
-	float volume, float delta,
-	long size, void *sptr
-)
-{
-	long n;
-
-	sample_t **sampptr;
-
-	int n_channels;
-
-	ASSERT(bits == 32 || bits == 64);
-	ASSERT(sptr);
-	ASSERT(sig_samples);
-	ASSERT(sig_samples_size);
-
-	if (!sigrenderer)
-		return 0;
-
-	n_channels = duh_sigrenderer_get_n_channels(sigrenderer);
-
-	ASSERT(n_channels > 0);
-	/* This restriction will be removed when need be. At the moment, tightly
-	 * optimised loops exist for exactly one or two channels.
-	 */
-	ASSERT(n_channels <= 2);
-
-	if ((*sig_samples == NULL) || (*sig_samples_size != size))
-	{
-		destroy_sample_buffer(*sig_samples);
-		*sig_samples = allocate_sample_buffer(n_channels, size);
-		*sig_samples_size = size;
-	}
-	sampptr = *sig_samples;
-
-	if (!sampptr)
-		return 0;
-
-	dumb_silence(sampptr[0], n_channels * size);
-
-	size = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, sampptr);
-
-	if (bits == 64) {
-		for (n = 0; n < size * n_channels; n++) {
-			CONVERT64F(sampptr[0][n], n);
-		}
-	} else
-	if (bits == 32) {
-		for (n = 0; n < size * n_channels; n++) {
-			CONVERT32F(sampptr[0][n], n);
-		}
-	} 
-
-	return size;
-}
-
-
-/* DEPRECATED */
-int duh_renderer_get_n_channels(DUH_SIGRENDERER *dr)
-{
-	return duh_sigrenderer_get_n_channels(dr);
-}
-
-
-
-/* DEPRECATED */
-long duh_renderer_get_position(DUH_SIGRENDERER *dr)
-{
-	return duh_sigrenderer_get_position(dr);
-}
-
-
-
-/* DEPRECATED */
-void duh_end_renderer(DUH_SIGRENDERER *dr)
-{
-	duh_end_sigrenderer(dr);
-}
-
-
-
-/* DEPRECATED */
-DUH_SIGRENDERER *duh_renderer_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer)
-{
-	return sigrenderer;
-}
-
-
-
-/* DEPRECATED */
-DUH_SIGRENDERER *duh_renderer_get_sigrenderer(DUH_SIGRENDERER *dr)
-{
-	return dr;
-}
-
-
-
-/* DEPRECATED */
-DUH_SIGRENDERER *duh_renderer_decompose_to_sigrenderer(DUH_SIGRENDERER *dr)
-{
-	return dr;
-}
--- a/dumb/src/core/rendsig.c
+++ /dev/null
@@ -1,352 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * rendsig.c - Wrappers to render samples from        / / \  \
- *             the signals in a DUH.                 | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-struct DUH_SIGRENDERER
-{
-	DUH_SIGTYPE_DESC *desc;
-
-	sigrenderer_t *sigrenderer;
-
-	int n_channels;
-
-	long pos;
-	int subpos;
-
-	DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK callback;
-	void *callback_data;
-};
-
-
-
-DUH_SIGRENDERER *duh_start_sigrenderer(DUH *duh, int sig, int n_channels, long pos)
-{
-	DUH_SIGRENDERER *sigrenderer;
-
-	DUH_SIGNAL *signal;
-	DUH_START_SIGRENDERER proc;
-
-	if (!duh)
-		return NULL;
-
-	if ((unsigned int)sig >= (unsigned int)duh->n_signals)
-		return NULL;
-
-	signal = duh->signal[sig];
-	if (!signal)
-		return NULL;
-
-	sigrenderer = malloc(sizeof(*sigrenderer));
-	if (!sigrenderer)
-		return NULL;
-
-	sigrenderer->desc = signal->desc;
-
-	proc = sigrenderer->desc->start_sigrenderer;
-
-	if (proc) {
-		duh->signal[sig] = NULL;
-		sigrenderer->sigrenderer = (*proc)(duh, signal->sigdata, n_channels, pos);
-		duh->signal[sig] = signal;
-
-		if (!sigrenderer->sigrenderer) {
-			free(sigrenderer);
-			return NULL;
-		}
-	} else
-		sigrenderer->sigrenderer = NULL;
-
-	sigrenderer->n_channels = n_channels;
-
-	sigrenderer->pos = pos;
-	sigrenderer->subpos = 0;
-
-	sigrenderer->callback = NULL;
-
-	return sigrenderer;
-}
-
-
-
-#include <stdio.h>
-void duh_sigrenderer_set_callback(
-	DUH_SIGRENDERER *sigrenderer,
-	DUH_SIGRENDERER_CALLBACK callback, void *data
-)
-{
-	(void)sigrenderer;
-	(void)callback;
-	(void)data;
-	/*fprintf(stderr,
-		"Call to deprecated function duh_sigrenderer_set_callback(). The callback\n"
-		"was not installed. See dumb/docs/deprec.txt for how to fix this.\n");*/
-}
-
-
-
-void duh_sigrenderer_set_analyser_callback(
-	DUH_SIGRENDERER *sigrenderer,
-	DUH_SIGRENDERER_ANALYSER_CALLBACK callback, void *data
-)
-{
-	(void)sigrenderer;
-	(void)callback;
-	(void)data;
-	fprintf(stderr,
-		"Call to deprecated function duh_sigrenderer_set_analyser_callback(). The\n"
-		"callback was not installed. See dumb/docs/deprec.txt for how to fix this.\n");
-}
-
-
-
-void duh_sigrenderer_set_sample_analyser_callback(
-	DUH_SIGRENDERER *sigrenderer,
-	DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK callback, void *data
-)
-{
-	if (sigrenderer) {
-		sigrenderer->callback = callback;
-		sigrenderer->callback_data = data;
-	}
-}
-
-
-
-int duh_sigrenderer_get_n_channels(DUH_SIGRENDERER *sigrenderer)
-{
-	return sigrenderer ? sigrenderer->n_channels : 0;
-}
-
-
-
-long duh_sigrenderer_get_position(DUH_SIGRENDERER *sigrenderer)
-{
-	DUH_SIGRENDERER_GET_POSITION proc;
-
-	if (!sigrenderer) return -1;
-
-	proc = sigrenderer->desc->sigrenderer_get_position;
-	if (proc)
-		return (*proc)(sigrenderer->sigrenderer);
-	else
-		return sigrenderer->pos;
-}
-
-
-
-void duh_sigrenderer_set_sigparam(
-	DUH_SIGRENDERER *sigrenderer,
-	unsigned char id, long value
-)
-{
-	DUH_SIGRENDERER_SET_SIGPARAM proc;
-
-	if (!sigrenderer) return;
-
-	proc = sigrenderer->desc->sigrenderer_set_sigparam;
-	if (proc)
-		(*proc)(sigrenderer->sigrenderer, id, value);
-	else
-		TRACE("Parameter #%d = %ld for signal %c%c%c%c, which does not take parameters.\n",
-			(int)id,
-			value,
-			(int)(sigrenderer->desc->type >> 24),
-			(int)(sigrenderer->desc->type >> 16),
-			(int)(sigrenderer->desc->type >> 8),
-			(int)(sigrenderer->desc->type));
-}
-
-
-
-long duh_sigrenderer_generate_samples(
-	DUH_SIGRENDERER *sigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-)
-{
-	long rendered;
-	LONG_LONG t;
-
-	if (!sigrenderer) return 0;
-
-	rendered = (*sigrenderer->desc->sigrenderer_generate_samples)
-				(sigrenderer->sigrenderer, volume, delta, size, samples);
-
-	if (rendered) {
-		if (sigrenderer->callback)
-			(*sigrenderer->callback)(sigrenderer->callback_data,
-				(const sample_t *const *)samples, sigrenderer->n_channels, rendered);
-
-		t = sigrenderer->subpos + (LONG_LONG)(delta * 65536.0 + 0.5) * rendered;
-
-		sigrenderer->pos += (long)(t >> 16);
-		sigrenderer->subpos = (int)t & 65535;
-	}
-
-	return rendered;
-}
-
-
-
-/* DEPRECATED */
-long duh_sigrenderer_get_samples(
-	DUH_SIGRENDERER *sigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-)
-{
-	sample_t **s;
-	long rendered;
-	long i;
-	int j;
-	if (!samples) return duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, NULL);
-	s = allocate_sample_buffer(sigrenderer->n_channels, size);
-	if (!s) return 0;
-	dumb_silence(s[0], sigrenderer->n_channels * size);
-	rendered = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, s);
-	for (j = 0; j < sigrenderer->n_channels; j++)
-		for (i = 0; i < rendered; i++)
-			samples[j][i] += s[0][i*sigrenderer->n_channels+j];
-	destroy_sample_buffer(s);
-	return rendered;
-}
-
-
-
-/* DEPRECATED */
-long duh_render_signal(
-	DUH_SIGRENDERER *sigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-)
-{
-	sample_t **s;
-	long rendered;
-	long i;
-	int j;
-	if (!samples) return duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, NULL);
-	s = allocate_sample_buffer(sigrenderer->n_channels, size);
-	if (!s) return 0;
-	dumb_silence(s[0], sigrenderer->n_channels * size);
-	rendered = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size, s);
-	for (j = 0; j < sigrenderer->n_channels; j++)
-		for (i = 0; i < rendered; i++)
-			samples[j][i] += s[0][i*sigrenderer->n_channels+j] >> 8;
-	destroy_sample_buffer(s);
-	return rendered;
-}
-
-
-
-void duh_sigrenderer_get_current_sample(DUH_SIGRENDERER *sigrenderer, float volume, sample_t *samples)
-{
-	if (sigrenderer)
-		(*sigrenderer->desc->sigrenderer_get_current_sample)(sigrenderer->sigrenderer, volume, samples);
-}
-
-
-
-void duh_end_sigrenderer(DUH_SIGRENDERER *sigrenderer)
-{
-	if (sigrenderer) {
-		if (sigrenderer->desc->end_sigrenderer)
-			if (sigrenderer->sigrenderer)
-				(*sigrenderer->desc->end_sigrenderer)(sigrenderer->sigrenderer);
-
-		free(sigrenderer);
-	}
-}
-
-
-
-DUH_SIGRENDERER *duh_encapsulate_raw_sigrenderer(sigrenderer_t *vsigrenderer, DUH_SIGTYPE_DESC *desc, int n_channels, long pos)
-{
-	DUH_SIGRENDERER *sigrenderer;
-
-	if (desc->start_sigrenderer && !vsigrenderer) return NULL;
-
-	sigrenderer = malloc(sizeof(*sigrenderer));
-	if (!sigrenderer) {
-		if (desc->end_sigrenderer)
-			if (vsigrenderer)
-				(*desc->end_sigrenderer)(vsigrenderer);
-		return NULL;
-	}
-
-	sigrenderer->desc = desc;
-	sigrenderer->sigrenderer = vsigrenderer;
-
-	sigrenderer->n_channels = n_channels;
-
-	sigrenderer->pos = pos;
-	sigrenderer->subpos = 0;
-
-	sigrenderer->callback = NULL;
-
-	return sigrenderer;
-}
-
-
-
-sigrenderer_t *duh_get_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer, long type)
-{
-	if (sigrenderer && sigrenderer->desc->type == type)
-		return sigrenderer->sigrenderer;
-
-	return NULL;
-}
-
-
-
-#if 0
-// This function is disabled because we don't know whether we want to destroy
-// the sigrenderer if the type doesn't match. We don't even know if we need
-// the function at all. Who would want to keep an IT_SIGRENDERER (for
-// instance) without keeping the DUH_SIGRENDERER?
-sigrenderer_t *duh_decompose_to_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer, long type)
-{
-	if (sigrenderer && sigrenderer->desc->type == type) {
-
-
-
-	if (sigrenderer) {
-		if (sigrenderer->desc->end_sigrenderer)
-			if (sigrenderer->sigrenderer)
-				(*sigrenderer->desc->end_sigrenderer)(sigrenderer->sigrenderer);
-
-		free(sigrenderer);
-	}
-
-
-
-
-
-
-		return sigrenderer->sigrenderer;
-	}
-
-	return NULL;
-}
-#endif
--- a/dumb/src/core/unload.c
+++ /dev/null
@@ -1,64 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * unload.c - Code to free a DUH from memory.         / / \  \
- *                                                   | <  /   \_
- * By entheh.                                        |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-
-
-
-static void destroy_signal(DUH_SIGNAL *signal)
-{
-	if (signal) {
-		if (signal->desc)
-			if (signal->desc->unload_sigdata)
-				if (signal->sigdata)
-					(*signal->desc->unload_sigdata)(signal->sigdata);
-
-		free(signal);
-	}
-}
-
-
-
-/* unload_duh(): destroys a DUH struct. You must call this for every DUH
- * struct created, when you've finished with it.
- */
-void unload_duh(DUH *duh)
-{
-	int i;
-
-	if (duh) {
-		if (duh->signal) {
-			for (i = 0; i < duh->n_signals; i++)
-				destroy_signal(duh->signal[i]);
-
-			free(duh->signal);
-		}
-
-		if (duh->tag) {
-			if (duh->tag[0][0])
-				free(duh->tag[0][0]);
-			free(duh->tag);
-		}
-
-		free(duh);
-	}
-}
--- a/dumb/src/helpers/barray.c
+++ /dev/null
@@ -1,189 +1,0 @@
-#include "internal/barray.h"
-
-#include <string.h>
-
-
-void * bit_array_create(size_t size)
-{
-	size_t bsize = ((size + 7) >> 3) + sizeof(size_t);
-	void * ret = calloc(1, bsize);
-	if (ret) *(size_t *)ret = size;
-	return ret;
-}
-
-void bit_array_destroy(void * array)
-{
-	if (array) free(array);
-}
-
-void * bit_array_dup(void * array)
-{
-	if (array)
-	{
-		size_t * size = (size_t *) array;
-		size_t bsize = ((*size + 7) >> 3) + sizeof(*size);
-		void * ret = malloc(bsize);
-		if (ret) memcpy(ret, array, bsize);
-		return ret;
-	}
-	return NULL;
-}
-
-void bit_array_reset(void * array)
-{
-	if (array)
-	{
-		size_t * size = (size_t *) array;
-		size_t bsize = (*size + 7) >> 3;
-		memset(size + 1, 0, bsize);
-	}
-}
-
-
-void bit_array_set(void * array, size_t bit)
-{
-	if (array)
-	{
-		size_t * size = (size_t *) array;
-		if (bit < *size)
-		{
-			unsigned char * ptr = (unsigned char *)(size + 1);
-			ptr[bit >> 3] |= (1U << (bit & 7));
-		}
-	}
-}
-
-void bit_array_set_range(void * array, size_t bit, size_t count)
-{
-    if (array && count)
-    {
-        size_t * size = (size_t *) array;
-        if (bit < *size)
-        {
-            unsigned char * ptr = (unsigned char *)(size + 1);
-            size_t i;
-            for (i = bit; i < *size && i < bit + count; ++i)
-                ptr[i >> 3] |= (1U << (i & 7));
-        }
-    }
-}
-
-int bit_array_test(void * array, size_t bit)
-{
-	if (array)
-	{
-		size_t * size = (size_t *) array;
-		if (bit < *size)
-		{
-			unsigned char * ptr = (unsigned char *)(size + 1);
-			if (ptr[bit >> 3] & (1U << (bit & 7)))
-			{
-				return 1;
-			}
-		}
-	}
-	return 0;
-}
-
-int bit_array_test_range(void * array, size_t bit, size_t count)
-{
-	if (array)
-	{
-		size_t * size = (size_t *) array;
-		if (bit < *size)
-		{
-			unsigned char * ptr = (unsigned char *)(size + 1);
-			if ((bit & 7) && (count > 8))
-			{
-				while ((bit < *size) && count && (bit & 7))
-				{
-					if (ptr[bit >> 3] & (1U << (bit & 7))) return 1;
-					bit++;
-					count--;
-				}
-			}
-			if (!(bit & 7))
-			{
-				while (((*size - bit) >= 8) && (count >= 8))
-				{
-					if (ptr[bit >> 3]) return 1;
-					bit += 8;
-					count -= 8;
-				}
-			}
-			while ((bit < *size) && count)
-			{
-				if (ptr[bit >> 3] & (1U << (bit & 7))) return 1;
-				bit++;
-				count--;
-			}
-		}
-	}
-	return 0;
-}
-
-void bit_array_clear(void * array, size_t bit)
-{
-	if (array)
-	{
-		size_t * size = (size_t *) array;
-		if (bit < *size)
-		{
-			unsigned char * ptr = (unsigned char *)(size + 1);
-			ptr[bit >> 3] &= ~(1U << (bit & 7));
-		}
-	}
-}
-
-void bit_array_clear_range(void * array, size_t bit, size_t count)
-{
-    if (array && count)
-    {
-        size_t * size = (size_t *) array;
-        if (bit < *size)
-        {
-            unsigned char * ptr = (unsigned char *)(size + 1);
-            size_t i;
-            for (i = bit; i < *size && i < bit + count; ++i)
-                ptr[i >> 3] &= ~(1U << (i & 7));
-        }
-    }
-}
-
-void bit_array_merge(void * dest, void * source, size_t offset)
-{
-	if (dest && source)
-	{
-		size_t * dsize = (size_t *) dest;
-		size_t * ssize = (size_t *) source;
-		size_t soffset = 0;
-		while (offset < *dsize && soffset < *ssize)
-		{
-			if (bit_array_test(source, soffset))
-			{
-				bit_array_set(dest, offset);
-			}
-			soffset++;
-			offset++;
-		}
-	}
-}
-
-void bit_array_mask(void * dest, void * source, size_t offset)
-{
-	if (dest && source)
-	{
-		size_t * dsize = (size_t *) dest;
-		size_t * ssize = (size_t *) source;
-		size_t soffset = 0;
-		while (offset < *dsize && soffset < *ssize)
-		{
-			if (bit_array_test(source, soffset))
-			{
-				bit_array_clear(dest, offset);
-			}
-			soffset++;
-			offset++;
-		}
-	}
-}
--- a/dumb/src/helpers/clickrem.c
+++ /dev/null
@@ -1,281 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * clickrem.c - Click removal helpers.                / / \  \
- *                                                   | <  /   \_
- * By entheh.                                        |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <math.h>
-#include "dumb.h"
-
-
-
-typedef struct DUMB_CLICK DUMB_CLICK;
-
-
-struct DUMB_CLICK_REMOVER
-{
-	DUMB_CLICK *click;
-	int n_clicks;
-
-	int offset;
-};
-
-
-struct DUMB_CLICK
-{
-	DUMB_CLICK *next;
-	long pos;
-	sample_t step;
-};
-
-
-
-DUMB_CLICK_REMOVER *dumb_create_click_remover(void)
-{
-	DUMB_CLICK_REMOVER *cr = malloc(sizeof(*cr));
-	if (!cr) return NULL;
-
-	cr->click = NULL;
-	cr->n_clicks = 0;
-
-	cr->offset = 0;
-
-	return cr;
-}
-
-
-
-void dumb_record_click(DUMB_CLICK_REMOVER *cr, long pos, sample_t step)
-{
-	DUMB_CLICK *click;
-
-	ASSERT(pos >= 0);
-
-	if (!cr || !step) return;
-
-	if (pos == 0) {
-		cr->offset -= step;
-		return;
-	}
-
-	click = malloc(sizeof(*click));
-	if (!click) return;
-
-	click->pos = pos;
-	click->step = step;
-
-	click->next = cr->click;
-	cr->click = click;
-	cr->n_clicks++;
-}
-
-
-
-static DUMB_CLICK *dumb_click_mergesort(DUMB_CLICK *click, int n_clicks)
-{
-	int i;
-	DUMB_CLICK *c1, *c2, **cp;
-
-	if (n_clicks <= 1) return click;
-
-	/* Split the list into two */
-	c1 = click;
-	cp = &c1;
-	for (i = 0; i < n_clicks; i += 2) cp = &(*cp)->next;
-	c2 = *cp;
-	*cp = NULL;
-
-	/* Sort the sublists */
-	c1 = dumb_click_mergesort(c1, (n_clicks + 1) >> 1);
-	c2 = dumb_click_mergesort(c2, n_clicks >> 1);
-
-	/* Merge them */
-	cp = &click;
-	while (c1 && c2) {
-		if (c1->pos > c2->pos) {
-			*cp = c2;
-			c2 = c2->next;
-		} else {
-			*cp = c1;
-			c1 = c1->next;
-		}
-		cp = &(*cp)->next;
-	}
-	if (c2)
-		*cp = c2;
-	else
-		*cp = c1;
-
-	return click;
-}
-
-
-
-void dumb_remove_clicks(DUMB_CLICK_REMOVER *cr, sample_t *samples, long length, int step, float halflife)
-{
-	DUMB_CLICK *click;
-	long pos = 0;
-	int offset;
-	int factor;
-
-	if (!cr) return;
-
-	factor = (int)floor(pow(0.5, 1.0/halflife) * (1U << 31));
-
-	click = dumb_click_mergesort(cr->click, cr->n_clicks);
-	cr->click = NULL;
-	cr->n_clicks = 0;
-
-	length *= step;
-
-	while (click) {
-		DUMB_CLICK *next = click->next;
-		int end = click->pos * step;
-		ASSERT(end <= length);
-		offset = cr->offset;
-		if (offset < 0) {
-			offset = -offset;
-			while (pos < end) {
-				samples[pos] -= offset;
-				offset = (int)(((LONG_LONG)(offset << 1) * factor) >> 32);
-				pos += step;
-			}
-			offset = -offset;
-		} else {
-			while (pos < end) {
-				samples[pos] += offset;
-				offset = (int)(((LONG_LONG)(offset << 1) * factor) >> 32);
-				pos += step;
-			}
-		}
-		cr->offset = offset - click->step;
-		free(click);
-		click = next;
-	}
-
-	offset = cr->offset;
-	if (offset < 0) {
-		offset = -offset;
-		while (pos < length) {
-			samples[pos] -= offset;
-			offset = (int)((LONG_LONG)(offset << 1) * factor >> 32);
-			pos += step;
-		}
-		offset = -offset;
-	} else {
-		while (pos < length) {
-			samples[pos] += offset;
-			offset = (int)((LONG_LONG)(offset << 1) * factor >> 32);
-			pos += step;
-		}
-	}
-	cr->offset = offset;
-}
-
-
-
-sample_t dumb_click_remover_get_offset(DUMB_CLICK_REMOVER *cr)
-{
-	return cr ? cr->offset : 0;
-}
-
-
-
-void dumb_destroy_click_remover(DUMB_CLICK_REMOVER *cr)
-{
-	if (cr) {
-		DUMB_CLICK *click = cr->click;
-		while (click) {
-			DUMB_CLICK *next = click->next;
-			free(click);
-			click = next;
-		}
-		free(cr);
-	}
-}
-
-
-
-DUMB_CLICK_REMOVER **dumb_create_click_remover_array(int n)
-{
-	int i;
-	DUMB_CLICK_REMOVER **cr;
-	if (n <= 0) return NULL;
-	cr = malloc(n * sizeof(*cr));
-	if (!cr) return NULL;
-	for (i = 0; i < n; i++) cr[i] = dumb_create_click_remover();
-	return cr;
-}
-
-
-
-void dumb_record_click_array(int n, DUMB_CLICK_REMOVER **cr, long pos, sample_t *step)
-{
-	if (cr) {
-		int i;
-		for (i = 0; i < n; i++)
-			dumb_record_click(cr[i], pos, step[i]);
-	}
-}
-
-
-
-void dumb_record_click_negative_array(int n, DUMB_CLICK_REMOVER **cr, long pos, sample_t *step)
-{
-	if (cr) {
-		int i;
-		for (i = 0; i < n; i++)
-			dumb_record_click(cr[i], pos, -step[i]);
-	}
-}
-
-
-
-void dumb_remove_clicks_array(int n, DUMB_CLICK_REMOVER **cr, sample_t **samples, long length, float halflife)
-{
-	if (cr) {
-		int i;
-		for (i = 0; i < n >> 1; i++) {
-			dumb_remove_clicks(cr[i << 1], samples[i], length, 2, halflife);
-			dumb_remove_clicks(cr[(i << 1) + 1], samples[i] + 1, length, 2, halflife);
-		}
-		if (n & 1)
-			dumb_remove_clicks(cr[i << 1], samples[i], length, 1, halflife);
-	}
-}
-
-
-
-void dumb_click_remover_get_offset_array(int n, DUMB_CLICK_REMOVER **cr, sample_t *offset)
-{
-	if (cr) {
-		int i;
-		for (i = 0; i < n; i++)
-			if (cr[i]) offset[i] += cr[i]->offset;
-	}
-}
-
-
-
-void dumb_destroy_click_remover_array(int n, DUMB_CLICK_REMOVER **cr)
-{
-	if (cr) {
-		int i;
-		for (i = 0; i < n; i++) dumb_destroy_click_remover(cr[i]);
-		free(cr);
-	}
-}
--- a/dumb/src/helpers/fir_resampler.c
+++ /dev/null
@@ -1,281 +1,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "internal/fir_resampler.h"
-
-enum { fir_width = 16 };
-
-enum { fir_max_res = 1024 };
-enum { fir_min_width = (fir_width < 4 ? 4 : fir_width) };
-enum { fir_adj_width = fir_min_width / 4 * 4 + 2 };
-enum { fir_stereo = 1 }; /* channel count, not boolean value */
-enum { fir_write_offset = fir_adj_width * fir_stereo };
-
-enum { fir_buffer_size = fir_width * 2 };
-
-typedef short fir_impulse[fir_adj_width];
-
-/* exp slope to 31/32 of ln(8) */
-static const double fir_ratios[32] = {
-	1.000, 1.067, 1.139, 1.215, 1.297, 1.384, 1.477, 1.576,
-	1.682, 1.795, 1.915, 2.044, 2.181, 2.327, 2.484, 2.650,
-	2.828, 3.018, 3.221, 3.437, 3.668, 3.914, 4.177, 4.458,
-	4.757, 5.076, 5.417, 5.781, 6.169, 6.583, 7.025, 7.497
-};
-
-static fir_impulse fir_impulses[32][fir_max_res];
-
-#undef PI
-#define PI 3.1415926535897932384626433832795029
-
-static void gen_sinc( double rolloff, int width, double offset, double spacing, double scale,
-		int count, short* out )
-{
-	double const maxh = 256;
-	double const step = PI / maxh * spacing;
-	double const to_w = maxh * 2 / width;
-	double const pow_a_n = pow( rolloff, maxh );
-	
-	double angle = (count / 2 - 1 + offset) * -step;
-
-	scale /= maxh * 2;
-
-	while ( count-- )
-	{
-		double w;
-		*out++ = 0;
-		w = angle * to_w;
-		if ( fabs( w ) < PI )
-		{
-			double rolloff_cos_a = rolloff * cos( angle );
-			double num = 1 - rolloff_cos_a -
-					pow_a_n * cos( maxh * angle ) +
-					pow_a_n * rolloff * cos( (maxh - 1) * angle );
-			double den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff;
-			double sinc = scale * num / den - scale;
-			
-			out [-1] = (short) (cos( w ) * sinc + sinc);
-		}
-		angle += step;
-	}
-}
-
-typedef struct fir_resampler
-{
-    int write_pos, write_filled;
-    int read_pos, read_filled;
-    unsigned short phase;
-    unsigned int phase_inc;
-	unsigned int ratio_set;
-    int buffer_in[fir_buffer_size * 2];
-    int buffer_out[fir_buffer_size];
-} fir_resampler;
-
-void * fir_resampler_create()
-{
-	fir_resampler * r = ( fir_resampler * ) malloc( sizeof(fir_resampler) );
-    if ( !r ) return 0;
-
-	r->write_pos = 0;
-    r->write_filled = 0;
-    r->read_pos = 0;
-    r->read_filled = 0;
-    r->phase = 0;
-    r->phase_inc = 0;
-	r->ratio_set = 0;
-    memset( r->buffer_in, 0, sizeof(r->buffer_in) );
-    memset( r->buffer_out, 0, sizeof(r->buffer_out) );
-
-	return r;
-}
-
-void fir_resampler_delete(void * _r)
-{
-	free( _r );
-}
-
-void * fir_resampler_dup(void * _r)
-{
-    fir_resampler * r_in = ( fir_resampler * ) _r;
-    fir_resampler * r_out = ( fir_resampler * ) malloc( sizeof(fir_resampler) );
-    if ( !r_out ) return 0;
-
-    r_out->write_pos = r_in->write_pos;
-    r_out->write_filled = r_in->write_filled;
-    r_out->read_pos = r_in->read_pos;
-    r_out->read_filled = r_in->read_filled;
-    r_out->phase = r_in->phase;
-    r_out->phase_inc = r_in->phase_inc;
-	r_out->ratio_set = r_in->ratio_set;
-    memcpy( r_out->buffer_in, r_in->buffer_in, sizeof(r_in->buffer_in) );
-    memcpy( r_out->buffer_out, r_in->buffer_out, sizeof(r_in->buffer_out) );
-
-    return r_out;
-}
-
-int fir_resampler_get_free_count(void *_r)
-{
-	fir_resampler * r = ( fir_resampler * ) _r;
-    return fir_buffer_size - r->write_filled;
-}
-
-int fir_resampler_ready(void *_r)
-{
-    fir_resampler * r = ( fir_resampler * ) _r;
-    return r->write_filled > fir_adj_width;
-}
-
-void fir_resampler_clear(void *_r)
-{
-    fir_resampler * r = ( fir_resampler * ) _r;
-    r->write_pos = 0;
-    r->write_filled = 0;
-    r->read_pos = 0;
-    r->read_filled = 0;
-    r->phase = 0;
-    memset( r->buffer_in, 0, sizeof(r->buffer_in) );
-}
-
-void fir_resampler_set_rate(void *_r, double new_factor)
-{
-    fir_resampler * r = ( fir_resampler * ) _r;
-    r->phase_inc = (int)( new_factor * 65536.0 );
-	r->ratio_set = 0;
-	while ( r->ratio_set < 31 && new_factor > fir_ratios[ r->ratio_set ] ) r->ratio_set++;
-}
-
-void fir_resampler_write_sample(void *_r, short s)
-{
-	fir_resampler * r = ( fir_resampler * ) _r;
-
-    if ( r->write_filled < fir_buffer_size )
-	{
-        int s32 = s;
-
-        r->buffer_in[ r->write_pos ] = s32;
-        r->buffer_in[ r->write_pos + fir_buffer_size ] = s32;
-
-        ++r->write_filled;
-
-		r->write_pos = ( r->write_pos + 1 ) % fir_buffer_size;
-	}
-}
-
-void fir_init()
-{
-	double const rolloff = 0.999;
-    double const gain = 1.0;
-
-    int const res = fir_max_res;
-
-	int i;
-
-	for (i = 0; i < 32; i++)
-	{
-	    double const ratio_ = fir_ratios[ i ];
-	
-		double fraction = 1.0 / (double)fir_max_res;
-
-		double const filter = (ratio_ < 1.0) ? 1.0 : 1.0 / ratio_;
-		double pos = 0.0;
-		short* out = (short*) fir_impulses[ i ];
-	    int n;
-		for ( n = res; --n >= 0; )
-		{
-			gen_sinc( rolloff, (int) (fir_adj_width * filter + 1) & ~1, pos, filter,
-				    (double) (0x7FFF * gain * filter), (int) fir_adj_width, out );
-			out += fir_adj_width;
-
-			pos += fraction;
-		}
-	}
-}
-
-int fir_resampler_run(void *_r, int ** out_, int * out_end)
-{
-	fir_resampler * r = ( fir_resampler * ) _r;
-    int in_size = r->write_filled;
-    int const* in_ = r->buffer_in + fir_buffer_size + r->write_pos - r->write_filled;
-	int used = 0;
-	in_size -= fir_write_offset;
-	if ( in_size > 0 )
-	{
-		int* out = *out_;
-		int const* in = in_;
-		int const* const in_end = in + in_size;
-        int phase = r->phase;
-        int phase_inc = r->phase_inc;
-		int ratio_set = r->ratio_set;
-		
-		do
-		{
-			// accumulate in extended precision
-            short const* imp = fir_impulses[ratio_set][(phase & 0xFFC0) >> 6];
-            int pt = imp [0];
-            int s = pt * in [0];
-            int n;
-			if ( out >= out_end )
-				break;
-            for ( n = (fir_adj_width - 2) / 2; n; --n )
-			{
-				pt = imp [1];
-				s += pt * in [1];
-				
-				// pre-increment more efficient on some RISC processors
-				imp += 2;
-				pt = imp [0];
-				in += 2;
-				s += pt * in [0];
-			}
-			pt = imp [1];
-			s += pt * in [1];
-
-            phase += phase_inc;
-
-            in += (phase >> 16) - fir_adj_width + 2;
-
-            phase &= 65535;
-			
-            *out++ = (int) (s >> 7);
-		}
-		while ( in < in_end );
-		
-        r->phase = phase;
-		*out_ = out;
-
-		used = in - in_;
-
-        r->write_filled -= used;
-	}
-	
-	return used;
-}
-
-int fir_resampler_get_sample(void *_r)
-{
-    fir_resampler * r = ( fir_resampler * ) _r;
-    if ( r->read_filled < 1 )
-    {
-        int write_pos = ( r->read_pos + r->read_filled ) % fir_buffer_size;
-        int write_size = fir_buffer_size - write_pos;
-        int * out = r->buffer_out + write_pos;
-        if ( write_size > ( fir_buffer_size - r->read_filled ) )
-            write_size = fir_buffer_size - r->read_filled;
-        fir_resampler_run( r, &out, out + write_size );
-        r->read_filled += out - r->buffer_out - write_pos;
-    }
-    if ( r->read_filled < 1 )
-        return 0;
-    return r->buffer_out[ r->read_pos ];
-}
-
-void fir_resampler_remove_sample(void *_r)
-{
-    fir_resampler * r = ( fir_resampler * ) _r;
-    if ( r->read_filled > 0 )
-    {
-        --r->read_filled;
-        r->read_pos = ( r->read_pos + 1 ) % fir_buffer_size;
-    }
-}
--- a/dumb/src/helpers/lpc.c
+++ /dev/null
@@ -1,320 +1,0 @@
-/********************************************************************
- *                                                                  *
- * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
- *                                                                  *
- * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
- * by the Xiph.Org Foundation http://www.xiph.org/                  *
- *                                                                  *
- ********************************************************************
-
-  function: LPC low level routines
-  last mod: $Id: lpc.c 16227 2009-07-08 06:58:46Z xiphmont $
-
- ********************************************************************/
-
-/* Some of these routines (autocorrelator, LPC coefficient estimator)
-   are derived from code written by Jutta Degener and Carsten Bormann;
-   thus we include their copyright below.  The entirety of this file
-   is freely redistributable on the condition that both of these
-   copyright notices are preserved without modification.  */
-
-/* Preserved Copyright: *********************************************/
-
-/* Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann,
-Technische Universita"t Berlin
-
-Any use of this software is permitted provided that this notice is not
-removed and that neither the authors nor the Technische Universita"t
-Berlin are deemed to have made any representations as to the
-suitability of this software for any purpose nor are held responsible
-for any defects of this software. THERE IS ABSOLUTELY NO WARRANTY FOR
-THIS SOFTWARE.
-
-As a matter of courtesy, the authors request to be informed about uses
-this software has found, about bugs in this software, and about any
-improvements that may be of general interest.
-
-Berlin, 28.11.1994
-Jutta Degener
-Carsten Bormann
-
-*********************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include "internal/stack_alloc.h"
-#include "internal/lpc.h"
-
-/* Autocorrelation LPC coeff generation algorithm invented by
-   N. Levinson in 1947, modified by J. Durbin in 1959. */
-
-/* Input : n elements of time doamin data
-   Output: m lpc coefficients, excitation energy */
-
-static float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
-  double *aut=alloca(sizeof(*aut)*(m+1));
-  double *lpc=alloca(sizeof(*lpc)*(m));
-  double error;
-  double epsilon;
-  int i,j;
-
-  /* autocorrelation, p+1 lag coefficients */
-  j=m+1;
-  while(j--){
-    double d=0; /* double needed for accumulator depth */
-    for(i=j;i<n;i++)d+=(double)data[i]*data[(i-j)];
-    aut[j]=d;
-  }
-
-  /* Generate lpc coefficients from autocorr values */
-
-  /* set our noise floor to about -100dB */
-  error=aut[0] * (1. + 1e-10);
-  epsilon=1e-9*aut[0]+1e-10;
-
-  for(i=0;i<m;i++){
-    double r= -aut[i+1];
-
-    if(error<epsilon){
-      memset(lpc+i,0,(m-i)*sizeof(*lpc));
-      goto done;
-    }
-
-    /* Sum up this iteration's reflection coefficient; note that in
-       Vorbis we don't save it.  If anyone wants to recycle this code
-       and needs reflection coefficients, save the results of 'r' from
-       each iteration. */
-
-    for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
-    r/=error;
-
-    /* Update LPC coefficients and total error */
-
-    lpc[i]=r;
-    for(j=0;j<i/2;j++){
-      double tmp=lpc[j];
-
-      lpc[j]+=r*lpc[i-1-j];
-      lpc[i-1-j]+=r*tmp;
-    }
-    if(i&1)lpc[j]+=lpc[j]*r;
-
-    error*=1.-r*r;
-
-  }
-
- done:
-
-  /* slightly damp the filter */
-  {
-    double g = .99;
-    double damp = g;
-    for(j=0;j<m;j++){
-      lpc[j]*=damp;
-      damp*=g;
-    }
-  }
-
-  for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
-
-  /* we need the error value to know how big an impulse to hit the
-     filter with later */
-
-  return error;
-}
-
-static void vorbis_lpc_predict(float *coeff,float *prime,int m,
-                     float *data,long n){
-
-  /* in: coeff[0...m-1] LPC coefficients
-         prime[0...m-1] initial values (allocated size of n+m-1)
-    out: data[0...n-1] data samples */
-
-  long i,j,o,p;
-  float y;
-  float *work=alloca(sizeof(*work)*(m+n));
-
-  if(!prime)
-    for(i=0;i<m;i++)
-      work[i]=0.f;
-  else
-    for(i=0;i<m;i++)
-      work[i]=prime[i];
-
-  for(i=0;i<n;i++){
-    y=0;
-    o=i;
-    p=m;
-    for(j=0;j<m;j++)
-      y-=work[o++]*coeff[--p];
-
-    data[i]=work[o]=y;
-  }
-}
-
-#include "dumb.h"
-#include "internal/dumb.h"
-#include "internal/it.h"
-
-enum { lpc_max   = 256 }; /* Maximum number of input samples to train the function */
-enum { lpc_order = 32  }; /* Order of the filter */
-enum { lpc_extra = 64  }; /* How many samples of padding to predict or silence */
-
-
-/* This extra sample padding is really only needed by the FIR resampler, but it helps the other resamplers as well. */
-
-void dumb_it_add_lpc(struct DUMB_IT_SIGDATA *sigdata){
-    float lpc[lpc_order * 2];
-    float lpc_input[lpc_max * 2];
-    float lpc_output[lpc_extra * 2];
-
-    signed char * s8;
-    signed short * s16;
-
-    int n, o, offset, lpc_samples;
-
-    for ( n = 0; n < sigdata->n_samples; n++ ) {
-        IT_SAMPLE * sample = sigdata->sample + n;
-        if ( ( sample->flags & ( IT_SAMPLE_EXISTS | IT_SAMPLE_LOOP) ) == IT_SAMPLE_EXISTS ) {
-            /* If we have enough sample data to train the filter, use the filter to generate the padding */
-            if ( sample->length >= lpc_order ) {
-                lpc_samples = sample->length;
-                if (lpc_samples > lpc_max) lpc_samples = lpc_max;
-                offset = sample->length - lpc_samples;
-
-                if ( sample->flags & IT_SAMPLE_STEREO )
-                {
-                    if ( sample->flags & IT_SAMPLE_16BIT )
-                    {
-                        s16 = ( signed short * ) sample->data;
-                        s16 += offset * 2;
-                        for ( o = 0; o < lpc_samples; o++ )
-                        {
-                            lpc_input[ o ] = s16[ o * 2 + 0 ];
-                            lpc_input[ o + lpc_max ] = s16[ o * 2 + 1 ];
-                        }
-                    }
-                    else
-                    {
-                        s8 = ( signed char * ) sample->data;
-                        s8 += offset * 2;
-                        for ( o = 0; o < lpc_samples; o++ )
-                        {
-                            lpc_input[ o ] = s8[ o * 2 + 0 ];
-                            lpc_input[ o + lpc_max ] = s8[ o * 2 + 1 ];
-                        }
-                    }
-
-                    vorbis_lpc_from_data( lpc_input, lpc, lpc_samples, lpc_order );
-                    vorbis_lpc_from_data( lpc_input + lpc_max, lpc + lpc_order, lpc_samples, lpc_order );
-
-                    vorbis_lpc_predict( lpc, lpc_input + lpc_samples - lpc_order, lpc_order, lpc_output, lpc_extra );
-                    vorbis_lpc_predict( lpc + lpc_order, lpc_input + lpc_max + lpc_samples - lpc_order, lpc_order, lpc_output + lpc_extra, lpc_extra );
-
-                    if ( sample->flags & IT_SAMPLE_16BIT )
-                    {
-                        s16 = ( signed short * ) realloc( sample->data, ( sample->length + lpc_extra ) * 2 * sizeof(short) );
-                        sample->data = s16;
-
-                        s16 += sample->length * 2;
-                        sample->length += lpc_extra;
-
-                        for ( o = 0; o < lpc_extra; o++ )
-                        {
-                            s16[ o * 2 + 0 ] = lpc_output[ o ];
-                            s16[ o * 2 + 1 ] = lpc_output[ o + lpc_extra ];
-                        }
-                    }
-                    else
-                    {
-                        s8 = ( signed char * ) realloc( sample->data, ( sample->length + lpc_extra ) * 2 );
-                        sample->data = s8;
-
-                        s8 += sample->length * 2;
-                        sample->length += lpc_extra;
-
-                        for ( o = 0; o < lpc_extra; o++ )
-                        {
-                            s8[ o * 2 + 0 ] = lpc_output[ o ];
-                            s8[ o * 2 + 1 ] = lpc_output[ o + lpc_extra ];
-                        }
-                    }
-                }
-                else
-                {
-                    if ( sample->flags & IT_SAMPLE_16BIT )
-                    {
-                        s16 = ( signed short * ) sample->data;
-                        s16 += offset;
-                        for ( o = 0; o < lpc_samples; o++ )
-                        {
-                            lpc_input[ o ] = s16[ o ];
-                        }
-                    }
-                    else
-                    {
-                        s8 = ( signed char * ) sample->data;
-                        s8 += offset;
-                        for ( o = 0; o < lpc_samples; o++ )
-                        {
-                            lpc_input[ o ] = s8[ o ];
-                        }
-                    }
-
-                    vorbis_lpc_from_data( lpc_input, lpc, lpc_samples, lpc_order );
-
-                    vorbis_lpc_predict( lpc, lpc_input + lpc_samples - lpc_order, lpc_order, lpc_output, lpc_extra );
-
-                    if ( sample->flags & IT_SAMPLE_16BIT )
-                    {
-                        s16 = ( signed short * ) realloc( sample->data, ( sample->length + lpc_extra ) * sizeof(short) );
-                        sample->data = s16;
-
-                        s16 += sample->length;
-                        sample->length += lpc_extra;
-
-                        for ( o = 0; o < lpc_extra; o++ )
-                        {
-                            s16[ o ] = lpc_output[ o ];
-                        }
-                    }
-                    else
-                    {
-                        s8 = ( signed char * ) realloc( sample->data, sample->length + lpc_extra );
-                        sample->data = s8;
-
-                        s8 += sample->length;
-                        sample->length += lpc_extra;
-
-                        for ( o = 0; o < lpc_extra; o++ )
-                        {
-                            s8[ o ] = lpc_output[ o ];
-                        }
-                    }
-                }
-            }
-            else
-            /* Otherwise, pad with silence. */
-            {
-                offset = sample->length;
-                lpc_samples = lpc_extra;
-
-                sample->length += lpc_samples;
-
-                n = 1;
-                if ( sample->flags & IT_SAMPLE_STEREO ) n *= 2;
-                if ( sample->flags & IT_SAMPLE_16BIT ) n *= 2;
-
-                offset *= n;
-                lpc_samples *= n;
-
-                sample->data = realloc( sample->data, offset + lpc_samples );
-                memset( (char*)sample->data + offset, 0, lpc_samples );
-            }
-        }
-    }
-}
--- a/dumb/src/helpers/memfile.c
+++ /dev/null
@@ -1,117 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * memfile.c - Module for reading data from           / / \  \
- *             memory using a DUMBFILE.              | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-
-
-
-typedef struct MEMFILE MEMFILE;
-
-struct MEMFILE
-{
-	const char *ptr, *ptr_begin;
-	long left, size;
-};
-
-
-
-static int dumb_memfile_skip(void *f, long n)
-{
-	MEMFILE *m = f;
-	if (n > m->left) return -1;
-	m->ptr += n;
-	m->left -= n;
-	return 0;
-}
-
-
-
-static int dumb_memfile_getc(void *f)
-{
-	MEMFILE *m = f;
-	if (m->left <= 0) return -1;
-	m->left--;
-	return *(const unsigned char *)m->ptr++;
-}
-
-
-
-static long dumb_memfile_getnc(char *ptr, long n, void *f)
-{
-	MEMFILE *m = f;
-	if (n > m->left) n = m->left;
-	memcpy(ptr, m->ptr, n);
-	m->ptr += n;
-	m->left -= n;
-	return n;
-}
-
-
-
-static void dumb_memfile_close(void *f)
-{
-	free(f);
-}
-
-
-static int dumb_memfile_seek(void *f, long n)
-{
-	MEMFILE *m = f;
-
-	m->ptr = m->ptr_begin + n;
-	m->left = m->size - n;
-
-	return 0;
-}
-
-
-static long dumb_memfile_get_size(void *f)
-{
-	MEMFILE *m = f;
-	return m->size;
-}
-
-
-static const DUMBFILE_SYSTEM memfile_dfs = {
-	NULL,
-	&dumb_memfile_skip,
-	&dumb_memfile_getc,
-	&dumb_memfile_getnc,
-	&dumb_memfile_close,
-	&dumb_memfile_seek,
-	&dumb_memfile_get_size
-};
-
-
-
-DUMBFILE *dumbfile_open_memory(const char *data, long size)
-{
-	MEMFILE *m = malloc(sizeof(*m));
-	if (!m) return NULL;
-
-	m->ptr_begin = data;
-	m->ptr = data;
-	m->left = size;
-	m->size = size;
-
-	return dumbfile_open_ex(m, &memfile_dfs);
-}
--- a/dumb/src/helpers/resamp2.inc
+++ /dev/null
@@ -1,162 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * resamp2.inc - Resampling helper template.          / / \  \
- *                                                   | <  /   \_
- * By Bob and entheh.                                |  \/ /\   /
- *                                                    \_  /  > /
- * In order to find a good trade-off between            | \ / /
- * speed and accuracy in this code, some tests          |  ' /
- * were carried out regarding the behaviour of           \__/
- * long long ints with gcc. The following code
- * was tested:
- *
- * int a, b, c;
- * c = ((long long)a * b) >> 16;
- *
- * DJGPP GCC Version 3.0.3 generated the following assembly language code for
- * the multiplication and scaling, leaving the 32-bit result in EAX.
- *
- * movl  -8(%ebp), %eax    ; read one int into EAX
- * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
- * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
- *
- * Note that a 32*32->64 multiplication is performed, allowing for high
- * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
- * so it is a minor concern when four multiplications are being performed
- * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
- * more cycles, so this method is unsuitable for use in the low-quality
- * resamplers.
- *
- * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
- * defined in dumb.h. We may investigate later what code MSVC generates, but
- * if it seems too slow then we suggest you use a good compiler.
- *
- * FIXME: these comments are somewhat out of date now.
- */
-
-
-
-#define SUFFIX3 _1
-
-/* For convenience, returns nonzero on stop. */
-static int process_pickup(DUMB_RESAMPLER *resampler)
-{
-	if (resampler->overshot < 0) {
-		resampler->overshot = 0;
-		dumb_resample(resampler, NULL, 2, MONO_DEST_VOLUME_ZEROS, 1.0f); /* Doesn't matter which SUFFIX3. */
-		COPYSRC(resampler->X, 0, resampler->X, 1);
-	}
-
-	for (;;) {
-		SRCTYPE *src = resampler->src;
-
-		if (resampler->dir < 0) {
-			if (resampler->overshot >= 3 && resampler->pos+3 >= resampler->start) COPYSRC(resampler->X, 0, src, resampler->pos+3);
-			if (resampler->overshot >= 2 && resampler->pos+2 >= resampler->start) COPYSRC(resampler->X, 1, src, resampler->pos+2);
-			if (resampler->overshot >= 1 && resampler->pos+1 >= resampler->start) COPYSRC(resampler->X, 2, src, resampler->pos+1);
-			resampler->overshot = resampler->start - resampler->pos - 1;
-		} else {
-			if (resampler->overshot >= 3 && resampler->pos-3 < resampler->end) COPYSRC(resampler->X, 0, src, resampler->pos-3);
-			if (resampler->overshot >= 2 && resampler->pos-2 < resampler->end) COPYSRC(resampler->X, 1, src, resampler->pos-2);
-			if (resampler->overshot >= 1 && resampler->pos-1 < resampler->end) COPYSRC(resampler->X, 2, src, resampler->pos-1);
-			resampler->overshot = resampler->pos - resampler->end;
-		}
-
-		if (resampler->overshot < 0) {
-			resampler->overshot = 0;
-			return 0;
-		}
-
-		if (!resampler->pickup) {
-			resampler->dir = 0;
-			return 1;
-		}
-		(*resampler->pickup)(resampler, resampler->pickup_data);
-		if (resampler->dir == 0) return 1;
-		ASSERT(resampler->dir == -1 || resampler->dir == 1);
-	}
-}
-
-
-
-/* Create mono destination resampler. */
-/* SUFFIX3 was set above. */
-#define VOLUME_PARAMETERS MONO_DEST_VOLUME_PARAMETERS
-#define VOLUME_VARIABLES MONO_DEST_VOLUME_VARIABLES
-#define SET_VOLUME_VARIABLES SET_MONO_DEST_VOLUME_VARIABLES
-#define RETURN_VOLUME_VARIABLES RETURN_MONO_DEST_VOLUME_VARIABLES
-#define VOLUMES_ARE_ZERO MONO_DEST_VOLUMES_ARE_ZERO
-#define PEEK_FIR MONO_DEST_PEEK_FIR
-#define MIX_FIR MONO_DEST_MIX_FIR
-#define MIX_ZEROS(op) *dst++ op 0
-#include "resamp3.inc"
-
-/* Create stereo destination resampler. */
-#define SUFFIX3 _2
-#define VOLUME_PARAMETERS DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right
-#define VOLUME_VARIABLES lvol, lvolr, lvold, lvolt, lvolm, rvol, rvolr, rvold, rvolt, rvolm
-#define SET_VOLUME_VARIABLES { \
-	if ( volume_left ) { \
-		lvolr = (int)(volume_left->volume * 16777216.0); \
-		lvold = (int)(volume_left->delta * 16777216.0); \
-		lvolt = (int)(volume_left->target * 16777216.0); \
-		lvolm = (int)(volume_left->mix * 16777216.0); \
-		lvol = MULSCV( lvolr, lvolm ); \
-		if ( lvolr == lvolt ) volume_left = NULL; \
-	} else { \
-		lvol = 0; \
-		lvold = 0; \
-		lvolt = 0; \
-		lvolm = 0; \
-	} \
-	if ( volume_right ) { \
-		rvolr = (int)(volume_right->volume * 16777216.0); \
-		rvold = (int)(volume_right->delta * 16777216.0); \
-		rvolt = (int)(volume_right->target * 16777216.0); \
-		rvolm = (int)(volume_right->mix * 16777216.0); \
-		rvol = MULSCV( rvolr, rvolm ); \
-		if ( rvolr == rvolt ) volume_right = NULL; \
-	} else { \
-		rvol = 0; \
-		rvold = 0; \
-		rvolt = 0; \
-		rvolm = 0; \
-	} \
-}
-#define RETURN_VOLUME_VARIABLES { \
-	if ( volume_left ) volume_left->volume = (float)lvolr / 16777216.0f; \
-	if ( volume_right ) volume_right->volume = (float)rvolr / 16777216.0f; \
-}
-#define VOLUMES_ARE_ZERO (lvol == 0 && lvolt == 0 && rvol == 0 && rvolt == 0)
-#define PEEK_FIR STEREO_DEST_PEEK_FIR
-#define MIX_FIR STEREO_DEST_MIX_FIR
-#define MIX_ZEROS(op) { *dst++ op 0; *dst++ op 0; }
-#include "resamp3.inc"
-
-
-
-#undef MONO_DEST_VOLUMES_ARE_ZERO
-#undef SET_MONO_DEST_VOLUME_VARIABLES
-#undef RETURN_MONO_DEST_VOLUME_VARIABLES
-#undef MONO_DEST_VOLUME_ZEROS
-#undef MONO_DEST_VOLUME_VARIABLES
-#undef MONO_DEST_VOLUME_PARAMETERS
-#undef MONO_DEST_PEEK_FIR
-#undef STEREO_DEST_PEEK_FIR
-#undef MONO_DEST_MIX_FIR
-#undef STEREO_DEST_MIX_FIR
-#undef ADVANCE_FIR
-#undef POKE_FIR
-#undef COPYSRC2
-#undef COPYSRC
-#undef DIVIDE_BY_SRC_CHANNELS
-#undef SRC_CHANNELS
-#undef SUFFIX2
--- a/dumb/src/helpers/resamp3.inc
+++ /dev/null
@@ -1,258 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * resamp3.inc - Resampling helper template.          / / \  \
- *                                                   | <  /   \_
- * By Bob and entheh.                                |  \/ /\   /
- *                                                    \_  /  > /
- * In order to find a good trade-off between            | \ / /
- * speed and accuracy in this code, some tests          |  ' /
- * were carried out regarding the behaviour of           \__/
- * long long ints with gcc. The following code
- * was tested:
- *
- * int a, b, c;
- * c = ((long long)a * b) >> 16;
- *
- * DJGPP GCC Version 3.0.3 generated the following assembly language code for
- * the multiplication and scaling, leaving the 32-bit result in EAX.
- *
- * movl  -8(%ebp), %eax    ; read one int into EAX
- * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
- * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
- *
- * Note that a 32*32->64 multiplication is performed, allowing for high
- * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
- * so it is a minor concern when four multiplications are being performed
- * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
- * more cycles, so this method is unsuitable for use in the low-quality
- * resamplers.
- *
- * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
- * defined in dumb.h. We may investigate later what code MSVC generates, but
- * if it seems too slow then we suggest you use a good compiler.
- *
- * FIXME: these comments are somewhat out of date now.
- */
-
-
-
-long dumb_resample(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, VOLUME_PARAMETERS, float delta)
-{
-	int dt, inv_dt;
-	int VOLUME_VARIABLES;
-	long done;
-	long todo;
-	LONG_LONG todo64;
-	int quality;
-
-	if (!resampler || resampler->dir == 0) return 0;
-	ASSERT(resampler->dir == -1 || resampler->dir == 1);
-
-	done = 0;
-	dt = (int)(delta * 65536.0 + 0.5);
-        if (dt == 0 || dt == (int)-0x80000000) return 0;
-        inv_dt = (int)(1.0 / delta * 65536.0 + 0.5);
-	SET_VOLUME_VARIABLES;
-
-	if (VOLUMES_ARE_ZERO) dst = NULL;
-
-	_dumb_init_cubic();
-
-	quality = resampler->quality;
-
-	while (done < dst_size) {
-                if (process_pickup(resampler)) {
-			RETURN_VOLUME_VARIABLES;
-			return done;
-		}
-
-		if ((resampler->dir ^ dt) < 0)
-			dt = -dt;
-
-		if (resampler->dir < 0)
-			todo64 = ((((LONG_LONG)(resampler->pos - resampler->start) << 16) + resampler->subpos - dt) / -dt);
-		else
-			todo64 = ((((LONG_LONG)(resampler->end - resampler->pos) << 16) - resampler->subpos - 1 + dt) / dt);
-
-		if (todo64 < 0)
-			todo = 0;
-		else if (todo64 > dst_size - done)
-			todo = dst_size - done;
-		else
-			todo = (long) todo64;
-
-		done += todo;
-
-		{
-			SRCTYPE *src = resampler->src;
-			long pos = resampler->pos;
-			int subpos = resampler->subpos;
-			long diff = pos;
-			long overshot;
-			if (resampler->dir < 0) {
-				if (!dst) {
-					/* Silence or simulation */
-					LONG_LONG new_subpos = subpos + (LONG_LONG)dt * todo;
-					pos += (long)(new_subpos >> 16);
-					subpos = (long)new_subpos & 65535;
-                                } else {
-                                    /* FIR resampling, backwards */
-                                    SRCTYPE *x;
-                                    if ( resampler->fir_resampler_ratio != delta ) {
-                                        resampler_set_rate( resampler->fir_resampler[0], delta );
-                                        resampler_set_rate( resampler->fir_resampler[1], delta );
-                                        resampler->fir_resampler_ratio = delta;
-                                    }
-                                    x = &src[pos*SRC_CHANNELS];
-                                    while ( todo ) {
-                                            while ( ( resampler_get_free_count( resampler->fir_resampler[0] ) ||
-                                            (!resampler_get_sample_count( resampler->fir_resampler[0] )
-#if SRC_CHANNELS == 2
-                                            && !resampler_get_sample_count( resampler->fir_resampler[1] )
-#endif
-                                            ) ) && pos >= resampler->start )
-                                            {
-                                                    POKE_FIR(0);
-                                                    pos--;
-                                                    x -= SRC_CHANNELS;
-                                            }
-                                            if ( !resampler_get_sample_count( resampler->fir_resampler[0] ) ) break;
-                                            MIX_FIR;
-                                            ADVANCE_FIR;
-                                            --todo;
-                                    }
-                                    done -= todo;
-                                }
-				diff = diff - pos;
-				overshot = resampler->start - pos - 1;
-				if (diff >= 3) {
-					COPYSRC2(resampler->X, 0, overshot < 3, src, pos+3);
-					COPYSRC2(resampler->X, 1, overshot < 2, src, pos+2);
-					COPYSRC2(resampler->X, 2, overshot < 1, src, pos+1);
-				} else if (diff >= 2) {
-					COPYSRC(resampler->X, 0, resampler->X, 2);
-					COPYSRC2(resampler->X, 1, overshot < 2, src, pos+2);
-					COPYSRC2(resampler->X, 2, overshot < 1, src, pos+1);
-				} else if (diff >= 1) {
-					COPYSRC(resampler->X, 0, resampler->X, 1);
-					COPYSRC(resampler->X, 1, resampler->X, 2);
-					COPYSRC2(resampler->X, 2, overshot < 1, src, pos+1);
-				}
-			} else {
-				if (!dst) {
-					/* Silence or simulation */
-					LONG_LONG new_subpos = subpos + (LONG_LONG)dt * todo;
-					pos += (long)(new_subpos >> 16);
-					subpos = (long)new_subpos & 65535;
-                                } else {
-                                    /* FIR resampling, forwards */
-                                    SRCTYPE *x;
-                                    if ( resampler->fir_resampler_ratio != delta ) {
-                                        resampler_set_rate( resampler->fir_resampler[0], delta );
-                                        resampler_set_rate( resampler->fir_resampler[1], delta );
-                                        resampler->fir_resampler_ratio = delta;
-                                    }
-                                    x = &src[pos*SRC_CHANNELS];
-                                    while ( todo ) {
-                                            while ( ( resampler_get_free_count( resampler->fir_resampler[0] ) ||
-                                            (!resampler_get_sample_count( resampler->fir_resampler[0] )
-#if SRC_CHANNELS == 2
-                                            && !resampler_get_sample_count( resampler->fir_resampler[1] )
-#endif
-                                            ) ) && pos < resampler->end )
-                                            {
-                                                    POKE_FIR(0);
-                                                    pos++;
-                                                    x += SRC_CHANNELS;
-                                            }
-                                            if ( !resampler_get_sample_count( resampler->fir_resampler[0] ) ) break;
-                                            MIX_FIR;
-                                            ADVANCE_FIR;
-                                            --todo;
-                                    }
-                                    done -= todo;
-                                }
-				diff = pos - diff;
-				overshot = pos - resampler->end;
-				if (diff >= 3) {
-					COPYSRC2(resampler->X, 0, overshot < 3, src, pos-3);
-					COPYSRC2(resampler->X, 1, overshot < 2, src, pos-2);
-					COPYSRC2(resampler->X, 2, overshot < 1, src, pos-1);
-				} else if (diff >= 2) {
-					COPYSRC(resampler->X, 0, resampler->X, 2);
-					COPYSRC2(resampler->X, 1, overshot < 2, src, pos-2);
-					COPYSRC2(resampler->X, 2, overshot < 1, src, pos-1);
-				} else if (diff >= 1) {
-					COPYSRC(resampler->X, 0, resampler->X, 1);
-					COPYSRC(resampler->X, 1, resampler->X, 2);
-					COPYSRC2(resampler->X, 2, overshot < 1, src, pos-1);
-				}
-			}
-			resampler->pos = pos;
-			resampler->subpos = subpos;
-		}
-	}
-
-	RETURN_VOLUME_VARIABLES;
-	return done;
-}
-
-
-
-void dumb_resample_get_current_sample(DUMB_RESAMPLER *resampler, VOLUME_PARAMETERS, sample_t *dst)
-{
-	int VOLUME_VARIABLES;
-	SRCTYPE *src;
-	long pos;
-	int subpos;
-	int quality;
-	SRCTYPE *x;
-
-	if (!resampler || resampler->dir == 0) { MIX_ZEROS(=); return; }
-	ASSERT(resampler->dir == -1 || resampler->dir == 1);
-
-	if (process_pickup(resampler)) { MIX_ZEROS(=); return; }
-
-	SET_VOLUME_VARIABLES;
-
-	if (VOLUMES_ARE_ZERO) { MIX_ZEROS(=); return; }
-
-	_dumb_init_cubic();
-
-	quality = resampler->quality;
-
-	src = resampler->src;
-	pos = resampler->pos;
-	subpos = resampler->subpos;
-	x = resampler->X;
-
-	if (resampler->dir < 0) {
-		HEAVYASSERT(pos >= resampler->start);
-                        /* FIR resampling, backwards */
-                        PEEK_FIR;
-	} else {
-		HEAVYASSERT(pos < resampler->end);
-                        /* FIR resampling, forwards */
-                        PEEK_FIR;
-	}
-}
-
-
-
-#undef MIX_ZEROS
-#undef MIX_FIR
-#undef PEEK_FIR
-#undef VOLUMES_ARE_ZERO
-#undef SET_VOLUME_VARIABLES
-#undef RETURN_VOLUME_VARIABLES
-#undef VOLUME_VARIABLES
-#undef VOLUME_PARAMETERS
-#undef SUFFIX3
--- a/dumb/src/helpers/resample.c
+++ /dev/null
@@ -1,330 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * resample.c - Resampling helpers.                   / / \  \
- *                                                   | <  /   \_
- * By Bob and entheh.                                |  \/ /\   /
- *                                                    \_  /  > /
- * In order to find a good trade-off between            | \ / /
- * speed and accuracy in this code, some tests          |  ' /
- * were carried out regarding the behaviour of           \__/
- * long long ints with gcc. The following code
- * was tested:
- *
- * int a, b, c;
- * c = ((long long)a * b) >> 16;
- *
- * DJGPP GCC Version 3.0.3 generated the following assembly language code for
- * the multiplication and scaling, leaving the 32-bit result in EAX.
- *
- * movl  -8(%ebp), %eax    ; read one int into EAX
- * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
- * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
- *
- * Note that a 32*32->64 multiplication is performed, allowing for high
- * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
- * so it is a minor concern when four multiplications are being performed
- * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
- * more cycles, so this method is unsuitable for use in the low-quality
- * resamplers.
- *
- * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
- * defined in dumb.h. We may investigate later what code MSVC generates, but
- * if it seems too slow then we suggest you use a good compiler.
- *
- * FIXME: these comments are somewhat out of date now.
- */
-
-#include <math.h>
-#include "dumb.h"
-
-#include "internal/resampler.h"
-
-
-
-/* Compile with -DHEAVYDEBUG if you want to make sure the pick-up function is
- * called when it should be. There will be a considerable performance hit,
- * since at least one condition has to be tested for every sample generated.
- */
-#ifdef HEAVYDEBUG
-#define HEAVYASSERT(cond) ASSERT(cond)
-#else
-#define HEAVYASSERT(cond)
-#endif
-
-
-
-/* Make MSVC shut the hell up about if ( upd ) UPDATE_VOLUME() conditions being constant */
-#ifdef _MSC_VER
-#pragma warning(disable:4127 4701)
-#endif
-
-
-
-/* A global variable for controlling resampling quality wherever a local
- * specification doesn't override it. The following values are valid:
- *
- *  0 - DUMB_RQ_ALIASING - fastest
- *  1 - DUMB_RQ_BLEP     - nicer than aliasing, but slower
- *  2 - DUMB_RQ_LINEAR
- *  3 - DUMB_RQ_BLAM     - band-limited linear interpolation, nice but slower
- *  4 - DUMB_RQ_CUBIC
- *  5 - DUMB_RQ_FIR      - nicest
- *
- * Values outside the range 0-4 will behave the same as the nearest
- * value within the range.
- */
-int dumb_resampling_quality = DUMB_RQ_CUBIC;
-
-
-
-//#define MULSC(a, b) ((int)((LONG_LONG)(a) * (b) >> 16))
-//#define MULSC(a, b) ((a) * ((b) >> 2) >> 14)
-#define MULSCV(a, b) ((int)((LONG_LONG)(a) * (b) >> 32))
-#define MULSC(a, b) ((int)((LONG_LONG)((a) << 4) * ((b) << 12) >> 32))
-#define MULSC16(a, b) ((int)((LONG_LONG)((a) << 12) * ((b) << 12) >> 32))
-
-
-
-/* Executes the content 'iterator' times.
- * Clobbers the 'iterator' variable.
- * The loop is unrolled by four.
- */
-#if 0
-#define LOOP4(iterator, CONTENT) \
-{ \
-	if ((iterator) & 2) { \
-		CONTENT; \
-		CONTENT; \
-	} \
-	if ((iterator) & 1) { \
-		CONTENT; \
-	} \
-	(iterator) >>= 2; \
-	while (iterator) { \
-		CONTENT; \
-		CONTENT; \
-		CONTENT; \
-		CONTENT; \
-		(iterator)--; \
-	} \
-}
-#else
-#define LOOP4(iterator, CONTENT) \
-{ \
-	while ( (iterator)-- ) \
-	{ \
-		CONTENT; \
-	} \
-}
-#endif
-
-#define PASTERAW(a, b) a ## b /* This does not expand macros in b ... */
-#define PASTE(a, b) PASTERAW(a, b) /* ... but b is expanded during this substitution. */
-
-#define X PASTE(x.x, SRCBITS)
-
-
-
-void _dumb_init_cubic(void)
-{
-	static int done = 0;
-	if (done) return;
-
-	resampler_init();
-
-	done = 1;
-}
-
-
-
-/* Create resamplers for 24-in-32-bit source samples. */
-
-/* #define SUFFIX
- * MSVC warns if we try to paste a null SUFFIX, so instead we define
- * special macros for the function names that don't bother doing the
- * corresponding paste. The more generic definitions are further down.
- */
-#define process_pickup PASTE(process_pickup, SUFFIX2)
-#define dumb_resample PASTE(PASTE(dumb_resample, SUFFIX2), SUFFIX3)
-#define dumb_resample_get_current_sample PASTE(PASTE(dumb_resample_get_current_sample, SUFFIX2), SUFFIX3)
-
-#define SRCTYPE sample_t
-#define SRCBITS 24
-#define FIR(x) (x >> 8)
-#include "resample.inc"
-
-/* Undefine the simplified macros. */
-#undef dumb_resample_get_current_sample
-#undef dumb_resample
-#undef process_pickup
-
-
-/* Now define the proper ones that use SUFFIX. */
-#define dumb_reset_resampler PASTE(dumb_reset_resampler, SUFFIX)
-#define dumb_start_resampler PASTE(dumb_start_resampler, SUFFIX)
-#define process_pickup PASTE(PASTE(process_pickup, SUFFIX), SUFFIX2)
-#define dumb_resample PASTE(PASTE(PASTE(dumb_resample, SUFFIX), SUFFIX2), SUFFIX3)
-#define dumb_resample_get_current_sample PASTE(PASTE(PASTE(dumb_resample_get_current_sample, SUFFIX), SUFFIX2), SUFFIX3)
-#define dumb_end_resampler PASTE(dumb_end_resampler, SUFFIX)
-
-/* Create resamplers for 16-bit source samples. */
-#define SUFFIX _16
-#define SRCTYPE short
-#define SRCBITS 16
-#define FIR(x) (x)
-#include "resample.inc"
-
-/* Create resamplers for 8-bit source samples. */
-#define SUFFIX _8
-#define SRCTYPE signed char
-#define SRCBITS 8
-#define FIR(x) (x << 8)
-#include "resample.inc"
-
-
-#undef dumb_reset_resampler
-#undef dumb_start_resampler
-#undef process_pickup
-#undef dumb_resample
-#undef dumb_resample_get_current_sample
-#undef dumb_end_resampler
-
-
-
-void dumb_reset_resampler_n(int n, DUMB_RESAMPLER *resampler, void *src, int src_channels, long pos, long start, long end, int quality)
-{
-	if (n == 8)
-		dumb_reset_resampler_8(resampler, src, src_channels, pos, start, end, quality);
-	else if (n == 16)
-		dumb_reset_resampler_16(resampler, src, src_channels, pos, start, end, quality);
-	else
-		dumb_reset_resampler(resampler, src, src_channels, pos, start, end, quality);
-}
-
-
-
-DUMB_RESAMPLER *dumb_start_resampler_n(int n, void *src, int src_channels, long pos, long start, long end, int quality)
-{
-	if (n == 8)
-		return dumb_start_resampler_8(src, src_channels, pos, start, end, quality);
-	else if (n == 16)
-		return dumb_start_resampler_16(src, src_channels, pos, start, end, quality);
-	else
-		return dumb_start_resampler(src, src_channels, pos, start, end, quality);
-}
-
-
-
-long dumb_resample_n_1_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume, float delta)
-{
-	if (n == 8)
-		return dumb_resample_8_1_1(resampler, dst, dst_size, volume, delta);
-	else if (n == 16)
-		return dumb_resample_16_1_1(resampler, dst, dst_size, volume, delta);
-	else
-		return dumb_resample_1_1(resampler, dst, dst_size, volume, delta);
-}
-
-
-
-long dumb_resample_n_1_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta)
-{
-	if (n == 8)
-		return dumb_resample_8_1_2(resampler, dst, dst_size, volume_left, volume_right, delta);
-	else if (n == 16)
-		return dumb_resample_16_1_2(resampler, dst, dst_size, volume_left, volume_right, delta);
-	else
-		return dumb_resample_1_2(resampler, dst, dst_size, volume_left, volume_right, delta);
-}
-
-
-
-long dumb_resample_n_2_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta)
-{
-	if (n == 8)
-		return dumb_resample_8_2_1(resampler, dst, dst_size, volume_left, volume_right, delta);
-	else if (n == 16)
-		return dumb_resample_16_2_1(resampler, dst, dst_size, volume_left, volume_right, delta);
-	else
-		return dumb_resample_2_1(resampler, dst, dst_size, volume_left, volume_right, delta);
-}
-
-
-
-long dumb_resample_n_2_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, float delta)
-{
-	if (n == 8)
-		return dumb_resample_8_2_2(resampler, dst, dst_size, volume_left, volume_right, delta);
-	else if (n == 16)
-		return dumb_resample_16_2_2(resampler, dst, dst_size, volume_left, volume_right, delta);
-	else
-		return dumb_resample_2_2(resampler, dst, dst_size, volume_left, volume_right, delta);
-}
-
-
-
-void dumb_resample_get_current_sample_n_1_1(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume, sample_t *dst)
-{
-	if (n == 8)
-		dumb_resample_get_current_sample_8_1_1(resampler, volume, dst);
-	else if (n == 16)
-		dumb_resample_get_current_sample_16_1_1(resampler, volume, dst);
-	else
-		dumb_resample_get_current_sample_1_1(resampler, volume, dst);
-}
-
-
-
-void dumb_resample_get_current_sample_n_1_2(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst)
-{
-	if (n == 8)
-		dumb_resample_get_current_sample_8_1_2(resampler, volume_left, volume_right, dst);
-	else if (n == 16)
-		dumb_resample_get_current_sample_16_1_2(resampler, volume_left, volume_right, dst);
-	else
-		dumb_resample_get_current_sample_1_2(resampler, volume_left, volume_right, dst);
-}
-
-
-
-void dumb_resample_get_current_sample_n_2_1(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst)
-{
-	if (n == 8)
-		dumb_resample_get_current_sample_8_2_1(resampler, volume_left, volume_right, dst);
-	else if (n == 16)
-		dumb_resample_get_current_sample_16_2_1(resampler, volume_left, volume_right, dst);
-	else
-		dumb_resample_get_current_sample_2_1(resampler, volume_left, volume_right, dst);
-}
-
-
-
-void dumb_resample_get_current_sample_n_2_2(int n, DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right, sample_t *dst)
-{
-	if (n == 8)
-		dumb_resample_get_current_sample_8_2_2(resampler, volume_left, volume_right, dst);
-	else if (n == 16)
-		dumb_resample_get_current_sample_16_2_2(resampler, volume_left, volume_right, dst);
-	else
-		dumb_resample_get_current_sample_2_2(resampler, volume_left, volume_right, dst);
-}
-
-
-
-void dumb_end_resampler_n(int n, DUMB_RESAMPLER *resampler)
-{
-	if (n == 8)
-		dumb_end_resampler_8(resampler);
-	else if (n == 16)
-		dumb_end_resampler_16(resampler);
-	else
-		dumb_end_resampler(resampler);
-}
--- a/dumb/src/helpers/resample.inc
+++ /dev/null
@@ -1,256 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * resample.inc - Resampling helper template.         / / \  \
- *                                                   | <  /   \_
- * By Bob and entheh.                                |  \/ /\   /
- *                                                    \_  /  > /
- * In order to find a good trade-off between            | \ / /
- * speed and accuracy in this code, some tests          |  ' /
- * were carried out regarding the behaviour of           \__/
- * long long ints with gcc. The following code
- * was tested:
- *
- * int a, b, c;
- * c = ((long long)a * b) >> 16;
- *
- * DJGPP GCC Version 3.0.3 generated the following assembly language code for
- * the multiplication and scaling, leaving the 32-bit result in EAX.
- *
- * movl  -8(%ebp), %eax    ; read one int into EAX
- * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
- * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
- *
- * Note that a 32*32->64 multiplication is performed, allowing for high
- * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
- * so it is a minor concern when four multiplications are being performed
- * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
- * more cycles, so this method is unsuitable for use in the low-quality
- * resamplers.
- *
- * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
- * defined in dumb.h. We may investigate later what code MSVC generates, but
- * if it seems too slow then we suggest you use a good compiler.
- *
- * FIXME: these comments are somewhat out of date now.
- */
-
-
-
-void dumb_reset_resampler(DUMB_RESAMPLER *resampler, SRCTYPE *src, int src_channels, long pos, long start, long end, int quality)
-{
-	int i;
-	resampler->src = src;
-	resampler->pos = pos;
-	resampler->subpos = 0;
-	resampler->start = start;
-	resampler->end = end;
-	resampler->dir = 1;
-	resampler->pickup = NULL;
-	resampler->pickup_data = NULL;
-	if (quality < 0)
-	{
-		resampler->quality = 0;
-	}
-	else if (quality > DUMB_RQ_N_LEVELS - 1)
-	{
-		resampler->quality = DUMB_RQ_N_LEVELS - 1;
-	}
-	else
-	{
-		resampler->quality = quality;
-	}
-	for (i = 0; i < src_channels*3; i++) resampler->X[i] = 0;
-	resampler->overshot = -1;
-        resampler->fir_resampler_ratio = 0;
-        resampler_clear(resampler->fir_resampler[0]);
-        resampler_clear(resampler->fir_resampler[1]);
-        resampler_set_quality(resampler->fir_resampler[0], resampler->quality);
-        resampler_set_quality(resampler->fir_resampler[1], resampler->quality);
-}
-
-
-
-DUMB_RESAMPLER *dumb_start_resampler(SRCTYPE *src, int src_channels, long pos, long start, long end, int quality)
-{
-	DUMB_RESAMPLER *resampler = malloc(sizeof(*resampler));
-	if (!resampler) return NULL;
-	dumb_reset_resampler(resampler, src, src_channels, pos, start, end, quality);
-	return resampler;
-}
-
-
-
-#define UPDATE_VOLUME( pvol, vol ) {                               \
-	if (pvol) {                                                    \
-		vol##r += vol##d;                                          \
-		if ((vol##d < 0 && vol##r <= vol##t) ||                    \
-			(vol##d > 0 && vol##r >= vol##t)) {                    \
-			pvol->volume = pvol->target;                           \
-            if ( pvol->declick_stage == 0 ||                       \
-                 pvol->declick_stage >= 3)                         \
-                 pvol->declick_stage++;                            \
-			pvol = NULL;                                           \
-			vol = MULSCV( vol##t, vol##m );                        \
-		} else {                                                   \
-			vol = MULSCV( vol##r, vol##m );                        \
-		}                                                          \
-	}                                                              \
-}
-
-
-
-/* Create mono source resampler. */
-#define SUFFIX2 _1
-#define SRC_CHANNELS 1
-#define DIVIDE_BY_SRC_CHANNELS(x) (x)
-#define COPYSRC(dstarray, dstindex, srcarray, srcindex) (dstarray)[dstindex] = (srcarray)[srcindex]
-#define COPYSRC2(dstarray, dstindex, condition, srcarray, srcindex) (dstarray)[dstindex] = condition ? (srcarray)[srcindex] : 0
-#define MONO_DEST_VOLUME_PARAMETERS DUMB_VOLUME_RAMP_INFO * volume
-#define MONO_DEST_VOLUME_VARIABLES vol, volr, vold, volt, volm
-#define MONO_DEST_VOLUME_ZEROS 0
-#define SET_MONO_DEST_VOLUME_VARIABLES { \
-	if ( volume ) { \
-		volr = (int)(volume->volume * 16777216.0); \
-		vold = (int)(volume->delta * 16777216.0); \
-		volt = (int)(volume->target * 16777216.0); \
-		volm = (int)(volume->mix * 16777216.0); \
-		vol = MULSCV( volr, volm ); \
-		if ( volr == volt ) volume = NULL; \
-	} else { \
-		vol = 0; \
-		vold = 0; \
-		volt = 0; \
-		volm = 0; \
-	} \
-}
-#define RETURN_MONO_DEST_VOLUME_VARIABLES if ( volume ) volume->volume = (float)volr / 16777216.0f
-#define MONO_DEST_VOLUMES_ARE_ZERO (vol == 0 && volt == 0)
-#define POKE_FIR(offset) { \
-        resampler_write_sample( resampler->fir_resampler[0], FIR(x[offset]) ); \
-}
-#define MONO_DEST_PEEK_FIR *dst = MULSC( resampler_get_sample( resampler->fir_resampler[0] ), vol )
-#define MONO_DEST_MIX_FIR { \
-        *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[0] ), vol ); \
-        UPDATE_VOLUME( volume, vol ); \
-}
-#define ADVANCE_FIR resampler_remove_sample( resampler->fir_resampler[0], 1 )
-#define STEREO_DEST_PEEK_FIR { \
-        int sample = resampler_get_sample( resampler->fir_resampler[0] ); \
-        *dst++ = MULSC( sample, lvol ); \
-        *dst++ = MULSC( sample, rvol ); \
-}
-#define STEREO_DEST_MIX_FIR { \
-        int sample = resampler_get_sample( resampler->fir_resampler[0] ); \
-        *dst++ += MULSC( sample, lvol ); \
-        *dst++ += MULSC( sample, rvol ); \
-        UPDATE_VOLUME( volume_left, lvol ); \
-        UPDATE_VOLUME( volume_right, rvol ); \
-}
-#include "resamp2.inc"
-
-/* Create stereo source resampler. */
-#define SUFFIX2 _2
-#define SRC_CHANNELS 2
-#define DIVIDE_BY_SRC_CHANNELS(x) ((x) >> 1)
-#define COPYSRC(dstarray, dstindex, srcarray, srcindex) { \
-	(dstarray)[(dstindex)*2] = (srcarray)[(srcindex)*2]; \
-	(dstarray)[(dstindex)*2+1] = (srcarray)[(srcindex)*2+1]; \
-}
-#define COPYSRC2(dstarray, dstindex, condition, srcarray, srcindex) { \
-	if (condition) { \
-		(dstarray)[(dstindex)*2] = (srcarray)[(srcindex)*2]; \
-		(dstarray)[(dstindex)*2+1] = (srcarray)[(srcindex)*2+1]; \
-	} else { \
-		(dstarray)[(dstindex)*2] = 0; \
-		(dstarray)[(dstindex)*2+1] = 0; \
-	} \
-}
-
-#define MONO_DEST_VOLUME_PARAMETERS DUMB_VOLUME_RAMP_INFO * volume_left, DUMB_VOLUME_RAMP_INFO * volume_right
-#define MONO_DEST_VOLUME_VARIABLES lvol, lvolr, lvold, lvolt, lvolm, rvol, rvolr, rvold, rvolt, rvolm
-#define MONO_DEST_VOLUME_ZEROS 0, 0
-#define SET_MONO_DEST_VOLUME_VARIABLES { \
-	if ( volume_left ) { \
-		lvolr = (int)(volume_left->volume * 16777216.0); \
-		lvold = (int)(volume_left->delta * 16777216.0); \
-		lvolt = (int)(volume_left->target * 16777216.0); \
-		lvolm = (int)(volume_left->mix * 16777216.0); \
-		lvol = MULSCV( lvolr, lvolm ); \
-		if ( lvolr == lvolt ) volume_left = NULL; \
-	} else { \
-		lvol = 0; \
-		lvold = 0; \
-		lvolt = 0; \
-		lvolm = 0; \
-	} \
-	if ( volume_right ) { \
-		rvolr = (int)(volume_right->volume * 16777216.0); \
-		rvold = (int)(volume_right->delta * 16777216.0); \
-		rvolt = (int)(volume_right->target * 16777216.0); \
-		rvolm = (int)(volume_right->mix * 16777216.0); \
-		rvol = MULSCV( rvolr, rvolm ); \
-		if ( rvolr == rvolt ) volume_right = NULL; \
-	} else { \
-		rvol = 0; \
-		rvold = 0; \
-		rvolt = 0; \
-		rvolm = 0; \
-	} \
-}
-#define RETURN_MONO_DEST_VOLUME_VARIABLES { \
-	if ( volume_left ) volume_left->volume = (float)lvolr / 16777216.0f; \
-	if ( volume_right ) volume_right->volume = (float)rvolr / 16777216.0f; \
-}
-#define MONO_DEST_VOLUMES_ARE_ZERO (lvol == 0 && lvolt == 0 && rvol == 0 && rvolt == 0)
-#define POKE_FIR(offset) { \
-        resampler_write_sample( resampler->fir_resampler[0], FIR(x[(offset)*2+0]) ); \
-        resampler_write_sample( resampler->fir_resampler[1], FIR(x[(offset)*2+1]) ); \
-}
-#define MONO_DEST_PEEK_FIR { \
-        *dst = MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ) + \
-                MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
-}
-#define MONO_DEST_MIX_FIR { \
-        *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ) + \
-                MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
-        UPDATE_VOLUME( volume_left, lvol ); \
-        UPDATE_VOLUME( volume_right, rvol ); \
-}
-#define ADVANCE_FIR { \
-        resampler_remove_sample( resampler->fir_resampler[0], 1 ); \
-        resampler_remove_sample( resampler->fir_resampler[1], 1 ); \
-}
-#define STEREO_DEST_PEEK_FIR { \
-        *dst++ = MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ); \
-        *dst++ = MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
-}
-#define STEREO_DEST_MIX_FIR { \
-        *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[0] ), lvol ); \
-        *dst++ += MULSC( resampler_get_sample( resampler->fir_resampler[1] ), rvol ); \
-        UPDATE_VOLUME( volume_left, lvol ); \
-        UPDATE_VOLUME( volume_right, rvol ); \
-}
-#include "resamp2.inc"
-
-
-
-void dumb_end_resampler(DUMB_RESAMPLER *resampler)
-{
-	if (resampler)
-		free(resampler);
-}
-
-
-
-#undef FIR
-#undef SRCBITS
-#undef SRCTYPE
-#undef SUFFIX
--- a/dumb/src/helpers/resampler.c
+++ /dev/null
@@ -1,1496 +1,0 @@
-#include <stdlib.h>
-#include <string.h>
-#define _USE_MATH_DEFINES
-#include <math.h>
-#if (defined(_M_IX86) && (_M_IX86_FP != 0)) ||\
-    (defined(__i386__) && defined(__SSE__)) ||\
-     defined(_M_X64) || defined(_M_AMD64) || defined(__amd64__)
-#include <xmmintrin.h>
-#define RESAMPLER_SSE
-#endif
-#ifdef __APPLE__
-#include <TargetConditionals.h>
-#if TARGET_CPU_ARM || TARGET_CPU_ARM64
-#define RESAMPLER_NEON
-#endif
-#elif (defined(__arm__) && defined(__ARM_NEON__)) || defined(_M_ARM)
-#define RESAMPLER_NEON
-#endif
-#ifdef RESAMPLER_NEON
-#include <arm_neon.h>
-#endif
-
-#ifdef _MSC_VER
-#define ALIGNED     _declspec(align(16))
-#else
-#define ALIGNED     __attribute__((aligned(16)))
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#include "internal/resampler.h"
-
-enum { RESAMPLER_SHIFT = 10 };
-enum { RESAMPLER_SHIFT_EXTRA = 8 };
-enum { RESAMPLER_RESOLUTION = 1 << RESAMPLER_SHIFT };
-enum { RESAMPLER_RESOLUTION_EXTRA = 1 << (RESAMPLER_SHIFT + RESAMPLER_SHIFT_EXTRA) };
-enum { SINC_WIDTH = 16 };
-enum { SINC_SAMPLES = RESAMPLER_RESOLUTION * SINC_WIDTH };
-enum { CUBIC_SAMPLES = RESAMPLER_RESOLUTION * 4 };
-
-static const float RESAMPLER_BLEP_CUTOFF = 0.90f;
-static const float RESAMPLER_BLAM_CUTOFF = 0.93f;
-static const float RESAMPLER_SINC_CUTOFF = 0.999f;
-
-ALIGNED static float cubic_lut[CUBIC_SAMPLES];
-
-static float sinc_lut[SINC_SAMPLES + 1];
-static float window_lut[SINC_SAMPLES + 1];
-
-enum { resampler_buffer_size = SINC_WIDTH * 4 };
-
-static int fEqual(const float b, const float a)
-{
-    return fabs(a - b) < 1.0e-6;
-}
-
-static float sinc(float x)
-{
-    return fEqual(x, 0.0) ? 1.0 : sin(x * M_PI) / (x * M_PI);
-}
-
-#ifdef RESAMPLER_SSE
-#ifdef _MSC_VER
-#include <intrin.h>
-#elif defined(__clang__) || defined(__GNUC__)
-static inline void
-__cpuid(int *data, int selector)
-{
-#if defined(__PIC__) && defined(__i386__)
-    asm("xchgl %%ebx, %%esi; cpuid; xchgl %%ebx, %%esi"
-        : "=a" (data[0]),
-        "=S" (data[1]),
-        "=c" (data[2]),
-        "=d" (data[3])
-        : "0" (selector));
-#elif defined(__PIC__) && defined(__amd64__)
-    asm("xchg{q} {%%}rbx, %q1; cpuid; xchg{q} {%%}rbx, %q1"
-        : "=a" (data[0]),
-        "=&r" (data[1]),
-        "=c" (data[2]),
-        "=d" (data[3])
-        : "0" (selector));
-#else
-    asm("cpuid"
-        : "=a" (data[0]),
-        "=b" (data[1]),
-        "=c" (data[2]),
-        "=d" (data[3])
-        : "0" (selector));
-#endif
-}
-#else
-#define __cpuid(a,b) memset((a), 0, sizeof(int) * 4)
-#endif
-
-static int query_cpu_feature_sse() {
-    int buffer[4];
-    __cpuid(buffer,1);
-    if ((buffer[3]&(1<<25)) == 0) return 0;
-    return 1;
-}
-
-static int resampler_has_sse = 0;
-#endif
-
-void resampler_init(void)
-{
-    unsigned i;
-    double dx = (float)(SINC_WIDTH) / SINC_SAMPLES, x = 0.0;
-    for (i = 0; i < SINC_SAMPLES + 1; ++i, x += dx)
-    {
-        float y = x / SINC_WIDTH;
-#if 0
-        // Blackman
-        float window = 0.42659 - 0.49656 * cos(M_PI + M_PI * y) + 0.076849 * cos(2.0 * M_PI * y);
-#elif 1
-        // Nuttal 3 term
-        float window = 0.40897 + 0.5 * cos(M_PI * y) + 0.09103 * cos(2.0 * M_PI * y);
-#elif 0
-        // C.R.Helmrich's 2 term window
-        float window = 0.79445 * cos(0.5 * M_PI * y) + 0.20555 * cos(1.5 * M_PI * y);
-#elif 0
-        // Lanczos
-        float window = sinc(y);
-#endif
-        sinc_lut[i] = fabs(x) < SINC_WIDTH ? sinc(x) : 0.0;
-        window_lut[i] = window;
-    }
-    dx = 1.0 / (float)(RESAMPLER_RESOLUTION);
-    x = 0.0;
-    for (i = 0; i < RESAMPLER_RESOLUTION; ++i, x += dx)
-    {
-        cubic_lut[i*4]   = (float)(-0.5 * x * x * x +       x * x - 0.5 * x);
-        cubic_lut[i*4+1] = (float)( 1.5 * x * x * x - 2.5 * x * x           + 1.0);
-        cubic_lut[i*4+2] = (float)(-1.5 * x * x * x + 2.0 * x * x + 0.5 * x);
-        cubic_lut[i*4+3] = (float)( 0.5 * x * x * x - 0.5 * x * x);
-    }
-#ifdef RESAMPLER_SSE
-    resampler_has_sse = query_cpu_feature_sse();
-#endif
-}
-
-typedef struct resampler
-{
-    int write_pos, write_filled;
-    int read_pos, read_filled;
-    float phase;
-    float phase_inc;
-    float inv_phase;
-    float inv_phase_inc;
-    unsigned char quality;
-    signed char delay_added;
-    signed char delay_removed;
-    float last_amp;
-    float accumulator;
-    float buffer_in[resampler_buffer_size * 2];
-    float buffer_out[resampler_buffer_size + SINC_WIDTH * 2 - 1];
-} resampler;
-
-void * resampler_create(void)
-{
-    resampler * r = ( resampler * ) malloc( sizeof(resampler) );
-    if ( !r ) return 0;
-
-    r->write_pos = SINC_WIDTH - 1;
-    r->write_filled = 0;
-    r->read_pos = 0;
-    r->read_filled = 0;
-    r->phase = 0;
-    r->phase_inc = 0;
-    r->inv_phase = 0;
-    r->inv_phase_inc = 0;
-    r->quality = RESAMPLER_QUALITY_MAX;
-    r->delay_added = -1;
-    r->delay_removed = -1;
-    r->last_amp = 0;
-    r->accumulator = 0;
-    memset( r->buffer_in, 0, sizeof(r->buffer_in) );
-    memset( r->buffer_out, 0, sizeof(r->buffer_out) );
-
-    return r;
-}
-
-void resampler_delete(void * _r)
-{
-    free( _r );
-}
-
-void * resampler_dup(const void * _r)
-{
-    void * r_out = malloc( sizeof(resampler) );
-    if ( !r_out ) return 0;
-
-    resampler_dup_inplace(r_out, _r);
-
-    return r_out;
-}
-
-void resampler_dup_inplace(void *_d, const void *_s)
-{
-    const resampler * r_in = ( const resampler * ) _s;
-    resampler * r_out = ( resampler * ) _d;
-
-    r_out->write_pos = r_in->write_pos;
-    r_out->write_filled = r_in->write_filled;
-    r_out->read_pos = r_in->read_pos;
-    r_out->read_filled = r_in->read_filled;
-    r_out->phase = r_in->phase;
-    r_out->phase_inc = r_in->phase_inc;
-    r_out->inv_phase = r_in->inv_phase;
-    r_out->inv_phase_inc = r_in->inv_phase_inc;
-    r_out->quality = r_in->quality;
-    r_out->delay_added = r_in->delay_added;
-    r_out->delay_removed = r_in->delay_removed;
-    r_out->last_amp = r_in->last_amp;
-    r_out->accumulator = r_in->accumulator;
-    memcpy( r_out->buffer_in, r_in->buffer_in, sizeof(r_in->buffer_in) );
-    memcpy( r_out->buffer_out, r_in->buffer_out, sizeof(r_in->buffer_out) );
-}
-
-void resampler_set_quality(void *_r, int quality)
-{
-    resampler * r = ( resampler * ) _r;
-    if (quality < RESAMPLER_QUALITY_MIN)
-        quality = RESAMPLER_QUALITY_MIN;
-    else if (quality > RESAMPLER_QUALITY_MAX)
-        quality = RESAMPLER_QUALITY_MAX;
-    if ( r->quality != quality )
-    {
-        if ( quality == RESAMPLER_QUALITY_BLEP || r->quality == RESAMPLER_QUALITY_BLEP ||
-             quality == RESAMPLER_QUALITY_BLAM || r->quality == RESAMPLER_QUALITY_BLAM )
-        {
-            r->read_pos = 0;
-            r->read_filled = 0;
-            r->last_amp = 0;
-            r->accumulator = 0;
-            memset( r->buffer_out, 0, sizeof(r->buffer_out) );
-        }
-        r->delay_added = -1;
-        r->delay_removed = -1;
-    }
-    r->quality = (unsigned char)quality;
-}
-
-int resampler_get_free_count(void *_r)
-{
-    resampler * r = ( resampler * ) _r;
-    return resampler_buffer_size - r->write_filled;
-}
-
-static int resampler_min_filled(resampler *r)
-{
-    switch (r->quality)
-    {
-    default:
-    case RESAMPLER_QUALITY_ZOH:
-    case RESAMPLER_QUALITY_BLEP:
-        return 1;
-            
-    case RESAMPLER_QUALITY_LINEAR:
-    case RESAMPLER_QUALITY_BLAM:
-        return 2;
-            
-    case RESAMPLER_QUALITY_CUBIC:
-        return 4;
-            
-    case RESAMPLER_QUALITY_SINC:
-        return SINC_WIDTH * 2;
-    }
-}
-
-static int resampler_input_delay(resampler *r)
-{
-    switch (r->quality)
-    {
-    default:
-    case RESAMPLER_QUALITY_ZOH:
-    case RESAMPLER_QUALITY_BLEP:
-    case RESAMPLER_QUALITY_LINEAR:
-    case RESAMPLER_QUALITY_BLAM:
-        return 0;
-            
-    case RESAMPLER_QUALITY_CUBIC:
-        return 1;
-            
-    case RESAMPLER_QUALITY_SINC:
-        return SINC_WIDTH - 1;
-    }
-}
-
-static int resampler_output_delay(resampler *r)
-{
-    switch (r->quality)
-    {
-    default:
-    case RESAMPLER_QUALITY_ZOH:
-    case RESAMPLER_QUALITY_LINEAR:
-    case RESAMPLER_QUALITY_CUBIC:
-    case RESAMPLER_QUALITY_SINC:
-        return 0;
-            
-    case RESAMPLER_QUALITY_BLEP:
-    case RESAMPLER_QUALITY_BLAM:
-        return SINC_WIDTH - 1;
-    }
-}
-
-int resampler_ready(void *_r)
-{
-    resampler * r = ( resampler * ) _r;
-    return r->write_filled > resampler_min_filled(r);
-}
-
-void resampler_clear(void *_r)
-{
-    resampler * r = ( resampler * ) _r;
-    r->write_pos = SINC_WIDTH - 1;
-    r->write_filled = 0;
-    r->read_pos = 0;
-    r->read_filled = 0;
-    r->phase = 0;
-    r->delay_added = -1;
-    r->delay_removed = -1;
-    memset(r->buffer_in, 0, (SINC_WIDTH - 1) * sizeof(r->buffer_in[0]));
-    memset(r->buffer_in + resampler_buffer_size, 0, (SINC_WIDTH - 1) * sizeof(r->buffer_in[0]));
-    if (r->quality == RESAMPLER_QUALITY_BLEP || r->quality == RESAMPLER_QUALITY_BLAM)
-    {
-        r->inv_phase = 0;
-        r->last_amp = 0;
-        r->accumulator = 0;
-        memset(r->buffer_out, 0, sizeof(r->buffer_out));
-    }
-}
-
-void resampler_set_rate(void *_r, double new_factor)
-{
-    resampler * r = ( resampler * ) _r;
-    r->phase_inc = new_factor;
-    new_factor = 1.0 / new_factor;
-    r->inv_phase_inc = new_factor;
-}
-
-void resampler_write_sample(void *_r, short s)
-{
-    resampler * r = ( resampler * ) _r;
-
-    if ( r->delay_added < 0 )
-    {
-        r->delay_added = 0;
-        r->write_filled = resampler_input_delay( r );
-    }
-    
-    if ( r->write_filled < resampler_buffer_size )
-    {
-        float s32 = s;
-        s32 *= 256.0;
-
-        r->buffer_in[ r->write_pos ] = s32;
-        r->buffer_in[ r->write_pos + resampler_buffer_size ] = s32;
-
-        ++r->write_filled;
-
-        r->write_pos = ( r->write_pos + 1 ) % resampler_buffer_size;
-    }
-}
-
-void resampler_write_sample_fixed(void *_r, int s, unsigned char depth)
-{
-    resampler * r = ( resampler * ) _r;
-    
-    if ( r->delay_added < 0 )
-    {
-        r->delay_added = 0;
-        r->write_filled = resampler_input_delay( r );
-    }
-    
-    if ( r->write_filled < resampler_buffer_size )
-    {
-        float s32 = s;
-        s32 /= (double)(1 << (depth - 1));
-        
-        r->buffer_in[ r->write_pos ] = s32;
-        r->buffer_in[ r->write_pos + resampler_buffer_size ] = s32;
-        
-        ++r->write_filled;
-        
-        r->write_pos = ( r->write_pos + 1 ) % resampler_buffer_size;
-    }
-}
-
-static int resampler_run_zoh(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 1;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        
-        do
-        {
-            float sample;
-            
-            if ( out >= out_end )
-                break;
-
-            sample = *in;
-            *out++ = sample;
-            
-            phase += phase_inc;
-            
-            in += (int)phase;
-            
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-
-#ifndef RESAMPLER_NEON
-static int resampler_run_blep(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 1;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float last_amp = r->last_amp;
-        float inv_phase = r->inv_phase;
-        float inv_phase_inc = r->inv_phase_inc;
-        
-        const int step = RESAMPLER_BLEP_CUTOFF * RESAMPLER_RESOLUTION;
-        const int window_step = RESAMPLER_RESOLUTION;
-        
-        do
-        {
-            float sample;
-            
-            if ( out + SINC_WIDTH * 2 > out_end )
-                break;
-            
-            sample = *in++ - last_amp;
-            
-            if (sample)
-            {
-                float kernel[SINC_WIDTH * 2], kernel_sum = 0.0f;
-                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
-                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-                int i = SINC_WIDTH;
-
-                for (; i >= -SINC_WIDTH + 1; --i)
-                {
-                    int pos = i * step;
-                    int window_pos = i * window_step;
-                    kernel_sum += kernel[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-                }
-                last_amp += sample;
-                sample /= kernel_sum;
-                for (i = 0; i < SINC_WIDTH * 2; ++i)
-                    out[i] += sample * kernel[i];
-            }
-            
-            inv_phase += inv_phase_inc;
-            
-            out += (int)inv_phase;
-            
-            inv_phase = fmod(inv_phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->inv_phase = inv_phase;
-        r->last_amp = last_amp;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_SSE
-static int resampler_run_blep_sse(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 1;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float last_amp = r->last_amp;
-        float inv_phase = r->inv_phase;
-        float inv_phase_inc = r->inv_phase_inc;
-        
-        const int step = RESAMPLER_BLEP_CUTOFF * RESAMPLER_RESOLUTION;
-        const int window_step = RESAMPLER_RESOLUTION;
-        
-        do
-        {
-            float sample;
-            
-            if ( out + SINC_WIDTH * 2 > out_end )
-                break;
-            
-            sample = *in++ - last_amp;
-            
-            if (sample)
-            {
-                float kernel_sum = 0.0f;
-                __m128 kernel[SINC_WIDTH / 2];
-                __m128 temp1, temp2;
-                __m128 samplex;
-                float *kernelf = (float*)(&kernel);
-                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
-                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-                int i = SINC_WIDTH;
-
-                for (; i >= -SINC_WIDTH + 1; --i)
-                {
-                    int pos = i * step;
-                    int window_pos = i * window_step;
-                    kernel_sum += kernelf[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-                }
-                last_amp += sample;
-                sample /= kernel_sum;
-                samplex = _mm_set1_ps( sample );
-                for (i = 0; i < SINC_WIDTH / 2; ++i)
-                {
-                    temp1 = _mm_load_ps( (const float *)( kernel + i ) );
-                    temp1 = _mm_mul_ps( temp1, samplex );
-                    temp2 = _mm_loadu_ps( (const float *) out + i * 4 );
-                    temp1 = _mm_add_ps( temp1, temp2 );
-                    _mm_storeu_ps( (float *) out + i * 4, temp1 );
-                }
-            }
-            
-            inv_phase += inv_phase_inc;
-            
-            out += (int)inv_phase;
-            
-            inv_phase = fmod(inv_phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->inv_phase = inv_phase;
-        r->last_amp = last_amp;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_NEON
-static int resampler_run_blep(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 1;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float last_amp = r->last_amp;
-        float inv_phase = r->inv_phase;
-        float inv_phase_inc = r->inv_phase_inc;
-        
-        const int step = RESAMPLER_BLEP_CUTOFF * RESAMPLER_RESOLUTION;
-        const int window_step = RESAMPLER_RESOLUTION;
-        
-        do
-        {
-            float sample;
-            
-            if ( out + SINC_WIDTH * 2 > out_end )
-                break;
-            
-            sample = *in++ - last_amp;
-            
-            if (sample)
-            {
-                float kernel_sum = 0.0f;
-                float32x4_t kernel[SINC_WIDTH / 2];
-                float32x4_t temp1, temp2;
-                float32x4_t samplex;
-                float *kernelf = (float*)(&kernel);
-                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
-                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-                int i = SINC_WIDTH;
-
-                for (; i >= -SINC_WIDTH + 1; --i)
-                {
-                    int pos = i * step;
-                    int window_pos = i * window_step;
-                    kernel_sum += kernelf[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-                }
-                last_amp += sample;
-                sample /= kernel_sum;
-                samplex = vdupq_n_f32(sample);
-                for (i = 0; i < SINC_WIDTH / 2; ++i)
-                {
-                    temp1 = vld1q_f32( (const float32_t *)( kernel + i ) );
-                    temp2 = vld1q_f32( (const float32_t *) out + i * 4 );
-                    temp2 = vmlaq_f32( temp2, temp1, samplex );
-                    vst1q_f32( (float32_t *) out + i * 4, temp2 );
-                }
-            }
-            
-            inv_phase += inv_phase_inc;
-            
-            out += (int)inv_phase;
-            
-            inv_phase = fmod(inv_phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->inv_phase = inv_phase;
-        r->last_amp = last_amp;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-static int resampler_run_linear(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 2;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        
-        do
-        {
-            float sample;
-            
-            if ( out >= out_end )
-                break;
-            
-            sample = in[0] + (in[1] - in[0]) * phase;
-            *out++ = sample;
-            
-            phase += phase_inc;
-            
-            in += (int)phase;
-            
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-
-#ifndef RESAMPLER_NEON
-static int resampler_run_blam(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 2;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float last_amp = r->last_amp;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        float inv_phase = r->inv_phase;
-        float inv_phase_inc = r->inv_phase_inc;
-        
-        const int step = RESAMPLER_BLAM_CUTOFF * RESAMPLER_RESOLUTION;
-        const int window_step = RESAMPLER_RESOLUTION;
-
-        do
-        {
-            float sample;
-            
-            if ( out + SINC_WIDTH * 2 > out_end )
-                break;
-            
-            sample = in[0];
-            if (phase_inc < 1.0f)
-                sample += (in[1] - in[0]) * phase;
-            sample -= last_amp;
-            
-            if (sample)
-            {
-                float kernel[SINC_WIDTH * 2], kernel_sum = 0.0f;
-                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
-                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-                int i = SINC_WIDTH;
-
-                for (; i >= -SINC_WIDTH + 1; --i)
-                {
-                    int pos = i * step;
-                    int window_pos = i * window_step;
-                    kernel_sum += kernel[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-                }
-                last_amp += sample;
-                sample /= kernel_sum;
-                for (i = 0; i < SINC_WIDTH * 2; ++i)
-                    out[i] += sample * kernel[i];
-            }
-            
-            if (inv_phase_inc < 1.0f)
-            {
-                ++in;
-                inv_phase += inv_phase_inc;
-                out += (int)inv_phase;
-                inv_phase = fmod(inv_phase, 1.0f);
-            }
-            else
-            {
-                phase += phase_inc;
-                ++out;
-                in += (int)phase;
-                phase = fmod(phase, 1.0f);
-            }
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        r->inv_phase = inv_phase;
-        r->last_amp = last_amp;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_SSE
-static int resampler_run_blam_sse(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 2;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float last_amp = r->last_amp;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        float inv_phase = r->inv_phase;
-        float inv_phase_inc = r->inv_phase_inc;
-        
-        const int step = RESAMPLER_BLAM_CUTOFF * RESAMPLER_RESOLUTION;
-        const int window_step = RESAMPLER_RESOLUTION;
-
-        do
-        {
-            float sample;
-            
-            if ( out + SINC_WIDTH * 2 > out_end )
-                break;
-
-            sample = in[0];
-            if (phase_inc < 1.0f)
-            {
-                sample += (in[1] - in[0]) * phase;
-            }
-            sample -= last_amp;
-            
-            if (sample)
-            {
-                float kernel_sum = 0.0f;
-                __m128 kernel[SINC_WIDTH / 2];
-                __m128 temp1, temp2;
-                __m128 samplex;
-                float *kernelf = (float*)(&kernel);
-                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
-                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-                int i = SINC_WIDTH;
-
-                for (; i >= -SINC_WIDTH + 1; --i)
-                {
-                    int pos = i * step;
-                    int window_pos = i * window_step;
-                    kernel_sum += kernelf[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-                }
-                last_amp += sample;
-                sample /= kernel_sum;
-                samplex = _mm_set1_ps( sample );
-                for (i = 0; i < SINC_WIDTH / 2; ++i)
-                {
-                    temp1 = _mm_load_ps( (const float *)( kernel + i ) );
-                    temp1 = _mm_mul_ps( temp1, samplex );
-                    temp2 = _mm_loadu_ps( (const float *) out + i * 4 );
-                    temp1 = _mm_add_ps( temp1, temp2 );
-                    _mm_storeu_ps( (float *) out + i * 4, temp1 );
-                }
-            }
-            
-            if (inv_phase_inc < 1.0f)
-            {
-                ++in;
-                inv_phase += inv_phase_inc;
-                out += (int)inv_phase;
-                inv_phase = fmod(inv_phase, 1.0f);
-            }
-            else
-            {
-                phase += phase_inc;
-                ++out;
-                
-                if (phase >= 1.0f)
-                {
-                    ++in;
-                    phase = fmod(phase, 1.0f);
-                }
-            }
-        }
-        while ( in < in_end );
-
-        r->phase = phase;
-        r->inv_phase = inv_phase;
-        r->last_amp = last_amp;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_NEON
-static int resampler_run_blam(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 2;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float last_amp = r->last_amp;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        float inv_phase = r->inv_phase;
-        float inv_phase_inc = r->inv_phase_inc;
-        
-        const int step = RESAMPLER_BLAM_CUTOFF * RESAMPLER_RESOLUTION;
-        const int window_step = RESAMPLER_RESOLUTION;
-
-        do
-        {
-            float sample;
-            
-            if ( out + SINC_WIDTH * 2 > out_end )
-                break;
-            
-            sample = in[0];
-            if (phase_inc < 1.0f)
-                sample += (in[1] - in[0]) * phase;
-            sample -= last_amp;
-            
-            if (sample)
-            {
-                float kernel_sum = 0.0;
-                float32x4_t kernel[SINC_WIDTH / 2];
-                float32x4_t temp1, temp2;
-                float32x4_t samplex;
-                float *kernelf = (float*)(&kernel);
-                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
-                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-                int i = SINC_WIDTH;
-
-                for (; i >= -SINC_WIDTH + 1; --i)
-                {
-                    int pos = i * step;
-                    int window_pos = i * window_step;
-                    kernel_sum += kernelf[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-                }
-                last_amp += sample;
-                sample /= kernel_sum;
-                samplex = vdupq_n_f32(sample);
-                for (i = 0; i < SINC_WIDTH / 2; ++i)
-                {
-                    temp1 = vld1q_f32( (const float32_t *)( kernel + i ) );
-                    temp2 = vld1q_f32( (const float32_t *) out + i * 4 );
-                    temp2 = vmlaq_f32( temp2, temp1, samplex );
-                    vst1q_f32( (float32_t *) out + i * 4, temp2 );
-                }
-            }
-
-            if (inv_phase_inc < 1.0f)
-            {
-                ++in;
-                inv_phase += inv_phase_inc;
-                out += (int)inv_phase;
-                inv_phase = fmod(inv_phase, 1.0f);
-            }
-            else
-            {
-                phase += phase_inc;
-                ++out;
-                
-                if (phase >= 1.0f)
-                {
-                    ++in;
-                    phase = fmod(phase, 1.0f);
-                }
-            }
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        r->inv_phase = inv_phase;
-        r->last_amp = last_amp;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifndef RESAMPLER_NEON
-static int resampler_run_cubic(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 4;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        
-        do
-        {
-            float * kernel;
-            int i;
-            float sample;
-            
-            if ( out >= out_end )
-                break;
-            
-            kernel = cubic_lut + (int)(phase * RESAMPLER_RESOLUTION) * 4;
-            
-            for (sample = 0, i = 0; i < 4; ++i)
-                sample += in[i] * kernel[i];
-            *out++ = sample;
-            
-            phase += phase_inc;
-            
-            in += (int)phase;
-            
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_SSE
-static int resampler_run_cubic_sse(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 4;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        
-        do
-        {
-            __m128 temp1, temp2;
-            __m128 samplex = _mm_setzero_ps();
-            
-            if ( out >= out_end )
-                break;
-            
-            temp1 = _mm_loadu_ps( (const float *)( in ) );
-            temp2 = _mm_load_ps( (const float *)( cubic_lut + (int)(phase * RESAMPLER_RESOLUTION) * 4 ) );
-            temp1 = _mm_mul_ps( temp1, temp2 );
-            samplex = _mm_add_ps( samplex, temp1 );
-            temp1 = _mm_movehl_ps( temp1, samplex );
-            samplex = _mm_add_ps( samplex, temp1 );
-            temp1 = samplex;
-            temp1 = _mm_shuffle_ps( temp1, samplex, _MM_SHUFFLE(0, 0, 0, 1) );
-            samplex = _mm_add_ps( samplex, temp1 );
-            _mm_store_ss( out, samplex );
-            ++out;
-            
-            phase += phase_inc;
-            
-            in += (int)phase;
-            
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_NEON
-static int resampler_run_cubic(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= 4;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        
-        do
-        {
-            float32x4_t temp1, temp2;
-            float32x2_t half;
-            
-            if ( out >= out_end )
-                break;
-            
-            temp1 = vld1q_f32( (const float32_t *)( in ) );
-            temp2 = vld1q_f32( (const float32_t *)( cubic_lut + (int)(phase * RESAMPLER_RESOLUTION) * 4 ) );
-            temp1 = vmulq_f32( temp1, temp2 );
-            half = vadd_f32(vget_high_f32(temp1), vget_low_f32(temp1));
-            *out++ = vget_lane_f32(vpadd_f32(half, half), 0);
-            
-            phase += phase_inc;
-            
-            in += (int)phase;
-            
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifndef RESAMPLER_NEON
-static int resampler_run_sinc(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= SINC_WIDTH * 2;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-
-        int step = phase_inc > 1.0f ? (int)(RESAMPLER_RESOLUTION / phase_inc * RESAMPLER_SINC_CUTOFF) : (int)(RESAMPLER_RESOLUTION * RESAMPLER_SINC_CUTOFF);
-        int window_step = RESAMPLER_RESOLUTION;
-
-        do
-        {
-            float kernel[SINC_WIDTH * 2], kernel_sum = 0.0;
-            int i = SINC_WIDTH;
-            int phase_reduced = (int)(phase * RESAMPLER_RESOLUTION);
-            int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-            float sample;
-
-            if ( out >= out_end )
-                break;
-
-            for (; i >= -SINC_WIDTH + 1; --i)
-            {
-                int pos = i * step;
-                int window_pos = i * window_step;
-                kernel_sum += kernel[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-            }
-            for (sample = 0, i = 0; i < SINC_WIDTH * 2; ++i)
-                sample += in[i] * kernel[i];
-            *out++ = (float)(sample / kernel_sum);
-
-            phase += phase_inc;
-
-            in += (int)phase;
-
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-
-        r->phase = phase;
-        *out_ = out;
-
-        used = (int)(in - in_);
-
-        r->write_filled -= used;
-    }
-
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_SSE
-static int resampler_run_sinc_sse(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= SINC_WIDTH * 2;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        
-        int step = phase_inc > 1.0f ? (int)(RESAMPLER_RESOLUTION / phase_inc * RESAMPLER_SINC_CUTOFF) : (int)(RESAMPLER_RESOLUTION * RESAMPLER_SINC_CUTOFF);
-        int window_step = RESAMPLER_RESOLUTION;
-        
-        do
-        {
-            // accumulate in extended precision
-            float kernel_sum = 0.0;
-            __m128 kernel[SINC_WIDTH / 2];
-            __m128 temp1, temp2;
-            __m128 samplex = _mm_setzero_ps();
-            float *kernelf = (float*)(&kernel);
-            int i = SINC_WIDTH;
-            int phase_reduced = (int)(phase * RESAMPLER_RESOLUTION);
-            int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-            
-            if ( out >= out_end )
-                break;
-            
-            for (; i >= -SINC_WIDTH + 1; --i)
-            {
-                int pos = i * step;
-                int window_pos = i * window_step;
-                kernel_sum += kernelf[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-            }
-            for (i = 0; i < SINC_WIDTH / 2; ++i)
-            {
-                temp1 = _mm_loadu_ps( (const float *)( in + i * 4 ) );
-                temp2 = _mm_load_ps( (const float *)( kernel + i ) );
-                temp1 = _mm_mul_ps( temp1, temp2 );
-                samplex = _mm_add_ps( samplex, temp1 );
-            }
-            kernel_sum = 1.0 / kernel_sum;
-            temp1 = _mm_movehl_ps( temp1, samplex );
-            samplex = _mm_add_ps( samplex, temp1 );
-            temp1 = samplex;
-            temp1 = _mm_shuffle_ps( temp1, samplex, _MM_SHUFFLE(0, 0, 0, 1) );
-            samplex = _mm_add_ps( samplex, temp1 );
-            temp1 = _mm_set_ss( kernel_sum );
-            samplex = _mm_mul_ps( samplex, temp1 );
-            _mm_store_ss( out, samplex );
-            ++out;
-            
-            phase += phase_inc;
-            
-            in += (int)phase;
-            
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-#ifdef RESAMPLER_NEON
-static int resampler_run_sinc(resampler * r, float ** out_, float * out_end)
-{
-    int in_size = r->write_filled;
-    float const* in_ = r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
-    int used = 0;
-    in_size -= SINC_WIDTH * 2;
-    if ( in_size > 0 )
-    {
-        float* out = *out_;
-        float const* in = in_;
-        float const* const in_end = in + in_size;
-        float phase = r->phase;
-        float phase_inc = r->phase_inc;
-        
-        int step = phase_inc > 1.0f ? (int)(RESAMPLER_RESOLUTION / phase_inc * RESAMPLER_SINC_CUTOFF) : (int)(RESAMPLER_RESOLUTION * RESAMPLER_SINC_CUTOFF);
-        int window_step = RESAMPLER_RESOLUTION;
-        
-        do
-        {
-            // accumulate in extended precision
-            float kernel_sum = 0.0;
-            float32x4_t kernel[SINC_WIDTH / 2];
-            float32x4_t temp1, temp2;
-            float32x4_t samplex = {0};
-            float32x2_t half;
-            float *kernelf = (float*)(&kernel);
-            int i = SINC_WIDTH;
-            int phase_reduced = (int)(phase * RESAMPLER_RESOLUTION);
-            int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
-            
-            if ( out >= out_end )
-                break;
-            
-            for (; i >= -SINC_WIDTH + 1; --i)
-            {
-                int pos = i * step;
-                int window_pos = i * window_step;
-                kernel_sum += kernelf[i + SINC_WIDTH - 1] = sinc_lut[abs(phase_adj - pos)] * window_lut[abs(phase_reduced - window_pos)];
-            }
-            for (i = 0; i < SINC_WIDTH / 2; ++i)
-            {
-                temp1 = vld1q_f32( (const float32_t *)( in + i * 4 ) );
-                temp2 = vld1q_f32( (const float32_t *)( kernel + i ) );
-                samplex = vmlaq_f32( samplex, temp1, temp2 );
-            }
-            kernel_sum = 1.0 / kernel_sum;
-            samplex = vmulq_f32(samplex, vmovq_n_f32(kernel_sum));
-            half = vadd_f32(vget_high_f32(samplex), vget_low_f32(samplex));
-            *out++ = vget_lane_f32(vpadd_f32(half, half), 0);
-            
-            phase += phase_inc;
-            
-            in += (int)phase;
-            
-            phase = fmod(phase, 1.0f);
-        }
-        while ( in < in_end );
-        
-        r->phase = phase;
-        *out_ = out;
-        
-        used = (int)(in - in_);
-        
-        r->write_filled -= used;
-    }
-    
-    return used;
-}
-#endif
-
-static void resampler_fill(resampler * r)
-{
-    int min_filled = resampler_min_filled(r);
-    int quality = r->quality;
-    while ( r->write_filled > min_filled &&
-            r->read_filled < resampler_buffer_size )
-    {
-        int write_pos = ( r->read_pos + r->read_filled ) % resampler_buffer_size;
-        int write_size = resampler_buffer_size - write_pos;
-        float * out = r->buffer_out + write_pos;
-        if ( write_size > ( resampler_buffer_size - r->read_filled ) )
-            write_size = resampler_buffer_size - r->read_filled;
-        switch (quality)
-        {
-        case RESAMPLER_QUALITY_ZOH:
-            resampler_run_zoh( r, &out, out + write_size );
-            break;
-                
-        case RESAMPLER_QUALITY_BLEP:
-        {
-            int used;
-            int write_extra = 0;
-            if ( write_pos >= r->read_pos )
-                write_extra = r->read_pos;
-            if ( write_extra > SINC_WIDTH * 2 - 1 )
-                write_extra = SINC_WIDTH * 2 - 1;
-            memcpy( r->buffer_out + resampler_buffer_size, r->buffer_out, write_extra * sizeof(r->buffer_out[0]) );
-#ifdef RESAMPLER_SSE
-            if ( resampler_has_sse )
-                used = resampler_run_blep_sse( r, &out, out + write_size + write_extra );
-            else
-#endif
-                used = resampler_run_blep( r, &out, out + write_size + write_extra );
-            memcpy( r->buffer_out, r->buffer_out + resampler_buffer_size, write_extra * sizeof(r->buffer_out[0]) );
-            if (!used)
-                return;
-            break;
-        }
-                
-        case RESAMPLER_QUALITY_LINEAR:
-            resampler_run_linear( r, &out, out + write_size );
-            break;
-                
-        case RESAMPLER_QUALITY_BLAM:
-        {
-            float * out_ = out;
-            int write_extra = 0;
-            if ( write_pos >= r->read_pos )
-                write_extra = r->read_pos;
-            if ( write_extra > SINC_WIDTH * 2 - 1 )
-                write_extra = SINC_WIDTH * 2 - 1;
-            memcpy( r->buffer_out + resampler_buffer_size, r->buffer_out, write_extra * sizeof(r->buffer_out[0]) );
-#ifdef RESAMPLER_SSE
-            if ( resampler_has_sse )
-                resampler_run_blam_sse( r, &out, out + write_size + write_extra );
-            else
-#endif
-                resampler_run_blam( r, &out, out + write_size + write_extra );
-            memcpy( r->buffer_out, r->buffer_out + resampler_buffer_size, write_extra * sizeof(r->buffer_out[0]) );
-            if ( out == out_ )
-                return;
-            break;
-        }
-
-        case RESAMPLER_QUALITY_CUBIC:
-#ifdef RESAMPLER_SSE
-            if ( resampler_has_sse )
-                resampler_run_cubic_sse( r, &out, out + write_size );
-            else
-#endif
-                resampler_run_cubic( r, &out, out + write_size );
-            break;
-                
-        case RESAMPLER_QUALITY_SINC:
-#ifdef RESAMPLER_SSE
-            if ( resampler_has_sse )
-                resampler_run_sinc_sse( r, &out, out + write_size );
-            else
-#endif
-                resampler_run_sinc( r, &out, out + write_size );
-            break;
-        }
-        r->read_filled += out - r->buffer_out - write_pos;
-    }
-}
-
-static void resampler_fill_and_remove_delay(resampler * r)
-{
-    resampler_fill( r );
-    if ( r->delay_removed < 0 )
-    {
-        int delay = resampler_output_delay( r );
-        r->delay_removed = 0;
-        while ( delay-- )
-            resampler_remove_sample( r, 1 );
-    }
-}
-
-int resampler_get_sample_count(void *_r)
-{
-    resampler * r = ( resampler * ) _r;
-    if ( r->read_filled < 1 && ((r->quality != RESAMPLER_QUALITY_BLEP && r->quality != RESAMPLER_QUALITY_BLAM) || r->inv_phase_inc))
-        resampler_fill_and_remove_delay( r );
-    return r->read_filled;
-}
-
-int resampler_get_sample(void *_r)
-{
-    resampler * r = ( resampler * ) _r;
-    if ( r->read_filled < 1 && r->phase_inc)
-        resampler_fill_and_remove_delay( r );
-    if ( r->read_filled < 1 )
-        return 0;
-    if ( r->quality == RESAMPLER_QUALITY_BLEP || r->quality == RESAMPLER_QUALITY_BLAM )
-        return (int)(r->buffer_out[ r->read_pos ] + r->accumulator);
-    else
-        return (int)r->buffer_out[ r->read_pos ];
-}
-
-float resampler_get_sample_float(void *_r)
-{
-    resampler * r = ( resampler * ) _r;
-    if ( r->read_filled < 1 && r->phase_inc)
-        resampler_fill_and_remove_delay( r );
-    if ( r->read_filled < 1 )
-        return 0;
-    if ( r->quality == RESAMPLER_QUALITY_BLEP || r->quality == RESAMPLER_QUALITY_BLAM )
-        return r->buffer_out[ r->read_pos ] + r->accumulator;
-    else
-        return r->buffer_out[ r->read_pos ];
-}
-
-void resampler_remove_sample(void *_r, int decay)
-{
-    resampler * r = ( resampler * ) _r;
-    if ( r->read_filled > 0 )
-    {
-        if ( r->quality == RESAMPLER_QUALITY_BLEP || r->quality == RESAMPLER_QUALITY_BLAM )
-        {
-            r->accumulator += r->buffer_out[ r->read_pos ];
-            r->buffer_out[ r->read_pos ] = 0;
-            if (decay)
-            {
-                r->accumulator -= r->accumulator * (1.0f / 8192.0f);
-                if (fabs(r->accumulator) < 1e-20f)
-                    r->accumulator = 0;
-            }
-        }
-        --r->read_filled;
-        r->read_pos = ( r->read_pos + 1 ) % resampler_buffer_size;
-    }
-}
--- a/dumb/src/helpers/riff.c
+++ /dev/null
@@ -1,85 +1,0 @@
-#include "dumb.h"
-#include "internal/riff.h"
-
-#include <stdlib.h>
-
-struct riff * riff_parse( DUMBFILE * f, long offset, long size, unsigned proper )
-{
-	unsigned stream_size;
-	struct riff * stream;
-
-    if ( size < 8 ) return 0;
-
-    if ( dumbfile_seek(f, offset, DFS_SEEK_SET) ) return 0;
-    if ( dumbfile_mgetl(f) != DUMB_ID('R','I','F','F') ) return 0;
-
-    stream_size = dumbfile_igetl(f);
-    if ( stream_size + 8 > size ) return 0;
-	if ( stream_size < 4 ) return 0;
-
-    stream = (struct riff *) malloc( sizeof( struct riff ) );
-	if ( ! stream ) return 0;
-
-    stream->type = dumbfile_mgetl(f);
-	stream->chunk_count = 0;
-	stream->chunks = 0;
-
-	stream_size -= 4;
-
-    while ( stream_size && !dumbfile_error(f) )
-	{
-		struct riff_chunk * chunk;
-		if ( stream_size < 8 ) break;
-        stream->chunks = ( struct riff_chunk * ) realloc( stream->chunks, ( stream->chunk_count + 1 ) * sizeof( struct riff_chunk ) );
-		if ( ! stream->chunks ) break;
-		chunk = stream->chunks + stream->chunk_count;
-        chunk->type = dumbfile_mgetl(f);
-        chunk->size = dumbfile_igetl(f);
-        chunk->offset = dumbfile_pos(f);
-		stream_size -= 8;
-		if ( stream_size < chunk->size ) break;
-        if ( chunk->type == DUMB_ID('R','I','F','F') )
-		{
-            chunk->nested = riff_parse( f, chunk->offset - 8, chunk->size + 8, proper );
-            if ( ! chunk->nested ) break;
-		}
-		else
-		{
-            chunk->nested = 0;
-		}
-        dumbfile_seek(f, chunk->offset + chunk->size, DFS_SEEK_SET);
-		stream_size -= chunk->size;
-		if ( proper && ( chunk->size & 1 ) )
-		{
-            dumbfile_skip(f, 1);
-			-- stream_size;
-		}
-		++stream->chunk_count;
-	}
-	
-	if ( stream_size )
-	{
-		riff_free( stream );
-		stream = 0;
-	}
-
-	return stream;
-}
-
-void riff_free( struct riff * stream )
-{
-	if ( stream )
-	{
-		if ( stream->chunks )
-		{
-			unsigned i;
-			for ( i = 0; i < stream->chunk_count; ++i )
-			{
-				struct riff_chunk * chunk = stream->chunks + i;
-                if ( chunk->nested ) riff_free( chunk->nested );
-			}
-			free( stream->chunks );
-		}
-		free( stream );
-	}
-}
--- a/dumb/src/helpers/sampbuf.c
+++ /dev/null
@@ -1,64 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * sampbuf.c - Helper for allocating sample           / / \  \
- *             buffers.                              | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include "dumb.h"
-
-
-
-/* DEPRECATED */
-sample_t **create_sample_buffer(int n_channels, long length)
-{
-	int i;
-	sample_t **samples = malloc(n_channels * sizeof(*samples));
-	if (!samples) return NULL;
-	samples[0] = malloc(n_channels * length * sizeof(*samples[0]));
-	if (!samples[0]) {
-		free(samples);
-		return NULL;
-	}
-	for (i = 1; i < n_channels; i++) samples[i] = samples[i-1] + length;
-	return samples;
-}
-
-
-
-sample_t **allocate_sample_buffer(int n_channels, long length)
-{
-	int i;
-	sample_t **samples = malloc(((n_channels + 1) >> 1) * sizeof(*samples));
-	if (!samples) return NULL;
-	samples[0] = malloc(n_channels * length * sizeof(*samples[0]));
-	if (!samples[0]) {
-		free(samples);
-		return NULL;
-	}
-	for (i = 1; i < (n_channels + 1) >> 1; i++) samples[i] = samples[i-1] + length*2;
-	return samples;
-}
-
-
-
-void destroy_sample_buffer(sample_t **samples)
-{
-	if (samples) {
-		free(samples[0]);
-		free(samples);
-	}
-}
--- a/dumb/src/helpers/silence.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * silence.c - Silencing helper.                      / / \  \
- *                                                   | <  /   \_
- * By entheh.                                        |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <string.h>
-#include "dumb.h"
-
-
-
-void dumb_silence(sample_t *samples, long length)
-{
-	memset(samples, 0, length * sizeof(*samples));
-}
-
--- a/dumb/src/helpers/stdfile.c
+++ /dev/null
@@ -1,146 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * stdfile.c - stdio file input module.               / / \  \
- *                                                   | <  /   \_
- * By entheh.                                        |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdio.h>
-
-#include "dumb.h"
-
-
-
-typedef struct dumb_stdfile
-{
-    FILE * file;
-    long size;
-} dumb_stdfile;
-
-
-
-static void *dumb_stdfile_open(const char *filename)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) malloc( sizeof(dumb_stdfile) );
-    if ( !file ) return 0;
-    file->file = fopen(filename, "rb");
-    fseek(file->file, 0, SEEK_END);
-    file->size = ftell(file->file);
-    fseek(file->file, 0, SEEK_SET);
-    return file;
-}
-
-
-
-static int dumb_stdfile_skip(void *f, long n)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) f;
-    return fseek(file->file, n, SEEK_CUR);
-}
-
-
-
-static int dumb_stdfile_getc(void *f)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) f;
-    return fgetc(file->file);
-}
-
-
-
-static long dumb_stdfile_getnc(char *ptr, long n, void *f)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) f;
-    return fread(ptr, 1, n, file->file);
-}
-
-
-
-static void dumb_stdfile_close(void *f)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) f;
-    fclose(file->file);
-    free(f);
-}
-
-
-
-static void dumb_stdfile_noclose(void *f)
-{
-    free(f);
-}
-
-
-
-static int dumb_stdfile_seek(void *f, long n)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) f;
-    return fseek(file->file, n, SEEK_SET);
-}
-
-
-
-static long dumb_stdfile_get_size(void *f)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) f;
-    return file->size;
-}
-
-
-
-static const DUMBFILE_SYSTEM stdfile_dfs = {
-	&dumb_stdfile_open,
-	&dumb_stdfile_skip,
-	&dumb_stdfile_getc,
-	&dumb_stdfile_getnc,
-    &dumb_stdfile_close,
-    &dumb_stdfile_seek,
-    &dumb_stdfile_get_size
-};
-
-
-
-void dumb_register_stdfiles(void)
-{
-	register_dumbfile_system(&stdfile_dfs);
-}
-
-
-
-static const DUMBFILE_SYSTEM stdfile_dfs_leave_open = {
-	NULL,
-	&dumb_stdfile_skip,
-	&dumb_stdfile_getc,
-	&dumb_stdfile_getnc,
-    &dumb_stdfile_noclose,
-    &dumb_stdfile_seek,
-    &dumb_stdfile_get_size
-};
-
-
-
-DUMBFILE *dumbfile_open_stdfile(FILE *p)
-{
-    dumb_stdfile * file = ( dumb_stdfile * ) malloc( sizeof(dumb_stdfile) );
-	DUMBFILE *d;
-    if ( !file ) return 0;
-    file->file = p;
-    fseek(p, 0, SEEK_END);
-    file->size = ftell(p);
-    fseek(p, 0, SEEK_SET);
-    d = dumbfile_open_ex(file, &stdfile_dfs_leave_open);
-
-	return d;
-}
--- a/dumb/src/helpers/tarray.c
+++ /dev/null
@@ -1,175 +1,0 @@
-#include "internal/tarray.h"
-
-#include <string.h>
-
-	/*
-	   Structures which contain the play times of each pattern and row combination in the song,
-	   not guaranteed to be valid for the whole song until the loop status is no longer zero.
-	   The initial count and restart count will both be zero on song start, then both will be
-	   incremented until the song loops. Restart count will be reset to zero on loop for all
-	   rows which have a time equal to or greater than the loop start point, so time keeping
-	   functions will know which timestamp the song is currently located at.
-
-	   Timestamp lists are guaranteed to be allocated in blocks of 16 timestamps at a time.
-	*/
-
-	/*
-	   We don't need full timekeeping because the player loop only wants the first play time
-	   of the loop start order/row. We also don't really want full timekeeping because it
-	   involves a lot of memory allocations, which is also slow.
-	*/
-
-#undef FULL_TIMEKEEPING
-
-typedef struct DUMB_IT_ROW_TIME
-{
-	unsigned int count, restart_count;
-#ifndef FULL_TIMEKEEPING
-	LONG_LONG first_time;
-#else
-	LONG_LONG * times;
-#endif
-} DUMB_IT_ROW_TIME;
-
-void * timekeeping_array_create(size_t size)
-{
-	size_t * _size = (size_t *) calloc( 1, sizeof(size_t) + sizeof(DUMB_IT_ROW_TIME) * size );
-	if ( _size ) {
-		*_size = size;
-	}
-	return _size;
-}
-
-void timekeeping_array_destroy(void * array)
-{
-#ifdef FULL_TIMEKEEPING
-	size_t i;
-	size_t * size = (size_t *) array;
-	DUMB_IT_ROW_TIME * s = (DUMB_IT_ROW_TIME *)(size + 1);
-
-	for (i = 0; i < *size; i++) {
-		if (s[i].times) free(s[i].times);
-	}
-#endif
-
-    free(array);
-}
-
-void * timekeeping_array_dup(void * array)
-{
-	size_t i;
-	size_t * size = (size_t *) array;
-	DUMB_IT_ROW_TIME * s = (DUMB_IT_ROW_TIME *)(size + 1);
-	size_t * new_size = (size_t *) calloc( 1, sizeof(size_t) + sizeof(DUMB_IT_ROW_TIME) * *size );
-	if ( new_size ) {
-		DUMB_IT_ROW_TIME * new_s = (DUMB_IT_ROW_TIME *)(new_size + 1);
-
-		*new_size = *size;
-
-		for (i = 0; i < *size; i++) {
-			new_s[i].count = s[i].count;
-			new_s[i].restart_count = s[i].restart_count;
-
-#ifndef FULL_TIMEKEEPING
-			new_s[i].first_time = s[i].first_time;
-#else
-			if ( s[i].times ) {
-				size_t time_count = ( s[i].count + 15 ) & ~15;
-				new_s[i].times = (LONG_LONG *) malloc( sizeof(LONG_LONG) * time_count );
-				if ( new_s[i].times == (void *)0 ) {
-					timekeeping_array_destroy( new_size );
-					return (void *) 0;
-				}
-				memcpy( new_s[i].times, s[i].times, sizeof(LONG_LONG) * s[i].count );
-			}
-#endif
-		}
-	}
-
-	return new_size;
-}
-
-void timekeeping_array_reset(void * array, size_t loop_start)
-{
-	size_t i;
-	size_t * size = (size_t *) array;
-	DUMB_IT_ROW_TIME * s = (DUMB_IT_ROW_TIME *)(size + 1);
-
-	DUMB_IT_ROW_TIME * s_loop_start = s + loop_start;
-	LONG_LONG loop_start_time;
-
-	if ( loop_start >= *size || s_loop_start->count < 1 ) return;
-
-#ifndef FULL_TIMEKEEPING
-	loop_start_time = s_loop_start->first_time;
-#else
-	loop_start_time = s_loop_start->times[0];
-#endif
-
-	for ( i = 0; i < *size; i++ ) {
-#ifndef FULL_TIMEKEEPING
-		if ( s[i].count && s[i].first_time >= loop_start_time ) {
-#else
-		if ( s[i].count && s[i].times[0] >= loop_start_time ) {
-#endif
-			s[i].restart_count = 0;
-		}
-	}
-}
-
-void timekeeping_array_push(void * array, size_t index, LONG_LONG time)
-{
-#ifdef FULL_TIMEKEEPING
-	size_t i;
-    size_t time_count;
-#endif
-    size_t * size = (size_t *) array;
-	DUMB_IT_ROW_TIME * s = (DUMB_IT_ROW_TIME *)(size + 1);
-
-	if (index >= *size) return;
-
-#ifndef FULL_TIMEKEEPING
-	if ( !s[index].count++ )
-		s[index].first_time = time;
-#else
-	time_count = ( s[index].count + 16 ) & ~15;
-
-	s[index].times = (LONG_LONG *) realloc( s[index].times, sizeof(LONG_LONG) * time_count );
-
-	s[index].times[s[index].count++] = time;
-#endif
-}
-
-void timekeeping_array_bump(void * array, size_t index)
-{
-	size_t * size = (size_t *) array;
-	DUMB_IT_ROW_TIME * s = (DUMB_IT_ROW_TIME *)(size + 1);
-
-	if (index >= *size) return;
-
-	s[index].restart_count++;
-}
-
-unsigned int timekeeping_array_get_count(void * array, size_t index)
-{
-	size_t * size = (size_t *) array;
-	DUMB_IT_ROW_TIME * s = (DUMB_IT_ROW_TIME *)(size + 1);
-
-	if (index >= *size) return 0;
-
-	return s[index].count;
-}
-
-LONG_LONG timekeeping_array_get_item(void * array, size_t index)
-{
-	size_t * size = (size_t *) array;
-	DUMB_IT_ROW_TIME * s = (DUMB_IT_ROW_TIME *)(size + 1);
-
-	if (index >= *size || s[index].restart_count >= s[index].count) return 0;
-
-#ifndef FULL_TIMEKEEPING
-	return s[index].first_time;
-#else
-	return s[index].times[s[index].restart_count];
-#endif
-}
--- a/dumb/src/it/itload.c
+++ /dev/null
@@ -1,43 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itload.c - Code to read an Impulse Tracker         / / \  \
- *            file, opening and closing it for       | <  /   \_
- *            you.                                   |  \/ /\   /
- *                                                    \_  /  > /
- * By entheh. Don't worry Bob, you're credited          | \ / /
- * in itread.c!                                         |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_it_quick(): loads an IT file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must pass
- * the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_it_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_it_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
-
--- a/dumb/src/it/itload2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itload2.c - Function to read an Impulse Tracker    / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you, and do an initial run-through.   |  \/ /\   /
- *                                                    \_  /  > /
- * Split off from itload.c by entheh.                   | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_it(const char *filename)
-{
-	DUH *duh = dumb_load_it_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/itmisc.c
+++ /dev/null
@@ -1,249 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itmisc.c - Miscellaneous functions relating        / / \  \
- *            to module files.                       | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-int dumb_it_default_panning_separation = 25;
-
-
-DUMB_IT_SIGDATA *duh_get_it_sigdata(DUH *duh)
-{
-	return duh_get_raw_sigdata(duh, -1, SIGTYPE_IT);
-}
-
-
-
-const unsigned char *dumb_it_sd_get_song_message(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->song_message : NULL;
-}
-
-
-
-int dumb_it_sd_get_n_orders(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->n_orders : 0;
-}
-
-
-
-int dumb_it_sd_get_n_samples(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->n_samples : 0;
-}
-
-
-
-int dumb_it_sd_get_n_instruments(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->n_instruments : 0;
-}
-
-
-
-const unsigned char *dumb_it_sd_get_sample_name(DUMB_IT_SIGDATA *sd, int i)
-{
-	ASSERT(sd && sd->sample && i >= 0 && i < sd->n_samples);
-	return sd->sample[i].name;
-}
-
-
-
-const unsigned char *dumb_it_sd_get_sample_filename(DUMB_IT_SIGDATA *sd, int i)
-{
-	ASSERT(sd && sd->sample && i >= 0 && i < sd->n_samples);
-	return sd->sample[i].filename;
-}
-
-
-
-const unsigned char *dumb_it_sd_get_instrument_name(DUMB_IT_SIGDATA *sd, int i)
-{
-	ASSERT(sd && sd->instrument && i >= 0 && i < sd->n_instruments);
-	return sd->instrument[i].name;
-}
-
-
-
-const unsigned char *dumb_it_sd_get_instrument_filename(DUMB_IT_SIGDATA *sd, int i)
-{
-	ASSERT(sd && sd->instrument && i >= 0 && i < sd->n_instruments);
-	return sd->instrument[i].filename;
-}
-
-
-
-int dumb_it_sd_get_initial_global_volume(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->global_volume : 0;
-}
-
-
-
-void dumb_it_sd_set_initial_global_volume(DUMB_IT_SIGDATA *sd, int gv)
-{
-	if (sd) sd->global_volume = gv;
-}
-
-
-
-int dumb_it_sd_get_mixing_volume(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->mixing_volume : 0;
-}
-
-
-
-void dumb_it_sd_set_mixing_volume(DUMB_IT_SIGDATA *sd, int mv)
-{
-	if (sd) sd->mixing_volume = mv;
-}
-
-
-
-int dumb_it_sd_get_initial_speed(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->speed : 0;
-}
-
-
-
-void dumb_it_sd_set_initial_speed(DUMB_IT_SIGDATA *sd, int speed)
-{
-	if (sd) sd->speed = speed;
-}
-
-
-
-int dumb_it_sd_get_initial_tempo(DUMB_IT_SIGDATA *sd)
-{
-	return sd ? sd->tempo : 0;
-}
-
-
-
-void dumb_it_sd_set_initial_tempo(DUMB_IT_SIGDATA *sd, int tempo)
-{
-	if (sd) sd->tempo = tempo;
-}
-
-
-
-int dumb_it_sd_get_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel)
-{
-	ASSERT(channel >= 0 && channel < DUMB_IT_N_CHANNELS);
-	return sd ? sd->channel_volume[channel] : 0;
-}
-
-void dumb_it_sd_set_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel, int volume)
-{
-	ASSERT(channel >= 0 && channel < DUMB_IT_N_CHANNELS);
-	if (sd) sd->channel_volume[channel] = volume;
-}
-
-
-
-int dumb_it_sr_get_current_order(DUMB_IT_SIGRENDERER *sr)
-{
-	return sr ? sr->order : -1;
-}
-
-
-
-int dumb_it_sr_get_current_row(DUMB_IT_SIGRENDERER *sr)
-{
-	return sr ? sr->row : -1;
-}
-
-
-
-int dumb_it_sr_get_global_volume(DUMB_IT_SIGRENDERER *sr)
-{
-	return sr ? sr->globalvolume : 0;
-}
-
-
-
-void dumb_it_sr_set_global_volume(DUMB_IT_SIGRENDERER *sr, int gv)
-{
-	if (sr) sr->globalvolume = gv;
-}
-
-
-
-int dumb_it_sr_get_tempo(DUMB_IT_SIGRENDERER *sr)
-{
-	return sr ? sr->tempo : 0;
-}
-
-
-
-void dumb_it_sr_set_tempo(DUMB_IT_SIGRENDERER *sr, int tempo)
-{
-	if (sr) sr->tempo = tempo;
-}
-
-
-
-int dumb_it_sr_get_speed(DUMB_IT_SIGRENDERER *sr)
-{
-	return sr ? sr->speed : 0;
-}
-
-
-
-void dumb_it_sr_set_speed(DUMB_IT_SIGRENDERER *sr, int speed)
-{
-	if (sr) sr->speed = speed;
-}
-
-
-
-int dumb_it_sr_get_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel)
-{
-	return sr ? sr->channel[channel].channelvolume : 0;
-}
-
-
-
-void dumb_it_sr_set_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel, int volume)
-{
-	if (sr) sr->channel[channel].channelvolume = volume;
-}
-
-
-
-void dumb_it_sr_set_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel, int muted)
-{
-	if (sr) {
-		if (muted)
-			sr->channel[channel].flags |= IT_CHANNEL_MUTED;
-		else
-			sr->channel[channel].flags &= ~IT_CHANNEL_MUTED;
-	}
-}
-
-
-
-int dumb_it_sr_get_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel)
-{
-	return sr ? (sr->channel[channel].flags & IT_CHANNEL_MUTED) != 0 : 0;
-}
--- a/dumb/src/it/itorder.c
+++ /dev/null
@@ -1,63 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itorder.c - Code to fix invalid patterns in        / / \  \
- *             the pattern table.                    | <  /   \_
- *                                                   |  \/ /\   /
- * By Julien Cugniere.                                \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* This function ensures that any pattern mentioned in the order table but
- * not present in the pattern table is treated as an empty 64 rows pattern.
- * This is done by adding such a dummy pattern at the end of the pattern
- * table, and redirect invalid orders to it.
- * Patterns 254 and 255 are left untouched, unless the signal is an XM.
- */
-int _dumb_it_fix_invalid_orders(DUMB_IT_SIGDATA *sigdata)
-{
-	int i;
-	int found_some = 0;
-
-	int first_invalid = sigdata->n_patterns;
-	int last_invalid = (sigdata->flags & IT_WAS_AN_XM) ? 255 : 253;
-
-	for (i = 0; i < sigdata->n_orders; i++) {
-		if (sigdata->order[i] >= first_invalid && sigdata->order[i] <= last_invalid) {
-			sigdata->order[i] = sigdata->n_patterns;
-			found_some = 1;
-		}
-	}
-
-	if (found_some) {
-		IT_PATTERN *new_pattern = realloc(sigdata->pattern, sizeof(*sigdata->pattern) * (sigdata->n_patterns + 1));
-		if (!new_pattern)
-			return -1;
-		
-		new_pattern[sigdata->n_patterns].n_rows = 64;
-		new_pattern[sigdata->n_patterns].n_entries = 0;
-		new_pattern[sigdata->n_patterns].entry = NULL;
-		sigdata->pattern = new_pattern;
-		sigdata->n_patterns++;
-	}
-
-	return 0;
-}
--- a/dumb/src/it/itread.c
+++ /dev/null
@@ -1,1416 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itread.c - Code to read an Impulse Tracker         / / \  \
- *            module from an open file.              | <  /   \_
- *                                                   |  \/ /\   /
- * Based on the loader from an IT player by Bob.      \_  /  > /
- * Adapted for DUMB by entheh.                          | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>//might not be necessary later; required for memset
-
-#include "dumb.h"
-#include "internal/it.h"
-
-#ifndef min
-#define min(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
-
-#define INVESTIGATE_OLD_INSTRUMENTS
-
-
-
-typedef unsigned char byte;
-typedef unsigned short word;
-typedef unsigned long dword;
-
-typedef struct readblock_crap readblock_crap;
-
-struct readblock_crap {
-	unsigned char *sourcebuf;
-	unsigned char *sourcepos;
-	unsigned char *sourceend;
-	int rembits;
-};
-
-
-static int readblock(DUMBFILE *f, readblock_crap * crap)
-{
-	long size;
-	int c;
-
-	size = dumbfile_igetw(f);
-	if (size < 0)
-		return (int)size;
-
-	crap->sourcebuf = malloc(size);
-	if (!crap->sourcebuf)
-		return -1;
-
-	c = (int)dumbfile_getnc((char *)crap->sourcebuf, size, f);
-	if (c < size) {
-		free(crap->sourcebuf);
-		crap->sourcebuf = NULL;
-		return -1;
-	}
-
-	crap->sourcepos = crap->sourcebuf;
-	crap->sourceend = crap->sourcebuf + size;
-	crap->rembits = 8;
-	return 0;
-}
-
-
-
-static void freeblock(readblock_crap * crap)
-{
-	free(crap->sourcebuf);
-	crap->sourcebuf = NULL;
-}
-
-
-
-static int readbits(int bitwidth, readblock_crap * crap)
-{
-	int val = 0;
-	int b = 0;
-
-	if (crap->sourcepos >= crap->sourceend) return val;
-
-	while (bitwidth > crap->rembits) {
-		val |= *crap->sourcepos++ << b;
-		if (crap->sourcepos >= crap->sourceend) return val;
-		b += crap->rembits;
-		bitwidth -= crap->rembits;
-		crap->rembits = 8;
-	}
-
-	val |= (*crap->sourcepos & ((1 << bitwidth) - 1)) << b;
-	*crap->sourcepos >>= bitwidth;
-	crap->rembits -= bitwidth;
-
-	return val;
-}
-
-
-
-/** WARNING - do we even need to pass `right`? */
-/** WARNING - why bother memsetting at all? The whole array is written... */
-// if we do memset, dumb_silence() would be neater...
-static int decompress8(DUMBFILE *f, signed char *data, int len, int it215, int stereo)
-{
-	int blocklen, blockpos;
-	byte bitwidth;
-	word val;
-	signed char d1, d2;
-	readblock_crap crap;
-
-	memset(&crap, 0, sizeof(crap));
-
-	for (blocklen = 0, blockpos = 0; blocklen < len; blocklen++, blockpos += 1 + stereo)
-		data[ blockpos ] = 0;
-
-	while (len > 0) {
-		//Read a block of compressed data:
-		if (readblock(f, &crap))
-			return -1;
-		//Set up a few variables
-		blocklen = (len < 0x8000) ? len : 0x8000; //Max block length is 0x8000 bytes
-		blockpos = 0;
-		bitwidth = 9;
-		d1 = d2 = 0;
-		//Start the decompression:
-		while (blockpos < blocklen) {
-			//Read a value:
-			val = (word)readbits(bitwidth, &crap);
-			//Check for bit width change:
-
-			if (bitwidth < 7) { //Method 1:
-				if (val == (1 << (bitwidth - 1))) {
-					val = (word)readbits(3, &crap) + 1;
-					bitwidth = (val < bitwidth) ? val : val + 1;
-					continue;
-				}
-			}
-			else if (bitwidth < 9) { //Method 2
-				byte border = (0xFF >> (9 - bitwidth)) - 4;
-
-				if (val > border && val <= (border + 8)) {
-					val -= border;
-					bitwidth = (val < bitwidth) ? val : val + 1;
-					continue;
-				}
-			}
-			else if (bitwidth == 9) { //Method 3
-				if (val & 0x100) {
-					bitwidth = (val + 1) & 0xFF;
-					continue;
-				}
-			}
-			else { //Illegal width, abort ?
-				freeblock(&crap);
-				return -1;
-			}
-
-			//Expand the value to signed byte:
-			{
-				signed char v; //The sample value:
-				if (bitwidth < 8) {
-					byte shift = 8 - bitwidth;
-					v = (val << shift);
-					v >>= shift;
-				}
-				else
-					v = (signed char)val;
-
-				//And integrate the sample value
-				//(It always has to end with integration doesn't it ? ;-)
-				d1 += v;
-				d2 += d1;
-			}
-
-			//Store !
-			/* Version 2.15 was an unofficial version with hacked compression
-			 * code. Yay, better compression :D
-			 */
-			*data++ = it215 ? d2 : d1;
-			data += stereo;
-			len--;
-			blockpos++;
-		}
-		freeblock(&crap);
-	}
-	return 0;
-}
-
-
-
-static int decompress16(DUMBFILE *f, short *data, int len, int it215, int stereo)
-{
-	int blocklen, blockpos;
-	byte bitwidth;
-	long val;
-	signed short d1, d2;
-	readblock_crap crap;
-
-	memset(&crap, 0, sizeof(crap));
-
-	for ( blocklen = 0, blockpos = 0; blocklen < len; blocklen++, blockpos += 1 + stereo )
-		data[ blockpos ] = 0;
-
-	while (len > 0) {
-		//Read a block of compressed data:
-		if (readblock(f, &crap))
-			return -1;
-		//Set up a few variables
-		blocklen = (len < 0x4000) ? len : 0x4000; // Max block length is 0x4000 bytes
-		blockpos = 0;
-		bitwidth = 17;
-		d1 = d2 = 0;
-		//Start the decompression:
-		while (blockpos < blocklen) {
-			val = readbits(bitwidth, &crap);
-			//Check for bit width change:
-
-			if (bitwidth < 7) { //Method 1:
-				if (val == (1 << (bitwidth - 1))) {
-					val = readbits(4, &crap) + 1;
-					bitwidth = (val < bitwidth) ? val : val + 1;
-					continue;
-				}
-			}
-			else if (bitwidth < 17) { //Method 2
-				word border = (0xFFFF >> (17 - bitwidth)) - 8;
-
-				if (val > border && val <= (border + 16)) {
-					val -= border;
-					bitwidth = val < bitwidth ? val : val + 1;
-					continue;
-				}
-			}
-			else if (bitwidth == 17) { //Method 3
-				if (val & 0x10000) {
-					bitwidth = (val + 1) & 0xFF;
-					continue;
-				}
-			}
-			else { //Illegal width, abort ?
-				freeblock(&crap);
-				return -1;
-			}
-
-			//Expand the value to signed byte:
-			{
-				short v; //The sample value:
-				if (bitwidth < 16) {
-					byte shift = 16 - bitwidth;
-					v = (short)(val << shift);
-					v >>= shift;
-				}
-				else
-					v = (short)val;
-
-				//And integrate the sample value
-				//(It always has to end with integration doesn't it ? ;-)
-				d1 += v;
-				d2 += d1;
-			}
-
-			//Store !
-			/* Version 2.15 was an unofficial version with hacked compression
-			 * code. Yay, better compression :D
-			 */
-			*data++ = it215 ? d2 : d1;
-			data += stereo;
-			len--;
-			blockpos++;
-		}
-		freeblock(&crap);
-	}
-	return 0;
-}
-
-
-
-static int it_read_envelope(IT_ENVELOPE *envelope, DUMBFILE *f)
-{
-	int n;
-
-	envelope->flags = dumbfile_getc(f);
-	envelope->n_nodes = dumbfile_getc(f);
-	if(envelope->n_nodes > 25) {
-		TRACE("IT error: wrong number of envelope nodes (%d)\n", envelope->n_nodes);
-		envelope->n_nodes = 0;
-		return -1;
-	}
-	envelope->loop_start = dumbfile_getc(f);
-	envelope->loop_end = dumbfile_getc(f);
-	envelope->sus_loop_start = dumbfile_getc(f);
-	envelope->sus_loop_end = dumbfile_getc(f);
-	for (n = 0; n < envelope->n_nodes; n++) {
-		envelope->node_y[n] = dumbfile_getc(f);
-		envelope->node_t[n] = dumbfile_igetw(f);
-	}
-	dumbfile_skip(f, 75 - envelope->n_nodes * 3 + 1);
-
-	if (envelope->n_nodes <= 0)
-		envelope->flags &= ~IT_ENVELOPE_ON;
-	else {
-		if (envelope->loop_end >= envelope->n_nodes || envelope->loop_start > envelope->loop_end) envelope->flags &= ~IT_ENVELOPE_LOOP_ON;
-		if (envelope->sus_loop_end >= envelope->n_nodes || envelope->sus_loop_start > envelope->sus_loop_end) envelope->flags &= ~IT_ENVELOPE_SUSTAIN_LOOP;
-	}
-
-	return dumbfile_error(f);
-}
-
-
-
-static int it_read_old_instrument(IT_INSTRUMENT *instrument, DUMBFILE *f)
-{
-	int n;
-
-	/*if (dumbfile_mgetl(f) != IT_INSTRUMENT_SIGNATURE)
-		return -1;*/
-	// XXX
-	dumbfile_skip(f, 4);
-
-    dumbfile_getnc((char *)instrument->filename, 13, f);
-	instrument->filename[13] = 0;
-
-	instrument->volume_envelope.flags = dumbfile_getc(f);
-	instrument->volume_envelope.loop_start = dumbfile_getc(f);
-	instrument->volume_envelope.loop_end = dumbfile_getc(f);
-	instrument->volume_envelope.sus_loop_start = dumbfile_getc(f);
-	instrument->volume_envelope.sus_loop_end = dumbfile_getc(f);
-
-	/* Skip two unused bytes. */
-	dumbfile_skip(f, 2);
-
-	/* In the old instrument format, fadeout ranges from 0 to 64, and is
-	 * subtracted at intervals from a value starting at 512. In the new
-	 * format, all these values are doubled. Therefore we double when loading
-	 * from the old instrument format - that way we don't have to think about
-	 * it later.
-	 */
-	instrument->fadeout = dumbfile_igetw(f) << 1;
-	instrument->new_note_action = dumbfile_getc(f);
-	instrument->dup_check_type = dumbfile_getc(f);
-	instrument->dup_check_action = DCA_NOTE_CUT; // This might be wrong!
-	/** WARNING - what is the duplicate check action for old-style instruments? */
-
-	/* Skip Tracker Version and Number of Samples. These are only used in
-	 * separate instrument files. Also skip unused byte.
-	 */
-	dumbfile_skip(f, 4);
-
-    dumbfile_getnc((char *)instrument->name, 26, f);
-	instrument->name[26] = 0;
-
-	/* Skip unused bytes following the Instrument Name. */
-	dumbfile_skip(f, 6);
-
-	instrument->pp_separation = 0;
-	instrument->pp_centre = 60;
-	instrument->global_volume = 128;
-	/** WARNING - should global_volume be 64 or something? */
-	instrument->default_pan = 32;
-	/** WARNING - should default_pan be 128, meaning don`t use? */
-	instrument->random_volume = 0;
-	instrument->random_pan = 0;
-
-	for (n = 0; n < 120; n++) {
-		instrument->map_note[n] = dumbfile_getc(f);
-		instrument->map_sample[n] = dumbfile_getc(f);
-	}
-
-	/* Skip "Volume envelope (200 bytes)". */
-	// - need to know better what this is for though.
-	dumbfile_skip(f, 200);
-
-#ifdef INVESTIGATE_OLD_INSTRUMENTS
-	fprintf(stderr, "Inst %02d Env:", n);
-#endif
-
-	for (n = 0; n < 25; n++)
-	{
-		instrument->volume_envelope.node_t[n] = dumbfile_getc(f);
-		instrument->volume_envelope.node_y[n] = dumbfile_getc(f);
-
-#ifdef INVESTIGATE_OLD_INSTRUMENTS
-		fprintf(stderr, " %d,%d",
-				instrument->volume_envelope.node_t[n],
-				instrument->volume_envelope.node_y[n]);
-#endif
-
-		// This loop is unfinished, as we can probably escape from it before
-		// the end if we want to. Hence the otherwise useless dumbfile_skip()
-		// call below.
-	}
-	dumbfile_skip(f, 50 - (n << 1));
-	instrument->volume_envelope.n_nodes = n;
-
-#ifdef INVESTIGATE_OLD_INSTRUMENTS
-	fprintf(stderr, "\n");
-#endif
-
-	if (dumbfile_error(f))
-		return -1;
-
-	{
-		IT_ENVELOPE *envelope = &instrument->volume_envelope;
-		if (envelope->n_nodes <= 0)
-			envelope->flags &= ~IT_ENVELOPE_ON;
-		else {
-			if (envelope->loop_end >= envelope->n_nodes || envelope->loop_start > envelope->loop_end) envelope->flags &= ~IT_ENVELOPE_LOOP_ON;
-			if (envelope->sus_loop_end >= envelope->n_nodes || envelope->sus_loop_start > envelope->sus_loop_end) envelope->flags &= ~IT_ENVELOPE_SUSTAIN_LOOP;
-		}
-	}
-
-	instrument->filter_cutoff = 127;
-	instrument->filter_resonance = 0;
-
-	instrument->pan_envelope.flags = 0;
-	instrument->pitch_envelope.flags = 0;
-
-	return 0;
-}
-
-
-
-static int it_read_instrument(IT_INSTRUMENT *instrument, DUMBFILE *f, int maxlen)
-{
-    int n;
-    long len;
-
-	/*if (dumbfile_mgetl(f) != IT_INSTRUMENT_SIGNATURE)
-		return -1;*/
-	// XXX
-
-	if (maxlen) len = dumbfile_pos(f);
-    else len = 0;
-
-	dumbfile_skip(f, 4);
-
-    dumbfile_getnc((char *)instrument->filename, 13, f);
-	instrument->filename[13] = 0;
-
-	instrument->new_note_action = dumbfile_getc(f);
-	instrument->dup_check_type = dumbfile_getc(f);
-	instrument->dup_check_action = dumbfile_getc(f);
-	instrument->fadeout = dumbfile_igetw(f);
-	instrument->pp_separation = dumbfile_getc(f);
-	instrument->pp_centre = dumbfile_getc(f);
-	instrument->global_volume = dumbfile_getc(f);
-	instrument->default_pan = dumbfile_getc(f);
-	instrument->random_volume = dumbfile_getc(f);
-	instrument->random_pan = dumbfile_getc(f);
-
-	/* Skip Tracker Version and Number of Samples. These are only used in
-	 * separate instrument files. Also skip unused byte.
-	 */
-	dumbfile_skip(f, 4);
-
-    dumbfile_getnc((char *)instrument->name, 26, f);
-	instrument->name[26] = 0;
-
-	instrument->filter_cutoff = dumbfile_getc(f);
-	instrument->filter_resonance = dumbfile_getc(f);
-
-	/* Skip MIDI Channel, Program and Bank. */
-	//dumbfile_skip(f, 4);
-	/*instrument->output = dumbfile_getc(f);
-	if ( instrument->output > 16 ) {
-		instrument->output -= 128;
-	} else {
-		instrument->output = 0;
-	}
-	dumbfile_skip(f, 3);*/
-	dumbfile_skip(f, 4);
-
-	for (n = 0; n < 120; n++) {
-		instrument->map_note[n] = dumbfile_getc(f);
-		instrument->map_sample[n] = dumbfile_getc(f);
-	}
-
-	if (dumbfile_error(f))
-		return -1;
-
-	if (it_read_envelope(&instrument->volume_envelope, f)) return -1;
-	if (it_read_envelope(&instrument->pan_envelope, f)) return -1;
-	if (it_read_envelope(&instrument->pitch_envelope, f)) return -1;
-
-	if (maxlen) {
-		len = dumbfile_pos(f) - len;
-		if ( maxlen - len < 124 ) return 0;
-	}
-
-	if ( dumbfile_mgetl(f) == IT_MPTX_SIGNATURE ) {
-		for ( n = 0; n < 120; n++ ) {
-			instrument->map_sample[ n ] += dumbfile_getc( f ) << 8;
-		}
-
-		if (dumbfile_error(f))
-			return -1;
-	}
-
-	/*if ( dumbfile_mgetl(f) == IT_INSM_SIGNATURE ) {
-		long end = dumbfile_igetl(f);
-		end += dumbfile_pos(f);
-		while ( dumbfile_pos(f) < end ) {
-			int chunkid = dumbfile_igetl(f);
-			switch ( chunkid ) {
-				case DUMB_ID('P','L','U','G'):
-					instrument->output = dumbfile_getc(f);
-					break;
-				default:
-					chunkid = chunkid / 0x100 + dumbfile_getc(f) * 0x1000000;
-					break;
-			}
-		}
-
-		if (dumbfile_error(f))
-			return -1;
-	}*/
-
-	return 0;
-}
-
-
-
-static int it_read_sample_header(IT_SAMPLE *sample, unsigned char *convert, long *offset, DUMBFILE *f)
-{
-	/* XXX
-	if (dumbfile_mgetl(f) != IT_SAMPLE_SIGNATURE)
-		return -1;*/
-	int hax = 0;
-	long s = dumbfile_mgetl(f);
-	if (s != IT_SAMPLE_SIGNATURE) {
-		if ( s == ( IT_SAMPLE_SIGNATURE >> 16 ) ) {
-			s <<= 16;
-			s |= dumbfile_mgetw(f);
-			if ( s != IT_SAMPLE_SIGNATURE )
-				return -1;
-			hax = 1;
-		}
-	}
-
-    dumbfile_getnc((char *)sample->filename, 13, f);
-	sample->filename[13] = 0;
-
-	sample->global_volume = dumbfile_getc(f);
-	sample->flags = dumbfile_getc(f);
-	sample->default_volume = dumbfile_getc(f);
-
-    dumbfile_getnc((char *)sample->name, 26, f);
-	sample->name[26] = 0;
-
-	*convert = dumbfile_getc(f);
-	sample->default_pan = dumbfile_getc(f);
-	sample->length = dumbfile_igetl(f);
-	sample->loop_start = dumbfile_igetl(f);
-	sample->loop_end = dumbfile_igetl(f);
-	sample->C5_speed = dumbfile_igetl(f);
-	sample->sus_loop_start = dumbfile_igetl(f);
-	sample->sus_loop_end = dumbfile_igetl(f);
-
-#ifdef STEREO_SAMPLES_COUNT_AS_TWO
-	if (sample->flags & IT_SAMPLE_STEREO) {
-		sample->length >>= 1;
-		sample->loop_start >>= 1;
-		sample->loop_end >>= 1;
-		sample->C5_speed >>= 1;
-		sample->sus_loop_start >>= 1;
-		sample->sus_loop_end >>= 1;
-	}
-#endif
-
-	if (sample->flags & IT_SAMPLE_EXISTS) {
-		if (sample->length <= 0)
-			sample->flags &= ~IT_SAMPLE_EXISTS;
-		else {
-			if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
-				sample->flags &= ~IT_SAMPLE_LOOP;
-			else if ((unsigned int)sample->loop_start >= (unsigned int)sample->loop_end)
-				sample->flags &= ~IT_SAMPLE_LOOP;
-
-			if ((unsigned int)sample->sus_loop_end > (unsigned int)sample->length)
-				sample->flags &= ~IT_SAMPLE_SUS_LOOP;
-			else if ((unsigned int)sample->sus_loop_start >= (unsigned int)sample->sus_loop_end)
-				sample->flags &= ~IT_SAMPLE_SUS_LOOP;
-
-			/* We may be able to truncate the sample to save memory. */
-			if (sample->flags & IT_SAMPLE_LOOP &&
-				*convert != 0xFF) { /* not truncating compressed samples, for now... */
-				if ((sample->flags & IT_SAMPLE_SUS_LOOP) && sample->sus_loop_end >= sample->loop_end)
-					sample->length = sample->sus_loop_end;
-				else
-					sample->length = sample->loop_end;
-			}
-		}
-	}
-
-	*offset = dumbfile_igetl(f);
-
-	sample->vibrato_speed = dumbfile_getc(f);
-	sample->vibrato_depth = dumbfile_getc(f);
-	if ( ! hax ) {
-		sample->vibrato_rate = dumbfile_getc(f);
-		sample->vibrato_waveform = dumbfile_getc(f);
-	} else {
-		sample->vibrato_rate = 0;
-		sample->vibrato_waveform = 0;
-	}
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-long _dumb_it_read_sample_data_adpcm4(IT_SAMPLE *sample, DUMBFILE *f)
-{
-	long n, len, delta;
-	signed char * ptr, * end;
-	signed char compression_table[16];
-    if (dumbfile_getnc((char *)compression_table, 16, f) != 16)
-        return -1;
-	ptr = (signed char *) sample->data;
-	delta = 0;
-
-	end = ptr + sample->length;
-	len = (sample->length + 1) / 2;
-	for (n = 0; n < len; n++) {
-		int b = dumbfile_getc(f);
-		if (b < 0) return -1;
-		delta += compression_table[b & 0x0F];
-		*ptr++ = delta;
-		if (ptr >= end) break;
-		delta += compression_table[b >> 4];
-		*ptr++ = delta;
-	}
-
-	return 0;
-}
-
-
-static long it_read_sample_data(IT_SAMPLE *sample, unsigned char convert, DUMBFILE *f)
-{
-	long n;
-
-	long datasize = sample->length;
-	if (sample->flags & IT_SAMPLE_STEREO) datasize <<= 1;
-
-	sample->data = malloc(datasize * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
-	if (!sample->data)
-		return -1;
-
-	if (!(sample->flags & IT_SAMPLE_16BIT) && (convert == 0xFF)) {
-		if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
-			return -1;
-	} else if (sample->flags & 8) {
-		/* If the sample is packed, then we must unpack it. */
-
-		/* Behavior as defined by greasemonkey's munch.py and observed by XMPlay and OpenMPT */
-
-		if (sample->flags & IT_SAMPLE_STEREO) {
-			if (sample->flags & IT_SAMPLE_16BIT) {
-				decompress16(f, (short *) sample->data, (int)(datasize >> 1), convert & 4, 1);
-				decompress16(f, (short *) sample->data + 1, (int)(datasize >> 1), convert & 4, 1);
-			} else {
-				decompress8(f, (signed char *) sample->data, (int)(datasize >> 1), convert & 4, 1);
-				decompress8(f, (signed char *) sample->data + 1, (int)(datasize >> 1), convert & 4, 1);
-			}
-		} else {
-			if (sample->flags & IT_SAMPLE_16BIT)
-				decompress16(f, (short *) sample->data, (int)datasize, convert & 4, 0);
-			else
-				decompress8(f, (signed char *) sample->data, (int)datasize, convert & 4, 0);
-		}
- 	} else if (sample->flags & IT_SAMPLE_16BIT) {
-		if (sample->flags & IT_SAMPLE_STEREO) {
-			if (convert & 2) {
-				for (n = 0; n < datasize; n += 2)
-					((short *)sample->data)[n] = dumbfile_mgetw(f);
-				for (n = 1; n < datasize; n += 2)
-					((short *)sample->data)[n] = dumbfile_mgetw(f);
-			} else {
-				for (n = 0; n < datasize; n += 2)
-					((short *)sample->data)[n] = dumbfile_igetw(f);
-				for (n = 1; n < datasize; n += 2)
-					((short *)sample->data)[n] = dumbfile_igetw(f);
-			}
-		} else {
- 			if (convert & 2)
-				for (n = 0; n < datasize; n++)
-					((short *)sample->data)[n] = dumbfile_mgetw(f);
-			else
-				for (n = 0; n < datasize; n++)
-					((short *)sample->data)[n] = dumbfile_igetw(f);
-		}
- 	} else {
-		if (sample->flags & IT_SAMPLE_STEREO) {
-			for (n = 0; n < datasize; n += 2)
-				((signed char *)sample->data)[n] = dumbfile_getc(f);
-			for (n = 1; n < datasize; n += 2)
-				((signed char *)sample->data)[n] = dumbfile_getc(f);
-		} else
-			for (n = 0; n < datasize; n++)
-				((signed char *)sample->data)[n] = dumbfile_getc(f);
-	}
-
-	if (dumbfile_error(f))
-		return -1;
-
-	if (!(convert & 1)) {
-		/* Convert to signed. */
-		if (sample->flags & IT_SAMPLE_16BIT)
-			for (n = 0; n < datasize; n++)
-				((short *)sample->data)[n] ^= 0x8000;
-		else
-			for (n = 0; n < datasize; n++)
-				((signed char *)sample->data)[n] ^= 0x80;
-	}
-
-	/* NOT SUPPORTED:
-	 *
-	 * convert &  4 - Samples stored as delta values
-	 * convert & 16 - Samples stored as TX-Wave 12-bit values
-	 * convert & 32 - Left/Right/All Stereo prompt
-	 */
-
-	return 0;
-}
-
-
-
-//#define DETECT_DUPLICATE_CHANNELS
-#ifdef DETECT_DUPLICATE_CHANNELS
-#include <stdio.h>
-#endif
-static int it_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, unsigned char *buffer)
-{
-	unsigned char cmask[DUMB_IT_N_CHANNELS];
-	unsigned char cnote[DUMB_IT_N_CHANNELS];
-	unsigned char cinstrument[DUMB_IT_N_CHANNELS];
-	unsigned char cvolpan[DUMB_IT_N_CHANNELS];
-	unsigned char ceffect[DUMB_IT_N_CHANNELS];
-	unsigned char ceffectvalue[DUMB_IT_N_CHANNELS];
-#ifdef DETECT_DUPLICATE_CHANNELS
-	IT_ENTRY *dupentry[DUMB_IT_N_CHANNELS];
-#endif
-
-	int n_entries = 0;
-	int buflen;
-	int bufpos = 0;
-
-	IT_ENTRY *entry;
-
-	unsigned char channel;
-	unsigned char mask;
-
-	memset(cmask, 0, sizeof(cmask));
-	memset(cnote, 0, sizeof(cnote));
-	memset(cinstrument, 0, sizeof(cinstrument));
-	memset(cvolpan, 0, sizeof(cvolpan));
-	memset(ceffect, 0, sizeof(ceffect));
-	memset(ceffectvalue, 0, sizeof(ceffectvalue));
-#ifdef DETECT_DUPLICATE_CHANNELS
-	{
-		int i;
-		for (i = 0; i < DUMB_IT_N_CHANNELS; i++) dupentry[i] = NULL;
-	}
-#endif
-
-	buflen = dumbfile_igetw(f);
-	pattern->n_rows = dumbfile_igetw(f);
-
-	/* Skip four unused bytes. */
-	dumbfile_skip(f, 4);
-
-	if (dumbfile_error(f))
-		return -1;
-
-	/* Read in the pattern data. */
-    dumbfile_getnc((char *)buffer, buflen, f);
-
-	if (dumbfile_error(f))
-		return -1;
-
-	/* Scan the pattern data, and work out how many entries we need room for. */
-	while (bufpos < buflen) {
-		unsigned char b = buffer[bufpos++];
-
-		if (b == 0) {
-			/* End of row */
-			n_entries++;
-			continue;
-		}
-
-		channel = (b - 1) & 63;
-
-		if (b & 128)
-			cmask[channel] = mask = buffer[bufpos++];
-		else
-			mask = cmask[channel];
-
-		{
-			static const unsigned char used[16] = {0, 1, 1, 2, 1, 2, 2, 3, 2, 3, 3, 4, 3, 4, 4, 5};
-			n_entries += (mask != 0);
-			bufpos += used[mask & 15];
-		}
-	}
-
-	pattern->n_entries = n_entries;
-
-	pattern->entry = malloc(n_entries * sizeof(*pattern->entry));
-
-	if (!pattern->entry)
-		return -1;
-
-	bufpos = 0;
-	memset(cmask, 0, sizeof(cmask));
-
-	entry = pattern->entry;
-
-	while (bufpos < buflen) {
-		unsigned char b = buffer[bufpos++];
-
-		if (b == 0) {
-			/* End of row */
-			IT_SET_END_ROW(entry);
-			entry++;
-#ifdef DETECT_DUPLICATE_CHANNELS
-			{
-				int i;
-				for (i = 0; i < DUMB_IT_N_CHANNELS; i++) dupentry[i] = NULL;
-			}
-#endif
-			continue;
-		}
-
-		channel = (b - 1) & 63;
-
-		if (b & 128)
-			cmask[channel] = mask = buffer[bufpos++];
-		else
-			mask = cmask[channel];
-
-		if (mask) {
-			entry->mask = (mask & 15) | (mask >> 4);
-			entry->channel = channel;
-
-			if (mask & IT_ENTRY_NOTE)
-				cnote[channel] = entry->note = buffer[bufpos++];
-			else if (mask & (IT_ENTRY_NOTE << 4))
-				entry->note = cnote[channel];
-
-			if (mask & IT_ENTRY_INSTRUMENT)
-				cinstrument[channel] = entry->instrument = buffer[bufpos++];
-			else if (mask & (IT_ENTRY_INSTRUMENT << 4))
-				entry->instrument = cinstrument[channel];
-
-			if (mask & IT_ENTRY_VOLPAN)
-				cvolpan[channel] = entry->volpan = buffer[bufpos++];
-			else if (mask & (IT_ENTRY_VOLPAN << 4))
-				entry->volpan = cvolpan[channel];
-
-			if (mask & IT_ENTRY_EFFECT) {
-				ceffect[channel] = entry->effect = buffer[bufpos++];
-				ceffectvalue[channel] = entry->effectvalue = buffer[bufpos++];
-			} else {
-				entry->effect = ceffect[channel];
-				entry->effectvalue = ceffectvalue[channel];
-			}
-
-#ifdef DETECT_DUPLICATE_CHANNELS
-			if (dupentry[channel]) {
-				FILE *f = fopen("dupentry.txt", "a");
-				if (!f) abort();
-				fprintf(f, "Two events on channel %d:", channel);
-				fprintf(f, "  Event #1:");
-				if (dupentry[channel]->mask & IT_ENTRY_NOTE      ) fprintf(f, " %03d", dupentry[channel]->note      ); else fprintf(f, " ...");
-				if (dupentry[channel]->mask & IT_ENTRY_INSTRUMENT) fprintf(f, " %03d", dupentry[channel]->instrument); else fprintf(f, " ...");
-				if (dupentry[channel]->mask & IT_ENTRY_VOLPAN    ) fprintf(f, " %03d", dupentry[channel]->volpan    ); else fprintf(f, " ...");
-				if (dupentry[channel]->mask & IT_ENTRY_EFFECT) fprintf(f, " %c%02X\n", 'A' - 1 + dupentry[channel]->effect, dupentry[channel]->effectvalue); else fprintf(f, " ...\n");
-				fprintf(f, "  Event #2:");
-				if (entry->mask & IT_ENTRY_NOTE      ) fprintf(f, " %03d", entry->note      ); else fprintf(f, " ...");
-				if (entry->mask & IT_ENTRY_INSTRUMENT) fprintf(f, " %03d", entry->instrument); else fprintf(f, " ...");
-				if (entry->mask & IT_ENTRY_VOLPAN    ) fprintf(f, " %03d", entry->volpan    ); else fprintf(f, " ...");
-				if (entry->mask & IT_ENTRY_EFFECT) fprintf(f, " %c%02X\n", 'A' - 1 + entry->effect, entry->effectvalue); else fprintf(f, " ...\n");
-				fclose(f);
-			}
-			dupentry[channel] = entry;
-#endif
-
-			entry++;
-		}
-	}
-
-	ASSERT(entry == pattern->entry + n_entries);
-
-	return 0;
-}
-
-
-
-/* Currently we assume the sample data are stored after the sample headers in
- * module files. This assumption may be unjustified; let me know if you have
- * trouble.
- */
-
-#define IT_COMPONENT_SONG_MESSAGE 1
-#define IT_COMPONENT_INSTRUMENT   2
-#define IT_COMPONENT_PATTERN      3
-#define IT_COMPONENT_SAMPLE       4
-
-typedef struct IT_COMPONENT
-{
-	unsigned char type;
-	unsigned short n;
-	long offset;
-	short sampfirst; /* component[sampfirst] = first sample data after this */
-	short sampnext; /* sampnext is used to create linked lists of sample data */
-}
-IT_COMPONENT;
-
-
-
-static int it_component_compare(const void *e1, const void *e2)
-{
-	return (int)(((const IT_COMPONENT *)e1)->offset -
-	             ((const IT_COMPONENT *)e2)->offset);
-}
-
-
-
-static sigdata_t *it_load_sigdata(DUMBFILE *f)
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	int cwt, cmwt;
-	int special;
-	int message_length, message_offset;
-
-	IT_COMPONENT *component;
-	int n_components = 0;
-
-	unsigned char sample_convert[4096];
-
-	int n;
-
-	unsigned char *buffer;
-
-	if (dumbfile_mgetl(f) != IT_SIGNATURE)
-    {
-		return NULL;
-    }
-
-	sigdata = malloc(sizeof(*sigdata));
-
-	if (!sigdata)
-    {
-		return NULL;
-    }
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-    dumbfile_getnc((char *)sigdata->name, 26, f);
-	sigdata->name[26] = 0;
-
-	/* Skip pattern row highlight info. */
-	dumbfile_skip(f, 2);
-
-	sigdata->n_orders = dumbfile_igetw(f);
-	sigdata->n_instruments = dumbfile_igetw(f);
-	sigdata->n_samples = dumbfile_igetw(f);
-	sigdata->n_patterns = dumbfile_igetw(f);
-
-	cwt = dumbfile_igetw(f);
-	cmwt = dumbfile_igetw(f);
-
-	sigdata->flags = dumbfile_igetw(f);
-	special = dumbfile_igetw(f);
-
-	sigdata->global_volume = dumbfile_getc(f);
-	sigdata->mixing_volume = dumbfile_getc(f);
-	sigdata->speed = dumbfile_getc(f);
-	if (sigdata->speed == 0) sigdata->speed = 6; // Should we? What about tempo?
-	sigdata->tempo = dumbfile_getc(f);
-	sigdata->pan_separation = dumbfile_getc(f); /** WARNING: use this */
-
-	/* Skip Pitch Wheel Depth */
-	dumbfile_skip(f, 1);
-
-	message_length = dumbfile_igetw(f);
-	message_offset = (int)dumbfile_igetl(f);
-
-	/* Skip Reserved. */
-	dumbfile_skip(f, 4);
-
-    dumbfile_getnc((char *)sigdata->channel_pan, DUMB_IT_N_CHANNELS, f);
-    dumbfile_getnc((char *)sigdata->channel_volume, DUMB_IT_N_CHANNELS, f);
-
-	// XXX sample count
-	if (dumbfile_error(f) || sigdata->n_orders <= 0 || sigdata->n_instruments > 256 || sigdata->n_samples > 4000 || sigdata->n_patterns > 256) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	sigdata->order = malloc(sigdata->n_orders);
-	if (!sigdata->order) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	if (sigdata->n_instruments) {
-		sigdata->instrument = malloc(sigdata->n_instruments * sizeof(*sigdata->instrument));
-		if (!sigdata->instrument) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-	}
-
-	if (sigdata->n_samples) {
-		sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-		if (!sigdata->sample) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (n = 0; n < sigdata->n_samples; n++)
-			sigdata->sample[n].data = NULL;
-	}
-
-	if (sigdata->n_patterns) {
-		sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-		if (!sigdata->pattern) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (n = 0; n < sigdata->n_patterns; n++)
-			sigdata->pattern[n].entry = NULL;
-	}
-
-    dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
-	sigdata->restart_position = 0;
-
-	component = malloc(769 * sizeof(*component));
-	if (!component) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	if (special & 1) {
-		component[n_components].type = IT_COMPONENT_SONG_MESSAGE;
-		component[n_components].offset = message_offset;
-		component[n_components].sampfirst = -1;
-		n_components++;
-	}
-
-	for (n = 0; n < sigdata->n_instruments; n++) {
-		component[n_components].type = IT_COMPONENT_INSTRUMENT;
-		component[n_components].n = n;
-		component[n_components].offset = dumbfile_igetl(f);
-		component[n_components].sampfirst = -1;
-		n_components++;
-	}
-
-	for (n = 0; n < sigdata->n_samples; n++) {
-		component[n_components].type = IT_COMPONENT_SAMPLE;
-		component[n_components].n = n;
-		component[n_components].offset = dumbfile_igetl(f);
-		component[n_components].sampfirst = -1;
-		n_components++;
-	}
-
-	for (n = 0; n < sigdata->n_patterns; n++) {
-		long offset = dumbfile_igetl(f);
-		if (offset) {
-			component[n_components].type = IT_COMPONENT_PATTERN;
-			component[n_components].n = n;
-			component[n_components].offset = offset;
-			component[n_components].sampfirst = -1;
-			n_components++;
-		} else {
-			/* Empty 64-row pattern */
-			sigdata->pattern[n].n_rows = 64;
-			sigdata->pattern[n].n_entries = 0;
-		}
-	}
-
-	if (dumbfile_error(f)) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	/*
-	if (!(sigdata->flags & 128) != !(special & 8)) {
-		fprintf(stderr, "Flags   Bit 7 (\"Request embedded MIDI configuration\"): %s\n", sigdata->flags & 128 ? "=SET=" : "clear");
-		fprintf(stderr, "Special Bit 3     (\"MIDI configuration embedded\")    : %s\n", special        &   8 ? "=SET=" : "clear");
-		fprintf(stderr, "entheh would like to investigate this IT file.\n");
-		fprintf(stderr, "Please contact him! entheh@users.sf.net\n");
-	}
-	*/
-
-	if (special & 8) {
-		/* MIDI configuration is embedded. */
-		unsigned char mididata[32];
-		int i;
-		sigdata->midi = malloc(sizeof(*sigdata->midi));
-		if (!sigdata->midi) {
-			free(component);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-			// Should we be happy with this outcome in some situations?
-		}
-		// What are we skipping?
-		i = dumbfile_igetw(f);
-		if (dumbfile_error(f) || dumbfile_skip(f, 8*i)) {
-			free(component);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		/* Read embedded MIDI configuration */
-		// What are the first 9 commands for?
-		if (dumbfile_skip(f, 32*9)) {
-			free(component);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (i = 0; i < 16; i++) {
-			unsigned char len = 0;
-			int j, leftdigit = -1;
-            if (dumbfile_getnc((char *)mididata, 32, f) < 32) {
-				free(component);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-			sigdata->midi->SFmacroz[i] = 0;
-			for (j = 0; j < 32; j++) {
-				if (leftdigit >= 0) {
-					if (mididata[j] == 0) {
-						sigdata->midi->SFmacro[i][len++] = leftdigit;
-						break;
-					} else if (mididata[j] == ' ')
-						sigdata->midi->SFmacro[i][len++] = leftdigit;
-					else if (mididata[j] >= '0' && mididata[j] <= '9')
-						sigdata->midi->SFmacro[i][len++] = (leftdigit << 4) | (mididata[j] - '0');
-					else if (mididata[j] >= 'A' && mididata[j] <= 'F')
-						sigdata->midi->SFmacro[i][len++] = (leftdigit << 4) | (mididata[j] - 'A' + 0xA);
-					leftdigit = -1;
-				} else if (mididata[j] == 0)
-					break;
-				else if (mididata[j] == 'z')
-					sigdata->midi->SFmacroz[i] |= 1 << len++;
-				else if (mididata[j] >= '0' && mididata[j] <= '9')
-					leftdigit = mididata[j] - '0';
-				else if (mididata[j] >= 'A' && mididata[j] <= 'F')
-					leftdigit = mididata[j] - 'A' + 0xA;
-			}
-			sigdata->midi->SFmacrolen[i] = len;
-		}
-		for (i = 0; i < 128; i++) {
-			unsigned char len = 0;
-			int j, leftdigit = -1;
-            dumbfile_getnc((char *)mididata, 32, f);
-			for (j = 0; j < 32; j++) {
-				if (leftdigit >= 0) {
-					if (mididata[j] == 0) {
-						sigdata->midi->Zmacro[i][len++] = leftdigit;
-						break;
-					} else if (mididata[j] == ' ')
-						sigdata->midi->Zmacro[i][len++] = leftdigit;
-					else if (mididata[j] >= '0' && mididata[j] <= '9')
-						sigdata->midi->Zmacro[i][len++] = (leftdigit << 4) | (mididata[j] - '0');
-					else if (mididata[j] >= 'A' && mididata[j] <= 'F')
-						sigdata->midi->Zmacro[i][len++] = (leftdigit << 4) | (mididata[j] - 'A' + 0xA);
-					leftdigit = -1;
-				} else if (mididata[j] == 0)
-					break;
-				else if (mididata[j] >= '0' && mididata[j] <= '9')
-					leftdigit = mididata[j] - '0';
-				else if (mididata[j] >= 'A' && mididata[j] <= 'F')
-					leftdigit = mididata[j] - 'A' + 0xA;
-			}
-			sigdata->midi->Zmacrolen[i] = len;
-		}
-	}
-
-	sigdata->flags &= IT_REAL_FLAGS;
-
-    qsort(component, n_components, sizeof(IT_COMPONENT), &it_component_compare);
-
-	buffer = malloc(65536);
-	if (!buffer) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (n = 0; n < n_components; n++) {
-		long offset;
-		int m;
-
-		/* XXX */
-		if ( component[n].offset == 0 ) {
-			switch (component[n].type) {
-				case IT_COMPONENT_INSTRUMENT:
-					memset( &sigdata->instrument[component[n].n], 0, sizeof(IT_INSTRUMENT) );
-					break;
-				case IT_COMPONENT_SAMPLE:
-					memset( &sigdata->sample[component[n].n], 0, sizeof(IT_SAMPLE) );
-					break;
-				case IT_COMPONENT_PATTERN:
-					{
-						IT_PATTERN * p = &sigdata->pattern[component[n].n];
-						p->entry = 0;
-						p->n_rows = 64;
-						p->n_entries = 0;
-					}
-					break;
-			}
-			continue;
-		}
-
-        if (dumbfile_seek(f, component[n].offset, DFS_SEEK_SET)) {
-			free(buffer);
-			free(component);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-
-		switch (component[n].type) {
-
-			case IT_COMPONENT_SONG_MESSAGE:
-				if ( n < n_components ) {
-					message_length = min( message_length, (int)(component[n+1].offset - component[n].offset) );
-				}
-				sigdata->song_message = malloc(message_length + 1);
-				if (sigdata->song_message) {
-                    if (dumbfile_getnc((char *)sigdata->song_message, message_length, f) < message_length) {
-						free(buffer);
-						free(component);
-						_dumb_it_unload_sigdata(sigdata);
-						return NULL;
-					}
-					sigdata->song_message[message_length] = 0;
-				}
-				break;
-
-			case IT_COMPONENT_INSTRUMENT:
-				if (cmwt < 0x200)
-					m = it_read_old_instrument(&sigdata->instrument[component[n].n], f);
-				else
-					m = it_read_instrument(&sigdata->instrument[component[n].n], f, (n + 1 < n_components) ? (int)(component[n+1].offset - component[n].offset) : 0);
-
-				if (m) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-				break;
-
-			case IT_COMPONENT_PATTERN:
-				if (it_read_pattern(&sigdata->pattern[component[n].n], f, buffer)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-				break;
-
-			case IT_COMPONENT_SAMPLE:
-				if (it_read_sample_header(&sigdata->sample[component[n].n], &sample_convert[component[n].n], &offset, f)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-
-				if (sigdata->sample[component[n].n].flags & IT_SAMPLE_EXISTS) {
-					short *sample;
-
-					for (m = n + 1; m < n_components; m++)
-						if (component[m].offset > offset)
-							break;
-					m--;
-
-					sample = &component[m].sampfirst;
-
-					while (*sample >= 0 && component[*sample].offset <= offset)
-						sample = &component[*sample].sampnext;
-
-					component[n].sampnext = *sample;
-					*sample = n;
-
-					component[n].offset = offset;
-				}
-		}
-
-		m = component[n].sampfirst;
-
-		while (m >= 0) {
-            if (dumbfile_seek(f, component[m].offset, DFS_SEEK_SET)) {
-				free(buffer);
-				free(component);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-
-			if (it_read_sample_data(&sigdata->sample[component[m].n], sample_convert[component[m].n], f)) {
-				free(buffer);
-				free(component);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-
-			m = component[m].sampnext;
-		}
-    }
-
-    for ( n = 0; n < 10; n++ )
-    {
-        if ( dumbfile_getc( f ) == 'X' )
-        {
-            if ( dumbfile_getc( f ) == 'T' )
-            {
-                if ( dumbfile_getc( f ) == 'P' )
-                {
-                    if ( dumbfile_getc( f ) == 'M' )
-                    {
-                        break;
-                    }
-                }
-            }
-        }
-    }
-
-    if ( !dumbfile_error( f ) && n < 10 )
-    {
-        unsigned int mptx_id = (unsigned int)dumbfile_igetl( f );
-        while ( !dumbfile_error( f ) && mptx_id != DUMB_ID('M','P','T','S') )
-        {
-            unsigned int size = dumbfile_igetw( f );
-            switch (mptx_id)
-            {
-            /* TODO: Add instrument extension readers */
-
-            default:
-                dumbfile_skip(f, size * sigdata->n_instruments);
-                break;
-            }
-
-            mptx_id = (unsigned int)dumbfile_igetl( f );
-        }
-
-        mptx_id = (unsigned int)dumbfile_igetl( f );
-        while ( !dumbfile_error(f) && dumbfile_pos(f) < dumbfile_get_size(f) )
-        {
-            unsigned int size = dumbfile_igetw( f );
-            switch (mptx_id)
-            {
-            /* TODO: Add more song extension readers */
-
-            case DUMB_ID('D','T','.','.'):
-                if ( size == 2 )
-                    sigdata->tempo = dumbfile_igetw( f );
-                else if ( size == 4 )
-                    sigdata->tempo = (int)dumbfile_igetl( f );
-                break;
-
-            default:
-                dumbfile_skip(f, size);
-                break;
-            }
-            mptx_id = (unsigned int)dumbfile_igetl( f );
-        }
-    }
-
-    free(buffer);
-	free(component);
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-
-
-DUH *dumb_read_it_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_load_sigdata(f);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "IT";
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/itread2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itread2.c - Function to read an Impulse Tracker    / / \  \
- *             module from an open file and do an    | <  /   \_
- *             initial run-through.                  |  \/ /\   /
- *                                                    \_  /  > /
- * Split off from itread.c by entheh.                   | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_it(DUMBFILE *f)
-{
-	DUH *duh = dumb_read_it_quick(f);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/itrender.c
+++ /dev/null
@@ -1,6102 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itrender.c - Code to render an Impulse Tracker     / / \  \
- *              module.                              | <  /   \_
- *                                                   |  \/ /\   /
- * Written - painstakingly - by entheh.               \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/dumb.h"
-#include "internal/it.h"
-#include "internal/lpc.h"
-
-#include "internal/resampler.h"
-
-// Keep this disabled, as it's actually slower than the original C/integer version
-//
-//#ifdef __APPLE__
-//#include <TargetConditionals.h>
-//#if TARGET_CPU_ARM || TARGET_CPU_ARM64
-//#include <arm_neon.h>
-//#define FILTER_NEON
-//#endif
-//#endif
-
-// #define BIT_ARRAY_BULLSHIT
-
-static IT_PLAYING *new_playing()
-{
-	IT_PLAYING * r = (IT_PLAYING*) malloc(sizeof(*r));
-	if (r)
-	{
-		r->resampler.fir_resampler_ratio = 0.0;
-		r->resampler.fir_resampler[0] = resampler_create();
-		if ( !r->resampler.fir_resampler[0] ) {
-			free( r );
-			return NULL;
-		}
-		r->resampler.fir_resampler[1] = resampler_create();
-		if ( !r->resampler.fir_resampler[1] ) {
-			resampler_delete( r->resampler.fir_resampler[0] );
-			free( r );
-			return NULL;
-		}
-	}
-	return r;
-}
-
-static void free_playing(IT_PLAYING * r)
-{
-	resampler_delete( r->resampler.fir_resampler[1] );
-	resampler_delete( r->resampler.fir_resampler[0] );
-	free( r );
-}
-
-static IT_PLAYING *dup_playing(IT_PLAYING *src, IT_CHANNEL *dstchannel, IT_CHANNEL *srcchannel)
-{
-	IT_PLAYING *dst;
-
-	if (!src) return NULL;
-
-	dst = malloc(sizeof(*dst));
-	if (!dst) return NULL;
-
-	dst->flags = src->flags;
-	dst->resampling_quality = src->resampling_quality;
-
-	ASSERT(src->channel);
-	dst->channel = &dstchannel[src->channel - srcchannel];
-	dst->sample = src->sample;
-	dst->instrument = src->instrument;
-	dst->env_instrument = src->env_instrument;
-
-	dst->sampnum = src->sampnum;
-	dst->instnum = src->instnum;
-
-	dst->declick_stage = src->declick_stage;
-
-	dst->float_volume[0] = src->float_volume[0];
-	dst->float_volume[1] = src->float_volume[1];
-
-	dst->ramp_volume[0] = src->ramp_volume[0];
-	dst->ramp_volume[1] = src->ramp_volume[1];
-
-	dst->ramp_delta[0] = src->ramp_delta[0];
-	dst->ramp_delta[1] = src->ramp_delta[1];
-
-	dst->channel_volume = src->channel_volume;
-
-	dst->volume = src->volume;
-	dst->pan = src->pan;
-
-	dst->volume_offset = src->volume_offset;
-	dst->panning_offset = src->panning_offset;
-
-	dst->note = src->note;
-
-	dst->enabled_envelopes = src->enabled_envelopes;
-
-	dst->filter_cutoff = src->filter_cutoff;
-	dst->filter_resonance = src->filter_resonance;
-
-	dst->true_filter_cutoff = src->true_filter_cutoff;
-	dst->true_filter_resonance = src->true_filter_resonance;
-
-	dst->vibrato_speed = src->vibrato_speed;
-	dst->vibrato_depth = src->vibrato_depth;
-	dst->vibrato_n = src->vibrato_n;
-	dst->vibrato_time = src->vibrato_time;
-	dst->vibrato_waveform = src->vibrato_waveform;
-
-	dst->tremolo_speed = src->tremolo_speed;
-	dst->tremolo_depth = src->tremolo_depth;
-	dst->tremolo_time = src->tremolo_time;
-	dst->tremolo_waveform = src->tremolo_waveform;
-
-	dst->panbrello_speed = src->panbrello_speed;
-	dst->panbrello_depth = src->panbrello_depth;
-	dst->panbrello_time = src->panbrello_time;
-	dst->panbrello_waveform = src->panbrello_waveform;
-	dst->panbrello_random = src->panbrello_random;
-
-	dst->sample_vibrato_time = src->sample_vibrato_time;
-	dst->sample_vibrato_waveform = src->sample_vibrato_waveform;
-	dst->sample_vibrato_depth = src->sample_vibrato_depth;
-
-	dst->slide = src->slide;
-	dst->delta = src->delta;
-	dst->finetune = src->finetune;
-
-	dst->volume_envelope = src->volume_envelope;
-	dst->pan_envelope = src->pan_envelope;
-	dst->pitch_envelope = src->pitch_envelope;
-
-	dst->fadeoutcount = src->fadeoutcount;
-
-	dst->filter_state[0] = src->filter_state[0];
-	dst->filter_state[1] = src->filter_state[1];
-
-	dst->resampler = src->resampler;
-	dst->resampler.pickup_data = dst;
-	dst->resampler.fir_resampler_ratio = src->resampler.fir_resampler_ratio;
-	dst->resampler.fir_resampler[0] = resampler_dup( src->resampler.fir_resampler[0] );
-	if ( !dst->resampler.fir_resampler[0] ) {
-		free( dst );
-		return NULL;
-	}
-	dst->resampler.fir_resampler[1] = resampler_dup( src->resampler.fir_resampler[1] );
-	if ( !dst->resampler.fir_resampler[1] ) {
-		resampler_delete( dst->resampler.fir_resampler[0] );
-		free( dst );
-		return NULL;
-	}
-	dst->time_lost = src->time_lost;
-
-	//dst->output = src->output;
-
-	return dst;
-}
-
-
-
-static void dup_channel(IT_CHANNEL *dst, IT_CHANNEL *src)
-{
-	dst->flags = src->flags;
-
-	dst->volume = src->volume;
-	dst->volslide = src->volslide;
-	dst->xm_volslide = src->xm_volslide;
-	dst->panslide = src->panslide;
-
-	dst->pan = src->pan;
-	dst->truepan = src->truepan;
-
-	dst->channelvolume = src->channelvolume;
-	dst->channelvolslide = src->channelvolslide;
-
-	dst->instrument = src->instrument;
-	dst->note = src->note;
-
-	dst->SFmacro = src->SFmacro;
-
-	dst->filter_cutoff = src->filter_cutoff;
-	dst->filter_resonance = src->filter_resonance;
-
-	dst->key_off_count = src->key_off_count;
-	dst->note_cut_count = src->note_cut_count;
-	dst->note_delay_count = src->note_delay_count;
-	dst->note_delay_entry = src->note_delay_entry;
-
-	dst->new_note_action = src->new_note_action;
-
-	dst->arpeggio_table = src->arpeggio_table;
-	memcpy(dst->arpeggio_offsets, src->arpeggio_offsets, sizeof(dst->arpeggio_offsets));
-	dst->retrig = src->retrig;
-	dst->xm_retrig = src->xm_retrig;
-	dst->retrig_tick = src->retrig_tick;
-
-	dst->tremor_time = src->tremor_time;
-
-	dst->vibrato_waveform = src->vibrato_waveform;
-	dst->tremolo_waveform = src->tremolo_waveform;
-	dst->panbrello_waveform = src->panbrello_waveform;
-
-	dst->portamento = src->portamento;
-	dst->toneporta = src->toneporta;
-	dst->toneslide = src->toneslide;
-	dst->toneslide_tick = src->toneslide_tick;
-	dst->last_toneslide_tick = src->last_toneslide_tick;
-	dst->ptm_toneslide = src->ptm_toneslide;
-	dst->ptm_last_toneslide = src->ptm_last_toneslide;
-	dst->okt_toneslide = src->okt_toneslide;
-	dst->destnote = src->destnote;
-
-	dst->glissando = src->glissando;
-
-	dst->sample = src->sample;
-	dst->truenote = src->truenote;
-
-	dst->midi_state = src->midi_state;
-
-	dst->lastvolslide = src->lastvolslide;
-	dst->lastDKL = src->lastDKL;
-	dst->lastEF = src->lastEF;
-	dst->lastG = src->lastG;
-	dst->lastHspeed = src->lastHspeed;
-	dst->lastHdepth = src->lastHdepth;
-	dst->lastRspeed = src->lastRspeed;
-	dst->lastRdepth = src->lastRdepth;
-	dst->lastYspeed = src->lastYspeed;
-	dst->lastYdepth = src->lastYdepth;
-	dst->lastI = src->lastI;
-	dst->lastJ = src->lastJ;
-	dst->lastN = src->lastN;
-	dst->lastO = src->lastO;
-	dst->high_offset = src->high_offset;
-	dst->lastP = src->lastP;
-	dst->lastQ = src->lastQ;
-	dst->lastS = src->lastS;
-	dst->pat_loop_row = src->pat_loop_row;
-	dst->pat_loop_count = src->pat_loop_count;
-	dst->pat_loop_end_row = src->pat_loop_end_row;
-	dst->lastW = src->lastW;
-
-	dst->xm_lastE1 = src->xm_lastE1;
-	dst->xm_lastE2 = src->xm_lastE2;
-	dst->xm_lastEA = src->xm_lastEA;
-	dst->xm_lastEB = src->xm_lastEB;
-	dst->xm_lastX1 = src->xm_lastX1;
-	dst->xm_lastX2 = src->xm_lastX2;
-
-	dst->inv_loop_delay = src->inv_loop_delay;
-	dst->inv_loop_speed = src->inv_loop_speed;
-	dst->inv_loop_offset = src->inv_loop_offset;
-
-	dst->playing = dup_playing(src->playing, dst, src);
-
-#ifdef BIT_ARRAY_BULLSHIT
-	dst->played_patjump = bit_array_dup(src->played_patjump);
-	dst->played_patjump_order = src->played_patjump_order;
-#endif
-
-	//dst->output = src->output;
-}
-
-
-
-/* Allocate the new callbacks first, then pass them to this function!
- * It will free them on failure.
- */
-static DUMB_IT_SIGRENDERER *dup_sigrenderer(DUMB_IT_SIGRENDERER *src, int n_channels, IT_CALLBACKS *callbacks)
-{
-	DUMB_IT_SIGRENDERER *dst;
-	int i;
-
-	if (!src) {
-		if (callbacks) free(callbacks);
-		return NULL;
-	}
-
-	dst = malloc(sizeof(*dst));
-	if (!dst) {
-		if (callbacks) free(callbacks);
-		return NULL;
-	}
-
-	dst->sigdata = src->sigdata;
-
-	dst->n_channels = n_channels;
-
-	dst->resampling_quality = src->resampling_quality;
-
-	dst->globalvolume = src->globalvolume;
-	dst->globalvolslide = src->globalvolslide;
-
-	dst->tempo = src->tempo;
-	dst->temposlide = src->temposlide;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++)
-		dup_channel(&dst->channel[i], &src->channel[i]);
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
-		dst->playing[i] = dup_playing(src->playing[i], dst->channel, src->channel);
-
-	dst->tick = src->tick;
-	dst->speed = src->speed;
-	dst->rowcount = src->rowcount;
-
-	dst->order = src->order;
-	dst->row = src->row;
-	dst->processorder = src->processorder;
-	dst->processrow = src->processrow;
-	dst->breakrow = src->breakrow;
-
-	dst->restart_position = src->restart_position;
-
-	dst->n_rows = src->n_rows;
-
-	dst->entry_start = src->entry_start;
-	dst->entry = src->entry;
-	dst->entry_end = src->entry_end;
-
-	dst->time_left = src->time_left;
-	dst->sub_time_left = src->sub_time_left;
-
-	dst->ramp_style = src->ramp_style;
-
-	dst->click_remover = NULL;
-
-	dst->callbacks = callbacks;
-
-#ifdef BIT_ARRAY_BULLSHIT
-	dst->played = bit_array_dup(src->played);
-
-	dst->looped = src->looped;
-	dst->time_played = src->time_played;
-	dst->row_timekeeper = timekeeping_array_dup(src->row_timekeeper);
-#endif
-
-	dst->gvz_time = src->gvz_time;
-	dst->gvz_sub_time = src->gvz_sub_time;
-
-	//dst->max_output = src->max_output;
-
-	return dst;
-}
-
-
-
-static const IT_MIDI default_midi = {
-	/* unsigned char SFmacro[16][16]; */
-	{
-		{0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
-	},
-	/* unsigned char SFmacrolen[16]; */
-	{4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
-	/* unsigned short SFmacroz[16]; */
-	/* Bitfield; bit 0 set = z in first position */
-	{
-		0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-		0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
-	},
-	/* unsigned char Zmacro[128][16]; */
-	{
-		{0xF0, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0xF0, 0xF0, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-		{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
-	},
-	/* unsigned char Zmacrolen[128]; */
-	{
-		4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-	}
-};
-
-
-
-static void it_reset_filter_state(IT_FILTER_STATE *state)
-{
-	state->currsample = 0;
-	state->prevsample = 0;
-}
-
-
-
-#define LOG10 2.30258509299
-
-/* IMPORTANT: This function expects one extra sample in 'src' so it can apply
- * click removal. It reads size samples, starting from src[0], and writes its
- * output starting at dst[pos]. The pos parameter is required for getting
- * click removal right.
- */
-
-static void it_filter_int(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state, sample_t *dst, long pos, sample_t *src, long size, int step, int sampfreq, int cutoff, int resonance)
-{
-	sample_t currsample = state->currsample;
-	sample_t prevsample = state->prevsample;
-
-	float a, b, c;
-
-	long datasize;
-
-	{
-		float inv_angle = (float)(sampfreq * pow(0.5, 0.25 + cutoff*(1.0/(24<<IT_ENVELOPE_SHIFT))) * (1.0/(2*3.14159265358979323846*110.0)));
-		float loss = (float)exp(resonance*(-LOG10*1.2/128.0));
-		float d, e;
-#if 0
-		loss *= 2; // This is the mistake most players seem to make!
-#endif
-
-#if 1
-		d = (1.0f - loss) / inv_angle;
-		if (d > 2.0f) d = 2.0f;
-		d = (loss - d) * inv_angle;
-		e = inv_angle * inv_angle;
-		a = 1.0f / (1.0f + d + e);
-		c = -e * a;
-		b = 1.0f - a - c;
-#else
-		a = 1.0f / (inv_angle*inv_angle + inv_angle*loss + loss);
-		c = -(inv_angle*inv_angle) * a;
-		b = 1.0f - a - c;
-#endif
-	}
-
-	dst += pos * step;
-	datasize = size * step;
-
-#define INT_FILTERS
-#ifdef INT_FILTERS
-#define MULSCA(a, b) ((int)((LONG_LONG)((a) << 4) * (b) >> 32))
-#define SCALEB 12
-	{
-		int ai = (int)(a * (1 << (16+SCALEB)));
-		int bi = (int)(b * (1 << (16+SCALEB)));
-		int ci = (int)(c * (1 << (16+SCALEB)));
-		int i;
-
-		if (cr) {
-			sample_t startstep = MULSCA(src[0], ai) + MULSCA(currsample, bi) + MULSCA(prevsample, ci);
-			dumb_record_click(cr, pos, startstep);
-		}
-
-		for (i = 0; i < datasize; i += step) {
-			{
-				sample_t newsample = MULSCA(src[i], ai) + MULSCA(currsample, bi) + MULSCA(prevsample, ci);
-				prevsample = currsample;
-				currsample = newsample;
-			}
-			dst[i] += currsample;
-		}
-
-		if (cr) {
-			sample_t endstep = MULSCA(src[datasize], ai) + MULSCA(currsample, bi) + MULSCA(prevsample, ci);
-			dumb_record_click(cr, pos + size, -endstep);
-		}
-	}
-#else
-#error This version is broken - it does not use step, and state should contain floats for it
-	if (cr) {
-		float startstep = src[0]*a + currsample*b + prevsample*c;
-		dumb_record_click(cr, pos, (sample_t)startstep);
-	}
-
-	{
-		int i = size % 3;
-		while (i > 0) {
-			{
-				float newsample = *src++*a + currsample*b + prevsample*c;
-				prevsample = currsample;
-				currsample = newsample;
-			}
-			*dst++ += (sample_t)currsample;
-			i--;
-		}
-		i = size / 3;
-		while (i > 0) {
-			float newsample;
-			/* Gotta love unrolled loops! */
-			*dst++ += (sample_t)(newsample = *src++*a + currsample*b + prevsample*c);
-			*dst++ += (sample_t)(prevsample = *src++*a + newsample*b + currsample*c);
-			*dst++ += (sample_t)(currsample = *src++*a + prevsample*b + newsample*c);
-			i--;
-		}
-	}
-
-	if (cr) {
-		float endstep = src[datasize]*a + currsample*b + prevsample*c;
-		dumb_record_click(cr, pos + size, -(sample_t)endstep);
-	}
-#endif
-
-	state->currsample = currsample;
-	state->prevsample = prevsample;
-}
-
-#if defined(_USE_SSE) && (defined(_M_IX86) || defined(__i386__) || defined(_M_X64) || defined(__amd64__))
-#include <xmmintrin.h>
-
-static void it_filter_sse(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state, sample_t *dst, long pos, sample_t *src, long size, int step, int sampfreq, int cutoff, int resonance)
-{
-	__m128 data, impulse;
-	__m128 temp1, temp2;
-
-	sample_t currsample = state->currsample;
-	sample_t prevsample = state->prevsample;
-
-	float imp[4];
-
-	//profiler( filter_sse ); On ClawHammer Athlon64 3200+, ~12000 cycles, ~500 for that x87 setup code (as opposed to ~25500 for the original integer code)
-
-	long datasize;
-
-	{
-		float inv_angle = (float)(sampfreq * pow(0.5, 0.25 + cutoff*(1.0/(24<<IT_ENVELOPE_SHIFT))) * (1.0/(2*3.14159265358979323846*110.0)));
-		float loss = (float)exp(resonance*(-LOG10*1.2/128.0));
-		float d, e;
-#if 0
-		loss *= 2; // This is the mistake most players seem to make!
-#endif
-
-#if 1
-		d = (1.0f - loss) / inv_angle;
-		if (d > 2.0f) d = 2.0f;
-		d = (loss - d) * inv_angle;
-		e = inv_angle * inv_angle;
-		imp[0] = 1.0f / (1.0f + d + e);
-		imp[2] = -e * imp[0];
-		imp[1] = 1.0f - imp[0] - imp[2];
-#else
-		imp[0] = 1.0f / (inv_angle*inv_angle + inv_angle*loss + loss);
-		imp[2] = -(inv_angle*inv_angle) * imp[0];
-		imp[1] = 1.0f - imp[0] - imp[2];
-#endif
-		imp[3] = 0.0f;
-	}
-
-	dst += pos * step;
-	datasize = size * step;
-
-	{
-		int ai, bi, ci, i;
-
-		if (cr) {
-			sample_t startstep;
-			ai = (int)(imp[0] * (1 << (16+SCALEB)));
-			bi = (int)(imp[1] * (1 << (16+SCALEB)));
-			ci = (int)(imp[2] * (1 << (16+SCALEB)));
-			startstep = MULSCA(src[0], ai) + MULSCA(currsample, bi) + MULSCA(prevsample, ci);
-			dumb_record_click(cr, pos, startstep);
-		}
-
-		temp1 = _mm_setzero_ps();
-		data = _mm_cvtsi32_ss( temp1, currsample );
-		temp2 = _mm_cvtsi32_ss( temp1, prevsample );
-		impulse = _mm_loadu_ps( (const float *) &imp );
-		data = _mm_shuffle_ps( data, temp2, _MM_SHUFFLE(1, 0, 0, 1) );
-
-		for (i = 0; i < datasize; i += step) {
-			temp1 = _mm_cvtsi32_ss( data, src [i] );
-			temp1 = _mm_mul_ps( temp1, impulse );
-			temp2 = _mm_movehl_ps( temp2, temp1 );
-			temp1 = _mm_add_ps( temp1, temp2 );
-			temp2 = temp1;
-			temp2 = _mm_shuffle_ps( temp2, temp1, _MM_SHUFFLE(0, 0, 0, 1) );
-			temp1 = _mm_add_ps( temp1, temp2 );
-			temp1 = _mm_shuffle_ps( temp1, data, _MM_SHUFFLE(2, 1, 0, 0) );
-			data = temp1;
-			dst [i] += _mm_cvtss_si32( temp1 );
-		}
-
-		currsample = _mm_cvtss_si32( temp1 );
-		temp1 = _mm_shuffle_ps( temp1, data, _MM_SHUFFLE(0, 0, 0, 2) );
-		prevsample = _mm_cvtss_si32( temp1 );
-
-		if (cr) {
-			sample_t endstep = MULSCA(src[datasize], ai) + MULSCA(currsample, bi) + MULSCA(prevsample, ci);
-			dumb_record_click(cr, pos + size, -endstep);
-		}
-	}
-
-	state->currsample = currsample;
-	state->prevsample = prevsample;
-}
-#endif
-
-#ifdef FILTER_NEON
-static void it_filter_neon(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state, sample_t *dst, long pos, sample_t *src, long size, int step, int sampfreq, int cutoff, int resonance)
-{
-    float32x4_t data, impulse;
-    float32x4_t temp1;
-    float32x2_t temp2;
-    float32_t temp3;
-    
-    sample_t currsample = state->currsample;
-    sample_t prevsample = state->prevsample;
-    
-    float imp[4];
-    
-    //profiler( filter_sse ); On ClawHammer Athlon64 3200+, ~12000 cycles, ~500 for that x87 setup code (as opposed to ~25500 for the original integer code)
-    
-    long datasize;
-    
-    {
-        float inv_angle = (float)(sampfreq * pow(0.5, 0.25 + cutoff*(1.0/(24<<IT_ENVELOPE_SHIFT))) * (1.0/(2*3.14159265358979323846*110.0)));
-        float loss = (float)exp(resonance*(-LOG10*1.2/128.0));
-        float d, e;
-#if 0
-        loss *= 2; // This is the mistake most players seem to make!
-#endif
-        
-#if 1
-        d = (1.0f - loss) / inv_angle;
-        if (d > 2.0f) d = 2.0f;
-        d = (loss - d) * inv_angle;
-        e = inv_angle * inv_angle;
-        imp[0] = 1.0f / (1.0f + d + e);
-        imp[2] = -e * imp[0];
-        imp[1] = 1.0f - imp[0] - imp[2];
-#else
-        imp[0] = 1.0f / (inv_angle*inv_angle + inv_angle*loss + loss);
-        imp[2] = -(inv_angle*inv_angle) * imp[0];
-        imp[1] = 1.0f - imp[0] - imp[2];
-#endif
-        imp[3] = 0.0f;
-    }
-    
-    dst += pos * step;
-    datasize = size * step;
-    
-    {
-        int ai, bi, ci, i;
-        
-        if (cr) {
-            sample_t startstep;
-            ai = (int)(imp[0] * (1 << (16+SCALEB)));
-            bi = (int)(imp[1] * (1 << (16+SCALEB)));
-            ci = (int)(imp[2] * (1 << (16+SCALEB)));
-            startstep = MULSCA(src[0], ai) + MULSCA(currsample, bi) + MULSCA(prevsample, ci);
-            dumb_record_click(cr, pos, startstep);
-        }
-        
-        data = vdupq_n_f32(0.0f);
-        data = vsetq_lane_f32( currsample, data, 1 );
-        data = vsetq_lane_f32( prevsample, data, 2 );
-        impulse = vld1q_f32( (const float32_t *) &imp );
-        
-        for (i = 0; i < datasize; i += step) {
-            data = vsetq_lane_f32( src [i], data, 0 );
-            temp1 = vmulq_f32(data, impulse);
-            temp2 = vadd_f32(vget_high_f32(temp1), vget_low_f32(temp1));
-            temp3 = vget_lane_f32(vpadd_f32(temp2, temp2), 0);
-            data = vextq_f32(data, data, 3);
-            data = vsetq_lane_f32(temp3, data, 1);
-            dst [i] += temp3;
-        }
-        
-        currsample = temp3;
-        prevsample = vgetq_lane_f32(data, 2);
-        
-        if (cr) {
-            sample_t endstep = MULSCA(src[datasize], ai) + MULSCA(currsample, bi) + MULSCA(prevsample, ci);
-            dumb_record_click(cr, pos + size, -endstep);
-        }
-    }
-    
-    state->currsample = currsample;
-    state->prevsample = prevsample;
-}
-#endif
-
-#undef LOG10
-
-#ifdef _USE_SSE
-#if defined(_M_IX86) || defined(__i386__)
-
-#ifdef _MSC_VER
-#include <intrin.h>
-#elif defined(__clang__) || defined(__GNUC__)
-static inline void
-__cpuid(int *data, int selector)
-{
-#if defined(__PIC__) && defined(__i386__)
-    asm("xchgl %%ebx, %%esi; cpuid; xchgl %%ebx, %%esi"
-        : "=a" (data[0]),
-        "=S" (data[1]),
-        "=c" (data[2]),
-        "=d" (data[3])
-        : "0" (selector));
-#elif defined(__PIC__) && defined(__amd64__)
-    asm("xchg{q} {%%}rbx, %q1; cpuid; xchg{q} {%%}rbx, %q1"
-        : "=a" (data[0]),
-        "=&r" (data[1]),
-        "=c" (data[2]),
-        "=d" (data[3])
-        : "0" (selector));
-#else
-    asm("cpuid"
-        : "=a" (data[0]),
-        "=b" (data[1]),
-        "=c" (data[2]),
-        "=d" (data[3])
-        : "a"(selector));
-#endif
-}
-#else
-#define __cpuid(a,b) memset((a), 0, sizeof(int) * 4)
-#endif
-
-static int query_cpu_feature_sse() {
-	int buffer[4];
-	__cpuid(buffer,1);
-	if ((buffer[3]&(1<<25)) == 0) return 0;
-	return 1;
-}
-
-static int _dumb_it_use_sse = 0;
-
-void _dumb_init_sse()
-{
-    static int initialized = 0;
-    if (!initialized)
-    {
-        _dumb_it_use_sse = query_cpu_feature_sse();
-        initialized = 1;
-    }
-}
-
-#elif defined(_M_X64) || defined(__amd64__)
-
-static const int _dumb_it_use_sse = 1;
-
-void _dumb_init_sse() { }
-
-#else
-
-static const int _dumb_it_use_sse = 0;
-
-void _dumb_init_sse() { }
-
-#endif
-#endif
-
-static void it_filter(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state, sample_t *dst, long pos, sample_t *src, long size, int step, int sampfreq, int cutoff, int resonance)
-{
-#if defined(_USE_SSE) && (defined(_M_IX86) || defined(__i386__) || defined(_M_X64) || defined(__amd64__))
-    _dumb_init_sse();
-	if ( _dumb_it_use_sse ) it_filter_sse( cr, state, dst, pos, src, size, step, sampfreq, cutoff, resonance );
-	else
-#endif
-#ifdef FILTER_NEON
-    it_filter_neon( cr, state, dst, pos, src, size, step, sampfreq, cutoff, resonance );
-#else
-	it_filter_int( cr, state, dst, pos, src, size, step, sampfreq, cutoff, resonance );
-#endif
-}
-
-
-
-static const signed char it_sine[256] = {
-	  0,  2,  3,  5,  6,  8,  9, 11, 12, 14, 16, 17, 19, 20, 22, 23,
-	 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44,
-	 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59,
-	 59, 60, 60, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 63, 63, 63, 62, 62, 62, 61, 61, 60, 60,
-	 59, 59, 58, 57, 56, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46,
-	 45, 44, 43, 42, 41, 39, 38, 37, 36, 34, 33, 32, 30, 29, 27, 26,
-	 24, 23, 22, 20, 19, 17, 16, 14, 12, 11,  9,  8,  6,  5,  3,  2,
-	  0, -2, -3, -5, -6, -8, -9,-11,-12,-14,-16,-17,-19,-20,-22,-23,
-	-24,-26,-27,-29,-30,-32,-33,-34,-36,-37,-38,-39,-41,-42,-43,-44,
-	-45,-46,-47,-48,-49,-50,-51,-52,-53,-54,-55,-56,-56,-57,-58,-59,
-	-59,-60,-60,-61,-61,-62,-62,-62,-63,-63,-63,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-63,-63,-63,-62,-62,-62,-61,-61,-60,-60,
-	-59,-59,-58,-57,-56,-56,-55,-54,-53,-52,-51,-50,-49,-48,-47,-46,
-	-45,-44,-43,-42,-41,-39,-38,-37,-36,-34,-33,-32,-30,-29,-27,-26,
-	-24,-23,-22,-20,-19,-17,-16,-14,-12,-11, -9, -8, -6, -5, -3, -2
-};
-
-
-
-#if 1
-/** WARNING: use these! */
-/** JULIEN: Plus for XM compatibility it could be interesting to rename
- * it_sawtooth[] to it_rampdown[], and add an it_rampup[].
- * Also, still for XM compat', twood be good if it was possible to tell the
- * the player not to retrig' the waveform on a new instrument.
- * Both of these are only for completness though, as I don't think it would
- * be very noticeable ;)
- */
-/** ENTHEH: IT also has the 'don't retrig' thingy :) */
-static const signed char it_sawtooth[256] = {
-	 64, 63, 63, 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 56,
-	 56, 55, 55, 54, 54, 53, 53, 52, 52, 51, 51, 50, 50, 49, 49, 48,
-	 48, 47, 47, 46, 46, 45, 45, 44, 44, 43, 43, 42, 42, 41, 41, 40,
-	 40, 39, 39, 38, 38, 37, 37, 36, 36, 35, 35, 34, 34, 33, 33, 32,
-	 32, 31, 31, 30, 30, 29, 29, 28, 28, 27, 27, 26, 26, 25, 25, 24,
-	 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18, 17, 17, 16,
-	 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10,  9,  9,  8,
-	  8,  7,  7,  6,  6,  5,  5,  4,  4,  3,  3,  2,  2,  1,  1,  0,
-	  0, -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8,
-	 -8, -9, -9,-10,-10,-11,-11,-12,-12,-13,-13,-14,-14,-15,-15,-16,
-	-16,-17,-17,-18,-18,-19,-19,-20,-20,-21,-21,-22,-22,-23,-23,-24,
-	-24,-25,-25,-26,-26,-27,-27,-28,-28,-29,-29,-30,-30,-31,-31,-32,
-	-32,-33,-33,-34,-34,-35,-35,-36,-36,-37,-37,-38,-38,-39,-39,-40,
-	-40,-41,-41,-42,-42,-43,-43,-44,-44,-45,-45,-46,-46,-47,-47,-48,
-	-48,-49,-49,-50,-50,-51,-51,-52,-52,-53,-53,-54,-54,-55,-55,-56,
-	-56,-57,-57,-58,-58,-59,-59,-60,-60,-61,-61,-62,-62,-63,-63,-64
-};
-
-static const signed char it_squarewave[256] = {
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
-};
-
-static const signed char it_xm_ramp[256] = {
-	  0, -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, -8,
-	 -8, -9, -9,-10,-10,-11,-11,-12,-12,-13,-13,-14,-14,-15,-15,-16,
-	-16,-17,-17,-18,-18,-19,-19,-20,-20,-21,-21,-22,-22,-23,-23,-24,
-	-24,-25,-25,-26,-26,-27,-27,-28,-28,-29,-29,-30,-30,-31,-31,-32,
-	-32,-33,-33,-34,-34,-35,-35,-36,-36,-37,-37,-38,-38,-39,-39,-40,
-	-40,-41,-41,-42,-42,-43,-43,-44,-44,-45,-45,-46,-46,-47,-47,-48,
-	-48,-49,-49,-50,-50,-51,-51,-52,-52,-53,-53,-54,-54,-55,-55,-56,
-	-56,-57,-57,-58,-58,-59,-59,-60,-60,-61,-61,-62,-62,-63,-63,-64,
-	 64, 63, 63, 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 56,
-	 56, 55, 55, 54, 54, 53, 53, 52, 52, 51, 51, 50, 50, 49, 49, 48,
-	 48, 47, 47, 46, 46, 45, 45, 44, 44, 43, 43, 42, 42, 41, 41, 40,
-	 40, 39, 39, 38, 38, 37, 37, 36, 36, 35, 35, 34, 34, 33, 33, 32,
-	 32, 31, 31, 30, 30, 29, 29, 28, 28, 27, 27, 26, 26, 25, 25, 24,
-	 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18, 17, 17, 16,
-	 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10,  9,  9,  8,
-	  8,  7,  7,  6,  6,  5,  5,  4,  4,  3,  3,  2,  2,  1,  1,  0
-};
-
-static const signed char it_xm_squarewave[256] = {
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,
-	-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64,-64
-};
-
-#endif
-
-
-
-static void reset_tick_counts(DUMB_IT_SIGRENDERER *sigrenderer)
-{
-	int i;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		IT_CHANNEL *channel = &sigrenderer->channel[i];
-		channel->key_off_count = 0;
-		channel->note_cut_count = 0;
-		channel->note_delay_count = 0;
-	}
-}
-
-
-
-static const unsigned char arpeggio_mod[32] = {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1};
-static const unsigned char arpeggio_xm[32] = {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
-static const unsigned char arpeggio_okt_3[32] = {1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0};
-static const unsigned char arpeggio_okt_4[32] = {0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1};
-static const unsigned char arpeggio_okt_5[32] = {2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2};
-
-
-
-static void reset_channel_effects(IT_CHANNEL *channel)
-{
-	channel->volslide = 0;
-	channel->xm_volslide = 0;
-	channel->panslide = 0;
-	channel->channelvolslide = 0;
-	channel->arpeggio_table = (const unsigned char *) &arpeggio_mod;
-	memset(channel->arpeggio_offsets, 0, sizeof(channel->arpeggio_offsets));
-	channel->retrig = 0;
-	if (channel->xm_retrig) {
-		channel->xm_retrig = 0;
-		channel->retrig_tick = 0;
-	}
-	channel->tremor_time &= 127;
-	channel->portamento = 0;
-	channel->toneporta = 0;
-	if (channel->ptm_toneslide) {
-		channel->ptm_last_toneslide = channel->ptm_toneslide;
-		channel->last_toneslide_tick = channel->toneslide_tick;
-	} else
-		channel->ptm_last_toneslide = 0;
-	channel->ptm_toneslide = 0;
-	channel->toneslide_tick = 0;
-	channel->okt_toneslide = 0;
-	if (channel->playing) {
-		channel->playing->vibrato_n = 0;
-		channel->playing->tremolo_speed = 0;
-		channel->playing->tremolo_depth = 0;
-		channel->playing->panbrello_speed = 0;
-	}
-}
-
-static void reset_effects(DUMB_IT_SIGRENDERER *sigrenderer)
-{
-	int i;
-
-	sigrenderer->globalvolslide = 0;
-	sigrenderer->temposlide = 0;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		reset_channel_effects(&sigrenderer->channel[i]);
-	}
-}
-
-
-
-static void update_tremor(IT_CHANNEL *channel)
-{
-	if ((channel->tremor_time & 128) && channel->playing) {
-		if (channel->tremor_time == 128)
-			channel->tremor_time = (channel->lastI >> 4) | 192;
-		else if (channel->tremor_time == 192)
-			channel->tremor_time = (channel->lastI & 15) | 128;
-		else
-			channel->tremor_time--;
-	}
-}
-
-
-
-static void it_pickup_loop(DUMB_RESAMPLER *resampler, void *data)
-{
-	resampler->pos -= resampler->end - resampler->start;
-	((IT_PLAYING *)data)->time_lost += resampler->end - resampler->start;
-}
-
-
-
-static void it_pickup_pingpong_loop(DUMB_RESAMPLER *resampler, void *data)
-{
-	if (resampler->dir < 0) {
-		resampler->pos = (resampler->start << 1) - 1 - resampler->pos;
-		resampler->subpos ^= 65535;
-		resampler->dir = 1;
-		((IT_PLAYING *)data)->time_lost += (resampler->end - resampler->start) << 1;
-	} else {
-		resampler->pos = (resampler->end << 1) - 1 - resampler->pos;
-		resampler->subpos ^= 65535;
-		resampler->dir = -1;
-	}
-}
-
-
-
-static void it_pickup_stop_at_end(DUMB_RESAMPLER *resampler, void *data)
-{
-	(void)data;
-
-	if (resampler->dir < 0) {
-		resampler->pos = (resampler->start << 1) - 1 - resampler->pos;
-		resampler->subpos ^= 65535;
-		/* By rights, time_lost would be updated here. However, there is no
-		 * need at this point; it will not be used.
-		 *
-		 * ((IT_PLAYING *)data)->time_lost += (resampler->src_end - resampler->src_start) << 1;
-		 */
-		resampler->dir = 1;
-	} else
-		resampler->dir = 0;
-}
-
-
-
-static void it_pickup_stop_after_reverse(DUMB_RESAMPLER *resampler, void *data)
-{
-	(void)data;
-
-	resampler->dir = 0;
-}
-
-
-
-static void it_playing_update_resamplers(IT_PLAYING *playing)
-{
-	if ((playing->sample->flags & IT_SAMPLE_SUS_LOOP) && !(playing->flags & IT_PLAYING_SUSTAINOFF)) {
-		playing->resampler.start = playing->sample->sus_loop_start;
-		playing->resampler.end = playing->sample->sus_loop_end;
-		if (playing->resampler.start == playing->resampler.end)
-			playing->resampler.pickup = &it_pickup_stop_at_end;
-		else if (playing->sample->flags & IT_SAMPLE_PINGPONG_SUS_LOOP)
-			playing->resampler.pickup = &it_pickup_pingpong_loop;
-		else
-			playing->resampler.pickup = &it_pickup_loop;
-	} else if (playing->sample->flags & IT_SAMPLE_LOOP) {
-		playing->resampler.start = playing->sample->loop_start;
-		playing->resampler.end = playing->sample->loop_end;
-		if (playing->resampler.start == playing->resampler.end)
-			playing->resampler.pickup = &it_pickup_stop_at_end;
-		else if (playing->sample->flags & IT_SAMPLE_PINGPONG_LOOP)
-			playing->resampler.pickup = &it_pickup_pingpong_loop;
-		else
-			playing->resampler.pickup = &it_pickup_loop;
-	} else if (playing->flags & IT_PLAYING_REVERSE) {
-		playing->resampler.start = 0;
-		playing->resampler.end = playing->sample->length;
-		playing->resampler.dir = -1;
-		playing->resampler.pickup = &it_pickup_stop_after_reverse;
-	} else {
-		if (playing->sample->flags & IT_SAMPLE_SUS_LOOP)
-			playing->resampler.start = playing->sample->sus_loop_start;
-		else
-			playing->resampler.start = 0;
-		playing->resampler.end = playing->sample->length;
-		playing->resampler.pickup = &it_pickup_stop_at_end;
-	}
-	ASSERT(playing->resampler.pickup_data == playing);
-}
-
-
-
-/* This should be called whenever the sample or sample position changes. */
-static void it_playing_reset_resamplers(IT_PLAYING *playing, long pos)
-{
-	int bits = playing->sample->flags & IT_SAMPLE_16BIT ? 16 : 8;
-	int quality = playing->resampling_quality;
-	int channels = playing->sample->flags & IT_SAMPLE_STEREO ? 2 : 1;
-	if (playing->sample->max_resampling_quality >= 0 && quality > playing->sample->max_resampling_quality)
-		quality = playing->sample->max_resampling_quality;
-	dumb_reset_resampler_n(bits, &playing->resampler, playing->sample->data, channels, pos, 0, 0, quality);
-	playing->resampler.pickup_data = playing;
-	playing->time_lost = 0;
-	playing->flags &= ~IT_PLAYING_DEAD;
-	it_playing_update_resamplers(playing);
-}
-
-static void it_retrigger_note(DUMB_IT_SIGRENDERER *sigrenderer, IT_CHANNEL *channel);
-
-/* Should we only be retriggering short samples on XM? */
-
-static void update_retrig(DUMB_IT_SIGRENDERER *sigrenderer, IT_CHANNEL *channel)
-{
-	if (channel->xm_retrig) {
-		channel->retrig_tick--;
-		if (channel->retrig_tick <= 0) {
-			if (channel->playing) {
-				it_playing_reset_resamplers(channel->playing, 0);
-				channel->playing->declick_stage = 0;
-			} else if (sigrenderer->sigdata->flags & IT_WAS_AN_XM) it_retrigger_note(sigrenderer, channel);
-			channel->retrig_tick = channel->xm_retrig;
-		}
-	} else if (channel->retrig & 0x0F) {
-		channel->retrig_tick--;
-		if (channel->retrig_tick <= 0) {
-			if (channel->retrig < 0x10) {
-			} else if (channel->retrig < 0x20) {
-				channel->volume--;
-				if (channel->volume > 64) channel->volume = 0;
-			} else if (channel->retrig < 0x30) {
-				channel->volume -= 2;
-				if (channel->volume > 64) channel->volume = 0;
-			} else if (channel->retrig < 0x40) {
-				channel->volume -= 4;
-				if (channel->volume > 64) channel->volume = 0;
-			} else if (channel->retrig < 0x50) {
-				channel->volume -= 8;
-				if (channel->volume > 64) channel->volume = 0;
-			} else if (channel->retrig < 0x60) {
-				channel->volume -= 16;
-				if (channel->volume > 64) channel->volume = 0;
-			} else if (channel->retrig < 0x70) {
-				channel->volume <<= 1;
-				channel->volume /= 3;
-			} else if (channel->retrig < 0x80) {
-				channel->volume >>= 1;
-			} else if (channel->retrig < 0x90) {
-			} else if (channel->retrig < 0xA0) {
-				channel->volume++;
-				if (channel->volume > 64) channel->volume = 64;
-			} else if (channel->retrig < 0xB0) {
-				channel->volume += 2;
-				if (channel->volume > 64) channel->volume = 64;
-			} else if (channel->retrig < 0xC0) {
-				channel->volume += 4;
-				if (channel->volume > 64) channel->volume = 64;
-			} else if (channel->retrig < 0xD0) {
-				channel->volume += 8;
-				if (channel->volume > 64) channel->volume = 64;
-			} else if (channel->retrig < 0xE0) {
-				channel->volume += 16;
-				if (channel->volume > 64) channel->volume = 64;
-			} else if (channel->retrig < 0xF0) {
-				channel->volume *= 3;
-				channel->volume >>= 1;
-				if (channel->volume > 64) channel->volume = 64;
-			} else {
-				channel->volume <<= 1;
-				if (channel->volume > 64) channel->volume = 64;
-			}
-			if (channel->playing) {
-				it_playing_reset_resamplers(channel->playing, 0);
-				channel->playing->declick_stage = 0;
-			} else if (sigrenderer->sigdata->flags & IT_WAS_AN_XM) it_retrigger_note(sigrenderer, channel);
-			channel->retrig_tick = channel->retrig & 0x0F;
-		}
-	}
-}
-
-
-static void update_smooth_effects_playing(IT_PLAYING *playing)
-{
-	playing->vibrato_time += playing->vibrato_n *
-		(playing->vibrato_speed << 2);
-	playing->tremolo_time += playing->tremolo_speed << 2;
-	playing->panbrello_time += playing->panbrello_speed;
-	if (playing->panbrello_waveform == 3)
-		playing->panbrello_random = (rand() % 129) - 64;
-}
-
-static void update_smooth_effects(DUMB_IT_SIGRENDERER *sigrenderer)
-{
-	int i;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		IT_CHANNEL *channel = &sigrenderer->channel[i];
-		IT_PLAYING *playing = channel->playing;
-
-		if (playing) {
-			update_smooth_effects_playing(playing);
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-		IT_PLAYING *playing = sigrenderer->playing[i];
-
-		if (playing) {
-			update_smooth_effects_playing(playing);
-		}
-	}
-}
-
-
-static const unsigned char pt_tab_invloop[16] =
-{
-	0x00, 0x05, 0x06, 0x07, 0x08, 0x0A, 0x0B, 0x0D,
-	0x0F, 0x13, 0x16, 0x1A, 0x20, 0x2B, 0x40, 0x80
-};
-
-static void update_invert_loop(IT_CHANNEL *channel, IT_SAMPLE *sample)
-{
-	channel->inv_loop_delay += pt_tab_invloop[channel->inv_loop_speed];
-	if (channel->inv_loop_delay >= 0x80)
-	{
-		channel->inv_loop_delay = 0;
-
-		if (sample && ((sample->flags & (IT_SAMPLE_EXISTS | IT_SAMPLE_LOOP)) == (IT_SAMPLE_EXISTS | IT_SAMPLE_LOOP)) && !(sample->flags & (IT_SAMPLE_STEREO | IT_SAMPLE_16BIT)))
-		{
-			if (sample->loop_end - sample->loop_start >= 4)
-			{
-				channel->inv_loop_offset++;
-				if (channel->inv_loop_offset >= (sample->loop_end - sample->loop_start)) channel->inv_loop_offset = 0;
-
-				((char *)sample->data)[sample->loop_start + channel->inv_loop_offset] ^= 0xFF;
-			}
-		}
-	}
-}
-
-
-static void update_playing_effects(IT_PLAYING *playing)
-{
-	IT_CHANNEL *channel = playing->channel;
-
-	if (channel->channelvolslide) {
-		playing->channel_volume = channel->channelvolume;
-	}
-
-	if (channel->okt_toneslide) {
-		if (channel->okt_toneslide--) {
-			playing->note += channel->toneslide;
-			if (playing->note >= 120) {
-				if (channel->toneslide < 0) playing->note = 0;
-				else playing->note = 119;
-			}
-		}
-	} else if (channel->ptm_toneslide) {
-		if (--channel->toneslide_tick == 0) {
-			channel->toneslide_tick = channel->ptm_toneslide;
-			if (playing) {
-				playing->note += channel->toneslide;
-				if (playing->note >= 120) {
-					if (channel->toneslide < 0) playing->note = 0;
-					else playing->note = 119;
-				}
-				if (channel->playing == playing) {
-					channel->note = channel->truenote = playing->note;
-				}
-				if (channel->toneslide_retrig) {
-					it_playing_reset_resamplers(playing, 0);
-					playing->declick_stage = 0;
-				}
-			}
-		}
-	}
-}
-
-
-static void update_effects(DUMB_IT_SIGRENDERER *sigrenderer)
-{
-    int i;
-
-	if (sigrenderer->globalvolslide) {
-		sigrenderer->globalvolume += sigrenderer->globalvolslide;
-		if (sigrenderer->globalvolume > 128) {
-			if (sigrenderer->globalvolslide >= 0)
-				sigrenderer->globalvolume = 128;
-			else
-				sigrenderer->globalvolume = 0;
-		}
-	}
-
-	if (sigrenderer->temposlide) {
-		sigrenderer->tempo += sigrenderer->temposlide;
-		if (sigrenderer->tempo < 32) {
-			if (sigrenderer->temposlide >= 0)
-				sigrenderer->tempo = 255;
-			else
-				sigrenderer->tempo = 32;
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		IT_CHANNEL *channel = &sigrenderer->channel[i];
-		IT_PLAYING *playing = channel->playing;
-
-		if (channel->xm_volslide) {
-			channel->volume += channel->xm_volslide;
-			if (channel->volume > 64) {
-				if (channel->xm_volslide >= 0)
-					channel->volume = 64;
-				else
-					channel->volume = 0;
-			}
-		}
-
-		if (channel->volslide) {
-			int clip = (sigrenderer->sigdata->flags & IT_WAS_AN_S3M) ? 63 : 64;
-			channel->volume += channel->volslide;
-			if (channel->volume > clip) {
-				if (channel->volslide >= 0)
-					channel->volume = clip;
-				else
-					channel->volume = 0;
-			}
-		}
-
-		if (channel->panslide) {
-			if (sigrenderer->sigdata->flags & IT_WAS_AN_XM) {
-				if (IT_IS_SURROUND(channel->pan))
-				{
-					channel->pan = 32;
-					channel->truepan = 32 + 128 * 64;
-				}
-				if (channel->panslide == -128)
-					channel->truepan = 32;
-				else
-					channel->truepan = MID(32, channel->truepan + channel->panslide*64, 32+255*64);
-			} else {
-				if (IT_IS_SURROUND(channel->pan))
-				{
-					channel->pan = 32;
-				}
-				channel->pan += channel->panslide;
-				if (channel->pan > 64) {
-					if (channel->panslide >= 0)
-						channel->pan = 64;
-					else
-						channel->pan = 0;
-				}
-				channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
-			}
-		}
-
-		if (channel->channelvolslide) {
-			channel->channelvolume += channel->channelvolslide;
-			if (channel->channelvolume > 64) {
-				if (channel->channelvolslide >= 0)
-					channel->channelvolume = 64;
-				else
-					channel->channelvolume = 0;
-			}
-		}
-
-		update_tremor(channel);
-
-		update_retrig(sigrenderer, channel);
-
-		if (channel->inv_loop_speed) update_invert_loop(channel, playing ? playing->sample : NULL);
-
-		if (playing) {
-			playing->slide += channel->portamento;
-
-			if (sigrenderer->sigdata->flags & IT_LINEAR_SLIDES) {
-				if (channel->toneporta && channel->destnote < 120) {
-					int currpitch = ((playing->note - 60) << 8) + playing->slide;
-					int destpitch = (channel->destnote - 60) << 8;
-					if (currpitch > destpitch) {
-						currpitch -= channel->toneporta;
-						if (currpitch < destpitch) {
-							currpitch = destpitch;
-							channel->destnote = IT_NOTE_OFF;
-						}
-					} else if (currpitch < destpitch) {
-						currpitch += channel->toneporta;
-						if (currpitch > destpitch) {
-							currpitch = destpitch;
-							channel->destnote = IT_NOTE_OFF;
-						}
-					}
-					playing->slide = currpitch - ((playing->note - 60) << 8);
-				}
-			} else {
-				if (channel->toneporta && channel->destnote < 120) {
-					float amiga_multiplier = playing->sample->C5_speed * (1.0f / AMIGA_DIVISOR);
-
-					float deltanote = (float)pow(DUMB_SEMITONE_BASE, 60 - playing->note);
-					/* deltanote is 1.0 for C-5, 0.5 for C-6, etc. */
-
-					float deltaslid = deltanote - playing->slide * amiga_multiplier;
-
-					float destdelta = (float)pow(DUMB_SEMITONE_BASE, 60 - channel->destnote);
-					if (deltaslid < destdelta) {
-						playing->slide -= channel->toneporta;
-						deltaslid = deltanote - playing->slide * amiga_multiplier;
-						if (deltaslid > destdelta) {
-							playing->note = channel->destnote;
-							playing->slide = 0;
-							channel->destnote = IT_NOTE_OFF;
-						}
-					} else {
-						playing->slide += channel->toneporta;
-						deltaslid = deltanote - playing->slide * amiga_multiplier;
-						if (deltaslid < destdelta) {
-							playing->note = channel->destnote;
-							playing->slide = 0;
-							channel->destnote = IT_NOTE_OFF;
-						}
-					}
-				}
-			}
-
-			update_playing_effects(playing);
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-		IT_PLAYING *playing = sigrenderer->playing[i];
-		if (playing) update_playing_effects(playing);
-	}
-
-	update_smooth_effects(sigrenderer);
-}
-
-
-static void it_note_off(IT_PLAYING *playing);
-
-// This function should be renamed; it doesn't do the 'Update Pattern Variables' operation ittech.txt describes
-/* Returns 1 if a pattern loop is happening. */
-static int update_pattern_variables(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry)
-{
-	IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
-
-	if (entry->mask & IT_ENTRY_EFFECT) {
-		switch (entry->effect) {
-			case IT_JUMP_TO_ORDER:
-				/* XXX jump and break in same row */
-				if ( ( ( sigrenderer->processrow | 0xC00 ) == 0xFFFE ) &&
-					! ( sigrenderer->processrow & 0x800 ) ) {
-					sigrenderer->processrow = 0xFFFE & ~0xC00;
-				} else {
-					sigrenderer->breakrow = 0;
-					sigrenderer->processrow = 0xFFFE & ~0x400;
-				}
-				sigrenderer->processorder = entry->effectvalue - 1;
-				break;
-
-			case IT_S:
-				{
-					unsigned char effectvalue = entry->effectvalue;
-					if (sigrenderer->sigdata->flags & IT_WAS_AN_S3M) {
-						if (effectvalue == 0)
-							effectvalue = channel->lastDKL;
-						channel->lastDKL = effectvalue;
-					} else {
-						if (effectvalue == 0)
-							effectvalue = channel->lastS;
-					}
-					channel->lastS = effectvalue;
-					switch (effectvalue >> 4) {
-						case IT_S_PATTERN_LOOP:
-							{
-								unsigned char v = effectvalue & 15;
-								if (v == 0) {
-#ifdef BIT_ARRAY_BULLSHIT
-									if (!channel->played_patjump)
-										channel->played_patjump = bit_array_create(256);
-									else {
-										if ( channel->played_patjump_order != 0xFFFE && channel->played_patjump_order != sigrenderer->order )
-											bit_array_merge(sigrenderer->played, channel->played_patjump, channel->played_patjump_order * 256);
-										//if (channel->played_patjump_order != sigrenderer->order)
-											bit_array_reset(channel->played_patjump);
-									}
-									channel->played_patjump_order = sigrenderer->order;
-#endif
-									channel->pat_loop_row = sigrenderer->processrow;
-								} else {
-									if (channel->pat_loop_count == 0) {
-#ifdef BIT_ARRAY_BULLSHIT
-										/* wft, uninitialized and no start marker yet... */
-										if (channel->played_patjump_order == 0xFFFE) {
-											int n;
-											bit_array_destroy(channel->played_patjump);
-											channel->played_patjump = bit_array_create(256);
-											for (n = channel->pat_loop_row; n <= sigrenderer->row; n++)
-												bit_array_clear(sigrenderer->played, sigrenderer->order * 256 + n);
-											channel->played_patjump_order = sigrenderer->order;
-										} else if (channel->played_patjump_order == sigrenderer->order) {
-											bit_array_set(channel->played_patjump, sigrenderer->row);
-											bit_array_mask(sigrenderer->played, channel->played_patjump, channel->played_patjump_order * 256);
-											//bit_array_reset(channel->played_patjump);
-										}
-#endif
-										channel->pat_loop_count = v;
-										sigrenderer->breakrow = channel->pat_loop_row;
-										if ((sigrenderer->sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_MOD)) == IT_WAS_AN_XM) {
-											/* For XM files, if a loop occurs by itself, keep breakrow set for when the pattern ends - fun bug in FT2! */
-											if ((sigrenderer->processrow|0xC00) < 0xFFFE) {
-												/* Infinite pattern loops are possible, so we check whether the pattern loop we're hitting now is earlier than the last one we hit. */
-												if (sigrenderer->processrow < channel->pat_loop_end_row)
-													sigrenderer->processorder = 0xFFFE; /* suspect infinite loop, so trigger loop callback */
-												else
-													sigrenderer->processorder = 0xFFFF; /* don't trigger loop callback */
-												channel->pat_loop_end_row = sigrenderer->processrow;
-												sigrenderer->processrow = 0xFFFF; /* special case: don't reset breakrow or pat_loop_end_row */
-											}
-										} else {
-											/* IT files do this regardless of other flow control effects seen here. */
-											sigrenderer->processorder = 0xFFFF; /* special case: don't trigger loop callback */
-											sigrenderer->processrow = 0xFFFE;
-										}
-										return 1;
-									} else if (--channel->pat_loop_count) {
-#ifdef BIT_ARRAY_BULLSHIT
-										if (channel->played_patjump_order == sigrenderer->order) {
-											bit_array_set(channel->played_patjump, sigrenderer->row);
-											bit_array_mask(sigrenderer->played, channel->played_patjump, channel->played_patjump_order * 256);
-											//bit_array_reset(channel->played_patjump);
-										}
-#endif
-										sigrenderer->breakrow = channel->pat_loop_row;
-										if ((sigrenderer->sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_MOD)) == IT_WAS_AN_XM) {
-											/* For XM files, if a loop occurs by itself, keep breakrow set for when the pattern ends - fun bug in FT2! */
-											if ((sigrenderer->processrow|0xC00) < 0xFFFE) {
-												/* Infinite pattern loops are possible, so we check whether the pattern loop we're hitting now is earlier than the last one we hit. */
-												if (sigrenderer->processrow < channel->pat_loop_end_row)
-													sigrenderer->processorder = 0xFFFE; /* suspect infinite loop, so trigger loop callback */
-												else
-													sigrenderer->processorder = 0xFFFF; /* don't trigger loop callback */
-												channel->pat_loop_end_row = sigrenderer->processrow;
-												sigrenderer->processrow = 0xFFFF; /* special case: don't reset breakrow or pat_loop_end_row */
-											}
-										} else {
-											/* IT files do this regardless of other flow control effects seen here. */
-											sigrenderer->processorder = 0xFFFF; /* special case: don't trigger loop callback */
-											sigrenderer->processrow = 0xFFFE;
-										}
-										return 1;
-									} else if ((sigrenderer->sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_MOD)) == IT_WAS_AN_XM) {
-										channel->pat_loop_end_row = 0;
-										// TODO
-										/* Findings:
-										- If a pattern loop completes successfully, and then the pattern terminates, then the next pattern will start on the row corresponding to the E60.
-										- If a pattern loop doesn't do any loops, and then the pattern terminates, then the next pattern will start on the first row.
-										- If a break appears to the left of the pattern loop, it jumps into the relevant position in the next pattern, and that's it.
-										- If a break appears to the right of the pattern loop, it jumps to the start of the next pattern, and that's it.
-										- If we jump, then effect a loop using an old E60, and then the pattern ends, the next pattern starts on the row corresponding to the E60.
-										- Theory: breakrow is not cleared when it's a pattern loop effect!
-										*/
-										if ((sigrenderer->processrow | 0xC00) < 0xFFFE) // I have no idea if this is correct or not - FT2 is so weird :(
-											sigrenderer->breakrow = channel->pat_loop_row; /* emulate bug in FT2 */
-									} else
-										channel->pat_loop_row = sigrenderer->processrow + 1;
-#ifdef BIT_ARRAY_BULLSHIT
-									/*channel->played_patjump_order |= 0x8000;*/
-									if (channel->played_patjump_order == sigrenderer->order) {
-										bit_array_destroy(channel->played_patjump);
-										channel->played_patjump = 0;
-										channel->played_patjump_order = 0xFFFE;
-									}
-									bit_array_clear(sigrenderer->played, sigrenderer->order * 256 + sigrenderer->row);
-#endif
-								}
-							}
-							break;
-						case IT_S_PATTERN_DELAY:
-							sigrenderer->rowcount = 1 + (effectvalue & 15);
-							break;
-					}
-				}
-		}
-	}
-
-	return 0;
-}
-
-
-
-/* This function guarantees that channel->sample will always be valid if it
- * is nonzero. In other words, to check if it is valid, simply check if it is
- * nonzero.
- */
-static void instrument_to_sample(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel)
-{
-	if (sigdata->flags & IT_USE_INSTRUMENTS) {
-		if (channel->instrument >= 1 && channel->instrument <= sigdata->n_instruments) {
-			if (channel->note < 120) {
-				channel->sample = sigdata->instrument[channel->instrument-1].map_sample[channel->note];
-				channel->truenote = sigdata->instrument[channel->instrument-1].map_note[channel->note];
-			} else
-				channel->sample = 0;
-		} else
-			channel->sample = 0;
-	} else {
-		channel->sample = channel->instrument;
-		channel->truenote = channel->note;
-	}
-	if (!(channel->sample >= 1 && channel->sample <= sigdata->n_samples && (sigdata->sample[channel->sample-1].flags & IT_SAMPLE_EXISTS) && sigdata->sample[channel->sample-1].C5_speed))
-		channel->sample = 0;
-}
-
-
-
-static void fix_sample_looping(IT_PLAYING *playing)
-{
-	if ((playing->sample->flags & (IT_SAMPLE_LOOP | IT_SAMPLE_SUS_LOOP)) ==
-	                              (IT_SAMPLE_LOOP | IT_SAMPLE_SUS_LOOP)) {
-		if (playing->resampler.dir < 0) {
-			playing->resampler.pos = (playing->sample->sus_loop_end << 1) - 1 - playing->resampler.pos;
-			playing->resampler.subpos ^= 65535;
-			playing->resampler.dir = 1;
-		}
-
-		playing->resampler.pos += playing->time_lost;
-		// XXX what
-		playing->time_lost = 0;
-	}
-}
-
-
-
-static void it_compatible_gxx_retrigger(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel)
-{
-	int flags = 0;
-	if (channel->sample) {
-		if (sigdata->flags & IT_USE_INSTRUMENTS) {
-			if (!(channel->playing->flags & IT_PLAYING_SUSTAINOFF)) {
-				if (channel->playing->env_instrument->volume_envelope.flags & IT_ENVELOPE_CARRY)
-					flags |= 1;
-				if (channel->playing->env_instrument->pan_envelope.flags & IT_ENVELOPE_CARRY)
-					flags |= 2;
-				if (channel->playing->env_instrument->pitch_envelope.flags & IT_ENVELOPE_CARRY)
-					flags |= 4;
-			}
-		}
-	}
-	if (!(flags & 1)) {
-		channel->playing->volume_envelope.next_node = 0;
-		channel->playing->volume_envelope.tick = 0;
-	}
-	if (!(flags & 2)) {
-		channel->playing->pan_envelope.next_node = 0;
-		channel->playing->pan_envelope.tick = 0;
-	}
-	if (!(flags & 4)) {
-		channel->playing->pitch_envelope.next_node = 0;
-		channel->playing->pitch_envelope.tick = 0;
-	}
-	channel->playing->fadeoutcount = 1024;
-	// Should we remove IT_PLAYING_BACKGROUND? Test with sample with sustain loop...
-	channel->playing->flags &= ~(IT_PLAYING_BACKGROUND | IT_PLAYING_SUSTAINOFF | IT_PLAYING_FADING | IT_PLAYING_DEAD);
-	it_playing_update_resamplers(channel->playing);
-
-	if (!flags && channel->sample)
-		if (sigdata->flags & IT_USE_INSTRUMENTS)
-			channel->playing->env_instrument = &sigdata->instrument[channel->instrument-1];
-}
-
-
-
-static void it_note_off(IT_PLAYING *playing)
-{
-	if (playing) {
-		playing->enabled_envelopes |= IT_ENV_VOLUME;
-		playing->flags |= IT_PLAYING_BACKGROUND | IT_PLAYING_SUSTAINOFF;
-		fix_sample_looping(playing);
-		it_playing_update_resamplers(playing);
-		if (playing->instrument)
-			if ((playing->instrument->volume_envelope.flags & (IT_ENVELOPE_ON | IT_ENVELOPE_LOOP_ON)) != IT_ENVELOPE_ON)
-				playing->flags |= IT_PLAYING_FADING;
-	}
-}
-
-
-
-static void xm_note_off(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel)
-{
-	if (channel->playing) {
-		if (!channel->instrument || channel->instrument > sigdata->n_instruments ||
-			!(sigdata->instrument[channel->instrument-1].volume_envelope.flags & IT_ENVELOPE_ON))
-			//if (!(entry->mask & IT_ENTRY_INSTRUMENT))
-			// dunno what that was there for ...
-				channel->volume = 0;
-		channel->playing->flags |= IT_PLAYING_SUSTAINOFF | IT_PLAYING_FADING;
-		it_playing_update_resamplers(channel->playing);
-	}
-}
-
-
-static void recalculate_it_envelope_node(IT_PLAYING_ENVELOPE *pe, IT_ENVELOPE *e)
-{
-	int envpos = pe->tick;
-	unsigned int pt = e->n_nodes - 1;
-	unsigned int i;
-	for (i = 0; i < (unsigned int)(e->n_nodes - 1); ++i)
-	{
-		if (envpos <= e->node_t[i])
-		{
-			pt = i;
-			break;
-		}
-	}
-	pe->next_node = pt;
-}
-
-
-static void recalculate_it_envelope_nodes(IT_PLAYING *playing)
-{
-	recalculate_it_envelope_node(&playing->volume_envelope, &playing->env_instrument->volume_envelope);
-	recalculate_it_envelope_node(&playing->pan_envelope, &playing->env_instrument->pitch_envelope);
-	recalculate_it_envelope_node(&playing->pitch_envelope, &playing->env_instrument->pitch_envelope);
-}
-
-
-static void it_retrigger_note(DUMB_IT_SIGRENDERER *sigrenderer, IT_CHANNEL *channel)
-{
-	int vol_env_tick = 0;
-	int pan_env_tick = 0;
-	int pitch_env_tick = 0;
-
-	DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
-	unsigned char nna = ~0;
-	int i, envelopes_copied = 0;
-
-	if (channel->playing) {
-		if (channel->note == IT_NOTE_CUT)
-			nna = NNA_NOTE_CUT;
-		else if (channel->note == IT_NOTE_OFF)
-			nna = NNA_NOTE_OFF;
-		else if (channel->note > 120)
-			nna = NNA_NOTE_FADE;
-		else if (!channel->playing->instrument || (channel->playing->flags & IT_PLAYING_DEAD))
-			nna = NNA_NOTE_CUT;
-		else if (channel->new_note_action != 0xFF)
-		{
-			nna = channel->new_note_action;
-		}
-		else
-			nna = channel->playing->instrument->new_note_action;
-
-		if (!(channel->playing->flags & IT_PLAYING_SUSTAINOFF))
-		{
-			if (nna != NNA_NOTE_CUT)
-				vol_env_tick = channel->playing->volume_envelope.tick;
-			pan_env_tick = channel->playing->pan_envelope.tick;
-			pitch_env_tick = channel->playing->pitch_envelope.tick;
-			envelopes_copied = 1;
-		}
-
-		switch (nna) {
-			case NNA_NOTE_CUT:
-				channel->playing->declick_stage = 3;
-				break;
-			case NNA_NOTE_OFF:
-				it_note_off(channel->playing);
-				break;
-			case NNA_NOTE_FADE:
-				channel->playing->flags |= IT_PLAYING_BACKGROUND | IT_PLAYING_FADING;
-				break;
-		}
-	}
-
-	channel->new_note_action = 0xFF;
-
-	if (channel->sample == 0 || channel->note > 120)
-		return;
-
-	channel->destnote = IT_NOTE_OFF;
-
-	if (channel->playing) {
-		for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-			if (!sigrenderer->playing[i]) {
-				sigrenderer->playing[i] = channel->playing;
-				channel->playing = NULL;
-				break;
-			}
-		}
-
-		if (sigrenderer->sigdata->flags & IT_USE_INSTRUMENTS)
-		{
-			for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-				IT_PLAYING * playing = sigrenderer->playing[i];
-				if (playing && playing->channel == channel && playing->instrument->dup_check_type) {
-					int match = 1;
-					switch (playing->instrument->dup_check_type)
-					{
-					case DCT_NOTE:
-						match = (channel->truenote == playing->note);
-					case DCT_SAMPLE:
-						match = match && (channel->sample == playing->sampnum);
-					case DCT_INSTRUMENT:
-						match = match && (channel->instrument == playing->instnum);
-						break;
-					}
-
-					if (match)
-					{
-						switch (playing->instrument->dup_check_action)
-						{
-						case DCA_NOTE_CUT:
-							playing->declick_stage = 3;
-							if (channel->playing == playing) channel->playing = NULL;
-							break;
-						case DCA_NOTE_OFF:
-							if (!(playing->flags & IT_PLAYING_SUSTAINOFF))
-								it_note_off(playing);
-							break;
-						case DCA_NOTE_FADE:
-							playing->flags |= IT_PLAYING_BACKGROUND | IT_PLAYING_FADING;
-							break;
-						}
-					}
-				}
-			}
-		}
-
-/** WARNING - come up with some more heuristics for replacing old notes */
-#if 0
-		if (channel->playing) {
-			for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-				if (sigrenderer->playing[i]->flags & IT_PLAYING_BACKGROUND) {
-					write_seqtime();
-					sequence_c(SEQUENCE_STOP_SIGNAL);
-					sequence_c(i);
-					channel->VChannel = &module->VChannel[i];
-					break;
-				}
-			}
-		}
-#endif
-	}
-
-	if (channel->playing)
-		free_playing(channel->playing);
-
-	channel->playing = new_playing();
-
-	if (!channel->playing)
-		return;
-
-	if (!envelopes_copied && sigdata->flags & IT_USE_INSTRUMENTS) {
-		for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-			IT_PLAYING * playing = sigrenderer->playing[i];
-			if (!playing || playing->channel != channel) continue;
-			if (playing->flags & IT_PLAYING_SUSTAINOFF) continue;
-			if (nna != NNA_NOTE_CUT)
-				vol_env_tick = playing->volume_envelope.tick;
-			pan_env_tick = playing->pan_envelope.tick;
-			pitch_env_tick = playing->pitch_envelope.tick;
-			envelopes_copied = 1;
-			break;
-		}
-	}				
-
-	channel->playing->flags = 0;
-	channel->playing->resampling_quality = sigrenderer->resampling_quality;
-	channel->playing->channel = channel;
-	channel->playing->sample = &sigdata->sample[channel->sample-1];
-	if (sigdata->flags & IT_USE_INSTRUMENTS)
-		channel->playing->instrument = &sigdata->instrument[channel->instrument-1];
-	else
-		channel->playing->instrument = NULL;
-	channel->playing->env_instrument = channel->playing->instrument;
-	channel->playing->sampnum = channel->sample;
-	channel->playing->instnum = channel->instrument;
-	channel->playing->declick_stage = 0;
-	channel->playing->channel_volume = channel->channelvolume;
-	channel->playing->note = channel->truenote;
-	channel->playing->enabled_envelopes = 0;
-	channel->playing->volume_offset = 0;
-	channel->playing->panning_offset = 0;
-	//channel->playing->output = channel->output;
-	if (sigdata->flags & IT_USE_INSTRUMENTS) {
-		IT_PLAYING * playing = channel->playing;
-		IT_INSTRUMENT * instrument = playing->instrument;
-		if (instrument->volume_envelope.flags & IT_ENVELOPE_ON) playing->enabled_envelopes |= IT_ENV_VOLUME;
-		if (instrument->pan_envelope.flags & IT_ENVELOPE_ON) playing->enabled_envelopes |= IT_ENV_PANNING;
-		if (instrument->pitch_envelope.flags & IT_ENVELOPE_ON) playing->enabled_envelopes |= IT_ENV_PITCH;
-		if (instrument->random_volume) playing->volume_offset = (rand() % (instrument->random_volume * 2 + 1)) - instrument->random_volume;
-		if (instrument->random_pan) playing->panning_offset = (rand() % (instrument->random_pan * 2 + 1)) - instrument->random_pan;
-		//if (instrument->output) playing->output = instrument->output;
-	}
-	channel->playing->filter_cutoff = 127;
-	channel->playing->filter_resonance = 0;
-	channel->playing->true_filter_cutoff = 127 << 8;
-	channel->playing->true_filter_resonance = 0;
-	channel->playing->vibrato_speed = 0;
-	channel->playing->vibrato_depth = 0;
-	channel->playing->vibrato_n = 0;
-	channel->playing->vibrato_time = 0;
-	channel->playing->vibrato_waveform = channel->vibrato_waveform;
-	channel->playing->tremolo_speed = 0;
-	channel->playing->tremolo_depth = 0;
-	channel->playing->tremolo_time = 0;
-	channel->playing->tremolo_waveform = channel->tremolo_waveform;
-	channel->playing->panbrello_speed = 0;
-	channel->playing->panbrello_depth = 0;
-	channel->playing->panbrello_time = 0;
-	channel->playing->panbrello_waveform = channel->panbrello_waveform;
-	channel->playing->panbrello_random = 0;
-	channel->playing->sample_vibrato_time = 0;
-	channel->playing->sample_vibrato_waveform = channel->playing->sample->vibrato_waveform;
-	channel->playing->sample_vibrato_depth = 0;
-	channel->playing->slide = 0;
-	channel->playing->finetune = channel->playing->sample->finetune;
-
-	if (sigdata->flags & IT_USE_INSTRUMENTS)
-	{
-		if (envelopes_copied && channel->playing->env_instrument->volume_envelope.flags & IT_ENVELOPE_CARRY) {
-			channel->playing->volume_envelope.tick = vol_env_tick;
-		} else {
-			channel->playing->volume_envelope.tick = 0;
-		}
-		if (envelopes_copied && channel->playing->env_instrument->pan_envelope.flags & IT_ENVELOPE_CARRY) {
-			channel->playing->pan_envelope.tick = pan_env_tick;
-		} else {
-			channel->playing->pan_envelope.tick = 0;
-		}
-		if (envelopes_copied && channel->playing->env_instrument->pitch_envelope.flags & IT_ENVELOPE_CARRY) {
-			channel->playing->pitch_envelope.tick = pitch_env_tick;
-		} else {
-			channel->playing->pitch_envelope.tick = 0;
-		}
-		recalculate_it_envelope_nodes(channel->playing);
-	}
-	channel->playing->fadeoutcount = 1024;
-	it_reset_filter_state(&channel->playing->filter_state[0]);
-	it_reset_filter_state(&channel->playing->filter_state[1]);
-	it_playing_reset_resamplers(channel->playing, 0);
-
-	/** WARNING - is everything initialised? */
-}
-
-
-
-static void get_default_volpan(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel)
-{
-	if (channel->sample == 0)
-		return;
-
-	channel->volume = sigdata->sample[channel->sample-1].default_volume;
-
-	if (sigdata->flags & IT_WAS_AN_XM) {
-		if (!(sigdata->flags & IT_WAS_A_MOD))
-			channel->truepan = 32 + sigdata->sample[channel->sample-1].default_pan*64;
-		return;
-	}
-
-	{
-		int pan = sigdata->sample[channel->sample-1].default_pan;
-		if (pan >= 128 && pan <= 192) {
-			channel->pan = pan - 128;
-			return;
-		}
-	}
-
-	if (sigdata->flags & IT_USE_INSTRUMENTS) {
-		IT_INSTRUMENT *instrument = &sigdata->instrument[channel->instrument-1];
-		if (instrument->default_pan <= 64)
-			channel->pan = instrument->default_pan;
-		if (instrument->filter_cutoff >= 128)
-			channel->filter_cutoff = instrument->filter_cutoff - 128;
-		if (instrument->filter_resonance >= 128)
-			channel->filter_resonance = instrument->filter_resonance - 128;
-	}
-}
-
-
-
-static void get_true_pan(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel)
-{
-	channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
-
-	if (channel->sample && !IT_IS_SURROUND_SHIFTED(channel->truepan) && (sigdata->flags & IT_USE_INSTRUMENTS)) {
-		IT_INSTRUMENT *instrument = &sigdata->instrument[channel->instrument-1];
-		int truepan = channel->truepan;
-		truepan += (channel->note - instrument->pp_centre) * instrument->pp_separation << (IT_ENVELOPE_SHIFT - 3);
-		channel->truepan = (unsigned short)MID(0, truepan, 64 << IT_ENVELOPE_SHIFT);
-	}
-}
-
-
-
-static void post_process_it_volpan(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry)
-{
-	IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
-
-	if (entry->mask & IT_ENTRY_VOLPAN) {
-		if (entry->volpan <= 84) {
-			/* Volume */
-			/* Fine volume slide up */
-			/* Fine volume slide down */
-		} else if (entry->volpan <= 94) {
-			/* Volume slide up */
-			unsigned char v = entry->volpan - 85;
-			if (v == 0)
-				v = channel->lastvolslide;
-			channel->lastvolslide = v;
-			/* = effect Dx0 where x == entry->volpan - 85 */
-			channel->volslide += v;
-		} else if (entry->volpan <= 104) {
-			/* Volume slide down */
-			unsigned char v = entry->volpan - 95;
-			if (v == 0)
-				v = channel->lastvolslide;
-			channel->lastvolslide = v;
-			/* = effect D0x where x == entry->volpan - 95 */
-			channel->volslide -= v;
-		} else if (entry->volpan <= 114) {
-			/* Portamento down */
-			unsigned char v = (entry->volpan - 105) << 2;
-			if (v == 0)
-				v = channel->lastEF;
-			channel->lastEF = v;
-			channel->portamento -= v << 4;
-		} else if (entry->volpan <= 124) {
-			/* Portamento up */
-			unsigned char v = (entry->volpan - 115) << 2;
-			if (v == 0)
-				v = channel->lastEF;
-			channel->lastEF = v;
-			channel->portamento += v << 4;
-		} else if (entry->volpan <= 202) {
-			/* Pan */
-			/* Tone Portamento */
-		} else if (entry->volpan <= 212) {
-			/* Vibrato */
-			/* This is unaffected by IT_OLD_EFFECTS. However, if v == 0, then any doubling of depth that happened before (with Hxy in the effect column) will be preserved. */
-			unsigned char v = entry->volpan - 203;
-			if (v == 0)
-				v = channel->lastHdepth;
-			else {
-				v <<= 2;
-				channel->lastHdepth = v;
-			}
-			if (channel->playing) {
-				channel->playing->vibrato_speed = channel->lastHspeed;
-				channel->playing->vibrato_depth = v;
-				channel->playing->vibrato_n++;
-			}
-		}
-	}
-}
-
-
-
-static void it_send_midi(DUMB_IT_SIGRENDERER *sigrenderer, IT_CHANNEL *channel, unsigned char midi_byte)
-{
-	if (sigrenderer->callbacks->midi)
-		if ((*sigrenderer->callbacks->midi)(sigrenderer->callbacks->midi_data, (int)(channel - sigrenderer->channel), midi_byte))
-			return;
-
-	switch (channel->midi_state) {
-		case 4: /* Ready to receive resonance parameter */
-			if (midi_byte < 0x80) channel->filter_resonance = midi_byte;
-			channel->midi_state = 0;
-			break;
-		case 3: /* Ready to receive cutoff parameter */
-			if (midi_byte < 0x80) channel->filter_cutoff = midi_byte;
-			channel->midi_state = 0;
-			break;
-		case 2: /* Ready for byte specifying which parameter will follow */
-			if (midi_byte == 0) /* Cutoff */
-				channel->midi_state = 3;
-			else if (midi_byte == 1) /* Resonance */
-				channel->midi_state = 4;
-			else
-				channel->midi_state = 0;
-			break;
-		default: /* Counting initial F0 bytes */
-			switch (midi_byte) {
-				case 0xF0:
-					channel->midi_state++;
-					break;
-				case 0xFA:
-				case 0xFC:
-				case 0xFF:
-					/* Reset filter parameters for all channels */
-					{
-						int i;
-						for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-							sigrenderer->channel[i].filter_cutoff = 127;
-							sigrenderer->channel[i].filter_resonance = 0;
-							//// should we be resetting channel[i].playing->filter_* here?
-						}
-					}
-					/* Fall through */
-				default:
-					channel->midi_state = 0;
-					break;
-			}
-	}
-}
-
-
-
-static void xm_envelope_calculate_value(IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe)
-{
-	if (pe->next_node <= 0)
-		pe->value = envelope->node_y[0] << IT_ENVELOPE_SHIFT;
-	else if (pe->next_node >= envelope->n_nodes)
-		pe->value = envelope->node_y[envelope->n_nodes-1] << IT_ENVELOPE_SHIFT;
-	else {
-		int ys = envelope->node_y[pe->next_node-1] << IT_ENVELOPE_SHIFT;
-		int ts = envelope->node_t[pe->next_node-1];
-		int te = envelope->node_t[pe->next_node];
-
-		if (ts == te)
-			pe->value = ys;
-		else {
-			int ye = envelope->node_y[pe->next_node] << IT_ENVELOPE_SHIFT;
-			int t = pe->tick;
-
-			pe->value = ys + (ye - ys) * (t - ts) / (te - ts);
-		}
-	}
-}
-
-
-
-extern const char xm_convert_vibrato[];
-
-const char mod_convert_vibrato[] = {
-	IT_VIBRATO_SINE,
-	IT_VIBRATO_RAMP_UP, /* this will be inverted by IT_OLD_EFFECTS */
-	IT_VIBRATO_XM_SQUARE,
-	IT_VIBRATO_XM_SQUARE
-};
-
-/* Returns 1 if a callback caused termination of playback. */
-static int process_effects(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry, int ignore_cxx)
-{
-	DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
-	IT_PLAYING *playing;
-	int i;
-
-	IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
-
-	if (entry->mask & IT_ENTRY_EFFECT) {
-		switch (entry->effect) {
-/*
-Notes about effects (as compared to other module formats)
-
-C               This is now in *HEX*. (Used to be in decimal in ST3)
-E/F/G/H/U       You need to check whether the song uses Amiga/Linear slides.
-H/U             Vibrato in Impulse Tracker is two times finer than in
-                any other tracker and is updated EVERY tick.
-                If "Old Effects" is *ON*, then the vibrato is played in the
-                normal manner (every non-row tick and normal depth)
-E/F/G           These commands ALL share the same memory.
-Oxx             Offsets to samples are to the 'xx00th' SAMPLE. (ie. for
-                16 bit samples, the offset is xx00h*2)
-                Oxx past the sample end will be ignored, unless "Old Effects"
-                is ON, in which case the Oxx will play from the end of the
-                sample.
-Yxy             This uses a table 4 times larger (hence 4 times slower) than
-                vibrato or tremelo. If the waveform is set to random, then
-                the 'speed' part of the command is interpreted as a delay.
-*/
-			case IT_SET_SPEED:
-				if (entry->effectvalue)
-				{
-					/*if (entry->effectvalue == 255)
-						if (sigrenderer->callbacks->xm_speed_zero && (*sigrenderer->callbacks->xm_speed_zero)(sigrenderer->callbacks->xm_speed_zero_data))
-							return 1;*/
-					if (sigdata->flags & IT_WAS_AN_STM) {
-						int n = entry->effectvalue;
-						if (n >= 32) {
-							sigrenderer->tick = sigrenderer->speed = n;
-						}
-					} else {
-						sigrenderer->tick = sigrenderer->speed = entry->effectvalue;
-					}
-				}
-				else if ((sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_MOD)) == IT_WAS_AN_XM) {
-#ifdef BIT_ARRAY_BULLSHIT
-					bit_array_set(sigrenderer->played, sigrenderer->order * 256 + sigrenderer->row);
-#endif
-					sigrenderer->speed = 0;
-#ifdef BIT_ARRAY_BULLSHIT
-					sigrenderer->looped = 1;
-#endif
-					if (sigrenderer->callbacks->xm_speed_zero && (*sigrenderer->callbacks->xm_speed_zero)(sigrenderer->callbacks->xm_speed_zero_data))
-						return 1;
-				}
-				break;
-
-			case IT_BREAK_TO_ROW:
-				if (ignore_cxx) break;
-				sigrenderer->breakrow = entry->effectvalue;
-				/* XXX jump and break on the same row */
-				if ( ( ( sigrenderer->processrow | 0xC00 ) == 0xFFFE ) &&
-					! ( sigrenderer->processrow & 0x400 ) ) {
-					sigrenderer->processrow = 0xFFFE & ~0xC00;
-				} else {
-					sigrenderer->processorder = sigrenderer->order;
-					sigrenderer->processrow = 0xFFFE & ~0x800;
-				}
-				break;
-
-			case IT_VOLSLIDE_VIBRATO:
-				for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-					if (i < 0) playing = channel->playing;
-					else {
-						playing = sigrenderer->playing[i];
-						if (!playing || playing->channel != channel) continue;
-					}
-					if (playing) {
-						playing->vibrato_speed = channel->lastHspeed;
-						playing->vibrato_depth = channel->lastHdepth;
-						playing->vibrato_n++;
-					}
-				}
-				/* Fall through and process volume slide. */
-			case IT_VOLUME_SLIDE:
-			case IT_VOLSLIDE_TONEPORTA:
-				/* The tone portamento component is handled elsewhere. */
-				{
-					unsigned char v = entry->effectvalue;
-					if (!(sigdata->flags & IT_WAS_A_MOD)) {
-						if (v == 0)
-							v = channel->lastDKL;
-						channel->lastDKL = v;
-					}
-					if (!(sigdata->flags & IT_WAS_AN_XM)) {
-						int clip = (sigdata->flags & IT_WAS_AN_S3M) ? 63 : 64;
-						if ((v & 0x0F) == 0x0F) {
-							if (!(v & 0xF0)) {
-								channel->volslide = -15;
-								channel->volume -= 15;
-								if (channel->volume > clip) channel->volume = 0;
-							} else {
-								channel->volume += v >> 4;
-								if (channel->volume > clip) channel->volume = clip;
-							}
-						} else if ((v & 0xF0) == 0xF0) {
-							if (!(v & 0x0F)) {
-								channel->volslide = 15;
-								channel->volume += 15;
-								if (channel->volume > clip) channel->volume = clip;
-							} else {
-								channel->volume -= v & 15;
-								if (channel->volume > clip) channel->volume = 0;
-							}
-						} else if (!(v & 0x0F)) {
-							channel->volslide = v >> 4;
-						} else {
-							channel->volslide = -(v & 15);
-						}
-					} else {
-						if ((v & 0x0F) == 0) { /* Dx0 */
-							channel->volslide = v >> 4;
-						} else if ((v & 0xF0) == 0) { /* D0x */
-							channel->volslide = -v;
-						} else if ((v & 0x0F) == 0x0F) { /* DxF */
-							channel->volume += v >> 4;
-							if (channel->volume > 64) channel->volume = 64;
-						} else if ((v & 0xF0) == 0xF0) { /* DFx */
-							channel->volume -= v & 15;
-							if (channel->volume > 64) channel->volume = 0;
-						}
-					}
-				}
-				break;
-			case IT_XM_FINE_VOLSLIDE_DOWN:
-				{
-					unsigned char v = entry->effectvalue;
-					if (v == 0)
-						v = channel->xm_lastEB;
-					channel->xm_lastEB = v;
-					channel->volume -= v;
-					if (channel->volume > 64) channel->volume = 0;
-				}
-				break;
-			case IT_XM_FINE_VOLSLIDE_UP:
-				{
-					unsigned char v = entry->effectvalue;
-					if (v == 0)
-						v = channel->xm_lastEA;
-					channel->xm_lastEA = v;
-					channel->volume += v;
-					if (channel->volume > 64) channel->volume = 64;
-				}
-				break;
-			case IT_PORTAMENTO_DOWN:
-				{
-					unsigned char v = entry->effectvalue;
-					if (sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_669)) {
-						if (!(sigdata->flags & IT_WAS_A_MOD)) {
-							if (v == 0xF0)
-								v |= channel->xm_lastE2;
-							else if (v >= 0xF0)
-								channel->xm_lastE2 = v & 15;
-							else if (v == 0xE0)
-								v |= channel->xm_lastX2;
-							else
-								channel->xm_lastX2 = v & 15;
-						}
-					} else if (sigdata->flags & IT_WAS_AN_S3M) {
-						if (v == 0)
-							v = channel->lastDKL;
-						channel->lastDKL = v;
-					} else {
-						if (v == 0)
-							v = channel->lastEF;
-						channel->lastEF = v;
-					}
-					for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-						if (i < 0) playing = channel->playing;
-						else {
-							playing = sigrenderer->playing[i];
-							if (!playing || playing->channel != channel) continue;
-						}
-						if (playing) {
-							if ((v & 0xF0) == 0xF0)
-								playing->slide -= (v & 15) << 4;
-							else if ((v & 0xF0) == 0xE0)
-								playing->slide -= (v & 15) << 2;
-							else if (i < 0 && sigdata->flags & IT_WAS_A_669)
-								channel->portamento -= v << 3;
-							else if (i < 0)
-								channel->portamento -= v << 4;
-						}
-					}
-				}
-				break;
-			case IT_PORTAMENTO_UP:
-				{
-					unsigned char v = entry->effectvalue;
-					if (sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_669)) {
-						if (!(sigdata->flags & IT_WAS_A_MOD)) {
-							if (v == 0xF0)
-								v |= channel->xm_lastE1;
-							else if (v >= 0xF0)
-								channel->xm_lastE1 = v & 15;
-							else if (v == 0xE0)
-								v |= channel->xm_lastX1;
-							else
-								channel->xm_lastX1 = v & 15;
-						}
-					} else if (sigdata->flags & IT_WAS_AN_S3M) {
-						if (v == 0)
-							v = channel->lastDKL;
-						channel->lastDKL = v;
-					} else {
-						if (v == 0)
-							v = channel->lastEF;
-						channel->lastEF = v;
-					}
-					for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-						if (i < 0) playing = channel->playing;
-						else {
-							playing = sigrenderer->playing[i];
-							if (!playing || playing->channel != channel) continue;
-						}
-						if (playing) {
-							if ((v & 0xF0) == 0xF0)
-								playing->slide += (v & 15) << 4;
-							else if ((v & 0xF0) == 0xE0)
-								playing->slide += (v & 15) << 2;
-							else if (i < 0 && sigdata->flags & IT_WAS_A_669)
-								channel->portamento += v << 3;
-							else if (i < 0)
-								channel->portamento += v << 4;
-						}
-					}
-				}
-				break;
-			case IT_XM_PORTAMENTO_DOWN:
-				{
-					unsigned char v = entry->effectvalue;
-					if (!(sigdata->flags & IT_WAS_A_MOD)) {
-						if (v == 0)
-							v = channel->lastJ;
-						channel->lastJ = v;
-					}
-					if (channel->playing)
-						channel->portamento -= v << 4;
-				}
-				break;
-			case IT_XM_PORTAMENTO_UP:
-				{
-					unsigned char v = entry->effectvalue;
-					if (!(sigdata->flags & IT_WAS_A_MOD)) {
-						if (v == 0)
-							v = channel->lastEF;
-						channel->lastEF = v;
-					}
-					if (channel->playing)
-						channel->portamento += v << 4;
-				}
-				break;
-			case IT_XM_KEY_OFF:
-				channel->key_off_count = entry->effectvalue;
-				if (!channel->key_off_count) xm_note_off(sigdata, channel);
-				break;
-			case IT_VIBRATO:
-				{
-					if (entry->effectvalue || !(sigdata->flags & IT_WAS_A_669)) {
-						unsigned char speed = entry->effectvalue >> 4;
-						unsigned char depth = entry->effectvalue & 15;
-						if (speed == 0)
-							speed = channel->lastHspeed;
-						channel->lastHspeed = speed;
-						if (depth == 0)
-							depth = channel->lastHdepth;
-						else {
-							if (sigdata->flags & IT_OLD_EFFECTS && !(sigdata->flags & IT_WAS_A_MOD))
-								depth <<= 3;
-							else
-								depth <<= 2;
-							channel->lastHdepth = depth;
-						}
-						for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-							if (i < 0) playing = channel->playing;
-							else {
-								playing = sigrenderer->playing[i];
-								if (!playing || playing->channel != channel) continue;
-							}
-							if (playing) {
-								playing->vibrato_speed = speed;
-								playing->vibrato_depth = depth;
-								playing->vibrato_n++;
-							}
-						}
-					}
-				}
-				break;
-			case IT_TREMOR:
-				{
-					unsigned char v = entry->effectvalue;
-					if (v == 0) {
-						if (sigdata->flags & IT_WAS_AN_S3M)
-							v = channel->lastDKL;
-						else
-							v = channel->lastI;
-					}
-					else if (!(sigdata->flags & IT_OLD_EFFECTS)) {
-						if (v & 0xF0) v -= 0x10;
-						if (v & 0x0F) v -= 0x01;
-					}
-					if (sigdata->flags & IT_WAS_AN_S3M)
-						channel->lastDKL = v;
-					else
-						channel->lastI = v;
-					channel->tremor_time |= 128;
-				}
-				update_tremor(channel);
-				break;
-			case IT_ARPEGGIO:
-				{
-					unsigned char v = entry->effectvalue;
-					/* XM files have no memory for arpeggio (000 = no effect)
-					 * and we use lastJ for portamento down instead.
-					 */
-					if (!(sigdata->flags & IT_WAS_AN_XM)) {
-						if (sigdata->flags & IT_WAS_AN_S3M) {
-							if (v == 0)
-								v = channel->lastDKL;
-							channel->lastDKL = v;
-						} else {
-							if (v == 0)
-								v = channel->lastJ;
-							channel->lastJ = v;
-						}
-					}
-					channel->arpeggio_offsets[0] = 0;
-					channel->arpeggio_offsets[1] = (v & 0xF0) >> 4;
-					channel->arpeggio_offsets[2] = (v & 0x0F);
-					channel->arpeggio_table = (const unsigned char *)(((sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_MOD))==IT_WAS_AN_XM) ? &arpeggio_xm : &arpeggio_mod);
-				}
-				break;
-			case IT_SET_CHANNEL_VOLUME:
-				if (sigdata->flags & IT_WAS_AN_XM)
-					channel->volume = MIN(entry->effectvalue, 64);
-				else if (entry->effectvalue <= 64)
-					channel->channelvolume = entry->effectvalue;
-#ifdef VOLUME_OUT_OF_RANGE_SETS_MAXIMUM
-				else
-					channel->channelvolume = 64;
-#endif
-				if (channel->playing)
-					channel->playing->channel_volume = channel->channelvolume;
-				break;
-			case IT_CHANNEL_VOLUME_SLIDE:
-				{
-					unsigned char v = entry->effectvalue;
-					if (v == 0)
-						v = channel->lastN;
-					channel->lastN = v;
-					if ((v & 0x0F) == 0) { /* Nx0 */
-						channel->channelvolslide = v >> 4;
-					} else if ((v & 0xF0) == 0) { /* N0x */
-						channel->channelvolslide = -v;
-					} else {
-						if ((v & 0x0F) == 0x0F) { /* NxF */
-							channel->channelvolume += v >> 4;
-							if (channel->channelvolume > 64) channel->channelvolume = 64;
-						} else if ((v & 0xF0) == 0xF0) { /* NFx */
-							channel->channelvolume -= v & 15;
-							if (channel->channelvolume > 64) channel->channelvolume = 0;
-						} else
-							break;
-						if (channel->playing)
-							channel->playing->channel_volume = channel->channelvolume;
-					}
-				}
-				break;
-			case IT_SET_SAMPLE_OFFSET:
-				{
-					unsigned char v = entry->effectvalue;
-					/*if (sigdata->flags & IT_WAS_A_MOD) {
-						if (v == 0) break;
-					} else*/ {
-						if (v == 0)
-							v = channel->lastO;
-						channel->lastO = v;
-					}
-					/* Note: we set the offset even if tone portamento is
-					 * specified. Impulse Tracker does the same.
-					 */
-					if (entry->mask & IT_ENTRY_NOTE) {
-						if (channel->playing) {
-							int offset = ((int)channel->high_offset << 16) | ((int)v << 8);
-							IT_PLAYING *playing = channel->playing;
-							IT_SAMPLE *sample = playing->sample;
-							int end;
-							if ((sample->flags & IT_SAMPLE_SUS_LOOP) && !(playing->flags & IT_PLAYING_SUSTAINOFF))
-								end = (int)sample->sus_loop_end;
-							else if (sample->flags & IT_SAMPLE_LOOP)
-								end = (int)sample->loop_end;
-							else {
-								end = (int)sample->length;
-								if ( sigdata->flags & IT_WAS_PROCESSED && end > 64 ) // XXX bah damn LPC and edge case modules
-									end -= 64;
-							}
-							if ((sigdata->flags & IT_WAS_A_PTM) && (sample->flags & IT_SAMPLE_16BIT))
-								offset >>= 1;
-							if (offset < end) {
-								it_playing_reset_resamplers(playing, offset);
-								playing->declick_stage = 0;
-							} else if (sigdata->flags & IT_OLD_EFFECTS) {
-								it_playing_reset_resamplers(playing, end);
-								playing->declick_stage = 0;
-							}
-						}
-					}
-				}
-				break;
-			case IT_PANNING_SLIDE:
-				/** JULIEN: guess what? the docs are wrong! (how unusual ;)
-				 * Pxy seems to memorize its previous value... and there
-				 * might be other mistakes like that... (sigh!)
-				 */
-				/** ENTHEH: umm... but... the docs say that Pxy memorises its
-				 * value... don't they? :o
-				 */
-				{
-					unsigned char v = entry->effectvalue;
-					int p = channel->truepan;
-					if (sigdata->flags & IT_WAS_AN_XM)
-					{
-						if (IT_IS_SURROUND(channel->pan))
-						{
-							channel->pan = 32;
-							p = 32 + 128 * 64;
-						}
-						p >>= 6;
-					}
-					else {
-						if (IT_IS_SURROUND(channel->pan)) p = 32 << 8;
-						p = (p + 128) >> 8;
-						channel->pan = p;
-					}
-					if (v == 0)
-						v = channel->lastP;
-					channel->lastP = v;
-					if ((v & 0x0F) == 0) { /* Px0 */
-						channel->panslide = -(v >> 4);
-					} else if ((v & 0xF0) == 0) { /* P0x */
-						channel->panslide = v;
-					} else if ((v & 0x0F) == 0x0F) { /* PxF */
-						p -= v >> 4;
-					} else if ((v & 0xF0) == 0xF0) { /* PFx */
-						p += v & 15;
-					}
-					if (sigdata->flags & IT_WAS_AN_XM)
-						channel->truepan = 32 + MID(0, p, 255) * 64;
-					else {
-						if (p < 0) p = 0;
-						else if (p > 64) p = 64;
-						channel->pan = p;
-						channel->truepan = p << 8;
-					}
-				}
-				break;
-			case IT_RETRIGGER_NOTE:
-				{
-					unsigned char v = entry->effectvalue;
-					if (sigdata->flags & IT_WAS_AN_XM) {
-						if ((v & 0x0F) == 0) v |= channel->lastQ & 0x0F;
-						if ((v & 0xF0) == 0) v |= channel->lastQ & 0xF0;
-						channel->lastQ = v;
-					} else if (sigdata->flags & IT_WAS_AN_S3M) {
-						if (v == 0)
-							v = channel->lastDKL;
-						channel->lastDKL = v;
-					} else {
-						if (v == 0)
-							v = channel->lastQ;
-						channel->lastQ = v;
-					}
-					if ((v & 0x0F) == 0) v |= 0x01;
-					channel->retrig = v;
-					if (entry->mask & IT_ENTRY_NOTE) {
-						channel->retrig_tick = v & 0x0F;
-						/* Emulate a bug */
-						if (sigdata->flags & IT_WAS_AN_XM)
-							update_retrig(sigrenderer, channel);
-					} else
-						update_retrig(sigrenderer, channel);
-				}
-				break;
-			case IT_XM_RETRIGGER_NOTE:
-				channel->retrig_tick = channel->xm_retrig = entry->effectvalue;
-				if (entry->effectvalue == 0)
-					if (channel->playing) {
-						it_playing_reset_resamplers(channel->playing, 0);
-						channel->playing->declick_stage = 0;
-					}
-				break;
-			case IT_TREMOLO:
-				{
-					unsigned char speed, depth;
-					if (sigdata->flags & IT_WAS_AN_S3M) {
-						unsigned char v = entry->effectvalue;
-						if (v == 0)
-							v = channel->lastDKL;
-						channel->lastDKL = v;
-						speed = v >> 4;
-						depth = v & 15;
-					} else {
-						speed = entry->effectvalue >> 4;
-						depth = entry->effectvalue & 15;
-						if (speed == 0)
-							speed = channel->lastRspeed;
-						channel->lastRspeed = speed;
-						if (depth == 0)
-							depth = channel->lastRdepth;
-						channel->lastRdepth = depth;
-					}
-					for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-						if (i < 0) playing = channel->playing;
-						else {
-							playing = sigrenderer->playing[i];
-							if (!playing || playing->channel != channel) continue;
-						}
-						if (playing) {
-							playing->tremolo_speed = speed;
-							playing->tremolo_depth = depth;
-						}
-					}
-				}
-				break;
-			case IT_S:
-				{
-					/* channel->lastS was set in update_pattern_variables(). */
-					unsigned char effectvalue = channel->lastS;
-					switch (effectvalue >> 4) {
-						//case IT_S_SET_FILTER:
-							/* Waveforms for commands S3x, S4x and S5x:
-							 *   0: Sine wave
-							 *   1: Ramp down
-							 *   2: Square wave
-							 *   3: Random wave
-							 */
-						case IT_S_SET_GLISSANDO_CONTROL:
-							channel->glissando = effectvalue & 15;
-							break;
-
-						case IT_S_FINETUNE:
-							if (channel->playing) {
-								channel->playing->finetune = ((int)(effectvalue & 15) - 8) << 5;
-							}
-							break;
-
-						case IT_S_SET_VIBRATO_WAVEFORM:
-							{
-								int waveform = effectvalue & 3;
-								if (sigdata->flags & IT_WAS_A_MOD) waveform = mod_convert_vibrato[waveform];
-								else if (sigdata->flags & IT_WAS_AN_XM) waveform = xm_convert_vibrato[waveform];
-								channel->vibrato_waveform = waveform;
-								if (channel->playing) {
-									channel->playing->vibrato_waveform = waveform;
-									if (!(effectvalue & 4))
-										channel->playing->vibrato_time = 0;
-								}
-							}
-							break;
-						case IT_S_SET_TREMOLO_WAVEFORM:
-							{
-								int waveform = effectvalue & 3;
-								if (sigdata->flags & IT_WAS_A_MOD) waveform = mod_convert_vibrato[waveform];
-								else if (sigdata->flags & IT_WAS_AN_XM) waveform = xm_convert_vibrato[waveform];
-								channel->tremolo_waveform = waveform;
-								if (channel->playing) {
-									channel->playing->tremolo_waveform = waveform;
-									if (!(effectvalue & 4))
-										channel->playing->tremolo_time = 0;
-								}
-							}
-							break;
-						case IT_S_SET_PANBRELLO_WAVEFORM:
-							channel->panbrello_waveform = effectvalue & 3;
-							if (channel->playing) {
-								channel->playing->panbrello_waveform = effectvalue & 3;
-								if (!(effectvalue & 4))
-									channel->playing->panbrello_time = 0;
-							}
-							break;
-
-						case IT_S_FINE_PATTERN_DELAY:
-							sigrenderer->tick += effectvalue & 15;
-							break;
-#if 1
-						case IT_S7:
-							{
-								if (sigrenderer->sigdata->flags & IT_USE_INSTRUMENTS)
-								{
-									int i;
-									switch (effectvalue & 15)
-									{
-									case 0: /* cut background notes */
-										for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
-										{
-											IT_PLAYING * playing = sigrenderer->playing[i];
-											if (playing && channel == playing->channel)
-											{
-												playing->declick_stage = 3;
-												if (channel->playing == playing) channel->playing = NULL;
-											}
-										}
-										break;
-									case 1: /* release background notes */
-										for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
-										{
-											IT_PLAYING * playing = sigrenderer->playing[i];
-											if (playing && channel == playing->channel && !(playing->flags & IT_PLAYING_SUSTAINOFF))
-											{
-												it_note_off(playing);
-											}
-										}
-										break;
-									case 2: /* fade background notes */
-										for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
-										{
-											IT_PLAYING * playing = sigrenderer->playing[i];
-											if (playing && channel == playing->channel)
-											{
-												//playing->flags &= IT_PLAYING_SUSTAINOFF;
-												playing->flags |= IT_PLAYING_FADING;
-											}
-										}
-										break;
-									case 3:
-										channel->new_note_action = NNA_NOTE_CUT;
-										break;
-									case 4:
-										channel->new_note_action = NNA_NOTE_CONTINUE;
-										break;
-									case 5:
-										channel->new_note_action = NNA_NOTE_OFF;
-										break;
-									case 6:
-										channel->new_note_action = NNA_NOTE_FADE;
-										break;
-
-									case 7:
-										if (channel->playing)
-											channel->playing->enabled_envelopes &= ~IT_ENV_VOLUME;
-										break;
-									case 8:
-										if (channel->playing)
-											channel->playing->enabled_envelopes |= IT_ENV_VOLUME;
-										break;
-
-									case 9:
-										if (channel->playing)
-											channel->playing->enabled_envelopes &= ~IT_ENV_PANNING;
-										break;
-									case 10:
-										if (channel->playing)
-											channel->playing->enabled_envelopes |= IT_ENV_PANNING;
-										break;
-
-									case 11:
-										if (channel->playing)
-											channel->playing->enabled_envelopes &= ~IT_ENV_PITCH;
-										break;
-									case 12:
-										if (channel->playing)
-											channel->playing->enabled_envelopes |= IT_ENV_PITCH;
-										break;
-									}
-								}
-							}
-							break;
-#endif
-						case IT_S_SET_PAN:
-							//ASSERT(!(sigdata->flags & IT_WAS_AN_XM));
-							channel->pan =
-								((effectvalue & 15) << 2) |
-								((effectvalue & 15) >> 2);
-							channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
-
-							if (channel->playing)
-								channel->playing->panbrello_depth = 0;
-							break;
-						case IT_S_SET_SURROUND_SOUND:
-							if ((effectvalue & 15) == 15) {
-								if (channel->playing && channel->playing->sample &&
-									!(channel->playing->sample->flags & (IT_SAMPLE_LOOP | IT_SAMPLE_SUS_LOOP))) {
-									channel->playing->flags |= IT_PLAYING_REVERSE;
-									it_playing_reset_resamplers( channel->playing, channel->playing->sample->length - 1 );
-								}
-							} else if ((effectvalue & 15) == 1) {
-								channel->pan = IT_SURROUND;
-								channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
-							}
-							if (channel->playing)
-								channel->playing->panbrello_depth = 0;
-							break;
-						case IT_S_SET_HIGH_OFFSET:
-							channel->high_offset = effectvalue & 15;
-							break;
-						//case IT_S_PATTERN_LOOP:
-						case IT_S_DELAYED_NOTE_CUT:
-							channel->note_cut_count = effectvalue & 15;
-							if (!channel->note_cut_count) {
-								if (sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_PTM))
-									channel->volume = 0;
-								else
-									channel->note_cut_count = 1;
-							}
-							break;
-						case IT_S_SET_MIDI_MACRO:
-							if ((sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_MOD)) == (IT_WAS_AN_XM | IT_WAS_A_MOD)) {
-								channel->inv_loop_speed = effectvalue & 15;
-								update_invert_loop(channel, channel->playing ? channel->playing->sample : NULL);
-							} else channel->SFmacro = effectvalue & 15;
-							break;
-					}
-				}
-				break;
-			case IT_SET_SONG_TEMPO:
-				{
-					unsigned char v = entry->effectvalue;
-					if (v == 0)
-						v = channel->lastW;
-					channel->lastW = v;
-					if (v < 0x10)
-						sigrenderer->temposlide = -v;
-					else if (v < 0x20)
-						sigrenderer->temposlide = v & 15;
-					else
-						sigrenderer->tempo = v;
-				}
-				break;
-			case IT_FINE_VIBRATO:
-				{
-					unsigned char speed = entry->effectvalue >> 4;
-					unsigned char depth = entry->effectvalue & 15;
-					if (speed == 0)
-						speed = channel->lastHspeed;
-					channel->lastHspeed = speed;
-					if (depth == 0)
-						depth = channel->lastHdepth;
-					else {
-						if (sigdata->flags & IT_OLD_EFFECTS)
-							depth <<= 1;
-						channel->lastHdepth = depth;
-					}
-					for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-						if (i < 0) playing = channel->playing;
-						else {
-							playing = sigrenderer->playing[i];
-							if (!playing || playing->channel != channel) continue;
-						}
-						if (playing) {
-							playing->vibrato_speed = speed;
-							playing->vibrato_depth = depth;
-							playing->vibrato_n++;
-						}
-					}
-				}
-				break;
-			case IT_SET_GLOBAL_VOLUME:
-				if ((sigdata->flags & IT_WAS_AN_S3M) && (entry->effectvalue > 64))
-					break;
-				if (entry->effectvalue <= 128)
-					sigrenderer->globalvolume = entry->effectvalue;
-#ifdef VOLUME_OUT_OF_RANGE_SETS_MAXIMUM
-				else
-					sigrenderer->globalvolume = 128;
-#endif
-				break;
-			case IT_GLOBAL_VOLUME_SLIDE:
-				{
-					unsigned char v = entry->effectvalue;
-					if (v == 0)
-						v = channel->lastW;
-					channel->lastW = v;
-					if ((v & 0x0F) == 0) { /* Wx0 */
-						sigrenderer->globalvolslide =
-							(sigdata->flags & IT_WAS_AN_XM) ? (v >> 4)*2 : (v >> 4);
-					} else if ((v & 0xF0) == 0) { /* W0x */
-						sigrenderer->globalvolslide =
-							(sigdata->flags & IT_WAS_AN_XM) ? (-v)*2 : (-v);
-					} else if ((v & 0x0F) == 0x0F) { /* WxF */
-						sigrenderer->globalvolume += v >> 4;
-						if (sigrenderer->globalvolume > 128) sigrenderer->globalvolume = 128;
-					} else if ((v & 0xF0) == 0xF0) { /* WFx */
-						sigrenderer->globalvolume -= v & 15;
-						if (sigrenderer->globalvolume > 128) sigrenderer->globalvolume = 0;
-					}
-				}
-				break;
-			case IT_SET_PANNING:
-				if (sigdata->flags & IT_WAS_AN_XM) {
-					channel->truepan = 32 + entry->effectvalue*64;
-				} else {
-					if (sigdata->flags & IT_WAS_AN_S3M)
-						channel->pan = (entry->effectvalue + 1) >> 1;
-					else
-						channel->pan = (entry->effectvalue + 2) >> 2;
-					channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
-				}
-				if (channel->playing)
-					channel->playing->panbrello_depth = 0;
-				break;
-			case IT_PANBRELLO:
-				{
-					unsigned char speed = entry->effectvalue >> 4;
-					unsigned char depth = entry->effectvalue & 15;
-					if (speed == 0)
-						speed = channel->lastYspeed;
-					channel->lastYspeed = speed;
-					if (depth == 0)
-						depth = channel->lastYdepth;
-					channel->lastYdepth = depth;
-					if (channel->playing) {
-						channel->playing->panbrello_speed = speed;
-						channel->playing->panbrello_depth = depth;
-					}
-				}
-				break;
-			case IT_MIDI_MACRO:
-				{
-					const IT_MIDI *midi = sigdata->midi ? sigdata->midi : &default_midi;
-					if (entry->effectvalue >= 0x80) {
-						int n = midi->Zmacrolen[entry->effectvalue-0x80];
-						int i;
-						for (i = 0; i < n; i++)
-							it_send_midi(sigrenderer, channel, midi->Zmacro[entry->effectvalue-0x80][i]);
-					} else {
-						int n = midi->SFmacrolen[channel->SFmacro];
-						int i, j;
-						for (i = 0, j = 1; i < n; i++, j <<= 1)
-							it_send_midi(sigrenderer, channel,
-								(unsigned char)(midi->SFmacroz[channel->SFmacro] & j ?
-									entry->effectvalue : midi->SFmacro[channel->SFmacro][i]));
-					}
-				}
-				break;
-			case IT_XM_SET_ENVELOPE_POSITION:
-				if (channel->playing && channel->playing->env_instrument) {
-					IT_ENVELOPE *envelope = &channel->playing->env_instrument->volume_envelope;
-					if (envelope->flags & IT_ENVELOPE_ON) {
-						IT_PLAYING_ENVELOPE *pe = &channel->playing->volume_envelope;
-						pe->tick = entry->effectvalue;
-						if (pe->tick >= envelope->node_t[envelope->n_nodes-1])
-							pe->tick = envelope->node_t[envelope->n_nodes-1];
-						pe->next_node = 0;
-						while (pe->tick > envelope->node_t[pe->next_node]) pe->next_node++;
-						xm_envelope_calculate_value(envelope, pe);
-					}
-				}
-				break;
-
-			/* uggly plain portamento for now */
-			case IT_PTM_NOTE_SLIDE_DOWN:
-			case IT_PTM_NOTE_SLIDE_DOWN_RETRIG:
-				{
-					channel->toneslide_retrig = (entry->effect == IT_PTM_NOTE_SLIDE_DOWN_RETRIG);
-
-					if (channel->ptm_last_toneslide) {
-						channel->toneslide_tick = channel->last_toneslide_tick;
-
-						if (--channel->toneslide_tick == 0) {
-							channel->truenote += channel->toneslide;
-							if (channel->truenote >= 120) {
-								if (channel->toneslide < 0) channel->truenote = 0;
-								else channel->truenote = 119;
-							}
-							channel->note += channel->toneslide;
-							if (channel->note >= 120) {
-								if (channel->toneslide < 0) channel->note = 0;
-								else channel->note = 119;
-							}
-
-							if (channel->playing) {
-								if (channel->sample) channel->playing->note = channel->truenote;
-								else channel->playing->note = channel->note;
-								it_playing_reset_resamplers(channel->playing, 0);
-								channel->playing->declick_stage = 0;
-							}
-						}
-					}
-
-					channel->ptm_last_toneslide = 0;
-
-					channel->toneslide = -(entry->effectvalue & 15);
-					channel->ptm_toneslide = (entry->effectvalue & 0xF0) >> 4;
-					channel->toneslide_tick += channel->ptm_toneslide;
-				}
-				break;
-			case IT_PTM_NOTE_SLIDE_UP:
-			case IT_PTM_NOTE_SLIDE_UP_RETRIG:
-				{
-					channel->toneslide_retrig = (entry->effect == IT_PTM_NOTE_SLIDE_UP_RETRIG);
-
-					if (channel->ptm_last_toneslide) {
-						channel->toneslide_tick = channel->last_toneslide_tick;
-
-						if (--channel->toneslide_tick == 0) {
-							channel->truenote += channel->toneslide;
-							if (channel->truenote >= 120) {
-								if (channel->toneslide < 0) channel->truenote = 0;
-								else channel->truenote = 119;
-							}
-							channel->note += channel->toneslide;
-							if (channel->note >= 120) {
-								if (channel->toneslide < 0) channel->note = 0;
-								else channel->note = 119;
-							}
-
-							if (channel->playing) {
-								if (channel->sample) channel->playing->note = channel->truenote;
-								else channel->playing->note = channel->note;
-								it_playing_reset_resamplers(channel->playing, 0);
-								channel->playing->declick_stage = 0;
-							}
-						}
-					}
-
-					channel->ptm_last_toneslide = 0;
-
-					channel->toneslide = -(entry->effectvalue & 15);
-					channel->ptm_toneslide = (entry->effectvalue & 0xF0) >> 4;
-					channel->toneslide_tick += channel->ptm_toneslide;
-				}
-				break;
-
-			case IT_OKT_NOTE_SLIDE_DOWN:
-			case IT_OKT_NOTE_SLIDE_DOWN_ROW:
-				channel->toneslide = -entry->effectvalue;
-				channel->okt_toneslide = (entry->effect == IT_OKT_NOTE_SLIDE_DOWN) ? 255 : 1;
-				break;
-
-			case IT_OKT_NOTE_SLIDE_UP:
-			case IT_OKT_NOTE_SLIDE_UP_ROW:
-				channel->toneslide = entry->effectvalue;
-				channel->okt_toneslide = (entry->effect == IT_OKT_NOTE_SLIDE_UP) ? 255 : 1;
-				break;
-
-			case IT_OKT_ARPEGGIO_3:
-			case IT_OKT_ARPEGGIO_4:
-			case IT_OKT_ARPEGGIO_5:
-				{
-					channel->arpeggio_offsets[0] = 0;
-					channel->arpeggio_offsets[1] = -(entry->effectvalue >> 4);
-					channel->arpeggio_offsets[2] = entry->effectvalue & 0x0F;
-
-					switch (entry->effect)
-					{
-					case IT_OKT_ARPEGGIO_3:
-						channel->arpeggio_table = (const unsigned char *)&arpeggio_okt_3;
-						break;
-
-					case IT_OKT_ARPEGGIO_4:
-						channel->arpeggio_table = (const unsigned char *)&arpeggio_okt_4;
-						break;
-
-					case IT_OKT_ARPEGGIO_5:
-						channel->arpeggio_table = (const unsigned char *)&arpeggio_okt_5;
-						break;
-					}
-				}
-				break;
-
-			case IT_OKT_VOLUME_SLIDE_DOWN:
-				if ( entry->effectvalue <= 16 ) channel->volslide = -entry->effectvalue;
-				else
-				{
-					channel->volume -= entry->effectvalue - 16;
-					if (channel->volume > 64) channel->volume = 0;
-				}
-				break;
-
-			case IT_OKT_VOLUME_SLIDE_UP:
-				if ( entry->effectvalue <= 16 ) channel->volslide = entry->effectvalue;
-				else
-				{
-					channel->volume += entry->effectvalue - 16;
-					if (channel->volume > 64) channel->volume = 64;
-				}
-				break;
-		}
-	}
-
-	if (!(sigdata->flags & IT_WAS_AN_XM))
-		post_process_it_volpan(sigrenderer, entry);
-
-	return 0;
-}
-
-
-
-static int process_it_note_data(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry)
-{
-	DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
-	IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
-
-	// When tone portamento and instrument are specified:
-	// If Gxx is off:
-	//   - same sample, do nothing but portamento
-	//   - diff sample, retrigger all but keep current note+slide + do porta
-	//   - if instrument is invalid, nothing; if sample is invalid, cut
-	// If Gxx is on:
-	//   - same sample or new sample invalid, retrigger envelopes and initialise note value for portamento to 'seek' to
-	//   - diff sample/inst, start using new envelopes
-	// When tone portamento is specified alone, sample won't change.
-	// TODO: consider what happens with instrument alone after all this...
-
-	if (entry->mask & (IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT)) {
-		if (entry->mask & IT_ENTRY_INSTRUMENT)
-			channel->instrument = entry->instrument;
-		instrument_to_sample(sigdata, channel);
-		if (channel->note <= 120) {
-			if ((sigdata->flags & IT_USE_INSTRUMENTS) && channel->sample == 0)
-				it_retrigger_note(sigrenderer, channel); /* Stop the note */ /*return 1;*/
-			if (entry->mask & IT_ENTRY_INSTRUMENT)
-				get_default_volpan(sigdata, channel);
-		} else
-			it_retrigger_note(sigrenderer, channel); /* Stop the note */
-	}
-
-	/** WARNING: This is not ideal, since channel->playing might not get allocated owing to lack of memory... */
-	if (((entry->mask & IT_ENTRY_VOLPAN) && entry->volpan >= 193 && entry->volpan <= 202) ||
-	    ((entry->mask & IT_ENTRY_EFFECT) && (entry->effect == IT_TONE_PORTAMENTO || entry->effect == IT_VOLSLIDE_TONEPORTA)))
-	{
-		if (channel->playing && (entry->mask & IT_ENTRY_INSTRUMENT)) {
-			if (sigdata->flags & IT_COMPATIBLE_GXX)
-				it_compatible_gxx_retrigger(sigdata, channel);
-			else if ((!(sigdata->flags & IT_USE_INSTRUMENTS) ||
-				(channel->instrument >= 1 && channel->instrument <= sigdata->n_instruments)) &&
-				channel->sample != channel->playing->sampnum)
-			{
-				unsigned char note = channel->playing->note;
-				int slide = channel->playing->slide;
-				it_retrigger_note(sigrenderer, channel);
-				if (channel->playing) {
-					channel->playing->note = note;
-					channel->playing->slide = slide;
-					// Should we be preserving sample_vibrato_time? depth?
-				}
-			}
-		}
-
-		channel->toneporta = 0;
-
-		if ((entry->mask & IT_ENTRY_VOLPAN) && entry->volpan >= 193 && entry->volpan <= 202) {
-			/* Tone Portamento in the volume column */
-			static const unsigned char slidetable[] = {0, 1, 4, 8, 16, 32, 64, 96, 128, 255};
-			unsigned char v = slidetable[entry->volpan - 193];
-			if (sigdata->flags & IT_COMPATIBLE_GXX) {
-				if (v == 0)
-					v = channel->lastG;
-				channel->lastG = v;
-			} else {
-				if (v == 0)
-					v = channel->lastEF;
-				channel->lastEF = v;
-			}
-			channel->toneporta += v << 4;
-		}
-
-		if ((entry->mask & IT_ENTRY_EFFECT) && (entry->effect == IT_TONE_PORTAMENTO || entry->effect == IT_VOLSLIDE_TONEPORTA)) {
-			/* Tone Portamento in the effect column */
-			unsigned char v;
-			if (entry->effect == IT_TONE_PORTAMENTO)
-				v = entry->effectvalue;
-			else
-				v = 0;
-			if (sigdata->flags & IT_COMPATIBLE_GXX) {
-				if (v == 0)
-					v = channel->lastG;
-				channel->lastG = v;
-			} else {
-				if (v == 0 && !(sigdata->flags & IT_WAS_A_669))
-					v = channel->lastEF;
-				channel->lastEF = v;
-			}
-			channel->toneporta += v << 4;
-		}
-
-		if ((entry->mask & IT_ENTRY_NOTE) || ((sigdata->flags & IT_COMPATIBLE_GXX) && (entry->mask & IT_ENTRY_INSTRUMENT))) {
-			if (channel->note <= 120) {
-				if (channel->sample)
-					channel->destnote = channel->truenote;
-				else
-					channel->destnote = channel->note;
-			}
-		}
-
-		if (channel->playing) goto skip_start_note;
-	}
-
-	if ((entry->mask & IT_ENTRY_NOTE) ||
-		((entry->mask & IT_ENTRY_INSTRUMENT) && (!channel->playing || entry->instrument != channel->playing->instnum)))
-	{
-		if (channel->note <= 120) {
-			get_true_pan(sigdata, channel);
-			if ((entry->mask & IT_ENTRY_NOTE) || !(sigdata->flags & (IT_WAS_AN_S3M|IT_WAS_A_PTM)))
-				it_retrigger_note(sigrenderer, channel);
-		}
-	}
-
-	skip_start_note:
-
-	if (entry->mask & IT_ENTRY_VOLPAN) {
-		if (entry->volpan <= 64) {
-			/* Volume */
-			channel->volume = entry->volpan;
-		} else if (entry->volpan <= 74) {
-			/* Fine volume slide up */
-			unsigned char v = entry->volpan - 65;
-			if (v == 0)
-				v = channel->lastvolslide;
-			channel->lastvolslide = v;
-			/* = effect DxF where x == entry->volpan - 65 */
-			channel->volume += v;
-			if (channel->volume > 64) channel->volume = 64;
-		} else if (entry->volpan <= 84) {
-			/* Fine volume slide down */
-			unsigned char v = entry->volpan - 75;
-			if (v == 0)
-				v = channel->lastvolslide;
-			channel->lastvolslide = v;
-			/* = effect DFx where x == entry->volpan - 75 */
-			channel->volume -= v;
-			if (channel->volume > 64) channel->volume = 0;
-		} else if (entry->volpan < 128) {
-			/* Volume slide up */
-			/* Volume slide down */
-			/* Portamento down */
-			/* Portamento up */
-		} else if (entry->volpan <= 192) {
-			/* Pan */
-			channel->pan = entry->volpan - 128;
-			channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
-		}
-		/* else */
-		/* Tone Portamento */
-		/* Vibrato */
-	}
-	return 0;
-}
-
-
-
-static void retrigger_xm_envelopes(IT_PLAYING *playing)
-{
-	playing->volume_envelope.next_node = 0;
-	playing->volume_envelope.tick = -1;
-	playing->pan_envelope.next_node = 0;
-	playing->pan_envelope.tick = -1;
-	playing->fadeoutcount = 1024;
-}
-
-
-
-static void process_xm_note_data(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry)
-{
-	DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
-	IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
-	IT_PLAYING * playing = NULL;
-
-	if (entry->mask & IT_ENTRY_INSTRUMENT) {
-		int oldsample = channel->sample;
-		channel->inv_loop_offset = 0;
-		channel->instrument = entry->instrument;
-		instrument_to_sample(sigdata, channel);
-		if (channel->playing &&
-			!((entry->mask & IT_ENTRY_NOTE) && entry->note >= 120) &&
-			!((entry->mask & IT_ENTRY_EFFECT) && entry->effect == IT_XM_KEY_OFF && entry->effectvalue == 0)) {
-			playing = dup_playing(channel->playing, channel, channel);
-			if (!playing) return;
-			if (!(sigdata->flags & IT_WAS_A_MOD)) {
-				/* Retrigger vol/pan envelopes if enabled, and cancel fadeout.
-				 * Also reset vol/pan to that of _original_ instrument.
-				 */
-				channel->playing->flags &= ~(IT_PLAYING_SUSTAINOFF | IT_PLAYING_FADING);
-				it_playing_update_resamplers(channel->playing);
-
-				channel->volume = channel->playing->sample->default_volume;
-				channel->truepan = 32 + channel->playing->sample->default_pan*64;
-
-				retrigger_xm_envelopes(channel->playing);
-			} else {
-				/* Switch if sample changed */
-				if (oldsample != channel->sample) {
-					int i;
-					for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-						if (!sigrenderer->playing[i]) {
-							channel->playing->declick_stage = 3;
-							sigrenderer->playing[i] = channel->playing;
-							channel->playing = NULL;
-							break;
-						}
-					}
-
-					if (!channel->sample) {
-						if (channel->playing)
-						{
-							free_playing(channel->playing);
-							channel->playing = NULL;
-						}
-					} else {
-						if (channel->playing) {
-							free_playing(channel->playing);
-						}
-						channel->playing = playing;
-						playing = NULL;
-						channel->playing->declick_stage = 0;
-						channel->playing->sampnum = channel->sample;
-						channel->playing->sample = &sigdata->sample[channel->sample-1];
-						it_playing_reset_resamplers(channel->playing, 0);
-					}
-				}
-				get_default_volpan(sigdata, channel);
-			}
-		}
-	}
-
-	if (!((entry->mask & IT_ENTRY_EFFECT) && entry->effect == IT_XM_KEY_OFF && entry->effectvalue == 0) &&
-		(entry->mask & IT_ENTRY_NOTE))
-	{
-		if (!(entry->mask & IT_ENTRY_INSTRUMENT))
-			instrument_to_sample(sigdata, channel);
-
-		if (channel->note >= 120)
-			xm_note_off(sigdata, channel);
-		else if (channel->sample == 0) {
-			/** If we get here, one of the following is the case:
-			 ** 1. The instrument has never been specified on this channel.
-			 ** 2. The specified instrument is invalid.
-			 ** 3. The instrument has no sample mapped to the selected note.
-			 ** What should happen?
-			 **
-			 ** Experimentation shows that any existing note stops and cannot
-			 ** be brought back. A subsequent instrument change fixes that.
-			 **/
-			if (channel->playing) {
-				int i;
-				if (playing) {
-					free_playing(channel->playing);
-					channel->playing = playing;
-					playing = NULL;
-				}
-				for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-					if (!sigrenderer->playing[i]) {
-						channel->playing->declick_stage = 3;
-						sigrenderer->playing[i] = channel->playing;
-						channel->playing = NULL;
-						break;
-					}
-				}
-				if (channel->playing) {
-					free_playing(channel->playing);
-					channel->playing = NULL;
-				}
-			}
-			if (playing) free_playing(playing);
-			return;
-		} else if (channel->playing && (entry->mask & IT_ENTRY_VOLPAN) && ((entry->volpan>>4) == 0xF)) {
-			/* Don't retrigger note; portamento in the volume column. */
-		} else if (channel->playing &&
-		           (entry->mask & IT_ENTRY_EFFECT) &&
-		           (entry->effect == IT_TONE_PORTAMENTO ||
-		            entry->effect == IT_VOLSLIDE_TONEPORTA)) {
-			/* Don't retrigger note; portamento in the effects column. */
-		} else {
-			channel->destnote = IT_NOTE_OFF;
-
-			if (!channel->playing) {
-				channel->playing = new_playing();
-				if (!channel->playing) {
-					if (playing) free_playing(playing);
-					return;
-				}
-				// Adding the following seems to do the trick for the case where a piece starts with an instrument alone and then some notes alone.
-				retrigger_xm_envelopes(channel->playing);
-			}
-			else if (playing) {
-				/* volume rampy stuff! move note to NNA */
-				int i;
-				IT_PLAYING * ptemp;
-				if (playing->sample) ptemp = playing;
-				else ptemp = channel->playing;
-				if (!ptemp) {
-					if (playing) free_playing(playing);
-					return;
-				}
-				playing = NULL;
-				for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-					if (!sigrenderer->playing[i]) {
-						ptemp->declick_stage = 3;
-						ptemp->flags |= IT_PLAYING_SUSTAINOFF | IT_PLAYING_FADING;
-						sigrenderer->playing[i] = ptemp;
-						ptemp = NULL;
-						break;
-					}
-				}
-				if (ptemp) free_playing(ptemp);
-			}
-
-			channel->playing->flags = 0;
-			channel->playing->resampling_quality = sigrenderer->resampling_quality;
-			channel->playing->channel = channel;
-			channel->playing->sample = &sigdata->sample[channel->sample-1];
-			if (sigdata->flags & IT_USE_INSTRUMENTS)
-				channel->playing->instrument = &sigdata->instrument[channel->instrument-1];
-			else
-				channel->playing->instrument = NULL;
-			channel->playing->env_instrument = channel->playing->instrument;
-			channel->playing->sampnum = channel->sample;
-			channel->playing->instnum = channel->instrument;
-			channel->playing->declick_stage = 0;
-			channel->playing->channel_volume = channel->channelvolume;
-			channel->playing->note = channel->truenote;
-			channel->playing->enabled_envelopes = 0;
-			channel->playing->volume_offset = 0;
-			channel->playing->panning_offset = 0;
-			//channel->playing->output = channel->output;
-			if (sigdata->flags & IT_USE_INSTRUMENTS) {
-				IT_PLAYING * playing = channel->playing;
-				IT_INSTRUMENT * instrument = playing->instrument;
-				if (instrument->volume_envelope.flags & IT_ENVELOPE_ON) playing->enabled_envelopes |= IT_ENV_VOLUME;
-				if (instrument->pan_envelope.flags & IT_ENVELOPE_ON) playing->enabled_envelopes |= IT_ENV_PANNING;
-				//if (instrument->output) playing->output = instrument->output;
-			}
-			channel->playing->filter_cutoff = 127;
-			channel->playing->filter_resonance = 0;
-			channel->playing->true_filter_cutoff = 127 << 8;
-			channel->playing->true_filter_resonance = 0;
-			channel->playing->vibrato_speed = 0;
-			channel->playing->vibrato_depth = 0;
-			channel->playing->vibrato_n = 0;
-			channel->playing->vibrato_time = 0;
-			channel->playing->vibrato_waveform = 0;
-			channel->playing->tremolo_speed = 0;
-			channel->playing->tremolo_depth = 0;
-			channel->playing->tremolo_time = 0;
-			channel->playing->tremolo_waveform = 0;
-			channel->playing->panbrello_speed = 0;
-			channel->playing->panbrello_depth = 0;
-			channel->playing->panbrello_time = 0;
-			channel->playing->panbrello_waveform = 0;
-			channel->playing->panbrello_random = 0;
-			channel->playing->sample_vibrato_time = 0;
-			channel->playing->sample_vibrato_waveform = channel->playing->sample->vibrato_waveform;
-			channel->playing->sample_vibrato_depth = 0;
-			channel->playing->slide = 0;
-			channel->playing->finetune = channel->playing->sample->finetune;
-			it_reset_filter_state(&channel->playing->filter_state[0]); // Are these
-			it_reset_filter_state(&channel->playing->filter_state[1]); // necessary?
-			it_playing_reset_resamplers(channel->playing, 0);
-
-			/** WARNING - is everything initialised? */
-		}
-	}
-
-	if (!((entry->mask & IT_ENTRY_EFFECT) && entry->effect == IT_XM_KEY_OFF && entry->effectvalue == 0) &&
-		!((entry->mask & IT_ENTRY_NOTE) && entry->note >= 120) &&
-		(entry->mask & (IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT)) == (IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT))
-	{
-		if (channel->playing) retrigger_xm_envelopes(channel->playing);
-		get_default_volpan(sigdata, channel);
-	}
-
-	if ((entry->mask & IT_ENTRY_VOLPAN) && ((entry->volpan>>4) == 0xF)) {
-		/* Tone Portamento */
-		unsigned char v = (entry->volpan & 15) << 4;
-		if (v == 0)
-			v = channel->lastG;
-		channel->lastG = v;
-		if (entry->mask & IT_ENTRY_NOTE)
-			if (channel->sample && channel->note < 120)
-				channel->destnote = channel->truenote;
-		channel->toneporta = v << 4;
-	} else if ((entry->mask & IT_ENTRY_EFFECT) &&
-	           (entry->effect == IT_TONE_PORTAMENTO ||
-	            entry->effect == IT_VOLSLIDE_TONEPORTA)) {
-		unsigned char v;
-		if (entry->effect == IT_TONE_PORTAMENTO)
-			v = entry->effectvalue;
-		else
-			v = 0;
-		if (v == 0)
-			v = channel->lastG;
-		channel->lastG = v;
-		if (entry->mask & IT_ENTRY_NOTE)
-			if (channel->sample && channel->note < 120)
-				channel->destnote = channel->truenote;
-		channel->toneporta = v << 4;
-	}
-
-	if (entry->mask & IT_ENTRY_VOLPAN) {
-		int effect = entry->volpan >> 4;
-		int value  = entry->volpan & 15;
-		switch (effect) {
-			case 0x6: /* Volume slide down */
-				channel->xm_volslide = -value;
-				break;
-			case 0x7: /* Volume slide up */
-				channel->xm_volslide = value;
-				break;
-			case 0x8: /* Fine volume slide down */
-				channel->volume -= value;
-				if (channel->volume > 64) channel->volume = 0;
-				break;
-			case 0x9: /* Fine volume slide up */
-				channel->volume += value;
-				if (channel->volume > 64) channel->volume = 64;
-				break;
-			case 0xA: /* Set vibrato speed */
-				if (value)
-					channel->lastHspeed = value;
-				if (channel->playing)
-					channel->playing->vibrato_speed = channel->lastHspeed;
-				break;
-			case 0xB: /* Vibrato */
-				if (value)
-					channel->lastHdepth = value << 2; /** WARNING: correct ? */
-				if (channel->playing) {
-					channel->playing->vibrato_depth = channel->lastHdepth;
-					channel->playing->vibrato_speed = channel->lastHspeed;
-					channel->playing->vibrato_n++;
-				}
-				break;
-			case 0xC: /* Set panning */
-				channel->truepan = 32 + value*(17*64);
-				break;
-			case 0xD: /* Pan slide left */
-				/* -128 is a special case for emulating a 'feature' in FT2.
-				 * As soon as effects are processed, it goes hard left.
-				 */
-				channel->panslide = value ? -value : -128;
-				break;
-			case 0xE: /* Pan slide Right */
-				channel->panslide = value;
-				break;
-			case 0xF: /* Tone porta */
-				break;
-			default:  /* Volume */
-				channel->volume = entry->volpan - 0x10;
-				break;
-		}
-	}
-
-	if (playing) free_playing(playing);
-}
-
-
-
-/* This function assumes !IT_IS_END_ROW(entry). */
-static int process_note_data(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry, int ignore_cxx)
-{
-	DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
-
-	if (sigdata->flags & IT_WAS_AN_XM)
-		process_xm_note_data(sigrenderer, entry);
-	else
-		if (process_it_note_data(sigrenderer, entry)) return 0;
-
-	return process_effects(sigrenderer, entry, ignore_cxx);
-}
-
-
-
-static int process_entry(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry, int ignore_cxx)
-{
-	IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
-
-	if (entry->mask & IT_ENTRY_NOTE)
-		channel->note = entry->note;
-
-	if ((entry->mask & (IT_ENTRY_NOTE|IT_ENTRY_EFFECT)) && (sigrenderer->sigdata->flags & IT_WAS_A_669)) {
-		reset_channel_effects(channel);
-		// XXX unknown
-		if (channel->playing) channel->playing->finetune = 0;
-	}
-
-	if ((entry->mask & IT_ENTRY_EFFECT) && entry->effect == IT_S) {
-		/* channel->lastS was set in update_pattern_variables(). */
-		unsigned char effectvalue = channel->lastS;
-		if (effectvalue >> 4 == IT_S_NOTE_DELAY) {
-			channel->note_delay_count = effectvalue & 15;
-			if (channel->note_delay_count == 0)
-				channel->note_delay_count = 1;
-			channel->note_delay_entry = entry;
-			return 0;
-		}
-	}
-
-	return process_note_data(sigrenderer, entry, ignore_cxx);
-}
-
-
-
-static void update_tick_counts(DUMB_IT_SIGRENDERER *sigrenderer)
-{
-	int i;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		IT_CHANNEL *channel = &sigrenderer->channel[i];
-
-		if (channel->key_off_count) {
-			channel->key_off_count--;
-			if (channel->key_off_count == 0)
-				xm_note_off(sigrenderer->sigdata, channel);
-		} else if (channel->note_cut_count) {
-			channel->note_cut_count--;
-			if (channel->note_cut_count == 0) {
-				if (sigrenderer->sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_PTM))
-					channel->volume = 0;
-				else if (channel->playing) {
-					int i;
-					for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-						if (!sigrenderer->playing[i]) {
-							channel->playing->declick_stage = 3;
-							sigrenderer->playing[i] = channel->playing;
-							channel->playing = NULL;
-							break;
-						}
-					}
-					if (channel->playing) {
-						free_playing(channel->playing);
-						channel->playing = NULL;
-					}
-				}
-			}
-		} else if (channel->note_delay_count) {
-			channel->note_delay_count--;
-			if (channel->note_delay_count == 0)
-				process_note_data(sigrenderer, channel->note_delay_entry, 0);
-					/* Don't bother checking the return value; if the note
-					 * was delayed, there can't have been a speed=0.
-					 */
-		}
-	}
-}
-
-
-
-static int envelope_get_y(IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe)
-{
-#if 1
-	(void)envelope; //TODO: remove the parameter
-	return pe->value;
-#else
-	int ys, ye;
-	int ts, te;
-	int t;
-
-	if (pe->next_node <= 0)
-		return envelope->node_y[0] << IT_ENVELOPE_SHIFT;
-
-	if (pe->next_node >= envelope->n_nodes)
-		return envelope->node_y[envelope->n_nodes-1] << IT_ENVELOPE_SHIFT;
-
-	ys = envelope->node_y[pe->next_node-1] << IT_ENVELOPE_SHIFT;
-	ts = envelope->node_t[pe->next_node-1];
-	te = envelope->node_t[pe->next_node];
-
-	if (ts == te)
-		return ys;
-
-	ye = envelope->node_y[pe->next_node] << IT_ENVELOPE_SHIFT;
-
-	t = pe->tick;
-
-	return ys + (ye - ys) * (t - ts) / (te - ts);
-#endif
-}
-
-
-
-#if 0
-static int it_envelope_end(IT_PLAYING *playing, IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe)
-{
-	if (pe->next_node >= envelope->n_nodes)
-		return 1;
-
-	if (pe->tick < envelope->node_t[pe->next_node]) return 0;
-
-	if ((envelope->flags & IT_ENVELOPE_LOOP_ON) &&
-	    envelope->loop_end >= pe->next_node &&
-	    envelope->node_t[envelope->loop_end] <= pe->tick) return 0;
-
-	if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) &&
-	    !(playing->flags & IT_PLAYING_SUSTAINOFF) &&
-	    envelope->sus_loop_end >= pe->next_node &&
-	    envelope->node_t[envelope->sus_loop_end] <= pe->tick) return 0;
-
-	if (envelope->node_t[envelope->n_nodes-1] <= pe->tick) return 1;
-
-	return 0;
-}
-#endif
-
-
-
-/* Returns 1 when fading should be initiated for a volume envelope. */
-static int update_it_envelope(IT_PLAYING *playing, IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe, int flags)
-{
-	if (!(playing->enabled_envelopes & flags) || !envelope->n_nodes)
-		return 0;
-
-	ASSERT(envelope->n_nodes > 0);
-
-	if (pe->tick <= 0)
-		pe->value = envelope->node_y[0] << IT_ENVELOPE_SHIFT;
-	else if (pe->tick >= envelope->node_t[envelope->n_nodes-1]) {
-		pe->value = envelope->node_y[envelope->n_nodes-1] << IT_ENVELOPE_SHIFT;
-	} else {
-		int ys = envelope->node_y[pe->next_node-1] << IT_ENVELOPE_SHIFT;
-		int ts = envelope->node_t[pe->next_node-1];
-		int te = envelope->node_t[pe->next_node];
-
-		if (ts == te)
-			pe->value = ys;
-		else {
-			int ye = envelope->node_y[pe->next_node] << IT_ENVELOPE_SHIFT;
-			int t = pe->tick;
-
-			pe->value = ys + (ye - ys) * (t - ts) / (te - ts);
-		}
-	}
-
-	pe->tick++;
-
-	recalculate_it_envelope_node(pe, envelope);
-
-	if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) && !(playing->flags & IT_PLAYING_SUSTAINOFF)) {
-		if (pe->tick > envelope->node_t[envelope->sus_loop_end]) {
-			pe->next_node = envelope->sus_loop_start + 1;
-			ASSERT(pe->next_node <= envelope->n_nodes);
-			pe->tick = envelope->node_t[envelope->sus_loop_start];
-			return 0;
-		}
-	} else if (envelope->flags & IT_ENVELOPE_LOOP_ON) {
-		if (pe->tick > envelope->node_t[envelope->loop_end]) {
-			pe->next_node = envelope->loop_start + 1;
-			ASSERT(pe->next_node <= envelope->n_nodes);
-			pe->tick = envelope->node_t[envelope->loop_start];
-			return 0;
-		}
-	}
-	else if (pe->tick > envelope->node_t[envelope->n_nodes - 1])
-		return 1;
-
-	return 0;
-}
-
-
-
-static void update_it_envelopes(IT_PLAYING *playing)
-{
-	IT_ENVELOPE *envelope = &playing->env_instrument->volume_envelope;
-	IT_PLAYING_ENVELOPE *pe = &playing->volume_envelope;
-
-	if (update_it_envelope(playing, envelope, pe, IT_ENV_VOLUME)) {
-		playing->flags |= IT_PLAYING_FADING;
-		if (pe->value == 0)
-			playing->flags |= IT_PLAYING_DEAD;
-	}
-
-	update_it_envelope(playing, &playing->env_instrument->pan_envelope, &playing->pan_envelope, IT_ENV_PANNING);
-	update_it_envelope(playing, &playing->env_instrument->pitch_envelope, &playing->pitch_envelope, IT_ENV_PITCH);
-}
-
-
-
-static int xm_envelope_is_sustaining(IT_PLAYING *playing, IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe)
-{
-	if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) && !(playing->flags & IT_PLAYING_SUSTAINOFF))
-		if (envelope->sus_loop_start < envelope->n_nodes)
-			if (pe->tick == envelope->node_t[envelope->sus_loop_start])
-				return 1;
-	return 0;
-}
-
-
-
-static void update_xm_envelope(IT_PLAYING *playing, IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe)
-{
-	if (!(envelope->flags & IT_ENVELOPE_ON))
-		return;
-
-	if (xm_envelope_is_sustaining(playing, envelope, pe))
-		return;
-
-	if (pe->tick >= envelope->node_t[envelope->n_nodes-1])
-		return;
-
-	pe->tick++;
-
-	/* pe->next_node must be kept up to date for envelope_get_y(). */
-	while (pe->tick > envelope->node_t[pe->next_node])
-		pe->next_node++;
-
-	if ((envelope->flags & IT_ENVELOPE_LOOP_ON) && envelope->loop_end < envelope->n_nodes) {
-		if (pe->tick == envelope->node_t[envelope->loop_end]) {
-			pe->next_node = MID(0, envelope->loop_start, envelope->n_nodes - 1);
-			pe->tick = envelope->node_t[pe->next_node];
-		}
-	}
-
-	xm_envelope_calculate_value(envelope, pe);
-}
-
-
-
-static void update_xm_envelopes(IT_PLAYING *playing)
-{
-	update_xm_envelope(playing, &playing->env_instrument->volume_envelope, &playing->volume_envelope);
-	update_xm_envelope(playing, &playing->env_instrument->pan_envelope, &playing->pan_envelope);
-}
-
-
-
-static void update_fadeout(DUMB_IT_SIGDATA *sigdata, IT_PLAYING *playing)
-{
-	if (playing->flags & IT_PLAYING_FADING) {
-		playing->fadeoutcount -= playing->env_instrument->fadeout;
-		if (playing->fadeoutcount <= 0) {
-			playing->fadeoutcount = 0;
-			if (!(sigdata->flags & IT_WAS_AN_XM))
-				playing->flags |= IT_PLAYING_DEAD;
-		}
-	}
-}
-
-static int apply_pan_envelope(IT_PLAYING *playing);
-static float calculate_volume(DUMB_IT_SIGRENDERER *sigrenderer, IT_PLAYING *playing, float volume);
-
-static void playing_volume_setup(DUMB_IT_SIGRENDERER * sigrenderer, IT_PLAYING * playing, float invt2g)
-{
-	DUMB_IT_SIGDATA * sigdata = sigrenderer->sigdata;
-	int pan;
-	float vol, span;
-    float rampScale;
-    int ramp_style = sigrenderer->ramp_style;
- 
-	pan = apply_pan_envelope(playing);
-
-	if ((sigrenderer->n_channels >= 2) && (sigdata->flags & IT_STEREO) && (sigrenderer->n_channels != 3 || !IT_IS_SURROUND_SHIFTED(pan))) {
-		if (!IT_IS_SURROUND_SHIFTED(pan)) {
-			span = (pan - (32<<8)) * sigdata->pan_separation * (1.0f / ((32<<8) * 128));
-			vol = 0.5f * (1.0f - span);
-			playing->float_volume[0] = vol;
-			playing->float_volume[1] = 1.0f - vol;
-		} else {
-			playing->float_volume[0] = -0.5f;
-			playing->float_volume[1] = 0.5f;
-		}
- 	} else {
-		playing->float_volume[0] = 1.0f;
-		playing->float_volume[1] = 1.0f;
-	}
-
-	vol = calculate_volume(sigrenderer, playing, 1.0f);
-	playing->float_volume[0] *= vol;
-	playing->float_volume[1] *= vol;
-    
-    rampScale = 4;
-
-    if (ramp_style > 0 && playing->declick_stage == 2) {
-        if ((playing->ramp_volume[0] == 0 && playing->ramp_volume[1] == 0) || vol == 0)
-            rampScale = 48;
-    }
-
-    if (ramp_style == 0 || (ramp_style < 2 && playing->declick_stage == 2)) {
-		if (playing->declick_stage <= 2) {
-			playing->ramp_volume[0] = playing->float_volume[0];
-			playing->ramp_volume[1] = playing->float_volume[1];
-			playing->declick_stage = 2;
-		} else {
-			playing->float_volume[0] = 0;
-			playing->float_volume[1] = 0;
-			playing->ramp_volume[0] = 0;
-			playing->ramp_volume[1] = 0;
-			playing->declick_stage = 5;
-		}
-		playing->ramp_delta[0] = 0;
-        playing->ramp_delta[1] = 0;
-    } else {
-        if (playing->declick_stage == 0) {
-            playing->ramp_volume[0] = 0;
-            playing->ramp_volume[1] = 0;
-            rampScale = 48;
-            playing->declick_stage++;
-        } else if (playing->declick_stage == 1) {
-            rampScale = 48;
-        } else if (playing->declick_stage >= 3) {
-            playing->float_volume[0] = 0;
-            playing->float_volume[1] = 0;
-            if (playing->declick_stage == 3)
-                playing->declick_stage++;
-            rampScale = 48;
-        }
-        playing->ramp_delta[0] = rampScale * invt2g * (playing->float_volume[0] - playing->ramp_volume[0]);
-        playing->ramp_delta[1] = rampScale * invt2g * (playing->float_volume[1] - playing->ramp_volume[1]);
-    }
-}
-
-static void process_playing(DUMB_IT_SIGRENDERER *sigrenderer, IT_PLAYING *playing, float invt2g)
-{
-	DUMB_IT_SIGDATA * sigdata = sigrenderer->sigdata;
-
-	if (playing->instrument) {
-		if (sigdata->flags & IT_WAS_AN_XM)
-			update_xm_envelopes(playing);
-		else
-			update_it_envelopes(playing);
-		update_fadeout(sigdata, playing);
-	}
-
-	playing_volume_setup(sigrenderer, playing, invt2g);
-
-	if (sigdata->flags & IT_WAS_AN_XM) {
-		/* 'depth' is used to store the tick number for XM files. */
-		if (playing->sample_vibrato_depth < playing->sample->vibrato_rate)
-			playing->sample_vibrato_depth++;
-	} else {
-		playing->sample_vibrato_depth += playing->sample->vibrato_rate;
-		if (playing->sample_vibrato_depth > playing->sample->vibrato_depth << 8)
-			playing->sample_vibrato_depth = playing->sample->vibrato_depth << 8;
-	}
-
-	playing->sample_vibrato_time += playing->sample->vibrato_speed;
-}
-
-static int delta_to_note(float delta, int base)
-{
-#define DUMB_LOG2(x) ((float)log((x))/(float)log(2.0f))
-
-	float note;
-	note = DUMB_LOG2(delta * 65536.f / (float)base)*12.0f+60.5f;
-	if (note > 119) note = 119;
-	else if (note < 0) note = 0;
-	return (int)note;
-
-#undef DUMB_LOG2
-}
-
-// Period table for Protracker octaves 0-5:
-#if 0
-static const unsigned short ProTrackerPeriodTable[6*12] =
-{
-	1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907,
-	856,808,762,720,678,640,604,570,538,508,480,453,
-	428,404,381,360,339,320,302,285,269,254,240,226,
-	214,202,190,180,170,160,151,143,135,127,120,113,
-	107,101,95,90,85,80,75,71,67,63,60,56,
-	53,50,47,45,42,40,37,35,33,31,30,28
-};
-
-
-static const unsigned short ProTrackerTunedPeriods[16*12] = 
-{
-	1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907,
-	1700,1604,1514,1430,1348,1274,1202,1134,1070,1010,954,900,
-	1688,1592,1504,1418,1340,1264,1194,1126,1064,1004,948,894,
-	1676,1582,1492,1408,1330,1256,1184,1118,1056,996,940,888,
-	1664,1570,1482,1398,1320,1246,1176,1110,1048,990,934,882,
-	1652,1558,1472,1388,1310,1238,1168,1102,1040,982,926,874,
-	1640,1548,1460,1378,1302,1228,1160,1094,1032,974,920,868,
-	1628,1536,1450,1368,1292,1220,1150,1086,1026,968,914,862,
-	1814,1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,
-	1800,1700,1604,1514,1430,1350,1272,1202,1134,1070,1010,954,
-	1788,1688,1592,1504,1418,1340,1264,1194,1126,1064,1004,948,
-	1774,1676,1582,1492,1408,1330,1256,1184,1118,1056,996,940,
-	1762,1664,1570,1482,1398,1320,1246,1176,1110,1048,988,934,
-	1750,1652,1558,1472,1388,1310,1238,1168,1102,1040,982,926,
-	1736,1640,1548,1460,1378,1302,1228,1160,1094,1032,974,920,
-	1724,1628,1536,1450,1368,1292,1220,1150,1086,1026,968,914 
-};
-#endif
-
-static void process_all_playing(DUMB_IT_SIGRENDERER *sigrenderer)
-{
-	DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
-	int i;
-
-	float invt2g = 1.0f / ((float)TICK_TIME_DIVIDEND / (float)sigrenderer->tempo / 256.0f);
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		IT_CHANNEL *channel = &sigrenderer->channel[i];
-		IT_PLAYING *playing = channel->playing;
-
-		if (playing) {
-			int vibrato_shift;
-			switch (playing->vibrato_waveform)
-			{
-			default:
-				vibrato_shift = it_sine[playing->vibrato_time];
-				break;
-			case 1:
-				vibrato_shift = it_sawtooth[playing->vibrato_time];
-				break;
-			case 2:
-				vibrato_shift = it_squarewave[playing->vibrato_time];
-				break;
-			case 3:
-				vibrato_shift = (rand() % 129) - 64;
-				break;
-			case 4:
-				vibrato_shift = it_xm_squarewave[playing->vibrato_time];
-				break;
-			case 5:
-				vibrato_shift = it_xm_ramp[playing->vibrato_time];
-				break;
-			case 6:
-				vibrato_shift = it_xm_ramp[255-playing->vibrato_time];
-				break;
-			}
-			vibrato_shift *= playing->vibrato_n;
-			vibrato_shift *= playing->vibrato_depth;
-			vibrato_shift >>= 4;
-
-			if (sigdata->flags & IT_OLD_EFFECTS)
-				vibrato_shift = -vibrato_shift;
-
-			playing->volume = channel->volume;
-			playing->pan = channel->truepan;
-
-			if (playing->volume_offset) {
-				playing->volume += (playing->volume_offset * playing->volume) >> 7;
-				if (playing->volume > 64) {
-					if (playing->volume_offset < 0) playing->volume = 0;
-					else playing->volume = 64;
-				}
-			}
-
-			if (playing->panning_offset && !IT_IS_SURROUND_SHIFTED(playing->pan)) {
-				playing->pan += playing->panning_offset << IT_ENVELOPE_SHIFT;
-				if (playing->pan > 64 << IT_ENVELOPE_SHIFT) {
-					if (playing->panning_offset < 0) playing->pan = 0;
-					else playing->pan = 64 << IT_ENVELOPE_SHIFT;
-				}
-			}
-
-			if (sigdata->flags & IT_LINEAR_SLIDES) {
-				int currpitch = ((playing->note - 60) << 8) + playing->slide
-				                                            + vibrato_shift
-															+ playing->finetune;
-
-				/* We add a feature here, which is that of keeping the pitch
-				 * within range. Otherwise it crashes. Trust me. It happened.
-				 * The limit 32768 gives almost 11 octaves either way.
-				 */
-				if (currpitch < -32768)
-					currpitch = -32768;
-				else if (currpitch > 32767)
-					currpitch = 32767;
-
-				playing->delta = (float)pow(DUMB_PITCH_BASE, currpitch);
-				playing->delta *= playing->sample->C5_speed * (1.f / 65536.0f);
-			} else {
-				int slide = playing->slide + vibrato_shift;
-
-				playing->delta = (float)pow(DUMB_PITCH_BASE, ((60 - playing->note) << 8) - playing->finetune );
-				/* playing->delta is 1.0 for C-5, 0.5 for C-6, etc. */
-
-				playing->delta *= 1.0f / playing->sample->C5_speed;
-
-				playing->delta -= slide / AMIGA_DIVISOR;
-
-				if (playing->delta < (1.0f / 65536.0f) / 32768.0f) {
-					// Should XM notes die if Amiga slides go out of range?
-					playing->flags |= IT_PLAYING_DEAD;
-					playing->delta = 1. / 32768.;
-					continue;
-				}
-
-				playing->delta = (1.0f / 65536.0f) / playing->delta;
-			}
-
-			if (playing->channel->glissando && playing->channel->toneporta && playing->channel->destnote < 120) {
-				playing->delta = (float)pow(DUMB_SEMITONE_BASE, delta_to_note(playing->delta, (int)playing->sample->C5_speed) - 60)
-					* playing->sample->C5_speed * (1.f / 65536.f);
-			}
-
-			/*
-			if ( channel->arpeggio ) { // another FT2 bug...
-				if ((sigdata->flags & (IT_LINEAR_SLIDES|IT_WAS_AN_XM|IT_WAS_A_MOD)) == (IT_WAS_AN_XM|IT_LINEAR_SLIDES) &&
-					playing->flags & IT_PLAYING_SUSTAINOFF)
-				{
-					if ( channel->arpeggio > 0xFF )
-						playing->delta = playing->sample->C5_speed * (1.f / 65536.f);
-				}
-				else*/
-				{
-					int tick = sigrenderer->tick - 1;
-					if ((sigrenderer->sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_MOD))!=IT_WAS_AN_XM)
-						tick = sigrenderer->speed - tick - 1;
-					else if (tick == sigrenderer->speed - 1)
-						tick = 0;
-					else
-						++tick;
-					playing->delta *= (float)pow(DUMB_SEMITONE_BASE, channel->arpeggio_offsets[channel->arpeggio_table[tick&31]]);
-				}
-			/*
-			}*/
-
-			playing->filter_cutoff = channel->filter_cutoff;
-			playing->filter_resonance = channel->filter_resonance;
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		if (sigrenderer->channel[i].playing) {
-			process_playing(sigrenderer, sigrenderer->channel[i].playing, invt2g);
-			if (!(sigdata->flags & IT_WAS_AN_XM)) {
-				//if ((sigrenderer->channel[i].playing->flags & (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) == (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) {
-				// This change was made so Gxx would work correctly when a note faded out or whatever. Let's hope nothing else was broken by it.
-				if (sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD) {
-					free_playing(sigrenderer->channel[i].playing);
-					sigrenderer->channel[i].playing = NULL;
-				}
-			}
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-		if (sigrenderer->playing[i]) {
-			process_playing(sigrenderer, sigrenderer->playing[i], invt2g);
-			if (sigrenderer->playing[i]->flags & IT_PLAYING_DEAD) {
-				free_playing(sigrenderer->playing[i]);
-				sigrenderer->playing[i] = NULL;
-			}
-		}
-	}
-}
-
-
-
-static int process_tick(DUMB_IT_SIGRENDERER *sigrenderer)
-{
-	DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
-
-	// Set note vol/freq to vol/freq set for each channel
-
-	if (sigrenderer->speed && --sigrenderer->tick == 0) {
-		reset_tick_counts(sigrenderer);
-		sigrenderer->tick = sigrenderer->speed;
-		sigrenderer->rowcount--;
-		if (sigrenderer->rowcount == 0) {
-			sigrenderer->rowcount = 1;
-
-#ifdef BIT_ARRAY_BULLSHIT
-			if (sigrenderer->n_rows)
-			{
-#if 1
-				/*
-				if (bit_array_test(sigrenderer->played, sigrenderer->order * 256 + sigrenderer->row))
-				{
-					if (sigrenderer->callbacks->loop) {
-						if ((*sigrenderer->callbacks->loop)(sigrenderer->callbacks->loop_data))
-							return 1;
-						bit_array_reset(sigrenderer->played);
-						if (sigrenderer->speed == 0)
-                            goto speed0; I love goto
-					}
-				}
-				*/
-#endif
-				bit_array_set(sigrenderer->played, sigrenderer->order * 256 + sigrenderer->row);
-				{
-					int n;
-					for (n = 0; n < DUMB_IT_N_CHANNELS; n++)
-					{
-						IT_CHANNEL * channel = &sigrenderer->channel[n];
-						if (channel->played_patjump)
-						{
-							if (channel->played_patjump_order == sigrenderer->order)
-							{
-								bit_array_set(channel->played_patjump, sigrenderer->row);
-							}
-							/*
-							else if ((channel->played_patjump_order & 0x7FFF) == sigrenderer->order)
-							{
-								channel->played_patjump_order |= 0x4000;
-							}
-							else if ((channel->played_patjump_order & 0x3FFF) == sigrenderer->order)
-							{
-								if ((sigdata->flags & (IT_WAS_AN_XM|IT_WAS_A_MOD)) == IT_WAS_AN_XM)
-								{
-                                    joy, was XM, pattern loop bug triggered break to row in same order
-									bit_array_mask(sigrenderer->played, channel->played_patjump, sigrenderer->order * 256);
-								}
-								bit_array_destroy(channel->played_patjump);
-								channel->played_patjump = 0;
-								channel->played_patjump_order = 0xFFFE;
-							}
-							*/
-							else
-							{
-								bit_array_destroy(channel->played_patjump);
-								channel->played_patjump = 0;
-								channel->played_patjump_order = 0xFFFE;
-							}
-						}
-					}
-				}
-			}
-#endif
-
-			sigrenderer->processrow++;
-
-			if (sigrenderer->processrow >= sigrenderer->n_rows) {
-				IT_PATTERN *pattern;
-				int n;
-				int processorder = sigrenderer->processorder;
-
-				if ((sigrenderer->processrow|0xC00) == 0xFFFE + 1) { /* It was incremented above! */
-					sigrenderer->processrow = sigrenderer->breakrow;
-					sigrenderer->breakrow = 0;
-					for (n = 0; n < DUMB_IT_N_CHANNELS; n++) sigrenderer->channel[n].pat_loop_end_row = 0;
-				} else {
-					sigrenderer->processrow = sigrenderer->breakrow;
-					sigrenderer->breakrow = 0; // XXX lolwut
-				}
-
-				if (sigrenderer->processorder == 0xFFFF)
-					sigrenderer->processorder = sigrenderer->order - 1;
-
-				for (;;) {
-					sigrenderer->processorder++;
-
-					if (sigrenderer->processorder >= sigdata->n_orders) {
-						sigrenderer->processorder = sigrenderer->restart_position;
-						if (sigrenderer->processorder >= sigdata->n_orders) {
-							/* Restarting beyond end. We'll loop for now. */
-							sigrenderer->processorder = -1;
-							continue;
-						}
-						if (sigdata->flags & IT_WAS_AN_OKT) {
-							/* Reset some things */
-							sigrenderer->speed = sigdata->speed;
-							sigrenderer->tempo = sigdata->tempo;
-							for (n = 0; n < DUMB_IT_N_CHANNELS; n++) {
-								xm_note_off(sigdata, &sigrenderer->channel[n]);
-							}
-						}
-					}
-
-					n = sigdata->order[sigrenderer->processorder];
-
-					if (n < sigdata->n_patterns)
-						break;
-
-#ifdef INVALID_ORDERS_END_SONG
-					if (n != IT_ORDER_SKIP)
-#else
-					if (n == IT_ORDER_END)
-#endif
-					{
-						sigrenderer->processorder = sigrenderer->restart_position - 1;
-					}
-
-#ifdef BIT_ARRAY_BULLSHIT
-					/* Fix play tracking and timekeeping for orders containing skip commands */
-					for (n = 0; n < 256; n++) {
-						bit_array_set(sigrenderer->played, sigrenderer->processorder * 256 + n);
-						timekeeping_array_push(sigrenderer->row_timekeeper, sigrenderer->processorder * 256 + n, sigrenderer->time_played);
-						timekeeping_array_bump(sigrenderer->row_timekeeper, sigrenderer->processorder * 256 + n);
-					}
-#endif
-				}
-
-				pattern = &sigdata->pattern[n];
-
-				n = sigrenderer->n_rows;
-				sigrenderer->n_rows = pattern->n_rows;
-
-				if (sigrenderer->processrow >= sigrenderer->n_rows)
-					sigrenderer->processrow = 0;
-
-/** WARNING - everything pertaining to a new pattern initialised? */
-
-				sigrenderer->entry = sigrenderer->entry_start = pattern->entry;
-				sigrenderer->entry_end = sigrenderer->entry + pattern->n_entries;
-
-				/* If n_rows was 0, we're only just starting. Don't do anything weird here. */
-				/* added: process row check, for break to row spooniness */
-				if (n && (processorder == 0xFFFF ? sigrenderer->order > sigrenderer->processorder : sigrenderer->order >= sigrenderer->processorder)
-#ifdef BIT_ARRAY_BULLSHIT
-					&& bit_array_test(sigrenderer->played, sigrenderer->processorder * 256 + sigrenderer->processrow)
-#endif
-					) {
-#ifdef BIT_ARRAY_BULLSHIT
-					sigrenderer->looped = 1;
-#endif
-					if (sigrenderer->callbacks->loop) {
-						if ((*sigrenderer->callbacks->loop)(sigrenderer->callbacks->loop_data))
-							return 1;
-#ifdef BIT_ARRAY_BULLSHIT
-						bit_array_reset(sigrenderer->played);
-#endif
-						if (sigrenderer->speed == 0)
-							goto speed0; /* I love goto */
-					}
-				}
-				sigrenderer->order = sigrenderer->processorder;
-
-				n = sigrenderer->processrow;
-				while (n) {
-					while (sigrenderer->entry < sigrenderer->entry_end) {
-						if (IT_IS_END_ROW(sigrenderer->entry)) {
-							sigrenderer->entry++;
-							break;
-						}
-						sigrenderer->entry++;
-					}
-					n--;
-				}
-				sigrenderer->row = sigrenderer->processrow;
-			} else {
-				if (sigrenderer->entry) {
-					while (sigrenderer->entry < sigrenderer->entry_end) {
-						if (IT_IS_END_ROW(sigrenderer->entry)) {
-							sigrenderer->entry++;
-							break;
-						}
-						sigrenderer->entry++;
-					}
-					sigrenderer->row++;
-				} else {
-#ifdef BIT_ARRAY_BULLSHIT
-					bit_array_clear(sigrenderer->played, sigrenderer->order * 256);
-#endif
-					sigrenderer->entry = sigrenderer->entry_start;
-					sigrenderer->row = 0;
-				}
-			}
-
-#ifdef BIT_ARRAY_BULLSHIT
-			if (sigrenderer->looped == 0) {
-				timekeeping_array_push(sigrenderer->row_timekeeper, sigrenderer->order * 256 + sigrenderer->row, sigrenderer->time_played);
-			}
-			timekeeping_array_bump(sigrenderer->row_timekeeper, sigrenderer->order * 256 + sigrenderer->row);
-#endif
-
-			if (!(sigdata->flags & IT_WAS_A_669))
-				reset_effects(sigrenderer);
-
-			{
-				IT_ENTRY *entry = sigrenderer->entry;
-				int ignore_cxx = 0;
-
-				while (entry < sigrenderer->entry_end && !IT_IS_END_ROW(entry))
-					ignore_cxx |= update_pattern_variables(sigrenderer, entry++);
-
-				entry = sigrenderer->entry;
-
-				while (entry < sigrenderer->entry_end && !IT_IS_END_ROW(entry))
-					if (process_entry(sigrenderer, entry++, sigdata->flags & IT_WAS_AN_XM ? 0 : ignore_cxx))
-						return 1;
-			}
-
-			if (sigdata->flags & IT_WAS_AN_OKT)
-				update_effects(sigrenderer);
-			else if (!(sigdata->flags & IT_OLD_EFFECTS))
-				update_smooth_effects(sigrenderer);
-		} else {
-			{
-				IT_ENTRY *entry = sigrenderer->entry;
-
-				while (entry < sigrenderer->entry_end && !IT_IS_END_ROW(entry)) {
-					if (entry->mask & IT_ENTRY_EFFECT && entry->effect != IT_SET_SAMPLE_OFFSET)
-						process_effects(sigrenderer, entry, 0);
-							/* Don't bother checking the return value; if there
-							 * was a pattern delay, there can't be a speed=0.
-							 */
-					entry++;
-				}
-			}
-
-			update_effects(sigrenderer);
-		}
-	} else {
-		if ( !(sigdata->flags & IT_WAS_AN_STM) || !(sigrenderer->tick & 15)) {
-			speed0:
-			update_effects(sigrenderer);
-			update_tick_counts(sigrenderer);
-		}
-	}
-
-	if (sigrenderer->globalvolume == 0) {
-		if (sigrenderer->callbacks->global_volume_zero) {
-			LONG_LONG t = sigrenderer->gvz_sub_time + ((TICK_TIME_DIVIDEND / (sigrenderer->tempo << 8)) << 16);
-			sigrenderer->gvz_time += (int)(t >> 16);
-			sigrenderer->gvz_sub_time = (int)t & 65535;
-			if (sigrenderer->gvz_time >= 65536 * 12) {
-#ifdef BIT_ARRAY_BULLSHIT
-				sigrenderer->looped = 1;
-#endif
-				if ((*sigrenderer->callbacks->global_volume_zero)(sigrenderer->callbacks->global_volume_zero_data))
-					return 1;
-			}
-		}
-	} else {
-		if (sigrenderer->callbacks->global_volume_zero) {
-			sigrenderer->gvz_time = 0;
-			sigrenderer->gvz_sub_time = 0;
-		}
-	}
-
-	process_all_playing(sigrenderer);
-
-	{
-		LONG_LONG t = (TICK_TIME_DIVIDEND / (sigrenderer->tempo << 8)) << 16;
-		if ( sigrenderer->sigdata->flags & IT_WAS_AN_STM ) {
-			t /= 16;
-		}
-		t += sigrenderer->sub_time_left;
-		sigrenderer->time_left += (int)(t >> 16);
-		sigrenderer->sub_time_left = (int)t & 65535;
-	}
-
-	return 0;
-}
-
-
-
-int dumb_it_max_to_mix = 64;
-
-#if 0
-static const int aiMODVol[] =
-{
-	0,
-		16, 24, 32, 48, 64, 80, 96, 112,
-		128, 144, 160, 176, 192, 208, 224, 240,
-		256, 272, 288, 304, 320, 336, 352, 368,
-		384, 400, 416, 432, 448, 464, 480, 496,
-		529, 545, 561, 577, 593, 609, 625, 641,
-		657, 673, 689, 705, 721, 737, 753, 769,
-		785, 801, 817, 833, 849, 865, 881, 897,
-		913, 929, 945, 961, 977, 993, 1009, 1024
-};
-#endif
-
-static const int aiPTMVolScaled[] =
-{
-	0,
-		31, 54, 73, 96, 111, 130, 153, 172,
-		191, 206, 222, 237, 252, 275, 298, 317,
-		336, 351, 370, 386, 401, 416, 428, 443,
-		454, 466, 477, 489, 512, 531, 553, 573,
-		592, 611, 626, 645, 660, 679, 695, 710,
-		725, 740, 756, 767, 782, 798, 809, 820,
-		836, 847, 859, 870, 881, 897, 908, 916,
-		927, 939, 950, 962, 969, 983, 1005, 1024
-};
-
-static float calculate_volume(DUMB_IT_SIGRENDERER *sigrenderer, IT_PLAYING *playing, float volume)
-{
-	if (volume != 0) {
-		int vol;
-
-		if (playing->channel->flags & IT_CHANNEL_MUTED)
-			return 0;
-
-		if ((playing->channel->tremor_time & 192) == 128)
-			return 0;
-
-		switch (playing->tremolo_waveform)
-		{
-		default:
-			vol = it_sine[playing->tremolo_time];
-			break;
-		case 1:
-			vol = it_sawtooth[playing->tremolo_time];
-			break;
-		case 2:
-			vol = it_squarewave[playing->tremolo_time];
-			break;
-		case 3:
-			vol = (rand() % 129) - 64;
-			break;
-		case 4:
-			vol = it_xm_squarewave[playing->tremolo_time];
-			break;
-		case 5:
-			vol = it_xm_ramp[playing->tremolo_time];
-			break;
-		case 6:
-			vol = it_xm_ramp[255-((sigrenderer->sigdata->flags & IT_WAS_A_MOD)?playing->vibrato_time:playing->tremolo_time)];
-			break;
-		}
-		vol *= playing->tremolo_depth;
-
-		vol = (playing->volume << 5) + vol;
-
-		if (vol <= 0)
-			return 0;
-
-		if (vol > 64 << 5)
-			vol = 64 << 5;
-
-		if ( sigrenderer->sigdata->flags & IT_WAS_A_PTM )
-		{
-			int v = aiPTMVolScaled[ vol >> 5 ];
-			if ( vol < 64 << 5 )
-			{
-				int f = vol & ( ( 1 << 5 ) - 1 );
-				int f2 = ( 1 << 5 ) - f;
-				int v2 = aiPTMVolScaled[ ( vol >> 5 ) + 1 ];
-				v = ( v * f2 + v2 * f ) >> 5;
-			}
-			vol = v << 1;
-		}
-
-		volume *= vol; /* 64 << 5 */
-		volume *= playing->sample->global_volume; /* 64 */
-		volume *= playing->channel_volume; /* 64 */
-		volume *= sigrenderer->globalvolume; /* 128 */
-		volume *= sigrenderer->sigdata->mixing_volume; /* 128 */
-		volume *= 1.0f / ((64 << 5) * 64.0f * 64.0f * 128.0f * 128.0f);
-
-		if (volume && playing->instrument) {
-			if (playing->enabled_envelopes & IT_ENV_VOLUME && playing->env_instrument->volume_envelope.n_nodes) {
-				volume *= envelope_get_y(&playing->env_instrument->volume_envelope, &playing->volume_envelope);
-				volume *= 1.0f / (64 << IT_ENVELOPE_SHIFT);
-			}
-			volume *= playing->instrument->global_volume; /* 128 */
-			volume *= playing->fadeoutcount; /* 1024 */
-			volume *= 1.0f / (128.0f * 1024.0f);
-		}
-	}
-
-	return volume;
-}
-
-
-
-static int apply_pan_envelope(IT_PLAYING *playing)
-{
-	if (playing->pan <= 64 << IT_ENVELOPE_SHIFT) {
-		int pan;
-		if (playing->panbrello_depth) {
-			switch (playing->panbrello_waveform) {
-			default:
-				pan = it_sine[playing->panbrello_time];
-				break;
-			case 1:
-				pan = it_sawtooth[playing->panbrello_time];
-				break;
-			case 2:
-				pan = it_squarewave[playing->panbrello_time];
-				break;
-			case 3:
-				pan = playing->panbrello_random;
-				break;
-			}
-			pan *= playing->panbrello_depth << 3;
-
-			pan += playing->pan;
-			if (pan < 0) pan = 0;
-			else if (pan > 64 << IT_ENVELOPE_SHIFT) pan = 64 << IT_ENVELOPE_SHIFT;
-		} else {
-			pan = playing->pan;
-		}
-
-		if (playing->env_instrument && (playing->enabled_envelopes & IT_ENV_PANNING)) {
-			int p = envelope_get_y(&playing->env_instrument->pan_envelope, &playing->pan_envelope);
-			if (pan > 32 << IT_ENVELOPE_SHIFT)
-				p *= (64 << IT_ENVELOPE_SHIFT) - pan;
-			else
-				p *= pan;
-			pan += p >> (5 + IT_ENVELOPE_SHIFT);
-		}
-		return pan;
-	}
-	return playing->pan;
-}
-
-
-
-/* Note: if a click remover is provided, and store_end_sample is set, then
- * the end point will be computed twice. This situation should not arise.
- */
-static long render_playing(DUMB_IT_SIGRENDERER *sigrenderer, IT_PLAYING *playing, float volume, float main_delta, float delta, long pos, long size, sample_t **samples, int store_end_sample, int *left_to_mix)
-{
-	int bits;
-
-	long size_rendered;
-
-	DUMB_VOLUME_RAMP_INFO lvol, rvol;
-
-	if (playing->flags & IT_PLAYING_DEAD)
-		return 0;
-
-	if (*left_to_mix <= 0)
-		volume = 0;
-
-	{
-		int quality = sigrenderer->resampling_quality;
-		if (playing->sample->max_resampling_quality >= 0 && quality > playing->sample->max_resampling_quality)
-			quality = playing->sample->max_resampling_quality;
-		playing->resampler.quality = quality;
-                resampler_set_quality(playing->resampler.fir_resampler[0], quality);
-                resampler_set_quality(playing->resampler.fir_resampler[1], quality);
-	}
-
-	bits = playing->sample->flags & IT_SAMPLE_16BIT ? 16 : 8;
-
-	if (volume == 0) {
-		if (playing->sample->flags & IT_SAMPLE_STEREO)
-			size_rendered = dumb_resample_n_2_1(bits, &playing->resampler, NULL, size, 0, 0, delta);
-		else
-			size_rendered = dumb_resample_n_1_1(bits, &playing->resampler, NULL, size, 0, delta);
-	} else {
-		lvol.volume = playing->ramp_volume [0];
-		rvol.volume = playing->ramp_volume [1];
-		lvol.delta  = playing->ramp_delta [0] * main_delta;
-		rvol.delta  = playing->ramp_delta [1] * main_delta;
-		lvol.target = playing->float_volume [0];
-		rvol.target = playing->float_volume [1];
-		rvol.mix = lvol.mix = volume;
-        lvol.declick_stage = rvol.declick_stage = playing->declick_stage;
-		if (sigrenderer->n_channels >= 2) {
-			if (playing->sample->flags & IT_SAMPLE_STEREO) {
-				if (sigrenderer->click_remover) {
-					sample_t click[2];
-					dumb_resample_get_current_sample_n_2_2(bits, &playing->resampler, &lvol, &rvol, click);
-					dumb_record_click(sigrenderer->click_remover[0], pos, click[0]);
-					dumb_record_click(sigrenderer->click_remover[1], pos, click[1]);
-				}
-				size_rendered = dumb_resample_n_2_2(bits, &playing->resampler, samples[0] + pos*2, size, &lvol, &rvol, delta);
-				if (store_end_sample) {
-					sample_t click[2];
-					dumb_resample_get_current_sample_n_2_2(bits, &playing->resampler, &lvol, &rvol, click);
-					samples[0][(pos + size_rendered) * 2] = click[0];
-					samples[0][(pos + size_rendered) * 2 + 1] = click[1];
-				}
-				if (sigrenderer->click_remover) {
-					sample_t click[2];
-					dumb_resample_get_current_sample_n_2_2(bits, &playing->resampler, &lvol, &rvol, click);
-					dumb_record_click(sigrenderer->click_remover[0], pos + size_rendered, -click[0]);
-					dumb_record_click(sigrenderer->click_remover[1], pos + size_rendered, -click[1]);
-				}
-			} else {
-				if (sigrenderer->click_remover) {
-					sample_t click[2];
-					dumb_resample_get_current_sample_n_1_2(bits, &playing->resampler, &lvol, &rvol, click);
-					dumb_record_click(sigrenderer->click_remover[0], pos, click[0]);
-					dumb_record_click(sigrenderer->click_remover[1], pos, click[1]);
-				}
-				size_rendered = dumb_resample_n_1_2(bits, &playing->resampler, samples[0] + pos*2, size, &lvol, &rvol, delta);
-				if (store_end_sample) {
-					sample_t click[2];
-					dumb_resample_get_current_sample_n_1_2(bits, &playing->resampler, &lvol, &rvol, click);
-					samples[0][(pos + size_rendered) * 2] = click[0];
-					samples[0][(pos + size_rendered) * 2 + 1] = click[1];
-				}
-				if (sigrenderer->click_remover) {
-					sample_t click[2];
-					dumb_resample_get_current_sample_n_1_2(bits, &playing->resampler, &lvol, &rvol, click);
-					dumb_record_click(sigrenderer->click_remover[0], pos + size_rendered, -click[0]);
-					dumb_record_click(sigrenderer->click_remover[1], pos + size_rendered, -click[1]);
-				}
-			}
-		} else {
-			if (playing->sample->flags & IT_SAMPLE_STEREO) {
-				if (sigrenderer->click_remover) {
-					sample_t click;
-					dumb_resample_get_current_sample_n_2_1(bits, &playing->resampler, &lvol, &rvol, &click);
-					dumb_record_click(sigrenderer->click_remover[0], pos, click);
-				}
-				size_rendered = dumb_resample_n_2_1(bits, &playing->resampler, samples[0] + pos, size, &lvol, &rvol, delta);
-				if (store_end_sample)
-					dumb_resample_get_current_sample_n_2_1(bits, &playing->resampler, &lvol, &rvol, &samples[0][pos + size_rendered]);
-				if (sigrenderer->click_remover) {
-					sample_t click;
-					dumb_resample_get_current_sample_n_2_1(bits, &playing->resampler, &lvol, &rvol, &click);
-					dumb_record_click(sigrenderer->click_remover[0], pos + size_rendered, -click);
-				}
-			} else {
-				if (sigrenderer->click_remover) {
-					sample_t click;
-					dumb_resample_get_current_sample_n_1_1(bits, &playing->resampler, &lvol, &click);
-					dumb_record_click(sigrenderer->click_remover[0], pos, click);
-				}
-				size_rendered = dumb_resample_n_1_1(bits, &playing->resampler, samples[0] + pos, size, &lvol, delta);
-				if (store_end_sample)
-					dumb_resample_get_current_sample_n_1_1(bits, &playing->resampler, &lvol, &samples[0][pos + size_rendered]);
-				if (sigrenderer->click_remover) {
-					sample_t click;
-					dumb_resample_get_current_sample_n_1_1(bits, &playing->resampler, &lvol, &click);
-					dumb_record_click(sigrenderer->click_remover[0], pos + size_rendered, -click);
-				}
-			}
-		}
-		playing->ramp_volume [0] = lvol.volume;
-		playing->ramp_volume [1] = rvol.volume;
-        playing->declick_stage = (lvol.declick_stage > rvol.declick_stage) ? lvol.declick_stage : rvol.declick_stage;
-        if (playing->declick_stage >= 4)
-            playing->flags |= IT_PLAYING_DEAD;
-		(*left_to_mix)--;
-	}
-
-	if (playing->resampler.dir == 0)
-		playing->flags |= IT_PLAYING_DEAD;
-
-	return size_rendered;
-}
-
-typedef struct IT_TO_MIX
-{
-	IT_PLAYING *playing;
-	float volume;
-}
-IT_TO_MIX;
-
-
-
-static int it_to_mix_compare(const void *e1, const void *e2)
-{
-	if (((const IT_TO_MIX *)e1)->volume > ((const IT_TO_MIX *)e2)->volume)
-		return -1;
-
-	if (((const IT_TO_MIX *)e1)->volume < ((const IT_TO_MIX *)e2)->volume)
-		return 1;
-
-	return 0;
-}
-
-
-
-static void apply_pitch_modifications(DUMB_IT_SIGDATA *sigdata, IT_PLAYING *playing, float *delta, int *cutoff)
-{
-	{
-		int sample_vibrato_shift;
-		switch (playing->sample_vibrato_waveform)
-		{
-		default:
-			sample_vibrato_shift = it_sine[playing->sample_vibrato_time];
-			break;
-		case 1:
-			sample_vibrato_shift = it_sawtooth[playing->sample_vibrato_time];
-			break;
-		case 2:
-			sample_vibrato_shift = it_squarewave[playing->sample_vibrato_time];
-			break;
-		case 3:
-			sample_vibrato_shift = (rand() % 129) - 64;
-			break;
-		case 4:
-			sample_vibrato_shift = it_xm_squarewave[playing->sample_vibrato_time];
-			break;
-		case 5:
-			sample_vibrato_shift = it_xm_ramp[playing->sample_vibrato_time];
-			break;
-		case 6:
-			sample_vibrato_shift = it_xm_ramp[255-playing->sample_vibrato_time];
-			break;
-		}
-
-		if (sigdata->flags & IT_WAS_AN_XM) {
-			int depth = playing->sample->vibrato_depth; /* True depth */
-			if (playing->sample->vibrato_rate) {
-				depth *= playing->sample_vibrato_depth; /* Tick number */
-				depth /= playing->sample->vibrato_rate; /* XM sweep */
-			}
-			sample_vibrato_shift *= depth;
-		} else
-			sample_vibrato_shift *= playing->sample_vibrato_depth >> 8;
-
-		sample_vibrato_shift >>= 4;
-
-		if (sample_vibrato_shift) {
-			if ((sigdata->flags & IT_LINEAR_SLIDES) || !(sigdata->flags & IT_WAS_AN_XM))
-				*delta *= (float)pow(DUMB_PITCH_BASE, sample_vibrato_shift);
-			else {
-				/* complicated! */
-				float scale = *delta / playing->delta;
-
-				*delta = (1.0f / 65536.0f) / playing->delta;
-
-				*delta -= sample_vibrato_shift / AMIGA_DIVISOR;
-
-				if (*delta < (1.0f / 65536.0f) / 32767.0f) {
-					*delta = (1.0f / 65536.0f) / 32767.0f;
-				}
-
-				*delta = (1.0f / 65536.0f) / *delta * scale;
-			}
-		}
-	}
-
-	if (playing->env_instrument &&
-		(playing->enabled_envelopes & IT_ENV_PITCH))
-	{
-		int p = envelope_get_y(&playing->env_instrument->pitch_envelope, &playing->pitch_envelope);
-		if (playing->env_instrument->pitch_envelope.flags & IT_ENVELOPE_PITCH_IS_FILTER)
-			*cutoff = (*cutoff * (p+(32<<IT_ENVELOPE_SHIFT))) >> (6 + IT_ENVELOPE_SHIFT);
-		else
-			*delta *= (float)pow(DUMB_PITCH_BASE, p >> (IT_ENVELOPE_SHIFT - 7));
-	}
-}
-
-
-
-static void render_normal(DUMB_IT_SIGRENDERER *sigrenderer, float volume, float delta, long pos, long size, sample_t **samples)
-{
-	int i;
-
-	int n_to_mix = 0;
-	IT_TO_MIX to_mix[DUMB_IT_TOTAL_CHANNELS];
-	int left_to_mix = dumb_it_max_to_mix;
-
-	sample_t **samples_to_filter = NULL;
-
-	//int max_output = sigrenderer->max_output;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		if (sigrenderer->channel[i].playing && !(sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD)) {
-			to_mix[n_to_mix].playing = sigrenderer->channel[i].playing;
-			to_mix[n_to_mix].volume = volume == 0 ? 0 : calculate_volume(sigrenderer, sigrenderer->channel[i].playing, volume);
-			n_to_mix++;
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-		if (sigrenderer->playing[i]) { /* Won't be dead; it would have been freed. */
-			to_mix[n_to_mix].playing = sigrenderer->playing[i];
-			to_mix[n_to_mix].volume = volume == 0 ? 0 : calculate_volume(sigrenderer, sigrenderer->playing[i], volume);
-			n_to_mix++;
-		}
-	}
-
-	if (volume != 0)
-		qsort(to_mix, n_to_mix, sizeof(IT_TO_MIX), &it_to_mix_compare);
-
-	for (i = 0; i < n_to_mix; i++) {
-		IT_PLAYING *playing = to_mix[i].playing;
-		float note_delta = delta * playing->delta;
-		int cutoff = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
-		//int output = min( playing->output, max_output );
-
-		apply_pitch_modifications(sigrenderer->sigdata, playing, &note_delta, &cutoff);
-
-		if (cutoff != 127 << IT_ENVELOPE_SHIFT || playing->filter_resonance != 0) {
-			playing->true_filter_cutoff = cutoff;
-			playing->true_filter_resonance = playing->filter_resonance;
-		}
-
-		if (volume && (playing->true_filter_cutoff != 127 << IT_ENVELOPE_SHIFT || playing->true_filter_resonance != 0)) {
-			if (!samples_to_filter) {
-				samples_to_filter = allocate_sample_buffer(sigrenderer->n_channels, size + 1);
-				if (!samples_to_filter) {
-					render_playing(sigrenderer, playing, 0, delta, note_delta, pos, size, NULL, 0, &left_to_mix);
-					continue;
-				}
-			}
-			{
-				long size_rendered;
-				DUMB_CLICK_REMOVER **cr = sigrenderer->click_remover;
-				dumb_silence(samples_to_filter[0], sigrenderer->n_channels * (size + 1));
-				sigrenderer->click_remover = NULL;
-				size_rendered = render_playing(sigrenderer, playing, volume, delta, note_delta, 0, size, samples_to_filter, 1, &left_to_mix);
-				sigrenderer->click_remover = cr;
-				if (sigrenderer->n_channels == 2) {
-					it_filter(cr ? cr[0] : NULL, &playing->filter_state[0], samples[0 /*output*/], pos, samples_to_filter[0], size_rendered,
-						2, (int)(65536.0f/delta), playing->true_filter_cutoff, playing->true_filter_resonance);
-					it_filter(cr ? cr[1] : NULL, &playing->filter_state[1], samples[0 /*output*/]+1, pos, samples_to_filter[0]+1, size_rendered,
-						2, (int)(65536.0f/delta), playing->true_filter_cutoff, playing->true_filter_resonance);
-				} else {
-					it_filter(cr ? cr[0] : NULL, &playing->filter_state[0], samples[0 /*output*/], pos, samples_to_filter[0], size_rendered,
-						1, (int)(65536.0f/delta), playing->true_filter_cutoff, playing->true_filter_resonance);
-				}
-				// FIXME: filtering is not prevented by low left_to_mix!
-				// FIXME: change 'warning' to 'FIXME' everywhere
-			}
-		} else {
-			it_reset_filter_state(&playing->filter_state[0]);
-			it_reset_filter_state(&playing->filter_state[1]);
-			render_playing(sigrenderer, playing, volume, delta, note_delta, pos, size, samples /*&samples[output]*/, 0, &left_to_mix);
-		}
-	}
-
-	destroy_sample_buffer(samples_to_filter);
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		if (sigrenderer->channel[i].playing) {
-			//if ((sigrenderer->channel[i].playing->flags & (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) == (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) {
-			// This change was made so Gxx would work correctly when a note faded out or whatever. Let's hope nothing else was broken by it.
-			if (sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD) {
-				free_playing(sigrenderer->channel[i].playing);
-				sigrenderer->channel[i].playing = NULL;
-			}
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-		if (sigrenderer->playing[i]) {
-			if (sigrenderer->playing[i]->flags & IT_PLAYING_DEAD) {
-				free_playing(sigrenderer->playing[i]);
-				sigrenderer->playing[i] = NULL;
-			}
-		}
-	}
-}
-
-
-
-static void render_surround(DUMB_IT_SIGRENDERER *sigrenderer, float volume, float delta, long pos, long size, sample_t **samples)
-{
-	int i;
-
-	int n_to_mix = 0, n_to_mix_surround = 0;
-	IT_TO_MIX to_mix[DUMB_IT_TOTAL_CHANNELS];
-	IT_TO_MIX to_mix_surround[DUMB_IT_TOTAL_CHANNELS];
-	int left_to_mix = dumb_it_max_to_mix;
-
-	int saved_channels = sigrenderer->n_channels;
-
-	sample_t **samples_to_filter = NULL;
-
-	DUMB_CLICK_REMOVER **saved_cr = sigrenderer->click_remover;
-
-	//int max_output = sigrenderer->max_output;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		if (sigrenderer->channel[i].playing && !(sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD)) {
-			IT_PLAYING *playing = sigrenderer->channel[i].playing;
-			IT_TO_MIX *_to_mix = IT_IS_SURROUND_SHIFTED(playing->pan) ? to_mix_surround + n_to_mix_surround++ : to_mix + n_to_mix++;
-			_to_mix->playing = playing;
-			_to_mix->volume = volume == 0 ? 0 : calculate_volume(sigrenderer, playing, volume);
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-		if (sigrenderer->playing[i]) { /* Won't be dead; it would have been freed. */
-			IT_PLAYING *playing = sigrenderer->playing[i];
-			IT_TO_MIX *_to_mix = IT_IS_SURROUND_SHIFTED(playing->pan) ? to_mix_surround + n_to_mix_surround++ : to_mix + n_to_mix++;
-			_to_mix->playing = playing;
-			_to_mix->volume = volume == 0 ? 0 : calculate_volume(sigrenderer, playing, volume);
-		}
-	}
-
-	if (volume != 0) {
-		qsort(to_mix, n_to_mix, sizeof(IT_TO_MIX), &it_to_mix_compare);
-		qsort(to_mix_surround, n_to_mix_surround, sizeof(IT_TO_MIX), &it_to_mix_compare);
-	}
-
-	sigrenderer->n_channels = 2;
-
-	for (i = 0; i < n_to_mix; i++) {
-		IT_PLAYING *playing = to_mix[i].playing;
-		float note_delta = delta * playing->delta;
-		int cutoff = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
-		//int output = min( playing->output, max_output );
-
-		apply_pitch_modifications(sigrenderer->sigdata, playing, &note_delta, &cutoff);
-
-		if (cutoff != 127 << IT_ENVELOPE_SHIFT || playing->filter_resonance != 0) {
-			playing->true_filter_cutoff = cutoff;
-			playing->true_filter_resonance = playing->filter_resonance;
-		}
-
-		if (volume && (playing->true_filter_cutoff != 127 << IT_ENVELOPE_SHIFT || playing->true_filter_resonance != 0)) {
-			if (!samples_to_filter) {
-				samples_to_filter = allocate_sample_buffer(sigrenderer->n_channels, size + 1);
-				if (!samples_to_filter) {
-					render_playing(sigrenderer, playing, 0, delta, note_delta, pos, size, NULL, 0, &left_to_mix);
-					continue;
-				}
-			}
-			{
-				long size_rendered;
-				DUMB_CLICK_REMOVER **cr = sigrenderer->click_remover;
-				dumb_silence(samples_to_filter[0], sigrenderer->n_channels * (size + 1));
-				sigrenderer->click_remover = NULL;
-				size_rendered = render_playing(sigrenderer, playing, volume, delta, note_delta, 0, size, samples_to_filter, 1, &left_to_mix);
-				sigrenderer->click_remover = cr;
-				it_filter(cr ? cr[0] : NULL, &playing->filter_state[0], samples[0 /*output*/], pos, samples_to_filter[0], size_rendered,
-					2, (int)(65536.0f/delta), playing->true_filter_cutoff, playing->true_filter_resonance);
-				it_filter(cr ? cr[1] : NULL, &playing->filter_state[1], samples[0 /*output*/]+1, pos, samples_to_filter[0]+1, size_rendered,
-					2, (int)(65536.0f/delta), playing->true_filter_cutoff, playing->true_filter_resonance);
-			}
-		} else {
-			it_reset_filter_state(&playing->filter_state[0]);
-			it_reset_filter_state(&playing->filter_state[1]);
-			render_playing(sigrenderer, playing, volume, delta, note_delta, pos, size, samples /*&samples[output]*/, 0, &left_to_mix);
-		}
-	}
-
-	sigrenderer->n_channels = 1;
-	sigrenderer->click_remover = saved_cr ? saved_cr + 2 : 0;
-
-	for (i = 0; i < n_to_mix_surround; i++) {
-		IT_PLAYING *playing = to_mix_surround[i].playing;
-		float note_delta = delta * playing->delta;
-		int cutoff = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
-		//int output = min( playing->output, max_output );
-
-		apply_pitch_modifications(sigrenderer->sigdata, playing, &note_delta, &cutoff);
-
-		if (cutoff != 127 << IT_ENVELOPE_SHIFT || playing->filter_resonance != 0) {
-			playing->true_filter_cutoff = cutoff;
-			playing->true_filter_resonance = playing->filter_resonance;
-		}
-
-		if (volume && (playing->true_filter_cutoff != 127 << IT_ENVELOPE_SHIFT || playing->true_filter_resonance != 0)) {
-			if (!samples_to_filter) {
-				samples_to_filter = allocate_sample_buffer(sigrenderer->n_channels, size + 1);
-				if (!samples_to_filter) {
-					render_playing(sigrenderer, playing, 0, delta, note_delta, pos, size, NULL, 0, &left_to_mix);
-					continue;
-				}
-			}
-			{
-				long size_rendered;
-				DUMB_CLICK_REMOVER **cr = sigrenderer->click_remover;
-				dumb_silence(samples_to_filter[0], size + 1);
-				sigrenderer->click_remover = NULL;
-				size_rendered = render_playing(sigrenderer, playing, volume, delta, note_delta, 0, size, samples_to_filter, 1, &left_to_mix);
-				sigrenderer->click_remover = cr;
-				it_filter(cr ? cr[0] : NULL, &playing->filter_state[0], samples[1 /*output*/], pos, samples_to_filter[0], size_rendered,
-					1, (int)(65536.0f/delta), playing->true_filter_cutoff, playing->true_filter_resonance);
-				// FIXME: filtering is not prevented by low left_to_mix!
-				// FIXME: change 'warning' to 'FIXME' everywhere
-			}
-		} else {
-			it_reset_filter_state(&playing->filter_state[0]);
-			it_reset_filter_state(&playing->filter_state[1]);
-			render_playing(sigrenderer, playing, volume, delta, note_delta, pos, size, &samples[1], 0, &left_to_mix);
-		}
-	}
-
-	sigrenderer->n_channels = saved_channels;
-	sigrenderer->click_remover = saved_cr;
-
-	destroy_sample_buffer(samples_to_filter);
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		if (sigrenderer->channel[i].playing) {
-			//if ((sigrenderer->channel[i].playing->flags & (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) == (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) {
-			// This change was made so Gxx would work correctly when a note faded out or whatever. Let's hope nothing else was broken by it.
-			if (sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD) {
-				free_playing(sigrenderer->channel[i].playing);
-				sigrenderer->channel[i].playing = NULL;
-			}
-		}
-	}
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-		if (sigrenderer->playing[i]) {
-			if (sigrenderer->playing[i]->flags & IT_PLAYING_DEAD) {
-				free_playing(sigrenderer->playing[i]);
-				sigrenderer->playing[i] = NULL;
-			}
-		}
-	}
-}
-
-
-
-static void render(DUMB_IT_SIGRENDERER *sigrenderer, float volume, float delta, long pos, long size, sample_t **samples)
-{
-	if (size == 0) return;
-	if (sigrenderer->n_channels == 1 || sigrenderer->n_channels == 2)
-		render_normal(sigrenderer, volume, delta, pos, size, samples);
-	else if (sigrenderer->n_channels == 3)
-		render_surround(sigrenderer, volume, delta, pos, size, samples);
-}
-
-
-
-static DUMB_IT_SIGRENDERER *init_sigrenderer(DUMB_IT_SIGDATA *sigdata, int n_channels, int startorder, IT_CALLBACKS *callbacks, DUMB_CLICK_REMOVER **cr)
-{
-	DUMB_IT_SIGRENDERER *sigrenderer;
-	int i;
-
-	if (startorder > sigdata->n_orders) {
-		free(callbacks);
-		dumb_destroy_click_remover_array(n_channels, cr);
-		return NULL;
-	}
-
-	sigrenderer = malloc(sizeof(*sigrenderer));
-	if (!sigrenderer) {
-		free(callbacks);
-		dumb_destroy_click_remover_array(n_channels, cr);
-		return NULL;
-	}
-
-	sigrenderer->callbacks = callbacks;
-	sigrenderer->click_remover = cr;
-
-	sigrenderer->sigdata = sigdata;
-	sigrenderer->n_channels = n_channels;
-	sigrenderer->resampling_quality = dumb_resampling_quality;
-    sigrenderer->ramp_style = DUMB_IT_RAMP_FULL;
-	sigrenderer->globalvolume = sigdata->global_volume;
-	sigrenderer->tempo = sigdata->tempo;
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-		IT_CHANNEL *channel = &sigrenderer->channel[i];
-#if IT_CHANNEL_MUTED != 1
-#error this is wrong
-#endif
-		channel->flags = sigdata->channel_pan[i] >> 7;
-		channel->volume = (sigdata->flags & IT_WAS_AN_XM) ? 0 : 64;
-		channel->pan = sigdata->channel_pan[i] & 0x7F;
-		channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
-		channel->channelvolume = sigdata->channel_volume[i];
-		channel->instrument = 0;
-		channel->sample = 0;
-		channel->note = IT_NOTE_OFF;
-		channel->SFmacro = 0;
-		channel->filter_cutoff = 127;
-		channel->filter_resonance = 0;
-		channel->new_note_action = 0xFF;
-		channel->xm_retrig = 0;
-		channel->retrig_tick = 0;
-		channel->tremor_time = 0;
-		channel->vibrato_waveform = 0;
-		channel->tremolo_waveform = 0;
-		channel->panbrello_waveform = 0;
-		channel->glissando = 0;
-		channel->toneslide = 0;
-		channel->ptm_toneslide = 0;
-		channel->ptm_last_toneslide = 0;
-		channel->okt_toneslide = 0;
-		channel->midi_state = 0;
-		channel->lastvolslide = 0;
-		channel->lastDKL = 0;
-		channel->lastEF = 0;
-		channel->lastG = 0;
-		channel->lastHspeed = 0;
-		channel->lastHdepth = 0;
-		channel->lastRspeed = 0;
-		channel->lastRdepth = 0;
-		channel->lastYspeed = 0;
-		channel->lastYdepth = 0;
-		channel->lastI = 0;
-		channel->lastJ = 0;
-		channel->lastN = 0;
-		channel->lastO = 0;
-		channel->high_offset = 0;
-		channel->lastP = 0;
-		channel->lastQ = 0;
-		channel->lastS = 0;
-		channel->pat_loop_row = 0;
-		channel->pat_loop_count = 0;
-		channel->pat_loop_end_row = 0;
-		channel->lastW = 0;
-		channel->xm_lastE1 = 0;
-		channel->xm_lastE2 = 0;
-		channel->xm_lastEA = 0;
-		channel->xm_lastEB = 0;
-		channel->xm_lastX1 = 0;
-		channel->xm_lastX2 = 0;
-		channel->inv_loop_delay = 0;
-		channel->inv_loop_speed = 0;
-		channel->inv_loop_offset = 0;
-		channel->playing = NULL;
-#ifdef BIT_ARRAY_BULLSHIT
-		channel->played_patjump = NULL;
-		channel->played_patjump_order = 0xFFFE;
-#endif
-		//channel->output = 0;
-	}
-
-	if (sigdata->flags & IT_WAS_A_669)
-		reset_effects(sigrenderer);
-
-	for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
-		sigrenderer->playing[i] = NULL;
-
-	sigrenderer->speed = sigdata->speed;
-
-	sigrenderer->processrow = 0xFFFE;
-	sigrenderer->n_rows = 0;
-	sigrenderer->breakrow = 0;
-	sigrenderer->rowcount = 1;
-	sigrenderer->order = startorder;
-	/* meh!
-	if (startorder > 0) {
-		int n;
-		for (n = startorder - 1; n >= 0; n--) {
-			if (sigdata->order[n] > sigdata->n_patterns) {
-				sigrenderer->restart_position = n + 1;
-				break;
-			}
-		}
-	}
-	*/
-	if (startorder > 0) {
-		sigrenderer->restart_position = startorder;
-	} else {
-		sigrenderer->restart_position = sigdata->restart_position;
-	}
-
-	sigrenderer->row = 0;
-	sigrenderer->processorder = startorder - 1;
-	sigrenderer->tick = 1;
-
-#ifdef BIT_ARRAY_BULLSHIT
-	sigrenderer->played = bit_array_create(sigdata->n_orders * 256);
-
-	sigrenderer->looped = 0;
-	sigrenderer->time_played = 0;
-	sigrenderer->row_timekeeper = timekeeping_array_create(sigdata->n_orders * 256);
-#endif
-
-	{
-		int order;
-		for (order = 0; order < sigdata->n_orders; order++) {
-			int n = sigdata->order[order];
-			if (n < sigdata->n_patterns) goto found_valid_order;
-#ifdef INVALID_ORDERS_END_SONG
-			if (n != IT_ORDER_SKIP)
-#else
-			if (n == IT_ORDER_END)
-#endif
-				break;
-
-#ifdef BIT_ARRAY_BULLSHIT
-			/* Fix for played order detection for songs which have skips at the start of the orders list */
-			for (n = 0; n < 256; n++) {
-				bit_array_set(sigrenderer->played, order * 256 + n);
-				timekeeping_array_push(sigrenderer->row_timekeeper, order * 256 + n, 0);
-				timekeeping_array_bump(sigrenderer->row_timekeeper, order * 256 + n);
-			}
-#endif
-		}
-		/* If we get here, there were no valid orders in the song. */
-		_dumb_it_end_sigrenderer(sigrenderer);
-		return NULL;
-	}
-	found_valid_order:
-
-	sigrenderer->time_left = 0;
-	sigrenderer->sub_time_left = 0;
-
-	sigrenderer->gvz_time = 0;
-	sigrenderer->gvz_sub_time = 0;
-
-	//sigrenderer->max_output = 0;
-
-	if ( !(sigdata->flags & IT_WAS_PROCESSED) ) {
-		dumb_it_add_lpc( sigdata );
-
-		sigdata->flags |= IT_WAS_PROCESSED;
-	}
-
-	return sigrenderer;
-}
-
-
-void dumb_it_set_resampling_quality(DUMB_IT_SIGRENDERER * sigrenderer, int quality)
-{
-	if (sigrenderer && quality >= 0 && quality < DUMB_RQ_N_LEVELS)
-	{
-		int i;
-		sigrenderer->resampling_quality = quality;
-		for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-			if (sigrenderer->channel[i].playing)
-			{
-				IT_PLAYING * playing = sigrenderer->channel[i].playing;
-				playing->resampling_quality = quality;
-				playing->resampler.quality = quality;
-                                resampler_set_quality(playing->resampler.fir_resampler[0], quality);
-                                resampler_set_quality(playing->resampler.fir_resampler[1], quality);
-			}
-		}
-		for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
-			if (sigrenderer->playing[i]) {
-				IT_PLAYING * playing = sigrenderer->playing[i];
-				playing->resampling_quality = quality;
-				playing->resampler.quality = quality;
-                                resampler_set_quality(playing->resampler.fir_resampler[0], quality);
-                                resampler_set_quality(playing->resampler.fir_resampler[1], quality);
-			}
-		}
-	}
-}
-
-
-void dumb_it_set_ramp_style(DUMB_IT_SIGRENDERER * sigrenderer, int ramp_style) {
-	if (sigrenderer && ramp_style >= 0 && ramp_style <= 2) {
-		sigrenderer->ramp_style = ramp_style;
-	}
-}
-
-
-void dumb_it_set_loop_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data)
-{
-	if (sigrenderer) {
-		sigrenderer->callbacks->loop = callback;
-		sigrenderer->callbacks->loop_data = data;
-	}
-}
-
-
-
-void dumb_it_set_xm_speed_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data)
-{
-	if (sigrenderer) {
-		sigrenderer->callbacks->xm_speed_zero = callback;
-		sigrenderer->callbacks->xm_speed_zero_data = data;
-	}
-}
-
-
-
-void dumb_it_set_midi_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data, int channel, unsigned char midi_byte), void *data)
-{
-	if (sigrenderer) {
-		sigrenderer->callbacks->midi = callback;
-		sigrenderer->callbacks->midi_data = data;
-	}
-}
-
-
-
-void dumb_it_set_global_volume_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer, int (*callback)(void *data), void *data)
-{
-	if (sigrenderer) {
-		sigrenderer->callbacks->global_volume_zero = callback;
-		sigrenderer->callbacks->global_volume_zero_data = data;
-	}
-}
-
-
-
-static IT_CALLBACKS *create_callbacks(void)
-{
-	IT_CALLBACKS *callbacks = malloc(sizeof(*callbacks));
-	if (!callbacks) return NULL;
-	callbacks->loop = NULL;
-	callbacks->xm_speed_zero = NULL;
-	callbacks->midi = NULL;
-	callbacks->global_volume_zero = NULL;
-	return callbacks;
-}
-
-
-
-static DUMB_IT_SIGRENDERER *dumb_it_init_sigrenderer(DUMB_IT_SIGDATA *sigdata, int n_channels, int startorder)
-{
-	IT_CALLBACKS *callbacks;
-
-	if (!sigdata) return NULL;
-
-	callbacks = create_callbacks();
-	if (!callbacks) return NULL;
-
-	return init_sigrenderer(sigdata, n_channels, startorder, callbacks,
-		dumb_create_click_remover_array(n_channels));
-}
-
-
-
-DUH_SIGRENDERER *dumb_it_start_at_order(DUH *duh, int n_channels, int startorder)
-{
-	DUMB_IT_SIGDATA *itsd = duh_get_it_sigdata(duh);
-	DUMB_IT_SIGRENDERER *itsr = dumb_it_init_sigrenderer(itsd, n_channels, startorder);
-	/*duh->length = dumb_it_build_checkpoints(itsd, startorder);*/
-	return duh_encapsulate_it_sigrenderer(itsr, n_channels, 0);
-}
-
-
-
-static sigrenderer_t *it_start_sigrenderer(DUH *duh, sigdata_t *vsigdata, int n_channels, long pos)
-{
-	DUMB_IT_SIGDATA *sigdata = vsigdata;
-	DUMB_IT_SIGRENDERER *sigrenderer;
-
-	(void)duh;
-
-	{
-		IT_CALLBACKS *callbacks = create_callbacks();
-		if (!callbacks) return NULL;
-
-		if (sigdata->checkpoint) {
-			IT_CHECKPOINT *checkpoint = sigdata->checkpoint;
-			while (checkpoint->next && checkpoint->next->time < pos)
-				checkpoint = checkpoint->next;
-			sigrenderer = dup_sigrenderer(checkpoint->sigrenderer, n_channels, callbacks);
-			if (!sigrenderer) return NULL;
-			sigrenderer->click_remover = dumb_create_click_remover_array(n_channels);
-			pos -= checkpoint->time;
-		} else {
-			sigrenderer = init_sigrenderer(sigdata, n_channels, 0, callbacks,
-				dumb_create_click_remover_array(n_channels));
-			if (!sigrenderer) return NULL;
-		}
-	}
-
-	while (pos > 0 && pos >= sigrenderer->time_left) {
-		render(sigrenderer, 0, 1.0f, 0, sigrenderer->time_left, NULL);
-
-#ifdef BIT_ARRAY_BULLSHIT
-		sigrenderer->time_played += (LONG_LONG)sigrenderer->time_left << 16;
-#endif
-
-		pos -= sigrenderer->time_left;
-		sigrenderer->time_left = 0;
-
-		if (process_tick(sigrenderer)) {
-			_dumb_it_end_sigrenderer(sigrenderer);
-			return NULL;
-		}
-	}
-
-	render(sigrenderer, 0, 1.0f, 0, pos, NULL);
-	sigrenderer->time_left -= pos;
-
-#ifdef BIT_ARRAY_BULLSHIT
-	sigrenderer->time_played += (LONG_LONG)pos << 16;
-#endif
-
-	return sigrenderer;
-}
-
-
-
-static long it_sigrenderer_get_samples(
-	sigrenderer_t *vsigrenderer,
-	float volume, float delta,
-	long size, sample_t **samples
-)
-{
-	DUMB_IT_SIGRENDERER *sigrenderer = vsigrenderer;
-	long pos;
-	int dt;
-	long todo;
-	int ret;
-	LONG_LONG t;
-
-	if (sigrenderer->order < 0) return 0; // problematic
-
-	pos = 0;
-	dt = (int)(delta * 65536.0f + 0.5f);
-
-	/* When samples is finally used in render_playing(), it won't be used if
-	 * volume is 0.
-	 */
-	if (!samples) volume = 0;
-
-	for (;;) {
-		todo = (long)((((LONG_LONG)sigrenderer->time_left << 16) | sigrenderer->sub_time_left) / dt);
-
-		if (todo >= size)
-			break;
-
-		render(sigrenderer, volume, delta, pos, todo, samples);
-
-		pos += todo;
-		size -= todo;
-
-		t = sigrenderer->sub_time_left - (LONG_LONG)todo * dt;
-		sigrenderer->sub_time_left = (long)t & 65535;
-		sigrenderer->time_left += (long)(t >> 16);
-
-#ifdef BIT_ARRAY_BULLSHIT
-		sigrenderer->time_played += (LONG_LONG)todo * dt;
-#endif
-
-		ret = process_tick(sigrenderer);
-
-		if (ret) {
-			sigrenderer->order = -1;
-			sigrenderer->row = -1;
-		}
-
-#ifdef BIT_ARRAY_BULLSHIT
-		if (sigrenderer->looped == 1) {
-			sigrenderer->looped = -1;
-			size = 0;
-			timekeeping_array_reset(sigrenderer->row_timekeeper, sigrenderer->order * 256 + sigrenderer->row);
-			sigrenderer->time_played = timekeeping_array_get_item(sigrenderer->row_timekeeper, sigrenderer->order * 256 + sigrenderer->row);
-			break;
-		}
-#endif
-
-		if (ret) {
-			return pos;
-		}
-	}
-
-	render(sigrenderer, volume, delta, pos, size, samples);
-
-	pos += size;
-
-	t = sigrenderer->sub_time_left - (LONG_LONG)size * dt;
-	sigrenderer->sub_time_left = (long)t & 65535;
-	sigrenderer->time_left += (long)(t >> 16);
-
-#ifdef BIT_ARRAY_BULLSHIT
-	sigrenderer->time_played += (LONG_LONG)size * dt;
-#endif
-
-	if (samples)
-		dumb_remove_clicks_array(sigrenderer->n_channels, sigrenderer->click_remover, samples, pos, 512.0f / delta);
-
-	return pos;
-}
-
-
-
-static void it_sigrenderer_get_current_sample(sigrenderer_t *vsigrenderer, float volume, sample_t *samples)
-{
-	DUMB_IT_SIGRENDERER *sigrenderer = vsigrenderer;
-	(void)volume; // for consideration: in any of these such functions, is 'volume' going to be required?
-	dumb_click_remover_get_offset_array(sigrenderer->n_channels, sigrenderer->click_remover, samples);
-}
-
-
-
-void _dumb_it_end_sigrenderer(sigrenderer_t *vsigrenderer)
-{
-	DUMB_IT_SIGRENDERER *sigrenderer = vsigrenderer;
-
-	int i;
-
-	if (sigrenderer) {
-		for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
-			if (sigrenderer->channel[i].playing)
-				free_playing(sigrenderer->channel[i].playing);
-#ifdef BIT_ARRAY_BULLSHIT
-			bit_array_destroy(sigrenderer->channel[i].played_patjump);
-#endif
-		}
-
-		for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
-			if (sigrenderer->playing[i])
-				free_playing(sigrenderer->playing[i]);
-
-		dumb_destroy_click_remover_array(sigrenderer->n_channels, sigrenderer->click_remover);
-
-		if (sigrenderer->callbacks)
-			free(sigrenderer->callbacks);
-
-#ifdef BIT_ARRAY_BULLSHIT
-		bit_array_destroy(sigrenderer->played);
-
-		timekeeping_array_destroy(sigrenderer->row_timekeeper);
-#endif
-
-		free(vsigrenderer);
-	}
-}
-
-
-
-#ifdef BIT_ARRAY_BULLSHIT
-static long it_sigrenderer_get_position(sigrenderer_t *vsigrenderer)
-{
-	DUMB_IT_SIGRENDERER *sigrenderer = (DUMB_IT_SIGRENDERER *) vsigrenderer;
-
-	return (long)(sigrenderer->time_played >> 16);
-}
-#endif
-
-
-
-DUH_SIGTYPE_DESC _dumb_sigtype_it = {
-	SIGTYPE_IT,
-	NULL,
-	&it_start_sigrenderer,
-	NULL,
-	&it_sigrenderer_get_samples,
-	&it_sigrenderer_get_current_sample,
-#ifdef BIT_ARRAY_BULLSHIT
-	&it_sigrenderer_get_position,
-#else
-	NULL,
-#endif
-	&_dumb_it_end_sigrenderer,
-	&_dumb_it_unload_sigdata
-};
-
-
-
-DUH_SIGRENDERER *duh_encapsulate_it_sigrenderer(DUMB_IT_SIGRENDERER *it_sigrenderer, int n_channels, long pos)
-{
-	return duh_encapsulate_raw_sigrenderer(it_sigrenderer, &_dumb_sigtype_it, n_channels, pos);
-}
-
-
-
-DUMB_IT_SIGRENDERER *duh_get_it_sigrenderer(DUH_SIGRENDERER *sigrenderer)
-{
-	return duh_get_raw_sigrenderer(sigrenderer, SIGTYPE_IT);
-}
-
-
-
-/* Values of 64 or more will access NNA channels here. */
-void dumb_it_sr_get_channel_state(DUMB_IT_SIGRENDERER *sr, int channel, DUMB_IT_CHANNEL_STATE *state)
-{
-	IT_PLAYING *playing;
-	int t; /* temporary var for holding accurate pan and filter cutoff */
-	float delta;
-	ASSERT(channel < DUMB_IT_TOTAL_CHANNELS);
-	if (!sr) { state->sample = 0; return; }
-	if (channel >= DUMB_IT_N_CHANNELS) {
-		playing = sr->playing[channel - DUMB_IT_N_CHANNELS];
-		if (!playing) { state->sample = 0; return; }
-	} else {
-		playing = sr->channel[channel].playing;
-		if (!playing) { state->sample = 0; return; }
-	}
-
-	if (playing->flags & IT_PLAYING_DEAD) { state->sample = 0; return; }
-
-	state->channel = (int)(playing->channel - sr->channel);
-	state->sample = playing->sampnum;
-	state->volume = calculate_volume(sr, playing, 1.0f);
-
-	t = apply_pan_envelope(playing);
-	state->pan = (unsigned char)((t + 128) >> IT_ENVELOPE_SHIFT);
-	state->subpan = (signed char)t;
-
-	delta = playing->delta * 65536.0f;
-	t = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
-	apply_pitch_modifications(sr->sigdata, playing, &delta, &t);
-	state->freq = (int)delta;
-	if (t == 127 << IT_ENVELOPE_SHIFT && playing->filter_resonance == 0) {
-		state->filter_resonance = playing->true_filter_resonance;
-		t = playing->true_filter_cutoff;
-	} else
-		state->filter_resonance = playing->filter_resonance;
-	state->filter_cutoff = (unsigned char)(t >> 8);
-	state->filter_subcutoff = (unsigned char)t;
-}
-
-
-
-int dumb_it_callback_terminate(void *data)
-{
-	(void)data;
-	return 1;
-}
-
-
-
-int dumb_it_callback_midi_block(void *data, int channel, unsigned char midi_byte)
-{
-	(void)data;
-	(void)channel;
-	(void)midi_byte;
-	return 1;
-}
-
-
-
-#define IT_CHECKPOINT_INTERVAL (30 * 65536) /* Half a minute */
-
-#define FUCKIT_THRESHOLD (120 * 60 * 65536) /* two hours? probably a pattern loop mess... */
-
-/* Returns the length of the module, up until it first loops. */
-long dumb_it_build_checkpoints(DUMB_IT_SIGDATA *sigdata, int startorder)
-{
-	IT_CHECKPOINT *checkpoint;
-	if (!sigdata) return 0;
-	checkpoint = sigdata->checkpoint;
-	while (checkpoint) {
-		IT_CHECKPOINT *next = checkpoint->next;
-		_dumb_it_end_sigrenderer(checkpoint->sigrenderer);
-		free(checkpoint);
-		checkpoint = next;
-	}
-	sigdata->checkpoint = NULL;
-	checkpoint = malloc(sizeof(*checkpoint));
-	if (!checkpoint) return 0;
-	checkpoint->time = 0;
-	checkpoint->sigrenderer = dumb_it_init_sigrenderer(sigdata, 0, startorder);
-	if (!checkpoint->sigrenderer) {
-		free(checkpoint);
-		return 0;
-	}
-	checkpoint->sigrenderer->callbacks->loop = &dumb_it_callback_terminate;
-	checkpoint->sigrenderer->callbacks->xm_speed_zero = &dumb_it_callback_terminate;
-	checkpoint->sigrenderer->callbacks->global_volume_zero = &dumb_it_callback_terminate;
-
-	if (sigdata->checkpoint)
-	{
-		IT_CHECKPOINT *checkpoint = sigdata->checkpoint;
-		while (checkpoint) {
-			IT_CHECKPOINT *next = checkpoint->next;
-			_dumb_it_end_sigrenderer(checkpoint->sigrenderer);
-			free(checkpoint);
-			checkpoint = next;
-		}
-	}
-
-	sigdata->checkpoint = checkpoint;
-
-	for (;;) {
-		long l;
-		DUMB_IT_SIGRENDERER *sigrenderer = dup_sigrenderer(checkpoint->sigrenderer, 0, checkpoint->sigrenderer->callbacks);
-		checkpoint->sigrenderer->callbacks = NULL;
-		if (!sigrenderer) {
-			checkpoint->next = NULL;
-			return checkpoint->time;
-		}
-
-		l = it_sigrenderer_get_samples(sigrenderer, 0, 1.0f, IT_CHECKPOINT_INTERVAL, NULL);
-		if (l < IT_CHECKPOINT_INTERVAL) {
-			_dumb_it_end_sigrenderer(sigrenderer);
-			checkpoint->next = NULL;
-			return checkpoint->time + l;
-		}
-
-		checkpoint->next = malloc(sizeof(*checkpoint->next));
-		if (!checkpoint->next) {
-			_dumb_it_end_sigrenderer(sigrenderer);
-			return checkpoint->time + IT_CHECKPOINT_INTERVAL;
-		}
-
-		checkpoint->next->time = checkpoint->time + IT_CHECKPOINT_INTERVAL;
-		checkpoint = checkpoint->next;
-		checkpoint->sigrenderer = sigrenderer;
-
-		if (checkpoint->time >= FUCKIT_THRESHOLD) {
-			checkpoint->next = NULL;
-			return 0;
-		}
-	}
-}
-
-
-
-void dumb_it_do_initial_runthrough(DUH *duh)
-{
-	if (duh) {
-		DUMB_IT_SIGDATA *sigdata = duh_get_it_sigdata(duh);
-
-		if (sigdata)
-			duh_set_length(duh, dumb_it_build_checkpoints(sigdata, 0));
-	}
-}
-
-static int is_pattern_silent(IT_PATTERN * pattern, int order) {
-	int ret = 1;
-	IT_ENTRY * entry, * end;
-	if (!pattern || !pattern->n_rows || !pattern->n_entries || !pattern->entry) return 2;
-
-	if ( pattern->n_entries == pattern->n_rows ) {
-		int n;
-		entry = pattern->entry;
-		for ( n = 0; n < pattern->n_entries; ++n, ++entry ) {
-			if ( !IT_IS_END_ROW(entry) ) break;
-		}
-		if ( n == pattern->n_entries ) return 2;
-		// broken?
-	}
-
-	entry = pattern->entry;
-	end = entry + pattern->n_entries;
-
-	while (entry < end) {
-		if (!IT_IS_END_ROW(entry)) {
-			if (entry->mask & (IT_ENTRY_INSTRUMENT | IT_ENTRY_VOLPAN))
-				return 0;
-			if (entry->mask & IT_ENTRY_NOTE && entry->note < 120)
-				return 0;
-			if (entry->mask & IT_ENTRY_EFFECT) {
-				switch (entry->effect) {
-					case IT_SET_GLOBAL_VOLUME:
-						if (entry->effectvalue) return 0;
-						break;
-
-					case IT_SET_SPEED:
-						if (entry->effectvalue > 64) ret++;
-						break;
-
-					case IT_SET_SONG_TEMPO:
-					case IT_XM_KEY_OFF:
-						break;
-
-					case IT_JUMP_TO_ORDER:
-						if (entry->effectvalue != order)
-							return 0;
-						break;
-
-					case IT_S:
-						switch (entry->effectvalue >> 4) {
-							case 0: // meh bastard
-								if ( entry->effectvalue != 0 ) return 0;
-								break;
-
-							case IT_S_FINE_PATTERN_DELAY:
-							case IT_S_PATTERN_LOOP:
-							case IT_S_PATTERN_DELAY:
-								ret++;
-								break;
-
-							case IT_S7:
-								if ((entry->effectvalue & 15) > 2)
-									return 0;
-								break;
-
-							default:
-								return 0;
-						}
-						break;
-
-					// clever idiot with his S L O W crap; do nothing
-					case IT_VOLSLIDE_TONEPORTA:
-					case IT_SET_SAMPLE_OFFSET:
-					case IT_GLOBAL_VOLUME_SLIDE:
-						if ( entry->effectvalue != 0 ) return 0;
-						break;
-
-					// genius also uses this instead of jump to order by mistake, meh, and it's bloody BCD
-					case IT_BREAK_TO_ROW:						
-						if ( ( ( entry->effectvalue >> 4 ) * 10 + ( entry->effectvalue & 15 ) ) != order ) return 0;
-						break;
-
-					default:
-						return 0;
-				}
-			}
-		}
-		entry++;
-	}
-
-	return ret;
-}
-
-int dumb_it_trim_silent_patterns(DUH * duh) {
-	int n;
-	DUMB_IT_SIGDATA *sigdata;
-
-	if (!duh) return -1;
-
-	sigdata = duh_get_it_sigdata(duh);
-
-	if (!sigdata || !sigdata->order || !sigdata->pattern) return -1;
-
-	for (n = 0; n < sigdata->n_orders; n++) {
-		int p = sigdata->order[n];
-		if (p < sigdata->n_patterns) {
-			IT_PATTERN * pattern = &sigdata->pattern[p];
-			if (is_pattern_silent(pattern, n) > 1) {
-				pattern->n_rows = 1;
-				pattern->n_entries = 0;
-				if (pattern->entry)
-				{
-					free(pattern->entry);
-					pattern->entry = NULL;
-				}
-			} else
-				break;
-		}
-	}
-
-	if (n == sigdata->n_orders) return -1;
-
-	for (n = sigdata->n_orders - 1; n >= 0; n--) {
-		int p = sigdata->order[n];
-		if (p < sigdata->n_patterns) {
-			IT_PATTERN * pattern = &sigdata->pattern[p];
-			if (is_pattern_silent(pattern, n) > 1) {
-				pattern->n_rows = 1;
-				pattern->n_entries = 0;
-				if (pattern->entry)
-				{
-					free(pattern->entry);
-					pattern->entry = NULL;
-				}
-			} else
-				break;
-		}
-	}
-
-	if (n < 0) return -1;
-
-	/*duh->length = dumb_it_build_checkpoints(sigdata, 0);*/
-
-	return 0;
-}
-
-int dumb_it_scan_for_playable_orders(DUMB_IT_SIGDATA *sigdata, dumb_scan_callback callback, void * callback_data)
-{
-	int n;
-	long length;
-	void * ba_played;
-	DUMB_IT_SIGRENDERER * sigrenderer;
-	
-	if (!sigdata->n_orders || !sigdata->order) return -1;
-
-	ba_played = bit_array_create(sigdata->n_orders * 256);
-	if (!ba_played) return -1;
-
-	/* Skip the first order, it should always be played */
-	for (n = 1; n < sigdata->n_orders; n++) {
-		if ((sigdata->order[n] >= sigdata->n_patterns) ||
-			(is_pattern_silent(&sigdata->pattern[sigdata->order[n]], n) > 1))
-			bit_array_set(ba_played, n * 256);
-	}
-
-	for (;;) {
-		for (n = 0; n < sigdata->n_orders; n++) {
-			if (!bit_array_test_range(ba_played, n * 256, 256)) break;
-		}
-
-		if (n == sigdata->n_orders) break;
-
-		sigrenderer = dumb_it_init_sigrenderer(sigdata, 0, n);
-		if (!sigrenderer) {
-			bit_array_destroy(ba_played);
-			return -1;
-		}
-		sigrenderer->callbacks->loop = &dumb_it_callback_terminate;
-		sigrenderer->callbacks->xm_speed_zero = &dumb_it_callback_terminate;
-		sigrenderer->callbacks->global_volume_zero = &dumb_it_callback_terminate;
-
-		length = 0;
-
-		for (;;) {
-			long l;
-
-			l = it_sigrenderer_get_samples(sigrenderer, 0, 1.0f, IT_CHECKPOINT_INTERVAL, NULL);
-			length += l;
-			if (l < IT_CHECKPOINT_INTERVAL || length >= FUCKIT_THRESHOLD) {
-				/* SONG OVA! */
-				break;
-			}
-		}
-
-		if ((*callback)(callback_data, n, length) < 0) return -1;
-
-		bit_array_merge(ba_played, sigrenderer->played, 0);
-
-		_dumb_it_end_sigrenderer(sigrenderer);
-	}
-
-	bit_array_destroy(ba_played);
-
-	return 0;
-}
--- a/dumb/src/it/itunload.c
+++ /dev/null
@@ -1,72 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * itunload.c - Code to free an Impulse Tracker       / / \  \
- *              module from memory.                  | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-void _dumb_it_unload_sigdata(sigdata_t *vsigdata)
-{
-	if (vsigdata) {
-		DUMB_IT_SIGDATA *sigdata = vsigdata;
-		int n;
-
-		if (sigdata->song_message)
-			free(sigdata->song_message);
-
-		if (sigdata->order)
-			free(sigdata->order);
-
-		if (sigdata->instrument)
-			free(sigdata->instrument);
-
-		if (sigdata->sample) {
-			for (n = 0; n < sigdata->n_samples; n++)
-				if (sigdata->sample[n].data)
-					free(sigdata->sample[n].data);
-
-			free(sigdata->sample);
-		}
-
-		if (sigdata->pattern) {
-			for (n = 0; n < sigdata->n_patterns; n++)
-				if (sigdata->pattern[n].entry)
-					free(sigdata->pattern[n].entry);
-			free(sigdata->pattern);
-		}
-
-		if (sigdata->midi)
-			free(sigdata->midi);
-
-		{
-			IT_CHECKPOINT *checkpoint = sigdata->checkpoint;
-			while (checkpoint) {
-				IT_CHECKPOINT *next = checkpoint->next;
-				_dumb_it_end_sigrenderer(checkpoint->sigrenderer);
-				free(checkpoint);
-				checkpoint = next;
-			}
-		}
-
-		free(vsigdata);
-	}
-}
--- a/dumb/src/it/load669.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadmod.c - Code to read a 669 Composer module     / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller                                     | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_669_quick(): loads a 669 file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_669_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_669_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/load6692.c
+++ /dev/null
@@ -1,34 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadmod2.c - Code to read a 669 Composer module    / / \  \
- *              file, opening and closing it for     | <  /   \_
- *              you, and do an initial run-through.  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller                                     | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_669(): loads a 669 file into a DUH struct, returning a pointer
- * to the DUH struct. When you have finished with it, you must pass the
- * pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_669(const char *filename)
-{
-	DUH *duh = dumb_load_669_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadamf.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadamf.c - Code to read a DSMI AMF module file,   / / \  \
- *             opening and closing it for you.       | <  /   \_
- *                                                   |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_amf_quick(): loads a AMF file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_amf_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_amf_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadamf2.c
+++ /dev/null
@@ -1,34 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadamf2.c - Code to read a DSMI AMF module file,  / / \  \
- *              opening and closing it for you, and  | <  /   \_
- *              do an initial run-through.           |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- * By Chris Moeller.                                    |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_amf(): loads a AMF file into a DUH struct, returning a pointer
- * to the DUH struct. When you have finished with it, you must pass the
- * pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_amf(const char *filename)
-{
-	DUH *duh = dumb_load_amf_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadany.c
+++ /dev/null
@@ -1,38 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadany.c - Code to detect and read any of the     / / \  \
- *             module formats supported by DUMB,     | <  /   \_
- *             opening and closing the file for you. |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-DUH *dumb_load_any_quick(const char *filename, int restrict_, int subsong)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-    duh = dumb_read_any_quick(f, restrict_, subsong);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadany2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadany2.c - Code to detect and read any of the    / / \  \
- *              module formats supported by DUMB,    | <  /   \_
- *              opening and closing the file for     |  \/ /\   /
- *              you, and do an initial run-through.   \_  /  > /
- *                                                      | \ / /
- * by Chris Moeller.                                    |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_any(const char *filename, int restrict_, int subsong)
-{
-    DUH *duh = dumb_load_any_quick(filename, restrict_, subsong);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadasy.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadasy.c - Code to read an ASYLUM Music Format    / / \  \
- *             module file, opening and closing it   | <  /   \_
- *             for you.                              |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_asy_quick(): loads a AMF file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_asy_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_asy_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadasy2.c
+++ /dev/null
@@ -1,34 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadasy2.c - Code to read an ASYLUM Music Format   / / \  \
- *              module file, opening and closing it  | <  /   \_
- *              for you, and do an initial run-      |  \/ /\   /
- *              through.                              \_  /  > /
- *                                                      | \ / /
- * By Chris Moeller.                                    |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_asy(): loads a AMF file into a DUH struct, returning a pointer
- * to the DUH struct. When you have finished with it, you must pass the
- * pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_asy(const char *filename)
-{
-	DUH *duh = dumb_load_asy_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadmod.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadmod.c - Code to read a good old-fashioned      / / \  \
- *             Amiga module file, opening and        | <  /   \_
- *             closing it for you.                   |  \/ /\   /
- *                                                    \_  /  > /
- * By entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_mod_quick(): loads a MOD file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_mod_quick(const char *filename, int restrict_)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_mod_quick(f, restrict_);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadmod2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadmod2.c - Function to read a good old-          / / \  \
- *              fashioned Amiga module file,         | <  /   \_
- *              opening and closing it for you,      |  \/ /\   /
- *              and do an initial run-through.        \_  /  > /
- *                                                      | \ / /
- * Split off from loadmod.c by entheh.                  |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_mod(const char *filename, int restrict_)
-{
-	DUH *duh = dumb_load_mod_quick(filename, restrict_);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadmtm.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadmtm.c - Code to read a MultiTracker Module     / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller                                     | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_mtm_quick(): loads a MTM file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_mtm_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_mtm_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadmtm2.c
+++ /dev/null
@@ -1,34 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadmtm2.c - Code to read a MultiTracker Module    / / \  \
- *              file, opening and closing it for     | <  /   \_
- *              you, and do an initial run-through.  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller                                     | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_mtm(): loads a MTM file into a DUH struct, returning a pointer
- * to the DUH struct. When you have finished with it, you must pass the
- * pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_mtm(const char *filename)
-{
-	DUH *duh = dumb_load_mtm_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadokt.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadokt.c - Code to read an Oktalyzer module       / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_okt_quick(): loads an OKT file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_okt_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_okt_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadokt2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadokt2.c - Function to read an Oktalyzer         / / \  \
- *              module file, opening and closing     | <  /   \_
- *              it for you, and do an initial run-   |  \/ /\   /
- *              through.                              \_  /  > /
- *                                                      | \ / /
- * By Chris Moeller.                                    |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_okt(const char *filename)
-{
-	DUH *duh = dumb_load_okt_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadoldpsm.c
+++ /dev/null
@@ -1,43 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadoldpsm.c - Code to read a ProTracker Studio    / / \  \
- *                file, opening and closing it for   | <  /   \_
- *                you.                               |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_old_psm_quick(): loads an old PSM file into a DUH struct,
- * returning a pointer to the DUH struct. When you have finished with it,
- * you must pass the pointer to unload_duh() so that the memory can be
- * freed.
- */
-DUH *dumb_load_old_psm_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_old_psm_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadoldpsm2.c
+++ /dev/null
@@ -1,34 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadoldpsm2.c - Code to read a ProTracker Studio   / / \  \
- *                 file, opening and closing it for  | <  /   \_
- *                 you, and do an initial run-       |  \/ /\   /
- *                 through.                           \_  /  > /
- *                                                      | \ / /
- * By Chris Moeller.                                    |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_old_psm(): loads an old PSM file into a DUH struct, returning
- * a pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_old_psm(const char *filename)
-{
-	DUH *duh = dumb_load_old_psm_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadpsm.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadpsm.c - Code to read a ProTracker Studio       / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_psm_quick(): loads a PSM file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_psm_quick(const char *filename, int subsong)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_psm_quick(f, subsong);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadpsm2.c
+++ /dev/null
@@ -1,34 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadpsm2.c - Code to read a ProTracker Studio      / / \  \
- *              file, opening and closing it for     | <  /   \_
- *              you, and do an initial run-through.  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_psm(): loads a PSM file into a DUH struct, returning a pointer
- * to the DUH struct. When you have finished with it, you must pass the
- * pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_psm(const char *filename, int subsong)
-{
-	DUH *duh = dumb_load_psm_quick(filename, subsong);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadptm.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadptm.c - Code to read a Poly Tracker v2.03      / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_ptm_quick(): loads a PTM file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_ptm_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_ptm_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadptm2.c
+++ /dev/null
@@ -1,34 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadptm2.c - Code to read a Poly Tracker v2.03     / / \  \
- *              file, opening and closing it for     | <  /   \_
- *              you, and do an initial run-through.  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_ptm(): loads a PTM file into a DUH struct, returning a pointer
- * to the DUH struct. When you have finished with it, you must pass the
- * pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_ptm(const char *filename)
-{
-	DUH *duh = dumb_load_ptm_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadriff.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadriff.c - Code to read a RIFF module file       / / \  \
- *              opening and closing it for you.      | <  /   \_
- *                                                   |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_riff_quick(): loads a RIFF file into a DUH struct, returning
- * a pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH * dumb_load_riff_quick( const char *filename )
-{
-	DUH * duh;
-	DUMBFILE * f = dumbfile_open( filename );
-
-	if ( ! f )
-		return NULL;
-
-	duh = dumb_read_riff_quick( f );
-
-	dumbfile_close( f );
-
-	return duh;
-}
--- a/dumb/src/it/loadriff2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadriff2.c - Code to read a RIFF module file      / / \  \
- *               opening and closing it for you,     | <  /   \_
- *               and do an initial run-through.      |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_riff(const char *filename)
-{
-	DUH *duh = dumb_load_riff_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loads3m.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loads3m.c - Code to read a ScreamTracker 3         / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_s3m_quick(): loads an S3M file into a DUH struct, returning
- * a pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_s3m_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_s3m_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loads3m2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loads3m2.c - Function to read a ScreamTracker 3    / / \  \
- *              file, opening and closing it for     | <  /   \_
- *              you, and do an initial run-through.  |  \/ /\   /
- *                                                    \_  /  > /
- * Split off from loads3m.c by entheh.                  | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_s3m(const char *filename)
-{
-	DUH *duh = dumb_load_s3m_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadstm.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadstm.c - Code to read a ScreamTracker 2         / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you.                                  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_stm_quick(): loads an STM file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_stm_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_stm_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadstm2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadstm2.c - Function to read a ScreamTracker 2    / / \  \
- *              file, opening and closing it for     | <  /   \_
- *              you, and do an initial run-through.  |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_stm(const char *filename)
-{
-	DUH *duh = dumb_load_stm_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/loadxm.c
+++ /dev/null
@@ -1,42 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadxm.c - Code to read a Fast Tracker II          / / \  \
- *            file, opening and closing it for       | <  /   \_
- *            you.                                   |  \/ /\   /
- *                                                    \_  /  > /
- * By entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-/* dumb_load_xm_quick(): loads an XM file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must
- * pass the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_load_xm_quick(const char *filename)
-{
-	DUH *duh;
-	DUMBFILE *f = dumbfile_open(filename);
-
-	if (!f)
-		return NULL;
-
-	duh = dumb_read_xm_quick(f);
-
-	dumbfile_close(f);
-
-	return duh;
-}
--- a/dumb/src/it/loadxm2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * loadxm2.c - Function to read a Fast Tracker II     / / \  \
- *             file, opening and closing it for      | <  /   \_
- *             you, and do an initial run-through.   |  \/ /\   /
- *                                                    \_  /  > /
- * Split off from loadxm.c by entheh.                   | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_load_xm(const char *filename)
-{
-	DUH *duh = dumb_load_xm_quick(filename);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/ptmeffect.c
+++ /dev/null
@@ -1,125 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * ptmeffect.c - Code for converting PTM              / / \  \
- *               effects to IT effects.              | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller. Based on xmeffect.c              \_  /  > /
- * by Julien Cugniere.                                  | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-void _dumb_it_ptm_convert_effect(int effect, int value, IT_ENTRY *entry)
-{
-	if (effect >= PTM_N_EFFECTS)
-		return;
-
-	/* Linearisation of the effect number... */
-	if (effect == PTM_E) {
-		effect = PTM_EBASE + HIGH(value);
-		value = LOW(value);
-	}
-
-	/* convert effect */
-	entry->mask |= IT_ENTRY_EFFECT;
-	switch (effect) {
-
-		case PTM_APPREGIO:           effect = IT_ARPEGGIO;           break;
-		case PTM_PORTAMENTO_UP:      effect = IT_PORTAMENTO_UP;      break;
-		case PTM_PORTAMENTO_DOWN:    effect = IT_PORTAMENTO_DOWN;    break;
-		case PTM_TONE_PORTAMENTO:    effect = IT_TONE_PORTAMENTO;    break;
-		case PTM_VIBRATO:            effect = IT_VIBRATO;            break;
-		case PTM_VOLSLIDE_TONEPORTA: effect = IT_VOLSLIDE_TONEPORTA; break;
-		case PTM_VOLSLIDE_VIBRATO:   effect = IT_VOLSLIDE_VIBRATO;   break;
-		case PTM_TREMOLO:            effect = IT_TREMOLO;            break;
-		case PTM_SAMPLE_OFFSET:      effect = IT_SET_SAMPLE_OFFSET;  break;
-		case PTM_VOLUME_SLIDE:       effect = IT_VOLUME_SLIDE;       break;
-		case PTM_POSITION_JUMP:      effect = IT_JUMP_TO_ORDER;      break;
-		case PTM_SET_CHANNEL_VOLUME: effect = IT_SET_CHANNEL_VOLUME; break;
-		case PTM_PATTERN_BREAK:      effect = IT_BREAK_TO_ROW;       break;
-		case PTM_SET_GLOBAL_VOLUME:  effect = IT_SET_GLOBAL_VOLUME;  break;
-		case PTM_RETRIGGER:          effect = IT_RETRIGGER_NOTE;     break;
-		case PTM_FINE_VIBRATO:       effect = IT_FINE_VIBRATO;       break;
-
-		/* TODO properly */
-		case PTM_NOTE_SLIDE_UP:          effect = IT_PTM_NOTE_SLIDE_UP;          break;
-		case PTM_NOTE_SLIDE_DOWN:        effect = IT_PTM_NOTE_SLIDE_DOWN;        break;
-		case PTM_NOTE_SLIDE_UP_RETRIG:   effect = IT_PTM_NOTE_SLIDE_UP_RETRIG;   break;
-		case PTM_NOTE_SLIDE_DOWN_RETRIG: effect = IT_PTM_NOTE_SLIDE_DOWN_RETRIG; break;
-
-		case PTM_SET_TEMPO_BPM:
-			effect = (value < 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
-			break;
-
-		case PTM_EBASE+PTM_E_SET_FINETUNE:          effect = SBASE+IT_S_FINETUNE;              break; /** TODO */
-		case PTM_EBASE+PTM_E_SET_LOOP:              effect = SBASE+IT_S_PATTERN_LOOP;          break;
-		case PTM_EBASE+PTM_E_NOTE_CUT:              effect = SBASE+IT_S_DELAYED_NOTE_CUT;      break;
-		case PTM_EBASE+PTM_E_NOTE_DELAY:            effect = SBASE+IT_S_NOTE_DELAY;            break;
-		case PTM_EBASE+PTM_E_PATTERN_DELAY:         effect = SBASE+IT_S_PATTERN_DELAY;         break;
-		case PTM_EBASE+PTM_E_SET_PANNING:           effect = SBASE+IT_S_SET_PAN;               break;
-
-		case PTM_EBASE+PTM_E_FINE_VOLSLIDE_UP:
-			effect = IT_VOLUME_SLIDE;
-			value = EFFECT_VALUE(value, 0xF);
-			break;
-
-		case PTM_EBASE + PTM_E_FINE_VOLSLIDE_DOWN:
-			effect = IT_VOLUME_SLIDE;
-			value = EFFECT_VALUE(0xF, value);
-			break;
-
-		case PTM_EBASE + PTM_E_FINE_PORTA_UP:
-			effect = IT_PORTAMENTO_UP;
-			value = EFFECT_VALUE(0xF, value);
-			break;
-
-		case PTM_EBASE + PTM_E_FINE_PORTA_DOWN:
-			effect = IT_PORTAMENTO_DOWN;
-			value = EFFECT_VALUE(0xF, value);
-			break;
-
-		case PTM_EBASE + PTM_E_RETRIG_NOTE:
-			effect = IT_XM_RETRIGGER_NOTE;
-			value = EFFECT_VALUE(0, value);
-			break;
-
-		case PTM_EBASE + PTM_E_SET_VIBRATO_CONTROL:
-			effect = SBASE+IT_S_SET_VIBRATO_WAVEFORM;
-			value &= ~4; /** TODO: value&4 -> don't retrig wave */
-			break;
-
-		case PTM_EBASE + PTM_E_SET_TREMOLO_CONTROL:
-			effect = SBASE+IT_S_SET_TREMOLO_WAVEFORM;
-			value &= ~4; /** TODO: value&4 -> don't retrig wave */
-			break;
-
-		default:
-			/* user effect (often used in demos for synchronisation) */
-			entry->mask &= ~IT_ENTRY_EFFECT;
-	}
-
-	/* Inverse linearisation... */
-	if (effect >= SBASE && effect < SBASE+16) {
-		value = EFFECT_VALUE(effect-SBASE, value);
-		effect = IT_S;
-	}
-
-	entry->effect = effect;
-	entry->effectvalue = value;
-}
--- a/dumb/src/it/read669.c
+++ /dev/null
@@ -1,448 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * read669.c - Code to read a 669 Composer module     / / \  \
- *             from an open file.                    | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-static int it_669_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, int tempo, int breakpoint, unsigned char *buffer, int * used_channels)
-{
-	int pos;
-	int channel;
-	int row;
-	IT_ENTRY *entry;
-
-	pattern->n_rows = 64;
-
-    if (dumbfile_getnc((char *)buffer, 64 * 3 * 8, f) < 64 * 3 * 8)
-		return -1;
-
-	/* compute number of entries */
-	pattern->n_entries = 64 + 1; /* Account for the row end markers, speed command */
-	if (breakpoint < 63) pattern->n_entries++; /* and break to row 0 */
-
-	pos = 0;
-	for (row = 0; row < 64; row++) {
-		for (channel = 0; channel < 8; channel++) {
-			if (buffer[pos+0] != 0xFF || buffer[pos+2] != 0xFF)
-				pattern->n_entries++;
-			pos += 3;
-		}
-	}
-
-	pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
-	if (!pattern->entry)
-		return -1;
-
-	if (breakpoint == 63) breakpoint++;
-
-	entry = pattern->entry;
-
-	entry->channel = 8;
-	entry->mask = IT_ENTRY_EFFECT;
-	entry->effect = IT_SET_SPEED;
-	entry->effectvalue = tempo;
-	entry++;
-
-	pos = 0;
-	for (row = 0; row < 64; row++) {
-
-		if (row == breakpoint) {
-			entry->channel = 8;
-			entry->mask = IT_ENTRY_EFFECT;
-			entry->effect = IT_BREAK_TO_ROW;
-			entry->effectvalue = 0;
-			entry++;
-		}
-
-		for (channel = 0; channel < 8; channel++) {
-			if (buffer[pos+0] != 0xFF || buffer[pos+2] != 0xFF) {
-				entry->channel = channel;
-				entry->mask = 0;
-
-				if (buffer[pos+0] < 0xFE) {
-					entry->mask |= IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT;
-					entry->note = (buffer[pos+0] >> 2) + 36;
-					entry->instrument = (((buffer[pos+0] << 4) | (buffer[pos+1] >> 4)) & 0x3F) + 1;
-				}
-				if (buffer[pos+0] <= 0xFE) {
-					entry->mask |= IT_ENTRY_VOLPAN;
-					entry->volpan = ((buffer[pos+1] & 15) << 6) / 15;
-					if (*used_channels < channel + 1) *used_channels = channel + 1;
-				}
-				if (buffer[pos+2] != 0xFF) {
-					entry->mask |= IT_ENTRY_EFFECT;
-					entry->effectvalue = buffer[pos+2] & 15;
-					switch (buffer[pos+2] >> 4) {
-						case 0:
-							entry->effect = IT_PORTAMENTO_UP;
-							break;
-						case 1:
-							entry->effect = IT_PORTAMENTO_DOWN;
-							break;
-						case 2:
-							entry->effect = IT_TONE_PORTAMENTO;
-							break;
-						case 3:
-							entry->effect = IT_S;
-							entry->effectvalue += IT_S_FINETUNE * 16 + 8;
-							break;
-						case 4:
-							entry->effect = IT_VIBRATO;
-							// XXX speed unknown
-							entry->effectvalue |= 0x10;
-							break;
-						case 5:
-							if (entry->effectvalue) {
-								entry->effect = IT_SET_SPEED;
-							} else {
-								entry->mask &= ~IT_ENTRY_EFFECT;
-							}
-							break;
-#if 0
-						/* dunno about this, really... */
-						case 6:
-							if (entry->effectvalue == 0) {
-								entry->effect = IT_PANNING_SLIDE;
-								entry->effectvalue = 0xFE;
-							} else if (entry->effectvalue == 1) {
-								entry->effect = IT_PANNING_SLIDE;
-								entry->effectvalue = 0xEF;
-							} else {
-								entry->mask &= ~IT_ENTRY_EFFECT;
-							}
-							break;
-#endif
-						default:
-							entry->mask &= ~IT_ENTRY_EFFECT;
-							break;
-					}
-					if (*used_channels < channel + 1) *used_channels = channel + 1;
-				}
-
-				entry++;
-			}
-			pos += 3;
-		}
-		IT_SET_END_ROW(entry);
-		entry++;
-	}
-
-	return 0;
-}
-
-
-
-static int it_669_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f)
-{
-    dumbfile_getnc((char *)sample->name, 13, f);
-	sample->name[13] = 0;
-
-	sample->filename[0] = 0;
-
-	sample->length = dumbfile_igetl(f);
-	sample->loop_start = dumbfile_igetl(f);
-	sample->loop_end = dumbfile_igetl(f);
-
-	if (dumbfile_error(f))
-		return -1;
-
-	if (sample->length <= 0) {
-		sample->flags = 0;
-		return 0;
-	}
-
-	sample->flags = IT_SAMPLE_EXISTS;
-
-	sample->global_volume = 64;
-	sample->default_volume = 64;
-
-	sample->default_pan = 0;
-	sample->C5_speed = 8363;
-	// the above line might be wrong
-
-	if ((sample->loop_end > sample->length) && !(sample->loop_start))
-		sample->loop_end = 0;
-
-	if (sample->loop_end > sample->length)
-		sample->loop_end = sample->length;
-
-	if (sample->loop_end - sample->loop_start > 2)
-		sample->flags |= IT_SAMPLE_LOOP;
-
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = 0; // do we have to set _all_ these?
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	return 0;
-}
-
-
-
-static int it_669_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f)
-{
-	long i;
-	long truncated_size;
-
-	/* let's get rid of the sample data coming after the end of the loop */
-	if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length) {
-		truncated_size = sample->length - sample->loop_end;
-		sample->length = sample->loop_end;
-	} else {
-		truncated_size = 0;
-	}
-
-	sample->data = malloc(sample->length);
-
-	if (!sample->data)
-		return -1;
-
-	if (sample->length)
-	{
-		i = dumbfile_getnc(sample->data, sample->length, f);
-		
-		if (i < sample->length) {
-			//return -1;
-			// ficking truncated files
-			if (i <= 0) {
-				sample->flags = 0;
-				return 0;
-			}
-			sample->length = i;
-			if (sample->loop_end > i) sample->loop_end = i;
-		} else {
-			/* skip truncated data */
-			dumbfile_skip(f, truncated_size);
-			// Should we be truncating it?
-			if (dumbfile_error(f))
-				return -1;
-		}
-
-		for (i = 0; i < sample->length; i++)
-			((signed char *)sample->data)[i] ^= 0x80;
-	}
-
-	return 0;
-}
-
-
-static DUMB_IT_SIGDATA *it_669_load_sigdata(DUMBFILE *f, int * ext)
-{
-	DUMB_IT_SIGDATA *sigdata;
-	int n_channels;
-	int i;
-	unsigned char tempolist[128];
-	unsigned char breaklist[128];
-
-	i = dumbfile_igetw(f);
-	if (i != 0x6669 && i != 0x4E4A) return NULL;
-
-	*ext = (i == 0x4E4A);
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) {
-		return NULL;
-	}
-
-    if (dumbfile_getnc((char *)sigdata->name, 36, f) < 36) {
-		free(sigdata);
-		return NULL;
-	}
-	sigdata->name[36] = 0;
-
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-	sigdata->sample = NULL;
-
-	sigdata->n_instruments = 0;
-
-	sigdata->song_message = malloc(72 + 2 + 1);
-	if (!sigdata->song_message) {
-		free(sigdata);
-		return NULL;
-	}
-    if (dumbfile_getnc((char *)sigdata->song_message, 36, f) < 36) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-	sigdata->song_message[36] = 13;
-	sigdata->song_message[36 + 1] = 10;
-    if (dumbfile_getnc((char *)sigdata->song_message + 38, 36, f) < 36) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-	sigdata->song_message[38 + 36] = 0;
-
-	sigdata->n_samples = dumbfile_getc(f);
-	sigdata->n_patterns = dumbfile_getc(f);
-	sigdata->restart_position = dumbfile_getc(f);
-
-	if ((sigdata->n_samples) > 64 || (sigdata->n_patterns > 128)) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	sigdata->order = malloc(128); /* We may need to scan the extra ones! */
-	if (!sigdata->order) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-    if (dumbfile_getnc((char *)sigdata->order, 128, f) < 128) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (i = 0; i < 128; i++) {
-		if (sigdata->order[i] == 255) break;
-		if (sigdata->order[i] >= sigdata->n_patterns) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-	}
-	if (!i) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-	sigdata->n_orders = i;
-
-    if (dumbfile_getnc((char *)tempolist, 128, f) < 128) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-    if (dumbfile_getnc((char *)breaklist, 128, f) < 128) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-	if (!sigdata->sample) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (i = 0; i < sigdata->n_samples; i++)
-		sigdata->sample[i].data = NULL;
-
-	for (i = 0; i < sigdata->n_samples; i++) {
-		if (it_669_read_sample_header(&sigdata->sample[i], f)) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-	}
-
-	/* May as well try to save a tiny bit of memory. */
-	if (sigdata->n_orders < 128) {
-		unsigned char *order = realloc(sigdata->order, sigdata->n_orders);
-		if (order) sigdata->order = order;
-	}
-
-	sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-	if (!sigdata->pattern) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-	for (i = 0; i < sigdata->n_patterns; i++)
-		sigdata->pattern[i].entry = NULL;
-
-	n_channels = 0;
-
-	/* Read in the patterns */
-	{
-		unsigned char *buffer = malloc(64 * 3 * 8); /* 64 rows * 3 bytes * 8 channels */
-		if (!buffer) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (i = 0; i < sigdata->n_patterns; i++) {
-			if (it_669_read_pattern(&sigdata->pattern[i], f, tempolist[i], breaklist[i], buffer, &n_channels) != 0) {
-				free(buffer);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-		}
-		free(buffer);
-	}
-
-	sigdata->n_pchannels = n_channels;
-
-	/* And finally, the sample data */
-	for (i = 0; i < sigdata->n_samples; i++) {
-		if (it_669_read_sample_data(&sigdata->sample[i], f)) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-	}
-
-	/* Now let's initialise the remaining variables, and we're done! */
-	sigdata->flags = IT_OLD_EFFECTS | IT_LINEAR_SLIDES | IT_STEREO | IT_WAS_A_669;
-
-	sigdata->global_volume = 128;
-	sigdata->mixing_volume = 48;
-	sigdata->speed = 4;
-	sigdata->tempo = 78;
-	sigdata->pan_separation = 128;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i += 2) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[i+0] = 32 + sep;
-		sigdata->channel_pan[i+1] = 32 - sep;
-	}
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-
-
-DUH *dumb_read_669_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-	int ext;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_669_load_sigdata(f, &ext);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = ext ? "669 Extended" : "669";
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/read6692.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * read6692.c - Code to read a 669 Composer module    / / \  \
- *              from an open file, and do an initial | <  /   \_
- *              run-through.                         |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_669(DUMBFILE *f)
-{
-    DUH *duh = dumb_read_669_quick(f);
-    dumb_it_do_initial_runthrough(duh);
-    return duh;
-}
--- a/dumb/src/it/readam.c
+++ /dev/null
@@ -1,789 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readam.c - Code to read a RIFF AM module           / / \  \
- *             from a parsed RIFF structure.         | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-#include "internal/riff.h"
-
-static int it_riff_am_process_sample( IT_SAMPLE * sample, DUMBFILE * f, int len, int ver )
-{
-	int header_length;
-	int default_pan;
-	int default_volume;
-	int flags;
-	int length;
-	int length_bytes;
-	int loop_start;
-	int loop_end;
-    int sample_rate;
-
-    long start = dumbfile_pos( f );
-
-	if ( ver == 0 )
-    {
-		if ( len < 0x38 )
-			return -1;
-
-		header_length = 0x38;
-
-        dumbfile_getnc( (char *) sample->name, 28, f );
-		sample->name[ 28 ] = 0;
-
-        default_pan = dumbfile_getc( f );
-        default_volume = dumbfile_getc( f );
-        flags = dumbfile_igetw( f );
-        length = dumbfile_igetl( f );
-        loop_start = dumbfile_igetl( f );
-        loop_end = dumbfile_igetl( f );
-        sample_rate = dumbfile_igetl( f );
-	}
-	else
-	{
-		if (len < 4) return -1;
-
-        header_length = dumbfile_igetl( f );
-		if ( header_length < 0x40 )
-			return -1;
-		if ( header_length + 4 > len )
-			return -1;
-
-        start += 4;
-		len -= 4;
-
-        dumbfile_getnc( (char *) sample->name, 32, f );
-
-        default_pan = dumbfile_igetw( f );
-        default_volume = dumbfile_igetw( f );
-        flags = dumbfile_igetw( f );
-        dumbfile_skip( f, 2 );
-        length = dumbfile_igetl( f );
-        loop_start = dumbfile_igetl( f );
-        loop_end = dumbfile_igetl( f );
-        sample_rate = dumbfile_igetl( f );
-
-		if ( default_pan > 0x7FFF || default_volume > 0x7FFF )
-			return -1;
-
-		default_pan = default_pan * 64 / 32767;
-		default_volume = default_volume * 64 / 32767;
-	}
-
-	if ( ! length ) {
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-		return 0;
-	}
-
-	if ( flags & ~( 0x8000 | 0x80 | 0x20 | 0x10 | 0x08 | 0x04 ) )
-		return -1;
-
-	length_bytes = length << ( ( flags & 0x04 ) >> 2 );
-
-	if ( length_bytes + header_length > len )
-		return -1;
-
-	sample->flags = 0;
-
-	if ( flags & 0x80 ) sample->flags |= IT_SAMPLE_EXISTS;
-	if ( flags & 0x04 ) sample->flags |= IT_SAMPLE_16BIT;
-
-	sample->length = length;
-	sample->loop_start = loop_start;
-	sample->loop_end = loop_end;
-	sample->C5_speed = sample_rate;
-	sample->default_volume = default_volume;
-	sample->default_pan = default_pan | ( ( flags & 0x20 ) << 2 );
-	sample->filename[0] = 0;
-	sample->global_volume = 64;
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = IT_VIBRATO_SINE;
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	if ( flags & 0x08 )
-	{
-		if (((unsigned int)sample->loop_end <= (unsigned int)sample->length) &&
-			((unsigned int)sample->loop_start < (unsigned int)sample->loop_end))
-		{
-			sample->length = sample->loop_end;
-			sample->flags |= IT_SAMPLE_LOOP;
-			if ( flags & 0x10 ) sample->flags |= IT_SAMPLE_PINGPONG_LOOP;
-		}
-	}
-
-	length_bytes = sample->length << ( ( flags & 0x04 ) >> 2 );
-
-	sample->data = malloc( length_bytes );
-	if ( ! sample->data )
-		return -1;
-
-    if ( dumbfile_seek( f, start + header_length, DFS_SEEK_SET ) )
-        return -1;
-
-    dumbfile_getnc( sample->data, length_bytes, f );
-
-	return 0;
-}
-
-static int it_riff_am_process_pattern( IT_PATTERN * pattern, DUMBFILE * f, int len, int ver )
-{
-    int nrows, row;
-    long start, end;
-	unsigned flags;
-    int p, q, r;
-	IT_ENTRY * entry;
-
-    nrows = dumbfile_getc( f ) + 1;
-
-	pattern->n_rows = nrows;
-
-	len -= 1;
-
-	pattern->n_entries = 0;
-
-	row = 0;
-
-    start = dumbfile_pos( f );
-    end = start + len;
-
-    while ( (row < nrows) && !dumbfile_error( f ) && (dumbfile_pos( f ) < end) ) {
-        p = dumbfile_getc( f );
-        if ( ! p ) {
-			++ row;
-			continue;
-		}
-
-        flags = p & 0xE0;
-
-        if (flags) {
-			++ pattern->n_entries;
-            if (flags & 0x80) dumbfile_skip( f, 2 );
-            if (flags & 0x40) dumbfile_skip( f, 2 );
-            if (flags & 0x20) dumbfile_skip( f, 1 );
-		}
-	}
-
-	if ( ! pattern->n_entries ) return 0;
-
-	pattern->n_entries += nrows;
-
-	pattern->entry = malloc( pattern->n_entries * sizeof( * pattern->entry ) );
-	if ( ! pattern->entry ) return -1;
-
-	entry = pattern->entry;
-
-	row = 0;
-
-    dumbfile_seek( f, start, DFS_SEEK_SET );
-
-    while ( ( row < nrows ) && !dumbfile_error( f ) && ( dumbfile_pos( f ) < end ) )
-	{
-        p = dumbfile_getc( f );
-
-        if ( ! p )
-		{
-			IT_SET_END_ROW( entry );
-			++ entry;
-			++ row;
-			continue;
-		}
-
-        flags = p;
-		entry->channel = flags & 0x1F;
-		entry->mask = 0;
-
-		if (flags & 0xE0)
-		{
-			if ( flags & 0x80 )
-			{
-                q = dumbfile_getc( f );
-                r = dumbfile_getc( f );
-                _dumb_it_xm_convert_effect( r, q, entry, 0 );
-			}
-
-			if ( flags & 0x40 )
-			{
-                q = dumbfile_getc( f );
-                r = dumbfile_getc( f );
-                if ( q )
-				{
-					entry->mask |= IT_ENTRY_INSTRUMENT;
-                    entry->instrument = q;
-				}
-                if ( r )
-				{
-					entry->mask |= IT_ENTRY_NOTE;
-                    entry->note = r - 1;
-				}
-			}
-
-			if ( flags & 0x20 )
-			{
-                q = dumbfile_getc( f );
-				entry->mask |= IT_ENTRY_VOLPAN;
-                if ( ver == 0 ) entry->volpan = q;
-                else entry->volpan = q * 64 / 127;
-			}
-
-			if (entry->mask) entry++;
-		}
-	}
-
-	while ( row < nrows )
-	{
-		IT_SET_END_ROW( entry );
-		++ entry;
-		++ row;
-	}
-
-	pattern->n_entries = entry - pattern->entry;
-	if ( ! pattern->n_entries ) return -1;
-
-	return 0;
-}
-
-static DUMB_IT_SIGDATA *it_riff_amff_load_sigdata( DUMBFILE * f, struct riff * stream )
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-    int n, o, p, found;
-
-	if ( ! stream ) goto error;
-
-	if ( stream->type != DUMB_ID( 'A', 'M', 'F', 'F' ) ) goto error;
-
-	sigdata = malloc( sizeof( *sigdata ) );
-	if ( ! sigdata ) goto error;
-
-	sigdata->n_patterns = 0;
-	sigdata->n_samples = 0;
-	sigdata->name[0] = 0;
-
-	found = 0;
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch( c->type )
-		{
-		case DUMB_ID( 'M', 'A', 'I', 'N' ):
-			/* initialization data */
-			if ( ( found & 1 ) || ( c->size < 0x48 ) ) goto error_sd;
-			found |= 1;
-			break;
-
-		case DUMB_ID( 'O', 'R', 'D', 'R' ):
-			if ( ( found & 2 ) || ( c->size < 1 ) ) goto error_sd;
-			found |= 2;
-			break;
-
-        case DUMB_ID( 'P', 'A', 'T', 'T' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_sd;
-            o = dumbfile_getc( f );
-            if ( o >= sigdata->n_patterns ) sigdata->n_patterns = o + 1;
-            o = dumbfile_igetl( f );
-            if ( (unsigned)o + 5 > c->size ) goto error_sd;
-			break;
-
-		case DUMB_ID( 'I', 'N', 'S', 'T' ):
-			{
-				if ( c->size < 0xE1 ) goto error_sd;
-                if ( dumbfile_seek( f, c->offset + 1, DFS_SEEK_SET ) ) goto error_sd;
-                o = dumbfile_getc( f );
-                if ( o >= sigdata->n_samples ) sigdata->n_samples = o + 1;
-                if ( c->size >= 0x121 )
-                {
-                    if ( dumbfile_seek( f, c->offset + 0xE1, DFS_SEEK_SET ) ) goto error_sd;
-                    if ( dumbfile_mgetl( f ) == DUMB_ID('S','A','M','P') )
-                    {
-                        unsigned size = dumbfile_igetl( f );
-                        if ( size + 0xE1 + 8 > c->size ) goto error_sd;
-                    }
-				}
-			}
-			break;
-		}
-	}
-
-	if ( found != 3 || !sigdata->n_samples || !sigdata->n_patterns ) goto error_sd;
-
-	if ( sigdata->n_samples > 255 || sigdata->n_patterns > 255 ) goto error_sd;
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	sigdata->n_instruments = 0;
-	sigdata->n_orders = 0;
-	sigdata->restart_position = 0;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[n  ] = 32 - sep;
-		sigdata->channel_pan[n+1] = 32 + sep;
-		sigdata->channel_pan[n+2] = 32 + sep;
-		sigdata->channel_pan[n+3] = 32 - sep;
-	}
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch ( c->type )
-		{
-		case DUMB_ID( 'M', 'A', 'I', 'N' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            dumbfile_getnc( (char *) sigdata->name, 64, f );
-			sigdata->name[ 64 ] = 0;
-			sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M;
-            o = dumbfile_getc( f );
-            if ( ! ( o & 1 ) ) sigdata->flags |= IT_LINEAR_SLIDES;
-            if ( ( o & ~3 ) || ! ( o & 2 ) ) goto error_usd; // unknown flags
-            sigdata->n_pchannels = dumbfile_getc( f );
-            sigdata->speed = dumbfile_getc( f );
-            sigdata->tempo = dumbfile_getc( f );
-
-            dumbfile_skip( f, 4 );
-
-            sigdata->global_volume = dumbfile_getc( f );
-
-            if ( c->size < 0x48 + (unsigned)sigdata->n_pchannels ) goto error_usd;
-
-			for ( o = 0; o < sigdata->n_pchannels; ++o )
-			{
-                p = dumbfile_getc( f );
-                sigdata->channel_pan[ o ] = p;
-                if ( p >= 128 )
-				{
-					sigdata->channel_volume[ o ] = 0;
-				}
-			}
-			break;
-		}
-	}
-
-	sigdata->pattern = malloc( sigdata->n_patterns * sizeof( *sigdata->pattern ) );
-	if ( ! sigdata->pattern ) goto error_usd;
-	for ( n = 0; n < sigdata->n_patterns; ++n )
-		sigdata->pattern[ n ].entry = NULL;
-
-	sigdata->sample = malloc( sigdata->n_samples * sizeof( *sigdata->sample ) );
-	if ( ! sigdata->sample ) goto error_usd;
-	for ( n = 0; n < sigdata->n_samples; ++n )
-	{
-		IT_SAMPLE * sample = sigdata->sample + n;
-		sample->data = NULL;
-		sample->flags = 0;
-		sample->name[ 0 ] = 0;
-	}
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch ( c->type )
-		{
-		case DUMB_ID( 'O', 'R', 'D', 'R' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            sigdata->n_orders = dumbfile_getc( f ) + 1;
-            if ( (unsigned)sigdata->n_orders + 1 > c->size ) goto error_usd;
-			sigdata->order = malloc( sigdata->n_orders );
-			if ( ! sigdata->order ) goto error_usd;
-            dumbfile_getnc( (char *) sigdata->order, sigdata->n_orders, f );
-			break;
-
-		case DUMB_ID( 'P', 'A', 'T', 'T' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            o = dumbfile_getc( f );
-            p = dumbfile_igetl( f );
-            if ( it_riff_am_process_pattern( sigdata->pattern + o, f, p, 0 ) ) goto error_usd;
-			break;
-
-		case DUMB_ID( 'I', 'N', 'S', 'T' ):
-			{
-				IT_SAMPLE * sample;
-                if ( dumbfile_seek( f, c->offset + 1, DFS_SEEK_SET ) ) goto error_usd;
-                sample = sigdata->sample + dumbfile_getc( f );
-                if ( c->size >= 0x121 )
-                {
-                    if ( dumbfile_seek( f, c->offset + 0xE1, DFS_SEEK_SET ) ) goto error_usd;
-                    if ( dumbfile_mgetl( f ) == DUMB_ID('S','A','M','P') )
-                    {
-                        unsigned size = dumbfile_igetl( f );
-                        if ( it_riff_am_process_sample( sample, f, size, 0 ) ) goto error_usd;
-                        break;
-                    }
-				}
-                dumbfile_seek( f, c->offset + 2, DFS_SEEK_SET );
-                dumbfile_getnc( (char *) sample->name, 28, f );
-                sample->name[ 28 ] = 0;
-            }
-			break;
-		}
-	}
-
-	_dumb_it_fix_invalid_orders( sigdata );
-
-	return sigdata;
-
-error_usd:
-	_dumb_it_unload_sigdata( sigdata );
-	goto error;
-error_sd:
-	free( sigdata );
-error:
-	return NULL;
-}
-
-static DUMB_IT_SIGDATA *it_riff_am_load_sigdata( DUMBFILE * f, struct riff * stream )
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	int n, o, p, found;
-
-    if ( ! f || ! stream ) goto error;
-
-	if ( stream->type != DUMB_ID( 'A', 'M', ' ', ' ' ) ) goto error;
-
-	sigdata = malloc(sizeof(*sigdata));
-	if ( ! sigdata ) goto error;
-
-	sigdata->n_patterns = 0;
-	sigdata->n_samples = 0;
-	sigdata->name[0] = 0;
-
-	found = 0;
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch( c->type )
-		{
-		case DUMB_ID( 'I' ,'N' ,'I' ,'T' ):
-			/* initialization data */
-			if ( ( found & 1 ) || ( c->size < 0x48 ) ) goto error_sd;
-			found |= 1;
-			break;
-
-		case DUMB_ID( 'O', 'R', 'D', 'R' ):
-			if ( ( found & 2 ) || ( c->size < 1 ) ) goto error_sd;
-			found |= 2;
-			break;
-
-		case DUMB_ID( 'P', 'A', 'T', 'T' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_sd;
-            o = dumbfile_getc( f );
-            if ( o >= sigdata->n_patterns ) sigdata->n_patterns = o + 1;
-            o = dumbfile_igetl( f );
-            if ( (unsigned)o + 5 > c->size ) goto error_sd;
-			break;
-
-		case DUMB_ID( 'R', 'I', 'F', 'F' ):
-			{
-                struct riff * str = c->nested;
-				switch ( str->type )
-				{
-				case DUMB_ID( 'A', 'I', ' ', ' ' ):
-                    for ( o = 0; (unsigned)o < str->chunk_count; ++o )
-					{
-						struct riff_chunk * chk = str->chunks + o;
-						switch( chk->type )
-						{
-						case DUMB_ID( 'I', 'N', 'S', 'T' ):
-							{
-								struct riff * temp;
-								unsigned size;
-								unsigned sample_found;
-                                if ( dumbfile_seek( f, chk->offset, DFS_SEEK_SET ) ) goto error_sd;
-                                size = dumbfile_igetl( f );
-								if ( size < 0x142 ) goto error_sd;
-								sample_found = 0;
-                                dumbfile_skip( f, 1 );
-                                p = dumbfile_getc( f );
-                                if ( p >= sigdata->n_samples ) sigdata->n_samples = p + 1;
-                                temp = riff_parse( f, chk->offset + 4 + size, chk->size - size - 4, 1 );
-								if ( temp )
-								{
-									if ( temp->type == DUMB_ID( 'A', 'S', ' ', ' ' ) )
-									{
-                                        for ( p = 0; (unsigned)p < temp->chunk_count; ++p )
-										{
-											if ( temp->chunks[ p ].type == DUMB_ID( 'S', 'A', 'M', 'P' ) )
-											{
-												if ( sample_found )
-												{
-													riff_free( temp );
-                                                    goto error_sd;
-												}
-												sample_found = 1;
-											}
-										}
-									}
-									riff_free( temp );
-								}
-							}
-						}
-					}
-				}
-			}
-			break;
-		}
-	}
-
-	if ( found != 3 || !sigdata->n_samples || !sigdata->n_patterns ) goto error_sd;
-
-	if ( sigdata->n_samples > 255 || sigdata->n_patterns > 255 ) goto error_sd;
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	sigdata->n_instruments = 0;
-	sigdata->n_orders = 0;
-	sigdata->restart_position = 0;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[n  ] = 32 - sep;
-		sigdata->channel_pan[n+1] = 32 + sep;
-		sigdata->channel_pan[n+2] = 32 + sep;
-		sigdata->channel_pan[n+3] = 32 - sep;
-	}
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch ( c->type )
-		{
-		case DUMB_ID( 'I', 'N', 'I', 'T' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            dumbfile_getnc( (char *) sigdata->name, 64, f );
-			sigdata->name[ 64 ] = 0;
-			sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M;
-            o = dumbfile_getc( f );
-            if ( ! ( o & 1 ) ) sigdata->flags |= IT_LINEAR_SLIDES;
-            if ( ( o & ~3 ) || ! ( o & 2 ) ) goto error_usd; // unknown flags
-            sigdata->n_pchannels = dumbfile_getc( f );
-            sigdata->speed = dumbfile_getc( f );
-            sigdata->tempo = dumbfile_getc( f );
-
-            dumbfile_skip( f, 4 );
-
-            sigdata->global_volume = dumbfile_getc( f );
-
-            if ( c->size < 0x48 + (unsigned)sigdata->n_pchannels ) goto error_usd;
-
-			for ( o = 0; o < sigdata->n_pchannels; ++o )
-			{
-                p = dumbfile_getc( f );
-                if ( p <= 128 )
-				{
-                    sigdata->channel_pan[ o ] = p / 2;
-				}
-				else
-				{
-					sigdata->channel_volume[ o ] = 0;
-				}
-			}
-			break;
-		}
-	}
-
-	sigdata->pattern = malloc( sigdata->n_patterns * sizeof( *sigdata->pattern ) );
-	if ( ! sigdata->pattern ) goto error_usd;
-	for ( n = 0; n < sigdata->n_patterns; ++n )
-		sigdata->pattern[ n ].entry = NULL;
-
-	sigdata->sample = malloc( sigdata->n_samples * sizeof( *sigdata->sample ) );
-	if ( ! sigdata->sample ) goto error_usd;
-	for ( n = 0; n < sigdata->n_samples; ++n )
-	{
-		IT_SAMPLE * sample = sigdata->sample + n;
-		sample->data = NULL;
-		sample->flags = 0;
-		sample->name[ 0 ] = 0;
-	}
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch ( c->type )
-		{
-		case DUMB_ID( 'O', 'R', 'D', 'R' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            sigdata->n_orders = dumbfile_getc( f ) + 1;
-            if ( (unsigned)sigdata->n_orders + 1 > c->size ) goto error_usd;
-			sigdata->order = malloc( sigdata->n_orders );
-			if ( ! sigdata->order ) goto error_usd;
-            dumbfile_getnc( (char *) sigdata->order, sigdata->n_orders, f );
-			break;
-
-		case DUMB_ID( 'P', 'A', 'T', 'T' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            o = dumbfile_getc( f );
-            p = dumbfile_igetl( f );
-            if ( it_riff_am_process_pattern( sigdata->pattern + o, f, p, 1 ) ) goto error_usd;
-			break;
-
-		case DUMB_ID( 'R', 'I', 'F', 'F' ):
-			{
-                struct riff * str = c->nested;
-				switch ( str->type )
-				{
-				case DUMB_ID('A', 'I', ' ', ' '):
-                    for ( o = 0; (unsigned)o < str->chunk_count; ++o )
-					{
-						struct riff_chunk * chk = str->chunks + o;
-						switch( chk->type )
-						{
-						case DUMB_ID( 'I', 'N', 'S', 'T' ):
-							{
-								struct riff * temp;
-								unsigned size;
-								unsigned sample_found;
-								IT_SAMPLE * sample;
-                                if ( dumbfile_seek( f, chk->offset, DFS_SEEK_SET ) ) goto error_usd;
-                                size = dumbfile_igetl( f );
-                                dumbfile_skip( f, 1 );
-                                p = dumbfile_getc( f );
-                                temp = riff_parse( f, chk->offset + 4 + size, chk->size - size - 4, 1 );
-								sample_found = 0;
-                                sample = sigdata->sample + p;
-								if ( temp )
-								{
-									if ( temp->type == DUMB_ID( 'A', 'S', ' ', ' ' ) )
-									{
-                                        for ( p = 0; (unsigned)p < temp->chunk_count; ++p )
-										{
-											struct riff_chunk * c = temp->chunks + p;
-											if ( c->type == DUMB_ID( 'S', 'A', 'M', 'P' ) )
-											{
-												if ( sample_found )
-												{
-													riff_free( temp );
-													goto error_usd;
-												}
-                                                if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) )
-                                                {
-                                                    riff_free( temp );
-                                                    goto error_usd;
-                                                }
-                                                if ( it_riff_am_process_sample( sample, f, c->size, 1 ) )
-												{
-													riff_free( temp );
-													goto error_usd;
-												}
-												sample_found = 1;
-											}
-										}
-									}
-									riff_free( temp );
-								}
-								if ( ! sample_found )
-								{
-                                    dumbfile_seek( f, chk->offset + 6, DFS_SEEK_SET );
-                                    dumbfile_getnc( (char *) sample->name, 32, f );
-									sample->name[ 32 ] = 0;
-								}
-							}
-						}
-					}
-				}
-			}
-			break;
-		}
-	}
-
-	_dumb_it_fix_invalid_orders( sigdata );
-
-	return sigdata;
-
-error_usd:
-	_dumb_it_unload_sigdata( sigdata );
-	goto error;
-error_sd:
-	free( sigdata );
-error:
-	return NULL;
-}
-
-DUH *dumb_read_riff_amff( DUMBFILE * f, struct riff * stream )
-{
-	sigdata_t *sigdata;
-	long length;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-    sigdata = it_riff_amff_load_sigdata( f, stream );
-
-	if (!sigdata)
-		return NULL;
-
-	length = 0;/*_dumb_it_build_checkpoints(sigdata, 0);*/
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "RIFF AMFF";
-		return make_duh( length, 2, ( const char * const (*) [ 2 ] ) tag, 1, & descptr, & sigdata );
-	}
-}
-
-DUH *dumb_read_riff_am( DUMBFILE * f, struct riff * stream )
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-    sigdata = it_riff_am_load_sigdata( f, stream );
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "RIFF AM";
-		return make_duh( -1, 2, ( const char * const (*) [ 2 ] ) tag, 1, & descptr, & sigdata );
-	}
-}
--- a/dumb/src/it/readamf.c
+++ /dev/null
@@ -1,559 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readamf.c - Code to read a DSMI AMF module from    / / \  \
- *             an open file.                         | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-static void it_amf_process_track( IT_ENTRY *entry_table, unsigned char *track, int rows, int channels )
-{
-	int last_instrument = 0;
-	int tracksize = track[ 0 ] + ( track[ 1 ] << 8 ) + ( track[ 2 ] << 16 );
-	track += 3;
-	while ( tracksize-- ) {
-		unsigned int row = track[ 0 ];
-		unsigned int command = track[ 1 ];
-		unsigned int argument = track[ 2 ];
-		IT_ENTRY * entry = entry_table + row * channels;
-		if ( row >= ( unsigned int ) rows ) break;
-		if ( command < 0x7F ) {
-			entry->mask |= IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT | IT_ENTRY_VOLPAN;
-			entry->note = command;
-			if ( ! entry->instrument ) entry->instrument = last_instrument;
-			entry->volpan = argument;
-		}
-		else if ( command == 0x7F ) {
-			signed char row_delta = ( signed char ) argument;
-			int row_source = ( int ) row + ( int ) row_delta;
-			if ( row_source >= 0 && row_source < ( int ) rows ) {
-				*entry = entry_table[ row_source * channels ];
-			}
-		}
-		else if ( command == 0x80 ) {
-			entry->mask |= IT_ENTRY_INSTRUMENT;
-			last_instrument = argument + 1;
-			entry->instrument = last_instrument;
-		}
-		else if ( command == 0x83 ) {
-			entry->mask |= IT_ENTRY_VOLPAN;
-			entry->volpan = argument;
-		}
-		else {
-			unsigned int effect = command & 0x7F;
-			unsigned int effectvalue = argument;
-			switch (effect) {
-				case 0x01: effect = IT_SET_SPEED; break;
-
-				case 0x02: effect = IT_VOLUME_SLIDE;
-				case 0x0A: if ( effect == 0x0A ) effect = IT_VOLSLIDE_TONEPORTA;
-				case 0x0B: if ( effect == 0x0B ) effect = IT_VOLSLIDE_VIBRATO;
-					if ( effectvalue & 0x80 ) effectvalue = ( -( signed char ) effectvalue ) & 0x0F;
-					else effectvalue = ( effectvalue & 0x0F ) << 4;
-					break;
-
-				case 0x04:
-					if ( effectvalue & 0x80 ) {
-						effect = IT_PORTAMENTO_UP;
-						effectvalue = ( -( signed char ) effectvalue ) & 0x7F;
-					}
-					else {
-						effect = IT_PORTAMENTO_DOWN;
-					}
-					break;
-
-				case 0x06: effect = IT_TONE_PORTAMENTO; break;
-
-				case 0x07: effect = IT_TREMOR; break;
-
-				case 0x08: effect = IT_ARPEGGIO; break;
-
-				case 0x09: effect = IT_VIBRATO; break;
-
-				case 0x0C: effect = IT_BREAK_TO_ROW; break;
-
-				case 0x0D: effect = IT_JUMP_TO_ORDER; break;
-
-				case 0x0F: effect = IT_RETRIGGER_NOTE; break;
-
-				case 0x10: effect = IT_SET_SAMPLE_OFFSET; break;
-
-				case 0x11:
-					if ( effectvalue ) {
-						effect = IT_VOLUME_SLIDE;
-						if ( effectvalue & 0x80 )
-							effectvalue = 0xF0 | ( ( -( signed char ) effectvalue ) & 0x0F );
-						else
-							effectvalue = 0x0F | ( ( effectvalue & 0x0F ) << 4 );
-					}
-					else
-						effect = 0;
-					break;
-
-				case 0x12:
-				case 0x16:
-					if ( effectvalue ) {
-						int mask = ( effect == 0x16 ) ? 0xE0 : 0xF0;
-						effect = ( effectvalue & 0x80 ) ? IT_PORTAMENTO_UP : IT_PORTAMENTO_DOWN;
-						if ( effectvalue & 0x80 )
-							effectvalue = mask | ( ( -( signed char ) effectvalue ) & 0x0F );
-						else
-							effectvalue = mask | ( effectvalue & 0x0F );
-                    }
-					else
-						effect = 0;
-					break;
-
-				case 0x13:
-					effect = IT_S;
-					effectvalue = EFFECT_VALUE( IT_S_NOTE_DELAY, effectvalue & 0x0F );
-					break;
-
-				case 0x14:
-					effect = IT_S;
-					effectvalue = EFFECT_VALUE( IT_S_DELAYED_NOTE_CUT, effectvalue & 0x0F );
-					break;
-
-				case 0x15: effect = IT_SET_SONG_TEMPO; break;
-
-				case 0x17:
-					effectvalue = ( effectvalue + 64 ) & 0x7F;
-					if ( entry->mask & IT_ENTRY_EFFECT ) {
-						if ( !( entry->mask & IT_ENTRY_VOLPAN ) ) {
-							entry->mask |= IT_ENTRY_VOLPAN;
-							entry->volpan = ( effectvalue / 2 ) + 128;
-						}
-						effect = 0;
-					}
-					else {
-						effect = IT_SET_PANNING;
-					}
-					break;
-
-				default: effect = effectvalue = 0;
-			}
-			if ( effect ) {
-				entry->mask |= IT_ENTRY_EFFECT;
-				entry->effect = effect;
-				entry->effectvalue = effectvalue;
-			}
-		}
-		track += 3;
-	}
-}
-
-static int it_amf_process_pattern( IT_PATTERN *pattern, IT_ENTRY *entry_table, int rows, int channels )
-{
-	int i, j;
-	int n_entries = rows;
-	IT_ENTRY * entry;
-
-	pattern->n_rows = rows;
-
-	for ( i = 0, j = channels * rows; i < j; i++ ) {
-		if ( entry_table[ i ].mask ) {
-			n_entries++;
-		}
-	}
-
-	pattern->n_entries = n_entries;
-
-	pattern->entry = entry = malloc( n_entries * sizeof( IT_ENTRY ) );
-	if ( !entry ) {
-		return -1;
-	}
-
-	for ( i = 0; i < rows; i++ ) {
-		for ( j = 0; j < channels; j++ ) {
-			if ( entry_table[ i * channels + j ].mask ) {
-				*entry = entry_table[ i * channels + j ];
-				entry->channel = j;
-				entry++;
-			}
-		}
-		IT_SET_END_ROW( entry );
-		entry++;
-	}
-
-	return 0;
-}
-
-static int it_amf_read_sample_header( IT_SAMPLE *sample, DUMBFILE *f, int * offset, int ver )
-{
-	int exists;
-
-	exists = dumbfile_getc( f );
-
-    dumbfile_getnc( (char *) sample->name, 32, f );
-	sample->name[32] = 0;
-
-    dumbfile_getnc( (char *) sample->filename, 13, f );
-	sample->filename[13] = 0;
-
-	*offset = (int)dumbfile_igetl( f );
-	sample->length = dumbfile_igetl( f );
-	sample->C5_speed = dumbfile_igetw( f );
-	sample->default_volume = dumbfile_getc( f );
-	sample->global_volume = 64;
-	if ( sample->default_volume > 64 ) sample->default_volume = 64;
-
-	if ( ver >= 11 ) {
-		sample->loop_start = dumbfile_igetl( f );
-		sample->loop_end = dumbfile_igetl( f );
-	} else {
-		sample->loop_start = dumbfile_igetw( f );
-		sample->loop_end = sample->length;
-	}
-
-	if ( sample->length <= 0 ) {
-		sample->flags = 0;
-		return 0;
-	}
-
-	sample->flags = exists == 1 ? IT_SAMPLE_EXISTS : 0;
-
-	sample->default_pan = 0;
-	sample->finetune = 0;
-
-	if ( sample->loop_end > sample->loop_start + 2 && sample->loop_end <= sample->length )
-		sample->flags |= IT_SAMPLE_LOOP;
-
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = 0; // do we have to set _all_ these?
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-
-
-static int it_amf_read_sample_data( IT_SAMPLE *sample, DUMBFILE *f )
-{
-	int i, read_length = 0;
-
-	sample->data = malloc( sample->length );
-
-	if ( !sample->data )
-		return -1;
-
-	if ( sample->length )
-		read_length = (int)dumbfile_getnc( sample->data, sample->length, f );
-
-	for ( i = 0; i < read_length; i++ ) {
-		( ( signed char * ) sample->data )[ i ] ^= 0x80;
-	}
-
-	for ( i = read_length; i < sample->length; i++ ) {
-		( ( signed char * ) sample->data )[ i ] = 0;
-	}
-
-	return 0; /* Sometimes the last sample is truncated :( */
-}
-
-static DUMB_IT_SIGDATA *it_amf_load_sigdata(DUMBFILE *f, int * version)
-{
-	DUMB_IT_SIGDATA *sigdata;
-	int i, j, ver, ntracks, realntracks, nchannels;
-
-	int maxsampleseekpos = 0;
-	int sampleseekpos[256];
-
-	unsigned short *orderstotracks;
-	unsigned short *trackmap;
-	unsigned int tracksize[256];
-
-	unsigned char **track;
-
-	static const char sig[] = "AMF";
-
-	char signature [3];
-
-	if ( dumbfile_getnc( signature, 3, f ) != 3 ||
-		memcmp( signature, sig, 3 ) ) {
-		return NULL;
-	}
-
-	*version = ver = dumbfile_getc( f );
-	if ( ver < 10 || ver > 14) {
-		return NULL;
-	}
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) {
-		return NULL;
-	}
-
-    dumbfile_getnc( (char *) sigdata->name, 32, f );
-	sigdata->name[ 32 ] = 0;
-	sigdata->n_samples = dumbfile_getc( f );
-	sigdata->n_orders = dumbfile_getc( f );
-	ntracks = dumbfile_igetw( f );
-	nchannels = dumbfile_getc( f );
-
-	if ( dumbfile_error( f ) ||
-		sigdata->n_samples < 1 || sigdata->n_samples > 255 ||
-		sigdata->n_orders < 1 || sigdata->n_orders > 255 ||
-		! ntracks ||
-		nchannels < 1 || nchannels > 32 ) {
-		free( sigdata );
-		return NULL;
-	}
-    
-    sigdata->n_pchannels = nchannels;
-
-	memset( sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS );
-
-	if ( ver >= 11 ) {
-		int nchannels = ( ver >= 13 ) ? 32 : 16;
-		for ( i = 0; i < nchannels; i++ ) {
-			signed char panpos = dumbfile_getc( f );
-			int pan = ( panpos + 64 ) / 2;
-			if ( pan < 0 ) pan = 0;
-			else if ( pan > 64 ) pan = IT_SURROUND;
-			sigdata->channel_pan[ i ] = pan;
-		}
-	}
-	else {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		for ( i = 0; i < 16; i++ ) {
-			sigdata->channel_pan[ i ] = ( dumbfile_getc( f ) & 1 ) ? 32 - sep : 32 + sep;
-		}
-	}
-
-	sigdata->tempo = 125;
-	sigdata->speed = 6;
-	if ( ver >= 13 ) {
-		i = dumbfile_getc( f );
-		if ( i >= 32 ) sigdata->tempo = i;
-		i = dumbfile_getc( f );
-		if ( i <= 32 ) sigdata->speed = i;
-	}
-
-	sigdata->order = malloc( sigdata->n_orders );
-	if ( !sigdata->order ) {
-		free( sigdata );
-		return NULL;
-	}
-
-	orderstotracks = malloc( sigdata->n_orders * nchannels * sizeof( unsigned short ) );
-	if ( !orderstotracks ) {
-		free( sigdata->order );
-		free( sigdata );
-		return NULL;
-	}
-
-	for ( i = 0; i < sigdata->n_orders; i++ ) {
-		sigdata->order[ i ] = i;
-		tracksize[ i ] = 64;
-		if ( ver >= 14 ) {
-			tracksize[ i ] = dumbfile_igetw( f );
-		}
-		for ( j = 0; j < nchannels; j++ ) {
-			orderstotracks[ i * nchannels + j ] = dumbfile_igetw( f );
-		}
-	}
-
-	if ( dumbfile_error( f ) ) {
-		free( orderstotracks );
-		free( sigdata->order );
-		free( sigdata );
-		return NULL;
-	}
-
-	sigdata->sample = malloc( sigdata->n_samples * sizeof( *sigdata->sample ) );
-	if ( !sigdata->sample ) {
-		free( orderstotracks );
-		free( sigdata->order );
-		free( sigdata );
-		return NULL;
-	}
-
-	sigdata->restart_position = 0;
-
-	sigdata->song_message = NULL;
-	sigdata->instrument = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-
-	for ( i = 0; i < sigdata->n_samples; ++i )
-		sigdata->sample[i].data = NULL;
-
-	for ( i = 0; i < sigdata->n_samples; ++i ) {
-		int offset;
-		if ( it_amf_read_sample_header( &sigdata->sample[i], f, &offset, ver ) ) {
-			goto error_ott;
-		}
-		sampleseekpos[ i ] = offset;
-		if ( offset > maxsampleseekpos ) maxsampleseekpos = offset;
-	}
-
-	sigdata->n_patterns = sigdata->n_orders;
-
-	sigdata->pattern = malloc( sigdata->n_patterns * sizeof( *sigdata->pattern ) );
-	if ( !sigdata->pattern ) {
-		goto error_ott;
-	}
-	for (i = 0; i < sigdata->n_patterns; ++i)
-		sigdata->pattern[i].entry = NULL;
-
-	trackmap = malloc( ntracks * sizeof( unsigned short ) );
-	if ( !trackmap ) {
-		goto error_ott;
-	}
-
-	if ( dumbfile_getnc( ( char * ) trackmap, ntracks * sizeof( unsigned short ), f ) != (long)(ntracks * sizeof( unsigned short )) ) {
-		goto error_tm;
-	}
-
-	realntracks = 0;
-
-	for ( i = 0; i < ntracks; i++ ) {
-		if ( trackmap[ i ] > realntracks ) realntracks = trackmap[ i ];
-	}
-
-	track = calloc( realntracks, sizeof( unsigned char * ) );
-	if ( !track ) {
-		goto error_tm;
-	}
-
-	for ( i = 0; i < realntracks; i++ ) {
-		int tracksize = dumbfile_igetw( f );
-		tracksize += dumbfile_getc( f ) << 16;
-		track[ i ] = malloc( tracksize * 3 + 3 );
-		if ( !track[ i ] ) {
-			goto error_all;
-		}
-		track[ i ][ 0 ] = tracksize & 255;
-		track[ i ][ 1 ] = ( tracksize >> 8 ) & 255;
-		track[ i ][ 2 ] = ( tracksize >> 16 ) & 255;
-        if ( dumbfile_getnc( (char *) track[ i ] + 3, tracksize * 3, f ) != tracksize * 3 ) {
-			goto error_all;
-		}
-	}
-
-	for ( i = 1; i <= maxsampleseekpos; i++ ) {
-		for ( j = 0; j < sigdata->n_samples; j++ ) {
-			if ( sampleseekpos[ j ] == i ) {
-				if ( it_amf_read_sample_data( &sigdata->sample[ j ], f ) ) {
-					goto error_all;
-				}
-				break;
-			}
-		}
-	}
-
-	/* Process tracks into patterns */
-	for ( i = 0; i < sigdata->n_patterns; i++ ) {
-		IT_ENTRY * entry_table = calloc( tracksize[ i ] * nchannels, sizeof( IT_ENTRY ) );
-		if ( !entry_table ) {
-			goto error_all;
-		}
-		for ( j = 0; j < nchannels; j++ ) {
-			int ntrack = orderstotracks[ i * nchannels + j ];
-			if ( ntrack && ntrack <= ntracks ) {
-				int realtrack = trackmap[ ntrack - 1 ];
-				if ( realtrack ) {
-					realtrack--;
-					if ( realtrack < realntracks && track[ realtrack ] ) {
-						it_amf_process_track( entry_table + j, track[ realtrack ], tracksize[ i ], nchannels );
-					}
-				}
-			}
-		}
-		if ( it_amf_process_pattern( &sigdata->pattern[ i ], entry_table, tracksize[ i ], nchannels ) ) {
-			free( entry_table );
-			goto error_all;
-		}
-		free( entry_table );
-	}
-
-	/* Now let's initialise the remaining variables, and we're done! */
-	sigdata->flags = IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_STEREO | IT_WAS_AN_S3M;
-
-	sigdata->global_volume = 128;
-	sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	for ( i = 0; i < realntracks; i++ ) {
-		if ( track[ i ] ) {
-			free( track[ i ] );
-		}
-	}
-	free( track );
-	free( trackmap );
-	free( orderstotracks );
-
-	return sigdata;
-
-error_all:
-	for ( i = 0; i < realntracks; i++ ) {
-		if ( track[ i ] ) {
-			free( track[ i ] );
-		}
-	}
-	free( track );
-error_tm:
-	free( trackmap );
-error_ott:
-	free( orderstotracks );
-	_dumb_it_unload_sigdata( sigdata );
-	return NULL;
-}
-
-
-
-DUH *dumb_read_amf_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	int version;
-
-	sigdata = it_amf_load_sigdata(f, &version);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		char ver_string[14];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		memcpy( ver_string, "DSMI AMF v", 10 );
-		ver_string[10] = '0' + version / 10;
-		ver_string[11] = '.';
-		ver_string[12] = '0' + version % 10;
-		ver_string[13] = 0;
-		tag[1][1] = ver_string;
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readamf2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readamf2.c - Function to read a DSMI AMF module    / / \  \
- *              from an open file and do an initial  | <  /   \_
- *              run-through.                         |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_amf(DUMBFILE *f)
-{
-	DUH *duh = dumb_read_amf_quick(f);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/readany.c
+++ /dev/null
@@ -1,132 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readany.c - Code to detect and read any of the     / / \  \
- *             module formats supported by DUMB.     | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-
-#ifdef _MSC_VER
-	#define strnicmp _strnicmp
-#else
-	#if defined(unix) || defined(__unix__) || defined(__unix)
-		#include <strings.h>
-	#endif
-	#define strnicmp strncasecmp
-#endif
-
-enum { maximum_signature_size = 0x30 };
-
-DUH *dumb_read_any_quick(DUMBFILE *f, int restrict_, int subsong)
-{
-    unsigned char signature[ maximum_signature_size ];
-    unsigned long signature_size;
-    DUH * duh = NULL;
-
-    /* signature_size = dumbfile_get_size(f); */
-
-    signature_size = dumbfile_getnc( (char *)signature, maximum_signature_size, f );
-    dumbfile_seek( f, 0, DFS_SEEK_SET );
-
-    if (signature_size >= 4 &&
-        signature[0] == 'I' && signature[1] == 'M' &&
-        signature[2] == 'P' && signature[3] == 'M')
-    {
-        duh = dumb_read_it_quick( f );
-    }
-    else if (signature_size >= 17 && !memcmp(signature, "Extended Module: ", 17))
-    {
-        duh = dumb_read_xm_quick( f );
-    }
-    else if (signature_size >= 0x30 &&
-        signature[0x2C] == 'S' && signature[0x2D] == 'C' &&
-        signature[0x2E] == 'R' && signature[0x2F] == 'M')
-    {
-        duh = dumb_read_s3m_quick( f );
-    }
-    else if (signature_size >= 30 &&
-        /*signature[28] == 0x1A &&*/ signature[29] == 2 &&
-        ( ! strnicmp( ( const char * ) signature + 20, "!Scream!", 8 ) ||
-        ! strnicmp( ( const char * ) signature + 20, "BMOD2STM", 8 ) ||
-        ! strnicmp( ( const char * ) signature + 20, "WUZAMOD!", 8 ) ) )
-    {
-        duh = dumb_read_stm_quick( f );
-    }
-    else if (signature_size >= 2 &&
-        ((signature[0] == 0x69 && signature[1] == 0x66) ||
-        (signature[0] == 0x4A && signature[1] == 0x4E)))
-    {
-        duh = dumb_read_669_quick( f );
-    }
-    else if (signature_size >= 0x30 &&
-        signature[0x2C] == 'P' && signature[0x2D] == 'T' &&
-        signature[0x2E] == 'M' && signature[0x2F] == 'F')
-    {
-        duh = dumb_read_ptm_quick( f );
-    }
-    else if (signature_size >= 4 &&
-        signature[0] == 'P' && signature[1] == 'S' &&
-        signature[2] == 'M' && signature[3] == ' ')
-    {
-        duh = dumb_read_psm_quick( f, subsong );
-    }
-    else if (signature_size >= 4 &&
-        signature[0] == 'P' && signature[1] == 'S' &&
-        signature[2] == 'M' && signature[3] == 254)
-    {
-        duh = dumb_read_old_psm_quick( f );
-    }
-    else if (signature_size >= 3 &&
-        signature[0] == 'M' && signature[1] == 'T' &&
-        signature[2] == 'M')
-    {
-        duh = dumb_read_mtm_quick( f );
-    }
-    else if ( signature_size >= 4 &&
-        signature[0] == 'R' && signature[1] == 'I' &&
-        signature[2] == 'F' && signature[3] == 'F')
-    {
-        duh = dumb_read_riff_quick( f );
-    }
-    else if ( signature_size >= 24 &&
-        !memcmp( signature, "ASYLUM Music Format", 19 ) &&
-        !memcmp( signature + 19, " V1.0", 5 ) )
-    {
-        duh = dumb_read_asy_quick( f );
-    }
-    else if ( signature_size >= 3 &&
-        signature[0] == 'A' && signature[1] == 'M' &&
-        signature[2] == 'F')
-    {
-        duh = dumb_read_amf_quick( f );
-    }
-    else if ( signature_size >= 8 &&
-        !memcmp( signature, "OKTASONG", 8 ) )
-    {
-        duh = dumb_read_okt_quick( f );
-    }
-
-    if ( !duh )
-    {
-        dumbfile_seek( f, 0, DFS_SEEK_SET );
-        duh = dumb_read_mod_quick( f, restrict_ );
-    }
-
-    return duh;
-}
--- a/dumb/src/it/readany2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readany2.c - Code to detect and read any of the    / / \  \
- *              module formats supported by DUMB     | <  /   \_
- *              from an open file and do an initial  |  \/ /\   /
- *              run-through.                          \_  /  > /
- *                                                      | \ / /
- * by Chris Moeller.                                    |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_any(DUMBFILE *f, int restrict_, int subsong)
-{
-    DUH *duh = dumb_read_any_quick(f, restrict_, subsong);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/readasy.c
+++ /dev/null
@@ -1,339 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readasy.c - Code to read an ASYLUM Music Format    / / \  \
- *             module from an open file.             | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-static int it_asy_read_pattern( IT_PATTERN *pattern, DUMBFILE *f, unsigned char *buffer )
-{
-	int pos;
-	int channel;
-	int row;
-	IT_ENTRY *entry;
-
-	pattern->n_rows = 64;
-
-    if ( dumbfile_getnc( (char *) buffer, 64 * 8 * 4, f ) != 64 * 8 * 4 )
-		return -1;
-
-	/* compute number of entries */
-	pattern->n_entries = 64; /* Account for the row end markers */
-	pos = 0;
-	for ( row = 0; row < 64; ++row ) {
-		for ( channel = 0; channel < 8; ++channel ) {
-			if ( buffer[ pos + 0 ] | buffer[ pos + 1 ] | buffer[ pos + 2 ] | buffer[ pos + 3 ] )
-				++pattern->n_entries;
-			pos += 4;
-		}
-	}
-
-	pattern->entry = malloc( pattern->n_entries * sizeof( *pattern->entry ) );
-	if ( !pattern->entry )
-		return -1;
-
-	entry = pattern->entry;
-	pos = 0;
-	for ( row = 0; row < 64; ++row ) {
-		for ( channel = 0; channel < 8; ++channel ) {
-			if ( buffer[ pos + 0 ] | buffer[ pos + 1 ] | buffer[ pos + 2 ] | buffer[ pos + 3 ] ) {
-				entry->channel = channel;
-				entry->mask = 0;
-
-				if ( buffer[ pos + 0 ] && buffer[ pos + 0 ] < 96 ) {
-					entry->note = buffer[ pos + 0 ];
-					entry->mask |= IT_ENTRY_NOTE;
-				}
-
-				if ( buffer[ pos + 1 ] && buffer[ pos + 1 ] <= 64 ) {
-					entry->instrument = buffer[ pos + 1 ];
-					entry->mask |= IT_ENTRY_INSTRUMENT;
-				}
-
-				_dumb_it_xm_convert_effect( buffer[ pos + 2 ], buffer[ pos + 3 ], entry, 1 );
-                
-                // fixup
-                switch ( entry->effect ) {
-                    case IT_SET_PANNING:
-                        entry->effectvalue <<= 1;
-                        break;
-                }
-
-				if ( entry->mask ) ++entry;
-			}
-			pos += 4;
-		}
-		IT_SET_END_ROW( entry );
-		++entry;
-	}
-
-	pattern->n_entries = entry - pattern->entry;
-
-	return 0;
-}
-
-
-
-static int it_asy_read_sample_header( IT_SAMPLE *sample, DUMBFILE *f )
-{
-	int finetune, key_offset;
-
-/**
-     21       22   Chars     Sample 1 name.  If the name is not a full
-                             22 chars in length, it will be null
-                             terminated.
-
-If
-the sample name begins with a '#' character (ASCII $23 (35)) then this is
-assumed not to be an instrument name, and is probably a message.
-*/
-    dumbfile_getnc( (char *) sample->name, 22, f );
-	sample->name[22] = 0;
-
-	sample->filename[0] = 0;
-
-/** Each  finetune step changes  the note 1/8th  of  a  semitone. */
-	finetune = ( signed char ) ( dumbfile_getc( f ) << 4 ) >> 4; /* signed nibble */
-	sample->default_volume = dumbfile_getc( f ); // Should we be setting global_volume to this instead?
-	sample->global_volume = 64;
-	if ( sample->default_volume > 64 ) sample->default_volume = 64;
-	key_offset = ( signed char ) dumbfile_getc( f ); /* base key offset */
-	sample->length = dumbfile_igetl( f );
-	sample->loop_start = dumbfile_igetl( f );
-	sample->loop_end = sample->loop_start + dumbfile_igetl( f );
-
-	if ( sample->length <= 0 ) {
-		sample->flags = 0;
-		return 0;
-	}
-
-	sample->flags = IT_SAMPLE_EXISTS;
-
-	sample->default_pan = 0;
-	sample->C5_speed = (int)( AMIGA_CLOCK / 214.0 * pow( DUMB_SEMITONE_BASE, key_offset ) );//( long )( 16726.0 * pow( DUMB_PITCH_BASE, finetune * 32 ) );
-	sample->finetune = finetune * 32;
-	// the above line might be wrong
-
-	if ( ( sample->loop_end - sample->loop_start > 2 ) && ( sample->loop_end <= sample->length ) )
-		sample->flags |= IT_SAMPLE_LOOP;
-
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = 0; // do we have to set _all_ these?
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-
-
-static int it_asy_read_sample_data( IT_SAMPLE *sample, DUMBFILE *f )
-{
-	long truncated_size;
-
-	/* let's get rid of the sample data coming after the end of the loop */
-	if ( ( sample->flags & IT_SAMPLE_LOOP ) && sample->loop_end < sample->length ) {
-		truncated_size = sample->length - sample->loop_end;
-		sample->length = sample->loop_end;
-	} else {
-		truncated_size = 0;
-	}
-
-	sample->data = malloc( sample->length );
-
-	if ( !sample->data )
-		return -1;
-
-	if ( sample->length )
-		dumbfile_getnc( sample->data, sample->length, f );
-
-	dumbfile_skip( f, truncated_size );
-
-	return dumbfile_error( f );
-}
-
-
-
-static DUMB_IT_SIGDATA *it_asy_load_sigdata(DUMBFILE *f)
-{
-	DUMB_IT_SIGDATA *sigdata;
-	int i;
-
-	static const char sig_part[] = "ASYLUM Music Format";
-	static const char sig_rest[] = " V1.0"; /* whee, string space optimization with format type below */
-
-	char signature [32];
-
-	if ( dumbfile_getnc( signature, 32, f ) != 32 ||
-		memcmp( signature, sig_part, 19 ) ||
-		memcmp( signature + 19, sig_rest, 5 ) ) {
-		return NULL;
-	}
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) {
-		return NULL;
-	}
-
-	sigdata->speed = dumbfile_getc( f ); /* XXX seems to fit the files I have */
-	sigdata->tempo = dumbfile_getc( f ); /* ditto */
-	sigdata->n_samples = dumbfile_getc( f ); /* ditto */
-	sigdata->n_patterns = dumbfile_getc( f );
-	sigdata->n_orders = dumbfile_getc( f );
-	sigdata->restart_position = dumbfile_getc( f );
-
-	if ( dumbfile_error( f ) || !sigdata->n_samples || sigdata->n_samples > 64 || !sigdata->n_patterns ||
-		!sigdata->n_orders ) {
-		free( sigdata );
-		return NULL;
-	}
-
-	if ( sigdata->restart_position > sigdata->n_orders ) /* XXX */
-		sigdata->restart_position = 0;
-
-	sigdata->order = malloc( sigdata->n_orders );
-	if ( !sigdata->order ) {
-		free( sigdata );
-		return NULL;
-	}
-
-    if ( dumbfile_getnc( (char *) sigdata->order, sigdata->n_orders, f ) != sigdata->n_orders ||
-		dumbfile_skip( f, 256 - sigdata->n_orders ) ) {
-		free( sigdata->order );
-		free( sigdata );
-		return NULL;
-	}
-
-	sigdata->sample = malloc( sigdata->n_samples * sizeof( *sigdata->sample ) );
-	if ( !sigdata->sample ) {
-		free( sigdata->order );
-		free( sigdata );
-		return NULL;
-	}
-
-	sigdata->song_message = NULL;
-	sigdata->instrument = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-
-	for ( i = 0; i < sigdata->n_samples; ++i )
-		sigdata->sample[i].data = NULL;
-
-	for ( i = 0; i < sigdata->n_samples; ++i ) {
-		if ( it_asy_read_sample_header( &sigdata->sample[i], f ) ) {
-			_dumb_it_unload_sigdata( sigdata );
-			return NULL;
-		}
-	}
-
-	if ( dumbfile_skip( f, 37 * ( 64 - sigdata->n_samples ) ) ) {
-		_dumb_it_unload_sigdata( sigdata );
-		return NULL;
-	}
-
-	sigdata->pattern = malloc( sigdata->n_patterns * sizeof( *sigdata->pattern ) );
-	if ( !sigdata->pattern ) {
-		_dumb_it_unload_sigdata( sigdata );
-		return NULL;
-	}
-	for (i = 0; i < sigdata->n_patterns; ++i)
-		sigdata->pattern[i].entry = NULL;
-
-	/* Read in the patterns */
-	{
-		unsigned char *buffer = malloc( 64 * 8 * 4 ); /* 64 rows * 8 channels * 4 bytes */
-		if ( !buffer ) {
-			_dumb_it_unload_sigdata( sigdata );
-			return NULL;
-		}
-		for ( i = 0; i < sigdata->n_patterns; ++i ) {
-			if ( it_asy_read_pattern( &sigdata->pattern[i], f, buffer ) != 0 ) {
-				free( buffer );
-				_dumb_it_unload_sigdata( sigdata );
-				return NULL;
-			}
-		}
-		free( buffer );
-	}
-
-	/* And finally, the sample data */
-	for ( i = 0; i < sigdata->n_samples; ++i ) {
-		if ( it_asy_read_sample_data( &sigdata->sample[i], f ) ) {
-			_dumb_it_unload_sigdata( sigdata );
-			return NULL;
-		}
-	}
-
-	/* Now let's initialise the remaining variables, and we're done! */
-	sigdata->flags = IT_WAS_AN_XM | IT_WAS_A_MOD | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_STEREO;
-
-	sigdata->global_volume = 128;
-	sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	sigdata->n_pchannels = 8;
-
-	sigdata->name[0] = 0;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[i+0] = 32 - sep;
-		sigdata->channel_pan[i+1] = 32 + sep;
-		sigdata->channel_pan[i+2] = 32 + sep;
-		sigdata->channel_pan[i+3] = 32 - sep;
-	}
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-
-
-DUH *dumb_read_asy_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_asy_load_sigdata(f);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "ASYLUM Music Format";
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readdsmf.c
+++ /dev/null
@@ -1,383 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readam.c - Code to read a RIFF DSMF module         / / \  \
- *             from a parsed RIFF structure.         | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-#include "internal/riff.h"
-
-static int it_riff_dsmf_process_sample( IT_SAMPLE * sample, DUMBFILE * f, int len )
-{
-	int flags;
-
-    dumbfile_getnc( (char *) sample->filename, 13, f );
-	sample->filename[ 14 ] = 0;
-	
-    flags = dumbfile_igetw( f );
-    sample->default_volume = dumbfile_getc( f );
-    sample->length = dumbfile_igetl( f );
-    sample->loop_start = dumbfile_igetl( f );
-    sample->loop_end = dumbfile_igetl( f );
-    dumbfile_skip( f, 32 - 28 );
-    sample->C5_speed = dumbfile_igetw( f ) * 2;
-    dumbfile_skip( f, 36 - 34 );
-    dumbfile_getnc( (char *) sample->name, 28, f );
-	sample->name[ 28 ] = 0;
-
-	/*if ( data[ 0x38 ] || data[ 0x39 ] || data[ 0x3A ] || data[ 0x3B ] )
-		return -1;*/
-
-	if ( ! sample->length ) {
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-		return 0;
-	}
-
-	/*if ( flags & ~( 2 | 1 ) )
-		return -1;*/
-
-	if ( sample->length + 64 > len )
-		return -1;
-
-	sample->flags = IT_SAMPLE_EXISTS;
-
-	sample->default_pan = 0;
-	sample->global_volume = 64;
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = IT_VIBRATO_SINE;
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	if ( flags & 1 )
-	{
-		if (((unsigned int)sample->loop_end <= (unsigned int)sample->length) &&
-			((unsigned int)sample->loop_start < (unsigned int)sample->loop_end))
-		{
-			sample->length = sample->loop_end;
-			sample->flags |= IT_SAMPLE_LOOP;
-			if ( flags & 0x10 ) sample->flags |= IT_SAMPLE_PINGPONG_LOOP;
-		}
-	}
-
-	sample->data = malloc( sample->length );
-	if ( ! sample->data )
-		return -1;
-
-    dumbfile_getnc( sample->data, sample->length, f );
-
-	if ( ! ( flags & 2 ) )
-	{
-		for ( flags = 0; flags < sample->length; ++flags )
-			( ( signed char * ) sample->data ) [ flags ] ^= 0x80;
-	}
-
-	return 0;
-}
-
-static int it_riff_dsmf_process_pattern( IT_PATTERN * pattern, DUMBFILE * f, int len )
-{
-    int length, row;
-	unsigned flags;
-    long start, end;
-    int p, q, r;
-	IT_ENTRY * entry;
-
-    length = dumbfile_igetw( f );
-	if ( length > len ) return -1;
-
-	len = length - 2;
-
-	pattern->n_rows = 64;
-	pattern->n_entries = 64;
-
-	row = 0;
-
-    start = dumbfile_pos( f );
-    end = start + len;
-
-    while ( (row < 64) && !dumbfile_error( f ) && (dumbfile_pos( f ) < end) ) {
-        p = dumbfile_getc( f );
-        if ( ! p ) {
-			++ row;
-			continue;
-		}
-
-        flags = p & 0xF0;
-
-		if (flags) {
-			++ pattern->n_entries;
-            if (flags & 0x80) dumbfile_skip( f, 1 );
-            if (flags & 0x40) dumbfile_skip( f, 1 );
-            if (flags & 0x20) dumbfile_skip( f, 1 );
-            if (flags & 0x10) dumbfile_skip( f, 2 );
-		}
-	}
-
-	if ( pattern->n_entries == 64 ) return 0;
-
-	pattern->entry = malloc( pattern->n_entries * sizeof( * pattern->entry ) );
-	if ( ! pattern->entry ) return -1;
-
-	entry = pattern->entry;
-
-	row = 0;
-
-    if ( dumbfile_seek( f, start, DFS_SEEK_SET ) ) return -1;
-
-    while ( ( row < 64 ) && !dumbfile_error( f ) && ( dumbfile_pos( f ) < end ) )
-	{
-        p = dumbfile_getc( f );
-        if ( ! p )
-		{
-			IT_SET_END_ROW( entry );
-			++ entry;
-			++ row;
-			continue;
-		}
-
-        flags = p;
-		entry->channel = flags & 0x0F;
-		entry->mask = 0;
-
-		if ( flags & 0xF0 )
-		{
-			if ( flags & 0x80 )
-			{
-                q = dumbfile_getc( f );
-                if ( q )
-				{
-					entry->mask |= IT_ENTRY_NOTE;
-                    entry->note = q - 1;
-				}
-			}
-
-			if ( flags & 0x40 )
-			{
-                q = dumbfile_getc( f );
-                if ( q )
-				{
-					entry->mask |= IT_ENTRY_INSTRUMENT;
-                    entry->instrument = q;
-				}
-			}
-
-			if ( flags & 0x20 )
-			{
-				entry->mask |= IT_ENTRY_VOLPAN;
-                entry->volpan = dumbfile_getc( f );
-			}
-
-			if ( flags & 0x10 )
-			{
-                q = dumbfile_getc( f );
-                r = dumbfile_getc( f );
-                _dumb_it_xm_convert_effect( q, r, entry, 0 );
-			}
-
-			if (entry->mask) entry++;
-		}
-	}
-
-	while ( row < 64 )
-	{
-		IT_SET_END_ROW( entry );
-		++ entry;
-		++ row;
-	}
-
-	pattern->n_entries = entry - pattern->entry;
-	if ( ! pattern->n_entries ) return -1;
-
-	return 0;
-}
-
-static DUMB_IT_SIGDATA *it_riff_dsmf_load_sigdata( DUMBFILE * f, struct riff * stream )
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	int n, o, found;
-
-	if ( ! stream ) goto error;
-
-	if ( stream->type != DUMB_ID( 'D', 'S', 'M', 'F' ) ) goto error;
-
-	sigdata = malloc(sizeof(*sigdata));
-	if ( ! sigdata ) goto error;
-
-	sigdata->n_patterns = 0;
-	sigdata->n_samples = 0;
-	sigdata->name[0] = 0;
-
-	found = 0;
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch( c->type )
-		{
-		case DUMB_ID( 'S' ,'O' ,'N' ,'G' ):
-			/* initialization data */
-			if ( ( found ) || ( c->size < 192 ) ) goto error_sd;
-			found = 1;
-			break;
-
-		case DUMB_ID( 'P', 'A', 'T', 'T' ):
-			++ sigdata->n_patterns;
-			break;
-
-		case DUMB_ID( 'I', 'N', 'S', 'T' ):
-			++ sigdata->n_samples;
-			break;
-		}
-	}
-
-	if ( !found || !sigdata->n_samples || !sigdata->n_patterns ) goto error_sd;
-
-	if ( sigdata->n_samples > 255 || sigdata->n_patterns > 255 ) goto error_sd;
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	sigdata->n_instruments = 0;
-	sigdata->n_orders = 0;
-	sigdata->restart_position = 0;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[n  ] = 32 - sep;
-		sigdata->channel_pan[n+1] = 32 + sep;
-		sigdata->channel_pan[n+2] = 32 + sep;
-		sigdata->channel_pan[n+3] = 32 - sep;
-	}
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch ( c->type )
-		{
-		case DUMB_ID( 'S', 'O', 'N', 'G' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            dumbfile_getnc( (char *) sigdata->name, 28, f );
-			sigdata->name[ 28 ] = 0;
-			sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX;
-            dumbfile_skip( f, 36 - 28 );
-            sigdata->n_orders = dumbfile_igetw( f );
-			//sigdata->n_samples = ptr[ 38 ] | ( ptr[ 39 ] << 8 ); // whatever
-			//sigdata->n_patterns = ptr[ 40 ] | ( ptr[ 41 ] << 8 );
-            dumbfile_skip( f, 42 - 38 );
-            sigdata->n_pchannels = dumbfile_igetw( f );
-            sigdata->global_volume = dumbfile_getc( f );
-            sigdata->mixing_volume = dumbfile_getc( f );
-            sigdata->speed = dumbfile_getc( f );
-            sigdata->tempo = dumbfile_getc( f );
-
-			for ( o = 0; o < 16; ++o )
-			{
-                sigdata->channel_pan[ o ] = dumbfile_getc( f ) / 2;
-			}
-
-			sigdata->order = malloc( 128 );
-			if ( ! sigdata->order ) goto error_usd;
-            dumbfile_getnc( (char *) sigdata->order, 128, f );
-
-			break;
-		}
-	}
-
-	sigdata->pattern = malloc( sigdata->n_patterns * sizeof( *sigdata->pattern ) );
-	if ( ! sigdata->pattern ) goto error_usd;
-	for ( n = 0; n < sigdata->n_patterns; ++n )
-		sigdata->pattern[ n ].entry = NULL;
-
-	sigdata->sample = malloc( sigdata->n_samples * sizeof( *sigdata->sample ) );
-	if ( ! sigdata->sample ) goto error_usd;
-	for ( n = 0; n < sigdata->n_samples; ++n )
-	{
-		IT_SAMPLE * sample = sigdata->sample + n;
-		sample->data = NULL;
-	}
-
-	sigdata->n_samples = 0;
-	sigdata->n_patterns = 0;
-
-    for ( n = 0; (unsigned)n < stream->chunk_count; ++n )
-	{
-		struct riff_chunk * c = stream->chunks + n;
-		switch ( c->type )
-		{
-		case DUMB_ID( 'P', 'A', 'T', 'T' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            if ( it_riff_dsmf_process_pattern( sigdata->pattern + sigdata->n_patterns, f, c->size ) ) goto error_usd;
-			++ sigdata->n_patterns;
-			break;
-
-		case DUMB_ID( 'I', 'N', 'S', 'T' ):
-            if ( dumbfile_seek( f, c->offset, DFS_SEEK_SET ) ) goto error_usd;
-            if ( it_riff_dsmf_process_sample( sigdata->sample + sigdata->n_samples, f, c->size ) ) goto error_usd;
-			++ sigdata->n_samples;
-			break;
-		}
-	}
-
-	_dumb_it_fix_invalid_orders( sigdata );
-
-	return sigdata;
-
-error_usd:
-	_dumb_it_unload_sigdata( sigdata );
-	goto error;
-error_sd:
-	free( sigdata );
-error:
-	return NULL;
-}
-
-DUH *dumb_read_riff_dsmf( DUMBFILE * f, struct riff * stream )
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-    sigdata = it_riff_dsmf_load_sigdata( f, stream );
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "RIFF DSMF";
-		return make_duh( -1, 2, ( const char * const (*) [ 2 ] ) tag, 1, & descptr, & sigdata );
-	}
-}
--- a/dumb/src/it/readmod.c
+++ /dev/null
@@ -1,637 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readmod.c - Code to read a good old-fashioned      / / \  \
- *             Amiga module from an open file.       | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-static int it_mod_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, int n_channels, unsigned char *buffer)
-{
-	int pos;
-	int channel;
-	int row;
-	IT_ENTRY *entry;
-
-	pattern->n_rows = 64;
-
-	if (n_channels == 0) {
-		/* Read the first four channels, leaving gaps for the rest. */
-		for (pos = 0; pos < 64*8*4; pos += 8*4)
-            dumbfile_getnc((char *)buffer + pos, 4*4, f);
-		/* Read the other channels into the gaps we left. */
-		for (pos = 4*4; pos < 64*8*4; pos += 8*4)
-            dumbfile_getnc((char *)buffer + pos, 4*4, f);
-
-		n_channels = 8;
-	} else
-        dumbfile_getnc((char *)buffer, 64 * n_channels * 4, f);
-
-	if (dumbfile_error(f))
-		return -1;
-
-	/* compute number of entries */
-	pattern->n_entries = 64; /* Account for the row end markers */
-	pos = 0;
-	for (row = 0; row < 64; row++) {
-		for (channel = 0; channel < n_channels; channel++) {
-			if (buffer[pos+0] | buffer[pos+1] | buffer[pos+2] | buffer[pos+3])
-				pattern->n_entries++;
-			pos += 4;
-		}
-	}
-
-	pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
-	if (!pattern->entry)
-		return -1;
-
-	entry = pattern->entry;
-	pos = 0;
-	for (row = 0; row < 64; row++) {
-		for (channel = 0; channel < n_channels; channel++) {
-			if (buffer[pos+0] | buffer[pos+1] | buffer[pos+2] | buffer[pos+3]) {
-				unsigned char sample = (buffer[pos+0] & 0xF0) | (buffer[pos+2] >> 4);
-				int period = ((int)(buffer[pos+0] & 0x0F) << 8) | buffer[pos+1];
-
-				entry->channel = channel;
-				entry->mask = 0;
-
-				if (period) {
-					int note;
-					entry->mask |= IT_ENTRY_NOTE;
-
-					/* frequency = (AMIGA_DIVISOR / 8) / (period * 2)
-					 * C-1: period = 214 -> frequency = 16726
-					 * so, set C5_speed to 16726
-					 * and period = 214 should translate to C5 aka 60
-					 * halve the period, go up an octive
-					 *
-					 * period = 214 / pow(DUMB_SEMITONE_BASE, note - 60)
-					 * pow(DUMB_SEMITONE_BASE, note - 60) = 214 / period
-					 * note - 60 = log(214/period) / log(DUMB_SEMITONE_BASE)
-					 */
-					note = (int)floor(log(214.0/period) / log(DUMB_SEMITONE_BASE) + 60.5);
-					entry->note = MID(0, note, 119);
-					// or should we preserve the period?
-					//entry->note = buffer[pos+0] & 0x0F; /* High nibble */
-					//entry->volpan = buffer[pos+1]; /* Low byte */
-					// and what about finetune?
-				}
-
-				if (sample) {
-					entry->mask |= IT_ENTRY_INSTRUMENT;
-					entry->instrument = sample;
-				}
-
-				_dumb_it_xm_convert_effect(buffer[pos+2] & 0x0F, buffer[pos+3], entry, 1);
-
-				entry++;
-			}
-			pos += 4;
-		}
-		IT_SET_END_ROW(entry);
-		entry++;
-	}
-
-	return 0;
-}
-
-
-
-static int it_mod_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f, unsigned long fft, int stk)
-{
-	int finetune, loop_start, loop_length;
-
-/**
-     21       22   Chars     Sample 1 name.  If the name is not a full
-                             22 chars in length, it will be null
-                             terminated.
-
-If
-the sample name begins with a '#' character (ASCII $23 (35)) then this is
-assumed not to be an instrument name, and is probably a message.
-*/
-    dumbfile_getnc((char *)sample->name, 22, f);
-	sample->name[22] = 0;
-
-	sample->filename[0] = 0;
-
-	sample->length = dumbfile_mgetw(f) << 1;
-	if (fft == DUMB_ID('F','E','S','T'))
-		finetune = (signed char)((-dumbfile_getc(f) & 0x1F) << 3) >> 3;
-	else
-		finetune = (signed char)(dumbfile_getc(f) << 4) >> 4; /* signed nibble */
-/** Each  finetune step changes  the note 1/8th  of  a  semitone. */
-	sample->global_volume = 64;
-	sample->default_volume = dumbfile_getc(f); // Should we be setting global_volume to this instead?
-	loop_start = dumbfile_mgetw(f);
-	if ( !stk ) loop_start <<= 1;
-	loop_length = dumbfile_mgetw(f) << 1;
-	if ( loop_length > 2 && loop_start + loop_length > sample->length && loop_start / 2 + loop_length <= sample->length )
-		loop_start /= 2;
-	sample->loop_start = loop_start;
-	sample->loop_end = loop_start + loop_length;
-/**
-Once this sample has been played completely from beginning
-to end, if the  repeat length (next field)  is greater than two  bytes it
-will loop back to this position in the sample and continue playing.  Once
-it has played for  the repeat length,  it continues to  loop back to  the
-repeat start offset.  This means the sample continues playing until it is
-told to stop.
-*/
-
-	if (sample->length <= 0) {
-		sample->flags = 0;
-		return 0;
-	}
-
-	sample->flags = IT_SAMPLE_EXISTS;
-
-	sample->default_pan = 0;
-	sample->C5_speed = (int)( AMIGA_CLOCK / 214.0 ); //(long)(16726.0*pow(DUMB_PITCH_BASE, finetune*32));
-	sample->finetune = finetune * ((fft == DUMB_ID('F','E','S','T')) ? 16 : 32);
-	// the above line might be wrong
-
-	if (sample->loop_end > sample->length)
-		sample->loop_end = sample->length;
-
-	if (sample->loop_end - sample->loop_start > 2)
-		sample->flags |= IT_SAMPLE_LOOP;
-
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = 0; // do we have to set _all_ these?
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-
-
-static int it_mod_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f, unsigned long fft)
-{
-	long i;
-	long truncated_size;
-
-	/* let's get rid of the sample data coming after the end of the loop */
-	if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length) {
-		truncated_size = sample->length - sample->loop_end;
-		sample->length = sample->loop_end;
-	} else {
-		truncated_size = 0;
-	}
-
-	if (sample->length) {
-		sample->data = malloc(sample->length);
-
-		if (!sample->data)
-			return -1;
-
-		/* Sample data are stored in "8-bit two's compliment format" (sic). */
-		/*
-		for (i = 0; i < sample->length; i++)
-			((signed char *)sample->left)[i] = dumbfile_getc(f);
-		*/
-		/* F U Olivier Lapicque */
-		if (sample->length >= 5)
-		{
-			i = dumbfile_getnc(sample->data, 5, f);
-			if (i == 5)
-			{
-				if (!memcmp(sample->data, "ADPCM", 5))
-				{
-					if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
-						return -1;
-
-					return 0;
-				}
-				else
-				{
-					i += dumbfile_getnc(((char *)sample->data) + 5, sample->length - 5, f);
-				}
-			}
-		}
-		else
-		{
-			i = dumbfile_getnc(sample->data, sample->length, f);
-		}
-		if (i < sample->length)
-		{
-			if (i <= 0)
-			{
-				sample->flags = 0;
-				return 0;
-			}
-			sample->length = i;
-			if (sample->loop_end > i) sample->loop_end = i;
-			// holy crap!
-			if (sample->loop_start > i) sample->flags &= ~IT_SAMPLE_LOOP;
-		}
-		else
-		{
-			/* skip truncated data */
-			int feh = dumbfile_error(f);
-
-			if (truncated_size) dumbfile_skip(f, truncated_size);
-			// Should we be truncating it?
-
-			if (feh)
-				return -1;
-		}
-
-		if (fft == DUMB_ID('M',0,0,0) || fft == DUMB_ID('8',0,0,0)) {
-			int delta = 0;
-			for (i = 0; i < sample->length; i++) {
-				delta += ((signed char *)sample->data)[i];
-				((signed char *)sample->data)[i] = delta;
-			}
-		}
-	}
-
-	return 0;
-}
-
-
-
-#define MOD_FFT_OFFSET (20 + 31*(22+2+1+1+2+2) + 1 + 1 + 128)
-
-static DUMB_IT_SIGDATA *it_mod_load_sigdata(DUMBFILE *f, int restrict_)
-{
-	DUMB_IT_SIGDATA *sigdata;
-	int n_channels;
-	int i;
-	unsigned long fft;
-
-    if ( dumbfile_seek(f, MOD_FFT_OFFSET, DFS_SEEK_SET) )
-        return NULL;
-
-    fft = dumbfile_mgetl(f);
-    if (dumbfile_error(f))
-        return NULL;
-
-    if ( dumbfile_seek(f, 0, DFS_SEEK_SET) )
-        return NULL;
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) {
-		return NULL;
-	}
-
-	/**
-      1       20   Chars     Title of the song.  If the title is not a
-                             full 20 chars in length, it will be null-
-                             terminated.
-	*/
-    if (dumbfile_getnc((char *)sigdata->name, 20, f) < 20) {
-		free(sigdata);
-        return NULL;
-	}
-	sigdata->name[20] = 0;
-
-	sigdata->n_samples = 31;
-
-	switch (fft) {
-		case DUMB_ID('M','.','K','.'):
-		case DUMB_ID('M','!','K','!'):
-		case DUMB_ID('M','&','K','!'):
-		case DUMB_ID('N','.','T','.'):
-		case DUMB_ID('N','S','M','S'):
-		case DUMB_ID('F','L','T','4'):
-		case DUMB_ID('M',0,0,0):
-		case DUMB_ID('8',0,0,0):
-		case DUMB_ID('F','E','S','T'):
-			n_channels = 4;
-			break;
-		case DUMB_ID('F','L','T','8'):
-			n_channels = 0;
-			/* 0 indicates a special case; two four-channel patterns must be
-			 * combined into one eight-channel pattern. Pattern indexes must
-			 * be halved. Why oh why do they obfuscate so?
-			 */
-			/*for (i = 0; i < 128; i++)
-				sigdata->order[i] >>= 1;*/
-			break;
-		case DUMB_ID('C','D','8','1'):
-		case DUMB_ID('O','C','T','A'):
-		case DUMB_ID('O','K','T','A'):
-			n_channels = 8;
-			break;
-		case DUMB_ID('1','6','C','N'):
-			n_channels = 16;
-			break;
-		case DUMB_ID('3','2','C','N'):
-			n_channels = 32;
-			break;
-		default:
-			/* If we get an illegal tag, assume 4 channels 15 samples. */
-			if ((fft & 0x0000FFFFL) == DUMB_ID(0,0,'C','H')) {
-				if (fft >= '1' << 24 && fft < '4' << 24) {
-					n_channels = ((fft & 0x00FF0000L) >> 16) - '0';
-					if ((unsigned int)n_channels >= 10) {
-						/* Rightmost character wasn't a digit. */
-						n_channels = 4;
-						sigdata->n_samples = 15;
-					} else {
-						n_channels += (((fft & 0xFF000000L) >> 24) - '0') * 10;
-						/* MODs should really only go up to 32 channels, but we're lenient. */
-						if ((unsigned int)(n_channels - 1) >= DUMB_IT_N_CHANNELS - 1) {
-							/* No channels or too many? Can't be right... */
-							n_channels = 4;
-							sigdata->n_samples = 15;
-						}
-					}
-				} else {
-					n_channels = 4;
-					sigdata->n_samples = 15;
-				}
-			} else if ((fft & 0x00FFFFFFL) == DUMB_ID(0,'C','H','N')) {
-				n_channels = (fft >> 24) - '0';
-				if ((unsigned int)(n_channels - 1) >= 9) {
-					/* Character was '0' or it wasn't a digit */
-					n_channels = 4;
-					sigdata->n_samples = 15;
-				}
-			} else if ((fft & 0xFFFFFF00L) == DUMB_ID('T','D','Z',0)) {
-				n_channels = (fft & 0x000000FFL) - '0';
-				if ((unsigned int)(n_channels - 1) >= 9) {
-					/* We've been very lenient, given that it should have
-					 * been 1, 2 or 3, but this MOD has been very naughty and
-					 * must be punished.
-					 */
-					n_channels = 4;
-					sigdata->n_samples = 15;
-				}
-			} else {
-				n_channels = 4;
-				sigdata->n_samples = 15;
-				fft = 0;
-			}
-	}
-
-	// moo
-	if ( ( restrict_ & 1 ) && sigdata->n_samples == 15 )
-	{
-		free(sigdata);
-        return NULL;
-	}
-
-	sigdata->n_pchannels = n_channels ? n_channels : 8; /* special case for 0, see above */
-
-	sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-	if (!sigdata->sample) {
-		free(sigdata);
-        return NULL;
-	}
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-
-	for (i = 0; i < sigdata->n_samples; i++)
-		sigdata->sample[i].data = NULL;
-
-	for (i = 0; i < sigdata->n_samples; i++) {
-		if (it_mod_read_sample_header(&sigdata->sample[i], f, fft, sigdata->n_samples == 15)) {
-			_dumb_it_unload_sigdata(sigdata);
-            return NULL;
-		}
-	}
-
-	sigdata->n_orders = dumbfile_getc(f);
-	sigdata->restart_position = dumbfile_getc(f);
-	// what if this is >= 127? what about with Fast Tracker II?
-
-/*	if (sigdata->n_orders <= 0 || sigdata->n_orders > 128) { // is this right?
-		_dumb_it_unload_sigdata(sigdata);
-        return NULL;
-	}*/
-
-	//if (sigdata->restart_position >= sigdata->n_orders)
-		//sigdata->restart_position = 0;
-
-	sigdata->order = malloc(128); /* We may need to scan the extra ones! */
-	if (!sigdata->order) {
-		_dumb_it_unload_sigdata(sigdata);
-        return NULL;
-	}
-    if (dumbfile_getnc((char *)sigdata->order, 128, f) < 128) {
-		_dumb_it_unload_sigdata(sigdata);
-        return NULL;
-	}
-
-	if (sigdata->n_orders <= 0 || sigdata->n_orders > 128) { // is this right?
-		sigdata->n_orders = 128;
-		//while (sigdata->n_orders > 1 && !sigdata->order[sigdata->n_orders - 1]) sigdata->n_orders--;
-	}
-
-	if ( ! n_channels )
-		for (i = 0; i < 128; i++)
-			sigdata->order[i] >>= 1;
-
-	/* "The old NST format contains only 15 samples (instead of 31). Further
-	 * it doesn't contain a file format tag (id). So Pattern data offset is
-	 * at 20+15*30+1+1+128."
-	 * - Then I shall assume the File Format Tag never exists if there are
-	 * only 15 samples. I hope this isn't a faulty assumption...
-	 */
-	if (sigdata->n_samples == 31)
-		dumbfile_skip(f, 4);
-
-	sigdata->n_patterns = -1;
-
-    if ( ( restrict_ & 2 ) )
-	{
-        unsigned char buffer[5];
-        long sample_number;
-        long total_sample_size;
-        long offset = dumbfile_pos(f);
-        long remain = dumbfile_get_size(f) - offset;
-        if ( dumbfile_error( f ) ||
-             dumbfile_seek( f, 0, SEEK_END ) ) {
-            _dumb_it_unload_sigdata(sigdata);
-            return NULL;
-        }
-        sample_number = sigdata->n_samples - 1;
-        total_sample_size = 0;
-        while (dumbfile_pos(f) > offset && sample_number >= 0) {
-            if (sigdata->sample[sample_number].flags & IT_SAMPLE_EXISTS) {
-                if ( dumbfile_seek(f, -((sigdata->sample[sample_number].length + 1) / 2 + 5 + 16), DFS_SEEK_CUR) ||
-                     dumbfile_getnc((char *)buffer, 5, f) < 5 ) {
-                    _dumb_it_unload_sigdata(sigdata);
-                    return NULL;
-                }
-                if ( !memcmp( buffer, "ADPCM", 5 ) ) { /* BAH */
-                    total_sample_size += (sigdata->sample[sample_number].length + 1) / 2 + 5 + 16;
-                    if ( dumbfile_seek(f, -5, DFS_SEEK_CUR) ) {
-                        _dumb_it_unload_sigdata(sigdata);
-                        return NULL;
-                    }
-                } else {
-                    total_sample_size += sigdata->sample[sample_number].length;
-                    if ( dumbfile_seek(f, -(sigdata->sample[sample_number].length - ((sigdata->sample[sample_number].length + 1) / 2 + 5 + 16) + 5), DFS_SEEK_CUR) ) {
-                        _dumb_it_unload_sigdata(sigdata);
-                        return NULL;
-                    }
-                }
-            }
-            --sample_number;
-        }
-
-		if (remain > total_sample_size) {
-			sigdata->n_patterns = ( remain - total_sample_size + 4 ) / ( 256 * sigdata->n_pchannels );
-			if (fft == DUMB_ID('M',0,0,0) || fft == DUMB_ID('8',0,0,0)) {
-				remain -= sigdata->n_patterns * 256 * sigdata->n_pchannels;
-				if (dumbfile_skip(f, remain - total_sample_size)) {
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-			}
-		}
-	}
-	else
-    {
-        for (i = 0; i < 128; i++)
-        {
-            if (sigdata->order[i] > sigdata->n_patterns)
-                sigdata->n_patterns = sigdata->order[i];
-        }
-		sigdata->n_patterns++;
-	}
-
-	if ( sigdata->n_patterns <= 0 ) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	/* May as well try to save a tiny bit of memory. */
-	if (sigdata->n_orders < 128) {
-		unsigned char *order = realloc(sigdata->order, sigdata->n_orders);
-		if (order) sigdata->order = order;
-	}
-
-	sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-	if (!sigdata->pattern) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-	for (i = 0; i < sigdata->n_patterns; i++)
-		sigdata->pattern[i].entry = NULL;
-
-	/* Read in the patterns */
-	{
-		unsigned char *buffer = malloc(256 * sigdata->n_pchannels); /* 64 rows * 4 bytes */
-		if (!buffer) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (i = 0; i < sigdata->n_patterns; i++) {
-			if (it_mod_read_pattern(&sigdata->pattern[i], f, n_channels, buffer) != 0) {
-				free(buffer);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-		}
-		free(buffer);
-	}
-
-	/* And finally, the sample data */
-	for (i = 0; i < sigdata->n_samples; i++) {
-		if (it_mod_read_sample_data(&sigdata->sample[i], f, fft)) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-	}
-
-	/* w00t! */
-	/*if ( n_channels == 4 &&
-		( sigdata->n_samples == 15 ||
-		( ( fft & 240 ) != DUMB_ID( 0, 0, 'C', 0 ) &&
-		( fft & 240 ) != DUMB_ID( 0, 0, 'H', 0 ) &&
-		( fft & 240 ) != 0 ) ) ) {
-		for ( i = 0; i < sigdata->n_samples; ++i ) {
-			IT_SAMPLE * sample = &sigdata->sample [i];
-			if ( sample && ( sample->flags & IT_SAMPLE_EXISTS ) ) {
-				int n, o;
-				o = sample->length;
-				if ( o > 4 ) o = 4;
-				for ( n = 0; n < o; ++n )
-					( ( char * ) sample->data ) [n] = 0;
-			}
-		}
-	}*/
-
-	/* Now let's initialise the remaining variables, and we're done! */
-	sigdata->flags = IT_WAS_AN_XM | IT_WAS_A_MOD | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_STEREO;
-
-	sigdata->global_volume = 128;
-	sigdata->mixing_volume = 48;
-	/* We want 50 ticks per second; 50/6 row advances per second;
-	 * 50*10=500 row advances per minute; 500/4=125 beats per minute.
-	 */
-	sigdata->speed = 6;
-	sigdata->tempo = 125;
-	sigdata->pan_separation = 128;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (i = 0; i < DUMB_IT_N_CHANNELS; i += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[i+0] = 32 - sep;
-		sigdata->channel_pan[i+1] = 32 + sep;
-		sigdata->channel_pan[i+2] = 32 + sep;
-		sigdata->channel_pan[i+3] = 32 - sep;
-	}
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-
-
-DUH *dumb_read_mod_quick(DUMBFILE *f, int restrict_)
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_mod_load_sigdata(f, restrict_);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "MOD";
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readmod2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readmod2.c - Function to read a good old-          / / \  \
- *              fashioned Amiga module from an       | <  /   \_
- *              open file and do an initial          |  \/ /\   /
- *              run-through.                          \_  /  > /
- *                                                      | \ / /
- * Split off from readmod.c by entheh.                  |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_mod(DUMBFILE *f, int restrict_)
-{
-	DUH *duh = dumb_read_mod_quick(f, restrict_);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/readmtm.c
+++ /dev/null
@@ -1,413 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readmtm.c - Code to read a MultiTracker Module     / / \  \
- *             from an open file.                    | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-size_t strlen_max(const char * ptr, size_t max)
-{
-	const char * end, * start;
-	if (ptr==0) return 0;
-	start = ptr;
-	end = ptr + max;
-	while(*ptr && ptr < end) ptr++;
-	return ptr - start;
-}
-
-static int it_mtm_assemble_pattern(IT_PATTERN *pattern, const unsigned char * track, const unsigned short * sequence, int n_rows)
-{
-	int n, o, note, sample;
-	const unsigned char * t;
-	IT_ENTRY * entry;
-
-	pattern->n_rows = n_rows;
-	pattern->n_entries = n_rows;
-
-	for (n = 0; n < 32; n++) {
-		if (sequence[n]) {
-			t = &track[192 * (sequence[n] - 1)];
-			for (o = 0; o < n_rows; o++) {
-				if (t[0] || t[1] || t[2]) pattern->n_entries++;
-				t += 3;
-			}
-		}
-	}
-
-	entry = malloc(pattern->n_entries * sizeof(*entry));
-	if (!entry) return -1;
-	pattern->entry = entry;
-
-	for (n = 0; n < n_rows; n++) {
-		for (o = 0; o < 32; o++) {
-			if (sequence[o]) {
-				t = &track[192 * (sequence[o] - 1) + (n * 3)];
-				if (t[0] || t[1] || t[2]) {
-					entry->channel = o;
-					entry->mask = 0;
-					note = t[0] >> 2;
-					sample = ((t[0] << 4) | (t[1] >> 4)) & 0x3F;
-
-					if (note) {
-						entry->mask |= IT_ENTRY_NOTE;
-						entry->note = note + 24;
-					}
-
-					if (sample) {
-						entry->mask |= IT_ENTRY_INSTRUMENT;
-						entry->instrument = sample;
-					}
-
-					_dumb_it_xm_convert_effect(t[1] & 0xF, t[2], entry, 1);
-
-					if (entry->mask) entry++;
-				}
-			}
-		}
-		IT_SET_END_ROW(entry);
-		entry++;
-	}
-
-	pattern->n_entries = entry - pattern->entry;
-
-	return 0;
-}
-
-static int it_mtm_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f)
-{
-	int finetune, flags;
-
-    dumbfile_getnc((char *)sample->name, 22, f);
-	sample->name[22] = 0;
-
-	sample->filename[0] = 0;
-
-	sample->length = dumbfile_igetl(f);
-	sample->loop_start = dumbfile_igetl(f);
-	sample->loop_end = dumbfile_igetl(f);
-	finetune = (signed char)(dumbfile_getc(f) << 4) >> 4; /* signed nibble */
-	sample->global_volume = 64;
-	sample->default_volume = dumbfile_getc(f);
-
-	flags = dumbfile_getc(f);
-
-	if (sample->length <= 0) {
-		sample->flags = 0;
-		return 0;
-	}
-
-	sample->flags = IT_SAMPLE_EXISTS;
-
-	if (flags & 1) {
-		sample->flags |= IT_SAMPLE_16BIT;
-		sample->length >>= 1;
-		sample->loop_start >>= 1;
-		sample->loop_end >>= 1;
-	}
-
-	sample->default_pan = 0;
-	sample->C5_speed = (int)( AMIGA_CLOCK / 214.0 );//(long)(16726.0*pow(DUMB_PITCH_BASE, finetune*32));
-	sample->finetune = finetune * 32;
-	// the above line might be wrong
-
-	if (sample->loop_end > sample->length)
-		sample->loop_end = sample->length;
-
-	if (sample->loop_end - sample->loop_start > 2)
-		sample->flags |= IT_SAMPLE_LOOP;
-
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = 0; // do we have to set _all_ these?
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-static int it_mtm_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f)
-{
-	long i;
-	long truncated_size;
-
-	/* let's get rid of the sample data coming after the end of the loop */
-	if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length) {
-		truncated_size = sample->length - sample->loop_end;
-		sample->length = sample->loop_end;
-	} else {
-		truncated_size = 0;
-	}
-
-	sample->data = malloc(sample->length);
-
-	if (!sample->data)
-		return -1;
-
-	dumbfile_getnc((char *)sample->data, sample->length, f);
-	dumbfile_skip(f, truncated_size);
-
-	if (dumbfile_error(f))
-		return -1;
-
-	for (i = 0; i < sample->length; i++)
-		((signed char *)sample->data)[i] ^= 0x80;
-
-	return 0;
-}
-
-static DUMB_IT_SIGDATA *it_mtm_load_sigdata(DUMBFILE *f, int * version)
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	int n, o, n_tracks, l_comment, n_rows, n_channels;
-
-	unsigned char * track;
-
-	unsigned short * sequence;
-
-	char * comment;
-
-	if (dumbfile_getc(f) != 'M' ||
-		dumbfile_getc(f) != 'T' ||
-		dumbfile_getc(f) != 'M') goto error;
-
-	*version = dumbfile_getc(f);
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) goto error;
-
-    dumbfile_getnc((char *)sigdata->name, 20, f);
-	sigdata->name[20] = 0;
-
-	n_tracks = dumbfile_igetw(f);
-	sigdata->n_patterns = dumbfile_getc(f) + 1;
-	sigdata->n_orders = dumbfile_getc(f) + 1;
-	l_comment = dumbfile_igetw(f);
-	sigdata->n_samples = dumbfile_getc(f);
-	//if (dumbfile_getc(f)) goto error_sd;
-	dumbfile_getc(f);
-	n_rows = dumbfile_getc(f);
-	n_channels = dumbfile_getc(f);
-
-	if (dumbfile_error(f) ||
-		(n_tracks <= 0) ||
-		(sigdata->n_samples <= 0) ||
-		(n_rows <= 0 || n_rows > 64) ||
-		(n_channels <= 0 || n_channels > 32)) goto error_sd;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-    if (dumbfile_getnc((char *)sigdata->channel_pan, 32, f) < 32) goto error_sd;
-
-	for (n = 0; n < 32; n++) {
-		if (sigdata->channel_pan[n] <= 15) {
-			sigdata->channel_pan[n] -= (sigdata->channel_pan[n] & 8) >> 3;
-			sigdata->channel_pan[n] = (sigdata->channel_pan[n] * 32) / 7;
-		} else {
-			sigdata->channel_volume[n] = 0;
-			sigdata->channel_pan[n] = 7;
-		}
-	}
-
-	for (n = 32; n < DUMB_IT_N_CHANNELS; n += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[n  ] = 32 - sep;
-		sigdata->channel_pan[n+1] = 32 + sep;
-		sigdata->channel_pan[n+2] = 32 + sep;
-		sigdata->channel_pan[n+3] = 32 - sep;
-	}
-
-	sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-	if (!sigdata->sample) goto error_sd;
-
-	sigdata->flags = IT_WAS_AN_XM | IT_WAS_A_MOD | IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX;
-
-	sigdata->global_volume = 128;
-	sigdata->mixing_volume = 48;
-	sigdata->speed = 6;
-	sigdata->tempo = 125;
-	sigdata->pan_separation = 128;
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-
-	sigdata->restart_position = 0;
-	sigdata->n_pchannels = n_channels;
-
-	for (n = 0; n < sigdata->n_samples; n++)
-		sigdata->sample[n].data = NULL;
-
-	for (n = 0; n < sigdata->n_samples; n++) {
-		if (it_mtm_read_sample_header(&sigdata->sample[n], f)) goto error_usd;
-	}
-
-	sigdata->order = malloc(sigdata->n_orders);
-	if (!sigdata->order) goto error_usd;
-
-    if (dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f) < sigdata->n_orders) goto error_usd;
-	if (sigdata->n_orders < 128)
-		if (dumbfile_skip(f, 128 - sigdata->n_orders)) goto error_usd;
-
-	track = malloc(192 * n_tracks);
-	if (!track) goto error_usd;
-
-    if (dumbfile_getnc((char *)track, 192 * n_tracks, f) < 192 * n_tracks) goto error_ft;
-
-	sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-	if (!sigdata->pattern) goto error_ft;
-	for (n = 0; n < sigdata->n_patterns; n++)
-		sigdata->pattern[n].entry = NULL;
-
-	sequence = malloc(sigdata->n_patterns * 32 * sizeof(*sequence));
-	if (!sequence) goto error_ft;
-
-	for (n = 0; n < sigdata->n_patterns; n++) {
-		for (o = 0; o < 32; o++) {
-			sequence[(n * 32) + o] = dumbfile_igetw(f);
-			if (sequence[(n * 32) + o] > n_tracks)
-			{
-				//goto error_fs;
-				// illegal track number, silence instead of rejecting the file
-				sequence[(n * 32) + o] = 0;
-			}
-		}
-	}
-
-	for (n = 0; n < sigdata->n_patterns; n++) {
-		if (it_mtm_assemble_pattern(&sigdata->pattern[n], track, &sequence[n * 32], n_rows)) goto error_fs;
-	}
-
-	if (l_comment) {
-		comment = malloc(l_comment);
-		if (!comment) goto error_fs;
-		if (dumbfile_getnc(comment, l_comment, f) < l_comment) goto error_fc;
-
-		/* Time for annoying "logic", yes. We want each line which has text,
-		 * and each blank line in between all the valid lines.
-		 */
-
-		/* Find last actual line. */
-		for (o = -1, n = 0; n < l_comment; n += 40) {
-			if (comment[n]) o = n;
-		}
-
-		if (o >= 0) {
-
-			int l, m;
-
-			for (l = 0, n = 0; n <= o; n += 40) {
-				l += strlen_max(&comment[n], 40) + 2;
-			}
-
-			l -= 1;
-
-			sigdata->song_message = malloc(l);
-			if (!sigdata->song_message) goto error_fc;
-
-			for (m = 0, n = 0; n <= o; n += 40) {
-				int p = strlen_max(&comment[n], 40);
-				if (p) {
-					memcpy(sigdata->song_message + m, &comment[n], p);
-					m += p;
-				}
-				if (l - m > 1) {
-					sigdata->song_message[m++] = 13;
-					sigdata->song_message[m++] = 10;
-				}
-			}
-			
-			sigdata->song_message[m] = 0;
-		}
-
-		free(comment);
-	}
-
-	for (n = 0; n < sigdata->n_samples; n++) {
-		if (it_mtm_read_sample_data(&sigdata->sample[n], f)) goto error_fs;
-	}
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	free(sequence);
-	free(track);
-
-	return sigdata;
-
-error_fc:
-	free(comment);
-error_fs:
-	free(sequence);
-error_ft:
-	free(track);
-error_usd:
-	_dumb_it_unload_sigdata(sigdata);
-	return NULL;
-
-error_sd:
-	free(sigdata);
-error:
-	return NULL;
-}
-
-static char hexdigit(int in)
-{
-	if (in < 10) return in + '0';
-	else return in + 'A' - 10;
-}
-
-DUH *dumb_read_mtm_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-	int ver;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_mtm_load_sigdata(f, &ver);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		char version[16];
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		version[0] = 'M';
-		version[1] = 'T';
-		version[2] = 'M';
-		version[3] = ' ';
-		version[4] = 'v';
-		version[5] = hexdigit(ver >> 4);
-		version[6] = '.';
-		version[7] = hexdigit(ver & 15);
-		version[8] = 0;
-		tag[1][1] = (const char *) &version;
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readokt.c
+++ /dev/null
@@ -1,558 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readokt.c - Code to read an Oktalyzer module       / / \  \
- *             from an open file.                    | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-static int it_okt_read_pattern(IT_PATTERN *pattern, const unsigned char *data, int length, int n_channels)
-{
-	int pos;
-	int channel;
-	int row;
-	int n_rows;
-	IT_ENTRY *entry;
-
-	if (length < 2) return -1;
-
-	n_rows = (data[0] << 8) | data[1];
-	if (!n_rows) n_rows = 64;
-
-	if (length < 2 + (n_rows * n_channels * 4)) return -1;
-
-	pattern->n_rows = n_rows;
-
-	/* compute number of entries */
-	pattern->n_entries = n_rows; /* Account for the row end markers */
-	pos = 2;
-	for (row = 0; row < pattern->n_rows; row++) {
-		for (channel = 0; channel < n_channels; channel++) {
-			if (data[pos+0] | data[pos+2])
-				pattern->n_entries++;
-			pos += 4;
-		}
-	}
-
-	pattern->entry = (IT_ENTRY *) malloc(pattern->n_entries * sizeof(*pattern->entry));
-	if (!pattern->entry)
-		return -1;
-
-	entry = pattern->entry;
-	pos = 2;
-	for (row = 0; row < n_rows; row++) {
-		for (channel = 0; channel < n_channels; channel++) {
-			if (data[pos+0] | data[pos+2]) {
-				entry->channel = channel;
-				entry->mask = 0;
-
-				if (data[pos+0] > 0 && data[pos+0] <= 36) {
-					entry->mask |= IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT;
-
-					entry->note = data[pos+0] + 35;
-					entry->instrument = data[pos+1] + 1;
-				}
-
-				entry->effect = 0;
-				entry->effectvalue = data[pos+3];
-
-				switch (data[pos+2]) {
-				case  2: if (data[pos+3]) entry->effect = IT_PORTAMENTO_DOWN; break; // XXX code calls this rs_portu, but it's adding to the period, which decreases the pitch
-				case 13: if (data[pos+3]) entry->effect = IT_OKT_NOTE_SLIDE_DOWN; break;
-				case 21: if (data[pos+3]) entry->effect = IT_OKT_NOTE_SLIDE_DOWN_ROW; break;
-
-				case  1: if (data[pos+3]) entry->effect = IT_PORTAMENTO_UP; break;   // XXX same deal here, increasing the pitch
-				case 17: if (data[pos+3]) entry->effect = IT_OKT_NOTE_SLIDE_UP; break;
-				case 30: if (data[pos+3]) entry->effect = IT_OKT_NOTE_SLIDE_UP_ROW; break;
-
-				case 10: if (data[pos+3]) entry->effect = IT_OKT_ARPEGGIO_3; break;
-				case 11: if (data[pos+3]) entry->effect = IT_OKT_ARPEGGIO_4; break;
-				case 12: if (data[pos+3]) entry->effect = IT_OKT_ARPEGGIO_5; break;
-
-				case 15: entry->effect = IT_S; entry->effectvalue = EFFECT_VALUE(IT_S_SET_FILTER, data[pos+3] & 0x0F); break;
-
-				case 25: entry->effect = IT_JUMP_TO_ORDER; break;
-
-				case 27: entry->note = IT_NOTE_OFF; entry->mask |= IT_ENTRY_NOTE; break;
-
-				case 28: entry->effect = IT_SET_SPEED; break;
-
-				case 31:
-					if ( data[pos+3] <= 0x40 ) entry->effect = IT_SET_CHANNEL_VOLUME;
-					else if ( data[pos+3] <= 0x50 ) { entry->effect = IT_OKT_VOLUME_SLIDE_DOWN; entry->effectvalue = data[pos+3] - 0x40; }
-					else if ( data[pos+3] <= 0x60 ) { entry->effect = IT_OKT_VOLUME_SLIDE_UP;   entry->effectvalue = data[pos+3] - 0x50; }
-					else if ( data[pos+3] <= 0x70 ) { entry->effect = IT_OKT_VOLUME_SLIDE_DOWN; entry->effectvalue = data[pos+3] - 0x50; }
-					else if ( data[pos+3] <= 0x80 ) { entry->effect = IT_OKT_VOLUME_SLIDE_UP;   entry->effectvalue = data[pos+3] - 0x60; }
-					break;
-				}
-
-				if ( entry->effect ) entry->mask |= IT_ENTRY_EFFECT;
-
-				entry++;
-			}
-			pos += 4;
-		}
-		IT_SET_END_ROW(entry);
-		entry++;
-	}
-
-	return 0;
-}
-
-
-
-static void it_okt_read_sample_header(IT_SAMPLE *sample, const unsigned char * data)
-{
-	int loop_start, loop_length;
-
-	memcpy(sample->name, data, 20);
-	sample->name[20] = 0;
-
-	sample->filename[0] = 0;
-
-	sample->length = (data[20] << 24) | (data[21] << 16) | (data[22] << 8) | data[23];
-	sample->global_volume = 64;
-	sample->default_volume = data[29];
-	loop_start = ((data[24] << 8) | data[25]) << 1;
-	loop_length = ((data[26] << 8) | data[27]) << 1;
-	sample->sus_loop_start = loop_start;
-	sample->sus_loop_end = loop_start + loop_length;
-
-	if (sample->length <= 0) {
-		sample->flags = 0;
-		return;
-	}
-
-	sample->flags = IT_SAMPLE_EXISTS;
-
-	sample->default_pan = 0;
-	sample->C5_speed = (int)( AMIGA_CLOCK / 214.0 ); //(long)(16726.0*pow(DUMB_PITCH_BASE, finetune*32));
-	sample->finetune = 0;
-
-	if (sample->sus_loop_end > sample->length)
-		sample->sus_loop_end = sample->length;
-
-	if (loop_length > 2)
-		sample->flags |= IT_SAMPLE_SUS_LOOP;
-
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = 0; // do we have to set _all_ these?
-	sample->max_resampling_quality = -1;
-}
-
-
-
-static int it_okt_read_sample_data(IT_SAMPLE *sample, const char * data, int length)
-{
-	if (length && sample->length) {
-		if (length < sample->length) {
-			sample->length = length;
-			if (length < sample->sus_loop_end) sample->sus_loop_end = length;
-		}
-
-		sample->data = malloc(length);
-
-		if (!sample->data)
-			return -1;
-
-		memcpy(sample->data, data, length);
-	}
-
-	return 0;
-}
-
-
-
-typedef struct IFF_CHUNK IFF_CHUNK;
-typedef struct IFF_CHUNKED IFF_CHUNKED;
-
-struct IFF_CHUNK
-{
-	unsigned type;
-	unsigned char * data;
-	unsigned size;
-};
-
-struct IFF_CHUNKED
-{
-	unsigned chunk_count;
-	IFF_CHUNK * chunks;
-};
-
-
-
-static IFF_CHUNKED *dumbfile_read_okt(DUMBFILE *f)
-{
-	IFF_CHUNKED *mod = (IFF_CHUNKED *) malloc(sizeof(*mod));
-	if (!mod) return NULL;
-
-	mod->chunk_count = 0;
-	mod->chunks = 0;
-
-	for (;;)
-	{
-		long bytes_read;
-		IFF_CHUNK * chunk = ( IFF_CHUNK * ) realloc( mod->chunks, ( mod->chunk_count + 1 ) * sizeof( IFF_CHUNK ) );
-		if ( !chunk )
-		{
-			if ( mod->chunks ) free( mod->chunks );
-			free( mod );
-			return NULL;
-		}
-		mod->chunks = chunk;
-		chunk += mod->chunk_count;
-
-		bytes_read = dumbfile_mgetl( f );
-		if ( bytes_read < 0 ) break;
-
-		chunk->type = bytes_read;
-		chunk->size = dumbfile_mgetl( f );
-
-		if ( dumbfile_error( f ) ) break;
-
-		chunk->data = (unsigned char *) malloc( chunk->size );
-		if ( !chunk->data )
-		{
-			free( mod->chunks );
-			free( mod );
-			return NULL;
-		}
-
-		bytes_read = dumbfile_getnc( ( char * ) chunk->data, chunk->size, f );
-		if ( bytes_read < chunk->size )
-		{
-			if ( bytes_read <= 0 ) {
-				free( chunk->data );
-				break;
-			} else {
-				chunk->size = bytes_read;
-				mod->chunk_count++;
-				break;
-			}
-		}
-
-		mod->chunk_count++;
-	}
-
-	if ( !mod->chunk_count ) {
-		if ( mod->chunks ) free(mod->chunks);
-		free(mod);
-		mod = NULL;
-	}
-
-	return mod;
-}
-
-void free_okt(IFF_CHUNKED * mod)
-{
-	unsigned i;
-	if (mod)
-	{
-		if (mod->chunks)
-		{
-			for (i = 0; i < mod->chunk_count; i++)
-			{
-				if (mod->chunks[i].data) free(mod->chunks[i].data);
-			}
-			free(mod->chunks);
-		}
-		free(mod);
-	}
-}
-
-const IFF_CHUNK * get_chunk_by_type(IFF_CHUNKED * mod, unsigned type, unsigned offset)
-{
-	unsigned i;
-	if (mod)
-	{
-		if (mod->chunks)
-		{
-			for (i = 0; i < mod->chunk_count; i++)
-			{
-				if (mod->chunks[i].type == type)
-				{
-					if (!offset) return &mod->chunks[i];
-					else offset--;
-				}
-			}
-		}
-	}
-	return NULL;
-}
-
-unsigned get_chunk_count(IFF_CHUNKED *mod, unsigned type)
-{
-	unsigned i, count = 0;
-	if (mod)
-	{
-		if (mod->chunks)
-		{
-			for (i = 0; i < mod->chunk_count; i++)
-			{
-				if (mod->chunks[i].type == type) count++;
-			}
-		}
-	}
-	return count;
-}
-
-
-static DUMB_IT_SIGDATA *it_okt_load_sigdata(DUMBFILE *f)
-{
-	DUMB_IT_SIGDATA *sigdata;
-    int n_channels;
-    int i, j, k, l;
-	IFF_CHUNKED *mod;
-	const IFF_CHUNK *chunk;
-
-	char signature[8];
-
-	if (dumbfile_getnc(signature, 8, f) < 8 ||
-		memcmp(signature, "OKTASONG", 8)) {
-		return NULL;
-	}
-
-	mod = dumbfile_read_okt(f);
-	if (!mod)
-		return NULL;
-
-	sigdata = (DUMB_IT_SIGDATA *) malloc(sizeof(*sigdata));
-	if (!sigdata) {
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->name[0] = 0;
-
-	chunk = get_chunk_by_type(mod, DUMB_ID('S','P','E','E'), 0);
-	if (!chunk || chunk->size < 2) {
-		free(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->speed = (chunk->data[0] << 8) | chunk->data[1];
-
-	chunk = get_chunk_by_type(mod, DUMB_ID('S','A','M','P'), 0);
-	if (!chunk || chunk->size < 32) {
-		free(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->n_samples = chunk->size / 32;
-
-	chunk = get_chunk_by_type(mod, DUMB_ID('C','M','O','D'), 0);
-	if (!chunk || chunk->size < 8) {
-		free(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	n_channels = 0;
-
-	for (i = 0; i < 4; i++) {
-		j = (chunk->data[i * 2] << 8) | chunk->data[i * 2 + 1];
-		if (!j) n_channels++;
-		else if (j == 1) n_channels += 2;
-	}
-
-	if (!n_channels) {
-		free(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->n_pchannels = n_channels;
-
-	sigdata->sample = (IT_SAMPLE *) malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-	if (!sigdata->sample) {
-		free(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-
-	for (i = 0; i < sigdata->n_samples; i++)
-		sigdata->sample[i].data = NULL;
-
-	chunk = get_chunk_by_type(mod, DUMB_ID('S','A','M','P'), 0);
-
-	for (i = 0; i < sigdata->n_samples; i++) {
-		it_okt_read_sample_header(&sigdata->sample[i], chunk->data + 32 * i);
-	}
-
-	sigdata->restart_position = 0;
-
-	chunk = get_chunk_by_type(mod, DUMB_ID('P','L','E','N'), 0);
-	if (!chunk || chunk->size < 2) {
-		_dumb_it_unload_sigdata(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->n_orders = (chunk->data[0] << 8) | chunk->data[1];
-	// what if this is > 128?
-
-	if (sigdata->n_orders <= 0 || sigdata->n_orders > 128) {
-		_dumb_it_unload_sigdata(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	chunk = get_chunk_by_type(mod, DUMB_ID('P','A','T','T'), 0);
-    if (!chunk || chunk->size < (unsigned)sigdata->n_orders) {
-		_dumb_it_unload_sigdata(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->order = (unsigned char *) malloc(sigdata->n_orders);
-	if (!sigdata->order) {
-		_dumb_it_unload_sigdata(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	memcpy(sigdata->order, chunk->data, sigdata->n_orders);
-
-	/* Work out how many patterns there are. */
-	chunk = get_chunk_by_type(mod, DUMB_ID('S','L','E','N'), 0);
-	if (!chunk || chunk->size < 2) {
-		_dumb_it_unload_sigdata(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->n_patterns = (chunk->data[0] << 8) | chunk->data[1];
-
-	j = get_chunk_count(mod, DUMB_ID('P','B','O','D'));
-	if (sigdata->n_patterns > j) sigdata->n_patterns = j;
-
-	if (!sigdata->n_patterns) {
-		_dumb_it_unload_sigdata(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-
-	sigdata->pattern = (IT_PATTERN *) malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-	if (!sigdata->pattern) {
-		_dumb_it_unload_sigdata(sigdata);
-		free_okt(mod);
-		return NULL;
-	}
-	for (i = 0; i < sigdata->n_patterns; i++)
-		sigdata->pattern[i].entry = NULL;
-
-	/* Read in the patterns */
-	for (i = 0; i < sigdata->n_patterns; i++) {
-		chunk = get_chunk_by_type(mod, DUMB_ID('P','B','O','D'), i);
-		if (it_okt_read_pattern(&sigdata->pattern[i], chunk->data, chunk->size, n_channels) != 0) {
-			_dumb_it_unload_sigdata(sigdata);
-			free_okt(mod);
-			return NULL;
-		}
-	}
-
-	/* And finally, the sample data */
-	k = get_chunk_count(mod, DUMB_ID('S','B','O','D'));
-	for (i = 0, j = 0; i < sigdata->n_samples && j < k; i++) {
-		if (sigdata->sample[i].flags & IT_SAMPLE_EXISTS) {
-			chunk = get_chunk_by_type(mod, DUMB_ID('S','B','O','D'), j);
-			if (it_okt_read_sample_data(&sigdata->sample[i], (const char *)chunk->data, chunk->size)) {
-				_dumb_it_unload_sigdata(sigdata);
-				free_okt(mod);
-				return NULL;
-			}
-			j++;
-		}
-	}
-	for (; i < sigdata->n_samples; i++) {
-		sigdata->sample[i].flags = 0;
-	}
-
-	chunk = get_chunk_by_type(mod, DUMB_ID('C','M','O','D'), 0);
-
-	for (i = 0, j = 0; i < n_channels && j < 4; j++) {
-		k = (chunk->data[j * 2] << 8) | chunk->data[j * 2 + 1];
-		l = (j == 1 || j == 2) ? 48 : 16;
-		if (k == 0) {
-			sigdata->channel_pan[i++] = l;
-		}
-		else if (k == 1) {
-			sigdata->channel_pan[i++] = l;
-			sigdata->channel_pan[i++] = l;
-		}
-	}
-
-	free_okt(mod);
-
-	/* Now let's initialise the remaining variables, and we're done! */
-	sigdata->flags = IT_WAS_AN_OKT | IT_WAS_AN_XM | IT_WAS_A_MOD | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_STEREO;
-
-	sigdata->global_volume = 128;
-	sigdata->mixing_volume = 48;
-	/* We want 50 ticks per second; 50/6 row advances per second;
-	 * 50*10=500 row advances per minute; 500/4=125 beats per minute.
-	 */
-	sigdata->tempo = 125;
-	sigdata->pan_separation = 128;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-	memset(sigdata->channel_pan + n_channels, 32, DUMB_IT_N_CHANNELS - n_channels);
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-
-
-DUH *dumb_read_okt_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-    sigdata = it_okt_load_sigdata(f);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[1][2];
-		tag[0][0] = "FORMAT";
-		tag[0][1] = "Oktalyzer";
-		return make_duh(-1, 1, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readokt2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readokt2.c - Function to read an Oktalyzer         / / \  \
- *              module from an open file and do      | <  /   \_
- *              an initial run-through.              |  \/ /\   /
- *                                                    \_  /  > /
- *                                                      | \ / /
- * By Chris Moeller.                                    |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_okt(DUMBFILE *f)
-{
-	DUH *duh = dumb_read_okt_quick(f);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/readoldpsm.c
+++ /dev/null
@@ -1,689 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readpsm.c - Code to read an old Protracker         / / \  \
- *             Studio module from an open file.      | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-static int psm_sample_compare(const void *e1, const void *e2)
-{
-	const unsigned char * pa = e1;
-	const unsigned char * pb = e2;
-	int a = pa[37] | (pa[38] << 8) | (pa[39] << 16) | (pa[40] << 24);
-	int b = pb[37] | (pb[38] << 8) | (pb[39] << 16) | (pb[40] << 24);
-	return a - b;
-}
-
-static int it_old_psm_read_samples(IT_SAMPLE ** sample, DUMBFILE * f, int * num)
-{
-    int n, o, count = *num, true_num, snum, offset, flags, finetune, delta;
-
-    unsigned char * buffer;
-	const unsigned char * sdata;
-    long sample_bytes;
-
-	buffer = malloc(count * 64);
-	if (!buffer) goto error;
-
-    if (dumbfile_getnc((char *)buffer, count * 64, f) < count * 64) goto error_fb;
-
-	true_num = 0;
-
-	for (n = 0; n < count; n++) {
-		snum = buffer[(n * 64) + 45] | (buffer[(n * 64) + 46] << 8);
-		if ((snum < 1) || (snum > 255)) goto error_fb;
-		if (true_num < snum) true_num = snum;
-	}
-
-	if (true_num > count) {
-		IT_SAMPLE * meh = realloc(*sample, true_num * sizeof(*meh));
-		if (!meh) goto error_fb;
-		for (n = count; n < true_num; n++) {
-			meh[n].data = NULL;
-		}
-		*sample = meh;
-		*num = true_num;
-	}
-
-	qsort(buffer, count, 64, &psm_sample_compare);
-
-	for (n = 0; n < true_num; n++) {
-		(*sample)[n].flags = 0;
-	}
-
-	for (n = 0; n < count; n++) {
-		IT_SAMPLE * s;
-		snum = buffer[(n * 64) + 45] | (buffer[(n * 64) + 46] << 8);
-		s = &((*sample)[snum - 1]);
-		memcpy(s->filename, buffer + (n * 64), 13);
-		s->filename[13] = 0;
-		memcpy(s->name, buffer + (n * 64) + 13, 24);
-		s->name[24] = 0;
-		offset = buffer[(n * 64) + 37] | (buffer[(n * 64) + 38] << 8) |
-				 (buffer[(n * 64) + 39] << 16) | (buffer[(n * 64) + 40] << 24);
-		flags = buffer[(n * 64) + 47];
-		s->length = buffer[(n * 64) + 48] | (buffer[(n * 64) + 49] << 8) |
-					(buffer[(n * 64) + 50] << 16) | (buffer[(n * 64) + 51] << 24);
-		s->loop_start = buffer[(n * 64) + 52] | (buffer[(n * 64) + 53] << 8) |
-						(buffer[(n * 64) + 54] << 16) | (buffer[(n * 64) + 55] << 24);
-		s->loop_end = buffer[(n * 64) + 56] | (buffer[(n * 64) + 57] << 8) |
-					  (buffer[(n * 64) + 58] << 16) | (buffer[(n * 64) + 59] << 24);
-
-		if (s->length <= 0) continue;
-
-		finetune = buffer[(n * 64) + 60];
-		s->default_volume = buffer[(n * 64) + 61];
-		s->C5_speed = buffer[(n * 64) + 62] | (buffer[(n * 64) + 63] << 8);
-		if (finetune & 15) {
-			finetune &= 15;
-			if (finetune >= 8) finetune -= 16;
-			//s->C5_speed = (long)((double)s->C5_speed * pow(DUMB_PITCH_BASE, finetune*32));
-			s->finetune = finetune * 32;
-		}
-		else s->finetune = 0;
-
-		s->flags |= IT_SAMPLE_EXISTS;
-		if (flags & 0x41) {
-			s->flags &= ~IT_SAMPLE_EXISTS;
-			continue;
-		}
-		if (flags & 0x20) s->flags |= IT_SAMPLE_PINGPONG_LOOP;
-		if (flags & 4) s->flags |= IT_SAMPLE_16BIT;
-
-		if (flags & 0x80) {
-			s->flags |= IT_SAMPLE_LOOP;
-			if ((unsigned int)s->loop_end > (unsigned int)s->length)
-				s->loop_end = s->length;
-			else if ((unsigned int)s->loop_start >= (unsigned int)s->loop_end)
-				s->flags &= ~IT_SAMPLE_LOOP;
-			else
-				s->length = s->loop_end;
-		}
-
-		s->global_volume = 64;
-
-		s->vibrato_speed = 0;
-		s->vibrato_depth = 0;
-		s->vibrato_rate = 0;
-		s->vibrato_waveform = IT_VIBRATO_SINE;
-		s->max_resampling_quality = -1;
-
-        sample_bytes = s->length * ((flags & 4) ? 2 : 1);
-        s->data = malloc(sample_bytes);
-		if (!s->data) goto error_fb;
-
-        if (dumbfile_seek(f, offset, DFS_SEEK_SET) || dumbfile_getnc(s->data, sample_bytes, f) < sample_bytes) goto error_fb;
-        sdata = ( const unsigned char * ) s->data;
-
-		if (flags & 0x10) {
-			if (flags & 8) {
-				if (flags & 4) {
-					for (o = 0; o < s->length; o++)
-						((short *)s->data)[o] = (sdata[o * 2] | (sdata[(o * 2) + 1] << 8)) ^ 0x8000;
-				} else {
-					for (o = 0; o < s->length; o++)
-						((signed char *)s->data)[o] = sdata[o] ^ 0x80;
-				}
-			} else {
-				if (flags & 4) {
-					for (o = 0; o < s->length; o++)
-						((short *)s->data)[o] = sdata[o * 2] | (sdata[(o * 2) + 1] << 8);
-				} else {
-					memcpy(s->data, sdata, s->length);
-				}
-			}
-		} else {
-			delta = 0;
-			if (flags & 8) {
-				/* unsigned delta? mehhh, does anything even use this? */
-				if (flags & 4) {
-					for (o = 0; o < s->length; o++) {
-						delta += (short)(sdata[o * 2] | (sdata[(o * 2) + 1] << 8));
-						((short *)s->data)[o] = delta ^ 0x8000;
-					}
-				} else {
-					for (o = 0; o < s->length; o++) {
-						delta += (signed char)sdata[o];
-						((signed char *)s->data)[o] = delta ^ 0x80;
-					}
-				}
-			} else {
-				if (flags & 4) {
-					for (o = 0; o < s->length; o++) {
-						delta += (signed short)(sdata[o * 2] | (sdata[(o * 2) + 1] << 8));
-						((signed short *)s->data)[o] = delta;
-					}
-				} else {
-					for (o = 0; o < s->length; o++) {
-						delta += (signed char)sdata[o];
-						((signed char *)s->data)[o] = delta;
-					}
-				}
-			}
-		}
-	}
-
-	free(buffer);
-
-	return 0;
-
-error_fb:
-	free(buffer);
-error:
-	return -1;
-}
-
-static int it_old_psm_read_patterns(IT_PATTERN * pattern, DUMBFILE * f, int num, int size, int pchans)
-{
-	int n, offset, psize, rows, chans, row, flags, channel;
-
-	unsigned char * buffer, * ptr, * end;
-
-	IT_ENTRY * entry;
-
-	buffer = malloc(size);
-	if (!buffer) goto error;
-
-    if (dumbfile_getnc((char *)buffer, size, f) < size) goto error_fb;
-
-	offset = 0;
-
-	for (n = 0; n < num; n++) {
-		IT_PATTERN * p = &pattern[n];
-
-		if (offset >= size) goto error_fb;
-
-		ptr = buffer + offset;
-		psize = ptr[0] | (ptr[1] << 8);
-		rows = ptr[2];
-		chans = ptr[3];
-
-		if (!rows || !chans) {
-			p->n_rows = 1;
-			p->n_entries = 0;
-			continue;
-		}
-
-		psize = (psize + 15) & ~15;
-
-		end = ptr + psize;
-		ptr += 4;
-
-		p->n_rows = rows;
-		p->n_entries = rows;
-		row = 0;
-
-		while ((row < rows) && (ptr < end)) {
-			flags = *ptr++;
-			if (!flags) {
-				row++;
-				continue;
-			}
-			if (flags & 0xE0) {
-				p->n_entries++;
-				if (flags & 0x80) ptr += 2;
-				if (flags & 0x40) ptr++;
-				if (flags & 0x20) {
-					ptr++;
-					if (*ptr == 40) ptr += 3;
-					else ptr++;
-				}
-			}
-		}
-
-		entry = malloc(p->n_entries * sizeof(*p->entry));
-		if (!entry) goto error_fb;
-
-		p->entry = entry;
-
-		ptr = buffer + offset + 4;
-		row = 0;
-
-		while ((row < rows) && (ptr < end)) {
-			flags = *ptr++;
-			if (!flags) {
-				IT_SET_END_ROW(entry);
-				entry++;
-				row++;
-				continue;
-			}
-			if (flags & 0xE0) {
-				entry->mask = 0;
-				entry->channel = channel = flags & 0x1F;
-				if (channel >= chans)
-				{
-					//channel = 0;
-					//goto error_fb;
-				}
-				if (flags & 0x80) {
-					if ((*ptr < 60) && (channel < pchans)) {
-						entry->mask |= IT_ENTRY_NOTE;
-						entry->note = *ptr + 35;
-					}
-					ptr++;
-					if (*ptr) {
-						entry->mask |= IT_ENTRY_INSTRUMENT;
-						entry->instrument = *ptr;
-					}
-					ptr++;
-				}
-				if (flags & 0x40) {
-					if (*ptr <= 64) {
-						entry->mask |= IT_ENTRY_VOLPAN;
-						entry->volpan = *ptr;
-					}
-					ptr++;
-				}
-				if (flags & 0x20) {
-					entry->mask |= IT_ENTRY_EFFECT;
-
-					switch (*ptr) {
-						case 1:
-							entry->effect = IT_XM_FINE_VOLSLIDE_UP;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 2:
-							entry->effect = IT_VOLUME_SLIDE;
-							entry->effectvalue = (ptr[1] << 4) & 0xF0;
-							break;
-
-						case 3:
-							entry->effect = IT_XM_FINE_VOLSLIDE_DOWN;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 4:
-							entry->effect = IT_VOLUME_SLIDE;
-							entry->effectvalue = ptr[1] & 0xF;
-							break;
-
-						case 10:
-							entry->effect = IT_PORTAMENTO_UP;
-							entry->effectvalue = EFFECT_VALUE(0xF, ptr[1]);
-							break;
-
-						case 11:
-							entry->effect = IT_PORTAMENTO_UP;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 12:
-							entry->effect = IT_PORTAMENTO_DOWN;
-							entry->effectvalue = EFFECT_VALUE(ptr[1], 0xF);
-							break;
-
-						case 13:
-							entry->effect = IT_PORTAMENTO_DOWN;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 14:
-							entry->effect = IT_TONE_PORTAMENTO;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 15:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_SET_GLISSANDO_CONTROL, ptr[1] & 15);
-							break;
-
-						case 16:
-							entry->effect = IT_VOLSLIDE_TONEPORTA;
-							entry->effectvalue = ptr[1] << 4;
-							break;
-
-						case 17:
-							entry->effect = IT_VOLSLIDE_TONEPORTA;
-							entry->effectvalue = ptr[1] & 0xF;
-							break;
-
-						case 20:
-							entry->effect = IT_VIBRATO;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 21:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_SET_VIBRATO_WAVEFORM, ptr[1] & 11);
-							break;
-
-						case 22:
-							entry->effect = IT_VOLSLIDE_VIBRATO;
-							entry->effectvalue = ptr[1] << 4;
-							break;
-
-						case 23:
-							entry->effect = IT_VOLSLIDE_VIBRATO;
-							entry->effectvalue = ptr[1] & 0xF;
-							break;
-
-						case 30:
-							entry->effect = IT_TREMOLO;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 31:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_SET_TREMOLO_WAVEFORM, ptr[1] & 11);
-							break;
-
-						case 40:
-							entry->effect = IT_SET_SAMPLE_OFFSET;
-							entry->effectvalue = ptr[2];
-							ptr += 2;
-							break;
-
-						case 41:
-							entry->effect = IT_XM_RETRIGGER_NOTE;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 42:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_DELAYED_NOTE_CUT, ptr[1] & 0xF);
-							break;
-
-						case 43:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_NOTE_DELAY, ptr[1] & 0xF);
-							break;
-
-						case 50:
-							entry->effect = IT_JUMP_TO_ORDER;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 51:
-							entry->effect = IT_BREAK_TO_ROW;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 52:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_PATTERN_LOOP, ptr[1] & 0xF);
-							break;
-
-						case 53:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_PATTERN_DELAY, ptr[1] & 0xF);
-							break;
-
-						case 60:
-							entry->effect = IT_SET_SPEED;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 61:
-							entry->effect = IT_SET_SONG_TEMPO;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 70:
-							entry->effect = IT_ARPEGGIO;
-							entry->effectvalue = ptr[1];
-							break;
-
-						case 71:
-							entry->effect = IT_S;
-							entry->effectvalue = EFFECT_VALUE(IT_S_FINETUNE, ptr[1] & 0xF);
-							break;
-
-						case 72:
-							/* "balance" ... panning? */
-							entry->effect = IT_SET_PANNING;
-							entry->effectvalue = ((ptr[1] - ((ptr[1] & 8) >> 3)) << 5) / 7;
-							break;
-
-						default:
-							entry->mask &= ~IT_ENTRY_EFFECT;
-					}
-
-					ptr += 2;
-				}
-				if (entry->mask) entry++;
-			}
-		}
-
-		p->n_entries = (int)(entry - p->entry);
-		offset += psize;
-	}
-
-	free(buffer);
-
-	return 0;
-
-error_fb:
-	free(buffer);
-error:
-	return -1;
-}
-
-#define PSM_COMPONENT_ORDERS            0
-#define PSM_COMPONENT_PANPOS            1
-#define PSM_COMPONENT_PATTERNS          2
-#define PSM_COMPONENT_SAMPLE_HEADERS    3
-#define PSM_COMPONENT_COMMENTS          4
-
-typedef struct PSM_COMPONENT
-{
-	unsigned char type;
-	long offset;
-}
-PSM_COMPONENT;
-
-static int psm_component_compare(const void *e1, const void *e2)
-{
-	return (int)(((const PSM_COMPONENT *)e1)->offset -
-	             ((const PSM_COMPONENT *)e2)->offset);
-}
-
-static DUMB_IT_SIGDATA *it_old_psm_load_sigdata(DUMBFILE *f)
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	PSM_COMPONENT *component;
-	int n_components = 0;
-
-	int n, flags, version, pver, n_orders, n_channels, total_pattern_size;
-
-	if (dumbfile_mgetl(f) != DUMB_ID('P','S','M',254)) goto error;
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) goto error;
-
-    if (dumbfile_getnc((char *)sigdata->name, 60, f) < 60 ||
-		sigdata->name[59] != 0x1A) goto error_sd;
-	sigdata->name[59] = 0;
-
-	flags = dumbfile_getc(f);
-	version = dumbfile_getc(f);
-	pver = dumbfile_getc(f);
-	sigdata->speed = dumbfile_getc(f);
-	sigdata->tempo = dumbfile_getc(f);
-	sigdata->mixing_volume = dumbfile_getc(f);
-	sigdata->n_orders = dumbfile_igetw(f);
-	n_orders = dumbfile_igetw(f);
-	sigdata->n_patterns = dumbfile_igetw(f);
-	sigdata->n_samples = dumbfile_igetw(f);
-	sigdata->n_pchannels = dumbfile_igetw(f);
-	n_channels = dumbfile_igetw(f);
-
-	if (dumbfile_error(f) ||
-		(flags & 1) ||
-		(version != 1 && version != 0x10) ||
-		(pver) ||
-		(sigdata->n_orders <= 0) ||
-		(sigdata->n_orders > 255) ||
-		(n_orders > 255) ||
-		(n_orders < sigdata->n_orders) ||
-		(sigdata->n_patterns > 255) ||
-		(sigdata->n_samples > 255) ||
-		(sigdata->n_pchannels > DUMB_IT_N_CHANNELS) ||
-		(sigdata->n_pchannels > n_channels) ||
-		(n_channels > DUMB_IT_N_CHANNELS))
-		goto error_sd;
-
-	sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX;
-
-	sigdata->global_volume = 128;
-	sigdata->pan_separation = 128;
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-
-	sigdata->restart_position = 0;
-
-	sigdata->order = malloc(sigdata->n_orders);
-	if (!sigdata->order) goto error_usd;
-
-	if (sigdata->n_samples) {
-		sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-		if (!sigdata->sample) goto error_usd;
-		for (n = 0; n < sigdata->n_samples; n++)
-			sigdata->sample[n].data = NULL;
-	}
-
-	if (sigdata->n_patterns) {
-		sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-		if (!sigdata->pattern) goto error_usd;
-		for (n = 0; n < sigdata->n_patterns; n++)
-			sigdata->pattern[n].entry = NULL;
-	}
-
-	component = malloc(5 * sizeof(*component));
-	if (!component) goto error_usd;
-
-	for (n = 0; n < 5; n++) {
-		component[n_components].offset = dumbfile_igetl(f);
-		if (component[n_components].offset) {
-			component[n_components].type = n;
-			n_components++;
-		}
-	}
-
-	if (!n_components) goto error_fc;
-
-	total_pattern_size = (int)dumbfile_igetl(f);
-	if (!total_pattern_size) goto error_fc;
-
-	qsort(component, n_components, sizeof(PSM_COMPONENT), &psm_component_compare);
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[n  ] = 32 - sep;
-		sigdata->channel_pan[n+1] = 32 + sep;
-		sigdata->channel_pan[n+2] = 32 + sep;
-		sigdata->channel_pan[n+3] = 32 - sep;
-	}
-
-	for (n = 0; n < n_components; n++)
-	{
-		int o;
-
-        if ( dumbfile_seek(f, component[n].offset, DFS_SEEK_SET) ) goto error_fc;
-
-		switch (component[n].type) {
-
-			case PSM_COMPONENT_ORDERS:
-                if (dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f) < sigdata->n_orders) goto error_fc;
-				if (n_orders > sigdata->n_orders)
-					if (dumbfile_skip(f, n_orders - sigdata->n_orders))
-                        goto error_fc;
-                if (dumbfile_igetw(f)) goto error_fc;
-				break;
-
-			case PSM_COMPONENT_PANPOS:
-                if (dumbfile_getnc((char *)sigdata->channel_pan, sigdata->n_pchannels, f) < sigdata->n_pchannels) goto error_fc;
-				for (o = 0; o < sigdata->n_pchannels; o++) {
-					sigdata->channel_pan[o] -= (sigdata->channel_pan[o] & 8) >> 3;
-					sigdata->channel_pan[o] = ((int)sigdata->channel_pan[o] << 5) / 7;
-				}
-				break;
-
-			case PSM_COMPONENT_PATTERNS:
-                if (it_old_psm_read_patterns(sigdata->pattern, f, sigdata->n_patterns, total_pattern_size, sigdata->n_pchannels)) goto error_fc;
-				break;
-
-			case PSM_COMPONENT_SAMPLE_HEADERS:
-                if (it_old_psm_read_samples(&sigdata->sample, f, &sigdata->n_samples)) goto error_fc;
-				break;
-
-			case PSM_COMPONENT_COMMENTS:
-				if (dumbfile_mgetl(f) == DUMB_ID('T','E','X','T')) {
-					o = dumbfile_igetw(f);
-					if (o > 0) {
-						sigdata->song_message = malloc(o + 1);
-                        if (dumbfile_getnc((char *)sigdata->song_message, o, f) < o) goto error_fc;
-						sigdata->song_message[o] = 0;
-					}
-				}
-				break;
-		}
-	}
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	free(component);
-
-	return sigdata;
-
-error_fc:
-	free(component);
-error_usd:
-	_dumb_it_unload_sigdata(sigdata);
-	return NULL;
-error_sd:
-	free(sigdata);
-error:
-	return NULL;
-}
-
-DUH *dumb_read_old_psm_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_old_psm_load_sigdata(f);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "PSM (old)";
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readpsm.c
+++ /dev/null
@@ -1,1289 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readpsm.c - Code to read a Protracker Studio       / / \  \
- *             module from an open file.             | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-#ifndef min
-#define min(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
-#ifdef _MSC_VER
-#define snprintf sprintf_s
-#endif
-
-#define PSMV_OLD 940730
-#define PSMV_NEW 940902
-
-typedef struct _PSMCHUNK
-{
-	int id;
-	int len;
-	unsigned char * data;
-} PSMCHUNK;
-
-typedef struct _PSMEVENT
-{
-	int type;
-	unsigned char data[8];
-} PSMEVENT;
-
-#define PSM_EVENT_END               0
-#define PSM_EVENT_PLAY_PATTERN      1
-#define PSM_EVENT_JUMP_TO_LINE      4
-#define PSM_EVENT_SET_SPEED         7
-#define PSM_EVENT_SET_BPM           8
-#define PSM_EVENT_SAMPLE_MAP_TABLE 12
-#define PSM_EVENT_CHANGE_PAN       13
-#define PSM_EVENT_CHANGE_VOL       14
-
-static int it_psm_process_sample(IT_SAMPLE * sample, const unsigned char * data, int len, int id, int version) {
-	int flags;
-	int insno;
-	int length;
-	int loopstart;
-	int loopend;
-	int panpos;
-	int defvol;
-	int samplerate;
-
-	if (len < 0x60) return -1;
-
-	flags = data[0];
-
-	if (version == PSMV_OLD) {
-		memcpy(sample->name, data + 0x0D, 34);
-		sample->name[34] = 0;
-
-		insno = data[0x34] | (data[0x35] << 8);
-		length = data[0x36] | (data[0x37] << 8) | (data[0x38] << 16) | (data[0x39] << 24);
-		loopstart = data[0x3A] | (data[0x3B] << 8) | (data[0x3C] << 16) | (data[0x3D] << 24);
-		loopend = data[0x3E] | (data[0x3F] << 8) | (data[0x40] << 16) | (data[0x41] << 24);
-		panpos = data[0x43];
-		defvol = data[0x44];
-		samplerate = data[0x49] | (data[0x4A] << 8) | (data[0x4B] << 16) | (data[0x4C] << 24);
-	} else /*if (version == PSMV_NEW)*/ {
-		memcpy(sample->name, data + 0x11, 34);
-		sample->name[34] = 0;
-
-		insno = data[0x38] | (data[0x39] << 8);
-		length = data[0x3A] | (data[0x3B] << 8) | (data[0x3C] << 16) | (data[0x3D] << 24);
-		loopstart = data[0x3E] | (data[0x3F] << 8) | (data[0x40] << 16) | (data[0x41] << 24);
-		loopend = data[0x42] | (data[0x43] << 8) | (data[0x44] << 16) | (data[0x45] << 24);
-		panpos = data[0x48];
-		defvol = data[0x49];
-		samplerate = data[0x4E] | (data[0x4F] << 8) | (data[0x50] << 16) | (data[0x51] << 24);
-	}
-
-	if (insno != id) return -1;
-
-	if (!length) {
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-		return 0;
-	}
-	
-	if ((length > len - 0x60) || ((flags & 0x7F) != 0)) return -1;
-
-	sample->flags = IT_SAMPLE_EXISTS;
-	sample->length = length;
-	sample->loop_start = loopstart;
-	sample->loop_end = loopend;
-	sample->C5_speed = samplerate;
-	sample->default_volume = defvol >> 1;
-	sample->default_pan = 0;
-	sample->filename[0] = 0;
-	sample->global_volume = 64;
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = IT_VIBRATO_SINE;
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	if (flags & 0x80) {
-		if (((unsigned int)sample->loop_end <= (unsigned int)sample->length) &&
-			((unsigned int)sample->loop_start < (unsigned int)sample->loop_end)) {
-			sample->length = sample->loop_end;
-			sample->flags |= IT_SAMPLE_LOOP;
-		}
-	}
-
-	sample->data = malloc(sample->length);
-	if (!sample->data)
-		return -1;
-
-	flags = 0;
-	data += 0x60;
-
-	for (insno = 0; insno < sample->length; insno++) {
-		flags += (signed char)(*data++);
-		((signed char *)sample->data)[insno] = flags;
-	}
-
-	return 0;
-}
-
-static int it_psm_process_pattern(IT_PATTERN * pattern, const unsigned char * data, int len, int speed, int bpm, const unsigned char * pan, const int * vol, int version) {
-	int length, nrows, row, rowlen, pos;
-	unsigned flags, chan;
-	IT_ENTRY * entry;
-
-	length = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
-	if (len > length) len = length;
-
-	if (version == PSMV_OLD) {
-		if (len < 10) return -1;
-		data += 8;
-		len -= 8;
-	} else /*if (version == PSMV_NEW)*/ {
-		if (len < 14) return -1;
-		data += 12;
-		len -= 12;
-	}
-
-	nrows = data[0] | (data[1] << 8);
-
-	if (!nrows) return 0;
-
-	pattern->n_rows = nrows;
-
-	data += 2;
-	len -= 2;
-
-	pattern->n_entries = 0;
-
-	row = 0;
-	pos = 2;
-	rowlen = data[0] | (data[1] << 8);
-
-	while ((row < nrows) && (pos < len)) {
-		if (pos >= rowlen) {
-			row++;
-			rowlen += data[pos] | (data[pos+1] << 8);
-			pos += 2;
-			continue;
-		}
-
-		flags = data[pos++];
-		chan = data[pos++];
-
-		if (chan > 63) return -1;
-
-		if (flags & 0xF0) {
-			pattern->n_entries++;
-			if (flags & 0x80) pos++;
-			if (flags & 0x40) pos++;
-			if (flags & 0x20) pos++;
-			if (flags & 0x10) {
-				switch (data[pos]) {
-					case 0x29:
-						pos++;
-					case 0x33:
-						pos++;
-					default:
-						pos += 2;
-				}
-			}
-		}
-	}
-
-	if (!pattern->n_entries) return 0;
-
-	pattern->n_entries += nrows;
-	if (speed) pattern->n_entries++;
-	if (bpm >= 0x20) pattern->n_entries++;
-
-	for (pos = 0; pos < 32; pos++) {
-		if (!(pan[pos*2+1] & 0xF9)) pattern->n_entries++;
-		if (vol[pos] != -1) pattern->n_entries++;
-	}
-
-	pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
-	if (!pattern->entry) return -1;
-
-	entry = pattern->entry;
-
-	if (speed) {
-		entry->channel = 0;
-		entry->mask = IT_ENTRY_EFFECT;
-		entry->effect = IT_SET_SPEED;
-		entry->effectvalue = speed;
-		entry++;
-	}
-
-	if (bpm >= 0x20) {
-		entry->channel = 0;
-		entry->mask = IT_ENTRY_EFFECT;
-		entry->effect = IT_SET_SONG_TEMPO;
-		entry->effectvalue = bpm;
-		entry++;
-	}
-
-	for (pos = 0; pos < 32; pos++) {
-		if (!(pan[pos*2+1] & 0xF9)) {
-			entry->channel = pos;
-			entry->mask = IT_ENTRY_EFFECT;
-			switch (pan[pos*2+1]) {
-			case 0:
-				entry->effect = IT_SET_PANNING;
-				entry->effectvalue = pan[pos*2] ^ 128;
-				break;
-			case 2:
-				entry->effect = IT_S;
-				entry->effectvalue = EFFECT_VALUE(IT_S_SET_SURROUND_SOUND,1);
-				break;
-			case 4:
-				entry->effect = IT_SET_PANNING;
-				entry->effectvalue = 128;
-				break;
-			}
-			entry++;
-		}
-		if (vol[pos] != -1) {
-			entry->channel = pos;
-			entry->mask = IT_ENTRY_EFFECT;
-			entry->effect = IT_SET_CHANNEL_VOLUME;
-			entry->effectvalue = (vol[pos] + 2) >> 2;
-			entry++;
-		}
-	}
-
-	row = 0;
-	pos = 2;
-	rowlen = data[0] | (data[1] << 8);
-
-	while ((row < nrows) && (pos < len)) {
-		if (pos >= rowlen) {
-			IT_SET_END_ROW(entry);
-			entry++;
-			row++;
-			rowlen += data[pos] | (data[pos+1] << 8);
-			pos += 2;
-			continue;
-		}
-
-		flags = data[pos++];
-		entry->channel = data[pos++];
-		entry->mask = 0;
-
-		if (flags & 0xF0) {
-			if (flags & 0x80) {
-				entry->mask |= IT_ENTRY_NOTE;
-				if (version == PSMV_OLD) {
-					if ((data[pos] < 0x80)) entry->note = (data[pos]>>4)*12+(data[pos]&0x0f)+12;
-					else entry->mask &= ~IT_ENTRY_NOTE;
-				} else /*if (version == PSMV_NEW)*/ {
-					if ((data[pos]) && (data[pos] < 84)) entry->note = data[pos] + 35;
-					else entry->mask &= ~IT_ENTRY_NOTE;
-				}
-				pos++;
-			}
-
-			if (flags & 0x40) {
-				entry->mask |= IT_ENTRY_INSTRUMENT;
-				entry->instrument = data[pos++] + 1;
-			}
-
-			if (flags & 0x20) {
-				entry->mask |= IT_ENTRY_VOLPAN;
-				entry->volpan = (data[pos++] + 1) >> 1;
-			}
-
-			if (flags & 0x10) {
-				entry->mask |= IT_ENTRY_EFFECT;
-				length = data[pos+1];
-				switch (data[pos]) {
-					case 1:
-						entry->effect = IT_VOLUME_SLIDE;
-						if (version == PSMV_OLD) entry->effectvalue = ((length&0x1e)<<3) | 0xF;
-						else /*if (version == PSMV_NEW)*/ entry->effectvalue = (length<<4) | 0xF;
-						break;
-
-					case 2:
-						entry->effect = IT_VOLUME_SLIDE;
-						if (version == PSMV_OLD) entry->effectvalue = (length << 3) & 0xF0;
-						else /*if (version == PSMV_NEW)*/ entry->effectvalue = (length << 4) & 0xF0;
-						break;
-
-					case 3:
-						entry->effect = IT_VOLUME_SLIDE;
-						if (version == PSMV_OLD) entry->effectvalue = (length >> 1) | 0xF0;
-						else /*if (version == PSMV_NEW)*/ entry->effectvalue = length | 0xF0;
-						break;
-
-					case 4:
-						entry->effect = IT_VOLUME_SLIDE;
-						if (version == PSMV_OLD) entry->effectvalue = (length >> 1) & 0xF;
-						else /*if (version == PSMV_NEW)*/ entry->effectvalue = length & 0xF;
-						break;
-
-					case 12:
-						entry->effect = IT_PORTAMENTO_UP;
-						if (version == PSMV_OLD) {
-							if (length < 4) entry->effectvalue = length | 0xF0;
-							else entry->effectvalue = length >> 2;
-						} else /*if (version == PSMV_NEW)*/ {
-							entry->effectvalue = length;
-						}
-						break;
-
-					case 14:
-						entry->effect = IT_PORTAMENTO_DOWN;
-						if (version == PSMV_OLD) {
-							if (length < 4) entry->effectvalue = length | 0xF0;
-							else entry->effectvalue = length >> 2;
-						} else /*if (version == PSMV_NEW)*/ {
-							entry->effectvalue = length;
-						}
-						break;
-
-					case 15:
-						entry->effect = IT_TONE_PORTAMENTO;
-						if (version == PSMV_OLD) entry->effectvalue = length >> 2;
-						else /*if (version == PSMV_NEW)*/ entry->effectvalue = length;
-						break;
-
-					case 0x15:
-						entry->effect = IT_VIBRATO;
-						entry->effectvalue = length;
-						break;
-
-					case 0x18:
-						entry->effect = IT_VOLSLIDE_VIBRATO;
-						entry->effectvalue = length;
-						break;
-
-					case 0x29:
-						entry->effect = IT_SET_SAMPLE_OFFSET;
-						entry->effectvalue = data[pos+2];
-						pos += 2;
-						break;
-
-					case 0x2A:
-						entry->effect = IT_RETRIGGER_NOTE;
-						entry->effectvalue = length;
-						break;
-
-					case 0x33:
-#if 0
-						entry->effect = IT_POSITION_JUMP;
-						entry->effectvalue = data[pos+2];
-#else
-						entry->mask &= ~IT_ENTRY_EFFECT;
-#endif
-						pos++;
-						break;
-
-					case 0x34:
-						entry->effect = IT_BREAK_TO_ROW;
-						entry->effectvalue = length;
-						break;
-
-					case 0x3D:
-						entry->effect = IT_SET_SPEED;
-						entry->effectvalue = length;
-						break;
-
-					case 0x3E:
-						if (length >= 0x20) {
-							entry->effect = IT_SET_SONG_TEMPO;
-							entry->effectvalue = length;
-						} else {
-							entry->mask &= ~IT_ENTRY_EFFECT;
-						}
-						break;
-
-					case 0x47:
-						entry->effect = IT_ARPEGGIO;
-						entry->effectvalue = length;
-						break;
-
-					default:
-						return -1;
-				}
-				pos += 2;
-			}
-			if (entry->mask) entry++;
-		}
-	}
-
-	while (row < nrows) {
-		IT_SET_END_ROW(entry);
-		entry++;
-		row++;
-	}
-
-	pattern->n_entries = entry - pattern->entry;
-	if (!pattern->n_entries) return -1;
-
-	return 0;
-}
-
-
-static void free_chunks(PSMCHUNK * chunk, int count) {
-	int n;
-
-	for (n = 0; n < count; n++) {
-		if (chunk[n].data)
-			free(chunk[n].data);
-	}
-
-	free(chunk);
-}
-
-static void dumb_it_optimize_orders(DUMB_IT_SIGDATA * sigdata);
-
-static int pattcmp( const unsigned char *, const unsigned char *, size_t );
-
-static DUMB_IT_SIGDATA *it_psm_load_sigdata(DUMBFILE *f, int * ver, int subsong)
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	PSMCHUNK *chunk;
-	int n_chunks = 0;
-
-	PSMCHUNK *songchunk;
-	int n_song_chunks = 0;
-
-	PSMEVENT *event = 0;
-	int n_events = 0;
-
-	unsigned char * ptr;
-
-	int n, length, o;
-
-	int found;
-
-	int n_patterns = 0;
-
-	int first_pattern_line = -1;
-	int first_pattern;
-
-	int speed, bpm;
-	unsigned char pan[64];
-	int vol[32];
-
-	if (dumbfile_mgetl(f) != DUMB_ID('P','S','M',' ')) goto error;
-
-	length = dumbfile_igetl(f);
-
-	if (dumbfile_mgetl(f) != DUMB_ID('F','I','L','E')) goto error;
-
-	chunk = calloc(768, sizeof(*chunk));
-
-	while (length >= 8) {
-		chunk[n_chunks].id = dumbfile_mgetl(f);
-		n = dumbfile_igetl(f);
-		length -= 8;
-		if (n < 0 || n > length)
-			goto error_fc;
-		chunk[n_chunks].len = n;
-		if (n) {
-			ptr = malloc(n);
-			if (!ptr) goto error_fc;
-            if (dumbfile_getnc((char *)ptr, n, f) < n)
-			{
-				free(ptr);
-				goto error_fc;
-			}
-			chunk[n_chunks].data = ptr;
-		}
-		n_chunks++;
-		length -= n;
-	}
-
-	if (!n_chunks) goto error_fc;
-				
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) goto error_fc;
-
-	sigdata->n_patterns = 0;
-	sigdata->n_samples = 0;
-	sigdata->name[0] = 0;
-
-	found = 0;
-
-	for (n = 0; n < n_chunks; n++) {
-		PSMCHUNK * c = &chunk[n];
-		switch(c->id) {
-		case DUMB_ID('S','D','F','T'):
-			/* song data format? */
-			if ((found & 1) || (c->len != 8) || memcmp(c->data, "MAINSONG", 8)) goto error_sd;
-			found |= 1;
-			break;
-
-		case DUMB_ID('S','O','N','G'):
-			if (/*(found & 2) ||*/ (c->len < 11) /*|| memcmp(c->data, "MAINSONG", 8)*/) goto error_sd;
-			found |= 2;
-			break;
-
-		case DUMB_ID('D','S','M','P'):
-			sigdata->n_samples++;
-			break;
-
-		case DUMB_ID('T','I','T','L'):
-            length = min(sizeof(sigdata->name) - 1, (unsigned)c->len);
-			memcpy(sigdata->name, c->data, length);
-			sigdata->name[length] = 0;
-		}
-	}
-
-	if (found != 3 || !sigdata->n_samples) goto error_sd;
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-	sigdata->n_orders = 0;
-
-	for (n = 0; n < n_chunks; n++) {
-		PSMCHUNK * c = &chunk[n];
-		if (c->id == DUMB_ID('S','O','N','G')) {
-			if (subsong == 0) break;
-			subsong--;
-		}
-	}
-
-	if (n == n_chunks) return NULL;
-	subsong = n;
-
-	/*for (n = 0; n < n_chunks; n++) {
-		PSMCHUNK * c = &chunk[n];
-		if (c->id == DUMB_ID('S','O','N','G')) {*/
-	{
-		PSMCHUNK * c = &chunk[subsong];
-		{
-			ptr = c->data;
-			if (ptr[10] > 32) goto error_usd;
-			sigdata->n_pchannels = ptr[10];
-			length = c->len - 11;
-			ptr += 11;
-			songchunk = 0;
-			if (length >= 8) {
-				songchunk = malloc(128 * sizeof(*songchunk));
-				if (!songchunk) goto error_usd;
-				while (length >= 8) {
-					songchunk[n_song_chunks].id = DUMB_ID(ptr[0], ptr[1], ptr[2], ptr[3]);
-					n = ptr[4] | (ptr[5] << 8) | (ptr[6] << 16) | (ptr[7] << 24);
-					length -= 8;
-					if (n > length) goto error_sc;
-					songchunk[n_song_chunks].len = n;
-					songchunk[n_song_chunks].data = ptr + 8;
-					n_song_chunks++;
-					length -= n;
-					ptr += 8 + n;
-				}
-			}
-			/*break;*/
-		}
-	}
-
-	if (!n_song_chunks) goto error_sc;
-
-	found = 0;
-
-	for (n = 0; n < n_song_chunks; n++) {
-		PSMCHUNK * c = &songchunk[n];
-
-		if (c->id == DUMB_ID('D','A','T','E')) {
-			/* date of the library build / format spec */
-			if (c->len == 6) {
-				length = c->len;
-				ptr = c->data;
-				while (length > 0) {
-					if (*ptr >= '0' && *ptr <= '9') {
-						found = (found * 10) + (*ptr - '0');
-					} else {
-						found = 0;
-						break;
-					}
-					ptr++;
-					length--;
-				}
-			}
-			break;
-		}
-	}
-
-	/*
-	if (found != 940506 &&
-		found != 940509 &&
-		found != 940510 &&
-		found != 940530 &&
-		found != 940629 &&
-		found != PSMV_OLD &&
-		found != 941011 &&
-		found != PSMV_NEW &&
-		found != 940906 &&
-		found != 940903 &&
-		found != 940914 &&
-		found != 941213 &&
-        found != 800211)    WTF?
-		goto error_sc;
-	*/
-
-	*ver = found;
-
-	if (found == 800211 ||
-		found == PSMV_NEW ||
-		found == 940903 ||
-		found == 940906 ||
-		found == 940914 ||
-		found == 941213) found = PSMV_NEW;
-	else found = PSMV_OLD;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-
-	for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
-		int sep = 32 * dumb_it_default_panning_separation / 100;
-		sigdata->channel_pan[n  ] = 32 - sep;
-		sigdata->channel_pan[n+1] = 32 + sep;
-		sigdata->channel_pan[n+2] = 32 + sep;
-		sigdata->channel_pan[n+3] = 32 - sep;
-	}
-
-	for (n = 0; n < n_song_chunks; n++) {
-		PSMCHUNK * c = &songchunk[n];
-
-		switch (c->id) {
-			case DUMB_ID('O','P','L','H'):
-				if (c->len < 2) goto error_sc;
-				ptr = c->data;
-				o = ptr[0] | (ptr[1] << 8);
-				if (!o) goto error_sc;
-				event = malloc(o * sizeof(*event));
-				if (!event) goto error_sc;
-				length = c->len - 2;
-				ptr += 2;
-				while ((length > 0) && (n_events < o)) {
-					event[n_events].type = *ptr;
-					switch (*ptr) {
-					case PSM_EVENT_END:
-						ptr++;
-						length--;
-						break;
-
-					case PSM_EVENT_PLAY_PATTERN:
-						if (found == PSMV_OLD) {
-							if (length < 5) goto error_ev;
-							memcpy(event[n_events].data, ptr + 1, 4);
-							ptr += 5;
-							length -= 5;
-						} else /*if (found == PSMV_NEW)*/ {
-							if (length < 9) goto error_ev;
-							memcpy(event[n_events].data, ptr + 1, 8);
-							ptr += 9;
-							length -= 9;
-						}
-						break;
-
-					case PSM_EVENT_SET_SPEED:
-					case PSM_EVENT_SET_BPM:
-						if (length < 2) goto error_ev;
-						event[n_events].data[0] = ptr[1];
-						ptr += 2;
-						length -= 2;
-						break;
-
-					case PSM_EVENT_JUMP_TO_LINE:
-					case PSM_EVENT_CHANGE_VOL:
-						if (length < 3) goto error_ev;
-						memcpy(event[n_events].data, ptr + 1, 2);
-						ptr += 3;
-						length -= 3;
-						break;
-
-					case PSM_EVENT_SAMPLE_MAP_TABLE:
-						if (length < 7) goto error_ev;
-						memcpy(event[n_events].data, ptr + 1, 6);
-						ptr += 7;
-						length -= 7;
-						break;
-
-					case PSM_EVENT_CHANGE_PAN:
-						if (length < 4) goto error_ev;
-						memcpy(event[n_events].data, ptr + 1, 3);
-						ptr += 4;
-						length -= 4;
-						break;
-
-					default:
-						goto error_ev;
-					}
-					n_events++;
-				}
-				break;
-
-			case DUMB_ID('P','P','A','N'):
-				length = c->len;
-				if (length & 1) goto error_ev;
-				ptr = c->data;
-				o = 0;
-				while (length > 0) {
-					switch (ptr[0]) {
-					case 0:
-						sigdata->channel_pan[o] = ((((int)(signed char)ptr[1]) * 32) / 127) + 32;
-						break;
-					case 2:
-						sigdata->channel_pan[o] = IT_SURROUND;
-						break;
-					case 4:
-						sigdata->channel_pan[o] = 32;
-						break;
-					}
-					ptr += 2;
-					length -= 2;
-					if (++o >= DUMB_IT_N_CHANNELS) break;
-				}
-				break;
-
-			/*
-			case DUMB_ID('P','A','T','T'):
-			case DUMB_ID('D','S','A','M'):
-			*/
-		}
-	}
-
-	sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX;
-
-	sigdata->global_volume = 128;
-	sigdata->speed = 6;
-	sigdata->tempo = 125;
-	sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	speed = 0;
-	bpm = 0;
-	memset(pan, 255, sizeof(pan));
-	memset(vol, 255, sizeof(vol));
-
-	sigdata->n_patterns = n_events;
-	sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-	if (!sigdata->pattern) goto error_ev;
-	for (n = 0; n < sigdata->n_patterns; n++)
-		sigdata->pattern[n].entry = NULL;
-
-	for (n = 0; n < n_events; n++) {
-		PSMEVENT * e = &event[n];
-		switch (e->type) {
-		case PSM_EVENT_END:
-			n = n_events;
-			break;
-
-		case PSM_EVENT_PLAY_PATTERN:
-			for (o = 0; o < n_chunks; o++) {
-				PSMCHUNK * c = &chunk[o];
-				if (c->id == DUMB_ID('P','B','O','D')) {
-					ptr = c->data;
-					length = c->len;
-					if (found == PSMV_OLD) {
-						if (length < 8) goto error_ev;
-						if (!pattcmp(ptr + 4, e->data, 4)) {
-							if (it_psm_process_pattern(&sigdata->pattern[n_patterns], ptr, length, speed, bpm, pan, vol, found)) goto error_ev;
-							if (first_pattern_line < 0) {
-								first_pattern_line = n;
-								first_pattern = o;
-							}
-							e->data[0] = n_patterns;
-							e->data[1] = n_patterns >> 8;
-							n_patterns++;
-							break;
-						}
-					} else /*if (found == PSMV_NEW)*/ {
-						if (length < 12) goto error_ev;
-						if (!pattcmp(ptr + 4, e->data, 8)) {
-							if (it_psm_process_pattern(&sigdata->pattern[n_patterns], ptr, length, speed, bpm, pan, vol, found)) goto error_ev;
-							if (first_pattern_line < 0) {
-								first_pattern_line = n;
-								first_pattern = o;
-							}
-							e->data[0] = n_patterns;
-							e->data[1] = n_patterns >> 8;
-							n_patterns++;
-							break;
-						}
-					}
-				}
-			}
-			if (o == n_chunks) goto error_ev;
-
-			speed = 0;
-			bpm = 0;
-			memset(pan, 255, sizeof(pan));
-			memset(vol, 255, sizeof(vol));
-
-			e->type = PSM_EVENT_END;
-			break;
-
-		case PSM_EVENT_JUMP_TO_LINE:
-			o = e->data[0] | (e->data[1] << 8);
-			if (o >= n_events) goto error_ev;
-			if (o == 0) {
-				/* whew! easy case! */
-				sigdata->restart_position = 0;
-				n = n_events;
-			} else if (o == n) {
-				/* freeze */
-				n = n_events;
-			} else if (o > n) {
-				/* jump ahead, setting played event numbers to zero will prevent endless looping */
-				n = o - 1;
-			} else if (o >= first_pattern_line) {
-				/* another semi-easy case */
-				sigdata->restart_position = event[o].data[0] | (event[o].data[1] << 8);
-				n = n_events;
-			} else {
-				/* crud, try to simulate rerunning all of the commands from the indicated
-				 * line up to the first pattern, then dupe the first pattern again.
-				 */
-				/*
-				PSMCHUNK * c = &chunk[first_pattern];
-
-				for (; o < first_pattern_line; o++) {
-					PSMEVENT * ev = &event[o];
-					switch (ev->type) {
-					case PSM_EVENT_SET_SPEED:
-						speed = ev->data[0];
-						break;
-					case PSM_EVENT_SET_BPM:
-						bpm = ev->data[0];
-						break;
-					case PSM_EVENT_CHANGE_PAN:
-						if (ev->data[0] > 31) goto error_ev;
-						pan[ev->data[0] * 2] = ev->data[1];
-						pan[ev->data[0] * 2 + 1] = ev->data[2];
-						break;
-					case PSM_EVENT_CHANGE_VOL:
-						if (ev->data[0] > 31) goto error_ev;
-						vol[ev->data[0]] = ev->data[1];
-						break;
-					}
-				}
-
-				if (it_psm_process_pattern(&sigdata->pattern[n_patterns], c->data, c->len, speed, bpm, pan, vol, found)) goto error_ev;
-				n_patterns++;
-				sigdata->restart_position = 1;
-				n = n_events;
-
-				Eh, what the hell? PSM has no panning commands anyway.
-				*/
-				sigdata->restart_position = 0;
-				n = n_events;
-			}
-			e->type = PSM_EVENT_END;
-			break;
-
-		case PSM_EVENT_SET_SPEED:
-			speed = e->data[0];
-			break;
-
-		case PSM_EVENT_SET_BPM:
-			bpm = e->data[0];
-			break;
-
-		case PSM_EVENT_CHANGE_PAN:
-			o = e->data[0];
-			if (o > 31) goto error_ev;
-			pan[o * 2] = e->data[1];
-			pan[o * 2 + 1] = e->data[2];
-			break;
-
-		case PSM_EVENT_CHANGE_VOL:
-			o = e->data[0];
-			if (o > 31) goto error_ev;
-			vol[o] = e->data[1];
-			break;
-
-		case PSM_EVENT_SAMPLE_MAP_TABLE:
-			if (e->data[0] != 0 || e->data[1] != 0xFF ||
-				e->data[2] != 0 || e->data[3] != 0 ||
-				e->data[4] != 1 || e->data[5] != 0)
-				goto error_ev;
-			break;
-		}
-	}
-
-	if (n_patterns > 256) goto error_ev;
-
-	sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-	if (!sigdata->sample) goto error_ev;
-	for (n = 0; n < sigdata->n_samples; n++) {
-		sigdata->sample[n].data = NULL;
-		sigdata->sample[n].flags = 0;
-	}
-
-	o = 0;
-	for (n = 0; n < n_chunks; n++) {
-		PSMCHUNK * c = &chunk[n];
-		if (c->id == DUMB_ID('D','S','M','P')) {
-			if (it_psm_process_sample(&sigdata->sample[o], c->data, c->len, o, found)) goto error_ev;
-			o++;
-		}
-	}
-
-	sigdata->n_orders = n_patterns;
-	sigdata->n_patterns = n_patterns;
-
-	sigdata->order = malloc(n_patterns);
-
-	for (n = 0; n < n_patterns; n++) {
-		sigdata->order[n] = n;
-	}
-
-	free(event);
-	free(songchunk);
-	free_chunks(chunk, n_chunks);
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	dumb_it_optimize_orders(sigdata);
-
-	return sigdata;
-
-error_ev:
-	free(event);
-error_sc:
-	if (songchunk) free(songchunk);
-error_usd:
-	_dumb_it_unload_sigdata(sigdata);
-	goto error_fc;
-error_sd:
-	free(sigdata);
-error_fc:
-	free_chunks(chunk, n_chunks);
-error:
-	return NULL;
-}
-
-static int it_order_compare(const void *e1, const void *e2) {
-	if (*((const char *)e1) < *((const char *)e2))
-		return -1;
-
-	if (*((const char *)e1) > *((const char *)e2))
-		return 1;
-
-	return 0;
-}
-
-/*
-static int it_optimize_compare(const void *e1, const void *e2) {
-	if (((const IT_ENTRY *)e1)->channel < ((const IT_ENTRY *)e2)->channel)
-		return -1;
-
-	if (((const IT_ENTRY *)e1)->channel > ((const IT_ENTRY *)e2)->channel)
-		return 1;
-
-	return 0;
-}
-*/
-
-static int it_entry_compare(const IT_ENTRY * e1, const IT_ENTRY * e2) {
-	if (IT_IS_END_ROW(e1) && IT_IS_END_ROW(e2)) return 1;
-	if (e1->channel != e2->channel) return 0;
-	if (e1->mask != e2->mask) return 0;
-	if ((e1->mask & IT_ENTRY_NOTE) && (e1->note != e2->note)) return 0;
-	if ((e1->mask & IT_ENTRY_INSTRUMENT) && (e1->instrument != e2->instrument)) return 0;
-	if ((e1->mask & IT_ENTRY_VOLPAN) && (e1->volpan != e2->volpan)) return 0;
-	if ((e1->mask & IT_ENTRY_EFFECT) && ((e1->effect != e2->effect) || (e1->effectvalue != e2->effectvalue))) return 0;
-	return 1;
-}
-
-/*
-static void dumb_it_optimize_pattern(IT_PATTERN * pattern) {
-	IT_ENTRY * entry, * end;
-	IT_ENTRY * rowstart, * rowend;
-	IT_ENTRY * current;
-
-	if (!pattern->n_entries || !pattern->entry) return;
-
-	current = entry = pattern->entry;
-	end = entry + pattern->n_entries;
-
-	while (entry < end) {
-		rowstart = entry;
-		while (!IT_IS_END_ROW(entry)) entry++;
-		rowend = entry;
-		if (rowend > rowstart + 1)
-			qsort(rowstart, rowend - rowstart, sizeof(IT_ENTRY), &it_optimize_compare);
-		entry = rowstart;
-		while (entry < rowend) {
-			if (!(entry->mask)) {}
-			else if (it_entry_compare(entry, current)) {}
-			else if (!(current->mask) ||
-					 ((entry->channel == current->channel) &&
-					 ((entry->mask | current->mask) == (entry->mask ^ current->mask)))) {
-				current->mask |= entry->mask;
-				if (entry->mask & IT_ENTRY_NOTE) current->note = entry->note;
-				if (entry->mask & IT_ENTRY_INSTRUMENT) current->instrument = entry->instrument;
-				if (entry->mask & IT_ENTRY_VOLPAN) current->volpan = entry->volpan;
-				if (entry->mask & IT_ENTRY_EFFECT) {
-					current->effect = entry->effect;
-					current->effectvalue = entry->effectvalue;
-				}
-			} else {
-				if (++current < entry) *current = *entry;
-			}
-			entry++;
-		}
-		if (++current < entry) *current = *entry;
-		entry++;
-	}
-
-	current++;
-
-	if (current < end) {
-		IT_ENTRY * opt;
-		pattern->n_entries = current - pattern->entry;
-		opt = realloc(pattern->entry, pattern->n_entries * sizeof(*pattern->entry));
-		if (opt) pattern->entry = opt;
-	}
-}
-*/
-
-static int it_pattern_compare(const IT_PATTERN * p1, const IT_PATTERN * p2) {
-	IT_ENTRY * e1, * end;
-	IT_ENTRY * e2;
-
-	if (p1 == p2) return 1;
-	if (p1->n_entries != p2->n_entries) return 0;
-	
-	e1 = p1->entry; end = e1 + p1->n_entries;
-	e2 = p2->entry;
-
-	while (e1 < end) {
-		if (!it_entry_compare(e1, e2)) return 0;
-		e1++; e2++;
-	}
-
-	return 1;
-}
-
-static void dumb_it_optimize_orders(DUMB_IT_SIGDATA * sigdata) {
-	int n, o, p;
-
-    /*int last_invalid = (sigdata->flags & IT_WAS_AN_XM) ? 255 : 253;*/
-
-	unsigned char * order_list;
-	int n_patterns;
-
-	IT_PATTERN * pattern;
-
-	if (!sigdata->n_orders || !sigdata->n_patterns) return;
-
-	n_patterns = 0;
-	order_list = malloc(sigdata->n_orders);
-
-	if (!order_list) return;
-
-	for (n = 0; n < sigdata->n_orders; n++) {
-		if (sigdata->order[n] < sigdata->n_patterns) {
-			for (o = 0; o < n_patterns; o++) {
-				if (sigdata->order[n] == order_list[o]) break;
-			}
-			if (o == n_patterns) {
-				order_list[n_patterns++] = sigdata->order[n];
-			}
-		}
-	}
-
-	if (!n_patterns) {
-		free(order_list);
-		return;
-	}
-
-	/*for (n = 0; n < n_patterns; n++) {
-		dumb_it_optimize_pattern(&sigdata->pattern[order_list[n]]);
-	}*/
-
-	for (n = 0; n < n_patterns; n++) {
-		for (o = n + 1; o < n_patterns; o++) {
-			if ((order_list[n] != order_list[o]) &&
-				it_pattern_compare(&sigdata->pattern[order_list[n]], &sigdata->pattern[order_list[o]])) {
-				for (p = 0; p < sigdata->n_orders; p++) {
-					if (sigdata->order[p] == order_list[o]) {
-						sigdata->order[p] = order_list[n];
-					}
-				}
-				for (p = o + 1; p < n_patterns; p++) {
-					if (order_list[p] == order_list[o]) {
-						order_list[p] = order_list[n];
-					}
-				}
-				order_list[o] = order_list[n];
-			}
-		}
-	}
-
-	qsort(order_list, n_patterns, sizeof(*order_list), &it_order_compare);
-
-	for (n = 0, o = 0; n < n_patterns; n++) {
-		if (order_list[n] != order_list[o]) {
-			if (++o < n) order_list[o] = order_list[n];
-		}
-	}
-
-	n_patterns = o + 1;
-
-	pattern = malloc(n_patterns * sizeof(*pattern));
-	if (!pattern) {
-		free(order_list);
-		return;
-	}
-
-	for (n = 0; n < n_patterns; n++) {
-		pattern[n] = sigdata->pattern[order_list[n]];
-	}
-
-	for (n = 0; n < sigdata->n_patterns; n++) {
-		for (o = 0; o < n_patterns; o++) {
-			if (order_list[o] == n) break;
-		}
-		if (o == n_patterns) {
-			if (sigdata->pattern[n].entry)
-				free(sigdata->pattern[n].entry);
-		}
-	}
-
-	free(sigdata->pattern);
-	sigdata->pattern = pattern;
-	sigdata->n_patterns = n_patterns;
-
-	for (n = 0; n < sigdata->n_orders; n++) {
-		for (o = 0; o < n_patterns; o++) {
-			if (sigdata->order[n] == order_list[o]) {
-				sigdata->order[n] = o;
-				break;
-			}
-		}
-	}
-
-	free(order_list);
-}
-
-int dumb_get_psm_subsong_count(DUMBFILE *f) {
-	int length, subsongs;
-	long l;
-	
-	if (dumbfile_mgetl(f) != DUMB_ID('P','S','M',' ')) return 0;
-
-	length = dumbfile_igetl(f);
-
-	if (dumbfile_mgetl(f) != DUMB_ID('F','I','L','E')) return 0;
-
-	subsongs = 0;
-
-	while (length >= 8 && !dumbfile_error(f)) {
-		if (dumbfile_mgetl(f) == DUMB_ID('S','O','N','G')) subsongs++;
-		l = dumbfile_igetl(f);
-		dumbfile_skip(f, l);
-		length -= l + 8;
-	}
-
-	if (dumbfile_error(f)) return 0;
-
-	return subsongs;
-}
-
-
-
-/* Eww */
-int pattcmp( const unsigned char * a, const unsigned char * b, size_t l )
-{
-    size_t i, j, na, nb;
-	char * p;
-
-	na = nb = 0;
-
-	i = memcmp( a, b, l );
-	if ( !i ) return i;
-
-	/* damnit */
-
-	for ( i = 0; i < l; ++i )
-	{
-		if ( a [i] >= '0' && a [i] <= '9' ) break;
-	}
-
-	if ( i < l )
-	{
-		na = strtoul( (const char *)a + i, &p, 10 );
-		if ( (const unsigned char *)p == a + i ) return 1;
-	}
-
-	for ( j = 0; j < l; ++j )
-	{
-		if ( b [j] >= '0' && b [j] <= '9' ) break;
-	}
-
-	if ( j < l )
-	{
-		nb = strtoul( (const char *)b + j, &p, 10 );
-		if ( (const unsigned char *)p == b + j ) return -1;
-	}
-
-	if ( i < j ) return -1;
-	else if ( i > j ) return 1;
-
-	i = memcmp( a, b, j );
-	if ( i ) return i;
-
-	return na - nb;
-}
-
-
-
-DUH *dumb_read_psm_quick(DUMBFILE *f, int subsong)
-{
-	sigdata_t *sigdata;
-	int ver;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_psm_load_sigdata(f, &ver, subsong);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		int n_tags = 2;
-		char version[16];
-		const char *tag[3][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "PSM";
-		if ( ver )
-		{
-			tag[2][0] = "FORMATVERSION";
-            snprintf( version, 15, "%d", ver );
-            version[15] = 0;
-			tag[2][1] = (const char *) &version;
-			++n_tags;
-		}
-		return make_duh(-1, n_tags, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readptm.c
+++ /dev/null
@@ -1,554 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readptm.c - Code to read a Poly Tracker v2.03      / / \  \
- *             module from an open file.             | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller. Based on reads3m.c               \_  /  > /
- * by entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-// IT_STEREO... :o
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-
-
-static int it_ptm_read_sample_header(IT_SAMPLE *sample, long *offset, DUMBFILE *f)
-{
-	int flags;
-
-	flags = dumbfile_getc(f);
-
-    dumbfile_getnc((char *)sample->filename, 12, f);
-	sample->filename[12] = 0;
-
-	sample->default_volume = dumbfile_getc(f);
-
-	sample->C5_speed = dumbfile_igetw(f) << 1;
-
-	dumbfile_skip(f, 2); /* segment */
-
-	*offset = dumbfile_igetl(f);
-
-	sample->length = dumbfile_igetl(f);
-	sample->loop_start = dumbfile_igetl(f);
-	sample->loop_end = dumbfile_igetl(f);
-
-	/* GUSBegin, GUSLStart, GUSLEnd, GUSLoop, reserverd */
-	dumbfile_skip(f, 4+4+4+1+1);
-
-    dumbfile_getnc((char *)sample->name, 28, f);
-	sample->name[28] = 0;
-
-	/*
-	if (dumbfile_mgetl(f) != DUMB_ID('P','T','M','S'))
-		return -1;
-	*/
-
-	/* BLAH! Shit likes to have broken or missing sample IDs */
-	dumbfile_skip(f, 4);
-
-	if ((flags & 3) == 0) {
-		/* Looks like no sample */
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-		return dumbfile_error(f);
-	}
-
-	sample->global_volume = 64;
-
-	sample->flags = IT_SAMPLE_EXISTS;
-	if (flags & 4) sample->flags |= IT_SAMPLE_LOOP;
-	if (flags & 8) sample->flags |= IT_SAMPLE_PINGPONG_LOOP;
-
-	if (flags & 16) {
-		sample->flags |= IT_SAMPLE_16BIT;
-
-		sample->length >>= 1;
-		sample->loop_start >>= 1;
-		sample->loop_end >>= 1;
-	}
-
-	if (sample->loop_end) sample->loop_end--;
-
-	sample->default_pan = 0; // 0 = don't use, or 160 = centre?
-
-	if (sample->length <= 0)
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-	else if (sample->flags & IT_SAMPLE_LOOP) {
-		if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
-			sample->flags &= ~IT_SAMPLE_LOOP;
-		else if ((unsigned int)sample->loop_start >= (unsigned int)sample->loop_end)
-			sample->flags &= ~IT_SAMPLE_LOOP;
-		else
-			sample->length = sample->loop_end;
-	}
-
-
-	//Do we need to set all these?
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = IT_VIBRATO_SINE;
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-
-static int it_ptm_read_byte(DUMBFILE *f)
-{
-	int meh = dumbfile_getc(f);
-	if (meh < 0) return 0;
-	return meh;
-}
-
-static int it_ptm_read_sample_data(IT_SAMPLE *sample, int last, DUMBFILE *f)
-{
-	long n;
-	int s;
-
-	sample->data = malloc(sample->length * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
-	if (!sample->data)
-		return -1;
-
-	s = 0;
-
-	if (sample->flags & IT_SAMPLE_16BIT) {
-		unsigned char a, b;
-		for (n = 0; n < sample->length; n++) {
-			a = s += (signed char) it_ptm_read_byte(f);
-			b = s += (signed char) it_ptm_read_byte(f);
-			((short *)sample->data)[n] = a | (b << 8);
-		}
-	} else {
-		for (n = 0; n < sample->length; n++) {
-			s += (signed char) it_ptm_read_byte(f);
-			((signed char *)sample->data)[n] = s;
-		}
-	}
-
-	if (dumbfile_error(f) && !last)
-		return -1;
-
-	return 0;
-}
-
-
-
-static int it_ptm_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, unsigned char *buffer, int length)
-{
-	int buflen = 0;
-	int bufpos = 0;
-	int effect, effectvalue;
-
-	IT_ENTRY *entry;
-
-	unsigned char channel;
-
-	if (!length)
-		return -1;
-
-	pattern->n_rows = 0;
-	pattern->n_entries = 0;
-
-	/* Read in the pattern data, little by little, and work out how many
-	 * entries we need room for. Sorry, but this is just so funny...
-	 */
-	for (;;) {
-		unsigned char b = buffer[buflen++] = dumbfile_getc(f);
-
-#if 1
-		static const unsigned char used[8] = {0, 2, 2, 4, 1, 3, 3, 5};
-		channel = b & 31;
-		b >>= 5;
-		pattern->n_entries++;
-		if (b) {
-			if (buflen + used[b] >= 65536) return -1;
-            dumbfile_getnc((char *)buffer + buflen, used[b], f);
-			buflen += used[b];
-		} else {
-			/* End of row */
-			if (++pattern->n_rows == 64) break;
-			if (buflen >= 65536) return -1;
-		}
-#else
-		if (b == 0) {
-			/* End of row */
-			pattern->n_entries++;
-			if (++pattern->n_rows == 64) break;
-			if (buflen >= 65536) return -1;
-		} else {
-			static const unsigned char used[8] = {0, 2, 2, 4, 1, 3, 3, 5};
-			channel = b & 31;
-			b >>= 5;
-			if (b) {
-				pattern->n_entries++;
-				if (buflen + used[b] >= 65536) return -1;
-				dumbfile_getnc(buffer + buflen, used[b], f);
-				buflen += used[b];
-			}
-		}
-#endif
-
-		/* We have ensured that buflen < 65536 at this point, so it is safe
-		 * to iterate and read at least one more byte without checking.
-		 * However, now would be a good time to check for errors reading from
-		 * the file.
-		 */
-
-		if (dumbfile_error(f))
-			return -1;
-
-		/* Great. We ran out of data, but there should be data for more rows.
-		 * Fill the rest with null data...
-		 */
-		if (buflen >= length && pattern->n_rows < 64)
-		{
-			while (pattern->n_rows < 64)
-			{
-				if (buflen >= 65536) return -1;
-				buffer[buflen++] = 0;
-				pattern->n_entries++;
-				pattern->n_rows++;
-			}
-			break;
-		}
-	}
-
-	pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
-
-	if (!pattern->entry)
-		return -1;
-
-	entry = pattern->entry;
-
-	while (bufpos < buflen) {
-		unsigned char b = buffer[bufpos++];
-
-		if (b == 0)
-		{
-			/* End of row */
-			IT_SET_END_ROW(entry);
-			entry++;
-			continue;
-		}
-
-		channel = b & 31;
-
-		if (b & 224) {
-			entry->mask = 0;
-			entry->channel = channel;
-
-			if (b & 32) {
-				unsigned char n = buffer[bufpos++];
-				if (n == 254 || (n >= 1 && n <= 120)) {
-					if (n == 254)
-						entry->note = IT_NOTE_CUT;
-					else
-						entry->note = n - 1;
-					entry->mask |= IT_ENTRY_NOTE;
-				}
-
-				entry->instrument = buffer[bufpos++];
-				if (entry->instrument)
-					entry->mask |= IT_ENTRY_INSTRUMENT;
-			}
-
-			if (b & 64) {
-				effect = buffer[bufpos++];
-				effectvalue = buffer[bufpos++];
-				_dumb_it_ptm_convert_effect(effect, effectvalue, entry);
-			}
-
-			if (b & 128) {
-				entry->volpan = buffer[bufpos++];
-				if (entry->volpan <= 64)
-					entry->mask |= IT_ENTRY_VOLPAN;
-			}
-
-			entry++;
-		}
-	}
-
-	ASSERT(entry == pattern->entry + pattern->n_entries);
-
-	return 0;
-}
-
-
-
-/** WARNING: this is duplicated in itread.c - also bad practice to use the same struct name unless they are unified in a header */
-/* Currently we assume the sample data are stored after the sample headers in
- * module files. This assumption may be unjustified; let me know if you have
- * trouble.
- */
-
-#define PTM_COMPONENT_INSTRUMENT 1
-#define PTM_COMPONENT_PATTERN    2
-#define PTM_COMPONENT_SAMPLE     3
-
-typedef struct PTM_COMPONENT
-{
-	unsigned char type;
-	unsigned char n;
-	long offset;
-}
-PTM_COMPONENT;
-
-
-
-static int ptm_component_compare(const void *e1, const void *e2)
-{
-	return ((const PTM_COMPONENT *)e1)->offset -
-	       ((const PTM_COMPONENT *)e2)->offset;
-}
-
-
-
-static DUMB_IT_SIGDATA *it_ptm_load_sigdata(DUMBFILE *f)
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	PTM_COMPONENT *component;
-	int n_components = 0;
-
-	int n;
-
-	unsigned char *buffer;
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) return NULL;
-
-	/* Skip song name. */
-    dumbfile_getnc((char *)sigdata->name, 28, f);
-	sigdata->name[28] = 0;
-
-	if (dumbfile_getc(f) != 0x1A || dumbfile_igetw(f) != 0x203) {
-		free(sigdata);
-		return NULL;
-	}
-
-	dumbfile_skip(f, 1);
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_orders = dumbfile_igetw(f);
-	sigdata->n_instruments = 0;
-	sigdata->n_samples = dumbfile_igetw(f);
-	sigdata->n_patterns = dumbfile_igetw(f);
-
-	if (dumbfile_error(f) || sigdata->n_orders <= 0 || sigdata->n_samples > 255 || sigdata->n_patterns > 128) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	sigdata->n_pchannels = dumbfile_igetw(f);
-
-	if (dumbfile_igetw(f) != 0) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	dumbfile_skip(f, 2);
-
-	if (dumbfile_mgetl(f) != DUMB_ID('P','T','M','F')) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	dumbfile_skip(f, 16);
-
-	sigdata->order = malloc(sigdata->n_orders);
-	if (!sigdata->order) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	if (sigdata->n_samples) {
-		sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-		if (!sigdata->sample) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (n = 0; n < sigdata->n_samples; n++)
-			sigdata->sample[n].data = NULL;
-	}
-
-	if (sigdata->n_patterns) {
-		sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-		if (!sigdata->pattern) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (n = 0; n < sigdata->n_patterns; n++)
-			sigdata->pattern[n].entry = NULL;
-	}
-
-	/** WARNING: which ones? */
-	sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_A_PTM;
-
-	sigdata->global_volume = 128;
-	sigdata->speed = 6;
-	sigdata->tempo = 125;
-	sigdata->mixing_volume = 48;
-
-	/* Panning positions for 32 channels */
-	{
-		int i;
-		for (i = 0; i < 32; i++) {
-			int c = dumbfile_getc(f);
-			if (c <= 15) {
-				sigdata->channel_volume[i] = 64;
-				sigdata->channel_pan[i] = c;
-			} else {
-				/** WARNING: this could be improved if we support channel muting... */
-				sigdata->channel_volume[i] = 0;
-				sigdata->channel_pan[i] = 7;
-			}
-		}
-	}
-
-	/* Orders, byte each, length = sigdata->n_orders (should be even) */
-    dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
-	sigdata->restart_position = 0;
-
-	component = malloc(768*sizeof(*component));
-	if (!component) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-    if (dumbfile_seek(f, 352, DFS_SEEK_SET)) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (n = 0; n < sigdata->n_patterns; n++) {
-		component[n_components].type = PTM_COMPONENT_PATTERN;
-		component[n_components].n = n;
-		component[n_components].offset = dumbfile_igetw(f) << 4;
-		n_components++;
-	}
-
-    if (dumbfile_seek(f, 608, DFS_SEEK_SET)) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (n = 0; n < sigdata->n_samples; n++) {
-		if (it_ptm_read_sample_header(&sigdata->sample[n], &component[n_components].offset, f)) {
-			free(component);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		if (!(sigdata->sample[n].flags & IT_SAMPLE_EXISTS)) continue;
-		component[n_components].type = PTM_COMPONENT_SAMPLE;
-		component[n_components].n = n;
-		n_components++;
-	}
-
-	qsort(component, n_components, sizeof(PTM_COMPONENT), &ptm_component_compare);
-
-	{
-		int i;
-		for (i = 0; i < 32; i++) {
-			sigdata->channel_pan[i] -= (sigdata->channel_pan[i] & 8) >> 3;
-			sigdata->channel_pan[i] = ((int)sigdata->channel_pan[i] << 5) / 7;
-			if (sigdata->channel_pan[i] > 64) sigdata->channel_pan[i] = 64;
-		}
-	}
-
-	sigdata->pan_separation = 128;
-
-	if (dumbfile_error(f)) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	buffer = malloc(65536);
-	if (!buffer) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (n = 0; n < n_components; n++) {
-        if (dumbfile_seek(f, component[n].offset, DFS_SEEK_SET)) {
-			free(buffer);
-			free(component);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-
-		switch (component[n].type) {
-
-			case PTM_COMPONENT_PATTERN:
-				if (it_ptm_read_pattern(&sigdata->pattern[component[n].n], f, buffer, (n + 1 < n_components) ? (component[n+1].offset - component[n].offset) : 0)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-				break;
-
-			case PTM_COMPONENT_SAMPLE:
-				if (it_ptm_read_sample_data(&sigdata->sample[component[n].n], (n + 1 == n_components), f)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-		}
-	}
-
-	free(buffer);
-	free(component);
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-DUH *dumb_read_ptm_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_ptm_load_sigdata(f);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "PTM";
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readriff.c
+++ /dev/null
@@ -1,57 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readriff.c - Code to read a RIFF module file       / / \  \
- *              from memory.                         | <  /   \_
- *                                                   |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-#include "internal/it.h"
-#include "internal/riff.h"
-
-
-DUH *dumb_read_riff_amff( DUMBFILE * f, struct riff * stream );
-DUH *dumb_read_riff_am( DUMBFILE * f, struct riff * stream );
-DUH *dumb_read_riff_dsmf( DUMBFILE * f, struct riff * stream );
-
-/* dumb_read_riff_quick(): reads a RIFF file into a DUH struct, returning a
- * pointer to the DUH struct. When you have finished with it, you must pass
- * the pointer to unload_duh() so that the memory can be freed.
- */
-DUH *dumb_read_riff_quick( DUMBFILE * f )
-{
-	DUH * duh;
-	struct riff * stream;
-    long size;
-
-    size = dumbfile_get_size(f);
-
-    stream = riff_parse( f, 0, size, 1 );
-    if ( ! stream ) stream = riff_parse( f, 0, size, 0 );
-
-	if ( ! stream ) return 0;
-
-	if ( stream->type == DUMB_ID( 'A', 'M', ' ', ' ' ) )
-        duh = dumb_read_riff_am( f, stream );
-	else if ( stream->type == DUMB_ID( 'A', 'M', 'F', 'F' ) )
-        duh = dumb_read_riff_amff( f, stream );
-	else if ( stream->type == DUMB_ID( 'D', 'S', 'M', 'F' ) )
-        duh = dumb_read_riff_dsmf( f, stream );
-	else duh = 0;
-
-	riff_free( stream );
-
-	return duh;
-}
--- a/dumb/src/it/reads3m.c
+++ /dev/null
@@ -1,766 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * reads3m.c - Code to read a ScreamTracker 3         / / \  \
- *             module from an open file.             | <  /   \_
- *                                                   |  \/ /\   /
- * By entheh.                                         \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-// IT_STEREO... :o
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-static int it_s3m_read_sample_header(IT_SAMPLE *sample, long *offset, unsigned char *pack, int cwtv, DUMBFILE *f)
-{
-	unsigned char type;
-	int flags;
-
-	type = dumbfile_getc(f);
-
-    dumbfile_getnc((char *)sample->filename, 12, f);
-	sample->filename[12] = 0;
-
-	if (type > 1) {
-		/** WARNING: no adlib support */
-		dumbfile_skip(f, 3 + 12 + 1 + 1 + 2 + 2 + 2 + 12);
-        dumbfile_getnc((char *)sample->name, 28, f);
-		sample->name[28] = 0;
-		dumbfile_skip(f, 4);
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-		return dumbfile_error(f);
-	}
-
-	*offset = dumbfile_getc(f) << 20;
-	*offset += dumbfile_igetw(f) << 4;
-
-	sample->length = dumbfile_igetl(f);
-	sample->loop_start = dumbfile_igetl(f);
-	sample->loop_end = dumbfile_igetl(f);
-
-	sample->default_volume = dumbfile_getc(f);
-
-	dumbfile_skip(f, 1);
-
-	flags = dumbfile_getc(f);
-
-	if (flags < 0 || (flags != 0 && flags != 4))
-		/* Sample is packed apparently (or error reading from file). We don't
-		 * know how to read packed samples.
-		 */
-		return -1;
-
-	*pack = flags;
-
-	flags = dumbfile_getc(f);
-
-	sample->C5_speed = dumbfile_igetl(f) << 1;
-
-	/* Skip four unused bytes and three internal variables. */
-	dumbfile_skip(f, 4+2+2+4);
-
-    dumbfile_getnc((char *)sample->name, 28, f);
-	sample->name[28] = 0;
-
-	if (type == 0 || sample->length <= 0) {
-		/* Looks like no-existy. Anyway, there's for sure no 'SCRS' ... */
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-		return dumbfile_error(f);
-	}
-
-	if (dumbfile_mgetl(f) != DUMB_ID('S','C','R','S'))
-		return -1;
-
-	sample->global_volume = 64;
-
-	sample->flags = IT_SAMPLE_EXISTS;
-	if (flags & 1) sample->flags |= IT_SAMPLE_LOOP;
-
-	/* The ST3 TECH.DOC is unclear on this, but IMAGO Orpheus is not. Piece of crap. */
-
-	if (flags & 2) {
-		sample->flags |= IT_SAMPLE_STEREO;
-
-		if ((cwtv & 0xF000) == 0x2000) {
-			sample->length >>= 1;
-			sample->loop_start >>= 1;
-			sample->loop_end >>= 1;
-		}
-	}
-
-	if (flags & 4) {
-		sample->flags |= IT_SAMPLE_16BIT;
-
-		if ((cwtv & 0xF000) == 0x2000) {
-			sample->length >>= 1;
-			sample->loop_start >>= 1;
-			sample->loop_end >>= 1;
-		}
-	}
-
-	sample->default_pan = 0; // 0 = don't use, or 160 = centre?
-
-	if (sample->flags & IT_SAMPLE_LOOP) {
-		if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
-			/*sample->flags &= ~IT_SAMPLE_LOOP;*/
-			sample->loop_end = sample->length;
-		else if ((unsigned int)sample->loop_start >= (unsigned int)sample->loop_end)
-			sample->flags &= ~IT_SAMPLE_LOOP;
-		else
-			/* ScreamTracker seems not to save what comes after the loop end
-			 * point, but rather to assume it is a duplicate of what comes at
-			 * the loop start point. I am not completely sure of this though.
-			 * It is easy to evade; simply truncate the sample.
-			 */
-			sample->length = sample->loop_end;
-	}
-
-
-	//Do we need to set all these?
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = IT_VIBRATO_SINE;
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-
-
-static int it_s3m_read_sample_data(IT_SAMPLE *sample, int ffi, unsigned char pack, DUMBFILE *f)
-{
-	long n;
-
-	long datasize = sample->length;
-	if (sample->flags & IT_SAMPLE_STEREO) datasize <<= 1;
-
-	sample->data = malloc(datasize * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
-	if (!sample->data)
-		return -1;
-
-	if (pack == 4) {
-		if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
-			return -1;
-	}
-	else if (sample->flags & IT_SAMPLE_STEREO) {
-		if (sample->flags & IT_SAMPLE_16BIT) {
-			for (n = 0; n < datasize; n += 2)
-				((short *)sample->data)[n] = dumbfile_igetw(f);
-			for (n = 1; n < datasize; n += 2)
-				((short *)sample->data)[n] = dumbfile_igetw(f);
-		} else {
-			for (n = 0; n < datasize; n += 2)
-				((signed char *)sample->data)[n] = dumbfile_getc(f);
-			for (n = 1; n < datasize; n += 2)
-				((signed char *)sample->data)[n] = dumbfile_getc(f);
-		}
-	} else if (sample->flags & IT_SAMPLE_16BIT)
-		for (n = 0; n < sample->length; n++)
-			((short *)sample->data)[n] = dumbfile_igetw(f);
-	else
-		for (n = 0; n < sample->length; n++)
-			((signed char *)sample->data)[n] = dumbfile_getc(f);
-
-	if (dumbfile_error(f))
-		return -1;
-
-	if (ffi != 1) {
-		/* Convert to signed. */
-		if (sample->flags & IT_SAMPLE_16BIT)
-			for (n = 0; n < datasize; n++)
-				((short *)sample->data)[n] ^= 0x8000;
-		else
-			for (n = 0; n < datasize; n++)
-				((signed char *)sample->data)[n] ^= 0x80;
-	}
-
-	return 0;
-}
-
-
-
-static int it_s3m_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, unsigned char *buffer)
-{
-	int length;
-	int buflen = 0;
-	int bufpos = 0;
-
-	IT_ENTRY *entry;
-
-	unsigned char channel;
-
-	/* Haha, this is hilarious!
-	 *
-	 * Well, after some experimentation, it seems that different S3M writers
-	 * define the format in different ways. The S3M docs say that the first
-	 * two bytes hold the "length of [the] packed pattern", and the packed
-	 * pattern data follow. Judging by the contents of ARMANI.S3M, packaged
-	 * with ScreamTracker itself, the measure of length _includes_ the two
-	 * bytes used to store the length; in other words, we should read
-	 * (length - 2) more bytes. However, aryx.s3m, packaged with ModPlug
-	 * Tracker, excludes these two bytes, so (length) more bytes must be
-	 * read.
-	 *
-	 * Call me crazy, but I just find it insanely funny that the format was
-	 * misunderstood in this way :D
-	 *
-	 * Now we can't just risk reading two extra bytes, because then we
-	 * overshoot, and DUMBFILEs don't support backward seeking (for a good
-	 * reason). Luckily, there is a way. We can read the data little by
-	 * little, and stop when we have 64 rows in memory. Provided we protect
-	 * against buffer overflow, this method should work with all sensibly
-	 * written S3M files. If you find one for which it does not work, please
-	 * let me know at entheh@users.sf.net so I can look at it.
-     *
-     * "for a good reason" ? What's this nonsense? -kode54
-     *
-	 */
-
-	length = dumbfile_igetw(f);
-	
-	if (dumbfile_error(f) || !length)
-		return -1;
-
-	pattern->n_rows = 0;
-	pattern->n_entries = 0;
-
-	/* Read in the pattern data, little by little, and work out how many
-	 * entries we need room for. Sorry, but this is just so funny...
-	 */
-	for (;;) {
-		unsigned char b = buffer[buflen++] = dumbfile_getc(f);
-
-#if 1
-		static const unsigned char used[8] = {0, 2, 1, 3, 2, 4, 3, 5};
-		channel = b & 31;
-		b >>= 5;
-		pattern->n_entries++;
-		if (b) {
-			if (buflen + used[b] >= 65536) return -1;
-			if (buflen + used[b] <= length)
-                dumbfile_getnc((char *)buffer + buflen, used[b], f);
-			else
-				memset(buffer + buflen, 0, used[b]);
-			buflen += used[b];
-		} else {
-			/* End of row */
-			if (++pattern->n_rows == 64) break;
-			if (buflen >= 65536) return -1;
-		}
-#else
-		if (b == 0) {
-			/* End of row */
-			pattern->n_entries++;
-			if (++pattern->n_rows == 64) break;
-			if (buflen >= 65536) return -1;
-		} else {
-			static const unsigned char used[8] = {0, 2, 1, 3, 2, 4, 3, 5};
-			channel = b & 31;
-			b >>= 5;
-			if (b) {
-				pattern->n_entries++;
-				if (buflen + used[b] >= 65536) return -1;
-				dumbfile_getnc(buffer + buflen, used[b], f);
-				buflen += used[b];
-			}
-		}
-#endif
-
-		/* We have ensured that buflen < 65536 at this point, so it is safe
-		 * to iterate and read at least one more byte without checking.
-		 * However, now would be a good time to check for errors reading from
-		 * the file.
-		 */
-
-		if (dumbfile_error(f))
-			return -1;
-
-		/* Great. We ran out of data, but there should be data for more rows.
-		 * Fill the rest with null data...
-		 */
-		if (buflen >= length && pattern->n_rows < 64)
-		{
-			while (pattern->n_rows < 64)
-			{
-				if (buflen >= 65536) return -1;
-				buffer[buflen++] = 0;
-				pattern->n_entries++;
-				pattern->n_rows++;
-			}
-			break;
-		}
-	}
-
-	pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
-
-	if (!pattern->entry)
-		return -1;
-
-	entry = pattern->entry;
-
-	while (bufpos < buflen) {
-		unsigned char b = buffer[bufpos++];
-
-#if 1
-		if (!(b & ~31))
-#else
-		if (b == 0)
-#endif
-		{
-			/* End of row */
-			IT_SET_END_ROW(entry);
-			entry++;
-			continue;
-		}
-
-		channel = b & 31;
-
-		if (b & 224) {
-			entry->mask = 0;
-			entry->channel = channel;
-
-			if (b & 32) {
-				unsigned char n = buffer[bufpos++];
-				if (n != 255) {
-					if (n == 254)
-						entry->note = IT_NOTE_CUT;
-					else
-						entry->note = (n >> 4) * 12 + (n & 15);
-					entry->mask |= IT_ENTRY_NOTE;
-				}
-
-				entry->instrument = buffer[bufpos++];
-				if (entry->instrument)
-					entry->mask |= IT_ENTRY_INSTRUMENT;
-			}
-
-			if (b & 64) {
-				entry->volpan = buffer[bufpos++];
-				if (entry->volpan != 255)
-					entry->mask |= IT_ENTRY_VOLPAN;
-			}
-
-			if (b & 128) {
-				entry->effect = buffer[bufpos++];
-				entry->effectvalue = buffer[bufpos++];
-				// XXX woot
-				if (entry->effect && entry->effect < IT_MIDI_MACRO /*!= 255*/) {
-					entry->mask |= IT_ENTRY_EFFECT;
-					switch (entry->effect) {
-					case IT_BREAK_TO_ROW:
-						entry->effectvalue -= (entry->effectvalue >> 4) * 6;
-						break;
-
-					case IT_SET_CHANNEL_VOLUME:
-					case IT_CHANNEL_VOLUME_SLIDE:
-					case IT_PANNING_SLIDE:
-					case IT_GLOBAL_VOLUME_SLIDE:
-					case IT_PANBRELLO:
-					case IT_MIDI_MACRO:
-						entry->mask &= ~IT_ENTRY_EFFECT;
-						break;
-
-					case IT_S:
-						switch (entry->effectvalue >> 4) {
-						case IT_S_SET_PANBRELLO_WAVEFORM:
-						case IT_S_FINE_PATTERN_DELAY:
-						case IT_S7:
-						case IT_S_SET_SURROUND_SOUND:
-						case IT_S_SET_MIDI_MACRO:
-							entry->mask &= ~IT_ENTRY_EFFECT;
-							break;
-						}
-						break;
-					}
-				}
-				/** WARNING: ARGH! CONVERT TEH EFFECTS!@~ */
-			}
-
-			entry++;
-		}
-	}
-
-	ASSERT(entry == pattern->entry + pattern->n_entries);
-
-	return 0;
-}
-
-
-
-/** WARNING: this is duplicated in itread.c - also bad practice to use the same struct name unless they are unified in a header */
-/* Currently we assume the sample data are stored after the sample headers in
- * module files. This assumption may be unjustified; let me know if you have
- * trouble.
- */
-
-#define S3M_COMPONENT_INSTRUMENT 1
-#define S3M_COMPONENT_PATTERN    2
-#define S3M_COMPONENT_SAMPLE     3
-
-typedef struct S3M_COMPONENT
-{
-	unsigned char type;
-	unsigned char n;
-	long offset;
-	short sampfirst; /* component[sampfirst] = first sample data after this */
-	short sampnext; /* sampnext is used to create linked lists of sample data */
-}
-S3M_COMPONENT;
-
-
-
-static int s3m_component_compare(const void *e1, const void *e2)
-{
-	return ((const S3M_COMPONENT *)e1)->offset -
-	       ((const S3M_COMPONENT *)e2)->offset;
-}
-
-
-
-static DUMB_IT_SIGDATA *it_s3m_load_sigdata(DUMBFILE *f, int * cwtv)
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	int flags, ffi;
-	int default_pan_present;
-
-	int master_volume;
-
-	unsigned char sample_pack[256];
-
-	S3M_COMPONENT *component;
-	int n_components = 0;
-
-	int n;
-
-	unsigned char *buffer;
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) return NULL;
-
-    dumbfile_getnc((char *)sigdata->name, 28, f);
-	sigdata->name[28] = 0;
-
-	n = dumbfile_getc(f);
-
-	if (n != 0x1A && n != 0) {
-		free(sigdata);
-		return NULL;
-	}
-
-	if (dumbfile_getc(f) != 16) {
-		free(sigdata);
-		return NULL;
-	}
-
-	dumbfile_skip(f, 2);
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_orders = dumbfile_igetw(f);
-	sigdata->n_instruments = 0;
-	sigdata->n_samples = dumbfile_igetw(f);
-	sigdata->n_patterns = dumbfile_igetw(f);
-
-	if (dumbfile_error(f) || sigdata->n_orders <= 0 || sigdata->n_samples > 256 || sigdata->n_patterns > 256) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	sigdata->order = malloc(sigdata->n_orders);
-	if (!sigdata->order) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	if (sigdata->n_samples) {
-		sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-		if (!sigdata->sample) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (n = 0; n < sigdata->n_samples; n++)
-			sigdata->sample[n].data = NULL;
-	}
-
-	if (sigdata->n_patterns) {
-		sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-		if (!sigdata->pattern) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (n = 0; n < sigdata->n_patterns; n++)
-			sigdata->pattern[n].entry = NULL;
-	}
-
-	flags = dumbfile_igetw(f);
-
-	*cwtv = dumbfile_igetw(f);
-
-	if (*cwtv == 0x1300) {
-		/** WARNING: volume slides on every frame */
-	}
-
-	ffi = dumbfile_igetw(f);
-
-	/** WARNING: which ones? */
-	sigdata->flags = IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M;
-
-	if (dumbfile_mgetl(f) != DUMB_ID('S','C','R','M')) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	sigdata->global_volume = dumbfile_getc(f);
-	if ( !sigdata->global_volume || sigdata->global_volume > 64 ) sigdata->global_volume = 64;
-	sigdata->speed = dumbfile_getc(f);
-	if (sigdata->speed == 0) sigdata->speed = 6; // Should we? What about tempo?
-	sigdata->tempo = dumbfile_getc(f);
-	master_volume = dumbfile_getc(f); // 7 bits; +128 for stereo
-	sigdata->mixing_volume = master_volume & 127;
-
-	if (master_volume & 128) sigdata->flags |= IT_STEREO;
-
-	/* Skip GUS Ultra Click Removal byte. */
-	dumbfile_getc(f);
-
-	default_pan_present = dumbfile_getc(f);
-
-	dumbfile_skip(f, 8);
-
-	/* Skip Special Custom Data Pointer. */
-	/** WARNING: investigate this? */
-	dumbfile_igetw(f);
-
-	sigdata->n_pchannels = 0;
-	/* Channel settings for 32 channels, 255=unused, +128=disabled */
-	{
-		int i;
-		int sep = (7 * dumb_it_default_panning_separation + 50) / 100;
-		for (i = 0; i < 32; i++) {
-			int c = dumbfile_getc(f);
-			if (!(c & (128 | 16))) { /* +128=disabled, +16=Adlib */
-				if (sigdata->n_pchannels < i + 1) sigdata->n_pchannels = i + 1;
-				sigdata->channel_volume[i] = 64;
-				sigdata->channel_pan[i] = c & 8 ? 7 + sep : 7 - sep;
-				/** WARNING: ah, but it should be 7 for mono... */
-			} else {
-				/** WARNING: this could be improved if we support channel muting... */
-				sigdata->channel_volume[i] = 0;
-				sigdata->channel_pan[i] = 7;
-			}
-		}
-	}
-
-	/* Orders, byte each, length = sigdata->n_orders (should be even) */
-    dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
-	sigdata->restart_position = 0;
-
-	component = malloc(768*sizeof(*component));
-	if (!component) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (n = 0; n < sigdata->n_samples; n++) {
-		component[n_components].type = S3M_COMPONENT_SAMPLE;
-		component[n_components].n = n;
-		component[n_components].offset = dumbfile_igetw(f) << 4;
-		component[n_components].sampfirst = -1;
-		n_components++;
-	}
-
-	for (n = 0; n < sigdata->n_patterns; n++) {
-		long offset = dumbfile_igetw(f) << 4;
-		if (offset) {
-			component[n_components].type = S3M_COMPONENT_PATTERN;
-			component[n_components].n = n;
-			component[n_components].offset = offset;
-			component[n_components].sampfirst = -1;
-			n_components++;
-		} else {
-			/** WARNING: Empty 64-row pattern ... ? (this does happen!) */
-			sigdata->pattern[n].n_rows = 64;
-			sigdata->pattern[n].n_entries = 0;
-		}
-	}
-
-	qsort(component, n_components, sizeof(S3M_COMPONENT), &s3m_component_compare);
-
-	/* I found a really dumb S3M file that claimed to contain default pan
-	 * data but didn't contain any. Programs would load it by reading part of
-	 * the first instrument header, assuming the data to be default pan
-	 * positions, and then rereading the instrument module. We cannot do this
-	 * without obfuscating the file input model, so we insert an extra check
-	 * here that we won't overrun the start of the first component.
-	 */
-	if (default_pan_present == 252 && component[0].offset >= dumbfile_pos(f) + 32) {
-		/* Channel default pan positions */
-		int i;
-		for (i = 0; i < 32; i++) {
-			int c = dumbfile_getc(f);
-			if (c & 32)
-				sigdata->channel_pan[i] = c & 15;
-		}
-	}
-
-	{
-		int i;
-		for (i = 0; i < 32; i++) {
-			sigdata->channel_pan[i] -= (sigdata->channel_pan[i] & 8) >> 3;
-			sigdata->channel_pan[i] = ((int)sigdata->channel_pan[i] << 5) / 7;
-		}
-	}
-
-	sigdata->pan_separation = 128;
-
-	if (dumbfile_error(f)) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	buffer = malloc(65536);
-	if (!buffer) {
-		free(component);
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	for (n = 0; n < n_components; n++) {
-		long offset;
-		int m;
-
-		offset = 0;
-        if (dumbfile_seek(f, component[n].offset, DFS_SEEK_SET)) {
-			free(buffer);
-			free(component);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-
-		switch (component[n].type) {
-
-			case S3M_COMPONENT_PATTERN:
-                if (it_s3m_read_pattern(&sigdata->pattern[component[n].n], f, buffer)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-				break;
-
-			case S3M_COMPONENT_SAMPLE:
-				if (it_s3m_read_sample_header(&sigdata->sample[component[n].n], &offset, &sample_pack[component[n].n], *cwtv, f)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-
-				if (sigdata->sample[component[n].n].flags & IT_SAMPLE_EXISTS) {
-					short *sample;
-
-					for (m = n + 1; m < n_components; m++)
-						if (component[m].offset > offset)
-							break;
-					m--;
-
-					sample = &component[m].sampfirst;
-
-					while (*sample >= 0 && component[*sample].offset <= offset)
-						sample = &component[*sample].sampnext;
-
-					component[n].sampnext = *sample;
-					*sample = n;
-
-					component[n].offset = offset;
-				}
-		}
-
-		m = component[n].sampfirst;
-
-		while (m >= 0) {
-			// XXX
-                if (dumbfile_seek(f, component[m].offset, DFS_SEEK_SET)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-
-				if (it_s3m_read_sample_data(&sigdata->sample[component[m].n], ffi, sample_pack[component[m].n], f)) {
-					free(buffer);
-					free(component);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-
-			m = component[m].sampnext;
-		}
-	}
-
-	free(buffer);
-	free(component);
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-static char hexdigit(int in)
-{
-	if (in < 10) return in + '0';
-	else return in + 'A' - 10;
-}
-
-DUH *dumb_read_s3m_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-	int cwtv;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_s3m_load_sigdata(f, &cwtv);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		char version[8];
-		const char *tag[3][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		tag[1][1] = "S3M";
-		tag[2][0] = "TRACKERVERSION";
-		version[0] = hexdigit((cwtv >> 8) & 15);
-		version[1] = '.';
-		version[2] = hexdigit((cwtv >> 4) & 15);
-		version[3] = hexdigit(cwtv & 15);
-		version[4] = 0;
-		tag[2][1] = (const char *) &version;
-		return make_duh(-1, 3, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/reads3m2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * reads3m2.c - Function to read a ScreamTracker 3    / / \  \
- *              module from an open file and do an   | <  /   \_
- *              initial run-through.                 |  \/ /\   /
- *                                                    \_  /  > /
- * Split off from reads3m.c by entheh.                  | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_s3m(DUMBFILE *f)
-{
-	DUH *duh = dumb_read_s3m_quick(f);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/readstm.c
+++ /dev/null
@@ -1,397 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readstm.c - Code to read a ScreamTracker 2         / / \  \
- *             module from an open file.             | <  /   \_
- *                                                   |  \/ /\   /
- * By Chris Moeller.                                  \_  /  > /
- *                                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-// IT_STEREO... :o
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-#ifdef _MSC_VER
-	#define strnicmp _strnicmp
-#else
-	#if defined(unix) || defined(__unix__) || defined(__unix)
-		#include <strings.h>
-	#endif
-	#define strnicmp strncasecmp
-#endif
-
-static int it_stm_read_sample_header( IT_SAMPLE *sample, DUMBFILE *f, unsigned short *offset )
-{
-    dumbfile_getnc( (char *) sample->filename, 12, f );
-	sample->filename[12] = 0;
-
-	memcpy( sample->name, sample->filename, 13 );
-
-	dumbfile_skip( f, 2 );
-
-	*offset = dumbfile_igetw( f );
-
-	sample->length = dumbfile_igetw( f );
-	sample->loop_start = dumbfile_igetw( f );
-	sample->loop_end = dumbfile_igetw( f );
-
-	sample->default_volume = dumbfile_getc( f );
-
-	dumbfile_skip( f, 1 );
-
-	sample->C5_speed = dumbfile_igetw( f ) << 3;
-
-	dumbfile_skip( f, 6 );
-
-	if ( sample->length < 4 || !sample->default_volume ) {
-		/* Looks like no-existy. */
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-		sample->length = 0;
-		*offset = 0;
-		return dumbfile_error( f );
-	}
-
-	sample->flags = IT_SAMPLE_EXISTS;
-	sample->global_volume = 64;
-	sample->default_pan = 0; // 0 = don't use, or 160 = centre?
-
-	if ( ( sample->loop_start < sample->length ) &&
-		( sample->loop_end > sample->loop_start ) &&
-		( sample->loop_end != 0xFFFF ) ) {
-		sample->flags |= IT_SAMPLE_LOOP;
-		if ( sample->loop_end > sample->length ) sample->loop_end = sample->length;
-	}
-
-	//Do we need to set all these?
-	sample->vibrato_speed = 0;
-	sample->vibrato_depth = 0;
-	sample->vibrato_rate = 0;
-	sample->vibrato_waveform = IT_VIBRATO_SINE;
-	sample->finetune = 0;
-	sample->max_resampling_quality = -1;
-
-	return dumbfile_error(f);
-}
-
-static int it_stm_read_sample_data( IT_SAMPLE *sample, DUMBFILE * f )
-{
-	if ( ! sample->length ) return 0;
-
-	sample->data = malloc( sample->length );
-	if (!sample->data)
-		return -1;
-
-    dumbfile_getnc( sample->data, sample->length, f );
-
-    return dumbfile_error( f );
-}
-
-static int it_stm_read_pattern( IT_PATTERN *pattern, DUMBFILE *f, unsigned char *buffer )
-{
-	int pos;
-	int channel;
-	int row;
-	IT_ENTRY *entry;
-
-	pattern->n_rows = 64;
-
-    if ( dumbfile_getnc( (char *) buffer, 64 * 4 * 4, f ) != 64 * 4 * 4 )
-		return -1;
-
-	pattern->n_entries = 64;
-	pos = 0;
-	for ( row = 0; row < 64; ++row ) {
-		for ( channel = 0; channel < 4; ++channel ) {
-			if ( buffer[ pos + 0 ] | buffer[ pos + 1 ] | buffer[ pos + 2 ] | buffer[ pos + 3 ] )
-				++pattern->n_entries;
-			pos += 4;
-		}
-	}
-
-	pattern->entry = malloc( pattern->n_entries * sizeof( *pattern->entry ) );
-	if ( !pattern->entry )
-		return -1;
-
-	entry = pattern->entry;
-	pos = 0;
-	for ( row = 0; row < 64; ++row ) {
-		for ( channel = 0; channel < 4; ++channel ) {
-			if ( buffer[ pos + 0 ] | buffer[ pos + 1 ] | buffer[ pos + 2 ] | buffer[ pos + 3 ] ) {
-				unsigned note;
-				note = buffer[ pos + 0 ];
-				entry->channel = channel;
-				entry->mask = 0;
-				entry->instrument = buffer[ pos + 1 ] >> 3;
-				entry->volpan = ( buffer[ pos + 1 ] & 0x07 ) + ( buffer[ pos + 2 ] >> 1 );
-				entry->effect = buffer[ pos + 2 ] & 0x0F;
-				entry->effectvalue = buffer[ pos + 3 ];
-				if ( entry->instrument && entry->instrument < 32 )
-					entry->mask |= IT_ENTRY_INSTRUMENT;
-				if ( note < 251 ) {
-					entry->mask |= IT_ENTRY_NOTE;
-					entry->note = ( note >> 4 ) * 12 + ( note & 0x0F );
-				}
-				if ( entry->volpan <= 64 )
-					entry->mask |= IT_ENTRY_VOLPAN;
-				entry->mask |= IT_ENTRY_EFFECT;
-				switch ( entry->effect ) {
-                    case IT_SET_SPEED:
-                    /* taken care of in the renderer */
-                        break;
-
-					case IT_BREAK_TO_ROW:
-						entry->effectvalue -= (entry->effectvalue >> 4) * 6;
-						break;
-
-					case IT_JUMP_TO_ORDER:
-					case IT_VOLUME_SLIDE:
-					case IT_PORTAMENTO_DOWN:
-					case IT_PORTAMENTO_UP:
-					case IT_TONE_PORTAMENTO:
-					case IT_VIBRATO:
-					case IT_TREMOR:
-					case IT_ARPEGGIO:
-					case IT_VOLSLIDE_VIBRATO:
-					case IT_VOLSLIDE_TONEPORTA:
-						break;
-
-					default:
-						entry->mask &= ~IT_ENTRY_EFFECT;
-						break;
-				}
-				if ( entry->mask ) ++entry;
-			}
-			pos += 4;
-		}
-		IT_SET_END_ROW(entry);
-		++entry;
-	}
-
-	pattern->n_entries = entry - pattern->entry;
-
-	return 0;
-}
-
-
-
-static DUMB_IT_SIGDATA *it_stm_load_sigdata(DUMBFILE *f, int * version)
-{
-	DUMB_IT_SIGDATA *sigdata;
-
-	char tracker_name[ 8 ];
-
-	unsigned short sample_offset[ 31 ];
-
-    int n;
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata) return NULL;
-
-	/* Skip song name. */
-    dumbfile_getnc((char *)sigdata->name, 20, f);
-	sigdata->name[20] = 0;
-
-	dumbfile_getnc(tracker_name, 8, f);
-	n = dumbfile_getc(f);
-	if ( n != 0x02 && n != 0x1A && n != 0x1B )
-	{
-		free( sigdata );
-		return NULL;
-	}
-	if ( dumbfile_getc(f) != 2 ) /* only support modules */
-	{
-		free( sigdata );
-		return NULL;
-	}
-	if ( strnicmp( tracker_name, "!Scream!", 8 ) &&
-		strnicmp( tracker_name, "BMOD2STM", 8 ) &&
-		strnicmp( tracker_name, "WUZAMOD!", 8 ) )
-	{
-		free( sigdata );
-		return NULL;
-	}
-
-	*version = dumbfile_mgetw(f);
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_instruments = 0;
-	sigdata->n_samples = 31;
-	sigdata->n_pchannels = 4;
-
-    sigdata->tempo = 125;
-    sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	/** WARNING: which ones? */
-    sigdata->flags = IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M | IT_WAS_AN_STM | IT_STEREO;
-
-    n = dumbfile_getc(f);
-    if ( n < 32 ) n = 32;
-    sigdata->speed = n;
-    sigdata->n_patterns = dumbfile_getc(f);
-	sigdata->global_volume = dumbfile_getc(f) << 1;
-	if ( sigdata->global_volume > 128 ) sigdata->global_volume = 128;
-	
-	dumbfile_skip(f, 13);
-
-	if ( dumbfile_error(f) || sigdata->n_patterns < 1 || sigdata->n_patterns > 99 ) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
-	if (!sigdata->sample) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-	for (n = 0; n < sigdata->n_samples; n++)
-		sigdata->sample[n].data = NULL;
-
-	if (sigdata->n_patterns) {
-		sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-		if (!sigdata->pattern) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (n = 0; n < sigdata->n_patterns; n++)
-			sigdata->pattern[n].entry = NULL;
-	}
-
-	memset( sigdata->channel_volume, 64, 4 );
-	n = 32 * dumb_it_default_panning_separation / 100;
-	sigdata->channel_pan[ 0 ] = 32 + n;
-	sigdata->channel_pan[ 1 ] = 32 - n;
-	sigdata->channel_pan[ 2 ] = 32 + n;
-	sigdata->channel_pan[ 3 ] = 32 - n;
-
-	for ( n = 0; n < sigdata->n_samples; ++n ) {
-		if ( it_stm_read_sample_header( &sigdata->sample[ n ], f, &sample_offset[ n ] ) ) {
-			_dumb_it_unload_sigdata( sigdata );
-			return NULL;
-		}
-	}
-
-	sigdata->order = malloc( 128 );
-	if ( !sigdata->order ) {
-		_dumb_it_unload_sigdata( sigdata );
-		return NULL;
-	}
-
-	/* Orders, byte each, length = sigdata->n_orders (should be even) */
-    dumbfile_getnc( (char *) sigdata->order, *version >= 0x200 ? 128 : 64, f );
-	if (*version < 0x200) memset( sigdata->order + 64, 0xFF, 64 );
-	sigdata->restart_position = 0;
-
-	for ( n = 127; n >= 0; --n ) {
-		if ( sigdata->order[ n ] < sigdata->n_patterns ) break;
-	}
-	if ( n < 0 ) {
-		_dumb_it_unload_sigdata( sigdata );
-		return NULL;
-	}
-	sigdata->n_orders = n + 1;
-
-	for ( n = 0; n < 128; ++n ) {
-		if ( sigdata->order[ n ] >= 99 ) sigdata->order[ n ] = 0xFF;
-	}
-
-	if ( sigdata->n_patterns ) {
-		unsigned char * buffer = malloc( 64 * 4 * 4 );
-		if ( ! buffer ) {
-			_dumb_it_unload_sigdata( sigdata );
-			return NULL;
-		}
-		for ( n = 0; n < sigdata->n_patterns; ++n ) {
-			if ( it_stm_read_pattern( &sigdata->pattern[ n ], f, buffer ) ) {
-				free( buffer );
-				_dumb_it_unload_sigdata( sigdata );
-				return NULL;
-			}
-		}
-		free( buffer );
-	}
-
-    for ( n = 0; n < sigdata->n_samples; ++n ) {
-        if ( sample_offset[ n ] )
-        {
-            if ( dumbfile_seek( f, sample_offset[ n ] * 16, DFS_SEEK_SET ) ||
-                 it_stm_read_sample_data( &sigdata->sample[ n ], f ) ) {
-                _dumb_it_unload_sigdata( sigdata );
-                return NULL;
-            }
-        }
-        else
-        {
-            sigdata->sample[ n ].flags = 0;
-            sigdata->sample[ n ].length = 0;
-        }
-    }
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-DUH *dumb_read_stm_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-	int ver;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_stm_load_sigdata(f , &ver);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		char version[16];
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		version[0] = 'S';
-		version[1] = 'T';
-		version[2] = 'M';
-		version[3] = ' ';
-		version[4] = 'v';
-		version[5] = '0' + ((ver >> 8) & 15);
-		version[6] = '.';
-		if ((ver & 255) > 99)
-		{
-			version[7] = '0' + ((ver & 255) / 100 );
-			version[8] = '0' + (((ver & 255) / 10) % 10);
-			version[9] = '0' + ((ver & 255) % 10);
-			version[10] = 0;
-		}
-		else
-		{
-			version[7] = '0' + ((ver & 255) / 10);
-			version[8] = '0' + ((ver & 255) % 10);
-			version[9] = 0;
-		}
-		tag[1][1] = (const char *) &version;
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readstm2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readstm2.c - Function to read a ScreamTracker 2    / / \  \
- *              module from an open file and do an   | <  /   \_
- *              initial run-through.                 |  \/ /\   /
- *                                                    \_  /  > /
- * By Chris Moeller.                                    | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_stm(DUMBFILE *f)
-{
-	DUH *duh = dumb_read_stm_quick(f);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/readxm.c
+++ /dev/null
@@ -1,1428 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readxm.c - Code to read a Fast Tracker II          / / \  \
- *            module from an open file.              | <  /   \_
- *                                                   |  \/ /\   /
- * By Julien Cugniere. Some bits of code taken        \_  /  > /
- * from reads3m.c.                                      | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-#include "internal/dumbfile.h"
-
-
-
-/** TODO:
-
- * XM_TREMOLO                        doesn't sound quite right...
- * XM_SET_ENVELOPE_POSITION          todo.
-
- * VIBRATO conversion needs to be checked (sample/effect/volume). Plus check
-   that effect memory is correct when using XM_VOLSLIDE_VIBRATO.
-   - sample vibrato (instrument vibrato) is now handled correctly. - entheh
-
- * XM_E_SET_VIBRATO/TREMOLO_CONTROL: effectvalue&4 -> don't retrig wave when
-   a new instrument is played. In retrigger_note()?. Is it worth implementing?
-
- * Lossy fadeout approximation. 0..31 converted to 0 --> won't fade at all.
-
- * Replace DUMB's sawtooth by ramp_down/ramp_up. Update XM loader.
-
- * A lot of things need to be reset when the end of the song is reached.
-
- * It seems that IT and XM don't behave the same way when dealing with
-   mixed loops. When IT encounters multiple SBx (x>0) commands on the same
-   row, it decrements the loop count for all, but only execute the loop of
-   the last one (highest channel). FT2 only decrements the loop count of the
-   last one. Not that I know of any modules using so convoluted combinations!
-
- * Maybe we could remove patterns that don't appear in the order table ? Or
-   provide a function to "optimize" a DUMB_IT_SIGDATA ?
-
-*/
-
-
-
-#define XM_LINEAR_FREQUENCY        1 /* otherwise, use amiga slides */
-
-#define XM_ENTRY_PACKED            128
-#define XM_ENTRY_NOTE              1
-#define XM_ENTRY_INSTRUMENT        2
-#define XM_ENTRY_VOLUME            4
-#define XM_ENTRY_EFFECT            8
-#define XM_ENTRY_EFFECTVALUE       16
-
-#define XM_NOTE_OFF                97
-
-#define XM_ENVELOPE_ON             1
-#define XM_ENVELOPE_SUSTAIN        2
-#define XM_ENVELOPE_LOOP           4
-
-#define XM_SAMPLE_NO_LOOP          0
-#define XM_SAMPLE_FORWARD_LOOP     1
-#define XM_SAMPLE_PINGPONG_LOOP    2
-#define XM_SAMPLE_16BIT            16
-#define XM_SAMPLE_STEREO           32
-
-#define XM_VIBRATO_SINE            0
-#define XM_VIBRATO_SQUARE          1
-#define XM_VIBRATO_RAMP_DOWN       2
-#define XM_VIBRATO_RAMP_UP         3
-
-
-
-/* Probably useless :) */
-const char xm_convert_vibrato[] = {
-	IT_VIBRATO_SINE,
-	IT_VIBRATO_XM_SQUARE,
-	IT_VIBRATO_RAMP_DOWN,
-	IT_VIBRATO_RAMP_UP,
-	IT_VIBRATO_RANDOM
-};
-
-
-
-#define XM_MAX_SAMPLES_PER_INSTRUMENT 16
-
-
-
-/* Extra data that doesn't fit inside IT_INSTRUMENT */
-typedef struct XM_INSTRUMENT_EXTRA
-{
-	int n_samples;
-	int vibrato_type;
-	int vibrato_sweep; /* 0-0xFF */
-	int vibrato_depth; /* 0-0x0F */
-	int vibrato_speed; /* 0-0x3F */
-	int sample_header_size;
-}
-XM_INSTRUMENT_EXTRA;
-
-
-
-/* Trims off trailing white space, usually added by the tracker on file creation
- */
-static void trim_whitespace(char *ptr, size_t size)
-{
-	char *p = ptr + size - 1;
-	while (p >= ptr && *p <= 0x20) *p-- = '\0';
-}
-
-/* Frees the original block if it can't resize it or if size is 0, and acts
- * as malloc if ptr is NULL.
- */
-static void *safe_realloc(void *ptr, size_t size)
-{
-	if (ptr == NULL)
-		return malloc(size);
-
-	if (size == 0) {
-		free(ptr);
-		return NULL;
-	} else {
-		void *new_block = realloc(ptr, size);
-		if (!new_block)
-			free(ptr);
-		return new_block;
-	}
-}
-
-
-
-/* The interpretation of the XM volume column is left to the player. Here, we
- * just filter bad values.
- */
-// This function is so tiny now, should we inline it?
-static void it_xm_convert_volume(int volume, IT_ENTRY *entry)
-{
-	entry->mask |= IT_ENTRY_VOLPAN;
-	entry->volpan = volume;
-
-	switch (volume >> 4) {
-		case 0xA: /* set vibrato speed */
-		case 0xB: /* vibrato */
-		case 0xF: /* tone porta */
-		case 0x6: /* vol slide up */
-		case 0x7: /* vol slide down */
-		case 0x8: /* fine vol slide up */
-		case 0x9: /* fine vol slide down */
-		case 0xC: /* set panning */
-		case 0xD: /* pan slide left */
-		case 0xE: /* pan slide right */
-		case 0x1: /* set volume */
-		case 0x2: /* set volume */
-		case 0x3: /* set volume */
-		case 0x4: /* set volume */
-			break;
-
-		case 0x5:
-			if (volume == 0x50)
-				break; /* set volume */
-			/* else fall through */
-
-		default:
-			entry->mask &= ~IT_ENTRY_VOLPAN;
-			break;
-	}
-}
-
-
-
-static int it_xm_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, int n_channels, unsigned char *buffer, int version)
-{
-	int size;
-	int pos;
-	int channel;
-	int row;
-	int effect, effectvalue;
-	IT_ENTRY *entry;
-
-	/* pattern header size */
-	if (dumbfile_igetl(f) != ( version == 0x0102 ? 0x08 : 0x09 ) ) {
-		TRACE("XM error: unexpected pattern header size\n");
-		return -1;
-	}
-
-	/* pattern data packing type */
-	if (dumbfile_getc(f) != 0) {
-		TRACE("XM error: unexpected pattern packing type\n");
-		return -1;
-	}
-
-	if ( version == 0x0102 )
-		pattern->n_rows = dumbfile_getc(f) + 1;
-	else
-		pattern->n_rows = dumbfile_igetw(f);  /* 1..256 */
-	size = dumbfile_igetw(f);
-	pattern->n_entries = 0;
-
-	if (dumbfile_error(f))
-		return -1;
-
-	if (size == 0)
-		return 0;
-
-	if (size > 1280 * n_channels) {
-		TRACE("XM error: pattern data size > %d bytes\n", 1280 * n_channels);
-		return -1;
-	}
-
-    if (dumbfile_getnc((char *)buffer, size, f) < size)
-		return -1;
-
-	/* compute number of entries */
-	pattern->n_entries = 0;
-	pos = channel = row = 0;
-	while (pos < size) {
-		if (!(buffer[pos] & XM_ENTRY_PACKED) || (buffer[pos] & 31))
-			pattern->n_entries++;
-
-		channel++;
-		if (channel >= n_channels) {
-			channel = 0;
-			row++;
-			pattern->n_entries++;
-		}
-
-		if (buffer[pos] & XM_ENTRY_PACKED) {
-			static const char offset[] = { 0, 1, 1, 2, 1, 2, 2, 3,   1, 2, 2, 3, 2, 3, 3, 4,
-			                               1, 2, 2, 3, 2, 3, 3, 4,   2, 3, 3, 4, 3, 4, 4, 5 };
-			pos += 1 + offset[buffer[pos] & 31];
-		} else {
-			pos += 5;
-		}
-	}
-
-	if (row > pattern->n_rows) {
-		TRACE("XM error: wrong number of rows in pattern data\n");
-		return -1;
-	}
-
-	/* Whoops, looks like some modules may be short, a few channels, maybe even rows... */
-
-	while (row < pattern->n_rows)
-	{
-		pattern->n_entries++;
-		row++;
-	}
-
-	pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
-	if (!pattern->entry)
-		return -1;
-
-	/* read the entries */
-	entry = pattern->entry;
-	pos = channel = row = 0;
-	while (pos < size) {
-		unsigned char mask;
-
-		if (buffer[pos] & XM_ENTRY_PACKED)
-			mask = buffer[pos++] & 31;
-		else
-			mask = 31;
-
-		if (mask) {
-			ASSERT(entry < pattern->entry + pattern->n_entries);
-
-			entry->channel = channel;
-			entry->mask = 0;
-
-			if (mask & XM_ENTRY_NOTE) {
-				int note = buffer[pos++]; /* 1-96 <=> C0-B7 */
-				entry->note = (note == XM_NOTE_OFF) ? (IT_NOTE_OFF) : (note-1);
-				entry->mask |= IT_ENTRY_NOTE;
-			}
-
-			if (mask & XM_ENTRY_INSTRUMENT) {
-				entry->instrument = buffer[pos++]; /* 1-128 */
-				entry->mask |= IT_ENTRY_INSTRUMENT;
-			}
-
-			if (mask & XM_ENTRY_VOLUME)
-				it_xm_convert_volume(buffer[pos++], entry);
-
-			effect = effectvalue = 0;
-			if (mask & XM_ENTRY_EFFECT)      effect = buffer[pos++];
-			if (mask & XM_ENTRY_EFFECTVALUE) effectvalue = buffer[pos++];
-			_dumb_it_xm_convert_effect(effect, effectvalue, entry, 0);
-
-			entry++;
-		}
-
-		channel++;
-		if (channel >= n_channels) {
-			channel = 0;
-			row++;
-			IT_SET_END_ROW(entry);
-			entry++;
-		}
-	}
-
-	while (row < pattern->n_rows)
-	{
-		row++;
-		IT_SET_END_ROW(entry);
-		entry++;
-	}
-
-	return 0;
-}
-
-
-
-static int it_xm_make_envelope(IT_ENVELOPE *envelope, const unsigned short *data, int y_offset)
-{
-    int i, pos, val;
-
-	if (envelope->n_nodes > 12) {
-		/* XXX
-		TRACE("XM error: wrong number of envelope nodes (%d)\n", envelope->n_nodes);
-		envelope->n_nodes = 0;
-		return -1; */
-		envelope->n_nodes = 12;
-	}
-
-	if (envelope->sus_loop_start >= 12) envelope->flags &= ~IT_ENVELOPE_SUSTAIN_LOOP;
-	if (envelope->loop_end >= 12) envelope->loop_end = 0;
-	if (envelope->loop_start >= envelope->loop_end) envelope->flags &= ~IT_ENVELOPE_LOOP_ON;
-
-	pos = 0;
-	for (i = 0; i < envelope->n_nodes; i++) {
-		envelope->node_t[i] = data[pos++];
-        val = data[pos++];
-        if (val > 64) {
-            TRACE("XM error: out-of-range envelope node (node_y[%d]=%d)\n", i, val);
-            /* FT2 seems to simply clip the value */
-            val = 64;
-		}
-        envelope->node_y[i] = (signed char)(val + y_offset);
-	}
-
-	return 0;
-}
-
-
-
-typedef struct LIMITED_XM LIMITED_XM;
-
-struct LIMITED_XM
-{
-	unsigned char *buffered;
-	long ptr, limit, allocated;
-	DUMBFILE *remaining;
-};
-
-static int limit_xm_resize(void *f, long n)
-{
-	DUMBFILE *df = f;
-	LIMITED_XM *lx = df->file;
-	if (lx->buffered || n) {
-		if (n > lx->allocated) {
-			unsigned char *buffered = realloc( lx->buffered, n );
-			if ( !buffered ) return -1;
-			lx->buffered = buffered;
-			memset( buffered + lx->allocated, 0, n - lx->allocated );
-			lx->allocated = n;
-		}
-        if ( dumbfile_getnc( (char *)lx->buffered, n, lx->remaining ) < n ) return -1;
-	} else if (!n) {
-		if ( lx->buffered ) free( lx->buffered );
-		lx->buffered = NULL;
-		lx->allocated = 0;
-	}
-	lx->limit = n;
-	lx->ptr = 0;
-	return 0;
-}
-
-static int limit_xm_skip_end(void *f, long n)
-{
-	DUMBFILE *df = f;
-	LIMITED_XM *lx = df->file;
-	return dumbfile_skip( lx->remaining, n );
-}
-
-static int limit_xm_skip(void *f, long n)
-{
-	LIMITED_XM *lx = f;
-	lx->ptr += n;
-	return 0;
-}
-
-
-
-static int limit_xm_getc(void *f)
-{
-	LIMITED_XM *lx = f;
-	if (lx->ptr >= lx->allocated) {
-		return 0;
-	}
-	return lx->buffered[lx->ptr++];
-}
-
-
-
-static long limit_xm_getnc(char *ptr, long n, void *f)
-{
-	LIMITED_XM *lx = f;
-	int left;
-	left = lx->allocated - lx->ptr;
-	if (n > left) {
-		if (left > 0) {
-			memcpy( ptr, lx->buffered + lx->ptr, left );
-			memset( ptr + left, 0, n - left );
-		} else {
-			memset( ptr, 0, n );
-		}
-	} else {
-		memcpy( ptr, lx->buffered + lx->ptr, n );
-	}
-	lx->ptr += n;
-	return n;
-}
-
-
-
-static void limit_xm_close(void *f)
-{
-	LIMITED_XM *lx = f;
-	if (lx->buffered) free(lx->buffered);
-	/* Do NOT close lx->remaining */
-	free(f);
-}
-
-
-/* These two can be stubs since this implementation doesn't use seeking */
-static int limit_xm_seek(void *f, long n)
-{
-    (void)f;
-    (void)n;
-    return 1;
-}
-
-
-
-static long limit_xm_get_size(void *f)
-{
-    (void)f;
-    return 0;
-}
-
-
-
-DUMBFILE_SYSTEM limit_xm_dfs = {
-	NULL,
-	&limit_xm_skip,
-	&limit_xm_getc,
-	&limit_xm_getnc,
-    &limit_xm_close,
-    &limit_xm_seek,
-    &limit_xm_get_size
-};
-
-static DUMBFILE *dumbfile_limit_xm(DUMBFILE *f)
-{
-	LIMITED_XM * lx = malloc(sizeof(*lx));
-	lx->remaining = f;
-	lx->buffered = NULL;
-	lx->ptr = 0;
-	lx->limit = 0;
-	lx->allocated = 0;
-	return dumbfile_open_ex( lx, &limit_xm_dfs );
-}
-
-static int it_xm_read_instrument(IT_INSTRUMENT *instrument, XM_INSTRUMENT_EXTRA *extra, DUMBFILE *f)
-{
-	unsigned long size, bytes_read;
-	unsigned short vol_points[24];
-	unsigned short pan_points[24];
-	int i, type;
-	const unsigned long max_size = 4 + 22 + 1 + 2 + 4 + 96 + 48 + 48 + 1 * 14 + 2 + 2;
-	unsigned long skip_end = 0;
-
-	/* Header size. Tends to be more than the actual size of the structure.
-	 * So unread bytes must be skipped before reading the first sample
-	 * header.
-	 */
-
-	if ( limit_xm_resize( f, 4 ) < 0 ) return -1;
-
-	size = dumbfile_igetl(f);
-
-	if ( size == 0 ) size = max_size;
-	else if ( size > max_size )
-	{
-		skip_end = size - max_size;
-		size = max_size;
-	}
-
-	if ( limit_xm_resize( f, size - 4 ) < 0 ) return -1;
-
-    dumbfile_getnc((char *)instrument->name, 22, f);
-	instrument->name[22] = 0;
-    trim_whitespace((char *)instrument->name, 22);
-	instrument->filename[0] = 0;
-	dumbfile_skip(f, 1);  /* Instrument type. Should be 0, but seems random. */
-	extra->n_samples = dumbfile_igetw(f);
-
-	if (dumbfile_error(f) || (unsigned int)extra->n_samples > XM_MAX_SAMPLES_PER_INSTRUMENT)
-		return -1;
-
-	bytes_read = 4 + 22 + 1 + 2;
-
-	if (extra->n_samples) {
-		/* sample header size */
-		/*i = dumbfile_igetl(f);
-		if (!i || i > 0x28) i = 0x28;*/
-		dumbfile_skip(f, 4);
-		i = 0x28;
-		extra->sample_header_size = i;
-
-		/* sample map */
-		for (i = 0; i < 96; i++) {
-			instrument->map_sample[i] = dumbfile_getc(f) + 1;
-			instrument->map_note[i] = i;
-		}
-
-		if (dumbfile_error(f))
-			return 1;
-
-		/* volume/panning envelopes */
-		for (i = 0; i < 24; i++)
-			vol_points[i] = dumbfile_igetw(f);
-		for (i = 0; i < 24; i++)
-			pan_points[i] = dumbfile_igetw(f);
-
-		instrument->volume_envelope.n_nodes = dumbfile_getc(f);
-		instrument->pan_envelope.n_nodes = dumbfile_getc(f);
-
-		if (dumbfile_error(f))
-			return -1;
-
-		instrument->volume_envelope.sus_loop_start = dumbfile_getc(f);
-		instrument->volume_envelope.loop_start = dumbfile_getc(f);
-		instrument->volume_envelope.loop_end = dumbfile_getc(f);
-
-		instrument->pan_envelope.sus_loop_start = dumbfile_getc(f);
-		instrument->pan_envelope.loop_start = dumbfile_getc(f);
-		instrument->pan_envelope.loop_end = dumbfile_getc(f);
-
-		/* The envelope handler for XM files won't use sus_loop_end. */
-
-		type = dumbfile_getc(f);
-		instrument->volume_envelope.flags = 0;
-		if ((type & XM_ENVELOPE_ON) && instrument->volume_envelope.n_nodes)
-			instrument->volume_envelope.flags |= IT_ENVELOPE_ON;
-		if (type & XM_ENVELOPE_LOOP)    instrument->volume_envelope.flags |= IT_ENVELOPE_LOOP_ON;
-#if 1
-		if (type & XM_ENVELOPE_SUSTAIN) instrument->volume_envelope.flags |= IT_ENVELOPE_SUSTAIN_LOOP;
-#else // This is now handled in itrender.c
-		/* let's avoid fading out when reaching the last envelope node */
-		if (!(type & XM_ENVELOPE_LOOP)) {
-			instrument->volume_envelope.loop_start = instrument->volume_envelope.n_nodes-1;
-			instrument->volume_envelope.loop_end = instrument->volume_envelope.n_nodes-1;
-		}
-		instrument->volume_envelope.flags |= IT_ENVELOPE_LOOP_ON;
-#endif
-
-		type = dumbfile_getc(f);
-		instrument->pan_envelope.flags = 0;
-		if ((type & XM_ENVELOPE_ON) && instrument->pan_envelope.n_nodes)
-			instrument->pan_envelope.flags |= IT_ENVELOPE_ON;
-		if (type & XM_ENVELOPE_LOOP)    instrument->pan_envelope.flags |= IT_ENVELOPE_LOOP_ON; // should this be here?
-		if (type & XM_ENVELOPE_SUSTAIN) instrument->pan_envelope.flags |= IT_ENVELOPE_SUSTAIN_LOOP;
-
-		if (it_xm_make_envelope(&instrument->volume_envelope, vol_points, 0) != 0) {
-			TRACE("XM error: volume envelope\n");
-			if (instrument->volume_envelope.flags & IT_ENVELOPE_ON) return -1;
-		}
-
-		if (it_xm_make_envelope(&instrument->pan_envelope, pan_points, -32) != 0) {
-			TRACE("XM error: pan envelope\n");
-			if (instrument->pan_envelope.flags & IT_ENVELOPE_ON) return -1;
-		}
-
-		instrument->pitch_envelope.flags = 0;
-
-		extra->vibrato_type = dumbfile_getc(f);
-		extra->vibrato_sweep = dumbfile_getc(f);
-		extra->vibrato_depth = dumbfile_getc(f);
-		extra->vibrato_speed = dumbfile_getc(f);
-
-		if (dumbfile_error(f) || extra->vibrato_type > 4) // XXX
-			return -1;
-
-		/** WARNING: lossy approximation */
-		instrument->fadeout = (dumbfile_igetw(f)*128 + 64)/0xFFF;
-
-		dumbfile_skip(f, 2); /* reserved */
-
-		bytes_read += 4 + 96 + 48 + 48 + 14*1 + 2 + 2;
-	} else
-		for (i = 0; i < 96; i++)
-			instrument->map_sample[i] = 0;
-
-	if (size > bytes_read && dumbfile_skip(f, size - bytes_read))
-		return -1;
-
-	if (skip_end && limit_xm_skip_end(f, skip_end))
-		return -1;
-
-	instrument->new_note_action = NNA_NOTE_CUT;
-	instrument->dup_check_type = DCT_OFF;
-	instrument->dup_check_action = DCA_NOTE_CUT;
-	instrument->pp_separation = 0;
-	instrument->pp_centre = 60; /* C-5 */
-	instrument->global_volume = 128;
-	instrument->default_pan = 32;
-	instrument->random_volume = 0;
-	instrument->random_pan = 0;
-	instrument->filter_cutoff = 0;
-	instrument->filter_resonance = 0;
-
-	return 0;
-}
-
-
-
-/* I (entheh) have two XM files saved by a very naughty program. After a
- * 16-bit sample, it saved a rogue byte. The length of the sample was indeed
- * an odd number, incremented to include the rogue byte.
- *
- * In this function we are converting sample lengths and loop points so they
- * are measured in samples. This means we forget about the extra bytes, and
- * they don't get skipped. So we fail trying to read the next instrument.
- *
- * To get around this, this function returns the number of rogue bytes that
- * won't be accounted for by reading sample->length samples. It returns a
- * negative number on failure.
- */
-static int it_xm_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f)
-{
-	int type;
-	int relative_note_number; /* relative to C4 */
-	int finetune;
-	int roguebytes;
-	int roguebytesmask;
-	int reserved;
-
-	sample->length         = dumbfile_igetl(f);
-	sample->loop_start     = dumbfile_igetl(f);
-	sample->loop_end       = sample->loop_start + dumbfile_igetl(f);
-	sample->global_volume  = 64;
-	sample->default_volume = dumbfile_getc(f);
-	finetune               = (signed char)dumbfile_getc(f); /* -128..127 <=> -1 semitone .. +127/128 of a semitone */
-	type                   = dumbfile_getc(f);
-	sample->default_pan    = dumbfile_getc(f); /* 0-255 */
-	relative_note_number   = (signed char)dumbfile_getc(f);
-
-	reserved = dumbfile_getc(f);
-
-    dumbfile_getnc((char *)sample->name, 22, f);
-	sample->name[22] = 0;
-    trim_whitespace((char *)sample->name, 22);
-
-	sample->filename[0] = 0;
-
-	if (dumbfile_error(f))
-		return -1;
-
-	sample->C5_speed = (long)(16726.0*pow(DUMB_SEMITONE_BASE, relative_note_number) /**pow(DUMB_PITCH_BASE, )*/ );
-	sample->finetune = finetune*2;
-
-	sample->flags = IT_SAMPLE_EXISTS;
-
-	if (reserved == 0xAD &&
-		(!(type & (XM_SAMPLE_16BIT | XM_SAMPLE_STEREO))))
-	{
-		/* F U Olivier Lapicque */
-		roguebytes = 4;
-		roguebytesmask = 4 << 2;
-	}
-	else
-	{
-		roguebytes = (int)sample->length;
-		roguebytesmask = 3;
-	}
-
-	if (type & XM_SAMPLE_16BIT) {
-		sample->flags |= IT_SAMPLE_16BIT;
-		sample->length >>= 1;
-		sample->loop_start >>= 1;
-		sample->loop_end >>= 1;
-	} else
-		roguebytesmask >>= 1;
-
-	if (type & XM_SAMPLE_STEREO) {
-		sample->flags |= IT_SAMPLE_STEREO;
-		sample->length >>= 1;
-		sample->loop_start >>= 1;
-		sample->loop_end >>= 1;
-	} else
-		roguebytesmask >>= 1;
-
-	roguebytes &= roguebytesmask;
-
-	if ((unsigned int)sample->loop_start < (unsigned int)sample->loop_end) {
-		if (type & XM_SAMPLE_FORWARD_LOOP) sample->flags |= IT_SAMPLE_LOOP;
-		if (type & XM_SAMPLE_PINGPONG_LOOP) sample->flags |= IT_SAMPLE_LOOP | IT_SAMPLE_PINGPONG_LOOP;
-	}
-
-	if (sample->length <= 0)
-		sample->flags &= ~IT_SAMPLE_EXISTS;
-	else if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
-		sample->flags &= ~IT_SAMPLE_LOOP;
-	else if ((unsigned int)sample->loop_start >= (unsigned int)sample->loop_end)
-		sample->flags &= ~IT_SAMPLE_LOOP;
-
-	return roguebytes;
-}
-
-
-
-static int it_xm_read_sample_data(IT_SAMPLE *sample, unsigned char roguebytes, DUMBFILE *f)
-{
-	int old;
-	long i;
-	long truncated_size;
-	int n_channels;
-	long datasize;
-
-	if (!(sample->flags & IT_SAMPLE_EXISTS))
-		return dumbfile_skip(f, roguebytes);
-
-	/* let's get rid of the sample data coming after the end of the loop */
-	if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length && roguebytes != 4) {
-		truncated_size = sample->length - sample->loop_end;
-		sample->length = sample->loop_end;
-	} else {
-		truncated_size = 0;
-	}
-
-	n_channels = sample->flags & IT_SAMPLE_STEREO ? 2 : 1;
-	datasize = sample->length * n_channels;
-
-	sample->data = malloc(datasize * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
-	if (!sample->data)
-		return -1;
-
-	if (roguebytes == 4)
-	{
-		if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
-			return -1;
-		roguebytes = 0;
-	}
-	else
-	{
-		/* sample data is stored as signed delta values */
-		old = 0;
-		if (sample->flags & IT_SAMPLE_16BIT)
-			for (i = 0; i < sample->length; i++)
-				((short *)sample->data)[i*n_channels] = old += dumbfile_igetw(f);
-		else
-			for (i = 0; i < sample->length; i++)
-				((signed char *)sample->data)[i*n_channels] = old += dumbfile_getc(f);
-	}
-
-	/* skip truncated data */
-	dumbfile_skip(f, (sample->flags & IT_SAMPLE_16BIT) ? (2*truncated_size) : (truncated_size));
-
-	if (sample->flags & IT_SAMPLE_STEREO) {
-		old = 0;
-		if (sample->flags & IT_SAMPLE_16BIT)
-			for (i = 1; i < datasize; i += 2)
-				((short *)sample->data)[i] = old += dumbfile_igetw(f);
-		else
-			for (i = 1; i < datasize; i += 2)
-				((signed char *)sample->data)[i] = old += dumbfile_getc(f);
-
-		/* skip truncated data */
-		dumbfile_skip(f, (sample->flags & IT_SAMPLE_16BIT) ? (2*truncated_size) : (truncated_size));
-	}
-
-	dumbfile_skip(f, roguebytes);
-
-	if (dumbfile_error(f))
-		return -1;
-
-	return 0;
-}
-
-
-
-/* "Real programmers don't document. If it was hard to write,
- *  it should be hard to understand."
- *
- * (Never trust the documentation provided with a tracker.
- *  Real files are the only truth...)
- */
-static DUMB_IT_SIGDATA *it_xm_load_sigdata(DUMBFILE *f, int * version)
-{
-	DUMB_IT_SIGDATA *sigdata;
-	char id_text[18];
-
-	int header_size;
-	int flags;
-	int n_channels;
-	int total_samples;
-	int i, j;
-
-	/* check ID text */
-	if (dumbfile_getnc(id_text, 17, f) < 17)
-		return NULL;
-	id_text[17] = 0;
-	if (strcmp(id_text, "Extended Module: ") != 0) {
-		TRACE("XM error: Not an Extended Module\n");
-		return NULL;
-	}
-
-	sigdata = malloc(sizeof(*sigdata));
-	if (!sigdata)
-		return NULL;
-
-	/* song name */
-    if (dumbfile_getnc((char *)sigdata->name, 20, f) < 20) {
-		free(sigdata);
-		return NULL;
-	}
-	sigdata->name[20] = 0;
-    trim_whitespace((char *)sigdata->name, 20);
-
-	if (dumbfile_getc(f) != 0x1A) {
-		TRACE("XM error: 0x1A not found\n");
-		free(sigdata);
-		return NULL;
-	}
-
-	/* tracker name */
-	if (dumbfile_skip(f, 20)) {
-		free(sigdata);
-		return NULL;
-	}
-
-	/* version number */
-	* version = dumbfile_igetw(f);
-	if (* version > 0x0104 || * version < 0x0102) {
-		TRACE("XM error: wrong format version\n");
-		free(sigdata);
-		return NULL;
-	}
-
-	/*
-		------------------
-		---   Header   ---
-		------------------
-	*/
-
-	/* header size */
-	header_size = dumbfile_igetl(f);
-	if (header_size < (4 + 2*8 + 1) || header_size > 0x114) {
-		TRACE("XM error: unexpected header size\n");
-		free(sigdata);
-		return NULL;
-	}
-
-	sigdata->song_message = NULL;
-	sigdata->order = NULL;
-	sigdata->instrument = NULL;
-	sigdata->sample = NULL;
-	sigdata->pattern = NULL;
-	sigdata->midi = NULL;
-	sigdata->checkpoint = NULL;
-
-	sigdata->n_samples        = 0;
-	sigdata->n_orders         = dumbfile_igetw(f);
-	sigdata->restart_position = dumbfile_igetw(f);
-	n_channels                = dumbfile_igetw(f); /* max 32 but we'll be lenient */
-	sigdata->n_pchannels      = n_channels;
-	sigdata->n_patterns       = dumbfile_igetw(f);
-	sigdata->n_instruments    = dumbfile_igetw(f); /* max 128 */ /* XXX upped to 256 */
-	flags                     = dumbfile_igetw(f);
-	sigdata->speed            = dumbfile_igetw(f);
-	if (sigdata->speed == 0) sigdata->speed = 6; // Should we? What about tempo?
-	sigdata->tempo            = dumbfile_igetw(f);
-
-    // FT2 always clips restart position against the song length
-    if (sigdata->restart_position > sigdata->n_orders)
-        sigdata->restart_position = sigdata->n_orders;
-    // And FT2 starts playback on order 0, regardless of length,
-    // and only checks if the next order is greater than or equal
-    // to this, not the current pattern. Work around this with
-    // DUMB's playback core by overriding a zero length with one.
-    if (sigdata->n_orders == 0)
-        sigdata->n_orders = 1;
-
-	/* sanity checks */
-	// XXX
-	i = header_size - 4 - 2 * 8; /* Maximum number of orders expected */
-	if (dumbfile_error(f) || sigdata->n_orders <= 0 || sigdata->n_orders > i || sigdata->n_patterns > 256 || sigdata->n_instruments > 256 || n_channels > DUMB_IT_N_CHANNELS) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	//if (sigdata->restart_position >= sigdata->n_orders)
-		//sigdata->restart_position = 0;
-
-	/* order table */
-	sigdata->order = malloc(sigdata->n_orders*sizeof(*sigdata->order));
-	if (!sigdata->order) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-    dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
-	dumbfile_skip(f, i - sigdata->n_orders);
-
-	if (dumbfile_error(f)) {
-		_dumb_it_unload_sigdata(sigdata);
-		return NULL;
-	}
-
-	if ( * version > 0x103 ) {
-		/*
-			--------------------
-			---   Patterns   ---
-			--------------------
-		*/
-
-		sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-		if (!sigdata->pattern) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (i = 0; i < sigdata->n_patterns; i++)
-			sigdata->pattern[i].entry = NULL;
-
-		{
-			unsigned char *buffer = malloc(1280 * n_channels); /* 256 rows * 5 bytes */
-			if (!buffer) {
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-			for (i = 0; i < sigdata->n_patterns; i++) {
-				if (it_xm_read_pattern(&sigdata->pattern[i], f, n_channels, buffer, * version) != 0) {
-					free(buffer);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-			}
-			free(buffer);
-		}
-
-		/*
-		-----------------------------------
-		---   Instruments and Samples   ---
-		-----------------------------------
-		*/
-
-		sigdata->instrument = malloc(sigdata->n_instruments * sizeof(*sigdata->instrument));
-		if (!sigdata->instrument) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-
-		/* With XM, samples are not global, they're part of an instrument. In a
-		* file, each instrument is stored with its samples. Because of this, I
-		* don't know how to find how many samples are present in the file. Thus
-		* I have to do n_instruments reallocation on sigdata->sample.
-		* Looking at FT2, it doesn't seem possible to have more than 16 samples
-		* per instrument (even though n_samples is stored as 2 bytes). So maybe
-		* we could allocate a 128*16 array of samples, and shrink it back to the
-		* correct size when we know it?
-		* Alternatively, I could allocate samples by blocks of N (still O(n)),
-		* or double the number of allocated samples when I need more (O(log n)).
-		*/
-		total_samples = 0;
-		sigdata->sample = NULL;
-
-		for (i = 0; i < sigdata->n_instruments; i++) {
-			XM_INSTRUMENT_EXTRA extra;
-
-			DUMBFILE * lf = dumbfile_limit_xm( f );
-			if ( !lf ) {
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-
-			if (it_xm_read_instrument(&sigdata->instrument[i], &extra, lf) < 0) {
-				// XXX
-				if ( ! i )
-				{
-					TRACE("XM error: instrument %d\n", i+1);
-					dumbfile_close( lf );
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-				else
-				{
-					dumbfile_close( lf );
-					sigdata->n_instruments = i;
-					break;
-				}
-			}
-
-			if (extra.n_samples) {
-				unsigned char roguebytes[XM_MAX_SAMPLES_PER_INSTRUMENT];
-
-				/* adjust instrument sample map (make indices absolute) */
-				for (j = 0; j < 96; j++)
-					sigdata->instrument[i].map_sample[j] += total_samples;
-
-				sigdata->sample = safe_realloc(sigdata->sample, sizeof(*sigdata->sample)*(total_samples+extra.n_samples));
-				if (!sigdata->sample) {
-					dumbfile_close( lf );
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-				for (j = total_samples; j < total_samples+extra.n_samples; j++)
-					sigdata->sample[j].data = NULL;
-
-				if ( limit_xm_resize( lf, 0 ) < 0 ) {
-					dumbfile_close( lf );
-					_dumb_it_unload_sigdata( sigdata );
-					return NULL;
-				}
-
-				/* read instrument's samples */
-				for (j = 0; j < extra.n_samples; j++) {
-					IT_SAMPLE *sample = &sigdata->sample[total_samples+j];
-					int b;
-					if ( limit_xm_resize( lf, extra.sample_header_size ) < 0 ) {
-						dumbfile_close( lf );
-						_dumb_it_unload_sigdata( sigdata );
-						return NULL;
-					}
-					b = it_xm_read_sample_header(sample, lf);
-					if (b < 0) {
-						dumbfile_close( lf );
-						_dumb_it_unload_sigdata(sigdata);
-						return NULL;
-					}
-					roguebytes[j] = b;
-					// Any reason why these can't be set inside it_xm_read_sample_header()?
-					sample->vibrato_speed = extra.vibrato_speed;
-					sample->vibrato_depth = extra.vibrato_depth;
-					sample->vibrato_rate = extra.vibrato_sweep;
-					/* Rate and sweep don't match, but the difference is
-					* accounted for in itrender.c.
-				 */
-					sample->vibrato_waveform = xm_convert_vibrato[extra.vibrato_type];
-					sample->max_resampling_quality = -1;
-				}
-				for (j = 0; j < extra.n_samples; j++) {
-					if (it_xm_read_sample_data(&sigdata->sample[total_samples+j], roguebytes[j], f) != 0) {
-						dumbfile_close( lf );
-						_dumb_it_unload_sigdata(sigdata);
-						return NULL;
-					}
-				}
-				total_samples += extra.n_samples;
-			}
-
-			dumbfile_close( lf );
-		}
-
-		sigdata->n_samples = total_samples;
-	} else {
-		// ahboy! old layout!
-		// first instruments and sample headers, then patterns, then sample data!
-
-		/*
-		-----------------------------------
-		---   Instruments and Samples   ---
-		-----------------------------------
-		*/
-
-		unsigned char * roguebytes = malloc( sigdata->n_instruments * XM_MAX_SAMPLES_PER_INSTRUMENT );
-		if (!roguebytes) {
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-
-		sigdata->instrument = malloc(sigdata->n_instruments * sizeof(*sigdata->instrument));
-		if (!sigdata->instrument) {
-			free(roguebytes);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-
-		total_samples = 0;
-		sigdata->sample = NULL;
-
-		for (i = 0; i < sigdata->n_instruments; i++) {
-			XM_INSTRUMENT_EXTRA extra;
-
-			DUMBFILE * lf = dumbfile_limit_xm( f );
-			if ( !lf ) {
-				free(roguebytes);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-
-			if (it_xm_read_instrument(&sigdata->instrument[i], &extra, lf) < 0) {
-				TRACE("XM error: instrument %d\n", i+1);
-				dumbfile_close(lf);
-				free(roguebytes);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-
-			if (extra.n_samples) {
-				/* adjust instrument sample map (make indices absolute) */
-				for (j = 0; j < 96; j++)
-					sigdata->instrument[i].map_sample[j] += total_samples;
-
-				sigdata->sample = safe_realloc(sigdata->sample, sizeof(*sigdata->sample)*(total_samples+extra.n_samples));
-				if (!sigdata->sample) {
-					dumbfile_close( lf );
-					free(roguebytes);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-				for (j = total_samples; j < total_samples+extra.n_samples; j++)
-					sigdata->sample[j].data = NULL;
-
-				if ( limit_xm_resize( lf, 0 ) < 0 ) {
-					dumbfile_close( lf );
-					free( roguebytes );
-					_dumb_it_unload_sigdata( sigdata );
-					return NULL;
-				}
-
-				/* read instrument's samples */
-				for (j = 0; j < extra.n_samples; j++) {
-					IT_SAMPLE *sample = &sigdata->sample[total_samples+j];
-					int b;
-					if ( limit_xm_resize( lf, extra.sample_header_size ) < 0 ) {
-							dumbfile_close( lf );
-							free( roguebytes );
-							_dumb_it_unload_sigdata( sigdata );
-							return NULL;
-					}
-					b = it_xm_read_sample_header(sample, lf);
-					if (b < 0) {
-						free(roguebytes);
-						_dumb_it_unload_sigdata(sigdata);
-						return NULL;
-					}
-					roguebytes[total_samples+j] = b;
-					// Any reason why these can't be set inside it_xm_read_sample_header()?
-					sample->vibrato_speed = extra.vibrato_speed;
-					sample->vibrato_depth = extra.vibrato_depth;
-					sample->vibrato_rate = extra.vibrato_sweep;
-					/* Rate and sweep don't match, but the difference is
-					* accounted for in itrender.c.
-				 */
-					sample->vibrato_waveform = xm_convert_vibrato[extra.vibrato_type];
-					sample->max_resampling_quality = -1;
-				}
-				total_samples += extra.n_samples;
-			}
-
-			dumbfile_close( lf );
-		}
-
-		sigdata->n_samples = total_samples;
-
-		/*
-			--------------------
-			---   Patterns   ---
-			--------------------
-		*/
-
-		sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
-		if (!sigdata->pattern) {
-			free(roguebytes);
-			_dumb_it_unload_sigdata(sigdata);
-			return NULL;
-		}
-		for (i = 0; i < sigdata->n_patterns; i++)
-			sigdata->pattern[i].entry = NULL;
-
-		{
-			unsigned char *buffer = malloc(1280 * n_channels); /* 256 rows * 5 bytes */
-			if (!buffer) {
-				free(roguebytes);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-			for (i = 0; i < sigdata->n_patterns; i++) {
-				if (it_xm_read_pattern(&sigdata->pattern[i], f, n_channels, buffer, * version) != 0) {
-					free(buffer);
-					free(roguebytes);
-					_dumb_it_unload_sigdata(sigdata);
-					return NULL;
-				}
-			}
-			free(buffer);
-		}
-
-		// and now we load the sample data
-		for (j = 0; j < total_samples; j++) {
-			if (it_xm_read_sample_data(&sigdata->sample[j], roguebytes[j], f) != 0) {
-				free(roguebytes);
-				_dumb_it_unload_sigdata(sigdata);
-				return NULL;
-			}
-		}
-
-		free(roguebytes);
-	}
-
-
-	sigdata->flags = IT_WAS_AN_XM | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_STEREO | IT_USE_INSTRUMENTS;
-	// Are we OK with IT_COMPATIBLE_GXX off?
-	//
-	// When specifying note + instr + tone portamento, and an old note is still playing (even after note off):
-	// - If Compatible Gxx is on, the new note will be triggered only if the instrument _changes_.
-	// - If Compatible Gxx is off, the new note will always be triggered, provided the instrument is specified.
-	// - FT2 seems to do the latter (unconfirmed).
-
-	// Err, wait. XM playback has its own code. The change made to the IT
-	// playbackc code didn't affect XM playback. Forget this then. There's
-	// still a bug in XM playback though, and it'll need some investigation...
-	// tomorrow...
-
-	// UPDATE: IT_COMPATIBLE_GXX is required to be on, so that tone porta has
-	// separate memory from portamento.
-
-	if (flags & XM_LINEAR_FREQUENCY)
-		sigdata->flags |= IT_LINEAR_SLIDES;
-
-	sigdata->global_volume = 128;
-	sigdata->mixing_volume = 48;
-	sigdata->pan_separation = 128;
-
-	memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
-	memset(sigdata->channel_pan, 32, DUMB_IT_N_CHANNELS);
-
-	_dumb_it_fix_invalid_orders(sigdata);
-
-	return sigdata;
-}
-
-
-
-#if 0 // no fucking way, dude!
-
-/* The length returned is the time required to play from the beginning of the
- * file to the last row of the last order (which is when the player will
- * loop). Depending on the song, the sound might stop sooner.
- * Due to fixed point roundoffs, I think this is only reliable to the second.
- * Full precision could be achieved by using a double during the computation,
- * or maybe a LONG_LONG.
- */
-long it_compute_length(const DUMB_IT_SIGDATA *sigdata)
-{
-	IT_PATTERN *pattern;
-	int tempo, speed;
-	int loop_start[IT_N_CHANNELS];
-	char loop_count[IT_N_CHANNELS];
-	int order, entry;
-	int row_first_entry = 0;
-	int jump, jump_dest;
-	int delay, fine_delay;
-	int i;
-	long t;
-
-	if (!sigdata)
-		return 0;
-
-	tempo = sigdata->tempo;
-	speed = sigdata->speed;
-	order = entry = 0;
-	jump = jump_dest = 0;
-	t = 0;
-
-	/* for each PATTERN */
-	for (order = 0; order < sigdata->n_orders; order++) {
-
-		if (sigdata->order[order] == IT_ORDER_END) break;
-		if (sigdata->order[order] == IT_ORDER_SKIP) continue;
-
-		for (i = 0; i < IT_N_CHANNELS; i++)
-			loop_count[i] = -1;
-
-		pattern = &sigdata->pattern[ sigdata->order[order] ];
-		entry = 0;
-		if (jump == IT_BREAK_TO_ROW) {
-			int row = 0;
-			while (row < jump_dest)
-				if (pattern->entry[entry++].channel >= IT_N_CHANNELS)
-					row++;
-		}
-
-		/* for each ROW */
-		while (entry < pattern->n_entries) {
-			row_first_entry = entry;
-			delay = fine_delay = 0;
-			jump = 0;
-
-			/* for each note NOTE */
-			while (entry < pattern->n_entries && pattern->entry[entry].channel < IT_N_CHANNELS) {
-				int value   = pattern->entry[entry].effectvalue;
-				int channel = pattern->entry[entry].channel;
-
-				switch (pattern->entry[entry].effect) {
-
-					case IT_SET_SPEED: speed = value; break;
-
-					case IT_JUMP_TO_ORDER:
-						if (value <= order) /* infinite loop */
-							return 0;
-						jump = IT_JUMP_TO_ORDER;
-						jump_dest = value;
-						break;
-
-					case IT_BREAK_TO_ROW:
-						jump = IT_BREAK_TO_ROW;
-						jump_dest = value;
-						break;
-
-					case IT_S:
-						switch (HIGH(value)) {
-							case IT_S_PATTERN_DELAY:      delay      = LOW(value); break;
-							case IT_S_FINE_PATTERN_DELAY: fine_delay = LOW(value); break;
-							case IT_S_PATTERN_LOOP:
-								if (LOW(value) == 0) {
-									loop_start[channel] = row_first_entry;
-								} else {
-									if (loop_count[channel] == -1)
-										loop_count[channel] = LOW(value);
-
-									if (loop_count[channel]) {
-										jump = IT_S_PATTERN_LOOP;
-										jump_dest = loop_start[channel];
-									}
-									loop_count[channel]--;
-								}
-								break;
-						}
-						break;
-
-					case IT_SET_SONG_TEMPO:
-						switch (HIGH(value)) { /* slides happen every non-row frames */
-							case 0:  tempo = tempo - LOW(value)*(speed-1); break;
-							case 1:  tempo = tempo + LOW(value)*(speed-1); break;
-							default: tempo = value;
-						}
-						tempo = MID(32, tempo, 255);
-						break;
-				}
-
-				entry++;
-			}
-
-			/* end of ROW */
-			entry++;
-			t += TICK_TIME_DIVIDEND * (speed*(1+delay) + fine_delay) / tempo;
-
-			if (jump == IT_JUMP_TO_ORDER) {
-				order = jump_dest - 1;
-				break;
-			} else if (jump == IT_BREAK_TO_ROW)
-				break;
-			else if (jump == IT_S_PATTERN_LOOP)
-				entry = jump_dest - 1;
-		}
-
-		/* end of PATTERN */
-	}
-
-	return t;
-}
-
-#endif /* 0 */
-
-
-static char hexdigit(int in)
-{
-	if (in < 10) return in + '0';
-	else return in + 'A' - 10;
-}
-
-DUH *dumb_read_xm_quick(DUMBFILE *f)
-{
-	sigdata_t *sigdata;
-	int ver;
-
-	DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
-
-	sigdata = it_xm_load_sigdata(f, &ver);
-
-	if (!sigdata)
-		return NULL;
-
-	{
-		char version[16];
-		const char *tag[2][2];
-		tag[0][0] = "TITLE";
-        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
-		tag[1][0] = "FORMAT";
-		version[0] = 'X';
-		version[1] = 'M';
-		version[2] = ' ';
-		version[3] = 'v';
-		version[4] = hexdigit( ( ver >> 8 ) & 15 );
-		version[5] = '.';
-		version[6] = hexdigit( ( ver >> 4 ) & 15 );
-		version[7] = hexdigit( ver & 15 );
-		version[8] = 0;
-		tag[1][1] = ( const char * ) & version;
-		return make_duh(-1, 2, (const char *const (*)[2])tag, 1, &descptr, &sigdata);
-	}
-}
--- a/dumb/src/it/readxm2.c
+++ /dev/null
@@ -1,29 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * readxm2.c - Function to read a Fast Tracker II     / / \  \
- *             module from an open file and do an    | <  /   \_
- *             initial run-through.                  |  \/ /\   /
- *                                                    \_  /  > /
- * Split off from readxm.c by entheh.                   | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-#include "dumb.h"
-
-
-
-DUH *dumb_read_xm(DUMBFILE *f)
-{
-	DUH *duh = dumb_read_xm_quick(f);
-	dumb_it_do_initial_runthrough(duh);
-	return duh;
-}
--- a/dumb/src/it/xmeffect.c
+++ /dev/null
@@ -1,245 +1,0 @@
-/*  _______         ____    __         ___    ___
- * \    _  \       \    /  \  /       \   \  /   /       '   '  '
- *  |  | \  \       |  |    ||         |   \/   |         .      .
- *  |  |  |  |      |  |    ||         ||\  /|  |
- *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
- *  |  |  |  |      |  |    ||         ||    |  |         .      .
- *  |  |_/  /        \  \__//          ||    |  |
- * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
- *                                                      /  \
- *                                                     / .  \
- * xmeffect.c - Code for converting MOD/XM            / / \  \
- *              effects to IT effects.               | <  /   \_
- *                                                   |  \/ /\   /
- * By Julien Cugniere. Ripped out of readxm.c         \_  /  > /
- * by entheh.                                           | \ / /
- *                                                      |  ' /
- *                                                       \__/
- */
-
-
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dumb.h"
-#include "internal/it.h"
-
-#if 0
-unsigned char **_dumb_malloc2(int w, int h)
-{
-	unsigned char **line =  malloc(h * sizeof(*line));
-	int i;
-	if (!line) return NULL;
-
-	line[0] = malloc(w * h * sizeof(*line[0]));
-	if (!line[0]) {
-		free(line);
-		return NULL;
-	}
-
-	for (i = 1; i < h; i++)
-		line[i] = line[i-1] + w;
-
-	memset(line[0], 0, w*h);
-
-	return line;
-}
-
-
-
-void _dumb_free2(unsigned char **line)
-{
-	if (line) {
-		if (line[0])
-			free(line[0]);
-		free(line);
-	}
-}
-
-
-
-/* Effects having a memory. 2 means that the two parts of the effectvalue
- * should be handled separately.
- */
-static const char xm_has_memory[] = {
-/*	0  1  2  3  4  5  6  7  8  9  A  B  C  D (E) F  G  H        K  L           P     R     T          (X) */
-	0, 1, 1, 1, 2, 1, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
-
-/*  E0 E1 E2 E3 E4 E5 E6 E7    E9 EA EB EC ED EE         X1 X2 */
-	0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,   0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-#endif
-
-
-
-/* Effects marked with 'special' are handled specifically in itrender.c */
-void _dumb_it_xm_convert_effect(int effect, int value, IT_ENTRY *entry, int mod)
-{
-const int log = 0;
-
-	if ((!effect && !value) || (effect >= XM_N_EFFECTS))
-		return;
-
-if (log) printf("%c%02X", (effect<10)?('0'+effect):('A'+effect-10), value);
-
-	/* Linearisation of the effect number... */
-	if (effect == XM_E) {
-		effect = EBASE + HIGH(value);
-		value = LOW(value);
-	} else if (effect == XM_X) {
-		effect = XBASE + HIGH(value);
-		value = LOW(value);
-	}
-
-if (log) printf(" - %2d %02X", effect, value);
-
-#if 0 // This should be handled in itrender.c!
-	/* update effect memory */
-	switch (xm_has_memory[effect]) {
-		case 1:
-			if (!value)
-				value = memory[entry->channel][effect];
-			else
-				memory[entry->channel][effect] = value;
-			break;
-
-		case 2:
-			if (!HIGH(value))
-				SET_HIGH(value, HIGH(memory[entry->channel][effect]));
-			else
-				SET_HIGH(memory[entry->channel][effect], HIGH(value));
-
-			if (!LOW(value))
-				SET_LOW(value, LOW(memory[entry->channel][effect]));
-			else
-				SET_LOW(memory[entry->channel][effect], LOW(value));
-			break;
-	}
-#endif
-
-	/* convert effect */
-	entry->mask |= IT_ENTRY_EFFECT;
-	switch (effect) {
-
-		case XM_APPREGIO:           effect = IT_ARPEGGIO;           break;
-		case XM_VIBRATO:            effect = IT_VIBRATO;            break;
-		case XM_TONE_PORTAMENTO:    effect = IT_TONE_PORTAMENTO;    break;
-		case XM_TREMOLO:            effect = IT_TREMOLO;            break;
-		case XM_SET_PANNING:        effect = IT_SET_PANNING;        break;
-		case XM_SAMPLE_OFFSET:      effect = IT_SET_SAMPLE_OFFSET;  break;
-		case XM_POSITION_JUMP:      effect = IT_JUMP_TO_ORDER;      break;
-		case XM_MULTI_RETRIG:       effect = IT_RETRIGGER_NOTE;     break;
-		case XM_TREMOR:             effect = IT_TREMOR;             break;
-		case XM_PORTAMENTO_UP:      effect = IT_XM_PORTAMENTO_UP;   break;
-		case XM_PORTAMENTO_DOWN:    effect = IT_XM_PORTAMENTO_DOWN; break;
-		case XM_SET_CHANNEL_VOLUME: effect = IT_SET_CHANNEL_VOLUME; break; /* special */
-		case XM_VOLSLIDE_TONEPORTA: effect = IT_VOLSLIDE_TONEPORTA; break; /* special */
-		case XM_VOLSLIDE_VIBRATO:   effect = IT_VOLSLIDE_VIBRATO;   break; /* special */
-
-		case XM_PATTERN_BREAK:
-			effect = IT_BREAK_TO_ROW;
-			value = BCD_TO_NORMAL(value);
-			if (value > 63) value = 0; /* FT2, maybe ProTracker? */
-			break;
-
-		case XM_VOLUME_SLIDE: /* special */
-			effect = IT_VOLUME_SLIDE;
-			value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0) : EFFECT_VALUE(0, LOW(value));
-			break;
-
-		case XM_PANNING_SLIDE:
-			effect = IT_PANNING_SLIDE;
-			//value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0) : EFFECT_VALUE(0, LOW(value));
-			value = HIGH(value) ? EFFECT_VALUE(0, HIGH(value)) : EFFECT_VALUE(LOW(value), 0);
-			break;
-
-		case XM_GLOBAL_VOLUME_SLIDE: /* special */
-			effect = IT_GLOBAL_VOLUME_SLIDE;
-			value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0) : EFFECT_VALUE(0, LOW(value));
-			break;
-
-		case XM_SET_TEMPO_BPM:
-			if (mod) effect = (value <= 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
-			else effect = (value < 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
-			break;
-
-		case XM_SET_GLOBAL_VOLUME:
-			effect = IT_SET_GLOBAL_VOLUME;
-			value *= 2;
-			if (value > 128) value = 128;
-			break;
-
-		case XM_KEY_OFF:
-			effect = IT_XM_KEY_OFF;
-			break;
-
-		case XM_SET_ENVELOPE_POSITION:
-			effect = IT_XM_SET_ENVELOPE_POSITION;
-			break;
-
-		case EBASE+XM_E_SET_FILTER:            effect = SBASE+IT_S_SET_FILTER;            break;
-		case EBASE+XM_E_SET_GLISSANDO_CONTROL: effect = SBASE+IT_S_SET_GLISSANDO_CONTROL; break; /** TODO */
-		case EBASE+XM_E_SET_FINETUNE:          effect = SBASE+IT_S_FINETUNE;              break;
-		case EBASE+XM_E_SET_LOOP:              effect = SBASE+IT_S_PATTERN_LOOP;          break;
-		case EBASE+XM_E_NOTE_CUT:              effect = SBASE+IT_S_DELAYED_NOTE_CUT;      break;
-		case EBASE+XM_E_NOTE_DELAY:            effect = SBASE+IT_S_NOTE_DELAY;            break;
-		case EBASE+XM_E_PATTERN_DELAY:         effect = SBASE+IT_S_PATTERN_DELAY;         break;
-		case EBASE+XM_E_SET_PANNING:           effect = SBASE+IT_S_SET_PAN;               break;
-		case EBASE+XM_E_FINE_VOLSLIDE_UP:      effect = IT_XM_FINE_VOLSLIDE_UP;           break;
-		case EBASE+XM_E_FINE_VOLSLIDE_DOWN:    effect = IT_XM_FINE_VOLSLIDE_DOWN;         break;
-		case EBASE+XM_E_SET_MIDI_MACRO:        effect = SBASE+IT_S_SET_MIDI_MACRO;        break;
-
-		case EBASE + XM_E_FINE_PORTA_UP:
-			effect = IT_PORTAMENTO_UP;
-			value = EFFECT_VALUE(0xF, value);
-			break;
-
-		case EBASE + XM_E_FINE_PORTA_DOWN:
-			effect = IT_PORTAMENTO_DOWN;
-			value = EFFECT_VALUE(0xF, value);
-			break;
-
-		case EBASE + XM_E_RETRIG_NOTE:
-			effect = IT_XM_RETRIGGER_NOTE;
-			value = EFFECT_VALUE(0, value);
-			break;
-
-		case EBASE + XM_E_SET_VIBRATO_CONTROL:
-			effect = SBASE+IT_S_SET_VIBRATO_WAVEFORM;
-			value &= ~4;
-			break;
-
-		case EBASE + XM_E_SET_TREMOLO_CONTROL:
-			effect = SBASE+IT_S_SET_TREMOLO_WAVEFORM;
-			value &= ~4;
-			break;
-
-		case XBASE + XM_X_EXTRAFINE_PORTA_UP:
-			effect = IT_PORTAMENTO_UP;
-			value = EFFECT_VALUE(0xE, value);
-			break;
-
-		case XBASE + XM_X_EXTRAFINE_PORTA_DOWN:
-			effect = IT_PORTAMENTO_DOWN;
-			value = EFFECT_VALUE(0xE, value);
-			break;
-
-		default:
-			/* user effect (often used in demos for synchronisation) */
-			entry->mask &= ~IT_ENTRY_EFFECT;
-	}
-
-if (log) printf(" - %2d %02X", effect, value);
-
-	/* Inverse linearisation... */
-	if (effect >= SBASE && effect < SBASE+16) {
-		value = EFFECT_VALUE(effect-SBASE, value);
-		effect = IT_S;
-	}
-
-if (log) printf(" - %c%02X\n", 'A'+effect-1, value);
-
-	entry->effect = effect;
-	entry->effectvalue = value;
-}
--- a/dumb/vc6/dumb/.gitignore
+++ /dev/null
@@ -1,3 +1,0 @@
-*.user
-Debug
-Release
\ No newline at end of file
--- a/dumb/vc6/dumb/dumb.vcproj
+++ /dev/null
@@ -1,2007 +1,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
-	ProjectType="Visual C++"
-	Version="9.00"
-	Name="dumb"
-	ProjectGUID="{612D360C-A51B-4B34-8F49-33F42A2957F5}"
-	RootNamespace="dumb"
-	SccProjectName="&quot;$/foobar2000/plugins.root/plugins&quot;, CEAAAAAA"
-	SccLocalPath="..\..\..\.."
-	SccProvider="MSSCCI:Microsoft Visual SourceSafe"
-	TargetFrameworkVersion="131072"
-	>
-	<Platforms>
-		<Platform
-			Name="Win32"
-		/>
-	</Platforms>
-	<ToolFiles>
-	</ToolFiles>
-	<Configurations>
-		<Configuration
-			Name="Release|Win32"
-			OutputDirectory="$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
-			ConfigurationType="4"
-			UseOfMFC="0"
-			ATLMinimizesCRunTimeLibraryUsage="false"
-			CharacterSet="2"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-			/>
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="2"
-				WholeProgramOptimization="true"
-				AdditionalIncludeDirectories="../../include"
-				PreprocessorDefinitions="NDEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED"
-				StringPooling="true"
-				RuntimeLibrary="2"
-				EnableFunctionLevelLinking="true"
-				PrecompiledHeaderFile="$(IntDir)\$(ProjectName).pch"
-				AssemblerListingLocation="$(IntDir)\"
-				ObjectFile="$(IntDir)\"
-				ProgramDataBaseFileName="$(IntDir)\"
-				WarningLevel="3"
-				SuppressStartupBanner="true"
-				CompileAs="0"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-				PreprocessorDefinitions="NDEBUG"
-				Culture="1033"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				Name="VCLibrarianTool"
-				OutputFile="$(OutDir)\$(ProjectName).lib"
-				SuppressStartupBanner="true"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-		<Configuration
-			Name="Debug|Win32"
-			OutputDirectory="$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
-			ConfigurationType="4"
-			UseOfMFC="0"
-			ATLMinimizesCRunTimeLibraryUsage="false"
-			CharacterSet="2"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-			/>
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="../../include"
-				PreprocessorDefinitions="_DEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED;DEBUGMODE=1"
-				BasicRuntimeChecks="3"
-				RuntimeLibrary="1"
-				PrecompiledHeaderFile="$(IntDir)\$(ProjectName).pch"
-				AssemblerListingLocation="$(IntDir)\"
-				ObjectFile="$(IntDir)\"
-				ProgramDataBaseFileName="$(IntDir)\"
-				WarningLevel="3"
-				SuppressStartupBanner="true"
-				DebugInformationFormat="4"
-				CompileAs="0"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-				PreprocessorDefinitions="_DEBUG"
-				Culture="1033"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				Name="VCLibrarianTool"
-				OutputFile="$(OutDir)\$(ProjectName).lib"
-				SuppressStartupBanner="true"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-		<Configuration
-			Name="Release staticlink|Win32"
-			OutputDirectory="$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
-			ConfigurationType="4"
-			UseOfMFC="0"
-			ATLMinimizesCRunTimeLibraryUsage="false"
-			CharacterSet="2"
-			WholeProgramOptimization="1"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-			/>
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				InlineFunctionExpansion="2"
-				AdditionalIncludeDirectories="../../include"
-				PreprocessorDefinitions="NDEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED"
-				StringPooling="true"
-				RuntimeLibrary="0"
-				EnableFunctionLevelLinking="true"
-				PrecompiledHeaderFile="$(IntDir)\$(ProjectName).pch"
-				AssemblerListingLocation="$(IntDir)\"
-				ObjectFile="$(IntDir)\"
-				ProgramDataBaseFileName="$(IntDir)\"
-				WarningLevel="3"
-				SuppressStartupBanner="true"
-				DebugInformationFormat="3"
-				CompileAs="0"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-				PreprocessorDefinitions="NDEBUG"
-				Culture="1033"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				Name="VCLibrarianTool"
-				OutputFile="$(OutDir)\$(ProjectName).lib"
-				SuppressStartupBanner="true"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-	</Configurations>
-	<References>
-	</References>
-	<Files>
-		<Filter
-			Name="src"
-			>
-			<Filter
-				Name="core"
-				>
-				<File
-					RelativePath="..\..\src\core\atexit.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\duhlen.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\duhtag.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\dumbfile.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\loadduh.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\makeduh.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\rawsig.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\readduh.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\register.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\rendduh.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\rendsig.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\core\unload.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-			</Filter>
-			<Filter
-				Name="helpers"
-				>
-				<File
-					RelativePath="..\..\src\helpers\barray.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\clickrem.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\memfile.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\resamp2.inc"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\resamp3.inc"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\resample.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\resample.inc"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCustomBuildTool"
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\riff.c"
-					>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\sampbuf.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\silence.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\helpers\stdfile.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-			</Filter>
-			<Filter
-				Name="it"
-				>
-				<File
-					RelativePath="..\..\src\it\itmisc.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\it\itorder.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\it\itrender.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\it\itunload.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\it\ptmeffect.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<File
-					RelativePath="..\..\src\it\xmeffect.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="0"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-							BasicRuntimeChecks="3"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release staticlink|Win32"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							Optimization="2"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-				</File>
-				<Filter
-					Name="loaders"
-					>
-					<File
-						RelativePath="..\..\src\it\itload.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\itload2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\load669.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\load6692.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadamf.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadamf2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadasy.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadasy2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadmod.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadmod2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadmtm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadmtm2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadoldpsm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadoldpsm2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadpsm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadpsm2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadptm.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadptm2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadriff.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadriff2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loads3m.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loads3m2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadstm.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadstm2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadxm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\loadxm2.c"
-						>
-					</File>
-				</Filter>
-				<Filter
-					Name="readers"
-					>
-					<File
-						RelativePath="..\..\src\it\itread.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\itread2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\read669.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\read6692.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readam.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readamf.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readamf2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readasy.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readdsmf.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readmod.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readmod2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readmtm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readoldpsm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readpsm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readptm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readriff.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\reads3m.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\reads3m2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readstm.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readstm2.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\helpers\fir_resampler.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\helpers\lpc.c"
-						>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readxm.c"
-						>
-						<FileConfiguration
-							Name="Release|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Debug|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="0"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-								BasicRuntimeChecks="3"
-							/>
-						</FileConfiguration>
-						<FileConfiguration
-							Name="Release staticlink|Win32"
-							>
-							<Tool
-								Name="VCCLCompilerTool"
-								Optimization="2"
-								AdditionalIncludeDirectories=""
-								PreprocessorDefinitions=""
-							/>
-						</FileConfiguration>
-					</File>
-					<File
-						RelativePath="..\..\src\it\readxm2.c"
-						>
-					</File>
-				</Filter>
-			</Filter>
-		</Filter>
-		<Filter
-			Name="include"
-			>
-			<File
-				RelativePath="..\..\include\dumb.h"
-				>
-			</File>
-			<Filter
-				Name="internal"
-				>
-				<File
-					RelativePath="..\..\include\internal\barray.h"
-					>
-				</File>
-				<File
-					RelativePath="..\..\include\internal\dumb.h"
-					>
-				</File>
-				<File
-					RelativePath="..\..\include\internal\dumbfile.h"
-					>
-				</File>
-				<File
-					RelativePath="..\..\include\internal\it.h"
-					>
-				</File>
-				<File
-					RelativePath="..\..\include\internal\riff.h"
-					>
-				</File>
-				<File
-					RelativePath="..\..\include\internal\fir_resampler.h"
-					>
-				</File>
-				<File
-					RelativePath="..\..\include\internal\lpc.h"
-					>
-				</File>
-				<File
-					RelativePath="..\..\include\internal\stack_alloc.h"
-					>
-				</File>
-			</Filter>
-		</Filter>
-	</Files>
-	<Globals>
-	</Globals>
-</VisualStudioProject>
--- a/dumb/vc6/dumb/dumb.vcxproj
+++ /dev/null
@@ -1,217 +1,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{612D360C-A51B-4B34-8F49-33F42A2957F5}</ProjectGuid>
-    <RootNamespace>dumb</RootNamespace>
-    <SccProjectName>
-    </SccProjectName>
-    <SccLocalPath>
-    </SccLocalPath>
-    <SccProvider>
-    </SccProvider>
-    <SccAuxPath>
-    </SccAuxPath>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <PlatformToolset>v100</PlatformToolset>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <PlatformToolset>v100</PlatformToolset>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup>
-    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
-    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
-    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_USE_SSE;RESAMPLER_DECORATE=dumb;BARRAY_DECORATE=dumb;_DEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED;DEBUGMODE=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
-      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
-      <WarningLevel>Level3</WarningLevel>
-      <SuppressStartupBanner>true</SuppressStartupBanner>
-      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
-      <CompileAs>Default</CompileAs>
-    </ClCompile>
-    <ResourceCompile>
-      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <Culture>0x0409</Culture>
-    </ResourceCompile>
-    <Lib>
-      <SuppressStartupBanner>true</SuppressStartupBanner>
-    </Lib>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <Optimization>MaxSpeed</Optimization>
-      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
-      <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_WIN32_WINNT=0x501;_USE_SSE;RESAMPLER_DECORATE=dumb;BARRAY_DECORATE=dumb;NDEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <StringPooling>true</StringPooling>
-      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <WarningLevel>Level3</WarningLevel>
-      <SuppressStartupBanner>true</SuppressStartupBanner>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <CompileAs>Default</CompileAs>
-      <FloatingPointModel>Fast</FloatingPointModel>
-    </ClCompile>
-    <ResourceCompile>
-      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <Culture>0x0409</Culture>
-    </ResourceCompile>
-    <Lib>
-      <SuppressStartupBanner>true</SuppressStartupBanner>
-    </Lib>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\src\core\atexit.c" />
-    <ClCompile Include="..\..\src\core\duhlen.c" />
-    <ClCompile Include="..\..\src\core\duhtag.c" />
-    <ClCompile Include="..\..\src\core\dumbfile.c" />
-    <ClCompile Include="..\..\src\core\loadduh.c" />
-    <ClCompile Include="..\..\src\core\makeduh.c" />
-    <ClCompile Include="..\..\src\core\rawsig.c" />
-    <ClCompile Include="..\..\src\core\readduh.c" />
-    <ClCompile Include="..\..\src\core\register.c" />
-    <ClCompile Include="..\..\src\core\rendduh.c" />
-    <ClCompile Include="..\..\src\core\rendsig.c" />
-    <ClCompile Include="..\..\src\core\unload.c" />
-    <ClCompile Include="..\..\src\helpers\barray.c" />
-    <ClCompile Include="..\..\src\helpers\clickrem.c" />
-    <ClCompile Include="..\..\src\helpers\resampler.c" />
-    <ClCompile Include="..\..\src\helpers\lpc.c" />
-    <ClCompile Include="..\..\src\helpers\memfile.c" />
-    <ClCompile Include="..\..\src\helpers\resample.c" />
-    <ClCompile Include="..\..\src\helpers\riff.c" />
-    <ClCompile Include="..\..\src\helpers\sampbuf.c" />
-    <ClCompile Include="..\..\src\helpers\silence.c" />
-    <ClCompile Include="..\..\src\helpers\stdfile.c" />
-    <ClCompile Include="..\..\src\helpers\tarray.c" />
-    <ClCompile Include="..\..\src\it\itmisc.c" />
-    <ClCompile Include="..\..\src\it\itorder.c" />
-    <ClCompile Include="..\..\src\it\itrender.c" />
-    <ClCompile Include="..\..\src\it\itunload.c" />
-    <ClCompile Include="..\..\src\it\loadany.c" />
-    <ClCompile Include="..\..\src\it\loadany2.c" />
-    <ClCompile Include="..\..\src\it\loadokt.c" />
-    <ClCompile Include="..\..\src\it\loadokt2.c" />
-    <ClCompile Include="..\..\src\it\ptmeffect.c" />
-    <ClCompile Include="..\..\src\it\readany.c" />
-    <ClCompile Include="..\..\src\it\readany2.c" />
-    <ClCompile Include="..\..\src\it\readokt.c" />
-    <ClCompile Include="..\..\src\it\readokt2.c" />
-    <ClCompile Include="..\..\src\it\xmeffect.c" />
-    <ClCompile Include="..\..\src\it\itload.c" />
-    <ClCompile Include="..\..\src\it\itload2.c" />
-    <ClCompile Include="..\..\src\it\load669.c" />
-    <ClCompile Include="..\..\src\it\load6692.c" />
-    <ClCompile Include="..\..\src\it\loadamf.c" />
-    <ClCompile Include="..\..\src\it\loadamf2.c" />
-    <ClCompile Include="..\..\src\it\loadasy.c" />
-    <ClCompile Include="..\..\src\it\loadasy2.c" />
-    <ClCompile Include="..\..\src\it\loadmod.c" />
-    <ClCompile Include="..\..\src\it\loadmod2.c" />
-    <ClCompile Include="..\..\src\it\loadmtm.c" />
-    <ClCompile Include="..\..\src\it\loadmtm2.c" />
-    <ClCompile Include="..\..\src\it\loadoldpsm.c" />
-    <ClCompile Include="..\..\src\it\loadoldpsm2.c" />
-    <ClCompile Include="..\..\src\it\loadpsm.c" />
-    <ClCompile Include="..\..\src\it\loadpsm2.c" />
-    <ClCompile Include="..\..\src\it\loadptm.c" />
-    <ClCompile Include="..\..\src\it\loadptm2.c" />
-    <ClCompile Include="..\..\src\it\loadriff.c" />
-    <ClCompile Include="..\..\src\it\loadriff2.c" />
-    <ClCompile Include="..\..\src\it\loads3m.c" />
-    <ClCompile Include="..\..\src\it\loads3m2.c" />
-    <ClCompile Include="..\..\src\it\loadstm.c" />
-    <ClCompile Include="..\..\src\it\loadstm2.c" />
-    <ClCompile Include="..\..\src\it\loadxm.c" />
-    <ClCompile Include="..\..\src\it\loadxm2.c" />
-    <ClCompile Include="..\..\src\it\itread.c" />
-    <ClCompile Include="..\..\src\it\itread2.c" />
-    <ClCompile Include="..\..\src\it\read669.c" />
-    <ClCompile Include="..\..\src\it\read6692.c" />
-    <ClCompile Include="..\..\src\it\readam.c" />
-    <ClCompile Include="..\..\src\it\readamf.c" />
-    <ClCompile Include="..\..\src\it\readamf2.c" />
-    <ClCompile Include="..\..\src\it\readasy.c" />
-    <ClCompile Include="..\..\src\it\readdsmf.c" />
-    <ClCompile Include="..\..\src\it\readmod.c" />
-    <ClCompile Include="..\..\src\it\readmod2.c" />
-    <ClCompile Include="..\..\src\it\readmtm.c" />
-    <ClCompile Include="..\..\src\it\readoldpsm.c" />
-    <ClCompile Include="..\..\src\it\readpsm.c" />
-    <ClCompile Include="..\..\src\it\readptm.c" />
-    <ClCompile Include="..\..\src\it\readriff.c" />
-    <ClCompile Include="..\..\src\it\reads3m.c" />
-    <ClCompile Include="..\..\src\it\reads3m2.c" />
-    <ClCompile Include="..\..\src\it\readstm.c" />
-    <ClCompile Include="..\..\src\it\readstm2.c" />
-    <ClCompile Include="..\..\src\it\readxm.c" />
-    <ClCompile Include="..\..\src\it\readxm2.c" />
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="..\..\src\helpers\resamp2.inc">
-      <FileType>Document</FileType>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-    </CustomBuild>
-    <CustomBuild Include="..\..\src\helpers\resamp3.inc">
-      <FileType>Document</FileType>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-    </CustomBuild>
-    <CustomBuild Include="..\..\src\helpers\resample.inc">
-      <FileType>Document</FileType>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-    </CustomBuild>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\include\dumb.h" />
-    <ClInclude Include="..\..\include\internal\barray.h" />
-    <ClInclude Include="..\..\include\internal\dumb.h" />
-    <ClInclude Include="..\..\include\internal\dumbfile.h" />
-    <ClInclude Include="..\..\include\internal\fir_resampler.h" />
-    <ClInclude Include="..\..\include\internal\it.h" />
-    <ClInclude Include="..\..\include\internal\resampler.h" />
-    <ClInclude Include="..\..\include\internal\lpc.h" />
-    <ClInclude Include="..\..\include\internal\riff.h" />
-    <ClInclude Include="..\..\include\internal\stack_alloc.h" />
-    <ClInclude Include="..\..\include\internal\tarray.h" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
-</Project>
\ No newline at end of file
--- a/dumb/vc6/dumb/dumb.vcxproj.filters
+++ /dev/null
@@ -1,332 +1,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="include">
-      <UniqueIdentifier>{419c5e1f-2bf4-473a-b2e5-2e531285aa62}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="include\internal">
-      <UniqueIdentifier>{44b333b3-1607-4820-82bc-e4c21a40e31a}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="src">
-      <UniqueIdentifier>{0b122556-3781-4ef3-87fe-ffa5fb50b493}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="src\core">
-      <UniqueIdentifier>{e961cd19-26f6-4df0-b895-e099d3e81db9}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="src\helpers">
-      <UniqueIdentifier>{82e35139-08ff-4e99-a3ce-2254d7427ec4}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="src\it">
-      <UniqueIdentifier>{5f7fc0f6-4008-4166-83ad-e5d914718bd0}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="src\it\loaders">
-      <UniqueIdentifier>{0fd0715e-5824-4419-aa5b-2d4272d222ce}</UniqueIdentifier>
-    </Filter>
-    <Filter Include="src\it\readers">
-      <UniqueIdentifier>{b9e26fe7-6056-4580-b2c6-10e6116d4129}</UniqueIdentifier>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\src\core\atexit.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\duhlen.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\duhtag.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\dumbfile.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\loadduh.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\makeduh.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\rawsig.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\readduh.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\register.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\rendduh.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\rendsig.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\core\unload.c">
-      <Filter>src\core</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\barray.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\clickrem.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\lpc.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\memfile.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\resample.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\riff.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\sampbuf.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\silence.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\stdfile.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itload.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itload2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itmisc.c">
-      <Filter>src\it</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itorder.c">
-      <Filter>src\it</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itread.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itread2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itrender.c">
-      <Filter>src\it</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\itunload.c">
-      <Filter>src\it</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\load669.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\load6692.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadamf.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadamf2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadasy.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadasy2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadmod.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadmod2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadmtm.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadmtm2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadoldpsm.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadoldpsm2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadpsm.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadpsm2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadptm.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadptm2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadriff.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadriff2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loads3m.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loads3m2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadstm.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadstm2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadxm.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadxm2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\ptmeffect.c">
-      <Filter>src\it</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\read669.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\read6692.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readam.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readamf.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readamf2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readasy.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readdsmf.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readmod.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readmod2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readmtm.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readoldpsm.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readpsm.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readptm.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readriff.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\reads3m.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\reads3m2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readstm.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readstm2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readxm.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readxm2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\xmeffect.c">
-      <Filter>src\it</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readokt.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readokt2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadokt.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadokt2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadany.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\loadany2.c">
-      <Filter>src\it\loaders</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readany.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\it\readany2.c">
-      <Filter>src\it\readers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\resampler.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-    <ClCompile Include="..\..\src\helpers\tarray.c">
-      <Filter>src\helpers</Filter>
-    </ClCompile>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\include\dumb.h">
-      <Filter>include</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\barray.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\dumb.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\dumbfile.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\fir_resampler.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\it.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\lpc.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\riff.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\stack_alloc.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\resampler.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-    <ClInclude Include="..\..\include\internal\tarray.h">
-      <Filter>include\internal</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <CustomBuild Include="..\..\src\helpers\resamp3.inc">
-      <Filter>src\helpers</Filter>
-    </CustomBuild>
-    <CustomBuild Include="..\..\src\helpers\resamp2.inc">
-      <Filter>src\helpers</Filter>
-    </CustomBuild>
-    <CustomBuild Include="..\..\src\helpers\resample.inc">
-      <Filter>src\helpers</Filter>
-    </CustomBuild>
-  </ItemGroup>
-</Project>
\ No newline at end of file
--- /dev/null
+++ b/examples/README.md
@@ -1,0 +1,19 @@
+# libdumb example programs
+
+Two simple example programs are provided.
+
+
+## dumbplay
+
+dumplay will play a module file from command-line. It requires SDL2 for audio
+output and argtable2 for argument parsing.
+
+
+## dumbout
+
+dumbout streams a module file to raw PCM. This can be used to pipe its output
+to an encoder such as oggenc (with appropriate command-line options). Or it can
+be written to a .pcm file which can be read by any respectable waveform editor.
+It is also convenient for timing DUMB. Compare the time it takes to render a
+module with the module's playing time! All options are set on the command line.
+The argtable2-library is required for argument parsing.
--- /dev/null
+++ b/examples/dumbout.c
@@ -1,0 +1,306 @@
+#include <argtable2.h>
+#include <dumb.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdbool.h>
+#include <math.h>
+
+static const int endian_test = 1;
+#define is_bigendian() ((*(char *)&endian_test) == 0)
+
+enum ENDIANNESS { DUMB_LITTLE_ENDIAN = 0, DUMB_BIG_ENDIAN };
+
+typedef struct {
+    DUH_SIGRENDERER *renderer;
+    DUH *src;
+    sample_t **sig_samples;
+    long sig_samples_size;
+    FILE *dst;
+    float delta;
+    int bufsize;
+    bool is_stdout;
+} streamer_t;
+
+typedef struct {
+    int bits;
+    int endianness;
+    int is_unsigned;
+    int freq;
+    int quality;
+    int n_channels;
+    float volume;
+    float delay;
+    const char *input;
+    char *output;
+} settings_t;
+
+int main(int argc, char *argv[]) {
+    int retcode = 1;
+    int nerrors = 0;
+    streamer_t streamer;
+    settings_t settings;
+    memset(&streamer, 0, sizeof(streamer_t));
+    memset(&settings, 0, sizeof(settings_t));
+
+    // Defaults
+    settings.freq = 44100;
+    settings.n_channels = 2;
+    settings.bits = 16;
+    settings.endianness = DUMB_LITTLE_ENDIAN;
+    settings.is_unsigned = false;
+    settings.volume = 1.0f;
+    settings.delay = 0.0f;
+    settings.quality = DUMB_RQ_CUBIC;
+
+    // commandline argument parser options
+    struct arg_lit *arg_help =
+        arg_lit0("h", "help", "print this help and exits");
+    struct arg_dbl *arg_delay = arg_dbl0(
+        "d", "delay", "<delay>",
+        "sets the initial delay in seconds (0.0 to 64.0, default 0.0)");
+    struct arg_dbl *arg_volume =
+        arg_dbl0("v", "volume", "<volume",
+                 "sets the output volume (-8.0 to +8.0, default 1.0)");
+    struct arg_int *arg_samplerate = arg_int0(
+        "s", "samplerate", "<freq>", "sets the sampling rate (default 44100)");
+    struct arg_int *arg_quality = arg_int0(
+        "r", "quality", "<quality>", "specify the resampling quality to use");
+    struct arg_lit *arg_mono =
+        arg_lit0("m", "mono", "generate mono output instead of stereo");
+    struct arg_lit *arg_bigendian = arg_lit0(
+        "b", "bigendian", "generate big-endian data instead of little-endian");
+    struct arg_lit *arg_eight =
+        arg_lit0("8", "eight", "generate 8-bit instead of 16-bit");
+    struct arg_lit *arg_unsigned =
+        arg_lit0("u", "unsigned", "generate unsigned output instead of signed");
+    struct arg_file *arg_output =
+        arg_file0("o", "output", "<file>", "output file");
+    struct arg_file *arg_input =
+        arg_file1(NULL, NULL, "<file>", "input module file");
+    struct arg_end *arg_fend = arg_end(20);
+    void *argtable[] = {arg_help,      arg_input,      arg_output,   arg_delay,
+                        arg_volume,    arg_samplerate, arg_quality,  arg_mono,
+                        arg_bigendian, arg_eight,      arg_unsigned, arg_fend};
+    const char *progname = "dumbout";
+
+    // Make sure everything got allocated
+    if (arg_nullcheck(argtable) != 0) {
+        fprintf(stderr, "%s: insufficient memory\n", progname);
+        goto exit_0;
+    }
+
+    // Parse inputs
+    nerrors = arg_parse(argc, argv, argtable);
+
+    // Handle help
+    if (arg_help->count > 0) {
+        fprintf(stderr, "Usage: %s", progname);
+        arg_print_syntax(stderr, argtable, "\n");
+        fprintf(stderr, "\nArguments:\n");
+        arg_print_glossary(stderr, argtable, "%-25s %s\n");
+        goto exit_0;
+    }
+
+    // Handle errors
+    if (nerrors > 0) {
+        arg_print_errors(stderr, arg_fend, progname);
+        fprintf(stderr, "Try '%s --help' for more information.\n", progname);
+        goto exit_0;
+    }
+
+    // Get input and output filenames
+    settings.input = arg_input->filename[0];
+    if (arg_output->count > 0) {
+        settings.output = malloc(strlen(arg_output->filename[0]) + 1);
+        strcpy(settings.output, arg_output->filename[0]);
+    } else {
+        settings.output = malloc(strlen(arg_output->basename[0]) + 5);
+        sprintf(settings.output, "%s%s", arg_output->basename[0], ".pcm");
+    }
+
+    // Handle the switch options
+    if (arg_bigendian->count > 0) {
+        settings.endianness = DUMB_BIG_ENDIAN;
+    }
+    if (arg_eight->count > 0) {
+        settings.bits = 8;
+    }
+    if (arg_unsigned->count > 0) {
+        settings.is_unsigned = true;
+    }
+    if (arg_mono->count > 0) {
+        settings.n_channels = 1;
+    }
+
+    if (arg_delay->count > 0) {
+        settings.delay = arg_delay->dval[0];
+        if (settings.delay < 0.0f || settings.delay >= 64.0f) {
+            fprintf(stderr, "Initial delay must be between 0.0f and 64.0f.\n");
+            goto exit_0;
+        }
+    }
+
+    if (arg_volume->count > 0) {
+        settings.volume = arg_volume->dval[0];
+        if (settings.volume < -8.0f || settings.volume > 8.0f) {
+            fprintf(stderr, "Volume must be between -8.0f and 8.0f.\n");
+            goto exit_0;
+        }
+    }
+
+    if (arg_samplerate->count > 0) {
+        settings.freq = arg_samplerate->ival[0];
+        if (settings.freq < 1 || settings.freq > 96000) {
+            fprintf(stderr, "Sampling rate must be between 1 and 96000.\n");
+            goto exit_0;
+        }
+    }
+
+    if (arg_quality->count > 0) {
+        settings.quality = arg_quality->ival[0];
+        if (settings.quality < 0 || settings.quality >= DUMB_RQ_N_LEVELS) {
+            fprintf(stderr, "Quality must be between %d and %d.\n", 0,
+                    DUMB_RQ_N_LEVELS - 1);
+            goto exit_0;
+        }
+    }
+
+    // dumb settings stuff
+    dumb_register_stdfiles();
+
+    // Load source
+    streamer.src = dumb_load_any(settings.input, 0, 0);
+    if (!streamer.src) {
+        fprintf(stderr, "Unable to load file %s for playback!\n",
+                settings.input);
+        goto exit_0;
+    }
+
+    // Set up playback
+    streamer.renderer =
+        duh_start_sigrenderer(streamer.src, 0, settings.n_channels, 0);
+    streamer.delta = 65536.0f / settings.freq;
+    streamer.bufsize = 4096 * (settings.bits / 8) * settings.n_channels;
+
+    // Stop producing samples on module end
+    DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(streamer.renderer);
+    dumb_it_set_loop_callback(itsr, &dumb_it_callback_terminate, NULL);
+    dumb_it_set_xm_speed_zero_callback(itsr, &dumb_it_callback_terminate, NULL);
+    dumb_it_set_resampling_quality(itsr, settings.quality);
+
+    // Open output
+    if (strcmp(settings.output, "-") == 0) {
+        streamer.dst = stdout;
+        streamer.is_stdout = true;
+    } else {
+        streamer.dst = fopen(settings.output, "wb");
+        streamer.is_stdout = false;
+        if (!streamer.dst) {
+            fprintf(stderr, "Could not open output file %s!", settings.output);
+            goto exit_1;
+        }
+    }
+
+    bool run = true;
+    char *buffer = malloc(streamer.bufsize);
+    int read_samples;
+    int read_bytes;
+
+    // If output endianness is different than machine endianness, and output is
+    // 16 bits, reorder bytes.
+    int switch_endianness =
+        ((is_bigendian() && settings.endianness == DUMB_LITTLE_ENDIAN) ||
+         (!is_bigendian() && settings.endianness == DUMB_BIG_ENDIAN));
+
+    // Write the initial delay to the file if one was requested.
+    long d = ((long)floor(settings.delay * settings.freq + 0.5f)) *
+             settings.n_channels * (settings.bits / 8);
+    if (d) {
+        // Fill the buffer with silence. Remember to take into account
+        // endianness
+        if (settings.is_unsigned) {
+            if (settings.bits == 16) {
+                if (settings.endianness == DUMB_BIG_ENDIAN) {
+                    // Unsigned 16bits big endian
+                    for (int i = 0; i < streamer.bufsize; i += 2) {
+                        buffer[i] = (char)0x80;
+                        buffer[i + 1] = (char)0x00;
+                    }
+                } else {
+                    // Unsigned 16bits little endian
+                    for (int i = 0; i < streamer.bufsize; i += 2) {
+                        buffer[i] = (char)0x00;
+                        buffer[i + 1] = (char)0x80;
+                    }
+                }
+            } else {
+                // Unsigned 8 bits
+                memset(buffer, 0x80, streamer.bufsize);
+            }
+        } else {
+            // Signed
+            memset(buffer, 0, streamer.bufsize);
+        }
+
+        while (d >= streamer.bufsize) {
+            fwrite(buffer, 1, streamer.bufsize, streamer.dst);
+            d -= streamer.bufsize;
+        }
+        if (d) {
+            fwrite(buffer, 1, d, streamer.dst);
+        }
+    }
+
+    // Loop until we have nothing to loop through. Dumb will stop giving out
+    // bytes when the file is done.
+    while (run) {
+        read_samples =
+            duh_render_int(streamer.renderer, &streamer.sig_samples,
+                           &streamer.sig_samples_size, settings.bits,
+                           (int)settings.is_unsigned, settings.volume,
+                           streamer.delta, 4096, buffer);
+        read_bytes = read_samples * (settings.bits / 8) * settings.n_channels;
+
+        // switch endianness if required
+        if (switch_endianness && settings.bits == 16) {
+            char tmp;
+            for (int i = 0; i < read_bytes / 2; i++) {
+                tmp = buffer[i * 2 + 0];
+                buffer[i * 2 + 0] = buffer[i * 2 + 1];
+                buffer[i * 2 + 1] = tmp;
+            }
+        }
+
+        // Write to output stream and flush if it happens to be stdout
+        fwrite(buffer, 1, read_bytes, streamer.dst);
+        if (streamer.is_stdout) {
+            fflush(streamer.dst);
+        }
+        run = (read_samples > 0);
+    }
+    free(buffer);
+
+    // We made it this far without crashing, so let's just exit with no error :)
+    retcode = 0;
+
+    if (!streamer.is_stdout && streamer.dst) {
+        fclose(streamer.dst);
+    }
+
+    if (streamer.sig_samples) {
+        destroy_sample_buffer(streamer.sig_samples);
+    }
+
+exit_1:
+    if (streamer.renderer) {
+        duh_end_sigrenderer(streamer.renderer);
+    }
+    if (streamer.src) {
+        unload_duh(streamer.src);
+    }
+
+exit_0:
+    free(settings.output);
+    arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
+    return retcode;
+}
--- /dev/null
+++ b/examples/dumbplay.c
@@ -1,0 +1,315 @@
+#include <argtable2.h>
+#include <dumb.h>
+#include <stdint.h>
+#include <string.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <SDL2/SDL.h>
+
+// How many samples we should handle per callback call
+#define SAMPLES 8192
+
+// How many chars wide the progress bar is
+#define PROGRESSBAR_LENGTH 25
+
+typedef struct {
+    // Library contexts
+    DUH_SIGRENDERER *renderer;
+    DUH *src;
+    SDL_AudioDeviceID dev;
+    sample_t **sig_samples;
+    long sig_samples_size;
+
+    // Runtime vars
+    float delta;
+    int spos;   // Samples read
+    int ssize;  // Total samples available
+    int sbytes; // bytes per sample
+    bool ended;
+
+    // Config switches
+    int bits;
+    int freq;
+    int quality;
+    int n_channels;
+    bool no_progress;
+    float volume;
+    const char *input;
+} streamer_t;
+
+// Set to true if SIGTERM or SIGINT is caught
+static bool stop_signal = false;
+
+// Simple signal handler function
+static void sig_fn(int signo) { stop_signal = true; }
+
+// This is called from SDL2, and should read data from a source and hand it over
+// to SDL2 via the stream buffer.
+void stream_audio(void *userdata, Uint8 *stream, int len) {
+    streamer_t *streamer = (streamer_t *)userdata;
+
+    // Read samples from libdumb save them to the SDL buffer. Note that we are
+    // reading SAMPLES, not bytes!
+    int r_samples = len / streamer->sbytes;
+    int got =
+        duh_render_int(streamer->renderer, &streamer->sig_samples,
+                       &streamer->sig_samples_size, streamer->bits, 0,
+                       streamer->volume, streamer->delta, r_samples, stream);
+    if (got == 0) {
+        streamer->ended = true;
+    }
+
+    // Get current position from libdumb for the playback display. If we get
+    // position that is 0, it probably means that the song ended and
+    // duh_sigrenderer_get_position points to the start of the file.
+    streamer->spos = duh_sigrenderer_get_position(streamer->renderer);
+    if (streamer->spos == 0) {
+        streamer->spos = streamer->ssize;
+    }
+}
+
+// Simply formats timestamp to string
+void format_ms(int ticks) {
+    int total_seconds = ticks / 1000;
+    int hours = 0;
+    int minutes = 0;
+    int seconds = 0;
+
+    // Calculate hours, minutes and seconds
+    if (total_seconds > 3600) {
+        hours = total_seconds / 3600;
+        total_seconds = total_seconds % 3600;
+    }
+    if (total_seconds > 60) {
+        minutes = total_seconds / 60;
+        total_seconds = total_seconds % 60;
+    }
+    seconds = total_seconds;
+
+    // If necessary, show hours. Otherwise only minutes and seconds.
+    if (hours > 0) {
+        printf("%02d:%02d:%02d", hours, minutes, seconds);
+    } else {
+        printf("%02d:%02d", minutes, seconds);
+    }
+}
+
+// Shows progressbar and time played
+void show_progress(int width, float progress, int ticks) {
+    int d = progress * width;
+    printf("%3d%% [", (int)(progress * 100));
+    for (int x = 0; x < d; x++) {
+        printf("=");
+    }
+    for (int x = 0; x < (width - d); x++) {
+        printf(" ");
+    }
+    printf("] ");
+    format_ms(ticks);
+    printf("\r");
+    fflush(stdout);
+}
+
+int main(int argc, char *argv[]) {
+    int retcode = 1;
+    int nerrors = 0;
+    streamer_t streamer;
+    memset(&streamer, 0, sizeof(streamer_t));
+
+    // Signal handlers
+    signal(SIGINT, sig_fn);
+    signal(SIGTERM, sig_fn);
+
+    // Initialize SDL2
+    if (SDL_Init(SDL_INIT_AUDIO) != 0) {
+        fprintf(stderr, "%s\n", SDL_GetError());
+        return 1;
+    }
+
+    // Defaults
+    streamer.freq = 44100;
+    streamer.n_channels = 2;
+    streamer.bits = 16;
+    streamer.volume = 1.0f;
+    streamer.quality = DUMB_RQ_CUBIC;
+
+    // commandline argument parser options
+    struct arg_lit *arg_help =
+        arg_lit0("h", "help", "print this help and exits");
+    struct arg_dbl *arg_volume =
+        arg_dbl0("v", "volume", "<volume",
+                 "sets the output volume (-8.0 to +8.0, default 1.0)");
+    struct arg_int *arg_samplerate = arg_int0(
+        "s", "samplerate", "<freq>", "sets the sampling rate (default 44100)");
+    struct arg_int *arg_quality = arg_int0(
+        "r", "quality", "<quality>", "specify the resampling quality to use");
+    struct arg_lit *arg_mono =
+        arg_lit0("m", "mono", "generate mono output instead of stereo");
+    struct arg_lit *arg_eight =
+        arg_lit0("8", "eight", "generate 8-bit instead of 16-bit");
+    struct arg_lit *arg_noprogress =
+        arg_lit0("n", "noprogress", "hide progress bar");
+    struct arg_file *arg_output =
+        arg_file0("o", "output", "<file>", "output file");
+    struct arg_file *arg_input =
+        arg_file1(NULL, NULL, "<file>", "input module file");
+    struct arg_end *arg_fend = arg_end(20);
+    void *argtable[] = {arg_help,       arg_input,      arg_volume,
+                        arg_samplerate, arg_quality,    arg_mono,
+                        arg_eight,      arg_noprogress, arg_fend};
+    const char *progname = "dumbplay";
+
+    // Make sure everything got allocated
+    if (arg_nullcheck(argtable) != 0) {
+        fprintf(stderr, "%s: insufficient memory\n", progname);
+        goto exit_0;
+    }
+
+    // Parse inputs
+    nerrors = arg_parse(argc, argv, argtable);
+
+    // Handle help
+    if (arg_help->count > 0) {
+        fprintf(stderr, "Usage: %s", progname);
+        arg_print_syntax(stderr, argtable, "\n");
+        fprintf(stderr, "\nArguments:\n");
+        arg_print_glossary(stderr, argtable, "%-25s %s\n");
+        goto exit_0;
+    }
+
+    // Handle libargtable errors
+    if (nerrors > 0) {
+        arg_print_errors(stderr, arg_fend, progname);
+        fprintf(stderr, "Try '%s --help' for more information.\n", progname);
+        goto exit_0;
+    }
+
+    // Handle the switch options
+    streamer.input = arg_input->filename[0];
+    if (arg_eight->count > 0) {
+        streamer.bits = 8;
+    }
+    if (arg_mono->count > 0) {
+        streamer.n_channels = 1;
+    }
+    if (arg_noprogress->count > 0) {
+        streamer.no_progress = true;
+    }
+
+    if (arg_volume->count > 0) {
+        streamer.volume = arg_volume->dval[0];
+        if (streamer.volume < -8.0f || streamer.volume > 8.0f) {
+            fprintf(stderr, "Volume must be between -8.0f and 8.0f.\n");
+            goto exit_0;
+        }
+    }
+
+    if (arg_samplerate->count > 0) {
+        streamer.freq = arg_samplerate->ival[0];
+        if (streamer.freq < 1 || streamer.freq > 96000) {
+            fprintf(stderr, "Sampling rate must be between 1 and 96000.\n");
+            goto exit_0;
+        }
+    }
+
+    if (arg_quality->count > 0) {
+        streamer.quality = arg_quality->ival[0];
+        if (streamer.quality < 0 || streamer.quality >= DUMB_RQ_N_LEVELS) {
+            fprintf(stderr, "Quality must be between %d and %d.\n", 0,
+                    DUMB_RQ_N_LEVELS - 1);
+            goto exit_0;
+        }
+    }
+
+    // Load source file.
+    dumb_register_stdfiles();
+    streamer.src = dumb_load_any(streamer.input, 0, 0);
+    if (!streamer.src) {
+        fprintf(stderr, "Unable to load file %s for playback!\n",
+                streamer.input);
+        goto exit_0;
+    }
+
+    // Set up playback
+    streamer.renderer =
+        duh_start_sigrenderer(streamer.src, 0, streamer.n_channels, 0);
+    streamer.delta = 65536.0f / streamer.freq;
+    streamer.sbytes = (streamer.bits / 8) * streamer.n_channels;
+    streamer.ssize = duh_get_length(streamer.src);
+
+    // Stop producing samples on module end
+    DUMB_IT_SIGRENDERER *itsr = duh_get_it_sigrenderer(streamer.renderer);
+    dumb_it_set_loop_callback(itsr, &dumb_it_callback_terminate, NULL);
+    dumb_it_set_xm_speed_zero_callback(itsr, &dumb_it_callback_terminate, NULL);
+    dumb_it_set_resampling_quality(itsr, streamer.quality);
+
+    // Set up the SDL2 format we want for playback.
+    SDL_AudioSpec want;
+    SDL_zero(want);
+    want.freq = streamer.freq;
+    want.format = (streamer.bits == 16) ? AUDIO_S16 : AUDIO_S8;
+    want.channels = streamer.n_channels;
+    want.samples = SAMPLES;
+    want.callback = stream_audio;
+    want.userdata = &streamer;
+
+    // Find SDL2 audio device, and request the format we just set up.
+    // SDL2 will tell us what we got in the "have" struct.
+    SDL_AudioSpec have;
+    streamer.dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0);
+    if (streamer.dev == 0) {
+        fprintf(stderr, "%s\n", SDL_GetError());
+        goto exit_1;
+    }
+
+    // Make sure we got the format we wanted. If not, stop here.
+    if (have.format != want.format) {
+        fprintf(stderr, "Could not get correct playback format.\n");
+        goto exit_2;
+    }
+
+    // Play file
+    SDL_PauseAudioDevice(streamer.dev, 0);
+
+    // Show initial state of the progress bar (if it is enabled)
+    int time_start = SDL_GetTicks();
+    float seek = 0.0f;
+    int ms_played = 0;
+    if (!streamer.no_progress) {
+        show_progress(PROGRESSBAR_LENGTH, seek, ms_played);
+    }
+
+    // Loop while dumb is still giving data. Update progressbar if enabled.
+    while (!stop_signal && !streamer.ended) {
+        if (!streamer.no_progress) {
+            seek = ((float)streamer.spos) / ((float)streamer.ssize);
+            ms_played = SDL_GetTicks() - time_start;
+            show_progress(PROGRESSBAR_LENGTH, seek, ms_played);
+        }
+        SDL_Delay(100);
+    }
+
+    // We made it this far without crashing, so let's just exit with no error :)
+    retcode = 0;
+
+    // Free up resources and exit.
+    if (streamer.sig_samples) {
+        destroy_sample_buffer(streamer.sig_samples);
+    }
+
+exit_2:
+    SDL_CloseAudioDevice(streamer.dev);
+
+exit_1:
+    if (streamer.renderer) {
+        duh_end_sigrenderer(streamer.renderer);
+    }
+    if (streamer.src) {
+        unload_duh(streamer.src);
+    }
+
+exit_0:
+    arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
+    SDL_Quit();
+    return retcode;
+}
--- /dev/null
+++ b/include/aldumb.h
@@ -1,0 +1,83 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * aldumb.h - The user header file for DUMB with      / / \  \
+ *            Allegro.                               | <  /   \_
+ *                                                   |  \/ /\   /
+ * Include this file if you wish to use DUMB          \_  /  > /
+ * with Allegro. It will include dumb.h for you,        | \ / /
+ * and provide extra functionality such as audio        |  ' /
+ * stream and datafile integration.                      \__/
+ */
+
+#ifndef ALDUMB_H
+#define ALDUMB_H
+
+#include <allegro.h>
+
+#include "dumb.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Packfile Support */
+
+void dumb_register_packfiles(void);
+
+DUMBFILE *dumbfile_open_packfile(PACKFILE *p);
+DUMBFILE *dumbfile_from_packfile(PACKFILE *p);
+
+/* Datafile Registration Functions */
+
+#define DUMB_DAT_DUH DAT_ID('D', 'U', 'H', ' ')
+#define DUMB_DAT_IT DAT_ID('I', 'T', ' ', ' ')
+#define DUMB_DAT_XM DAT_ID('X', 'M', ' ', ' ')
+#define DUMB_DAT_S3M DAT_ID('S', '3', 'M', ' ')
+#define DUMB_DAT_MOD DAT_ID('M', 'O', 'D', ' ')
+
+void dumb_register_dat_duh(long type);
+void dumb_register_dat_it(long type);
+void dumb_register_dat_xm(long type);
+void dumb_register_dat_s3m(long type);
+void dumb_register_dat_mod(long type);
+void dumb_register_dat_it_quick(long type);
+void dumb_register_dat_xm_quick(long type);
+void dumb_register_dat_s3m_quick(long type);
+void dumb_register_dat_mod_quick(long type);
+
+/* DUH Playing Functions */
+
+typedef struct AL_DUH_PLAYER AL_DUH_PLAYER;
+
+AL_DUH_PLAYER *al_start_duh(DUH *duh, int n_channels, long pos, float volume,
+                            long bufsize, int freq);
+void al_stop_duh(AL_DUH_PLAYER *dp);
+void al_pause_duh(AL_DUH_PLAYER *dp);
+void al_resume_duh(AL_DUH_PLAYER *dp);
+void al_duh_set_priority(AL_DUH_PLAYER *dp, int priority);
+void al_duh_set_volume(AL_DUH_PLAYER *dp, float volume);
+float al_duh_get_volume(AL_DUH_PLAYER *dp);
+int al_poll_duh(AL_DUH_PLAYER *dp);
+long al_duh_get_position(AL_DUH_PLAYER *dp);
+
+AL_DUH_PLAYER *al_duh_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer,
+                                              float volume, long bufsize,
+                                              int freq);
+DUH_SIGRENDERER *al_duh_get_sigrenderer(AL_DUH_PLAYER *dp);
+
+/* IMPORTANT: This function will return NULL if the music has ended. */
+DUH_SIGRENDERER *al_duh_decompose_to_sigrenderer(AL_DUH_PLAYER *dp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ALDUMB_H */
--- /dev/null
+++ b/include/dumb.h
@@ -1,0 +1,819 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * dumb.h - The user header file for DUMB.            / / \  \
+ *                                                   | <  /   \_
+ * Include this file in any of your files in         |  \/ /\   /
+ * which you wish to use the DUMB functions           \_  /  > /
+ * and variables.                                       | \ / /
+ *                                                      |  ' /
+ * Allegro users, you will probably want aldumb.h.       \__/
+ */
+
+#ifndef DUMB_H
+#define DUMB_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef _DEBUG
+#ifdef _MSC_VER
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * When you bump major, minor, or patch, bump both the number and the string.
+ * When you bump major or minor version, bump them in CMakeLists.txt, too.
+ */
+#define DUMB_MAJOR_VERSION 2
+#define DUMB_MINOR_VERSION 0
+#define DUMB_REVISION_VERSION 2
+#define DUMB_VERSION_STR "2.0.2"
+
+#define DUMB_VERSION                                                           \
+    (DUMB_MAJOR_VERSION * 10000 + DUMB_MINOR_VERSION * 100 +                   \
+     DUMB_REVISION_VERSION)
+#define DUMB_NAME "DUMB v" DUMB_VERSION_STR
+
+#ifdef DEBUGMODE
+
+#ifndef ASSERT
+#include <assert.h>
+#define ASSERT(n) assert(n)
+#endif
+#ifndef TRACE
+// it would be nice if this did actually trace ...
+#define TRACE 1 ? (void)0 : (void)printf
+#endif
+
+#else
+
+#ifndef ASSERT
+#define ASSERT(n)
+#endif
+#ifndef TRACE
+#define TRACE 1 ? (void)0 : (void)printf
+#endif
+
+#endif // DEBUGMODE
+
+#define DUMB_ID(a, b, c, d)                                                    \
+    (((unsigned int)(a) << 24) | ((unsigned int)(b) << 16) |                   \
+     ((unsigned int)(c) << 8) | ((unsigned int)(d)))
+
+#if __GNUC__ * 100 + __GNUC_MINOR__ >= 301 /* GCC 3.1+ */
+#ifndef DUMB_DECLARE_DEPRECATED
+#define DUMB_DECLARE_DEPRECATED
+#endif
+#define DUMB_DEPRECATED __attribute__((__deprecated__))
+#else
+#define DUMB_DEPRECATED
+#endif
+
+/* Basic Sample Type. Normal range is -0x800000 to 0x7FFFFF. */
+
+typedef int sample_t;
+
+/* Library Clean-up Management */
+
+int dumb_atexit(void (*proc)(void));
+
+void dumb_exit(void);
+
+/* File Input Functions */
+#ifdef DUMB_OFF_T_CUSTOM
+typedef DUMB_OFF_T_CUSTOM dumb_off_t;
+#elif defined _MSC_VER || defined __WATCOMC__
+typedef __int64 dumb_off_t;
+#elif defined __DJGPP__ || defined __MINGW32__
+/* MingW-W64 does not have off64_t and supports _FILE_OFFSET_BITS,
+ * DJGPP and old MinGW do have off64_t, but don't support _FILE_OFFSET_BITS.
+ */
+#include <sys/types.h>
+#if defined(__MINGW64_VERSION_MAJOR)
+typedef off_t dumb_off_t;
+#else
+typedef off64_t dumb_off_t;
+#endif
+#elif _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 500
+#include <sys/types.h>
+typedef off_t dumb_off_t;
+#else
+typedef long long dumb_off_t;
+#endif
+
+/*
+ * If the build fails here, it does so, because we need a 64-bit-type for
+ * defining offsets. To fix this do either of the following:
+ *
+ * 1. Compile your code with -D_FILE_OFFSET_BITS=64, so that off_t is 64-bit
+ *    (recommended, but make sure the rest of your code can handle it)
+ * 2. Supply your own definition of a signed 64-bit integer
+ *    such as off64_t or int64_t before including dumb.h as follows:
+ *    #define DUMB_OFF_T_CUSTOM int64_t
+ */
+#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) &&                \
+    !defined __cplusplus
+_Static_assert(sizeof(dumb_off_t) >= 8, "dumb: off_t must be 64bit");
+#else
+struct dumb_off_t_needs_to_be_at_least_8_bytes {
+    unsigned int dumb_off_t_needs_to_be_at_least_8_bytes_
+        : ((sizeof(dumb_off_t) >= 8) ? 1 : -42);
+};
+#endif
+
+/*
+ * ssize_t is defined in POSIX to hold either a size_t or an error.
+ * We will use dumb_ssize_t on all platforms for (either size_t or error) in
+ * all getnc-type functions. See DUMBFILE_SYSTEM.md for that function's spec.
+ */
+#if defined(_MSC_VER)
+#include <BaseTsd.h>
+typedef SSIZE_T dumb_ssize_t;
+#else
+#include <sys/types.h>
+typedef ssize_t dumb_ssize_t;
+#endif
+
+/*
+ * DUMB provides an abstraction over files, to work with memory-mapped files,
+ * files on disk, files read into memory by other libraries in their own
+ * custom formats, ...
+ *
+ * Register your own file-handling functions as callbacks via this struct.
+ * DUMB 2.0 doesn't use long anymore. The 64-bit dumb_*_t are defined above.
+ *
+ * See DUMBFILE_SYSTEM.md in project's root for a complete spec.
+ */
+typedef struct DUMBFILE_SYSTEM {
+    /* open */
+    /* Open filename. Returned file may be of any custom type. */
+    void *(*open)(const char *filename);
+
+    /* skip */
+    /* Ignore the next n bytes in file f. Returns 0 on succes, -1 on error. */
+    int (*skip)(void *f, dumb_off_t n);
+
+    /* getc */
+    /* Read the next byte. Returns byte as unsigned, or -1 on error. */
+    int (*getc)(void *f);
+
+    /* getnc */
+    /* Read n bytes into buffer ptr. Returns number of bytes read or -1. */
+    dumb_ssize_t (*getnc)(char *ptr, size_t n, void *f);
+
+    /* close */
+    /* Called when DUMB is done with the file. User code may do anything. */
+    void (*close)(void *f);
+
+    /* seek */
+    /* Jump to offset in bytes from beginning. Returns 0 if OK, -1 on error. */
+    int (*seek)(void *f, dumb_off_t offset);
+
+    /* get_size */
+    /* Returns the size in bytes of the file. */
+    dumb_off_t (*get_size)(void *f);
+} DUMBFILE_SYSTEM;
+
+typedef struct DUMBFILE DUMBFILE;
+
+void register_dumbfile_system(const DUMBFILE_SYSTEM *dfs);
+
+DUMBFILE *dumbfile_open(const char *filename);
+DUMBFILE *dumbfile_open_ex(void *file, const DUMBFILE_SYSTEM *dfs);
+
+dumb_off_t dumbfile_pos(DUMBFILE *f);
+int dumbfile_skip(DUMBFILE *f, dumb_off_t n);
+
+#define DFS_SEEK_SET 0
+#define DFS_SEEK_CUR 1
+#define DFS_SEEK_END 2
+
+int dumbfile_seek(DUMBFILE *f, dumb_off_t n, int origin);
+
+dumb_off_t dumbfile_get_size(DUMBFILE *f);
+
+int dumbfile_getc(DUMBFILE *f);
+
+int dumbfile_igetw(DUMBFILE *f);
+int dumbfile_mgetw(DUMBFILE *f);
+
+long dumbfile_igetl(DUMBFILE *f);
+long dumbfile_mgetl(DUMBFILE *f);
+
+unsigned long dumbfile_cgetul(DUMBFILE *f);
+signed long dumbfile_cgetsl(DUMBFILE *f);
+
+dumb_ssize_t dumbfile_getnc(char *ptr, size_t n, DUMBFILE *f);
+
+int dumbfile_error(DUMBFILE *f);
+int dumbfile_close(DUMBFILE *f);
+
+/* stdio File Input Module */
+
+void dumb_register_stdfiles(void);
+
+DUMBFILE *dumbfile_open_stdfile(FILE *p);
+
+/* Memory File Input Module */
+
+DUMBFILE *dumbfile_open_memory(const char *data, size_t size);
+
+/* DUH Management */
+
+typedef struct DUH DUH;
+
+#define DUH_SIGNATURE DUMB_ID('D', 'U', 'H', '!')
+
+void unload_duh(DUH *duh);
+
+DUH *load_duh(const char *filename);
+DUH *read_duh(DUMBFILE *f);
+
+dumb_off_t duh_get_length(DUH *duh);
+
+const char *duh_get_tag(DUH *duh, const char *key);
+int duh_get_tag_iterator_size(DUH *duh);
+int duh_get_tag_iterator_get(DUH *duh, const char **key, const char **tag,
+                             int i);
+
+/* Signal Rendering Functions */
+
+typedef struct DUH_SIGRENDERER DUH_SIGRENDERER;
+
+DUH_SIGRENDERER *duh_start_sigrenderer(DUH *duh, int sig, int n_channels,
+                                       long pos);
+
+typedef void (*DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK)(
+    void *data, const sample_t *const *samples, int n_channels, long length);
+
+void duh_sigrenderer_set_sample_analyser_callback(
+    DUH_SIGRENDERER *sigrenderer,
+    DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK callback, void *data);
+
+int duh_sigrenderer_get_n_channels(DUH_SIGRENDERER *sigrenderer);
+long duh_sigrenderer_get_position(DUH_SIGRENDERER *sigrenderer);
+
+void duh_sigrenderer_set_sigparam(DUH_SIGRENDERER *sigrenderer,
+                                  unsigned char id, long value);
+
+long duh_sigrenderer_generate_samples(DUH_SIGRENDERER *sigrenderer,
+                                      float volume, float delta, long size,
+                                      sample_t **samples);
+
+void duh_sigrenderer_get_current_sample(DUH_SIGRENDERER *sigrenderer,
+                                        float volume, sample_t *samples);
+
+void duh_end_sigrenderer(DUH_SIGRENDERER *sigrenderer);
+
+/* DUH Rendering Functions */
+
+/* For packed integers: 8, 16, 24-bit wide.
+ * Intermediary buffer sig_samples must be freed with destroy_sample_buffer()
+ * in the end of the rendering loop.
+ */
+long duh_render_int(DUH_SIGRENDERER *sigrenderer, sample_t ***sig_samples,
+                    long *sig_samples_size, int bits, int unsign, float volume,
+                    float delta, long size, void *sptr);
+
+/* For floats: 32, 64-bit wide.
+ * Intermediary buffer sig_samples must be freed with destroy_sample_buffer()
+ * in the end of the rendering loop.
+ */
+long duh_render_float(DUH_SIGRENDERER *sigrenderer, sample_t ***sig_samples,
+                      long *sig_samples_size, int bits, float volume,
+                      float delta, long size, void *sptr);
+
+#ifdef DUMB_DECLARE_DEPRECATED
+
+/* DEPRECATED since 2.0.0. Please use duh_render_int or duh_render_float. */
+long duh_render(DUH_SIGRENDERER *sigrenderer, int bits, int unsign,
+                float volume, float delta, long size,
+                void *sptr) DUMB_DEPRECATED;
+
+#endif
+
+/* Impulse Tracker Support */
+
+extern int dumb_it_max_to_mix;
+
+typedef struct DUMB_IT_SIGDATA DUMB_IT_SIGDATA;
+typedef struct DUMB_IT_SIGRENDERER DUMB_IT_SIGRENDERER;
+
+DUMB_IT_SIGDATA *duh_get_it_sigdata(DUH *duh);
+DUH_SIGRENDERER *
+duh_encapsulate_it_sigrenderer(DUMB_IT_SIGRENDERER *it_sigrenderer,
+                               int n_channels, long pos);
+DUMB_IT_SIGRENDERER *duh_get_it_sigrenderer(DUH_SIGRENDERER *sigrenderer);
+
+int dumb_it_trim_silent_patterns(DUH *duh);
+
+typedef int (*dumb_scan_callback)(void *, int, long);
+int dumb_it_scan_for_playable_orders(DUMB_IT_SIGDATA *sigdata,
+                                     dumb_scan_callback callback,
+                                     void *callback_data);
+
+DUH_SIGRENDERER *dumb_it_start_at_order(DUH *duh, int n_channels,
+                                        int startorder);
+
+enum {
+    DUMB_IT_RAMP_NONE = 0,
+    DUMB_IT_RAMP_ONOFF_ONLY = 1,
+    DUMB_IT_RAMP_FULL = 2
+};
+
+void dumb_it_set_ramp_style(DUMB_IT_SIGRENDERER *sigrenderer, int ramp_style);
+
+void dumb_it_set_loop_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                               int (*callback)(void *data), void *data);
+void dumb_it_set_xm_speed_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                                        int (*callback)(void *data),
+                                        void *data);
+void dumb_it_set_midi_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                               int (*callback)(void *data, int channel,
+                                               unsigned char midi_byte),
+                               void *data);
+void dumb_it_set_global_volume_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                                             int (*callback)(void *data),
+                                             void *data);
+
+int dumb_it_callback_terminate(void *data);
+int dumb_it_callback_midi_block(void *data, int channel,
+                                unsigned char midi_byte);
+
+/* dumb_*_mod*: restrict_ - OR these together */
+enum {
+    DUMB_MOD_RESTRICT_NO_15_SAMPLE = (1 << 0), /* Don't load 15 sample files,
+                                                  which have no identifying
+                                                  signature */
+    DUMB_MOD_RESTRICT_OLD_PATTERN_COUNT =
+        (1 << 1) /* Use old pattern counting method */
+};
+
+DUH *dumb_load_it(const char *filename);
+DUH *dumb_load_xm(const char *filename);
+DUH *dumb_load_s3m(const char *filename);
+DUH *dumb_load_stm(const char *filename);
+DUH *dumb_load_mod(const char *filename, int restrict_);
+DUH *dumb_load_ptm(const char *filename);
+DUH *dumb_load_669(const char *filename);
+DUH *dumb_load_psm(const char *filename, int subsong);
+DUH *dumb_load_old_psm(const char *filename);
+DUH *dumb_load_mtm(const char *filename);
+DUH *dumb_load_riff(const char *filename);
+DUH *dumb_load_asy(const char *filename);
+DUH *dumb_load_amf(const char *filename);
+DUH *dumb_load_okt(const char *filename);
+
+DUH *dumb_read_it(DUMBFILE *f);
+DUH *dumb_read_xm(DUMBFILE *f);
+DUH *dumb_read_s3m(DUMBFILE *f);
+DUH *dumb_read_stm(DUMBFILE *f);
+DUH *dumb_read_mod(DUMBFILE *f, int restrict_);
+DUH *dumb_read_ptm(DUMBFILE *f);
+DUH *dumb_read_669(DUMBFILE *f);
+DUH *dumb_read_psm(DUMBFILE *f, int subsong);
+DUH *dumb_read_old_psm(DUMBFILE *f);
+DUH *dumb_read_mtm(DUMBFILE *f);
+DUH *dumb_read_riff(DUMBFILE *f);
+DUH *dumb_read_asy(DUMBFILE *f);
+DUH *dumb_read_amf(DUMBFILE *f);
+DUH *dumb_read_okt(DUMBFILE *f);
+
+DUH *dumb_load_it_quick(const char *filename);
+DUH *dumb_load_xm_quick(const char *filename);
+DUH *dumb_load_s3m_quick(const char *filename);
+DUH *dumb_load_stm_quick(const char *filename);
+DUH *dumb_load_mod_quick(const char *filename, int restrict_);
+DUH *dumb_load_ptm_quick(const char *filename);
+DUH *dumb_load_669_quick(const char *filename);
+DUH *dumb_load_psm_quick(const char *filename, int subsong);
+DUH *dumb_load_old_psm_quick(const char *filename);
+DUH *dumb_load_mtm_quick(const char *filename);
+DUH *dumb_load_riff_quick(const char *filename);
+DUH *dumb_load_asy_quick(const char *filename);
+DUH *dumb_load_amf_quick(const char *filename);
+DUH *dumb_load_okt_quick(const char *filename);
+
+DUH *dumb_read_it_quick(DUMBFILE *f);
+DUH *dumb_read_xm_quick(DUMBFILE *f);
+DUH *dumb_read_s3m_quick(DUMBFILE *f);
+DUH *dumb_read_stm_quick(DUMBFILE *f);
+DUH *dumb_read_mod_quick(DUMBFILE *f, int restrict_);
+DUH *dumb_read_ptm_quick(DUMBFILE *f);
+DUH *dumb_read_669_quick(DUMBFILE *f);
+DUH *dumb_read_psm_quick(DUMBFILE *f, int subsong);
+DUH *dumb_read_old_psm_quick(DUMBFILE *f);
+DUH *dumb_read_mtm_quick(DUMBFILE *f);
+DUH *dumb_read_riff_quick(DUMBFILE *f);
+DUH *dumb_read_asy_quick(DUMBFILE *f);
+DUH *dumb_read_amf_quick(DUMBFILE *f);
+DUH *dumb_read_okt_quick(DUMBFILE *f);
+
+DUH *dumb_read_any_quick(DUMBFILE *f, int restrict_, int subsong);
+DUH *dumb_read_any(DUMBFILE *f, int restrict_, int subsong);
+
+DUH *dumb_load_any_quick(const char *filename, int restrict_, int subsong);
+DUH *dumb_load_any(const char *filename, int restrict_, int subsong);
+
+long dumb_it_build_checkpoints(DUMB_IT_SIGDATA *sigdata, int startorder);
+void dumb_it_do_initial_runthrough(DUH *duh);
+
+int dumb_get_psm_subsong_count(DUMBFILE *f);
+
+const unsigned char *dumb_it_sd_get_song_message(DUMB_IT_SIGDATA *sd);
+
+int dumb_it_sd_get_n_orders(DUMB_IT_SIGDATA *sd);
+int dumb_it_sd_get_n_samples(DUMB_IT_SIGDATA *sd);
+int dumb_it_sd_get_n_instruments(DUMB_IT_SIGDATA *sd);
+
+const unsigned char *dumb_it_sd_get_sample_name(DUMB_IT_SIGDATA *sd, int i);
+const unsigned char *dumb_it_sd_get_sample_filename(DUMB_IT_SIGDATA *sd, int i);
+const unsigned char *dumb_it_sd_get_instrument_name(DUMB_IT_SIGDATA *sd, int i);
+const unsigned char *dumb_it_sd_get_instrument_filename(DUMB_IT_SIGDATA *sd,
+                                                        int i);
+
+int dumb_it_sd_get_initial_global_volume(DUMB_IT_SIGDATA *sd);
+void dumb_it_sd_set_initial_global_volume(DUMB_IT_SIGDATA *sd, int gv);
+
+int dumb_it_sd_get_mixing_volume(DUMB_IT_SIGDATA *sd);
+void dumb_it_sd_set_mixing_volume(DUMB_IT_SIGDATA *sd, int mv);
+
+int dumb_it_sd_get_initial_speed(DUMB_IT_SIGDATA *sd);
+void dumb_it_sd_set_initial_speed(DUMB_IT_SIGDATA *sd, int speed);
+
+int dumb_it_sd_get_initial_tempo(DUMB_IT_SIGDATA *sd);
+void dumb_it_sd_set_initial_tempo(DUMB_IT_SIGDATA *sd, int tempo);
+
+int dumb_it_sd_get_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel);
+void dumb_it_sd_set_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel,
+                                           int volume);
+
+int dumb_it_sr_get_current_order(DUMB_IT_SIGRENDERER *sr);
+int dumb_it_sr_get_current_row(DUMB_IT_SIGRENDERER *sr);
+
+int dumb_it_sr_get_global_volume(DUMB_IT_SIGRENDERER *sr);
+void dumb_it_sr_set_global_volume(DUMB_IT_SIGRENDERER *sr, int gv);
+
+int dumb_it_sr_get_tempo(DUMB_IT_SIGRENDERER *sr);
+void dumb_it_sr_set_tempo(DUMB_IT_SIGRENDERER *sr, int tempo);
+
+int dumb_it_sr_get_speed(DUMB_IT_SIGRENDERER *sr);
+void dumb_it_sr_set_speed(DUMB_IT_SIGRENDERER *sr, int speed);
+
+#define DUMB_IT_N_CHANNELS 64
+#define DUMB_IT_N_NNA_CHANNELS 192
+#define DUMB_IT_TOTAL_CHANNELS (DUMB_IT_N_CHANNELS + DUMB_IT_N_NNA_CHANNELS)
+
+/* Channels passed to any of these functions are 0-based */
+int dumb_it_sr_get_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel);
+void dumb_it_sr_set_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel,
+                                   int volume);
+
+int dumb_it_sr_get_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel);
+void dumb_it_sr_set_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel,
+                                  int muted);
+
+typedef struct DUMB_IT_CHANNEL_STATE DUMB_IT_CHANNEL_STATE;
+
+struct DUMB_IT_CHANNEL_STATE {
+    int channel;  /* 0-based; meaningful for NNA channels */
+    int sample;   /* 1-based; 0 if nothing playing, then other fields undef */
+    int freq;     /* in Hz */
+    float volume; /* 1.0 maximum; affected by ALL factors, inc. mixing vol */
+    unsigned char pan;  /* 0-64, 100 for surround */
+    signed char subpan; /* use (pan + subpan/256.0f) or ((pan<<8)+subpan) */
+    unsigned char filter_cutoff;    /* 0-127    cutoff=127 AND resonance=0 */
+    unsigned char filter_subcutoff; /* 0-255      -> no filters (subcutoff */
+    unsigned char filter_resonance; /* 0-127        always 0 in this case) */
+    /* subcutoff only changes from zero if filter envelopes are in use. The
+     * calculation (filter_cutoff + filter_subcutoff/256.0f) gives a more
+     * accurate filter cutoff measurement as a float. It would often be more
+     * useful to use a scaled int such as ((cutoff<<8) + subcutoff).
+     */
+};
+
+/* Values of 64 or more will access NNA channels here. */
+void dumb_it_sr_get_channel_state(DUMB_IT_SIGRENDERER *sr, int channel,
+                                  DUMB_IT_CHANNEL_STATE *state);
+
+/* Signal Design Helper Values */
+
+/* Use pow(DUMB_SEMITONE_BASE, n) to get the 'delta' value to transpose up by
+ * n semitones. To transpose down, use negative n.
+ */
+#define DUMB_SEMITONE_BASE 1.059463094359295309843105314939748495817
+
+/* Use pow(DUMB_QUARTERTONE_BASE, n) to get the 'delta' value to transpose up
+ * by n quartertones. To transpose down, use negative n.
+ */
+#define DUMB_QUARTERTONE_BASE 1.029302236643492074463779317738953977823
+
+/* Use pow(DUMB_PITCH_BASE, n) to get the 'delta' value to transpose up by n
+ * units. In this case, 256 units represent one semitone; 3072 units
+ * represent one octave. These units are used by the sequence signal (SEQU).
+ */
+#define DUMB_PITCH_BASE 1.000225659305069791926712241547647863626
+
+/* Signal Design Function Types */
+
+typedef void sigdata_t;
+typedef void sigrenderer_t;
+
+typedef sigdata_t *(*DUH_LOAD_SIGDATA)(DUH *duh, DUMBFILE *file);
+
+typedef sigrenderer_t *(*DUH_START_SIGRENDERER)(DUH *duh, sigdata_t *sigdata,
+                                                int n_channels, long pos);
+
+typedef void (*DUH_SIGRENDERER_SET_SIGPARAM)(sigrenderer_t *sigrenderer,
+                                             unsigned char id, long value);
+
+typedef long (*DUH_SIGRENDERER_GENERATE_SAMPLES)(sigrenderer_t *sigrenderer,
+                                                 float volume, float delta,
+                                                 long size, sample_t **samples);
+
+typedef void (*DUH_SIGRENDERER_GET_CURRENT_SAMPLE)(sigrenderer_t *sigrenderer,
+                                                   float volume,
+                                                   sample_t *samples);
+
+typedef long (*DUH_SIGRENDERER_GET_POSITION)(sigrenderer_t *sigrenderer);
+
+typedef void (*DUH_END_SIGRENDERER)(sigrenderer_t *sigrenderer);
+
+typedef void (*DUH_UNLOAD_SIGDATA)(sigdata_t *sigdata);
+
+/* Signal Design Function Registration */
+
+typedef struct DUH_SIGTYPE_DESC {
+    long type;
+    DUH_LOAD_SIGDATA load_sigdata;
+    DUH_START_SIGRENDERER start_sigrenderer;
+    DUH_SIGRENDERER_SET_SIGPARAM sigrenderer_set_sigparam;
+    DUH_SIGRENDERER_GENERATE_SAMPLES sigrenderer_generate_samples;
+    DUH_SIGRENDERER_GET_CURRENT_SAMPLE sigrenderer_get_current_sample;
+    DUH_SIGRENDERER_GET_POSITION sigrenderer_get_position;
+    DUH_END_SIGRENDERER end_sigrenderer;
+    DUH_UNLOAD_SIGDATA unload_sigdata;
+} DUH_SIGTYPE_DESC;
+
+void dumb_register_sigtype(DUH_SIGTYPE_DESC *desc);
+
+int duh_add_signal(DUH *duh, DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata);
+
+// Decide where to put these functions; new heading?
+
+sigdata_t *duh_get_raw_sigdata(DUH *duh, int sig, long type);
+
+DUH_SIGRENDERER *duh_encapsulate_raw_sigrenderer(sigrenderer_t *vsigrenderer,
+                                                 DUH_SIGTYPE_DESC *desc,
+                                                 int n_channels, long pos);
+sigrenderer_t *duh_get_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer, long type);
+
+/* Standard Signal Types */
+
+// void dumb_register_sigtype_sample(void);
+
+/* Sample Buffer Allocation Helpers */
+
+sample_t **allocate_sample_buffer(int n_channels, long length);
+void destroy_sample_buffer(sample_t **samples);
+
+/* Silencing Helper */
+
+void dumb_silence(sample_t *samples, long length);
+
+/* Click Removal Helpers */
+
+typedef struct DUMB_CLICK_REMOVER DUMB_CLICK_REMOVER;
+
+DUMB_CLICK_REMOVER *dumb_create_click_remover(void);
+void dumb_record_click(DUMB_CLICK_REMOVER *cr, long pos, sample_t step);
+void dumb_remove_clicks(DUMB_CLICK_REMOVER *cr, sample_t *samples, long length,
+                        int step, float halflife);
+sample_t dumb_click_remover_get_offset(DUMB_CLICK_REMOVER *cr);
+void dumb_destroy_click_remover(DUMB_CLICK_REMOVER *cr);
+
+DUMB_CLICK_REMOVER **dumb_create_click_remover_array(int n);
+void dumb_record_click_array(int n, DUMB_CLICK_REMOVER **cr, long pos,
+                             sample_t *step);
+void dumb_record_click_negative_array(int n, DUMB_CLICK_REMOVER **cr, long pos,
+                                      sample_t *step);
+void dumb_remove_clicks_array(int n, DUMB_CLICK_REMOVER **cr,
+                              sample_t **samples, long length, float halflife);
+void dumb_click_remover_get_offset_array(int n, DUMB_CLICK_REMOVER **cr,
+                                         sample_t *offset);
+void dumb_destroy_click_remover_array(int n, DUMB_CLICK_REMOVER **cr);
+
+/* Resampling Helpers */
+
+#define DUMB_RQ_ALIASING 0
+#define DUMB_RQ_BLEP 1
+#define DUMB_RQ_LINEAR 2
+#define DUMB_RQ_BLAM 3
+#define DUMB_RQ_CUBIC 4
+#define DUMB_RQ_FIR 5
+#define DUMB_RQ_N_LEVELS 6
+
+extern int dumb_resampling_quality; /* This specifies the default */
+void dumb_it_set_resampling_quality(DUMB_IT_SIGRENDERER *sigrenderer,
+                                    int quality); /* This overrides it */
+
+typedef struct DUMB_RESAMPLER DUMB_RESAMPLER;
+
+typedef struct DUMB_VOLUME_RAMP_INFO DUMB_VOLUME_RAMP_INFO;
+
+typedef void (*DUMB_RESAMPLE_PICKUP)(DUMB_RESAMPLER *resampler, void *data);
+
+struct DUMB_RESAMPLER {
+    void *src;
+    long pos;
+    int subpos;
+    long start, end;
+    int dir;
+    DUMB_RESAMPLE_PICKUP pickup;
+    void *pickup_data;
+    int quality;
+    /* Everything below this point is internal: do not use. */
+    union {
+        sample_t x24[3 * 2];
+        short x16[3 * 2];
+        signed char x8[3 * 2];
+    } x;
+    int overshot;
+    double fir_resampler_ratio;
+    void *fir_resampler[2];
+};
+
+struct DUMB_VOLUME_RAMP_INFO {
+    float volume;
+    float delta;
+    float target;
+    float mix;
+    unsigned char declick_stage;
+};
+
+void dumb_reset_resampler(DUMB_RESAMPLER *resampler, sample_t *src,
+                          int src_channels, long pos, long start, long end,
+                          int quality);
+DUMB_RESAMPLER *dumb_start_resampler(sample_t *src, int src_channels, long pos,
+                                     long start, long end, int quality);
+long dumb_resample_1_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size,
+                       DUMB_VOLUME_RAMP_INFO *volume, float delta);
+long dumb_resample_1_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size,
+                       DUMB_VOLUME_RAMP_INFO *volume_left,
+                       DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_2_1(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size,
+                       DUMB_VOLUME_RAMP_INFO *volume_left,
+                       DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_2_2(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size,
+                       DUMB_VOLUME_RAMP_INFO *volume_left,
+                       DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+void dumb_resample_get_current_sample_1_1(DUMB_RESAMPLER *resampler,
+                                          DUMB_VOLUME_RAMP_INFO *volume,
+                                          sample_t *dst);
+void dumb_resample_get_current_sample_1_2(DUMB_RESAMPLER *resampler,
+                                          DUMB_VOLUME_RAMP_INFO *volume_left,
+                                          DUMB_VOLUME_RAMP_INFO *volume_right,
+                                          sample_t *dst);
+void dumb_resample_get_current_sample_2_1(DUMB_RESAMPLER *resampler,
+                                          DUMB_VOLUME_RAMP_INFO *volume_left,
+                                          DUMB_VOLUME_RAMP_INFO *volume_right,
+                                          sample_t *dst);
+void dumb_resample_get_current_sample_2_2(DUMB_RESAMPLER *resampler,
+                                          DUMB_VOLUME_RAMP_INFO *volume_left,
+                                          DUMB_VOLUME_RAMP_INFO *volume_right,
+                                          sample_t *dst);
+void dumb_end_resampler(DUMB_RESAMPLER *resampler);
+
+void dumb_reset_resampler_16(DUMB_RESAMPLER *resampler, short *src,
+                             int src_channels, long pos, long start, long end,
+                             int quality);
+DUMB_RESAMPLER *dumb_start_resampler_16(short *src, int src_channels, long pos,
+                                        long start, long end, int quality);
+long dumb_resample_16_1_1(DUMB_RESAMPLER *resampler, sample_t *dst,
+                          long dst_size, DUMB_VOLUME_RAMP_INFO *volume,
+                          float delta);
+long dumb_resample_16_1_2(DUMB_RESAMPLER *resampler, sample_t *dst,
+                          long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                          DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_16_2_1(DUMB_RESAMPLER *resampler, sample_t *dst,
+                          long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                          DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_16_2_2(DUMB_RESAMPLER *resampler, sample_t *dst,
+                          long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                          DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+void dumb_resample_get_current_sample_16_1_1(DUMB_RESAMPLER *resampler,
+                                             DUMB_VOLUME_RAMP_INFO *volume,
+                                             sample_t *dst);
+void dumb_resample_get_current_sample_16_1_2(
+    DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO *volume_left,
+    DUMB_VOLUME_RAMP_INFO *volume_right, sample_t *dst);
+void dumb_resample_get_current_sample_16_2_1(
+    DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO *volume_left,
+    DUMB_VOLUME_RAMP_INFO *volume_right, sample_t *dst);
+void dumb_resample_get_current_sample_16_2_2(
+    DUMB_RESAMPLER *resampler, DUMB_VOLUME_RAMP_INFO *volume_left,
+    DUMB_VOLUME_RAMP_INFO *volume_right, sample_t *dst);
+void dumb_end_resampler_16(DUMB_RESAMPLER *resampler);
+
+void dumb_reset_resampler_8(DUMB_RESAMPLER *resampler, signed char *src,
+                            int src_channels, long pos, long start, long end,
+                            int quality);
+DUMB_RESAMPLER *dumb_start_resampler_8(signed char *src, int src_channels,
+                                       long pos, long start, long end,
+                                       int quality);
+long dumb_resample_8_1_1(DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume,
+                         float delta);
+long dumb_resample_8_1_2(DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_8_2_1(DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_8_2_2(DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+void dumb_resample_get_current_sample_8_1_1(DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume,
+                                            sample_t *dst);
+void dumb_resample_get_current_sample_8_1_2(DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst);
+void dumb_resample_get_current_sample_8_2_1(DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst);
+void dumb_resample_get_current_sample_8_2_2(DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst);
+void dumb_end_resampler_8(DUMB_RESAMPLER *resampler);
+
+void dumb_reset_resampler_n(int n, DUMB_RESAMPLER *resampler, void *src,
+                            int src_channels, long pos, long start, long end,
+                            int quality);
+DUMB_RESAMPLER *dumb_start_resampler_n(int n, void *src, int src_channels,
+                                       long pos, long start, long end,
+                                       int quality);
+long dumb_resample_n_1_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume,
+                         float delta);
+long dumb_resample_n_1_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_n_2_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+long dumb_resample_n_2_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta);
+void dumb_resample_get_current_sample_n_1_1(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume,
+                                            sample_t *dst);
+void dumb_resample_get_current_sample_n_1_2(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst);
+void dumb_resample_get_current_sample_n_2_1(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst);
+void dumb_resample_get_current_sample_n_2_2(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst);
+void dumb_end_resampler_n(int n, DUMB_RESAMPLER *resampler);
+
+/* This sets the default panning separation for hard panned formats,
+   or for formats with default panning information. This must be set
+   before using any readers or loaders, and is not really thread safe. */
+
+extern int dumb_it_default_panning_separation; /* in percent, default 25 */
+
+/* DUH Construction */
+
+DUH *make_duh(dumb_off_t length, int n_tags, const char *const tag[][2],
+              int n_signals, DUH_SIGTYPE_DESC *desc[], sigdata_t *sigdata[]);
+
+void duh_set_length(DUH *duh, dumb_off_t length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DUMB_H */
--- /dev/null
+++ b/include/internal/aldumb.h
@@ -1,0 +1,25 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * internal/aldumb.h - The internal header file       / / \  \
+ *                     for DUMB with Allegro.        | <  /   \_
+ *                                                   |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#ifndef INTERNAL_ALDUMB_H
+#define INTERNAL_ALDUMB_H
+
+void _dat_unload_duh(void *duh);
+
+#endif /* INTERNAL_DUMB_H */
--- /dev/null
+++ b/include/internal/barray.h
@@ -1,0 +1,43 @@
+#ifndef _B_ARRAY_H_
+#define _B_ARRAY_H_
+
+#include <stdlib.h>
+
+#ifdef BARRAY_DECORATE
+#undef PASTE
+#undef EVALUATE
+#define PASTE(a, b) a##b
+#define EVALUATE(a, b) PASTE(a, b)
+#define bit_array_create EVALUATE(BARRAY_DECORATE, _bit_array_create)
+#define bit_array_destroy EVALUATE(BARRAY_DECORATE, _bit_array_destroy)
+#define bit_array_dup EVALUATE(BARRAY_DECORATE, _bit_array_dup)
+#define bit_array_reset EVALUATE(BARRAY_DECORATE, _bit_array_reset)
+#define bit_array_set EVALUATE(BARRAY_DECORATE, _bit_array_set)
+#define bit_array_set_range EVALUATE(BARRAY_DECORATE, _bit_array_set_range)
+#define bit_array_test EVALUATE(BARRAY_DECORATE, _bit_array_test)
+#define bit_array_test_range EVALUATE(BARRAY_DECORATE, _bit_array_test_range)
+#define bit_array_clear EVALUATE(BARRAY_DECORATE, _bit_array_clear)
+#define bit_array_clear_range EVALUATE(BARRAY_DECORATE, _bit_array_clear_range)
+#define bit_array_merge EVALUATE(BARRAY_DECORATE, _bit_array_merge)
+#define bit_array_mask EVALUATE(BARRAY_DECORATE, _bit_array_mask)
+#endif
+
+void *bit_array_create(size_t size);
+void bit_array_destroy(void *array);
+void *bit_array_dup(void *array);
+
+void bit_array_reset(void *array);
+
+void bit_array_set(void *array, size_t bit);
+void bit_array_set_range(void *array, size_t bit, size_t count);
+
+int bit_array_test(void *array, size_t bit);
+int bit_array_test_range(void *array, size_t bit, size_t count);
+
+void bit_array_clear(void *array, size_t bit);
+void bit_array_clear_range(void *array, size_t bit, size_t count);
+
+void bit_array_merge(void *array, void *source, size_t offset);
+void bit_array_mask(void *array, void *source, size_t offset);
+
+#endif
--- /dev/null
+++ b/include/internal/dumb.h
@@ -1,0 +1,75 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * internal/dumb.h - DUMB's internal declarations.    / / \  \
+ *                                                   | <  /   \_
+ * This header file provides access to the           |  \/ /\   /
+ * internal structure of DUMB, and is liable          \_  /  > /
+ * to change, mutate or cease to exist at any           | \ / /
+ * moment. Include it at your own peril.                |  ' /
+ *                                                       \__/
+ * ...
+ *
+ * Seriously. You don't need access to anything in this file. All right, you
+ * probably do actually. But if you use it, you will be relying on a specific
+ * version of DUMB, so please check DUMB_VERSION defined in dumb.h. Please
+ * contact the authors so that we can provide a public API for what you need.
+ */
+
+#ifndef INTERNAL_DUMB_H
+#define INTERNAL_DUMB_H
+
+#include "../dumb.h"
+
+#undef MIN
+#undef MAX
+#undef MID
+
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#define MID(x, y, z) MAX((x), MIN((y), (z)))
+
+#undef ABS
+#define ABS(x) (((x) >= 0) ? (x) : (-(x)))
+
+#ifndef LONG_LONG
+#if defined __GNUC__ || defined __INTEL_COMPILER || defined __MWERKS__ ||      \
+    defined __sgi
+#define LONG_LONG long long
+#elif defined _MSC_VER || defined __WATCOMC__
+#define LONG_LONG __int64
+#else
+#error 64-bit integer type unknown
+#endif
+#endif
+
+typedef struct DUH_SIGTYPE_DESC_LINK {
+    struct DUH_SIGTYPE_DESC_LINK *next;
+    DUH_SIGTYPE_DESC *desc;
+} DUH_SIGTYPE_DESC_LINK;
+
+typedef struct DUH_SIGNAL {
+    sigdata_t *sigdata;
+    DUH_SIGTYPE_DESC *desc;
+} DUH_SIGNAL;
+
+struct DUH {
+    dumb_off_t length;
+
+    int n_tags;
+    char *(*tag)[2];
+
+    int n_signals;
+    DUH_SIGNAL **signal;
+};
+
+DUH_SIGTYPE_DESC *_dumb_get_sigtype_desc(long type);
+
+#endif /* INTERNAL_DUMB_H */
--- /dev/null
+++ b/include/internal/dumbfile.h
@@ -1,0 +1,12 @@
+#ifndef DUMBFILE_H
+#define DUMBFILE_H
+
+#include "../dumb.h"
+
+struct DUMBFILE {
+    const DUMBFILE_SYSTEM *dfs;
+    void *file;
+    long pos;
+};
+
+#endif // DUMBFILE_H
--- /dev/null
+++ b/include/internal/it.h
@@ -1,0 +1,874 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * internal/it.h - Internal stuff for IT playback     / / \  \
+ *                 and MOD/XM/S3M conversion.        | <  /   \_
+ *                                                   |  \/ /\   /
+ * This header file provides access to the            \_  /  > /
+ * internal structure of DUMB, and is liable            | \ / /
+ * to change, mutate or cease to exist at any           |  ' /
+ * moment. Include it at your own peril.                 \__/
+ *
+ * ...
+ *
+ * Seriously. You don't need access to anything in this file. All right, you
+ * probably do actually. But if you use it, you will be relying on a specific
+ * version of DUMB, so please check DUMB_VERSION defined in dumb.h. Please
+ * contact the authors so that we can provide a public API for what you need.
+ */
+
+#ifndef INTERNAL_IT_H
+#define INTERNAL_IT_H
+
+#define BIT_ARRAY_BULLSHIT
+
+#include <stddef.h>
+
+#include "barray.h"
+#include "tarray.h"
+
+/** TO DO: THINK ABOUT THE FOLLOWING:
+
+sigdata->flags & IT_COMPATIBLE_GXX
+
+                Bit 5: On = Link Effect G's memory with Effect E/F. Also
+                            Gxx with an instrument present will cause the
+                            envelopes to be retriggered. If you change a
+                            sample on a row with Gxx, it'll adjust the
+                            frequency of the current note according to:
+
+                              NewFrequency = OldFrequency * NewC5 / OldC5;
+*/
+
+/* These #defines are TEMPORARY. They are used to write alternative code to
+ * handle ambiguities in the format specification. The correct code in each
+ * case will be determined most likely by experimentation.
+ */
+//#define STEREO_SAMPLES_COUNT_AS_TWO
+#define INVALID_ORDERS_END_SONG
+#define SUSTAIN_LOOP_OVERRIDES_NORMAL_LOOP
+#define VOLUME_OUT_OF_RANGE_SETS_MAXIMUM
+
+#define SIGTYPE_IT DUMB_ID('I', 'T', ' ', ' ')
+
+#define IT_SIGNATURE DUMB_ID('I', 'M', 'P', 'M')
+#define IT_INSTRUMENT_SIGNATURE DUMB_ID('I', 'M', 'P', 'I')
+#define IT_SAMPLE_SIGNATURE DUMB_ID('I', 'M', 'P', 'S')
+
+// olivier sux
+#define IT_MPTX_SIGNATURE DUMB_ID('X', 'T', 'P', 'M')
+#define IT_INSM_SIGNATURE DUMB_ID('M', 'S', 'N', 'I')
+
+/* This is divided by the tempo times 256 to get the interval between ticks.
+ */
+#define TICK_TIME_DIVIDEND (65536 * 5 * 128)
+
+/* I'm not going to try to explain this, because I didn't derive it very
+ * formally ;)
+ */
+/* #define AMIGA_DIVISOR ((float)(4.0 * 14317056.0)) */
+/* I believe the following one to be more accurate. */
+//#define AMIGA_DIVISOR ((float)(8.0 * 7159090.5))
+#define AMIGA_CLOCK 3546895
+#define AMIGA_DIVISOR ((float)(16.0 * AMIGA_CLOCK))
+
+typedef struct IT_MIDI IT_MIDI;
+typedef struct IT_FILTER_STATE IT_FILTER_STATE;
+typedef struct IT_ENVELOPE IT_ENVELOPE;
+typedef struct IT_INSTRUMENT IT_INSTRUMENT;
+typedef struct IT_SAMPLE IT_SAMPLE;
+typedef struct IT_ENTRY IT_ENTRY;
+typedef struct IT_PATTERN IT_PATTERN;
+typedef struct IT_PLAYING_ENVELOPE IT_PLAYING_ENVELOPE;
+typedef struct IT_PLAYING IT_PLAYING;
+typedef struct IT_CHANNEL IT_CHANNEL;
+typedef struct IT_CHECKPOINT IT_CHECKPOINT;
+typedef struct IT_CALLBACKS IT_CALLBACKS;
+
+struct IT_MIDI {
+    unsigned char SFmacro[16][16]; // read these from 0x120
+    unsigned char SFmacrolen[16];
+    unsigned short SFmacroz[16]; /* Bitfield; bit 0 set = z in first position */
+    unsigned char Zmacro[128][16]; // read these from 0x320
+    unsigned char Zmacrolen[128];
+};
+
+struct IT_FILTER_STATE {
+    sample_t currsample, prevsample;
+};
+
+#define IT_ENVELOPE_ON 1
+#define IT_ENVELOPE_LOOP_ON 2
+#define IT_ENVELOPE_SUSTAIN_LOOP 4
+#define IT_ENVELOPE_CARRY 8
+#define IT_ENVELOPE_PITCH_IS_FILTER 128
+
+struct IT_ENVELOPE {
+    unsigned char flags;
+    unsigned char n_nodes;
+    unsigned char loop_start;
+    unsigned char loop_end;
+    unsigned char sus_loop_start;
+    unsigned char sus_loop_end;
+    signed char node_y[25];
+    unsigned short node_t[25];
+};
+
+#define NNA_NOTE_CUT 0
+#define NNA_NOTE_CONTINUE 1
+#define NNA_NOTE_OFF 2
+#define NNA_NOTE_FADE 3
+
+#define DCT_OFF 0
+#define DCT_NOTE 1
+#define DCT_SAMPLE 2
+#define DCT_INSTRUMENT 3
+
+#define DCA_NOTE_CUT 0
+#define DCA_NOTE_OFF 1
+#define DCA_NOTE_FADE 2
+
+struct IT_INSTRUMENT {
+    unsigned char name[27];
+    unsigned char filename[14];
+
+    int fadeout;
+
+    IT_ENVELOPE volume_envelope;
+    IT_ENVELOPE pan_envelope;
+    IT_ENVELOPE pitch_envelope;
+
+    unsigned char new_note_action;
+    unsigned char dup_check_type;
+    unsigned char dup_check_action;
+    signed char pp_separation;
+    unsigned char pp_centre;
+    unsigned char global_volume;
+    unsigned char default_pan;
+    unsigned char random_volume;
+    unsigned char random_pan;
+
+    unsigned char filter_cutoff;
+    unsigned char filter_resonance;
+
+    unsigned char map_note[120];
+    unsigned short map_sample[120];
+
+    // int output;
+};
+
+#define IT_SAMPLE_EXISTS 1
+#define IT_SAMPLE_16BIT 2
+#define IT_SAMPLE_STEREO 4
+#define IT_SAMPLE_LOOP 16
+#define IT_SAMPLE_SUS_LOOP 32
+#define IT_SAMPLE_PINGPONG_LOOP 64
+#define IT_SAMPLE_PINGPONG_SUS_LOOP 128
+
+#define IT_VIBRATO_SINE 0
+#define IT_VIBRATO_SAWTOOTH 1
+#define IT_VIBRATO_SQUARE 2
+#define IT_VIBRATO_RANDOM 3
+#define IT_VIBRATO_XM_SQUARE 4
+#define IT_VIBRATO_RAMP_DOWN 5
+#define IT_VIBRATO_RAMP_UP 6
+
+struct IT_SAMPLE {
+    unsigned char name[35];
+    unsigned char filename[15];
+    unsigned char flags;
+    unsigned char global_volume;
+    unsigned char default_volume;
+    unsigned char default_pan;
+    /* default_pan:
+     *   0-255 for XM
+     *   ignored for MOD
+     *   otherwise, 0-64, and add 128 to enable
+     */
+
+    long length;
+    long loop_start;
+    long loop_end;
+    long C5_speed;
+    long sus_loop_start;
+    long sus_loop_end;
+
+    unsigned char vibrato_speed;
+    unsigned char vibrato_depth;
+    unsigned char vibrato_rate;
+    unsigned char vibrato_waveform;
+
+    signed short finetune;
+
+    void *data;
+
+    int max_resampling_quality;
+};
+
+#define IT_ENTRY_NOTE 1
+#define IT_ENTRY_INSTRUMENT 2
+#define IT_ENTRY_VOLPAN 4
+#define IT_ENTRY_EFFECT 8
+
+#define IT_SET_END_ROW(entry) ((entry)->channel = 255)
+#define IT_IS_END_ROW(entry) ((entry)->channel >= DUMB_IT_N_CHANNELS)
+
+#define IT_NOTE_OFF 255
+#define IT_NOTE_CUT 254
+
+#define IT_ENVELOPE_SHIFT 8
+
+#define IT_SURROUND 100
+#define IT_IS_SURROUND(pan) ((pan) > 64)
+#define IT_IS_SURROUND_SHIFTED(pan) ((pan) > 64 << IT_ENVELOPE_SHIFT)
+
+#define IT_SET_SPEED 1
+#define IT_JUMP_TO_ORDER 2
+#define IT_BREAK_TO_ROW 3
+#define IT_VOLUME_SLIDE 4
+#define IT_PORTAMENTO_DOWN 5
+#define IT_PORTAMENTO_UP 6
+#define IT_TONE_PORTAMENTO 7
+#define IT_VIBRATO 8
+#define IT_TREMOR 9
+#define IT_ARPEGGIO 10
+#define IT_VOLSLIDE_VIBRATO 11
+#define IT_VOLSLIDE_TONEPORTA 12
+#define IT_SET_CHANNEL_VOLUME 13
+#define IT_CHANNEL_VOLUME_SLIDE 14
+#define IT_SET_SAMPLE_OFFSET 15
+#define IT_PANNING_SLIDE 16
+#define IT_RETRIGGER_NOTE 17
+#define IT_TREMOLO 18
+#define IT_S 19
+#define IT_SET_SONG_TEMPO 20
+#define IT_FINE_VIBRATO 21
+#define IT_SET_GLOBAL_VOLUME 22
+#define IT_GLOBAL_VOLUME_SLIDE 23
+#define IT_SET_PANNING 24
+#define IT_PANBRELLO 25
+#define IT_MIDI_MACRO 26 // see MIDI.TXT
+
+/* Some effects needed for XM compatibility */
+#define IT_XM_PORTAMENTO_DOWN 27
+#define IT_XM_PORTAMENTO_UP 28
+#define IT_XM_FINE_VOLSLIDE_DOWN 29
+#define IT_XM_FINE_VOLSLIDE_UP 30
+#define IT_XM_RETRIGGER_NOTE 31
+#define IT_XM_KEY_OFF 32
+#define IT_XM_SET_ENVELOPE_POSITION 33
+
+/* More effects needed for PTM compatibility */
+#define IT_PTM_NOTE_SLIDE_DOWN 34
+#define IT_PTM_NOTE_SLIDE_UP 35
+#define IT_PTM_NOTE_SLIDE_DOWN_RETRIG 36
+#define IT_PTM_NOTE_SLIDE_UP_RETRIG 37
+
+/* More effects needed for OKT compatibility */
+#define IT_OKT_NOTE_SLIDE_DOWN 38
+#define IT_OKT_NOTE_SLIDE_DOWN_ROW 39
+#define IT_OKT_NOTE_SLIDE_UP 40
+#define IT_OKT_NOTE_SLIDE_UP_ROW 41
+#define IT_OKT_ARPEGGIO_3 42
+#define IT_OKT_ARPEGGIO_4 43
+#define IT_OKT_ARPEGGIO_5 44
+#define IT_OKT_VOLUME_SLIDE_DOWN 45
+#define IT_OKT_VOLUME_SLIDE_UP 46
+
+#define IT_N_EFFECTS 47
+
+/* These represent the top nibble of the command value. */
+#define IT_S_SET_FILTER 0            /* Greyed out in IT... */
+#define IT_S_SET_GLISSANDO_CONTROL 1 /* Greyed out in IT... */
+#define IT_S_FINETUNE 2              /* Greyed out in IT... */
+#define IT_S_SET_VIBRATO_WAVEFORM 3
+#define IT_S_SET_TREMOLO_WAVEFORM 4
+#define IT_S_SET_PANBRELLO_WAVEFORM 5
+#define IT_S_FINE_PATTERN_DELAY 6
+#define IT_S7 7
+#define IT_S_SET_PAN 8
+#define IT_S_SET_SURROUND_SOUND 9
+#define IT_S_SET_HIGH_OFFSET 10
+#define IT_S_PATTERN_LOOP 11
+#define IT_S_DELAYED_NOTE_CUT 12
+#define IT_S_NOTE_DELAY 13
+#define IT_S_PATTERN_DELAY 14
+#define IT_S_SET_MIDI_MACRO 15
+
+/*
+S0x Set filter
+S1x Set glissando control
+S2x Set finetune
+
+
+S3x Set vibrato waveform to type x
+S4x Set tremelo waveform to type x
+S5x Set panbrello waveform to type x
+  Waveforms for commands S3x, S4x and S5x:
+    0: Sine wave
+    1: Ramp down
+    2: Square wave
+    3: Random wave
+S6x Pattern delay for x ticks
+S70 Past note cut
+S71 Past note off
+S72 Past note fade
+S73 Set NNA to note cut
+S74 Set NNA to continue
+S75 Set NNA to note off
+S76 Set NNA to note fade
+S77 Turn off volume envelope
+S78 Turn on volume envelope
+S79 Turn off panning envelope
+S7A Turn on panning envelope
+S7B Turn off pitch envelope
+S7C Turn on pitch envelope
+S8x Set panning position
+S91 Set surround sound
+SAy Set high value of sample offset yxx00h
+SB0 Set loopback point
+SBx Loop x times to loopback point
+SCx Note cut after x ticks
+SDx Note delay for x ticks
+SEx Pattern delay for x rows
+SFx Set parameterised MIDI Macro
+*/
+
+struct IT_ENTRY {
+    unsigned char channel; /* End of row if channel >= DUMB_IT_N_CHANNELS */
+    unsigned char mask;
+    unsigned char note;
+    unsigned char instrument;
+    unsigned char volpan;
+    unsigned char effect;
+    unsigned char effectvalue;
+};
+
+struct IT_PATTERN {
+    int n_rows;
+    int n_entries;
+    IT_ENTRY *entry;
+};
+
+#define IT_STEREO 1
+#define IT_USE_INSTRUMENTS 4
+#define IT_LINEAR_SLIDES 8 /* If not set, use Amiga slides */
+#define IT_OLD_EFFECTS 16
+#define IT_COMPATIBLE_GXX 32
+
+/* Make sure IT_WAS_AN_XM and IT_WAS_A_MOD aren't set accidentally */
+#define IT_REAL_FLAGS 63
+
+#define IT_WAS_AN_XM 64 /* Set for both XMs and MODs */
+#define IT_WAS_A_MOD 128
+
+#define IT_WAS_AN_S3M 256
+
+#define IT_WAS_A_PTM 512
+
+#define IT_WAS_A_669 1024
+
+#define IT_WAS_AN_OKT 2048
+
+#define IT_WAS_AN_STM 4096
+
+#define IT_WAS_PROCESSED                                                       \
+    8192 /* Will be set the first time a sigdata passes through a sigrenderer  \
+          */
+
+#define IT_ORDER_END 255
+#define IT_ORDER_SKIP 254
+
+struct DUMB_IT_SIGDATA {
+    unsigned char name[65];
+
+    unsigned char *song_message;
+
+    int n_orders;
+    int n_instruments;
+    int n_samples;
+    int n_patterns;
+    int n_pchannels;
+
+    int flags;
+
+    int global_volume;
+    int mixing_volume;
+    int speed;
+    int tempo;
+    int pan_separation;
+
+    unsigned char channel_pan[DUMB_IT_N_CHANNELS];
+    unsigned char channel_volume[DUMB_IT_N_CHANNELS];
+
+    unsigned char *order;
+    unsigned char restart_position; /* for XM compatiblity */
+
+    IT_INSTRUMENT *instrument;
+    IT_SAMPLE *sample;
+    IT_PATTERN *pattern;
+
+    IT_MIDI *midi;
+
+    IT_CHECKPOINT *checkpoint;
+};
+
+struct IT_PLAYING_ENVELOPE {
+    int next_node;
+    int tick;
+    int value;
+};
+
+#define IT_PLAYING_BACKGROUND 1
+#define IT_PLAYING_SUSTAINOFF 2
+#define IT_PLAYING_FADING 4
+#define IT_PLAYING_DEAD 8
+#define IT_PLAYING_REVERSE 16
+
+struct IT_PLAYING {
+    int flags;
+
+    int resampling_quality;
+
+    IT_CHANNEL *channel;
+    IT_SAMPLE *sample;
+    IT_INSTRUMENT *instrument;
+    IT_INSTRUMENT *env_instrument;
+
+    unsigned short sampnum;
+    unsigned char instnum;
+
+    unsigned char declick_stage;
+
+    float float_volume[2];
+    float ramp_volume[2];
+    float ramp_delta[2];
+
+    unsigned char channel_volume;
+
+    unsigned char volume;
+    unsigned short pan;
+
+    signed char volume_offset, panning_offset;
+
+    unsigned char note;
+
+    unsigned char enabled_envelopes;
+
+    unsigned char filter_cutoff;
+    unsigned char filter_resonance;
+
+    unsigned short
+        true_filter_cutoff; /* These incorporate the filter envelope, and will
+                               not */
+    unsigned char true_filter_resonance; /* be changed if they would be set to
+                                            127<<8 and 0.    */
+
+    unsigned char vibrato_speed;
+    unsigned char vibrato_depth;
+    unsigned char vibrato_n; /* May be specified twice: volpan & effect. */
+    unsigned char vibrato_time;
+    unsigned char vibrato_waveform;
+
+    unsigned char tremolo_speed;
+    unsigned char tremolo_depth;
+    unsigned char tremolo_time;
+    unsigned char tremolo_waveform;
+
+    unsigned char panbrello_speed;
+    unsigned char panbrello_depth;
+    unsigned char panbrello_time;
+    unsigned char panbrello_waveform;
+    signed char panbrello_random;
+
+    unsigned char sample_vibrato_time;
+    unsigned char sample_vibrato_waveform;
+    int sample_vibrato_depth; /* Starts at rate?0:depth, increases by rate */
+
+    int slide;
+    float delta;
+    int finetune;
+
+    IT_PLAYING_ENVELOPE volume_envelope;
+    IT_PLAYING_ENVELOPE pan_envelope;
+    IT_PLAYING_ENVELOPE pitch_envelope;
+
+    int fadeoutcount;
+
+    IT_FILTER_STATE filter_state[2]; /* Left and right */
+
+    DUMB_RESAMPLER resampler;
+
+    /* time_lost is used to emulate Impulse Tracker's sample looping
+     * characteristics. When time_lost is added to pos, the result represents
+     * the position in the theoretical version of the sample where all loops
+     * have been expanded. If this is stored, the resampling helpers will
+     * safely convert it for use with new loop boundaries. The situation is
+     * slightly more complicated if dir == -1 when the change takes place; we
+     * must reflect pos off the loop end point and set dir to 1 before
+     * proceeding.
+     */
+    long time_lost;
+
+    // int output;
+};
+
+#define IT_CHANNEL_MUTED 1
+
+#define IT_ENV_VOLUME 1
+#define IT_ENV_PANNING 2
+#define IT_ENV_PITCH 4
+
+struct IT_CHANNEL {
+    int flags;
+
+    unsigned char volume;
+    signed char volslide;
+    signed char xm_volslide;
+    signed char panslide;
+
+    /* xm_volslide is used for volume slides done in the volume column in an
+     * XM file, since it seems the volume column slide is applied first,
+     * followed by clamping, followed by the effects column slide. IT does
+     * not exhibit this behaviour, so xm_volslide is maintained at zero.
+     */
+
+    unsigned char pan;
+    unsigned short truepan;
+
+    unsigned char channelvolume;
+    signed char channelvolslide;
+
+    unsigned char instrument;
+    unsigned char note;
+
+    unsigned char SFmacro;
+
+    unsigned char filter_cutoff;
+    unsigned char filter_resonance;
+
+    unsigned char key_off_count;
+    unsigned char note_cut_count;
+    unsigned char note_delay_count;
+    IT_ENTRY *note_delay_entry;
+
+    unsigned char new_note_action;
+
+    unsigned char const *arpeggio_table;
+    signed char arpeggio_offsets[3];
+
+    int arpeggio_shift;
+    unsigned char retrig;
+    unsigned char xm_retrig;
+    int retrig_tick;
+
+    unsigned char tremor;
+    unsigned char
+        tremor_time; /* Bit 6 set if note on; bit 7 set if tremor active. */
+
+    unsigned char vibrato_waveform;
+    unsigned char tremolo_waveform;
+    unsigned char panbrello_waveform;
+
+    int portamento;
+    int toneporta;
+    int toneslide;
+    unsigned char toneslide_tick, last_toneslide_tick, ptm_toneslide,
+        ptm_last_toneslide, okt_toneslide;
+    unsigned char destnote;
+    unsigned char toneslide_retrig;
+
+    unsigned char glissando;
+
+    /** WARNING - for neatness, should one or both of these be in the IT_PLAYING
+     * struct? */
+    unsigned short sample;
+    unsigned char truenote;
+
+    unsigned char midi_state;
+
+    signed char lastvolslide;
+    unsigned char lastDKL;
+    unsigned char lastEF; /* Doubles as last portamento up for XM files */
+    unsigned char lastG;
+    unsigned char lastHspeed;
+    unsigned char lastHdepth;
+    unsigned char lastRspeed;
+    unsigned char lastRdepth;
+    unsigned char lastYspeed;
+    unsigned char lastYdepth;
+    unsigned char lastI;
+    unsigned char lastJ; /* Doubles as last portamento down for XM files */
+    unsigned char lastN;
+    unsigned char lastO;
+    unsigned char high_offset;
+    unsigned char lastP;
+    unsigned char lastQ;
+    unsigned char lastS;
+    unsigned char pat_loop_row;
+    unsigned char pat_loop_count;
+    unsigned char pat_loop_end_row; /* Used to catch infinite pattern loops */
+    unsigned char lastW;
+
+    unsigned char xm_lastE1;
+    unsigned char xm_lastE2;
+    unsigned char xm_lastEA;
+    unsigned char xm_lastEB;
+    unsigned char xm_lastX1;
+    unsigned char xm_lastX2;
+
+    unsigned char inv_loop_delay;
+    unsigned char inv_loop_speed;
+    int inv_loop_offset;
+
+    IT_PLAYING *playing;
+
+#ifdef BIT_ARRAY_BULLSHIT
+    void *played_patjump;
+    int played_patjump_order;
+#endif
+
+    // int output;
+};
+
+struct DUMB_IT_SIGRENDERER {
+    DUMB_IT_SIGDATA *sigdata;
+
+    int n_channels;
+
+    int resampling_quality;
+
+    unsigned char globalvolume;
+    signed char globalvolslide;
+
+    int tempo;
+    signed char temposlide;
+
+    IT_CHANNEL channel[DUMB_IT_N_CHANNELS];
+
+    IT_PLAYING *playing[DUMB_IT_N_NNA_CHANNELS];
+
+    int tick;
+    int speed;
+    int rowcount;
+
+    int order; /* Set to -1 if the song is terminated by a callback. */
+    int row;
+    int processorder;
+    int processrow;
+    int breakrow;
+
+    int restart_position;
+
+    int n_rows;
+
+    IT_ENTRY *entry_start;
+    IT_ENTRY *entry;
+    IT_ENTRY *entry_end;
+
+    long time_left; /* Time before the next tick is processed */
+    int sub_time_left;
+
+    DUMB_CLICK_REMOVER **click_remover;
+
+    IT_CALLBACKS *callbacks;
+
+#ifdef BIT_ARRAY_BULLSHIT
+    /* bit array, which rows are played, only checked by pattern break or loop
+     * commands */
+    void *played;
+
+    /*
+       Loop indicator for internal processes, may also be useful for external
+      processes 0 - Not looped 1 - Looped -1 - Continued past loop
+     */
+    int looped;
+
+    /*
+       Kept until looped
+    */
+    LONG_LONG time_played;
+
+    void *row_timekeeper;
+#endif
+
+    long gvz_time;
+    int gvz_sub_time;
+
+    int ramp_style;
+
+    // int max_output;
+};
+
+struct IT_CHECKPOINT {
+    IT_CHECKPOINT *next;
+    long time;
+    DUMB_IT_SIGRENDERER *sigrenderer;
+};
+
+struct IT_CALLBACKS {
+    int (*loop)(void *data);
+    void *loop_data;
+    /* Return 1 to prevent looping; the music will terminate abruptly. If you
+     * want to make the music stop but allow samples to fade (beware, as they
+     * might not fade at all!), use dumb_it_sr_set_speed() and set the speed
+     * to 0. Note that xm_speed_zero() will not be called if you set the
+     * speed manually, and also that this will work for IT and S3M files even
+     * though the music can't stop in this way by itself.
+     */
+
+    int (*xm_speed_zero)(void *data);
+    void *xm_speed_zero_data;
+    /* Return 1 to terminate the mod, without letting samples fade. */
+
+    int (*midi)(void *data, int channel, unsigned char byte);
+    void *midi_data;
+    /* Return 1 to prevent DUMB from subsequently interpreting the MIDI bytes
+     * itself. In other words, return 1 if the Zxx macros in an IT file are
+     * controlling filters and shouldn't be.
+     */
+
+    int (*global_volume_zero)(void *data);
+    void *global_volume_zero_data;
+    /* Return 1 to terminate the module when global volume is set to zero. */
+};
+
+void _dumb_it_end_sigrenderer(sigrenderer_t *sigrenderer);
+void _dumb_it_unload_sigdata(sigdata_t *vsigdata);
+
+extern DUH_SIGTYPE_DESC _dumb_sigtype_it;
+
+#define XM_APPREGIO 0
+#define XM_PORTAMENTO_UP 1
+#define XM_PORTAMENTO_DOWN 2
+#define XM_TONE_PORTAMENTO 3
+#define XM_VIBRATO 4
+#define XM_VOLSLIDE_TONEPORTA 5
+#define XM_VOLSLIDE_VIBRATO 6
+#define XM_TREMOLO 7
+#define XM_SET_PANNING 8
+#define XM_SAMPLE_OFFSET 9
+#define XM_VOLUME_SLIDE 10          /* A */
+#define XM_POSITION_JUMP 11         /* B */
+#define XM_SET_CHANNEL_VOLUME 12    /* C */
+#define XM_PATTERN_BREAK 13         /* D */
+#define XM_E 14                     /* E */
+#define XM_SET_TEMPO_BPM 15         /* F */
+#define XM_SET_GLOBAL_VOLUME 16     /* G */
+#define XM_GLOBAL_VOLUME_SLIDE 17   /* H */
+#define XM_KEY_OFF 20               /* K (undocumented) */
+#define XM_SET_ENVELOPE_POSITION 21 /* L */
+#define XM_PANNING_SLIDE 25         /* P */
+#define XM_MULTI_RETRIG 27          /* R */
+#define XM_TREMOR 29                /* T */
+#define XM_X 33                     /* X */
+#define XM_N_EFFECTS (10 + 26)
+
+#define XM_E_SET_FILTER 0x0
+#define XM_E_FINE_PORTA_UP 0x1
+#define XM_E_FINE_PORTA_DOWN 0x2
+#define XM_E_SET_GLISSANDO_CONTROL 0x3
+#define XM_E_SET_VIBRATO_CONTROL 0x4
+#define XM_E_SET_FINETUNE 0x5
+#define XM_E_SET_LOOP 0x6
+#define XM_E_SET_TREMOLO_CONTROL 0x7
+#define XM_E_SET_PANNING 0x8
+#define XM_E_RETRIG_NOTE 0x9
+#define XM_E_FINE_VOLSLIDE_UP 0xA
+#define XM_E_FINE_VOLSLIDE_DOWN 0xB
+#define XM_E_NOTE_CUT 0xC
+#define XM_E_NOTE_DELAY 0xD
+#define XM_E_PATTERN_DELAY 0xE
+#define XM_E_SET_MIDI_MACRO 0xF
+
+#define XM_X_EXTRAFINE_PORTA_UP 1
+#define XM_X_EXTRAFINE_PORTA_DOWN 2
+
+/* To make my life a bit simpler during conversion, effect E:xy is converted
+ * to effect number EBASE+x:y. The same applies to effect X, and IT's S. That
+ * way, these effects can be manipulated like regular effects.
+ */
+#define EBASE (XM_N_EFFECTS)
+#define XBASE (EBASE + 16)
+#define SBASE (IT_N_EFFECTS)
+
+#define EFFECT_VALUE(x, y) (((x) << 4) | (y))
+#define HIGH(v) ((v) >> 4)
+#define LOW(v) ((v)&0x0F)
+#define SET_HIGH(v, x) v = (((x) << 4) | ((v)&0x0F))
+#define SET_LOW(v, y) v = (((v)&0xF0) | (y))
+#define BCD_TO_NORMAL(v) (HIGH(v) * 10 + LOW(v))
+
+#if 0
+unsigned char **_dumb_malloc2(int w, int h);
+void _dumb_free2(unsigned char **line);
+#endif
+
+void _dumb_it_xm_convert_effect(int effect, int value, IT_ENTRY *entry,
+                                int mod);
+int _dumb_it_fix_invalid_orders(DUMB_IT_SIGDATA *sigdata);
+
+#define PTM_APPREGIO 0
+#define PTM_PORTAMENTO_UP 1
+#define PTM_PORTAMENTO_DOWN 2
+#define PTM_TONE_PORTAMENTO 3
+#define PTM_VIBRATO 4
+#define PTM_VOLSLIDE_TONEPORTA 5
+#define PTM_VOLSLIDE_VIBRATO 6
+#define PTM_TREMOLO 7
+#define PTM_SAMPLE_OFFSET 9
+#define PTM_VOLUME_SLIDE 10           /* A */
+#define PTM_POSITION_JUMP 11          /* B */
+#define PTM_SET_CHANNEL_VOLUME 12     /* C */
+#define PTM_PATTERN_BREAK 13          /* D */
+#define PTM_E 14                      /* E */
+#define PTM_SET_TEMPO_BPM 15          /* F */
+#define PTM_SET_GLOBAL_VOLUME 16      /* G */
+#define PTM_RETRIGGER 17              /* H */
+#define PTM_FINE_VIBRATO 18           /* I */
+#define PTM_NOTE_SLIDE_UP 19          /* J */
+#define PTM_NOTE_SLIDE_DOWN 20        /* K */
+#define PTM_NOTE_SLIDE_UP_RETRIG 21   /* L */
+#define PTM_NOTE_SLIDE_DOWN_RETRIG 22 /* M */
+#define PTM_N_EFFECTS 23
+
+#define PTM_E_FINE_PORTA_DOWN 0x1
+#define PTM_E_FINE_PORTA_UP 0x2
+#define PTM_E_SET_VIBRATO_CONTROL 0x4
+#define PTM_E_SET_FINETUNE 0x5
+#define PTM_E_SET_LOOP 0x6
+#define PTM_E_SET_TREMOLO_CONTROL 0x7
+#define PTM_E_SET_PANNING 0x8
+#define PTM_E_RETRIG_NOTE 0x9
+#define PTM_E_FINE_VOLSLIDE_UP 0xA
+#define PTM_E_FINE_VOLSLIDE_DOWN 0xB
+#define PTM_E_NOTE_CUT 0xC
+#define PTM_E_NOTE_DELAY 0xD
+#define PTM_E_PATTERN_DELAY 0xE
+
+/* To make my life a bit simpler during conversion, effect E:xy is converted
+ * to effect number EBASE+x:y. The same applies to effect X, and IT's S. That
+ * way, these effects can be manipulated like regular effects.
+ */
+#define PTM_EBASE (PTM_N_EFFECTS)
+
+void _dumb_it_ptm_convert_effect(int effect, int value, IT_ENTRY *entry);
+
+long _dumb_it_read_sample_data_adpcm4(IT_SAMPLE *sample, DUMBFILE *f);
+
+void _dumb_it_interleave_stereo_sample(IT_SAMPLE *sample);
+
+/* Calling either of these is optional */
+void _dumb_init_cubic(void);
+#ifdef _USE_SSE
+void _dumb_init_sse(void);
+#endif
+
+#endif /* INTERNAL_IT_H */
--- /dev/null
+++ b/include/internal/lpc.h
@@ -1,0 +1,24 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+  function: LPC low level routines
+  last mod: $Id: lpc.h 16037 2009-05-26 21:10:58Z xiphmont $
+
+ ********************************************************************/
+
+#ifndef _V_LPC_H_
+#define _V_LPC_H_
+
+struct DUMB_IT_SIGDATA;
+extern int dumb_it_add_lpc(struct DUMB_IT_SIGDATA *sigdata);
+
+#endif
--- /dev/null
+++ b/include/internal/resampler.h
@@ -1,0 +1,70 @@
+#ifndef _RESAMPLER_H_
+#define _RESAMPLER_H_
+
+// Ugglay
+#ifdef RESAMPLER_DECORATE
+#undef PASTE
+#undef EVALUATE
+#define PASTE(a, b) a##b
+#define EVALUATE(a, b) PASTE(a, b)
+#define resampler_init EVALUATE(RESAMPLER_DECORATE, _resampler_init)
+#define resampler_create EVALUATE(RESAMPLER_DECORATE, _resampler_create)
+#define resampler_delete EVALUATE(RESAMPLER_DECORATE, _resampler_delete)
+#define resampler_dup EVALUATE(RESAMPLER_DECORATE, _resampler_dup)
+#define resampler_dup_inplace                                                  \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_dup_inplace)
+#define resampler_set_quality                                                  \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_set_quality)
+#define resampler_get_free_count                                               \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_get_free_count)
+#define resampler_write_sample                                                 \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_write_sample)
+#define resampler_write_sample_fixed                                           \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_write_sample_fixed)
+#define resampler_write_sample_float                                           \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_write_sample_float)
+#define resampler_set_rate EVALUATE(RESAMPLER_DECORATE, _resampler_set_rate)
+#define resampler_ready EVALUATE(RESAMPLER_DECORATE, _resampler_ready)
+#define resampler_clear EVALUATE(RESAMPLER_DECORATE, _resampler_clear)
+#define resampler_get_sample_count                                             \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_get_sample_count)
+#define resampler_get_sample EVALUATE(RESAMPLER_DECORATE, _resampler_get_sample)
+#define resampler_get_sample_float                                             \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_get_sample_float)
+#define resampler_remove_sample                                                \
+    EVALUATE(RESAMPLER_DECORATE, _resampler_remove_sample)
+#endif
+
+void resampler_init(void);
+
+void *resampler_create(void);
+void resampler_delete(void *);
+void *resampler_dup(const void *);
+void resampler_dup_inplace(void *, const void *);
+
+enum {
+    RESAMPLER_QUALITY_MIN = 0,
+    RESAMPLER_QUALITY_ZOH = 0,
+    RESAMPLER_QUALITY_BLEP = 1,
+    RESAMPLER_QUALITY_LINEAR = 2,
+    RESAMPLER_QUALITY_BLAM = 3,
+    RESAMPLER_QUALITY_CUBIC = 4,
+    RESAMPLER_QUALITY_SINC = 5,
+    RESAMPLER_QUALITY_MAX = 5
+};
+
+void resampler_set_quality(void *, int quality);
+
+int resampler_get_free_count(void *);
+void resampler_write_sample(void *, short sample);
+void resampler_write_sample_fixed(void *, int sample, unsigned char depth);
+void resampler_write_sample_float(void *, float sample);
+void resampler_set_rate(void *, double new_factor);
+int resampler_ready(void *);
+void resampler_clear(void *);
+int resampler_get_sample_count(void *);
+int resampler_get_sample(void *);
+float resampler_get_sample_float(void *);
+void resampler_remove_sample(void *, int decay);
+
+#endif
--- /dev/null
+++ b/include/internal/riff.h
@@ -1,0 +1,22 @@
+#ifndef RIFF_H
+#define RIFF_H
+
+struct riff;
+
+struct riff_chunk {
+    unsigned type;
+    long offset;
+    unsigned size;
+    struct riff *nested;
+};
+
+struct riff {
+    unsigned type;
+    unsigned chunk_count;
+    struct riff_chunk *chunks;
+};
+
+struct riff *riff_parse(DUMBFILE *f, long offset, long size, unsigned proper);
+void riff_free(struct riff *);
+
+#endif
--- /dev/null
+++ b/include/internal/stack_alloc.h
@@ -1,0 +1,118 @@
+/* Copyright (C) 2002 Jean-Marc Valin */
+/**
+   @file stack_alloc.h
+   @brief Temporary memory allocation on stack
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef STACK_ALLOC_H
+#define STACK_ALLOC_H
+
+#ifdef WIN32
+#include <malloc.h>
+#else
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#else
+#include <stdlib.h>
+#endif
+#endif
+
+/**
+ * @def ALIGN(stack, size)
+ *
+ * Aligns the stack to a 'size' boundary
+ *
+ * @param stack Stack
+ * @param size  New size boundary
+ */
+
+/**
+ * @def PUSH(stack, size, type)
+ *
+ * Allocates 'size' elements of type 'type' on the stack
+ *
+ * @param stack Stack
+ * @param size  Number of elements
+ * @param type  Type of element
+ */
+
+/**
+ * @def VARDECL(var)
+ *
+ * Declare variable on stack
+ *
+ * @param var Variable to declare
+ */
+
+/**
+ * @def ALLOC(var, size, type)
+ *
+ * Allocate 'size' elements of 'type' on stack
+ *
+ * @param var  Name of variable to allocate
+ * @param size Number of elements
+ * @param type Type of element
+ */
+
+#ifdef ENABLE_VALGRIND
+
+#include <valgrind/memcheck.h>
+
+#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size)-1))
+
+#define PUSH(stack, size, type)                                                \
+    (VALGRIND_MAKE_NOACCESS(stack, 1000), ALIGN((stack), sizeof(type)),        \
+     VALGRIND_MAKE_WRITABLE(stack, ((size) * sizeof(type))),                   \
+     (stack) += ((size) * sizeof(type)),                                       \
+     (type *)((stack) - ((size) * sizeof(type))))
+
+#else
+
+#define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size)-1))
+
+#define PUSH(stack, size, type)                                                \
+    (ALIGN((stack), sizeof(type)), (stack) += ((size) * sizeof(type)),         \
+     (type *)((stack) - ((size) * sizeof(type))))
+
+#endif
+
+#if defined(VAR_ARRAYS)
+#define VARDECL(var)
+#define ALLOC(var, size, type) type var[size]
+#elif defined(USE_ALLOCA)
+#define VARDECL(var) var
+#define ALLOC(var, size, type) var = alloca(sizeof(type) * (size))
+#else
+#define VARDECL(var) var
+#define ALLOC(var, size, type) var = PUSH(stack, size, type)
+#endif
+
+#endif
--- /dev/null
+++ b/include/internal/tarray.h
@@ -1,0 +1,20 @@
+#ifndef _T_ARRAY_H_
+#define _T_ARRAY_H_
+
+#include <stdlib.h>
+#include "internal/dumb.h"
+
+void *timekeeping_array_create(size_t size);
+void timekeeping_array_destroy(void *array);
+void *timekeeping_array_dup(void *array);
+
+void timekeeping_array_reset(void *array, size_t loop_start);
+
+void timekeeping_array_push(void *array, size_t index, LONG_LONG time);
+void timekeeping_array_bump(void *array, size_t index);
+
+unsigned int timekeeping_array_get_count(void *array, size_t index);
+
+LONG_LONG timekeeping_array_get_item(void *array, size_t index);
+
+#endif
--- /dev/null
+++ b/pkg-config.pc.in
@@ -1,0 +1,12 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=@CMAKE_INSTALL_FULL_LIBDIR@
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
+
+Name: DUMB
+Description: DUMB is a module audio renderer library. 
+Version: @DUMB_VERSION@
+URL: https://github.com/kode54/dumb/
+Libs: -L${libdir} -l@PROJECT_NAME@
+Libs.private: -lm
+Cflags: -I${includedir} 
--- /dev/null
+++ b/src/allegro/alplay.c
@@ -1,0 +1,217 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * alplay.c - Functions to play a DUH through         / / \  \
+ *            an Allegro audio stream.               | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include <allegro.h>
+
+#include "aldumb.h"
+
+#define ADP_PLAYING 1
+
+struct AL_DUH_PLAYER {
+    int flags;
+    long bufsize;
+    int freq;
+    AUDIOSTREAM *stream;
+    DUH_SIGRENDERER *sigrenderer; /* If this is NULL, stream is invalid. */
+    float volume;
+    int silentcount;
+};
+
+AL_DUH_PLAYER *al_start_duh(DUH *duh, int n_channels, long pos, float volume,
+                            long bufsize, int freq) {
+    AL_DUH_PLAYER *dp;
+
+    /* This restriction is imposed by Allegro. */
+    ASSERT(n_channels > 0);
+    ASSERT(n_channels <= 2);
+
+    if (!duh)
+        return NULL;
+
+    dp = malloc(sizeof(*dp));
+    if (!dp)
+        return NULL;
+
+    dp->flags = ADP_PLAYING;
+    dp->bufsize = bufsize;
+    dp->freq = freq;
+
+    dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128);
+
+    if (!dp->stream) {
+        free(dp);
+        return NULL;
+    }
+
+    voice_set_priority(dp->stream->voice, 255);
+
+    dp->sigrenderer = duh_start_sigrenderer(duh, 0, n_channels, pos);
+
+    if (!dp->sigrenderer) {
+        stop_audio_stream(dp->stream);
+        free(dp);
+        return NULL;
+    }
+
+    dp->volume = volume;
+    dp->silentcount = 0;
+
+    return dp;
+}
+
+void al_stop_duh(AL_DUH_PLAYER *dp) {
+    if (dp) {
+        if (dp->sigrenderer) {
+            duh_end_sigrenderer(dp->sigrenderer);
+            stop_audio_stream(dp->stream);
+        }
+        free(dp);
+    }
+}
+
+void al_pause_duh(AL_DUH_PLAYER *dp) {
+    if (dp && dp->sigrenderer && (dp->flags & ADP_PLAYING)) {
+        voice_stop(dp->stream->voice);
+        dp->flags &= ~ADP_PLAYING;
+    }
+}
+
+void al_resume_duh(AL_DUH_PLAYER *dp) {
+    if (dp && dp->sigrenderer && !(dp->flags & ADP_PLAYING)) {
+        voice_start(dp->stream->voice);
+        dp->flags |= ADP_PLAYING;
+    }
+}
+
+void al_duh_set_priority(AL_DUH_PLAYER *dp, int priority) {
+    if (dp && dp->sigrenderer)
+        voice_set_priority(dp->stream->voice, priority);
+}
+
+void al_duh_set_volume(AL_DUH_PLAYER *dp, float volume) {
+    if (dp)
+        dp->volume = volume;
+}
+
+float al_duh_get_volume(AL_DUH_PLAYER *dp) { return dp ? dp->volume : 0; }
+
+int al_poll_duh(AL_DUH_PLAYER *dp) {
+    unsigned short *sptr;
+    long n;
+    long size;
+    int n_channels;
+
+    if (!dp || !dp->sigrenderer)
+        return 1;
+
+    if (!(dp->flags & ADP_PLAYING))
+        return 0;
+
+    sptr = get_audio_stream_buffer(dp->stream);
+
+    if (!sptr)
+        return 0;
+
+    n = duh_render(dp->sigrenderer, 16, 1, dp->volume, 65536.0 / dp->freq,
+                   dp->bufsize, sptr);
+
+    if (n == 0) {
+        if (++dp->silentcount >= 2) {
+            duh_end_sigrenderer(dp->sigrenderer);
+            free_audio_stream_buffer(dp->stream);
+            stop_audio_stream(dp->stream);
+            dp->sigrenderer = NULL;
+            return 1;
+        }
+    }
+
+    n_channels = duh_sigrenderer_get_n_channels(dp->sigrenderer);
+    n *= n_channels;
+    size = dp->bufsize * n_channels;
+    for (; n < size; n++)
+        sptr[n] = 0x8000;
+
+    free_audio_stream_buffer(dp->stream);
+
+    return 0;
+}
+
+long al_duh_get_position(AL_DUH_PLAYER *dp) {
+    return dp ? duh_sigrenderer_get_position(dp->sigrenderer) : -1;
+}
+
+AL_DUH_PLAYER *al_duh_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer,
+                                              float volume, long bufsize,
+                                              int freq) {
+    AL_DUH_PLAYER *dp;
+    int n_channels;
+
+    if (!sigrenderer)
+        return NULL;
+
+    dp = malloc(sizeof(*dp));
+    if (!dp)
+        return NULL;
+
+    n_channels = duh_sigrenderer_get_n_channels(sigrenderer);
+
+    /* This restriction is imposed by Allegro. */
+    ASSERT(n_channels > 0);
+    ASSERT(n_channels <= 2);
+
+    dp->flags = ADP_PLAYING;
+    dp->bufsize = bufsize;
+    dp->freq = freq;
+
+    dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128);
+
+    if (!dp->stream) {
+        free(dp);
+        return NULL;
+    }
+
+    voice_set_priority(dp->stream->voice, 255);
+
+    dp->sigrenderer = sigrenderer;
+
+    dp->volume = volume;
+    dp->silentcount = 0;
+
+    return dp;
+}
+
+DUH_SIGRENDERER *al_duh_get_sigrenderer(AL_DUH_PLAYER *dp) {
+    return dp ? dp->sigrenderer : NULL;
+}
+
+/* IMPORTANT: This function will return NULL if the music has ended. */
+// Should this be changed? User might want to hack the underlying SIGRENDERER
+// and resurrect it (e.g. change pattern number), before it gets destroyed...
+DUH_SIGRENDERER *al_duh_decompose_to_sigrenderer(AL_DUH_PLAYER *dp) {
+    if (dp) {
+        DUH_SIGRENDERER *sigrenderer = dp->sigrenderer;
+        if (sigrenderer)
+            stop_audio_stream(dp->stream);
+        free(dp);
+        return sigrenderer;
+    }
+    return NULL;
+}
--- /dev/null
+++ b/src/allegro/datduh.c
@@ -1,0 +1,50 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datduh.c - Integration with Allegro's              / / \  \
+ *            datafiles.                             | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_duh(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = read_duh(df);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_duh(): tells Allegro about the DUH datafile object. If
+ * you intend to load a datafile containing a DUH object, you must call this
+ * function first. It is recommended you pass DAT_DUH, but you may have a
+ * reason to use a different type (apart from pride, that doesn't count).
+ */
+void dumb_register_dat_duh(long type) {
+    register_datafile_object(type, &dat_read_duh, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/datit.c
@@ -1,0 +1,51 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datit.c - Integration of IT files with             / / \  \
+ *           Allegro's datafiles.                    | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_it(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_it(df);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_it(): tells Allegro about the IT datafile object. If you
+ * intend to load a datafile containing an IT object, you must call this
+ * function first. It is recommended you pass DUMB_DAT_IT, but you may have a
+ * reason to use a different type (perhaps you already have a datafile with
+ * IT files in and they use a different type).
+ */
+void dumb_register_dat_it(long type) {
+    register_datafile_object(type, &dat_read_it, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/datitq.c
@@ -1,0 +1,54 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datitq.c - Integration of IT files with            / / \  \
+ *            Allegro's datafiles.                   | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_it_quick(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_it_quick(df);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_it_quick(): tells Allegro about the IT datafile object.
+ * If you intend to load a datafile containing an IT object, you must call
+ * this function first. It is recommended you pass DUMB_DAT_IT, but you may
+ * have a reason to use a different type (perhaps you already have a datafile
+ * with IT files in and they use a different type).
+ *
+ * This installs the quick loader: the song length and fast seek points are
+ * not calculated.
+ */
+void dumb_register_dat_it_quick(long type) {
+    register_datafile_object(type, &dat_read_it_quick, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/datmod.c
@@ -1,0 +1,51 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datmod.c - Integration of MOD files with           / / \  \
+ *            Allegro's datafiles.                   | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_mod(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_mod(df, 2);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_mod(): tells Allegro about the MOD datafile object. If
+ * you intend to load a datafile containing a MOD object, you must call this
+ * function first. It is recommended you pass DUMB_DAT_MOD, but you may have
+ * a reason to use a different type (perhaps you already have a datafile with
+ * MOD files in and they use a different type).
+ */
+void dumb_register_dat_mod(long type) {
+    register_datafile_object(type, &dat_read_mod, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/datmodq.c
@@ -1,0 +1,54 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datmodq.c - Integration of MOD files with          / / \  \
+ *             Allegro's datafiles.                  | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_mod_quick(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_mod_quick(df, 2);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_mod_quick(): tells Allegro about the MOD datafile object.
+ * If you intend to load a datafile containing a MOD object, you must call this
+ * function first. It is recommended you pass DUMB_DAT_MOD, but you may have
+ * a reason to use a different type (perhaps you already have a datafile with
+ * MOD files in and they use a different type).
+ *
+ * This installs the quick loader: the song length and fast seek points are
+ * not calculated.
+ */
+void dumb_register_dat_mod_quick(long type) {
+    register_datafile_object(type, &dat_read_mod_quick, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/dats3m.c
@@ -1,0 +1,51 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * dats3m.c - Integration of S3M files with           / / \  \
+ *            Allegro's datafiles.                   | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_s3m(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_s3m(df);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_s3m(): tells Allegro about the S3M datafile object. If
+ * you intend to load a datafile containing an S3M object, you must call this
+ * function first. It is recommended you pass DUMB_DAT_S3M, but you may have
+ * a reason to use a different type (perhaps you already have a datafile with
+ * S3M files in and they use a different type).
+ */
+void dumb_register_dat_s3m(long type) {
+    register_datafile_object(type, &dat_read_s3m, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/dats3mq.c
@@ -1,0 +1,54 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * dats3mq.c - Integration of S3M files with          / / \  \
+ *             Allegro's datafiles.                  | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_s3m_quick(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_s3m_quick(df);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_s3m_quick(): tells Allegro about the S3M datafile object.
+ * If you intend to load a datafile containing an S3M object, you must call this
+ * function first. It is recommended you pass DUMB_DAT_S3M, but you may have
+ * a reason to use a different type (perhaps you already have a datafile with
+ * S3M files in and they use a different type).
+ *
+ * This installs the quick loader: the song length and fast seek points are
+ * not calculated.
+ */
+void dumb_register_dat_s3m_quick(long type) {
+    register_datafile_object(type, &dat_read_s3m_quick, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/datunld.c
@@ -1,0 +1,25 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datunld.c - Unload function for integration        / / \  \
+ *             with Allegro's datafiles.             | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+void _dat_unload_duh(void *duh) { unload_duh(duh); }
--- /dev/null
+++ b/src/allegro/datxm.c
@@ -1,0 +1,51 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datxm.c - Integration of XM files with             / / \  \
+ *           Allegro's datafiles.                    | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_xm(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_xm(df);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_xm(): tells Allegro about the XM datafile object. If you
+ * intend to load a datafile containing an XM object, you must call this
+ * function first. It is recommended you pass DUMB_DAT_XM, but you may have a
+ * reason to use a different type (perhaps you already have a datafile with
+ * XM files in and they use a different type).
+ */
+void dumb_register_dat_xm(long type) {
+    register_datafile_object(type, &dat_read_xm, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/datxmq.c
@@ -1,0 +1,54 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * datxmq.c - Integration of XM files with            / / \  \
+ *            Allegro's datafiles.                   | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+#include "internal/aldumb.h"
+
+static void *dat_read_xm_quick(PACKFILE *f, long size) {
+    DUMBFILE *df;
+    DUH *duh;
+
+    (void)size;
+
+    df = dumbfile_open_packfile(f);
+
+    if (!df)
+        return NULL;
+
+    duh = dumb_read_xm_quick(df);
+
+    dumbfile_close(df);
+
+    return duh;
+}
+
+/* dumb_register_dat_xm_quick(): tells Allegro about the XM datafile object.
+ * If you intend to load a datafile containing an XM object, you must call this
+ * function first. It is recommended you pass DUMB_DAT_XM, but you may have a
+ * reason to use a different type (perhaps you already have a datafile with
+ * XM files in and they use a different type).
+ *
+ * This installs the quick loader: the song length and fast seek points are
+ * not calculated.
+ */
+void dumb_register_dat_xm_quick(long type) {
+    register_datafile_object(type, &dat_read_xm_quick, &_dat_unload_duh);
+}
--- /dev/null
+++ b/src/allegro/packfile.c
@@ -1,0 +1,119 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * packfile.c - Packfile input module.                / / \  \
+ *                                                   | <  /   \_
+ * By entheh.                                        |  \/ /\   /
+ *                                                    \_  /  > /
+ * Note that this does not use file compression;        | \ / /
+ * for that you must open the file yourself and         |  ' /
+ * then use dumbfile_open_packfile().                    \__/
+ */
+
+#include <allegro.h>
+
+#include "aldumb.h"
+
+typedef struct dumb_packfile {
+    PACKFILE *p;
+    long size;
+    long pos;
+} dumb_packfile;
+
+static void *dumb_packfile_open_ex(PACKFILE *p, long size) {
+    dumb_packfile *file = (dumb_packfile *)malloc(sizeof(dumb_packfile));
+    if (!file)
+        return 0;
+    file->p = p;
+    file->size = size;
+    file->pos = 0;
+    return file;
+}
+
+static void *dumb_packfile_open(const char *filename) {
+    PACKFILE *p = pack_fopen(filename, F_READ);
+    if (p)
+        return dumb_packfile_open_ex(p, file_size_ex(filename));
+    else
+        return 0;
+}
+
+static int dumb_packfile_skip(void *f, dumb_off_t n) {
+    dumb_packfile *file = (dumb_packfile *)f;
+    file->pos += n;
+    return pack_fseek(file->p, file->pos);
+}
+
+static int dumb_packfile_getc(void *f) {
+    dumb_packfile *file = (dumb_packfile *)f;
+    int c = pack_getc(file->p);
+    if (c != EOF)
+        file->pos++;
+    return c;
+}
+
+static dumb_ssize_t dumb_packfile_getnc(char *ptr, size_t n, void *f) {
+    dumb_packfile *file = (dumb_packfile *)f;
+    errno = 0;
+    long nr = pack_fread(ptr, n, file->p);
+    if (nr > 0) {
+        file->pos += nr;
+        return nr;
+    }
+    return errno != 0 ? -1 : 0;
+}
+
+static void dumb_packfile_close(void *f) {
+    dumb_packfile *file = (dumb_packfile *)f;
+    pack_fclose(file->p);
+    free(f);
+}
+
+static void dumb_packfile_noclose(void *f) { free(f); }
+
+static int dumb_packfile_seek(void *f, dumb_off_t n) {
+    dumb_packfile *file = (dumb_packfile *)f;
+    file->pos = n;
+    return pack_fseek(file->p, n);
+}
+
+static dumb_off_t dumb_packfile_get_size(void *f) {
+    dumb_packfile *file = (dumb_packfile *)f;
+    return file->size;
+}
+
+static DUMBFILE_SYSTEM packfile_dfs = {
+    &dumb_packfile_open,    &dumb_packfile_skip,  &dumb_packfile_getc,
+    &dumb_packfile_getnc,   &dumb_packfile_close, &dumb_packfile_seek,
+    &dumb_packfile_get_size};
+
+void dumb_register_packfiles(void) { register_dumbfile_system(&packfile_dfs); }
+
+static DUMBFILE_SYSTEM packfile_dfs_leave_open = {NULL,
+                                                  &dumb_packfile_skip,
+                                                  &dumb_packfile_getc,
+                                                  &dumb_packfile_getnc,
+                                                  &dumb_packfile_noclose,
+                                                  &dumb_packfile_seek,
+                                                  &dumb_packfile_get_size};
+
+/* XXX no way to get the file size from an existing PACKFILE without reading the
+ * entire contents first */
+
+DUMBFILE *dumbfile_open_packfile(PACKFILE *p) {
+    return dumbfile_open_ex(dumb_packfile_open_ex(p, 0x7fffffff),
+                            &packfile_dfs_leave_open);
+}
+
+DUMBFILE *dumbfile_from_packfile(PACKFILE *p) {
+    return p ? dumbfile_open_ex(dumb_packfile_open_ex(p, 0x7fffffff),
+                                &packfile_dfs)
+             : NULL;
+}
--- /dev/null
+++ b/src/core/atexit.c
@@ -1,0 +1,60 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * atexit.c - Library Clean-up Management.            / / \  \
+ *                                                   | <  /   \_
+ * By entheh.                                        |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+typedef struct DUMB_ATEXIT_PROC {
+    struct DUMB_ATEXIT_PROC *next;
+    void (*proc)(void);
+} DUMB_ATEXIT_PROC;
+
+static DUMB_ATEXIT_PROC *dumb_atexit_proc = NULL;
+
+int dumb_atexit(void (*proc)(void)) {
+    DUMB_ATEXIT_PROC *dap = dumb_atexit_proc;
+
+    while (dap) {
+        if (dap->proc == proc)
+            return 0;
+        dap = dap->next;
+    }
+
+    dap = malloc(sizeof(*dap));
+
+    if (!dap)
+        return -1;
+
+    dap->next = dumb_atexit_proc;
+    dap->proc = proc;
+    dumb_atexit_proc = dap;
+
+    return 0;
+}
+
+void dumb_exit(void) {
+    while (dumb_atexit_proc) {
+        DUMB_ATEXIT_PROC *next = dumb_atexit_proc->next;
+        (*dumb_atexit_proc->proc)();
+        free(dumb_atexit_proc);
+        dumb_atexit_proc = next;
+    }
+}
--- /dev/null
+++ b/src/core/duhlen.c
@@ -1,0 +1,34 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * duhlen.c - Functions to set and return the         / / \  \
+ *            length of a DUH.                       | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ * Note that the length of a DUH is a constant          |  ' /
+ * stored in the DUH struct and in the DUH disk          \__/
+ * format. It will be calculated on loading for
+ * other formats in which the length is not explicitly stored. Also note that
+ * it does not necessarily correspond to the length of time for which the DUH
+ * will generate samples. Rather it represents a suitable point for a player
+ * such as Winamp to stop, and in any good DUH it will allow for any final
+ * flourish to fade out and be appreciated.
+ */
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+dumb_off_t duh_get_length(DUH *duh) { return duh ? duh->length : 0; }
+
+void duh_set_length(DUH *duh, dumb_off_t length) {
+    if (duh)
+        duh->length = length;
+}
--- /dev/null
+++ b/src/core/duhtag.c
@@ -1,0 +1,53 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * duhtag.c - Function to return the tags stored      / / \  \
+ *            in a DUH struct (typically author      | <  /   \_
+ *            information).                          |  \/ /\   /
+ *                                                    \_  /  > /
+ * By entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+const char *duh_get_tag(DUH *duh, const char *key) {
+    int i;
+    ASSERT(key);
+    if (!duh || !duh->tag)
+        return NULL;
+
+    for (i = 0; i < duh->n_tags; i++)
+        if (strcmp(key, duh->tag[i][0]) == 0)
+            return duh->tag[i][1];
+
+    return NULL;
+}
+
+int duh_get_tag_iterator_size(DUH *duh) {
+    return (duh && duh->tag ? duh->n_tags : 0);
+}
+
+int duh_get_tag_iterator_get(DUH *duh, const char **key, const char **tag,
+                             int i) {
+    ASSERT(key);
+    ASSERT(tag);
+    if (!duh || !duh->tag || i >= duh->n_tags)
+        return -1;
+
+    *key = duh->tag[i][0];
+    *tag = duh->tag[i][1];
+
+    return 0;
+}
--- /dev/null
+++ b/src/core/dumbfile.c
@@ -1,0 +1,373 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * dumbfile.c - Hookable, strictly sequential         / / \  \
+ *              file input functions.                | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+static const DUMBFILE_SYSTEM *the_dfs = NULL;
+
+void register_dumbfile_system(const DUMBFILE_SYSTEM *dfs) {
+    ASSERT(dfs);
+    ASSERT(dfs->open);
+    ASSERT(dfs->getc);
+    ASSERT(dfs->close);
+    ASSERT(dfs->seek);
+    ASSERT(dfs->get_size);
+    the_dfs = dfs;
+}
+
+#include "internal/dumbfile.h"
+
+DUMBFILE *dumbfile_open(const char *filename) {
+    DUMBFILE *f;
+
+    ASSERT(the_dfs);
+
+    f = (DUMBFILE *)malloc(sizeof(*f));
+
+    if (!f)
+        return NULL;
+
+    f->dfs = the_dfs;
+
+    f->file = (*the_dfs->open)(filename);
+
+    if (!f->file) {
+        free(f);
+        return NULL;
+    }
+
+    f->pos = 0;
+
+    return f;
+}
+
+DUMBFILE *dumbfile_open_ex(void *file, const DUMBFILE_SYSTEM *dfs) {
+    DUMBFILE *f;
+
+    ASSERT(dfs);
+    ASSERT(dfs->getc);
+    ASSERT(file);
+
+    f = (DUMBFILE *)malloc(sizeof(*f));
+
+    if (!f) {
+        if (dfs->close)
+            (*dfs->close)(file);
+        return NULL;
+    }
+
+    f->dfs = dfs;
+    f->file = file;
+
+    f->pos = 0;
+
+    return f;
+}
+
+dumb_off_t dumbfile_pos(DUMBFILE *f) {
+    ASSERT(f);
+
+    return f->pos;
+}
+
+/* Move forward in the file from the current position by n bytes. */
+int dumbfile_skip(DUMBFILE *f, dumb_off_t n) {
+    int rv;
+
+    ASSERT(f);
+    ASSERT(n >= 0);
+
+    if (f->pos < 0)
+        return -1;
+
+    f->pos += n;
+
+    if (f->dfs->skip) {
+        rv = (*f->dfs->skip)(f->file, n);
+        if (rv) {
+            f->pos = -1;
+            return rv;
+        }
+    } else {
+        while (n) {
+            rv = (*f->dfs->getc)(f->file);
+            if (rv < 0) {
+                f->pos = -1;
+                return rv;
+            }
+            n--;
+        }
+    }
+
+    return 0;
+}
+
+int dumbfile_getc(DUMBFILE *f) {
+    int rv;
+
+    ASSERT(f);
+
+    if (f->pos < 0)
+        return -1;
+
+    rv = (*f->dfs->getc)(f->file);
+
+    if (rv < 0) {
+        f->pos = -1;
+        return rv;
+    }
+
+    f->pos++;
+
+    return rv;
+}
+
+int dumbfile_igetw(DUMBFILE *f) {
+    int l, h;
+
+    ASSERT(f);
+
+    if (f->pos < 0)
+        return -1;
+
+    l = (*f->dfs->getc)(f->file);
+    if (l < 0) {
+        f->pos = -1;
+        return l;
+    }
+
+    h = (*f->dfs->getc)(f->file);
+    if (h < 0) {
+        f->pos = -1;
+        return h;
+    }
+
+    f->pos += 2;
+
+    return l | (h << 8);
+}
+
+int dumbfile_mgetw(DUMBFILE *f) {
+    int l, h;
+
+    ASSERT(f);
+
+    if (f->pos < 0)
+        return -1;
+
+    h = (*f->dfs->getc)(f->file);
+    if (h < 0) {
+        f->pos = -1;
+        return h;
+    }
+
+    l = (*f->dfs->getc)(f->file);
+    if (l < 0) {
+        f->pos = -1;
+        return l;
+    }
+
+    f->pos += 2;
+
+    return l | (h << 8);
+}
+
+long dumbfile_igetl(DUMBFILE *f) {
+    unsigned long rv, b;
+
+    ASSERT(f);
+
+    if (f->pos < 0)
+        return -1;
+
+    rv = (*f->dfs->getc)(f->file);
+    if ((signed long)rv < 0) {
+        f->pos = -1;
+        return rv;
+    }
+
+    b = (*f->dfs->getc)(f->file);
+    if ((signed long)b < 0) {
+        f->pos = -1;
+        return b;
+    }
+    rv |= b << 8;
+
+    b = (*f->dfs->getc)(f->file);
+    if ((signed long)b < 0) {
+        f->pos = -1;
+        return b;
+    }
+    rv |= b << 16;
+
+    b = (*f->dfs->getc)(f->file);
+    if ((signed long)b < 0) {
+        f->pos = -1;
+        return b;
+    }
+    rv |= b << 24;
+
+    f->pos += 4;
+
+    return rv;
+}
+
+long dumbfile_mgetl(DUMBFILE *f) {
+    unsigned long rv, b;
+
+    ASSERT(f);
+
+    if (f->pos < 0)
+        return -1;
+
+    rv = (*f->dfs->getc)(f->file);
+    if ((signed long)rv < 0) {
+        f->pos = -1;
+        return rv;
+    }
+    rv <<= 24;
+
+    b = (*f->dfs->getc)(f->file);
+    if ((signed long)b < 0) {
+        f->pos = -1;
+        return b;
+    }
+    rv |= b << 16;
+
+    b = (*f->dfs->getc)(f->file);
+    if ((signed long)b < 0) {
+        f->pos = -1;
+        return b;
+    }
+    rv |= b << 8;
+
+    b = (*f->dfs->getc)(f->file);
+    if ((signed long)b < 0) {
+        f->pos = -1;
+        return b;
+    }
+    rv |= b;
+
+    f->pos += 4;
+
+    return rv;
+}
+
+unsigned long dumbfile_cgetul(DUMBFILE *f) {
+    unsigned long rv = 0;
+    int v;
+
+    do {
+        v = dumbfile_getc(f);
+
+        if (v < 0)
+            return v;
+
+        rv <<= 7;
+        rv |= v & 0x7F;
+    } while (v & 0x80);
+
+    return rv;
+}
+
+signed long dumbfile_cgetsl(DUMBFILE *f) {
+    unsigned long rv = dumbfile_cgetul(f);
+
+    if (f->pos < 0)
+        return rv;
+
+    return (rv >> 1) | (rv << 31);
+}
+
+dumb_ssize_t dumbfile_getnc(char *ptr, size_t n, DUMBFILE *f) {
+    dumb_ssize_t rv;
+
+    ASSERT(f);
+    ASSERT(n >= 0);
+
+    if (f->pos < 0)
+        return -1;
+
+    if (f->dfs->getnc) {
+        rv = (*f->dfs->getnc)(ptr, n, f->file);
+        if (rv < (dumb_ssize_t)n) {
+            f->pos = -1;
+            return MAX(rv, 0);
+        }
+    } else {
+        for (rv = 0; rv < (dumb_ssize_t)n; rv++) {
+            int c = (*f->dfs->getc)(f->file);
+            if (c < 0) {
+                f->pos = -1;
+                return rv;
+            }
+            *ptr++ = c;
+        }
+    }
+
+    f->pos += rv;
+
+    return rv;
+}
+
+/* Move to an arbitrary position n in the file, specified relative to origin,
+ * where origin shall be one of the DFS_SEEK_* constants.
+ */
+int dumbfile_seek(DUMBFILE *f, dumb_off_t n, int origin) {
+    switch (origin) {
+    case DFS_SEEK_CUR:
+        n += f->pos;
+        break;
+    case DFS_SEEK_END:
+        n += (*f->dfs->get_size)(f->file);
+        break;
+    default:
+        break; /* keep n, seek position from beginning of file */
+    }
+    f->pos = n;
+    return (*f->dfs->seek)(f->file, n);
+}
+
+dumb_off_t dumbfile_get_size(DUMBFILE *f) {
+    return (*f->dfs->get_size)(f->file);
+}
+
+int dumbfile_error(DUMBFILE *f) {
+    ASSERT(f);
+
+    return f->pos < 0;
+}
+
+int dumbfile_close(DUMBFILE *f) {
+    int rv;
+
+    ASSERT(f);
+
+    rv = f->pos < 0;
+
+    if (f->dfs->close)
+        (*f->dfs->close)(f->file);
+
+    free(f);
+
+    return rv;
+}
--- /dev/null
+++ b/src/core/loadduh.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadduh.c - Code to read a DUH from a file,        / / \  \
+ *             opening and closing the file for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+/* load_duh(): loads a .duh file, returning a pointer to a DUH struct.
+ * When you have finished with it, you must pass the pointer to unload_duh()
+ * so that the memory can be freed.
+ */
+DUH *load_duh(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = read_duh(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/core/makeduh.c
@@ -1,0 +1,146 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * makeduh.c - Function to construct a DUH from       / / \  \
+ *             its components.                       | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+static DUH_SIGNAL *make_signal(DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata) {
+    DUH_SIGNAL *signal;
+
+    ASSERT((desc->start_sigrenderer && desc->end_sigrenderer) ||
+           (!desc->start_sigrenderer && !desc->end_sigrenderer));
+    ASSERT(desc->sigrenderer_generate_samples &&
+           desc->sigrenderer_get_current_sample);
+
+    signal = malloc(sizeof(*signal));
+
+    if (!signal) {
+        if (desc->unload_sigdata)
+            if (sigdata)
+                (*desc->unload_sigdata)(sigdata);
+        return NULL;
+    }
+
+    signal->desc = desc;
+    signal->sigdata = sigdata;
+
+    return signal;
+}
+
+DUH *make_duh(dumb_off_t length, int n_tags, const char *const tags[][2],
+              int n_signals, DUH_SIGTYPE_DESC *desc[], sigdata_t *sigdata[]) {
+    DUH *duh = malloc(sizeof(*duh));
+    int i;
+    int fail;
+
+    if (duh) {
+        duh->n_signals = n_signals;
+
+        duh->signal = malloc(n_signals * sizeof(*duh->signal));
+
+        if (!duh->signal) {
+            free(duh);
+            duh = NULL;
+        }
+    }
+
+    if (!duh) {
+        for (i = 0; i < n_signals; i++)
+            if (desc[i]->unload_sigdata)
+                if (sigdata[i])
+                    (*desc[i]->unload_sigdata)(sigdata[i]);
+        return NULL;
+    }
+
+    duh->n_tags = 0;
+    duh->tag = NULL;
+
+    fail = 0;
+
+    for (i = 0; i < n_signals; i++) {
+        duh->signal[i] = make_signal(desc[i], sigdata[i]);
+        if (!duh->signal[i])
+            fail = 1;
+    }
+
+    if (fail) {
+        unload_duh(duh);
+        return NULL;
+    }
+
+    duh->length = length;
+
+    {
+        int mem = n_tags * 2; /* account for NUL terminators here */
+        char *ptr;
+
+        for (i = 0; i < n_tags; i++)
+            mem += strlen(tags[i][0]) + strlen(tags[i][1]);
+
+        if (mem <= 0)
+            return duh;
+
+        duh->tag = malloc(n_tags * sizeof(*duh->tag));
+        if (!duh->tag)
+            return duh;
+        duh->tag[0][0] = malloc(mem);
+        if (!duh->tag[0][0]) {
+            free(duh->tag);
+            duh->tag = NULL;
+            return duh;
+        }
+        duh->n_tags = n_tags;
+        ptr = duh->tag[0][0];
+        for (i = 0; i < n_tags; i++) {
+            duh->tag[i][0] = ptr;
+            strcpy(ptr, tags[i][0]);
+            ptr += strlen(tags[i][0]) + 1;
+            duh->tag[i][1] = ptr;
+            strcpy(ptr, tags[i][1]);
+            ptr += strlen(tags[i][1]) + 1;
+        }
+    }
+
+    return duh;
+}
+
+int duh_add_signal(DUH *duh, DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata) {
+    DUH_SIGNAL **signal;
+
+    if (!duh || !desc || !sigdata)
+        return -1;
+
+    signal = (DUH_SIGNAL **)realloc(duh->signal, (duh->n_signals + 1) *
+                                                     sizeof(*duh->signal));
+    if (!signal)
+        return -1;
+    duh->signal = signal;
+
+    memmove(signal + 1, signal, duh->n_signals * sizeof(*signal));
+    duh->n_signals++;
+
+    signal[0] = make_signal(desc, sigdata);
+    if (!signal[0])
+        return -1;
+
+    return 0;
+}
--- /dev/null
+++ b/src/core/rawsig.c
@@ -1,0 +1,53 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * rawsig.c - Function to retrieve raw signal         / / \  \
+ *            data from a DUH provided you know      | <  /   \_
+ *            what type of signal it is.             |  \/ /\   /
+ *                                                    \_  /  > /
+ * By entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+/* You have to specify the type of sigdata, proving you know what to do with
+ * the pointer. If you get it wrong, you can expect NULL back.
+ */
+sigdata_t *duh_get_raw_sigdata(DUH *duh, int sig, long type) {
+    int i;
+    DUH_SIGNAL *signal;
+
+    if (!duh)
+        return NULL;
+
+    if (sig >= 0) {
+        if ((unsigned int)sig >= (unsigned int)duh->n_signals)
+            return NULL;
+
+        signal = duh->signal[sig];
+
+        if (signal && signal->desc->type == type)
+            return signal->sigdata;
+    } else {
+        for (i = 0; i < duh->n_signals; i++) {
+            signal = duh->signal[i];
+
+            if (signal && signal->desc->type == type)
+                return signal->sigdata;
+        }
+    }
+
+    return NULL;
+}
--- /dev/null
+++ b/src/core/readduh.c
@@ -1,0 +1,101 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readduh.c - Code to read a DUH from an open        / / \  \
+ *             file.                                 | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+static DUH_SIGNAL *read_signal(DUH *duh, DUMBFILE *f) {
+    DUH_SIGNAL *signal;
+    long type;
+
+    signal = malloc(sizeof(*signal));
+
+    if (!signal)
+        return NULL;
+
+    type = dumbfile_mgetl(f);
+    if (dumbfile_error(f)) {
+        free(signal);
+        return NULL;
+    }
+
+    signal->desc = _dumb_get_sigtype_desc(type);
+    if (!signal->desc) {
+        free(signal);
+        return NULL;
+    }
+
+    if (signal->desc->load_sigdata) {
+        signal->sigdata = (*signal->desc->load_sigdata)(duh, f);
+        if (!signal->sigdata) {
+            free(signal);
+            return NULL;
+        }
+    } else
+        signal->sigdata = NULL;
+
+    return signal;
+}
+
+/* read_duh(): reads a DUH from an already open DUMBFILE, and returns its
+ * pointer, or null on error. The file is not closed.
+ */
+DUH *read_duh(DUMBFILE *f) {
+    DUH *duh;
+    int i;
+
+    if (dumbfile_mgetl(f) != DUH_SIGNATURE)
+        return NULL;
+
+    duh = malloc(sizeof(*duh));
+    if (!duh)
+        return NULL;
+
+    duh->length = dumbfile_igetl(f);
+    if (dumbfile_error(f) || duh->length <= 0) {
+        free(duh);
+        return NULL;
+    }
+
+    duh->n_signals = (int)dumbfile_igetl(f);
+    if (dumbfile_error(f) || duh->n_signals <= 0) {
+        free(duh);
+        return NULL;
+    }
+
+    duh->signal = malloc(sizeof(*duh->signal) * duh->n_signals);
+    if (!duh->signal) {
+        free(duh);
+        return NULL;
+    }
+
+    for (i = 0; i < duh->n_signals; i++)
+        duh->signal[i] = NULL;
+
+    for (i = 0; i < duh->n_signals; i++) {
+        if (!(duh->signal[i] = read_signal(duh, f))) {
+            unload_duh(duh);
+            return NULL;
+        }
+    }
+
+    return duh;
+}
--- /dev/null
+++ b/src/core/register.c
@@ -1,0 +1,96 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * register.c - Signal type registration.             / / \  \
+ *                                                   | <  /   \_
+ * By entheh.                                        |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+static DUH_SIGTYPE_DESC_LINK *sigtype_desc = NULL;
+static DUH_SIGTYPE_DESC_LINK **sigtype_desc_tail = &sigtype_desc;
+
+/* destroy_sigtypes(): frees all memory allocated while registering signal
+ * types. This function is set up to be called by dumb_exit().
+ */
+static void destroy_sigtypes(void) {
+    DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc, *next;
+    sigtype_desc = NULL;
+    sigtype_desc_tail = &sigtype_desc;
+
+    while (desc_link) {
+        next = desc_link->next;
+        free(desc_link);
+        desc_link = next;
+    }
+}
+
+/* dumb_register_sigtype(): registers a new signal type with DUMB. The signal
+ * type is identified by a four-character string (e.g. "WAVE"), which you can
+ * encode using the the DUMB_ID() macro (e.g. DUMB_ID('W','A','V','E')). The
+ * signal's behaviour is defined by four functions, whose pointers you pass
+ * here. See the documentation for details.
+ *
+ * If a DUH tries to use a signal that has not been registered using this
+ * function, then the library will fail to load the DUH.
+ */
+void dumb_register_sigtype(DUH_SIGTYPE_DESC *desc) {
+    DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc;
+
+    ASSERT((desc->load_sigdata && desc->unload_sigdata) ||
+           (!desc->load_sigdata && !desc->unload_sigdata));
+    ASSERT((desc->start_sigrenderer && desc->end_sigrenderer) ||
+           (!desc->start_sigrenderer && !desc->end_sigrenderer));
+    ASSERT(desc->sigrenderer_generate_samples &&
+           desc->sigrenderer_get_current_sample);
+
+    if (desc_link) {
+        do {
+            if (desc_link->desc->type == desc->type) {
+                desc_link->desc = desc;
+                return;
+            }
+            desc_link = desc_link->next;
+        } while (desc_link);
+    } else
+        dumb_atexit(&destroy_sigtypes);
+
+    desc_link = *sigtype_desc_tail = malloc(sizeof(DUH_SIGTYPE_DESC_LINK));
+
+    if (!desc_link)
+        return;
+
+    desc_link->next = NULL;
+    sigtype_desc_tail = &desc_link->next;
+
+    desc_link->desc = desc;
+}
+
+/* _dumb_get_sigtype_desc(): searches the registered functions for a signal
+ * type matching the parameter. If such a sigtype is found, it returns a
+ * pointer to a sigtype descriptor containing the necessary functions to
+ * manage the signal. If none is found, it returns NULL.
+ */
+DUH_SIGTYPE_DESC *_dumb_get_sigtype_desc(long type) {
+    DUH_SIGTYPE_DESC_LINK *desc_link = sigtype_desc;
+
+    while (desc_link && desc_link->desc->type != type)
+        desc_link = desc_link->next;
+
+    return desc_link ? desc_link->desc : NULL;
+}
--- /dev/null
+++ b/src/core/rendduh.c
@@ -1,0 +1,261 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * rendduh.c - Functions for rendering a DUH into     / / \  \
+ *             an end-user sample format.            | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <limits.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+/* On the x86, we can use some tricks to speed stuff up */
+#if (defined _MSC_VER) || (defined __DJGPP__) || (defined __MINGW__)
+// Can't we detect Linux and other x86 platforms here? :/
+
+#define FAST_MID(var, min, max)                                                \
+    {                                                                          \
+        var -= (min);                                                          \
+        var &= (~var) >> (sizeof(var) * CHAR_BIT - 1);                         \
+        var += (min);                                                          \
+        var -= (max);                                                          \
+        var &= var >> (sizeof(var) * CHAR_BIT - 1);                            \
+        var += (max);                                                          \
+    }
+
+#define CONVERT8(src, pos, signconv)                                           \
+    {                                                                          \
+        signed int f = (src + 0x8000) >> 16;                                   \
+        FAST_MID(f, -128, 127);                                                \
+        ((char *)sptr)[pos] = (char)f ^ signconv;                              \
+    }
+
+#define CONVERT16(src, pos, signconv)                                          \
+    {                                                                          \
+        signed int f = (src + 0x80) >> 8;                                      \
+        FAST_MID(f, -32768, 32767);                                            \
+        ((short *)sptr)[pos] = (short)(f ^ signconv);                          \
+    }
+
+#else
+
+#define CONVERT8(src, pos, signconv)                                           \
+    {                                                                          \
+        signed int f = (src + 0x8000) >> 16;                                   \
+        f = MID(-128, f, 127);                                                 \
+        ((char *)sptr)[pos] = (char)f ^ signconv;                              \
+    }
+
+#define CONVERT16(src, pos, signconv)                                          \
+    {                                                                          \
+        signed int f = (src + 0x80) >> 8;                                      \
+        f = MID(-32768, f, 32767);                                             \
+        ((short *)sptr)[pos] = (short)(f ^ signconv);                          \
+    }
+
+#endif
+
+#define CONVERT24(src, pos)                                                    \
+    {                                                                          \
+        signed int f = src;                                                    \
+        f = MID(-8388608, f, 8388607);                                         \
+        ((unsigned char *)sptr)[pos] = (f)&0xFF;                               \
+        ((unsigned char *)sptr)[pos + 1] = (f >> 8) & 0xFF;                    \
+        ((unsigned char *)sptr)[pos + 2] = (f >> 16) & 0xFF;                   \
+    }
+
+#define CONVERT32F(src, pos)                                                   \
+    {                                                                          \
+        ((float *)sptr)[pos] =                                                 \
+            (float)((signed int)src) * (1.0f / (float)(0xffffff / 2 + 1));     \
+    }
+
+#define CONVERT64F(src, pos)                                                   \
+    {                                                                          \
+        ((double *)sptr)[pos] =                                                \
+            (double)((signed int)src) * (1.0 / (double)(0xffffff / 2 + 1));    \
+    }
+
+/* This is the only deprecated function in 2.0.0. */
+/* DEPRECATED */
+long duh_render(DUH_SIGRENDERER *sigrenderer, int bits, int unsign,
+                float volume, float delta, long size, void *sptr) {
+    long n;
+
+    sample_t **sampptr;
+
+    int n_channels;
+
+    ASSERT(bits == 8 || bits == 16);
+    ASSERT(sptr);
+
+    if (!sigrenderer)
+        return 0;
+
+    n_channels = duh_sigrenderer_get_n_channels(sigrenderer);
+
+    ASSERT(n_channels > 0);
+    /* This restriction will be removed when need be. At the moment, tightly
+     * optimised loops exist for exactly one or two channels.
+     */
+    ASSERT(n_channels <= 2);
+
+    sampptr = allocate_sample_buffer(n_channels, size);
+
+    if (!sampptr)
+        return 0;
+
+    dumb_silence(sampptr[0], n_channels * size);
+
+    size = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size,
+                                            sampptr);
+
+    if (bits == 16) {
+        int signconv = unsign ? 0x8000 : 0x0000;
+
+        for (n = 0; n < size * n_channels; n++) {
+            CONVERT16(sampptr[0][n], n, signconv);
+        }
+    } else {
+        char signconv = unsign ? 0x80 : 0x00;
+
+        for (n = 0; n < size * n_channels; n++) {
+            CONVERT8(sampptr[0][n], n, signconv);
+        }
+    }
+
+    destroy_sample_buffer(sampptr);
+
+    return size;
+}
+
+long duh_render_int(DUH_SIGRENDERER *sigrenderer, sample_t ***sig_samples,
+                    long *sig_samples_size, int bits, int unsign, float volume,
+                    float delta, long size, void *sptr) {
+    long n;
+
+    sample_t **sampptr;
+
+    int n_channels;
+
+    ASSERT(bits == 8 || bits == 16 || bits == 24);
+    ASSERT(sptr);
+    ASSERT(sig_samples);
+    ASSERT(sig_samples_size);
+
+    if (!sigrenderer)
+        return 0;
+
+    n_channels = duh_sigrenderer_get_n_channels(sigrenderer);
+
+    ASSERT(n_channels > 0);
+    /* This restriction will be removed when need be. At the moment, tightly
+     * optimised loops exist for exactly one or two channels.
+     */
+    ASSERT(n_channels <= 2);
+
+    if ((*sig_samples == NULL) || (*sig_samples_size != size)) {
+        destroy_sample_buffer(*sig_samples);
+        *sig_samples = allocate_sample_buffer(n_channels, size);
+        *sig_samples_size = size;
+    }
+    sampptr = *sig_samples;
+
+    if (!sampptr)
+        return 0;
+
+    dumb_silence(sampptr[0], n_channels * size);
+
+    size = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size,
+                                            sampptr);
+
+    if (bits == 24) {
+        long i = 0;
+        ASSERT(unsign == 0);
+
+        for (n = 0; n < size * n_channels; n++, i += 3) {
+            CONVERT24(sampptr[0][n], i);
+        }
+    } else if (bits == 16) {
+        int signconv = unsign ? 0x8000 : 0x0000;
+
+        for (n = 0; n < size * n_channels; n++) {
+            CONVERT16(sampptr[0][n], n, signconv);
+        }
+    } else {
+        char signconv = unsign ? 0x80 : 0x00;
+
+        for (n = 0; n < size * n_channels; n++) {
+            CONVERT8(sampptr[0][n], n, signconv);
+        }
+    }
+
+    return size;
+}
+
+long duh_render_float(DUH_SIGRENDERER *sigrenderer, sample_t ***sig_samples,
+                      long *sig_samples_size, int bits, float volume,
+                      float delta, long size, void *sptr) {
+    long n;
+
+    sample_t **sampptr;
+
+    int n_channels;
+
+    ASSERT(bits == 32 || bits == 64);
+    ASSERT(sptr);
+    ASSERT(sig_samples);
+    ASSERT(sig_samples_size);
+
+    if (!sigrenderer)
+        return 0;
+
+    n_channels = duh_sigrenderer_get_n_channels(sigrenderer);
+
+    ASSERT(n_channels > 0);
+    /* This restriction will be removed when need be. At the moment, tightly
+     * optimised loops exist for exactly one or two channels.
+     */
+    ASSERT(n_channels <= 2);
+
+    if ((*sig_samples == NULL) || (*sig_samples_size != size)) {
+        destroy_sample_buffer(*sig_samples);
+        *sig_samples = allocate_sample_buffer(n_channels, size);
+        *sig_samples_size = size;
+    }
+    sampptr = *sig_samples;
+
+    if (!sampptr)
+        return 0;
+
+    dumb_silence(sampptr[0], n_channels * size);
+
+    size = duh_sigrenderer_generate_samples(sigrenderer, volume, delta, size,
+                                            sampptr);
+
+    if (bits == 64) {
+        for (n = 0; n < size * n_channels; n++) {
+            CONVERT64F(sampptr[0][n], n);
+        }
+    } else if (bits == 32) {
+        for (n = 0; n < size * n_channels; n++) {
+            CONVERT32F(sampptr[0][n], n);
+        }
+    }
+
+    return size;
+}
--- /dev/null
+++ b/src/core/rendsig.c
@@ -1,0 +1,242 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * rendsig.c - Wrappers to render samples from        / / \  \
+ *             the signals in a DUH.                 | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+struct DUH_SIGRENDERER {
+    DUH_SIGTYPE_DESC *desc;
+
+    sigrenderer_t *sigrenderer;
+
+    int n_channels;
+
+    long pos;
+    int subpos;
+
+    DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK callback;
+    void *callback_data;
+};
+
+DUH_SIGRENDERER *duh_start_sigrenderer(DUH *duh, int sig, int n_channels,
+                                       long pos) {
+    DUH_SIGRENDERER *sigrenderer;
+
+    DUH_SIGNAL *signal;
+    DUH_START_SIGRENDERER proc;
+
+    if (!duh)
+        return NULL;
+
+    if ((unsigned int)sig >= (unsigned int)duh->n_signals)
+        return NULL;
+
+    signal = duh->signal[sig];
+    if (!signal)
+        return NULL;
+
+    sigrenderer = malloc(sizeof(*sigrenderer));
+    if (!sigrenderer)
+        return NULL;
+
+    sigrenderer->desc = signal->desc;
+
+    proc = sigrenderer->desc->start_sigrenderer;
+
+    if (proc) {
+        duh->signal[sig] = NULL;
+        sigrenderer->sigrenderer =
+            (*proc)(duh, signal->sigdata, n_channels, pos);
+        duh->signal[sig] = signal;
+
+        if (!sigrenderer->sigrenderer) {
+            free(sigrenderer);
+            return NULL;
+        }
+    } else
+        sigrenderer->sigrenderer = NULL;
+
+    sigrenderer->n_channels = n_channels;
+
+    sigrenderer->pos = pos;
+    sigrenderer->subpos = 0;
+
+    sigrenderer->callback = NULL;
+
+    return sigrenderer;
+}
+
+void duh_sigrenderer_set_sample_analyser_callback(
+    DUH_SIGRENDERER *sigrenderer,
+    DUH_SIGRENDERER_SAMPLE_ANALYSER_CALLBACK callback, void *data) {
+    if (sigrenderer) {
+        sigrenderer->callback = callback;
+        sigrenderer->callback_data = data;
+    }
+}
+
+int duh_sigrenderer_get_n_channels(DUH_SIGRENDERER *sigrenderer) {
+    return sigrenderer ? sigrenderer->n_channels : 0;
+}
+
+long duh_sigrenderer_get_position(DUH_SIGRENDERER *sigrenderer) {
+    DUH_SIGRENDERER_GET_POSITION proc;
+
+    if (!sigrenderer)
+        return -1;
+
+    proc = sigrenderer->desc->sigrenderer_get_position;
+    if (proc)
+        return (*proc)(sigrenderer->sigrenderer);
+    else
+        return sigrenderer->pos;
+}
+
+void duh_sigrenderer_set_sigparam(DUH_SIGRENDERER *sigrenderer,
+                                  unsigned char id, long value) {
+    DUH_SIGRENDERER_SET_SIGPARAM proc;
+
+    if (!sigrenderer)
+        return;
+
+    proc = sigrenderer->desc->sigrenderer_set_sigparam;
+    if (proc)
+        (*proc)(sigrenderer->sigrenderer, id, value);
+    else
+        TRACE("Parameter #%d = %ld for signal %c%c%c%c, which does not take "
+              "parameters.\n",
+              (int)id, value, (int)(sigrenderer->desc->type >> 24),
+              (int)(sigrenderer->desc->type >> 16),
+              (int)(sigrenderer->desc->type >> 8),
+              (int)(sigrenderer->desc->type));
+}
+
+long duh_sigrenderer_generate_samples(DUH_SIGRENDERER *sigrenderer,
+                                      float volume, float delta, long size,
+                                      sample_t **samples) {
+    long rendered;
+    LONG_LONG t;
+
+    if (!sigrenderer)
+        return 0;
+
+    rendered = (*sigrenderer->desc->sigrenderer_generate_samples)(
+        sigrenderer->sigrenderer, volume, delta, size, samples);
+
+    if (rendered) {
+        if (sigrenderer->callback)
+            (*sigrenderer->callback)(sigrenderer->callback_data,
+                                     (const sample_t *const *)samples,
+                                     sigrenderer->n_channels, rendered);
+
+        t = sigrenderer->subpos + (LONG_LONG)(delta * 65536.0 + 0.5) * rendered;
+
+        sigrenderer->pos += (long)(t >> 16);
+        sigrenderer->subpos = (int)t & 65535;
+    }
+
+    return rendered;
+}
+
+void duh_sigrenderer_get_current_sample(DUH_SIGRENDERER *sigrenderer,
+                                        float volume, sample_t *samples) {
+    if (sigrenderer)
+        (*sigrenderer->desc->sigrenderer_get_current_sample)(
+            sigrenderer->sigrenderer, volume, samples);
+}
+
+void duh_end_sigrenderer(DUH_SIGRENDERER *sigrenderer) {
+    if (sigrenderer) {
+        if (sigrenderer->desc->end_sigrenderer)
+            if (sigrenderer->sigrenderer)
+                (*sigrenderer->desc->end_sigrenderer)(sigrenderer->sigrenderer);
+
+        free(sigrenderer);
+    }
+}
+
+DUH_SIGRENDERER *duh_encapsulate_raw_sigrenderer(sigrenderer_t *vsigrenderer,
+                                                 DUH_SIGTYPE_DESC *desc,
+                                                 int n_channels, long pos) {
+    DUH_SIGRENDERER *sigrenderer;
+
+    if (desc->start_sigrenderer && !vsigrenderer)
+        return NULL;
+
+    sigrenderer = malloc(sizeof(*sigrenderer));
+    if (!sigrenderer) {
+        if (desc->end_sigrenderer)
+            if (vsigrenderer)
+                (*desc->end_sigrenderer)(vsigrenderer);
+        return NULL;
+    }
+
+    sigrenderer->desc = desc;
+    sigrenderer->sigrenderer = vsigrenderer;
+
+    sigrenderer->n_channels = n_channels;
+
+    sigrenderer->pos = pos;
+    sigrenderer->subpos = 0;
+
+    sigrenderer->callback = NULL;
+
+    return sigrenderer;
+}
+
+sigrenderer_t *duh_get_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer,
+                                       long type) {
+    if (sigrenderer && sigrenderer->desc->type == type)
+        return sigrenderer->sigrenderer;
+
+    return NULL;
+}
+
+#if 0
+// This function is disabled because we don't know whether we want to destroy
+// the sigrenderer if the type doesn't match. We don't even know if we need
+// the function at all. Who would want to keep an IT_SIGRENDERER (for
+// instance) without keeping the DUH_SIGRENDERER?
+sigrenderer_t *duh_decompose_to_raw_sigrenderer(DUH_SIGRENDERER *sigrenderer, long type)
+{
+	if (sigrenderer && sigrenderer->desc->type == type) {
+
+
+
+	if (sigrenderer) {
+		if (sigrenderer->desc->end_sigrenderer)
+			if (sigrenderer->sigrenderer)
+				(*sigrenderer->desc->end_sigrenderer)(sigrenderer->sigrenderer);
+
+		free(sigrenderer);
+	}
+
+
+
+
+
+
+		return sigrenderer->sigrenderer;
+	}
+
+	return NULL;
+}
+#endif
--- /dev/null
+++ b/src/core/unload.c
@@ -1,0 +1,58 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * unload.c - Code to free a DUH from memory.         / / \  \
+ *                                                   | <  /   \_
+ * By entheh.                                        |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+
+static void destroy_signal(DUH_SIGNAL *signal) {
+    if (signal) {
+        if (signal->desc)
+            if (signal->desc->unload_sigdata)
+                if (signal->sigdata)
+                    (*signal->desc->unload_sigdata)(signal->sigdata);
+
+        free(signal);
+    }
+}
+
+/* unload_duh(): destroys a DUH struct. You must call this for every DUH
+ * struct created, when you've finished with it.
+ */
+void unload_duh(DUH *duh) {
+    int i;
+
+    if (duh) {
+        if (duh->signal) {
+            for (i = 0; i < duh->n_signals; i++)
+                destroy_signal(duh->signal[i]);
+
+            free(duh->signal);
+        }
+
+        if (duh->tag) {
+            if (duh->tag[0][0])
+                free(duh->tag[0][0]);
+            free(duh->tag);
+        }
+
+        free(duh);
+    }
+}
--- /dev/null
+++ b/src/helpers/barray.c
@@ -1,0 +1,155 @@
+#include "internal/barray.h"
+
+#include <string.h>
+
+void *bit_array_create(size_t size) {
+    size_t bsize = ((size + 7) >> 3) + sizeof(size_t);
+    void *ret = calloc(1, bsize);
+    if (ret)
+        *(size_t *)ret = size;
+    return ret;
+}
+
+void bit_array_destroy(void *array) {
+    if (array)
+        free(array);
+}
+
+void *bit_array_dup(void *array) {
+    if (array) {
+        size_t *size = (size_t *)array;
+        size_t bsize = ((*size + 7) >> 3) + sizeof(*size);
+        void *ret = malloc(bsize);
+        if (ret)
+            memcpy(ret, array, bsize);
+        return ret;
+    }
+    return NULL;
+}
+
+void bit_array_reset(void *array) {
+    if (array) {
+        size_t *size = (size_t *)array;
+        size_t bsize = (*size + 7) >> 3;
+        memset(size + 1, 0, bsize);
+    }
+}
+
+void bit_array_set(void *array, size_t bit) {
+    if (array) {
+        size_t *size = (size_t *)array;
+        if (bit < *size) {
+            unsigned char *ptr = (unsigned char *)(size + 1);
+            ptr[bit >> 3] |= (1U << (bit & 7));
+        }
+    }
+}
+
+void bit_array_set_range(void *array, size_t bit, size_t count) {
+    if (array && count) {
+        size_t *size = (size_t *)array;
+        if (bit < *size) {
+            unsigned char *ptr = (unsigned char *)(size + 1);
+            size_t i;
+            for (i = bit; i < *size && i < bit + count; ++i)
+                ptr[i >> 3] |= (1U << (i & 7));
+        }
+    }
+}
+
+int bit_array_test(void *array, size_t bit) {
+    if (array) {
+        size_t *size = (size_t *)array;
+        if (bit < *size) {
+            unsigned char *ptr = (unsigned char *)(size + 1);
+            if (ptr[bit >> 3] & (1U << (bit & 7))) {
+                return 1;
+            }
+        }
+    }
+    return 0;
+}
+
+int bit_array_test_range(void *array, size_t bit, size_t count) {
+    if (array) {
+        size_t *size = (size_t *)array;
+        if (bit < *size) {
+            unsigned char *ptr = (unsigned char *)(size + 1);
+            if ((bit & 7) && (count > 8)) {
+                while ((bit < *size) && count && (bit & 7)) {
+                    if (ptr[bit >> 3] & (1U << (bit & 7)))
+                        return 1;
+                    bit++;
+                    count--;
+                }
+            }
+            if (!(bit & 7)) {
+                while (((*size - bit) >= 8) && (count >= 8)) {
+                    if (ptr[bit >> 3])
+                        return 1;
+                    bit += 8;
+                    count -= 8;
+                }
+            }
+            while ((bit < *size) && count) {
+                if (ptr[bit >> 3] & (1U << (bit & 7)))
+                    return 1;
+                bit++;
+                count--;
+            }
+        }
+    }
+    return 0;
+}
+
+void bit_array_clear(void *array, size_t bit) {
+    if (array) {
+        size_t *size = (size_t *)array;
+        if (bit < *size) {
+            unsigned char *ptr = (unsigned char *)(size + 1);
+            ptr[bit >> 3] &= ~(1U << (bit & 7));
+        }
+    }
+}
+
+void bit_array_clear_range(void *array, size_t bit, size_t count) {
+    if (array && count) {
+        size_t *size = (size_t *)array;
+        if (bit < *size) {
+            unsigned char *ptr = (unsigned char *)(size + 1);
+            size_t i;
+            for (i = bit; i < *size && i < bit + count; ++i)
+                ptr[i >> 3] &= ~(1U << (i & 7));
+        }
+    }
+}
+
+void bit_array_merge(void *dest, void *source, size_t offset) {
+    if (dest && source) {
+        size_t *dsize = (size_t *)dest;
+        size_t *ssize = (size_t *)source;
+        size_t soffset = 0;
+        while (offset < *dsize && soffset < *ssize) {
+            if (bit_array_test(source, soffset)) {
+                bit_array_set(dest, offset);
+            }
+            soffset++;
+            offset++;
+        }
+    }
+}
+
+void bit_array_mask(void *dest, void *source, size_t offset) {
+    if (dest && source) {
+        size_t *dsize = (size_t *)dest;
+        size_t *ssize = (size_t *)source;
+        size_t soffset = 0;
+        while (offset < *dsize && soffset < *ssize) {
+            if (bit_array_test(source, soffset)) {
+                bit_array_clear(dest, offset);
+            }
+            soffset++;
+            offset++;
+        }
+    }
+}
--- /dev/null
+++ b/src/helpers/clickrem.c
@@ -1,0 +1,257 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * clickrem.c - Click removal helpers.                / / \  \
+ *                                                   | <  /   \_
+ * By entheh.                                        |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <math.h>
+#include "dumb.h"
+#include "internal/dumb.h"
+
+typedef struct DUMB_CLICK DUMB_CLICK;
+
+struct DUMB_CLICK_REMOVER {
+    DUMB_CLICK *click;
+    int n_clicks;
+
+    int offset;
+};
+
+struct DUMB_CLICK {
+    DUMB_CLICK *next;
+    long pos;
+    sample_t step;
+};
+
+DUMB_CLICK_REMOVER *dumb_create_click_remover(void) {
+    DUMB_CLICK_REMOVER *cr = malloc(sizeof(*cr));
+    if (!cr)
+        return NULL;
+
+    cr->click = NULL;
+    cr->n_clicks = 0;
+
+    cr->offset = 0;
+
+    return cr;
+}
+
+void dumb_record_click(DUMB_CLICK_REMOVER *cr, long pos, sample_t step) {
+    DUMB_CLICK *click;
+
+    ASSERT(pos >= 0);
+
+    if (!cr || !step)
+        return;
+
+    if (pos == 0) {
+        cr->offset -= step;
+        return;
+    }
+
+    click = malloc(sizeof(*click));
+    if (!click)
+        return;
+
+    click->pos = pos;
+    click->step = step;
+
+    click->next = cr->click;
+    cr->click = click;
+    cr->n_clicks++;
+}
+
+static DUMB_CLICK *dumb_click_mergesort(DUMB_CLICK *click, int n_clicks) {
+    int i;
+    DUMB_CLICK *c1, *c2, **cp;
+
+    if (n_clicks <= 1)
+        return click;
+
+    /* Split the list into two */
+    c1 = click;
+    cp = &c1;
+    for (i = 0; i < n_clicks; i += 2)
+        cp = &(*cp)->next;
+    c2 = *cp;
+    *cp = NULL;
+
+    /* Sort the sublists */
+    c1 = dumb_click_mergesort(c1, (n_clicks + 1) >> 1);
+    c2 = dumb_click_mergesort(c2, n_clicks >> 1);
+
+    /* Merge them */
+    cp = &click;
+    while (c1 && c2) {
+        if (c1->pos > c2->pos) {
+            *cp = c2;
+            c2 = c2->next;
+        } else {
+            *cp = c1;
+            c1 = c1->next;
+        }
+        cp = &(*cp)->next;
+    }
+    if (c2)
+        *cp = c2;
+    else
+        *cp = c1;
+
+    return click;
+}
+
+void dumb_remove_clicks(DUMB_CLICK_REMOVER *cr, sample_t *samples, long length,
+                        int step, float halflife) {
+    DUMB_CLICK *click;
+    long pos = 0;
+    int offset;
+    int factor;
+
+    if (!cr)
+        return;
+
+    factor = (int)floor(pow(0.5, 1.0 / halflife) * (1U << 31));
+
+    click = dumb_click_mergesort(cr->click, cr->n_clicks);
+    cr->click = NULL;
+    cr->n_clicks = 0;
+
+    length *= step;
+
+    while (click) {
+        DUMB_CLICK *next = click->next;
+        long end = click->pos * step;
+        ASSERT(end <= length);
+        offset = cr->offset;
+        if (offset < 0) {
+            offset = -offset;
+            while (pos < end) {
+                samples[pos] -= offset;
+                offset = (int)(((LONG_LONG)(offset << 1) * factor) >> 32);
+                pos += step;
+            }
+            offset = -offset;
+        } else {
+            while (pos < end) {
+                samples[pos] += offset;
+                offset = (int)(((LONG_LONG)(offset << 1) * factor) >> 32);
+                pos += step;
+            }
+        }
+        cr->offset = offset - click->step;
+        free(click);
+        click = next;
+    }
+
+    offset = cr->offset;
+    if (offset < 0) {
+        offset = -offset;
+        while (pos < length) {
+            samples[pos] -= offset;
+            offset = (int)((LONG_LONG)(offset << 1) * factor >> 32);
+            pos += step;
+        }
+        offset = -offset;
+    } else {
+        while (pos < length) {
+            samples[pos] += offset;
+            offset = (int)((LONG_LONG)(offset << 1) * factor >> 32);
+            pos += step;
+        }
+    }
+    cr->offset = offset;
+}
+
+sample_t dumb_click_remover_get_offset(DUMB_CLICK_REMOVER *cr) {
+    return cr ? cr->offset : 0;
+}
+
+void dumb_destroy_click_remover(DUMB_CLICK_REMOVER *cr) {
+    if (cr) {
+        DUMB_CLICK *click = cr->click;
+        while (click) {
+            DUMB_CLICK *next = click->next;
+            free(click);
+            click = next;
+        }
+        free(cr);
+    }
+}
+
+DUMB_CLICK_REMOVER **dumb_create_click_remover_array(int n) {
+    int i;
+    DUMB_CLICK_REMOVER **cr;
+    if (n <= 0)
+        return NULL;
+    cr = malloc(n * sizeof(*cr));
+    if (!cr)
+        return NULL;
+    for (i = 0; i < n; i++)
+        cr[i] = dumb_create_click_remover();
+    return cr;
+}
+
+void dumb_record_click_array(int n, DUMB_CLICK_REMOVER **cr, long pos,
+                             sample_t *step) {
+    if (cr) {
+        int i;
+        for (i = 0; i < n; i++)
+            dumb_record_click(cr[i], pos, step[i]);
+    }
+}
+
+void dumb_record_click_negative_array(int n, DUMB_CLICK_REMOVER **cr, long pos,
+                                      sample_t *step) {
+    if (cr) {
+        int i;
+        for (i = 0; i < n; i++)
+            dumb_record_click(cr[i], pos, -step[i]);
+    }
+}
+
+void dumb_remove_clicks_array(int n, DUMB_CLICK_REMOVER **cr,
+                              sample_t **samples, long length, float halflife) {
+    if (cr) {
+        int i;
+        for (i = 0; i<n>> 1; i++) {
+            dumb_remove_clicks(cr[i << 1], samples[i], length, 2, halflife);
+            dumb_remove_clicks(cr[(i << 1) + 1], samples[i] + 1, length, 2,
+                               halflife);
+        }
+        if (n & 1)
+            dumb_remove_clicks(cr[i << 1], samples[i], length, 1, halflife);
+    }
+}
+
+void dumb_click_remover_get_offset_array(int n, DUMB_CLICK_REMOVER **cr,
+                                         sample_t *offset) {
+    if (cr) {
+        int i;
+        for (i = 0; i < n; i++)
+            if (cr[i])
+                offset[i] += cr[i]->offset;
+    }
+}
+
+void dumb_destroy_click_remover_array(int n, DUMB_CLICK_REMOVER **cr) {
+    if (cr) {
+        int i;
+        for (i = 0; i < n; i++)
+            dumb_destroy_click_remover(cr[i]);
+        free(cr);
+    }
+}
--- /dev/null
+++ b/src/helpers/lpc.c
@@ -1,0 +1,340 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+  function: LPC low level routines
+  last mod: $Id: lpc.c 16227 2009-07-08 06:58:46Z xiphmont $
+
+ ********************************************************************/
+
+/* Some of these routines (autocorrelator, LPC coefficient estimator)
+   are derived from code written by Jutta Degener and Carsten Bormann;
+   thus we include their copyright below.  The entirety of this file
+   is freely redistributable on the condition that both of these
+   copyright notices are preserved without modification.  */
+
+/* Preserved Copyright: *********************************************/
+
+/* Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann,
+Technische Universita"t Berlin
+
+Any use of this software is permitted provided that this notice is not
+removed and that neither the authors nor the Technische Universita"t
+Berlin are deemed to have made any representations as to the
+suitability of this software for any purpose nor are held responsible
+for any defects of this software. THERE IS ABSOLUTELY NO WARRANTY FOR
+THIS SOFTWARE.
+
+As a matter of courtesy, the authors request to be informed about uses
+this software has found, about bugs in this software, and about any
+improvements that may be of general interest.
+
+Berlin, 28.11.1994
+Jutta Degener
+Carsten Bormann
+
+*********************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "internal/stack_alloc.h"
+#include "internal/lpc.h"
+
+/* Autocorrelation LPC coeff generation algorithm invented by
+   N. Levinson in 1947, modified by J. Durbin in 1959. */
+
+/* Input : n elements of time doamin data
+   Output: m lpc coefficients, excitation energy */
+
+static float vorbis_lpc_from_data(float *data, float *lpci, long n, long m) {
+    double *aut = alloca(sizeof(*aut) * (m + 1));
+    double *lpc = alloca(sizeof(*lpc) * (m));
+    double error;
+    double epsilon;
+    long i, j;
+
+    /* autocorrelation, p+1 lag coefficients */
+    j = m + 1;
+    while (j--) {
+        double d = 0; /* double needed for accumulator depth */
+        for (i = j; i < n; i++)
+            d += (double)data[i] * data[(i - j)];
+        aut[j] = d;
+    }
+
+    /* Generate lpc coefficients from autocorr values */
+
+    /* set our noise floor to about -100dB */
+    error = aut[0] * (1. + 1e-10);
+    epsilon = 1e-9 * aut[0] + 1e-10;
+
+    for (i = 0; i < m; i++) {
+        double r = -aut[i + 1];
+
+        if (error < epsilon) {
+            memset(lpc + i, 0, (m - i) * sizeof(*lpc));
+            goto done;
+        }
+
+        /* Sum up this iteration's reflection coefficient; note that in
+           Vorbis we don't save it.  If anyone wants to recycle this code
+           and needs reflection coefficients, save the results of 'r' from
+           each iteration. */
+
+        for (j = 0; j < i; j++)
+            r -= lpc[j] * aut[i - j];
+        r /= error;
+
+        /* Update LPC coefficients and total error */
+
+        lpc[i] = r;
+        for (j = 0; j < i / 2; j++) {
+            double tmp = lpc[j];
+
+            lpc[j] += r * lpc[i - 1 - j];
+            lpc[i - 1 - j] += r * tmp;
+        }
+        if (i & 1)
+            lpc[j] += lpc[j] * r;
+
+        error *= 1. - r * r;
+    }
+
+done:
+
+    /* slightly damp the filter */
+    {
+        double g = .99;
+        double damp = g;
+        for (j = 0; j < m; j++) {
+            lpc[j] *= damp;
+            damp *= g;
+        }
+    }
+
+    for (j = 0; j < m; j++)
+        lpci[j] = (float)lpc[j];
+
+    /* we need the error value to know how big an impulse to hit the
+       filter with later */
+
+    return error;
+}
+
+static void vorbis_lpc_predict(float *coeff, float *prime, long m, float *data,
+                               long n) {
+
+    /* in: coeff[0...m-1] LPC coefficients
+           prime[0...m-1] initial values (allocated size of n+m-1)
+      out: data[0...n-1] data samples */
+
+    long i, j, o, p;
+    float y;
+    float *work = alloca(sizeof(*work) * (m + n));
+
+    if (!prime)
+        for (i = 0; i < m; i++)
+            work[i] = 0.f;
+    else
+        for (i = 0; i < m; i++)
+            work[i] = prime[i];
+
+    for (i = 0; i < n; i++) {
+        y = 0;
+        o = i;
+        p = m;
+        for (j = 0; j < m; j++)
+            y -= work[o++] * coeff[--p];
+
+        data[i] = work[o] = y;
+    }
+}
+
+#include "dumb.h"
+#include "internal/dumb.h"
+#include "internal/it.h"
+
+enum {
+    lpc_max = 256
+}; /* Maximum number of input samples to train the function */
+enum { lpc_order = 32 }; /* Order of the filter */
+enum { lpc_extra = 64 }; /* How many samples of padding to predict or silence */
+
+/* This extra sample padding is really only needed by the FIR resampler, but it
+ * helps the other resamplers as well. */
+
+int dumb_it_add_lpc(struct DUMB_IT_SIGDATA *sigdata) {
+    float lpc[lpc_order * 2];
+    float lpc_input[lpc_max * 2];
+    float lpc_output[lpc_extra * 2];
+
+    signed char *s8;
+    signed short *s16;
+
+    long n, o, offset, lpc_samples;
+
+    for (n = 0; n < sigdata->n_samples; n++) {
+        IT_SAMPLE *sample = sigdata->sample + n;
+        if ((sample->flags & (IT_SAMPLE_EXISTS | IT_SAMPLE_LOOP)) ==
+                IT_SAMPLE_EXISTS &&
+            sample->data != NULL) {
+            /* If we have enough sample data to train the filter, use the filter
+             * to generate the padding */
+            if (sample->length >= lpc_order) {
+                lpc_samples = sample->length;
+                if (lpc_samples > lpc_max)
+                    lpc_samples = lpc_max;
+                offset = sample->length - lpc_samples;
+
+                if (sample->flags & IT_SAMPLE_STEREO) {
+                    if (sample->flags & IT_SAMPLE_16BIT) {
+                        s16 = (signed short *)sample->data;
+                        s16 += offset * 2;
+                        for (o = 0; o < lpc_samples; o++) {
+                            lpc_input[o] = s16[o * 2 + 0];
+                            lpc_input[o + lpc_max] = s16[o * 2 + 1];
+                        }
+                    } else {
+                        s8 = (signed char *)sample->data;
+                        s8 += offset * 2;
+                        for (o = 0; o < lpc_samples; o++) {
+                            lpc_input[o] = s8[o * 2 + 0];
+                            lpc_input[o + lpc_max] = s8[o * 2 + 1];
+                        }
+                    }
+
+                    vorbis_lpc_from_data(lpc_input, lpc, lpc_samples,
+                                         lpc_order);
+                    vorbis_lpc_from_data(lpc_input + lpc_max, lpc + lpc_order,
+                                         lpc_samples, lpc_order);
+
+                    vorbis_lpc_predict(lpc, lpc_input + lpc_samples - lpc_order,
+                                       lpc_order, lpc_output, lpc_extra);
+                    vorbis_lpc_predict(
+                        lpc + lpc_order,
+                        lpc_input + lpc_max + lpc_samples - lpc_order,
+                        lpc_order, lpc_output + lpc_extra, lpc_extra);
+
+                    if (sample->flags & IT_SAMPLE_16BIT) {
+                        s16 = (signed short *)realloc(
+                            sample->data,
+                            (sample->length + lpc_extra) * 2 * sizeof(short));
+                        if (!s16)
+                            return -1;
+
+                        sample->data = s16;
+
+                        s16 += sample->length * 2;
+                        sample->length += lpc_extra;
+
+                        for (o = 0; o < lpc_extra; o++) {
+                            s16[o * 2 + 0] = lpc_output[o];
+                            s16[o * 2 + 1] = lpc_output[o + lpc_extra];
+                        }
+                    } else {
+                        s8 = (signed char *)realloc(
+                            sample->data, (sample->length + lpc_extra) * 2);
+                        if (!s8)
+                            return -1;
+
+                        sample->data = s8;
+
+                        s8 += sample->length * 2;
+                        sample->length += lpc_extra;
+
+                        for (o = 0; o < lpc_extra; o++) {
+                            s8[o * 2 + 0] = lpc_output[o];
+                            s8[o * 2 + 1] = lpc_output[o + lpc_extra];
+                        }
+                    }
+                } else {
+                    if (sample->flags & IT_SAMPLE_16BIT) {
+                        s16 = (signed short *)sample->data;
+                        s16 += offset;
+                        for (o = 0; o < lpc_samples; o++) {
+                            lpc_input[o] = s16[o];
+                        }
+                    } else {
+                        s8 = (signed char *)sample->data;
+                        s8 += offset;
+                        for (o = 0; o < lpc_samples; o++) {
+                            lpc_input[o] = s8[o];
+                        }
+                    }
+
+                    vorbis_lpc_from_data(lpc_input, lpc, lpc_samples,
+                                         lpc_order);
+
+                    vorbis_lpc_predict(lpc, lpc_input + lpc_samples - lpc_order,
+                                       lpc_order, lpc_output, lpc_extra);
+
+                    if (sample->flags & IT_SAMPLE_16BIT) {
+                        s16 = (signed short *)realloc(
+                            sample->data,
+                            (sample->length + lpc_extra) * sizeof(short));
+                        if (!s16)
+                            return -1;
+
+                        sample->data = s16;
+
+                        s16 += sample->length;
+                        sample->length += lpc_extra;
+
+                        for (o = 0; o < lpc_extra; o++) {
+                            s16[o] = lpc_output[o];
+                        }
+                    } else {
+                        s8 = (signed char *)realloc(sample->data,
+                                                    sample->length + lpc_extra);
+                        if (!s8)
+                            return -1;
+
+                        sample->data = s8;
+
+                        s8 += sample->length;
+                        sample->length += lpc_extra;
+
+                        for (o = 0; o < lpc_extra; o++) {
+                            s8[o] = lpc_output[o];
+                        }
+                    }
+                }
+            } else
+            /* Otherwise, pad with silence. */
+            {
+                void *data;
+                offset = sample->length;
+                lpc_samples = lpc_extra;
+
+                sample->length += lpc_samples;
+
+                n = 1;
+                if (sample->flags & IT_SAMPLE_STEREO)
+                    n *= 2;
+                if (sample->flags & IT_SAMPLE_16BIT)
+                    n *= 2;
+
+                offset *= n;
+                lpc_samples *= n;
+
+                data = realloc(sample->data, offset + lpc_samples);
+                if (!data)
+                    return -1;
+                sample->data = data;
+
+                memset((char *)data + offset, 0, lpc_samples);
+            }
+        }
+    }
+
+    return 0;
+}
--- /dev/null
+++ b/src/helpers/memfile.c
@@ -1,0 +1,94 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * memfile.c - Module for reading data from           / / \  \
+ *             memory using a DUMBFILE.              | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+
+typedef struct MEMFILE MEMFILE;
+
+struct MEMFILE {
+    const char *ptr, *ptr_begin;
+    size_t left, size;
+};
+
+static int dumb_memfile_skip(void *f, dumb_off_t n) {
+    MEMFILE *m = f;
+    if (n > (dumb_off_t)m->left)
+        return -1;
+    m->ptr += n;
+    m->left -= n;
+    return 0;
+}
+
+static int dumb_memfile_getc(void *f) {
+    MEMFILE *m = f;
+    if (m->left <= 0)
+        return -1;
+    m->left--;
+    return *(const unsigned char *)m->ptr++;
+}
+
+static dumb_ssize_t dumb_memfile_getnc(char *ptr, size_t n, void *f) {
+    MEMFILE *m = f;
+    if (n > m->left)
+        n = m->left;
+    memcpy(ptr, m->ptr, n);
+    m->ptr += n;
+    m->left -= n;
+    return n;
+}
+
+static void dumb_memfile_close(void *f) { free(f); }
+
+static int dumb_memfile_seek(void *f, dumb_off_t n) {
+    MEMFILE *m = f;
+
+    m->ptr = m->ptr_begin + n;
+    m->left = m->size - n;
+
+    return 0;
+}
+
+static dumb_off_t dumb_memfile_get_size(void *f) {
+    MEMFILE *m = f;
+    return m->size;
+}
+
+static const DUMBFILE_SYSTEM memfile_dfs = {NULL,
+                                            &dumb_memfile_skip,
+                                            &dumb_memfile_getc,
+                                            &dumb_memfile_getnc,
+                                            &dumb_memfile_close,
+                                            &dumb_memfile_seek,
+                                            &dumb_memfile_get_size};
+
+DUMBFILE *dumbfile_open_memory(const char *data, size_t size) {
+    MEMFILE *m = malloc(sizeof(*m));
+    if (!m)
+        return NULL;
+
+    m->ptr_begin = data;
+    m->ptr = data;
+    m->left = size;
+    m->size = size;
+
+    return dumbfile_open_ex(m, &memfile_dfs);
+}
--- /dev/null
+++ b/src/helpers/resamp2.inc
@@ -1,0 +1,178 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * resamp2.inc - Resampling helper template.          / / \  \
+ *                                                   | <  /   \_
+ * By Bob and entheh.                                |  \/ /\   /
+ *                                                    \_  /  > /
+ * In order to find a good trade-off between            | \ / /
+ * speed and accuracy in this code, some tests          |  ' /
+ * were carried out regarding the behaviour of           \__/
+ * long long ints with gcc. The following code
+ * was tested:
+ *
+ * int a, b, c;
+ * c = ((long long)a * b) >> 16;
+ *
+ * DJGPP GCC Version 3.0.3 generated the following assembly language code for
+ * the multiplication and scaling, leaving the 32-bit result in EAX.
+ *
+ * movl  -8(%ebp), %eax    ; read one int into EAX
+ * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
+ * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
+ *
+ * Note that a 32*32->64 multiplication is performed, allowing for high
+ * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
+ * so it is a minor concern when four multiplications are being performed
+ * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
+ * more cycles, so this method is unsuitable for use in the low-quality
+ * resamplers.
+ *
+ * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
+ * defined in dumb.h. We may investigate later what code MSVC generates, but
+ * if it seems too slow then we suggest you use a good compiler.
+ *
+ * FIXME: these comments are somewhat out of date now.
+ */
+
+#define SUFFIX3 _1
+
+/* For convenience, returns nonzero on stop. */
+static int process_pickup(DUMB_RESAMPLER *resampler) {
+    if (resampler->overshot < 0) {
+        resampler->overshot = 0;
+        dumb_resample(resampler, NULL, 2, MONO_DEST_VOLUME_ZEROS,
+                      1.0f); /* Doesn't matter which SUFFIX3. */
+        COPYSRC(resampler->X, 0, resampler->X, 1);
+    }
+
+    for (;;) {
+        SRCTYPE *src = resampler->src;
+
+        if (resampler->dir < 0) {
+            if (resampler->overshot >= 3 &&
+                resampler->pos + 3 >= resampler->start)
+                COPYSRC(resampler->X, 0, src, resampler->pos + 3);
+            if (resampler->overshot >= 2 &&
+                resampler->pos + 2 >= resampler->start)
+                COPYSRC(resampler->X, 1, src, resampler->pos + 2);
+            if (resampler->overshot >= 1 &&
+                resampler->pos + 1 >= resampler->start)
+                COPYSRC(resampler->X, 2, src, resampler->pos + 1);
+            resampler->overshot = (int)(resampler->start - resampler->pos - 1);
+        } else {
+            if (resampler->overshot >= 3 && resampler->pos - 3 < resampler->end)
+                COPYSRC(resampler->X, 0, src, resampler->pos - 3);
+            if (resampler->overshot >= 2 && resampler->pos - 2 < resampler->end)
+                COPYSRC(resampler->X, 1, src, resampler->pos - 2);
+            if (resampler->overshot >= 1 && resampler->pos - 1 < resampler->end)
+                COPYSRC(resampler->X, 2, src, resampler->pos - 1);
+            resampler->overshot = (int)(resampler->pos - resampler->end);
+        }
+
+        if (resampler->overshot < 0) {
+            resampler->overshot = 0;
+            return 0;
+        }
+
+        if (!resampler->pickup) {
+            resampler->dir = 0;
+            return 1;
+        }
+        (*resampler->pickup)(resampler, resampler->pickup_data);
+        if (resampler->dir == 0)
+            return 1;
+        ASSERT(resampler->dir == -1 || resampler->dir == 1);
+    }
+}
+
+/* Create mono destination resampler. */
+/* SUFFIX3 was set above. */
+#define VOLUME_PARAMETERS MONO_DEST_VOLUME_PARAMETERS
+#define VOLUME_VARIABLES MONO_DEST_VOLUME_VARIABLES
+#define SET_VOLUME_VARIABLES SET_MONO_DEST_VOLUME_VARIABLES
+#define RETURN_VOLUME_VARIABLES RETURN_MONO_DEST_VOLUME_VARIABLES
+#define VOLUMES_ARE_ZERO MONO_DEST_VOLUMES_ARE_ZERO
+#define PEEK_FIR MONO_DEST_PEEK_FIR
+#define MIX_FIR MONO_DEST_MIX_FIR
+#define MIX_ZEROS(op) *dst++ op 0
+#include "resamp3.inc"
+
+/* Create stereo destination resampler. */
+#define SUFFIX3 _2
+#define VOLUME_PARAMETERS                                                      \
+    DUMB_VOLUME_RAMP_INFO *volume_left, DUMB_VOLUME_RAMP_INFO *volume_right
+#define VOLUME_VARIABLES                                                       \
+    lvol, lvolr, lvold, lvolt, lvolm, rvol, rvolr, rvold, rvolt, rvolm
+#define SET_VOLUME_VARIABLES                                                   \
+    {                                                                          \
+        if (volume_left) {                                                     \
+            lvolr = volume_left->volume;                                       \
+            lvold = volume_left->delta;                                        \
+            lvolt = volume_left->target;                                       \
+            lvolm = volume_left->mix;                                          \
+            lvol = lvolr * lvolm;                                              \
+            if (lvolr == lvolt)                                                \
+                volume_left = NULL;                                            \
+        } else {                                                               \
+            lvol = 0;                                                          \
+            lvold = 0;                                                         \
+            lvolt = 0;                                                         \
+            lvolm = 0;                                                         \
+        }                                                                      \
+        if (volume_right) {                                                    \
+            rvolr = volume_right->volume;                                      \
+            rvold = volume_right->delta;                                       \
+            rvolt = volume_right->target;                                      \
+            rvolm = volume_right->mix;                                         \
+            rvol = rvolr * rvolm;                                              \
+            if (rvolr == rvolt)                                                \
+                volume_right = NULL;                                           \
+        } else {                                                               \
+            rvol = 0;                                                          \
+            rvold = 0;                                                         \
+            rvolt = 0;                                                         \
+            rvolm = 0;                                                         \
+        }                                                                      \
+    }
+#define RETURN_VOLUME_VARIABLES                                                \
+    {                                                                          \
+        if (volume_left)                                                       \
+            volume_left->volume = lvolr;                                       \
+        if (volume_right)                                                      \
+            volume_right->volume = rvolr;                                      \
+    }
+#define VOLUMES_ARE_ZERO (lvol == 0 && lvolt == 0 && rvol == 0 && rvolt == 0)
+#define PEEK_FIR STEREO_DEST_PEEK_FIR
+#define MIX_FIR STEREO_DEST_MIX_FIR
+#define MIX_ZEROS(op)                                                          \
+    {                                                                          \
+        *dst++ op 0;                                                           \
+        *dst++ op 0;                                                           \
+    }
+#include "resamp3.inc"
+
+#undef MONO_DEST_VOLUMES_ARE_ZERO
+#undef SET_MONO_DEST_VOLUME_VARIABLES
+#undef RETURN_MONO_DEST_VOLUME_VARIABLES
+#undef MONO_DEST_VOLUME_ZEROS
+#undef MONO_DEST_VOLUME_VARIABLES
+#undef MONO_DEST_VOLUME_PARAMETERS
+#undef MONO_DEST_PEEK_FIR
+#undef STEREO_DEST_PEEK_FIR
+#undef MONO_DEST_MIX_FIR
+#undef STEREO_DEST_MIX_FIR
+#undef ADVANCE_FIR
+#undef POKE_FIR
+#undef COPYSRC2
+#undef COPYSRC
+#undef DIVIDE_BY_SRC_CHANNELS
+#undef SRC_CHANNELS
+#undef SUFFIX2
--- /dev/null
+++ b/src/helpers/resamp3.inc
@@ -1,0 +1,278 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * resamp3.inc - Resampling helper template.          / / \  \
+ *                                                   | <  /   \_
+ * By Bob and entheh.                                |  \/ /\   /
+ *                                                    \_  /  > /
+ * In order to find a good trade-off between            | \ / /
+ * speed and accuracy in this code, some tests          |  ' /
+ * were carried out regarding the behaviour of           \__/
+ * long long ints with gcc. The following code
+ * was tested:
+ *
+ * int a, b, c;
+ * c = ((long long)a * b) >> 16;
+ *
+ * DJGPP GCC Version 3.0.3 generated the following assembly language code for
+ * the multiplication and scaling, leaving the 32-bit result in EAX.
+ *
+ * movl  -8(%ebp), %eax    ; read one int into EAX
+ * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
+ * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
+ *
+ * Note that a 32*32->64 multiplication is performed, allowing for high
+ * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
+ * so it is a minor concern when four multiplications are being performed
+ * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
+ * more cycles, so this method is unsuitable for use in the low-quality
+ * resamplers.
+ *
+ * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
+ * defined in dumb.h. We may investigate later what code MSVC generates, but
+ * if it seems too slow then we suggest you use a good compiler.
+ *
+ * FIXME: these comments are somewhat out of date now.
+ */
+
+long dumb_resample(DUMB_RESAMPLER *resampler, sample_t *dst, long dst_size,
+                   VOLUME_PARAMETERS, float delta) {
+    int dt, inv_dt;
+    float VOLUME_VARIABLES;
+    long done;
+    long todo;
+    LONG_LONG todo64;
+    int quality;
+
+    if (!resampler || resampler->dir == 0)
+        return 0;
+    ASSERT(resampler->dir == -1 || resampler->dir == 1);
+
+    done = 0;
+    dt = (int)(delta * 65536.0 + 0.5);
+    if (dt == 0 || dt == (int)-0x80000000)
+        return 0;
+    inv_dt = (int)(1.0 / delta * 65536.0 + 0.5);
+    SET_VOLUME_VARIABLES;
+
+    if (VOLUMES_ARE_ZERO)
+        dst = NULL;
+
+    _dumb_init_cubic();
+
+    quality = resampler->quality;
+
+    while (done < dst_size) {
+        if (process_pickup(resampler)) {
+            RETURN_VOLUME_VARIABLES;
+            return done;
+        }
+
+        if ((resampler->dir ^ dt) < 0)
+            dt = -dt;
+
+        if (resampler->dir < 0)
+            todo64 = ((((LONG_LONG)(resampler->pos - resampler->start) << 16) +
+                       resampler->subpos - dt) /
+                      -dt);
+        else
+            todo64 = ((((LONG_LONG)(resampler->end - resampler->pos) << 16) -
+                       resampler->subpos - 1 + dt) /
+                      dt);
+
+        if (todo64 < 0)
+            todo = 0;
+        else if (todo64 > dst_size - done)
+            todo = dst_size - done;
+        else
+            todo = (long)todo64;
+
+        done += todo;
+
+        {
+            SRCTYPE *src = resampler->src;
+            long pos = resampler->pos;
+            int subpos = resampler->subpos;
+            long diff = pos;
+            long overshot;
+            if (resampler->dir < 0) {
+                if (!dst) {
+                    /* Silence or simulation */
+                    LONG_LONG new_subpos = subpos + (LONG_LONG)dt * todo;
+                    pos += (long)(new_subpos >> 16);
+                    subpos = (long)new_subpos & 65535;
+                } else {
+                    /* FIR resampling, backwards */
+                    SRCTYPE *x;
+                    if (resampler->fir_resampler_ratio != delta) {
+                        resampler_set_rate(resampler->fir_resampler[0], delta);
+                        resampler_set_rate(resampler->fir_resampler[1], delta);
+                        resampler->fir_resampler_ratio = delta;
+                    }
+                    x = &src[pos * SRC_CHANNELS];
+                    while (todo) {
+                        while ((resampler_get_free_count(
+                                    resampler->fir_resampler[0]) ||
+                                (!resampler_get_sample_count(
+                                     resampler->fir_resampler[0])
+#if SRC_CHANNELS == 2
+                                 && !resampler_get_sample_count(
+                                        resampler->fir_resampler[1])
+#endif
+                                     )) &&
+                               pos >= resampler->start) {
+                            POKE_FIR(0);
+                            pos--;
+                            x -= SRC_CHANNELS;
+                        }
+                        if (!resampler_get_sample_count(
+                                resampler->fir_resampler[0]))
+                            break;
+                        MIX_FIR;
+                        ADVANCE_FIR;
+                        --todo;
+                    }
+                    done -= todo;
+                }
+                diff = diff - pos;
+                overshot = resampler->start - pos - 1;
+                if (diff >= 3) {
+                    COPYSRC2(resampler->X, 0, overshot < 3, src, pos + 3);
+                    COPYSRC2(resampler->X, 1, overshot < 2, src, pos + 2);
+                    COPYSRC2(resampler->X, 2, overshot < 1, src, pos + 1);
+                } else if (diff >= 2) {
+                    COPYSRC(resampler->X, 0, resampler->X, 2);
+                    COPYSRC2(resampler->X, 1, overshot < 2, src, pos + 2);
+                    COPYSRC2(resampler->X, 2, overshot < 1, src, pos + 1);
+                } else if (diff >= 1) {
+                    COPYSRC(resampler->X, 0, resampler->X, 1);
+                    COPYSRC(resampler->X, 1, resampler->X, 2);
+                    COPYSRC2(resampler->X, 2, overshot < 1, src, pos + 1);
+                }
+            } else {
+                if (!dst) {
+                    /* Silence or simulation */
+                    LONG_LONG new_subpos = subpos + (LONG_LONG)dt * todo;
+                    pos += (long)(new_subpos >> 16);
+                    subpos = (long)new_subpos & 65535;
+                } else {
+                    /* FIR resampling, forwards */
+                    SRCTYPE *x;
+                    if (resampler->fir_resampler_ratio != delta) {
+                        resampler_set_rate(resampler->fir_resampler[0], delta);
+                        resampler_set_rate(resampler->fir_resampler[1], delta);
+                        resampler->fir_resampler_ratio = delta;
+                    }
+                    x = &src[pos * SRC_CHANNELS];
+                    while (todo) {
+                        while ((resampler_get_free_count(
+                                    resampler->fir_resampler[0]) ||
+                                (!resampler_get_sample_count(
+                                     resampler->fir_resampler[0])
+#if SRC_CHANNELS == 2
+                                 && !resampler_get_sample_count(
+                                        resampler->fir_resampler[1])
+#endif
+                                     )) &&
+                               pos < resampler->end) {
+                            POKE_FIR(0);
+                            pos++;
+                            x += SRC_CHANNELS;
+                        }
+                        if (!resampler_get_sample_count(
+                                resampler->fir_resampler[0]))
+                            break;
+                        MIX_FIR;
+                        ADVANCE_FIR;
+                        --todo;
+                    }
+                    done -= todo;
+                }
+                diff = pos - diff;
+                overshot = pos - resampler->end;
+                if (diff >= 3) {
+                    COPYSRC2(resampler->X, 0, overshot < 3, src, pos - 3);
+                    COPYSRC2(resampler->X, 1, overshot < 2, src, pos - 2);
+                    COPYSRC2(resampler->X, 2, overshot < 1, src, pos - 1);
+                } else if (diff >= 2) {
+                    COPYSRC(resampler->X, 0, resampler->X, 2);
+                    COPYSRC2(resampler->X, 1, overshot < 2, src, pos - 2);
+                    COPYSRC2(resampler->X, 2, overshot < 1, src, pos - 1);
+                } else if (diff >= 1) {
+                    COPYSRC(resampler->X, 0, resampler->X, 1);
+                    COPYSRC(resampler->X, 1, resampler->X, 2);
+                    COPYSRC2(resampler->X, 2, overshot < 1, src, pos - 1);
+                }
+            }
+            resampler->pos = pos;
+            resampler->subpos = subpos;
+        }
+    }
+
+    RETURN_VOLUME_VARIABLES;
+    return done;
+}
+
+void dumb_resample_get_current_sample(DUMB_RESAMPLER *resampler,
+                                      VOLUME_PARAMETERS, sample_t *dst) {
+    float VOLUME_VARIABLES;
+    SRCTYPE *src;
+    long pos;
+    int subpos;
+    int quality;
+    SRCTYPE *x;
+
+    if (!resampler || resampler->dir == 0) {
+        MIX_ZEROS(=);
+        return;
+    }
+    ASSERT(resampler->dir == -1 || resampler->dir == 1);
+
+    if (process_pickup(resampler)) {
+        MIX_ZEROS(=);
+        return;
+    }
+
+    SET_VOLUME_VARIABLES;
+
+    if (VOLUMES_ARE_ZERO) {
+        MIX_ZEROS(=);
+        return;
+    }
+
+    _dumb_init_cubic();
+
+    quality = resampler->quality;
+
+    src = resampler->src;
+    pos = resampler->pos;
+    subpos = resampler->subpos;
+    x = resampler->X;
+
+    if (resampler->dir < 0) {
+        HEAVYASSERT(pos >= resampler->start);
+        /* FIR resampling, backwards */
+        PEEK_FIR;
+    } else {
+        HEAVYASSERT(pos < resampler->end);
+        /* FIR resampling, forwards */
+        PEEK_FIR;
+    }
+}
+
+#undef MIX_ZEROS
+#undef MIX_FIR
+#undef PEEK_FIR
+#undef VOLUMES_ARE_ZERO
+#undef SET_VOLUME_VARIABLES
+#undef RETURN_VOLUME_VARIABLES
+#undef VOLUME_VARIABLES
+#undef VOLUME_PARAMETERS
+#undef SUFFIX3
--- /dev/null
+++ b/src/helpers/resample.c
@@ -1,0 +1,332 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * resample.c - Resampling helpers.                   / / \  \
+ *                                                   | <  /   \_
+ * By Bob and entheh.                                |  \/ /\   /
+ *                                                    \_  /  > /
+ * In order to find a good trade-off between            | \ / /
+ * speed and accuracy in this code, some tests          |  ' /
+ * were carried out regarding the behaviour of           \__/
+ * long long ints with gcc. The following code
+ * was tested:
+ *
+ * int a, b, c;
+ * c = ((long long)a * b) >> 16;
+ *
+ * DJGPP GCC Version 3.0.3 generated the following assembly language code for
+ * the multiplication and scaling, leaving the 32-bit result in EAX.
+ *
+ * movl  -8(%ebp), %eax    ; read one int into EAX
+ * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
+ * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
+ *
+ * Note that a 32*32->64 multiplication is performed, allowing for high
+ * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
+ * so it is a minor concern when four multiplications are being performed
+ * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
+ * more cycles, so this method is unsuitable for use in the low-quality
+ * resamplers.
+ *
+ * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
+ * defined in dumb.h. We may investigate later what code MSVC generates, but
+ * if it seems too slow then we suggest you use a good compiler.
+ *
+ * FIXME: these comments are somewhat out of date now.
+ */
+
+#include <math.h>
+#include "internal/resampler.h"
+#include "internal/dumb.h"
+
+/* Compile with -DHEAVYDEBUG if you want to make sure the pick-up function is
+ * called when it should be. There will be a considerable performance hit,
+ * since at least one condition has to be tested for every sample generated.
+ */
+#ifdef HEAVYDEBUG
+#define HEAVYASSERT(cond) ASSERT(cond)
+#else
+#define HEAVYASSERT(cond)
+#endif
+
+/* Make MSVC shut the hell up about if ( upd ) UPDATE_VOLUME() conditions being
+ * constant */
+#ifdef _MSC_VER
+#pragma warning(disable : 4127 4701)
+#endif
+
+/* A global variable for controlling resampling quality wherever a local
+ * specification doesn't override it. The following values are valid:
+ *
+ *  0 - DUMB_RQ_ALIASING - fastest
+ *  1 - DUMB_RQ_BLEP     - nicer than aliasing, but slower
+ *  2 - DUMB_RQ_LINEAR
+ *  3 - DUMB_RQ_BLAM     - band-limited linear interpolation, nice but slower
+ *  4 - DUMB_RQ_CUBIC
+ *  5 - DUMB_RQ_FIR      - nicest
+ *
+ * Values outside the range 0-4 will behave the same as the nearest
+ * value within the range.
+ */
+int dumb_resampling_quality = DUMB_RQ_CUBIC;
+
+//#define MULSC(a, b) ((int)((LONG_LONG)(a) * (b) >> 16))
+//#define MULSC(a, b) ((a) * ((b) >> 2) >> 14)
+#define MULSCV(a, b) ((int)((LONG_LONG)(a) * (b) >> 32))
+#define MULSC(a, b) ((int)((LONG_LONG)((a) << 4) * ((b) << 12) >> 32))
+#define MULSC16(a, b) ((int)((LONG_LONG)((a) << 12) * ((b) << 12) >> 32))
+
+/* Executes the content 'iterator' times.
+ * Clobbers the 'iterator' variable.
+ * The loop is unrolled by four.
+ */
+#if 0
+#define LOOP4(iterator, CONTENT)                                               \
+    {                                                                          \
+        if ((iterator)&2) {                                                    \
+            CONTENT;                                                           \
+            CONTENT;                                                           \
+        }                                                                      \
+        if ((iterator)&1) {                                                    \
+            CONTENT;                                                           \
+        }                                                                      \
+        (iterator) >>= 2;                                                      \
+        while (iterator) {                                                     \
+            CONTENT;                                                           \
+            CONTENT;                                                           \
+            CONTENT;                                                           \
+            CONTENT;                                                           \
+            (iterator)--;                                                      \
+        }                                                                      \
+    }
+#else
+#define LOOP4(iterator, CONTENT)                                               \
+    {                                                                          \
+        while ((iterator)--) {                                                 \
+            CONTENT;                                                           \
+        }                                                                      \
+    }
+#endif
+
+#define PASTERAW(a, b) a##b /* This does not expand macros in b ... */
+#define PASTE(a, b)                                                            \
+    PASTERAW(a, b) /* ... but b is expanded during this substitution. */
+
+#define X PASTE(x.x, SRCBITS)
+
+void _dumb_init_cubic(void) {
+    static int done = 0;
+    if (done)
+        return;
+
+    resampler_init();
+
+    done = 1;
+}
+
+/* Create resamplers for 24-in-32-bit source samples. */
+
+/* #define SUFFIX
+ * MSVC warns if we try to paste a null SUFFIX, so instead we define
+ * special macros for the function names that don't bother doing the
+ * corresponding paste. The more generic definitions are further down.
+ */
+#define process_pickup PASTE(process_pickup, SUFFIX2)
+#define dumb_resample PASTE(PASTE(dumb_resample, SUFFIX2), SUFFIX3)
+#define dumb_resample_get_current_sample                                       \
+    PASTE(PASTE(dumb_resample_get_current_sample, SUFFIX2), SUFFIX3)
+
+#define SRCTYPE sample_t
+#define SRCBITS 24
+#define FIR(x) (x >> 8)
+#include "resample.inc"
+
+/* Undefine the simplified macros. */
+#undef dumb_resample_get_current_sample
+#undef dumb_resample
+#undef process_pickup
+
+/* Now define the proper ones that use SUFFIX. */
+#define dumb_reset_resampler PASTE(dumb_reset_resampler, SUFFIX)
+#define dumb_start_resampler PASTE(dumb_start_resampler, SUFFIX)
+#define process_pickup PASTE(PASTE(process_pickup, SUFFIX), SUFFIX2)
+#define dumb_resample                                                          \
+    PASTE(PASTE(PASTE(dumb_resample, SUFFIX), SUFFIX2), SUFFIX3)
+#define dumb_resample_get_current_sample                                       \
+    PASTE(PASTE(PASTE(dumb_resample_get_current_sample, SUFFIX), SUFFIX2),     \
+          SUFFIX3)
+#define dumb_end_resampler PASTE(dumb_end_resampler, SUFFIX)
+
+/* Create resamplers for 16-bit source samples. */
+#define SUFFIX _16
+#define SRCTYPE short
+#define SRCBITS 16
+#define FIR(x) (x * (1.0f / 32768.0f))
+#include "resample.inc"
+
+/* Create resamplers for 8-bit source samples. */
+#define SUFFIX _8
+#define SRCTYPE signed char
+#define SRCBITS 8
+#define FIR(x) (x * (1.0f / 256.0f))
+#include "resample.inc"
+
+#undef dumb_reset_resampler
+#undef dumb_start_resampler
+#undef process_pickup
+#undef dumb_resample
+#undef dumb_resample_get_current_sample
+#undef dumb_end_resampler
+
+void dumb_reset_resampler_n(int n, DUMB_RESAMPLER *resampler, void *src,
+                            int src_channels, long pos, long start, long end,
+                            int quality) {
+    if (n == 8)
+        dumb_reset_resampler_8(resampler, src, src_channels, pos, start, end,
+                               quality);
+    else if (n == 16)
+        dumb_reset_resampler_16(resampler, src, src_channels, pos, start, end,
+                                quality);
+    else
+        dumb_reset_resampler(resampler, src, src_channels, pos, start, end,
+                             quality);
+}
+
+DUMB_RESAMPLER *dumb_start_resampler_n(int n, void *src, int src_channels,
+                                       long pos, long start, long end,
+                                       int quality) {
+    if (n == 8)
+        return dumb_start_resampler_8(src, src_channels, pos, start, end,
+                                      quality);
+    else if (n == 16)
+        return dumb_start_resampler_16(src, src_channels, pos, start, end,
+                                       quality);
+    else
+        return dumb_start_resampler(src, src_channels, pos, start, end,
+                                    quality);
+}
+
+long dumb_resample_n_1_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume,
+                         float delta) {
+    if (n == 8)
+        return dumb_resample_8_1_1(resampler, dst, dst_size, volume, delta);
+    else if (n == 16)
+        return dumb_resample_16_1_1(resampler, dst, dst_size, volume, delta);
+    else
+        return dumb_resample_1_1(resampler, dst, dst_size, volume, delta);
+}
+
+long dumb_resample_n_1_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta) {
+    if (n == 8)
+        return dumb_resample_8_1_2(resampler, dst, dst_size, volume_left,
+                                   volume_right, delta);
+    else if (n == 16)
+        return dumb_resample_16_1_2(resampler, dst, dst_size, volume_left,
+                                    volume_right, delta);
+    else
+        return dumb_resample_1_2(resampler, dst, dst_size, volume_left,
+                                 volume_right, delta);
+}
+
+long dumb_resample_n_2_1(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta) {
+    if (n == 8)
+        return dumb_resample_8_2_1(resampler, dst, dst_size, volume_left,
+                                   volume_right, delta);
+    else if (n == 16)
+        return dumb_resample_16_2_1(resampler, dst, dst_size, volume_left,
+                                    volume_right, delta);
+    else
+        return dumb_resample_2_1(resampler, dst, dst_size, volume_left,
+                                 volume_right, delta);
+}
+
+long dumb_resample_n_2_2(int n, DUMB_RESAMPLER *resampler, sample_t *dst,
+                         long dst_size, DUMB_VOLUME_RAMP_INFO *volume_left,
+                         DUMB_VOLUME_RAMP_INFO *volume_right, float delta) {
+    if (n == 8)
+        return dumb_resample_8_2_2(resampler, dst, dst_size, volume_left,
+                                   volume_right, delta);
+    else if (n == 16)
+        return dumb_resample_16_2_2(resampler, dst, dst_size, volume_left,
+                                    volume_right, delta);
+    else
+        return dumb_resample_2_2(resampler, dst, dst_size, volume_left,
+                                 volume_right, delta);
+}
+
+void dumb_resample_get_current_sample_n_1_1(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume,
+                                            sample_t *dst) {
+    if (n == 8)
+        dumb_resample_get_current_sample_8_1_1(resampler, volume, dst);
+    else if (n == 16)
+        dumb_resample_get_current_sample_16_1_1(resampler, volume, dst);
+    else
+        dumb_resample_get_current_sample_1_1(resampler, volume, dst);
+}
+
+void dumb_resample_get_current_sample_n_1_2(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst) {
+    if (n == 8)
+        dumb_resample_get_current_sample_8_1_2(resampler, volume_left,
+                                               volume_right, dst);
+    else if (n == 16)
+        dumb_resample_get_current_sample_16_1_2(resampler, volume_left,
+                                                volume_right, dst);
+    else
+        dumb_resample_get_current_sample_1_2(resampler, volume_left,
+                                             volume_right, dst);
+}
+
+void dumb_resample_get_current_sample_n_2_1(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst) {
+    if (n == 8)
+        dumb_resample_get_current_sample_8_2_1(resampler, volume_left,
+                                               volume_right, dst);
+    else if (n == 16)
+        dumb_resample_get_current_sample_16_2_1(resampler, volume_left,
+                                                volume_right, dst);
+    else
+        dumb_resample_get_current_sample_2_1(resampler, volume_left,
+                                             volume_right, dst);
+}
+
+void dumb_resample_get_current_sample_n_2_2(int n, DUMB_RESAMPLER *resampler,
+                                            DUMB_VOLUME_RAMP_INFO *volume_left,
+                                            DUMB_VOLUME_RAMP_INFO *volume_right,
+                                            sample_t *dst) {
+    if (n == 8)
+        dumb_resample_get_current_sample_8_2_2(resampler, volume_left,
+                                               volume_right, dst);
+    else if (n == 16)
+        dumb_resample_get_current_sample_16_2_2(resampler, volume_left,
+                                                volume_right, dst);
+    else
+        dumb_resample_get_current_sample_2_2(resampler, volume_left,
+                                             volume_right, dst);
+}
+
+void dumb_end_resampler_n(int n, DUMB_RESAMPLER *resampler) {
+    if (n == 8)
+        dumb_end_resampler_8(resampler);
+    else if (n == 16)
+        dumb_end_resampler_16(resampler);
+    else
+        dumb_end_resampler(resampler);
+}
--- /dev/null
+++ b/src/helpers/resample.inc
@@ -1,0 +1,288 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * resample.inc - Resampling helper template.         / / \  \
+ *                                                   | <  /   \_
+ * By Bob and entheh.                                |  \/ /\   /
+ *                                                    \_  /  > /
+ * In order to find a good trade-off between            | \ / /
+ * speed and accuracy in this code, some tests          |  ' /
+ * were carried out regarding the behaviour of           \__/
+ * long long ints with gcc. The following code
+ * was tested:
+ *
+ * int a, b, c;
+ * c = ((long long)a * b) >> 16;
+ *
+ * DJGPP GCC Version 3.0.3 generated the following assembly language code for
+ * the multiplication and scaling, leaving the 32-bit result in EAX.
+ *
+ * movl  -8(%ebp), %eax    ; read one int into EAX
+ * imull -4(%ebp)          ; multiply by the other; result goes in EDX:EAX
+ * shrdl $16, %edx, %eax   ; shift EAX right 16, shifting bits in from EDX
+ *
+ * Note that a 32*32->64 multiplication is performed, allowing for high
+ * accuracy. On the Pentium 2 and above, shrdl takes two cycles (generally),
+ * so it is a minor concern when four multiplications are being performed
+ * (the cubic resampler). On the Pentium MMX and earlier, it takes four or
+ * more cycles, so this method is unsuitable for use in the low-quality
+ * resamplers.
+ *
+ * Since "long long" is a gcc-specific extension, we use LONG_LONG instead,
+ * defined in dumb.h. We may investigate later what code MSVC generates, but
+ * if it seems too slow then we suggest you use a good compiler.
+ *
+ * FIXME: these comments are somewhat out of date now.
+ */
+
+void dumb_reset_resampler(DUMB_RESAMPLER *resampler, SRCTYPE *src,
+                          int src_channels, long pos, long start, long end,
+                          int quality) {
+    int i;
+    resampler->src = src;
+    resampler->pos = pos;
+    resampler->subpos = 0;
+    resampler->start = start;
+    resampler->end = end;
+    resampler->dir = 1;
+    resampler->pickup = NULL;
+    resampler->pickup_data = NULL;
+    if (quality < 0) {
+        resampler->quality = 0;
+    } else if (quality > DUMB_RQ_N_LEVELS - 1) {
+        resampler->quality = DUMB_RQ_N_LEVELS - 1;
+    } else {
+        resampler->quality = quality;
+    }
+    for (i = 0; i < src_channels * 3; i++)
+        resampler->X[i] = 0;
+    resampler->overshot = -1;
+    resampler->fir_resampler_ratio = 0;
+    resampler_clear(resampler->fir_resampler[0]);
+    resampler_clear(resampler->fir_resampler[1]);
+    resampler_set_quality(resampler->fir_resampler[0], resampler->quality);
+    resampler_set_quality(resampler->fir_resampler[1], resampler->quality);
+}
+
+DUMB_RESAMPLER *dumb_start_resampler(SRCTYPE *src, int src_channels, long pos,
+                                     long start, long end, int quality) {
+    DUMB_RESAMPLER *resampler = malloc(sizeof(*resampler));
+    if (!resampler)
+        return NULL;
+    dumb_reset_resampler(resampler, src, src_channels, pos, start, end,
+                         quality);
+    return resampler;
+}
+
+#define UPDATE_VOLUME(pvol, vol)                                               \
+    {                                                                          \
+        if (pvol) {                                                            \
+            vol##r += vol##d;                                                  \
+            if ((vol##d < 0 && vol##r <= vol##t) ||                            \
+                (vol##d > 0 && vol##r >= vol##t)) {                            \
+                pvol->volume = pvol->target;                                   \
+                if (pvol->declick_stage == 0 || pvol->declick_stage >= 3)      \
+                    pvol->declick_stage++;                                     \
+                pvol = NULL;                                                   \
+                vol = vol##t * vol##m;                                         \
+            } else {                                                           \
+                vol = vol##r * vol##m;                                         \
+            }                                                                  \
+        }                                                                      \
+    }
+
+/* Create mono source resampler. */
+#define SUFFIX2 _1
+#define SRC_CHANNELS 1
+#define DIVIDE_BY_SRC_CHANNELS(x) (x)
+#define COPYSRC(dstarray, dstindex, srcarray, srcindex)                        \
+    (dstarray)[dstindex] = (srcarray)[srcindex]
+#define COPYSRC2(dstarray, dstindex, condition, srcarray, srcindex)            \
+    (dstarray)[dstindex] = condition ? (srcarray)[srcindex] : 0
+#define MONO_DEST_VOLUME_PARAMETERS DUMB_VOLUME_RAMP_INFO *volume
+#define MONO_DEST_VOLUME_VARIABLES vol, volr, vold, volt, volm
+#define MONO_DEST_VOLUME_ZEROS 0
+#define SET_MONO_DEST_VOLUME_VARIABLES                                         \
+    {                                                                          \
+        if (volume) {                                                          \
+            volr = volume->volume;                                             \
+            vold = volume->delta;                                              \
+            volt = volume->target;                                             \
+            volm = volume->mix;                                                \
+            vol = volr * volm;                                                 \
+            if (volr == volt)                                                  \
+                volume = NULL;                                                 \
+        } else {                                                               \
+            vol = 0;                                                           \
+            volr = 0;                                                          \
+            vold = 0;                                                          \
+            volt = 0;                                                          \
+            volm = 0;                                                          \
+        }                                                                      \
+    }
+#define RETURN_MONO_DEST_VOLUME_VARIABLES                                      \
+    if (volume)                                                                \
+    volume->volume = volr
+#define MONO_DEST_VOLUMES_ARE_ZERO (vol == 0 && volt == 0)
+#define POKE_FIR(offset)                                                       \
+    {                                                                          \
+        resampler_write_sample_float(resampler->fir_resampler[0],              \
+                                     FIR(x[offset]));                          \
+    }
+#define MONO_DEST_PEEK_FIR                                                     \
+    *dst = resampler_get_sample_float(resampler->fir_resampler[0]) * vol *     \
+           16777216.0f
+#define MONO_DEST_MIX_FIR                                                      \
+    {                                                                          \
+        *dst++ += resampler_get_sample_float(resampler->fir_resampler[0]) *    \
+                  vol * 16777216.0f;                                           \
+        UPDATE_VOLUME(volume, vol);                                            \
+    }
+#define ADVANCE_FIR resampler_remove_sample(resampler->fir_resampler[0], 1)
+#define STEREO_DEST_PEEK_FIR                                                   \
+    {                                                                          \
+        float sample =                                                         \
+            resampler_get_sample_float(resampler->fir_resampler[0]);           \
+        *dst++ = sample * lvol * 16777216.0f;                                  \
+        *dst++ = sample * rvol * 16777216.0f;                                  \
+    }
+#define STEREO_DEST_MIX_FIR                                                    \
+    {                                                                          \
+        float sample =                                                         \
+            resampler_get_sample_float(resampler->fir_resampler[0]);           \
+        *dst++ += sample * lvol * 16777216.0f;                                 \
+        *dst++ += sample * rvol * 16777216.0f;                                 \
+        UPDATE_VOLUME(volume_left, lvol);                                      \
+        UPDATE_VOLUME(volume_right, rvol);                                     \
+    }
+#include "resamp2.inc"
+
+/* Create stereo source resampler. */
+#define SUFFIX2 _2
+#define SRC_CHANNELS 2
+#define DIVIDE_BY_SRC_CHANNELS(x) ((x) >> 1)
+#define COPYSRC(dstarray, dstindex, srcarray, srcindex)                        \
+    {                                                                          \
+        (dstarray)[(dstindex)*2] = (srcarray)[(srcindex)*2];                   \
+        (dstarray)[(dstindex)*2 + 1] = (srcarray)[(srcindex)*2 + 1];           \
+    }
+#define COPYSRC2(dstarray, dstindex, condition, srcarray, srcindex)            \
+    {                                                                          \
+        if (condition) {                                                       \
+            (dstarray)[(dstindex)*2] = (srcarray)[(srcindex)*2];               \
+            (dstarray)[(dstindex)*2 + 1] = (srcarray)[(srcindex)*2 + 1];       \
+        } else {                                                               \
+            (dstarray)[(dstindex)*2] = 0;                                      \
+            (dstarray)[(dstindex)*2 + 1] = 0;                                  \
+        }                                                                      \
+    }
+
+#define MONO_DEST_VOLUME_PARAMETERS                                            \
+    DUMB_VOLUME_RAMP_INFO *volume_left, DUMB_VOLUME_RAMP_INFO *volume_right
+#define MONO_DEST_VOLUME_VARIABLES                                             \
+    lvol, lvolr, lvold, lvolt, lvolm, rvol, rvolr, rvold, rvolt, rvolm
+#define MONO_DEST_VOLUME_ZEROS 0, 0
+#define SET_MONO_DEST_VOLUME_VARIABLES                                         \
+    {                                                                          \
+        if (volume_left) {                                                     \
+            lvolr = volume_left->volume;                                       \
+            lvold = volume_left->delta;                                        \
+            lvolt = volume_left->target;                                       \
+            lvolm = volume_left->mix;                                          \
+            lvol = lvolr * lvolm;                                              \
+            if (lvolr == lvolt)                                                \
+                volume_left = NULL;                                            \
+        } else {                                                               \
+            lvol = 0;                                                          \
+            lvolr = 0;                                                         \
+            lvold = 0;                                                         \
+            lvolt = 0;                                                         \
+            lvolm = 0;                                                         \
+        }                                                                      \
+        if (volume_right) {                                                    \
+            rvolr = volume_right->volume;                                      \
+            rvold = volume_right->delta;                                       \
+            rvolt = volume_right->target;                                      \
+            rvolm = volume_right->mix;                                         \
+            rvol = rvolr * rvolm;                                              \
+            if (rvolr == rvolt)                                                \
+                volume_right = NULL;                                           \
+        } else {                                                               \
+            rvol = 0;                                                          \
+            rvolr = 0;                                                         \
+            rvold = 0;                                                         \
+            rvolt = 0;                                                         \
+            rvolm = 0;                                                         \
+        }                                                                      \
+    }
+#define RETURN_MONO_DEST_VOLUME_VARIABLES                                      \
+    {                                                                          \
+        if (volume_left)                                                       \
+            volume_left->volume = lvolr;                                       \
+        if (volume_right)                                                      \
+            volume_right->volume = rvolr;                                      \
+    }
+#define MONO_DEST_VOLUMES_ARE_ZERO                                             \
+    (lvol == 0 && lvolt == 0 && rvol == 0 && rvolt == 0)
+#define POKE_FIR(offset)                                                       \
+    {                                                                          \
+        resampler_write_sample_float(resampler->fir_resampler[0],              \
+                                     FIR(x[(offset)*2 + 0]));                  \
+        resampler_write_sample_float(resampler->fir_resampler[1],              \
+                                     FIR(x[(offset)*2 + 1]));                  \
+    }
+#define MONO_DEST_PEEK_FIR                                                     \
+    {                                                                          \
+        *dst =                                                                 \
+            (resampler_get_sample_float(resampler->fir_resampler[0]) * lvol +  \
+             resampler_get_sample_float(resampler->fir_resampler[1]) * rvol) * \
+            16777216.0f;                                                       \
+    }
+#define MONO_DEST_MIX_FIR                                                      \
+    {                                                                          \
+        *dst++ +=                                                              \
+            (resampler_get_sample_float(resampler->fir_resampler[0]) * lvol +  \
+             resampler_get_sample_float(resampler->fir_resampler[1]) * rvol) * \
+            16777216.0f;                                                       \
+        UPDATE_VOLUME(volume_left, lvol);                                      \
+        UPDATE_VOLUME(volume_right, rvol);                                     \
+    }
+#define ADVANCE_FIR                                                            \
+    {                                                                          \
+        resampler_remove_sample(resampler->fir_resampler[0], 1);               \
+        resampler_remove_sample(resampler->fir_resampler[1], 1);               \
+    }
+#define STEREO_DEST_PEEK_FIR                                                   \
+    {                                                                          \
+        *dst++ = resampler_get_sample_float(resampler->fir_resampler[0]) *     \
+                 lvol * 16777216.0f;                                           \
+        *dst++ = resampler_get_sample_float(resampler->fir_resampler[1]) *     \
+                 rvol * 16777216.0f;                                           \
+    }
+#define STEREO_DEST_MIX_FIR                                                    \
+    {                                                                          \
+        *dst++ += resampler_get_sample_float(resampler->fir_resampler[0]) *    \
+                  lvol * 16777216.0f;                                          \
+        *dst++ += resampler_get_sample_float(resampler->fir_resampler[1]) *    \
+                  rvol * 16777216.0f;                                          \
+        UPDATE_VOLUME(volume_left, lvol);                                      \
+        UPDATE_VOLUME(volume_right, rvol);                                     \
+    }
+#include "resamp2.inc"
+
+void dumb_end_resampler(DUMB_RESAMPLER *resampler) {
+    if (resampler)
+        free(resampler);
+}
+
+#undef FIR
+#undef SRCBITS
+#undef SRCTYPE
+#undef SUFFIX
--- /dev/null
+++ b/src/helpers/resampler.c
@@ -1,0 +1,1433 @@
+#include <stdlib.h>
+#include <string.h>
+#define _USE_MATH_DEFINES
+#include <math.h>
+#if defined(_USE_SSE) && (defined(_M_IX86) || defined(__i386__) ||             \
+                          defined(_M_X64) || defined(__amd64__))
+#include <xmmintrin.h>
+#define RESAMPLER_SSE
+#endif
+#ifdef __APPLE__
+#include <TargetConditionals.h>
+#if TARGET_CPU_ARM || TARGET_CPU_ARM64
+#define RESAMPLER_NEON
+#endif
+#elif (defined(__arm__) && defined(__ARM_NEON__)) || defined(_M_ARM)
+#define RESAMPLER_NEON
+#endif
+#ifdef RESAMPLER_NEON
+#include <arm_neon.h>
+#endif
+
+#ifdef _MSC_VER
+#define ALIGNED _declspec(align(16))
+#else
+#define ALIGNED __attribute__((aligned(16)))
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+#include "internal/resampler.h"
+
+enum { RESAMPLER_SHIFT = 10 };
+enum { RESAMPLER_SHIFT_EXTRA = 8 };
+enum { RESAMPLER_RESOLUTION = 1 << RESAMPLER_SHIFT };
+enum {
+    RESAMPLER_RESOLUTION_EXTRA = 1 << (RESAMPLER_SHIFT + RESAMPLER_SHIFT_EXTRA)
+};
+enum { SINC_WIDTH = 16 };
+enum { SINC_SAMPLES = RESAMPLER_RESOLUTION * SINC_WIDTH };
+enum { CUBIC_SAMPLES = RESAMPLER_RESOLUTION * 4 };
+
+static const float RESAMPLER_BLEP_CUTOFF = 0.90f;
+static const float RESAMPLER_BLAM_CUTOFF = 0.93f;
+static const float RESAMPLER_SINC_CUTOFF = 0.999f;
+
+ALIGNED static float cubic_lut[CUBIC_SAMPLES];
+
+static float sinc_lut[SINC_SAMPLES + 1];
+static float window_lut[SINC_SAMPLES + 1];
+
+enum { resampler_buffer_size = SINC_WIDTH * 4 };
+
+static int fEqual(const float b, const float a) { return fabs(a - b) < 1.0e-6; }
+
+static float sinc(float x) {
+    return fEqual(x, 0.0) ? 1.0 : sin(x * M_PI) / (x * M_PI);
+}
+
+#ifdef RESAMPLER_SSE
+#ifdef _MSC_VER
+#include <intrin.h>
+#elif defined(__clang__) || defined(__GNUC__)
+static inline void __cpuid(int *data, int selector) {
+#if defined(__PIC__) && defined(__i386__)
+    __asm("xchgl %%ebx, %%esi; cpuid; xchgl %%ebx, %%esi"
+          : "=a"(data[0]), "=S"(data[1]), "=c"(data[2]), "=d"(data[3])
+          : "0"(selector));
+#elif defined(__PIC__) && defined(__amd64__)
+    __asm("xchg{q} {%%}rbx, %q1; cpuid; xchg{q} {%%}rbx, %q1"
+          : "=a"(data[0]), "=&r"(data[1]), "=c"(data[2]), "=d"(data[3])
+          : "0"(selector));
+#else
+    __asm("cpuid"
+          : "=a"(data[0]), "=b"(data[1]), "=c"(data[2]), "=d"(data[3])
+          : "0"(selector));
+#endif
+}
+#else
+#define __cpuid(a, b) memset((a), 0, sizeof(int) * 4)
+#endif
+
+static int query_cpu_feature_sse() {
+    int buffer[4];
+    __cpuid(buffer, 1);
+    if ((buffer[3] & (1 << 25)) == 0)
+        return 0;
+    return 1;
+}
+
+static int resampler_has_sse = 0;
+#endif
+
+void resampler_init(void) {
+    unsigned i;
+    double dx = (float)(SINC_WIDTH) / SINC_SAMPLES, x = 0.0;
+    for (i = 0; i < SINC_SAMPLES + 1; ++i, x += dx) {
+        float y = x / SINC_WIDTH;
+#if 0
+        // Blackman
+        float window = 0.42659 - 0.49656 * cos(M_PI + M_PI * y) + 0.076849 * cos(2.0 * M_PI * y);
+#elif 1
+        // Nuttal 3 term
+        float window =
+            0.40897 + 0.5 * cos(M_PI * y) + 0.09103 * cos(2.0 * M_PI * y);
+#elif 0
+        // C.R.Helmrich's 2 term window
+        float window =
+            0.79445 * cos(0.5 * M_PI * y) + 0.20555 * cos(1.5 * M_PI * y);
+#elif 0
+        // Lanczos
+        float window = sinc(y);
+#endif
+        sinc_lut[i] = fabs(x) < SINC_WIDTH ? sinc(x) : 0.0;
+        window_lut[i] = window;
+    }
+    dx = 1.0 / (float)(RESAMPLER_RESOLUTION);
+    x = 0.0;
+    for (i = 0; i < RESAMPLER_RESOLUTION; ++i, x += dx) {
+        cubic_lut[i * 4] = (float)(-0.5 * x * x * x + x * x - 0.5 * x);
+        cubic_lut[i * 4 + 1] = (float)(1.5 * x * x * x - 2.5 * x * x + 1.0);
+        cubic_lut[i * 4 + 2] =
+            (float)(-1.5 * x * x * x + 2.0 * x * x + 0.5 * x);
+        cubic_lut[i * 4 + 3] = (float)(0.5 * x * x * x - 0.5 * x * x);
+    }
+#ifdef RESAMPLER_SSE
+    resampler_has_sse = query_cpu_feature_sse();
+#endif
+}
+
+typedef struct resampler {
+    int write_pos, write_filled;
+    int read_pos, read_filled;
+    float phase;
+    float phase_inc;
+    float inv_phase;
+    float inv_phase_inc;
+    unsigned char quality;
+    signed char delay_added;
+    signed char delay_removed;
+    float last_amp;
+    float accumulator;
+    float buffer_in[resampler_buffer_size * 2];
+    float buffer_out[resampler_buffer_size + SINC_WIDTH * 2 - 1];
+} resampler;
+
+void *resampler_create(void) {
+    resampler *r = (resampler *)malloc(sizeof(resampler));
+    if (!r)
+        return 0;
+
+    r->write_pos = SINC_WIDTH - 1;
+    r->write_filled = 0;
+    r->read_pos = 0;
+    r->read_filled = 0;
+    r->phase = 0;
+    r->phase_inc = 0;
+    r->inv_phase = 0;
+    r->inv_phase_inc = 0;
+    r->quality = RESAMPLER_QUALITY_MAX;
+    r->delay_added = -1;
+    r->delay_removed = -1;
+    r->last_amp = 0;
+    r->accumulator = 0;
+    memset(r->buffer_in, 0, sizeof(r->buffer_in));
+    memset(r->buffer_out, 0, sizeof(r->buffer_out));
+
+    return r;
+}
+
+void resampler_delete(void *_r) { free(_r); }
+
+void *resampler_dup(const void *_r) {
+    void *r_out = malloc(sizeof(resampler));
+    if (!r_out)
+        return 0;
+
+    resampler_dup_inplace(r_out, _r);
+
+    return r_out;
+}
+
+void resampler_dup_inplace(void *_d, const void *_s) {
+    const resampler *r_in = (const resampler *)_s;
+    resampler *r_out = (resampler *)_d;
+
+    r_out->write_pos = r_in->write_pos;
+    r_out->write_filled = r_in->write_filled;
+    r_out->read_pos = r_in->read_pos;
+    r_out->read_filled = r_in->read_filled;
+    r_out->phase = r_in->phase;
+    r_out->phase_inc = r_in->phase_inc;
+    r_out->inv_phase = r_in->inv_phase;
+    r_out->inv_phase_inc = r_in->inv_phase_inc;
+    r_out->quality = r_in->quality;
+    r_out->delay_added = r_in->delay_added;
+    r_out->delay_removed = r_in->delay_removed;
+    r_out->last_amp = r_in->last_amp;
+    r_out->accumulator = r_in->accumulator;
+    memcpy(r_out->buffer_in, r_in->buffer_in, sizeof(r_in->buffer_in));
+    memcpy(r_out->buffer_out, r_in->buffer_out, sizeof(r_in->buffer_out));
+}
+
+void resampler_set_quality(void *_r, int quality) {
+    resampler *r = (resampler *)_r;
+    if (quality < RESAMPLER_QUALITY_MIN)
+        quality = RESAMPLER_QUALITY_MIN;
+    else if (quality > RESAMPLER_QUALITY_MAX)
+        quality = RESAMPLER_QUALITY_MAX;
+    if (r->quality != quality) {
+        if (quality == RESAMPLER_QUALITY_BLEP ||
+            r->quality == RESAMPLER_QUALITY_BLEP ||
+            quality == RESAMPLER_QUALITY_BLAM ||
+            r->quality == RESAMPLER_QUALITY_BLAM) {
+            r->read_pos = 0;
+            r->read_filled = 0;
+            r->last_amp = 0;
+            r->accumulator = 0;
+            memset(r->buffer_out, 0, sizeof(r->buffer_out));
+        }
+        r->delay_added = -1;
+        r->delay_removed = -1;
+    }
+    r->quality = (unsigned char)quality;
+}
+
+int resampler_get_free_count(void *_r) {
+    resampler *r = (resampler *)_r;
+    return resampler_buffer_size - r->write_filled;
+}
+
+static int resampler_min_filled(resampler *r) {
+    switch (r->quality) {
+    default:
+    case RESAMPLER_QUALITY_ZOH:
+    case RESAMPLER_QUALITY_BLEP:
+        return 1;
+
+    case RESAMPLER_QUALITY_LINEAR:
+    case RESAMPLER_QUALITY_BLAM:
+        return 2;
+
+    case RESAMPLER_QUALITY_CUBIC:
+        return 4;
+
+    case RESAMPLER_QUALITY_SINC:
+        return SINC_WIDTH * 2;
+    }
+}
+
+static int resampler_input_delay(resampler *r) {
+    switch (r->quality) {
+    default:
+    case RESAMPLER_QUALITY_ZOH:
+    case RESAMPLER_QUALITY_BLEP:
+    case RESAMPLER_QUALITY_LINEAR:
+    case RESAMPLER_QUALITY_BLAM:
+        return 0;
+
+    case RESAMPLER_QUALITY_CUBIC:
+        return 1;
+
+    case RESAMPLER_QUALITY_SINC:
+        return SINC_WIDTH - 1;
+    }
+}
+
+static int resampler_output_delay(resampler *r) {
+    switch (r->quality) {
+    default:
+    case RESAMPLER_QUALITY_ZOH:
+    case RESAMPLER_QUALITY_LINEAR:
+    case RESAMPLER_QUALITY_CUBIC:
+    case RESAMPLER_QUALITY_SINC:
+        return 0;
+
+    case RESAMPLER_QUALITY_BLEP:
+    case RESAMPLER_QUALITY_BLAM:
+        return SINC_WIDTH - 1;
+    }
+}
+
+int resampler_ready(void *_r) {
+    resampler *r = (resampler *)_r;
+    return r->write_filled > resampler_min_filled(r);
+}
+
+void resampler_clear(void *_r) {
+    resampler *r = (resampler *)_r;
+    r->write_pos = SINC_WIDTH - 1;
+    r->write_filled = 0;
+    r->read_pos = 0;
+    r->read_filled = 0;
+    r->phase = 0;
+    r->delay_added = -1;
+    r->delay_removed = -1;
+    memset(r->buffer_in, 0, (SINC_WIDTH - 1) * sizeof(r->buffer_in[0]));
+    memset(r->buffer_in + resampler_buffer_size, 0,
+           (SINC_WIDTH - 1) * sizeof(r->buffer_in[0]));
+    if (r->quality == RESAMPLER_QUALITY_BLEP ||
+        r->quality == RESAMPLER_QUALITY_BLAM) {
+        r->inv_phase = 0;
+        r->last_amp = 0;
+        r->accumulator = 0;
+        memset(r->buffer_out, 0, sizeof(r->buffer_out));
+    }
+}
+
+void resampler_set_rate(void *_r, double new_factor) {
+    resampler *r = (resampler *)_r;
+    r->phase_inc = new_factor;
+    new_factor = 1.0 / new_factor;
+    r->inv_phase_inc = new_factor;
+}
+
+void resampler_write_sample(void *_r, short s) {
+    resampler *r = (resampler *)_r;
+
+    if (r->delay_added < 0) {
+        r->delay_added = 0;
+        r->write_filled = resampler_input_delay(r);
+    }
+
+    if (r->write_filled < resampler_buffer_size) {
+        float s32 = s;
+        s32 *= 256.0;
+
+        r->buffer_in[r->write_pos] = s32;
+        r->buffer_in[r->write_pos + resampler_buffer_size] = s32;
+
+        ++r->write_filled;
+
+        r->write_pos = (r->write_pos + 1) % resampler_buffer_size;
+    }
+}
+
+void resampler_write_sample_fixed(void *_r, int s, unsigned char depth) {
+    resampler *r = (resampler *)_r;
+
+    if (r->delay_added < 0) {
+        r->delay_added = 0;
+        r->write_filled = resampler_input_delay(r);
+    }
+
+    if (r->write_filled < resampler_buffer_size) {
+        float s32 = s;
+        s32 /= (double)(1 << (depth - 1));
+
+        r->buffer_in[r->write_pos] = s32;
+        r->buffer_in[r->write_pos + resampler_buffer_size] = s32;
+
+        ++r->write_filled;
+
+        r->write_pos = (r->write_pos + 1) % resampler_buffer_size;
+    }
+}
+
+void resampler_write_sample_float(void *_r, float s) {
+    resampler *r = (resampler *)_r;
+
+    if (r->delay_added < 0) {
+        r->delay_added = 0;
+        r->write_filled = resampler_input_delay(r);
+    }
+
+    if (r->write_filled < resampler_buffer_size) {
+        r->buffer_in[r->write_pos] = s;
+        r->buffer_in[r->write_pos + resampler_buffer_size] = s;
+
+        ++r->write_filled;
+
+        r->write_pos = (r->write_pos + 1) % resampler_buffer_size;
+    }
+}
+
+static int resampler_run_zoh(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 1;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        do {
+            float sample;
+
+            if (out >= out_end)
+                break;
+
+            sample = *in;
+            *out++ = sample;
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+
+#ifndef RESAMPLER_NEON
+static int resampler_run_blep(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 1;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float last_amp = r->last_amp;
+        float inv_phase = r->inv_phase;
+        float inv_phase_inc = r->inv_phase_inc;
+
+        const int step = RESAMPLER_BLEP_CUTOFF * RESAMPLER_RESOLUTION;
+        const int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            float sample;
+
+            if (out + SINC_WIDTH * 2 > out_end)
+                break;
+
+            sample = *in++ - last_amp;
+
+            if (sample) {
+                float kernel[SINC_WIDTH * 2], kernel_sum = 0.0f;
+                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
+                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+                int i = SINC_WIDTH;
+
+                for (; i >= -SINC_WIDTH + 1; --i) {
+                    int pos = i * step;
+                    int window_pos = i * window_step;
+                    kernel_sum += kernel[i + SINC_WIDTH - 1] =
+                        sinc_lut[abs(phase_adj - pos)] *
+                        window_lut[abs(phase_reduced - window_pos)];
+                }
+                last_amp += sample;
+                sample /= kernel_sum;
+                for (i = 0; i < SINC_WIDTH * 2; ++i)
+                    out[i] += sample * kernel[i];
+            }
+
+            inv_phase += inv_phase_inc;
+
+            out += (int)inv_phase;
+
+            inv_phase = fmod(inv_phase, 1.0f);
+        } while (in < in_end);
+
+        r->inv_phase = inv_phase;
+        r->last_amp = last_amp;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_SSE
+static int resampler_run_blep_sse(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 1;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float last_amp = r->last_amp;
+        float inv_phase = r->inv_phase;
+        float inv_phase_inc = r->inv_phase_inc;
+
+        const int step = RESAMPLER_BLEP_CUTOFF * RESAMPLER_RESOLUTION;
+        const int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            float sample;
+
+            if (out + SINC_WIDTH * 2 > out_end)
+                break;
+
+            sample = *in++ - last_amp;
+
+            if (sample) {
+                float kernel_sum = 0.0f;
+                __m128 kernel[SINC_WIDTH / 2];
+                __m128 temp1, temp2;
+                __m128 samplex;
+                float *kernelf = (float *)(&kernel);
+                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
+                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+                int i = SINC_WIDTH;
+
+                for (; i >= -SINC_WIDTH + 1; --i) {
+                    int pos = i * step;
+                    int window_pos = i * window_step;
+                    kernel_sum += kernelf[i + SINC_WIDTH - 1] =
+                        sinc_lut[abs(phase_adj - pos)] *
+                        window_lut[abs(phase_reduced - window_pos)];
+                }
+                last_amp += sample;
+                sample /= kernel_sum;
+                samplex = _mm_set1_ps(sample);
+                for (i = 0; i < SINC_WIDTH / 2; ++i) {
+                    temp1 = _mm_load_ps((const float *)(kernel + i));
+                    temp1 = _mm_mul_ps(temp1, samplex);
+                    temp2 = _mm_loadu_ps((const float *)out + i * 4);
+                    temp1 = _mm_add_ps(temp1, temp2);
+                    _mm_storeu_ps((float *)out + i * 4, temp1);
+                }
+            }
+
+            inv_phase += inv_phase_inc;
+
+            out += (int)inv_phase;
+
+            inv_phase = fmod(inv_phase, 1.0f);
+        } while (in < in_end);
+
+        r->inv_phase = inv_phase;
+        r->last_amp = last_amp;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_NEON
+static int resampler_run_blep(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 1;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float last_amp = r->last_amp;
+        float inv_phase = r->inv_phase;
+        float inv_phase_inc = r->inv_phase_inc;
+
+        const int step = RESAMPLER_BLEP_CUTOFF * RESAMPLER_RESOLUTION;
+        const int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            float sample;
+
+            if (out + SINC_WIDTH * 2 > out_end)
+                break;
+
+            sample = *in++ - last_amp;
+
+            if (sample) {
+                float kernel_sum = 0.0f;
+                float32x4_t kernel[SINC_WIDTH / 2];
+                float32x4_t temp1, temp2;
+                float32x4_t samplex;
+                float *kernelf = (float *)(&kernel);
+                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
+                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+                int i = SINC_WIDTH;
+
+                for (; i >= -SINC_WIDTH + 1; --i) {
+                    int pos = i * step;
+                    int window_pos = i * window_step;
+                    kernel_sum += kernelf[i + SINC_WIDTH - 1] =
+                        sinc_lut[abs(phase_adj - pos)] *
+                        window_lut[abs(phase_reduced - window_pos)];
+                }
+                last_amp += sample;
+                sample /= kernel_sum;
+                samplex = vdupq_n_f32(sample);
+                for (i = 0; i < SINC_WIDTH / 2; ++i) {
+                    temp1 = vld1q_f32((const float32_t *)(kernel + i));
+                    temp2 = vld1q_f32((const float32_t *)out + i * 4);
+                    temp2 = vmlaq_f32(temp2, temp1, samplex);
+                    vst1q_f32((float32_t *)out + i * 4, temp2);
+                }
+            }
+
+            inv_phase += inv_phase_inc;
+
+            out += (int)inv_phase;
+
+            inv_phase = fmod(inv_phase, 1.0f);
+        } while (in < in_end);
+
+        r->inv_phase = inv_phase;
+        r->last_amp = last_amp;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+static int resampler_run_linear(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 2;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        do {
+            float sample;
+
+            if (out >= out_end)
+                break;
+
+            sample = in[0] + (in[1] - in[0]) * phase;
+            *out++ = sample;
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+
+#ifndef RESAMPLER_NEON
+static int resampler_run_blam(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 2;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float last_amp = r->last_amp;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+        float inv_phase = r->inv_phase;
+        float inv_phase_inc = r->inv_phase_inc;
+
+        const int step = RESAMPLER_BLAM_CUTOFF * RESAMPLER_RESOLUTION;
+        const int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            float sample;
+
+            if (out + SINC_WIDTH * 2 > out_end)
+                break;
+
+            sample = in[0];
+            if (phase_inc < 1.0f)
+                sample += (in[1] - in[0]) * phase;
+            sample -= last_amp;
+
+            if (sample) {
+                float kernel[SINC_WIDTH * 2], kernel_sum = 0.0f;
+                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
+                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+                int i = SINC_WIDTH;
+
+                for (; i >= -SINC_WIDTH + 1; --i) {
+                    int pos = i * step;
+                    int window_pos = i * window_step;
+                    kernel_sum += kernel[i + SINC_WIDTH - 1] =
+                        sinc_lut[abs(phase_adj - pos)] *
+                        window_lut[abs(phase_reduced - window_pos)];
+                }
+                last_amp += sample;
+                sample /= kernel_sum;
+                for (i = 0; i < SINC_WIDTH * 2; ++i)
+                    out[i] += sample * kernel[i];
+            }
+
+            if (inv_phase_inc < 1.0f) {
+                ++in;
+                inv_phase += inv_phase_inc;
+                out += (int)inv_phase;
+                inv_phase = fmod(inv_phase, 1.0f);
+            } else {
+                phase += phase_inc;
+                ++out;
+                in += (int)phase;
+                phase = fmod(phase, 1.0f);
+            }
+        } while (in < in_end);
+
+        r->phase = phase;
+        r->inv_phase = inv_phase;
+        r->last_amp = last_amp;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_SSE
+static int resampler_run_blam_sse(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 2;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float last_amp = r->last_amp;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+        float inv_phase = r->inv_phase;
+        float inv_phase_inc = r->inv_phase_inc;
+
+        const int step = RESAMPLER_BLAM_CUTOFF * RESAMPLER_RESOLUTION;
+        const int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            float sample;
+
+            if (out + SINC_WIDTH * 2 > out_end)
+                break;
+
+            sample = in[0];
+            if (phase_inc < 1.0f) {
+                sample += (in[1] - in[0]) * phase;
+            }
+            sample -= last_amp;
+
+            if (sample) {
+                float kernel_sum = 0.0f;
+                __m128 kernel[SINC_WIDTH / 2];
+                __m128 temp1, temp2;
+                __m128 samplex;
+                float *kernelf = (float *)(&kernel);
+                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
+                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+                int i = SINC_WIDTH;
+
+                for (; i >= -SINC_WIDTH + 1; --i) {
+                    int pos = i * step;
+                    int window_pos = i * window_step;
+                    kernel_sum += kernelf[i + SINC_WIDTH - 1] =
+                        sinc_lut[abs(phase_adj - pos)] *
+                        window_lut[abs(phase_reduced - window_pos)];
+                }
+                last_amp += sample;
+                sample /= kernel_sum;
+                samplex = _mm_set1_ps(sample);
+                for (i = 0; i < SINC_WIDTH / 2; ++i) {
+                    temp1 = _mm_load_ps((const float *)(kernel + i));
+                    temp1 = _mm_mul_ps(temp1, samplex);
+                    temp2 = _mm_loadu_ps((const float *)out + i * 4);
+                    temp1 = _mm_add_ps(temp1, temp2);
+                    _mm_storeu_ps((float *)out + i * 4, temp1);
+                }
+            }
+
+            if (inv_phase_inc < 1.0f) {
+                ++in;
+                inv_phase += inv_phase_inc;
+                out += (int)inv_phase;
+                inv_phase = fmod(inv_phase, 1.0f);
+            } else {
+                phase += phase_inc;
+                ++out;
+
+                if (phase >= 1.0f) {
+                    ++in;
+                    phase = fmod(phase, 1.0f);
+                }
+            }
+        } while (in < in_end);
+
+        r->phase = phase;
+        r->inv_phase = inv_phase;
+        r->last_amp = last_amp;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_NEON
+static int resampler_run_blam(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 2;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float last_amp = r->last_amp;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+        float inv_phase = r->inv_phase;
+        float inv_phase_inc = r->inv_phase_inc;
+
+        const int step = RESAMPLER_BLAM_CUTOFF * RESAMPLER_RESOLUTION;
+        const int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            float sample;
+
+            if (out + SINC_WIDTH * 2 > out_end)
+                break;
+
+            sample = in[0];
+            if (phase_inc < 1.0f)
+                sample += (in[1] - in[0]) * phase;
+            sample -= last_amp;
+
+            if (sample) {
+                float kernel_sum = 0.0;
+                float32x4_t kernel[SINC_WIDTH / 2];
+                float32x4_t temp1, temp2;
+                float32x4_t samplex;
+                float *kernelf = (float *)(&kernel);
+                int phase_reduced = (int)(inv_phase * RESAMPLER_RESOLUTION);
+                int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+                int i = SINC_WIDTH;
+
+                for (; i >= -SINC_WIDTH + 1; --i) {
+                    int pos = i * step;
+                    int window_pos = i * window_step;
+                    kernel_sum += kernelf[i + SINC_WIDTH - 1] =
+                        sinc_lut[abs(phase_adj - pos)] *
+                        window_lut[abs(phase_reduced - window_pos)];
+                }
+                last_amp += sample;
+                sample /= kernel_sum;
+                samplex = vdupq_n_f32(sample);
+                for (i = 0; i < SINC_WIDTH / 2; ++i) {
+                    temp1 = vld1q_f32((const float32_t *)(kernel + i));
+                    temp2 = vld1q_f32((const float32_t *)out + i * 4);
+                    temp2 = vmlaq_f32(temp2, temp1, samplex);
+                    vst1q_f32((float32_t *)out + i * 4, temp2);
+                }
+            }
+
+            if (inv_phase_inc < 1.0f) {
+                ++in;
+                inv_phase += inv_phase_inc;
+                out += (int)inv_phase;
+                inv_phase = fmod(inv_phase, 1.0f);
+            } else {
+                phase += phase_inc;
+                ++out;
+
+                if (phase >= 1.0f) {
+                    ++in;
+                    phase = fmod(phase, 1.0f);
+                }
+            }
+        } while (in < in_end);
+
+        r->phase = phase;
+        r->inv_phase = inv_phase;
+        r->last_amp = last_amp;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifndef RESAMPLER_NEON
+static int resampler_run_cubic(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 4;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        do {
+            float *kernel;
+            int i;
+            float sample;
+
+            if (out >= out_end)
+                break;
+
+            kernel = cubic_lut + (int)(phase * RESAMPLER_RESOLUTION) * 4;
+
+            for (sample = 0, i = 0; i < 4; ++i)
+                sample += in[i] * kernel[i];
+            *out++ = sample;
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_SSE
+static int resampler_run_cubic_sse(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 4;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        do {
+            __m128 temp1, temp2;
+            __m128 samplex = _mm_setzero_ps();
+
+            if (out >= out_end)
+                break;
+
+            temp1 = _mm_loadu_ps((const float *)(in));
+            temp2 = _mm_load_ps(
+                (const float *)(cubic_lut +
+                                (int)(phase * RESAMPLER_RESOLUTION) * 4));
+            temp1 = _mm_mul_ps(temp1, temp2);
+            samplex = _mm_add_ps(samplex, temp1);
+            temp1 = _mm_movehl_ps(temp1, samplex);
+            samplex = _mm_add_ps(samplex, temp1);
+            temp1 = samplex;
+            temp1 = _mm_shuffle_ps(temp1, samplex, _MM_SHUFFLE(0, 0, 0, 1));
+            samplex = _mm_add_ps(samplex, temp1);
+            _mm_store_ss(out, samplex);
+            ++out;
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_NEON
+static int resampler_run_cubic(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= 4;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        do {
+            float32x4_t temp1, temp2;
+            float32x2_t half;
+
+            if (out >= out_end)
+                break;
+
+            temp1 = vld1q_f32((const float32_t *)(in));
+            temp2 = vld1q_f32(
+                (const float32_t *)(cubic_lut +
+                                    (int)(phase * RESAMPLER_RESOLUTION) * 4));
+            temp1 = vmulq_f32(temp1, temp2);
+            half = vadd_f32(vget_high_f32(temp1), vget_low_f32(temp1));
+            *out++ = vget_lane_f32(vpadd_f32(half, half), 0);
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifndef RESAMPLER_NEON
+static int resampler_run_sinc(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= SINC_WIDTH * 2;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        int step = phase_inc > 1.0f
+                       ? (int)(RESAMPLER_RESOLUTION / phase_inc *
+                               RESAMPLER_SINC_CUTOFF)
+                       : (int)(RESAMPLER_RESOLUTION * RESAMPLER_SINC_CUTOFF);
+        int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            float kernel[SINC_WIDTH * 2], kernel_sum = 0.0;
+            int i = SINC_WIDTH;
+            int phase_reduced = (int)(phase * RESAMPLER_RESOLUTION);
+            int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+            float sample;
+
+            if (out >= out_end)
+                break;
+
+            for (; i >= -SINC_WIDTH + 1; --i) {
+                int pos = i * step;
+                int window_pos = i * window_step;
+                kernel_sum += kernel[i + SINC_WIDTH - 1] =
+                    sinc_lut[abs(phase_adj - pos)] *
+                    window_lut[abs(phase_reduced - window_pos)];
+            }
+            for (sample = 0, i = 0; i < SINC_WIDTH * 2; ++i)
+                sample += in[i] * kernel[i];
+            *out++ = (float)(sample / kernel_sum);
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_SSE
+static int resampler_run_sinc_sse(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= SINC_WIDTH * 2;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        int step = phase_inc > 1.0f
+                       ? (int)(RESAMPLER_RESOLUTION / phase_inc *
+                               RESAMPLER_SINC_CUTOFF)
+                       : (int)(RESAMPLER_RESOLUTION * RESAMPLER_SINC_CUTOFF);
+        int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            // accumulate in extended precision
+            float kernel_sum = 0.0;
+            __m128 kernel[SINC_WIDTH / 2];
+            __m128 temp1, temp2;
+            __m128 samplex = _mm_setzero_ps();
+            float *kernelf = (float *)(&kernel);
+            int i = SINC_WIDTH;
+            int phase_reduced = (int)(phase * RESAMPLER_RESOLUTION);
+            int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+
+            if (out >= out_end)
+                break;
+
+            for (; i >= -SINC_WIDTH + 1; --i) {
+                int pos = i * step;
+                int window_pos = i * window_step;
+                kernel_sum += kernelf[i + SINC_WIDTH - 1] =
+                    sinc_lut[abs(phase_adj - pos)] *
+                    window_lut[abs(phase_reduced - window_pos)];
+            }
+            for (i = 0; i < SINC_WIDTH / 2; ++i) {
+                temp1 = _mm_loadu_ps((const float *)(in + i * 4));
+                temp2 = _mm_load_ps((const float *)(kernel + i));
+                temp1 = _mm_mul_ps(temp1, temp2);
+                samplex = _mm_add_ps(samplex, temp1);
+            }
+            kernel_sum = 1.0 / kernel_sum;
+            temp1 = _mm_movehl_ps(temp1, samplex);
+            samplex = _mm_add_ps(samplex, temp1);
+            temp1 = samplex;
+            temp1 = _mm_shuffle_ps(temp1, samplex, _MM_SHUFFLE(0, 0, 0, 1));
+            samplex = _mm_add_ps(samplex, temp1);
+            temp1 = _mm_set_ss(kernel_sum);
+            samplex = _mm_mul_ps(samplex, temp1);
+            _mm_store_ss(out, samplex);
+            ++out;
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+#ifdef RESAMPLER_NEON
+static int resampler_run_sinc(resampler *r, float **out_, float *out_end) {
+    int in_size = r->write_filled;
+    float const *in_ =
+        r->buffer_in + resampler_buffer_size + r->write_pos - r->write_filled;
+    int used = 0;
+    in_size -= SINC_WIDTH * 2;
+    if (in_size > 0) {
+        float *out = *out_;
+        float const *in = in_;
+        float const *const in_end = in + in_size;
+        float phase = r->phase;
+        float phase_inc = r->phase_inc;
+
+        int step = phase_inc > 1.0f
+                       ? (int)(RESAMPLER_RESOLUTION / phase_inc *
+                               RESAMPLER_SINC_CUTOFF)
+                       : (int)(RESAMPLER_RESOLUTION * RESAMPLER_SINC_CUTOFF);
+        int window_step = RESAMPLER_RESOLUTION;
+
+        do {
+            // accumulate in extended precision
+            float kernel_sum = 0.0;
+            float32x4_t kernel[SINC_WIDTH / 2];
+            float32x4_t temp1, temp2;
+            float32x4_t samplex = {0};
+            float32x2_t half;
+            float *kernelf = (float *)(&kernel);
+            int i = SINC_WIDTH;
+            int phase_reduced = (int)(phase * RESAMPLER_RESOLUTION);
+            int phase_adj = phase_reduced * step / RESAMPLER_RESOLUTION;
+
+            if (out >= out_end)
+                break;
+
+            for (; i >= -SINC_WIDTH + 1; --i) {
+                int pos = i * step;
+                int window_pos = i * window_step;
+                kernel_sum += kernelf[i + SINC_WIDTH - 1] =
+                    sinc_lut[abs(phase_adj - pos)] *
+                    window_lut[abs(phase_reduced - window_pos)];
+            }
+            for (i = 0; i < SINC_WIDTH / 2; ++i) {
+                temp1 = vld1q_f32((const float32_t *)(in + i * 4));
+                temp2 = vld1q_f32((const float32_t *)(kernel + i));
+                samplex = vmlaq_f32(samplex, temp1, temp2);
+            }
+            kernel_sum = 1.0 / kernel_sum;
+            samplex = vmulq_f32(samplex, vmovq_n_f32(kernel_sum));
+            half = vadd_f32(vget_high_f32(samplex), vget_low_f32(samplex));
+            *out++ = vget_lane_f32(vpadd_f32(half, half), 0);
+
+            phase += phase_inc;
+
+            in += (int)phase;
+
+            phase = fmod(phase, 1.0f);
+        } while (in < in_end);
+
+        r->phase = phase;
+        *out_ = out;
+
+        used = (int)(in - in_);
+
+        r->write_filled -= used;
+    }
+
+    return used;
+}
+#endif
+
+static void resampler_fill(resampler *r) {
+    int min_filled = resampler_min_filled(r);
+    int quality = r->quality;
+    while (r->write_filled > min_filled &&
+           r->read_filled < resampler_buffer_size) {
+        int write_pos = (r->read_pos + r->read_filled) % resampler_buffer_size;
+        int write_size = resampler_buffer_size - write_pos;
+        float *out = r->buffer_out + write_pos;
+        if (write_size > (resampler_buffer_size - r->read_filled))
+            write_size = resampler_buffer_size - r->read_filled;
+        switch (quality) {
+        case RESAMPLER_QUALITY_ZOH:
+            resampler_run_zoh(r, &out, out + write_size);
+            break;
+
+        case RESAMPLER_QUALITY_BLEP: {
+            int used;
+            int write_extra = 0;
+            if (write_pos >= r->read_pos)
+                write_extra = r->read_pos;
+            if (write_extra > SINC_WIDTH * 2 - 1)
+                write_extra = SINC_WIDTH * 2 - 1;
+            memcpy(r->buffer_out + resampler_buffer_size, r->buffer_out,
+                   write_extra * sizeof(r->buffer_out[0]));
+#ifdef RESAMPLER_SSE
+            if (resampler_has_sse)
+                used = resampler_run_blep_sse(r, &out,
+                                              out + write_size + write_extra);
+            else
+#endif
+                used =
+                    resampler_run_blep(r, &out, out + write_size + write_extra);
+            memcpy(r->buffer_out, r->buffer_out + resampler_buffer_size,
+                   write_extra * sizeof(r->buffer_out[0]));
+            if (!used)
+                return;
+            break;
+        }
+
+        case RESAMPLER_QUALITY_LINEAR:
+            resampler_run_linear(r, &out, out + write_size);
+            break;
+
+        case RESAMPLER_QUALITY_BLAM: {
+            float *out_ = out;
+            int write_extra = 0;
+            if (write_pos >= r->read_pos)
+                write_extra = r->read_pos;
+            if (write_extra > SINC_WIDTH * 2 - 1)
+                write_extra = SINC_WIDTH * 2 - 1;
+            memcpy(r->buffer_out + resampler_buffer_size, r->buffer_out,
+                   write_extra * sizeof(r->buffer_out[0]));
+#ifdef RESAMPLER_SSE
+            if (resampler_has_sse)
+                resampler_run_blam_sse(r, &out, out + write_size + write_extra);
+            else
+#endif
+                resampler_run_blam(r, &out, out + write_size + write_extra);
+            memcpy(r->buffer_out, r->buffer_out + resampler_buffer_size,
+                   write_extra * sizeof(r->buffer_out[0]));
+            if (out == out_)
+                return;
+            break;
+        }
+
+        case RESAMPLER_QUALITY_CUBIC:
+#ifdef RESAMPLER_SSE
+            if (resampler_has_sse)
+                resampler_run_cubic_sse(r, &out, out + write_size);
+            else
+#endif
+                resampler_run_cubic(r, &out, out + write_size);
+            break;
+
+        case RESAMPLER_QUALITY_SINC:
+#ifdef RESAMPLER_SSE
+            if (resampler_has_sse)
+                resampler_run_sinc_sse(r, &out, out + write_size);
+            else
+#endif
+                resampler_run_sinc(r, &out, out + write_size);
+            break;
+        }
+        r->read_filled += out - r->buffer_out - write_pos;
+    }
+}
+
+static void resampler_fill_and_remove_delay(resampler *r) {
+    resampler_fill(r);
+    if (r->delay_removed < 0) {
+        int delay = resampler_output_delay(r);
+        r->delay_removed = 0;
+        while (delay--)
+            resampler_remove_sample(r, 1);
+    }
+}
+
+int resampler_get_sample_count(void *_r) {
+    resampler *r = (resampler *)_r;
+    if (r->read_filled < 1 && ((r->quality != RESAMPLER_QUALITY_BLEP &&
+                                r->quality != RESAMPLER_QUALITY_BLAM) ||
+                               r->inv_phase_inc))
+        resampler_fill_and_remove_delay(r);
+    return r->read_filled;
+}
+
+int resampler_get_sample(void *_r) {
+    resampler *r = (resampler *)_r;
+    if (r->read_filled < 1 && r->phase_inc)
+        resampler_fill_and_remove_delay(r);
+    if (r->read_filled < 1)
+        return 0;
+    if (r->quality == RESAMPLER_QUALITY_BLEP ||
+        r->quality == RESAMPLER_QUALITY_BLAM)
+        return (int)(r->buffer_out[r->read_pos] + r->accumulator);
+    else
+        return (int)r->buffer_out[r->read_pos];
+}
+
+float resampler_get_sample_float(void *_r) {
+    resampler *r = (resampler *)_r;
+    if (r->read_filled < 1 && r->phase_inc)
+        resampler_fill_and_remove_delay(r);
+    if (r->read_filled < 1)
+        return 0;
+    if (r->quality == RESAMPLER_QUALITY_BLEP ||
+        r->quality == RESAMPLER_QUALITY_BLAM)
+        return r->buffer_out[r->read_pos] + r->accumulator;
+    else
+        return r->buffer_out[r->read_pos];
+}
+
+void resampler_remove_sample(void *_r, int decay) {
+    resampler *r = (resampler *)_r;
+    if (r->read_filled > 0) {
+        if (r->quality == RESAMPLER_QUALITY_BLEP ||
+            r->quality == RESAMPLER_QUALITY_BLAM) {
+            r->accumulator += r->buffer_out[r->read_pos];
+            r->buffer_out[r->read_pos] = 0;
+            if (decay) {
+                r->accumulator -= r->accumulator * (1.0f / 8192.0f);
+                if (fabs(r->accumulator) < 1e-20f)
+                    r->accumulator = 0;
+            }
+        }
+        --r->read_filled;
+        r->read_pos = (r->read_pos + 1) % resampler_buffer_size;
+    }
+}
--- /dev/null
+++ b/src/helpers/riff.c
@@ -1,0 +1,88 @@
+#include "dumb.h"
+#include "internal/riff.h"
+
+#include <stdlib.h>
+
+struct riff *riff_parse(DUMBFILE *f, long offset, long size, unsigned proper) {
+    unsigned stream_size;
+    struct riff *stream;
+
+    if (size < 8)
+        return 0;
+
+    if (dumbfile_seek(f, offset, DFS_SEEK_SET))
+        return 0;
+    if (dumbfile_mgetl(f) != DUMB_ID('R', 'I', 'F', 'F'))
+        return 0;
+
+    stream_size = (int)dumbfile_igetl(f);
+    if (stream_size + 8 > size)
+        return 0;
+    if (stream_size < 4)
+        return 0;
+
+    stream = (struct riff *)malloc(sizeof(struct riff));
+    if (!stream)
+        return 0;
+
+    stream->type = (int)dumbfile_mgetl(f);
+    stream->chunk_count = 0;
+    stream->chunks = 0;
+
+    stream_size -= 4;
+
+    while (stream_size && !dumbfile_error(f)) {
+        struct riff_chunk *chunk;
+        if (stream_size < 8)
+            break;
+        stream->chunks = (struct riff_chunk *)realloc(
+            stream->chunks,
+            (stream->chunk_count + 1) * sizeof(struct riff_chunk));
+        if (!stream->chunks)
+            break;
+        chunk = stream->chunks + stream->chunk_count;
+        chunk->type = (int)dumbfile_mgetl(f);
+        chunk->size = (int)dumbfile_igetl(f);
+        chunk->offset = dumbfile_pos(f);
+        stream_size -= 8;
+        if (stream_size < chunk->size)
+            break;
+        if (chunk->type == DUMB_ID('R', 'I', 'F', 'F')) {
+            chunk->nested =
+                riff_parse(f, chunk->offset - 8, chunk->size + 8, proper);
+            if (!chunk->nested)
+                break;
+        } else {
+            chunk->nested = 0;
+        }
+        dumbfile_seek(f, chunk->offset + chunk->size, DFS_SEEK_SET);
+        stream_size -= chunk->size;
+        if (proper && (chunk->size & 1)) {
+            dumbfile_skip(f, 1);
+            --stream_size;
+        }
+        ++stream->chunk_count;
+    }
+
+    if (stream_size) {
+        riff_free(stream);
+        stream = 0;
+    }
+
+    return stream;
+}
+
+void riff_free(struct riff *stream) {
+    if (stream) {
+        if (stream->chunks) {
+            unsigned i;
+            for (i = 0; i < stream->chunk_count; ++i) {
+                struct riff_chunk *chunk = stream->chunks + i;
+                if (chunk->nested)
+                    riff_free(chunk->nested);
+            }
+            free(stream->chunks);
+        }
+        free(stream);
+    }
+}
--- /dev/null
+++ b/src/helpers/sampbuf.c
@@ -1,0 +1,43 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * sampbuf.c - Helper for allocating sample           / / \  \
+ *             buffers.                              | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include "dumb.h"
+
+sample_t **allocate_sample_buffer(int n_channels, long length) {
+    int i;
+    sample_t **samples = malloc(((n_channels + 1) >> 1) * sizeof(*samples));
+    if (!samples)
+        return NULL;
+    samples[0] = malloc(n_channels * length * sizeof(*samples[0]));
+    if (!samples[0]) {
+        free(samples);
+        return NULL;
+    }
+    for (i = 1; i<(n_channels + 1)>> 1; i++)
+        samples[i] = samples[i - 1] + length * 2;
+    return samples;
+}
+
+void destroy_sample_buffer(sample_t **samples) {
+    if (samples) {
+        free(samples[0]);
+        free(samples);
+    }
+}
--- /dev/null
+++ b/src/helpers/silence.c
@@ -1,0 +1,25 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * silence.c - Silencing helper.                      / / \  \
+ *                                                   | <  /   \_
+ * By entheh.                                        |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <string.h>
+#include "dumb.h"
+
+void dumb_silence(sample_t *samples, long length) {
+    memset(samples, 0, length * sizeof(*samples));
+}
--- /dev/null
+++ b/src/helpers/stdfile.c
@@ -1,0 +1,113 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * stdfile.c - stdio file input module.               / / \  \
+ *                                                   | <  /   \_
+ * By entheh.                                        |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdio.h>
+
+#include "dumb.h"
+
+typedef struct dumb_stdfile {
+    FILE *file;
+    dumb_off_t size;
+} dumb_stdfile;
+
+static void *dumb_stdfile_open(const char *filename) {
+    dumb_stdfile *file = (dumb_stdfile *)malloc(sizeof(dumb_stdfile));
+    if (!file)
+        return 0;
+    file->file = fopen(filename, "rb");
+    if (!file->file) {
+        free(file);
+        return 0;
+    }
+    fseek(file->file, 0, SEEK_END);
+    file->size = ftell(file->file);
+    if (file->size < 0) {
+        fclose(file->file);
+        free(file);
+        return 0;
+    }
+    fseek(file->file, 0, SEEK_SET);
+    return file;
+}
+
+static int dumb_stdfile_skip(void *f, dumb_off_t n) {
+    dumb_stdfile *file = (dumb_stdfile *)f;
+    return fseek(file->file, n, SEEK_CUR);
+}
+
+static int dumb_stdfile_getc(void *f) {
+    dumb_stdfile *file = (dumb_stdfile *)f;
+    return fgetc(file->file);
+}
+
+static dumb_ssize_t dumb_stdfile_getnc(char *ptr, size_t n, void *f) {
+    dumb_stdfile *file = (dumb_stdfile *)f;
+    return fread(ptr, 1, n, file->file);
+}
+
+static void dumb_stdfile_close(void *f) {
+    dumb_stdfile *file = (dumb_stdfile *)f;
+    fclose(file->file);
+    free(f);
+}
+
+static void dumb_stdfile_noclose(void *f) { free(f); }
+
+static int dumb_stdfile_seek(void *f, dumb_off_t n) {
+    dumb_stdfile *file = (dumb_stdfile *)f;
+    return fseek(file->file, n, SEEK_SET);
+}
+
+static dumb_off_t dumb_stdfile_get_size(void *f) {
+    dumb_stdfile *file = (dumb_stdfile *)f;
+    return file->size;
+}
+
+static const DUMBFILE_SYSTEM stdfile_dfs = {
+    &dumb_stdfile_open,    &dumb_stdfile_skip,  &dumb_stdfile_getc,
+    &dumb_stdfile_getnc,   &dumb_stdfile_close, &dumb_stdfile_seek,
+    &dumb_stdfile_get_size};
+
+void dumb_register_stdfiles(void) { register_dumbfile_system(&stdfile_dfs); }
+
+static const DUMBFILE_SYSTEM stdfile_dfs_leave_open = {NULL,
+                                                       &dumb_stdfile_skip,
+                                                       &dumb_stdfile_getc,
+                                                       &dumb_stdfile_getnc,
+                                                       &dumb_stdfile_noclose,
+                                                       &dumb_stdfile_seek,
+                                                       &dumb_stdfile_get_size};
+
+DUMBFILE *dumbfile_open_stdfile(FILE *p) {
+    dumb_stdfile *file = (dumb_stdfile *)malloc(sizeof(dumb_stdfile));
+    DUMBFILE *d;
+    if (!file)
+        return 0;
+    file->file = p;
+    fseek(p, 0, SEEK_END);
+    file->size = ftell(p);
+    if (file->size < 0) {
+        free(file);
+        return 0;
+    }
+    fseek(p, 0, SEEK_SET);
+    d = dumbfile_open_ex(file, &stdfile_dfs_leave_open);
+
+    return d;
+}
--- /dev/null
+++ b/src/helpers/tarray.c
@@ -1,0 +1,180 @@
+#include "internal/tarray.h"
+
+#include <string.h>
+
+/*
+   Structures which contain the play times of each pattern and row combination
+   in the song, not guaranteed to be valid for the whole song until the loop
+   status is no longer zero. The initial count and restart count will both be
+   zero on song start, then both will be incremented until the song loops.
+   Restart count will be reset to zero on loop for all rows which have a time
+   equal to or greater than the loop start point, so time keeping functions will
+   know which timestamp the song is currently located at.
+
+   Timestamp lists are guaranteed to be allocated in blocks of 16 timestamps at
+   a time.
+*/
+
+/*
+   We don't need full timekeeping because the player loop only wants the first
+   play time of the loop start order/row. We also don't really want full
+   timekeeping because it involves a lot of memory allocations, which is also
+   slow.
+*/
+
+#undef FULL_TIMEKEEPING
+
+typedef struct DUMB_IT_ROW_TIME {
+    unsigned int count, restart_count;
+#ifndef FULL_TIMEKEEPING
+    LONG_LONG first_time;
+#else
+    LONG_LONG *times;
+#endif
+} DUMB_IT_ROW_TIME;
+
+void *timekeeping_array_create(size_t size) {
+    size_t *_size =
+        (size_t *)calloc(1, sizeof(size_t) + sizeof(DUMB_IT_ROW_TIME) * size);
+    if (_size) {
+        *_size = size;
+    }
+    return _size;
+}
+
+void timekeeping_array_destroy(void *array) {
+#ifdef FULL_TIMEKEEPING
+    size_t i;
+    size_t *size = (size_t *)array;
+    DUMB_IT_ROW_TIME *s = (DUMB_IT_ROW_TIME *)(size + 1);
+
+    for (i = 0; i < *size; i++) {
+        if (s[i].times)
+            free(s[i].times);
+    }
+#endif
+
+    free(array);
+}
+
+void *timekeeping_array_dup(void *array) {
+    size_t i;
+    size_t *size = (size_t *)array;
+    DUMB_IT_ROW_TIME *s = (DUMB_IT_ROW_TIME *)(size + 1);
+    size_t *new_size =
+        (size_t *)calloc(1, sizeof(size_t) + sizeof(DUMB_IT_ROW_TIME) * *size);
+    if (new_size) {
+        DUMB_IT_ROW_TIME *new_s = (DUMB_IT_ROW_TIME *)(new_size + 1);
+
+        *new_size = *size;
+
+        for (i = 0; i < *size; i++) {
+            new_s[i].count = s[i].count;
+            new_s[i].restart_count = s[i].restart_count;
+
+#ifndef FULL_TIMEKEEPING
+            new_s[i].first_time = s[i].first_time;
+#else
+            if (s[i].times) {
+                size_t time_count = (s[i].count + 15) & ~15;
+                new_s[i].times =
+                    (LONG_LONG *)malloc(sizeof(LONG_LONG) * time_count);
+                if (new_s[i].times == (void *)0) {
+                    timekeeping_array_destroy(new_size);
+                    return (void *)0;
+                }
+                memcpy(new_s[i].times, s[i].times,
+                       sizeof(LONG_LONG) * s[i].count);
+            }
+#endif
+        }
+    }
+
+    return new_size;
+}
+
+void timekeeping_array_reset(void *array, size_t loop_start) {
+    size_t i;
+    size_t *size = (size_t *)array;
+    DUMB_IT_ROW_TIME *s = (DUMB_IT_ROW_TIME *)(size + 1);
+
+    DUMB_IT_ROW_TIME *s_loop_start = s + loop_start;
+    LONG_LONG loop_start_time;
+
+    if (loop_start >= *size || s_loop_start->count < 1)
+        return;
+
+#ifndef FULL_TIMEKEEPING
+    loop_start_time = s_loop_start->first_time;
+#else
+    loop_start_time = s_loop_start->times[0];
+#endif
+
+    for (i = 0; i < *size; i++) {
+#ifndef FULL_TIMEKEEPING
+        if (s[i].count && s[i].first_time >= loop_start_time) {
+#else
+        if (s[i].count && s[i].times[0] >= loop_start_time) {
+#endif
+            s[i].restart_count = 0;
+        }
+    }
+}
+
+void timekeeping_array_push(void *array, size_t index, LONG_LONG time) {
+#ifdef FULL_TIMEKEEPING
+    size_t i;
+    size_t time_count;
+#endif
+    size_t *size = (size_t *)array;
+    DUMB_IT_ROW_TIME *s = (DUMB_IT_ROW_TIME *)(size + 1);
+
+    if (index >= *size)
+        return;
+
+#ifndef FULL_TIMEKEEPING
+    if (!s[index].count++)
+        s[index].first_time = time;
+#else
+    time_count = (s[index].count + 16) & ~15;
+
+    s[index].times =
+        (LONG_LONG *)realloc(s[index].times, sizeof(LONG_LONG) * time_count);
+
+    s[index].times[s[index].count++] = time;
+#endif
+}
+
+void timekeeping_array_bump(void *array, size_t index) {
+    size_t *size = (size_t *)array;
+    DUMB_IT_ROW_TIME *s = (DUMB_IT_ROW_TIME *)(size + 1);
+
+    if (index >= *size)
+        return;
+
+    s[index].restart_count++;
+}
+
+unsigned int timekeeping_array_get_count(void *array, size_t index) {
+    size_t *size = (size_t *)array;
+    DUMB_IT_ROW_TIME *s = (DUMB_IT_ROW_TIME *)(size + 1);
+
+    if (index >= *size)
+        return 0;
+
+    return s[index].count;
+}
+
+LONG_LONG timekeeping_array_get_item(void *array, size_t index) {
+    size_t *size = (size_t *)array;
+    DUMB_IT_ROW_TIME *s = (DUMB_IT_ROW_TIME *)(size + 1);
+
+    if (index >= *size || s[index].restart_count >= s[index].count)
+        return 0;
+
+#ifndef FULL_TIMEKEEPING
+    return s[index].first_time;
+#else
+    return s[index].times[s[index].restart_count];
+#endif
+}
--- /dev/null
+++ b/src/it/itload.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itload.c - Code to read an Impulse Tracker         / / \  \
+ *            file, opening and closing it for       | <  /   \_
+ *            you.                                   |  \/ /\   /
+ *                                                    \_  /  > /
+ * By entheh. Don't worry Bob, you're credited          | \ / /
+ * in itread.c!                                         |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_it_quick(): loads an IT file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must pass
+ * the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_it_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_it_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/itload2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itload2.c - Function to read an Impulse Tracker    / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you, and do an initial run-through.   |  \/ /\   /
+ *                                                    \_  /  > /
+ * Split off from itload.c by entheh.                   | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_it(const char *filename) {
+    DUH *duh = dumb_load_it_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/itmisc.c
@@ -1,0 +1,169 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itmisc.c - Miscellaneous functions relating        / / \  \
+ *            to module files.                       | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+int dumb_it_default_panning_separation = 25;
+
+DUMB_IT_SIGDATA *duh_get_it_sigdata(DUH *duh) {
+    return duh_get_raw_sigdata(duh, -1, SIGTYPE_IT);
+}
+
+const unsigned char *dumb_it_sd_get_song_message(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->song_message : NULL;
+}
+
+int dumb_it_sd_get_n_orders(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->n_orders : 0;
+}
+
+int dumb_it_sd_get_n_samples(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->n_samples : 0;
+}
+
+int dumb_it_sd_get_n_instruments(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->n_instruments : 0;
+}
+
+const unsigned char *dumb_it_sd_get_sample_name(DUMB_IT_SIGDATA *sd, int i) {
+    ASSERT(sd && sd->sample && i >= 0 && i < sd->n_samples);
+    return sd->sample[i].name;
+}
+
+const unsigned char *dumb_it_sd_get_sample_filename(DUMB_IT_SIGDATA *sd,
+                                                    int i) {
+    ASSERT(sd && sd->sample && i >= 0 && i < sd->n_samples);
+    return sd->sample[i].filename;
+}
+
+const unsigned char *dumb_it_sd_get_instrument_name(DUMB_IT_SIGDATA *sd,
+                                                    int i) {
+    ASSERT(sd && sd->instrument && i >= 0 && i < sd->n_instruments);
+    return sd->instrument[i].name;
+}
+
+const unsigned char *dumb_it_sd_get_instrument_filename(DUMB_IT_SIGDATA *sd,
+                                                        int i) {
+    ASSERT(sd && sd->instrument && i >= 0 && i < sd->n_instruments);
+    return sd->instrument[i].filename;
+}
+
+int dumb_it_sd_get_initial_global_volume(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->global_volume : 0;
+}
+
+void dumb_it_sd_set_initial_global_volume(DUMB_IT_SIGDATA *sd, int gv) {
+    if (sd)
+        sd->global_volume = gv;
+}
+
+int dumb_it_sd_get_mixing_volume(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->mixing_volume : 0;
+}
+
+void dumb_it_sd_set_mixing_volume(DUMB_IT_SIGDATA *sd, int mv) {
+    if (sd)
+        sd->mixing_volume = mv;
+}
+
+int dumb_it_sd_get_initial_speed(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->speed : 0;
+}
+
+void dumb_it_sd_set_initial_speed(DUMB_IT_SIGDATA *sd, int speed) {
+    if (sd)
+        sd->speed = speed;
+}
+
+int dumb_it_sd_get_initial_tempo(DUMB_IT_SIGDATA *sd) {
+    return sd ? sd->tempo : 0;
+}
+
+void dumb_it_sd_set_initial_tempo(DUMB_IT_SIGDATA *sd, int tempo) {
+    if (sd)
+        sd->tempo = tempo;
+}
+
+int dumb_it_sd_get_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel) {
+    ASSERT(channel >= 0 && channel < DUMB_IT_N_CHANNELS);
+    return sd ? sd->channel_volume[channel] : 0;
+}
+
+void dumb_it_sd_set_initial_channel_volume(DUMB_IT_SIGDATA *sd, int channel,
+                                           int volume) {
+    ASSERT(channel >= 0 && channel < DUMB_IT_N_CHANNELS);
+    if (sd)
+        sd->channel_volume[channel] = volume;
+}
+
+int dumb_it_sr_get_current_order(DUMB_IT_SIGRENDERER *sr) {
+    return sr ? sr->order : -1;
+}
+
+int dumb_it_sr_get_current_row(DUMB_IT_SIGRENDERER *sr) {
+    return sr ? sr->row : -1;
+}
+
+int dumb_it_sr_get_global_volume(DUMB_IT_SIGRENDERER *sr) {
+    return sr ? sr->globalvolume : 0;
+}
+
+void dumb_it_sr_set_global_volume(DUMB_IT_SIGRENDERER *sr, int gv) {
+    if (sr)
+        sr->globalvolume = gv;
+}
+
+int dumb_it_sr_get_tempo(DUMB_IT_SIGRENDERER *sr) { return sr ? sr->tempo : 0; }
+
+void dumb_it_sr_set_tempo(DUMB_IT_SIGRENDERER *sr, int tempo) {
+    if (sr)
+        sr->tempo = tempo;
+}
+
+int dumb_it_sr_get_speed(DUMB_IT_SIGRENDERER *sr) { return sr ? sr->speed : 0; }
+
+void dumb_it_sr_set_speed(DUMB_IT_SIGRENDERER *sr, int speed) {
+    if (sr)
+        sr->speed = speed;
+}
+
+int dumb_it_sr_get_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel) {
+    return sr ? sr->channel[channel].channelvolume : 0;
+}
+
+void dumb_it_sr_set_channel_volume(DUMB_IT_SIGRENDERER *sr, int channel,
+                                   int volume) {
+    if (sr)
+        sr->channel[channel].channelvolume = volume;
+}
+
+void dumb_it_sr_set_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel,
+                                  int muted) {
+    if (sr) {
+        if (muted)
+            sr->channel[channel].flags |= IT_CHANNEL_MUTED;
+        else
+            sr->channel[channel].flags &= ~IT_CHANNEL_MUTED;
+    }
+}
+
+int dumb_it_sr_get_channel_muted(DUMB_IT_SIGRENDERER *sr, int channel) {
+    return sr ? (sr->channel[channel].flags & IT_CHANNEL_MUTED) != 0 : 0;
+}
--- /dev/null
+++ b/src/it/itorder.c
@@ -1,0 +1,65 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itorder.c - Code to fix invalid patterns in        / / \  \
+ *             the pattern table.                    | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Julien Cugniere.                                \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* This function ensures that any pattern mentioned in the order table but
+ * not present in the pattern table is treated as an empty 64 rows pattern.
+ * This is done by adding such a dummy pattern at the end of the pattern
+ * table, and redirect invalid orders to it.
+ * Patterns 254 and 255 are left untouched, unless the signal is an XM.
+ */
+int _dumb_it_fix_invalid_orders(DUMB_IT_SIGDATA *sigdata) {
+    int i;
+    int found_some = 0;
+
+    int first_invalid = sigdata->n_patterns;
+    int last_invalid = (sigdata->flags & IT_WAS_AN_XM) ? 255 : 253;
+
+    for (i = 0; i < sigdata->n_orders; i++) {
+        if (sigdata->order[i] >= first_invalid &&
+            sigdata->order[i] <= last_invalid) {
+            sigdata->order[i] = sigdata->n_patterns;
+            found_some = 1;
+        } else if (sigdata->order[i] < first_invalid) {
+            IT_PATTERN *pattern = sigdata->pattern + sigdata->order[i];
+            if (!pattern->n_rows || (pattern->n_entries && !pattern->entry))
+                return -1;
+        }
+    }
+
+    if (found_some) {
+        IT_PATTERN *new_pattern =
+            realloc(sigdata->pattern,
+                    sizeof(*sigdata->pattern) * (sigdata->n_patterns + 1));
+        if (!new_pattern)
+            return -1;
+
+        new_pattern[sigdata->n_patterns].n_rows = 64;
+        new_pattern[sigdata->n_patterns].n_entries = 0;
+        new_pattern[sigdata->n_patterns].entry = NULL;
+        sigdata->pattern = new_pattern;
+        sigdata->n_patterns++;
+    }
+
+    return 0;
+}
--- /dev/null
+++ b/src/it/itread.c
@@ -1,0 +1,1468 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itread.c - Code to read an Impulse Tracker         / / \  \
+ *            module from an open file.              | <  /   \_
+ *                                                   |  \/ /\   /
+ * Based on the loader from an IT player by Bob.      \_  /  > /
+ * Adapted for DUMB by entheh.                          | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h> //might not be necessary later; required for memset
+
+#include "dumb.h"
+#include "internal/it.h"
+
+#ifndef min
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+//#define INVESTIGATE_OLD_INSTRUMENTS
+
+typedef unsigned char byte;
+typedef unsigned short word;
+typedef unsigned long dword;
+
+typedef struct readblock_crap readblock_crap;
+
+struct readblock_crap {
+    unsigned char *sourcebuf;
+    unsigned char *sourcepos;
+    unsigned char *sourceend;
+    int rembits;
+};
+
+static int readblock(DUMBFILE *f, readblock_crap *crap) {
+    long size;
+    int c;
+
+    size = dumbfile_igetw(f);
+    if (size < 0)
+        return (int)size;
+
+    crap->sourcebuf = malloc(size);
+    if (!crap->sourcebuf)
+        return -1;
+
+    c = (int)dumbfile_getnc((char *)crap->sourcebuf, size, f);
+    if (c < size) {
+        free(crap->sourcebuf);
+        crap->sourcebuf = NULL;
+        return -1;
+    }
+
+    crap->sourcepos = crap->sourcebuf;
+    crap->sourceend = crap->sourcebuf + size;
+    crap->rembits = 8;
+    return 0;
+}
+
+static void freeblock(readblock_crap *crap) {
+    free(crap->sourcebuf);
+    crap->sourcebuf = NULL;
+}
+
+static int readbits(int bitwidth, readblock_crap *crap) {
+    int val = 0;
+    int b = 0;
+
+    if (crap->sourcepos >= crap->sourceend)
+        return val;
+
+    while (bitwidth > crap->rembits) {
+        val |= *crap->sourcepos++ << b;
+        if (crap->sourcepos >= crap->sourceend)
+            return val;
+        b += crap->rembits;
+        bitwidth -= crap->rembits;
+        crap->rembits = 8;
+    }
+
+    val |= (*crap->sourcepos & ((1 << bitwidth) - 1)) << b;
+    *crap->sourcepos >>= bitwidth;
+    crap->rembits -= bitwidth;
+
+    return val;
+}
+
+/** WARNING - do we even need to pass `right`? */
+/** WARNING - why bother memsetting at all? The whole array is written... */
+// if we do memset, dumb_silence() would be neater...
+static int decompress8(DUMBFILE *f, signed char *data, int len, int it215,
+                       int stereo) {
+    int blocklen, blockpos;
+    byte bitwidth;
+    word val;
+    signed char d1, d2;
+    readblock_crap crap;
+
+    memset(&crap, 0, sizeof(crap));
+
+    for (blocklen = 0, blockpos = 0; blocklen < len;
+         blocklen++, blockpos += 1 + stereo)
+        data[blockpos] = 0;
+
+    while (len > 0) {
+        // Read a block of compressed data:
+        if (readblock(f, &crap))
+            return -1;
+        // Set up a few variables
+        blocklen =
+            (len < 0x8000) ? len : 0x8000; // Max block length is 0x8000 bytes
+        blockpos = 0;
+        bitwidth = 9;
+        d1 = d2 = 0;
+        // Start the decompression:
+        while (blockpos < blocklen) {
+            // Read a value:
+            val = (word)readbits(bitwidth, &crap);
+            // Check for bit width change:
+
+            if (bitwidth < 7) { // Method 1:
+                if (val == (1 << (bitwidth - 1))) {
+                    val = (word)readbits(3, &crap) + 1;
+                    bitwidth = (val < bitwidth) ? val : val + 1;
+                    continue;
+                }
+            } else if (bitwidth < 9) { // Method 2
+                byte border = (0xFF >> (9 - bitwidth)) - 4;
+
+                if (val > border && val <= (border + 8)) {
+                    val -= border;
+                    bitwidth = (val < bitwidth) ? val : val + 1;
+                    continue;
+                }
+            } else if (bitwidth == 9) { // Method 3
+                if (val & 0x100) {
+                    bitwidth = (val + 1) & 0xFF;
+                    continue;
+                }
+            } else { // Illegal width, abort ?
+                freeblock(&crap);
+                return -1;
+            }
+
+            // Expand the value to signed byte:
+            {
+                signed char v; // The sample value:
+                if (bitwidth < 8) {
+                    byte shift = 8 - bitwidth;
+                    v = (val << shift);
+                    v >>= shift;
+                } else
+                    v = (signed char)val;
+
+                // And integrate the sample value
+                //(It always has to end with integration doesn't it ? ;-)
+                d1 += v;
+                d2 += d1;
+            }
+
+            // Store !
+            /* Version 2.15 was an unofficial version with hacked compression
+             * code. Yay, better compression :D
+             */
+            *data++ = it215 ? d2 : d1;
+            data += stereo;
+            len--;
+            blockpos++;
+        }
+        freeblock(&crap);
+    }
+    return 0;
+}
+
+static int decompress16(DUMBFILE *f, short *data, int len, int it215,
+                        int stereo) {
+    int blocklen, blockpos;
+    byte bitwidth;
+    long val;
+    signed short d1, d2;
+    readblock_crap crap;
+
+    memset(&crap, 0, sizeof(crap));
+
+    for (blocklen = 0, blockpos = 0; blocklen < len;
+         blocklen++, blockpos += 1 + stereo)
+        data[blockpos] = 0;
+
+    while (len > 0) {
+        // Read a block of compressed data:
+        if (readblock(f, &crap))
+            return -1;
+        // Set up a few variables
+        blocklen =
+            (len < 0x4000) ? len : 0x4000; // Max block length is 0x4000 bytes
+        blockpos = 0;
+        bitwidth = 17;
+        d1 = d2 = 0;
+        // Start the decompression:
+        while (blockpos < blocklen) {
+            val = readbits(bitwidth, &crap);
+            // Check for bit width change:
+
+            if (bitwidth < 7) { // Method 1:
+                if (val == (1 << (bitwidth - 1))) {
+                    val = readbits(4, &crap) + 1;
+                    bitwidth = (val < bitwidth) ? val : val + 1;
+                    continue;
+                }
+            } else if (bitwidth < 17) { // Method 2
+                word border = (0xFFFF >> (17 - bitwidth)) - 8;
+
+                if (val > border && val <= (border + 16)) {
+                    val -= border;
+                    bitwidth = val < bitwidth ? val : val + 1;
+                    continue;
+                }
+            } else if (bitwidth == 17) { // Method 3
+                if (val & 0x10000) {
+                    bitwidth = (val + 1) & 0xFF;
+                    continue;
+                }
+            } else { // Illegal width, abort ?
+                freeblock(&crap);
+                return -1;
+            }
+
+            // Expand the value to signed byte:
+            {
+                short v; // The sample value:
+                if (bitwidth < 16) {
+                    byte shift = 16 - bitwidth;
+                    v = (short)(val << shift);
+                    v >>= shift;
+                } else
+                    v = (short)val;
+
+                // And integrate the sample value
+                //(It always has to end with integration doesn't it ? ;-)
+                d1 += v;
+                d2 += d1;
+            }
+
+            // Store !
+            /* Version 2.15 was an unofficial version with hacked compression
+             * code. Yay, better compression :D
+             */
+            *data++ = it215 ? d2 : d1;
+            data += stereo;
+            len--;
+            blockpos++;
+        }
+        freeblock(&crap);
+    }
+    return 0;
+}
+
+static int it_read_envelope(IT_ENVELOPE *envelope, DUMBFILE *f) {
+    int n;
+
+    envelope->flags = dumbfile_getc(f);
+    envelope->n_nodes = dumbfile_getc(f);
+    if (envelope->n_nodes > 25) {
+        TRACE("IT error: wrong number of envelope nodes (%d)\n",
+              envelope->n_nodes);
+        envelope->n_nodes = 0;
+        return -1;
+    }
+    envelope->loop_start = dumbfile_getc(f);
+    envelope->loop_end = dumbfile_getc(f);
+    envelope->sus_loop_start = dumbfile_getc(f);
+    envelope->sus_loop_end = dumbfile_getc(f);
+    for (n = 0; n < envelope->n_nodes; n++) {
+        envelope->node_y[n] = dumbfile_getc(f);
+        envelope->node_t[n] = dumbfile_igetw(f);
+    }
+    dumbfile_skip(f, 75 - envelope->n_nodes * 3 + 1);
+
+    if (envelope->n_nodes <= 0)
+        envelope->flags &= ~IT_ENVELOPE_ON;
+    else {
+        if (envelope->loop_end >= envelope->n_nodes ||
+            envelope->loop_start > envelope->loop_end)
+            envelope->flags &= ~IT_ENVELOPE_LOOP_ON;
+        if (envelope->sus_loop_end >= envelope->n_nodes ||
+            envelope->sus_loop_start > envelope->sus_loop_end)
+            envelope->flags &= ~IT_ENVELOPE_SUSTAIN_LOOP;
+    }
+
+    return dumbfile_error(f);
+}
+
+static int it_read_old_instrument(IT_INSTRUMENT *instrument, DUMBFILE *f) {
+    int n;
+
+    /*if (dumbfile_mgetl(f) != IT_INSTRUMENT_SIGNATURE)
+            return -1;*/
+    // XXX
+    dumbfile_skip(f, 4);
+
+    dumbfile_getnc((char *)instrument->filename, 13, f);
+    instrument->filename[13] = 0;
+
+    instrument->volume_envelope.flags = dumbfile_getc(f);
+    instrument->volume_envelope.loop_start = dumbfile_getc(f);
+    instrument->volume_envelope.loop_end = dumbfile_getc(f);
+    instrument->volume_envelope.sus_loop_start = dumbfile_getc(f);
+    instrument->volume_envelope.sus_loop_end = dumbfile_getc(f);
+
+    /* Skip two unused bytes. */
+    dumbfile_skip(f, 2);
+
+    /* In the old instrument format, fadeout ranges from 0 to 64, and is
+     * subtracted at intervals from a value starting at 512. In the new
+     * format, all these values are doubled. Therefore we double when loading
+     * from the old instrument format - that way we don't have to think about
+     * it later.
+     */
+    instrument->fadeout = dumbfile_igetw(f) << 1;
+    instrument->new_note_action = dumbfile_getc(f);
+    instrument->dup_check_type = dumbfile_getc(f);
+    instrument->dup_check_action = DCA_NOTE_CUT; // This might be wrong!
+    /** WARNING - what is the duplicate check action for old-style instruments?
+     */
+
+    /* Skip Tracker Version and Number of Samples. These are only used in
+     * separate instrument files. Also skip unused byte.
+     */
+    dumbfile_skip(f, 4);
+
+    dumbfile_getnc((char *)instrument->name, 26, f);
+    instrument->name[26] = 0;
+
+    /* Skip unused bytes following the Instrument Name. */
+    dumbfile_skip(f, 6);
+
+    instrument->pp_separation = 0;
+    instrument->pp_centre = 60;
+    instrument->global_volume = 128;
+    /** WARNING - should global_volume be 64 or something? */
+    instrument->default_pan = 32;
+    /** WARNING - should default_pan be 128, meaning don`t use? */
+    instrument->random_volume = 0;
+    instrument->random_pan = 0;
+
+    for (n = 0; n < 120; n++) {
+        instrument->map_note[n] = dumbfile_getc(f);
+        instrument->map_sample[n] = dumbfile_getc(f);
+    }
+
+    /* Skip "Volume envelope (200 bytes)". */
+    // - need to know better what this is for though.
+    dumbfile_skip(f, 200);
+
+#ifdef INVESTIGATE_OLD_INSTRUMENTS
+    fprintf(stderr, "Inst %02d Env:", n);
+#endif
+
+    for (n = 0; n < 25; n++) {
+        instrument->volume_envelope.node_t[n] = dumbfile_getc(f);
+        instrument->volume_envelope.node_y[n] = dumbfile_getc(f);
+
+#ifdef INVESTIGATE_OLD_INSTRUMENTS
+        fprintf(stderr, " %d,%d", instrument->volume_envelope.node_t[n],
+                instrument->volume_envelope.node_y[n]);
+#endif
+
+        // This loop is unfinished, as we can probably escape from it before
+        // the end if we want to. Hence the otherwise useless dumbfile_skip()
+        // call below.
+    }
+    dumbfile_skip(f, 50 - (n << 1));
+    instrument->volume_envelope.n_nodes = n;
+
+#ifdef INVESTIGATE_OLD_INSTRUMENTS
+    fprintf(stderr, "\n");
+#endif
+
+    if (dumbfile_error(f))
+        return -1;
+
+    {
+        IT_ENVELOPE *envelope = &instrument->volume_envelope;
+        if (envelope->n_nodes <= 0)
+            envelope->flags &= ~IT_ENVELOPE_ON;
+        else {
+            if (envelope->loop_end >= envelope->n_nodes ||
+                envelope->loop_start > envelope->loop_end)
+                envelope->flags &= ~IT_ENVELOPE_LOOP_ON;
+            if (envelope->sus_loop_end >= envelope->n_nodes ||
+                envelope->sus_loop_start > envelope->sus_loop_end)
+                envelope->flags &= ~IT_ENVELOPE_SUSTAIN_LOOP;
+        }
+    }
+
+    instrument->filter_cutoff = 127;
+    instrument->filter_resonance = 0;
+
+    instrument->pan_envelope.flags = 0;
+    instrument->pitch_envelope.flags = 0;
+
+    return 0;
+}
+
+static int it_read_instrument(IT_INSTRUMENT *instrument, DUMBFILE *f,
+                              int maxlen) {
+    int n;
+    long len;
+
+    /*if (dumbfile_mgetl(f) != IT_INSTRUMENT_SIGNATURE)
+            return -1;*/
+    // XXX
+
+    if (maxlen)
+        len = dumbfile_pos(f);
+    else
+        len = 0;
+
+    dumbfile_skip(f, 4);
+
+    dumbfile_getnc((char *)instrument->filename, 13, f);
+    instrument->filename[13] = 0;
+
+    instrument->new_note_action = dumbfile_getc(f);
+    instrument->dup_check_type = dumbfile_getc(f);
+    instrument->dup_check_action = dumbfile_getc(f);
+    instrument->fadeout = dumbfile_igetw(f);
+    instrument->pp_separation = dumbfile_getc(f);
+    instrument->pp_centre = dumbfile_getc(f);
+    instrument->global_volume = dumbfile_getc(f);
+    instrument->default_pan = dumbfile_getc(f);
+    instrument->random_volume = dumbfile_getc(f);
+    instrument->random_pan = dumbfile_getc(f);
+
+    /* Skip Tracker Version and Number of Samples. These are only used in
+     * separate instrument files. Also skip unused byte.
+     */
+    dumbfile_skip(f, 4);
+
+    dumbfile_getnc((char *)instrument->name, 26, f);
+    instrument->name[26] = 0;
+
+    instrument->filter_cutoff = dumbfile_getc(f);
+    instrument->filter_resonance = dumbfile_getc(f);
+
+    /* Skip MIDI Channel, Program and Bank. */
+    // dumbfile_skip(f, 4);
+    /*instrument->output = dumbfile_getc(f);
+    if ( instrument->output > 16 ) {
+            instrument->output -= 128;
+    } else {
+            instrument->output = 0;
+    }
+    dumbfile_skip(f, 3);*/
+    dumbfile_skip(f, 4);
+
+    for (n = 0; n < 120; n++) {
+        instrument->map_note[n] = dumbfile_getc(f);
+        instrument->map_sample[n] = dumbfile_getc(f);
+    }
+
+    if (dumbfile_error(f))
+        return -1;
+
+    if (it_read_envelope(&instrument->volume_envelope, f))
+        return -1;
+    if (it_read_envelope(&instrument->pan_envelope, f))
+        return -1;
+    if (it_read_envelope(&instrument->pitch_envelope, f))
+        return -1;
+
+    if (maxlen) {
+        len = dumbfile_pos(f) - len;
+        if (maxlen - len < 124)
+            return 0;
+    }
+
+    if (dumbfile_mgetl(f) == IT_MPTX_SIGNATURE) {
+        for (n = 0; n < 120; n++) {
+            instrument->map_sample[n] += dumbfile_getc(f) << 8;
+        }
+
+        if (dumbfile_error(f))
+            return -1;
+    }
+
+    /*if ( dumbfile_mgetl(f) == IT_INSM_SIGNATURE ) {
+            long end = dumbfile_igetl(f);
+            end += dumbfile_pos(f);
+            while ( dumbfile_pos(f) < end ) {
+                    int chunkid = dumbfile_igetl(f);
+                    switch ( chunkid ) {
+                            case DUMB_ID('P','L','U','G'):
+                                    instrument->output = dumbfile_getc(f);
+                                    break;
+                            default:
+                                    chunkid = chunkid / 0x100 + dumbfile_getc(f)
+    * 0x1000000; break;
+                    }
+            }
+
+            if (dumbfile_error(f))
+                    return -1;
+    }*/
+
+    return 0;
+}
+
+static int it_read_sample_header(IT_SAMPLE *sample, unsigned char *convert,
+                                 long *offset, DUMBFILE *f) {
+    /* XXX
+    if (dumbfile_mgetl(f) != IT_SAMPLE_SIGNATURE)
+            return -1;*/
+    int hax = 0;
+    long s = dumbfile_mgetl(f);
+    if (s != IT_SAMPLE_SIGNATURE) {
+        if (s == (IT_SAMPLE_SIGNATURE >> 16)) {
+            s <<= 16;
+            s |= dumbfile_mgetw(f);
+            if (s != IT_SAMPLE_SIGNATURE)
+                return -1;
+            hax = 1;
+        }
+    }
+
+    dumbfile_getnc((char *)sample->filename, 13, f);
+    sample->filename[13] = 0;
+
+    sample->global_volume = dumbfile_getc(f);
+    sample->flags = dumbfile_getc(f);
+    sample->default_volume = dumbfile_getc(f);
+
+    dumbfile_getnc((char *)sample->name, 26, f);
+    sample->name[26] = 0;
+
+    *convert = dumbfile_getc(f);
+    sample->default_pan = dumbfile_getc(f);
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = dumbfile_igetl(f);
+    sample->C5_speed = dumbfile_igetl(f);
+    sample->sus_loop_start = dumbfile_igetl(f);
+    sample->sus_loop_end = dumbfile_igetl(f);
+
+#ifdef STEREO_SAMPLES_COUNT_AS_TWO
+    if (sample->flags & IT_SAMPLE_STEREO) {
+        sample->length >>= 1;
+        sample->loop_start >>= 1;
+        sample->loop_end >>= 1;
+        sample->C5_speed >>= 1;
+        sample->sus_loop_start >>= 1;
+        sample->sus_loop_end >>= 1;
+    }
+#endif
+
+    if (sample->flags & IT_SAMPLE_EXISTS) {
+        if (sample->length <= 0)
+            sample->flags &= ~IT_SAMPLE_EXISTS;
+        else {
+            if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
+                sample->flags &= ~IT_SAMPLE_LOOP;
+            else if ((unsigned int)sample->loop_start >=
+                     (unsigned int)sample->loop_end)
+                sample->flags &= ~IT_SAMPLE_LOOP;
+
+            if ((unsigned int)sample->sus_loop_end >
+                (unsigned int)sample->length)
+                sample->flags &= ~IT_SAMPLE_SUS_LOOP;
+            else if ((unsigned int)sample->sus_loop_start >=
+                     (unsigned int)sample->sus_loop_end)
+                sample->flags &= ~IT_SAMPLE_SUS_LOOP;
+
+            /* We may be able to truncate the sample to save memory. */
+            if (sample->flags & IT_SAMPLE_LOOP &&
+                *convert !=
+                    0xFF) { /* not truncating compressed samples, for now... */
+                if ((sample->flags & IT_SAMPLE_SUS_LOOP) &&
+                    sample->sus_loop_end >= sample->loop_end)
+                    sample->length = sample->sus_loop_end;
+                else
+                    sample->length = sample->loop_end;
+            }
+        }
+    }
+
+    *offset = dumbfile_igetl(f);
+
+    sample->vibrato_speed = dumbfile_getc(f);
+    sample->vibrato_depth = dumbfile_getc(f);
+    if (!hax) {
+        sample->vibrato_rate = dumbfile_getc(f);
+        sample->vibrato_waveform = dumbfile_getc(f);
+    } else {
+        sample->vibrato_rate = 0;
+        sample->vibrato_waveform = 0;
+    }
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+long _dumb_it_read_sample_data_adpcm4(IT_SAMPLE *sample, DUMBFILE *f) {
+    long n, len, delta;
+    signed char *ptr, *end;
+    signed char compression_table[16];
+    if (dumbfile_getnc((char *)compression_table, 16, f) != 16)
+        return -1;
+    ptr = (signed char *)sample->data;
+    delta = 0;
+
+    end = ptr + sample->length;
+    len = (sample->length + 1) / 2;
+    for (n = 0; n < len; n++) {
+        int b = dumbfile_getc(f);
+        if (b < 0)
+            return -1;
+        delta += compression_table[b & 0x0F];
+        *ptr++ = delta;
+        if (ptr >= end)
+            break;
+        delta += compression_table[b >> 4];
+        *ptr++ = delta;
+    }
+
+    return 0;
+}
+
+static long it_read_sample_data(IT_SAMPLE *sample, unsigned char convert,
+                                DUMBFILE *f) {
+    long n;
+
+    long datasize = sample->length;
+    if (sample->flags & IT_SAMPLE_STEREO)
+        datasize <<= 1;
+
+    sample->data = malloc(datasize * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
+    if (!sample->data)
+        return -1;
+
+    if (!(sample->flags & IT_SAMPLE_16BIT) && (convert == 0xFF)) {
+        if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
+            return -1;
+    } else if (sample->flags & 8) {
+        /* If the sample is packed, then we must unpack it. */
+
+        /* Behavior as defined by greasemonkey's munch.py and observed by XMPlay
+         * and OpenMPT */
+
+        if (sample->flags & IT_SAMPLE_STEREO) {
+            if (sample->flags & IT_SAMPLE_16BIT) {
+                decompress16(f, (short *)sample->data, (int)(datasize >> 1),
+                             convert & 4, 1);
+                decompress16(f, (short *)sample->data + 1, (int)(datasize >> 1),
+                             convert & 4, 1);
+            } else {
+                decompress8(f, (signed char *)sample->data,
+                            (int)(datasize >> 1), convert & 4, 1);
+                decompress8(f, (signed char *)sample->data + 1,
+                            (int)(datasize >> 1), convert & 4, 1);
+            }
+        } else {
+            if (sample->flags & IT_SAMPLE_16BIT)
+                decompress16(f, (short *)sample->data, (int)datasize,
+                             convert & 4, 0);
+            else
+                decompress8(f, (signed char *)sample->data, (int)datasize,
+                            convert & 4, 0);
+        }
+    } else if (sample->flags & IT_SAMPLE_16BIT) {
+        if (sample->flags & IT_SAMPLE_STEREO) {
+            if (convert & 2) {
+                for (n = 0; n < datasize; n += 2)
+                    ((short *)sample->data)[n] = dumbfile_mgetw(f);
+                for (n = 1; n < datasize; n += 2)
+                    ((short *)sample->data)[n] = dumbfile_mgetw(f);
+            } else {
+                for (n = 0; n < datasize; n += 2)
+                    ((short *)sample->data)[n] = dumbfile_igetw(f);
+                for (n = 1; n < datasize; n += 2)
+                    ((short *)sample->data)[n] = dumbfile_igetw(f);
+            }
+        } else {
+            if (convert & 2)
+                for (n = 0; n < datasize; n++)
+                    ((short *)sample->data)[n] = dumbfile_mgetw(f);
+            else
+                for (n = 0; n < datasize; n++)
+                    ((short *)sample->data)[n] = dumbfile_igetw(f);
+        }
+    } else {
+        if (sample->flags & IT_SAMPLE_STEREO) {
+            for (n = 0; n < datasize; n += 2)
+                ((signed char *)sample->data)[n] = dumbfile_getc(f);
+            for (n = 1; n < datasize; n += 2)
+                ((signed char *)sample->data)[n] = dumbfile_getc(f);
+        } else
+            for (n = 0; n < datasize; n++)
+                ((signed char *)sample->data)[n] = dumbfile_getc(f);
+    }
+
+    if (dumbfile_error(f))
+        return -1;
+
+    if (!(convert & 1)) {
+        /* Convert to signed. */
+        if (sample->flags & IT_SAMPLE_16BIT)
+            for (n = 0; n < datasize; n++)
+                ((short *)sample->data)[n] ^= 0x8000;
+        else
+            for (n = 0; n < datasize; n++)
+                ((signed char *)sample->data)[n] ^= 0x80;
+    }
+
+    /* NOT SUPPORTED:
+     *
+     * convert &  4 - Samples stored as delta values
+     * convert & 16 - Samples stored as TX-Wave 12-bit values
+     * convert & 32 - Left/Right/All Stereo prompt
+     */
+
+    return 0;
+}
+
+//#define DETECT_DUPLICATE_CHANNELS
+#ifdef DETECT_DUPLICATE_CHANNELS
+#include <stdio.h>
+#endif
+static int it_read_pattern(IT_PATTERN *pattern, DUMBFILE *f,
+                           unsigned char *buffer) {
+    unsigned char cmask[DUMB_IT_N_CHANNELS];
+    unsigned char cnote[DUMB_IT_N_CHANNELS];
+    unsigned char cinstrument[DUMB_IT_N_CHANNELS];
+    unsigned char cvolpan[DUMB_IT_N_CHANNELS];
+    unsigned char ceffect[DUMB_IT_N_CHANNELS];
+    unsigned char ceffectvalue[DUMB_IT_N_CHANNELS];
+#ifdef DETECT_DUPLICATE_CHANNELS
+    IT_ENTRY *dupentry[DUMB_IT_N_CHANNELS];
+#endif
+
+    int n_entries = 0;
+    int buflen;
+    int bufpos = 0;
+
+    IT_ENTRY *entry;
+
+    unsigned char channel;
+    unsigned char mask;
+
+    memset(cmask, 0, sizeof(cmask));
+    memset(cnote, 0, sizeof(cnote));
+    memset(cinstrument, 0, sizeof(cinstrument));
+    memset(cvolpan, 0, sizeof(cvolpan));
+    memset(ceffect, 0, sizeof(ceffect));
+    memset(ceffectvalue, 0, sizeof(ceffectvalue));
+#ifdef DETECT_DUPLICATE_CHANNELS
+    {
+        int i;
+        for (i = 0; i < DUMB_IT_N_CHANNELS; i++)
+            dupentry[i] = NULL;
+    }
+#endif
+
+    buflen = dumbfile_igetw(f);
+    pattern->n_rows = dumbfile_igetw(f);
+
+    /* Skip four unused bytes. */
+    dumbfile_skip(f, 4);
+
+    if (dumbfile_error(f))
+        return -1;
+
+    /* Read in the pattern data. */
+    dumbfile_getnc((char *)buffer, buflen, f);
+
+    if (dumbfile_error(f))
+        return -1;
+
+    /* Scan the pattern data, and work out how many entries we need room for. */
+    while (bufpos < buflen) {
+        unsigned char b = buffer[bufpos++];
+
+        if (b == 0) {
+            /* End of row */
+            n_entries++;
+            continue;
+        }
+
+        channel = (b - 1) & 63;
+
+        if (b & 128)
+            cmask[channel] = mask = buffer[bufpos++];
+        else
+            mask = cmask[channel];
+
+        {
+            static const unsigned char used[16] = {0, 1, 1, 2, 1, 2, 2, 3,
+                                                   2, 3, 3, 4, 3, 4, 4, 5};
+            n_entries += (mask != 0);
+            bufpos += used[mask & 15];
+        }
+    }
+
+    pattern->n_entries = n_entries;
+
+    pattern->entry = malloc(n_entries * sizeof(*pattern->entry));
+
+    if (!pattern->entry)
+        return -1;
+
+    bufpos = 0;
+    memset(cmask, 0, sizeof(cmask));
+
+    entry = pattern->entry;
+
+    while (bufpos < buflen) {
+        unsigned char b = buffer[bufpos++];
+
+        if (b == 0) {
+            /* End of row */
+            IT_SET_END_ROW(entry);
+            entry++;
+#ifdef DETECT_DUPLICATE_CHANNELS
+            {
+                int i;
+                for (i = 0; i < DUMB_IT_N_CHANNELS; i++)
+                    dupentry[i] = NULL;
+            }
+#endif
+            continue;
+        }
+
+        channel = (b - 1) & 63;
+
+        if (b & 128) {
+            if (bufpos >= buflen)
+                return -1;
+
+            cmask[channel] = mask = buffer[bufpos++];
+        } else
+            mask = cmask[channel];
+
+        if (mask) {
+            entry->mask = (mask & 15) | (mask >> 4);
+            entry->channel = channel;
+
+            if (mask & IT_ENTRY_NOTE) {
+                if (bufpos >= buflen)
+                    return -1;
+
+                cnote[channel] = entry->note = buffer[bufpos++];
+            } else if (mask & (IT_ENTRY_NOTE << 4))
+                entry->note = cnote[channel];
+
+            if (mask & IT_ENTRY_INSTRUMENT) {
+                if (bufpos >= buflen)
+                    return -1;
+
+                cinstrument[channel] = entry->instrument = buffer[bufpos++];
+            } else if (mask & (IT_ENTRY_INSTRUMENT << 4))
+                entry->instrument = cinstrument[channel];
+
+            if (mask & IT_ENTRY_VOLPAN) {
+                if (bufpos >= buflen)
+                    return -1;
+
+                cvolpan[channel] = entry->volpan = buffer[bufpos++];
+            } else if (mask & (IT_ENTRY_VOLPAN << 4))
+                entry->volpan = cvolpan[channel];
+
+            if (mask & IT_ENTRY_EFFECT) {
+                if (bufpos + 1 >= buflen)
+                    return -1;
+
+                ceffect[channel] = entry->effect = buffer[bufpos++];
+                ceffectvalue[channel] = entry->effectvalue = buffer[bufpos++];
+            } else {
+                entry->effect = ceffect[channel];
+                entry->effectvalue = ceffectvalue[channel];
+            }
+
+#ifdef DETECT_DUPLICATE_CHANNELS
+            if (dupentry[channel]) {
+                FILE *f = fopen("dupentry.txt", "a");
+                if (!f)
+                    abort();
+                fprintf(f, "Two events on channel %d:", channel);
+                fprintf(f, "  Event #1:");
+                if (dupentry[channel]->mask & IT_ENTRY_NOTE)
+                    fprintf(f, " %03d", dupentry[channel]->note);
+                else
+                    fprintf(f, " ...");
+                if (dupentry[channel]->mask & IT_ENTRY_INSTRUMENT)
+                    fprintf(f, " %03d", dupentry[channel]->instrument);
+                else
+                    fprintf(f, " ...");
+                if (dupentry[channel]->mask & IT_ENTRY_VOLPAN)
+                    fprintf(f, " %03d", dupentry[channel]->volpan);
+                else
+                    fprintf(f, " ...");
+                if (dupentry[channel]->mask & IT_ENTRY_EFFECT)
+                    fprintf(f, " %c%02X\n", 'A' - 1 + dupentry[channel]->effect,
+                            dupentry[channel]->effectvalue);
+                else
+                    fprintf(f, " ...\n");
+                fprintf(f, "  Event #2:");
+                if (entry->mask & IT_ENTRY_NOTE)
+                    fprintf(f, " %03d", entry->note);
+                else
+                    fprintf(f, " ...");
+                if (entry->mask & IT_ENTRY_INSTRUMENT)
+                    fprintf(f, " %03d", entry->instrument);
+                else
+                    fprintf(f, " ...");
+                if (entry->mask & IT_ENTRY_VOLPAN)
+                    fprintf(f, " %03d", entry->volpan);
+                else
+                    fprintf(f, " ...");
+                if (entry->mask & IT_ENTRY_EFFECT)
+                    fprintf(f, " %c%02X\n", 'A' - 1 + entry->effect,
+                            entry->effectvalue);
+                else
+                    fprintf(f, " ...\n");
+                fclose(f);
+            }
+            dupentry[channel] = entry;
+#endif
+
+            entry++;
+        }
+    }
+
+    ASSERT(entry == pattern->entry + n_entries);
+
+    return 0;
+}
+
+/* Currently we assume the sample data are stored after the sample headers in
+ * module files. This assumption may be unjustified; let me know if you have
+ * trouble.
+ */
+
+#define IT_COMPONENT_SONG_MESSAGE 1
+#define IT_COMPONENT_INSTRUMENT 2
+#define IT_COMPONENT_PATTERN 3
+#define IT_COMPONENT_SAMPLE 4
+
+typedef struct IT_COMPONENT {
+    unsigned char type;
+    unsigned short n;
+    long offset;
+    short sampfirst; /* component[sampfirst] = first sample data after this */
+    short sampnext; /* sampnext is used to create linked lists of sample data */
+} IT_COMPONENT;
+
+static int it_component_compare(const void *e1, const void *e2) {
+    return (int)(((const IT_COMPONENT *)e1)->offset -
+                 ((const IT_COMPONENT *)e2)->offset);
+}
+
+static sigdata_t *it_load_sigdata(DUMBFILE *f) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    int cwt, cmwt;
+    int special;
+    int message_length, message_offset;
+
+    IT_COMPONENT *component;
+    int min_components;
+    int n_components = 0;
+
+    unsigned char sample_convert[4096];
+
+    int n;
+
+    unsigned char *buffer;
+
+    if (dumbfile_mgetl(f) != IT_SIGNATURE) {
+        return NULL;
+    }
+
+    sigdata = malloc(sizeof(*sigdata));
+
+    if (!sigdata) {
+        return NULL;
+    }
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    dumbfile_getnc((char *)sigdata->name, 26, f);
+    sigdata->name[26] = 0;
+
+    /* Skip pattern row highlight info. */
+    dumbfile_skip(f, 2);
+
+    sigdata->n_orders = dumbfile_igetw(f);
+    sigdata->n_instruments = dumbfile_igetw(f);
+    sigdata->n_samples = dumbfile_igetw(f);
+    sigdata->n_patterns = dumbfile_igetw(f);
+
+    cwt = dumbfile_igetw(f);
+    cmwt = dumbfile_igetw(f);
+
+    sigdata->flags = dumbfile_igetw(f);
+    special = dumbfile_igetw(f);
+
+    sigdata->global_volume = dumbfile_getc(f);
+    sigdata->mixing_volume = dumbfile_getc(f);
+    sigdata->speed = dumbfile_getc(f);
+    if (sigdata->speed == 0)
+        sigdata->speed = 6; // Should we? What about tempo?
+    sigdata->tempo = dumbfile_getc(f);
+    sigdata->pan_separation = dumbfile_getc(f); /** WARNING: use this */
+
+    /* Skip Pitch Wheel Depth */
+    dumbfile_skip(f, 1);
+
+    message_length = dumbfile_igetw(f);
+    message_offset = (int)dumbfile_igetl(f);
+
+    /* Skip Reserved. */
+    dumbfile_skip(f, 4);
+
+    dumbfile_getnc((char *)sigdata->channel_pan, DUMB_IT_N_CHANNELS, f);
+    dumbfile_getnc((char *)sigdata->channel_volume, DUMB_IT_N_CHANNELS, f);
+
+    // XXX sample count
+    if (dumbfile_error(f) || sigdata->n_orders <= 0 ||
+        sigdata->n_orders > 1024 || // Whoa, nelly.
+        sigdata->n_instruments > 256 || sigdata->n_samples > 4000 ||
+        sigdata->n_patterns > 256) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->order = malloc(sigdata->n_orders);
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (sigdata->n_instruments) {
+        sigdata->instrument =
+            malloc(sigdata->n_instruments * sizeof(*sigdata->instrument));
+        if (!sigdata->instrument) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    if (sigdata->n_samples) {
+        sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+        if (!sigdata->sample) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_samples; n++)
+            sigdata->sample[n].data = NULL;
+    }
+
+    if (sigdata->n_patterns) {
+        sigdata->pattern =
+            malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+        if (!sigdata->pattern) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_patterns; n++)
+            sigdata->pattern[n].entry = NULL;
+    }
+
+    if (dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f) <
+        sigdata->n_orders) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    sigdata->restart_position = 0;
+
+    min_components = (special & 1) + sigdata->n_instruments +
+                     sigdata->n_samples + sigdata->n_patterns;
+
+    component = malloc(min_components * sizeof(*component));
+    if (!component) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (special & 1) {
+        component[n_components].type = IT_COMPONENT_SONG_MESSAGE;
+        component[n_components].offset = message_offset;
+        component[n_components].sampfirst = -1;
+        n_components++;
+    }
+
+    for (n = 0; n < sigdata->n_instruments; n++) {
+        component[n_components].type = IT_COMPONENT_INSTRUMENT;
+        component[n_components].n = n;
+        component[n_components].offset = dumbfile_igetl(f);
+        component[n_components].sampfirst = -1;
+        n_components++;
+    }
+
+    for (n = 0; n < sigdata->n_samples; n++) {
+        component[n_components].type = IT_COMPONENT_SAMPLE;
+        component[n_components].n = n;
+        component[n_components].offset = dumbfile_igetl(f);
+        component[n_components].sampfirst = -1;
+        n_components++;
+    }
+
+    for (n = 0; n < sigdata->n_patterns; n++) {
+        long offset = dumbfile_igetl(f);
+        if (offset) {
+            component[n_components].type = IT_COMPONENT_PATTERN;
+            component[n_components].n = n;
+            component[n_components].offset = offset;
+            component[n_components].sampfirst = -1;
+            n_components++;
+        } else {
+            /* Empty 64-row pattern */
+            sigdata->pattern[n].n_rows = 64;
+            sigdata->pattern[n].n_entries = 0;
+        }
+    }
+
+    if (dumbfile_error(f)) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    /*
+    if (!(sigdata->flags & 128) != !(special & 8)) {
+            fprintf(stderr, "Flags   Bit 7 (\"Request embedded MIDI
+    configuration\"): %s\n", sigdata->flags & 128 ? "=SET=" : "clear");
+            fprintf(stderr, "Special Bit 3     (\"MIDI configuration embedded\")
+    : %s\n", special        &   8 ? "=SET=" : "clear"); fprintf(stderr, "entheh
+    would like to investigate this IT file.\n"); fprintf(stderr, "Please contact
+    him! entheh@users.sf.net\n");
+    }
+    */
+
+    if (special & 8) {
+        /* MIDI configuration is embedded. */
+        unsigned char mididata[32];
+        int i;
+        sigdata->midi = malloc(sizeof(*sigdata->midi));
+        if (!sigdata->midi) {
+            free(component);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+            // Should we be happy with this outcome in some situations?
+        }
+        // What are we skipping?
+        i = dumbfile_igetw(f);
+        if (dumbfile_error(f) || dumbfile_skip(f, 8 * i)) {
+            free(component);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        /* Read embedded MIDI configuration */
+        // What are the first 9 commands for?
+        if (dumbfile_skip(f, 32 * 9)) {
+            free(component);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (i = 0; i < 16; i++) {
+            unsigned char len = 0;
+            int j, leftdigit = -1;
+            if (dumbfile_getnc((char *)mididata, 32, f) < 32) {
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+            sigdata->midi->SFmacroz[i] = 0;
+            for (j = 0; j < 32; j++) {
+                if (leftdigit >= 0) {
+                    if (mididata[j] == 0) {
+                        sigdata->midi->SFmacro[i][len++] = leftdigit;
+                        break;
+                    } else if (mididata[j] == ' ')
+                        sigdata->midi->SFmacro[i][len++] = leftdigit;
+                    else if (mididata[j] >= '0' && mididata[j] <= '9')
+                        sigdata->midi->SFmacro[i][len++] =
+                            (leftdigit << 4) | (mididata[j] - '0');
+                    else if (mididata[j] >= 'A' && mididata[j] <= 'F')
+                        sigdata->midi->SFmacro[i][len++] =
+                            (leftdigit << 4) | (mididata[j] - 'A' + 0xA);
+                    leftdigit = -1;
+                } else if (mididata[j] == 0)
+                    break;
+                else if (mididata[j] == 'z')
+                    sigdata->midi->SFmacroz[i] |= 1 << len++;
+                else if (mididata[j] >= '0' && mididata[j] <= '9')
+                    leftdigit = mididata[j] - '0';
+                else if (mididata[j] >= 'A' && mididata[j] <= 'F')
+                    leftdigit = mididata[j] - 'A' + 0xA;
+            }
+            sigdata->midi->SFmacrolen[i] = len;
+        }
+        for (i = 0; i < 128; i++) {
+            unsigned char len = 0;
+            int j, leftdigit = -1;
+            dumbfile_getnc((char *)mididata, 32, f);
+            for (j = 0; j < 32; j++) {
+                if (leftdigit >= 0) {
+                    if (mididata[j] == 0) {
+                        sigdata->midi->Zmacro[i][len++] = leftdigit;
+                        break;
+                    } else if (mididata[j] == ' ')
+                        sigdata->midi->Zmacro[i][len++] = leftdigit;
+                    else if (mididata[j] >= '0' && mididata[j] <= '9')
+                        sigdata->midi->Zmacro[i][len++] =
+                            (leftdigit << 4) | (mididata[j] - '0');
+                    else if (mididata[j] >= 'A' && mididata[j] <= 'F')
+                        sigdata->midi->Zmacro[i][len++] =
+                            (leftdigit << 4) | (mididata[j] - 'A' + 0xA);
+                    leftdigit = -1;
+                } else if (mididata[j] == 0)
+                    break;
+                else if (mididata[j] >= '0' && mididata[j] <= '9')
+                    leftdigit = mididata[j] - '0';
+                else if (mididata[j] >= 'A' && mididata[j] <= 'F')
+                    leftdigit = mididata[j] - 'A' + 0xA;
+            }
+            sigdata->midi->Zmacrolen[i] = len;
+        }
+    }
+
+    sigdata->flags &= IT_REAL_FLAGS;
+
+    qsort(component, n_components, sizeof(IT_COMPONENT), &it_component_compare);
+
+    buffer = malloc(65536);
+    if (!buffer) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (n = 0; n < n_components; n++) {
+        long offset;
+        int m;
+
+        /* XXX */
+        if (component[n].offset == 0) {
+            switch (component[n].type) {
+            case IT_COMPONENT_INSTRUMENT:
+                memset(&sigdata->instrument[component[n].n], 0,
+                       sizeof(IT_INSTRUMENT));
+                break;
+            case IT_COMPONENT_SAMPLE:
+                memset(&sigdata->sample[component[n].n], 0, sizeof(IT_SAMPLE));
+                break;
+            case IT_COMPONENT_PATTERN: {
+                IT_PATTERN *p = &sigdata->pattern[component[n].n];
+                p->entry = 0;
+                p->n_rows = 64;
+                p->n_entries = 0;
+            } break;
+            }
+            continue;
+        }
+
+        if (dumbfile_seek(f, component[n].offset, DFS_SEEK_SET)) {
+            free(buffer);
+            free(component);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+
+        switch (component[n].type) {
+
+        case IT_COMPONENT_SONG_MESSAGE:
+            if (n + 1 < n_components) {
+                message_length =
+                    min(message_length,
+                        (int)(component[n + 1].offset - component[n].offset));
+            }
+            sigdata->song_message = malloc(message_length + 1);
+            if (sigdata->song_message) {
+                if (dumbfile_getnc((char *)sigdata->song_message,
+                                   message_length, f) < message_length) {
+                    free(buffer);
+                    free(component);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+                sigdata->song_message[message_length] = 0;
+            }
+            break;
+
+        case IT_COMPONENT_INSTRUMENT:
+            if (cmwt < 0x200)
+                m = it_read_old_instrument(&sigdata->instrument[component[n].n],
+                                           f);
+            else
+                m = it_read_instrument(
+                    &sigdata->instrument[component[n].n], f,
+                    (n + 1 < n_components)
+                        ? (int)(component[n + 1].offset - component[n].offset)
+                        : 0);
+
+            if (m) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+            break;
+
+        case IT_COMPONENT_PATTERN:
+            if (it_read_pattern(&sigdata->pattern[component[n].n], f, buffer)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+            break;
+
+        case IT_COMPONENT_SAMPLE:
+            if (it_read_sample_header(&sigdata->sample[component[n].n],
+                                      &sample_convert[component[n].n], &offset,
+                                      f)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            if (sigdata->sample[component[n].n].flags & IT_SAMPLE_EXISTS) {
+                short *sample;
+
+                for (m = n + 1; m < n_components; m++)
+                    if (component[m].offset > offset)
+                        break;
+                m--;
+
+                sample = &component[m].sampfirst;
+
+                while (*sample >= 0 && component[*sample].offset <= offset)
+                    sample = &component[*sample].sampnext;
+
+                component[n].sampnext = *sample;
+                *sample = n;
+
+                component[n].offset = offset;
+            }
+        }
+
+        m = component[n].sampfirst;
+
+        while (m >= 0) {
+            if (dumbfile_seek(f, component[m].offset, DFS_SEEK_SET)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            if (it_read_sample_data(&sigdata->sample[component[m].n],
+                                    sample_convert[component[m].n], f)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            m = component[m].sampnext;
+        }
+    }
+
+    for (n = 0; n < 10; n++) {
+        if (dumbfile_getc(f) == 'X') {
+            if (dumbfile_getc(f) == 'T') {
+                if (dumbfile_getc(f) == 'P') {
+                    if (dumbfile_getc(f) == 'M') {
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    if (!dumbfile_error(f) && n < 10) {
+        unsigned int mptx_id = (unsigned int)dumbfile_igetl(f);
+        while (!dumbfile_error(f) && mptx_id != DUMB_ID('M', 'P', 'T', 'S')) {
+            unsigned int size = dumbfile_igetw(f);
+            switch (mptx_id) {
+                /* TODO: Add instrument extension readers */
+
+            default:
+                dumbfile_skip(f, size * sigdata->n_instruments);
+                break;
+            }
+
+            mptx_id = (unsigned int)dumbfile_igetl(f);
+        }
+
+        mptx_id = (unsigned int)dumbfile_igetl(f);
+        while (!dumbfile_error(f) && dumbfile_pos(f) < dumbfile_get_size(f)) {
+            unsigned int size = dumbfile_igetw(f);
+            switch (mptx_id) {
+                /* TODO: Add more song extension readers */
+
+            case DUMB_ID('D', 'T', '.', '.'):
+                if (size == 2)
+                    sigdata->tempo = dumbfile_igetw(f);
+                else if (size == 4)
+                    sigdata->tempo = (int)dumbfile_igetl(f);
+                break;
+
+            default:
+                dumbfile_skip(f, size);
+                break;
+            }
+            mptx_id = (unsigned int)dumbfile_igetl(f);
+        }
+    }
+
+    free(buffer);
+    free(component);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+DUH *dumb_read_it_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_load_sigdata(f);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "IT";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/itread2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itread2.c - Function to read an Impulse Tracker    / / \  \
+ *             module from an open file and do an    | <  /   \_
+ *             initial run-through.                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * Split off from itread.c by entheh.                   | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_it(DUMBFILE *f) {
+    DUH *duh = dumb_read_it_quick(f);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/itrender.c
@@ -1,0 +1,6595 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itrender.c - Code to render an Impulse Tracker     / / \  \
+ *              module.                              | <  /   \_
+ *                                                   |  \/ /\   /
+ * Written - painstakingly - by entheh.               \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+#include "internal/it.h"
+#include "internal/lpc.h"
+
+#include "internal/resampler.h"
+
+// Keep this disabled, as it's actually slower than the original C/integer
+// version
+//
+//#ifdef __APPLE__
+//#include <TargetConditionals.h>
+//#if TARGET_CPU_ARM || TARGET_CPU_ARM64
+//#include <arm_neon.h>
+//#define FILTER_NEON
+//#endif
+//#endif
+
+// #define BIT_ARRAY_BULLSHIT
+
+static IT_PLAYING *new_playing() {
+    IT_PLAYING *r = (IT_PLAYING *)malloc(sizeof(*r));
+    if (r) {
+        r->resampler.fir_resampler_ratio = 0.0;
+        r->resampler.fir_resampler[0] = resampler_create();
+        if (!r->resampler.fir_resampler[0]) {
+            free(r);
+            return NULL;
+        }
+        r->resampler.fir_resampler[1] = resampler_create();
+        if (!r->resampler.fir_resampler[1]) {
+            resampler_delete(r->resampler.fir_resampler[0]);
+            free(r);
+            return NULL;
+        }
+    }
+    return r;
+}
+
+static void free_playing(IT_PLAYING *r) {
+    resampler_delete(r->resampler.fir_resampler[1]);
+    resampler_delete(r->resampler.fir_resampler[0]);
+    free(r);
+}
+
+static IT_PLAYING *dup_playing(IT_PLAYING *src, IT_CHANNEL *dstchannel,
+                               IT_CHANNEL *srcchannel) {
+    IT_PLAYING *dst;
+
+    if (!src)
+        return NULL;
+
+    dst = malloc(sizeof(*dst));
+    if (!dst)
+        return NULL;
+
+    dst->flags = src->flags;
+    dst->resampling_quality = src->resampling_quality;
+
+    ASSERT(src->channel);
+    dst->channel = &dstchannel[src->channel - srcchannel];
+    dst->sample = src->sample;
+    dst->instrument = src->instrument;
+    dst->env_instrument = src->env_instrument;
+
+    dst->sampnum = src->sampnum;
+    dst->instnum = src->instnum;
+
+    dst->declick_stage = src->declick_stage;
+
+    dst->float_volume[0] = src->float_volume[0];
+    dst->float_volume[1] = src->float_volume[1];
+
+    dst->ramp_volume[0] = src->ramp_volume[0];
+    dst->ramp_volume[1] = src->ramp_volume[1];
+
+    dst->ramp_delta[0] = src->ramp_delta[0];
+    dst->ramp_delta[1] = src->ramp_delta[1];
+
+    dst->channel_volume = src->channel_volume;
+
+    dst->volume = src->volume;
+    dst->pan = src->pan;
+
+    dst->volume_offset = src->volume_offset;
+    dst->panning_offset = src->panning_offset;
+
+    dst->note = src->note;
+
+    dst->enabled_envelopes = src->enabled_envelopes;
+
+    dst->filter_cutoff = src->filter_cutoff;
+    dst->filter_resonance = src->filter_resonance;
+
+    dst->true_filter_cutoff = src->true_filter_cutoff;
+    dst->true_filter_resonance = src->true_filter_resonance;
+
+    dst->vibrato_speed = src->vibrato_speed;
+    dst->vibrato_depth = src->vibrato_depth;
+    dst->vibrato_n = src->vibrato_n;
+    dst->vibrato_time = src->vibrato_time;
+    dst->vibrato_waveform = src->vibrato_waveform;
+
+    dst->tremolo_speed = src->tremolo_speed;
+    dst->tremolo_depth = src->tremolo_depth;
+    dst->tremolo_time = src->tremolo_time;
+    dst->tremolo_waveform = src->tremolo_waveform;
+
+    dst->panbrello_speed = src->panbrello_speed;
+    dst->panbrello_depth = src->panbrello_depth;
+    dst->panbrello_time = src->panbrello_time;
+    dst->panbrello_waveform = src->panbrello_waveform;
+    dst->panbrello_random = src->panbrello_random;
+
+    dst->sample_vibrato_time = src->sample_vibrato_time;
+    dst->sample_vibrato_waveform = src->sample_vibrato_waveform;
+    dst->sample_vibrato_depth = src->sample_vibrato_depth;
+
+    dst->slide = src->slide;
+    dst->delta = src->delta;
+    dst->finetune = src->finetune;
+
+    dst->volume_envelope = src->volume_envelope;
+    dst->pan_envelope = src->pan_envelope;
+    dst->pitch_envelope = src->pitch_envelope;
+
+    dst->fadeoutcount = src->fadeoutcount;
+
+    dst->filter_state[0] = src->filter_state[0];
+    dst->filter_state[1] = src->filter_state[1];
+
+    dst->resampler = src->resampler;
+    dst->resampler.pickup_data = dst;
+    dst->resampler.fir_resampler_ratio = src->resampler.fir_resampler_ratio;
+    dst->resampler.fir_resampler[0] =
+        resampler_dup(src->resampler.fir_resampler[0]);
+    if (!dst->resampler.fir_resampler[0]) {
+        free(dst);
+        return NULL;
+    }
+    dst->resampler.fir_resampler[1] =
+        resampler_dup(src->resampler.fir_resampler[1]);
+    if (!dst->resampler.fir_resampler[1]) {
+        resampler_delete(dst->resampler.fir_resampler[0]);
+        free(dst);
+        return NULL;
+    }
+    dst->time_lost = src->time_lost;
+
+    // dst->output = src->output;
+
+    return dst;
+}
+
+static void dup_channel(IT_CHANNEL *dst, IT_CHANNEL *src) {
+    dst->flags = src->flags;
+
+    dst->volume = src->volume;
+    dst->volslide = src->volslide;
+    dst->xm_volslide = src->xm_volslide;
+    dst->panslide = src->panslide;
+
+    dst->pan = src->pan;
+    dst->truepan = src->truepan;
+
+    dst->channelvolume = src->channelvolume;
+    dst->channelvolslide = src->channelvolslide;
+
+    dst->instrument = src->instrument;
+    dst->note = src->note;
+
+    dst->SFmacro = src->SFmacro;
+
+    dst->filter_cutoff = src->filter_cutoff;
+    dst->filter_resonance = src->filter_resonance;
+
+    dst->key_off_count = src->key_off_count;
+    dst->note_cut_count = src->note_cut_count;
+    dst->note_delay_count = src->note_delay_count;
+    dst->note_delay_entry = src->note_delay_entry;
+
+    dst->new_note_action = src->new_note_action;
+
+    dst->arpeggio_table = src->arpeggio_table;
+    memcpy(dst->arpeggio_offsets, src->arpeggio_offsets,
+           sizeof(dst->arpeggio_offsets));
+    dst->retrig = src->retrig;
+    dst->xm_retrig = src->xm_retrig;
+    dst->retrig_tick = src->retrig_tick;
+
+    dst->tremor_time = src->tremor_time;
+
+    dst->vibrato_waveform = src->vibrato_waveform;
+    dst->tremolo_waveform = src->tremolo_waveform;
+    dst->panbrello_waveform = src->panbrello_waveform;
+
+    dst->portamento = src->portamento;
+    dst->toneporta = src->toneporta;
+    dst->toneslide = src->toneslide;
+    dst->toneslide_tick = src->toneslide_tick;
+    dst->last_toneslide_tick = src->last_toneslide_tick;
+    dst->ptm_toneslide = src->ptm_toneslide;
+    dst->ptm_last_toneslide = src->ptm_last_toneslide;
+    dst->okt_toneslide = src->okt_toneslide;
+    dst->destnote = src->destnote;
+
+    dst->glissando = src->glissando;
+
+    dst->sample = src->sample;
+    dst->truenote = src->truenote;
+
+    dst->midi_state = src->midi_state;
+
+    dst->lastvolslide = src->lastvolslide;
+    dst->lastDKL = src->lastDKL;
+    dst->lastEF = src->lastEF;
+    dst->lastG = src->lastG;
+    dst->lastHspeed = src->lastHspeed;
+    dst->lastHdepth = src->lastHdepth;
+    dst->lastRspeed = src->lastRspeed;
+    dst->lastRdepth = src->lastRdepth;
+    dst->lastYspeed = src->lastYspeed;
+    dst->lastYdepth = src->lastYdepth;
+    dst->lastI = src->lastI;
+    dst->lastJ = src->lastJ;
+    dst->lastN = src->lastN;
+    dst->lastO = src->lastO;
+    dst->high_offset = src->high_offset;
+    dst->lastP = src->lastP;
+    dst->lastQ = src->lastQ;
+    dst->lastS = src->lastS;
+    dst->pat_loop_row = src->pat_loop_row;
+    dst->pat_loop_count = src->pat_loop_count;
+    dst->pat_loop_end_row = src->pat_loop_end_row;
+    dst->lastW = src->lastW;
+
+    dst->xm_lastE1 = src->xm_lastE1;
+    dst->xm_lastE2 = src->xm_lastE2;
+    dst->xm_lastEA = src->xm_lastEA;
+    dst->xm_lastEB = src->xm_lastEB;
+    dst->xm_lastX1 = src->xm_lastX1;
+    dst->xm_lastX2 = src->xm_lastX2;
+
+    dst->inv_loop_delay = src->inv_loop_delay;
+    dst->inv_loop_speed = src->inv_loop_speed;
+    dst->inv_loop_offset = src->inv_loop_offset;
+
+    dst->playing = dup_playing(src->playing, dst, src);
+
+#ifdef BIT_ARRAY_BULLSHIT
+    dst->played_patjump = bit_array_dup(src->played_patjump);
+    dst->played_patjump_order = src->played_patjump_order;
+#endif
+
+    // dst->output = src->output;
+}
+
+/* Allocate the new callbacks first, then pass them to this function!
+ * It will free them on failure.
+ */
+static DUMB_IT_SIGRENDERER *dup_sigrenderer(DUMB_IT_SIGRENDERER *src,
+                                            int n_channels,
+                                            IT_CALLBACKS *callbacks) {
+    DUMB_IT_SIGRENDERER *dst;
+    int i;
+
+    if (!src) {
+        if (callbacks)
+            free(callbacks);
+        return NULL;
+    }
+
+    dst = malloc(sizeof(*dst));
+    if (!dst) {
+        if (callbacks)
+            free(callbacks);
+        return NULL;
+    }
+
+    dst->sigdata = src->sigdata;
+
+    dst->n_channels = n_channels;
+
+    dst->resampling_quality = src->resampling_quality;
+
+    dst->globalvolume = src->globalvolume;
+    dst->globalvolslide = src->globalvolslide;
+
+    dst->tempo = src->tempo;
+    dst->temposlide = src->temposlide;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++)
+        dup_channel(&dst->channel[i], &src->channel[i]);
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
+        dst->playing[i] =
+            dup_playing(src->playing[i], dst->channel, src->channel);
+
+    dst->tick = src->tick;
+    dst->speed = src->speed;
+    dst->rowcount = src->rowcount;
+
+    dst->order = src->order;
+    dst->row = src->row;
+    dst->processorder = src->processorder;
+    dst->processrow = src->processrow;
+    dst->breakrow = src->breakrow;
+
+    dst->restart_position = src->restart_position;
+
+    dst->n_rows = src->n_rows;
+
+    dst->entry_start = src->entry_start;
+    dst->entry = src->entry;
+    dst->entry_end = src->entry_end;
+
+    dst->time_left = src->time_left;
+    dst->sub_time_left = src->sub_time_left;
+
+    dst->ramp_style = src->ramp_style;
+
+    dst->click_remover = NULL;
+
+    dst->callbacks = callbacks;
+
+#ifdef BIT_ARRAY_BULLSHIT
+    dst->played = bit_array_dup(src->played);
+
+    dst->looped = src->looped;
+    dst->time_played = src->time_played;
+    dst->row_timekeeper = timekeeping_array_dup(src->row_timekeeper);
+#endif
+
+    dst->gvz_time = src->gvz_time;
+    dst->gvz_sub_time = src->gvz_sub_time;
+
+    // dst->max_output = src->max_output;
+
+    return dst;
+}
+
+static const IT_MIDI default_midi = {
+    /* unsigned char SFmacro[16][16]; */
+    {{0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00}},
+    /* unsigned char SFmacrolen[16]; */
+    {4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+    /* unsigned short SFmacroz[16]; */
+    /* Bitfield; bit 0 set = z in first position */
+    {0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
+    /* unsigned char Zmacro[128][16]; */
+    {{0xF0, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0xF0, 0xF0, 0x01, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00},
+     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00}},
+    /* unsigned char Zmacrolen[128]; */
+    {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0,
+     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+
+static void it_reset_filter_state(IT_FILTER_STATE *state) {
+    state->currsample = 0;
+    state->prevsample = 0;
+}
+
+#define LOG10 2.30258509299
+
+/* IMPORTANT: This function expects one extra sample in 'src' so it can apply
+ * click removal. It reads size samples, starting from src[0], and writes its
+ * output starting at dst[pos]. The pos parameter is required for getting
+ * click removal right.
+ */
+
+static void it_filter_int(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state,
+                          sample_t *dst, long pos, sample_t *src, long size,
+                          int step, int sampfreq, int cutoff, int resonance) {
+    sample_t currsample = state->currsample;
+    sample_t prevsample = state->prevsample;
+
+    float a, b, c;
+
+    long datasize;
+
+    {
+        float inv_angle =
+            (float)(sampfreq *
+                    pow(0.5,
+                        0.25 + cutoff * (1.0 / (24 << IT_ENVELOPE_SHIFT))) *
+                    (1.0 / (2 * 3.14159265358979323846 * 110.0)));
+        float loss = (float)exp(resonance * (-LOG10 * 1.2 / 128.0));
+        float d, e;
+#if 0
+		loss *= 2; // This is the mistake most players seem to make!
+#endif
+
+#if 1
+        d = (1.0f - loss) / inv_angle;
+        if (d > 2.0f)
+            d = 2.0f;
+        d = (loss - d) * inv_angle;
+        e = inv_angle * inv_angle;
+        a = 1.0f / (1.0f + d + e);
+        c = -e * a;
+        b = 1.0f - a - c;
+#else
+        a = 1.0f / (inv_angle * inv_angle + inv_angle * loss + loss);
+        c = -(inv_angle * inv_angle) * a;
+        b = 1.0f - a - c;
+#endif
+    }
+
+    dst += pos * step;
+    datasize = size * step;
+
+#define INT_FILTERS
+#ifdef INT_FILTERS
+#define MULSCA(a, b) ((int)((LONG_LONG)((a) << 4) * (b) >> 32))
+#define SCALEB 12
+    {
+        int ai = (int)(a * (1 << (16 + SCALEB)));
+        int bi = (int)(b * (1 << (16 + SCALEB)));
+        int ci = (int)(c * (1 << (16 + SCALEB)));
+        int i;
+
+        if (cr) {
+            sample_t startstep = MULSCA(src[0], ai) + MULSCA(currsample, bi) +
+                                 MULSCA(prevsample, ci);
+            dumb_record_click(cr, pos, startstep);
+        }
+
+        for (i = 0; i < datasize; i += step) {
+            {
+                sample_t newsample = MULSCA(src[i], ai) +
+                                     MULSCA(currsample, bi) +
+                                     MULSCA(prevsample, ci);
+                prevsample = currsample;
+                currsample = newsample;
+            }
+            dst[i] += currsample;
+        }
+
+        if (cr) {
+            sample_t endstep = MULSCA(src[datasize], ai) +
+                               MULSCA(currsample, bi) + MULSCA(prevsample, ci);
+            dumb_record_click(cr, pos + size, -endstep);
+        }
+    }
+#else
+#error This version is broken - it does not use step, and state should contain floats for it
+    if (cr) {
+        float startstep = src[0] * a + currsample * b + prevsample * c;
+        dumb_record_click(cr, pos, (sample_t)startstep);
+    }
+
+    {
+        int i = size % 3;
+        while (i > 0) {
+            {
+                float newsample = *src++ * a + currsample * b + prevsample * c;
+                prevsample = currsample;
+                currsample = newsample;
+            }
+            *dst++ += (sample_t)currsample;
+            i--;
+        }
+        i = size / 3;
+        while (i > 0) {
+            float newsample;
+            /* Gotta love unrolled loops! */
+            *dst++ += (sample_t)(newsample = *src++ * a + currsample * b +
+                                             prevsample * c);
+            *dst++ += (sample_t)(prevsample = *src++ * a + newsample * b +
+                                              currsample * c);
+            *dst++ += (sample_t)(currsample = *src++ * a + prevsample * b +
+                                              newsample * c);
+            i--;
+        }
+    }
+
+    if (cr) {
+        float endstep = src[datasize] * a + currsample * b + prevsample * c;
+        dumb_record_click(cr, pos + size, -(sample_t)endstep);
+    }
+#endif
+
+    state->currsample = currsample;
+    state->prevsample = prevsample;
+}
+
+#if defined(_USE_SSE) && (defined(_M_IX86) || defined(__i386__) ||             \
+                          defined(_M_X64) || defined(__amd64__))
+#include <xmmintrin.h>
+
+static void it_filter_sse(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state,
+                          sample_t *dst, long pos, sample_t *src, long size,
+                          int step, int sampfreq, int cutoff, int resonance) {
+    __m128 data, impulse;
+    __m128 temp1, temp2;
+
+    sample_t currsample = state->currsample;
+    sample_t prevsample = state->prevsample;
+
+    float imp[4];
+
+    // profiler( filter_sse ); On ClawHammer Athlon64 3200+, ~12000 cycles, ~500
+    // for that x87 setup code (as opposed to ~25500 for the original integer
+    // code)
+
+    long datasize;
+
+    {
+        float inv_angle =
+            (float)(sampfreq *
+                    pow(0.5,
+                        0.25 + cutoff * (1.0 / (24 << IT_ENVELOPE_SHIFT))) *
+                    (1.0 / (2 * 3.14159265358979323846 * 110.0)));
+        float loss = (float)exp(resonance * (-LOG10 * 1.2 / 128.0));
+        float d, e;
+#if 0
+		loss *= 2; // This is the mistake most players seem to make!
+#endif
+
+#if 1
+        d = (1.0f - loss) / inv_angle;
+        if (d > 2.0f)
+            d = 2.0f;
+        d = (loss - d) * inv_angle;
+        e = inv_angle * inv_angle;
+        imp[0] = 1.0f / (1.0f + d + e);
+        imp[2] = -e * imp[0];
+        imp[1] = 1.0f - imp[0] - imp[2];
+#else
+        imp[0] = 1.0f / (inv_angle * inv_angle + inv_angle * loss + loss);
+        imp[2] = -(inv_angle * inv_angle) * imp[0];
+        imp[1] = 1.0f - imp[0] - imp[2];
+#endif
+        imp[3] = 0.0f;
+    }
+
+    dst += pos * step;
+    datasize = size * step;
+
+    {
+        int ai, bi, ci, i;
+
+        if (cr) {
+            sample_t startstep;
+            ai = (int)(imp[0] * (1 << (16 + SCALEB)));
+            bi = (int)(imp[1] * (1 << (16 + SCALEB)));
+            ci = (int)(imp[2] * (1 << (16 + SCALEB)));
+            startstep = MULSCA(src[0], ai) + MULSCA(currsample, bi) +
+                        MULSCA(prevsample, ci);
+            dumb_record_click(cr, pos, startstep);
+        }
+
+        temp1 = _mm_setzero_ps();
+        data = _mm_cvtsi32_ss(temp1, currsample);
+        temp2 = _mm_cvtsi32_ss(temp1, prevsample);
+        impulse = _mm_loadu_ps((const float *)&imp);
+        data = _mm_shuffle_ps(data, temp2, _MM_SHUFFLE(1, 0, 0, 1));
+
+        for (i = 0; i < datasize; i += step) {
+            temp1 = _mm_cvtsi32_ss(data, src[i]);
+            temp1 = _mm_mul_ps(temp1, impulse);
+            temp2 = _mm_movehl_ps(temp2, temp1);
+            temp1 = _mm_add_ps(temp1, temp2);
+            temp2 = temp1;
+            temp2 = _mm_shuffle_ps(temp2, temp1, _MM_SHUFFLE(0, 0, 0, 1));
+            temp1 = _mm_add_ps(temp1, temp2);
+            temp1 = _mm_shuffle_ps(temp1, data, _MM_SHUFFLE(2, 1, 0, 0));
+            data = temp1;
+            dst[i] += _mm_cvtss_si32(temp1);
+        }
+
+        currsample = _mm_cvtss_si32(temp1);
+        temp1 = _mm_shuffle_ps(temp1, data, _MM_SHUFFLE(0, 0, 0, 2));
+        prevsample = _mm_cvtss_si32(temp1);
+
+        if (cr) {
+            sample_t endstep = MULSCA(src[datasize], ai) +
+                               MULSCA(currsample, bi) + MULSCA(prevsample, ci);
+            dumb_record_click(cr, pos + size, -endstep);
+        }
+    }
+
+    state->currsample = currsample;
+    state->prevsample = prevsample;
+}
+#endif
+
+#ifdef FILTER_NEON
+static void it_filter_neon(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state,
+                           sample_t *dst, long pos, sample_t *src, long size,
+                           int step, int sampfreq, int cutoff, int resonance) {
+    float32x4_t data, impulse;
+    float32x4_t temp1;
+    float32x2_t temp2;
+    float32_t temp3;
+
+    sample_t currsample = state->currsample;
+    sample_t prevsample = state->prevsample;
+
+    float imp[4];
+
+    // profiler( filter_sse ); On ClawHammer Athlon64 3200+, ~12000 cycles, ~500
+    // for that x87 setup code (as opposed to ~25500 for the original integer
+    // code)
+
+    long datasize;
+
+    {
+        float inv_angle =
+            (float)(sampfreq *
+                    pow(0.5,
+                        0.25 + cutoff * (1.0 / (24 << IT_ENVELOPE_SHIFT))) *
+                    (1.0 / (2 * 3.14159265358979323846 * 110.0)));
+        float loss = (float)exp(resonance * (-LOG10 * 1.2 / 128.0));
+        float d, e;
+#if 0
+        loss *= 2; // This is the mistake most players seem to make!
+#endif
+
+#if 1
+        d = (1.0f - loss) / inv_angle;
+        if (d > 2.0f)
+            d = 2.0f;
+        d = (loss - d) * inv_angle;
+        e = inv_angle * inv_angle;
+        imp[0] = 1.0f / (1.0f + d + e);
+        imp[2] = -e * imp[0];
+        imp[1] = 1.0f - imp[0] - imp[2];
+#else
+        imp[0] = 1.0f / (inv_angle * inv_angle + inv_angle * loss + loss);
+        imp[2] = -(inv_angle * inv_angle) * imp[0];
+        imp[1] = 1.0f - imp[0] - imp[2];
+#endif
+        imp[3] = 0.0f;
+    }
+
+    dst += pos * step;
+    datasize = size * step;
+
+    {
+        int ai, bi, ci, i;
+
+        if (cr) {
+            sample_t startstep;
+            ai = (int)(imp[0] * (1 << (16 + SCALEB)));
+            bi = (int)(imp[1] * (1 << (16 + SCALEB)));
+            ci = (int)(imp[2] * (1 << (16 + SCALEB)));
+            startstep = MULSCA(src[0], ai) + MULSCA(currsample, bi) +
+                        MULSCA(prevsample, ci);
+            dumb_record_click(cr, pos, startstep);
+        }
+
+        data = vdupq_n_f32(0.0f);
+        data = vsetq_lane_f32(currsample, data, 1);
+        data = vsetq_lane_f32(prevsample, data, 2);
+        impulse = vld1q_f32((const float32_t *)&imp);
+
+        for (i = 0; i < datasize; i += step) {
+            data = vsetq_lane_f32(src[i], data, 0);
+            temp1 = vmulq_f32(data, impulse);
+            temp2 = vadd_f32(vget_high_f32(temp1), vget_low_f32(temp1));
+            temp3 = vget_lane_f32(vpadd_f32(temp2, temp2), 0);
+            data = vextq_f32(data, data, 3);
+            data = vsetq_lane_f32(temp3, data, 1);
+            dst[i] += temp3;
+        }
+
+        currsample = temp3;
+        prevsample = vgetq_lane_f32(data, 2);
+
+        if (cr) {
+            sample_t endstep = MULSCA(src[datasize], ai) +
+                               MULSCA(currsample, bi) + MULSCA(prevsample, ci);
+            dumb_record_click(cr, pos + size, -endstep);
+        }
+    }
+
+    state->currsample = currsample;
+    state->prevsample = prevsample;
+}
+#endif
+
+#undef LOG10
+
+#ifdef _USE_SSE
+#if defined(_M_IX86) || defined(__i386__)
+
+#ifdef _MSC_VER
+#include <intrin.h>
+#elif defined(__clang__) || defined(__GNUC__)
+static inline void __cpuid(int *data, int selector) {
+#if defined(__PIC__) && defined(__i386__)
+    asm("xchgl %%ebx, %%esi; cpuid; xchgl %%ebx, %%esi"
+        : "=a"(data[0]), "=S"(data[1]), "=c"(data[2]), "=d"(data[3])
+        : "0"(selector));
+#elif defined(__PIC__) && defined(__amd64__)
+    asm("xchg{q} {%%}rbx, %q1; cpuid; xchg{q} {%%}rbx, %q1"
+        : "=a"(data[0]), "=&r"(data[1]), "=c"(data[2]), "=d"(data[3])
+        : "0"(selector));
+#else
+    asm("cpuid"
+        : "=a"(data[0]), "=b"(data[1]), "=c"(data[2]), "=d"(data[3])
+        : "a"(selector));
+#endif
+}
+#else
+#define __cpuid(a, b) memset((a), 0, sizeof(int) * 4)
+#endif
+
+static int query_cpu_feature_sse() {
+    int buffer[4];
+    __cpuid(buffer, 1);
+    if ((buffer[3] & (1 << 25)) == 0)
+        return 0;
+    return 1;
+}
+
+static int _dumb_it_use_sse = 0;
+
+void _dumb_init_sse() {
+    static int initialized = 0;
+    if (!initialized) {
+        _dumb_it_use_sse = query_cpu_feature_sse();
+        initialized = 1;
+    }
+}
+
+#elif defined(_M_X64) || defined(__amd64__)
+
+static const int _dumb_it_use_sse = 1;
+
+void _dumb_init_sse() {}
+
+#else
+
+static const int _dumb_it_use_sse = 0;
+
+void _dumb_init_sse() {}
+
+#endif
+#endif
+
+static void it_filter(DUMB_CLICK_REMOVER *cr, IT_FILTER_STATE *state,
+                      sample_t *dst, long pos, sample_t *src, long size,
+                      int step, int sampfreq, int cutoff, int resonance) {
+#if defined(_USE_SSE) && (defined(_M_IX86) || defined(__i386__) ||             \
+                          defined(_M_X64) || defined(__amd64__))
+    _dumb_init_sse();
+    if (_dumb_it_use_sse)
+        it_filter_sse(cr, state, dst, pos, src, size, step, sampfreq, cutoff,
+                      resonance);
+    else
+#endif
+#ifdef FILTER_NEON
+        it_filter_neon(cr, state, dst, pos, src, size, step, sampfreq, cutoff,
+                       resonance);
+#else
+    it_filter_int(cr, state, dst, pos, src, size, step, sampfreq, cutoff,
+                  resonance);
+#endif
+}
+
+static const signed char it_sine[256] = {
+    0,   2,   3,   5,   6,   8,   9,   11,  12,  14,  16,  17,  19,  20,  22,
+    23,  24,  26,  27,  29,  30,  32,  33,  34,  36,  37,  38,  39,  41,  42,
+    43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  56,
+    57,  58,  59,  59,  60,  60,  61,  61,  62,  62,  62,  63,  63,  63,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  63,  63,  63,  62,  62,
+    62,  61,  61,  60,  60,  59,  59,  58,  57,  56,  56,  55,  54,  53,  52,
+    51,  50,  49,  48,  47,  46,  45,  44,  43,  42,  41,  39,  38,  37,  36,
+    34,  33,  32,  30,  29,  27,  26,  24,  23,  22,  20,  19,  17,  16,  14,
+    12,  11,  9,   8,   6,   5,   3,   2,   0,   -2,  -3,  -5,  -6,  -8,  -9,
+    -11, -12, -14, -16, -17, -19, -20, -22, -23, -24, -26, -27, -29, -30, -32,
+    -33, -34, -36, -37, -38, -39, -41, -42, -43, -44, -45, -46, -47, -48, -49,
+    -50, -51, -52, -53, -54, -55, -56, -56, -57, -58, -59, -59, -60, -60, -61,
+    -61, -62, -62, -62, -63, -63, -63, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -63, -63, -63, -62, -62, -62, -61, -61, -60, -60, -59, -59,
+    -58, -57, -56, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, -46, -45,
+    -44, -43, -42, -41, -39, -38, -37, -36, -34, -33, -32, -30, -29, -27, -26,
+    -24, -23, -22, -20, -19, -17, -16, -14, -12, -11, -9,  -8,  -6,  -5,  -3,
+    -2};
+
+#if 1
+/** WARNING: use these! */
+/** JULIEN: Plus for XM compatibility it could be interesting to rename
+ * it_sawtooth[] to it_rampdown[], and add an it_rampup[].
+ * Also, still for XM compat', twood be good if it was possible to tell the
+ * the player not to retrig' the waveform on a new instrument.
+ * Both of these are only for completness though, as I don't think it would
+ * be very noticeable ;)
+ */
+/** ENTHEH: IT also has the 'don't retrig' thingy :) */
+static const signed char it_sawtooth[256] = {
+    64,  63,  63,  62,  62,  61,  61,  60,  60,  59,  59,  58,  58,  57,  57,
+    56,  56,  55,  55,  54,  54,  53,  53,  52,  52,  51,  51,  50,  50,  49,
+    49,  48,  48,  47,  47,  46,  46,  45,  45,  44,  44,  43,  43,  42,  42,
+    41,  41,  40,  40,  39,  39,  38,  38,  37,  37,  36,  36,  35,  35,  34,
+    34,  33,  33,  32,  32,  31,  31,  30,  30,  29,  29,  28,  28,  27,  27,
+    26,  26,  25,  25,  24,  24,  23,  23,  22,  22,  21,  21,  20,  20,  19,
+    19,  18,  18,  17,  17,  16,  16,  15,  15,  14,  14,  13,  13,  12,  12,
+    11,  11,  10,  10,  9,   9,   8,   8,   7,   7,   6,   6,   5,   5,   4,
+    4,   3,   3,   2,   2,   1,   1,   0,   0,   -1,  -1,  -2,  -2,  -3,  -3,
+    -4,  -4,  -5,  -5,  -6,  -6,  -7,  -7,  -8,  -8,  -9,  -9,  -10, -10, -11,
+    -11, -12, -12, -13, -13, -14, -14, -15, -15, -16, -16, -17, -17, -18, -18,
+    -19, -19, -20, -20, -21, -21, -22, -22, -23, -23, -24, -24, -25, -25, -26,
+    -26, -27, -27, -28, -28, -29, -29, -30, -30, -31, -31, -32, -32, -33, -33,
+    -34, -34, -35, -35, -36, -36, -37, -37, -38, -38, -39, -39, -40, -40, -41,
+    -41, -42, -42, -43, -43, -44, -44, -45, -45, -46, -46, -47, -47, -48, -48,
+    -49, -49, -50, -50, -51, -51, -52, -52, -53, -53, -54, -54, -55, -55, -56,
+    -56, -57, -57, -58, -58, -59, -59, -60, -60, -61, -61, -62, -62, -63, -63,
+    -64};
+
+static const signed char it_squarewave[256] = {
+    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
+    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+    0,  0,  0,  0,  0,  0,  0,  0,  0};
+
+static const signed char it_xm_ramp[256] = {
+    0,   -1,  -1,  -2,  -2,  -3,  -3,  -4,  -4,  -5,  -5,  -6,  -6,  -7,  -7,
+    -8,  -8,  -9,  -9,  -10, -10, -11, -11, -12, -12, -13, -13, -14, -14, -15,
+    -15, -16, -16, -17, -17, -18, -18, -19, -19, -20, -20, -21, -21, -22, -22,
+    -23, -23, -24, -24, -25, -25, -26, -26, -27, -27, -28, -28, -29, -29, -30,
+    -30, -31, -31, -32, -32, -33, -33, -34, -34, -35, -35, -36, -36, -37, -37,
+    -38, -38, -39, -39, -40, -40, -41, -41, -42, -42, -43, -43, -44, -44, -45,
+    -45, -46, -46, -47, -47, -48, -48, -49, -49, -50, -50, -51, -51, -52, -52,
+    -53, -53, -54, -54, -55, -55, -56, -56, -57, -57, -58, -58, -59, -59, -60,
+    -60, -61, -61, -62, -62, -63, -63, -64, 64,  63,  63,  62,  62,  61,  61,
+    60,  60,  59,  59,  58,  58,  57,  57,  56,  56,  55,  55,  54,  54,  53,
+    53,  52,  52,  51,  51,  50,  50,  49,  49,  48,  48,  47,  47,  46,  46,
+    45,  45,  44,  44,  43,  43,  42,  42,  41,  41,  40,  40,  39,  39,  38,
+    38,  37,  37,  36,  36,  35,  35,  34,  34,  33,  33,  32,  32,  31,  31,
+    30,  30,  29,  29,  28,  28,  27,  27,  26,  26,  25,  25,  24,  24,  23,
+    23,  22,  22,  21,  21,  20,  20,  19,  19,  18,  18,  17,  17,  16,  16,
+    15,  15,  14,  14,  13,  13,  12,  12,  11,  11,  10,  10,  9,   9,   8,
+    8,   7,   7,   6,   6,   5,   5,   4,   4,   3,   3,   2,   2,   1,   1,
+    0};
+
+static const signed char it_xm_squarewave[256] = {
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,  64,
+    64,  64,  64,  64,  64,  64,  64,  64,  -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
+    -64};
+
+#endif
+
+static void reset_tick_counts(DUMB_IT_SIGRENDERER *sigrenderer) {
+    int i;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        IT_CHANNEL *channel = &sigrenderer->channel[i];
+        channel->key_off_count = 0;
+        channel->note_cut_count = 0;
+        channel->note_delay_count = 0;
+    }
+}
+
+static const unsigned char arpeggio_mod[32] = {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1,
+                                               2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0,
+                                               1, 2, 0, 1, 2, 0, 1, 2, 0, 1};
+static const unsigned char arpeggio_xm[32] = {0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1,
+                                              2, 0, 1, 2, 0, 0, 2, 2, 2, 2, 2,
+                                              2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
+static const unsigned char arpeggio_okt_3[32] = {
+    1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1,
+    0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0};
+static const unsigned char arpeggio_okt_4[32] = {
+    0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1,
+    0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1, 0, 2, 0, 1};
+static const unsigned char arpeggio_okt_5[32] = {
+    2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2,
+    2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2, 0, 2, 2};
+
+static void reset_channel_effects(IT_CHANNEL *channel) {
+    channel->volslide = 0;
+    channel->xm_volslide = 0;
+    channel->panslide = 0;
+    channel->channelvolslide = 0;
+    channel->arpeggio_table = (const unsigned char *)&arpeggio_mod;
+    memset(channel->arpeggio_offsets, 0, sizeof(channel->arpeggio_offsets));
+    channel->retrig = 0;
+    if (channel->xm_retrig) {
+        channel->xm_retrig = 0;
+        channel->retrig_tick = 0;
+    }
+    channel->tremor_time &= 127;
+    channel->portamento = 0;
+    channel->toneporta = 0;
+    if (channel->ptm_toneslide) {
+        channel->ptm_last_toneslide = channel->ptm_toneslide;
+        channel->last_toneslide_tick = channel->toneslide_tick;
+    } else
+        channel->ptm_last_toneslide = 0;
+    channel->ptm_toneslide = 0;
+    channel->toneslide_tick = 0;
+    channel->okt_toneslide = 0;
+    if (channel->playing) {
+        channel->playing->vibrato_n = 0;
+        channel->playing->tremolo_speed = 0;
+        channel->playing->tremolo_depth = 0;
+        channel->playing->panbrello_speed = 0;
+    }
+}
+
+static void reset_effects(DUMB_IT_SIGRENDERER *sigrenderer) {
+    int i;
+
+    sigrenderer->globalvolslide = 0;
+    sigrenderer->temposlide = 0;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        reset_channel_effects(&sigrenderer->channel[i]);
+    }
+}
+
+static void update_tremor(IT_CHANNEL *channel) {
+    if ((channel->tremor_time & 128) && channel->playing) {
+        if (channel->tremor_time == 128)
+            channel->tremor_time = (channel->lastI >> 4) | 192;
+        else if (channel->tremor_time == 192)
+            channel->tremor_time = (channel->lastI & 15) | 128;
+        else
+            channel->tremor_time--;
+    }
+}
+
+static void it_pickup_loop(DUMB_RESAMPLER *resampler, void *data) {
+    resampler->pos -= resampler->end - resampler->start;
+    ((IT_PLAYING *)data)->time_lost += resampler->end - resampler->start;
+}
+
+static void it_pickup_pingpong_loop(DUMB_RESAMPLER *resampler, void *data) {
+    if (resampler->dir < 0) {
+        resampler->pos = (resampler->start << 1) - 1 - resampler->pos;
+        resampler->subpos ^= 65535;
+        resampler->dir = 1;
+        ((IT_PLAYING *)data)->time_lost += (resampler->end - resampler->start)
+                                           << 1;
+    } else {
+        resampler->pos = (resampler->end << 1) - 1 - resampler->pos;
+        resampler->subpos ^= 65535;
+        resampler->dir = -1;
+    }
+}
+
+static void it_pickup_stop_at_end(DUMB_RESAMPLER *resampler, void *data) {
+    (void)data;
+
+    if (resampler->dir < 0) {
+        resampler->pos = (resampler->start << 1) - 1 - resampler->pos;
+        resampler->subpos ^= 65535;
+        /* By rights, time_lost would be updated here. However, there is no
+         * need at this point; it will not be used.
+         *
+         * ((IT_PLAYING *)data)->time_lost += (resampler->src_end -
+         * resampler->src_start) << 1;
+         */
+        resampler->dir = 1;
+    } else
+        resampler->dir = 0;
+}
+
+static void it_pickup_stop_after_reverse(DUMB_RESAMPLER *resampler,
+                                         void *data) {
+    (void)data;
+
+    resampler->dir = 0;
+}
+
+static void it_playing_update_resamplers(IT_PLAYING *playing) {
+    if ((playing->sample->flags & IT_SAMPLE_SUS_LOOP) &&
+        !(playing->flags & IT_PLAYING_SUSTAINOFF)) {
+        playing->resampler.start = playing->sample->sus_loop_start;
+        playing->resampler.end = playing->sample->sus_loop_end;
+        if (playing->resampler.start == playing->resampler.end)
+            playing->resampler.pickup = &it_pickup_stop_at_end;
+        else if (playing->sample->flags & IT_SAMPLE_PINGPONG_SUS_LOOP)
+            playing->resampler.pickup = &it_pickup_pingpong_loop;
+        else
+            playing->resampler.pickup = &it_pickup_loop;
+    } else if (playing->sample->flags & IT_SAMPLE_LOOP) {
+        playing->resampler.start = playing->sample->loop_start;
+        playing->resampler.end = playing->sample->loop_end;
+        if (playing->resampler.start == playing->resampler.end)
+            playing->resampler.pickup = &it_pickup_stop_at_end;
+        else if (playing->sample->flags & IT_SAMPLE_PINGPONG_LOOP)
+            playing->resampler.pickup = &it_pickup_pingpong_loop;
+        else
+            playing->resampler.pickup = &it_pickup_loop;
+    } else if (playing->flags & IT_PLAYING_REVERSE) {
+        playing->resampler.start = 0;
+        playing->resampler.end = playing->sample->length;
+        playing->resampler.dir = -1;
+        playing->resampler.pickup = &it_pickup_stop_after_reverse;
+    } else {
+        if (playing->sample->flags & IT_SAMPLE_SUS_LOOP)
+            playing->resampler.start = playing->sample->sus_loop_start;
+        else
+            playing->resampler.start = 0;
+        playing->resampler.end = playing->sample->length;
+        playing->resampler.pickup = &it_pickup_stop_at_end;
+    }
+    ASSERT(playing->resampler.pickup_data == playing);
+}
+
+/* This should be called whenever the sample or sample position changes. */
+static void it_playing_reset_resamplers(IT_PLAYING *playing, long pos) {
+    int bits = playing->sample->flags & IT_SAMPLE_16BIT ? 16 : 8;
+    int quality = playing->resampling_quality;
+    int channels = playing->sample->flags & IT_SAMPLE_STEREO ? 2 : 1;
+    if (playing->sample->max_resampling_quality >= 0 &&
+        quality > playing->sample->max_resampling_quality)
+        quality = playing->sample->max_resampling_quality;
+    dumb_reset_resampler_n(bits, &playing->resampler, playing->sample->data,
+                           channels, pos, 0, 0, quality);
+    playing->resampler.pickup_data = playing;
+    playing->time_lost = 0;
+    playing->flags &= ~IT_PLAYING_DEAD;
+    it_playing_update_resamplers(playing);
+}
+
+static void it_retrigger_note(DUMB_IT_SIGRENDERER *sigrenderer,
+                              IT_CHANNEL *channel);
+
+/* Should we only be retriggering short samples on XM? */
+
+static void update_retrig(DUMB_IT_SIGRENDERER *sigrenderer,
+                          IT_CHANNEL *channel) {
+    if (channel->xm_retrig) {
+        channel->retrig_tick--;
+        if (channel->retrig_tick <= 0) {
+            if (channel->playing) {
+                it_playing_reset_resamplers(channel->playing, 0);
+                channel->playing->declick_stage = 0;
+            } else if (sigrenderer->sigdata->flags & IT_WAS_AN_XM)
+                it_retrigger_note(sigrenderer, channel);
+            channel->retrig_tick = channel->xm_retrig;
+        }
+    } else if (channel->retrig & 0x0F) {
+        channel->retrig_tick--;
+        if (channel->retrig_tick <= 0) {
+            if (channel->retrig < 0x10) {
+            } else if (channel->retrig < 0x20) {
+                channel->volume--;
+                if (channel->volume > 64)
+                    channel->volume = 0;
+            } else if (channel->retrig < 0x30) {
+                channel->volume -= 2;
+                if (channel->volume > 64)
+                    channel->volume = 0;
+            } else if (channel->retrig < 0x40) {
+                channel->volume -= 4;
+                if (channel->volume > 64)
+                    channel->volume = 0;
+            } else if (channel->retrig < 0x50) {
+                channel->volume -= 8;
+                if (channel->volume > 64)
+                    channel->volume = 0;
+            } else if (channel->retrig < 0x60) {
+                channel->volume -= 16;
+                if (channel->volume > 64)
+                    channel->volume = 0;
+            } else if (channel->retrig < 0x70) {
+                channel->volume <<= 1;
+                channel->volume /= 3;
+            } else if (channel->retrig < 0x80) {
+                channel->volume >>= 1;
+            } else if (channel->retrig < 0x90) {
+            } else if (channel->retrig < 0xA0) {
+                channel->volume++;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            } else if (channel->retrig < 0xB0) {
+                channel->volume += 2;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            } else if (channel->retrig < 0xC0) {
+                channel->volume += 4;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            } else if (channel->retrig < 0xD0) {
+                channel->volume += 8;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            } else if (channel->retrig < 0xE0) {
+                channel->volume += 16;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            } else if (channel->retrig < 0xF0) {
+                channel->volume *= 3;
+                channel->volume >>= 1;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            } else {
+                channel->volume <<= 1;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            }
+            if (channel->playing) {
+                it_playing_reset_resamplers(channel->playing, 0);
+                channel->playing->declick_stage = 0;
+            } else if (sigrenderer->sigdata->flags & IT_WAS_AN_XM)
+                it_retrigger_note(sigrenderer, channel);
+            channel->retrig_tick = channel->retrig & 0x0F;
+        }
+    }
+}
+
+static void update_smooth_effects_playing(IT_PLAYING *playing) {
+    playing->vibrato_time += playing->vibrato_n * (playing->vibrato_speed << 2);
+    playing->tremolo_time += playing->tremolo_speed << 2;
+    playing->panbrello_time += playing->panbrello_speed;
+    if (playing->panbrello_waveform == 3)
+        playing->panbrello_random = (rand() % 129) - 64;
+}
+
+static void update_smooth_effects(DUMB_IT_SIGRENDERER *sigrenderer) {
+    int i;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        IT_CHANNEL *channel = &sigrenderer->channel[i];
+        IT_PLAYING *playing = channel->playing;
+
+        if (playing) {
+            update_smooth_effects_playing(playing);
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+        IT_PLAYING *playing = sigrenderer->playing[i];
+
+        if (playing) {
+            update_smooth_effects_playing(playing);
+        }
+    }
+}
+
+static const unsigned char pt_tab_invloop[16] = {
+    0x00, 0x05, 0x06, 0x07, 0x08, 0x0A, 0x0B, 0x0D,
+    0x0F, 0x13, 0x16, 0x1A, 0x20, 0x2B, 0x40, 0x80};
+
+static void update_invert_loop(IT_CHANNEL *channel, IT_SAMPLE *sample) {
+    channel->inv_loop_delay += pt_tab_invloop[channel->inv_loop_speed];
+    if (channel->inv_loop_delay >= 0x80) {
+        channel->inv_loop_delay = 0;
+
+        if (sample &&
+            ((sample->flags & (IT_SAMPLE_EXISTS | IT_SAMPLE_LOOP)) ==
+             (IT_SAMPLE_EXISTS | IT_SAMPLE_LOOP)) &&
+            !(sample->flags & (IT_SAMPLE_STEREO | IT_SAMPLE_16BIT))) {
+            if (sample->loop_end - sample->loop_start >= 4) {
+                channel->inv_loop_offset++;
+                if (channel->inv_loop_offset >=
+                    (sample->loop_end - sample->loop_start))
+                    channel->inv_loop_offset = 0;
+
+                ((char *)sample
+                     ->data)[sample->loop_start + channel->inv_loop_offset] ^=
+                    0xFF;
+            }
+        }
+    }
+}
+
+static void update_playing_effects(IT_PLAYING *playing) {
+    IT_CHANNEL *channel = playing->channel;
+
+    if (channel->channelvolslide) {
+        playing->channel_volume = channel->channelvolume;
+    }
+
+    if (channel->okt_toneslide) {
+        if (channel->okt_toneslide--) {
+            playing->note += channel->toneslide;
+            if (playing->note >= 120) {
+                if (channel->toneslide < 0)
+                    playing->note = 0;
+                else
+                    playing->note = 119;
+            }
+        }
+    } else if (channel->ptm_toneslide) {
+        if (--channel->toneslide_tick == 0) {
+            channel->toneslide_tick = channel->ptm_toneslide;
+            if (playing) {
+                playing->note += channel->toneslide;
+                if (playing->note >= 120) {
+                    if (channel->toneslide < 0)
+                        playing->note = 0;
+                    else
+                        playing->note = 119;
+                }
+                if (channel->playing == playing) {
+                    channel->note = channel->truenote = playing->note;
+                }
+                if (channel->toneslide_retrig) {
+                    it_playing_reset_resamplers(playing, 0);
+                    playing->declick_stage = 0;
+                }
+            }
+        }
+    }
+}
+
+static void update_effects(DUMB_IT_SIGRENDERER *sigrenderer) {
+    int i;
+
+    if (sigrenderer->globalvolslide) {
+        sigrenderer->globalvolume += sigrenderer->globalvolslide;
+        if (sigrenderer->globalvolume > 128) {
+            if (sigrenderer->globalvolslide >= 0)
+                sigrenderer->globalvolume = 128;
+            else
+                sigrenderer->globalvolume = 0;
+        }
+    }
+
+    if (sigrenderer->temposlide) {
+        sigrenderer->tempo += sigrenderer->temposlide;
+        if (sigrenderer->tempo < 32) {
+            if (sigrenderer->temposlide >= 0)
+                sigrenderer->tempo = 255;
+            else
+                sigrenderer->tempo = 32;
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        IT_CHANNEL *channel = &sigrenderer->channel[i];
+        IT_PLAYING *playing = channel->playing;
+
+        if (channel->xm_volslide) {
+            channel->volume += channel->xm_volslide;
+            if (channel->volume > 64) {
+                if (channel->xm_volslide >= 0)
+                    channel->volume = 64;
+                else
+                    channel->volume = 0;
+            }
+        }
+
+        if (channel->volslide) {
+            int clip = (sigrenderer->sigdata->flags & IT_WAS_AN_S3M) ? 63 : 64;
+            channel->volume += channel->volslide;
+            if (channel->volume > clip) {
+                if (channel->volslide >= 0)
+                    channel->volume = clip;
+                else
+                    channel->volume = 0;
+            }
+        }
+
+        if (channel->panslide) {
+            if (sigrenderer->sigdata->flags & IT_WAS_AN_XM) {
+                if (IT_IS_SURROUND(channel->pan)) {
+                    channel->pan = 32;
+                    channel->truepan = 32 + 128 * 64;
+                }
+                if (channel->panslide == -128)
+                    channel->truepan = 32;
+                else
+                    channel->truepan =
+                        MID(32, channel->truepan + channel->panslide * 64,
+                            32 + 255 * 64);
+            } else {
+                if (IT_IS_SURROUND(channel->pan)) {
+                    channel->pan = 32;
+                }
+                channel->pan += channel->panslide;
+                if (channel->pan > 64) {
+                    if (channel->panslide >= 0)
+                        channel->pan = 64;
+                    else
+                        channel->pan = 0;
+                }
+                channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
+            }
+        }
+
+        if (channel->channelvolslide) {
+            channel->channelvolume += channel->channelvolslide;
+            if (channel->channelvolume > 64) {
+                if (channel->channelvolslide >= 0)
+                    channel->channelvolume = 64;
+                else
+                    channel->channelvolume = 0;
+            }
+        }
+
+        update_tremor(channel);
+
+        update_retrig(sigrenderer, channel);
+
+        if (channel->inv_loop_speed)
+            update_invert_loop(channel, playing ? playing->sample : NULL);
+
+        if (playing) {
+            playing->slide += channel->portamento;
+
+            if (sigrenderer->sigdata->flags & IT_LINEAR_SLIDES) {
+                if (channel->toneporta && channel->destnote < 120) {
+                    int currpitch =
+                        ((playing->note - 60) << 8) + playing->slide;
+                    int destpitch = (channel->destnote - 60) << 8;
+                    if (currpitch > destpitch) {
+                        currpitch -= channel->toneporta;
+                        if (currpitch < destpitch) {
+                            currpitch = destpitch;
+                            channel->destnote = IT_NOTE_OFF;
+                        }
+                    } else if (currpitch < destpitch) {
+                        currpitch += channel->toneporta;
+                        if (currpitch > destpitch) {
+                            currpitch = destpitch;
+                            channel->destnote = IT_NOTE_OFF;
+                        }
+                    }
+                    playing->slide = currpitch - ((playing->note - 60) << 8);
+                }
+            } else {
+                if (channel->toneporta && channel->destnote < 120) {
+                    float amiga_multiplier =
+                        playing->sample->C5_speed * (1.0f / AMIGA_DIVISOR);
+
+                    float deltanote =
+                        (float)pow(DUMB_SEMITONE_BASE, 60 - playing->note);
+                    /* deltanote is 1.0 for C-5, 0.5 for C-6, etc. */
+
+                    float deltaslid =
+                        deltanote - playing->slide * amiga_multiplier;
+
+                    float destdelta =
+                        (float)pow(DUMB_SEMITONE_BASE, 60 - channel->destnote);
+                    if (deltaslid < destdelta) {
+                        playing->slide -= channel->toneporta;
+                        deltaslid =
+                            deltanote - playing->slide * amiga_multiplier;
+                        if (deltaslid > destdelta) {
+                            playing->note = channel->destnote;
+                            playing->slide = 0;
+                            channel->destnote = IT_NOTE_OFF;
+                        }
+                    } else {
+                        playing->slide += channel->toneporta;
+                        deltaslid =
+                            deltanote - playing->slide * amiga_multiplier;
+                        if (deltaslid < destdelta) {
+                            playing->note = channel->destnote;
+                            playing->slide = 0;
+                            channel->destnote = IT_NOTE_OFF;
+                        }
+                    }
+                }
+            }
+
+            update_playing_effects(playing);
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+        IT_PLAYING *playing = sigrenderer->playing[i];
+        if (playing)
+            update_playing_effects(playing);
+    }
+
+    update_smooth_effects(sigrenderer);
+}
+
+static void it_note_off(IT_PLAYING *playing);
+
+// This function should be renamed; it doesn't do the 'Update Pattern Variables'
+// operation ittech.txt describes
+/* Returns 1 if a pattern loop is happening. */
+static int update_pattern_variables(DUMB_IT_SIGRENDERER *sigrenderer,
+                                    IT_ENTRY *entry) {
+    IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
+
+    if (entry->mask & IT_ENTRY_EFFECT) {
+        switch (entry->effect) {
+        case IT_JUMP_TO_ORDER:
+            /* XXX jump and break in same row */
+            if (((sigrenderer->processrow | 0xC00) == 0xFFFE) &&
+                !(sigrenderer->processrow & 0x800)) {
+                sigrenderer->processrow = 0xFFFE & ~0xC00;
+            } else {
+                sigrenderer->breakrow = 0;
+                sigrenderer->processrow = 0xFFFE & ~0x400;
+            }
+            sigrenderer->processorder = entry->effectvalue - 1;
+            break;
+
+        case IT_S: {
+            unsigned char effectvalue = entry->effectvalue;
+            if (sigrenderer->sigdata->flags & IT_WAS_AN_S3M) {
+                if (effectvalue == 0)
+                    effectvalue = channel->lastDKL;
+                channel->lastDKL = effectvalue;
+            } else {
+                if (effectvalue == 0)
+                    effectvalue = channel->lastS;
+            }
+            channel->lastS = effectvalue;
+            switch (effectvalue >> 4) {
+            case IT_S_PATTERN_LOOP: {
+                unsigned char v = effectvalue & 15;
+                if (v == 0) {
+#ifdef BIT_ARRAY_BULLSHIT
+                    if (!channel->played_patjump)
+                        channel->played_patjump = bit_array_create(256);
+                    else {
+                        if (channel->played_patjump_order != 0xFFFE &&
+                            channel->played_patjump_order != sigrenderer->order)
+                            bit_array_merge(
+                                sigrenderer->played, channel->played_patjump,
+                                channel->played_patjump_order * 256);
+                        // if (channel->played_patjump_order !=
+                        // sigrenderer->order)
+                        bit_array_reset(channel->played_patjump);
+                    }
+                    channel->played_patjump_order = sigrenderer->order;
+#endif
+                    channel->pat_loop_row = sigrenderer->processrow;
+                } else {
+                    if (channel->pat_loop_count == 0) {
+#ifdef BIT_ARRAY_BULLSHIT
+                        /* wft, uninitialized and no start marker yet... */
+                        if (channel->played_patjump_order == 0xFFFE) {
+                            int n;
+                            bit_array_destroy(channel->played_patjump);
+                            channel->played_patjump = bit_array_create(256);
+                            for (n = channel->pat_loop_row;
+                                 n <= sigrenderer->row; n++)
+                                bit_array_clear(sigrenderer->played,
+                                                sigrenderer->order * 256 + n);
+                            channel->played_patjump_order = sigrenderer->order;
+                        } else if (channel->played_patjump_order ==
+                                   sigrenderer->order) {
+                            bit_array_set(channel->played_patjump,
+                                          sigrenderer->row);
+                            bit_array_mask(sigrenderer->played,
+                                           channel->played_patjump,
+                                           channel->played_patjump_order * 256);
+                            // bit_array_reset(channel->played_patjump);
+                        }
+#endif
+                        channel->pat_loop_count = v;
+                        sigrenderer->breakrow = channel->pat_loop_row;
+                        if ((sigrenderer->sigdata->flags &
+                             (IT_WAS_AN_XM | IT_WAS_A_MOD)) == IT_WAS_AN_XM) {
+                            /* For XM files, if a loop occurs by itself, keep
+                             * breakrow set for when the pattern ends - fun bug
+                             * in FT2! */
+                            if ((sigrenderer->processrow | 0xC00) < 0xFFFE) {
+                                /* Infinite pattern loops are possible, so we
+                                 * check whether the pattern loop we're hitting
+                                 * now is earlier than the last one we hit. */
+                                if (sigrenderer->processrow <
+                                    channel->pat_loop_end_row)
+                                    sigrenderer->processorder =
+                                        0xFFFE; /* suspect infinite loop, so
+                                                   trigger loop callback */
+                                else
+                                    sigrenderer->processorder =
+                                        0xFFFF; /* don't trigger loop callback
+                                                 */
+                                channel->pat_loop_end_row =
+                                    sigrenderer->processrow;
+                                sigrenderer->processrow =
+                                    0xFFFF; /* special case: don't reset
+                                               breakrow or pat_loop_end_row */
+                            }
+                        } else {
+                            /* IT files do this regardless of other flow control
+                             * effects seen here. */
+                            sigrenderer->processorder =
+                                0xFFFF; /* special case: don't trigger loop
+                                           callback */
+                            sigrenderer->processrow = 0xFFFE;
+                        }
+                        return 1;
+                    } else if (--channel->pat_loop_count) {
+#ifdef BIT_ARRAY_BULLSHIT
+                        if (channel->played_patjump_order ==
+                            sigrenderer->order) {
+                            bit_array_set(channel->played_patjump,
+                                          sigrenderer->row);
+                            bit_array_mask(sigrenderer->played,
+                                           channel->played_patjump,
+                                           channel->played_patjump_order * 256);
+                            // bit_array_reset(channel->played_patjump);
+                        }
+#endif
+                        sigrenderer->breakrow = channel->pat_loop_row;
+                        if ((sigrenderer->sigdata->flags &
+                             (IT_WAS_AN_XM | IT_WAS_A_MOD)) == IT_WAS_AN_XM) {
+                            /* For XM files, if a loop occurs by itself, keep
+                             * breakrow set for when the pattern ends - fun bug
+                             * in FT2! */
+                            if ((sigrenderer->processrow | 0xC00) < 0xFFFE) {
+                                /* Infinite pattern loops are possible, so we
+                                 * check whether the pattern loop we're hitting
+                                 * now is earlier than the last one we hit. */
+                                if (sigrenderer->processrow <
+                                    channel->pat_loop_end_row)
+                                    sigrenderer->processorder =
+                                        0xFFFE; /* suspect infinite loop, so
+                                                   trigger loop callback */
+                                else
+                                    sigrenderer->processorder =
+                                        0xFFFF; /* don't trigger loop callback
+                                                 */
+                                channel->pat_loop_end_row =
+                                    sigrenderer->processrow;
+                                sigrenderer->processrow =
+                                    0xFFFF; /* special case: don't reset
+                                               breakrow or pat_loop_end_row */
+                            }
+                        } else {
+                            /* IT files do this regardless of other flow control
+                             * effects seen here. */
+                            sigrenderer->processorder =
+                                0xFFFF; /* special case: don't trigger loop
+                                           callback */
+                            sigrenderer->processrow = 0xFFFE;
+                        }
+                        return 1;
+                    } else if ((sigrenderer->sigdata->flags &
+                                (IT_WAS_AN_XM | IT_WAS_A_MOD)) ==
+                               IT_WAS_AN_XM) {
+                        channel->pat_loop_end_row = 0;
+                        // TODO
+                        /* Findings:
+                        - If a pattern loop completes successfully, and then the
+                        pattern terminates, then the next pattern will start on
+                        the row corresponding to the E60.
+                        - If a pattern loop doesn't do any loops, and then the
+                        pattern terminates, then the next pattern will start on
+                        the first row.
+                        - If a break appears to the left of the pattern loop, it
+                        jumps into the relevant position in the next pattern,
+                        and that's it.
+                        - If a break appears to the right of the pattern loop,
+                        it jumps to the start of the next pattern, and that's
+                        it.
+                        - If we jump, then effect a loop using an old E60, and
+                        then the pattern ends, the next pattern starts on the
+                        row corresponding to the E60.
+                        - Theory: breakrow is not cleared when it's a pattern
+                        loop effect!
+                        */
+                        if ((sigrenderer->processrow | 0xC00) <
+                            0xFFFE) // I have no idea if this is correct or not
+                                    // - FT2 is so weird :(
+                            sigrenderer->breakrow =
+                                channel->pat_loop_row; /* emulate bug in FT2 */
+                    } else
+                        channel->pat_loop_row = sigrenderer->processrow + 1;
+#ifdef BIT_ARRAY_BULLSHIT
+                    /*channel->played_patjump_order |= 0x8000;*/
+                    if (channel->played_patjump_order == sigrenderer->order) {
+                        bit_array_destroy(channel->played_patjump);
+                        channel->played_patjump = 0;
+                        channel->played_patjump_order = 0xFFFE;
+                    }
+                    bit_array_clear(sigrenderer->played,
+                                    sigrenderer->order * 256 +
+                                        sigrenderer->row);
+#endif
+                }
+            } break;
+            case IT_S_PATTERN_DELAY:
+                sigrenderer->rowcount = 1 + (effectvalue & 15);
+                break;
+            }
+        }
+        }
+    }
+
+    return 0;
+}
+
+/* This function guarantees that channel->sample will always be valid if it
+ * is nonzero. In other words, to check if it is valid, simply check if it is
+ * nonzero.
+ */
+static void instrument_to_sample(DUMB_IT_SIGDATA *sigdata,
+                                 IT_CHANNEL *channel) {
+    if (sigdata->flags & IT_USE_INSTRUMENTS) {
+        if (channel->instrument >= 1 &&
+            channel->instrument <= sigdata->n_instruments) {
+            if (channel->note < 120) {
+                channel->sample = sigdata->instrument[channel->instrument - 1]
+                                      .map_sample[channel->note];
+                channel->truenote = sigdata->instrument[channel->instrument - 1]
+                                        .map_note[channel->note];
+            } else
+                channel->sample = 0;
+        } else
+            channel->sample = 0;
+    } else {
+        channel->sample = channel->instrument;
+        channel->truenote = channel->note;
+    }
+    if (!(channel->sample >= 1 && channel->sample <= sigdata->n_samples &&
+          (sigdata->sample[channel->sample - 1].flags & IT_SAMPLE_EXISTS) &&
+          sigdata->sample[channel->sample - 1].C5_speed))
+        channel->sample = 0;
+}
+
+static void fix_sample_looping(IT_PLAYING *playing) {
+    if ((playing->sample->flags & (IT_SAMPLE_LOOP | IT_SAMPLE_SUS_LOOP)) ==
+        (IT_SAMPLE_LOOP | IT_SAMPLE_SUS_LOOP)) {
+        if (playing->resampler.dir < 0) {
+            playing->resampler.pos = (playing->sample->sus_loop_end << 1) - 1 -
+                                     playing->resampler.pos;
+            playing->resampler.subpos ^= 65535;
+            playing->resampler.dir = 1;
+        }
+
+        playing->resampler.pos += playing->time_lost;
+        // XXX what
+        playing->time_lost = 0;
+    }
+}
+
+static void it_compatible_gxx_retrigger(DUMB_IT_SIGDATA *sigdata,
+                                        IT_CHANNEL *channel) {
+    int flags = 0;
+    if (channel->sample) {
+        if (sigdata->flags & IT_USE_INSTRUMENTS) {
+            if (!(channel->playing->flags & IT_PLAYING_SUSTAINOFF)) {
+                if (channel->playing->env_instrument->volume_envelope.flags &
+                    IT_ENVELOPE_CARRY)
+                    flags |= 1;
+                if (channel->playing->env_instrument->pan_envelope.flags &
+                    IT_ENVELOPE_CARRY)
+                    flags |= 2;
+                if (channel->playing->env_instrument->pitch_envelope.flags &
+                    IT_ENVELOPE_CARRY)
+                    flags |= 4;
+            }
+        }
+    }
+    if (!(flags & 1)) {
+        channel->playing->volume_envelope.next_node = 0;
+        channel->playing->volume_envelope.tick = 0;
+    }
+    if (!(flags & 2)) {
+        channel->playing->pan_envelope.next_node = 0;
+        channel->playing->pan_envelope.tick = 0;
+    }
+    if (!(flags & 4)) {
+        channel->playing->pitch_envelope.next_node = 0;
+        channel->playing->pitch_envelope.tick = 0;
+    }
+    channel->playing->fadeoutcount = 1024;
+    // Should we remove IT_PLAYING_BACKGROUND? Test with sample with sustain
+    // loop...
+    channel->playing->flags &= ~(IT_PLAYING_BACKGROUND | IT_PLAYING_SUSTAINOFF |
+                                 IT_PLAYING_FADING | IT_PLAYING_DEAD);
+    it_playing_update_resamplers(channel->playing);
+
+    if (!flags && channel->sample)
+        if (sigdata->flags & IT_USE_INSTRUMENTS)
+            channel->playing->env_instrument =
+                &sigdata->instrument[channel->instrument - 1];
+}
+
+static void it_note_off(IT_PLAYING *playing) {
+    if (playing) {
+        playing->enabled_envelopes |= IT_ENV_VOLUME;
+        playing->flags |= IT_PLAYING_BACKGROUND | IT_PLAYING_SUSTAINOFF;
+        fix_sample_looping(playing);
+        it_playing_update_resamplers(playing);
+        if (playing->instrument)
+            if ((playing->instrument->volume_envelope.flags &
+                 (IT_ENVELOPE_ON | IT_ENVELOPE_LOOP_ON)) != IT_ENVELOPE_ON)
+                playing->flags |= IT_PLAYING_FADING;
+    }
+}
+
+static void xm_note_off(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel) {
+    if (channel->playing) {
+        if (!channel->instrument ||
+            channel->instrument > sigdata->n_instruments ||
+            !(sigdata->instrument[channel->instrument - 1]
+                  .volume_envelope.flags &
+              IT_ENVELOPE_ON))
+            // if (!(entry->mask & IT_ENTRY_INSTRUMENT))
+            // dunno what that was there for ...
+            channel->volume = 0;
+        channel->playing->flags |= IT_PLAYING_SUSTAINOFF | IT_PLAYING_FADING;
+        it_playing_update_resamplers(channel->playing);
+    }
+}
+
+static void recalculate_it_envelope_node(IT_PLAYING_ENVELOPE *pe,
+                                         IT_ENVELOPE *e) {
+    int envpos = pe->tick;
+    unsigned int pt = e->n_nodes - 1;
+    unsigned int i;
+    for (i = 0; i < (unsigned int)(e->n_nodes - 1); ++i) {
+        if (envpos <= e->node_t[i]) {
+            pt = i;
+            break;
+        }
+    }
+    pe->next_node = pt;
+}
+
+static void recalculate_it_envelope_nodes(IT_PLAYING *playing) {
+    recalculate_it_envelope_node(&playing->volume_envelope,
+                                 &playing->env_instrument->volume_envelope);
+    recalculate_it_envelope_node(&playing->pan_envelope,
+                                 &playing->env_instrument->pitch_envelope);
+    recalculate_it_envelope_node(&playing->pitch_envelope,
+                                 &playing->env_instrument->pitch_envelope);
+}
+
+static void it_retrigger_note(DUMB_IT_SIGRENDERER *sigrenderer,
+                              IT_CHANNEL *channel) {
+    int vol_env_tick = 0;
+    int pan_env_tick = 0;
+    int pitch_env_tick = 0;
+
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+    unsigned char nna = ~0;
+    int i, envelopes_copied = 0;
+
+    if (channel->playing) {
+        if (channel->note == IT_NOTE_CUT)
+            nna = NNA_NOTE_CUT;
+        else if (channel->note == IT_NOTE_OFF)
+            nna = NNA_NOTE_OFF;
+        else if (channel->note > 120)
+            nna = NNA_NOTE_FADE;
+        else if (!channel->playing->instrument ||
+                 (channel->playing->flags & IT_PLAYING_DEAD))
+            nna = NNA_NOTE_CUT;
+        else if (channel->new_note_action != 0xFF) {
+            nna = channel->new_note_action;
+        } else
+            nna = channel->playing->instrument->new_note_action;
+
+        if (!(channel->playing->flags & IT_PLAYING_SUSTAINOFF)) {
+            if (nna != NNA_NOTE_CUT)
+                vol_env_tick = channel->playing->volume_envelope.tick;
+            pan_env_tick = channel->playing->pan_envelope.tick;
+            pitch_env_tick = channel->playing->pitch_envelope.tick;
+            envelopes_copied = 1;
+        }
+
+        switch (nna) {
+        case NNA_NOTE_CUT:
+            channel->playing->declick_stage = 3;
+            break;
+        case NNA_NOTE_OFF:
+            it_note_off(channel->playing);
+            break;
+        case NNA_NOTE_FADE:
+            channel->playing->flags |=
+                IT_PLAYING_BACKGROUND | IT_PLAYING_FADING;
+            break;
+        }
+    }
+
+    channel->new_note_action = 0xFF;
+
+    if (channel->sample == 0 || channel->note > 120)
+        return;
+
+    channel->destnote = IT_NOTE_OFF;
+
+    if (channel->playing) {
+        for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+            if (!sigrenderer->playing[i]) {
+                sigrenderer->playing[i] = channel->playing;
+                channel->playing = NULL;
+                break;
+            }
+        }
+
+        if (sigrenderer->sigdata->flags & IT_USE_INSTRUMENTS) {
+            for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                IT_PLAYING *playing = sigrenderer->playing[i];
+                if (playing && playing->channel == channel &&
+                    playing->instrument->dup_check_type) {
+                    int match = 1;
+                    switch (playing->instrument->dup_check_type) {
+                    case DCT_NOTE:
+                        match = (channel->truenote == playing->note);
+                    case DCT_SAMPLE:
+                        match = match && (channel->sample == playing->sampnum);
+                    case DCT_INSTRUMENT:
+                        match =
+                            match && (channel->instrument == playing->instnum);
+                        break;
+                    }
+
+                    if (match) {
+                        switch (playing->instrument->dup_check_action) {
+                        case DCA_NOTE_CUT:
+                            playing->declick_stage = 3;
+                            if (channel->playing == playing)
+                                channel->playing = NULL;
+                            break;
+                        case DCA_NOTE_OFF:
+                            if (!(playing->flags & IT_PLAYING_SUSTAINOFF))
+                                it_note_off(playing);
+                            break;
+                        case DCA_NOTE_FADE:
+                            playing->flags |=
+                                IT_PLAYING_BACKGROUND | IT_PLAYING_FADING;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+/** WARNING - come up with some more heuristics for replacing old notes */
+#if 0
+		if (channel->playing) {
+			for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+				if (sigrenderer->playing[i]->flags & IT_PLAYING_BACKGROUND) {
+					write_seqtime();
+					sequence_c(SEQUENCE_STOP_SIGNAL);
+					sequence_c(i);
+					channel->VChannel = &module->VChannel[i];
+					break;
+				}
+			}
+		}
+#endif
+    }
+
+    if (channel->playing)
+        free_playing(channel->playing);
+
+    channel->playing = new_playing();
+
+    if (!channel->playing)
+        return;
+
+    if (!envelopes_copied && sigdata->flags & IT_USE_INSTRUMENTS) {
+        for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+            IT_PLAYING *playing = sigrenderer->playing[i];
+            if (!playing || playing->channel != channel)
+                continue;
+            if (playing->flags & IT_PLAYING_SUSTAINOFF)
+                continue;
+            if (nna != NNA_NOTE_CUT)
+                vol_env_tick = playing->volume_envelope.tick;
+            pan_env_tick = playing->pan_envelope.tick;
+            pitch_env_tick = playing->pitch_envelope.tick;
+            envelopes_copied = 1;
+            break;
+        }
+    }
+
+    channel->playing->flags = 0;
+    channel->playing->resampling_quality = sigrenderer->resampling_quality;
+    channel->playing->channel = channel;
+    channel->playing->sample = &sigdata->sample[channel->sample - 1];
+    if (sigdata->flags & IT_USE_INSTRUMENTS)
+        channel->playing->instrument =
+            &sigdata->instrument[channel->instrument - 1];
+    else
+        channel->playing->instrument = NULL;
+    channel->playing->env_instrument = channel->playing->instrument;
+    channel->playing->sampnum = channel->sample;
+    channel->playing->instnum = channel->instrument;
+    channel->playing->declick_stage = 0;
+    channel->playing->channel_volume = channel->channelvolume;
+    channel->playing->note = channel->truenote;
+    channel->playing->enabled_envelopes = 0;
+    channel->playing->volume_offset = 0;
+    channel->playing->panning_offset = 0;
+    // channel->playing->output = channel->output;
+    if (sigdata->flags & IT_USE_INSTRUMENTS) {
+        IT_PLAYING *playing = channel->playing;
+        IT_INSTRUMENT *instrument = playing->instrument;
+        if (instrument->volume_envelope.flags & IT_ENVELOPE_ON)
+            playing->enabled_envelopes |= IT_ENV_VOLUME;
+        if (instrument->pan_envelope.flags & IT_ENVELOPE_ON)
+            playing->enabled_envelopes |= IT_ENV_PANNING;
+        if (instrument->pitch_envelope.flags & IT_ENVELOPE_ON)
+            playing->enabled_envelopes |= IT_ENV_PITCH;
+        if (instrument->random_volume)
+            playing->volume_offset =
+                (rand() % (instrument->random_volume * 2 + 1)) -
+                instrument->random_volume;
+        if (instrument->random_pan)
+            playing->panning_offset =
+                (rand() % (instrument->random_pan * 2 + 1)) -
+                instrument->random_pan;
+        // if (instrument->output) playing->output = instrument->output;
+    }
+    channel->playing->filter_cutoff = 127;
+    channel->playing->filter_resonance = 0;
+    channel->playing->true_filter_cutoff = 127 << 8;
+    channel->playing->true_filter_resonance = 0;
+    channel->playing->vibrato_speed = 0;
+    channel->playing->vibrato_depth = 0;
+    channel->playing->vibrato_n = 0;
+    channel->playing->vibrato_time = 0;
+    channel->playing->vibrato_waveform = channel->vibrato_waveform;
+    channel->playing->tremolo_speed = 0;
+    channel->playing->tremolo_depth = 0;
+    channel->playing->tremolo_time = 0;
+    channel->playing->tremolo_waveform = channel->tremolo_waveform;
+    channel->playing->panbrello_speed = 0;
+    channel->playing->panbrello_depth = 0;
+    channel->playing->panbrello_time = 0;
+    channel->playing->panbrello_waveform = channel->panbrello_waveform;
+    channel->playing->panbrello_random = 0;
+    channel->playing->sample_vibrato_time = 0;
+    channel->playing->sample_vibrato_waveform =
+        channel->playing->sample->vibrato_waveform;
+    channel->playing->sample_vibrato_depth = 0;
+    channel->playing->slide = 0;
+    channel->playing->finetune = channel->playing->sample->finetune;
+
+    if (sigdata->flags & IT_USE_INSTRUMENTS) {
+        if (envelopes_copied &&
+            channel->playing->env_instrument->volume_envelope.flags &
+                IT_ENVELOPE_CARRY) {
+            channel->playing->volume_envelope.tick = vol_env_tick;
+        } else {
+            channel->playing->volume_envelope.tick = 0;
+        }
+        if (envelopes_copied &&
+            channel->playing->env_instrument->pan_envelope.flags &
+                IT_ENVELOPE_CARRY) {
+            channel->playing->pan_envelope.tick = pan_env_tick;
+        } else {
+            channel->playing->pan_envelope.tick = 0;
+        }
+        if (envelopes_copied &&
+            channel->playing->env_instrument->pitch_envelope.flags &
+                IT_ENVELOPE_CARRY) {
+            channel->playing->pitch_envelope.tick = pitch_env_tick;
+        } else {
+            channel->playing->pitch_envelope.tick = 0;
+        }
+        recalculate_it_envelope_nodes(channel->playing);
+    }
+    channel->playing->fadeoutcount = 1024;
+    it_reset_filter_state(&channel->playing->filter_state[0]);
+    it_reset_filter_state(&channel->playing->filter_state[1]);
+    it_playing_reset_resamplers(channel->playing, 0);
+
+    /** WARNING - is everything initialised? */
+}
+
+static void get_default_volpan(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel) {
+    if (channel->sample == 0)
+        return;
+
+    channel->volume = sigdata->sample[channel->sample - 1].default_volume;
+
+    if (sigdata->flags & IT_WAS_AN_XM) {
+        if (!(sigdata->flags & IT_WAS_A_MOD))
+            channel->truepan =
+                32 + sigdata->sample[channel->sample - 1].default_pan * 64;
+        return;
+    }
+
+    {
+        int pan = sigdata->sample[channel->sample - 1].default_pan;
+        if (pan >= 128 && pan <= 192) {
+            channel->pan = pan - 128;
+            return;
+        }
+    }
+
+    if (sigdata->flags & IT_USE_INSTRUMENTS) {
+        IT_INSTRUMENT *instrument =
+            &sigdata->instrument[channel->instrument - 1];
+        if (instrument->default_pan <= 64)
+            channel->pan = instrument->default_pan;
+        if (instrument->filter_cutoff >= 128)
+            channel->filter_cutoff = instrument->filter_cutoff - 128;
+        if (instrument->filter_resonance >= 128)
+            channel->filter_resonance = instrument->filter_resonance - 128;
+    }
+}
+
+static void get_true_pan(DUMB_IT_SIGDATA *sigdata, IT_CHANNEL *channel) {
+    channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
+
+    if (channel->sample && !IT_IS_SURROUND_SHIFTED(channel->truepan) &&
+        (sigdata->flags & IT_USE_INSTRUMENTS)) {
+        IT_INSTRUMENT *instrument =
+            &sigdata->instrument[channel->instrument - 1];
+        int truepan = channel->truepan;
+        truepan +=
+            (channel->note - instrument->pp_centre) * instrument->pp_separation
+            << (IT_ENVELOPE_SHIFT - 3);
+        channel->truepan =
+            (unsigned short)MID(0, truepan, 64 << IT_ENVELOPE_SHIFT);
+    }
+}
+
+static void post_process_it_volpan(DUMB_IT_SIGRENDERER *sigrenderer,
+                                   IT_ENTRY *entry) {
+    IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
+
+    if (entry->mask & IT_ENTRY_VOLPAN) {
+        if (entry->volpan <= 84) {
+            /* Volume */
+            /* Fine volume slide up */
+            /* Fine volume slide down */
+        } else if (entry->volpan <= 94) {
+            /* Volume slide up */
+            unsigned char v = entry->volpan - 85;
+            if (v == 0)
+                v = channel->lastvolslide;
+            channel->lastvolslide = v;
+            /* = effect Dx0 where x == entry->volpan - 85 */
+            channel->volslide += v;
+        } else if (entry->volpan <= 104) {
+            /* Volume slide down */
+            unsigned char v = entry->volpan - 95;
+            if (v == 0)
+                v = channel->lastvolslide;
+            channel->lastvolslide = v;
+            /* = effect D0x where x == entry->volpan - 95 */
+            channel->volslide -= v;
+        } else if (entry->volpan <= 114) {
+            /* Portamento down */
+            unsigned char v = (entry->volpan - 105) << 2;
+            if (v == 0)
+                v = channel->lastEF;
+            channel->lastEF = v;
+            channel->portamento -= v << 4;
+        } else if (entry->volpan <= 124) {
+            /* Portamento up */
+            unsigned char v = (entry->volpan - 115) << 2;
+            if (v == 0)
+                v = channel->lastEF;
+            channel->lastEF = v;
+            channel->portamento += v << 4;
+        } else if (entry->volpan <= 202) {
+            /* Pan */
+            /* Tone Portamento */
+        } else if (entry->volpan <= 212) {
+            /* Vibrato */
+            /* This is unaffected by IT_OLD_EFFECTS. However, if v == 0, then
+             * any doubling of depth that happened before (with Hxy in the
+             * effect column) will be preserved. */
+            unsigned char v = entry->volpan - 203;
+            if (v == 0)
+                v = channel->lastHdepth;
+            else {
+                v <<= 2;
+                channel->lastHdepth = v;
+            }
+            if (channel->playing) {
+                channel->playing->vibrato_speed = channel->lastHspeed;
+                channel->playing->vibrato_depth = v;
+                channel->playing->vibrato_n++;
+            }
+        }
+    }
+}
+
+static void it_send_midi(DUMB_IT_SIGRENDERER *sigrenderer, IT_CHANNEL *channel,
+                         unsigned char midi_byte) {
+    if (sigrenderer->callbacks->midi)
+        if ((*sigrenderer->callbacks->midi)(
+                sigrenderer->callbacks->midi_data,
+                (int)(channel - sigrenderer->channel), midi_byte))
+            return;
+
+    switch (channel->midi_state) {
+    case 4: /* Ready to receive resonance parameter */
+        if (midi_byte < 0x80)
+            channel->filter_resonance = midi_byte;
+        channel->midi_state = 0;
+        break;
+    case 3: /* Ready to receive cutoff parameter */
+        if (midi_byte < 0x80)
+            channel->filter_cutoff = midi_byte;
+        channel->midi_state = 0;
+        break;
+    case 2: /* Ready for byte specifying which parameter will follow */
+        if (midi_byte == 0) /* Cutoff */
+            channel->midi_state = 3;
+        else if (midi_byte == 1) /* Resonance */
+            channel->midi_state = 4;
+        else
+            channel->midi_state = 0;
+        break;
+    default: /* Counting initial F0 bytes */
+        switch (midi_byte) {
+        case 0xF0:
+            channel->midi_state++;
+            break;
+        case 0xFA:
+        case 0xFC:
+        case 0xFF:
+            /* Reset filter parameters for all channels */
+            {
+                int i;
+                for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+                    sigrenderer->channel[i].filter_cutoff = 127;
+                    sigrenderer->channel[i].filter_resonance = 0;
+                    //// should we be resetting channel[i].playing->filter_*
+                    /// here?
+                }
+            }
+            /* Fall through */
+        default:
+            channel->midi_state = 0;
+            break;
+        }
+    }
+}
+
+static void xm_envelope_calculate_value(IT_ENVELOPE *envelope,
+                                        IT_PLAYING_ENVELOPE *pe) {
+    if (pe->next_node <= 0)
+        pe->value = envelope->node_y[0] << IT_ENVELOPE_SHIFT;
+    else if (pe->next_node >= envelope->n_nodes)
+        pe->value = envelope->node_y[envelope->n_nodes - 1]
+                    << IT_ENVELOPE_SHIFT;
+    else {
+        int ys = envelope->node_y[pe->next_node - 1] << IT_ENVELOPE_SHIFT;
+        int ts = envelope->node_t[pe->next_node - 1];
+        int te = envelope->node_t[pe->next_node];
+
+        if (ts == te)
+            pe->value = ys;
+        else {
+            int ye = envelope->node_y[pe->next_node] << IT_ENVELOPE_SHIFT;
+            int t = pe->tick;
+
+            pe->value = ys + (ye - ys) * (t - ts) / (te - ts);
+        }
+    }
+}
+
+extern const char xm_convert_vibrato[];
+
+const char mod_convert_vibrato[] = {
+    IT_VIBRATO_SINE,
+    IT_VIBRATO_RAMP_UP, /* this will be inverted by IT_OLD_EFFECTS */
+    IT_VIBRATO_XM_SQUARE, IT_VIBRATO_XM_SQUARE};
+
+/* Returns 1 if a callback caused termination of playback. */
+static int process_effects(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry,
+                           int ignore_cxx) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+    IT_PLAYING *playing;
+    int i;
+
+    IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
+
+    if (entry->mask & IT_ENTRY_EFFECT) {
+        switch (entry->effect) {
+            /*
+            Notes about effects (as compared to other module formats)
+
+            C               This is now in *HEX*. (Used to be in decimal in ST3)
+            E/F/G/H/U       You need to check whether the song uses Amiga/Linear
+            slides. H/U             Vibrato in Impulse Tracker is two times
+            finer than in any other tracker and is updated EVERY tick. If "Old
+            Effects" is *ON*, then the vibrato is played in the normal manner
+            (every non-row tick and normal depth) E/F/G           These commands
+            ALL share the same memory. Oxx             Offsets to samples are to
+            the 'xx00th' SAMPLE. (ie. for 16 bit samples, the offset is xx00h*2)
+                            Oxx past the sample end will be ignored, unless "Old
+            Effects" is ON, in which case the Oxx will play from the end of the
+                            sample.
+            Yxy             This uses a table 4 times larger (hence 4 times
+            slower) than vibrato or tremelo. If the waveform is set to random,
+            then the 'speed' part of the command is interpreted as a delay.
+            */
+        case IT_SET_SPEED:
+            if (entry->effectvalue) {
+                /*if (entry->effectvalue == 255)
+                        if (sigrenderer->callbacks->xm_speed_zero &&
+                   (*sigrenderer->callbacks->xm_speed_zero)(sigrenderer->callbacks->xm_speed_zero_data))
+                                return 1;*/
+                if (sigdata->flags & IT_WAS_AN_STM) {
+                    int n = entry->effectvalue;
+                    if (n >= 32) {
+                        sigrenderer->tick = sigrenderer->speed = n;
+                    }
+                } else {
+                    sigrenderer->tick = sigrenderer->speed = entry->effectvalue;
+                }
+            } else if ((sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_MOD)) ==
+                       IT_WAS_AN_XM) {
+#ifdef BIT_ARRAY_BULLSHIT
+                bit_array_set(sigrenderer->played,
+                              sigrenderer->order * 256 + sigrenderer->row);
+#endif
+                sigrenderer->speed = 0;
+#ifdef BIT_ARRAY_BULLSHIT
+                sigrenderer->looped = 1;
+#endif
+                if (sigrenderer->callbacks->xm_speed_zero &&
+                    (*sigrenderer->callbacks->xm_speed_zero)(
+                        sigrenderer->callbacks->xm_speed_zero_data))
+                    return 1;
+            }
+            break;
+
+        case IT_BREAK_TO_ROW:
+            if (ignore_cxx)
+                break;
+            sigrenderer->breakrow = entry->effectvalue;
+            /* XXX jump and break on the same row */
+            if (((sigrenderer->processrow | 0xC00) == 0xFFFE) &&
+                !(sigrenderer->processrow & 0x400)) {
+                sigrenderer->processrow = 0xFFFE & ~0xC00;
+            } else {
+                sigrenderer->processorder = sigrenderer->order;
+                sigrenderer->processrow = 0xFFFE & ~0x800;
+            }
+            break;
+
+        case IT_VOLSLIDE_VIBRATO:
+            for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                if (i < 0)
+                    playing = channel->playing;
+                else {
+                    playing = sigrenderer->playing[i];
+                    if (!playing || playing->channel != channel)
+                        continue;
+                }
+                if (playing) {
+                    playing->vibrato_speed = channel->lastHspeed;
+                    playing->vibrato_depth = channel->lastHdepth;
+                    playing->vibrato_n++;
+                }
+            }
+            /* Fall through and process volume slide. */
+        case IT_VOLUME_SLIDE:
+        case IT_VOLSLIDE_TONEPORTA:
+            /* The tone portamento component is handled elsewhere. */
+            {
+                unsigned char v = entry->effectvalue;
+                if (!(sigdata->flags & IT_WAS_A_MOD)) {
+                    if (v == 0)
+                        v = channel->lastDKL;
+                    channel->lastDKL = v;
+                }
+                if (!(sigdata->flags & IT_WAS_AN_XM)) {
+                    int clip = (sigdata->flags & IT_WAS_AN_S3M) ? 63 : 64;
+                    if ((v & 0x0F) == 0x0F) {
+                        if (!(v & 0xF0)) {
+                            channel->volslide = -15;
+                            channel->volume -= 15;
+                            if (channel->volume > clip)
+                                channel->volume = 0;
+                        } else {
+                            channel->volume += v >> 4;
+                            if (channel->volume > clip)
+                                channel->volume = clip;
+                        }
+                    } else if ((v & 0xF0) == 0xF0) {
+                        if (!(v & 0x0F)) {
+                            channel->volslide = 15;
+                            channel->volume += 15;
+                            if (channel->volume > clip)
+                                channel->volume = clip;
+                        } else {
+                            channel->volume -= v & 15;
+                            if (channel->volume > clip)
+                                channel->volume = 0;
+                        }
+                    } else if (!(v & 0x0F)) {
+                        channel->volslide = v >> 4;
+                    } else {
+                        channel->volslide = -(v & 15);
+                    }
+                } else {
+                    if ((v & 0x0F) == 0) { /* Dx0 */
+                        channel->volslide = v >> 4;
+                    } else if ((v & 0xF0) == 0) { /* D0x */
+                        channel->volslide = -v;
+                    } else if ((v & 0x0F) == 0x0F) { /* DxF */
+                        channel->volume += v >> 4;
+                        if (channel->volume > 64)
+                            channel->volume = 64;
+                    } else if ((v & 0xF0) == 0xF0) { /* DFx */
+                        channel->volume -= v & 15;
+                        if (channel->volume > 64)
+                            channel->volume = 0;
+                    }
+                }
+            }
+            break;
+        case IT_XM_FINE_VOLSLIDE_DOWN: {
+            unsigned char v = entry->effectvalue;
+            if (v == 0)
+                v = channel->xm_lastEB;
+            channel->xm_lastEB = v;
+            channel->volume -= v;
+            if (channel->volume > 64)
+                channel->volume = 0;
+        } break;
+        case IT_XM_FINE_VOLSLIDE_UP: {
+            unsigned char v = entry->effectvalue;
+            if (v == 0)
+                v = channel->xm_lastEA;
+            channel->xm_lastEA = v;
+            channel->volume += v;
+            if (channel->volume > 64)
+                channel->volume = 64;
+        } break;
+        case IT_PORTAMENTO_DOWN: {
+            unsigned char v = entry->effectvalue;
+            if (sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_669)) {
+                if (!(sigdata->flags & IT_WAS_A_MOD)) {
+                    if (v == 0xF0)
+                        v |= channel->xm_lastE2;
+                    else if (v >= 0xF0)
+                        channel->xm_lastE2 = v & 15;
+                    else if (v == 0xE0)
+                        v |= channel->xm_lastX2;
+                    else
+                        channel->xm_lastX2 = v & 15;
+                }
+            } else if (sigdata->flags & IT_WAS_AN_S3M) {
+                if (v == 0)
+                    v = channel->lastDKL;
+                channel->lastDKL = v;
+            } else {
+                if (v == 0)
+                    v = channel->lastEF;
+                channel->lastEF = v;
+            }
+            for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                if (i < 0)
+                    playing = channel->playing;
+                else {
+                    playing = sigrenderer->playing[i];
+                    if (!playing || playing->channel != channel)
+                        continue;
+                }
+                if (playing) {
+                    if ((v & 0xF0) == 0xF0)
+                        playing->slide -= (v & 15) << 4;
+                    else if ((v & 0xF0) == 0xE0)
+                        playing->slide -= (v & 15) << 2;
+                    else if (i < 0 && sigdata->flags & IT_WAS_A_669)
+                        channel->portamento -= v << 3;
+                    else if (i < 0)
+                        channel->portamento -= v << 4;
+                }
+            }
+        } break;
+        case IT_PORTAMENTO_UP: {
+            unsigned char v = entry->effectvalue;
+            if (sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_669)) {
+                if (!(sigdata->flags & IT_WAS_A_MOD)) {
+                    if (v == 0xF0)
+                        v |= channel->xm_lastE1;
+                    else if (v >= 0xF0)
+                        channel->xm_lastE1 = v & 15;
+                    else if (v == 0xE0)
+                        v |= channel->xm_lastX1;
+                    else
+                        channel->xm_lastX1 = v & 15;
+                }
+            } else if (sigdata->flags & IT_WAS_AN_S3M) {
+                if (v == 0)
+                    v = channel->lastDKL;
+                channel->lastDKL = v;
+            } else {
+                if (v == 0)
+                    v = channel->lastEF;
+                channel->lastEF = v;
+            }
+            for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                if (i < 0)
+                    playing = channel->playing;
+                else {
+                    playing = sigrenderer->playing[i];
+                    if (!playing || playing->channel != channel)
+                        continue;
+                }
+                if (playing) {
+                    if ((v & 0xF0) == 0xF0)
+                        playing->slide += (v & 15) << 4;
+                    else if ((v & 0xF0) == 0xE0)
+                        playing->slide += (v & 15) << 2;
+                    else if (i < 0 && sigdata->flags & IT_WAS_A_669)
+                        channel->portamento += v << 3;
+                    else if (i < 0)
+                        channel->portamento += v << 4;
+                }
+            }
+        } break;
+        case IT_XM_PORTAMENTO_DOWN: {
+            unsigned char v = entry->effectvalue;
+            if (!(sigdata->flags & IT_WAS_A_MOD)) {
+                if (v == 0)
+                    v = channel->lastJ;
+                channel->lastJ = v;
+            }
+            if (channel->playing)
+                channel->portamento -= v << 4;
+        } break;
+        case IT_XM_PORTAMENTO_UP: {
+            unsigned char v = entry->effectvalue;
+            if (!(sigdata->flags & IT_WAS_A_MOD)) {
+                if (v == 0)
+                    v = channel->lastEF;
+                channel->lastEF = v;
+            }
+            if (channel->playing)
+                channel->portamento += v << 4;
+        } break;
+        case IT_XM_KEY_OFF:
+            channel->key_off_count = entry->effectvalue;
+            if (!channel->key_off_count)
+                xm_note_off(sigdata, channel);
+            break;
+        case IT_VIBRATO: {
+            if (entry->effectvalue || !(sigdata->flags & IT_WAS_A_669)) {
+                unsigned char speed = entry->effectvalue >> 4;
+                unsigned char depth = entry->effectvalue & 15;
+                if (speed == 0)
+                    speed = channel->lastHspeed;
+                channel->lastHspeed = speed;
+                if (depth == 0)
+                    depth = channel->lastHdepth;
+                else {
+                    if (sigdata->flags & IT_OLD_EFFECTS &&
+                        !(sigdata->flags & IT_WAS_A_MOD))
+                        depth <<= 3;
+                    else
+                        depth <<= 2;
+                    channel->lastHdepth = depth;
+                }
+                for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                    if (i < 0)
+                        playing = channel->playing;
+                    else {
+                        playing = sigrenderer->playing[i];
+                        if (!playing || playing->channel != channel)
+                            continue;
+                    }
+                    if (playing) {
+                        playing->vibrato_speed = speed;
+                        playing->vibrato_depth = depth;
+                        playing->vibrato_n++;
+                    }
+                }
+            }
+        } break;
+        case IT_TREMOR: {
+            unsigned char v = entry->effectvalue;
+            if (v == 0) {
+                if (sigdata->flags & IT_WAS_AN_S3M)
+                    v = channel->lastDKL;
+                else
+                    v = channel->lastI;
+            } else if (!(sigdata->flags & IT_OLD_EFFECTS)) {
+                if (v & 0xF0)
+                    v -= 0x10;
+                if (v & 0x0F)
+                    v -= 0x01;
+            }
+            if (sigdata->flags & IT_WAS_AN_S3M)
+                channel->lastDKL = v;
+            else
+                channel->lastI = v;
+            channel->tremor_time |= 128;
+        }
+            update_tremor(channel);
+            break;
+        case IT_ARPEGGIO: {
+            unsigned char v = entry->effectvalue;
+            /* XM files have no memory for arpeggio (000 = no effect)
+             * and we use lastJ for portamento down instead.
+             */
+            if (!(sigdata->flags & IT_WAS_AN_XM)) {
+                if (sigdata->flags & IT_WAS_AN_S3M) {
+                    if (v == 0)
+                        v = channel->lastDKL;
+                    channel->lastDKL = v;
+                } else {
+                    if (v == 0)
+                        v = channel->lastJ;
+                    channel->lastJ = v;
+                }
+            }
+            channel->arpeggio_offsets[0] = 0;
+            channel->arpeggio_offsets[1] = (v & 0xF0) >> 4;
+            channel->arpeggio_offsets[2] = (v & 0x0F);
+            channel->arpeggio_table =
+                (const unsigned char *)(((sigdata->flags &
+                                          (IT_WAS_AN_XM | IT_WAS_A_MOD)) ==
+                                         IT_WAS_AN_XM)
+                                            ? &arpeggio_xm
+                                            : &arpeggio_mod);
+        } break;
+        case IT_SET_CHANNEL_VOLUME:
+            if (sigdata->flags & IT_WAS_AN_XM)
+                channel->volume = MIN(entry->effectvalue, 64);
+            else if (entry->effectvalue <= 64)
+                channel->channelvolume = entry->effectvalue;
+#ifdef VOLUME_OUT_OF_RANGE_SETS_MAXIMUM
+            else
+                channel->channelvolume = 64;
+#endif
+            if (channel->playing)
+                channel->playing->channel_volume = channel->channelvolume;
+            break;
+        case IT_CHANNEL_VOLUME_SLIDE: {
+            unsigned char v = entry->effectvalue;
+            if (v == 0)
+                v = channel->lastN;
+            channel->lastN = v;
+            if ((v & 0x0F) == 0) { /* Nx0 */
+                channel->channelvolslide = v >> 4;
+            } else if ((v & 0xF0) == 0) { /* N0x */
+                channel->channelvolslide = -v;
+            } else {
+                if ((v & 0x0F) == 0x0F) { /* NxF */
+                    channel->channelvolume += v >> 4;
+                    if (channel->channelvolume > 64)
+                        channel->channelvolume = 64;
+                } else if ((v & 0xF0) == 0xF0) { /* NFx */
+                    channel->channelvolume -= v & 15;
+                    if (channel->channelvolume > 64)
+                        channel->channelvolume = 0;
+                } else
+                    break;
+                if (channel->playing)
+                    channel->playing->channel_volume = channel->channelvolume;
+            }
+        } break;
+        case IT_SET_SAMPLE_OFFSET: {
+            unsigned char v = entry->effectvalue;
+            /*if (sigdata->flags & IT_WAS_A_MOD) {
+						if (v == 0) break;
+					} else*/ {
+                if (v == 0)
+                    v = channel->lastO;
+                channel->lastO = v;
+            }
+            /* Note: we set the offset even if tone portamento is
+             * specified. Impulse Tracker does the same.
+             */
+            if (entry->mask & IT_ENTRY_NOTE) {
+                if (channel->playing) {
+                    int offset =
+                        ((int)channel->high_offset << 16) | ((int)v << 8);
+                    IT_PLAYING *playing = channel->playing;
+                    IT_SAMPLE *sample = playing->sample;
+                    int end;
+                    if ((sample->flags & IT_SAMPLE_SUS_LOOP) &&
+                        !(playing->flags & IT_PLAYING_SUSTAINOFF))
+                        end = (int)sample->sus_loop_end;
+                    else if (sample->flags & IT_SAMPLE_LOOP)
+                        end = (int)sample->loop_end;
+                    else {
+                        end = (int)sample->length;
+                        if (sigdata->flags & IT_WAS_PROCESSED &&
+                            end > 64) // XXX bah damn LPC and edge case modules
+                            end -= 64;
+                    }
+                    if ((sigdata->flags & IT_WAS_A_PTM) &&
+                        (sample->flags & IT_SAMPLE_16BIT))
+                        offset >>= 1;
+                    if (offset < end) {
+                        it_playing_reset_resamplers(playing, offset);
+                        playing->declick_stage = 0;
+                    } else if (sigdata->flags & IT_OLD_EFFECTS) {
+                        it_playing_reset_resamplers(playing, end);
+                        playing->declick_stage = 0;
+                    }
+                }
+            }
+        } break;
+        case IT_PANNING_SLIDE:
+            /** JULIEN: guess what? the docs are wrong! (how unusual ;)
+             * Pxy seems to memorize its previous value... and there
+             * might be other mistakes like that... (sigh!)
+             */
+            /** ENTHEH: umm... but... the docs say that Pxy memorises its
+             * value... don't they? :o
+             */
+            {
+                unsigned char v = entry->effectvalue;
+                int p = channel->truepan;
+                if (sigdata->flags & IT_WAS_AN_XM) {
+                    if (IT_IS_SURROUND(channel->pan)) {
+                        channel->pan = 32;
+                        p = 32 + 128 * 64;
+                    }
+                    p >>= 6;
+                } else {
+                    if (IT_IS_SURROUND(channel->pan))
+                        p = 32 << 8;
+                    p = (p + 128) >> 8;
+                    channel->pan = p;
+                }
+                if (v == 0)
+                    v = channel->lastP;
+                channel->lastP = v;
+                if ((v & 0x0F) == 0) { /* Px0 */
+                    channel->panslide = -(v >> 4);
+                } else if ((v & 0xF0) == 0) { /* P0x */
+                    channel->panslide = v;
+                } else if ((v & 0x0F) == 0x0F) { /* PxF */
+                    p -= v >> 4;
+                } else if ((v & 0xF0) == 0xF0) { /* PFx */
+                    p += v & 15;
+                }
+                if (sigdata->flags & IT_WAS_AN_XM)
+                    channel->truepan = 32 + MID(0, p, 255) * 64;
+                else {
+                    if (p < 0)
+                        p = 0;
+                    else if (p > 64)
+                        p = 64;
+                    channel->pan = p;
+                    channel->truepan = p << 8;
+                }
+            }
+            break;
+        case IT_RETRIGGER_NOTE: {
+            unsigned char v = entry->effectvalue;
+            if (sigdata->flags & IT_WAS_AN_XM) {
+                if ((v & 0x0F) == 0)
+                    v |= channel->lastQ & 0x0F;
+                if ((v & 0xF0) == 0)
+                    v |= channel->lastQ & 0xF0;
+                channel->lastQ = v;
+            } else if (sigdata->flags & IT_WAS_AN_S3M) {
+                if (v == 0)
+                    v = channel->lastDKL;
+                channel->lastDKL = v;
+            } else {
+                if (v == 0)
+                    v = channel->lastQ;
+                channel->lastQ = v;
+            }
+            if ((v & 0x0F) == 0)
+                v |= 0x01;
+            channel->retrig = v;
+            if (entry->mask & IT_ENTRY_NOTE) {
+                channel->retrig_tick = v & 0x0F;
+                /* Emulate a bug */
+                if (sigdata->flags & IT_WAS_AN_XM)
+                    update_retrig(sigrenderer, channel);
+            } else
+                update_retrig(sigrenderer, channel);
+        } break;
+        case IT_XM_RETRIGGER_NOTE:
+            channel->retrig_tick = channel->xm_retrig = entry->effectvalue;
+            if (entry->effectvalue == 0)
+                if (channel->playing) {
+                    it_playing_reset_resamplers(channel->playing, 0);
+                    channel->playing->declick_stage = 0;
+                }
+            break;
+        case IT_TREMOLO: {
+            unsigned char speed, depth;
+            if (sigdata->flags & IT_WAS_AN_S3M) {
+                unsigned char v = entry->effectvalue;
+                if (v == 0)
+                    v = channel->lastDKL;
+                channel->lastDKL = v;
+                speed = v >> 4;
+                depth = v & 15;
+            } else {
+                speed = entry->effectvalue >> 4;
+                depth = entry->effectvalue & 15;
+                if (speed == 0)
+                    speed = channel->lastRspeed;
+                channel->lastRspeed = speed;
+                if (depth == 0)
+                    depth = channel->lastRdepth;
+                channel->lastRdepth = depth;
+            }
+            for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                if (i < 0)
+                    playing = channel->playing;
+                else {
+                    playing = sigrenderer->playing[i];
+                    if (!playing || playing->channel != channel)
+                        continue;
+                }
+                if (playing) {
+                    playing->tremolo_speed = speed;
+                    playing->tremolo_depth = depth;
+                }
+            }
+        } break;
+        case IT_S: {
+            /* channel->lastS was set in update_pattern_variables(). */
+            unsigned char effectvalue = channel->lastS;
+            switch (effectvalue >> 4) {
+            // case IT_S_SET_FILTER:
+                /* Waveforms for commands S3x, S4x and S5x:
+                 *   0: Sine wave
+                 *   1: Ramp down
+                 *   2: Square wave
+                 *   3: Random wave
+                 */
+            case IT_S_SET_GLISSANDO_CONTROL:
+                channel->glissando = effectvalue & 15;
+                break;
+
+            case IT_S_FINETUNE:
+                if (channel->playing) {
+                    channel->playing->finetune = ((int)(effectvalue & 15) - 8)
+                                                 << 5;
+                }
+                break;
+
+            case IT_S_SET_VIBRATO_WAVEFORM: {
+                int waveform = effectvalue & 3;
+                if (sigdata->flags & IT_WAS_A_MOD)
+                    waveform = mod_convert_vibrato[waveform];
+                else if (sigdata->flags & IT_WAS_AN_XM)
+                    waveform = xm_convert_vibrato[waveform];
+                channel->vibrato_waveform = waveform;
+                if (channel->playing) {
+                    channel->playing->vibrato_waveform = waveform;
+                    if (!(effectvalue & 4))
+                        channel->playing->vibrato_time = 0;
+                }
+            } break;
+            case IT_S_SET_TREMOLO_WAVEFORM: {
+                int waveform = effectvalue & 3;
+                if (sigdata->flags & IT_WAS_A_MOD)
+                    waveform = mod_convert_vibrato[waveform];
+                else if (sigdata->flags & IT_WAS_AN_XM)
+                    waveform = xm_convert_vibrato[waveform];
+                channel->tremolo_waveform = waveform;
+                if (channel->playing) {
+                    channel->playing->tremolo_waveform = waveform;
+                    if (!(effectvalue & 4))
+                        channel->playing->tremolo_time = 0;
+                }
+            } break;
+            case IT_S_SET_PANBRELLO_WAVEFORM:
+                channel->panbrello_waveform = effectvalue & 3;
+                if (channel->playing) {
+                    channel->playing->panbrello_waveform = effectvalue & 3;
+                    if (!(effectvalue & 4))
+                        channel->playing->panbrello_time = 0;
+                }
+                break;
+
+            case IT_S_FINE_PATTERN_DELAY:
+                sigrenderer->tick += effectvalue & 15;
+                break;
+#if 1
+            case IT_S7: {
+                if (sigrenderer->sigdata->flags & IT_USE_INSTRUMENTS) {
+                    int i;
+                    switch (effectvalue & 15) {
+                    case 0: /* cut background notes */
+                        for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                            IT_PLAYING *playing = sigrenderer->playing[i];
+                            if (playing && channel == playing->channel) {
+                                playing->declick_stage = 3;
+                                if (channel->playing == playing)
+                                    channel->playing = NULL;
+                            }
+                        }
+                        break;
+                    case 1: /* release background notes */
+                        for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                            IT_PLAYING *playing = sigrenderer->playing[i];
+                            if (playing && channel == playing->channel &&
+                                !(playing->flags & IT_PLAYING_SUSTAINOFF)) {
+                                it_note_off(playing);
+                            }
+                        }
+                        break;
+                    case 2: /* fade background notes */
+                        for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                            IT_PLAYING *playing = sigrenderer->playing[i];
+                            if (playing && channel == playing->channel) {
+                                // playing->flags &= IT_PLAYING_SUSTAINOFF;
+                                playing->flags |= IT_PLAYING_FADING;
+                            }
+                        }
+                        break;
+                    case 3:
+                        channel->new_note_action = NNA_NOTE_CUT;
+                        break;
+                    case 4:
+                        channel->new_note_action = NNA_NOTE_CONTINUE;
+                        break;
+                    case 5:
+                        channel->new_note_action = NNA_NOTE_OFF;
+                        break;
+                    case 6:
+                        channel->new_note_action = NNA_NOTE_FADE;
+                        break;
+
+                    case 7:
+                        if (channel->playing)
+                            channel->playing->enabled_envelopes &=
+                                ~IT_ENV_VOLUME;
+                        break;
+                    case 8:
+                        if (channel->playing)
+                            channel->playing->enabled_envelopes |=
+                                IT_ENV_VOLUME;
+                        break;
+
+                    case 9:
+                        if (channel->playing)
+                            channel->playing->enabled_envelopes &=
+                                ~IT_ENV_PANNING;
+                        break;
+                    case 10:
+                        if (channel->playing)
+                            channel->playing->enabled_envelopes |=
+                                IT_ENV_PANNING;
+                        break;
+
+                    case 11:
+                        if (channel->playing)
+                            channel->playing->enabled_envelopes &=
+                                ~IT_ENV_PITCH;
+                        break;
+                    case 12:
+                        if (channel->playing)
+                            channel->playing->enabled_envelopes |= IT_ENV_PITCH;
+                        break;
+                    }
+                }
+            } break;
+#endif
+            case IT_S_SET_PAN:
+                // ASSERT(!(sigdata->flags & IT_WAS_AN_XM));
+                channel->pan =
+                    ((effectvalue & 15) << 2) | ((effectvalue & 15) >> 2);
+                channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
+
+                if (channel->playing)
+                    channel->playing->panbrello_depth = 0;
+                break;
+            case IT_S_SET_SURROUND_SOUND:
+                if ((effectvalue & 15) == 15) {
+                    if (channel->playing && channel->playing->sample &&
+                        !(channel->playing->sample->flags &
+                          (IT_SAMPLE_LOOP | IT_SAMPLE_SUS_LOOP))) {
+                        channel->playing->flags |= IT_PLAYING_REVERSE;
+                        it_playing_reset_resamplers(
+                            channel->playing,
+                            channel->playing->sample->length - 1);
+                    }
+                } else if ((effectvalue & 15) == 1) {
+                    channel->pan = IT_SURROUND;
+                    channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
+                }
+                if (channel->playing)
+                    channel->playing->panbrello_depth = 0;
+                break;
+            case IT_S_SET_HIGH_OFFSET:
+                channel->high_offset = effectvalue & 15;
+                break;
+            // case IT_S_PATTERN_LOOP:
+            case IT_S_DELAYED_NOTE_CUT:
+                channel->note_cut_count = effectvalue & 15;
+                if (!channel->note_cut_count) {
+                    if (sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_PTM))
+                        channel->volume = 0;
+                    else
+                        channel->note_cut_count = 1;
+                }
+                break;
+            case IT_S_SET_MIDI_MACRO:
+                if ((sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_MOD)) ==
+                    (IT_WAS_AN_XM | IT_WAS_A_MOD)) {
+                    channel->inv_loop_speed = effectvalue & 15;
+                    update_invert_loop(channel, channel->playing
+                                                    ? channel->playing->sample
+                                                    : NULL);
+                } else
+                    channel->SFmacro = effectvalue & 15;
+                break;
+            }
+        } break;
+        case IT_SET_SONG_TEMPO: {
+            unsigned char v = entry->effectvalue;
+            if (v == 0)
+                v = channel->lastW;
+            channel->lastW = v;
+            if (v < 0x10)
+                sigrenderer->temposlide = -v;
+            else if (v < 0x20)
+                sigrenderer->temposlide = v & 15;
+            else
+                sigrenderer->tempo = v;
+        } break;
+        case IT_FINE_VIBRATO: {
+            unsigned char speed = entry->effectvalue >> 4;
+            unsigned char depth = entry->effectvalue & 15;
+            if (speed == 0)
+                speed = channel->lastHspeed;
+            channel->lastHspeed = speed;
+            if (depth == 0)
+                depth = channel->lastHdepth;
+            else {
+                if (sigdata->flags & IT_OLD_EFFECTS)
+                    depth <<= 1;
+                channel->lastHdepth = depth;
+            }
+            for (i = -1; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                if (i < 0)
+                    playing = channel->playing;
+                else {
+                    playing = sigrenderer->playing[i];
+                    if (!playing || playing->channel != channel)
+                        continue;
+                }
+                if (playing) {
+                    playing->vibrato_speed = speed;
+                    playing->vibrato_depth = depth;
+                    playing->vibrato_n++;
+                }
+            }
+        } break;
+        case IT_SET_GLOBAL_VOLUME:
+            if ((sigdata->flags & IT_WAS_AN_S3M) && (entry->effectvalue > 64))
+                break;
+            if (entry->effectvalue <= 128)
+                sigrenderer->globalvolume = entry->effectvalue;
+#ifdef VOLUME_OUT_OF_RANGE_SETS_MAXIMUM
+            else
+                sigrenderer->globalvolume = 128;
+#endif
+            break;
+        case IT_GLOBAL_VOLUME_SLIDE: {
+            unsigned char v = entry->effectvalue;
+            if (v == 0)
+                v = channel->lastW;
+            channel->lastW = v;
+            if ((v & 0x0F) == 0) { /* Wx0 */
+                sigrenderer->globalvolslide =
+                    (sigdata->flags & IT_WAS_AN_XM) ? (v >> 4) * 2 : (v >> 4);
+            } else if ((v & 0xF0) == 0) { /* W0x */
+                sigrenderer->globalvolslide =
+                    (sigdata->flags & IT_WAS_AN_XM) ? (-v) * 2 : (-v);
+            } else if ((v & 0x0F) == 0x0F) { /* WxF */
+                sigrenderer->globalvolume += v >> 4;
+                if (sigrenderer->globalvolume > 128)
+                    sigrenderer->globalvolume = 128;
+            } else if ((v & 0xF0) == 0xF0) { /* WFx */
+                sigrenderer->globalvolume -= v & 15;
+                if (sigrenderer->globalvolume > 128)
+                    sigrenderer->globalvolume = 0;
+            }
+        } break;
+        case IT_SET_PANNING:
+            if (sigdata->flags & IT_WAS_AN_XM) {
+                channel->truepan = 32 + entry->effectvalue * 64;
+            } else {
+                if (sigdata->flags & IT_WAS_AN_S3M)
+                    channel->pan = (entry->effectvalue + 1) >> 1;
+                else
+                    channel->pan = (entry->effectvalue + 2) >> 2;
+                channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
+            }
+            if (channel->playing)
+                channel->playing->panbrello_depth = 0;
+            break;
+        case IT_PANBRELLO: {
+            unsigned char speed = entry->effectvalue >> 4;
+            unsigned char depth = entry->effectvalue & 15;
+            if (speed == 0)
+                speed = channel->lastYspeed;
+            channel->lastYspeed = speed;
+            if (depth == 0)
+                depth = channel->lastYdepth;
+            channel->lastYdepth = depth;
+            if (channel->playing) {
+                channel->playing->panbrello_speed = speed;
+                channel->playing->panbrello_depth = depth;
+            }
+        } break;
+        case IT_MIDI_MACRO: {
+            const IT_MIDI *midi = sigdata->midi ? sigdata->midi : &default_midi;
+            if (entry->effectvalue >= 0x80) {
+                int n = midi->Zmacrolen[entry->effectvalue - 0x80];
+                int i;
+                for (i = 0; i < n; i++)
+                    it_send_midi(sigrenderer, channel,
+                                 midi->Zmacro[entry->effectvalue - 0x80][i]);
+            } else {
+                int n = midi->SFmacrolen[channel->SFmacro];
+                int i, j;
+                for (i = 0, j = 1; i < n; i++, j <<= 1)
+                    it_send_midi(
+                        sigrenderer, channel,
+                        (unsigned char)(midi->SFmacroz[channel->SFmacro] & j
+                                            ? entry->effectvalue
+                                            : midi->SFmacro[channel->SFmacro]
+                                                           [i]));
+            }
+        } break;
+        case IT_XM_SET_ENVELOPE_POSITION:
+            if (channel->playing && channel->playing->env_instrument) {
+                IT_ENVELOPE *envelope =
+                    &channel->playing->env_instrument->volume_envelope;
+                if (envelope->flags & IT_ENVELOPE_ON) {
+                    IT_PLAYING_ENVELOPE *pe =
+                        &channel->playing->volume_envelope;
+                    pe->tick = entry->effectvalue;
+                    if (pe->tick >= envelope->node_t[envelope->n_nodes - 1])
+                        pe->tick = envelope->node_t[envelope->n_nodes - 1];
+                    pe->next_node = 0;
+                    while (pe->tick > envelope->node_t[pe->next_node])
+                        pe->next_node++;
+                    xm_envelope_calculate_value(envelope, pe);
+                }
+            }
+            break;
+
+        /* uggly plain portamento for now */
+        case IT_PTM_NOTE_SLIDE_DOWN:
+        case IT_PTM_NOTE_SLIDE_DOWN_RETRIG: {
+            channel->toneslide_retrig =
+                (entry->effect == IT_PTM_NOTE_SLIDE_DOWN_RETRIG);
+
+            if (channel->ptm_last_toneslide) {
+                channel->toneslide_tick = channel->last_toneslide_tick;
+
+                if (--channel->toneslide_tick == 0) {
+                    channel->truenote += channel->toneslide;
+                    if (channel->truenote >= 120) {
+                        if (channel->toneslide < 0)
+                            channel->truenote = 0;
+                        else
+                            channel->truenote = 119;
+                    }
+                    channel->note += channel->toneslide;
+                    if (channel->note >= 120) {
+                        if (channel->toneslide < 0)
+                            channel->note = 0;
+                        else
+                            channel->note = 119;
+                    }
+
+                    if (channel->playing) {
+                        if (channel->sample)
+                            channel->playing->note = channel->truenote;
+                        else
+                            channel->playing->note = channel->note;
+                        it_playing_reset_resamplers(channel->playing, 0);
+                        channel->playing->declick_stage = 0;
+                    }
+                }
+            }
+
+            channel->ptm_last_toneslide = 0;
+
+            channel->toneslide = -(entry->effectvalue & 15);
+            channel->ptm_toneslide = (entry->effectvalue & 0xF0) >> 4;
+            channel->toneslide_tick += channel->ptm_toneslide;
+        } break;
+        case IT_PTM_NOTE_SLIDE_UP:
+        case IT_PTM_NOTE_SLIDE_UP_RETRIG: {
+            channel->toneslide_retrig =
+                (entry->effect == IT_PTM_NOTE_SLIDE_UP_RETRIG);
+
+            if (channel->ptm_last_toneslide) {
+                channel->toneslide_tick = channel->last_toneslide_tick;
+
+                if (--channel->toneslide_tick == 0) {
+                    channel->truenote += channel->toneslide;
+                    if (channel->truenote >= 120) {
+                        if (channel->toneslide < 0)
+                            channel->truenote = 0;
+                        else
+                            channel->truenote = 119;
+                    }
+                    channel->note += channel->toneslide;
+                    if (channel->note >= 120) {
+                        if (channel->toneslide < 0)
+                            channel->note = 0;
+                        else
+                            channel->note = 119;
+                    }
+
+                    if (channel->playing) {
+                        if (channel->sample)
+                            channel->playing->note = channel->truenote;
+                        else
+                            channel->playing->note = channel->note;
+                        it_playing_reset_resamplers(channel->playing, 0);
+                        channel->playing->declick_stage = 0;
+                    }
+                }
+            }
+
+            channel->ptm_last_toneslide = 0;
+
+            channel->toneslide = -(entry->effectvalue & 15);
+            channel->ptm_toneslide = (entry->effectvalue & 0xF0) >> 4;
+            channel->toneslide_tick += channel->ptm_toneslide;
+        } break;
+
+        case IT_OKT_NOTE_SLIDE_DOWN:
+        case IT_OKT_NOTE_SLIDE_DOWN_ROW:
+            channel->toneslide = -entry->effectvalue;
+            channel->okt_toneslide =
+                (entry->effect == IT_OKT_NOTE_SLIDE_DOWN) ? 255 : 1;
+            break;
+
+        case IT_OKT_NOTE_SLIDE_UP:
+        case IT_OKT_NOTE_SLIDE_UP_ROW:
+            channel->toneslide = entry->effectvalue;
+            channel->okt_toneslide =
+                (entry->effect == IT_OKT_NOTE_SLIDE_UP) ? 255 : 1;
+            break;
+
+        case IT_OKT_ARPEGGIO_3:
+        case IT_OKT_ARPEGGIO_4:
+        case IT_OKT_ARPEGGIO_5: {
+            channel->arpeggio_offsets[0] = 0;
+            channel->arpeggio_offsets[1] = -(entry->effectvalue >> 4);
+            channel->arpeggio_offsets[2] = entry->effectvalue & 0x0F;
+
+            switch (entry->effect) {
+            case IT_OKT_ARPEGGIO_3:
+                channel->arpeggio_table =
+                    (const unsigned char *)&arpeggio_okt_3;
+                break;
+
+            case IT_OKT_ARPEGGIO_4:
+                channel->arpeggio_table =
+                    (const unsigned char *)&arpeggio_okt_4;
+                break;
+
+            case IT_OKT_ARPEGGIO_5:
+                channel->arpeggio_table =
+                    (const unsigned char *)&arpeggio_okt_5;
+                break;
+            }
+        } break;
+
+        case IT_OKT_VOLUME_SLIDE_DOWN:
+            if (entry->effectvalue <= 16)
+                channel->volslide = -entry->effectvalue;
+            else {
+                channel->volume -= entry->effectvalue - 16;
+                if (channel->volume > 64)
+                    channel->volume = 0;
+            }
+            break;
+
+        case IT_OKT_VOLUME_SLIDE_UP:
+            if (entry->effectvalue <= 16)
+                channel->volslide = entry->effectvalue;
+            else {
+                channel->volume += entry->effectvalue - 16;
+                if (channel->volume > 64)
+                    channel->volume = 64;
+            }
+            break;
+        }
+    }
+
+    if (!(sigdata->flags & IT_WAS_AN_XM))
+        post_process_it_volpan(sigrenderer, entry);
+
+    return 0;
+}
+
+static int process_it_note_data(DUMB_IT_SIGRENDERER *sigrenderer,
+                                IT_ENTRY *entry) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+    IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
+
+    // When tone portamento and instrument are specified:
+    // If Gxx is off:
+    //   - same sample, do nothing but portamento
+    //   - diff sample, retrigger all but keep current note+slide + do porta
+    //   - if instrument is invalid, nothing; if sample is invalid, cut
+    // If Gxx is on:
+    //   - same sample or new sample invalid, retrigger envelopes and initialise
+    //   note value for portamento to 'seek' to
+    //   - diff sample/inst, start using new envelopes
+    // When tone portamento is specified alone, sample won't change.
+    // TODO: consider what happens with instrument alone after all this...
+
+    if (entry->mask & (IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT)) {
+        if (entry->mask & IT_ENTRY_INSTRUMENT)
+            channel->instrument = entry->instrument;
+        instrument_to_sample(sigdata, channel);
+        if (channel->note <= 120) {
+            if ((sigdata->flags & IT_USE_INSTRUMENTS) && channel->sample == 0)
+                it_retrigger_note(sigrenderer, channel);
+            /* Stop the note */ /*return 1;*/
+            if (entry->mask & IT_ENTRY_INSTRUMENT)
+                get_default_volpan(sigdata, channel);
+        } else
+            it_retrigger_note(sigrenderer, channel); /* Stop the note */
+    }
+
+    /** WARNING: This is not ideal, since channel->playing might not get
+     * allocated owing to lack of memory... */
+    if (((entry->mask & IT_ENTRY_VOLPAN) && entry->volpan >= 193 &&
+         entry->volpan <= 202) ||
+        ((entry->mask & IT_ENTRY_EFFECT) &&
+         (entry->effect == IT_TONE_PORTAMENTO ||
+          entry->effect == IT_VOLSLIDE_TONEPORTA))) {
+        if (channel->playing && (entry->mask & IT_ENTRY_INSTRUMENT)) {
+            if (sigdata->flags & IT_COMPATIBLE_GXX)
+                it_compatible_gxx_retrigger(sigdata, channel);
+            else if ((!(sigdata->flags & IT_USE_INSTRUMENTS) ||
+                      (channel->instrument >= 1 &&
+                       channel->instrument <= sigdata->n_instruments)) &&
+                     channel->sample != channel->playing->sampnum) {
+                unsigned char note = channel->playing->note;
+                int slide = channel->playing->slide;
+                it_retrigger_note(sigrenderer, channel);
+                if (channel->playing) {
+                    channel->playing->note = note;
+                    channel->playing->slide = slide;
+                    // Should we be preserving sample_vibrato_time? depth?
+                }
+            }
+        }
+
+        channel->toneporta = 0;
+
+        if ((entry->mask & IT_ENTRY_VOLPAN) && entry->volpan >= 193 &&
+            entry->volpan <= 202) {
+            /* Tone Portamento in the volume column */
+            static const unsigned char slidetable[] = {0,  1,  4,  8,   16,
+                                                       32, 64, 96, 128, 255};
+            unsigned char v = slidetable[entry->volpan - 193];
+            if (sigdata->flags & IT_COMPATIBLE_GXX) {
+                if (v == 0)
+                    v = channel->lastG;
+                channel->lastG = v;
+            } else {
+                if (v == 0)
+                    v = channel->lastEF;
+                channel->lastEF = v;
+            }
+            channel->toneporta += v << 4;
+        }
+
+        if ((entry->mask & IT_ENTRY_EFFECT) &&
+            (entry->effect == IT_TONE_PORTAMENTO ||
+             entry->effect == IT_VOLSLIDE_TONEPORTA)) {
+            /* Tone Portamento in the effect column */
+            unsigned char v;
+            if (entry->effect == IT_TONE_PORTAMENTO)
+                v = entry->effectvalue;
+            else
+                v = 0;
+            if (sigdata->flags & IT_COMPATIBLE_GXX) {
+                if (v == 0)
+                    v = channel->lastG;
+                channel->lastG = v;
+            } else {
+                if (v == 0 && !(sigdata->flags & IT_WAS_A_669))
+                    v = channel->lastEF;
+                channel->lastEF = v;
+            }
+            channel->toneporta += v << 4;
+        }
+
+        if ((entry->mask & IT_ENTRY_NOTE) ||
+            ((sigdata->flags & IT_COMPATIBLE_GXX) &&
+             (entry->mask & IT_ENTRY_INSTRUMENT))) {
+            if (channel->note <= 120) {
+                if (channel->sample)
+                    channel->destnote = channel->truenote;
+                else
+                    channel->destnote = channel->note;
+            }
+        }
+
+        if (channel->playing)
+            goto skip_start_note;
+    }
+
+    if ((entry->mask & IT_ENTRY_NOTE) ||
+        ((entry->mask & IT_ENTRY_INSTRUMENT) &&
+         (!channel->playing ||
+          entry->instrument != channel->playing->instnum))) {
+        if (channel->note <= 120) {
+            get_true_pan(sigdata, channel);
+            if ((entry->mask & IT_ENTRY_NOTE) ||
+                !(sigdata->flags & (IT_WAS_AN_S3M | IT_WAS_A_PTM)))
+                it_retrigger_note(sigrenderer, channel);
+        }
+    }
+
+skip_start_note:
+
+    if (entry->mask & IT_ENTRY_VOLPAN) {
+        if (entry->volpan <= 64) {
+            /* Volume */
+            channel->volume = entry->volpan;
+        } else if (entry->volpan <= 74) {
+            /* Fine volume slide up */
+            unsigned char v = entry->volpan - 65;
+            if (v == 0)
+                v = channel->lastvolslide;
+            channel->lastvolslide = v;
+            /* = effect DxF where x == entry->volpan - 65 */
+            channel->volume += v;
+            if (channel->volume > 64)
+                channel->volume = 64;
+        } else if (entry->volpan <= 84) {
+            /* Fine volume slide down */
+            unsigned char v = entry->volpan - 75;
+            if (v == 0)
+                v = channel->lastvolslide;
+            channel->lastvolslide = v;
+            /* = effect DFx where x == entry->volpan - 75 */
+            channel->volume -= v;
+            if (channel->volume > 64)
+                channel->volume = 0;
+        } else if (entry->volpan < 128) {
+            /* Volume slide up */
+            /* Volume slide down */
+            /* Portamento down */
+            /* Portamento up */
+        } else if (entry->volpan <= 192) {
+            /* Pan */
+            channel->pan = entry->volpan - 128;
+            channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
+        }
+        /* else */
+        /* Tone Portamento */
+        /* Vibrato */
+    }
+    return 0;
+}
+
+static void retrigger_xm_envelopes(IT_PLAYING *playing) {
+    playing->volume_envelope.next_node = 0;
+    playing->volume_envelope.tick = -1;
+    playing->pan_envelope.next_node = 0;
+    playing->pan_envelope.tick = -1;
+    playing->fadeoutcount = 1024;
+}
+
+static void process_xm_note_data(DUMB_IT_SIGRENDERER *sigrenderer,
+                                 IT_ENTRY *entry) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+    IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
+    IT_PLAYING *playing = NULL;
+
+    if (entry->mask & IT_ENTRY_INSTRUMENT) {
+        int oldsample = channel->sample;
+        channel->inv_loop_offset = 0;
+        channel->instrument = entry->instrument;
+        instrument_to_sample(sigdata, channel);
+        if (channel->playing &&
+            !((entry->mask & IT_ENTRY_NOTE) && entry->note >= 120) &&
+            !((entry->mask & IT_ENTRY_EFFECT) &&
+              entry->effect == IT_XM_KEY_OFF && entry->effectvalue == 0)) {
+            playing = dup_playing(channel->playing, channel, channel);
+            if (!playing)
+                return;
+            if (!(sigdata->flags & IT_WAS_A_MOD)) {
+                /* Retrigger vol/pan envelopes if enabled, and cancel fadeout.
+                 * Also reset vol/pan to that of _original_ instrument.
+                 */
+                channel->playing->flags &=
+                    ~(IT_PLAYING_SUSTAINOFF | IT_PLAYING_FADING);
+                it_playing_update_resamplers(channel->playing);
+
+                channel->volume = channel->playing->sample->default_volume;
+                channel->truepan =
+                    32 + channel->playing->sample->default_pan * 64;
+
+                retrigger_xm_envelopes(channel->playing);
+            } else {
+                /* Switch if sample changed */
+                if (oldsample != channel->sample) {
+                    int i;
+                    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                        if (!sigrenderer->playing[i]) {
+                            channel->playing->declick_stage = 3;
+                            sigrenderer->playing[i] = channel->playing;
+                            channel->playing = NULL;
+                            break;
+                        }
+                    }
+
+                    if (!channel->sample) {
+                        if (channel->playing) {
+                            free_playing(channel->playing);
+                            channel->playing = NULL;
+                        }
+                    } else {
+                        if (channel->playing) {
+                            free_playing(channel->playing);
+                        }
+                        channel->playing = playing;
+                        playing = NULL;
+                        channel->playing->declick_stage = 0;
+                        channel->playing->sampnum = channel->sample;
+                        channel->playing->sample =
+                            &sigdata->sample[channel->sample - 1];
+                        it_playing_reset_resamplers(channel->playing, 0);
+                    }
+                }
+                get_default_volpan(sigdata, channel);
+            }
+        }
+    }
+
+    if (!((entry->mask & IT_ENTRY_EFFECT) && entry->effect == IT_XM_KEY_OFF &&
+          entry->effectvalue == 0) &&
+        (entry->mask & IT_ENTRY_NOTE)) {
+        if (!(entry->mask & IT_ENTRY_INSTRUMENT))
+            instrument_to_sample(sigdata, channel);
+
+        if (channel->note >= 120)
+            xm_note_off(sigdata, channel);
+        else if (channel->sample == 0) {
+            /** If we get here, one of the following is the case:
+             ** 1. The instrument has never been specified on this channel.
+             ** 2. The specified instrument is invalid.
+             ** 3. The instrument has no sample mapped to the selected note.
+             ** What should happen?
+             **
+             ** Experimentation shows that any existing note stops and cannot
+             ** be brought back. A subsequent instrument change fixes that.
+             **/
+            if (channel->playing) {
+                int i;
+                if (playing) {
+                    free_playing(channel->playing);
+                    channel->playing = playing;
+                    playing = NULL;
+                }
+                for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                    if (!sigrenderer->playing[i]) {
+                        channel->playing->declick_stage = 3;
+                        sigrenderer->playing[i] = channel->playing;
+                        channel->playing = NULL;
+                        break;
+                    }
+                }
+                if (channel->playing) {
+                    free_playing(channel->playing);
+                    channel->playing = NULL;
+                }
+            }
+            if (playing)
+                free_playing(playing);
+            return;
+        } else if (channel->playing && (entry->mask & IT_ENTRY_VOLPAN) &&
+                   ((entry->volpan >> 4) == 0xF)) {
+            /* Don't retrigger note; portamento in the volume column. */
+        } else if (channel->playing && (entry->mask & IT_ENTRY_EFFECT) &&
+                   (entry->effect == IT_TONE_PORTAMENTO ||
+                    entry->effect == IT_VOLSLIDE_TONEPORTA)) {
+            /* Don't retrigger note; portamento in the effects column. */
+        } else {
+            channel->destnote = IT_NOTE_OFF;
+
+            if (!channel->playing) {
+                channel->playing = new_playing();
+                if (!channel->playing) {
+                    if (playing)
+                        free_playing(playing);
+                    return;
+                }
+                // Adding the following seems to do the trick for the case where
+                // a piece starts with an instrument alone and then some notes
+                // alone.
+                retrigger_xm_envelopes(channel->playing);
+            } else if (playing) {
+                /* volume rampy stuff! move note to NNA */
+                int i;
+                IT_PLAYING *ptemp;
+                if (playing->sample)
+                    ptemp = playing;
+                else
+                    ptemp = channel->playing;
+                if (!ptemp) {
+                    if (playing)
+                        free_playing(playing);
+                    return;
+                }
+                playing = NULL;
+                for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                    if (!sigrenderer->playing[i]) {
+                        ptemp->declick_stage = 3;
+                        ptemp->flags |=
+                            IT_PLAYING_SUSTAINOFF | IT_PLAYING_FADING;
+                        sigrenderer->playing[i] = ptemp;
+                        ptemp = NULL;
+                        break;
+                    }
+                }
+                if (ptemp)
+                    free_playing(ptemp);
+            }
+
+            channel->playing->flags = 0;
+            channel->playing->resampling_quality =
+                sigrenderer->resampling_quality;
+            channel->playing->channel = channel;
+            channel->playing->sample = &sigdata->sample[channel->sample - 1];
+            if (sigdata->flags & IT_USE_INSTRUMENTS)
+                channel->playing->instrument =
+                    &sigdata->instrument[channel->instrument - 1];
+            else
+                channel->playing->instrument = NULL;
+            channel->playing->env_instrument = channel->playing->instrument;
+            channel->playing->sampnum = channel->sample;
+            channel->playing->instnum = channel->instrument;
+            channel->playing->declick_stage = 0;
+            channel->playing->channel_volume = channel->channelvolume;
+            channel->playing->note = channel->truenote;
+            channel->playing->enabled_envelopes = 0;
+            channel->playing->volume_offset = 0;
+            channel->playing->panning_offset = 0;
+            // channel->playing->output = channel->output;
+            if (sigdata->flags & IT_USE_INSTRUMENTS) {
+                IT_PLAYING *playing = channel->playing;
+                IT_INSTRUMENT *instrument = playing->instrument;
+                if (instrument->volume_envelope.flags & IT_ENVELOPE_ON)
+                    playing->enabled_envelopes |= IT_ENV_VOLUME;
+                if (instrument->pan_envelope.flags & IT_ENVELOPE_ON)
+                    playing->enabled_envelopes |= IT_ENV_PANNING;
+                // if (instrument->output) playing->output = instrument->output;
+            }
+            channel->playing->filter_cutoff = 127;
+            channel->playing->filter_resonance = 0;
+            channel->playing->true_filter_cutoff = 127 << 8;
+            channel->playing->true_filter_resonance = 0;
+            channel->playing->vibrato_speed = 0;
+            channel->playing->vibrato_depth = 0;
+            channel->playing->vibrato_n = 0;
+            channel->playing->vibrato_time = 0;
+            channel->playing->vibrato_waveform = 0;
+            channel->playing->tremolo_speed = 0;
+            channel->playing->tremolo_depth = 0;
+            channel->playing->tremolo_time = 0;
+            channel->playing->tremolo_waveform = 0;
+            channel->playing->panbrello_speed = 0;
+            channel->playing->panbrello_depth = 0;
+            channel->playing->panbrello_time = 0;
+            channel->playing->panbrello_waveform = 0;
+            channel->playing->panbrello_random = 0;
+            channel->playing->sample_vibrato_time = 0;
+            channel->playing->sample_vibrato_waveform =
+                channel->playing->sample->vibrato_waveform;
+            channel->playing->sample_vibrato_depth = 0;
+            channel->playing->slide = 0;
+            channel->playing->finetune = channel->playing->sample->finetune;
+            it_reset_filter_state(
+                &channel->playing->filter_state[0]); // Are these
+            it_reset_filter_state(
+                &channel->playing->filter_state[1]); // necessary?
+            it_playing_reset_resamplers(channel->playing, 0);
+
+            /** WARNING - is everything initialised? */
+        }
+    }
+
+    if (!((entry->mask & IT_ENTRY_EFFECT) && entry->effect == IT_XM_KEY_OFF &&
+          entry->effectvalue == 0) &&
+        !((entry->mask & IT_ENTRY_NOTE) && entry->note >= 120) &&
+        (entry->mask & (IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT)) ==
+            (IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT)) {
+        if (channel->playing)
+            retrigger_xm_envelopes(channel->playing);
+        get_default_volpan(sigdata, channel);
+    }
+
+    if ((entry->mask & IT_ENTRY_VOLPAN) && ((entry->volpan >> 4) == 0xF)) {
+        /* Tone Portamento */
+        unsigned char v = (entry->volpan & 15) << 4;
+        if (v == 0)
+            v = channel->lastG;
+        channel->lastG = v;
+        if (entry->mask & IT_ENTRY_NOTE)
+            if (channel->sample && channel->note < 120)
+                channel->destnote = channel->truenote;
+        channel->toneporta = v << 4;
+    } else if ((entry->mask & IT_ENTRY_EFFECT) &&
+               (entry->effect == IT_TONE_PORTAMENTO ||
+                entry->effect == IT_VOLSLIDE_TONEPORTA)) {
+        unsigned char v;
+        if (entry->effect == IT_TONE_PORTAMENTO)
+            v = entry->effectvalue;
+        else
+            v = 0;
+        if (v == 0)
+            v = channel->lastG;
+        channel->lastG = v;
+        if (entry->mask & IT_ENTRY_NOTE)
+            if (channel->sample && channel->note < 120)
+                channel->destnote = channel->truenote;
+        channel->toneporta = v << 4;
+    }
+
+    if (entry->mask & IT_ENTRY_VOLPAN) {
+        int effect = entry->volpan >> 4;
+        int value = entry->volpan & 15;
+        switch (effect) {
+        case 0x6: /* Volume slide down */
+            channel->xm_volslide = -value;
+            break;
+        case 0x7: /* Volume slide up */
+            channel->xm_volslide = value;
+            break;
+        case 0x8: /* Fine volume slide down */
+            channel->volume -= value;
+            if (channel->volume > 64)
+                channel->volume = 0;
+            break;
+        case 0x9: /* Fine volume slide up */
+            channel->volume += value;
+            if (channel->volume > 64)
+                channel->volume = 64;
+            break;
+        case 0xA: /* Set vibrato speed */
+            if (value)
+                channel->lastHspeed = value;
+            if (channel->playing)
+                channel->playing->vibrato_speed = channel->lastHspeed;
+            break;
+        case 0xB: /* Vibrato */
+            if (value)
+                channel->lastHdepth = value << 2; /** WARNING: correct ? */
+            if (channel->playing) {
+                channel->playing->vibrato_depth = channel->lastHdepth;
+                channel->playing->vibrato_speed = channel->lastHspeed;
+                channel->playing->vibrato_n++;
+            }
+            break;
+        case 0xC: /* Set panning */
+            channel->truepan = 32 + value * (17 * 64);
+            break;
+        case 0xD: /* Pan slide left */
+            /* -128 is a special case for emulating a 'feature' in FT2.
+             * As soon as effects are processed, it goes hard left.
+             */
+            channel->panslide = value ? -value : -128;
+            break;
+        case 0xE: /* Pan slide Right */
+            channel->panslide = value;
+            break;
+        case 0xF: /* Tone porta */
+            break;
+        default: /* Volume */
+            channel->volume = entry->volpan - 0x10;
+            break;
+        }
+    }
+
+    if (playing)
+        free_playing(playing);
+}
+
+/* This function assumes !IT_IS_END_ROW(entry). */
+static int process_note_data(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry,
+                             int ignore_cxx) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+
+    if (sigdata->flags & IT_WAS_AN_XM)
+        process_xm_note_data(sigrenderer, entry);
+    else if (process_it_note_data(sigrenderer, entry))
+        return 0;
+
+    return process_effects(sigrenderer, entry, ignore_cxx);
+}
+
+static int process_entry(DUMB_IT_SIGRENDERER *sigrenderer, IT_ENTRY *entry,
+                         int ignore_cxx) {
+    IT_CHANNEL *channel = &sigrenderer->channel[(int)entry->channel];
+
+    if (entry->mask & IT_ENTRY_NOTE)
+        channel->note = entry->note;
+
+    if ((entry->mask & (IT_ENTRY_NOTE | IT_ENTRY_EFFECT)) &&
+        (sigrenderer->sigdata->flags & IT_WAS_A_669)) {
+        reset_channel_effects(channel);
+        // XXX unknown
+        if (channel->playing)
+            channel->playing->finetune = 0;
+    }
+
+    if ((entry->mask & IT_ENTRY_EFFECT) && entry->effect == IT_S) {
+        /* channel->lastS was set in update_pattern_variables(). */
+        unsigned char effectvalue = channel->lastS;
+        if (effectvalue >> 4 == IT_S_NOTE_DELAY) {
+            channel->note_delay_count = effectvalue & 15;
+            if (channel->note_delay_count == 0)
+                channel->note_delay_count = 1;
+            channel->note_delay_entry = entry;
+            return 0;
+        }
+    }
+
+    return process_note_data(sigrenderer, entry, ignore_cxx);
+}
+
+static void update_tick_counts(DUMB_IT_SIGRENDERER *sigrenderer) {
+    int i;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        IT_CHANNEL *channel = &sigrenderer->channel[i];
+
+        if (channel->key_off_count) {
+            channel->key_off_count--;
+            if (channel->key_off_count == 0)
+                xm_note_off(sigrenderer->sigdata, channel);
+        } else if (channel->note_cut_count) {
+            channel->note_cut_count--;
+            if (channel->note_cut_count == 0) {
+                if (sigrenderer->sigdata->flags & (IT_WAS_AN_XM | IT_WAS_A_PTM))
+                    channel->volume = 0;
+                else if (channel->playing) {
+                    int i;
+                    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+                        if (!sigrenderer->playing[i]) {
+                            channel->playing->declick_stage = 3;
+                            sigrenderer->playing[i] = channel->playing;
+                            channel->playing = NULL;
+                            break;
+                        }
+                    }
+                    if (channel->playing) {
+                        free_playing(channel->playing);
+                        channel->playing = NULL;
+                    }
+                }
+            }
+        } else if (channel->note_delay_count && channel->note_delay_entry) {
+            channel->note_delay_count--;
+            if (channel->note_delay_count == 0)
+                process_note_data(sigrenderer, channel->note_delay_entry, 0);
+            /* Don't bother checking the return value; if the note
+             * was delayed, there can't have been a speed=0.
+             */
+        }
+    }
+}
+
+static int envelope_get_y(IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe) {
+#if 1
+    (void)envelope; // TODO: remove the parameter
+    return pe->value;
+#else
+    int ys, ye;
+    int ts, te;
+    int t;
+
+    if (pe->next_node <= 0)
+        return envelope->node_y[0] << IT_ENVELOPE_SHIFT;
+
+    if (pe->next_node >= envelope->n_nodes)
+        return envelope->node_y[envelope->n_nodes - 1] << IT_ENVELOPE_SHIFT;
+
+    ys = envelope->node_y[pe->next_node - 1] << IT_ENVELOPE_SHIFT;
+    ts = envelope->node_t[pe->next_node - 1];
+    te = envelope->node_t[pe->next_node];
+
+    if (ts == te)
+        return ys;
+
+    ye = envelope->node_y[pe->next_node] << IT_ENVELOPE_SHIFT;
+
+    t = pe->tick;
+
+    return ys + (ye - ys) * (t - ts) / (te - ts);
+#endif
+}
+
+#if 0
+static int it_envelope_end(IT_PLAYING *playing, IT_ENVELOPE *envelope, IT_PLAYING_ENVELOPE *pe)
+{
+	if (pe->next_node >= envelope->n_nodes)
+		return 1;
+
+	if (pe->tick < envelope->node_t[pe->next_node]) return 0;
+
+	if ((envelope->flags & IT_ENVELOPE_LOOP_ON) &&
+	    envelope->loop_end >= pe->next_node &&
+	    envelope->node_t[envelope->loop_end] <= pe->tick) return 0;
+
+	if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) &&
+	    !(playing->flags & IT_PLAYING_SUSTAINOFF) &&
+	    envelope->sus_loop_end >= pe->next_node &&
+	    envelope->node_t[envelope->sus_loop_end] <= pe->tick) return 0;
+
+	if (envelope->node_t[envelope->n_nodes-1] <= pe->tick) return 1;
+
+	return 0;
+}
+#endif
+
+/* Returns 1 when fading should be initiated for a volume envelope. */
+static int update_it_envelope(IT_PLAYING *playing, IT_ENVELOPE *envelope,
+                              IT_PLAYING_ENVELOPE *pe, int flags) {
+    if (!(playing->enabled_envelopes & flags) || !envelope->n_nodes)
+        return 0;
+
+    ASSERT(envelope->n_nodes > 0);
+
+    if (pe->tick <= 0)
+        pe->value = envelope->node_y[0] << IT_ENVELOPE_SHIFT;
+    else if (pe->tick >= envelope->node_t[envelope->n_nodes - 1]) {
+        pe->value = envelope->node_y[envelope->n_nodes - 1]
+                    << IT_ENVELOPE_SHIFT;
+    } else {
+        int ys = envelope->node_y[pe->next_node - 1] << IT_ENVELOPE_SHIFT;
+        int ts = envelope->node_t[pe->next_node - 1];
+        int te = envelope->node_t[pe->next_node];
+
+        if (ts == te)
+            pe->value = ys;
+        else {
+            int ye = envelope->node_y[pe->next_node] << IT_ENVELOPE_SHIFT;
+            int t = pe->tick;
+
+            pe->value = ys + (ye - ys) * (t - ts) / (te - ts);
+        }
+    }
+
+    pe->tick++;
+
+    recalculate_it_envelope_node(pe, envelope);
+
+    if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) &&
+        !(playing->flags & IT_PLAYING_SUSTAINOFF)) {
+        if (pe->tick > envelope->node_t[envelope->sus_loop_end]) {
+            pe->next_node = envelope->sus_loop_start + 1;
+            ASSERT(pe->next_node <= envelope->n_nodes);
+            pe->tick = envelope->node_t[envelope->sus_loop_start];
+            return 0;
+        }
+    } else if (envelope->flags & IT_ENVELOPE_LOOP_ON) {
+        if (pe->tick > envelope->node_t[envelope->loop_end]) {
+            pe->next_node = envelope->loop_start + 1;
+            ASSERT(pe->next_node <= envelope->n_nodes);
+            pe->tick = envelope->node_t[envelope->loop_start];
+            return 0;
+        }
+    } else if (pe->tick > envelope->node_t[envelope->n_nodes - 1])
+        return 1;
+
+    return 0;
+}
+
+static void update_it_envelopes(IT_PLAYING *playing) {
+    IT_ENVELOPE *envelope = &playing->env_instrument->volume_envelope;
+    IT_PLAYING_ENVELOPE *pe = &playing->volume_envelope;
+
+    if (update_it_envelope(playing, envelope, pe, IT_ENV_VOLUME)) {
+        playing->flags |= IT_PLAYING_FADING;
+        if (pe->value == 0)
+            playing->flags |= IT_PLAYING_DEAD;
+    }
+
+    update_it_envelope(playing, &playing->env_instrument->pan_envelope,
+                       &playing->pan_envelope, IT_ENV_PANNING);
+    update_it_envelope(playing, &playing->env_instrument->pitch_envelope,
+                       &playing->pitch_envelope, IT_ENV_PITCH);
+}
+
+static int xm_envelope_is_sustaining(IT_PLAYING *playing, IT_ENVELOPE *envelope,
+                                     IT_PLAYING_ENVELOPE *pe) {
+    if ((envelope->flags & IT_ENVELOPE_SUSTAIN_LOOP) &&
+        !(playing->flags & IT_PLAYING_SUSTAINOFF))
+        if (envelope->sus_loop_start < envelope->n_nodes)
+            if (pe->tick == envelope->node_t[envelope->sus_loop_start])
+                return 1;
+    return 0;
+}
+
+static void update_xm_envelope(IT_PLAYING *playing, IT_ENVELOPE *envelope,
+                               IT_PLAYING_ENVELOPE *pe) {
+    if (!(envelope->flags & IT_ENVELOPE_ON))
+        return;
+
+    if (xm_envelope_is_sustaining(playing, envelope, pe))
+        return;
+
+    if (pe->tick >= envelope->node_t[envelope->n_nodes - 1])
+        return;
+
+    pe->tick++;
+
+    /* pe->next_node must be kept up to date for envelope_get_y(). */
+    while (pe->tick > envelope->node_t[pe->next_node])
+        pe->next_node++;
+
+    if ((envelope->flags & IT_ENVELOPE_LOOP_ON) &&
+        envelope->loop_end < envelope->n_nodes) {
+        if (pe->tick == envelope->node_t[envelope->loop_end]) {
+            pe->next_node = MID(0, envelope->loop_start, envelope->n_nodes - 1);
+            pe->tick = envelope->node_t[pe->next_node];
+        }
+    }
+
+    xm_envelope_calculate_value(envelope, pe);
+}
+
+static void update_xm_envelopes(IT_PLAYING *playing) {
+    update_xm_envelope(playing, &playing->env_instrument->volume_envelope,
+                       &playing->volume_envelope);
+    update_xm_envelope(playing, &playing->env_instrument->pan_envelope,
+                       &playing->pan_envelope);
+}
+
+static void update_fadeout(DUMB_IT_SIGDATA *sigdata, IT_PLAYING *playing) {
+    if (playing->flags & IT_PLAYING_FADING) {
+        playing->fadeoutcount -= playing->env_instrument->fadeout;
+        if (playing->fadeoutcount <= 0) {
+            playing->fadeoutcount = 0;
+            if (!(sigdata->flags & IT_WAS_AN_XM))
+                playing->flags |= IT_PLAYING_DEAD;
+        }
+    }
+}
+
+static int apply_pan_envelope(IT_PLAYING *playing);
+static float calculate_volume(DUMB_IT_SIGRENDERER *sigrenderer,
+                              IT_PLAYING *playing, float volume);
+
+static void playing_volume_setup(DUMB_IT_SIGRENDERER *sigrenderer,
+                                 IT_PLAYING *playing, float invt2g) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+    int pan;
+    float vol, span;
+    float rampScale;
+    int ramp_style = sigrenderer->ramp_style;
+
+    pan = apply_pan_envelope(playing);
+
+    if ((sigrenderer->n_channels >= 2) && (sigdata->flags & IT_STEREO) &&
+        (sigrenderer->n_channels != 3 || !IT_IS_SURROUND_SHIFTED(pan))) {
+        if (!IT_IS_SURROUND_SHIFTED(pan)) {
+            span = (pan - (32 << 8)) * sigdata->pan_separation *
+                   (1.0f / ((32 << 8) * 128));
+            vol = 0.5f * (1.0f - span);
+            playing->float_volume[0] = vol;
+            playing->float_volume[1] = 1.0f - vol;
+        } else {
+            playing->float_volume[0] = -0.5f;
+            playing->float_volume[1] = 0.5f;
+        }
+    } else {
+        playing->float_volume[0] = 1.0f;
+        playing->float_volume[1] = 1.0f;
+    }
+
+    vol = calculate_volume(sigrenderer, playing, 1.0f);
+    playing->float_volume[0] *= vol;
+    playing->float_volume[1] *= vol;
+
+    rampScale = 4;
+
+    if (ramp_style > 0 && playing->declick_stage == 2) {
+        if ((playing->ramp_volume[0] == 0 && playing->ramp_volume[1] == 0) ||
+            vol == 0)
+            rampScale = 48;
+    }
+
+    if (ramp_style == 0 || (ramp_style < 2 && playing->declick_stage == 2)) {
+        if (playing->declick_stage <= 2) {
+            playing->ramp_volume[0] = playing->float_volume[0];
+            playing->ramp_volume[1] = playing->float_volume[1];
+            playing->declick_stage = 2;
+        } else {
+            playing->float_volume[0] = 0;
+            playing->float_volume[1] = 0;
+            playing->ramp_volume[0] = 0;
+            playing->ramp_volume[1] = 0;
+            playing->declick_stage = 5;
+        }
+        playing->ramp_delta[0] = 0;
+        playing->ramp_delta[1] = 0;
+    } else {
+        if (playing->declick_stage == 0) {
+            playing->ramp_volume[0] = 0;
+            playing->ramp_volume[1] = 0;
+            rampScale = 48;
+            playing->declick_stage++;
+        } else if (playing->declick_stage == 1) {
+            rampScale = 48;
+        } else if (playing->declick_stage >= 3) {
+            playing->float_volume[0] = 0;
+            playing->float_volume[1] = 0;
+            if (playing->declick_stage == 3)
+                playing->declick_stage++;
+            rampScale = 48;
+        }
+        playing->ramp_delta[0] =
+            rampScale * invt2g *
+            (playing->float_volume[0] - playing->ramp_volume[0]);
+        playing->ramp_delta[1] =
+            rampScale * invt2g *
+            (playing->float_volume[1] - playing->ramp_volume[1]);
+    }
+}
+
+static void process_playing(DUMB_IT_SIGRENDERER *sigrenderer,
+                            IT_PLAYING *playing, float invt2g) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+
+    if (playing->instrument) {
+        if (sigdata->flags & IT_WAS_AN_XM)
+            update_xm_envelopes(playing);
+        else
+            update_it_envelopes(playing);
+        update_fadeout(sigdata, playing);
+    }
+
+    playing_volume_setup(sigrenderer, playing, invt2g);
+
+    if (sigdata->flags & IT_WAS_AN_XM) {
+        /* 'depth' is used to store the tick number for XM files. */
+        if (playing->sample_vibrato_depth < playing->sample->vibrato_rate)
+            playing->sample_vibrato_depth++;
+    } else {
+        playing->sample_vibrato_depth += playing->sample->vibrato_rate;
+        if (playing->sample_vibrato_depth > playing->sample->vibrato_depth << 8)
+            playing->sample_vibrato_depth = playing->sample->vibrato_depth << 8;
+    }
+
+    playing->sample_vibrato_time += playing->sample->vibrato_speed;
+}
+
+#if (defined(_MSC_VER) && _MSC_VER < 1800) || defined(__ANDROID__)
+static float log2(float x) { return (float)log(x) / (float)log(2.0f); }
+#endif
+
+static int delta_to_note(float delta, int base) {
+    float note;
+    note = log2(delta * 65536.f / (float)base) * 12.0f + 60.5f;
+    if (note > 119)
+        note = 119;
+    else if (note < 0)
+        note = 0;
+    return (int)note;
+}
+
+// Period table for Protracker octaves 0-5:
+#if 0
+static const unsigned short ProTrackerPeriodTable[6*12] =
+{
+	1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907,
+	856,808,762,720,678,640,604,570,538,508,480,453,
+	428,404,381,360,339,320,302,285,269,254,240,226,
+	214,202,190,180,170,160,151,143,135,127,120,113,
+	107,101,95,90,85,80,75,71,67,63,60,56,
+	53,50,47,45,42,40,37,35,33,31,30,28
+};
+
+
+static const unsigned short ProTrackerTunedPeriods[16*12] = 
+{
+	1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907,
+	1700,1604,1514,1430,1348,1274,1202,1134,1070,1010,954,900,
+	1688,1592,1504,1418,1340,1264,1194,1126,1064,1004,948,894,
+	1676,1582,1492,1408,1330,1256,1184,1118,1056,996,940,888,
+	1664,1570,1482,1398,1320,1246,1176,1110,1048,990,934,882,
+	1652,1558,1472,1388,1310,1238,1168,1102,1040,982,926,874,
+	1640,1548,1460,1378,1302,1228,1160,1094,1032,974,920,868,
+	1628,1536,1450,1368,1292,1220,1150,1086,1026,968,914,862,
+	1814,1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,
+	1800,1700,1604,1514,1430,1350,1272,1202,1134,1070,1010,954,
+	1788,1688,1592,1504,1418,1340,1264,1194,1126,1064,1004,948,
+	1774,1676,1582,1492,1408,1330,1256,1184,1118,1056,996,940,
+	1762,1664,1570,1482,1398,1320,1246,1176,1110,1048,988,934,
+	1750,1652,1558,1472,1388,1310,1238,1168,1102,1040,982,926,
+	1736,1640,1548,1460,1378,1302,1228,1160,1094,1032,974,920,
+	1724,1628,1536,1450,1368,1292,1220,1150,1086,1026,968,914 
+};
+#endif
+
+static void process_all_playing(DUMB_IT_SIGRENDERER *sigrenderer) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+    int i;
+
+    float invt2g =
+        1.0f / ((float)TICK_TIME_DIVIDEND / (float)sigrenderer->tempo / 256.0f);
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        IT_CHANNEL *channel = &sigrenderer->channel[i];
+        IT_PLAYING *playing = channel->playing;
+
+        if (playing) {
+            int vibrato_shift;
+            switch (playing->vibrato_waveform) {
+            default:
+                vibrato_shift = it_sine[playing->vibrato_time];
+                break;
+            case 1:
+                vibrato_shift = it_sawtooth[playing->vibrato_time];
+                break;
+            case 2:
+                vibrato_shift = it_squarewave[playing->vibrato_time];
+                break;
+            case 3:
+                vibrato_shift = (rand() % 129) - 64;
+                break;
+            case 4:
+                vibrato_shift = it_xm_squarewave[playing->vibrato_time];
+                break;
+            case 5:
+                vibrato_shift = it_xm_ramp[playing->vibrato_time];
+                break;
+            case 6:
+                vibrato_shift = it_xm_ramp[255 - playing->vibrato_time];
+                break;
+            }
+            vibrato_shift *= playing->vibrato_n;
+            vibrato_shift *= playing->vibrato_depth;
+            vibrato_shift >>= 4;
+
+            if (sigdata->flags & IT_OLD_EFFECTS)
+                vibrato_shift = -vibrato_shift;
+
+            playing->volume = channel->volume;
+            playing->pan = channel->truepan;
+
+            if (playing->volume_offset) {
+                playing->volume +=
+                    (playing->volume_offset * playing->volume) >> 7;
+                if (playing->volume > 64) {
+                    if (playing->volume_offset < 0)
+                        playing->volume = 0;
+                    else
+                        playing->volume = 64;
+                }
+            }
+
+            if (playing->panning_offset &&
+                !IT_IS_SURROUND_SHIFTED(playing->pan)) {
+                playing->pan += playing->panning_offset << IT_ENVELOPE_SHIFT;
+                if (playing->pan > 64 << IT_ENVELOPE_SHIFT) {
+                    if (playing->panning_offset < 0)
+                        playing->pan = 0;
+                    else
+                        playing->pan = 64 << IT_ENVELOPE_SHIFT;
+                }
+            }
+
+            if (sigdata->flags & IT_LINEAR_SLIDES) {
+                int currpitch = ((playing->note - 60) << 8) + playing->slide +
+                                vibrato_shift + playing->finetune;
+
+                /* We add a feature here, which is that of keeping the pitch
+                 * within range. Otherwise it crashes. Trust me. It happened.
+                 * The limit 32768 gives almost 11 octaves either way.
+                 */
+                if (currpitch < -32768)
+                    currpitch = -32768;
+                else if (currpitch > 32767)
+                    currpitch = 32767;
+
+                playing->delta = (float)pow(DUMB_PITCH_BASE, currpitch);
+                playing->delta *= playing->sample->C5_speed * (1.f / 65536.0f);
+            } else {
+                int slide = playing->slide + vibrato_shift;
+
+                playing->delta =
+                    (float)pow(DUMB_PITCH_BASE,
+                               ((60 - playing->note) << 8) - playing->finetune);
+                /* playing->delta is 1.0 for C-5, 0.5 for C-6, etc. */
+
+                playing->delta *= 1.0f / playing->sample->C5_speed;
+
+                playing->delta -= slide / AMIGA_DIVISOR;
+
+                if (playing->delta < (1.0f / 65536.0f) / 32768.0f) {
+                    // Should XM notes die if Amiga slides go out of range?
+                    playing->flags |= IT_PLAYING_DEAD;
+                    playing->delta = 1. / 32768.;
+                    continue;
+                }
+
+                playing->delta = (1.0f / 65536.0f) / playing->delta;
+            }
+
+            if (playing->channel->glissando && playing->channel->toneporta &&
+                playing->channel->destnote < 120) {
+                playing->delta =
+                    (float)pow(DUMB_SEMITONE_BASE,
+                               delta_to_note(playing->delta,
+                                             (int)playing->sample->C5_speed) -
+                                   60) *
+                    playing->sample->C5_speed * (1.f / 65536.f);
+            }
+
+            /*
+            if ( channel->arpeggio ) { // another FT2 bug...
+                    if ((sigdata->flags &
+            (IT_LINEAR_SLIDES|IT_WAS_AN_XM|IT_WAS_A_MOD)) ==
+            (IT_WAS_AN_XM|IT_LINEAR_SLIDES) && playing->flags &
+            IT_PLAYING_SUSTAINOFF)
+                    {
+                            if ( channel->arpeggio > 0xFF )
+                                    playing->delta = playing->sample->C5_speed *
+            (1.f / 65536.f);
+                    }
+                    else*/
+            {
+                int tick = sigrenderer->tick - 1;
+                if ((sigrenderer->sigdata->flags &
+                     (IT_WAS_AN_XM | IT_WAS_A_MOD)) != IT_WAS_AN_XM)
+                    tick = sigrenderer->speed - tick - 1;
+                else if (tick == sigrenderer->speed - 1)
+                    tick = 0;
+                else
+                    ++tick;
+                if (sigrenderer->sigdata->flags & IT_WAS_AN_STM)
+                    tick /= 16;
+                playing->delta *= (float)pow(
+                    DUMB_SEMITONE_BASE,
+                    channel
+                        ->arpeggio_offsets[channel->arpeggio_table[tick & 31]]);
+            }
+            /*
+            }*/
+
+            playing->filter_cutoff = channel->filter_cutoff;
+            playing->filter_resonance = channel->filter_resonance;
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        if (sigrenderer->channel[i].playing) {
+            process_playing(sigrenderer, sigrenderer->channel[i].playing,
+                            invt2g);
+            if (!(sigdata->flags & IT_WAS_AN_XM)) {
+                // if ((sigrenderer->channel[i].playing->flags &
+                // (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) ==
+                // (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) {
+                // This change was made so Gxx would work correctly when a note
+                // faded out or whatever. Let's hope nothing else was broken by
+                // it.
+                if (sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD) {
+                    free_playing(sigrenderer->channel[i].playing);
+                    sigrenderer->channel[i].playing = NULL;
+                }
+            }
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+        if (sigrenderer->playing[i]) {
+            process_playing(sigrenderer, sigrenderer->playing[i], invt2g);
+            if (sigrenderer->playing[i]->flags & IT_PLAYING_DEAD) {
+                free_playing(sigrenderer->playing[i]);
+                sigrenderer->playing[i] = NULL;
+            }
+        }
+    }
+}
+
+static int process_tick(DUMB_IT_SIGRENDERER *sigrenderer) {
+    DUMB_IT_SIGDATA *sigdata = sigrenderer->sigdata;
+
+    if (sigrenderer->tempo < 32 || sigrenderer->tempo > 255) // problematic
+        return 1;
+
+    // Set note vol/freq to vol/freq set for each channel
+
+    if (sigrenderer->speed && --sigrenderer->tick == 0) {
+        reset_tick_counts(sigrenderer);
+        sigrenderer->tick = sigrenderer->speed;
+        sigrenderer->rowcount--;
+        if (sigrenderer->rowcount == 0) {
+            sigrenderer->rowcount = 1;
+
+#ifdef BIT_ARRAY_BULLSHIT
+            if (sigrenderer->n_rows) {
+#if 1
+                /*
+                if (bit_array_test(sigrenderer->played, sigrenderer->order * 256
+            + sigrenderer->row))
+                {
+                        if (sigrenderer->callbacks->loop) {
+                                if
+            ((*sigrenderer->callbacks->loop)(sigrenderer->callbacks->loop_data))
+                                        return 1;
+                                bit_array_reset(sigrenderer->played);
+                                if (sigrenderer->speed == 0)
+            goto speed0; I love goto
+                        }
+                }
+                */
+#endif
+                bit_array_set(sigrenderer->played,
+                              sigrenderer->order * 256 + sigrenderer->row);
+                {
+                    int n;
+                    for (n = 0; n < DUMB_IT_N_CHANNELS; n++) {
+                        IT_CHANNEL *channel = &sigrenderer->channel[n];
+                        if (channel->played_patjump) {
+                            if (channel->played_patjump_order ==
+                                sigrenderer->order) {
+                                bit_array_set(channel->played_patjump,
+                                              sigrenderer->row);
+                            }
+                            /*
+                            else if ((channel->played_patjump_order & 0x7FFF) ==
+        sigrenderer->order)
+                            {
+                                    channel->played_patjump_order |= 0x4000;
+                            }
+                            else if ((channel->played_patjump_order & 0x3FFF) ==
+        sigrenderer->order)
+                            {
+                                    if ((sigdata->flags &
+        (IT_WAS_AN_XM|IT_WAS_A_MOD)) == IT_WAS_AN_XM)
+                                    {
+        joy, was XM, pattern loop bug triggered break to row in same order
+                                            bit_array_mask(sigrenderer->played,
+        channel->played_patjump, sigrenderer->order * 256);
+                                    }
+                                    bit_array_destroy(channel->played_patjump);
+                                    channel->played_patjump = 0;
+                                    channel->played_patjump_order = 0xFFFE;
+                            }
+                            */
+                            else {
+                                bit_array_destroy(channel->played_patjump);
+                                channel->played_patjump = 0;
+                                channel->played_patjump_order = 0xFFFE;
+                            }
+                        }
+                    }
+                }
+            }
+#endif
+
+            sigrenderer->processrow++;
+
+            if (sigrenderer->processrow >= sigrenderer->n_rows) {
+                IT_PATTERN *pattern;
+                int n;
+                int processorder = sigrenderer->processorder;
+
+                if ((sigrenderer->processrow | 0xC00) ==
+                    0xFFFE + 1) { /* It was incremented above! */
+                    sigrenderer->processrow = sigrenderer->breakrow;
+                    sigrenderer->breakrow = 0;
+                    for (n = 0; n < DUMB_IT_N_CHANNELS; n++)
+                        sigrenderer->channel[n].pat_loop_end_row = 0;
+                } else {
+                    sigrenderer->processrow = sigrenderer->breakrow;
+                    sigrenderer->breakrow = 0; // XXX lolwut
+                }
+
+                if (sigrenderer->processorder == 0xFFFF)
+                    sigrenderer->processorder = sigrenderer->order - 1;
+
+                for (;;) {
+                    sigrenderer->processorder++;
+
+                    if (sigrenderer->processorder >= sigdata->n_orders) {
+                        sigrenderer->processorder =
+                            sigrenderer->restart_position;
+                        if (sigrenderer->processorder >= sigdata->n_orders) {
+                            /* Restarting beyond end. We'll loop for now. */
+                            sigrenderer->processorder = -1;
+                            continue;
+                        }
+                        if (sigdata->flags & IT_WAS_AN_OKT) {
+                            /* Reset some things */
+                            sigrenderer->speed = sigdata->speed;
+                            sigrenderer->tempo = sigdata->tempo;
+                            for (n = 0; n < DUMB_IT_N_CHANNELS; n++) {
+                                xm_note_off(sigdata, &sigrenderer->channel[n]);
+                            }
+                        }
+                    }
+
+                    n = sigdata->order[sigrenderer->processorder];
+
+                    if (n < sigdata->n_patterns)
+                        break;
+
+#ifdef INVALID_ORDERS_END_SONG
+                    if (n != IT_ORDER_SKIP)
+#else
+                    if (n == IT_ORDER_END)
+#endif
+                    {
+                        sigrenderer->processorder =
+                            sigrenderer->restart_position - 1;
+                    }
+
+#ifdef BIT_ARRAY_BULLSHIT
+                    /* Fix play tracking and timekeeping for orders containing
+                     * skip commands */
+                    for (n = 0; n < 256; n++) {
+                        bit_array_set(sigrenderer->played,
+                                      sigrenderer->processorder * 256 + n);
+                        timekeeping_array_push(sigrenderer->row_timekeeper,
+                                               sigrenderer->processorder * 256 +
+                                                   n,
+                                               sigrenderer->time_played);
+                        timekeeping_array_bump(sigrenderer->row_timekeeper,
+                                               sigrenderer->processorder * 256 +
+                                                   n);
+                    }
+#endif
+                }
+
+                pattern = &sigdata->pattern[n];
+
+                n = sigrenderer->n_rows;
+                sigrenderer->n_rows = pattern->n_rows;
+
+                if (sigrenderer->processrow >= sigrenderer->n_rows)
+                    sigrenderer->processrow = 0;
+
+                /** WARNING - everything pertaining to a new pattern
+                 * initialised? */
+
+                if (pattern->entry) {
+                    sigrenderer->entry = sigrenderer->entry_start =
+                        pattern->entry;
+                    sigrenderer->entry_end =
+                        sigrenderer->entry + pattern->n_entries;
+                } else {
+                    sigrenderer->entry = sigrenderer->entry_start = 0;
+                    sigrenderer->entry_end = 0;
+                }
+
+                /* If n_rows was 0, we're only just starting. Don't do anything
+                 * weird here. */
+                /* added: process row check, for break to row spooniness */
+                if (n &&
+                    (processorder == 0xFFFF
+                         ? sigrenderer->order > sigrenderer->processorder
+                         : sigrenderer->order >= sigrenderer->processorder)
+#ifdef BIT_ARRAY_BULLSHIT
+                    && bit_array_test(sigrenderer->played,
+                                      sigrenderer->processorder * 256 +
+                                          sigrenderer->processrow)
+#endif
+                ) {
+#ifdef BIT_ARRAY_BULLSHIT
+                    sigrenderer->looped = 1;
+#endif
+                    if (sigrenderer->callbacks->loop) {
+                        if ((*sigrenderer->callbacks->loop)(
+                                sigrenderer->callbacks->loop_data))
+                            return 1;
+#ifdef BIT_ARRAY_BULLSHIT
+                        bit_array_reset(sigrenderer->played);
+#endif
+                        if (sigrenderer->speed == 0)
+                            goto speed0; /* I love goto */
+                    }
+                }
+                sigrenderer->order = sigrenderer->processorder;
+
+                n = sigrenderer->processrow;
+                while (n) {
+                    while (sigrenderer->entry < sigrenderer->entry_end) {
+                        if (IT_IS_END_ROW(sigrenderer->entry)) {
+                            sigrenderer->entry++;
+                            break;
+                        }
+                        sigrenderer->entry++;
+                    }
+                    n--;
+                }
+                sigrenderer->row = sigrenderer->processrow;
+            } else {
+                if (sigrenderer->entry) {
+                    while (sigrenderer->entry < sigrenderer->entry_end) {
+                        if (IT_IS_END_ROW(sigrenderer->entry)) {
+                            sigrenderer->entry++;
+                            break;
+                        }
+                        sigrenderer->entry++;
+                    }
+                    sigrenderer->row++;
+                } else {
+#ifdef BIT_ARRAY_BULLSHIT
+                    bit_array_clear(sigrenderer->played,
+                                    sigrenderer->order * 256);
+#endif
+                    sigrenderer->entry = sigrenderer->entry_start;
+                    sigrenderer->row = 0;
+                }
+            }
+
+#ifdef BIT_ARRAY_BULLSHIT
+            if (sigrenderer->looped == 0) {
+                timekeeping_array_push(sigrenderer->row_timekeeper,
+                                       sigrenderer->order * 256 +
+                                           sigrenderer->row,
+                                       sigrenderer->time_played);
+            }
+            timekeeping_array_bump(sigrenderer->row_timekeeper,
+                                   sigrenderer->order * 256 + sigrenderer->row);
+#endif
+
+            if (!(sigdata->flags & IT_WAS_A_669))
+                reset_effects(sigrenderer);
+
+            if (sigrenderer->entry) {
+                IT_ENTRY *entry = sigrenderer->entry;
+                int ignore_cxx = 0;
+
+                while (entry < sigrenderer->entry_end && !IT_IS_END_ROW(entry))
+                    ignore_cxx |=
+                        update_pattern_variables(sigrenderer, entry++);
+
+                entry = sigrenderer->entry;
+
+                while (entry < sigrenderer->entry_end && !IT_IS_END_ROW(entry))
+                    if (process_entry(
+                            sigrenderer, entry++,
+                            sigdata->flags & IT_WAS_AN_XM ? 0 : ignore_cxx))
+                        return 1;
+            }
+
+            if (sigdata->flags & IT_WAS_AN_OKT)
+                update_effects(sigrenderer);
+            else if (!(sigdata->flags & IT_OLD_EFFECTS))
+                update_smooth_effects(sigrenderer);
+        } else {
+            if (sigrenderer->entry) {
+                IT_ENTRY *entry = sigrenderer->entry;
+
+                while (entry < sigrenderer->entry_end &&
+                       !IT_IS_END_ROW(entry)) {
+                    if (entry->mask & IT_ENTRY_EFFECT &&
+                        entry->effect != IT_SET_SAMPLE_OFFSET)
+                        process_effects(sigrenderer, entry, 0);
+                    /* Don't bother checking the return value; if there
+                     * was a pattern delay, there can't be a speed=0.
+                     */
+                    entry++;
+                }
+            }
+
+            update_effects(sigrenderer);
+        }
+    } else {
+        if (!(sigdata->flags & IT_WAS_AN_STM) || !(sigrenderer->tick & 15)) {
+        speed0:
+            update_effects(sigrenderer);
+            update_tick_counts(sigrenderer);
+        }
+    }
+
+    if (sigrenderer->globalvolume == 0) {
+        if (sigrenderer->callbacks->global_volume_zero) {
+            LONG_LONG t =
+                sigrenderer->gvz_sub_time +
+                ((TICK_TIME_DIVIDEND / (sigrenderer->tempo << 8)) << 16);
+            sigrenderer->gvz_time += (int)(t >> 16);
+            sigrenderer->gvz_sub_time = (int)t & 65535;
+            if (sigrenderer->gvz_time >= 65536 * 12) {
+#ifdef BIT_ARRAY_BULLSHIT
+                sigrenderer->looped = 1;
+#endif
+                if ((*sigrenderer->callbacks->global_volume_zero)(
+                        sigrenderer->callbacks->global_volume_zero_data))
+                    return 1;
+            }
+        }
+    } else {
+        if (sigrenderer->callbacks->global_volume_zero) {
+            sigrenderer->gvz_time = 0;
+            sigrenderer->gvz_sub_time = 0;
+        }
+    }
+
+    process_all_playing(sigrenderer);
+
+    {
+        LONG_LONG t = (TICK_TIME_DIVIDEND / (sigrenderer->tempo << 8)) << 16;
+        if (sigrenderer->sigdata->flags & IT_WAS_AN_STM) {
+            t /= 16;
+        }
+        t += sigrenderer->sub_time_left;
+        sigrenderer->time_left += (int)(t >> 16);
+        sigrenderer->sub_time_left = (int)t & 65535;
+    }
+
+    return 0;
+}
+
+int dumb_it_max_to_mix = 64;
+
+#if 0
+static const int aiMODVol[] =
+{
+	0,
+		16, 24, 32, 48, 64, 80, 96, 112,
+		128, 144, 160, 176, 192, 208, 224, 240,
+		256, 272, 288, 304, 320, 336, 352, 368,
+		384, 400, 416, 432, 448, 464, 480, 496,
+		529, 545, 561, 577, 593, 609, 625, 641,
+		657, 673, 689, 705, 721, 737, 753, 769,
+		785, 801, 817, 833, 849, 865, 881, 897,
+		913, 929, 945, 961, 977, 993, 1009, 1024
+};
+#endif
+
+static const int aiPTMVolScaled[] = {
+    0,   31,  54,  73,  96,  111, 130, 153, 172, 191, 206, 222,  237,
+    252, 275, 298, 317, 336, 351, 370, 386, 401, 416, 428, 443,  454,
+    466, 477, 489, 512, 531, 553, 573, 592, 611, 626, 645, 660,  679,
+    695, 710, 725, 740, 756, 767, 782, 798, 809, 820, 836, 847,  859,
+    870, 881, 897, 908, 916, 927, 939, 950, 962, 969, 983, 1005, 1024};
+
+static float calculate_volume(DUMB_IT_SIGRENDERER *sigrenderer,
+                              IT_PLAYING *playing, float volume) {
+    if (volume != 0) {
+        int vol;
+
+        if (playing->channel->flags & IT_CHANNEL_MUTED)
+            return 0;
+
+        if ((playing->channel->tremor_time & 192) == 128)
+            return 0;
+
+        switch (playing->tremolo_waveform) {
+        default:
+            vol = it_sine[playing->tremolo_time];
+            break;
+        case 1:
+            vol = it_sawtooth[playing->tremolo_time];
+            break;
+        case 2:
+            vol = it_squarewave[playing->tremolo_time];
+            break;
+        case 3:
+            vol = (rand() % 129) - 64;
+            break;
+        case 4:
+            vol = it_xm_squarewave[playing->tremolo_time];
+            break;
+        case 5:
+            vol = it_xm_ramp[playing->tremolo_time];
+            break;
+        case 6:
+            vol = it_xm_ramp[255 - ((sigrenderer->sigdata->flags & IT_WAS_A_MOD)
+                                        ? playing->vibrato_time
+                                        : playing->tremolo_time)];
+            break;
+        }
+        vol *= playing->tremolo_depth;
+
+        vol = (playing->volume << 5) + vol;
+
+        if (vol <= 0)
+            return 0;
+
+        if (vol > 64 << 5)
+            vol = 64 << 5;
+
+        if (sigrenderer->sigdata->flags & IT_WAS_A_PTM) {
+            int v = aiPTMVolScaled[vol >> 5];
+            if (vol < 64 << 5) {
+                int f = vol & ((1 << 5) - 1);
+                int f2 = (1 << 5) - f;
+                int v2 = aiPTMVolScaled[(vol >> 5) + 1];
+                v = (v * f2 + v2 * f) >> 5;
+            }
+            vol = v << 1;
+        }
+
+        volume *= vol;                                 /* 64 << 5 */
+        volume *= playing->sample->global_volume;      /* 64 */
+        volume *= playing->channel_volume;             /* 64 */
+        volume *= sigrenderer->globalvolume;           /* 128 */
+        volume *= sigrenderer->sigdata->mixing_volume; /* 128 */
+        volume *= 1.0f / ((64 << 5) * 64.0f * 64.0f * 128.0f * 128.0f);
+
+        if (volume && playing->instrument) {
+            if (playing->enabled_envelopes & IT_ENV_VOLUME &&
+                playing->env_instrument->volume_envelope.n_nodes) {
+                volume *=
+                    envelope_get_y(&playing->env_instrument->volume_envelope,
+                                   &playing->volume_envelope);
+                volume *= 1.0f / (64 << IT_ENVELOPE_SHIFT);
+            }
+            volume *= playing->instrument->global_volume; /* 128 */
+            volume *= playing->fadeoutcount;              /* 1024 */
+            volume *= 1.0f / (128.0f * 1024.0f);
+        }
+    }
+
+    return volume;
+}
+
+static int apply_pan_envelope(IT_PLAYING *playing) {
+    if (playing->pan <= 64 << IT_ENVELOPE_SHIFT) {
+        int pan;
+        if (playing->panbrello_depth) {
+            switch (playing->panbrello_waveform) {
+            default:
+                pan = it_sine[playing->panbrello_time];
+                break;
+            case 1:
+                pan = it_sawtooth[playing->panbrello_time];
+                break;
+            case 2:
+                pan = it_squarewave[playing->panbrello_time];
+                break;
+            case 3:
+                pan = playing->panbrello_random;
+                break;
+            }
+            pan *= playing->panbrello_depth << 3;
+
+            pan += playing->pan;
+            if (pan < 0)
+                pan = 0;
+            else if (pan > 64 << IT_ENVELOPE_SHIFT)
+                pan = 64 << IT_ENVELOPE_SHIFT;
+        } else {
+            pan = playing->pan;
+        }
+
+        if (playing->env_instrument &&
+            (playing->enabled_envelopes & IT_ENV_PANNING)) {
+            int p = envelope_get_y(&playing->env_instrument->pan_envelope,
+                                   &playing->pan_envelope);
+            if (pan > 32 << IT_ENVELOPE_SHIFT)
+                p *= (64 << IT_ENVELOPE_SHIFT) - pan;
+            else
+                p *= pan;
+            pan += p >> (5 + IT_ENVELOPE_SHIFT);
+        }
+        return pan;
+    }
+    return playing->pan;
+}
+
+/* Note: if a click remover is provided, and store_end_sample is set, then
+ * the end point will be computed twice. This situation should not arise.
+ */
+static long render_playing(DUMB_IT_SIGRENDERER *sigrenderer,
+                           IT_PLAYING *playing, float volume, float main_delta,
+                           float delta, long pos, long size, sample_t **samples,
+                           int store_end_sample, int *left_to_mix) {
+    int bits;
+
+    long size_rendered;
+
+    DUMB_VOLUME_RAMP_INFO lvol, rvol;
+
+    if (playing->flags & IT_PLAYING_DEAD)
+        return 0;
+
+    if (*left_to_mix <= 0)
+        volume = 0;
+
+    {
+        int quality = sigrenderer->resampling_quality;
+        if (playing->sample->max_resampling_quality >= 0 &&
+            quality > playing->sample->max_resampling_quality)
+            quality = playing->sample->max_resampling_quality;
+        playing->resampler.quality = quality;
+        resampler_set_quality(playing->resampler.fir_resampler[0], quality);
+        resampler_set_quality(playing->resampler.fir_resampler[1], quality);
+    }
+
+    bits = playing->sample->flags & IT_SAMPLE_16BIT ? 16 : 8;
+
+    if (volume == 0) {
+        if (playing->sample->flags & IT_SAMPLE_STEREO)
+            size_rendered = dumb_resample_n_2_1(bits, &playing->resampler, NULL,
+                                                size, 0, 0, delta);
+        else
+            size_rendered = dumb_resample_n_1_1(bits, &playing->resampler, NULL,
+                                                size, 0, delta);
+    } else {
+        lvol.volume = playing->ramp_volume[0];
+        rvol.volume = playing->ramp_volume[1];
+        lvol.delta = playing->ramp_delta[0] * main_delta;
+        rvol.delta = playing->ramp_delta[1] * main_delta;
+        lvol.target = playing->float_volume[0];
+        rvol.target = playing->float_volume[1];
+        rvol.mix = lvol.mix = volume;
+        lvol.declick_stage = rvol.declick_stage = playing->declick_stage;
+        if (sigrenderer->n_channels >= 2) {
+            if (playing->sample->flags & IT_SAMPLE_STEREO) {
+                if (sigrenderer->click_remover) {
+                    sample_t click[2];
+                    dumb_resample_get_current_sample_n_2_2(
+                        bits, &playing->resampler, &lvol, &rvol, click);
+                    dumb_record_click(sigrenderer->click_remover[0], pos,
+                                      click[0]);
+                    dumb_record_click(sigrenderer->click_remover[1], pos,
+                                      click[1]);
+                }
+                size_rendered = dumb_resample_n_2_2(bits, &playing->resampler,
+                                                    samples[0] + pos * 2, size,
+                                                    &lvol, &rvol, delta);
+                if (store_end_sample) {
+                    sample_t click[2];
+                    dumb_resample_get_current_sample_n_2_2(
+                        bits, &playing->resampler, &lvol, &rvol, click);
+                    samples[0][(pos + size_rendered) * 2] = click[0];
+                    samples[0][(pos + size_rendered) * 2 + 1] = click[1];
+                }
+                if (sigrenderer->click_remover) {
+                    sample_t click[2];
+                    dumb_resample_get_current_sample_n_2_2(
+                        bits, &playing->resampler, &lvol, &rvol, click);
+                    dumb_record_click(sigrenderer->click_remover[0],
+                                      pos + size_rendered, -click[0]);
+                    dumb_record_click(sigrenderer->click_remover[1],
+                                      pos + size_rendered, -click[1]);
+                }
+            } else {
+                if (sigrenderer->click_remover) {
+                    sample_t click[2];
+                    dumb_resample_get_current_sample_n_1_2(
+                        bits, &playing->resampler, &lvol, &rvol, click);
+                    dumb_record_click(sigrenderer->click_remover[0], pos,
+                                      click[0]);
+                    dumb_record_click(sigrenderer->click_remover[1], pos,
+                                      click[1]);
+                }
+                size_rendered = dumb_resample_n_1_2(bits, &playing->resampler,
+                                                    samples[0] + pos * 2, size,
+                                                    &lvol, &rvol, delta);
+                if (store_end_sample) {
+                    sample_t click[2];
+                    dumb_resample_get_current_sample_n_1_2(
+                        bits, &playing->resampler, &lvol, &rvol, click);
+                    samples[0][(pos + size_rendered) * 2] = click[0];
+                    samples[0][(pos + size_rendered) * 2 + 1] = click[1];
+                }
+                if (sigrenderer->click_remover) {
+                    sample_t click[2];
+                    dumb_resample_get_current_sample_n_1_2(
+                        bits, &playing->resampler, &lvol, &rvol, click);
+                    dumb_record_click(sigrenderer->click_remover[0],
+                                      pos + size_rendered, -click[0]);
+                    dumb_record_click(sigrenderer->click_remover[1],
+                                      pos + size_rendered, -click[1]);
+                }
+            }
+        } else {
+            if (playing->sample->flags & IT_SAMPLE_STEREO) {
+                if (sigrenderer->click_remover) {
+                    sample_t click;
+                    dumb_resample_get_current_sample_n_2_1(
+                        bits, &playing->resampler, &lvol, &rvol, &click);
+                    dumb_record_click(sigrenderer->click_remover[0], pos,
+                                      click);
+                }
+                size_rendered = dumb_resample_n_2_1(bits, &playing->resampler,
+                                                    samples[0] + pos, size,
+                                                    &lvol, &rvol, delta);
+                if (store_end_sample)
+                    dumb_resample_get_current_sample_n_2_1(
+                        bits, &playing->resampler, &lvol, &rvol,
+                        &samples[0][pos + size_rendered]);
+                if (sigrenderer->click_remover) {
+                    sample_t click;
+                    dumb_resample_get_current_sample_n_2_1(
+                        bits, &playing->resampler, &lvol, &rvol, &click);
+                    dumb_record_click(sigrenderer->click_remover[0],
+                                      pos + size_rendered, -click);
+                }
+            } else {
+                if (sigrenderer->click_remover) {
+                    sample_t click;
+                    dumb_resample_get_current_sample_n_1_1(
+                        bits, &playing->resampler, &lvol, &click);
+                    dumb_record_click(sigrenderer->click_remover[0], pos,
+                                      click);
+                }
+                size_rendered =
+                    dumb_resample_n_1_1(bits, &playing->resampler,
+                                        samples[0] + pos, size, &lvol, delta);
+                if (store_end_sample)
+                    dumb_resample_get_current_sample_n_1_1(
+                        bits, &playing->resampler, &lvol,
+                        &samples[0][pos + size_rendered]);
+                if (sigrenderer->click_remover) {
+                    sample_t click;
+                    dumb_resample_get_current_sample_n_1_1(
+                        bits, &playing->resampler, &lvol, &click);
+                    dumb_record_click(sigrenderer->click_remover[0],
+                                      pos + size_rendered, -click);
+                }
+            }
+        }
+        playing->ramp_volume[0] = lvol.volume;
+        playing->ramp_volume[1] = rvol.volume;
+        playing->declick_stage = (lvol.declick_stage > rvol.declick_stage)
+                                     ? lvol.declick_stage
+                                     : rvol.declick_stage;
+        if (playing->declick_stage >= 4)
+            playing->flags |= IT_PLAYING_DEAD;
+        (*left_to_mix)--;
+    }
+
+    if (playing->resampler.dir == 0)
+        playing->flags |= IT_PLAYING_DEAD;
+
+    return size_rendered;
+}
+
+typedef struct IT_TO_MIX {
+    IT_PLAYING *playing;
+    float volume;
+} IT_TO_MIX;
+
+static int it_to_mix_compare(const void *e1, const void *e2) {
+    if (((const IT_TO_MIX *)e1)->volume > ((const IT_TO_MIX *)e2)->volume)
+        return -1;
+
+    if (((const IT_TO_MIX *)e1)->volume < ((const IT_TO_MIX *)e2)->volume)
+        return 1;
+
+    return 0;
+}
+
+static void apply_pitch_modifications(DUMB_IT_SIGDATA *sigdata,
+                                      IT_PLAYING *playing, float *delta,
+                                      int *cutoff) {
+    {
+        int sample_vibrato_shift;
+        switch (playing->sample_vibrato_waveform) {
+        default:
+            sample_vibrato_shift = it_sine[playing->sample_vibrato_time];
+            break;
+        case 1:
+            sample_vibrato_shift = it_sawtooth[playing->sample_vibrato_time];
+            break;
+        case 2:
+            sample_vibrato_shift = it_squarewave[playing->sample_vibrato_time];
+            break;
+        case 3:
+            sample_vibrato_shift = (rand() % 129) - 64;
+            break;
+        case 4:
+            sample_vibrato_shift =
+                it_xm_squarewave[playing->sample_vibrato_time];
+            break;
+        case 5:
+            sample_vibrato_shift = it_xm_ramp[playing->sample_vibrato_time];
+            break;
+        case 6:
+            sample_vibrato_shift =
+                it_xm_ramp[255 - playing->sample_vibrato_time];
+            break;
+        }
+
+        if (sigdata->flags & IT_WAS_AN_XM) {
+            int depth = playing->sample->vibrato_depth; /* True depth */
+            if (playing->sample->vibrato_rate) {
+                depth *= playing->sample_vibrato_depth; /* Tick number */
+                depth /= playing->sample->vibrato_rate; /* XM sweep */
+            }
+            sample_vibrato_shift *= depth;
+        } else
+            sample_vibrato_shift *= playing->sample_vibrato_depth >> 8;
+
+        sample_vibrato_shift >>= 4;
+
+        if (sample_vibrato_shift) {
+            if ((sigdata->flags & IT_LINEAR_SLIDES) ||
+                !(sigdata->flags & IT_WAS_AN_XM))
+                *delta *= (float)pow(DUMB_PITCH_BASE, sample_vibrato_shift);
+            else {
+                /* complicated! */
+                float scale = *delta / playing->delta;
+
+                *delta = (1.0f / 65536.0f) / playing->delta;
+
+                *delta -= sample_vibrato_shift / AMIGA_DIVISOR;
+
+                if (*delta < (1.0f / 65536.0f) / 32767.0f) {
+                    *delta = (1.0f / 65536.0f) / 32767.0f;
+                }
+
+                *delta = (1.0f / 65536.0f) / *delta * scale;
+            }
+        }
+    }
+
+    if (playing->env_instrument &&
+        (playing->enabled_envelopes & IT_ENV_PITCH)) {
+        int p = envelope_get_y(&playing->env_instrument->pitch_envelope,
+                               &playing->pitch_envelope);
+        if (playing->env_instrument->pitch_envelope.flags &
+            IT_ENVELOPE_PITCH_IS_FILTER)
+            *cutoff = (*cutoff * (p + (32 << IT_ENVELOPE_SHIFT))) >>
+                      (6 + IT_ENVELOPE_SHIFT);
+        else
+            *delta *= (float)pow(DUMB_PITCH_BASE, p >> (IT_ENVELOPE_SHIFT - 7));
+    }
+}
+
+static void render_normal(DUMB_IT_SIGRENDERER *sigrenderer, float volume,
+                          float delta, long pos, long size,
+                          sample_t **samples) {
+    int i;
+
+    int n_to_mix = 0;
+    IT_TO_MIX to_mix[DUMB_IT_TOTAL_CHANNELS];
+    int left_to_mix = dumb_it_max_to_mix;
+
+    sample_t **samples_to_filter = NULL;
+
+    // int max_output = sigrenderer->max_output;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        if (sigrenderer->channel[i].playing &&
+            !(sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD)) {
+            to_mix[n_to_mix].playing = sigrenderer->channel[i].playing;
+            to_mix[n_to_mix].volume =
+                volume == 0
+                    ? 0
+                    : calculate_volume(sigrenderer,
+                                       sigrenderer->channel[i].playing, volume);
+            n_to_mix++;
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+        if (sigrenderer
+                ->playing[i]) { /* Won't be dead; it would have been freed. */
+            to_mix[n_to_mix].playing = sigrenderer->playing[i];
+            to_mix[n_to_mix].volume =
+                volume == 0 ? 0
+                            : calculate_volume(sigrenderer,
+                                               sigrenderer->playing[i], volume);
+            n_to_mix++;
+        }
+    }
+
+    if (volume != 0)
+        qsort(to_mix, n_to_mix, sizeof(IT_TO_MIX), &it_to_mix_compare);
+
+    for (i = 0; i < n_to_mix; i++) {
+        IT_PLAYING *playing = to_mix[i].playing;
+        float note_delta = delta * playing->delta;
+        int cutoff = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
+        // int output = min( playing->output, max_output );
+
+        apply_pitch_modifications(sigrenderer->sigdata, playing, &note_delta,
+                                  &cutoff);
+
+        if (cutoff != 127 << IT_ENVELOPE_SHIFT ||
+            playing->filter_resonance != 0) {
+            playing->true_filter_cutoff = cutoff;
+            playing->true_filter_resonance = playing->filter_resonance;
+        }
+
+        if (volume &&
+            (playing->true_filter_cutoff != 127 << IT_ENVELOPE_SHIFT ||
+             playing->true_filter_resonance != 0)) {
+            if (!samples_to_filter) {
+                samples_to_filter =
+                    allocate_sample_buffer(sigrenderer->n_channels, size + 1);
+                if (!samples_to_filter) {
+                    render_playing(sigrenderer, playing, 0, delta, note_delta,
+                                   pos, size, NULL, 0, &left_to_mix);
+                    continue;
+                }
+            }
+            {
+                long size_rendered;
+                DUMB_CLICK_REMOVER **cr = sigrenderer->click_remover;
+                dumb_silence(samples_to_filter[0],
+                             sigrenderer->n_channels * (size + 1));
+                sigrenderer->click_remover = NULL;
+                size_rendered = render_playing(
+                    sigrenderer, playing, volume, delta, note_delta, 0, size,
+                    samples_to_filter, 1, &left_to_mix);
+                sigrenderer->click_remover = cr;
+                if (sigrenderer->n_channels == 2) {
+                    it_filter(cr ? cr[0] : NULL, &playing->filter_state[0],
+                              samples[0 /*output*/], pos, samples_to_filter[0],
+                              size_rendered, 2, (int)(65536.0f / delta),
+                              playing->true_filter_cutoff,
+                              playing->true_filter_resonance);
+                    it_filter(cr ? cr[1] : NULL, &playing->filter_state[1],
+                              samples[0 /*output*/] + 1, pos,
+                              samples_to_filter[0] + 1, size_rendered, 2,
+                              (int)(65536.0f / delta),
+                              playing->true_filter_cutoff,
+                              playing->true_filter_resonance);
+                } else {
+                    it_filter(cr ? cr[0] : NULL, &playing->filter_state[0],
+                              samples[0 /*output*/], pos, samples_to_filter[0],
+                              size_rendered, 1, (int)(65536.0f / delta),
+                              playing->true_filter_cutoff,
+                              playing->true_filter_resonance);
+                }
+                // FIXME: filtering is not prevented by low left_to_mix!
+                // FIXME: change 'warning' to 'FIXME' everywhere
+            }
+        } else {
+            it_reset_filter_state(&playing->filter_state[0]);
+            it_reset_filter_state(&playing->filter_state[1]);
+            render_playing(sigrenderer, playing, volume, delta, note_delta, pos,
+                           size, samples /*&samples[output]*/, 0, &left_to_mix);
+        }
+    }
+
+    destroy_sample_buffer(samples_to_filter);
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        if (sigrenderer->channel[i].playing) {
+            // if ((sigrenderer->channel[i].playing->flags &
+            // (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) ==
+            // (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) {
+            // This change was made so Gxx would work correctly when a note
+            // faded out or whatever. Let's hope nothing else was broken by it.
+            if (sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD) {
+                free_playing(sigrenderer->channel[i].playing);
+                sigrenderer->channel[i].playing = NULL;
+            }
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+        if (sigrenderer->playing[i]) {
+            if (sigrenderer->playing[i]->flags & IT_PLAYING_DEAD) {
+                free_playing(sigrenderer->playing[i]);
+                sigrenderer->playing[i] = NULL;
+            }
+        }
+    }
+}
+
+static void render_surround(DUMB_IT_SIGRENDERER *sigrenderer, float volume,
+                            float delta, long pos, long size,
+                            sample_t **samples) {
+    int i;
+
+    int n_to_mix = 0, n_to_mix_surround = 0;
+    IT_TO_MIX to_mix[DUMB_IT_TOTAL_CHANNELS];
+    IT_TO_MIX to_mix_surround[DUMB_IT_TOTAL_CHANNELS];
+    int left_to_mix = dumb_it_max_to_mix;
+
+    int saved_channels = sigrenderer->n_channels;
+
+    sample_t **samples_to_filter = NULL;
+
+    DUMB_CLICK_REMOVER **saved_cr = sigrenderer->click_remover;
+
+    // int max_output = sigrenderer->max_output;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        if (sigrenderer->channel[i].playing &&
+            !(sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD)) {
+            IT_PLAYING *playing = sigrenderer->channel[i].playing;
+            IT_TO_MIX *_to_mix = IT_IS_SURROUND_SHIFTED(playing->pan)
+                                     ? to_mix_surround + n_to_mix_surround++
+                                     : to_mix + n_to_mix++;
+            _to_mix->playing = playing;
+            _to_mix->volume =
+                volume == 0 ? 0
+                            : calculate_volume(sigrenderer, playing, volume);
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+        if (sigrenderer
+                ->playing[i]) { /* Won't be dead; it would have been freed. */
+            IT_PLAYING *playing = sigrenderer->playing[i];
+            IT_TO_MIX *_to_mix = IT_IS_SURROUND_SHIFTED(playing->pan)
+                                     ? to_mix_surround + n_to_mix_surround++
+                                     : to_mix + n_to_mix++;
+            _to_mix->playing = playing;
+            _to_mix->volume =
+                volume == 0 ? 0
+                            : calculate_volume(sigrenderer, playing, volume);
+        }
+    }
+
+    if (volume != 0) {
+        qsort(to_mix, n_to_mix, sizeof(IT_TO_MIX), &it_to_mix_compare);
+        qsort(to_mix_surround, n_to_mix_surround, sizeof(IT_TO_MIX),
+              &it_to_mix_compare);
+    }
+
+    sigrenderer->n_channels = 2;
+
+    for (i = 0; i < n_to_mix; i++) {
+        IT_PLAYING *playing = to_mix[i].playing;
+        float note_delta = delta * playing->delta;
+        int cutoff = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
+        // int output = min( playing->output, max_output );
+
+        apply_pitch_modifications(sigrenderer->sigdata, playing, &note_delta,
+                                  &cutoff);
+
+        if (cutoff != 127 << IT_ENVELOPE_SHIFT ||
+            playing->filter_resonance != 0) {
+            playing->true_filter_cutoff = cutoff;
+            playing->true_filter_resonance = playing->filter_resonance;
+        }
+
+        if (volume &&
+            (playing->true_filter_cutoff != 127 << IT_ENVELOPE_SHIFT ||
+             playing->true_filter_resonance != 0)) {
+            if (!samples_to_filter) {
+                samples_to_filter =
+                    allocate_sample_buffer(sigrenderer->n_channels, size + 1);
+                if (!samples_to_filter) {
+                    render_playing(sigrenderer, playing, 0, delta, note_delta,
+                                   pos, size, NULL, 0, &left_to_mix);
+                    continue;
+                }
+            }
+            {
+                long size_rendered;
+                DUMB_CLICK_REMOVER **cr = sigrenderer->click_remover;
+                dumb_silence(samples_to_filter[0],
+                             sigrenderer->n_channels * (size + 1));
+                sigrenderer->click_remover = NULL;
+                size_rendered = render_playing(
+                    sigrenderer, playing, volume, delta, note_delta, 0, size,
+                    samples_to_filter, 1, &left_to_mix);
+                sigrenderer->click_remover = cr;
+                it_filter(cr ? cr[0] : NULL, &playing->filter_state[0],
+                          samples[0 /*output*/], pos, samples_to_filter[0],
+                          size_rendered, 2, (int)(65536.0f / delta),
+                          playing->true_filter_cutoff,
+                          playing->true_filter_resonance);
+                it_filter(cr ? cr[1] : NULL, &playing->filter_state[1],
+                          samples[0 /*output*/] + 1, pos,
+                          samples_to_filter[0] + 1, size_rendered, 2,
+                          (int)(65536.0f / delta), playing->true_filter_cutoff,
+                          playing->true_filter_resonance);
+            }
+        } else {
+            it_reset_filter_state(&playing->filter_state[0]);
+            it_reset_filter_state(&playing->filter_state[1]);
+            render_playing(sigrenderer, playing, volume, delta, note_delta, pos,
+                           size, samples /*&samples[output]*/, 0, &left_to_mix);
+        }
+    }
+
+    sigrenderer->n_channels = 1;
+    sigrenderer->click_remover = saved_cr ? saved_cr + 2 : 0;
+
+    for (i = 0; i < n_to_mix_surround; i++) {
+        IT_PLAYING *playing = to_mix_surround[i].playing;
+        float note_delta = delta * playing->delta;
+        int cutoff = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
+        // int output = min( playing->output, max_output );
+
+        apply_pitch_modifications(sigrenderer->sigdata, playing, &note_delta,
+                                  &cutoff);
+
+        if (cutoff != 127 << IT_ENVELOPE_SHIFT ||
+            playing->filter_resonance != 0) {
+            playing->true_filter_cutoff = cutoff;
+            playing->true_filter_resonance = playing->filter_resonance;
+        }
+
+        if (volume &&
+            (playing->true_filter_cutoff != 127 << IT_ENVELOPE_SHIFT ||
+             playing->true_filter_resonance != 0)) {
+            if (!samples_to_filter) {
+                samples_to_filter =
+                    allocate_sample_buffer(sigrenderer->n_channels, size + 1);
+                if (!samples_to_filter) {
+                    render_playing(sigrenderer, playing, 0, delta, note_delta,
+                                   pos, size, NULL, 0, &left_to_mix);
+                    continue;
+                }
+            }
+            {
+                long size_rendered;
+                DUMB_CLICK_REMOVER **cr = sigrenderer->click_remover;
+                dumb_silence(samples_to_filter[0], size + 1);
+                sigrenderer->click_remover = NULL;
+                size_rendered = render_playing(
+                    sigrenderer, playing, volume, delta, note_delta, 0, size,
+                    samples_to_filter, 1, &left_to_mix);
+                sigrenderer->click_remover = cr;
+                it_filter(cr ? cr[0] : NULL, &playing->filter_state[0],
+                          samples[1 /*output*/], pos, samples_to_filter[0],
+                          size_rendered, 1, (int)(65536.0f / delta),
+                          playing->true_filter_cutoff,
+                          playing->true_filter_resonance);
+                // FIXME: filtering is not prevented by low left_to_mix!
+                // FIXME: change 'warning' to 'FIXME' everywhere
+            }
+        } else {
+            it_reset_filter_state(&playing->filter_state[0]);
+            it_reset_filter_state(&playing->filter_state[1]);
+            render_playing(sigrenderer, playing, volume, delta, note_delta, pos,
+                           size, &samples[1], 0, &left_to_mix);
+        }
+    }
+
+    sigrenderer->n_channels = saved_channels;
+    sigrenderer->click_remover = saved_cr;
+
+    destroy_sample_buffer(samples_to_filter);
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        if (sigrenderer->channel[i].playing) {
+            // if ((sigrenderer->channel[i].playing->flags &
+            // (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) ==
+            // (IT_PLAYING_BACKGROUND | IT_PLAYING_DEAD)) {
+            // This change was made so Gxx would work correctly when a note
+            // faded out or whatever. Let's hope nothing else was broken by it.
+            if (sigrenderer->channel[i].playing->flags & IT_PLAYING_DEAD) {
+                free_playing(sigrenderer->channel[i].playing);
+                sigrenderer->channel[i].playing = NULL;
+            }
+        }
+    }
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+        if (sigrenderer->playing[i]) {
+            if (sigrenderer->playing[i]->flags & IT_PLAYING_DEAD) {
+                free_playing(sigrenderer->playing[i]);
+                sigrenderer->playing[i] = NULL;
+            }
+        }
+    }
+}
+
+static void render(DUMB_IT_SIGRENDERER *sigrenderer, float volume, float delta,
+                   long pos, long size, sample_t **samples) {
+    if (size == 0)
+        return;
+    if (sigrenderer->n_channels == 1 || sigrenderer->n_channels == 2)
+        render_normal(sigrenderer, volume, delta, pos, size, samples);
+    else if (sigrenderer->n_channels == 3)
+        render_surround(sigrenderer, volume, delta, pos, size, samples);
+}
+
+static DUMB_IT_SIGRENDERER *init_sigrenderer(DUMB_IT_SIGDATA *sigdata,
+                                             int n_channels, int startorder,
+                                             IT_CALLBACKS *callbacks,
+                                             DUMB_CLICK_REMOVER **cr) {
+    DUMB_IT_SIGRENDERER *sigrenderer;
+    int i;
+
+    if (startorder > sigdata->n_orders) {
+        free(callbacks);
+        dumb_destroy_click_remover_array(n_channels, cr);
+        return NULL;
+    }
+
+    sigrenderer = malloc(sizeof(*sigrenderer));
+    if (!sigrenderer) {
+        free(callbacks);
+        dumb_destroy_click_remover_array(n_channels, cr);
+        return NULL;
+    }
+
+    sigrenderer->callbacks = callbacks;
+    sigrenderer->click_remover = cr;
+
+    sigrenderer->sigdata = sigdata;
+    sigrenderer->n_channels = n_channels;
+    sigrenderer->resampling_quality = dumb_resampling_quality;
+    sigrenderer->ramp_style = DUMB_IT_RAMP_FULL;
+    sigrenderer->globalvolume = sigdata->global_volume;
+    sigrenderer->tempo = sigdata->tempo;
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+        IT_CHANNEL *channel = &sigrenderer->channel[i];
+#if IT_CHANNEL_MUTED != 1
+#error this is wrong
+#endif
+        channel->flags = sigdata->channel_pan[i] >> 7;
+        channel->volume = (sigdata->flags & IT_WAS_AN_XM) ? 0 : 64;
+        channel->pan = sigdata->channel_pan[i] & 0x7F;
+        channel->truepan = channel->pan << IT_ENVELOPE_SHIFT;
+        channel->channelvolume = sigdata->channel_volume[i];
+        channel->instrument = 0;
+        channel->sample = 0;
+        channel->note = IT_NOTE_OFF;
+        channel->SFmacro = 0;
+        channel->filter_cutoff = 127;
+        channel->filter_resonance = 0;
+        channel->new_note_action = 0xFF;
+        channel->xm_retrig = 0;
+        channel->retrig_tick = 0;
+        channel->tremor_time = 0;
+        channel->vibrato_waveform = 0;
+        channel->tremolo_waveform = 0;
+        channel->panbrello_waveform = 0;
+        channel->glissando = 0;
+        channel->toneslide = 0;
+        channel->ptm_toneslide = 0;
+        channel->ptm_last_toneslide = 0;
+        channel->okt_toneslide = 0;
+        channel->midi_state = 0;
+        channel->lastvolslide = 0;
+        channel->lastDKL = 0;
+        channel->lastEF = 0;
+        channel->lastG = 0;
+        channel->lastHspeed = 0;
+        channel->lastHdepth = 0;
+        channel->lastRspeed = 0;
+        channel->lastRdepth = 0;
+        channel->lastYspeed = 0;
+        channel->lastYdepth = 0;
+        channel->lastI = 0;
+        channel->lastJ = 0;
+        channel->lastN = 0;
+        channel->lastO = 0;
+        channel->high_offset = 0;
+        channel->lastP = 0;
+        channel->lastQ = 0;
+        channel->lastS = 0;
+        channel->pat_loop_row = 0;
+        channel->pat_loop_count = 0;
+        channel->pat_loop_end_row = 0;
+        channel->lastW = 0;
+        channel->xm_lastE1 = 0;
+        channel->xm_lastE2 = 0;
+        channel->xm_lastEA = 0;
+        channel->xm_lastEB = 0;
+        channel->xm_lastX1 = 0;
+        channel->xm_lastX2 = 0;
+        channel->inv_loop_delay = 0;
+        channel->inv_loop_speed = 0;
+        channel->inv_loop_offset = 0;
+        channel->playing = NULL;
+        channel->key_off_count = 0;
+        channel->note_cut_count = 0;
+        channel->note_delay_count = 0;
+        channel->note_delay_entry = 0;
+#ifdef BIT_ARRAY_BULLSHIT
+        channel->played_patjump = NULL;
+        channel->played_patjump_order = 0xFFFE;
+#endif
+        // channel->output = 0;
+    }
+
+    if (sigdata->flags & IT_WAS_A_669)
+        reset_effects(sigrenderer);
+
+    for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
+        sigrenderer->playing[i] = NULL;
+
+    sigrenderer->speed = sigdata->speed;
+
+    sigrenderer->processrow = 0xFFFE;
+    sigrenderer->n_rows = 0;
+    sigrenderer->breakrow = 0;
+    sigrenderer->rowcount = 1;
+    sigrenderer->order = startorder;
+    /* meh!
+    if (startorder > 0) {
+            int n;
+            for (n = startorder - 1; n >= 0; n--) {
+                    if (sigdata->order[n] > sigdata->n_patterns) {
+                            sigrenderer->restart_position = n + 1;
+                            break;
+                    }
+            }
+    }
+    */
+    if (startorder > 0) {
+        sigrenderer->restart_position = startorder;
+    } else {
+        sigrenderer->restart_position = sigdata->restart_position;
+    }
+
+    sigrenderer->row = 0;
+    sigrenderer->processorder = startorder - 1;
+    sigrenderer->tick = 1;
+
+#ifdef BIT_ARRAY_BULLSHIT
+    sigrenderer->played = bit_array_create(sigdata->n_orders * 256);
+
+    sigrenderer->looped = 0;
+    sigrenderer->time_played = 0;
+    sigrenderer->row_timekeeper =
+        timekeeping_array_create(sigdata->n_orders * 256);
+#endif
+
+    {
+        int order;
+        for (order = 0; order < sigdata->n_orders; order++) {
+            int n = sigdata->order[order];
+            if (n < sigdata->n_patterns)
+                goto found_valid_order;
+#ifdef INVALID_ORDERS_END_SONG
+            if (n != IT_ORDER_SKIP)
+#else
+            if (n == IT_ORDER_END)
+#endif
+                break;
+
+#ifdef BIT_ARRAY_BULLSHIT
+            /* Fix for played order detection for songs which have skips at the
+             * start of the orders list */
+            for (n = 0; n < 256; n++) {
+                bit_array_set(sigrenderer->played, order * 256 + n);
+                timekeeping_array_push(sigrenderer->row_timekeeper,
+                                       order * 256 + n, 0);
+                timekeeping_array_bump(sigrenderer->row_timekeeper,
+                                       order * 256 + n);
+            }
+#endif
+        }
+        /* If we get here, there were no valid orders in the song. */
+        _dumb_it_end_sigrenderer(sigrenderer);
+        return NULL;
+    }
+found_valid_order:
+
+    sigrenderer->time_left = 0;
+    sigrenderer->sub_time_left = 0;
+
+    sigrenderer->gvz_time = 0;
+    sigrenderer->gvz_sub_time = 0;
+
+    // sigrenderer->max_output = 0;
+
+    if (!(sigdata->flags & IT_WAS_PROCESSED)) {
+        if (dumb_it_add_lpc(sigdata) < 0) {
+            _dumb_it_end_sigrenderer(sigrenderer);
+            return NULL;
+        }
+
+        sigdata->flags |= IT_WAS_PROCESSED;
+    }
+
+    return sigrenderer;
+}
+
+void dumb_it_set_resampling_quality(DUMB_IT_SIGRENDERER *sigrenderer,
+                                    int quality) {
+    if (sigrenderer && quality >= 0 && quality < DUMB_RQ_N_LEVELS) {
+        int i;
+        sigrenderer->resampling_quality = quality;
+        for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+            if (sigrenderer->channel[i].playing) {
+                IT_PLAYING *playing = sigrenderer->channel[i].playing;
+                playing->resampling_quality = quality;
+                playing->resampler.quality = quality;
+                resampler_set_quality(playing->resampler.fir_resampler[0],
+                                      quality);
+                resampler_set_quality(playing->resampler.fir_resampler[1],
+                                      quality);
+            }
+        }
+        for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++) {
+            if (sigrenderer->playing[i]) {
+                IT_PLAYING *playing = sigrenderer->playing[i];
+                playing->resampling_quality = quality;
+                playing->resampler.quality = quality;
+                resampler_set_quality(playing->resampler.fir_resampler[0],
+                                      quality);
+                resampler_set_quality(playing->resampler.fir_resampler[1],
+                                      quality);
+            }
+        }
+    }
+}
+
+void dumb_it_set_ramp_style(DUMB_IT_SIGRENDERER *sigrenderer, int ramp_style) {
+    if (sigrenderer && ramp_style >= 0 && ramp_style <= 2) {
+        sigrenderer->ramp_style = ramp_style;
+    }
+}
+
+void dumb_it_set_loop_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                               int (*callback)(void *data), void *data) {
+    if (sigrenderer) {
+        sigrenderer->callbacks->loop = callback;
+        sigrenderer->callbacks->loop_data = data;
+    }
+}
+
+void dumb_it_set_xm_speed_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                                        int (*callback)(void *data),
+                                        void *data) {
+    if (sigrenderer) {
+        sigrenderer->callbacks->xm_speed_zero = callback;
+        sigrenderer->callbacks->xm_speed_zero_data = data;
+    }
+}
+
+void dumb_it_set_midi_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                               int (*callback)(void *data, int channel,
+                                               unsigned char midi_byte),
+                               void *data) {
+    if (sigrenderer) {
+        sigrenderer->callbacks->midi = callback;
+        sigrenderer->callbacks->midi_data = data;
+    }
+}
+
+void dumb_it_set_global_volume_zero_callback(DUMB_IT_SIGRENDERER *sigrenderer,
+                                             int (*callback)(void *data),
+                                             void *data) {
+    if (sigrenderer) {
+        sigrenderer->callbacks->global_volume_zero = callback;
+        sigrenderer->callbacks->global_volume_zero_data = data;
+    }
+}
+
+static IT_CALLBACKS *create_callbacks(void) {
+    IT_CALLBACKS *callbacks = malloc(sizeof(*callbacks));
+    if (!callbacks)
+        return NULL;
+    callbacks->loop = NULL;
+    callbacks->xm_speed_zero = NULL;
+    callbacks->midi = NULL;
+    callbacks->global_volume_zero = NULL;
+    return callbacks;
+}
+
+static DUMB_IT_SIGRENDERER *dumb_it_init_sigrenderer(DUMB_IT_SIGDATA *sigdata,
+                                                     int n_channels,
+                                                     int startorder) {
+    IT_CALLBACKS *callbacks;
+
+    if (!sigdata)
+        return NULL;
+
+    callbacks = create_callbacks();
+    if (!callbacks)
+        return NULL;
+
+    return init_sigrenderer(sigdata, n_channels, startorder, callbacks,
+                            dumb_create_click_remover_array(n_channels));
+}
+
+DUH_SIGRENDERER *dumb_it_start_at_order(DUH *duh, int n_channels,
+                                        int startorder) {
+    DUMB_IT_SIGDATA *itsd = duh_get_it_sigdata(duh);
+    DUMB_IT_SIGRENDERER *itsr =
+        dumb_it_init_sigrenderer(itsd, n_channels, startorder);
+    /*duh->length = dumb_it_build_checkpoints(itsd, startorder);*/
+    return duh_encapsulate_it_sigrenderer(itsr, n_channels, 0);
+}
+
+static sigrenderer_t *it_start_sigrenderer(DUH *duh, sigdata_t *vsigdata,
+                                           int n_channels, long pos) {
+    DUMB_IT_SIGDATA *sigdata = vsigdata;
+    DUMB_IT_SIGRENDERER *sigrenderer;
+
+    (void)duh;
+
+    {
+        IT_CALLBACKS *callbacks = create_callbacks();
+        if (!callbacks)
+            return NULL;
+
+        if (sigdata->checkpoint) {
+            IT_CHECKPOINT *checkpoint = sigdata->checkpoint;
+            while (checkpoint->next && checkpoint->next->time < pos)
+                checkpoint = checkpoint->next;
+            sigrenderer =
+                dup_sigrenderer(checkpoint->sigrenderer, n_channels, callbacks);
+            if (!sigrenderer)
+                return NULL;
+            sigrenderer->click_remover =
+                dumb_create_click_remover_array(n_channels);
+            pos -= checkpoint->time;
+        } else {
+            sigrenderer =
+                init_sigrenderer(sigdata, n_channels, 0, callbacks,
+                                 dumb_create_click_remover_array(n_channels));
+            if (!sigrenderer)
+                return NULL;
+        }
+    }
+
+    while (pos > 0 && pos >= sigrenderer->time_left) {
+        render(sigrenderer, 0, 1.0f, 0, sigrenderer->time_left, NULL);
+
+#ifdef BIT_ARRAY_BULLSHIT
+        sigrenderer->time_played += (LONG_LONG)sigrenderer->time_left << 16;
+#endif
+
+        pos -= sigrenderer->time_left;
+        sigrenderer->time_left = 0;
+
+        if (process_tick(sigrenderer)) {
+            _dumb_it_end_sigrenderer(sigrenderer);
+            return NULL;
+        }
+    }
+
+    render(sigrenderer, 0, 1.0f, 0, pos, NULL);
+    sigrenderer->time_left -= pos;
+
+#ifdef BIT_ARRAY_BULLSHIT
+    sigrenderer->time_played += (LONG_LONG)pos << 16;
+#endif
+
+    return sigrenderer;
+}
+
+static long it_sigrenderer_get_samples(sigrenderer_t *vsigrenderer,
+                                       float volume, float delta, long size,
+                                       sample_t **samples) {
+    DUMB_IT_SIGRENDERER *sigrenderer = vsigrenderer;
+    long pos;
+    int dt;
+    long todo;
+    int ret;
+    LONG_LONG t;
+
+    if (sigrenderer->order < 0)
+        return 0; // problematic
+
+    if (!sigrenderer->tempo)
+        return 0; // also problematic
+
+    pos = 0;
+    dt = (int)(delta * 65536.0f + 0.5f);
+
+    /* When samples is finally used in render_playing(), it won't be used if
+     * volume is 0.
+     */
+    if (!samples)
+        volume = 0;
+
+    for (;;) {
+        todo = (long)((((LONG_LONG)sigrenderer->time_left << 16) |
+                       sigrenderer->sub_time_left) /
+                      dt);
+
+        if (todo >= size)
+            break;
+
+        render(sigrenderer, volume, delta, pos, todo, samples);
+
+        pos += todo;
+        size -= todo;
+
+        t = sigrenderer->sub_time_left - (LONG_LONG)todo * dt;
+        sigrenderer->sub_time_left = (long)t & 65535;
+        sigrenderer->time_left += (long)(t >> 16);
+
+#ifdef BIT_ARRAY_BULLSHIT
+        sigrenderer->time_played += (LONG_LONG)todo * dt;
+#endif
+
+        ret = process_tick(sigrenderer);
+
+        if (ret) {
+            sigrenderer->order = -1;
+            sigrenderer->row = -1;
+        }
+
+#ifdef BIT_ARRAY_BULLSHIT
+        if (sigrenderer->looped == 1) {
+            sigrenderer->looped = -1;
+            size = 0;
+            timekeeping_array_reset(sigrenderer->row_timekeeper,
+                                    sigrenderer->order * 256 +
+                                        sigrenderer->row);
+            sigrenderer->time_played = timekeeping_array_get_item(
+                sigrenderer->row_timekeeper,
+                sigrenderer->order * 256 + sigrenderer->row);
+            break;
+        }
+#endif
+
+        if (ret) {
+            return pos;
+        }
+    }
+
+    render(sigrenderer, volume, delta, pos, size, samples);
+
+    pos += size;
+
+    t = sigrenderer->sub_time_left - (LONG_LONG)size * dt;
+    sigrenderer->sub_time_left = (long)t & 65535;
+    sigrenderer->time_left += (long)(t >> 16);
+
+#ifdef BIT_ARRAY_BULLSHIT
+    sigrenderer->time_played += (LONG_LONG)size * dt;
+#endif
+
+    if (samples)
+        dumb_remove_clicks_array(sigrenderer->n_channels,
+                                 sigrenderer->click_remover, samples, pos,
+                                 512.0f / delta);
+
+    return pos;
+}
+
+static void it_sigrenderer_get_current_sample(sigrenderer_t *vsigrenderer,
+                                              float volume, sample_t *samples) {
+    DUMB_IT_SIGRENDERER *sigrenderer = vsigrenderer;
+    (void)volume; // for consideration: in any of these such functions, is
+                  // 'volume' going to be required?
+    dumb_click_remover_get_offset_array(sigrenderer->n_channels,
+                                        sigrenderer->click_remover, samples);
+}
+
+void _dumb_it_end_sigrenderer(sigrenderer_t *vsigrenderer) {
+    DUMB_IT_SIGRENDERER *sigrenderer = vsigrenderer;
+
+    int i;
+
+    if (sigrenderer) {
+        for (i = 0; i < DUMB_IT_N_CHANNELS; i++) {
+            if (sigrenderer->channel[i].playing)
+                free_playing(sigrenderer->channel[i].playing);
+#ifdef BIT_ARRAY_BULLSHIT
+            bit_array_destroy(sigrenderer->channel[i].played_patjump);
+#endif
+        }
+
+        for (i = 0; i < DUMB_IT_N_NNA_CHANNELS; i++)
+            if (sigrenderer->playing[i])
+                free_playing(sigrenderer->playing[i]);
+
+        dumb_destroy_click_remover_array(sigrenderer->n_channels,
+                                         sigrenderer->click_remover);
+
+        if (sigrenderer->callbacks)
+            free(sigrenderer->callbacks);
+
+#ifdef BIT_ARRAY_BULLSHIT
+        bit_array_destroy(sigrenderer->played);
+
+        timekeeping_array_destroy(sigrenderer->row_timekeeper);
+#endif
+
+        free(vsigrenderer);
+    }
+}
+
+#ifdef BIT_ARRAY_BULLSHIT
+static long it_sigrenderer_get_position(sigrenderer_t *vsigrenderer) {
+    DUMB_IT_SIGRENDERER *sigrenderer = (DUMB_IT_SIGRENDERER *)vsigrenderer;
+
+    return (long)(sigrenderer->time_played >> 16);
+}
+#endif
+
+DUH_SIGTYPE_DESC _dumb_sigtype_it = {SIGTYPE_IT,
+                                     NULL,
+                                     &it_start_sigrenderer,
+                                     NULL,
+                                     &it_sigrenderer_get_samples,
+                                     &it_sigrenderer_get_current_sample,
+#ifdef BIT_ARRAY_BULLSHIT
+                                     &it_sigrenderer_get_position,
+#else
+                                     NULL,
+#endif
+                                     &_dumb_it_end_sigrenderer,
+                                     &_dumb_it_unload_sigdata};
+
+DUH_SIGRENDERER *
+duh_encapsulate_it_sigrenderer(DUMB_IT_SIGRENDERER *it_sigrenderer,
+                               int n_channels, long pos) {
+    return duh_encapsulate_raw_sigrenderer(it_sigrenderer, &_dumb_sigtype_it,
+                                           n_channels, pos);
+}
+
+DUMB_IT_SIGRENDERER *duh_get_it_sigrenderer(DUH_SIGRENDERER *sigrenderer) {
+    return duh_get_raw_sigrenderer(sigrenderer, SIGTYPE_IT);
+}
+
+/* Values of 64 or more will access NNA channels here. */
+void dumb_it_sr_get_channel_state(DUMB_IT_SIGRENDERER *sr, int channel,
+                                  DUMB_IT_CHANNEL_STATE *state) {
+    IT_PLAYING *playing;
+    int t; /* temporary var for holding accurate pan and filter cutoff */
+    float delta;
+    ASSERT(channel < DUMB_IT_TOTAL_CHANNELS);
+    if (!sr) {
+        state->sample = 0;
+        return;
+    }
+    if (channel >= DUMB_IT_N_CHANNELS) {
+        playing = sr->playing[channel - DUMB_IT_N_CHANNELS];
+        if (!playing) {
+            state->sample = 0;
+            return;
+        }
+    } else {
+        playing = sr->channel[channel].playing;
+        if (!playing) {
+            state->sample = 0;
+            return;
+        }
+    }
+
+    if (playing->flags & IT_PLAYING_DEAD) {
+        state->sample = 0;
+        return;
+    }
+
+    state->channel = (int)(playing->channel - sr->channel);
+    state->sample = playing->sampnum;
+    state->volume = calculate_volume(sr, playing, 1.0f);
+
+    t = apply_pan_envelope(playing);
+    state->pan = (unsigned char)((t + 128) >> IT_ENVELOPE_SHIFT);
+    state->subpan = (signed char)t;
+
+    delta = playing->delta * 65536.0f;
+    t = playing->filter_cutoff << IT_ENVELOPE_SHIFT;
+    apply_pitch_modifications(sr->sigdata, playing, &delta, &t);
+    state->freq = (int)delta;
+    if (t == 127 << IT_ENVELOPE_SHIFT && playing->filter_resonance == 0) {
+        state->filter_resonance = playing->true_filter_resonance;
+        t = playing->true_filter_cutoff;
+    } else
+        state->filter_resonance = playing->filter_resonance;
+    state->filter_cutoff = (unsigned char)(t >> 8);
+    state->filter_subcutoff = (unsigned char)t;
+}
+
+int dumb_it_callback_terminate(void *data) {
+    (void)data;
+    return 1;
+}
+
+int dumb_it_callback_midi_block(void *data, int channel,
+                                unsigned char midi_byte) {
+    (void)data;
+    (void)channel;
+    (void)midi_byte;
+    return 1;
+}
+
+#define IT_CHECKPOINT_INTERVAL (30 * 65536) /* Half a minute */
+
+#define FUCKIT_THRESHOLD                                                       \
+    (120 * 60 * 65536) /* two hours? probably a pattern loop mess... */
+
+/* Returns the length of the module, up until it first loops. */
+long dumb_it_build_checkpoints(DUMB_IT_SIGDATA *sigdata, int startorder) {
+    IT_CHECKPOINT *checkpoint;
+    if (!sigdata)
+        return 0;
+    checkpoint = sigdata->checkpoint;
+    while (checkpoint) {
+        IT_CHECKPOINT *next = checkpoint->next;
+        _dumb_it_end_sigrenderer(checkpoint->sigrenderer);
+        free(checkpoint);
+        checkpoint = next;
+    }
+    sigdata->checkpoint = NULL;
+    checkpoint = malloc(sizeof(*checkpoint));
+    if (!checkpoint)
+        return 0;
+    checkpoint->time = 0;
+    checkpoint->sigrenderer = dumb_it_init_sigrenderer(sigdata, 0, startorder);
+    if (!checkpoint->sigrenderer) {
+        free(checkpoint);
+        return 0;
+    }
+    checkpoint->sigrenderer->callbacks->loop = &dumb_it_callback_terminate;
+    checkpoint->sigrenderer->callbacks->xm_speed_zero =
+        &dumb_it_callback_terminate;
+    checkpoint->sigrenderer->callbacks->global_volume_zero =
+        &dumb_it_callback_terminate;
+
+    if (sigdata->checkpoint) {
+        IT_CHECKPOINT *checkpoint = sigdata->checkpoint;
+        while (checkpoint) {
+            IT_CHECKPOINT *next = checkpoint->next;
+            _dumb_it_end_sigrenderer(checkpoint->sigrenderer);
+            free(checkpoint);
+            checkpoint = next;
+        }
+    }
+
+    sigdata->checkpoint = checkpoint;
+
+    for (;;) {
+        long l;
+        DUMB_IT_SIGRENDERER *sigrenderer = dup_sigrenderer(
+            checkpoint->sigrenderer, 0, checkpoint->sigrenderer->callbacks);
+        checkpoint->sigrenderer->callbacks = NULL;
+        if (!sigrenderer) {
+            checkpoint->next = NULL;
+            return checkpoint->time;
+        }
+
+        l = it_sigrenderer_get_samples(sigrenderer, 0, 1.0f,
+                                       IT_CHECKPOINT_INTERVAL, NULL);
+        if (l < IT_CHECKPOINT_INTERVAL) {
+            _dumb_it_end_sigrenderer(sigrenderer);
+            checkpoint->next = NULL;
+            return checkpoint->time + l;
+        }
+
+        checkpoint->next = malloc(sizeof(*checkpoint->next));
+        if (!checkpoint->next) {
+            _dumb_it_end_sigrenderer(sigrenderer);
+            return checkpoint->time + IT_CHECKPOINT_INTERVAL;
+        }
+
+        checkpoint->next->time = checkpoint->time + IT_CHECKPOINT_INTERVAL;
+        checkpoint = checkpoint->next;
+        checkpoint->sigrenderer = sigrenderer;
+
+        if (checkpoint->time >= FUCKIT_THRESHOLD) {
+            checkpoint->next = NULL;
+            return 0;
+        }
+    }
+}
+
+void dumb_it_do_initial_runthrough(DUH *duh) {
+    if (duh) {
+        DUMB_IT_SIGDATA *sigdata = duh_get_it_sigdata(duh);
+
+        if (sigdata)
+            duh_set_length(duh, dumb_it_build_checkpoints(sigdata, 0));
+    }
+}
+
+static int is_pattern_silent(IT_PATTERN *pattern, int order) {
+    int ret = 1;
+    IT_ENTRY *entry, *end;
+    if (!pattern || !pattern->n_rows || !pattern->n_entries || !pattern->entry)
+        return 2;
+
+    if (pattern->n_entries == pattern->n_rows) {
+        int n;
+        entry = pattern->entry;
+        for (n = 0; n < pattern->n_entries; ++n, ++entry) {
+            if (!IT_IS_END_ROW(entry))
+                break;
+        }
+        if (n == pattern->n_entries)
+            return 2;
+        // broken?
+    }
+
+    entry = pattern->entry;
+    end = entry + pattern->n_entries;
+
+    while (entry < end) {
+        if (!IT_IS_END_ROW(entry)) {
+            if (entry->mask & (IT_ENTRY_INSTRUMENT | IT_ENTRY_VOLPAN))
+                return 0;
+            if (entry->mask & IT_ENTRY_NOTE && entry->note < 120)
+                return 0;
+            if (entry->mask & IT_ENTRY_EFFECT) {
+                switch (entry->effect) {
+                case IT_SET_GLOBAL_VOLUME:
+                    if (entry->effectvalue)
+                        return 0;
+                    break;
+
+                case IT_SET_SPEED:
+                    if (entry->effectvalue > 64)
+                        ret++;
+                    break;
+
+                case IT_SET_SONG_TEMPO:
+                case IT_XM_KEY_OFF:
+                    break;
+
+                case IT_JUMP_TO_ORDER:
+                    if (entry->effectvalue != order)
+                        return 0;
+                    break;
+
+                case IT_S:
+                    switch (entry->effectvalue >> 4) {
+                    case 0: // meh bastard
+                        if (entry->effectvalue != 0)
+                            return 0;
+                        break;
+
+                    case IT_S_FINE_PATTERN_DELAY:
+                    case IT_S_PATTERN_LOOP:
+                    case IT_S_PATTERN_DELAY:
+                        ret++;
+                        break;
+
+                    case IT_S7:
+                        if ((entry->effectvalue & 15) > 2)
+                            return 0;
+                        break;
+
+                    default:
+                        return 0;
+                    }
+                    break;
+
+                // clever idiot with his S L O W crap; do nothing
+                case IT_VOLSLIDE_TONEPORTA:
+                case IT_SET_SAMPLE_OFFSET:
+                case IT_GLOBAL_VOLUME_SLIDE:
+                    if (entry->effectvalue != 0)
+                        return 0;
+                    break;
+
+                // genius also uses this instead of jump to order by mistake,
+                // meh, and it's bloody BCD
+                case IT_BREAK_TO_ROW:
+                    if (((entry->effectvalue >> 4) * 10 +
+                         (entry->effectvalue & 15)) != order)
+                        return 0;
+                    break;
+
+                default:
+                    return 0;
+                }
+            }
+        }
+        entry++;
+    }
+
+    return ret;
+}
+
+int dumb_it_trim_silent_patterns(DUH *duh) {
+    int n;
+    DUMB_IT_SIGDATA *sigdata;
+
+    if (!duh)
+        return -1;
+
+    sigdata = duh_get_it_sigdata(duh);
+
+    if (!sigdata || !sigdata->order || !sigdata->pattern)
+        return -1;
+
+    for (n = 0; n < sigdata->n_orders; n++) {
+        int p = sigdata->order[n];
+        if (p < sigdata->n_patterns) {
+            IT_PATTERN *pattern = &sigdata->pattern[p];
+            if (is_pattern_silent(pattern, n) > 1) {
+                pattern->n_rows = 1;
+                pattern->n_entries = 0;
+                if (pattern->entry) {
+                    free(pattern->entry);
+                    pattern->entry = NULL;
+                }
+            } else
+                break;
+        }
+    }
+
+    if (n == sigdata->n_orders)
+        return -1;
+
+    for (n = sigdata->n_orders - 1; n >= 0; n--) {
+        int p = sigdata->order[n];
+        if (p < sigdata->n_patterns) {
+            IT_PATTERN *pattern = &sigdata->pattern[p];
+            if (is_pattern_silent(pattern, n) > 1) {
+                pattern->n_rows = 1;
+                pattern->n_entries = 0;
+                if (pattern->entry) {
+                    free(pattern->entry);
+                    pattern->entry = NULL;
+                }
+            } else
+                break;
+        }
+    }
+
+    if (n < 0)
+        return -1;
+
+    /*duh->length = dumb_it_build_checkpoints(sigdata, 0);*/
+
+    return 0;
+}
+
+int dumb_it_scan_for_playable_orders(DUMB_IT_SIGDATA *sigdata,
+                                     dumb_scan_callback callback,
+                                     void *callback_data) {
+    int n;
+    long length;
+    void *ba_played;
+    DUMB_IT_SIGRENDERER *sigrenderer;
+
+    if (!sigdata->n_orders || !sigdata->order)
+        return -1;
+
+    ba_played = bit_array_create(sigdata->n_orders * 256);
+    if (!ba_played)
+        return -1;
+
+    /* Skip the first order, it should always be played */
+    for (n = 1; n < sigdata->n_orders; n++) {
+        if ((sigdata->order[n] >= sigdata->n_patterns) ||
+            (is_pattern_silent(&sigdata->pattern[sigdata->order[n]], n) > 1))
+            bit_array_set(ba_played, n * 256);
+    }
+
+    for (;;) {
+        for (n = 0; n < sigdata->n_orders; n++) {
+            if (!bit_array_test_range(ba_played, n * 256, 256))
+                break;
+        }
+
+        if (n == sigdata->n_orders)
+            break;
+
+        sigrenderer = dumb_it_init_sigrenderer(sigdata, 0, n);
+        if (!sigrenderer) {
+            bit_array_destroy(ba_played);
+            return -1;
+        }
+        sigrenderer->callbacks->loop = &dumb_it_callback_terminate;
+        sigrenderer->callbacks->xm_speed_zero = &dumb_it_callback_terminate;
+        sigrenderer->callbacks->global_volume_zero =
+            &dumb_it_callback_terminate;
+
+        length = 0;
+
+        for (;;) {
+            long l;
+
+            l = it_sigrenderer_get_samples(sigrenderer, 0, 1.0f,
+                                           IT_CHECKPOINT_INTERVAL, NULL);
+            length += l;
+            if (l < IT_CHECKPOINT_INTERVAL || length >= FUCKIT_THRESHOLD) {
+                /* SONG OVA! */
+                break;
+            }
+        }
+
+        if ((*callback)(callback_data, n, length) < 0)
+            return -1;
+
+        bit_array_merge(ba_played, sigrenderer->played, 0);
+
+        _dumb_it_end_sigrenderer(sigrenderer);
+    }
+
+    bit_array_destroy(ba_played);
+
+    return 0;
+}
--- /dev/null
+++ b/src/it/itunload.c
@@ -1,0 +1,69 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * itunload.c - Code to free an Impulse Tracker       / / \  \
+ *              module from memory.                  | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+void _dumb_it_unload_sigdata(sigdata_t *vsigdata) {
+    if (vsigdata) {
+        DUMB_IT_SIGDATA *sigdata = vsigdata;
+        int n;
+
+        if (sigdata->song_message)
+            free(sigdata->song_message);
+
+        if (sigdata->order)
+            free(sigdata->order);
+
+        if (sigdata->instrument)
+            free(sigdata->instrument);
+
+        if (sigdata->sample) {
+            for (n = 0; n < sigdata->n_samples; n++)
+                if (sigdata->sample[n].data)
+                    free(sigdata->sample[n].data);
+
+            free(sigdata->sample);
+        }
+
+        if (sigdata->pattern) {
+            for (n = 0; n < sigdata->n_patterns; n++)
+                if (sigdata->pattern[n].entry)
+                    free(sigdata->pattern[n].entry);
+            free(sigdata->pattern);
+        }
+
+        if (sigdata->midi)
+            free(sigdata->midi);
+
+        {
+            IT_CHECKPOINT *checkpoint = sigdata->checkpoint;
+            while (checkpoint) {
+                IT_CHECKPOINT *next = checkpoint->next;
+                _dumb_it_end_sigrenderer(checkpoint->sigrenderer);
+                free(checkpoint);
+                checkpoint = next;
+            }
+        }
+
+        free(vsigdata);
+    }
+}
--- /dev/null
+++ b/src/it/load669.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadmod.c - Code to read a 669 Composer module     / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_669_quick(): loads a 669 file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_669_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_669_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/load6692.c
@@ -1,0 +1,31 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadmod2.c - Code to read a 669 Composer module    / / \  \
+ *              file, opening and closing it for     | <  /   \_
+ *              you, and do an initial run-through.  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_669(): loads a 669 file into a DUH struct, returning a pointer
+ * to the DUH struct. When you have finished with it, you must pass the
+ * pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_669(const char *filename) {
+    DUH *duh = dumb_load_669_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadamf.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadamf.c - Code to read a DSMI AMF module file,   / / \  \
+ *             opening and closing it for you.       | <  /   \_
+ *                                                   |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_amf_quick(): loads a AMF file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_amf_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_amf_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadamf2.c
@@ -1,0 +1,31 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadamf2.c - Code to read a DSMI AMF module file,  / / \  \
+ *              opening and closing it for you, and  | <  /   \_
+ *              do an initial run-through.           |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ * By Christopher Snowhill.                             |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_amf(): loads a AMF file into a DUH struct, returning a pointer
+ * to the DUH struct. When you have finished with it, you must pass the
+ * pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_amf(const char *filename) {
+    DUH *duh = dumb_load_amf_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadany.c
@@ -1,0 +1,35 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadany.c - Code to detect and read any of the     / / \  \
+ *             module formats supported by DUMB,     | <  /   \_
+ *             opening and closing the file for you. |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+DUH *dumb_load_any_quick(const char *filename, int restrict_, int subsong) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_any_quick(f, restrict_, subsong);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadany2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadany2.c - Code to detect and read any of the    / / \  \
+ *              module formats supported by DUMB,    | <  /   \_
+ *              opening and closing the file for     |  \/ /\   /
+ *              you, and do an initial run-through.   \_  /  > /
+ *                                                      | \ / /
+ * by Christopher Snowhill.                             |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_any(const char *filename, int restrict_, int subsong) {
+    DUH *duh = dumb_load_any_quick(filename, restrict_, subsong);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadasy.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadasy.c - Code to read an ASYLUM Music Format    / / \  \
+ *             module file, opening and closing it   | <  /   \_
+ *             for you.                              |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_asy_quick(): loads a AMF file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_asy_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_asy_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadasy2.c
@@ -1,0 +1,31 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadasy2.c - Code to read an ASYLUM Music Format   / / \  \
+ *              module file, opening and closing it  | <  /   \_
+ *              for you, and do an initial run-      |  \/ /\   /
+ *              through.                              \_  /  > /
+ *                                                      | \ / /
+ * By Christopher Snowhill.                             |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_asy(): loads a AMF file into a DUH struct, returning a pointer
+ * to the DUH struct. When you have finished with it, you must pass the
+ * pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_asy(const char *filename) {
+    DUH *duh = dumb_load_asy_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadmod.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadmod.c - Code to read a good old-fashioned      / / \  \
+ *             Amiga module file, opening and        | <  /   \_
+ *             closing it for you.                   |  \/ /\   /
+ *                                                    \_  /  > /
+ * By entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_mod_quick(): loads a MOD file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_mod_quick(const char *filename, int restrict_) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_mod_quick(f, restrict_);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadmod2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadmod2.c - Function to read a good old-          / / \  \
+ *              fashioned Amiga module file,         | <  /   \_
+ *              opening and closing it for you,      |  \/ /\   /
+ *              and do an initial run-through.        \_  /  > /
+ *                                                      | \ / /
+ * Split off from loadmod.c by entheh.                  |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_mod(const char *filename, int restrict_) {
+    DUH *duh = dumb_load_mod_quick(filename, restrict_);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadmtm.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadmtm.c - Code to read a MultiTracker Module     / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_mtm_quick(): loads a MTM file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_mtm_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_mtm_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadmtm2.c
@@ -1,0 +1,31 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadmtm2.c - Code to read a MultiTracker Module    / / \  \
+ *              file, opening and closing it for     | <  /   \_
+ *              you, and do an initial run-through.  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_mtm(): loads a MTM file into a DUH struct, returning a pointer
+ * to the DUH struct. When you have finished with it, you must pass the
+ * pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_mtm(const char *filename) {
+    DUH *duh = dumb_load_mtm_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadokt.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadokt.c - Code to read an Oktalyzer module       / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_okt_quick(): loads an OKT file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_okt_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_okt_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadokt2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadokt2.c - Function to read an Oktalyzer         / / \  \
+ *              module file, opening and closing     | <  /   \_
+ *              it for you, and do an initial run-   |  \/ /\   /
+ *              through.                              \_  /  > /
+ *                                                      | \ / /
+ * By Christopher Snowhill.                             |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_okt(const char *filename) {
+    DUH *duh = dumb_load_okt_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadoldpsm.c
@@ -1,0 +1,40 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadoldpsm.c - Code to read a ProTracker Studio    / / \  \
+ *                file, opening and closing it for   | <  /   \_
+ *                you.                               |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_old_psm_quick(): loads an old PSM file into a DUH struct,
+ * returning a pointer to the DUH struct. When you have finished with it,
+ * you must pass the pointer to unload_duh() so that the memory can be
+ * freed.
+ */
+DUH *dumb_load_old_psm_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_old_psm_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadoldpsm2.c
@@ -1,0 +1,31 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadoldpsm2.c - Code to read a ProTracker Studio   / / \  \
+ *                 file, opening and closing it for  | <  /   \_
+ *                 you, and do an initial run-       |  \/ /\   /
+ *                 through.                           \_  /  > /
+ *                                                      | \ / /
+ * By Christopher Snowhill.                             |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_old_psm(): loads an old PSM file into a DUH struct, returning
+ * a pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_old_psm(const char *filename) {
+    DUH *duh = dumb_load_old_psm_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadpsm.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadpsm.c - Code to read a ProTracker Studio       / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_psm_quick(): loads a PSM file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_psm_quick(const char *filename, int subsong) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_psm_quick(f, subsong);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadpsm2.c
@@ -1,0 +1,31 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadpsm2.c - Code to read a ProTracker Studio      / / \  \
+ *              file, opening and closing it for     | <  /   \_
+ *              you, and do an initial run-through.  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_psm(): loads a PSM file into a DUH struct, returning a pointer
+ * to the DUH struct. When you have finished with it, you must pass the
+ * pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_psm(const char *filename, int subsong) {
+    DUH *duh = dumb_load_psm_quick(filename, subsong);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadptm.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadptm.c - Code to read a Poly Tracker v2.03      / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_ptm_quick(): loads a PTM file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_ptm_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_ptm_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadptm2.c
@@ -1,0 +1,31 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadptm2.c - Code to read a Poly Tracker v2.03     / / \  \
+ *              file, opening and closing it for     | <  /   \_
+ *              you, and do an initial run-through.  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_ptm(): loads a PTM file into a DUH struct, returning a pointer
+ * to the DUH struct. When you have finished with it, you must pass the
+ * pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_ptm(const char *filename) {
+    DUH *duh = dumb_load_ptm_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadriff.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadriff.c - Code to read a RIFF module file       / / \  \
+ *              opening and closing it for you.      | <  /   \_
+ *                                                   |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_riff_quick(): loads a RIFF file into a DUH struct, returning
+ * a pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_riff_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_riff_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadriff2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadriff2.c - Code to read a RIFF module file      / / \  \
+ *               opening and closing it for you,     | <  /   \_
+ *               and do an initial run-through.      |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_riff(const char *filename) {
+    DUH *duh = dumb_load_riff_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loads3m.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loads3m.c - Code to read a ScreamTracker 3         / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_s3m_quick(): loads an S3M file into a DUH struct, returning
+ * a pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_s3m_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_s3m_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loads3m2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loads3m2.c - Function to read a ScreamTracker 3    / / \  \
+ *              file, opening and closing it for     | <  /   \_
+ *              you, and do an initial run-through.  |  \/ /\   /
+ *                                                    \_  /  > /
+ * Split off from loads3m.c by entheh.                  | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_s3m(const char *filename) {
+    DUH *duh = dumb_load_s3m_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadstm.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadstm.c - Code to read a ScreamTracker 2         / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you.                                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_stm_quick(): loads an STM file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_stm_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_stm_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadstm2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadstm2.c - Function to read a ScreamTracker 2    / / \  \
+ *              file, opening and closing it for     | <  /   \_
+ *              you, and do an initial run-through.  |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_stm(const char *filename) {
+    DUH *duh = dumb_load_stm_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadxm.c
@@ -1,0 +1,39 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadxm.c - Code to read a Fast Tracker II          / / \  \
+ *            file, opening and closing it for       | <  /   \_
+ *            you.                                   |  \/ /\   /
+ *                                                    \_  /  > /
+ * By entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+
+/* dumb_load_xm_quick(): loads an XM file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must
+ * pass the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_load_xm_quick(const char *filename) {
+    DUH *duh;
+    DUMBFILE *f = dumbfile_open(filename);
+
+    if (!f)
+        return NULL;
+
+    duh = dumb_read_xm_quick(f);
+
+    dumbfile_close(f);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/loadxm2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * loadxm2.c - Function to read a Fast Tracker II     / / \  \
+ *             file, opening and closing it for      | <  /   \_
+ *             you, and do an initial run-through.   |  \/ /\   /
+ *                                                    \_  /  > /
+ * Split off from loadxm.c by entheh.                   | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_load_xm(const char *filename) {
+    DUH *duh = dumb_load_xm_quick(filename);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/ptmeffect.c
@@ -1,0 +1,174 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * ptmeffect.c - Code for converting PTM              / / \  \
+ *               effects to IT effects.              | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill. Based on xmeffect.c       \_  /  > /
+ * by Julien Cugniere.                                  | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+void _dumb_it_ptm_convert_effect(int effect, int value, IT_ENTRY *entry) {
+    if (effect >= PTM_N_EFFECTS)
+        return;
+
+    /* Linearisation of the effect number... */
+    if (effect == PTM_E) {
+        effect = PTM_EBASE + HIGH(value);
+        value = LOW(value);
+    }
+
+    /* convert effect */
+    entry->mask |= IT_ENTRY_EFFECT;
+    switch (effect) {
+
+    case PTM_APPREGIO:
+        effect = IT_ARPEGGIO;
+        break;
+    case PTM_PORTAMENTO_UP:
+        effect = IT_PORTAMENTO_UP;
+        break;
+    case PTM_PORTAMENTO_DOWN:
+        effect = IT_PORTAMENTO_DOWN;
+        break;
+    case PTM_TONE_PORTAMENTO:
+        effect = IT_TONE_PORTAMENTO;
+        break;
+    case PTM_VIBRATO:
+        effect = IT_VIBRATO;
+        break;
+    case PTM_VOLSLIDE_TONEPORTA:
+        effect = IT_VOLSLIDE_TONEPORTA;
+        break;
+    case PTM_VOLSLIDE_VIBRATO:
+        effect = IT_VOLSLIDE_VIBRATO;
+        break;
+    case PTM_TREMOLO:
+        effect = IT_TREMOLO;
+        break;
+    case PTM_SAMPLE_OFFSET:
+        effect = IT_SET_SAMPLE_OFFSET;
+        break;
+    case PTM_VOLUME_SLIDE:
+        effect = IT_VOLUME_SLIDE;
+        break;
+    case PTM_POSITION_JUMP:
+        effect = IT_JUMP_TO_ORDER;
+        break;
+    case PTM_SET_CHANNEL_VOLUME:
+        effect = IT_SET_CHANNEL_VOLUME;
+        break;
+    case PTM_PATTERN_BREAK:
+        effect = IT_BREAK_TO_ROW;
+        break;
+    case PTM_SET_GLOBAL_VOLUME:
+        effect = IT_SET_GLOBAL_VOLUME;
+        break;
+    case PTM_RETRIGGER:
+        effect = IT_RETRIGGER_NOTE;
+        break;
+    case PTM_FINE_VIBRATO:
+        effect = IT_FINE_VIBRATO;
+        break;
+
+    /* TODO properly */
+    case PTM_NOTE_SLIDE_UP:
+        effect = IT_PTM_NOTE_SLIDE_UP;
+        break;
+    case PTM_NOTE_SLIDE_DOWN:
+        effect = IT_PTM_NOTE_SLIDE_DOWN;
+        break;
+    case PTM_NOTE_SLIDE_UP_RETRIG:
+        effect = IT_PTM_NOTE_SLIDE_UP_RETRIG;
+        break;
+    case PTM_NOTE_SLIDE_DOWN_RETRIG:
+        effect = IT_PTM_NOTE_SLIDE_DOWN_RETRIG;
+        break;
+
+    case PTM_SET_TEMPO_BPM:
+        effect = (value < 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
+        break;
+
+    case PTM_EBASE + PTM_E_SET_FINETUNE:
+        effect = SBASE + IT_S_FINETUNE;
+        break; /** TODO */
+    case PTM_EBASE + PTM_E_SET_LOOP:
+        effect = SBASE + IT_S_PATTERN_LOOP;
+        break;
+    case PTM_EBASE + PTM_E_NOTE_CUT:
+        effect = SBASE + IT_S_DELAYED_NOTE_CUT;
+        break;
+    case PTM_EBASE + PTM_E_NOTE_DELAY:
+        effect = SBASE + IT_S_NOTE_DELAY;
+        break;
+    case PTM_EBASE + PTM_E_PATTERN_DELAY:
+        effect = SBASE + IT_S_PATTERN_DELAY;
+        break;
+    case PTM_EBASE + PTM_E_SET_PANNING:
+        effect = SBASE + IT_S_SET_PAN;
+        break;
+
+    case PTM_EBASE + PTM_E_FINE_VOLSLIDE_UP:
+        effect = IT_VOLUME_SLIDE;
+        value = EFFECT_VALUE(value, 0xF);
+        break;
+
+    case PTM_EBASE + PTM_E_FINE_VOLSLIDE_DOWN:
+        effect = IT_VOLUME_SLIDE;
+        value = EFFECT_VALUE(0xF, value);
+        break;
+
+    case PTM_EBASE + PTM_E_FINE_PORTA_UP:
+        effect = IT_PORTAMENTO_UP;
+        value = EFFECT_VALUE(0xF, value);
+        break;
+
+    case PTM_EBASE + PTM_E_FINE_PORTA_DOWN:
+        effect = IT_PORTAMENTO_DOWN;
+        value = EFFECT_VALUE(0xF, value);
+        break;
+
+    case PTM_EBASE + PTM_E_RETRIG_NOTE:
+        effect = IT_XM_RETRIGGER_NOTE;
+        value = EFFECT_VALUE(0, value);
+        break;
+
+    case PTM_EBASE + PTM_E_SET_VIBRATO_CONTROL:
+        effect = SBASE + IT_S_SET_VIBRATO_WAVEFORM;
+        value &= ~4; /** TODO: value&4 -> don't retrig wave */
+        break;
+
+    case PTM_EBASE + PTM_E_SET_TREMOLO_CONTROL:
+        effect = SBASE + IT_S_SET_TREMOLO_WAVEFORM;
+        value &= ~4; /** TODO: value&4 -> don't retrig wave */
+        break;
+
+    default:
+        /* user effect (often used in demos for synchronisation) */
+        entry->mask &= ~IT_ENTRY_EFFECT;
+    }
+
+    /* Inverse linearisation... */
+    if (effect >= SBASE && effect < SBASE + 16) {
+        value = EFFECT_VALUE(effect - SBASE, value);
+        effect = IT_S;
+    }
+
+    entry->effect = effect;
+    entry->effectvalue = value;
+}
--- /dev/null
+++ b/src/it/read669.c
@@ -1,0 +1,454 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * read669.c - Code to read a 669 Composer module     / / \  \
+ *             from an open file.                    | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+static int it_669_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, int tempo,
+                               int breakpoint, unsigned char *buffer,
+                               int *used_channels) {
+    int pos;
+    int channel;
+    int row;
+    IT_ENTRY *entry;
+
+    pattern->n_rows = 64;
+
+    if (dumbfile_getnc((char *)buffer, 64 * 3 * 8, f) < 64 * 3 * 8)
+        return -1;
+
+    /* compute number of entries */
+    pattern->n_entries =
+        64 + 1; /* Account for the row end markers, speed command */
+    if (breakpoint < 63)
+        pattern->n_entries++; /* and break to row 0 */
+
+    pos = 0;
+    for (row = 0; row < 64; row++) {
+        for (channel = 0; channel < 8; channel++) {
+            if (buffer[pos + 0] != 0xFF || buffer[pos + 2] != 0xFF)
+                pattern->n_entries++;
+            pos += 3;
+        }
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    if (breakpoint == 63)
+        breakpoint++;
+
+    entry = pattern->entry;
+
+    entry->channel = 8;
+    entry->mask = IT_ENTRY_EFFECT;
+    entry->effect = IT_SET_SPEED;
+    entry->effectvalue = tempo;
+    entry++;
+
+    pos = 0;
+    for (row = 0; row < 64; row++) {
+
+        if (row == breakpoint) {
+            entry->channel = 8;
+            entry->mask = IT_ENTRY_EFFECT;
+            entry->effect = IT_BREAK_TO_ROW;
+            entry->effectvalue = 0;
+            entry++;
+        }
+
+        for (channel = 0; channel < 8; channel++) {
+            if (buffer[pos + 0] != 0xFF || buffer[pos + 2] != 0xFF) {
+                entry->channel = channel;
+                entry->mask = 0;
+
+                if (buffer[pos + 0] < 0xFE) {
+                    entry->mask |= IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT;
+                    entry->note = (buffer[pos + 0] >> 2) + 36;
+                    entry->instrument =
+                        (((buffer[pos + 0] << 4) | (buffer[pos + 1] >> 4)) &
+                         0x3F) +
+                        1;
+                }
+                if (buffer[pos + 0] <= 0xFE) {
+                    entry->mask |= IT_ENTRY_VOLPAN;
+                    entry->volpan = ((buffer[pos + 1] & 15) << 6) / 15;
+                    if (*used_channels < channel + 1)
+                        *used_channels = channel + 1;
+                }
+                if (buffer[pos + 2] != 0xFF) {
+                    entry->mask |= IT_ENTRY_EFFECT;
+                    entry->effectvalue = buffer[pos + 2] & 15;
+                    switch (buffer[pos + 2] >> 4) {
+                    case 0:
+                        entry->effect = IT_PORTAMENTO_UP;
+                        break;
+                    case 1:
+                        entry->effect = IT_PORTAMENTO_DOWN;
+                        break;
+                    case 2:
+                        entry->effect = IT_TONE_PORTAMENTO;
+                        break;
+                    case 3:
+                        entry->effect = IT_S;
+                        entry->effectvalue += IT_S_FINETUNE * 16 + 8;
+                        break;
+                    case 4:
+                        entry->effect = IT_VIBRATO;
+                        // XXX speed unknown
+                        entry->effectvalue |= 0x10;
+                        break;
+                    case 5:
+                        if (entry->effectvalue) {
+                            entry->effect = IT_SET_SPEED;
+                        } else {
+                            entry->mask &= ~IT_ENTRY_EFFECT;
+                        }
+                        break;
+#if 0
+						/* dunno about this, really... */
+						case 6:
+							if (entry->effectvalue == 0) {
+								entry->effect = IT_PANNING_SLIDE;
+								entry->effectvalue = 0xFE;
+							} else if (entry->effectvalue == 1) {
+								entry->effect = IT_PANNING_SLIDE;
+								entry->effectvalue = 0xEF;
+							} else {
+								entry->mask &= ~IT_ENTRY_EFFECT;
+							}
+							break;
+#endif
+                    default:
+                        entry->mask &= ~IT_ENTRY_EFFECT;
+                        break;
+                    }
+                    if (*used_channels < channel + 1)
+                        *used_channels = channel + 1;
+                }
+
+                entry++;
+            }
+            pos += 3;
+        }
+        IT_SET_END_ROW(entry);
+        entry++;
+    }
+
+    return 0;
+}
+
+static int it_669_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f) {
+    dumbfile_getnc((char *)sample->name, 13, f);
+    sample->name[13] = 0;
+
+    sample->filename[0] = 0;
+
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = dumbfile_igetl(f);
+
+    if (dumbfile_error(f))
+        return -1;
+
+    if (sample->length <= 0) {
+        sample->flags = 0;
+        return 0;
+    }
+
+    sample->flags = IT_SAMPLE_EXISTS;
+
+    sample->global_volume = 64;
+    sample->default_volume = 64;
+
+    sample->default_pan = 0;
+    sample->C5_speed = 8363;
+    // the above line might be wrong
+
+    if ((sample->loop_end > sample->length) && !(sample->loop_start))
+        sample->loop_end = 0;
+
+    if (sample->loop_end > sample->length)
+        sample->loop_end = sample->length;
+
+    if (sample->loop_end - sample->loop_start > 2)
+        sample->flags |= IT_SAMPLE_LOOP;
+
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = 0; // do we have to set _all_ these?
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    return 0;
+}
+
+static int it_669_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f) {
+    long i;
+    long truncated_size;
+
+    /* let's get rid of the sample data coming after the end of the loop */
+    if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length) {
+        truncated_size = sample->length - sample->loop_end;
+        sample->length = sample->loop_end;
+    } else {
+        truncated_size = 0;
+    }
+
+    sample->data = malloc(sample->length);
+
+    if (!sample->data)
+        return -1;
+
+    if (sample->length) {
+        i = dumbfile_getnc(sample->data, sample->length, f);
+
+        if (i < sample->length) {
+            // return -1;
+            // ficking truncated files
+            if (i <= 0) {
+                sample->flags = 0;
+                return 0;
+            }
+            sample->length = i;
+            if (sample->loop_end > i)
+                sample->loop_end = i;
+        } else {
+            /* skip truncated data */
+            dumbfile_skip(f, truncated_size);
+            // Should we be truncating it?
+            if (dumbfile_error(f))
+                return -1;
+        }
+
+        for (i = 0; i < sample->length; i++)
+            ((signed char *)sample->data)[i] ^= 0x80;
+    }
+
+    return 0;
+}
+
+static DUMB_IT_SIGDATA *it_669_load_sigdata(DUMBFILE *f, int *ext) {
+    DUMB_IT_SIGDATA *sigdata;
+    int n_channels;
+    int i;
+    unsigned char tempolist[128];
+    unsigned char breaklist[128];
+
+    i = dumbfile_igetw(f);
+    if (i != 0x6669 && i != 0x4E4A)
+        return NULL;
+
+    *ext = (i == 0x4E4A);
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata) {
+        return NULL;
+    }
+
+    if (dumbfile_getnc((char *)sigdata->name, 36, f) < 36) {
+        free(sigdata);
+        return NULL;
+    }
+    sigdata->name[36] = 0;
+
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+    sigdata->sample = NULL;
+
+    sigdata->n_instruments = 0;
+
+    sigdata->song_message = malloc(72 + 2 + 1);
+    if (!sigdata->song_message) {
+        free(sigdata);
+        return NULL;
+    }
+    if (dumbfile_getnc((char *)sigdata->song_message, 36, f) < 36) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    sigdata->song_message[36] = 13;
+    sigdata->song_message[36 + 1] = 10;
+    if (dumbfile_getnc((char *)sigdata->song_message + 38, 36, f) < 36) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    sigdata->song_message[38 + 36] = 0;
+
+    sigdata->n_samples = dumbfile_getc(f);
+    sigdata->n_patterns = dumbfile_getc(f);
+    sigdata->restart_position = dumbfile_getc(f);
+
+    if ((sigdata->n_samples) > 64 || (sigdata->n_patterns > 128)) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->order = malloc(128); /* We may need to scan the extra ones! */
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    if (dumbfile_getnc((char *)sigdata->order, 128, f) < 128) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (i = 0; i < 128; i++) {
+        if (sigdata->order[i] == 255)
+            break;
+        if (sigdata->order[i] >= sigdata->n_patterns) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+    if (!i) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    sigdata->n_orders = i;
+
+    if (dumbfile_getnc((char *)tempolist, 128, f) < 128) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (dumbfile_getnc((char *)breaklist, 128, f) < 128) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (i = 0; i < sigdata->n_samples; i++)
+        sigdata->sample[i].data = NULL;
+
+    for (i = 0; i < sigdata->n_samples; i++) {
+        if (it_669_read_sample_header(&sigdata->sample[i], f)) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    /* May as well try to save a tiny bit of memory. */
+    if (sigdata->n_orders < 128) {
+        unsigned char *order = realloc(sigdata->order, sigdata->n_orders);
+        if (order)
+            sigdata->order = order;
+    }
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    for (i = 0; i < sigdata->n_patterns; i++)
+        sigdata->pattern[i].entry = NULL;
+
+    n_channels = 0;
+
+    /* Read in the patterns */
+    {
+        unsigned char *buffer =
+            malloc(64 * 3 * 8); /* 64 rows * 3 bytes * 8 channels */
+        if (!buffer) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (i = 0; i < sigdata->n_patterns; i++) {
+            if (it_669_read_pattern(&sigdata->pattern[i], f, tempolist[i],
+                                    breaklist[i], buffer, &n_channels) != 0) {
+                free(buffer);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+        }
+        free(buffer);
+    }
+
+    sigdata->n_pchannels = n_channels;
+
+    /* And finally, the sample data */
+    for (i = 0; i < sigdata->n_samples; i++) {
+        if (it_669_read_sample_data(&sigdata->sample[i], f)) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    /* Now let's initialise the remaining variables, and we're done! */
+    sigdata->flags =
+        IT_OLD_EFFECTS | IT_LINEAR_SLIDES | IT_STEREO | IT_WAS_A_669;
+
+    sigdata->global_volume = 128;
+    sigdata->mixing_volume = 48;
+    sigdata->speed = 4;
+    sigdata->tempo = 78;
+    sigdata->pan_separation = 128;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i += 2) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[i + 0] = 32 + sep;
+        sigdata->channel_pan[i + 1] = 32 - sep;
+    }
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+DUH *dumb_read_669_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+    int ext;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_669_load_sigdata(f, &ext);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = ext ? "669 Extended" : "669";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/read6692.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * read6692.c - Code to read a 669 Composer module    / / \  \
+ *              from an open file, and do an initial | <  /   \_
+ *              run-through.                         |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_669(DUMBFILE *f) {
+    DUH *duh = dumb_read_669_quick(f);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/readam.c
@@ -1,0 +1,805 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readam.c - Code to read a RIFF AM module           / / \  \
+ *             from a parsed RIFF structure.         | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+#include "internal/riff.h"
+
+static int it_riff_am_process_sample(IT_SAMPLE *sample, DUMBFILE *f, size_t len,
+                                     int ver) {
+    size_t header_length;
+    int default_pan;
+    int default_volume;
+    int flags;
+    size_t length;
+    size_t length_bytes;
+    size_t loop_start;
+    size_t loop_end;
+    size_t sample_rate;
+
+    long start = dumbfile_pos(f);
+
+    if (ver == 0) {
+        if (len < 0x38)
+            return -1;
+
+        header_length = 0x38;
+
+        dumbfile_getnc((char *)sample->name, 28, f);
+        sample->name[28] = 0;
+
+        default_pan = dumbfile_getc(f);
+        default_volume = dumbfile_getc(f);
+        flags = dumbfile_igetw(f);
+        length = dumbfile_igetl(f);
+        loop_start = dumbfile_igetl(f);
+        loop_end = dumbfile_igetl(f);
+        sample_rate = dumbfile_igetl(f);
+    } else {
+        if (len < 4)
+            return -1;
+
+        header_length = dumbfile_igetl(f);
+        if (header_length < 0x40)
+            return -1;
+        if (header_length + 4 > len)
+            return -1;
+
+        start += 4;
+        len -= 4;
+
+        dumbfile_getnc((char *)sample->name, 32, f);
+
+        default_pan = dumbfile_igetw(f);
+        default_volume = dumbfile_igetw(f);
+        flags = dumbfile_igetw(f);
+        dumbfile_skip(f, 2);
+        length = dumbfile_igetl(f);
+        loop_start = dumbfile_igetl(f);
+        loop_end = dumbfile_igetl(f);
+        sample_rate = dumbfile_igetl(f);
+
+        if (default_pan > 0x7FFF || default_volume > 0x7FFF)
+            return -1;
+
+        default_pan = default_pan * 64 / 32767;
+        default_volume = default_volume * 64 / 32767;
+    }
+
+    if (!length) {
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+        return 0;
+    }
+
+    if (flags & ~(0x8000 | 0x80 | 0x20 | 0x10 | 0x08 | 0x04))
+        return -1;
+
+    length_bytes = length << ((flags & 0x04) >> 2);
+
+    if (length_bytes + header_length > len)
+        return -1;
+
+    sample->flags = 0;
+
+    if (flags & 0x80)
+        sample->flags |= IT_SAMPLE_EXISTS;
+    if (flags & 0x04)
+        sample->flags |= IT_SAMPLE_16BIT;
+
+    sample->length = length;
+    sample->loop_start = loop_start;
+    sample->loop_end = loop_end;
+    sample->C5_speed = sample_rate;
+    sample->default_volume = default_volume;
+    sample->default_pan = default_pan | ((flags & 0x20) << 2);
+    sample->filename[0] = 0;
+    sample->global_volume = 64;
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = IT_VIBRATO_SINE;
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    if (flags & 0x08) {
+        if (((unsigned int)sample->loop_end <= (unsigned int)sample->length) &&
+            ((unsigned int)sample->loop_start <
+             (unsigned int)sample->loop_end)) {
+            sample->length = sample->loop_end;
+            sample->flags |= IT_SAMPLE_LOOP;
+            if (flags & 0x10)
+                sample->flags |= IT_SAMPLE_PINGPONG_LOOP;
+        }
+    }
+
+    length_bytes = sample->length << ((flags & 0x04) >> 2);
+
+    sample->data = malloc(length_bytes);
+    if (!sample->data)
+        return -1;
+
+    if (dumbfile_seek(f, start + header_length, DFS_SEEK_SET))
+        return -1;
+
+    dumbfile_getnc(sample->data, length_bytes, f);
+
+    return 0;
+}
+
+static int it_riff_am_process_pattern(IT_PATTERN *pattern, DUMBFILE *f,
+                                      size_t len, int ver) {
+    int nrows, row;
+    long start, end;
+    unsigned flags;
+    int p, q, r;
+    IT_ENTRY *entry;
+
+    nrows = dumbfile_getc(f) + 1;
+
+    pattern->n_rows = nrows;
+
+    len -= 1;
+
+    pattern->n_entries = 0;
+
+    row = 0;
+
+    start = dumbfile_pos(f);
+    end = start + len;
+
+    while ((row < nrows) && !dumbfile_error(f) && (dumbfile_pos(f) < end)) {
+        p = dumbfile_getc(f);
+        if (!p) {
+            ++row;
+            continue;
+        }
+
+        flags = p & 0xE0;
+
+        if (flags) {
+            ++pattern->n_entries;
+            if (flags & 0x80)
+                dumbfile_skip(f, 2);
+            if (flags & 0x40)
+                dumbfile_skip(f, 2);
+            if (flags & 0x20)
+                dumbfile_skip(f, 1);
+        }
+    }
+
+    if (!pattern->n_entries)
+        return 0;
+
+    pattern->n_entries += nrows;
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+
+    row = 0;
+
+    dumbfile_seek(f, start, DFS_SEEK_SET);
+
+    while ((row < nrows) && !dumbfile_error(f) && (dumbfile_pos(f) < end)) {
+        p = dumbfile_getc(f);
+
+        if (!p) {
+            IT_SET_END_ROW(entry);
+            ++entry;
+            ++row;
+            continue;
+        }
+
+        flags = p;
+        entry->channel = flags & 0x1F;
+        entry->mask = 0;
+
+        if (flags & 0xE0) {
+            if (flags & 0x80) {
+                q = dumbfile_getc(f);
+                r = dumbfile_getc(f);
+                _dumb_it_xm_convert_effect(r, q, entry, 0);
+            }
+
+            if (flags & 0x40) {
+                q = dumbfile_getc(f);
+                r = dumbfile_getc(f);
+                if (q) {
+                    entry->mask |= IT_ENTRY_INSTRUMENT;
+                    entry->instrument = q;
+                }
+                if (r) {
+                    entry->mask |= IT_ENTRY_NOTE;
+                    entry->note = r - 1;
+                }
+            }
+
+            if (flags & 0x20) {
+                q = dumbfile_getc(f);
+                entry->mask |= IT_ENTRY_VOLPAN;
+                if (ver == 0)
+                    entry->volpan = q;
+                else
+                    entry->volpan = q * 64 / 127;
+            }
+
+            if (entry->mask)
+                entry++;
+        }
+    }
+
+    while (row < nrows) {
+        IT_SET_END_ROW(entry);
+        ++entry;
+        ++row;
+    }
+
+    pattern->n_entries = (int)((long)entry - (long)pattern->entry);
+    if (!pattern->n_entries)
+        return -1;
+
+    return 0;
+}
+
+static DUMB_IT_SIGDATA *it_riff_amff_load_sigdata(DUMBFILE *f,
+                                                  struct riff *stream) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    int n, found;
+    int o, p;
+
+    if (!stream)
+        goto error;
+
+    if (stream->type != DUMB_ID('A', 'M', 'F', 'F'))
+        goto error;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        goto error;
+
+    sigdata->n_patterns = 0;
+    sigdata->n_samples = 0;
+    sigdata->name[0] = 0;
+
+    found = 0;
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('M', 'A', 'I', 'N'):
+            /* initialization data */
+            if ((found & 1) || (c->size < 0x48))
+                goto error_sd;
+            found |= 1;
+            break;
+
+        case DUMB_ID('O', 'R', 'D', 'R'):
+            if ((found & 2) || (c->size < 1))
+                goto error_sd;
+            found |= 2;
+            break;
+
+        case DUMB_ID('P', 'A', 'T', 'T'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_sd;
+            o = dumbfile_getc(f);
+            if (o >= sigdata->n_patterns)
+                sigdata->n_patterns = (o + 1);
+            o = (int)dumbfile_igetl(f);
+            if ((unsigned)o + 5 > c->size)
+                goto error_sd;
+            break;
+
+        case DUMB_ID('I', 'N', 'S', 'T'): {
+            if (c->size < 0xE1)
+                goto error_sd;
+            if (dumbfile_seek(f, c->offset + 1, DFS_SEEK_SET))
+                goto error_sd;
+            o = dumbfile_getc(f);
+            if (o >= sigdata->n_samples)
+                sigdata->n_samples = (int)(o + 1);
+            if (c->size >= 0x121) {
+                if (dumbfile_seek(f, c->offset + 0xE1, DFS_SEEK_SET))
+                    goto error_sd;
+                if (dumbfile_mgetl(f) == DUMB_ID('S', 'A', 'M', 'P')) {
+                    size_t size = dumbfile_igetl(f);
+                    if (size + 0xE1 + 8 > c->size)
+                        goto error_sd;
+                }
+            }
+        } break;
+        }
+    }
+
+    if (found != 3 || !sigdata->n_samples || !sigdata->n_patterns)
+        goto error_sd;
+
+    if (sigdata->n_samples > 255 || sigdata->n_patterns > 255)
+        goto error_sd;
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    sigdata->n_instruments = 0;
+    sigdata->n_orders = 0;
+    sigdata->restart_position = 0;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[n] = 32 - sep;
+        sigdata->channel_pan[n + 1] = 32 + sep;
+        sigdata->channel_pan[n + 2] = 32 + sep;
+        sigdata->channel_pan[n + 3] = 32 - sep;
+    }
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('M', 'A', 'I', 'N'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            dumbfile_getnc((char *)sigdata->name, 64, f);
+            sigdata->name[64] = 0;
+            sigdata->flags =
+                IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M;
+            o = dumbfile_getc(f);
+            if (!(o & 1))
+                sigdata->flags |= IT_LINEAR_SLIDES;
+            if ((o & ~3) || !(o & 2))
+                goto error_usd; // unknown flags
+            sigdata->n_pchannels = dumbfile_getc(f);
+            sigdata->speed = dumbfile_getc(f);
+            sigdata->tempo = dumbfile_getc(f);
+
+            dumbfile_skip(f, 4);
+
+            sigdata->global_volume = dumbfile_getc(f);
+
+            if (c->size < 0x48 + (unsigned)sigdata->n_pchannels)
+                goto error_usd;
+
+            for (o = 0; o < sigdata->n_pchannels; ++o) {
+                p = dumbfile_getc(f);
+                sigdata->channel_pan[o] = p;
+                if (p >= 128) {
+                    sigdata->channel_volume[o] = 0;
+                }
+            }
+            break;
+        }
+    }
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern)
+        goto error_usd;
+    for (n = 0; n < sigdata->n_patterns; ++n)
+        sigdata->pattern[n].entry = NULL;
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample)
+        goto error_usd;
+    for (n = 0; n < sigdata->n_samples; ++n) {
+        IT_SAMPLE *sample = sigdata->sample + n;
+        sample->data = NULL;
+        sample->flags = 0;
+        sample->name[0] = 0;
+    }
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('O', 'R', 'D', 'R'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            sigdata->n_orders = dumbfile_getc(f) + 1;
+            if ((unsigned)sigdata->n_orders + 1 > c->size)
+                goto error_usd;
+            sigdata->order = malloc(sigdata->n_orders);
+            if (!sigdata->order)
+                goto error_usd;
+            dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
+            break;
+
+        case DUMB_ID('P', 'A', 'T', 'T'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            o = dumbfile_getc(f);
+            p = (int)dumbfile_igetl(f);
+            if (it_riff_am_process_pattern(sigdata->pattern + o, f, p, 0))
+                goto error_usd;
+            break;
+
+        case DUMB_ID('I', 'N', 'S', 'T'): {
+            IT_SAMPLE *sample;
+            if (dumbfile_seek(f, c->offset + 1, DFS_SEEK_SET))
+                goto error_usd;
+            sample = sigdata->sample + dumbfile_getc(f);
+            if (c->size >= 0x121) {
+                if (dumbfile_seek(f, c->offset + 0xE1, DFS_SEEK_SET))
+                    goto error_usd;
+                if (dumbfile_mgetl(f) == DUMB_ID('S', 'A', 'M', 'P')) {
+                    size_t size = dumbfile_igetl(f);
+                    if (it_riff_am_process_sample(sample, f, size, 0))
+                        goto error_usd;
+                    break;
+                }
+            }
+            dumbfile_seek(f, c->offset + 2, DFS_SEEK_SET);
+            dumbfile_getnc((char *)sample->name, 28, f);
+            sample->name[28] = 0;
+        } break;
+        }
+    }
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+
+error_usd:
+    _dumb_it_unload_sigdata(sigdata);
+    goto error;
+error_sd:
+    free(sigdata);
+error:
+    return NULL;
+}
+
+static DUMB_IT_SIGDATA *it_riff_am_load_sigdata(DUMBFILE *f,
+                                                struct riff *stream) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    int n, found;
+    int o, p;
+
+    if (!f || !stream)
+        goto error;
+
+    if (stream->type != DUMB_ID('A', 'M', ' ', ' '))
+        goto error;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        goto error;
+
+    sigdata->n_patterns = 0;
+    sigdata->n_samples = 0;
+    sigdata->name[0] = 0;
+
+    found = 0;
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('I', 'N', 'I', 'T'):
+            /* initialization data */
+            if ((found & 1) || (c->size < 0x48))
+                goto error_sd;
+            found |= 1;
+            break;
+
+        case DUMB_ID('O', 'R', 'D', 'R'):
+            if ((found & 2) || (c->size < 1))
+                goto error_sd;
+            found |= 2;
+            break;
+
+        case DUMB_ID('P', 'A', 'T', 'T'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_sd;
+            o = dumbfile_getc(f);
+            if (o >= sigdata->n_patterns)
+                sigdata->n_patterns = (int)(o + 1);
+            o = (int)dumbfile_igetl(f);
+            if ((unsigned)o + 5 > c->size)
+                goto error_sd;
+            break;
+
+        case DUMB_ID('R', 'I', 'F', 'F'): {
+            struct riff *str = c->nested;
+            switch (str->type) {
+            case DUMB_ID('A', 'I', ' ', ' '):
+                for (o = 0; (unsigned)o < str->chunk_count; ++o) {
+                    struct riff_chunk *chk = str->chunks + o;
+                    switch (chk->type) {
+                    case DUMB_ID('I', 'N', 'S', 'T'): {
+                        struct riff *temp;
+                        size_t size;
+                        unsigned sample_found;
+                        if (dumbfile_seek(f, chk->offset, DFS_SEEK_SET))
+                            goto error_sd;
+                        size = dumbfile_igetl(f);
+                        if (size < 0x142)
+                            goto error_sd;
+                        sample_found = 0;
+                        dumbfile_skip(f, 1);
+                        p = dumbfile_getc(f);
+                        if (p >= sigdata->n_samples)
+                            sigdata->n_samples = (int)(p + 1);
+                        temp = riff_parse(f, chk->offset + 4 + size,
+                                          chk->size - size - 4, 1);
+                        if (temp) {
+                            if (temp->type == DUMB_ID('A', 'S', ' ', ' ')) {
+                                for (p = 0; (unsigned)p < temp->chunk_count;
+                                     ++p) {
+                                    if (temp->chunks[p].type ==
+                                        DUMB_ID('S', 'A', 'M', 'P')) {
+                                        if (sample_found) {
+                                            riff_free(temp);
+                                            goto error_sd;
+                                        }
+                                        sample_found = 1;
+                                    }
+                                }
+                            }
+                            riff_free(temp);
+                        }
+                    }
+                    }
+                }
+            }
+        } break;
+        }
+    }
+
+    if (found != 3 || !sigdata->n_samples || !sigdata->n_patterns)
+        goto error_sd;
+
+    if (sigdata->n_samples > 255 || sigdata->n_patterns > 255)
+        goto error_sd;
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    sigdata->n_instruments = 0;
+    sigdata->n_orders = 0;
+    sigdata->restart_position = 0;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[n] = 32 - sep;
+        sigdata->channel_pan[n + 1] = 32 + sep;
+        sigdata->channel_pan[n + 2] = 32 + sep;
+        sigdata->channel_pan[n + 3] = 32 - sep;
+    }
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('I', 'N', 'I', 'T'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            dumbfile_getnc((char *)sigdata->name, 64, f);
+            sigdata->name[64] = 0;
+            sigdata->flags =
+                IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M;
+            o = dumbfile_getc(f);
+            if (!(o & 1))
+                sigdata->flags |= IT_LINEAR_SLIDES;
+            if ((o & ~3) || !(o & 2))
+                goto error_usd; // unknown flags
+            sigdata->n_pchannels = dumbfile_getc(f);
+            sigdata->speed = dumbfile_getc(f);
+            sigdata->tempo = dumbfile_getc(f);
+
+            dumbfile_skip(f, 4);
+
+            sigdata->global_volume = dumbfile_getc(f);
+
+            if (c->size < 0x48 + (unsigned)sigdata->n_pchannels)
+                goto error_usd;
+
+            for (o = 0; o < sigdata->n_pchannels; ++o) {
+                p = dumbfile_getc(f);
+                if (p <= 128) {
+                    sigdata->channel_pan[o] = p / 2;
+                } else {
+                    sigdata->channel_volume[o] = 0;
+                }
+            }
+            break;
+        }
+    }
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern)
+        goto error_usd;
+    for (n = 0; n < sigdata->n_patterns; ++n)
+        sigdata->pattern[n].entry = NULL;
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample)
+        goto error_usd;
+    for (n = 0; n < sigdata->n_samples; ++n) {
+        IT_SAMPLE *sample = sigdata->sample + n;
+        sample->data = NULL;
+        sample->flags = 0;
+        sample->name[0] = 0;
+    }
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('O', 'R', 'D', 'R'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            sigdata->n_orders = dumbfile_getc(f) + 1;
+            if ((unsigned)sigdata->n_orders + 1 > c->size)
+                goto error_usd;
+            sigdata->order = malloc(sigdata->n_orders);
+            if (!sigdata->order)
+                goto error_usd;
+            dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
+            break;
+
+        case DUMB_ID('P', 'A', 'T', 'T'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            o = dumbfile_getc(f);
+            p = (int)dumbfile_igetl(f);
+            if (it_riff_am_process_pattern(sigdata->pattern + o, f, p, 1))
+                goto error_usd;
+            break;
+
+        case DUMB_ID('R', 'I', 'F', 'F'): {
+            struct riff *str = c->nested;
+            switch (str->type) {
+            case DUMB_ID('A', 'I', ' ', ' '):
+                for (o = 0; (unsigned)o < str->chunk_count; ++o) {
+                    struct riff_chunk *chk = str->chunks + o;
+                    switch (chk->type) {
+                    case DUMB_ID('I', 'N', 'S', 'T'): {
+                        struct riff *temp;
+                        size_t size;
+                        unsigned sample_found;
+                        IT_SAMPLE *sample;
+                        if (dumbfile_seek(f, chk->offset, DFS_SEEK_SET))
+                            goto error_usd;
+                        size = dumbfile_igetl(f);
+                        dumbfile_skip(f, 1);
+                        p = dumbfile_getc(f);
+                        temp = riff_parse(f, chk->offset + 4 + size,
+                                          chk->size - size - 4, 1);
+                        sample_found = 0;
+                        sample = sigdata->sample + p;
+                        if (temp) {
+                            if (temp->type == DUMB_ID('A', 'S', ' ', ' ')) {
+                                for (p = 0; (unsigned)p < temp->chunk_count;
+                                     ++p) {
+                                    struct riff_chunk *c = temp->chunks + p;
+                                    if (c->type ==
+                                        DUMB_ID('S', 'A', 'M', 'P')) {
+                                        if (sample_found) {
+                                            riff_free(temp);
+                                            goto error_usd;
+                                        }
+                                        if (dumbfile_seek(f, c->offset,
+                                                          DFS_SEEK_SET)) {
+                                            riff_free(temp);
+                                            goto error_usd;
+                                        }
+                                        if (it_riff_am_process_sample(
+                                                sample, f, c->size, 1)) {
+                                            riff_free(temp);
+                                            goto error_usd;
+                                        }
+                                        sample_found = 1;
+                                    }
+                                }
+                            }
+                            riff_free(temp);
+                        }
+                        if (!sample_found) {
+                            dumbfile_seek(f, chk->offset + 6, DFS_SEEK_SET);
+                            dumbfile_getnc((char *)sample->name, 32, f);
+                            sample->name[32] = 0;
+                        }
+                    }
+                    }
+                }
+            }
+        } break;
+        }
+    }
+
+    _dumb_it_fix_invalid_orders(sigdata);
+
+    return sigdata;
+
+error_usd:
+    _dumb_it_unload_sigdata(sigdata);
+    goto error;
+error_sd:
+    free(sigdata);
+error:
+    return NULL;
+}
+
+DUH *dumb_read_riff_amff(DUMBFILE *f, struct riff *stream) {
+    sigdata_t *sigdata;
+    long length;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_riff_amff_load_sigdata(f, stream);
+
+    if (!sigdata)
+        return NULL;
+
+    length = 0; /*_dumb_it_build_checkpoints(sigdata, 0);*/
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "RIFF AMFF";
+        return make_duh(length, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
+
+DUH *dumb_read_riff_am(DUMBFILE *f, struct riff *stream) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_riff_am_load_sigdata(f, stream);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "RIFF AM";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readamf.c
@@ -1,0 +1,597 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readamf.c - Code to read a DSMI AMF module from    / / \  \
+ *             an open file.                         | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+static void it_amf_process_track(IT_ENTRY *entry_table, unsigned char *track,
+                                 int rows, int channels) {
+    int last_instrument = 0;
+    int tracksize = track[0] + (track[1] << 8) + (track[2] << 16);
+    track += 3;
+    while (tracksize--) {
+        unsigned int row = track[0];
+        unsigned int command = track[1];
+        unsigned int argument = track[2];
+        IT_ENTRY *entry = entry_table + row * channels;
+        if (row >= (unsigned int)rows)
+            break;
+        if (command < 0x7F) {
+            entry->mask |=
+                IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT | IT_ENTRY_VOLPAN;
+            entry->note = command;
+            if (!entry->instrument)
+                entry->instrument = last_instrument;
+            entry->volpan = argument;
+        } else if (command == 0x7F) {
+            signed char row_delta = (signed char)argument;
+            int row_source = (int)row + (int)row_delta;
+            if (row_source >= 0 && row_source < (int)rows) {
+                *entry = entry_table[row_source * channels];
+            }
+        } else if (command == 0x80) {
+            entry->mask |= IT_ENTRY_INSTRUMENT;
+            last_instrument = argument + 1;
+            entry->instrument = last_instrument;
+        } else if (command == 0x83) {
+            entry->mask |= IT_ENTRY_VOLPAN;
+            entry->volpan = argument;
+        } else {
+            unsigned int effect = command & 0x7F;
+            unsigned int effectvalue = argument;
+            switch (effect) {
+            case 0x01:
+                effect = IT_SET_SPEED;
+                break;
+
+            case 0x02:
+                effect = IT_VOLUME_SLIDE;
+            case 0x0A:
+                if (effect == 0x0A)
+                    effect = IT_VOLSLIDE_TONEPORTA;
+            case 0x0B:
+                if (effect == 0x0B)
+                    effect = IT_VOLSLIDE_VIBRATO;
+                if (effectvalue & 0x80)
+                    effectvalue = (-(signed char)effectvalue) & 0x0F;
+                else
+                    effectvalue = (effectvalue & 0x0F) << 4;
+                break;
+
+            case 0x04:
+                if (effectvalue & 0x80) {
+                    effect = IT_PORTAMENTO_UP;
+                    effectvalue = (-(signed char)effectvalue) & 0x7F;
+                } else {
+                    effect = IT_PORTAMENTO_DOWN;
+                }
+                break;
+
+            case 0x06:
+                effect = IT_TONE_PORTAMENTO;
+                break;
+
+            case 0x07:
+                effect = IT_TREMOR;
+                break;
+
+            case 0x08:
+                effect = IT_ARPEGGIO;
+                break;
+
+            case 0x09:
+                effect = IT_VIBRATO;
+                break;
+
+            case 0x0C:
+                effect = IT_BREAK_TO_ROW;
+                break;
+
+            case 0x0D:
+                effect = IT_JUMP_TO_ORDER;
+                break;
+
+            case 0x0F:
+                effect = IT_RETRIGGER_NOTE;
+                break;
+
+            case 0x10:
+                effect = IT_SET_SAMPLE_OFFSET;
+                break;
+
+            case 0x11:
+                if (effectvalue) {
+                    effect = IT_VOLUME_SLIDE;
+                    if (effectvalue & 0x80)
+                        effectvalue =
+                            0xF0 | ((-(signed char)effectvalue) & 0x0F);
+                    else
+                        effectvalue = 0x0F | ((effectvalue & 0x0F) << 4);
+                } else
+                    effect = 0;
+                break;
+
+            case 0x12:
+            case 0x16:
+                if (effectvalue) {
+                    int mask = (effect == 0x16) ? 0xE0 : 0xF0;
+                    effect = (effectvalue & 0x80) ? IT_PORTAMENTO_UP
+                                                  : IT_PORTAMENTO_DOWN;
+                    if (effectvalue & 0x80)
+                        effectvalue =
+                            mask | ((-(signed char)effectvalue) & 0x0F);
+                    else
+                        effectvalue = mask | (effectvalue & 0x0F);
+                } else
+                    effect = 0;
+                break;
+
+            case 0x13:
+                effect = IT_S;
+                effectvalue = EFFECT_VALUE(IT_S_NOTE_DELAY, effectvalue & 0x0F);
+                break;
+
+            case 0x14:
+                effect = IT_S;
+                effectvalue =
+                    EFFECT_VALUE(IT_S_DELAYED_NOTE_CUT, effectvalue & 0x0F);
+                break;
+
+            case 0x15:
+                effect = IT_SET_SONG_TEMPO;
+                break;
+
+            case 0x17:
+                effectvalue = (effectvalue + 64) & 0x7F;
+                if (entry->mask & IT_ENTRY_EFFECT) {
+                    if (!(entry->mask & IT_ENTRY_VOLPAN)) {
+                        entry->mask |= IT_ENTRY_VOLPAN;
+                        entry->volpan = (effectvalue / 2) + 128;
+                    }
+                    effect = 0;
+                } else {
+                    effect = IT_SET_PANNING;
+                }
+                break;
+
+            default:
+                effect = effectvalue = 0;
+            }
+            if (effect) {
+                entry->mask |= IT_ENTRY_EFFECT;
+                entry->effect = effect;
+                entry->effectvalue = effectvalue;
+            }
+        }
+        track += 3;
+    }
+}
+
+static int it_amf_process_pattern(IT_PATTERN *pattern, IT_ENTRY *entry_table,
+                                  int rows, int channels) {
+    int i, j;
+    int n_entries = rows;
+    IT_ENTRY *entry;
+
+    pattern->n_rows = rows;
+
+    for (i = 0, j = channels * rows; i < j; i++) {
+        if (entry_table[i].mask) {
+            n_entries++;
+        }
+    }
+
+    pattern->n_entries = n_entries;
+
+    pattern->entry = entry = malloc(n_entries * sizeof(IT_ENTRY));
+    if (!entry) {
+        return -1;
+    }
+
+    for (i = 0; i < rows; i++) {
+        for (j = 0; j < channels; j++) {
+            if (entry_table[i * channels + j].mask) {
+                *entry = entry_table[i * channels + j];
+                entry->channel = j;
+                entry++;
+            }
+        }
+        IT_SET_END_ROW(entry);
+        entry++;
+    }
+
+    return 0;
+}
+
+static int it_amf_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f,
+                                     int *offset, int ver) {
+    int exists;
+
+    exists = dumbfile_getc(f);
+
+    dumbfile_getnc((char *)sample->name, 32, f);
+    sample->name[32] = 0;
+
+    dumbfile_getnc((char *)sample->filename, 13, f);
+    sample->filename[13] = 0;
+
+    *offset = (int)dumbfile_igetl(f);
+    sample->length = dumbfile_igetl(f);
+    sample->C5_speed = dumbfile_igetw(f);
+    sample->default_volume = dumbfile_getc(f);
+    sample->global_volume = 64;
+    if (sample->default_volume > 64)
+        sample->default_volume = 64;
+
+    if (ver >= 11) {
+        sample->loop_start = dumbfile_igetl(f);
+        sample->loop_end = dumbfile_igetl(f);
+    } else {
+        sample->loop_start = dumbfile_igetw(f);
+        sample->loop_end = sample->length;
+    }
+
+    if (sample->length <= 0) {
+        sample->flags = 0;
+        return 0;
+    }
+
+    sample->flags = exists == 1 ? IT_SAMPLE_EXISTS : 0;
+
+    sample->default_pan = 0;
+    sample->finetune = 0;
+
+    if (sample->loop_end > sample->loop_start + 2 &&
+        sample->loop_end <= sample->length)
+        sample->flags |= IT_SAMPLE_LOOP;
+
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = 0; // do we have to set _all_ these?
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+static int it_amf_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f) {
+    int i, read_length = 0;
+
+    sample->data = malloc(sample->length);
+
+    if (!sample->data)
+        return -1;
+
+    if (sample->length)
+        read_length = (int)dumbfile_getnc(sample->data, sample->length, f);
+
+    if (read_length < 0)
+        read_length = 0;
+
+    for (i = 0; i < read_length; i++) {
+        ((signed char *)sample->data)[i] ^= 0x80;
+    }
+
+    for (i = read_length; i < sample->length; i++) {
+        ((signed char *)sample->data)[i] = 0;
+    }
+
+    return 0; /* Sometimes the last sample is truncated :( */
+}
+
+static DUMB_IT_SIGDATA *it_amf_load_sigdata(DUMBFILE *f, int *version) {
+    DUMB_IT_SIGDATA *sigdata;
+    int i, j, ver, ntracks, realntracks, nchannels;
+
+    int maxsampleseekpos = 0;
+    int sampleseekpos[256];
+
+    unsigned short *orderstotracks;
+    unsigned short *trackmap;
+    unsigned int tracksize[256];
+
+    unsigned char **track;
+
+    static const char sig[] = "AMF";
+
+    char signature[3];
+
+    if (dumbfile_getnc(signature, 3, f) != 3 || memcmp(signature, sig, 3)) {
+        return NULL;
+    }
+
+    *version = ver = dumbfile_getc(f);
+    if (ver < 10 || ver > 14) {
+        return NULL;
+    }
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata) {
+        return NULL;
+    }
+
+    dumbfile_getnc((char *)sigdata->name, 32, f);
+    sigdata->name[32] = 0;
+    sigdata->n_samples = dumbfile_getc(f);
+    sigdata->n_orders = dumbfile_getc(f);
+    ntracks = dumbfile_igetw(f);
+    nchannels = dumbfile_getc(f);
+
+    if (dumbfile_error(f) || sigdata->n_samples < 1 ||
+        sigdata->n_samples > 255 || sigdata->n_orders < 1 ||
+        sigdata->n_orders > 255 || !ntracks || nchannels < 1 ||
+        nchannels > 32) {
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->n_pchannels = nchannels;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    if (ver >= 11) {
+        int nchannels = (ver >= 13) ? 32 : 16;
+        for (i = 0; i < nchannels; i++) {
+            signed char panpos = dumbfile_getc(f);
+            int pan = (panpos + 64) / 2;
+            if (pan < 0)
+                pan = 0;
+            else if (pan > 64)
+                pan = IT_SURROUND;
+            sigdata->channel_pan[i] = pan;
+        }
+    } else {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        for (i = 0; i < 16; i++) {
+            sigdata->channel_pan[i] =
+                (dumbfile_getc(f) & 1) ? 32 - sep : 32 + sep;
+        }
+    }
+
+    sigdata->tempo = 125;
+    sigdata->speed = 6;
+    if (ver >= 13) {
+        i = dumbfile_getc(f);
+        if (i >= 32)
+            sigdata->tempo = i;
+        i = dumbfile_getc(f);
+        if (i <= 32)
+            sigdata->speed = i;
+    }
+
+    sigdata->order = malloc(sigdata->n_orders);
+    if (!sigdata->order) {
+        free(sigdata);
+        return NULL;
+    }
+
+    orderstotracks =
+        malloc(sigdata->n_orders * nchannels * sizeof(unsigned short));
+    if (!orderstotracks) {
+        free(sigdata->order);
+        free(sigdata);
+        return NULL;
+    }
+
+    for (i = 0; i < sigdata->n_orders; i++) {
+        sigdata->order[i] = i;
+        tracksize[i] = 64;
+        if (ver >= 14) {
+            tracksize[i] = dumbfile_igetw(f);
+        }
+        for (j = 0; j < nchannels; j++) {
+            orderstotracks[i * nchannels + j] = dumbfile_igetw(f);
+        }
+    }
+
+    if (dumbfile_error(f)) {
+        free(orderstotracks);
+        free(sigdata->order);
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample) {
+        free(orderstotracks);
+        free(sigdata->order);
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->restart_position = 0;
+
+    sigdata->song_message = NULL;
+    sigdata->instrument = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+
+    for (i = 0; i < sigdata->n_samples; ++i)
+        sigdata->sample[i].data = NULL;
+
+    for (i = 0; i < sigdata->n_samples; ++i) {
+        int offset;
+        if (it_amf_read_sample_header(&sigdata->sample[i], f, &offset, ver)) {
+            goto error_ott;
+        }
+        sampleseekpos[i] = offset;
+        if (offset > maxsampleseekpos)
+            maxsampleseekpos = offset;
+    }
+
+    sigdata->n_patterns = sigdata->n_orders;
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern) {
+        goto error_ott;
+    }
+    for (i = 0; i < sigdata->n_patterns; ++i)
+        sigdata->pattern[i].entry = NULL;
+
+    trackmap = malloc(ntracks * sizeof(unsigned short));
+    if (!trackmap) {
+        goto error_ott;
+    }
+
+    if (dumbfile_getnc((char *)trackmap, ntracks * sizeof(unsigned short), f) !=
+        (long)(ntracks * sizeof(unsigned short))) {
+        goto error_tm;
+    }
+
+    realntracks = 0;
+
+    for (i = 0; i < ntracks; i++) {
+        if (trackmap[i] > realntracks)
+            realntracks = trackmap[i];
+    }
+
+    track = calloc(realntracks, sizeof(unsigned char *));
+    if (!track) {
+        goto error_tm;
+    }
+
+    for (i = 0; i < realntracks; i++) {
+        int tracksize = dumbfile_igetw(f);
+        tracksize += dumbfile_getc(f) << 16;
+        track[i] = malloc(tracksize * 3 + 3);
+        if (!track[i]) {
+            goto error_all;
+        }
+        track[i][0] = tracksize & 255;
+        track[i][1] = (tracksize >> 8) & 255;
+        track[i][2] = (tracksize >> 16) & 255;
+        if (dumbfile_getnc((char *)track[i] + 3, tracksize * 3, f) !=
+            tracksize * 3) {
+            goto error_all;
+        }
+    }
+
+    for (i = 1; i <= maxsampleseekpos; i++) {
+        for (j = 0; j < sigdata->n_samples; j++) {
+            if (sampleseekpos[j] == i) {
+                if (it_amf_read_sample_data(&sigdata->sample[j], f)) {
+                    goto error_all;
+                }
+                break;
+            }
+        }
+    }
+
+    /* Process tracks into patterns */
+    for (i = 0; i < sigdata->n_patterns; i++) {
+        IT_ENTRY *entry_table =
+            calloc(tracksize[i] * nchannels, sizeof(IT_ENTRY));
+        if (!entry_table) {
+            goto error_all;
+        }
+        for (j = 0; j < nchannels; j++) {
+            int ntrack = orderstotracks[i * nchannels + j];
+            if (ntrack && ntrack <= ntracks) {
+                int realtrack = trackmap[ntrack - 1];
+                if (realtrack) {
+                    realtrack--;
+                    if (realtrack < realntracks && track[realtrack]) {
+                        it_amf_process_track(entry_table + j, track[realtrack],
+                                             tracksize[i], nchannels);
+                    }
+                }
+            }
+        }
+        if (it_amf_process_pattern(&sigdata->pattern[i], entry_table,
+                                   tracksize[i], nchannels)) {
+            free(entry_table);
+            goto error_all;
+        }
+        free(entry_table);
+    }
+
+    /* Now let's initialise the remaining variables, and we're done! */
+    sigdata->flags =
+        IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_STEREO | IT_WAS_AN_S3M;
+
+    sigdata->global_volume = 128;
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    for (i = 0; i < realntracks; i++) {
+        if (track[i]) {
+            free(track[i]);
+        }
+    }
+    free(track);
+    free(trackmap);
+    free(orderstotracks);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+
+error_all:
+    for (i = 0; i < realntracks; i++) {
+        if (track[i]) {
+            free(track[i]);
+        }
+    }
+    free(track);
+error_tm:
+    free(trackmap);
+error_ott:
+    free(orderstotracks);
+    _dumb_it_unload_sigdata(sigdata);
+    return NULL;
+}
+
+DUH *dumb_read_amf_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    int version;
+
+    sigdata = it_amf_load_sigdata(f, &version);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        char ver_string[14];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        memcpy(ver_string, "DSMI AMF v", 10);
+        ver_string[10] = '0' + version / 10;
+        ver_string[11] = '.';
+        ver_string[12] = '0' + version % 10;
+        ver_string[13] = 0;
+        tag[1][1] = ver_string;
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readamf2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readamf2.c - Function to read a DSMI AMF module    / / \  \
+ *              from an open file and do an initial  | <  /   \_
+ *              run-through.                         |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_amf(DUMBFILE *f) {
+    DUH *duh = dumb_read_amf_quick(f);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/readany.c
@@ -1,0 +1,103 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readany.c - Code to detect and read any of the     / / \  \
+ *             module formats supported by DUMB.     | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+
+#ifdef _MSC_VER
+#define strnicmp _strnicmp
+#else
+#if defined(unix) || defined(__unix__) || defined(__unix)
+#include <strings.h>
+#endif
+#define strnicmp strncasecmp
+#endif
+
+enum { maximum_signature_size = 0x30 };
+
+DUH *dumb_read_any_quick(DUMBFILE *f, int restrict_, int subsong) {
+    unsigned char signature[maximum_signature_size];
+    unsigned long signature_size;
+    DUH *duh = NULL;
+
+    /* signature_size = dumbfile_get_size(f); */
+
+    signature_size =
+        dumbfile_getnc((char *)signature, maximum_signature_size, f);
+    dumbfile_seek(f, 0, DFS_SEEK_SET);
+
+    if (signature_size >= 4 && signature[0] == 'I' && signature[1] == 'M' &&
+        signature[2] == 'P' && signature[3] == 'M') {
+        duh = dumb_read_it_quick(f);
+    } else if (signature_size >= 17 &&
+               !memcmp(signature, "Extended Module: ", 17)) {
+        duh = dumb_read_xm_quick(f);
+    } else if (signature_size >= 0x30 && signature[0x2C] == 'S' &&
+               signature[0x2D] == 'C' && signature[0x2E] == 'R' &&
+               signature[0x2F] == 'M') {
+        duh = dumb_read_s3m_quick(f);
+    } else if (signature_size >= 30 &&
+               /*signature[28] == 0x1A &&*/ signature[29] == 2 &&
+               (!strnicmp((const char *)signature + 20, "!Scream!", 8) ||
+                !strnicmp((const char *)signature + 20, "BMOD2STM", 8) ||
+                !strnicmp((const char *)signature + 20, "WUZAMOD!", 8))) {
+        duh = dumb_read_stm_quick(f);
+    } else if (signature_size >= 2 &&
+               ((signature[0] == 0x69 && signature[1] == 0x66) ||
+                (signature[0] == 0x4A && signature[1] == 0x4E))) {
+        duh = dumb_read_669_quick(f);
+    } else if (signature_size >= 0x30 && signature[0x2C] == 'P' &&
+               signature[0x2D] == 'T' && signature[0x2E] == 'M' &&
+               signature[0x2F] == 'F') {
+        duh = dumb_read_ptm_quick(f);
+    } else if (signature_size >= 4 && signature[0] == 'P' &&
+               signature[1] == 'S' && signature[2] == 'M' &&
+               signature[3] == ' ') {
+        duh = dumb_read_psm_quick(f, subsong);
+    } else if (signature_size >= 4 && signature[0] == 'P' &&
+               signature[1] == 'S' && signature[2] == 'M' &&
+               signature[3] == 254) {
+        duh = dumb_read_old_psm_quick(f);
+    } else if (signature_size >= 3 && signature[0] == 'M' &&
+               signature[1] == 'T' && signature[2] == 'M') {
+        duh = dumb_read_mtm_quick(f);
+    } else if (signature_size >= 4 && signature[0] == 'R' &&
+               signature[1] == 'I' && signature[2] == 'F' &&
+               signature[3] == 'F') {
+        duh = dumb_read_riff_quick(f);
+    } else if (signature_size >= 24 &&
+               !memcmp(signature, "ASYLUM Music Format", 19) &&
+               !memcmp(signature + 19, " V1.0", 5)) {
+        duh = dumb_read_asy_quick(f);
+    } else if (signature_size >= 3 && signature[0] == 'A' &&
+               signature[1] == 'M' && signature[2] == 'F') {
+        duh = dumb_read_amf_quick(f);
+    } else if (signature_size >= 8 && !memcmp(signature, "OKTASONG", 8)) {
+        duh = dumb_read_okt_quick(f);
+    }
+
+    if (!duh) {
+        dumbfile_seek(f, 0, DFS_SEEK_SET);
+        duh = dumb_read_mod_quick(f, restrict_);
+    }
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/readany2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readany2.c - Code to detect and read any of the    / / \  \
+ *              module formats supported by DUMB     | <  /   \_
+ *              from an open file and do an initial  |  \/ /\   /
+ *              run-through.                          \_  /  > /
+ *                                                      | \ / /
+ * by Christopher Snowhill.                             |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_any(DUMBFILE *f, int restrict_, int subsong) {
+    DUH *duh = dumb_read_any_quick(f, restrict_, subsong);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/readasy.c
@@ -1,0 +1,344 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readasy.c - Code to read an ASYLUM Music Format    / / \  \
+ *             module from an open file.             | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+static int it_asy_read_pattern(IT_PATTERN *pattern, DUMBFILE *f,
+                               unsigned char *buffer) {
+    int pos;
+    int channel;
+    int row;
+    IT_ENTRY *entry;
+
+    pattern->n_rows = 64;
+
+    if (dumbfile_getnc((char *)buffer, 64 * 8 * 4, f) != 64 * 8 * 4)
+        return -1;
+
+    /* compute number of entries */
+    pattern->n_entries = 64; /* Account for the row end markers */
+    pos = 0;
+    for (row = 0; row < 64; ++row) {
+        for (channel = 0; channel < 8; ++channel) {
+            if (buffer[pos + 0] | buffer[pos + 1] | buffer[pos + 2] |
+                buffer[pos + 3])
+                ++pattern->n_entries;
+            pos += 4;
+        }
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+    pos = 0;
+    for (row = 0; row < 64; ++row) {
+        for (channel = 0; channel < 8; ++channel) {
+            if (buffer[pos + 0] | buffer[pos + 1] | buffer[pos + 2] |
+                buffer[pos + 3]) {
+                entry->channel = channel;
+                entry->mask = 0;
+
+                if (buffer[pos + 0] && buffer[pos + 0] < 96) {
+                    entry->note = buffer[pos + 0];
+                    entry->mask |= IT_ENTRY_NOTE;
+                }
+
+                if (buffer[pos + 1] && buffer[pos + 1] <= 64) {
+                    entry->instrument = buffer[pos + 1];
+                    entry->mask |= IT_ENTRY_INSTRUMENT;
+                }
+
+                _dumb_it_xm_convert_effect(buffer[pos + 2], buffer[pos + 3],
+                                           entry, 1);
+
+                // fixup
+                switch (entry->effect) {
+                case IT_SET_PANNING:
+                    entry->effectvalue <<= 1;
+                    break;
+                }
+
+                if (entry->mask)
+                    ++entry;
+            }
+            pos += 4;
+        }
+        IT_SET_END_ROW(entry);
+        ++entry;
+    }
+
+    pattern->n_entries = (int)(entry - pattern->entry);
+
+    return 0;
+}
+
+static int it_asy_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f) {
+    int finetune, key_offset;
+
+    /**
+         21       22   Chars     Sample 1 name.  If the name is not a full
+                                 22 chars in length, it will be null
+                                 terminated.
+
+    If
+    the sample name begins with a '#' character (ASCII $23 (35)) then this is
+    assumed not to be an instrument name, and is probably a message.
+    */
+    dumbfile_getnc((char *)sample->name, 22, f);
+    sample->name[22] = 0;
+
+    sample->filename[0] = 0;
+
+    /** Each  finetune step changes  the note 1/8th  of  a  semitone. */
+    finetune = (signed char)(dumbfile_getc(f) << 4) >> 4; /* signed nibble */
+    sample->default_volume =
+        dumbfile_getc(f); // Should we be setting global_volume to this instead?
+    sample->global_volume = 64;
+    if (sample->default_volume > 64)
+        sample->default_volume = 64;
+    key_offset = (signed char)dumbfile_getc(f); /* base key offset */
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = sample->loop_start + dumbfile_igetl(f);
+
+    if (sample->length <= 0) {
+        sample->flags = 0;
+        return 0;
+    }
+
+    sample->flags = IT_SAMPLE_EXISTS;
+
+    sample->default_pan = 0;
+    sample->C5_speed =
+        (int)(AMIGA_CLOCK / 214.0 *
+              pow(DUMB_SEMITONE_BASE, key_offset)); //( long )( 16726.0 * pow(
+                                                    // DUMB_PITCH_BASE, finetune
+                                                    //* 32 ) );
+    sample->finetune = finetune * 32;
+    // the above line might be wrong
+
+    if ((sample->loop_end - sample->loop_start > 2) &&
+        (sample->loop_end <= sample->length))
+        sample->flags |= IT_SAMPLE_LOOP;
+
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = 0; // do we have to set _all_ these?
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+static int it_asy_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f) {
+    long truncated_size;
+
+    /* let's get rid of the sample data coming after the end of the loop */
+    if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length) {
+        truncated_size = sample->length - sample->loop_end;
+        sample->length = sample->loop_end;
+    } else {
+        truncated_size = 0;
+    }
+
+    sample->data = malloc(sample->length);
+
+    if (!sample->data)
+        return -1;
+
+    if (sample->length)
+        dumbfile_getnc(sample->data, sample->length, f);
+
+    dumbfile_skip(f, truncated_size);
+
+    return dumbfile_error(f);
+}
+
+static DUMB_IT_SIGDATA *it_asy_load_sigdata(DUMBFILE *f) {
+    DUMB_IT_SIGDATA *sigdata;
+    int i;
+
+    static const char sig_part[] = "ASYLUM Music Format";
+    static const char sig_rest[] =
+        " V1.0"; /* whee, string space optimization with format type below */
+
+    char signature[32];
+
+    if (dumbfile_getnc(signature, 32, f) != 32 ||
+        memcmp(signature, sig_part, 19) ||
+        memcmp(signature + 19, sig_rest, 5)) {
+        return NULL;
+    }
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata) {
+        return NULL;
+    }
+
+    sigdata->speed = dumbfile_getc(f); /* XXX seems to fit the files I have */
+    sigdata->tempo = dumbfile_getc(f); /* ditto */
+    sigdata->n_samples = dumbfile_getc(f); /* ditto */
+    sigdata->n_patterns = dumbfile_getc(f);
+    sigdata->n_orders = dumbfile_getc(f);
+    sigdata->restart_position = dumbfile_getc(f);
+
+    if (dumbfile_error(f) || !sigdata->n_samples || sigdata->n_samples > 64 ||
+        !sigdata->n_patterns || !sigdata->n_orders) {
+        free(sigdata);
+        return NULL;
+    }
+
+    if (sigdata->restart_position > sigdata->n_orders) /* XXX */
+        sigdata->restart_position = 0;
+
+    sigdata->order = malloc(sigdata->n_orders);
+    if (!sigdata->order) {
+        free(sigdata);
+        return NULL;
+    }
+
+    if (dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f) !=
+            sigdata->n_orders ||
+        dumbfile_skip(f, 256 - sigdata->n_orders)) {
+        free(sigdata->order);
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample) {
+        free(sigdata->order);
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->song_message = NULL;
+    sigdata->instrument = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+
+    for (i = 0; i < sigdata->n_samples; ++i)
+        sigdata->sample[i].data = NULL;
+
+    for (i = 0; i < sigdata->n_samples; ++i) {
+        if (it_asy_read_sample_header(&sigdata->sample[i], f)) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    if (dumbfile_skip(f, 37 * (64 - sigdata->n_samples))) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    for (i = 0; i < sigdata->n_patterns; ++i)
+        sigdata->pattern[i].entry = NULL;
+
+    /* Read in the patterns */
+    {
+        unsigned char *buffer =
+            malloc(64 * 8 * 4); /* 64 rows * 8 channels * 4 bytes */
+        if (!buffer) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (i = 0; i < sigdata->n_patterns; ++i) {
+            if (it_asy_read_pattern(&sigdata->pattern[i], f, buffer) != 0) {
+                free(buffer);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+        }
+        free(buffer);
+    }
+
+    /* And finally, the sample data */
+    for (i = 0; i < sigdata->n_samples; ++i) {
+        if (it_asy_read_sample_data(&sigdata->sample[i], f)) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    /* Now let's initialise the remaining variables, and we're done! */
+    sigdata->flags = IT_WAS_AN_XM | IT_WAS_A_MOD | IT_OLD_EFFECTS |
+                     IT_COMPATIBLE_GXX | IT_STEREO;
+
+    sigdata->global_volume = 128;
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    sigdata->n_pchannels = 8;
+
+    sigdata->name[0] = 0;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[i + 0] = 32 - sep;
+        sigdata->channel_pan[i + 1] = 32 + sep;
+        sigdata->channel_pan[i + 2] = 32 + sep;
+        sigdata->channel_pan[i + 3] = 32 - sep;
+    }
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+DUH *dumb_read_asy_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_asy_load_sigdata(f);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "ASYLUM Music Format";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readdsmf.c
@@ -1,0 +1,395 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readam.c - Code to read a RIFF DSMF module         / / \  \
+ *             from a parsed RIFF structure.         | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+#include "internal/riff.h"
+
+static int it_riff_dsmf_process_sample(IT_SAMPLE *sample, DUMBFILE *f,
+                                       int len) {
+    int flags;
+
+    dumbfile_getnc((char *)sample->filename, 13, f);
+    sample->filename[14] = 0;
+
+    flags = dumbfile_igetw(f);
+    sample->default_volume = dumbfile_getc(f);
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = dumbfile_igetl(f);
+    dumbfile_skip(f, 32 - 28);
+    sample->C5_speed = dumbfile_igetw(f) * 2;
+    dumbfile_skip(f, 36 - 34);
+    dumbfile_getnc((char *)sample->name, 28, f);
+    sample->name[28] = 0;
+
+    /*if ( data[ 0x38 ] || data[ 0x39 ] || data[ 0x3A ] || data[ 0x3B ] )
+            return -1;*/
+
+    if (!sample->length) {
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+        return 0;
+    }
+
+    /*if ( flags & ~( 2 | 1 ) )
+            return -1;*/
+
+    if (sample->length + 64 > len)
+        return -1;
+
+    sample->flags = IT_SAMPLE_EXISTS;
+
+    sample->default_pan = 0;
+    sample->global_volume = 64;
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = IT_VIBRATO_SINE;
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    if (flags & 1) {
+        if (((unsigned int)sample->loop_end <= (unsigned int)sample->length) &&
+            ((unsigned int)sample->loop_start <
+             (unsigned int)sample->loop_end)) {
+            sample->length = sample->loop_end;
+            sample->flags |= IT_SAMPLE_LOOP;
+            if (flags & 0x10)
+                sample->flags |= IT_SAMPLE_PINGPONG_LOOP;
+        }
+    }
+
+    sample->data = malloc(sample->length);
+    if (!sample->data)
+        return -1;
+
+    dumbfile_getnc(sample->data, sample->length, f);
+
+    if (!(flags & 2)) {
+        for (flags = 0; flags < sample->length; ++flags)
+            ((signed char *)sample->data)[flags] ^= 0x80;
+    }
+
+    return 0;
+}
+
+static int it_riff_dsmf_process_pattern(IT_PATTERN *pattern, DUMBFILE *f,
+                                        int len) {
+    int length, row;
+    unsigned flags;
+    long start, end;
+    int p, q, r;
+    IT_ENTRY *entry;
+
+    length = dumbfile_igetw(f);
+    if (length > len)
+        return -1;
+
+    len = length - 2;
+
+    pattern->n_rows = 64;
+    pattern->n_entries = 64;
+
+    row = 0;
+
+    start = dumbfile_pos(f);
+    end = start + len;
+
+    while ((row < 64) && !dumbfile_error(f) && (dumbfile_pos(f) < end)) {
+        p = dumbfile_getc(f);
+        if (!p) {
+            ++row;
+            continue;
+        }
+
+        flags = p & 0xF0;
+
+        if (flags) {
+            ++pattern->n_entries;
+            if (flags & 0x80)
+                dumbfile_skip(f, 1);
+            if (flags & 0x40)
+                dumbfile_skip(f, 1);
+            if (flags & 0x20)
+                dumbfile_skip(f, 1);
+            if (flags & 0x10)
+                dumbfile_skip(f, 2);
+        }
+    }
+
+    if (pattern->n_entries == 64)
+        return 0;
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+
+    row = 0;
+
+    if (dumbfile_seek(f, start, DFS_SEEK_SET))
+        return -1;
+
+    while ((row < 64) && !dumbfile_error(f) && (dumbfile_pos(f) < end)) {
+        p = dumbfile_getc(f);
+        if (!p) {
+            IT_SET_END_ROW(entry);
+            ++entry;
+            ++row;
+            continue;
+        }
+
+        flags = p;
+        entry->channel = flags & 0x0F;
+        entry->mask = 0;
+
+        if (flags & 0xF0) {
+            if (flags & 0x80) {
+                q = dumbfile_getc(f);
+                if (q) {
+                    entry->mask |= IT_ENTRY_NOTE;
+                    entry->note = q - 1;
+                }
+            }
+
+            if (flags & 0x40) {
+                q = dumbfile_getc(f);
+                if (q) {
+                    entry->mask |= IT_ENTRY_INSTRUMENT;
+                    entry->instrument = q;
+                }
+            }
+
+            if (flags & 0x20) {
+                entry->mask |= IT_ENTRY_VOLPAN;
+                entry->volpan = dumbfile_getc(f);
+            }
+
+            if (flags & 0x10) {
+                q = dumbfile_getc(f);
+                r = dumbfile_getc(f);
+                _dumb_it_xm_convert_effect(q, r, entry, 0);
+            }
+
+            if (entry->mask)
+                entry++;
+        }
+    }
+
+    while (row < 64) {
+        IT_SET_END_ROW(entry);
+        ++entry;
+        ++row;
+    }
+
+    pattern->n_entries = (int)((long)entry - (long)pattern->entry);
+    if (!pattern->n_entries)
+        return -1;
+
+    return 0;
+}
+
+static DUMB_IT_SIGDATA *it_riff_dsmf_load_sigdata(DUMBFILE *f,
+                                                  struct riff *stream) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    int n, o, found;
+
+    if (!stream)
+        goto error;
+
+    if (stream->type != DUMB_ID('D', 'S', 'M', 'F'))
+        goto error;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        goto error;
+
+    sigdata->n_patterns = 0;
+    sigdata->n_samples = 0;
+    sigdata->name[0] = 0;
+
+    found = 0;
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('S', 'O', 'N', 'G'):
+            /* initialization data */
+            if ((found) || (c->size < 192))
+                goto error_sd;
+            found = 1;
+            break;
+
+        case DUMB_ID('P', 'A', 'T', 'T'):
+            ++sigdata->n_patterns;
+            break;
+
+        case DUMB_ID('I', 'N', 'S', 'T'):
+            ++sigdata->n_samples;
+            break;
+        }
+    }
+
+    if (!found || !sigdata->n_samples || !sigdata->n_patterns)
+        goto error_sd;
+
+    if (sigdata->n_samples > 255 || sigdata->n_patterns > 255)
+        goto error_sd;
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    sigdata->n_instruments = 0;
+    sigdata->n_orders = 0;
+    sigdata->restart_position = 0;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[n] = 32 - sep;
+        sigdata->channel_pan[n + 1] = 32 + sep;
+        sigdata->channel_pan[n + 2] = 32 + sep;
+        sigdata->channel_pan[n + 3] = 32 - sep;
+    }
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('S', 'O', 'N', 'G'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            dumbfile_getnc((char *)sigdata->name, 28, f);
+            sigdata->name[28] = 0;
+            sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX;
+            dumbfile_skip(f, 36 - 28);
+            sigdata->n_orders = dumbfile_igetw(f);
+            if (sigdata->n_orders > 1024) // Whoa, nelly.
+                goto error_usd;
+            // sigdata->n_samples = ptr[ 38 ] | ( ptr[ 39 ] << 8 ); // whatever
+            // sigdata->n_patterns = ptr[ 40 ] | ( ptr[ 41 ] << 8 );
+            dumbfile_skip(f, 42 - 38);
+            sigdata->n_pchannels = dumbfile_igetw(f);
+            sigdata->global_volume = dumbfile_getc(f);
+            sigdata->mixing_volume = dumbfile_getc(f);
+            sigdata->speed = dumbfile_getc(f);
+            sigdata->tempo = dumbfile_getc(f);
+
+            for (o = 0; o < 16; ++o) {
+                sigdata->channel_pan[o] = dumbfile_getc(f) / 2;
+            }
+
+            sigdata->order = malloc(128);
+            if (!sigdata->order)
+                goto error_usd;
+            dumbfile_getnc((char *)sigdata->order, 128, f);
+
+            break;
+        }
+    }
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern)
+        goto error_usd;
+    for (n = 0; n < sigdata->n_patterns; ++n)
+        sigdata->pattern[n].entry = NULL;
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample)
+        goto error_usd;
+    for (n = 0; n < sigdata->n_samples; ++n) {
+        IT_SAMPLE *sample = sigdata->sample + n;
+        sample->data = NULL;
+    }
+
+    sigdata->n_samples = 0;
+    sigdata->n_patterns = 0;
+
+    for (n = 0; (unsigned)n < stream->chunk_count; ++n) {
+        struct riff_chunk *c = stream->chunks + n;
+        switch (c->type) {
+        case DUMB_ID('P', 'A', 'T', 'T'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            if (it_riff_dsmf_process_pattern(
+                    sigdata->pattern + sigdata->n_patterns, f, c->size))
+                goto error_usd;
+            ++sigdata->n_patterns;
+            break;
+
+        case DUMB_ID('I', 'N', 'S', 'T'):
+            if (dumbfile_seek(f, c->offset, DFS_SEEK_SET))
+                goto error_usd;
+            if (it_riff_dsmf_process_sample(
+                    sigdata->sample + sigdata->n_samples, f, c->size))
+                goto error_usd;
+            ++sigdata->n_samples;
+            break;
+        }
+    }
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+
+error_usd:
+    _dumb_it_unload_sigdata(sigdata);
+    goto error;
+error_sd:
+    free(sigdata);
+error:
+    return NULL;
+}
+
+DUH *dumb_read_riff_dsmf(DUMBFILE *f, struct riff *stream) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_riff_dsmf_load_sigdata(f, stream);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "RIFF DSMF";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readmod.c
@@ -1,0 +1,651 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readmod.c - Code to read a good old-fashioned      / / \  \
+ *             Amiga module from an open file.       | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/dumb.h"
+#include "internal/it.h"
+
+static int it_mod_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, int n_channels,
+                               unsigned char *buffer) {
+    int pos;
+    int channel;
+    int row;
+    IT_ENTRY *entry;
+
+    pattern->n_rows = 64;
+
+    if (n_channels == 0) {
+        /* Read the first four channels, leaving gaps for the rest. */
+        for (pos = 0; pos < 64 * 8 * 4; pos += 8 * 4)
+            dumbfile_getnc((char *)buffer + pos, 4 * 4, f);
+        /* Read the other channels into the gaps we left. */
+        for (pos = 4 * 4; pos < 64 * 8 * 4; pos += 8 * 4)
+            dumbfile_getnc((char *)buffer + pos, 4 * 4, f);
+
+        n_channels = 8;
+    } else
+        dumbfile_getnc((char *)buffer, 64 * n_channels * 4, f);
+
+    if (dumbfile_error(f))
+        return -1;
+
+    /* compute number of entries */
+    pattern->n_entries = 64; /* Account for the row end markers */
+    pos = 0;
+    for (row = 0; row < 64; row++) {
+        for (channel = 0; channel < n_channels; channel++) {
+            if (buffer[pos + 0] | buffer[pos + 1] | buffer[pos + 2] |
+                buffer[pos + 3])
+                pattern->n_entries++;
+            pos += 4;
+        }
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+    pos = 0;
+    for (row = 0; row < 64; row++) {
+        for (channel = 0; channel < n_channels; channel++) {
+            if (buffer[pos + 0] | buffer[pos + 1] | buffer[pos + 2] |
+                buffer[pos + 3]) {
+                unsigned char sample =
+                    (buffer[pos + 0] & 0xF0) | (buffer[pos + 2] >> 4);
+                int period =
+                    ((int)(buffer[pos + 0] & 0x0F) << 8) | buffer[pos + 1];
+
+                entry->channel = channel;
+                entry->mask = 0;
+
+                if (period) {
+                    int note;
+                    entry->mask |= IT_ENTRY_NOTE;
+
+                    /* frequency = (AMIGA_DIVISOR / 8) / (period * 2)
+                     * C-1: period = 214 -> frequency = 16726
+                     * so, set C5_speed to 16726
+                     * and period = 214 should translate to C5 aka 60
+                     * halve the period, go up an octive
+                     *
+                     * period = 214 / pow(DUMB_SEMITONE_BASE, note - 60)
+                     * pow(DUMB_SEMITONE_BASE, note - 60) = 214 / period
+                     * note - 60 = log(214/period) / log(DUMB_SEMITONE_BASE)
+                     */
+                    note = (int)floor(
+                        log(214.0 / period) / log(DUMB_SEMITONE_BASE) + 60.5);
+                    entry->note = MID(0, note, 119);
+                    // or should we preserve the period?
+                    // entry->note = buffer[pos+0] & 0x0F; /* High nibble */
+                    // entry->volpan = buffer[pos+1]; /* Low byte */
+                    // and what about finetune?
+                }
+
+                if (sample) {
+                    entry->mask |= IT_ENTRY_INSTRUMENT;
+                    entry->instrument = sample;
+                }
+
+                _dumb_it_xm_convert_effect(buffer[pos + 2] & 0x0F,
+                                           buffer[pos + 3], entry, 1);
+
+                entry++;
+            }
+            pos += 4;
+        }
+        IT_SET_END_ROW(entry);
+        entry++;
+    }
+
+    return 0;
+}
+
+static int it_mod_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f,
+                                     unsigned long fft, int stk) {
+    int finetune, loop_start, loop_length;
+
+    /**
+         21       22   Chars     Sample 1 name.  If the name is not a full
+                                 22 chars in length, it will be null
+                                 terminated.
+
+    If
+    the sample name begins with a '#' character (ASCII $23 (35)) then this is
+    assumed not to be an instrument name, and is probably a message.
+    */
+    dumbfile_getnc((char *)sample->name, 22, f);
+    sample->name[22] = 0;
+
+    sample->filename[0] = 0;
+
+    sample->length = dumbfile_mgetw(f) << 1;
+    if (fft == DUMB_ID('F', 'E', 'S', 'T'))
+        finetune = (signed char)((-dumbfile_getc(f) & 0x1F) << 3) >> 3;
+    else
+        finetune =
+            (signed char)(dumbfile_getc(f) << 4) >> 4; /* signed nibble */
+    /** Each  finetune step changes  the note 1/8th  of  a  semitone. */
+    sample->global_volume = 64;
+    sample->default_volume =
+        dumbfile_getc(f); // Should we be setting global_volume to this instead?
+    loop_start = dumbfile_mgetw(f);
+    if (!stk)
+        loop_start <<= 1;
+    loop_length = dumbfile_mgetw(f) << 1;
+    if (loop_length > 2 && loop_start + loop_length > sample->length &&
+        loop_start / 2 + loop_length <= sample->length)
+        loop_start /= 2;
+    sample->loop_start = loop_start;
+    sample->loop_end = loop_start + loop_length;
+    /**
+    Once this sample has been played completely from beginning
+    to end, if the  repeat length (next field)  is greater than two  bytes it
+    will loop back to this position in the sample and continue playing.  Once
+    it has played for  the repeat length,  it continues to  loop back to  the
+    repeat start offset.  This means the sample continues playing until it is
+    told to stop.
+    */
+
+    if (sample->length <= 0) {
+        sample->flags = 0;
+        return 0;
+    }
+
+    sample->flags = IT_SAMPLE_EXISTS;
+
+    sample->default_pan = 0;
+    sample->C5_speed =
+        (int)(AMIGA_CLOCK /
+              214.0); //(long)(16726.0*pow(DUMB_PITCH_BASE, finetune*32));
+    sample->finetune =
+        finetune * ((fft == DUMB_ID('F', 'E', 'S', 'T')) ? 16 : 32);
+    // the above line might be wrong
+
+    if (sample->loop_end > sample->length)
+        sample->loop_end = sample->length;
+
+    if (sample->loop_end - sample->loop_start > 2)
+        sample->flags |= IT_SAMPLE_LOOP;
+
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = 0; // do we have to set _all_ these?
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+static int it_mod_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f,
+                                   unsigned long fft) {
+    long i;
+    long truncated_size;
+
+    /* let's get rid of the sample data coming after the end of the loop */
+    if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length) {
+        truncated_size = sample->length - sample->loop_end;
+        sample->length = sample->loop_end;
+    } else {
+        truncated_size = 0;
+    }
+
+    if (sample->length) {
+        sample->data = malloc(sample->length);
+
+        if (!sample->data)
+            return -1;
+
+        /* Sample data are stored in "8-bit two's compliment format" (sic). */
+        /*
+        for (i = 0; i < sample->length; i++)
+                ((signed char *)sample->left)[i] = dumbfile_getc(f);
+        */
+        /* F U Olivier Lapicque */
+        if (sample->length >= 5) {
+            i = dumbfile_getnc(sample->data, 5, f);
+            if (i == 5) {
+                if (!memcmp(sample->data, "ADPCM", 5)) {
+                    if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
+                        return -1;
+
+                    return 0;
+                } else {
+                    i += dumbfile_getnc(((char *)sample->data) + 5,
+                                        sample->length - 5, f);
+                }
+            }
+        } else {
+            i = dumbfile_getnc(sample->data, sample->length, f);
+        }
+        if (i < sample->length) {
+            if (i <= 0) {
+                sample->flags = 0;
+                return 0;
+            }
+            sample->length = i;
+            if (sample->loop_end > i)
+                sample->loop_end = i;
+            // holy crap!
+            if (sample->loop_start > i)
+                sample->flags &= ~IT_SAMPLE_LOOP;
+        } else {
+            /* skip truncated data */
+            int feh = dumbfile_error(f);
+
+            if (truncated_size)
+                dumbfile_skip(f, truncated_size);
+            // Should we be truncating it?
+
+            if (feh)
+                return -1;
+        }
+
+        if (fft == DUMB_ID('M', 0, 0, 0) || fft == DUMB_ID('8', 0, 0, 0)) {
+            int delta = 0;
+            for (i = 0; i < sample->length; i++) {
+                delta += ((signed char *)sample->data)[i];
+                ((signed char *)sample->data)[i] = delta;
+            }
+        }
+    }
+
+    return 0;
+}
+
+#define MOD_FFT_OFFSET (20 + 31 * (22 + 2 + 1 + 1 + 2 + 2) + 1 + 1 + 128)
+
+static DUMB_IT_SIGDATA *it_mod_load_sigdata(DUMBFILE *f, int restrict_) {
+    DUMB_IT_SIGDATA *sigdata;
+    int n_channels;
+    int i;
+    unsigned long fft;
+
+    if (dumbfile_seek(f, MOD_FFT_OFFSET, DFS_SEEK_SET))
+        return NULL;
+
+    fft = dumbfile_mgetl(f);
+    if (dumbfile_error(f))
+        return NULL;
+
+    if (dumbfile_seek(f, 0, DFS_SEEK_SET))
+        return NULL;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata) {
+        return NULL;
+    }
+
+    /**
+  1       20   Chars     Title of the song.  If the title is not a
+                         full 20 chars in length, it will be null-
+                         terminated.
+    */
+    if (dumbfile_getnc((char *)sigdata->name, 20, f) < 20) {
+        free(sigdata);
+        return NULL;
+    }
+    sigdata->name[20] = 0;
+
+    sigdata->n_samples = 31;
+
+    switch (fft) {
+    case DUMB_ID('M', '.', 'K', '.'):
+    case DUMB_ID('M', '!', 'K', '!'):
+    case DUMB_ID('M', '&', 'K', '!'):
+    case DUMB_ID('N', '.', 'T', '.'):
+    case DUMB_ID('N', 'S', 'M', 'S'):
+    case DUMB_ID('F', 'L', 'T', '4'):
+    case DUMB_ID('M', 0, 0, 0):
+    case DUMB_ID('8', 0, 0, 0):
+    case DUMB_ID('F', 'E', 'S', 'T'):
+        n_channels = 4;
+        break;
+    case DUMB_ID('F', 'L', 'T', '8'):
+        n_channels = 0;
+        /* 0 indicates a special case; two four-channel patterns must be
+         * combined into one eight-channel pattern. Pattern indexes must
+         * be halved. Why oh why do they obfuscate so?
+         */
+        /*for (i = 0; i < 128; i++)
+                sigdata->order[i] >>= 1;*/
+        break;
+    case DUMB_ID('C', 'D', '8', '1'):
+    case DUMB_ID('O', 'C', 'T', 'A'):
+    case DUMB_ID('O', 'K', 'T', 'A'):
+        n_channels = 8;
+        break;
+    case DUMB_ID('1', '6', 'C', 'N'):
+        n_channels = 16;
+        break;
+    case DUMB_ID('3', '2', 'C', 'N'):
+        n_channels = 32;
+        break;
+    default:
+        /* If we get an illegal tag, assume 4 channels 15 samples. */
+        if ((fft & 0x0000FFFFL) == DUMB_ID(0, 0, 'C', 'H')) {
+            if (fft >= '1' << 24 && fft < '4' << 24) {
+                n_channels = ((fft & 0x00FF0000L) >> 16) - '0';
+                if ((unsigned int)n_channels >= 10) {
+                    /* Rightmost character wasn't a digit. */
+                    n_channels = 4;
+                    sigdata->n_samples = 15;
+                } else {
+                    n_channels += (((fft & 0xFF000000L) >> 24) - '0') * 10;
+                    /* MODs should really only go up to 32 channels, but we're
+                     * lenient. */
+                    if ((unsigned int)(n_channels - 1) >=
+                        DUMB_IT_N_CHANNELS - 1) {
+                        /* No channels or too many? Can't be right... */
+                        n_channels = 4;
+                        sigdata->n_samples = 15;
+                    }
+                }
+            } else {
+                n_channels = 4;
+                sigdata->n_samples = 15;
+            }
+        } else if ((fft & 0x00FFFFFFL) == DUMB_ID(0, 'C', 'H', 'N')) {
+            n_channels = (int)((fft >> 24) - '0');
+            if ((unsigned int)(n_channels - 1) >= 9) {
+                /* Character was '0' or it wasn't a digit */
+                n_channels = 4;
+                sigdata->n_samples = 15;
+            }
+        } else if ((fft & 0xFFFFFF00L) == DUMB_ID('T', 'D', 'Z', 0)) {
+            n_channels = (fft & 0x000000FFL) - '0';
+            if ((unsigned int)(n_channels - 1) >= 9) {
+                /* We've been very lenient, given that it should have
+                 * been 1, 2 or 3, but this MOD has been very naughty and
+                 * must be punished.
+                 */
+                n_channels = 4;
+                sigdata->n_samples = 15;
+            }
+        } else {
+            n_channels = 4;
+            sigdata->n_samples = 15;
+            fft = 0;
+        }
+    }
+
+    // moo
+    if ((restrict_ & 1) && sigdata->n_samples == 15) {
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->n_pchannels =
+        n_channels ? n_channels : 8; /* special case for 0, see above */
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample) {
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+
+    for (i = 0; i < sigdata->n_samples; i++)
+        sigdata->sample[i].data = NULL;
+
+    for (i = 0; i < sigdata->n_samples; i++) {
+        if (it_mod_read_sample_header(&sigdata->sample[i], f, fft,
+                                      sigdata->n_samples == 15)) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    sigdata->n_orders = dumbfile_getc(f);
+    sigdata->restart_position = dumbfile_getc(f);
+    // what if this is >= 127? what about with Fast Tracker II?
+
+    /*	if (sigdata->n_orders <= 0 || sigdata->n_orders > 128) { // is this
+       right? _dumb_it_unload_sigdata(sigdata); return NULL;
+            }*/
+
+    // if (sigdata->restart_position >= sigdata->n_orders)
+    // sigdata->restart_position = 0;
+
+    sigdata->order = malloc(128); /* We may need to scan the extra ones! */
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    if (dumbfile_getnc((char *)sigdata->order, 128, f) < 128) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (sigdata->n_orders <= 0 || sigdata->n_orders > 128) { // is this right?
+        sigdata->n_orders = 128;
+        // while (sigdata->n_orders > 1 && !sigdata->order[sigdata->n_orders -
+        // 1]) sigdata->n_orders--;
+    }
+
+    if (!n_channels)
+        for (i = 0; i < 128; i++)
+            sigdata->order[i] >>= 1;
+
+    /* "The old NST format contains only 15 samples (instead of 31). Further
+     * it doesn't contain a file format tag (id). So Pattern data offset is
+     * at 20+15*30+1+1+128."
+     * - Then I shall assume the File Format Tag never exists if there are
+     * only 15 samples. I hope this isn't a faulty assumption...
+     */
+    if (sigdata->n_samples == 31)
+        dumbfile_skip(f, 4);
+
+    sigdata->n_patterns = -1;
+
+    if ((restrict_ & 2)) {
+        unsigned char buffer[5];
+        long sample_number;
+        long total_sample_size;
+        long offset = dumbfile_pos(f);
+        long remain = dumbfile_get_size(f) - offset;
+        if (dumbfile_error(f) || dumbfile_seek(f, 0, SEEK_END)) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        sample_number = sigdata->n_samples - 1;
+        total_sample_size = 0;
+        while (dumbfile_pos(f) > offset && sample_number >= 0) {
+            if (sigdata->sample[sample_number].flags & IT_SAMPLE_EXISTS) {
+                if (dumbfile_seek(
+                        f,
+                        -((sigdata->sample[sample_number].length + 1) / 2 + 5 +
+                          16),
+                        DFS_SEEK_CUR) ||
+                    dumbfile_getnc((char *)buffer, 5, f) < 5) {
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+                if (!memcmp(buffer, "ADPCM", 5)) { /* BAH */
+                    total_sample_size +=
+                        (sigdata->sample[sample_number].length + 1) / 2 + 5 +
+                        16;
+                    if (dumbfile_seek(f, -5, DFS_SEEK_CUR)) {
+                        _dumb_it_unload_sigdata(sigdata);
+                        return NULL;
+                    }
+                } else {
+                    total_sample_size += sigdata->sample[sample_number].length;
+                    if (dumbfile_seek(
+                            f,
+                            -(sigdata->sample[sample_number].length -
+                              ((sigdata->sample[sample_number].length + 1) / 2 +
+                               5 + 16) +
+                              5),
+                            DFS_SEEK_CUR)) {
+                        _dumb_it_unload_sigdata(sigdata);
+                        return NULL;
+                    }
+                }
+            }
+            --sample_number;
+        }
+
+        if (remain > total_sample_size) {
+            sigdata->n_patterns = (int)((remain - total_sample_size + 4) /
+                                        (256 * sigdata->n_pchannels));
+            if (fft == DUMB_ID('M', 0, 0, 0) || fft == DUMB_ID('8', 0, 0, 0)) {
+                remain -= sigdata->n_patterns * 256 * sigdata->n_pchannels;
+                if (dumbfile_skip(f, remain - total_sample_size)) {
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+            }
+        }
+    } else {
+        for (i = 0; i < 128; i++) {
+            if (sigdata->order[i] > sigdata->n_patterns)
+                sigdata->n_patterns = sigdata->order[i];
+        }
+        sigdata->n_patterns++;
+    }
+
+    if (sigdata->n_patterns <= 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    /* May as well try to save a tiny bit of memory. */
+    if (sigdata->n_orders < 128) {
+        unsigned char *order = realloc(sigdata->order, sigdata->n_orders);
+        if (order)
+            sigdata->order = order;
+    }
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    for (i = 0; i < sigdata->n_patterns; i++)
+        sigdata->pattern[i].entry = NULL;
+
+    /* Read in the patterns */
+    {
+        unsigned char *buffer =
+            malloc(256 * sigdata->n_pchannels); /* 64 rows * 4 bytes */
+        if (!buffer) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (i = 0; i < sigdata->n_patterns; i++) {
+            if (it_mod_read_pattern(&sigdata->pattern[i], f, n_channels,
+                                    buffer) != 0) {
+                free(buffer);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+        }
+        free(buffer);
+    }
+
+    /* And finally, the sample data */
+    for (i = 0; i < sigdata->n_samples; i++) {
+        if (it_mod_read_sample_data(&sigdata->sample[i], f, fft)) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    /* w00t! */
+    /*if ( n_channels == 4 &&
+            ( sigdata->n_samples == 15 ||
+            ( ( fft & 240 ) != DUMB_ID( 0, 0, 'C', 0 ) &&
+            ( fft & 240 ) != DUMB_ID( 0, 0, 'H', 0 ) &&
+            ( fft & 240 ) != 0 ) ) ) {
+            for ( i = 0; i < sigdata->n_samples; ++i ) {
+                    IT_SAMPLE * sample = &sigdata->sample [i];
+                    if ( sample && ( sample->flags & IT_SAMPLE_EXISTS ) ) {
+                            int n, o;
+                            o = sample->length;
+                            if ( o > 4 ) o = 4;
+                            for ( n = 0; n < o; ++n )
+                                    ( ( char * ) sample->data ) [n] = 0;
+                    }
+            }
+    }*/
+
+    /* Now let's initialise the remaining variables, and we're done! */
+    sigdata->flags = IT_WAS_AN_XM | IT_WAS_A_MOD | IT_OLD_EFFECTS |
+                     IT_COMPATIBLE_GXX | IT_STEREO;
+
+    sigdata->global_volume = 128;
+    sigdata->mixing_volume = 48;
+    /* We want 50 ticks per second; 50/6 row advances per second;
+     * 50*10=500 row advances per minute; 500/4=125 beats per minute.
+     */
+    sigdata->speed = 6;
+    sigdata->tempo = 125;
+    sigdata->pan_separation = 128;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (i = 0; i < DUMB_IT_N_CHANNELS; i += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[i + 0] = 32 - sep;
+        sigdata->channel_pan[i + 1] = 32 + sep;
+        sigdata->channel_pan[i + 2] = 32 + sep;
+        sigdata->channel_pan[i + 3] = 32 - sep;
+    }
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+DUH *dumb_read_mod_quick(DUMBFILE *f, int restrict_) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_mod_load_sigdata(f, restrict_);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "MOD";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readmod2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readmod2.c - Function to read a good old-          / / \  \
+ *              fashioned Amiga module from an       | <  /   \_
+ *              open file and do an initial          |  \/ /\   /
+ *              run-through.                          \_  /  > /
+ *                                                      | \ / /
+ * Split off from readmod.c by entheh.                  |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_mod(DUMBFILE *f, int restrict_) {
+    DUH *duh = dumb_read_mod_quick(f, restrict_);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/readmtm.c
@@ -1,0 +1,458 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readmtm.c - Code to read a MultiTracker Module     / / \  \
+ *             from an open file.                    | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+size_t strlen_max(const char *ptr, size_t max) {
+    const char *end, *start;
+    if (ptr == 0)
+        return 0;
+    start = ptr;
+    end = ptr + max;
+    while (ptr < end && *ptr)
+        ptr++;
+    return ptr - start;
+}
+
+static int it_mtm_assemble_pattern(IT_PATTERN *pattern,
+                                   const unsigned char *track,
+                                   const unsigned short *sequence, int n_rows) {
+    int n, o, note, sample;
+    const unsigned char *t;
+    IT_ENTRY *entry;
+
+    pattern->n_rows = n_rows;
+    pattern->n_entries = n_rows;
+
+    for (n = 0; n < 32; n++) {
+        if (sequence[n]) {
+            t = &track[192 * (sequence[n] - 1)];
+            for (o = 0; o < n_rows; o++) {
+                if (t[0] || t[1] || t[2])
+                    pattern->n_entries++;
+                t += 3;
+            }
+        }
+    }
+
+    entry = malloc(pattern->n_entries * sizeof(*entry));
+    if (!entry)
+        return -1;
+    pattern->entry = entry;
+
+    for (n = 0; n < n_rows; n++) {
+        for (o = 0; o < 32; o++) {
+            if (sequence[o]) {
+                t = &track[192 * (sequence[o] - 1) + (n * 3)];
+                if (t[0] || t[1] || t[2]) {
+                    entry->channel = o;
+                    entry->mask = 0;
+                    note = t[0] >> 2;
+                    sample = ((t[0] << 4) | (t[1] >> 4)) & 0x3F;
+
+                    if (note) {
+                        entry->mask |= IT_ENTRY_NOTE;
+                        entry->note = note + 24;
+                    }
+
+                    if (sample) {
+                        entry->mask |= IT_ENTRY_INSTRUMENT;
+                        entry->instrument = sample;
+                    }
+
+                    _dumb_it_xm_convert_effect(t[1] & 0xF, t[2], entry, 1);
+
+                    if (entry->mask)
+                        entry++;
+                }
+            }
+        }
+        IT_SET_END_ROW(entry);
+        entry++;
+    }
+
+    pattern->n_entries = (int)(entry - pattern->entry);
+
+    return 0;
+}
+
+static int it_mtm_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f,
+                                     int *skip_bytes) {
+    int finetune, flags;
+
+    dumbfile_getnc((char *)sample->name, 22, f);
+    sample->name[22] = 0;
+
+    sample->filename[0] = 0;
+
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = dumbfile_igetl(f);
+    finetune = (signed char)(dumbfile_getc(f) << 4) >> 4; /* signed nibble */
+    sample->global_volume = 64;
+    sample->default_volume = dumbfile_getc(f);
+
+    flags = dumbfile_getc(f);
+
+    if (sample->length <= 0) {
+        sample->flags = 0;
+        return 0;
+    }
+
+    sample->flags = IT_SAMPLE_EXISTS;
+
+    *skip_bytes = 0;
+    if (flags & 1) {
+        *skip_bytes = sample->length & 1;
+        sample->flags |= IT_SAMPLE_16BIT;
+        sample->length >>= 1;
+        sample->loop_start >>= 1;
+        sample->loop_end >>= 1;
+    }
+
+    sample->default_pan = 0;
+    sample->C5_speed =
+        (int)(AMIGA_CLOCK /
+              214.0); //(long)(16726.0*pow(DUMB_PITCH_BASE, finetune*32));
+    sample->finetune = finetune * 32;
+    // the above line might be wrong
+
+    if (sample->loop_end > sample->length)
+        sample->loop_end = sample->length;
+
+    if (sample->loop_end - sample->loop_start > 2)
+        sample->flags |= IT_SAMPLE_LOOP;
+
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = 0; // do we have to set _all_ these?
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+static int it_mtm_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f,
+                                   int skip_bytes) {
+    long i;
+    long truncated_size;
+    long bytes_per_sample;
+
+    /* let's get rid of the sample data coming after the end of the loop */
+    if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length) {
+        truncated_size = sample->length - sample->loop_end;
+        sample->length = sample->loop_end;
+    } else {
+        truncated_size = 0;
+    }
+
+    bytes_per_sample = (sample->flags & IT_SAMPLE_16BIT) ? 2 : 1;
+
+    sample->data = malloc(sample->length * bytes_per_sample);
+
+    if (!sample->data)
+        return -1;
+
+    dumbfile_getnc((char *)sample->data, sample->length * bytes_per_sample, f);
+    dumbfile_skip(f, truncated_size * bytes_per_sample);
+    dumbfile_skip(f, skip_bytes);
+
+    if (dumbfile_error(f))
+        return -1;
+
+    if (bytes_per_sample == 1)
+        for (i = 0; i < sample->length; i++)
+            ((signed char *)sample->data)[i] ^= 0x80;
+
+    return 0;
+}
+
+static DUMB_IT_SIGDATA *it_mtm_load_sigdata(DUMBFILE *f, int *version) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    int n, o, n_tracks, l_comment, n_rows, n_channels;
+
+    unsigned char *track;
+
+    unsigned short *sequence;
+
+    char *comment;
+
+    int *skip_bytes;
+
+    if (dumbfile_getc(f) != 'M' || dumbfile_getc(f) != 'T' ||
+        dumbfile_getc(f) != 'M')
+        goto error;
+
+    *version = dumbfile_getc(f);
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        goto error;
+
+    dumbfile_getnc((char *)sigdata->name, 20, f);
+    sigdata->name[20] = 0;
+
+    n_tracks = dumbfile_igetw(f);
+    sigdata->n_patterns = dumbfile_getc(f) + 1;
+    sigdata->n_orders = dumbfile_getc(f) + 1;
+    l_comment = dumbfile_igetw(f);
+    sigdata->n_samples = dumbfile_getc(f);
+    // if (dumbfile_getc(f)) goto error_sd;
+    dumbfile_getc(f);
+    n_rows = dumbfile_getc(f);
+    n_channels = dumbfile_getc(f);
+
+    if (dumbfile_error(f) || (n_tracks <= 0) || (sigdata->n_samples <= 0) ||
+        (n_rows <= 0 || n_rows > 64) || (n_channels <= 0 || n_channels > 32))
+        goto error_sd;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    if (dumbfile_getnc((char *)sigdata->channel_pan, 32, f) < 32)
+        goto error_sd;
+
+    for (n = 0; n < 32; n++) {
+        if (sigdata->channel_pan[n] <= 15) {
+            sigdata->channel_pan[n] -= (sigdata->channel_pan[n] & 8) >> 3;
+            sigdata->channel_pan[n] = (sigdata->channel_pan[n] * 32) / 7;
+        } else {
+            sigdata->channel_volume[n] = 0;
+            sigdata->channel_pan[n] = 7;
+        }
+    }
+
+    for (n = 32; n < DUMB_IT_N_CHANNELS; n += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[n] = 32 - sep;
+        sigdata->channel_pan[n + 1] = 32 + sep;
+        sigdata->channel_pan[n + 2] = 32 + sep;
+        sigdata->channel_pan[n + 3] = 32 - sep;
+    }
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample)
+        goto error_sd;
+
+    sigdata->flags = IT_WAS_AN_XM | IT_WAS_A_MOD | IT_STEREO | IT_OLD_EFFECTS |
+                     IT_COMPATIBLE_GXX;
+
+    sigdata->global_volume = 128;
+    sigdata->mixing_volume = 48;
+    sigdata->speed = 6;
+    sigdata->tempo = 125;
+    sigdata->pan_separation = 128;
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+
+    sigdata->restart_position = 0;
+    sigdata->n_pchannels = n_channels;
+
+    for (n = 0; n < sigdata->n_samples; n++)
+        sigdata->sample[n].data = NULL;
+
+    skip_bytes = calloc(sizeof(int), sigdata->n_samples);
+    if (!skip_bytes)
+        goto error_usd;
+
+    for (n = 0; n < sigdata->n_samples; n++) {
+        if (it_mtm_read_sample_header(&sigdata->sample[n], f, skip_bytes + n))
+            goto error_sb;
+    }
+
+    sigdata->order = malloc(sigdata->n_orders);
+    if (!sigdata->order)
+        goto error_sb;
+
+    if (dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f) <
+        sigdata->n_orders)
+        goto error_sb;
+    if (sigdata->n_orders < 128)
+        if (dumbfile_skip(f, 128 - sigdata->n_orders))
+            goto error_sb;
+
+    track = malloc(192 * n_tracks);
+    if (!track)
+        goto error_sb;
+
+    if (dumbfile_getnc((char *)track, 192 * n_tracks, f) < 192 * n_tracks)
+        goto error_ft;
+
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern)
+        goto error_ft;
+    for (n = 0; n < sigdata->n_patterns; n++)
+        sigdata->pattern[n].entry = NULL;
+
+    sequence = malloc(sigdata->n_patterns * 32 * sizeof(*sequence));
+    if (!sequence)
+        goto error_ft;
+
+    for (n = 0; n < sigdata->n_patterns; n++) {
+        for (o = 0; o < 32; o++) {
+            sequence[(n * 32) + o] = dumbfile_igetw(f);
+            if (sequence[(n * 32) + o] > n_tracks) {
+                // goto error_fs;
+                // illegal track number, silence instead of rejecting the file
+                sequence[(n * 32) + o] = 0;
+            }
+        }
+    }
+
+    for (n = 0; n < sigdata->n_patterns; n++) {
+        if (it_mtm_assemble_pattern(&sigdata->pattern[n], track,
+                                    &sequence[n * 32], n_rows))
+            goto error_fs;
+    }
+
+    if (l_comment) {
+        comment = malloc(l_comment);
+        if (!comment)
+            goto error_fs;
+        if (dumbfile_getnc(comment, l_comment, f) < l_comment)
+            goto error_fc;
+
+        /* Time for annoying "logic", yes. We want each line which has text,
+         * and each blank line in between all the valid lines.
+         */
+
+        /* Find last actual line. */
+        for (o = -1, n = 0; n < l_comment; n += 40) {
+            if (comment[n])
+                o = n;
+        }
+
+        if (o >= 0) {
+
+            int l, m;
+
+            for (l = 0, n = 0; n <= o; n += 40) {
+                int maxlen = l_comment - n;
+                l += strlen_max(&comment[n], maxlen > 40 ? 40 : maxlen) + 2;
+            }
+
+            l -= 1;
+
+            sigdata->song_message = malloc(l);
+            if (!sigdata->song_message)
+                goto error_fc;
+
+            for (m = 0, n = 0; n <= o; n += 40) {
+                int maxlen = l_comment - n;
+                int p = (int)strlen_max(&comment[n], maxlen > 40 ? 40 : maxlen);
+                if (p) {
+                    memcpy(sigdata->song_message + m, &comment[n], p);
+                    m += p;
+                }
+                if (l - m > 1) {
+                    sigdata->song_message[m++] = 13;
+                    sigdata->song_message[m++] = 10;
+                }
+            }
+
+            sigdata->song_message[m] = 0;
+        }
+
+        free(comment);
+    }
+
+    for (n = 0; n < sigdata->n_samples; n++) {
+        if (it_mtm_read_sample_data(&sigdata->sample[n], f, skip_bytes[n]))
+            goto error_fs;
+    }
+
+    free(sequence);
+    free(track);
+    free(skip_bytes);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+
+error_fc:
+    free(comment);
+error_fs:
+    free(sequence);
+error_ft:
+    free(track);
+error_sb:
+    free(skip_bytes);
+error_usd:
+    _dumb_it_unload_sigdata(sigdata);
+    return NULL;
+
+error_sd:
+    free(sigdata);
+error:
+    return NULL;
+}
+
+static char hexdigit(int in) {
+    if (in < 10)
+        return in + '0';
+    else
+        return in + 'A' - 10;
+}
+
+DUH *dumb_read_mtm_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+    int ver;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_mtm_load_sigdata(f, &ver);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        char version[16];
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        version[0] = 'M';
+        version[1] = 'T';
+        version[2] = 'M';
+        version[3] = ' ';
+        version[4] = 'v';
+        version[5] = hexdigit(ver >> 4);
+        version[6] = '.';
+        version[7] = hexdigit(ver & 15);
+        version[8] = 0;
+        tag[1][1] = (const char *)&version;
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readokt.c
@@ -1,0 +1,605 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readokt.c - Code to read an Oktalyzer module       / / \  \
+ *             from an open file.                    | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+static int it_okt_read_pattern(IT_PATTERN *pattern, const unsigned char *data,
+                               int length, int n_channels) {
+    int pos;
+    int channel;
+    int row;
+    int n_rows;
+    IT_ENTRY *entry;
+
+    if (length < 2)
+        return -1;
+
+    n_rows = (data[0] << 8) | data[1];
+    if (!n_rows)
+        n_rows = 64;
+
+    if (length < 2 + (n_rows * n_channels * 4))
+        return -1;
+
+    pattern->n_rows = n_rows;
+
+    /* compute number of entries */
+    pattern->n_entries = n_rows; /* Account for the row end markers */
+    pos = 2;
+    for (row = 0; row < pattern->n_rows; row++) {
+        for (channel = 0; channel < n_channels; channel++) {
+            if (data[pos + 0] | data[pos + 2])
+                pattern->n_entries++;
+            pos += 4;
+        }
+    }
+
+    pattern->entry =
+        (IT_ENTRY *)malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+    pos = 2;
+    for (row = 0; row < n_rows; row++) {
+        for (channel = 0; channel < n_channels; channel++) {
+            if (data[pos + 0] | data[pos + 2]) {
+                entry->channel = channel;
+                entry->mask = 0;
+
+                if (data[pos + 0] > 0 && data[pos + 0] <= 36) {
+                    entry->mask |= IT_ENTRY_NOTE | IT_ENTRY_INSTRUMENT;
+
+                    entry->note = data[pos + 0] + 35;
+                    entry->instrument = data[pos + 1] + 1;
+                }
+
+                entry->effect = 0;
+                entry->effectvalue = data[pos + 3];
+
+                switch (data[pos + 2]) {
+                case 2:
+                    if (data[pos + 3])
+                        entry->effect = IT_PORTAMENTO_DOWN;
+                    break; // XXX code calls this rs_portu, but it's adding to
+                           // the period, which decreases the pitch
+                case 13:
+                    if (data[pos + 3])
+                        entry->effect = IT_OKT_NOTE_SLIDE_DOWN;
+                    break;
+                case 21:
+                    if (data[pos + 3])
+                        entry->effect = IT_OKT_NOTE_SLIDE_DOWN_ROW;
+                    break;
+
+                case 1:
+                    if (data[pos + 3])
+                        entry->effect = IT_PORTAMENTO_UP;
+                    break; // XXX same deal here, increasing the pitch
+                case 17:
+                    if (data[pos + 3])
+                        entry->effect = IT_OKT_NOTE_SLIDE_UP;
+                    break;
+                case 30:
+                    if (data[pos + 3])
+                        entry->effect = IT_OKT_NOTE_SLIDE_UP_ROW;
+                    break;
+
+                case 10:
+                    if (data[pos + 3])
+                        entry->effect = IT_OKT_ARPEGGIO_3;
+                    break;
+                case 11:
+                    if (data[pos + 3])
+                        entry->effect = IT_OKT_ARPEGGIO_4;
+                    break;
+                case 12:
+                    if (data[pos + 3])
+                        entry->effect = IT_OKT_ARPEGGIO_5;
+                    break;
+
+                case 15:
+                    entry->effect = IT_S;
+                    entry->effectvalue =
+                        EFFECT_VALUE(IT_S_SET_FILTER, data[pos + 3] & 0x0F);
+                    break;
+
+                case 25:
+                    entry->effect = IT_JUMP_TO_ORDER;
+                    break;
+
+                case 27:
+                    entry->note = IT_NOTE_OFF;
+                    entry->mask |= IT_ENTRY_NOTE;
+                    break;
+
+                case 28:
+                    entry->effect = IT_SET_SPEED;
+                    break;
+
+                case 31:
+                    if (data[pos + 3] <= 0x40)
+                        entry->effect = IT_SET_CHANNEL_VOLUME;
+                    else if (data[pos + 3] <= 0x50) {
+                        entry->effect = IT_OKT_VOLUME_SLIDE_DOWN;
+                        entry->effectvalue = data[pos + 3] - 0x40;
+                    } else if (data[pos + 3] <= 0x60) {
+                        entry->effect = IT_OKT_VOLUME_SLIDE_UP;
+                        entry->effectvalue = data[pos + 3] - 0x50;
+                    } else if (data[pos + 3] <= 0x70) {
+                        entry->effect = IT_OKT_VOLUME_SLIDE_DOWN;
+                        entry->effectvalue = data[pos + 3] - 0x50;
+                    } else if (data[pos + 3] <= 0x80) {
+                        entry->effect = IT_OKT_VOLUME_SLIDE_UP;
+                        entry->effectvalue = data[pos + 3] - 0x60;
+                    }
+                    break;
+                }
+
+                if (entry->effect)
+                    entry->mask |= IT_ENTRY_EFFECT;
+
+                entry++;
+            }
+            pos += 4;
+        }
+        IT_SET_END_ROW(entry);
+        entry++;
+    }
+
+    return 0;
+}
+
+static void it_okt_read_sample_header(IT_SAMPLE *sample,
+                                      const unsigned char *data) {
+    int loop_start, loop_length;
+
+    memcpy(sample->name, data, 20);
+    sample->name[20] = 0;
+
+    sample->filename[0] = 0;
+
+    sample->length =
+        (data[20] << 24) | (data[21] << 16) | (data[22] << 8) | data[23];
+    sample->global_volume = 64;
+    sample->default_volume = data[29];
+    loop_start = ((data[24] << 8) | data[25]) << 1;
+    loop_length = ((data[26] << 8) | data[27]) << 1;
+    sample->sus_loop_start = loop_start;
+    sample->sus_loop_end = loop_start + loop_length;
+
+    if (sample->length <= 0) {
+        sample->flags = 0;
+        return;
+    }
+
+    sample->flags = IT_SAMPLE_EXISTS;
+
+    sample->default_pan = 0;
+    sample->C5_speed =
+        (int)(AMIGA_CLOCK /
+              214.0); //(long)(16726.0*pow(DUMB_PITCH_BASE, finetune*32));
+    sample->finetune = 0;
+
+    if (sample->sus_loop_end > sample->length)
+        sample->sus_loop_end = sample->length;
+
+    if (loop_length > 2)
+        sample->flags |= IT_SAMPLE_SUS_LOOP;
+
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = 0; // do we have to set _all_ these?
+    sample->max_resampling_quality = -1;
+}
+
+static int it_okt_read_sample_data(IT_SAMPLE *sample, const char *data,
+                                   int length) {
+    if (length && sample->length) {
+        if (length < sample->length) {
+            sample->length = length;
+            if (length < sample->sus_loop_end)
+                sample->sus_loop_end = length;
+        }
+
+        sample->data = malloc(length);
+
+        if (!sample->data)
+            return -1;
+
+        memcpy(sample->data, data, length);
+    }
+
+    return 0;
+}
+
+typedef struct IFF_CHUNK IFF_CHUNK;
+typedef struct IFF_CHUNKED IFF_CHUNKED;
+
+struct IFF_CHUNK {
+    unsigned type;
+    unsigned char *data;
+    unsigned size;
+};
+
+struct IFF_CHUNKED {
+    unsigned chunk_count;
+    IFF_CHUNK *chunks;
+};
+
+static IFF_CHUNKED *dumbfile_read_okt(DUMBFILE *f) {
+    IFF_CHUNKED *mod = (IFF_CHUNKED *)malloc(sizeof(*mod));
+    if (!mod)
+        return NULL;
+
+    mod->chunk_count = 0;
+    mod->chunks = 0;
+
+    for (;;) {
+        long bytes_read;
+        IFF_CHUNK *chunk = (IFF_CHUNK *)realloc(
+            mod->chunks, (mod->chunk_count + 1) * sizeof(IFF_CHUNK));
+        if (!chunk) {
+            if (mod->chunks)
+                free(mod->chunks);
+            free(mod);
+            return NULL;
+        }
+        mod->chunks = chunk;
+        chunk += mod->chunk_count;
+
+        bytes_read = dumbfile_mgetl(f);
+        if (bytes_read < 0)
+            break;
+
+        chunk->type = (unsigned int)bytes_read;
+        chunk->size = (unsigned int)dumbfile_mgetl(f);
+
+        if (dumbfile_error(f))
+            break;
+
+        chunk->data = (unsigned char *)malloc(chunk->size);
+        if (!chunk->data) {
+            free(mod->chunks);
+            free(mod);
+            return NULL;
+        }
+
+        bytes_read = dumbfile_getnc((char *)chunk->data, chunk->size, f);
+        if (bytes_read < chunk->size) {
+            if (bytes_read <= 0) {
+                free(chunk->data);
+                break;
+            } else {
+                chunk->size = (unsigned int)bytes_read;
+                mod->chunk_count++;
+                break;
+            }
+        }
+
+        mod->chunk_count++;
+    }
+
+    if (!mod->chunk_count) {
+        if (mod->chunks)
+            free(mod->chunks);
+        free(mod);
+        mod = NULL;
+    }
+
+    return mod;
+}
+
+void free_okt(IFF_CHUNKED *mod) {
+    unsigned i;
+    if (mod) {
+        if (mod->chunks) {
+            for (i = 0; i < mod->chunk_count; i++) {
+                if (mod->chunks[i].data)
+                    free(mod->chunks[i].data);
+            }
+            free(mod->chunks);
+        }
+        free(mod);
+    }
+}
+
+const IFF_CHUNK *get_chunk_by_type(IFF_CHUNKED *mod, unsigned type,
+                                   unsigned offset) {
+    unsigned i;
+    if (mod) {
+        if (mod->chunks) {
+            for (i = 0; i < mod->chunk_count; i++) {
+                if (mod->chunks[i].type == type) {
+                    if (!offset)
+                        return &mod->chunks[i];
+                    else
+                        offset--;
+                }
+            }
+        }
+    }
+    return NULL;
+}
+
+unsigned get_chunk_count(IFF_CHUNKED *mod, unsigned type) {
+    unsigned i, count = 0;
+    if (mod) {
+        if (mod->chunks) {
+            for (i = 0; i < mod->chunk_count; i++) {
+                if (mod->chunks[i].type == type)
+                    count++;
+            }
+        }
+    }
+    return count;
+}
+
+static DUMB_IT_SIGDATA *it_okt_load_sigdata(DUMBFILE *f) {
+    DUMB_IT_SIGDATA *sigdata;
+    int n_channels;
+    int i, j, k, l;
+    IFF_CHUNKED *mod;
+    const IFF_CHUNK *chunk;
+
+    char signature[8];
+
+    if (dumbfile_getnc(signature, 8, f) < 8 ||
+        memcmp(signature, "OKTASONG", 8)) {
+        return NULL;
+    }
+
+    mod = dumbfile_read_okt(f);
+    if (!mod)
+        return NULL;
+
+    sigdata = (DUMB_IT_SIGDATA *)malloc(sizeof(*sigdata));
+    if (!sigdata) {
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->name[0] = 0;
+
+    chunk = get_chunk_by_type(mod, DUMB_ID('S', 'P', 'E', 'E'), 0);
+    if (!chunk || chunk->size < 2) {
+        free(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->speed = (chunk->data[0] << 8) | chunk->data[1];
+
+    chunk = get_chunk_by_type(mod, DUMB_ID('S', 'A', 'M', 'P'), 0);
+    if (!chunk || chunk->size < 32) {
+        free(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->n_samples = chunk->size / 32;
+
+    chunk = get_chunk_by_type(mod, DUMB_ID('C', 'M', 'O', 'D'), 0);
+    if (!chunk || chunk->size < 8) {
+        free(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    n_channels = 0;
+
+    for (i = 0; i < 4; i++) {
+        j = (chunk->data[i * 2] << 8) | chunk->data[i * 2 + 1];
+        if (!j)
+            n_channels++;
+        else if (j == 1)
+            n_channels += 2;
+    }
+
+    if (!n_channels) {
+        free(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->n_pchannels = n_channels;
+
+    sigdata->sample =
+        (IT_SAMPLE *)malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample) {
+        free(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+
+    for (i = 0; i < sigdata->n_samples; i++)
+        sigdata->sample[i].data = NULL;
+
+    chunk = get_chunk_by_type(mod, DUMB_ID('S', 'A', 'M', 'P'), 0);
+
+    for (i = 0; i < sigdata->n_samples; i++) {
+        it_okt_read_sample_header(&sigdata->sample[i], chunk->data + 32 * i);
+    }
+
+    sigdata->restart_position = 0;
+
+    chunk = get_chunk_by_type(mod, DUMB_ID('P', 'L', 'E', 'N'), 0);
+    if (!chunk || chunk->size < 2) {
+        _dumb_it_unload_sigdata(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->n_orders = (chunk->data[0] << 8) | chunk->data[1];
+    // what if this is > 128?
+
+    if (sigdata->n_orders <= 0 || sigdata->n_orders > 128) {
+        _dumb_it_unload_sigdata(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    chunk = get_chunk_by_type(mod, DUMB_ID('P', 'A', 'T', 'T'), 0);
+    if (!chunk || chunk->size < (unsigned)sigdata->n_orders) {
+        _dumb_it_unload_sigdata(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->order = (unsigned char *)malloc(sigdata->n_orders);
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    memcpy(sigdata->order, chunk->data, sigdata->n_orders);
+
+    /* Work out how many patterns there are. */
+    chunk = get_chunk_by_type(mod, DUMB_ID('S', 'L', 'E', 'N'), 0);
+    if (!chunk || chunk->size < 2) {
+        _dumb_it_unload_sigdata(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->n_patterns = (chunk->data[0] << 8) | chunk->data[1];
+
+    j = get_chunk_count(mod, DUMB_ID('P', 'B', 'O', 'D'));
+    if (sigdata->n_patterns > j)
+        sigdata->n_patterns = j;
+
+    if (!sigdata->n_patterns) {
+        _dumb_it_unload_sigdata(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+
+    sigdata->pattern =
+        (IT_PATTERN *)malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern) {
+        _dumb_it_unload_sigdata(sigdata);
+        free_okt(mod);
+        return NULL;
+    }
+    for (i = 0; i < sigdata->n_patterns; i++)
+        sigdata->pattern[i].entry = NULL;
+
+    /* Read in the patterns */
+    for (i = 0; i < sigdata->n_patterns; i++) {
+        chunk = get_chunk_by_type(mod, DUMB_ID('P', 'B', 'O', 'D'), i);
+        if (it_okt_read_pattern(&sigdata->pattern[i], chunk->data, chunk->size,
+                                n_channels) != 0) {
+            _dumb_it_unload_sigdata(sigdata);
+            free_okt(mod);
+            return NULL;
+        }
+    }
+
+    /* And finally, the sample data */
+    k = get_chunk_count(mod, DUMB_ID('S', 'B', 'O', 'D'));
+    for (i = 0, j = 0; i < sigdata->n_samples && j < k; i++) {
+        if (sigdata->sample[i].flags & IT_SAMPLE_EXISTS) {
+            chunk = get_chunk_by_type(mod, DUMB_ID('S', 'B', 'O', 'D'), j);
+            if (it_okt_read_sample_data(&sigdata->sample[i],
+                                        (const char *)chunk->data,
+                                        chunk->size)) {
+                _dumb_it_unload_sigdata(sigdata);
+                free_okt(mod);
+                return NULL;
+            }
+            j++;
+        }
+    }
+    for (; i < sigdata->n_samples; i++) {
+        sigdata->sample[i].flags = 0;
+    }
+
+    chunk = get_chunk_by_type(mod, DUMB_ID('C', 'M', 'O', 'D'), 0);
+
+    for (i = 0, j = 0; i < n_channels && j < 4; j++) {
+        k = (chunk->data[j * 2] << 8) | chunk->data[j * 2 + 1];
+        l = (j == 1 || j == 2) ? 48 : 16;
+        if (k == 0) {
+            sigdata->channel_pan[i++] = l;
+        } else if (k == 1) {
+            sigdata->channel_pan[i++] = l;
+            sigdata->channel_pan[i++] = l;
+        }
+    }
+
+    free_okt(mod);
+
+    /* Now let's initialise the remaining variables, and we're done! */
+    sigdata->flags = IT_WAS_AN_OKT | IT_WAS_AN_XM | IT_WAS_A_MOD |
+                     IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_STEREO;
+
+    sigdata->global_volume = 128;
+    sigdata->mixing_volume = 48;
+    /* We want 50 ticks per second; 50/6 row advances per second;
+     * 50*10=500 row advances per minute; 500/4=125 beats per minute.
+     */
+    sigdata->tempo = 125;
+    sigdata->pan_separation = 128;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+    memset(sigdata->channel_pan + n_channels, 32,
+           DUMB_IT_N_CHANNELS - n_channels);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+DUH *dumb_read_okt_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_okt_load_sigdata(f);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[1][2];
+        tag[0][0] = "FORMAT";
+        tag[0][1] = "Oktalyzer";
+        return make_duh(-1, 1, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readokt2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readokt2.c - Function to read an Oktalyzer         / / \  \
+ *              module from an open file and do      | <  /   \_
+ *              an initial run-through.              |  \/ /\   /
+ *                                                    \_  /  > /
+ *                                                      | \ / /
+ * By Christopher Snowhill.                             |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_okt(DUMBFILE *f) {
+    DUH *duh = dumb_read_okt_quick(f);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/readoldpsm.c
@@ -1,0 +1,745 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readpsm.c - Code to read an old Protracker         / / \  \
+ *             Studio module from an open file.      | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+static int psm_sample_compare(const void *e1, const void *e2) {
+    const unsigned char *pa = e1;
+    const unsigned char *pb = e2;
+    int a = pa[37] | (pa[38] << 8) | (pa[39] << 16) | (pa[40] << 24);
+    int b = pb[37] | (pb[38] << 8) | (pb[39] << 16) | (pb[40] << 24);
+    return a - b;
+}
+
+static int it_old_psm_read_samples(IT_SAMPLE **sample, DUMBFILE *f, int *num) {
+    int n, o, count = *num, true_num, snum, offset, flags, finetune, delta;
+
+    unsigned char *buffer;
+    const unsigned char *sdata;
+    long sample_bytes;
+
+    buffer = malloc(count * 64);
+    if (!buffer)
+        goto error;
+
+    if (dumbfile_getnc((char *)buffer, count * 64, f) < count * 64)
+        goto error_fb;
+
+    true_num = 0;
+
+    for (n = 0; n < count; n++) {
+        snum = buffer[(n * 64) + 45] | (buffer[(n * 64) + 46] << 8);
+        if ((snum < 1) || (snum > 255))
+            goto error_fb;
+        if (true_num < snum)
+            true_num = snum;
+    }
+
+    if (true_num > count) {
+        IT_SAMPLE *meh = realloc(*sample, true_num * sizeof(*meh));
+        if (!meh)
+            goto error_fb;
+        for (n = count; n < true_num; n++) {
+            meh[n].data = NULL;
+        }
+        *sample = meh;
+        *num = true_num;
+    }
+
+    qsort(buffer, count, 64, &psm_sample_compare);
+
+    for (n = 0; n < *num; n++) {
+        (*sample)[n].flags = 0;
+    }
+
+    for (n = 0; n < count; n++) {
+        IT_SAMPLE smp;
+        IT_SAMPLE *s;
+        snum = buffer[(n * 64) + 45] | (buffer[(n * 64) + 46] << 8);
+        s = &((*sample)[snum - 1]);
+        memcpy(smp.filename, buffer + (n * 64), 13);
+        smp.filename[13] = 0;
+        memcpy(smp.name, buffer + (n * 64) + 13, 24);
+        smp.name[24] = 0;
+        offset = buffer[(n * 64) + 37] | (buffer[(n * 64) + 38] << 8) |
+                 (buffer[(n * 64) + 39] << 16) | (buffer[(n * 64) + 40] << 24);
+        flags = buffer[(n * 64) + 47];
+        smp.length = buffer[(n * 64) + 48] | (buffer[(n * 64) + 49] << 8) |
+                     (buffer[(n * 64) + 50] << 16) |
+                     (buffer[(n * 64) + 51] << 24);
+        smp.loop_start = buffer[(n * 64) + 52] | (buffer[(n * 64) + 53] << 8) |
+                         (buffer[(n * 64) + 54] << 16) |
+                         (buffer[(n * 64) + 55] << 24);
+        smp.loop_end = buffer[(n * 64) + 56] | (buffer[(n * 64) + 57] << 8) |
+                       (buffer[(n * 64) + 58] << 16) |
+                       (buffer[(n * 64) + 59] << 24);
+
+        if (smp.length <= 0)
+            continue;
+
+        finetune = buffer[(n * 64) + 60];
+        smp.default_volume = buffer[(n * 64) + 61];
+        smp.C5_speed = buffer[(n * 64) + 62] | (buffer[(n * 64) + 63] << 8);
+        if (finetune & 15) {
+            finetune &= 15;
+            if (finetune >= 8)
+                finetune -= 16;
+            // s->C5_speed = (long)((double)s->C5_speed * pow(DUMB_PITCH_BASE,
+            // finetune*32));
+            smp.finetune = finetune * 32;
+        } else
+            smp.finetune = 0;
+
+        smp.flags = IT_SAMPLE_EXISTS;
+        if (flags & 0x41)
+            continue;
+        if (flags & 0x20)
+            smp.flags |= IT_SAMPLE_PINGPONG_LOOP;
+        if (flags & 4)
+            smp.flags |= IT_SAMPLE_16BIT;
+
+        if (flags & 0x80) {
+            smp.flags |= IT_SAMPLE_LOOP;
+            if ((unsigned int)smp.loop_end > (unsigned int)smp.length)
+                smp.loop_end = smp.length;
+            else if ((unsigned int)smp.loop_start >= (unsigned int)smp.loop_end)
+                smp.flags &= ~IT_SAMPLE_LOOP;
+            else
+                smp.length = smp.loop_end;
+        }
+
+        smp.global_volume = 64;
+
+        smp.vibrato_speed = 0;
+        smp.vibrato_depth = 0;
+        smp.vibrato_rate = 0;
+        smp.vibrato_waveform = IT_VIBRATO_SINE;
+        smp.max_resampling_quality = -1;
+
+        sample_bytes = smp.length * ((flags & 4) ? 2 : 1);
+        smp.data = malloc(sample_bytes);
+        if (!smp.data)
+            goto error_fb;
+        sdata = (const unsigned char *)smp.data;
+
+        if (dumbfile_seek(f, offset, DFS_SEEK_SET) ||
+            dumbfile_getnc(smp.data, sample_bytes, f) < sample_bytes)
+            goto error_fd;
+
+        if (flags & 0x10) {
+            if (flags & 8) {
+                if (flags & 4) {
+                    for (o = 0; o < smp.length; o++)
+                        ((short *)smp.data)[o] =
+                            (sdata[o * 2] | (sdata[(o * 2) + 1] << 8)) ^ 0x8000;
+                } else {
+                    for (o = 0; o < smp.length; o++)
+                        ((signed char *)smp.data)[o] = sdata[o] ^ 0x80;
+                }
+            } else {
+                if (flags & 4) {
+                    for (o = 0; o < smp.length; o++)
+                        ((short *)smp.data)[o] =
+                            sdata[o * 2] | (sdata[(o * 2) + 1] << 8);
+                } else {
+                    memcpy(smp.data, sdata, smp.length);
+                }
+            }
+        } else {
+            delta = 0;
+            if (flags & 8) {
+                /* unsigned delta? mehhh, does anything even use this? */
+                if (flags & 4) {
+                    for (o = 0; o < smp.length; o++) {
+                        delta +=
+                            (short)(sdata[o * 2] | (sdata[(o * 2) + 1] << 8));
+                        ((short *)smp.data)[o] = delta ^ 0x8000;
+                    }
+                } else {
+                    for (o = 0; o < smp.length; o++) {
+                        delta += (signed char)sdata[o];
+                        ((signed char *)smp.data)[o] = delta ^ 0x80;
+                    }
+                }
+            } else {
+                if (flags & 4) {
+                    for (o = 0; o < smp.length; o++) {
+                        delta += (signed short)(sdata[o * 2] |
+                                                (sdata[(o * 2) + 1] << 8));
+                        ((signed short *)smp.data)[o] = delta;
+                    }
+                } else {
+                    for (o = 0; o < smp.length; o++) {
+                        delta += (signed char)sdata[o];
+                        ((signed char *)smp.data)[o] = delta;
+                    }
+                }
+            }
+        }
+
+        if (s->data)
+            free(s->data);
+        *s = smp;
+    }
+
+    free(buffer);
+
+    return 0;
+
+error_fd:
+    free((void *)sdata);
+error_fb:
+    free(buffer);
+error:
+    return -1;
+}
+
+static int it_old_psm_read_patterns(IT_PATTERN *pattern, DUMBFILE *f, int num,
+                                    int size, int pchans) {
+    int n, offset, psize, rows, chans, row, flags, channel;
+
+    unsigned char *buffer, *ptr, *end;
+
+    IT_ENTRY *entry;
+
+    buffer = malloc(size);
+    if (!buffer)
+        goto error;
+
+    if (dumbfile_getnc((char *)buffer, size, f) < size)
+        goto error_fb;
+
+    offset = 0;
+
+    for (n = 0; n < num; n++) {
+        IT_PATTERN *p = &pattern[n];
+
+        if (offset >= size)
+            goto error_fb;
+
+        ptr = buffer + offset;
+        psize = ptr[0] | (ptr[1] << 8);
+        rows = ptr[2];
+        chans = ptr[3];
+
+        if (!rows || !chans) {
+            p->n_rows = 1;
+            p->n_entries = 0;
+            continue;
+        }
+
+        psize = (psize + 15) & ~15;
+
+        if (offset + psize > size)
+            goto error_fb;
+
+        end = ptr + psize;
+        ptr += 4;
+
+        p->n_rows = rows;
+        p->n_entries = rows;
+        row = 0;
+
+        while ((row < rows) && (ptr < end)) {
+            flags = *ptr++;
+            if (!flags) {
+                row++;
+                continue;
+            }
+            if (flags & 0xE0) {
+                p->n_entries++;
+                if (flags & 0x80)
+                    ptr += 2;
+                if (flags & 0x40)
+                    ptr++;
+                if (flags & 0x20) {
+                    if (*ptr == 40)
+                        ptr += 4;
+                    else
+                        ptr += 2;
+                }
+            }
+        }
+
+        entry = malloc(p->n_entries * sizeof(*p->entry));
+        if (!entry)
+            goto error_fb;
+
+        p->entry = entry;
+
+        ptr = buffer + offset + 4;
+        row = 0;
+
+        while ((row < rows) && (ptr < end)) {
+            flags = *ptr++;
+            if (!flags) {
+                IT_SET_END_ROW(entry);
+                entry++;
+                row++;
+                continue;
+            }
+            if (flags & 0xE0) {
+                entry->mask = 0;
+                entry->channel = channel = flags & 0x1F;
+                if (channel >= chans) {
+                    // channel = 0;
+                    // goto error_fb;
+                }
+                if (flags & 0x80) {
+                    if ((*ptr < 60) && (channel < pchans)) {
+                        entry->mask |= IT_ENTRY_NOTE;
+                        entry->note = *ptr + 35;
+                    }
+                    ptr++;
+                    if (*ptr) {
+                        entry->mask |= IT_ENTRY_INSTRUMENT;
+                        entry->instrument = *ptr;
+                    }
+                    ptr++;
+                }
+                if (flags & 0x40) {
+                    if (*ptr <= 64) {
+                        entry->mask |= IT_ENTRY_VOLPAN;
+                        entry->volpan = *ptr;
+                    }
+                    ptr++;
+                }
+                if (flags & 0x20) {
+                    entry->mask |= IT_ENTRY_EFFECT;
+
+                    switch (*ptr) {
+                    case 1:
+                        entry->effect = IT_XM_FINE_VOLSLIDE_UP;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 2:
+                        entry->effect = IT_VOLUME_SLIDE;
+                        entry->effectvalue = (ptr[1] << 4) & 0xF0;
+                        break;
+
+                    case 3:
+                        entry->effect = IT_XM_FINE_VOLSLIDE_DOWN;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 4:
+                        entry->effect = IT_VOLUME_SLIDE;
+                        entry->effectvalue = ptr[1] & 0xF;
+                        break;
+
+                    case 10:
+                        entry->effect = IT_PORTAMENTO_UP;
+                        entry->effectvalue = EFFECT_VALUE(0xF, ptr[1]);
+                        break;
+
+                    case 11:
+                        entry->effect = IT_PORTAMENTO_UP;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 12:
+                        entry->effect = IT_PORTAMENTO_DOWN;
+                        entry->effectvalue = EFFECT_VALUE(ptr[1], 0xF);
+                        break;
+
+                    case 13:
+                        entry->effect = IT_PORTAMENTO_DOWN;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 14:
+                        entry->effect = IT_TONE_PORTAMENTO;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 15:
+                        entry->effect = IT_S;
+                        entry->effectvalue = EFFECT_VALUE(
+                            IT_S_SET_GLISSANDO_CONTROL, ptr[1] & 15);
+                        break;
+
+                    case 16:
+                        entry->effect = IT_VOLSLIDE_TONEPORTA;
+                        entry->effectvalue = ptr[1] << 4;
+                        break;
+
+                    case 17:
+                        entry->effect = IT_VOLSLIDE_TONEPORTA;
+                        entry->effectvalue = ptr[1] & 0xF;
+                        break;
+
+                    case 20:
+                        entry->effect = IT_VIBRATO;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 21:
+                        entry->effect = IT_S;
+                        entry->effectvalue = EFFECT_VALUE(
+                            IT_S_SET_VIBRATO_WAVEFORM, ptr[1] & 11);
+                        break;
+
+                    case 22:
+                        entry->effect = IT_VOLSLIDE_VIBRATO;
+                        entry->effectvalue = ptr[1] << 4;
+                        break;
+
+                    case 23:
+                        entry->effect = IT_VOLSLIDE_VIBRATO;
+                        entry->effectvalue = ptr[1] & 0xF;
+                        break;
+
+                    case 30:
+                        entry->effect = IT_TREMOLO;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 31:
+                        entry->effect = IT_S;
+                        entry->effectvalue = EFFECT_VALUE(
+                            IT_S_SET_TREMOLO_WAVEFORM, ptr[1] & 11);
+                        break;
+
+                    case 40:
+                        entry->effect = IT_SET_SAMPLE_OFFSET;
+                        entry->effectvalue = ptr[2];
+                        ptr += 2;
+                        break;
+
+                    case 41:
+                        entry->effect = IT_XM_RETRIGGER_NOTE;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 42:
+                        entry->effect = IT_S;
+                        entry->effectvalue =
+                            EFFECT_VALUE(IT_S_DELAYED_NOTE_CUT, ptr[1] & 0xF);
+                        break;
+
+                    case 43:
+                        entry->effect = IT_S;
+                        entry->effectvalue =
+                            EFFECT_VALUE(IT_S_NOTE_DELAY, ptr[1] & 0xF);
+                        break;
+
+                    case 50:
+                        entry->effect = IT_JUMP_TO_ORDER;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 51:
+                        entry->effect = IT_BREAK_TO_ROW;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 52:
+                        entry->effect = IT_S;
+                        entry->effectvalue =
+                            EFFECT_VALUE(IT_S_PATTERN_LOOP, ptr[1] & 0xF);
+                        break;
+
+                    case 53:
+                        entry->effect = IT_S;
+                        entry->effectvalue =
+                            EFFECT_VALUE(IT_S_PATTERN_DELAY, ptr[1] & 0xF);
+                        break;
+
+                    case 60:
+                        entry->effect = IT_SET_SPEED;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 61:
+                        entry->effect = IT_SET_SONG_TEMPO;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 70:
+                        entry->effect = IT_ARPEGGIO;
+                        entry->effectvalue = ptr[1];
+                        break;
+
+                    case 71:
+                        entry->effect = IT_S;
+                        entry->effectvalue =
+                            EFFECT_VALUE(IT_S_FINETUNE, ptr[1] & 0xF);
+                        break;
+
+                    case 72:
+                        /* "balance" ... panning? */
+                        entry->effect = IT_SET_PANNING;
+                        entry->effectvalue =
+                            ((ptr[1] - ((ptr[1] & 8) >> 3)) << 5) / 7;
+                        break;
+
+                    default:
+                        entry->mask &= ~IT_ENTRY_EFFECT;
+                    }
+
+                    ptr += 2;
+                }
+                if (entry->mask)
+                    entry++;
+            }
+        }
+
+        p->n_entries = (int)(entry - p->entry);
+        offset += psize;
+    }
+
+    free(buffer);
+
+    return 0;
+
+error_fb:
+    free(buffer);
+error:
+    return -1;
+}
+
+#define PSM_COMPONENT_ORDERS 0
+#define PSM_COMPONENT_PANPOS 1
+#define PSM_COMPONENT_PATTERNS 2
+#define PSM_COMPONENT_SAMPLE_HEADERS 3
+#define PSM_COMPONENT_COMMENTS 4
+
+typedef struct PSM_COMPONENT {
+    unsigned char type;
+    long offset;
+} PSM_COMPONENT;
+
+static int psm_component_compare(const void *e1, const void *e2) {
+    return (int)(((const PSM_COMPONENT *)e1)->offset -
+                 ((const PSM_COMPONENT *)e2)->offset);
+}
+
+static DUMB_IT_SIGDATA *it_old_psm_load_sigdata(DUMBFILE *f) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    PSM_COMPONENT *component;
+    int n_components = 0;
+
+    int n, flags, version, pver, n_orders, n_channels, total_pattern_size;
+
+    if (dumbfile_mgetl(f) != DUMB_ID('P', 'S', 'M', 254))
+        goto error;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        goto error;
+
+    if (dumbfile_getnc((char *)sigdata->name, 60, f) < 60 ||
+        sigdata->name[59] != 0x1A)
+        goto error_sd;
+    sigdata->name[59] = 0;
+
+    flags = dumbfile_getc(f);
+    version = dumbfile_getc(f);
+    pver = dumbfile_getc(f);
+    sigdata->speed = dumbfile_getc(f);
+    sigdata->tempo = dumbfile_getc(f);
+    sigdata->mixing_volume = dumbfile_getc(f);
+    sigdata->n_orders = dumbfile_igetw(f);
+    n_orders = dumbfile_igetw(f);
+    sigdata->n_patterns = dumbfile_igetw(f);
+    sigdata->n_samples = dumbfile_igetw(f);
+    sigdata->n_pchannels = dumbfile_igetw(f);
+    n_channels = dumbfile_igetw(f);
+
+    if (dumbfile_error(f) || (flags & 1) || (version != 1 && version != 0x10) ||
+        (pver) || (sigdata->n_orders <= 0) || (sigdata->n_orders > 255) ||
+        (n_orders > 255) || (n_orders < sigdata->n_orders) ||
+        (sigdata->n_patterns > 255) || (sigdata->n_samples > 255) ||
+        (sigdata->n_pchannels > DUMB_IT_N_CHANNELS) ||
+        (sigdata->n_pchannels > n_channels) ||
+        (n_channels > DUMB_IT_N_CHANNELS))
+        goto error_sd;
+
+    sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX;
+
+    sigdata->global_volume = 128;
+    sigdata->pan_separation = 128;
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+
+    sigdata->restart_position = 0;
+
+    sigdata->order = malloc(sigdata->n_orders);
+    if (!sigdata->order)
+        goto error_usd;
+
+    if (sigdata->n_samples) {
+        sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+        if (!sigdata->sample)
+            goto error_usd;
+        for (n = 0; n < sigdata->n_samples; n++)
+            sigdata->sample[n].data = NULL;
+    }
+
+    if (sigdata->n_patterns) {
+        sigdata->pattern =
+            malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+        if (!sigdata->pattern)
+            goto error_usd;
+        for (n = 0; n < sigdata->n_patterns; n++)
+            sigdata->pattern[n].entry = NULL;
+    }
+
+    component = malloc(5 * sizeof(*component));
+    if (!component)
+        goto error_usd;
+
+    for (n = 0; n < 5; n++) {
+        component[n_components].offset = dumbfile_igetl(f);
+        if (component[n_components].offset) {
+            component[n_components].type = n;
+            n_components++;
+        }
+    }
+
+    if (!n_components)
+        goto error_fc;
+
+    total_pattern_size = (int)dumbfile_igetl(f);
+    if (!total_pattern_size)
+        goto error_fc;
+
+    qsort(component, n_components, sizeof(PSM_COMPONENT),
+          &psm_component_compare);
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[n] = 32 - sep;
+        sigdata->channel_pan[n + 1] = 32 + sep;
+        sigdata->channel_pan[n + 2] = 32 + sep;
+        sigdata->channel_pan[n + 3] = 32 - sep;
+    }
+
+    for (n = 0; n < n_components; n++) {
+        int o;
+
+        if (dumbfile_seek(f, component[n].offset, DFS_SEEK_SET))
+            goto error_fc;
+
+        switch (component[n].type) {
+
+        case PSM_COMPONENT_ORDERS:
+            if (dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f) <
+                sigdata->n_orders)
+                goto error_fc;
+            if (n_orders > sigdata->n_orders)
+                if (dumbfile_skip(f, n_orders - sigdata->n_orders))
+                    goto error_fc;
+            if (dumbfile_igetw(f))
+                goto error_fc;
+            break;
+
+        case PSM_COMPONENT_PANPOS:
+            if (dumbfile_getnc((char *)sigdata->channel_pan,
+                               sigdata->n_pchannels, f) < sigdata->n_pchannels)
+                goto error_fc;
+            for (o = 0; o < sigdata->n_pchannels; o++) {
+                sigdata->channel_pan[o] -= (sigdata->channel_pan[o] & 8) >> 3;
+                sigdata->channel_pan[o] =
+                    ((int)sigdata->channel_pan[o] << 5) / 7;
+            }
+            break;
+
+        case PSM_COMPONENT_PATTERNS:
+            if (it_old_psm_read_patterns(
+                    sigdata->pattern, f, sigdata->n_patterns,
+                    total_pattern_size, sigdata->n_pchannels))
+                goto error_fc;
+            break;
+
+        case PSM_COMPONENT_SAMPLE_HEADERS:
+            if (it_old_psm_read_samples(&sigdata->sample, f,
+                                        &sigdata->n_samples))
+                goto error_fc;
+            break;
+
+        case PSM_COMPONENT_COMMENTS:
+            if (dumbfile_mgetl(f) == DUMB_ID('T', 'E', 'X', 'T')) {
+                o = dumbfile_igetw(f);
+                if (o > 0) {
+                    sigdata->song_message = malloc(o + 1);
+                    if (dumbfile_getnc((char *)sigdata->song_message, o, f) < o)
+                        goto error_fc;
+                    sigdata->song_message[o] = 0;
+                }
+            }
+            break;
+        }
+    }
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0)
+        goto error_fc;
+
+    free(component);
+
+    return sigdata;
+
+error_fc:
+    free(component);
+error_usd:
+    _dumb_it_unload_sigdata(sigdata);
+    return NULL;
+error_sd:
+    free(sigdata);
+error:
+    return NULL;
+}
+
+DUH *dumb_read_old_psm_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_old_psm_load_sigdata(f);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "PSM (old)";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readpsm.c
@@ -1,0 +1,1418 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readpsm.c - Code to read a Protracker Studio       / / \  \
+ *             module from an open file.             | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+#ifndef min
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifdef _MSC_VER
+#define snprintf sprintf_s
+#endif
+
+#define PSMV_OLD 940730
+#define PSMV_NEW 940902
+
+typedef struct _PSMCHUNK {
+    int id;
+    size_t len;
+    unsigned char *data;
+} PSMCHUNK;
+
+typedef struct _PSMEVENT {
+    int type;
+    unsigned char data[8];
+} PSMEVENT;
+
+#define PSM_EVENT_END 0
+#define PSM_EVENT_PLAY_PATTERN 1
+#define PSM_EVENT_JUMP_TO_LINE 4
+#define PSM_EVENT_SET_SPEED 7
+#define PSM_EVENT_SET_BPM 8
+#define PSM_EVENT_SAMPLE_MAP_TABLE 12
+#define PSM_EVENT_CHANGE_PAN 13
+#define PSM_EVENT_CHANGE_VOL 14
+
+static int it_psm_process_sample(IT_SAMPLE *sample, const unsigned char *data,
+                                 size_t len, int id, int version) {
+    int flags;
+    int insno;
+    size_t length;
+    int loopstart;
+    int loopend;
+    int panpos;
+    int defvol;
+    int samplerate;
+
+    if (len < 0x60)
+        return -1;
+
+    flags = data[0];
+
+    if (version == PSMV_OLD) {
+        memcpy(sample->name, data + 0x0D, 34);
+        sample->name[34] = 0;
+
+        insno = data[0x34] | (data[0x35] << 8);
+        length = data[0x36] | (data[0x37] << 8) | (data[0x38] << 16) |
+                 (data[0x39] << 24);
+        loopstart = data[0x3A] | (data[0x3B] << 8) | (data[0x3C] << 16) |
+                    (data[0x3D] << 24);
+        loopend = data[0x3E] | (data[0x3F] << 8) | (data[0x40] << 16) |
+                  (data[0x41] << 24);
+        panpos = data[0x43];
+        defvol = data[0x44];
+        samplerate = data[0x49] | (data[0x4A] << 8) | (data[0x4B] << 16) |
+                     (data[0x4C] << 24);
+    } else /*if (version == PSMV_NEW)*/ {
+        memcpy(sample->name, data + 0x11, 34);
+        sample->name[34] = 0;
+
+        insno = data[0x38] | (data[0x39] << 8);
+        length = data[0x3A] | (data[0x3B] << 8) | (data[0x3C] << 16) |
+                 (data[0x3D] << 24);
+        loopstart = data[0x3E] | (data[0x3F] << 8) | (data[0x40] << 16) |
+                    (data[0x41] << 24);
+        loopend = data[0x42] | (data[0x43] << 8) | (data[0x44] << 16) |
+                  (data[0x45] << 24);
+        panpos = data[0x48];
+        defvol = data[0x49];
+        samplerate = data[0x4E] | (data[0x4F] << 8) | (data[0x50] << 16) |
+                     (data[0x51] << 24);
+    }
+
+    if (insno != id)
+        return -1;
+
+    if (length <= 0) {
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+        return 0;
+    }
+
+    if ((length > len - 0x60) || ((flags & 0x7F) != 0))
+        return -1;
+
+    sample->flags = IT_SAMPLE_EXISTS;
+    sample->length = length;
+    sample->loop_start = loopstart;
+    sample->loop_end = loopend;
+    sample->C5_speed = samplerate;
+    sample->default_volume = defvol >> 1;
+    sample->default_pan = 0;
+    sample->filename[0] = 0;
+    sample->global_volume = 64;
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = IT_VIBRATO_SINE;
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    if (flags & 0x80) {
+        if (((unsigned int)sample->loop_end <= (unsigned int)sample->length) &&
+            ((unsigned int)sample->loop_start <
+             (unsigned int)sample->loop_end)) {
+            sample->length = sample->loop_end;
+            sample->flags |= IT_SAMPLE_LOOP;
+        }
+    }
+
+    sample->data = malloc(sample->length);
+    if (!sample->data)
+        return -1;
+
+    flags = 0;
+    data += 0x60;
+
+    for (insno = 0; insno < sample->length; insno++) {
+        flags += (signed char)(*data++);
+        ((signed char *)sample->data)[insno] = flags;
+    }
+
+    return 0;
+}
+
+static int it_psm_process_pattern(IT_PATTERN *pattern,
+                                  const unsigned char *data, size_t len,
+                                  int speed, int bpm, const unsigned char *pan,
+                                  const int *vol, int version) {
+    size_t length, pos, rowlen;
+    int nrows, row;
+    unsigned flags, chan;
+    IT_ENTRY *entry;
+
+    length = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+    if (len > length)
+        len = length;
+
+    if (version == PSMV_OLD) {
+        if (len < 10)
+            return -1;
+        data += 8;
+        len -= 8;
+    } else /*if (version == PSMV_NEW)*/ {
+        if (len < 14)
+            return -1;
+        data += 12;
+        len -= 12;
+    }
+
+    nrows = data[0] | (data[1] << 8);
+
+    if (!nrows) {
+        pattern->n_rows = 0;
+        pattern->n_entries = 0;
+        pattern->entry = NULL;
+        return 0;
+    }
+
+    pattern->n_rows = nrows;
+
+    data += 2;
+    len -= 2;
+
+    pattern->n_entries = 0;
+
+    row = 0;
+    pos = 2;
+    rowlen = data[0] | (data[1] << 8);
+
+    while ((row < nrows) && (pos < len)) {
+        if (pos >= rowlen) {
+            row++;
+            rowlen += data[pos] | (data[pos + 1] << 8);
+            pos += 2;
+            continue;
+        }
+
+        flags = data[pos++];
+        chan = data[pos++];
+
+        if (chan > 63)
+            return -1;
+
+        if (flags & 0xF0) {
+            pattern->n_entries++;
+            if (flags & 0x80)
+                pos++;
+            if (flags & 0x40)
+                pos++;
+            if (flags & 0x20)
+                pos++;
+            if (flags & 0x10) {
+                switch (data[pos]) {
+                case 0x29:
+                    pos++;
+                case 0x33:
+                    pos++;
+                default:
+                    pos += 2;
+                }
+            }
+        }
+    }
+
+    if (!pattern->n_entries)
+        return 0;
+
+    pattern->n_entries += nrows;
+    if (speed)
+        pattern->n_entries++;
+    if (bpm >= 0x20)
+        pattern->n_entries++;
+
+    for (pos = 0; pos < 32; pos++) {
+        if (!(pan[pos * 2 + 1] & 0xF9))
+            pattern->n_entries++;
+        if (vol[pos] != -1)
+            pattern->n_entries++;
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+
+    if (speed) {
+        entry->channel = 0;
+        entry->mask = IT_ENTRY_EFFECT;
+        entry->effect = IT_SET_SPEED;
+        entry->effectvalue = speed;
+        entry++;
+    }
+
+    if (bpm >= 0x20) {
+        entry->channel = 0;
+        entry->mask = IT_ENTRY_EFFECT;
+        entry->effect = IT_SET_SONG_TEMPO;
+        entry->effectvalue = bpm;
+        entry++;
+    }
+
+    for (pos = 0; pos < 32; pos++) {
+        if (!(pan[pos * 2 + 1] & 0xF9)) {
+            entry->channel = pos;
+            entry->mask = IT_ENTRY_EFFECT;
+            switch (pan[pos * 2 + 1]) {
+            case 0:
+                entry->effect = IT_SET_PANNING;
+                entry->effectvalue = pan[pos * 2] ^ 128;
+                break;
+            case 2:
+                entry->effect = IT_S;
+                entry->effectvalue = EFFECT_VALUE(IT_S_SET_SURROUND_SOUND, 1);
+                break;
+            case 4:
+                entry->effect = IT_SET_PANNING;
+                entry->effectvalue = 128;
+                break;
+            }
+            entry++;
+        }
+        if (vol[pos] != -1) {
+            entry->channel = pos;
+            entry->mask = IT_ENTRY_EFFECT;
+            entry->effect = IT_SET_CHANNEL_VOLUME;
+            entry->effectvalue = (vol[pos] + 2) >> 2;
+            entry++;
+        }
+    }
+
+    row = 0;
+    pos = 2;
+    rowlen = data[0] | (data[1] << 8);
+
+    while ((row < nrows) && (pos < len)) {
+        if (pos >= rowlen) {
+            IT_SET_END_ROW(entry);
+            entry++;
+            row++;
+            rowlen += data[pos] | (data[pos + 1] << 8);
+            pos += 2;
+            continue;
+        }
+
+        flags = data[pos++];
+        entry->channel = data[pos++];
+        entry->mask = 0;
+
+        if (flags & 0xF0) {
+            if (flags & 0x80) {
+                entry->mask |= IT_ENTRY_NOTE;
+                if (version == PSMV_OLD) {
+                    if ((data[pos] < 0x80))
+                        entry->note =
+                            (data[pos] >> 4) * 12 + (data[pos] & 0x0f) + 12;
+                    else
+                        entry->mask &= ~IT_ENTRY_NOTE;
+                } else /*if (version == PSMV_NEW)*/ {
+                    if ((data[pos]) && (data[pos] < 84))
+                        entry->note = data[pos] + 35;
+                    else
+                        entry->mask &= ~IT_ENTRY_NOTE;
+                }
+                pos++;
+            }
+
+            if (flags & 0x40) {
+                entry->mask |= IT_ENTRY_INSTRUMENT;
+                entry->instrument = data[pos++] + 1;
+            }
+
+            if (flags & 0x20) {
+                entry->mask |= IT_ENTRY_VOLPAN;
+                entry->volpan = (data[pos++] + 1) >> 1;
+            }
+
+            if (flags & 0x10) {
+                entry->mask |= IT_ENTRY_EFFECT;
+                length = data[pos + 1];
+                switch (data[pos]) {
+                case 1:
+                    entry->effect = IT_VOLUME_SLIDE;
+                    if (version == PSMV_OLD)
+                        entry->effectvalue = ((length & 0x1e) << 3) | 0xF;
+                    else /*if (version == PSMV_NEW)*/
+                        entry->effectvalue = (length << 4) | 0xF;
+                    break;
+
+                case 2:
+                    entry->effect = IT_VOLUME_SLIDE;
+                    if (version == PSMV_OLD)
+                        entry->effectvalue = (length << 3) & 0xF0;
+                    else /*if (version == PSMV_NEW)*/
+                        entry->effectvalue = (length << 4) & 0xF0;
+                    break;
+
+                case 3:
+                    entry->effect = IT_VOLUME_SLIDE;
+                    if (version == PSMV_OLD)
+                        entry->effectvalue = (length >> 1) | 0xF0;
+                    else /*if (version == PSMV_NEW)*/
+                        entry->effectvalue = length | 0xF0;
+                    break;
+
+                case 4:
+                    entry->effect = IT_VOLUME_SLIDE;
+                    if (version == PSMV_OLD)
+                        entry->effectvalue = (length >> 1) & 0xF;
+                    else /*if (version == PSMV_NEW)*/
+                        entry->effectvalue = length & 0xF;
+                    break;
+
+                case 12:
+                    entry->effect = IT_PORTAMENTO_UP;
+                    if (version == PSMV_OLD) {
+                        if (length < 4)
+                            entry->effectvalue = length | 0xF0;
+                        else
+                            entry->effectvalue = length >> 2;
+                    } else /*if (version == PSMV_NEW)*/ {
+                        entry->effectvalue = length;
+                    }
+                    break;
+
+                case 14:
+                    entry->effect = IT_PORTAMENTO_DOWN;
+                    if (version == PSMV_OLD) {
+                        if (length < 4)
+                            entry->effectvalue = length | 0xF0;
+                        else
+                            entry->effectvalue = length >> 2;
+                    } else /*if (version == PSMV_NEW)*/ {
+                        entry->effectvalue = length;
+                    }
+                    break;
+
+                case 15:
+                    entry->effect = IT_TONE_PORTAMENTO;
+                    if (version == PSMV_OLD)
+                        entry->effectvalue = length >> 2;
+                    else /*if (version == PSMV_NEW)*/
+                        entry->effectvalue = length;
+                    break;
+
+                case 0x15:
+                    entry->effect = IT_VIBRATO;
+                    entry->effectvalue = length;
+                    break;
+
+                case 0x18:
+                    entry->effect = IT_VOLSLIDE_VIBRATO;
+                    entry->effectvalue = length;
+                    break;
+
+                case 0x29:
+                    entry->effect = IT_SET_SAMPLE_OFFSET;
+                    entry->effectvalue = data[pos + 2];
+                    pos += 2;
+                    break;
+
+                case 0x2A:
+                    entry->effect = IT_RETRIGGER_NOTE;
+                    entry->effectvalue = length;
+                    break;
+
+                case 0x33:
+#if 0
+						entry->effect = IT_POSITION_JUMP;
+						entry->effectvalue = data[pos+2];
+#else
+                    entry->mask &= ~IT_ENTRY_EFFECT;
+#endif
+                    pos++;
+                    break;
+
+                case 0x34:
+                    entry->effect = IT_BREAK_TO_ROW;
+                    entry->effectvalue = length;
+                    break;
+
+                case 0x3D:
+                    entry->effect = IT_SET_SPEED;
+                    entry->effectvalue = length;
+                    break;
+
+                case 0x3E:
+                    if (length >= 0x20) {
+                        entry->effect = IT_SET_SONG_TEMPO;
+                        entry->effectvalue = length;
+                    } else {
+                        entry->mask &= ~IT_ENTRY_EFFECT;
+                    }
+                    break;
+
+                case 0x47:
+                    entry->effect = IT_ARPEGGIO;
+                    entry->effectvalue = length;
+                    break;
+
+                default:
+                    return -1;
+                }
+                pos += 2;
+            }
+            if (entry->mask)
+                entry++;
+        }
+    }
+
+    while (row < nrows) {
+        IT_SET_END_ROW(entry);
+        entry++;
+        row++;
+    }
+
+    pattern->n_entries = (int)((long)entry - (long)pattern->entry);
+    if (!pattern->n_entries)
+        return -1;
+
+    return 0;
+}
+
+static void free_chunks(PSMCHUNK *chunk, int count) {
+    int n;
+
+    for (n = 0; n < count; n++) {
+        if (chunk[n].data)
+            free(chunk[n].data);
+    }
+
+    free(chunk);
+}
+
+static void dumb_it_optimize_orders(DUMB_IT_SIGDATA *sigdata);
+
+static int pattcmp(const unsigned char *, const unsigned char *, size_t);
+
+static DUMB_IT_SIGDATA *it_psm_load_sigdata(DUMBFILE *f, int *ver,
+                                            int subsong) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    PSMCHUNK *chunk;
+    int n_chunks = 0;
+
+    PSMCHUNK *songchunk = 0;
+    int n_song_chunks = 0;
+
+    PSMEVENT *event = 0;
+    int n_events = 0;
+
+    unsigned char *ptr;
+
+    int n, length;
+    int o;
+
+    int found;
+
+    int n_patterns = 0;
+
+    long first_pattern_line = -1;
+    int first_pattern;
+
+    int speed, bpm;
+    unsigned char pan[64];
+    int vol[32];
+
+    if (dumbfile_mgetl(f) != DUMB_ID('P', 'S', 'M', ' '))
+        goto error;
+
+    length = (int)dumbfile_igetl(f);
+
+    if (dumbfile_mgetl(f) != DUMB_ID('F', 'I', 'L', 'E'))
+        goto error;
+
+    chunk = calloc(768, sizeof(*chunk));
+
+    while (length >= 8) {
+        if (n_chunks >= 768)
+            goto error_fc;
+        chunk[n_chunks].id = (unsigned int)dumbfile_mgetl(f);
+        n = (int)dumbfile_igetl(f);
+        length -= 8;
+        if ((signed int)n <= 0 || n > length)
+            goto error_fc;
+        chunk[n_chunks].len = n;
+        if (n) {
+            ptr = malloc(n);
+            if (!ptr)
+                goto error_fc;
+            if (dumbfile_getnc((char *)ptr, n, f) < n) {
+                free(ptr);
+                goto error_fc;
+            }
+            chunk[n_chunks].data = ptr;
+        }
+        n_chunks++;
+        length -= n;
+    }
+
+    if (!n_chunks)
+        goto error_fc;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        goto error_fc;
+
+    sigdata->n_patterns = 0;
+    sigdata->n_samples = 0;
+    sigdata->name[0] = 0;
+
+    found = 0;
+
+    for (n = 0; n < n_chunks; n++) {
+        PSMCHUNK *c = &chunk[n];
+        switch (c->id) {
+        case DUMB_ID('S', 'D', 'F', 'T'):
+            /* song data format? */
+            if ((found & 1) || (c->len != 8) || memcmp(c->data, "MAINSONG", 8))
+                goto error_sd;
+            found |= 1;
+            break;
+
+        case DUMB_ID('S', 'O', 'N', 'G'):
+            if (/*(found & 2) ||*/ (c->len <
+                                    11) /*|| memcmp(c->data, "MAINSONG", 8)*/)
+                goto error_sd;
+            found |= 2;
+            break;
+
+        case DUMB_ID('D', 'S', 'M', 'P'):
+            sigdata->n_samples++;
+            break;
+
+        case DUMB_ID('T', 'I', 'T', 'L'):
+            length = min(sizeof(sigdata->name) - 1, (unsigned)c->len);
+            memcpy(sigdata->name, c->data, length);
+            sigdata->name[length] = 0;
+        }
+    }
+
+    if (found != 3 || !sigdata->n_samples)
+        goto error_sd;
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+    sigdata->n_orders = 0;
+
+    for (n = 0; n < n_chunks; n++) {
+        PSMCHUNK *c = &chunk[n];
+        if (c->id == DUMB_ID('S', 'O', 'N', 'G')) {
+            if (subsong == 0)
+                break;
+            subsong--;
+        }
+    }
+
+    if (n == n_chunks)
+        return NULL;
+    subsong = (int)n;
+
+    /*for (n = 0; n < n_chunks; n++) {
+            PSMCHUNK * c = &chunk[n];
+            if (c->id == DUMB_ID('S','O','N','G')) {*/
+    {
+        PSMCHUNK *c = &chunk[subsong];
+        {
+            ptr = c->data;
+            if (ptr[10] > 32)
+                goto error_usd;
+            sigdata->n_pchannels = ptr[10];
+            length = (int)(c->len - 11);
+            ptr += 11;
+            songchunk = 0;
+            if (length >= 8) {
+                songchunk = malloc(256 * sizeof(*songchunk));
+                if (!songchunk)
+                    goto error_usd;
+                while (length >= 8) {
+                    if (n_song_chunks >= 256)
+                        goto error_sc;
+                    songchunk[n_song_chunks].id =
+                        DUMB_ID(ptr[0], ptr[1], ptr[2], ptr[3]);
+                    n = ptr[4] | (ptr[5] << 8) | (ptr[6] << 16) |
+                        (ptr[7] << 24);
+                    length -= 8;
+                    if ((signed int)n < 0 || n > length)
+                        goto error_sc;
+                    songchunk[n_song_chunks].len = n;
+                    songchunk[n_song_chunks].data = ptr + 8;
+                    n_song_chunks++;
+                    length -= n;
+                    ptr += 8 + n;
+                }
+            }
+            /*break;*/
+        }
+    }
+
+    if (!n_song_chunks)
+        goto error_sc;
+
+    found = 0;
+
+    for (n = 0; n < n_song_chunks; n++) {
+        PSMCHUNK *c = &songchunk[n];
+
+        if (c->id == DUMB_ID('D', 'A', 'T', 'E')) {
+            /* date of the library build / format spec */
+            if (c->len == 6) {
+                length = (int)c->len;
+                ptr = c->data;
+                while (length > 0) {
+                    if (*ptr >= '0' && *ptr <= '9') {
+                        found = (found * 10) + (*ptr - '0');
+                    } else {
+                        found = 0;
+                        break;
+                    }
+                    ptr++;
+                    length--;
+                }
+            }
+            break;
+        }
+    }
+
+    /*
+    if (found != 940506 &&
+            found != 940509 &&
+            found != 940510 &&
+            found != 940530 &&
+            found != 940629 &&
+            found != PSMV_OLD &&
+            found != 941011 &&
+            found != PSMV_NEW &&
+            found != 940906 &&
+            found != 940903 &&
+            found != 940914 &&
+            found != 941213 &&
+    found != 800211)    WTF?
+            goto error_sc;
+    */
+
+    *ver = found;
+
+    if (found == 800211 || found == PSMV_NEW || found == 940903 ||
+        found == 940906 || found == 940914 || found == 941213)
+        found = PSMV_NEW;
+    else
+        found = PSMV_OLD;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+
+    for (n = 0; n < DUMB_IT_N_CHANNELS; n += 4) {
+        int sep = 32 * dumb_it_default_panning_separation / 100;
+        sigdata->channel_pan[n] = 32 - sep;
+        sigdata->channel_pan[n + 1] = 32 + sep;
+        sigdata->channel_pan[n + 2] = 32 + sep;
+        sigdata->channel_pan[n + 3] = 32 - sep;
+    }
+
+    for (n = 0; n < n_song_chunks; n++) {
+        PSMCHUNK *c = &songchunk[n];
+
+        switch (c->id) {
+        case DUMB_ID('O', 'P', 'L', 'H'):
+            if (c->len < 2)
+                goto error_sc;
+            ptr = c->data;
+            o = ptr[0] | (ptr[1] << 8);
+            if (!o)
+                goto error_sc;
+            event = malloc(o * sizeof(*event));
+            if (!event)
+                goto error_sc;
+            length = (int)(c->len - 2);
+            ptr += 2;
+            while ((length > 0) && (n_events < o)) {
+                event[n_events].type = *ptr;
+                switch (*ptr) {
+                case PSM_EVENT_END:
+                    ptr++;
+                    length--;
+                    break;
+
+                case PSM_EVENT_PLAY_PATTERN:
+                    if (found == PSMV_OLD) {
+                        if (length < 5)
+                            goto error_ev;
+                        memcpy(event[n_events].data, ptr + 1, 4);
+                        ptr += 5;
+                        length -= 5;
+                    } else /*if (found == PSMV_NEW)*/ {
+                        if (length < 9)
+                            goto error_ev;
+                        memcpy(event[n_events].data, ptr + 1, 8);
+                        ptr += 9;
+                        length -= 9;
+                    }
+                    break;
+
+                case PSM_EVENT_SET_SPEED:
+                case PSM_EVENT_SET_BPM:
+                    if (length < 2)
+                        goto error_ev;
+                    event[n_events].data[0] = ptr[1];
+                    ptr += 2;
+                    length -= 2;
+                    break;
+
+                case PSM_EVENT_JUMP_TO_LINE:
+                case PSM_EVENT_CHANGE_VOL:
+                    if (length < 3)
+                        goto error_ev;
+                    memcpy(event[n_events].data, ptr + 1, 2);
+                    ptr += 3;
+                    length -= 3;
+                    break;
+
+                case PSM_EVENT_SAMPLE_MAP_TABLE:
+                    if (length < 7)
+                        goto error_ev;
+                    memcpy(event[n_events].data, ptr + 1, 6);
+                    ptr += 7;
+                    length -= 7;
+                    break;
+
+                case PSM_EVENT_CHANGE_PAN:
+                    if (length < 4)
+                        goto error_ev;
+                    memcpy(event[n_events].data, ptr + 1, 3);
+                    ptr += 4;
+                    length -= 4;
+                    break;
+
+                default:
+                    goto error_ev;
+                }
+                n_events++;
+            }
+            break;
+
+        case DUMB_ID('P', 'P', 'A', 'N'):
+            length = (int)c->len;
+            if (length & 1)
+                goto error_ev;
+            ptr = c->data;
+            o = 0;
+            while (length > 0) {
+                switch (ptr[0]) {
+                case 0:
+                    sigdata->channel_pan[o] =
+                        ((((int)(signed char)ptr[1]) * 32) / 127) + 32;
+                    break;
+                case 2:
+                    sigdata->channel_pan[o] = IT_SURROUND;
+                    break;
+                case 4:
+                    sigdata->channel_pan[o] = 32;
+                    break;
+                }
+                ptr += 2;
+                length -= 2;
+                if (++o >= DUMB_IT_N_CHANNELS)
+                    break;
+            }
+            break;
+
+            /*
+            case DUMB_ID('P','A','T','T'):
+            case DUMB_ID('D','S','A','M'):
+            */
+        }
+    }
+
+    sigdata->flags = IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX;
+
+    sigdata->global_volume = 128;
+    sigdata->speed = 6;
+    sigdata->tempo = 125;
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    speed = 0;
+    bpm = 0;
+    memset(pan, 255, sizeof(pan));
+    memset(vol, 255, sizeof(vol));
+
+    sigdata->n_patterns = n_events;
+    sigdata->pattern = malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+    if (!sigdata->pattern)
+        goto error_ev;
+    for (n = 0; n < sigdata->n_patterns; n++)
+        sigdata->pattern[n].entry = NULL;
+
+    for (n = 0; n < n_events; n++) {
+        PSMEVENT *e = &event[n];
+        switch (e->type) {
+        case PSM_EVENT_END:
+            n = n_events;
+            break;
+
+        case PSM_EVENT_PLAY_PATTERN:
+            for (o = 0; o < n_chunks; o++) {
+                PSMCHUNK *c = &chunk[o];
+                if (c->id == DUMB_ID('P', 'B', 'O', 'D')) {
+                    ptr = c->data;
+                    length = (int)c->len;
+                    if (found == PSMV_OLD) {
+                        if (length < 8)
+                            goto error_ev;
+                        if (!pattcmp(ptr + 4, e->data, 4)) {
+                            if (it_psm_process_pattern(
+                                    &sigdata->pattern[n_patterns], ptr, length,
+                                    speed, bpm, pan, vol, found))
+                                goto error_ev;
+                            if (first_pattern_line < 0) {
+                                first_pattern_line = n;
+                                first_pattern = o;
+                            }
+                            e->data[0] = n_patterns;
+                            e->data[1] = n_patterns >> 8;
+                            n_patterns++;
+                            break;
+                        }
+                    } else /*if (found == PSMV_NEW)*/ {
+                        if (length < 12)
+                            goto error_ev;
+                        if (!pattcmp(ptr + 4, e->data, 8)) {
+                            if (it_psm_process_pattern(
+                                    &sigdata->pattern[n_patterns], ptr, length,
+                                    speed, bpm, pan, vol, found))
+                                goto error_ev;
+                            if (first_pattern_line < 0) {
+                                first_pattern_line = n;
+                                first_pattern = o;
+                            }
+                            e->data[0] = n_patterns;
+                            e->data[1] = n_patterns >> 8;
+                            n_patterns++;
+                            break;
+                        }
+                    }
+                }
+            }
+            if (o == n_chunks)
+                goto error_ev;
+
+            speed = 0;
+            bpm = 0;
+            memset(pan, 255, sizeof(pan));
+            memset(vol, 255, sizeof(vol));
+
+            e->type = PSM_EVENT_END;
+            break;
+
+        case PSM_EVENT_JUMP_TO_LINE:
+            o = e->data[0] | (e->data[1] << 8);
+            if (o >= n_events)
+                goto error_ev;
+            if (o == 0) {
+                /* whew! easy case! */
+                sigdata->restart_position = 0;
+                n = n_events;
+            } else if (o == n) {
+                /* freeze */
+                n = n_events;
+            } else if (o > n) {
+                /* jump ahead, setting played event numbers to zero will prevent
+                 * endless looping */
+                n = o - 1;
+            } else if (o >= first_pattern_line) {
+                /* another semi-easy case */
+                sigdata->restart_position =
+                    event[o].data[0] | (event[o].data[1] << 8);
+                n = n_events;
+            } else {
+                /* crud, try to simulate rerunning all of the commands from the
+                 * indicated line up to the first pattern, then dupe the first
+                 * pattern again.
+                 */
+                /*
+                PSMCHUNK * c = &chunk[first_pattern];
+
+                for (; o < first_pattern_line; o++) {
+                        PSMEVENT * ev = &event[o];
+                        switch (ev->type) {
+                        case PSM_EVENT_SET_SPEED:
+                                speed = ev->data[0];
+                                break;
+                        case PSM_EVENT_SET_BPM:
+                                bpm = ev->data[0];
+                                break;
+                        case PSM_EVENT_CHANGE_PAN:
+                                if (ev->data[0] > 31) goto error_ev;
+                                pan[ev->data[0] * 2] = ev->data[1];
+                                pan[ev->data[0] * 2 + 1] = ev->data[2];
+                                break;
+                        case PSM_EVENT_CHANGE_VOL:
+                                if (ev->data[0] > 31) goto error_ev;
+                                vol[ev->data[0]] = ev->data[1];
+                                break;
+                        }
+                }
+
+                if (it_psm_process_pattern(&sigdata->pattern[n_patterns],
+                c->data, c->len, speed, bpm, pan, vol, found)) goto error_ev;
+                n_patterns++;
+                sigdata->restart_position = 1;
+                n = n_events;
+
+                Eh, what the hell? PSM has no panning commands anyway.
+                */
+                sigdata->restart_position = 0;
+                n = n_events;
+            }
+            e->type = PSM_EVENT_END;
+            break;
+
+        case PSM_EVENT_SET_SPEED:
+            speed = e->data[0];
+            break;
+
+        case PSM_EVENT_SET_BPM:
+            bpm = e->data[0];
+            break;
+
+        case PSM_EVENT_CHANGE_PAN:
+            o = e->data[0];
+            if (o > 31)
+                goto error_ev;
+            pan[o * 2] = e->data[1];
+            pan[o * 2 + 1] = e->data[2];
+            break;
+
+        case PSM_EVENT_CHANGE_VOL:
+            o = e->data[0];
+            if (o > 31)
+                goto error_ev;
+            vol[o] = e->data[1];
+            break;
+
+        case PSM_EVENT_SAMPLE_MAP_TABLE:
+            if (e->data[0] != 0 || e->data[1] != 0xFF || e->data[2] != 0 ||
+                e->data[3] != 0 || e->data[4] != 1 || e->data[5] != 0)
+                goto error_ev;
+            break;
+        }
+    }
+
+    if (n_patterns > 256)
+        goto error_ev;
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample)
+        goto error_ev;
+    for (n = 0; n < sigdata->n_samples; n++) {
+        sigdata->sample[n].data = NULL;
+        sigdata->sample[n].flags = 0;
+    }
+
+    o = 0;
+    for (n = 0; n < n_chunks; n++) {
+        PSMCHUNK *c = &chunk[n];
+        if (c->id == DUMB_ID('D', 'S', 'M', 'P')) {
+            if (it_psm_process_sample(&sigdata->sample[o], c->data, c->len, o,
+                                      found))
+                goto error_ev;
+            o++;
+        }
+    }
+
+    sigdata->n_orders = n_patterns;
+    sigdata->n_patterns = n_patterns;
+
+    sigdata->order = malloc(n_patterns);
+
+    for (n = 0; n < n_patterns; n++) {
+        sigdata->order[n] = n;
+    }
+
+    free(event);
+    free(songchunk);
+    free_chunks(chunk, n_chunks);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    dumb_it_optimize_orders(sigdata);
+
+    return sigdata;
+
+error_ev:
+    free(event);
+error_sc:
+    if (songchunk)
+        free(songchunk);
+error_usd:
+    _dumb_it_unload_sigdata(sigdata);
+    goto error_fc;
+error_sd:
+    free(sigdata);
+error_fc:
+    free_chunks(chunk, n_chunks);
+error:
+    return NULL;
+}
+
+static int it_order_compare(const void *e1, const void *e2) {
+    if (*((const char *)e1) < *((const char *)e2))
+        return -1;
+
+    if (*((const char *)e1) > *((const char *)e2))
+        return 1;
+
+    return 0;
+}
+
+/*
+static int it_optimize_compare(const void *e1, const void *e2) {
+        if (((const IT_ENTRY *)e1)->channel < ((const IT_ENTRY *)e2)->channel)
+                return -1;
+
+        if (((const IT_ENTRY *)e1)->channel > ((const IT_ENTRY *)e2)->channel)
+                return 1;
+
+        return 0;
+}
+*/
+
+static int it_entry_compare(const IT_ENTRY *e1, const IT_ENTRY *e2) {
+    if (IT_IS_END_ROW(e1) && IT_IS_END_ROW(e2))
+        return 1;
+    if (e1->channel != e2->channel)
+        return 0;
+    if (e1->mask != e2->mask)
+        return 0;
+    if ((e1->mask & IT_ENTRY_NOTE) && (e1->note != e2->note))
+        return 0;
+    if ((e1->mask & IT_ENTRY_INSTRUMENT) && (e1->instrument != e2->instrument))
+        return 0;
+    if ((e1->mask & IT_ENTRY_VOLPAN) && (e1->volpan != e2->volpan))
+        return 0;
+    if ((e1->mask & IT_ENTRY_EFFECT) &&
+        ((e1->effect != e2->effect) || (e1->effectvalue != e2->effectvalue)))
+        return 0;
+    return 1;
+}
+
+/*
+static void dumb_it_optimize_pattern(IT_PATTERN * pattern) {
+        IT_ENTRY * entry, * end;
+        IT_ENTRY * rowstart, * rowend;
+        IT_ENTRY * current;
+
+        if (!pattern->n_entries || !pattern->entry) return;
+
+        current = entry = pattern->entry;
+        end = entry + pattern->n_entries;
+
+        while (entry < end) {
+                rowstart = entry;
+                while (!IT_IS_END_ROW(entry)) entry++;
+                rowend = entry;
+                if (rowend > rowstart + 1)
+                        qsort(rowstart, rowend - rowstart, sizeof(IT_ENTRY),
+&it_optimize_compare); entry = rowstart; while (entry < rowend) { if
+(!(entry->mask)) {} else if (it_entry_compare(entry, current)) {} else if
+(!(current->mask) ||
+                                         ((entry->channel == current->channel)
+&&
+                                         ((entry->mask | current->mask) ==
+(entry->mask ^ current->mask)))) { current->mask |= entry->mask; if (entry->mask
+& IT_ENTRY_NOTE) current->note = entry->note; if (entry->mask &
+IT_ENTRY_INSTRUMENT) current->instrument = entry->instrument; if (entry->mask &
+IT_ENTRY_VOLPAN) current->volpan = entry->volpan; if (entry->mask &
+IT_ENTRY_EFFECT) { current->effect = entry->effect; current->effectvalue =
+entry->effectvalue;
+                                }
+                        } else {
+                                if (++current < entry) *current = *entry;
+                        }
+                        entry++;
+                }
+                if (++current < entry) *current = *entry;
+                entry++;
+        }
+
+        current++;
+
+        if (current < end) {
+                IT_ENTRY * opt;
+                pattern->n_entries = current - pattern->entry;
+                opt = realloc(pattern->entry, pattern->n_entries *
+sizeof(*pattern->entry)); if (opt) pattern->entry = opt;
+        }
+}
+*/
+
+static int it_pattern_compare(const IT_PATTERN *p1, const IT_PATTERN *p2) {
+    IT_ENTRY *e1, *end;
+    IT_ENTRY *e2;
+
+    if (p1 == p2)
+        return 1;
+    if (p1->n_entries != p2->n_entries)
+        return 0;
+
+    e1 = p1->entry;
+    end = e1 + p1->n_entries;
+    e2 = p2->entry;
+
+    while (e1 < end) {
+        if (!it_entry_compare(e1, e2))
+            return 0;
+        e1++;
+        e2++;
+    }
+
+    return 1;
+}
+
+static void dumb_it_optimize_orders(DUMB_IT_SIGDATA *sigdata) {
+    int n, o, p;
+
+    /*int last_invalid = (sigdata->flags & IT_WAS_AN_XM) ? 255 : 253;*/
+
+    unsigned char *order_list;
+    int n_patterns;
+
+    IT_PATTERN *pattern;
+
+    if (!sigdata->n_orders || !sigdata->n_patterns)
+        return;
+
+    n_patterns = 0;
+    order_list = malloc(sigdata->n_orders);
+
+    if (!order_list)
+        return;
+
+    for (n = 0; n < sigdata->n_orders; n++) {
+        if (sigdata->order[n] < sigdata->n_patterns) {
+            for (o = 0; o < n_patterns; o++) {
+                if (sigdata->order[n] == order_list[o])
+                    break;
+            }
+            if (o == n_patterns) {
+                order_list[n_patterns++] = sigdata->order[n];
+            }
+        }
+    }
+
+    if (!n_patterns) {
+        free(order_list);
+        return;
+    }
+
+    /*for (n = 0; n < n_patterns; n++) {
+            dumb_it_optimize_pattern(&sigdata->pattern[order_list[n]]);
+    }*/
+
+    for (n = 0; n < n_patterns; n++) {
+        for (o = n + 1; o < n_patterns; o++) {
+            if ((order_list[n] != order_list[o]) &&
+                it_pattern_compare(&sigdata->pattern[order_list[n]],
+                                   &sigdata->pattern[order_list[o]])) {
+                for (p = 0; p < sigdata->n_orders; p++) {
+                    if (sigdata->order[p] == order_list[o]) {
+                        sigdata->order[p] = order_list[n];
+                    }
+                }
+                for (p = o + 1; p < n_patterns; p++) {
+                    if (order_list[p] == order_list[o]) {
+                        order_list[p] = order_list[n];
+                    }
+                }
+                order_list[o] = order_list[n];
+            }
+        }
+    }
+
+    qsort(order_list, n_patterns, sizeof(*order_list), &it_order_compare);
+
+    for (n = 0, o = 0; n < n_patterns; n++) {
+        if (order_list[n] != order_list[o]) {
+            if (++o < n)
+                order_list[o] = order_list[n];
+        }
+    }
+
+    n_patterns = o + 1;
+
+    pattern = malloc(n_patterns * sizeof(*pattern));
+    if (!pattern) {
+        free(order_list);
+        return;
+    }
+
+    for (n = 0; n < n_patterns; n++) {
+        pattern[n] = sigdata->pattern[order_list[n]];
+    }
+
+    for (n = 0; n < sigdata->n_patterns; n++) {
+        for (o = 0; o < n_patterns; o++) {
+            if (order_list[o] == n)
+                break;
+        }
+        if (o == n_patterns) {
+            if (sigdata->pattern[n].entry)
+                free(sigdata->pattern[n].entry);
+        }
+    }
+
+    free(sigdata->pattern);
+    sigdata->pattern = pattern;
+    sigdata->n_patterns = n_patterns;
+
+    for (n = 0; n < sigdata->n_orders; n++) {
+        for (o = 0; o < n_patterns; o++) {
+            if (sigdata->order[n] == order_list[o]) {
+                sigdata->order[n] = o;
+                break;
+            }
+        }
+    }
+
+    free(order_list);
+}
+
+int dumb_get_psm_subsong_count(DUMBFILE *f) {
+    size_t length;
+    int subsongs;
+    long l;
+
+    if (dumbfile_mgetl(f) != DUMB_ID('P', 'S', 'M', ' '))
+        return 0;
+
+    length = dumbfile_igetl(f);
+
+    if (dumbfile_mgetl(f) != DUMB_ID('F', 'I', 'L', 'E'))
+        return 0;
+
+    subsongs = 0;
+
+    while (length >= 8 && !dumbfile_error(f)) {
+        if (dumbfile_mgetl(f) == DUMB_ID('S', 'O', 'N', 'G'))
+            subsongs++;
+        l = dumbfile_igetl(f);
+        dumbfile_skip(f, l);
+        length -= l + 8;
+    }
+
+    if (dumbfile_error(f))
+        return 0;
+
+    return subsongs;
+}
+
+/* Eww */
+int pattcmp(const unsigned char *a, const unsigned char *b, size_t l) {
+    long i, j;
+    unsigned long na, nb;
+    char *p;
+
+    na = nb = 0;
+
+    i = memcmp(a, b, l);
+    if (!i)
+        return 0;
+
+    /* damnit */
+
+    for (i = 0; i < l; ++i) {
+        if (a[i] >= '0' && a[i] <= '9')
+            break;
+    }
+
+    if (i < l) {
+        na = strtoul((const char *)a + i, &p, 10);
+        if ((const unsigned char *)p == a + i)
+            return 1;
+    }
+
+    for (j = 0; j < l; ++j) {
+        if (b[j] >= '0' && b[j] <= '9')
+            break;
+    }
+
+    if (j < l) {
+        nb = strtoul((const char *)b + j, &p, 10);
+        if ((const unsigned char *)p == b + j)
+            return -1;
+    }
+
+    if (i < j)
+        return -1;
+    else if (i > j)
+        return 1;
+
+    i = memcmp(a, b, j);
+    if (i)
+        return (int)i;
+
+    return (int)(((long)na) - ((long)nb));
+}
+
+DUH *dumb_read_psm_quick(DUMBFILE *f, int subsong) {
+    sigdata_t *sigdata;
+    int ver;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_psm_load_sigdata(f, &ver, subsong);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        int n_tags = 2;
+        char version[16];
+        const char *tag[3][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "PSM";
+        if (ver) {
+            tag[2][0] = "FORMATVERSION";
+            snprintf(version, 15, "%d", ver);
+            version[15] = 0;
+            tag[2][1] = (const char *)&version;
+            ++n_tags;
+        }
+        return make_duh(-1, n_tags, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readptm.c
@@ -1,0 +1,565 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readptm.c - Code to read a Poly Tracker v2.03      / / \  \
+ *             module from an open file.             | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill. Based on reads3m.c        \_  /  > /
+ * by entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+// IT_STEREO... :o
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+static int it_ptm_read_sample_header(IT_SAMPLE *sample, long *offset,
+                                     DUMBFILE *f) {
+    int flags;
+
+    flags = dumbfile_getc(f);
+
+    dumbfile_getnc((char *)sample->filename, 12, f);
+    sample->filename[12] = 0;
+
+    sample->default_volume = dumbfile_getc(f);
+
+    sample->C5_speed = dumbfile_igetw(f) << 1;
+
+    dumbfile_skip(f, 2); /* segment */
+
+    *offset = dumbfile_igetl(f);
+
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = dumbfile_igetl(f);
+
+    /* GUSBegin, GUSLStart, GUSLEnd, GUSLoop, reserverd */
+    dumbfile_skip(f, 4 + 4 + 4 + 1 + 1);
+
+    dumbfile_getnc((char *)sample->name, 28, f);
+    sample->name[28] = 0;
+
+    /*
+    if (dumbfile_mgetl(f) != DUMB_ID('P','T','M','S'))
+            return -1;
+    */
+
+    /* BLAH! Shit likes to have broken or missing sample IDs */
+    dumbfile_skip(f, 4);
+
+    if ((flags & 3) == 0) {
+        /* Looks like no sample */
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+        return dumbfile_error(f);
+    }
+
+    sample->global_volume = 64;
+
+    sample->flags = IT_SAMPLE_EXISTS;
+    if (flags & 4)
+        sample->flags |= IT_SAMPLE_LOOP;
+    if (flags & 8)
+        sample->flags |= IT_SAMPLE_PINGPONG_LOOP;
+
+    if (flags & 16) {
+        sample->flags |= IT_SAMPLE_16BIT;
+
+        sample->length >>= 1;
+        sample->loop_start >>= 1;
+        sample->loop_end >>= 1;
+    }
+
+    if (sample->loop_end)
+        sample->loop_end--;
+
+    sample->default_pan = 0; // 0 = don't use, or 160 = centre?
+
+    if (sample->length <= 0)
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+    else if (sample->flags & IT_SAMPLE_LOOP) {
+        if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
+            sample->flags &= ~IT_SAMPLE_LOOP;
+        else if ((unsigned int)sample->loop_start >=
+                 (unsigned int)sample->loop_end)
+            sample->flags &= ~IT_SAMPLE_LOOP;
+        else
+            sample->length = sample->loop_end;
+    }
+
+    // Do we need to set all these?
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = IT_VIBRATO_SINE;
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+static int it_ptm_read_byte(DUMBFILE *f) {
+    int meh = dumbfile_getc(f);
+    if (meh < 0)
+        return 0;
+    return meh;
+}
+
+static int it_ptm_read_sample_data(IT_SAMPLE *sample, int last, DUMBFILE *f) {
+    long n;
+    int s;
+
+    sample->data =
+        malloc(sample->length * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
+    if (!sample->data)
+        return -1;
+
+    s = 0;
+
+    if (sample->flags & IT_SAMPLE_16BIT) {
+        unsigned char a, b;
+        for (n = 0; n < sample->length; n++) {
+            a = s += (signed char)it_ptm_read_byte(f);
+            b = s += (signed char)it_ptm_read_byte(f);
+            ((short *)sample->data)[n] = a | (b << 8);
+        }
+    } else {
+        for (n = 0; n < sample->length; n++) {
+            s += (signed char)it_ptm_read_byte(f);
+            ((signed char *)sample->data)[n] = s;
+        }
+    }
+
+    if (dumbfile_error(f) && !last)
+        return -1;
+
+    return 0;
+}
+
+static int it_ptm_read_pattern(IT_PATTERN *pattern, DUMBFILE *f,
+                               unsigned char *buffer, size_t length) {
+    int buflen = 0;
+    int bufpos = 0;
+    int effect, effectvalue;
+
+    IT_ENTRY *entry;
+
+    unsigned char channel;
+
+    if (!length)
+        return -1;
+
+    pattern->n_rows = 0;
+    pattern->n_entries = 0;
+
+    /* Read in the pattern data, little by little, and work out how many
+     * entries we need room for. Sorry, but this is just so funny...
+     */
+    for (;;) {
+        unsigned char b = buffer[buflen++] = dumbfile_getc(f);
+
+#if 1
+        static const unsigned char used[8] = {0, 2, 2, 4, 1, 3, 3, 5};
+        channel = b & 31;
+        b >>= 5;
+        pattern->n_entries++;
+        if (b) {
+            if (buflen + used[b] >= 65536)
+                return -1;
+            dumbfile_getnc((char *)buffer + buflen, used[b], f);
+            buflen += used[b];
+        } else {
+            /* End of row */
+            if (++pattern->n_rows == 64)
+                break;
+            if (buflen >= 65536)
+                return -1;
+        }
+#else
+        if (b == 0) {
+            /* End of row */
+            pattern->n_entries++;
+            if (++pattern->n_rows == 64)
+                break;
+            if (buflen >= 65536)
+                return -1;
+        } else {
+            static const unsigned char used[8] = {0, 2, 2, 4, 1, 3, 3, 5};
+            channel = b & 31;
+            b >>= 5;
+            if (b) {
+                pattern->n_entries++;
+                if (buflen + used[b] >= 65536)
+                    return -1;
+                dumbfile_getnc(buffer + buflen, used[b], f);
+                buflen += used[b];
+            }
+        }
+#endif
+
+        /* We have ensured that buflen < 65536 at this point, so it is safe
+         * to iterate and read at least one more byte without checking.
+         * However, now would be a good time to check for errors reading from
+         * the file.
+         */
+
+        if (dumbfile_error(f))
+            return -1;
+
+        /* Great. We ran out of data, but there should be data for more rows.
+         * Fill the rest with null data...
+         */
+        if (buflen >= (dumb_ssize_t)length && pattern->n_rows < 64) {
+            while (pattern->n_rows < 64) {
+                if (buflen >= 65536)
+                    return -1;
+                buffer[buflen++] = 0;
+                pattern->n_entries++;
+                pattern->n_rows++;
+            }
+            break;
+        }
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+
+    while (bufpos < buflen) {
+        unsigned char b = buffer[bufpos++];
+
+        if (b == 0) {
+            /* End of row */
+            IT_SET_END_ROW(entry);
+            entry++;
+            continue;
+        }
+
+        channel = b & 31;
+
+        if (b & 224) {
+            entry->mask = 0;
+            entry->channel = channel;
+
+            if (b & 32) {
+                unsigned char n = buffer[bufpos++];
+                if (n == 254 || (n >= 1 && n <= 120)) {
+                    if (n == 254)
+                        entry->note = IT_NOTE_CUT;
+                    else
+                        entry->note = n - 1;
+                    entry->mask |= IT_ENTRY_NOTE;
+                }
+
+                entry->instrument = buffer[bufpos++];
+                if (entry->instrument)
+                    entry->mask |= IT_ENTRY_INSTRUMENT;
+            }
+
+            if (b & 64) {
+                effect = buffer[bufpos++];
+                effectvalue = buffer[bufpos++];
+                _dumb_it_ptm_convert_effect(effect, effectvalue, entry);
+            }
+
+            if (b & 128) {
+                entry->volpan = buffer[bufpos++];
+                if (entry->volpan <= 64)
+                    entry->mask |= IT_ENTRY_VOLPAN;
+            }
+
+            entry++;
+        }
+    }
+
+    ASSERT(entry == pattern->entry + pattern->n_entries);
+
+    return 0;
+}
+
+/** WARNING: this is duplicated in itread.c - also bad practice to use the same
+ * struct name unless they are unified in a header */
+/* Currently we assume the sample data are stored after the sample headers in
+ * module files. This assumption may be unjustified; let me know if you have
+ * trouble.
+ */
+
+#define PTM_COMPONENT_INSTRUMENT 1
+#define PTM_COMPONENT_PATTERN 2
+#define PTM_COMPONENT_SAMPLE 3
+
+typedef struct PTM_COMPONENT {
+    unsigned char type;
+    unsigned char n;
+    long offset;
+} PTM_COMPONENT;
+
+static int ptm_component_compare(const void *e1, const void *e2) {
+    return (int)(((const PTM_COMPONENT *)e1)->offset -
+                 ((const PTM_COMPONENT *)e2)->offset);
+}
+
+static DUMB_IT_SIGDATA *it_ptm_load_sigdata(DUMBFILE *f) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    PTM_COMPONENT *component;
+    int n_components = 0;
+
+    int n;
+
+    unsigned char *buffer;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        return NULL;
+
+    /* Skip song name. */
+    dumbfile_getnc((char *)sigdata->name, 28, f);
+    sigdata->name[28] = 0;
+
+    if (dumbfile_getc(f) != 0x1A || dumbfile_igetw(f) != 0x203) {
+        free(sigdata);
+        return NULL;
+    }
+
+    dumbfile_skip(f, 1);
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_orders = dumbfile_igetw(f);
+    sigdata->n_instruments = 0;
+    sigdata->n_samples = dumbfile_igetw(f);
+    sigdata->n_patterns = dumbfile_igetw(f);
+
+    if (dumbfile_error(f) || sigdata->n_orders <= 0 ||
+        sigdata->n_orders > 1024 || // Whoa, nelly.
+        sigdata->n_samples > 255 || sigdata->n_patterns > 128) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->n_pchannels = dumbfile_igetw(f);
+
+    if (dumbfile_igetw(f) != 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    dumbfile_skip(f, 2);
+
+    if (dumbfile_mgetl(f) != DUMB_ID('P', 'T', 'M', 'F')) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    dumbfile_skip(f, 16);
+
+    sigdata->order = malloc(sigdata->n_orders);
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (sigdata->n_samples) {
+        sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+        if (!sigdata->sample) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_samples; n++)
+            sigdata->sample[n].data = NULL;
+    }
+
+    if (sigdata->n_patterns) {
+        sigdata->pattern =
+            malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+        if (!sigdata->pattern) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_patterns; n++)
+            sigdata->pattern[n].entry = NULL;
+    }
+
+    /** WARNING: which ones? */
+    sigdata->flags =
+        IT_STEREO | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_A_PTM;
+
+    sigdata->global_volume = 128;
+    sigdata->speed = 6;
+    sigdata->tempo = 125;
+    sigdata->mixing_volume = 48;
+
+    /* Panning positions for 32 channels */
+    {
+        int i;
+        for (i = 0; i < 32; i++) {
+            int c = dumbfile_getc(f);
+            if (c <= 15) {
+                sigdata->channel_volume[i] = 64;
+                sigdata->channel_pan[i] = c;
+            } else {
+                /** WARNING: this could be improved if we support channel
+                 * muting... */
+                sigdata->channel_volume[i] = 0;
+                sigdata->channel_pan[i] = 7;
+            }
+        }
+    }
+
+    /* Orders, byte each, length = sigdata->n_orders (should be even) */
+    dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
+    sigdata->restart_position = 0;
+
+    component = malloc(768 * sizeof(*component));
+    if (!component) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (dumbfile_seek(f, 352, DFS_SEEK_SET)) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (n = 0; n < sigdata->n_patterns; n++) {
+        component[n_components].type = PTM_COMPONENT_PATTERN;
+        component[n_components].n = n;
+        component[n_components].offset = dumbfile_igetw(f) << 4;
+        n_components++;
+    }
+
+    if (dumbfile_seek(f, 608, DFS_SEEK_SET)) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (n = 0; n < sigdata->n_samples; n++) {
+        if (it_ptm_read_sample_header(&sigdata->sample[n],
+                                      &component[n_components].offset, f)) {
+            free(component);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        if (!(sigdata->sample[n].flags & IT_SAMPLE_EXISTS))
+            continue;
+        component[n_components].type = PTM_COMPONENT_SAMPLE;
+        component[n_components].n = n;
+        n_components++;
+    }
+
+    qsort(component, n_components, sizeof(PTM_COMPONENT),
+          &ptm_component_compare);
+
+    {
+        int i;
+        for (i = 0; i < 32; i++) {
+            sigdata->channel_pan[i] -= (sigdata->channel_pan[i] & 8) >> 3;
+            sigdata->channel_pan[i] = ((int)sigdata->channel_pan[i] << 5) / 7;
+            if (sigdata->channel_pan[i] > 64)
+                sigdata->channel_pan[i] = 64;
+        }
+    }
+
+    sigdata->pan_separation = 128;
+
+    if (dumbfile_error(f)) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    buffer = malloc(65536);
+    if (!buffer) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (n = 0; n < n_components; n++) {
+        if (dumbfile_seek(f, component[n].offset, DFS_SEEK_SET)) {
+            free(buffer);
+            free(component);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+
+        switch (component[n].type) {
+
+        case PTM_COMPONENT_PATTERN:
+            if (it_ptm_read_pattern(
+                    &sigdata->pattern[component[n].n], f, buffer,
+                    (n + 1 < n_components)
+                        ? (component[n + 1].offset - component[n].offset)
+                        : 0)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+            break;
+
+        case PTM_COMPONENT_SAMPLE:
+            if (it_ptm_read_sample_data(&sigdata->sample[component[n].n],
+                                        (n + 1 == n_components), f)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+        }
+    }
+
+    free(buffer);
+    free(component);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+DUH *dumb_read_ptm_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_ptm_load_sigdata(f);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "PTM";
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readriff.c
@@ -1,0 +1,58 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readriff.c - Code to read a RIFF module file       / / \  \
+ *              from memory.                         | <  /   \_
+ *                                                   |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+#include "internal/it.h"
+#include "internal/riff.h"
+
+DUH *dumb_read_riff_amff(DUMBFILE *f, struct riff *stream);
+DUH *dumb_read_riff_am(DUMBFILE *f, struct riff *stream);
+DUH *dumb_read_riff_dsmf(DUMBFILE *f, struct riff *stream);
+
+/* dumb_read_riff_quick(): reads a RIFF file into a DUH struct, returning a
+ * pointer to the DUH struct. When you have finished with it, you must pass
+ * the pointer to unload_duh() so that the memory can be freed.
+ */
+DUH *dumb_read_riff_quick(DUMBFILE *f) {
+    DUH *duh;
+    struct riff *stream;
+    long size;
+
+    size = dumbfile_get_size(f);
+
+    stream = riff_parse(f, 0, size, 1);
+    if (!stream)
+        stream = riff_parse(f, 0, size, 0);
+
+    if (!stream)
+        return 0;
+
+    if (stream->type == DUMB_ID('A', 'M', ' ', ' '))
+        duh = dumb_read_riff_am(f, stream);
+    else if (stream->type == DUMB_ID('A', 'M', 'F', 'F'))
+        duh = dumb_read_riff_amff(f, stream);
+    else if (stream->type == DUMB_ID('D', 'S', 'M', 'F'))
+        duh = dumb_read_riff_dsmf(f, stream);
+    else
+        duh = 0;
+
+    riff_free(stream);
+
+    return duh;
+}
--- /dev/null
+++ b/src/it/reads3m.c
@@ -1,0 +1,780 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * reads3m.c - Code to read a ScreamTracker 3         / / \  \
+ *             module from an open file.             | <  /   \_
+ *                                                   |  \/ /\   /
+ * By entheh.                                         \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+// IT_STEREO... :o
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+static int it_s3m_read_sample_header(IT_SAMPLE *sample, long *offset,
+                                     unsigned char *pack, int cwtv,
+                                     DUMBFILE *f) {
+    unsigned char type;
+    int flags;
+
+    type = dumbfile_getc(f);
+
+    dumbfile_getnc((char *)sample->filename, 12, f);
+    sample->filename[12] = 0;
+
+    if (type > 1) {
+        /** WARNING: no adlib support */
+        dumbfile_skip(f, 3 + 12 + 1 + 1 + 2 + 2 + 2 + 12);
+        dumbfile_getnc((char *)sample->name, 28, f);
+        sample->name[28] = 0;
+        dumbfile_skip(f, 4);
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+        return dumbfile_error(f);
+    }
+
+    *offset = dumbfile_getc(f) << 20;
+    *offset += dumbfile_igetw(f) << 4;
+
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = dumbfile_igetl(f);
+
+    sample->default_volume = dumbfile_getc(f);
+
+    dumbfile_skip(f, 1);
+
+    flags = dumbfile_getc(f);
+
+    if (flags < 0 || (flags != 0 && flags != 4))
+        /* Sample is packed apparently (or error reading from file). We don't
+         * know how to read packed samples.
+         */
+        return -1;
+
+    *pack = flags;
+
+    flags = dumbfile_getc(f);
+
+    sample->C5_speed = dumbfile_igetl(f) << 1;
+
+    /* Skip four unused bytes and three internal variables. */
+    dumbfile_skip(f, 4 + 2 + 2 + 4);
+
+    dumbfile_getnc((char *)sample->name, 28, f);
+    sample->name[28] = 0;
+
+    if (type == 0 || sample->length <= 0) {
+        /* Looks like no-existy. Anyway, there's for sure no 'SCRS' ... */
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+        return dumbfile_error(f);
+    }
+
+    if (dumbfile_mgetl(f) != DUMB_ID('S', 'C', 'R', 'S'))
+        return -1;
+
+    sample->global_volume = 64;
+
+    sample->flags = IT_SAMPLE_EXISTS;
+    if (flags & 1)
+        sample->flags |= IT_SAMPLE_LOOP;
+
+    /* The ST3 TECH.DOC is unclear on this, but IMAGO Orpheus is not. Piece of
+     * crap. */
+
+    if (flags & 2) {
+        sample->flags |= IT_SAMPLE_STEREO;
+
+        if ((cwtv & 0xF000) == 0x2000) {
+            sample->length >>= 1;
+            sample->loop_start >>= 1;
+            sample->loop_end >>= 1;
+        }
+    }
+
+    if (flags & 4) {
+        sample->flags |= IT_SAMPLE_16BIT;
+
+        if ((cwtv & 0xF000) == 0x2000) {
+            sample->length >>= 1;
+            sample->loop_start >>= 1;
+            sample->loop_end >>= 1;
+        }
+    }
+
+    sample->default_pan = 0; // 0 = don't use, or 160 = centre?
+
+    if (sample->flags & IT_SAMPLE_LOOP) {
+        if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
+            /*sample->flags &= ~IT_SAMPLE_LOOP;*/
+            sample->loop_end = sample->length;
+        else if ((unsigned int)sample->loop_start >=
+                 (unsigned int)sample->loop_end)
+            sample->flags &= ~IT_SAMPLE_LOOP;
+        else
+            /* ScreamTracker seems not to save what comes after the loop end
+             * point, but rather to assume it is a duplicate of what comes at
+             * the loop start point. I am not completely sure of this though.
+             * It is easy to evade; simply truncate the sample.
+             */
+            sample->length = sample->loop_end;
+    }
+
+    // Do we need to set all these?
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = IT_VIBRATO_SINE;
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+static int it_s3m_read_sample_data(IT_SAMPLE *sample, int ffi,
+                                   unsigned char pack, DUMBFILE *f) {
+    long n;
+
+    long datasize = sample->length;
+    if (sample->flags & IT_SAMPLE_STEREO)
+        datasize <<= 1;
+
+    sample->data = malloc(datasize * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
+    if (!sample->data)
+        return -1;
+
+    if (pack == 4) {
+        if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
+            return -1;
+    } else if (sample->flags & IT_SAMPLE_STEREO) {
+        if (sample->flags & IT_SAMPLE_16BIT) {
+            for (n = 0; n < datasize; n += 2)
+                ((short *)sample->data)[n] = dumbfile_igetw(f);
+            for (n = 1; n < datasize; n += 2)
+                ((short *)sample->data)[n] = dumbfile_igetw(f);
+        } else {
+            for (n = 0; n < datasize; n += 2)
+                ((signed char *)sample->data)[n] = dumbfile_getc(f);
+            for (n = 1; n < datasize; n += 2)
+                ((signed char *)sample->data)[n] = dumbfile_getc(f);
+        }
+    } else if (sample->flags & IT_SAMPLE_16BIT)
+        for (n = 0; n < sample->length; n++)
+            ((short *)sample->data)[n] = dumbfile_igetw(f);
+    else
+        for (n = 0; n < sample->length; n++)
+            ((signed char *)sample->data)[n] = dumbfile_getc(f);
+
+    if (dumbfile_error(f))
+        return -1;
+
+    if (ffi != 1) {
+        /* Convert to signed. */
+        if (sample->flags & IT_SAMPLE_16BIT)
+            for (n = 0; n < datasize; n++)
+                ((short *)sample->data)[n] ^= 0x8000;
+        else
+            for (n = 0; n < datasize; n++)
+                ((signed char *)sample->data)[n] ^= 0x80;
+    }
+
+    return 0;
+}
+
+static int it_s3m_read_pattern(IT_PATTERN *pattern, DUMBFILE *f,
+                               unsigned char *buffer) {
+    int length;
+    int buflen = 0;
+    int bufpos = 0;
+
+    IT_ENTRY *entry;
+
+    unsigned char channel;
+
+    /* Haha, this is hilarious!
+     *
+     * Well, after some experimentation, it seems that different S3M writers
+     * define the format in different ways. The S3M docs say that the first
+     * two bytes hold the "length of [the] packed pattern", and the packed
+     * pattern data follow. Judging by the contents of ARMANI.S3M, packaged
+     * with ScreamTracker itself, the measure of length _includes_ the two
+     * bytes used to store the length; in other words, we should read
+     * (length - 2) more bytes. However, aryx.s3m, packaged with ModPlug
+     * Tracker, excludes these two bytes, so (length) more bytes must be
+     * read.
+     *
+     * Call me crazy, but I just find it insanely funny that the format was
+     * misunderstood in this way :D
+     *
+     * Now we can't just risk reading two extra bytes, because then we
+     * overshoot, and DUMBFILEs don't support backward seeking (for a good
+     * reason). Luckily, there is a way. We can read the data little by
+     * little, and stop when we have 64 rows in memory. Provided we protect
+     * against buffer overflow, this method should work with all sensibly
+     * written S3M files. If you find one for which it does not work, please
+     * let me know at entheh@users.sf.net so I can look at it.
+     *
+     * "for a good reason" ? What's this nonsense? -kode54
+     *
+     */
+
+    length = dumbfile_igetw(f);
+
+    if (dumbfile_error(f) || !length)
+        return -1;
+
+    pattern->n_rows = 0;
+    pattern->n_entries = 0;
+
+    /* Read in the pattern data, little by little, and work out how many
+     * entries we need room for. Sorry, but this is just so funny...
+     */
+    for (;;) {
+        unsigned char b = buffer[buflen++] = dumbfile_getc(f);
+
+#if 1
+        static const unsigned char used[8] = {0, 2, 1, 3, 2, 4, 3, 5};
+        channel = b & 31;
+        b >>= 5;
+        pattern->n_entries++;
+        if (b) {
+            if (buflen + used[b] >= 65536)
+                return -1;
+            if (buflen + used[b] <= length)
+                dumbfile_getnc((char *)buffer + buflen, used[b], f);
+            else
+                memset(buffer + buflen, 0, used[b]);
+            buflen += used[b];
+        } else {
+            /* End of row */
+            if (++pattern->n_rows == 64)
+                break;
+            if (buflen >= 65536)
+                return -1;
+        }
+#else
+        if (b == 0) {
+            /* End of row */
+            pattern->n_entries++;
+            if (++pattern->n_rows == 64)
+                break;
+            if (buflen >= 65536)
+                return -1;
+        } else {
+            static const unsigned char used[8] = {0, 2, 1, 3, 2, 4, 3, 5};
+            channel = b & 31;
+            b >>= 5;
+            if (b) {
+                pattern->n_entries++;
+                if (buflen + used[b] >= 65536)
+                    return -1;
+                dumbfile_getnc(buffer + buflen, used[b], f);
+                buflen += used[b];
+            }
+        }
+#endif
+
+        /* We have ensured that buflen < 65536 at this point, so it is safe
+         * to iterate and read at least one more byte without checking.
+         * However, now would be a good time to check for errors reading from
+         * the file.
+         */
+
+        if (dumbfile_error(f))
+            return -1;
+
+        /* Great. We ran out of data, but there should be data for more rows.
+         * Fill the rest with null data...
+         */
+        if (buflen >= length && pattern->n_rows < 64) {
+            while (pattern->n_rows < 64) {
+                if (buflen >= 65536)
+                    return -1;
+                buffer[buflen++] = 0;
+                pattern->n_entries++;
+                pattern->n_rows++;
+            }
+            break;
+        }
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+
+    while (bufpos < buflen) {
+        unsigned char b = buffer[bufpos++];
+
+#if 1
+        if (!(b & ~31))
+#else
+        if (b == 0)
+#endif
+        {
+            /* End of row */
+            IT_SET_END_ROW(entry);
+            entry++;
+            continue;
+        }
+
+        channel = b & 31;
+
+        if (b & 224) {
+            entry->mask = 0;
+            entry->channel = channel;
+
+            if (b & 32) {
+                unsigned char n = buffer[bufpos++];
+                if (n != 255) {
+                    if (n == 254)
+                        entry->note = IT_NOTE_CUT;
+                    else
+                        entry->note = (n >> 4) * 12 + (n & 15);
+                    entry->mask |= IT_ENTRY_NOTE;
+                }
+
+                entry->instrument = buffer[bufpos++];
+                if (entry->instrument)
+                    entry->mask |= IT_ENTRY_INSTRUMENT;
+            }
+
+            if (b & 64) {
+                entry->volpan = buffer[bufpos++];
+                if (entry->volpan != 255)
+                    entry->mask |= IT_ENTRY_VOLPAN;
+            }
+
+            if (b & 128) {
+                entry->effect = buffer[bufpos++];
+                entry->effectvalue = buffer[bufpos++];
+                // XXX woot
+                if (entry->effect && entry->effect < IT_MIDI_MACRO /*!= 255*/) {
+                    entry->mask |= IT_ENTRY_EFFECT;
+                    switch (entry->effect) {
+                    case IT_BREAK_TO_ROW:
+                        entry->effectvalue -= (entry->effectvalue >> 4) * 6;
+                        break;
+
+                    case IT_SET_CHANNEL_VOLUME:
+                    case IT_CHANNEL_VOLUME_SLIDE:
+                    case IT_PANNING_SLIDE:
+                    case IT_GLOBAL_VOLUME_SLIDE:
+                    case IT_PANBRELLO:
+                    case IT_MIDI_MACRO:
+                        entry->mask &= ~IT_ENTRY_EFFECT;
+                        break;
+
+                    case IT_S:
+                        switch (entry->effectvalue >> 4) {
+                        case IT_S_SET_PANBRELLO_WAVEFORM:
+                        case IT_S_FINE_PATTERN_DELAY:
+                        case IT_S7:
+                        case IT_S_SET_SURROUND_SOUND:
+                        case IT_S_SET_MIDI_MACRO:
+                            entry->mask &= ~IT_ENTRY_EFFECT;
+                            break;
+                        }
+                        break;
+                    }
+                }
+                /** WARNING: ARGH! CONVERT TEH EFFECTS!@~ */
+            }
+
+            entry++;
+        }
+    }
+
+    ASSERT(entry == pattern->entry + pattern->n_entries);
+
+    return 0;
+}
+
+/** WARNING: this is duplicated in itread.c - also bad practice to use the same
+ * struct name unless they are unified in a header */
+/* Currently we assume the sample data are stored after the sample headers in
+ * module files. This assumption may be unjustified; let me know if you have
+ * trouble.
+ */
+
+#define S3M_COMPONENT_INSTRUMENT 1
+#define S3M_COMPONENT_PATTERN 2
+#define S3M_COMPONENT_SAMPLE 3
+
+typedef struct S3M_COMPONENT {
+    unsigned char type;
+    unsigned char n;
+    long offset;
+    short sampfirst; /* component[sampfirst] = first sample data after this */
+    short sampnext; /* sampnext is used to create linked lists of sample data */
+} S3M_COMPONENT;
+
+static int s3m_component_compare(const void *e1, const void *e2) {
+    return (int)(((const S3M_COMPONENT *)e1)->offset -
+                 ((const S3M_COMPONENT *)e2)->offset);
+}
+
+static DUMB_IT_SIGDATA *it_s3m_load_sigdata(DUMBFILE *f, int *cwtv) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    int flags, ffi;
+    int default_pan_present;
+
+    int master_volume;
+
+    unsigned char sample_pack[256];
+
+    S3M_COMPONENT *component;
+    int n_components = 0;
+
+    int n;
+
+    unsigned char *buffer;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        return NULL;
+
+    dumbfile_getnc((char *)sigdata->name, 28, f);
+    sigdata->name[28] = 0;
+
+    n = dumbfile_getc(f);
+
+    if (n != 0x1A && n != 0) {
+        free(sigdata);
+        return NULL;
+    }
+
+    if (dumbfile_getc(f) != 16) {
+        free(sigdata);
+        return NULL;
+    }
+
+    dumbfile_skip(f, 2);
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_orders = dumbfile_igetw(f);
+    sigdata->n_instruments = 0;
+    sigdata->n_samples = dumbfile_igetw(f);
+    sigdata->n_patterns = dumbfile_igetw(f);
+
+    if (dumbfile_error(f) || sigdata->n_orders <= 0 ||
+        sigdata->n_orders > 1024 || // Whoa, nelly.
+        sigdata->n_samples > 256 || sigdata->n_patterns > 256) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->order = malloc(sigdata->n_orders);
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (sigdata->n_samples) {
+        sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+        if (!sigdata->sample) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_samples; n++)
+            sigdata->sample[n].data = NULL;
+    }
+
+    if (sigdata->n_patterns) {
+        sigdata->pattern =
+            malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+        if (!sigdata->pattern) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_patterns; n++)
+            sigdata->pattern[n].entry = NULL;
+    }
+
+    flags = dumbfile_igetw(f);
+
+    *cwtv = dumbfile_igetw(f);
+
+    if (*cwtv == 0x1300) {
+        /** WARNING: volume slides on every frame */
+    }
+
+    ffi = dumbfile_igetw(f);
+
+    /** WARNING: which ones? */
+    sigdata->flags = IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M;
+
+    if (dumbfile_mgetl(f) != DUMB_ID('S', 'C', 'R', 'M')) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->global_volume = dumbfile_getc(f);
+    if (!sigdata->global_volume || sigdata->global_volume > 64)
+        sigdata->global_volume = 64;
+    sigdata->speed = dumbfile_getc(f);
+    if (sigdata->speed == 0)
+        sigdata->speed = 6; // Should we? What about tempo?
+    sigdata->tempo = dumbfile_getc(f);
+    master_volume = dumbfile_getc(f); // 7 bits; +128 for stereo
+    sigdata->mixing_volume = master_volume & 127;
+
+    if (master_volume & 128)
+        sigdata->flags |= IT_STEREO;
+
+    /* Skip GUS Ultra Click Removal byte. */
+    dumbfile_getc(f);
+
+    default_pan_present = dumbfile_getc(f);
+
+    dumbfile_skip(f, 8);
+
+    /* Skip Special Custom Data Pointer. */
+    /** WARNING: investigate this? */
+    dumbfile_igetw(f);
+
+    sigdata->n_pchannels = 0;
+    /* Channel settings for 32 channels, 255=unused, +128=disabled */
+    {
+        int i;
+        int sep = (7 * dumb_it_default_panning_separation + 50) / 100;
+        for (i = 0; i < 32; i++) {
+            int c = dumbfile_getc(f);
+            if (!(c & (128 | 16))) { /* +128=disabled, +16=Adlib */
+                if (sigdata->n_pchannels < i + 1)
+                    sigdata->n_pchannels = i + 1;
+                sigdata->channel_volume[i] = 64;
+                sigdata->channel_pan[i] = c & 8 ? 7 + sep : 7 - sep;
+                /** WARNING: ah, but it should be 7 for mono... */
+            } else {
+                /** WARNING: this could be improved if we support channel
+                 * muting... */
+                sigdata->channel_volume[i] = 0;
+                sigdata->channel_pan[i] = 7;
+            }
+        }
+    }
+
+    /* Orders, byte each, length = sigdata->n_orders (should be even) */
+    dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
+    sigdata->restart_position = 0;
+
+    component = malloc(768 * sizeof(*component));
+    if (!component) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (n = 0; n < sigdata->n_samples; n++) {
+        component[n_components].type = S3M_COMPONENT_SAMPLE;
+        component[n_components].n = n;
+        component[n_components].offset = dumbfile_igetw(f) << 4;
+        component[n_components].sampfirst = -1;
+        n_components++;
+    }
+
+    for (n = 0; n < sigdata->n_patterns; n++) {
+        long offset = dumbfile_igetw(f) << 4;
+        if (offset) {
+            component[n_components].type = S3M_COMPONENT_PATTERN;
+            component[n_components].n = n;
+            component[n_components].offset = offset;
+            component[n_components].sampfirst = -1;
+            n_components++;
+        } else {
+            /** WARNING: Empty 64-row pattern ... ? (this does happen!) */
+            sigdata->pattern[n].n_rows = 64;
+            sigdata->pattern[n].n_entries = 0;
+        }
+    }
+
+    qsort(component, n_components, sizeof(S3M_COMPONENT),
+          &s3m_component_compare);
+
+    /* I found a really dumb S3M file that claimed to contain default pan
+     * data but didn't contain any. Programs would load it by reading part of
+     * the first instrument header, assuming the data to be default pan
+     * positions, and then rereading the instrument module. We cannot do this
+     * without obfuscating the file input model, so we insert an extra check
+     * here that we won't overrun the start of the first component.
+     */
+    if (default_pan_present == 252 &&
+        component[0].offset >= dumbfile_pos(f) + 32) {
+        /* Channel default pan positions */
+        int i;
+        for (i = 0; i < 32; i++) {
+            int c = dumbfile_getc(f);
+            if (c & 32)
+                sigdata->channel_pan[i] = c & 15;
+        }
+    }
+
+    {
+        int i;
+        for (i = 0; i < 32; i++) {
+            sigdata->channel_pan[i] -= (sigdata->channel_pan[i] & 8) >> 3;
+            sigdata->channel_pan[i] = ((int)sigdata->channel_pan[i] << 5) / 7;
+        }
+    }
+
+    sigdata->pan_separation = 128;
+
+    if (dumbfile_error(f)) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    buffer = malloc(65536);
+    if (!buffer) {
+        free(component);
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    for (n = 0; n < n_components; n++) {
+        long offset;
+        int m;
+
+        offset = 0;
+        if (dumbfile_seek(f, component[n].offset, DFS_SEEK_SET)) {
+            free(buffer);
+            free(component);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+
+        switch (component[n].type) {
+
+        case S3M_COMPONENT_PATTERN:
+            if (it_s3m_read_pattern(&sigdata->pattern[component[n].n], f,
+                                    buffer)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+            break;
+
+        case S3M_COMPONENT_SAMPLE:
+            if (it_s3m_read_sample_header(&sigdata->sample[component[n].n],
+                                          &offset, &sample_pack[component[n].n],
+                                          *cwtv, f)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            if (sigdata->sample[component[n].n].flags & IT_SAMPLE_EXISTS) {
+                short *sample;
+
+                for (m = n + 1; m < n_components; m++)
+                    if (component[m].offset > offset)
+                        break;
+                m--;
+
+                sample = &component[m].sampfirst;
+
+                while (*sample >= 0 && component[*sample].offset <= offset)
+                    sample = &component[*sample].sampnext;
+
+                component[n].sampnext = *sample;
+                *sample = n;
+
+                component[n].offset = offset;
+            }
+        }
+
+        m = component[n].sampfirst;
+
+        while (m >= 0) {
+            // XXX
+            if (dumbfile_seek(f, component[m].offset, DFS_SEEK_SET)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            if (it_s3m_read_sample_data(&sigdata->sample[component[m].n], ffi,
+                                        sample_pack[component[m].n], f)) {
+                free(buffer);
+                free(component);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            m = component[m].sampnext;
+        }
+    }
+
+    free(buffer);
+    free(component);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+static char hexdigit(int in) {
+    if (in < 10)
+        return in + '0';
+    else
+        return in + 'A' - 10;
+}
+
+DUH *dumb_read_s3m_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+    int cwtv;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_s3m_load_sigdata(f, &cwtv);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        char version[8];
+        const char *tag[3][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        tag[1][1] = "S3M";
+        tag[2][0] = "TRACKERVERSION";
+        version[0] = hexdigit((cwtv >> 8) & 15);
+        version[1] = '.';
+        version[2] = hexdigit((cwtv >> 4) & 15);
+        version[3] = hexdigit(cwtv & 15);
+        version[4] = 0;
+        tag[2][1] = (const char *)&version;
+        return make_duh(-1, 3, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/reads3m2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * reads3m2.c - Function to read a ScreamTracker 3    / / \  \
+ *              module from an open file and do an   | <  /   \_
+ *              initial run-through.                 |  \/ /\   /
+ *                                                    \_  /  > /
+ * Split off from reads3m.c by entheh.                  | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_s3m(DUMBFILE *f) {
+    DUH *duh = dumb_read_s3m_quick(f);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/readstm.c
@@ -1,0 +1,404 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readstm.c - Code to read a ScreamTracker 2         / / \  \
+ *             module from an open file.             | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Christopher Snowhill.                           \_  /  > /
+ *                                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+// IT_STEREO... :o
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+#ifdef _MSC_VER
+#define strnicmp _strnicmp
+#else
+#if defined(unix) || defined(__unix__) || defined(__unix)
+#include <strings.h>
+#endif
+#define strnicmp strncasecmp
+#endif
+
+static int it_stm_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f,
+                                     unsigned short *offset) {
+    dumbfile_getnc((char *)sample->filename, 12, f);
+    sample->filename[12] = 0;
+
+    memcpy(sample->name, sample->filename, 13);
+
+    dumbfile_skip(f, 2);
+
+    *offset = dumbfile_igetw(f);
+
+    sample->length = dumbfile_igetw(f);
+    sample->loop_start = dumbfile_igetw(f);
+    sample->loop_end = dumbfile_igetw(f);
+
+    sample->default_volume = dumbfile_getc(f);
+
+    dumbfile_skip(f, 1);
+
+    sample->C5_speed = dumbfile_igetw(f) << 3;
+
+    dumbfile_skip(f, 6);
+
+    if (sample->length < 4 || !sample->default_volume) {
+        /* Looks like no-existy. */
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+        sample->length = 0;
+        *offset = 0;
+        return dumbfile_error(f);
+    }
+
+    sample->flags = IT_SAMPLE_EXISTS;
+    sample->global_volume = 64;
+    sample->default_pan = 0; // 0 = don't use, or 160 = centre?
+
+    if ((sample->loop_start < sample->length) &&
+        (sample->loop_end > sample->loop_start) &&
+        (sample->loop_end != 0xFFFF)) {
+        sample->flags |= IT_SAMPLE_LOOP;
+        if (sample->loop_end > sample->length)
+            sample->loop_end = sample->length;
+    }
+
+    // Do we need to set all these?
+    sample->vibrato_speed = 0;
+    sample->vibrato_depth = 0;
+    sample->vibrato_rate = 0;
+    sample->vibrato_waveform = IT_VIBRATO_SINE;
+    sample->finetune = 0;
+    sample->max_resampling_quality = -1;
+
+    return dumbfile_error(f);
+}
+
+static int it_stm_read_sample_data(IT_SAMPLE *sample, DUMBFILE *f) {
+    if (!sample->length)
+        return 0;
+
+    sample->data = malloc(sample->length);
+    if (!sample->data)
+        return -1;
+
+    dumbfile_getnc(sample->data, sample->length, f);
+
+    return dumbfile_error(f);
+}
+
+static int it_stm_read_pattern(IT_PATTERN *pattern, DUMBFILE *f,
+                               unsigned char *buffer) {
+    int pos;
+    int channel;
+    int row;
+    IT_ENTRY *entry;
+
+    pattern->n_rows = 64;
+
+    if (dumbfile_getnc((char *)buffer, 64 * 4 * 4, f) != 64 * 4 * 4)
+        return -1;
+
+    pattern->n_entries = 64;
+    pos = 0;
+    for (row = 0; row < 64; ++row) {
+        for (channel = 0; channel < 4; ++channel) {
+            if (buffer[pos + 0] | buffer[pos + 1] | buffer[pos + 2] |
+                buffer[pos + 3])
+                ++pattern->n_entries;
+            pos += 4;
+        }
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    entry = pattern->entry;
+    pos = 0;
+    for (row = 0; row < 64; ++row) {
+        for (channel = 0; channel < 4; ++channel) {
+            if (buffer[pos + 0] | buffer[pos + 1] | buffer[pos + 2] |
+                buffer[pos + 3]) {
+                unsigned note;
+                note = buffer[pos + 0];
+                entry->channel = channel;
+                entry->mask = 0;
+                entry->instrument = buffer[pos + 1] >> 3;
+                entry->volpan =
+                    (buffer[pos + 1] & 0x07) + (buffer[pos + 2] >> 1);
+                entry->effect = buffer[pos + 2] & 0x0F;
+                entry->effectvalue = buffer[pos + 3];
+                if (entry->instrument && entry->instrument < 32)
+                    entry->mask |= IT_ENTRY_INSTRUMENT;
+                if (note < 251) {
+                    entry->mask |= IT_ENTRY_NOTE;
+                    entry->note = (note >> 4) * 12 + (note & 0x0F);
+                }
+                if (entry->volpan <= 64)
+                    entry->mask |= IT_ENTRY_VOLPAN;
+                entry->mask |= IT_ENTRY_EFFECT;
+                switch (entry->effect) {
+                case IT_SET_SPEED:
+                    /* taken care of in the renderer */
+                    break;
+
+                case IT_BREAK_TO_ROW:
+                    entry->effectvalue -= (entry->effectvalue >> 4) * 6;
+                    break;
+
+                case IT_JUMP_TO_ORDER:
+                case IT_VOLUME_SLIDE:
+                case IT_PORTAMENTO_DOWN:
+                case IT_PORTAMENTO_UP:
+                case IT_TONE_PORTAMENTO:
+                case IT_VIBRATO:
+                case IT_TREMOR:
+                case IT_ARPEGGIO:
+                case IT_VOLSLIDE_VIBRATO:
+                case IT_VOLSLIDE_TONEPORTA:
+                    break;
+
+                default:
+                    entry->mask &= ~IT_ENTRY_EFFECT;
+                    break;
+                }
+                if (entry->mask)
+                    ++entry;
+            }
+            pos += 4;
+        }
+        IT_SET_END_ROW(entry);
+        ++entry;
+    }
+
+    pattern->n_entries = (int)(entry - pattern->entry);
+
+    return 0;
+}
+
+static DUMB_IT_SIGDATA *it_stm_load_sigdata(DUMBFILE *f, int *version) {
+    DUMB_IT_SIGDATA *sigdata;
+
+    char tracker_name[8];
+
+    unsigned short sample_offset[31];
+
+    int n;
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        return NULL;
+
+    /* Skip song name. */
+    dumbfile_getnc((char *)sigdata->name, 20, f);
+    sigdata->name[20] = 0;
+
+    dumbfile_getnc(tracker_name, 8, f);
+    n = dumbfile_getc(f);
+    if (n != 0x02 && n != 0x1A && n != 0x1B) {
+        free(sigdata);
+        return NULL;
+    }
+    if (dumbfile_getc(f) != 2) /* only support modules */
+    {
+        free(sigdata);
+        return NULL;
+    }
+    if (strnicmp(tracker_name, "!Scream!", 8) &&
+        strnicmp(tracker_name, "BMOD2STM", 8) &&
+        strnicmp(tracker_name, "WUZAMOD!", 8)) {
+        free(sigdata);
+        return NULL;
+    }
+
+    *version = dumbfile_mgetw(f);
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_instruments = 0;
+    sigdata->n_samples = 31;
+    sigdata->n_pchannels = 4;
+
+    sigdata->tempo = 125;
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    /** WARNING: which ones? */
+    sigdata->flags = IT_OLD_EFFECTS | IT_COMPATIBLE_GXX | IT_WAS_AN_S3M |
+                     IT_WAS_AN_STM | IT_STEREO;
+
+    n = dumbfile_getc(f);
+    if (n < 32)
+        n = 32;
+    sigdata->speed = n;
+    sigdata->n_patterns = dumbfile_getc(f);
+    sigdata->global_volume = dumbfile_getc(f) << 1;
+    if (sigdata->global_volume > 128)
+        sigdata->global_volume = 128;
+
+    dumbfile_skip(f, 13);
+
+    if (dumbfile_error(f) || sigdata->n_patterns < 1 ||
+        sigdata->n_patterns > 99) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    sigdata->sample = malloc(sigdata->n_samples * sizeof(*sigdata->sample));
+    if (!sigdata->sample) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    for (n = 0; n < sigdata->n_samples; n++)
+        sigdata->sample[n].data = NULL;
+
+    if (sigdata->n_patterns) {
+        sigdata->pattern =
+            malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+        if (!sigdata->pattern) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_patterns; n++)
+            sigdata->pattern[n].entry = NULL;
+    }
+
+    memset(sigdata->channel_volume, 64, 4);
+    n = 32 * dumb_it_default_panning_separation / 100;
+    sigdata->channel_pan[0] = 32 + n;
+    sigdata->channel_pan[1] = 32 - n;
+    sigdata->channel_pan[2] = 32 + n;
+    sigdata->channel_pan[3] = 32 - n;
+
+    for (n = 0; n < sigdata->n_samples; ++n) {
+        if (it_stm_read_sample_header(&sigdata->sample[n], f,
+                                      &sample_offset[n])) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+    }
+
+    sigdata->order = malloc(128);
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    /* Orders, byte each, length = sigdata->n_orders (should be even) */
+    dumbfile_getnc((char *)sigdata->order, *version >= 0x200 ? 128 : 64, f);
+    if (*version < 0x200)
+        memset(sigdata->order + 64, 0xFF, 64);
+    sigdata->restart_position = 0;
+
+    for (n = 127; n >= 0; --n) {
+        if (sigdata->order[n] < sigdata->n_patterns)
+            break;
+    }
+    if (n < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    sigdata->n_orders = n + 1;
+
+    for (n = 0; n < 128; ++n) {
+        if (sigdata->order[n] >= 99)
+            sigdata->order[n] = 0xFF;
+    }
+
+    if (sigdata->n_patterns) {
+        unsigned char *buffer = malloc(64 * 4 * 4);
+        if (!buffer) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (n = 0; n < sigdata->n_patterns; ++n) {
+            if (it_stm_read_pattern(&sigdata->pattern[n], f, buffer)) {
+                free(buffer);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+        }
+        free(buffer);
+    }
+
+    for (n = 0; n < sigdata->n_samples; ++n) {
+        if (sample_offset[n]) {
+            if (dumbfile_seek(f, sample_offset[n] * 16, DFS_SEEK_SET) ||
+                it_stm_read_sample_data(&sigdata->sample[n], f)) {
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+        } else {
+            sigdata->sample[n].flags = 0;
+            sigdata->sample[n].length = 0;
+        }
+    }
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+DUH *dumb_read_stm_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+    int ver;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_stm_load_sigdata(f, &ver);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        char version[16];
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        version[0] = 'S';
+        version[1] = 'T';
+        version[2] = 'M';
+        version[3] = ' ';
+        version[4] = 'v';
+        version[5] = '0' + ((ver >> 8) & 15);
+        version[6] = '.';
+        if ((ver & 255) > 99) {
+            version[7] = '0' + ((ver & 255) / 100);
+            version[8] = '0' + (((ver & 255) / 10) % 10);
+            version[9] = '0' + ((ver & 255) % 10);
+            version[10] = 0;
+        } else {
+            version[7] = '0' + ((ver & 255) / 10);
+            version[8] = '0' + ((ver & 255) % 10);
+            version[9] = 0;
+        }
+        tag[1][1] = (const char *)&version;
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readstm2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readstm2.c - Function to read a ScreamTracker 2    / / \  \
+ *              module from an open file and do an   | <  /   \_
+ *              initial run-through.                 |  \/ /\   /
+ *                                                    \_  /  > /
+ * By Christopher Snowhill.                             | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_stm(DUMBFILE *f) {
+    DUH *duh = dumb_read_stm_quick(f);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/readxm.c
@@ -1,0 +1,1431 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readxm.c - Code to read a Fast Tracker II          / / \  \
+ *            module from an open file.              | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Julien Cugniere. Some bits of code taken        \_  /  > /
+ * from reads3m.c.                                      | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+#include "internal/dumbfile.h"
+
+/** TODO:
+
+ * XM_TREMOLO                        doesn't sound quite right...
+ * XM_SET_ENVELOPE_POSITION          todo.
+
+ * VIBRATO conversion needs to be checked (sample/effect/volume). Plus check
+   that effect memory is correct when using XM_VOLSLIDE_VIBRATO.
+   - sample vibrato (instrument vibrato) is now handled correctly. - entheh
+
+ * XM_E_SET_VIBRATO/TREMOLO_CONTROL: effectvalue&4 -> don't retrig wave when
+   a new instrument is played. In retrigger_note()?. Is it worth implementing?
+
+ * Lossy fadeout approximation. 0..31 converted to 0 --> won't fade at all.
+
+ * Replace DUMB's sawtooth by ramp_down/ramp_up. Update XM loader.
+
+ * A lot of things need to be reset when the end of the song is reached.
+
+ * It seems that IT and XM don't behave the same way when dealing with
+   mixed loops. When IT encounters multiple SBx (x>0) commands on the same
+   row, it decrements the loop count for all, but only execute the loop of
+   the last one (highest channel). FT2 only decrements the loop count of the
+   last one. Not that I know of any modules using so convoluted combinations!
+
+ * Maybe we could remove patterns that don't appear in the order table ? Or
+   provide a function to "optimize" a DUMB_IT_SIGDATA ?
+
+*/
+
+#define XM_LINEAR_FREQUENCY 1 /* otherwise, use amiga slides */
+
+#define XM_ENTRY_PACKED 128
+#define XM_ENTRY_NOTE 1
+#define XM_ENTRY_INSTRUMENT 2
+#define XM_ENTRY_VOLUME 4
+#define XM_ENTRY_EFFECT 8
+#define XM_ENTRY_EFFECTVALUE 16
+
+#define XM_NOTE_OFF 97
+
+#define XM_ENVELOPE_ON 1
+#define XM_ENVELOPE_SUSTAIN 2
+#define XM_ENVELOPE_LOOP 4
+
+#define XM_SAMPLE_NO_LOOP 0
+#define XM_SAMPLE_FORWARD_LOOP 1
+#define XM_SAMPLE_PINGPONG_LOOP 2
+#define XM_SAMPLE_16BIT 16
+#define XM_SAMPLE_STEREO 32
+
+#define XM_VIBRATO_SINE 0
+#define XM_VIBRATO_SQUARE 1
+#define XM_VIBRATO_RAMP_DOWN 2
+#define XM_VIBRATO_RAMP_UP 3
+
+/* Probably useless :) */
+const char xm_convert_vibrato[] = {IT_VIBRATO_SINE, IT_VIBRATO_XM_SQUARE,
+                                   IT_VIBRATO_RAMP_DOWN, IT_VIBRATO_RAMP_UP,
+                                   IT_VIBRATO_RANDOM};
+
+#define XM_MAX_SAMPLES_PER_INSTRUMENT 16
+
+/* Extra data that doesn't fit inside IT_INSTRUMENT */
+typedef struct XM_INSTRUMENT_EXTRA {
+    int n_samples;
+    int vibrato_type;
+    int vibrato_sweep; /* 0-0xFF */
+    int vibrato_depth; /* 0-0x0F */
+    int vibrato_speed; /* 0-0x3F */
+    int sample_header_size;
+} XM_INSTRUMENT_EXTRA;
+
+/* Trims off trailing white space, usually added by the tracker on file creation
+ */
+static void trim_whitespace(char *ptr, size_t size) {
+    char *p = ptr + size - 1;
+    while (p >= ptr && *p <= 0x20)
+        *p-- = '\0';
+}
+
+/* Frees the original block if it can't resize it or if size is 0, and acts
+ * as malloc if ptr is NULL.
+ */
+static void *safe_realloc(void *ptr, size_t size) {
+    if (ptr == NULL)
+        return malloc(size);
+
+    if (size == 0) {
+        free(ptr);
+        return NULL;
+    } else {
+        void *new_block = realloc(ptr, size);
+        if (!new_block)
+            free(ptr);
+        return new_block;
+    }
+}
+
+/* The interpretation of the XM volume column is left to the player. Here, we
+ * just filter bad values.
+ */
+// This function is so tiny now, should we inline it?
+static void it_xm_convert_volume(int volume, IT_ENTRY *entry) {
+    entry->mask |= IT_ENTRY_VOLPAN;
+    entry->volpan = volume;
+
+    switch (volume >> 4) {
+    case 0xA: /* set vibrato speed */
+    case 0xB: /* vibrato */
+    case 0xF: /* tone porta */
+    case 0x6: /* vol slide up */
+    case 0x7: /* vol slide down */
+    case 0x8: /* fine vol slide up */
+    case 0x9: /* fine vol slide down */
+    case 0xC: /* set panning */
+    case 0xD: /* pan slide left */
+    case 0xE: /* pan slide right */
+    case 0x1: /* set volume */
+    case 0x2: /* set volume */
+    case 0x3: /* set volume */
+    case 0x4: /* set volume */
+        break;
+
+    case 0x5:
+        if (volume == 0x50)
+            break; /* set volume */
+                   /* else fall through */
+
+    default:
+        entry->mask &= ~IT_ENTRY_VOLPAN;
+        break;
+    }
+}
+
+static int it_xm_read_pattern(IT_PATTERN *pattern, DUMBFILE *f, int n_channels,
+                              unsigned char *buffer, int version) {
+    int size;
+    int pos;
+    int channel;
+    int row;
+    int effect, effectvalue;
+    IT_ENTRY *entry;
+
+    /* pattern header size */
+    if (dumbfile_igetl(f) != (version == 0x0102 ? 0x08 : 0x09)) {
+        TRACE("XM error: unexpected pattern header size\n");
+        return -1;
+    }
+
+    /* pattern data packing type */
+    if (dumbfile_getc(f) != 0) {
+        TRACE("XM error: unexpected pattern packing type\n");
+        return -1;
+    }
+
+    if (version == 0x0102)
+        pattern->n_rows = dumbfile_getc(f) + 1;
+    else
+        pattern->n_rows = dumbfile_igetw(f); /* 1..256 */
+    size = dumbfile_igetw(f);
+    pattern->n_entries = 0;
+
+    if (dumbfile_error(f))
+        return -1;
+
+    if (size == 0)
+        return 0;
+
+    if (size > 1280 * n_channels) {
+        TRACE("XM error: pattern data size > %d bytes\n", 1280 * n_channels);
+        return -1;
+    }
+
+    if (dumbfile_getnc((char *)buffer, size, f) < size)
+        return -1;
+
+    /* compute number of entries */
+    pattern->n_entries = 0;
+    pos = channel = row = 0;
+    while (pos < size) {
+        if (!(buffer[pos] & XM_ENTRY_PACKED) || (buffer[pos] & 31))
+            pattern->n_entries++;
+
+        channel++;
+        if (channel >= n_channels) {
+            channel = 0;
+            row++;
+            pattern->n_entries++;
+        }
+
+        if (buffer[pos] & XM_ENTRY_PACKED) {
+            static const char offset[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2,
+                                          3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3,
+                                          3, 4, 2, 3, 3, 4, 3, 4, 4, 5};
+            pos += 1 + offset[buffer[pos] & 31];
+        } else {
+            pos += 5;
+        }
+    }
+
+    if (row > pattern->n_rows) {
+        TRACE("XM error: wrong number of rows in pattern data\n");
+        return -1;
+    }
+
+    /* Whoops, looks like some modules may be short, a few channels, maybe even
+     * rows... */
+
+    while (row < pattern->n_rows) {
+        pattern->n_entries++;
+        row++;
+    }
+
+    pattern->entry = malloc(pattern->n_entries * sizeof(*pattern->entry));
+    if (!pattern->entry)
+        return -1;
+
+    /* read the entries */
+    entry = pattern->entry;
+    pos = channel = row = 0;
+    while (pos < size) {
+        unsigned char mask;
+
+        if (buffer[pos] & XM_ENTRY_PACKED)
+            mask = buffer[pos++] & 31;
+        else
+            mask = 31;
+
+        if (mask) {
+            ASSERT(entry < pattern->entry + pattern->n_entries);
+
+            entry->channel = channel;
+            entry->mask = 0;
+
+            if (mask & XM_ENTRY_NOTE) {
+                int note = buffer[pos++]; /* 1-96 <=> C0-B7 */
+                entry->note =
+                    (note == XM_NOTE_OFF) ? (IT_NOTE_OFF) : (note - 1);
+                entry->mask |= IT_ENTRY_NOTE;
+            }
+
+            if (mask & XM_ENTRY_INSTRUMENT) {
+                entry->instrument = buffer[pos++]; /* 1-128 */
+                entry->mask |= IT_ENTRY_INSTRUMENT;
+            }
+
+            if (mask & XM_ENTRY_VOLUME)
+                it_xm_convert_volume(buffer[pos++], entry);
+
+            effect = effectvalue = 0;
+            if (mask & XM_ENTRY_EFFECT)
+                effect = buffer[pos++];
+            if (mask & XM_ENTRY_EFFECTVALUE)
+                effectvalue = buffer[pos++];
+            _dumb_it_xm_convert_effect(effect, effectvalue, entry, 0);
+
+            entry++;
+        }
+
+        channel++;
+        if (channel >= n_channels) {
+            channel = 0;
+            row++;
+            IT_SET_END_ROW(entry);
+            entry++;
+        }
+    }
+
+    while (row < pattern->n_rows) {
+        row++;
+        IT_SET_END_ROW(entry);
+        entry++;
+    }
+
+    return 0;
+}
+
+static int it_xm_make_envelope(IT_ENVELOPE *envelope,
+                               const unsigned short *data, int y_offset) {
+    int i, pos, val;
+
+    if (envelope->n_nodes > 12) {
+        /* XXX
+        TRACE("XM error: wrong number of envelope nodes (%d)\n",
+        envelope->n_nodes); envelope->n_nodes = 0; return -1; */
+        envelope->n_nodes = 12;
+    }
+
+    if (envelope->sus_loop_start >= 12)
+        envelope->flags &= ~IT_ENVELOPE_SUSTAIN_LOOP;
+    if (envelope->loop_end >= 12)
+        envelope->loop_end = 0;
+    if (envelope->loop_start >= envelope->loop_end)
+        envelope->flags &= ~IT_ENVELOPE_LOOP_ON;
+
+    pos = 0;
+    for (i = 0; i < envelope->n_nodes; i++) {
+        envelope->node_t[i] = data[pos++];
+        val = data[pos++];
+        if (val > 64) {
+            TRACE("XM error: out-of-range envelope node (node_y[%d]=%d)\n", i,
+                  val);
+            /* FT2 seems to simply clip the value */
+            val = 64;
+        }
+        envelope->node_y[i] = (signed char)(val + y_offset);
+    }
+
+    return 0;
+}
+
+typedef struct LIMITED_XM LIMITED_XM;
+
+struct LIMITED_XM {
+    unsigned char *buffered;
+    long ptr, limit, allocated;
+    DUMBFILE *remaining;
+};
+
+static int limit_xm_resize(void *f, long n) {
+    DUMBFILE *df = f;
+    LIMITED_XM *lx = df->file;
+    if (n < 0)
+        return -1;
+    if (lx->buffered || n) {
+        if (n > lx->allocated) {
+            unsigned char *buffered = realloc(lx->buffered, n);
+            if (!buffered)
+                return -1;
+            lx->buffered = buffered;
+            memset(buffered + lx->allocated, 0, n - lx->allocated);
+            lx->allocated = n;
+        }
+        if (dumbfile_getnc((char *)lx->buffered, n, lx->remaining) < n)
+            return -1;
+    } else if (!n) {
+        if (lx->buffered)
+            free(lx->buffered);
+        lx->buffered = NULL;
+        lx->allocated = 0;
+    }
+    lx->limit = n;
+    lx->ptr = 0;
+    return 0;
+}
+
+static int limit_xm_skip_end(void *f, long n) {
+    DUMBFILE *df = f;
+    LIMITED_XM *lx = df->file;
+    return dumbfile_skip(lx->remaining, n);
+}
+
+static int limit_xm_skip(void *f, dumb_off_t n) {
+    LIMITED_XM *lx = f;
+    lx->ptr += n;
+    return 0;
+}
+
+static int limit_xm_getc(void *f) {
+    LIMITED_XM *lx = f;
+    if (lx->ptr >= lx->allocated) {
+        return 0;
+    }
+    return lx->buffered[lx->ptr++];
+}
+
+static dumb_ssize_t limit_xm_getnc(char *ptr, size_t n, void *f) {
+    LIMITED_XM *lx = f;
+    dumb_ssize_t left;
+    left = lx->allocated - lx->ptr;
+    if ((dumb_ssize_t)n > left) {
+        if (left > 0) {
+            memcpy(ptr, lx->buffered + lx->ptr, left);
+            memset(ptr + left, 0, n - left);
+        } else {
+            memset(ptr, 0, n);
+        }
+    } else {
+        memcpy(ptr, lx->buffered + lx->ptr, n);
+    }
+    lx->ptr += n;
+    return n;
+}
+
+static void limit_xm_close(void *f) {
+    LIMITED_XM *lx = f;
+    if (lx->buffered)
+        free(lx->buffered);
+    /* Do NOT close lx->remaining */
+    free(f);
+}
+
+/* These two can be stubs since this implementation doesn't use seeking */
+static int limit_xm_seek(void *f, dumb_off_t n) {
+    (void)f;
+    (void)n;
+    return 1;
+}
+
+static dumb_off_t limit_xm_get_size(void *f) {
+    (void)f;
+    return 0;
+}
+
+DUMBFILE_SYSTEM limit_xm_dfs = {NULL,
+                                &limit_xm_skip,
+                                &limit_xm_getc,
+                                &limit_xm_getnc,
+                                &limit_xm_close,
+                                &limit_xm_seek,
+                                &limit_xm_get_size};
+
+static DUMBFILE *dumbfile_limit_xm(DUMBFILE *f) {
+    LIMITED_XM *lx = malloc(sizeof(*lx));
+    lx->remaining = f;
+    lx->buffered = NULL;
+    lx->ptr = 0;
+    lx->limit = 0;
+    lx->allocated = 0;
+    return dumbfile_open_ex(lx, &limit_xm_dfs);
+}
+
+static int it_xm_read_instrument(IT_INSTRUMENT *instrument,
+                                 XM_INSTRUMENT_EXTRA *extra, DUMBFILE *f) {
+    unsigned long size, bytes_read;
+    unsigned short vol_points[24];
+    unsigned short pan_points[24];
+    int i, type;
+    const unsigned long max_size =
+        4 + 22 + 1 + 2 + 4 + 96 + 48 + 48 + 1 * 14 + 2 + 2;
+    unsigned long skip_end = 0;
+
+    /* Header size. Tends to be more than the actual size of the structure.
+     * So unread bytes must be skipped before reading the first sample
+     * header.
+     */
+
+    if (limit_xm_resize(f, 4) < 0)
+        return -1;
+
+    size = dumbfile_igetl(f);
+
+    if (size == 0)
+        size = max_size;
+    else if (size > max_size) {
+        skip_end = size - max_size;
+        size = max_size;
+    }
+
+    if (limit_xm_resize(f, size - 4) < 0)
+        return -1;
+
+    dumbfile_getnc((char *)instrument->name, 22, f);
+    instrument->name[22] = 0;
+    trim_whitespace((char *)instrument->name, 22);
+    instrument->filename[0] = 0;
+    dumbfile_skip(f, 1); /* Instrument type. Should be 0, but seems random. */
+    extra->n_samples = dumbfile_igetw(f);
+
+    if (dumbfile_error(f) ||
+        (unsigned int)extra->n_samples > XM_MAX_SAMPLES_PER_INSTRUMENT)
+        return -1;
+
+    bytes_read = 4 + 22 + 1 + 2;
+
+    if (extra->n_samples) {
+        /* sample header size */
+        /*i = dumbfile_igetl(f);
+        if (!i || i > 0x28) i = 0x28;*/
+        dumbfile_skip(f, 4);
+        i = 0x28;
+        extra->sample_header_size = i;
+
+        /* sample map */
+        for (i = 0; i < 96; i++) {
+            instrument->map_sample[i] = dumbfile_getc(f) + 1;
+            instrument->map_note[i] = i;
+        }
+
+        if (dumbfile_error(f))
+            return 1;
+
+        /* volume/panning envelopes */
+        for (i = 0; i < 24; i++)
+            vol_points[i] = dumbfile_igetw(f);
+        for (i = 0; i < 24; i++)
+            pan_points[i] = dumbfile_igetw(f);
+
+        instrument->volume_envelope.n_nodes = dumbfile_getc(f);
+        instrument->pan_envelope.n_nodes = dumbfile_getc(f);
+
+        if (dumbfile_error(f))
+            return -1;
+
+        instrument->volume_envelope.sus_loop_start = dumbfile_getc(f);
+        instrument->volume_envelope.loop_start = dumbfile_getc(f);
+        instrument->volume_envelope.loop_end = dumbfile_getc(f);
+
+        instrument->pan_envelope.sus_loop_start = dumbfile_getc(f);
+        instrument->pan_envelope.loop_start = dumbfile_getc(f);
+        instrument->pan_envelope.loop_end = dumbfile_getc(f);
+
+        /* The envelope handler for XM files won't use sus_loop_end. */
+
+        type = dumbfile_getc(f);
+        instrument->volume_envelope.flags = 0;
+        if ((type & XM_ENVELOPE_ON) && instrument->volume_envelope.n_nodes)
+            instrument->volume_envelope.flags |= IT_ENVELOPE_ON;
+        if (type & XM_ENVELOPE_LOOP)
+            instrument->volume_envelope.flags |= IT_ENVELOPE_LOOP_ON;
+#if 1
+        if (type & XM_ENVELOPE_SUSTAIN)
+            instrument->volume_envelope.flags |= IT_ENVELOPE_SUSTAIN_LOOP;
+#else // This is now handled in itrender.c
+        /* let's avoid fading out when reaching the last envelope node */
+        if (!(type & XM_ENVELOPE_LOOP)) {
+            instrument->volume_envelope.loop_start =
+                instrument->volume_envelope.n_nodes - 1;
+            instrument->volume_envelope.loop_end =
+                instrument->volume_envelope.n_nodes - 1;
+        }
+        instrument->volume_envelope.flags |= IT_ENVELOPE_LOOP_ON;
+#endif
+
+        type = dumbfile_getc(f);
+        instrument->pan_envelope.flags = 0;
+        if ((type & XM_ENVELOPE_ON) && instrument->pan_envelope.n_nodes)
+            instrument->pan_envelope.flags |= IT_ENVELOPE_ON;
+        if (type & XM_ENVELOPE_LOOP)
+            instrument->pan_envelope.flags |=
+                IT_ENVELOPE_LOOP_ON; // should this be here?
+        if (type & XM_ENVELOPE_SUSTAIN)
+            instrument->pan_envelope.flags |= IT_ENVELOPE_SUSTAIN_LOOP;
+
+        if (it_xm_make_envelope(&instrument->volume_envelope, vol_points, 0) !=
+            0) {
+            TRACE("XM error: volume envelope\n");
+            if (instrument->volume_envelope.flags & IT_ENVELOPE_ON)
+                return -1;
+        }
+
+        if (it_xm_make_envelope(&instrument->pan_envelope, pan_points, -32) !=
+            0) {
+            TRACE("XM error: pan envelope\n");
+            if (instrument->pan_envelope.flags & IT_ENVELOPE_ON)
+                return -1;
+        }
+
+        instrument->pitch_envelope.flags = 0;
+
+        extra->vibrato_type = dumbfile_getc(f);
+        extra->vibrato_sweep = dumbfile_getc(f);
+        extra->vibrato_depth = dumbfile_getc(f);
+        extra->vibrato_speed = dumbfile_getc(f);
+
+        if (dumbfile_error(f) || extra->vibrato_type > 4) // XXX
+            return -1;
+
+        /** WARNING: lossy approximation */
+        instrument->fadeout = (dumbfile_igetw(f) * 128 + 64) / 0xFFF;
+
+        dumbfile_skip(f, 2); /* reserved */
+
+        bytes_read += 4 + 96 + 48 + 48 + 14 * 1 + 2 + 2;
+    } else
+        for (i = 0; i < 96; i++)
+            instrument->map_sample[i] = 0;
+
+    if (size > bytes_read && dumbfile_skip(f, size - bytes_read))
+        return -1;
+
+    if (skip_end && limit_xm_skip_end(f, skip_end))
+        return -1;
+
+    instrument->new_note_action = NNA_NOTE_CUT;
+    instrument->dup_check_type = DCT_OFF;
+    instrument->dup_check_action = DCA_NOTE_CUT;
+    instrument->pp_separation = 0;
+    instrument->pp_centre = 60; /* C-5 */
+    instrument->global_volume = 128;
+    instrument->default_pan = 32;
+    instrument->random_volume = 0;
+    instrument->random_pan = 0;
+    instrument->filter_cutoff = 0;
+    instrument->filter_resonance = 0;
+
+    return 0;
+}
+
+/* I (entheh) have two XM files saved by a very naughty program. After a
+ * 16-bit sample, it saved a rogue byte. The length of the sample was indeed
+ * an odd number, incremented to include the rogue byte.
+ *
+ * In this function we are converting sample lengths and loop points so they
+ * are measured in samples. This means we forget about the extra bytes, and
+ * they don't get skipped. So we fail trying to read the next instrument.
+ *
+ * To get around this, this function returns the number of rogue bytes that
+ * won't be accounted for by reading sample->length samples. It returns a
+ * negative number on failure.
+ */
+static int it_xm_read_sample_header(IT_SAMPLE *sample, DUMBFILE *f) {
+    int type;
+    int relative_note_number; /* relative to C4 */
+    int finetune;
+    int roguebytes;
+    int roguebytesmask;
+    int reserved;
+
+    sample->length = dumbfile_igetl(f);
+    sample->loop_start = dumbfile_igetl(f);
+    sample->loop_end = sample->loop_start + dumbfile_igetl(f);
+    sample->global_volume = 64;
+    sample->default_volume = dumbfile_getc(f);
+    finetune = (signed char)dumbfile_getc(
+        f); /* -128..127 <=> -1 semitone .. +127/128 of a semitone */
+    type = dumbfile_getc(f);
+    sample->default_pan = dumbfile_getc(f); /* 0-255 */
+    relative_note_number = (signed char)dumbfile_getc(f);
+
+    reserved = dumbfile_getc(f);
+
+    dumbfile_getnc((char *)sample->name, 22, f);
+    sample->name[22] = 0;
+    trim_whitespace((char *)sample->name, 22);
+
+    sample->filename[0] = 0;
+
+    if (dumbfile_error(f))
+        return -1;
+
+    sample->C5_speed =
+        (long)(16726.0 * pow(DUMB_SEMITONE_BASE,
+                             relative_note_number) /**pow(DUMB_PITCH_BASE, )*/);
+    sample->finetune = finetune * 2;
+
+    sample->flags = IT_SAMPLE_EXISTS;
+
+    if (reserved == 0xAD && (!(type & (XM_SAMPLE_16BIT | XM_SAMPLE_STEREO)))) {
+        /* F U Olivier Lapicque */
+        roguebytes = 4;
+        roguebytesmask = 4 << 2;
+    } else {
+        roguebytes = (int)sample->length;
+        roguebytesmask = 3;
+    }
+
+    if (type & XM_SAMPLE_16BIT) {
+        sample->flags |= IT_SAMPLE_16BIT;
+        sample->length >>= 1;
+        sample->loop_start >>= 1;
+        sample->loop_end >>= 1;
+    } else
+        roguebytesmask >>= 1;
+
+    if (type & XM_SAMPLE_STEREO) {
+        sample->flags |= IT_SAMPLE_STEREO;
+        sample->length >>= 1;
+        sample->loop_start >>= 1;
+        sample->loop_end >>= 1;
+    } else
+        roguebytesmask >>= 1;
+
+    roguebytes &= roguebytesmask;
+
+    if ((unsigned int)sample->loop_start < (unsigned int)sample->loop_end) {
+        if (type & XM_SAMPLE_FORWARD_LOOP)
+            sample->flags |= IT_SAMPLE_LOOP;
+        if (type & XM_SAMPLE_PINGPONG_LOOP)
+            sample->flags |= IT_SAMPLE_LOOP | IT_SAMPLE_PINGPONG_LOOP;
+    }
+
+    if (sample->length <= 0)
+        sample->flags &= ~IT_SAMPLE_EXISTS;
+    else if ((unsigned int)sample->loop_end > (unsigned int)sample->length)
+        sample->flags &= ~IT_SAMPLE_LOOP;
+    else if ((unsigned int)sample->loop_start >= (unsigned int)sample->loop_end)
+        sample->flags &= ~IT_SAMPLE_LOOP;
+
+    return roguebytes;
+}
+
+static int it_xm_read_sample_data(IT_SAMPLE *sample, unsigned char roguebytes,
+                                  DUMBFILE *f) {
+    int old;
+    long i;
+    long truncated_size;
+    int n_channels;
+    long datasize;
+
+    if (!(sample->flags & IT_SAMPLE_EXISTS))
+        return dumbfile_skip(f, roguebytes);
+
+    /* let's get rid of the sample data coming after the end of the loop */
+    if ((sample->flags & IT_SAMPLE_LOOP) && sample->loop_end < sample->length &&
+        roguebytes != 4) {
+        truncated_size = sample->length - sample->loop_end;
+        sample->length = sample->loop_end;
+    } else {
+        truncated_size = 0;
+    }
+
+    n_channels = sample->flags & IT_SAMPLE_STEREO ? 2 : 1;
+    datasize = sample->length * n_channels;
+
+    sample->data = malloc(datasize * (sample->flags & IT_SAMPLE_16BIT ? 2 : 1));
+    if (!sample->data)
+        return -1;
+
+    if (roguebytes == 4) {
+        if (_dumb_it_read_sample_data_adpcm4(sample, f) < 0)
+            return -1;
+        roguebytes = 0;
+    } else {
+        /* sample data is stored as signed delta values */
+        old = 0;
+        if (sample->flags & IT_SAMPLE_16BIT)
+            for (i = 0; i < sample->length; i++)
+                ((short *)sample->data)[i * n_channels] = old +=
+                    dumbfile_igetw(f);
+        else
+            for (i = 0; i < sample->length; i++)
+                ((signed char *)sample->data)[i * n_channels] = old +=
+                    dumbfile_getc(f);
+    }
+
+    /* skip truncated data */
+    dumbfile_skip(f, (sample->flags & IT_SAMPLE_16BIT) ? (2 * truncated_size)
+                                                       : (truncated_size));
+
+    if (sample->flags & IT_SAMPLE_STEREO) {
+        old = 0;
+        if (sample->flags & IT_SAMPLE_16BIT)
+            for (i = 1; i < datasize; i += 2)
+                ((short *)sample->data)[i] = old += dumbfile_igetw(f);
+        else
+            for (i = 1; i < datasize; i += 2)
+                ((signed char *)sample->data)[i] = old += dumbfile_getc(f);
+
+        /* skip truncated data */
+        dumbfile_skip(f, (sample->flags & IT_SAMPLE_16BIT)
+                             ? (2 * truncated_size)
+                             : (truncated_size));
+    }
+
+    dumbfile_skip(f, roguebytes);
+
+    if (dumbfile_error(f))
+        return -1;
+
+    return 0;
+}
+
+/* "Real programmers don't document. If it was hard to write,
+ *  it should be hard to understand."
+ *
+ * (Never trust the documentation provided with a tracker.
+ *  Real files are the only truth...)
+ */
+static DUMB_IT_SIGDATA *it_xm_load_sigdata(DUMBFILE *f, int *version) {
+    DUMB_IT_SIGDATA *sigdata;
+    char id_text[18];
+
+    size_t header_size;
+    int flags;
+    int n_channels;
+    int total_samples;
+    int i, j;
+
+    /* check ID text */
+    if (dumbfile_getnc(id_text, 17, f) < 17)
+        return NULL;
+    id_text[17] = 0;
+    if (strcmp(id_text, "Extended Module: ") != 0) {
+        TRACE("XM error: Not an Extended Module\n");
+        return NULL;
+    }
+
+    sigdata = malloc(sizeof(*sigdata));
+    if (!sigdata)
+        return NULL;
+
+    /* song name */
+    if (dumbfile_getnc((char *)sigdata->name, 20, f) < 20) {
+        free(sigdata);
+        return NULL;
+    }
+    sigdata->name[20] = 0;
+    trim_whitespace((char *)sigdata->name, 20);
+
+    if (dumbfile_getc(f) != 0x1A) {
+        TRACE("XM error: 0x1A not found\n");
+        free(sigdata);
+        return NULL;
+    }
+
+    /* tracker name */
+    if (dumbfile_skip(f, 20)) {
+        free(sigdata);
+        return NULL;
+    }
+
+    /* version number */
+    *version = dumbfile_igetw(f);
+    if (*version > 0x0104 || *version < 0x0102) {
+        TRACE("XM error: wrong format version\n");
+        free(sigdata);
+        return NULL;
+    }
+
+    /*
+            ------------------
+            ---   Header   ---
+            ------------------
+    */
+
+    /* header size */
+    header_size = dumbfile_igetl(f);
+    if (header_size < (4 + 2 * 8 + 1) || header_size > 0x114) {
+        TRACE("XM error: unexpected header size\n");
+        free(sigdata);
+        return NULL;
+    }
+
+    sigdata->song_message = NULL;
+    sigdata->order = NULL;
+    sigdata->instrument = NULL;
+    sigdata->sample = NULL;
+    sigdata->pattern = NULL;
+    sigdata->midi = NULL;
+    sigdata->checkpoint = NULL;
+
+    sigdata->n_samples = 0;
+    sigdata->n_orders = dumbfile_igetw(f);
+    sigdata->restart_position = dumbfile_igetw(f);
+    n_channels = dumbfile_igetw(f); /* max 32 but we'll be lenient */
+    sigdata->n_pchannels = n_channels;
+    sigdata->n_patterns = dumbfile_igetw(f);
+    sigdata->n_instruments = dumbfile_igetw(f);
+    /* max 128 */ /* XXX upped to 256 */
+    flags = dumbfile_igetw(f);
+    sigdata->speed = dumbfile_igetw(f);
+    if (sigdata->speed == 0)
+        sigdata->speed = 6; // Should we? What about tempo?
+    sigdata->tempo = dumbfile_igetw(f);
+
+    // FT2 always clips restart position against the song length
+    if (sigdata->restart_position > sigdata->n_orders)
+        sigdata->restart_position = sigdata->n_orders;
+    // And FT2 starts playback on order 0, regardless of length,
+    // and only checks if the next order is greater than or equal
+    // to this, not the current pattern. Work around this with
+    // DUMB's playback core by overriding a zero length with one.
+    if (sigdata->n_orders == 0)
+        sigdata->n_orders = 1;
+
+    /* sanity checks */
+    // XXX
+    i = (int)(header_size - 4 - 2 * 8); /* Maximum number of orders expected */
+    if (dumbfile_error(f) || sigdata->n_orders <= 0 || sigdata->n_orders > i ||
+        !sigdata->n_patterns || sigdata->n_patterns > 256 ||
+        !sigdata->n_instruments || sigdata->n_instruments > 256 ||
+        n_channels > DUMB_IT_N_CHANNELS) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    // if (sigdata->restart_position >= sigdata->n_orders)
+    // sigdata->restart_position = 0;
+
+    /* order table */
+    sigdata->order = malloc(sigdata->n_orders * sizeof(*sigdata->order));
+    if (!sigdata->order) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+    dumbfile_getnc((char *)sigdata->order, sigdata->n_orders, f);
+    dumbfile_skip(f, i - sigdata->n_orders);
+
+    if (dumbfile_error(f)) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    if (*version > 0x103) {
+        /*
+                --------------------
+                ---   Patterns   ---
+                --------------------
+        */
+
+        sigdata->pattern =
+            malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+        if (!sigdata->pattern) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (i = 0; i < sigdata->n_patterns; i++)
+            sigdata->pattern[i].entry = NULL;
+
+        {
+            unsigned char *buffer =
+                malloc(1280 * n_channels); /* 256 rows * 5 bytes */
+            if (!buffer) {
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+            for (i = 0; i < sigdata->n_patterns; i++) {
+                if (it_xm_read_pattern(&sigdata->pattern[i], f, n_channels,
+                                       buffer, *version) != 0) {
+                    free(buffer);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+            }
+            free(buffer);
+        }
+
+        /*
+        -----------------------------------
+        ---   Instruments and Samples   ---
+        -----------------------------------
+        */
+
+        sigdata->instrument =
+            malloc(sigdata->n_instruments * sizeof(*sigdata->instrument));
+        if (!sigdata->instrument) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+
+        /* With XM, samples are not global, they're part of an instrument. In a
+         * file, each instrument is stored with its samples. Because of this, I
+         * don't know how to find how many samples are present in the file. Thus
+         * I have to do n_instruments reallocation on sigdata->sample.
+         * Looking at FT2, it doesn't seem possible to have more than 16 samples
+         * per instrument (even though n_samples is stored as 2 bytes). So maybe
+         * we could allocate a 128*16 array of samples, and shrink it back to
+         * the correct size when we know it? Alternatively, I could allocate
+         * samples by blocks of N (still O(n)), or double the number of
+         * allocated samples when I need more (O(log n)).
+         */
+        total_samples = 0;
+        sigdata->sample = NULL;
+
+        for (i = 0; i < sigdata->n_instruments; i++) {
+            XM_INSTRUMENT_EXTRA extra;
+
+            DUMBFILE *lf = dumbfile_limit_xm(f);
+            if (!lf) {
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            if (it_xm_read_instrument(&sigdata->instrument[i], &extra, lf) <
+                0) {
+                // XXX
+                if (!i) {
+                    TRACE("XM error: instrument %d\n", i + 1);
+                    dumbfile_close(lf);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                } else {
+                    dumbfile_close(lf);
+                    sigdata->n_instruments = i;
+                    break;
+                }
+            }
+
+            if (extra.n_samples) {
+                unsigned char roguebytes[XM_MAX_SAMPLES_PER_INSTRUMENT];
+
+                /* adjust instrument sample map (make indices absolute) */
+                for (j = 0; j < 96; j++)
+                    sigdata->instrument[i].map_sample[j] += total_samples;
+
+                sigdata->sample = safe_realloc(
+                    sigdata->sample, sizeof(*sigdata->sample) *
+                                         (total_samples + extra.n_samples));
+                if (!sigdata->sample) {
+                    dumbfile_close(lf);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+                for (j = total_samples; j < total_samples + extra.n_samples;
+                     j++)
+                    sigdata->sample[j].data = NULL;
+
+                if (limit_xm_resize(lf, 0) < 0) {
+                    dumbfile_close(lf);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+
+                /* read instrument's samples */
+                for (j = 0; j < extra.n_samples; j++) {
+                    IT_SAMPLE *sample = &sigdata->sample[total_samples + j];
+                    int b;
+                    if (limit_xm_resize(lf, extra.sample_header_size) < 0) {
+                        dumbfile_close(lf);
+                        _dumb_it_unload_sigdata(sigdata);
+                        return NULL;
+                    }
+                    b = it_xm_read_sample_header(sample, lf);
+                    if (b < 0) {
+                        dumbfile_close(lf);
+                        _dumb_it_unload_sigdata(sigdata);
+                        return NULL;
+                    }
+                    roguebytes[j] = b;
+                    // Any reason why these can't be set inside
+                    // it_xm_read_sample_header()?
+                    sample->vibrato_speed = extra.vibrato_speed;
+                    sample->vibrato_depth = extra.vibrato_depth;
+                    sample->vibrato_rate = extra.vibrato_sweep;
+                    /* Rate and sweep don't match, but the difference is
+                     * accounted for in itrender.c.
+                     */
+                    sample->vibrato_waveform =
+                        xm_convert_vibrato[extra.vibrato_type];
+                    sample->max_resampling_quality = -1;
+                }
+                for (j = 0; j < extra.n_samples; j++) {
+                    if (it_xm_read_sample_data(
+                            &sigdata->sample[total_samples + j], roguebytes[j],
+                            f) != 0) {
+                        dumbfile_close(lf);
+                        _dumb_it_unload_sigdata(sigdata);
+                        return NULL;
+                    }
+                }
+                total_samples += extra.n_samples;
+            }
+
+            dumbfile_close(lf);
+        }
+
+        sigdata->n_samples = total_samples;
+    } else {
+        // ahboy! old layout!
+        // first instruments and sample headers, then patterns, then sample
+        // data!
+
+        /*
+        -----------------------------------
+        ---   Instruments and Samples   ---
+        -----------------------------------
+        */
+
+        unsigned char *roguebytes =
+            malloc(sigdata->n_instruments * XM_MAX_SAMPLES_PER_INSTRUMENT);
+        if (!roguebytes) {
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+
+        sigdata->instrument =
+            malloc(sigdata->n_instruments * sizeof(*sigdata->instrument));
+        if (!sigdata->instrument) {
+            free(roguebytes);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+
+        total_samples = 0;
+        sigdata->sample = NULL;
+
+        for (i = 0; i < sigdata->n_instruments; i++) {
+            XM_INSTRUMENT_EXTRA extra;
+
+            DUMBFILE *lf = dumbfile_limit_xm(f);
+            if (!lf) {
+                free(roguebytes);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            if (it_xm_read_instrument(&sigdata->instrument[i], &extra, lf) <
+                0) {
+                TRACE("XM error: instrument %d\n", i + 1);
+                dumbfile_close(lf);
+                free(roguebytes);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+
+            if (extra.n_samples) {
+                /* adjust instrument sample map (make indices absolute) */
+                for (j = 0; j < 96; j++)
+                    sigdata->instrument[i].map_sample[j] += total_samples;
+
+                sigdata->sample = safe_realloc(
+                    sigdata->sample, sizeof(*sigdata->sample) *
+                                         (total_samples + extra.n_samples));
+                if (!sigdata->sample) {
+                    dumbfile_close(lf);
+                    free(roguebytes);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+                for (j = total_samples; j < total_samples + extra.n_samples;
+                     j++)
+                    sigdata->sample[j].data = NULL;
+
+                if (limit_xm_resize(lf, 0) < 0) {
+                    dumbfile_close(lf);
+                    free(roguebytes);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+
+                /* read instrument's samples */
+                for (j = 0; j < extra.n_samples; j++) {
+                    IT_SAMPLE *sample = &sigdata->sample[total_samples + j];
+                    int b;
+                    if (limit_xm_resize(lf, extra.sample_header_size) < 0) {
+                        dumbfile_close(lf);
+                        free(roguebytes);
+                        _dumb_it_unload_sigdata(sigdata);
+                        return NULL;
+                    }
+                    b = it_xm_read_sample_header(sample, lf);
+                    if (b < 0) {
+                        free(roguebytes);
+                        _dumb_it_unload_sigdata(sigdata);
+                        return NULL;
+                    }
+                    roguebytes[total_samples + j] = b;
+                    // Any reason why these can't be set inside
+                    // it_xm_read_sample_header()?
+                    sample->vibrato_speed = extra.vibrato_speed;
+                    sample->vibrato_depth = extra.vibrato_depth;
+                    sample->vibrato_rate = extra.vibrato_sweep;
+                    /* Rate and sweep don't match, but the difference is
+                     * accounted for in itrender.c.
+                     */
+                    sample->vibrato_waveform =
+                        xm_convert_vibrato[extra.vibrato_type];
+                    sample->max_resampling_quality = -1;
+                }
+                total_samples += extra.n_samples;
+            }
+
+            dumbfile_close(lf);
+        }
+
+        sigdata->n_samples = total_samples;
+
+        /*
+                --------------------
+                ---   Patterns   ---
+                --------------------
+        */
+
+        sigdata->pattern =
+            malloc(sigdata->n_patterns * sizeof(*sigdata->pattern));
+        if (!sigdata->pattern) {
+            free(roguebytes);
+            _dumb_it_unload_sigdata(sigdata);
+            return NULL;
+        }
+        for (i = 0; i < sigdata->n_patterns; i++)
+            sigdata->pattern[i].entry = NULL;
+
+        {
+            unsigned char *buffer =
+                malloc(1280 * n_channels); /* 256 rows * 5 bytes */
+            if (!buffer) {
+                free(roguebytes);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+            for (i = 0; i < sigdata->n_patterns; i++) {
+                if (it_xm_read_pattern(&sigdata->pattern[i], f, n_channels,
+                                       buffer, *version) != 0) {
+                    free(buffer);
+                    free(roguebytes);
+                    _dumb_it_unload_sigdata(sigdata);
+                    return NULL;
+                }
+            }
+            free(buffer);
+        }
+
+        // and now we load the sample data
+        for (j = 0; j < total_samples; j++) {
+            if (it_xm_read_sample_data(&sigdata->sample[j], roguebytes[j], f) !=
+                0) {
+                free(roguebytes);
+                _dumb_it_unload_sigdata(sigdata);
+                return NULL;
+            }
+        }
+
+        free(roguebytes);
+    }
+
+    sigdata->flags = IT_WAS_AN_XM | IT_OLD_EFFECTS | IT_COMPATIBLE_GXX |
+                     IT_STEREO | IT_USE_INSTRUMENTS;
+    // Are we OK with IT_COMPATIBLE_GXX off?
+    //
+    // When specifying note + instr + tone portamento, and an old note is still
+    // playing (even after note off):
+    // - If Compatible Gxx is on, the new note will be triggered only if the
+    // instrument _changes_.
+    // - If Compatible Gxx is off, the new note will always be triggered,
+    // provided the instrument is specified.
+    // - FT2 seems to do the latter (unconfirmed).
+
+    // Err, wait. XM playback has its own code. The change made to the IT
+    // playbackc code didn't affect XM playback. Forget this then. There's
+    // still a bug in XM playback though, and it'll need some investigation...
+    // tomorrow...
+
+    // UPDATE: IT_COMPATIBLE_GXX is required to be on, so that tone porta has
+    // separate memory from portamento.
+
+    if (flags & XM_LINEAR_FREQUENCY)
+        sigdata->flags |= IT_LINEAR_SLIDES;
+
+    sigdata->global_volume = 128;
+    sigdata->mixing_volume = 48;
+    sigdata->pan_separation = 128;
+
+    memset(sigdata->channel_volume, 64, DUMB_IT_N_CHANNELS);
+    memset(sigdata->channel_pan, 32, DUMB_IT_N_CHANNELS);
+
+    if (_dumb_it_fix_invalid_orders(sigdata) < 0) {
+        _dumb_it_unload_sigdata(sigdata);
+        return NULL;
+    }
+
+    return sigdata;
+}
+
+#if 0 // no fucking way, dude!
+
+/* The length returned is the time required to play from the beginning of the
+ * file to the last row of the last order (which is when the player will
+ * loop). Depending on the song, the sound might stop sooner.
+ * Due to fixed point roundoffs, I think this is only reliable to the second.
+ * Full precision could be achieved by using a double during the computation,
+ * or maybe a LONG_LONG.
+ */
+long it_compute_length(const DUMB_IT_SIGDATA *sigdata)
+{
+	IT_PATTERN *pattern;
+	int tempo, speed;
+	int loop_start[IT_N_CHANNELS];
+	char loop_count[IT_N_CHANNELS];
+	int order, entry;
+	int row_first_entry = 0;
+	int jump, jump_dest;
+	int delay, fine_delay;
+	int i;
+	long t;
+
+	if (!sigdata)
+		return 0;
+
+	tempo = sigdata->tempo;
+	speed = sigdata->speed;
+	order = entry = 0;
+	jump = jump_dest = 0;
+	t = 0;
+
+	/* for each PATTERN */
+	for (order = 0; order < sigdata->n_orders; order++) {
+
+		if (sigdata->order[order] == IT_ORDER_END) break;
+		if (sigdata->order[order] == IT_ORDER_SKIP) continue;
+
+		for (i = 0; i < IT_N_CHANNELS; i++)
+			loop_count[i] = -1;
+
+		pattern = &sigdata->pattern[ sigdata->order[order] ];
+		entry = 0;
+		if (jump == IT_BREAK_TO_ROW) {
+			int row = 0;
+			while (row < jump_dest)
+				if (pattern->entry[entry++].channel >= IT_N_CHANNELS)
+					row++;
+		}
+
+		/* for each ROW */
+		while (entry < pattern->n_entries) {
+			row_first_entry = entry;
+			delay = fine_delay = 0;
+			jump = 0;
+
+			/* for each note NOTE */
+			while (entry < pattern->n_entries && pattern->entry[entry].channel < IT_N_CHANNELS) {
+				int value   = pattern->entry[entry].effectvalue;
+				int channel = pattern->entry[entry].channel;
+
+				switch (pattern->entry[entry].effect) {
+
+					case IT_SET_SPEED: speed = value; break;
+
+					case IT_JUMP_TO_ORDER:
+						if (value <= order) /* infinite loop */
+							return 0;
+						jump = IT_JUMP_TO_ORDER;
+						jump_dest = value;
+						break;
+
+					case IT_BREAK_TO_ROW:
+						jump = IT_BREAK_TO_ROW;
+						jump_dest = value;
+						break;
+
+					case IT_S:
+						switch (HIGH(value)) {
+							case IT_S_PATTERN_DELAY:      delay      = LOW(value); break;
+							case IT_S_FINE_PATTERN_DELAY: fine_delay = LOW(value); break;
+							case IT_S_PATTERN_LOOP:
+								if (LOW(value) == 0) {
+									loop_start[channel] = row_first_entry;
+								} else {
+									if (loop_count[channel] == -1)
+										loop_count[channel] = LOW(value);
+
+									if (loop_count[channel]) {
+										jump = IT_S_PATTERN_LOOP;
+										jump_dest = loop_start[channel];
+									}
+									loop_count[channel]--;
+								}
+								break;
+						}
+						break;
+
+					case IT_SET_SONG_TEMPO:
+						switch (HIGH(value)) { /* slides happen every non-row frames */
+							case 0:  tempo = tempo - LOW(value)*(speed-1); break;
+							case 1:  tempo = tempo + LOW(value)*(speed-1); break;
+							default: tempo = value;
+						}
+						tempo = MID(32, tempo, 255);
+						break;
+				}
+
+				entry++;
+			}
+
+			/* end of ROW */
+			entry++;
+			t += TICK_TIME_DIVIDEND * (speed*(1+delay) + fine_delay) / tempo;
+
+			if (jump == IT_JUMP_TO_ORDER) {
+				order = jump_dest - 1;
+				break;
+			} else if (jump == IT_BREAK_TO_ROW)
+				break;
+			else if (jump == IT_S_PATTERN_LOOP)
+				entry = jump_dest - 1;
+		}
+
+		/* end of PATTERN */
+	}
+
+	return t;
+}
+
+#endif /* 0 */
+
+static char hexdigit(int in) {
+    if (in < 10)
+        return in + '0';
+    else
+        return in + 'A' - 10;
+}
+
+DUH *dumb_read_xm_quick(DUMBFILE *f) {
+    sigdata_t *sigdata;
+    int ver;
+
+    DUH_SIGTYPE_DESC *descptr = &_dumb_sigtype_it;
+
+    sigdata = it_xm_load_sigdata(f, &ver);
+
+    if (!sigdata)
+        return NULL;
+
+    {
+        char version[16];
+        const char *tag[2][2];
+        tag[0][0] = "TITLE";
+        tag[0][1] = (const char *)(((DUMB_IT_SIGDATA *)sigdata)->name);
+        tag[1][0] = "FORMAT";
+        version[0] = 'X';
+        version[1] = 'M';
+        version[2] = ' ';
+        version[3] = 'v';
+        version[4] = hexdigit((ver >> 8) & 15);
+        version[5] = '.';
+        version[6] = hexdigit((ver >> 4) & 15);
+        version[7] = hexdigit(ver & 15);
+        version[8] = 0;
+        tag[1][1] = (const char *)&version;
+        return make_duh(-1, 2, (const char *const(*)[2])tag, 1, &descptr,
+                        &sigdata);
+    }
+}
--- /dev/null
+++ b/src/it/readxm2.c
@@ -1,0 +1,26 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * readxm2.c - Function to read a Fast Tracker II     / / \  \
+ *             module from an open file and do an    | <  /   \_
+ *             initial run-through.                  |  \/ /\   /
+ *                                                    \_  /  > /
+ * Split off from readxm.c by entheh.                   | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include "dumb.h"
+
+DUH *dumb_read_xm(DUMBFILE *f) {
+    DUH *duh = dumb_read_xm_quick(f);
+    dumb_it_do_initial_runthrough(duh);
+    return duh;
+}
--- /dev/null
+++ b/src/it/xmeffect.c
@@ -1,0 +1,305 @@
+/*  _______         ____    __         ___    ___
+ * \    _  \       \    /  \  /       \   \  /   /       '   '  '
+ *  |  | \  \       |  |    ||         |   \/   |         .      .
+ *  |  |  |  |      |  |    ||         ||\  /|  |
+ *  |  |  |  |      |  |    ||         || \/ |  |         '  '  '
+ *  |  |  |  |      |  |    ||         ||    |  |         .      .
+ *  |  |_/  /        \  \__//          ||    |  |
+ * /_______/ynamic    \____/niversal  /__\  /____\usic   /|  .  . ibliotheque
+ *                                                      /  \
+ *                                                     / .  \
+ * xmeffect.c - Code for converting MOD/XM            / / \  \
+ *              effects to IT effects.               | <  /   \_
+ *                                                   |  \/ /\   /
+ * By Julien Cugniere. Ripped out of readxm.c         \_  /  > /
+ * by entheh.                                           | \ / /
+ *                                                      |  ' /
+ *                                                       \__/
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dumb.h"
+#include "internal/it.h"
+
+#if 0
+unsigned char **_dumb_malloc2(int w, int h)
+{
+	unsigned char **line =  malloc(h * sizeof(*line));
+	int i;
+	if (!line) return NULL;
+
+	line[0] = malloc(w * h * sizeof(*line[0]));
+	if (!line[0]) {
+		free(line);
+		return NULL;
+	}
+
+	for (i = 1; i < h; i++)
+		line[i] = line[i-1] + w;
+
+	memset(line[0], 0, w*h);
+
+	return line;
+}
+
+
+
+void _dumb_free2(unsigned char **line)
+{
+	if (line) {
+		if (line[0])
+			free(line[0]);
+		free(line);
+	}
+}
+
+
+
+/* Effects having a memory. 2 means that the two parts of the effectvalue
+ * should be handled separately.
+ */
+static const char xm_has_memory[] = {
+/*	0  1  2  3  4  5  6  7  8  9  A  B  C  D (E) F  G  H        K  L           P     R     T          (X) */
+	0, 1, 1, 1, 2, 1, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
+
+/*  E0 E1 E2 E3 E4 E5 E6 E7    E9 EA EB EC ED EE         X1 X2 */
+	0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,   0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+#endif
+
+/* Effects marked with 'special' are handled specifically in itrender.c */
+void _dumb_it_xm_convert_effect(int effect, int value, IT_ENTRY *entry,
+                                int mod) {
+    const int log = 0;
+
+    if ((!effect && !value) || (effect >= XM_N_EFFECTS))
+        return;
+
+    if (log)
+        printf("%c%02X", (effect < 10) ? ('0' + effect) : ('A' + effect - 10),
+               value);
+
+    /* Linearisation of the effect number... */
+    if (effect == XM_E) {
+        effect = EBASE + HIGH(value);
+        value = LOW(value);
+    } else if (effect == XM_X) {
+        effect = XBASE + HIGH(value);
+        value = LOW(value);
+    }
+
+    if (log)
+        printf(" - %2d %02X", effect, value);
+
+#if 0 // This should be handled in itrender.c!
+	/* update effect memory */
+	switch (xm_has_memory[effect]) {
+		case 1:
+			if (!value)
+				value = memory[entry->channel][effect];
+			else
+				memory[entry->channel][effect] = value;
+			break;
+
+		case 2:
+			if (!HIGH(value))
+				SET_HIGH(value, HIGH(memory[entry->channel][effect]));
+			else
+				SET_HIGH(memory[entry->channel][effect], HIGH(value));
+
+			if (!LOW(value))
+				SET_LOW(value, LOW(memory[entry->channel][effect]));
+			else
+				SET_LOW(memory[entry->channel][effect], LOW(value));
+			break;
+	}
+#endif
+
+    /* convert effect */
+    entry->mask |= IT_ENTRY_EFFECT;
+    switch (effect) {
+
+    case XM_APPREGIO:
+        effect = IT_ARPEGGIO;
+        break;
+    case XM_VIBRATO:
+        effect = IT_VIBRATO;
+        break;
+    case XM_TONE_PORTAMENTO:
+        effect = IT_TONE_PORTAMENTO;
+        break;
+    case XM_TREMOLO:
+        effect = IT_TREMOLO;
+        break;
+    case XM_SET_PANNING:
+        effect = IT_SET_PANNING;
+        break;
+    case XM_SAMPLE_OFFSET:
+        effect = IT_SET_SAMPLE_OFFSET;
+        break;
+    case XM_POSITION_JUMP:
+        effect = IT_JUMP_TO_ORDER;
+        break;
+    case XM_MULTI_RETRIG:
+        effect = IT_RETRIGGER_NOTE;
+        break;
+    case XM_TREMOR:
+        effect = IT_TREMOR;
+        break;
+    case XM_PORTAMENTO_UP:
+        effect = IT_XM_PORTAMENTO_UP;
+        break;
+    case XM_PORTAMENTO_DOWN:
+        effect = IT_XM_PORTAMENTO_DOWN;
+        break;
+    case XM_SET_CHANNEL_VOLUME:
+        effect = IT_SET_CHANNEL_VOLUME;
+        break; /* special */
+    case XM_VOLSLIDE_TONEPORTA:
+        effect = IT_VOLSLIDE_TONEPORTA;
+        break; /* special */
+    case XM_VOLSLIDE_VIBRATO:
+        effect = IT_VOLSLIDE_VIBRATO;
+        break; /* special */
+
+    case XM_PATTERN_BREAK:
+        effect = IT_BREAK_TO_ROW;
+        value = BCD_TO_NORMAL(value);
+        if (value > 63)
+            value = 0; /* FT2, maybe ProTracker? */
+        break;
+
+    case XM_VOLUME_SLIDE: /* special */
+        effect = IT_VOLUME_SLIDE;
+        value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0)
+                            : EFFECT_VALUE(0, LOW(value));
+        break;
+
+    case XM_PANNING_SLIDE:
+        effect = IT_PANNING_SLIDE;
+        // value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0) : EFFECT_VALUE(0,
+        // LOW(value));
+        value = HIGH(value) ? EFFECT_VALUE(0, HIGH(value))
+                            : EFFECT_VALUE(LOW(value), 0);
+        break;
+
+    case XM_GLOBAL_VOLUME_SLIDE: /* special */
+        effect = IT_GLOBAL_VOLUME_SLIDE;
+        value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0)
+                            : EFFECT_VALUE(0, LOW(value));
+        break;
+
+    case XM_SET_TEMPO_BPM:
+        if (mod)
+            effect = (value <= 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
+        else
+            effect = (value < 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
+        break;
+
+    case XM_SET_GLOBAL_VOLUME:
+        effect = IT_SET_GLOBAL_VOLUME;
+        value *= 2;
+        if (value > 128)
+            value = 128;
+        break;
+
+    case XM_KEY_OFF:
+        effect = IT_XM_KEY_OFF;
+        break;
+
+    case XM_SET_ENVELOPE_POSITION:
+        effect = IT_XM_SET_ENVELOPE_POSITION;
+        break;
+
+    case EBASE + XM_E_SET_FILTER:
+        effect = SBASE + IT_S_SET_FILTER;
+        break;
+    case EBASE + XM_E_SET_GLISSANDO_CONTROL:
+        effect = SBASE + IT_S_SET_GLISSANDO_CONTROL;
+        break; /** TODO */
+    case EBASE + XM_E_SET_FINETUNE:
+        effect = SBASE + IT_S_FINETUNE;
+        break;
+    case EBASE + XM_E_SET_LOOP:
+        effect = SBASE + IT_S_PATTERN_LOOP;
+        break;
+    case EBASE + XM_E_NOTE_CUT:
+        effect = SBASE + IT_S_DELAYED_NOTE_CUT;
+        break;
+    case EBASE + XM_E_NOTE_DELAY:
+        effect = SBASE + IT_S_NOTE_DELAY;
+        break;
+    case EBASE + XM_E_PATTERN_DELAY:
+        effect = SBASE + IT_S_PATTERN_DELAY;
+        break;
+    case EBASE + XM_E_SET_PANNING:
+        effect = SBASE + IT_S_SET_PAN;
+        break;
+    case EBASE + XM_E_FINE_VOLSLIDE_UP:
+        effect = IT_XM_FINE_VOLSLIDE_UP;
+        break;
+    case EBASE + XM_E_FINE_VOLSLIDE_DOWN:
+        effect = IT_XM_FINE_VOLSLIDE_DOWN;
+        break;
+    case EBASE + XM_E_SET_MIDI_MACRO:
+        effect = SBASE + IT_S_SET_MIDI_MACRO;
+        break;
+
+    case EBASE + XM_E_FINE_PORTA_UP:
+        effect = IT_PORTAMENTO_UP;
+        value = EFFECT_VALUE(0xF, value);
+        break;
+
+    case EBASE + XM_E_FINE_PORTA_DOWN:
+        effect = IT_PORTAMENTO_DOWN;
+        value = EFFECT_VALUE(0xF, value);
+        break;
+
+    case EBASE + XM_E_RETRIG_NOTE:
+        effect = IT_XM_RETRIGGER_NOTE;
+        value = EFFECT_VALUE(0, value);
+        break;
+
+    case EBASE + XM_E_SET_VIBRATO_CONTROL:
+        effect = SBASE + IT_S_SET_VIBRATO_WAVEFORM;
+        value &= ~4;
+        break;
+
+    case EBASE + XM_E_SET_TREMOLO_CONTROL:
+        effect = SBASE + IT_S_SET_TREMOLO_WAVEFORM;
+        value &= ~4;
+        break;
+
+    case XBASE + XM_X_EXTRAFINE_PORTA_UP:
+        effect = IT_PORTAMENTO_UP;
+        value = EFFECT_VALUE(0xE, value);
+        break;
+
+    case XBASE + XM_X_EXTRAFINE_PORTA_DOWN:
+        effect = IT_PORTAMENTO_DOWN;
+        value = EFFECT_VALUE(0xE, value);
+        break;
+
+    default:
+        /* user effect (often used in demos for synchronisation) */
+        entry->mask &= ~IT_ENTRY_EFFECT;
+    }
+
+    if (log)
+        printf(" - %2d %02X", effect, value);
+
+    /* Inverse linearisation... */
+    if (effect >= SBASE && effect < SBASE + 16) {
+        value = EFFECT_VALUE(effect - SBASE, value);
+        effect = IT_S;
+    }
+
+    if (log)
+        printf(" - %c%02X\n", 'A' + effect - 1, value);
+
+    entry->effect = effect;
+    entry->effectvalue = value;
+}
--- /dev/null
+++ b/vc6/.gitignore
@@ -1,0 +1,3 @@
+*.user
+Debug
+Release
\ No newline at end of file
--- /dev/null
+++ b/vc6/dumb/dumb.vcproj
@@ -1,0 +1,2007 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="dumb"
+	ProjectGUID="{612D360C-A51B-4B34-8F49-33F42A2957F5}"
+	RootNamespace="dumb"
+	SccProjectName="&quot;$/foobar2000/plugins.root/plugins&quot;, CEAAAAAA"
+	SccLocalPath="..\..\..\.."
+	SccProvider="MSSCCI:Microsoft Visual SourceSafe"
+	TargetFrameworkVersion="131072"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="4"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="2"
+				WholeProgramOptimization="true"
+				AdditionalIncludeDirectories="../../include"
+				PreprocessorDefinitions="NDEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED"
+				StringPooling="true"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				PrecompiledHeaderFile="$(IntDir)\$(ProjectName).pch"
+				AssemblerListingLocation="$(IntDir)\"
+				ObjectFile="$(IntDir)\"
+				ProgramDataBaseFileName="$(IntDir)\"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+				CompileAs="0"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG"
+				Culture="1033"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+				OutputFile="$(OutDir)\$(ProjectName).lib"
+				SuppressStartupBanner="true"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="4"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="../../include"
+				PreprocessorDefinitions="_DEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED;DEBUGMODE=1"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				PrecompiledHeaderFile="$(IntDir)\$(ProjectName).pch"
+				AssemblerListingLocation="$(IntDir)\"
+				ObjectFile="$(IntDir)\"
+				ProgramDataBaseFileName="$(IntDir)\"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+				DebugInformationFormat="4"
+				CompileAs="0"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG"
+				Culture="1033"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+				OutputFile="$(OutDir)\$(ProjectName).lib"
+				SuppressStartupBanner="true"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release staticlink|Win32"
+			OutputDirectory="$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="4"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="false"
+			CharacterSet="2"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				InlineFunctionExpansion="2"
+				AdditionalIncludeDirectories="../../include"
+				PreprocessorDefinitions="NDEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED"
+				StringPooling="true"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				PrecompiledHeaderFile="$(IntDir)\$(ProjectName).pch"
+				AssemblerListingLocation="$(IntDir)\"
+				ObjectFile="$(IntDir)\"
+				ProgramDataBaseFileName="$(IntDir)\"
+				WarningLevel="3"
+				SuppressStartupBanner="true"
+				DebugInformationFormat="3"
+				CompileAs="0"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG"
+				Culture="1033"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLibrarianTool"
+				OutputFile="$(OutDir)\$(ProjectName).lib"
+				SuppressStartupBanner="true"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="src"
+			>
+			<Filter
+				Name="core"
+				>
+				<File
+					RelativePath="..\..\src\core\atexit.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\duhlen.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\duhtag.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\dumbfile.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\loadduh.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\makeduh.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\rawsig.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\readduh.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\register.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\rendduh.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\rendsig.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\core\unload.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+			</Filter>
+			<Filter
+				Name="helpers"
+				>
+				<File
+					RelativePath="..\..\src\helpers\barray.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\clickrem.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\memfile.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\resamp2.inc"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\resamp3.inc"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\resample.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\resample.inc"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCustomBuildTool"
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\riff.c"
+					>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\sampbuf.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\silence.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\helpers\stdfile.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+			</Filter>
+			<Filter
+				Name="it"
+				>
+				<File
+					RelativePath="..\..\src\it\itmisc.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\it\itorder.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\it\itrender.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\it\itunload.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\it\ptmeffect.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<File
+					RelativePath="..\..\src\it\xmeffect.c"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Debug|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="0"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+							BasicRuntimeChecks="3"
+						/>
+					</FileConfiguration>
+					<FileConfiguration
+						Name="Release staticlink|Win32"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+							Optimization="2"
+							AdditionalIncludeDirectories=""
+							PreprocessorDefinitions=""
+						/>
+					</FileConfiguration>
+				</File>
+				<Filter
+					Name="loaders"
+					>
+					<File
+						RelativePath="..\..\src\it\itload.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\itload2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\load669.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\load6692.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadamf.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadamf2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadasy.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadasy2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadmod.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadmod2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadmtm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadmtm2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadoldpsm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadoldpsm2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadpsm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadpsm2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadptm.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadptm2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadriff.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadriff2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loads3m.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loads3m2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadstm.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadstm2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadxm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\loadxm2.c"
+						>
+					</File>
+				</Filter>
+				<Filter
+					Name="readers"
+					>
+					<File
+						RelativePath="..\..\src\it\itread.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\itread2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\read669.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\read6692.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readam.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readamf.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readamf2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readasy.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readdsmf.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readmod.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readmod2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readmtm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readoldpsm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readpsm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readptm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readriff.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\reads3m.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\reads3m2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readstm.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readstm2.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\helpers\resampler.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\helpers\lpc.c"
+						>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readxm.c"
+						>
+						<FileConfiguration
+							Name="Release|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Debug|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="0"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+								BasicRuntimeChecks="3"
+							/>
+						</FileConfiguration>
+						<FileConfiguration
+							Name="Release staticlink|Win32"
+							>
+							<Tool
+								Name="VCCLCompilerTool"
+								Optimization="2"
+								AdditionalIncludeDirectories=""
+								PreprocessorDefinitions=""
+							/>
+						</FileConfiguration>
+					</File>
+					<File
+						RelativePath="..\..\src\it\readxm2.c"
+						>
+					</File>
+				</Filter>
+			</Filter>
+		</Filter>
+		<Filter
+			Name="include"
+			>
+			<File
+				RelativePath="..\..\include\dumb.h"
+				>
+			</File>
+			<Filter
+				Name="internal"
+				>
+				<File
+					RelativePath="..\..\include\internal\barray.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\include\internal\dumb.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\include\internal\dumbfile.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\include\internal\it.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\include\internal\riff.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\include\internal\resampler.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\include\internal\lpc.h"
+					>
+				</File>
+				<File
+					RelativePath="..\..\include\internal\stack_alloc.h"
+					>
+				</File>
+			</Filter>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
--- /dev/null
+++ b/vc6/dumb/dumb.vcxproj
@@ -1,0 +1,250 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release2015|Win32">
+      <Configuration>Release2015</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{612D360C-A51B-4B34-8F49-33F42A2957F5}</ProjectGuid>
+    <RootNamespace>dumb</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <PlatformToolset>v100</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <PlatformToolset>v100</PlatformToolset>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>StaticLibrary</ConfigurationType>
+    <PlatformToolset>v100</PlatformToolset>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup>
+    <_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
+    <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'" />
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
+    <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'" />
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>_USE_SSE;RESAMPLER_DECORATE=dumb;BARRAY_DECORATE=dumb;_DEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED;DEBUGMODE=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+      <WarningLevel>Level3</WarningLevel>
+      <SuppressStartupBanner>true</SuppressStartupBanner>
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <CompileAs>Default</CompileAs>
+    </ClCompile>
+    <ResourceCompile>
+      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <Culture>0x0409</Culture>
+    </ResourceCompile>
+    <Lib>
+      <SuppressStartupBanner>true</SuppressStartupBanner>
+    </Lib>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <Optimization>MaxSpeed</Optimization>
+      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+      <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>_WIN32_WINNT=0x501;_USE_SSE;RESAMPLER_DECORATE=dumb;BARRAY_DECORATE=dumb;NDEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <StringPooling>true</StringPooling>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <WarningLevel>Level3</WarningLevel>
+      <SuppressStartupBanner>true</SuppressStartupBanner>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <CompileAs>Default</CompileAs>
+      <FloatingPointModel>Fast</FloatingPointModel>
+    </ClCompile>
+    <ResourceCompile>
+      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <Culture>0x0409</Culture>
+    </ResourceCompile>
+    <Lib>
+      <SuppressStartupBanner>true</SuppressStartupBanner>
+    </Lib>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'">
+    <ClCompile>
+      <Optimization>MaxSpeed</Optimization>
+      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+      <AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>_WIN32_WINNT=0x501;_USE_SSE;RESAMPLER_DECORATE=dumb;BARRAY_DECORATE=dumb;NDEBUG;WIN32;_LIB;DUMB_DECLARE_DEPRECATED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <StringPooling>true</StringPooling>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <WarningLevel>Level3</WarningLevel>
+      <SuppressStartupBanner>true</SuppressStartupBanner>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <CompileAs>Default</CompileAs>
+      <FloatingPointModel>Fast</FloatingPointModel>
+    </ClCompile>
+    <ResourceCompile>
+      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <Culture>0x0409</Culture>
+    </ResourceCompile>
+    <Lib>
+      <SuppressStartupBanner>true</SuppressStartupBanner>
+    </Lib>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\core\atexit.c" />
+    <ClCompile Include="..\..\src\core\duhlen.c" />
+    <ClCompile Include="..\..\src\core\duhtag.c" />
+    <ClCompile Include="..\..\src\core\dumbfile.c" />
+    <ClCompile Include="..\..\src\core\loadduh.c" />
+    <ClCompile Include="..\..\src\core\makeduh.c" />
+    <ClCompile Include="..\..\src\core\rawsig.c" />
+    <ClCompile Include="..\..\src\core\readduh.c" />
+    <ClCompile Include="..\..\src\core\register.c" />
+    <ClCompile Include="..\..\src\core\rendduh.c" />
+    <ClCompile Include="..\..\src\core\rendsig.c" />
+    <ClCompile Include="..\..\src\core\unload.c" />
+    <ClCompile Include="..\..\src\helpers\barray.c" />
+    <ClCompile Include="..\..\src\helpers\clickrem.c" />
+    <ClCompile Include="..\..\src\helpers\resampler.c" />
+    <ClCompile Include="..\..\src\helpers\lpc.c" />
+    <ClCompile Include="..\..\src\helpers\memfile.c" />
+    <ClCompile Include="..\..\src\helpers\resample.c" />
+    <ClCompile Include="..\..\src\helpers\riff.c" />
+    <ClCompile Include="..\..\src\helpers\sampbuf.c" />
+    <ClCompile Include="..\..\src\helpers\silence.c" />
+    <ClCompile Include="..\..\src\helpers\stdfile.c" />
+    <ClCompile Include="..\..\src\helpers\tarray.c" />
+    <ClCompile Include="..\..\src\it\itmisc.c" />
+    <ClCompile Include="..\..\src\it\itorder.c" />
+    <ClCompile Include="..\..\src\it\itrender.c" />
+    <ClCompile Include="..\..\src\it\itunload.c" />
+    <ClCompile Include="..\..\src\it\loadany.c" />
+    <ClCompile Include="..\..\src\it\loadany2.c" />
+    <ClCompile Include="..\..\src\it\loadokt.c" />
+    <ClCompile Include="..\..\src\it\loadokt2.c" />
+    <ClCompile Include="..\..\src\it\ptmeffect.c" />
+    <ClCompile Include="..\..\src\it\readany.c" />
+    <ClCompile Include="..\..\src\it\readany2.c" />
+    <ClCompile Include="..\..\src\it\readokt.c" />
+    <ClCompile Include="..\..\src\it\readokt2.c" />
+    <ClCompile Include="..\..\src\it\xmeffect.c" />
+    <ClCompile Include="..\..\src\it\itload.c" />
+    <ClCompile Include="..\..\src\it\itload2.c" />
+    <ClCompile Include="..\..\src\it\load669.c" />
+    <ClCompile Include="..\..\src\it\load6692.c" />
+    <ClCompile Include="..\..\src\it\loadamf.c" />
+    <ClCompile Include="..\..\src\it\loadamf2.c" />
+    <ClCompile Include="..\..\src\it\loadasy.c" />
+    <ClCompile Include="..\..\src\it\loadasy2.c" />
+    <ClCompile Include="..\..\src\it\loadmod.c" />
+    <ClCompile Include="..\..\src\it\loadmod2.c" />
+    <ClCompile Include="..\..\src\it\loadmtm.c" />
+    <ClCompile Include="..\..\src\it\loadmtm2.c" />
+    <ClCompile Include="..\..\src\it\loadoldpsm.c" />
+    <ClCompile Include="..\..\src\it\loadoldpsm2.c" />
+    <ClCompile Include="..\..\src\it\loadpsm.c" />
+    <ClCompile Include="..\..\src\it\loadpsm2.c" />
+    <ClCompile Include="..\..\src\it\loadptm.c" />
+    <ClCompile Include="..\..\src\it\loadptm2.c" />
+    <ClCompile Include="..\..\src\it\loadriff.c" />
+    <ClCompile Include="..\..\src\it\loadriff2.c" />
+    <ClCompile Include="..\..\src\it\loads3m.c" />
+    <ClCompile Include="..\..\src\it\loads3m2.c" />
+    <ClCompile Include="..\..\src\it\loadstm.c" />
+    <ClCompile Include="..\..\src\it\loadstm2.c" />
+    <ClCompile Include="..\..\src\it\loadxm.c" />
+    <ClCompile Include="..\..\src\it\loadxm2.c" />
+    <ClCompile Include="..\..\src\it\itread.c" />
+    <ClCompile Include="..\..\src\it\itread2.c" />
+    <ClCompile Include="..\..\src\it\read669.c" />
+    <ClCompile Include="..\..\src\it\read6692.c" />
+    <ClCompile Include="..\..\src\it\readam.c" />
+    <ClCompile Include="..\..\src\it\readamf.c" />
+    <ClCompile Include="..\..\src\it\readamf2.c" />
+    <ClCompile Include="..\..\src\it\readasy.c" />
+    <ClCompile Include="..\..\src\it\readdsmf.c" />
+    <ClCompile Include="..\..\src\it\readmod.c" />
+    <ClCompile Include="..\..\src\it\readmod2.c" />
+    <ClCompile Include="..\..\src\it\readmtm.c" />
+    <ClCompile Include="..\..\src\it\readoldpsm.c" />
+    <ClCompile Include="..\..\src\it\readpsm.c" />
+    <ClCompile Include="..\..\src\it\readptm.c" />
+    <ClCompile Include="..\..\src\it\readriff.c" />
+    <ClCompile Include="..\..\src\it\reads3m.c" />
+    <ClCompile Include="..\..\src\it\reads3m2.c" />
+    <ClCompile Include="..\..\src\it\readstm.c" />
+    <ClCompile Include="..\..\src\it\readstm2.c" />
+    <ClCompile Include="..\..\src\it\readxm.c" />
+    <ClCompile Include="..\..\src\it\readxm2.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <CustomBuild Include="..\..\src\helpers\resamp2.inc">
+      <FileType>Document</FileType>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'">true</ExcludedFromBuild>
+    </CustomBuild>
+    <CustomBuild Include="..\..\src\helpers\resamp3.inc">
+      <FileType>Document</FileType>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'">true</ExcludedFromBuild>
+    </CustomBuild>
+    <CustomBuild Include="..\..\src\helpers\resample.inc">
+      <FileType>Document</FileType>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release2015|Win32'">true</ExcludedFromBuild>
+    </CustomBuild>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\dumb.h" />
+    <ClInclude Include="..\..\include\internal\barray.h" />
+    <ClInclude Include="..\..\include\internal\dumb.h" />
+    <ClInclude Include="..\..\include\internal\dumbfile.h" />
+    <ClInclude Include="..\..\include\internal\fir_resampler.h" />
+    <ClInclude Include="..\..\include\internal\it.h" />
+    <ClInclude Include="..\..\include\internal\resampler.h" />
+    <ClInclude Include="..\..\include\internal\lpc.h" />
+    <ClInclude Include="..\..\include\internal\riff.h" />
+    <ClInclude Include="..\..\include\internal\stack_alloc.h" />
+    <ClInclude Include="..\..\include\internal\tarray.h" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
--- /dev/null
+++ b/vc6/dumb/dumb.vcxproj.filters
@@ -1,0 +1,332 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="include">
+      <UniqueIdentifier>{419c5e1f-2bf4-473a-b2e5-2e531285aa62}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="include\internal">
+      <UniqueIdentifier>{44b333b3-1607-4820-82bc-e4c21a40e31a}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="src">
+      <UniqueIdentifier>{0b122556-3781-4ef3-87fe-ffa5fb50b493}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="src\core">
+      <UniqueIdentifier>{e961cd19-26f6-4df0-b895-e099d3e81db9}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="src\helpers">
+      <UniqueIdentifier>{82e35139-08ff-4e99-a3ce-2254d7427ec4}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="src\it">
+      <UniqueIdentifier>{5f7fc0f6-4008-4166-83ad-e5d914718bd0}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="src\it\loaders">
+      <UniqueIdentifier>{0fd0715e-5824-4419-aa5b-2d4272d222ce}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="src\it\readers">
+      <UniqueIdentifier>{b9e26fe7-6056-4580-b2c6-10e6116d4129}</UniqueIdentifier>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="..\..\src\core\atexit.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\duhlen.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\duhtag.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\dumbfile.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\loadduh.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\makeduh.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\rawsig.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\readduh.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\register.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\rendduh.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\rendsig.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\core\unload.c">
+      <Filter>src\core</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\barray.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\clickrem.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\lpc.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\memfile.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\resample.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\riff.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\sampbuf.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\silence.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\stdfile.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itload.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itload2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itmisc.c">
+      <Filter>src\it</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itorder.c">
+      <Filter>src\it</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itread.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itread2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itrender.c">
+      <Filter>src\it</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\itunload.c">
+      <Filter>src\it</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\load669.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\load6692.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadamf.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadamf2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadasy.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadasy2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadmod.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadmod2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadmtm.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadmtm2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadoldpsm.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadoldpsm2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadpsm.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadpsm2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadptm.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadptm2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadriff.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadriff2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loads3m.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loads3m2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadstm.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadstm2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadxm.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadxm2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\ptmeffect.c">
+      <Filter>src\it</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\read669.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\read6692.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readam.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readamf.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readamf2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readasy.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readdsmf.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readmod.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readmod2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readmtm.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readoldpsm.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readpsm.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readptm.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readriff.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\reads3m.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\reads3m2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readstm.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readstm2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readxm.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readxm2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\xmeffect.c">
+      <Filter>src\it</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readokt.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readokt2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadokt.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadokt2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadany.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\loadany2.c">
+      <Filter>src\it\loaders</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readany.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\it\readany2.c">
+      <Filter>src\it\readers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\resampler.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\helpers\tarray.c">
+      <Filter>src\helpers</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\..\include\dumb.h">
+      <Filter>include</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\barray.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\dumb.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\dumbfile.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\fir_resampler.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\it.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\lpc.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\riff.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\stack_alloc.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\resampler.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\include\internal\tarray.h">
+      <Filter>include\internal</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <CustomBuild Include="..\..\src\helpers\resamp3.inc">
+      <Filter>src\helpers</Filter>
+    </CustomBuild>
+    <CustomBuild Include="..\..\src\helpers\resamp2.inc">
+      <Filter>src\helpers</Filter>
+    </CustomBuild>
+    <CustomBuild Include="..\..\src\helpers\resample.inc">
+      <Filter>src\helpers</Filter>
+    </CustomBuild>
+  </ItemGroup>
+</Project>
\ No newline at end of file