AMPS - Ample Music Playback System

Discussion in 'Utilities' started by AURORA☆FIELDS, Apr 28, 2019.


    AURORA☆FIELDS the cute one here Member

    Oct 7, 2011
    Nat's lap

    is a sound driver I started developing in mid-2016, to be used for my hacks. I never found any use for it however. Instead, I kept developing it, if ever in the future I would need it. While I was working for this, Dual PCM was released, and with it, I made the driver work around it. After talking with MarkeyJester, I was allowed to use the future version of Dual PCM in the driver, the version which eventually became Dual PCM FlexEd. I worked on the driver every now and then for almost 2 more years, readying it for public release, and waiting for a Dual PCM release version along with it. You may have seen an early version of the driver in my hack, Achi, where it was used to power all the music related things.

    More about the driver

    AMPS is a sound driver based on Sound-Source, that runs on the Motorola 68000, designed to be used with ROM hacks and Sega Mega Drive software. Although similar to Sound-Source, AMPS is fundamentally different in many aspects. It is also heavily customized, RAM-efficient and cycle-efficient. AMPS is powered by Dual PCM FlexEd, meaning that you can use 2 DAC sample channels with pitch and volume control. AMPS was designed to be a well-documented driver with a lot of capabilities so that the music can sound better, and the program and music can interact with each other. To ensure this, AMPS has a very robust codebase built to allow future expansion and customized programming for program-specific circumstances.

    What features does AMPS have?
    • Highly optimized code, that will ensure that no time is wasted in processing the 68k-side code.
    • Lower RAM usage. The driver optimizes the RAM usage, so that it is easier to add into any program.
    • Various flags to control which features are enabled for AMPS. The user can customize the driver to fit their needs, saving RAM and processor cycles.
    • End user documentation with examples and helpful tools, and documented source code for easier modification.
    • Full support for Dual PCM FlexEd.
      • 2-channel PCM playback.
      • Volume and pitch control.
      • Reverse sample playback.
      • Looping sample support.
      • DMA quality loss prevention.
      • Simplistic sample filtering.
    • PCM sound effect channel and 2 music PCM channels.
    • PCM channels can choose between 2 modes; Sample mode where each note is the sample to be played, and pitch mode where each note changes the pitch instead.
    • Portamento effect for smoothly modulating from one note to another.
    • Full support for volume envelopes and modulation envelopes.
    • SMPS2ASM integration. This makes it possible to easily port music and allows for future expansion.
    • Universal sound bank for sound effects.
    • SSG-EG and LFO support.
    • Speed shoes tempo adjustment, and 2 tempo algorithms; overflow-based and tempo-based.
    • Toggleable 50hz "fix" for music.
    • Spindash sound effect support.
    • Special underwater mode. This allows for a cool underwater-esque effect for music and sound effects (as seen in Sonic 2 Recreation).
    • Customizable fading support. The driver supports multiple different types of fades, and they are user-defined, allowing for a huge variety of different ways to fade or manipulate channel volumes globally.
    • Better commands for using communications bytes for 2-way conversation between tracker files and the game code, and conditionally executing tracker code.
    • Continuous sound effects support. These are sound effects in Sonic 3 & Knuckles that instead of restarting, continue to play sound when the sound ID is played.
    • Music back-up support. This is used in Sonic games for the 1-up sound effect.
    • Sound driver debugging support. This feature allows the sound driver to alert the programmer when various errors or possible mistakes happen when playing tracker files. Very useful for finding out when something goes wrong with the sound driver.

    Why should you use AMPS over something else?

    As discussed already, AMPS provides a large set of features, while conserving CPU cycles and RAM usage. Furthermore, AMPS will be developed further with community feedback in mind, and with new features and optimizations. AMPS is also fully open-source, and can be modified for everyone's individual needs. The source code, while large and complicated, is well documented and open for suggestions. Additionally, since AMPS is built around Dual PCM FlexEd, its integration into the sound driver is deep, which allows the sound driver to reap all the benefits from using Dual PCM FlexEd. The improvements to the music and sound effect formats allow for better and more varied music to be made, especially when it comes to PCM channels. AMPS is also the only Sound-Source-based sound driver which makes it possible to integrate the music more deeply with gameplay or graphics of the host program, something which previously was not possible, or had to be custom built. AMPS has received a lot of attention to detail for its features and codebase.

    What the download contains

    The download contains a few things:
    • End-user technical documentation for AMPS, and the technical reference manual for Dual PCM FlexEd.
    • Depending on the package, either Sonic 1 implementation, Sonic 2 implementation, or files for the AMPS test program which helps debug music, and has a few custom goodies.
    • A folder containing a slightly customized version of Vladikcomper's error debugger. These customizations allow for scrolling menus.

    Few extra notes
    • We have a Discord server!
    • If you want to report a bug, or ask for help with an issue, please provide Aurora with enough information to go by, don't just ask why your assembler or the game is throwing up error messages. I need to know what you think is causing the issue, what you did before the error appeared, what you tried to do to fix it, and if applicable, the ROM, any music or sound effect files that are related. I may ask for more things if I can not figure out what is going on.
    • If you want to suggest a new feature or want me to change something, please also explain why, and how it will benefit the driver as a whole.
    • AMPS currently only supports ASM68K and AS. Because of the complexity of porting this to other assemblers, and limited free time, I am unable to provide a download for other assemblers at this time. If anyone is willing to help out in this regard, I am happy to offer the download here.
    • I have a life (surprising I know)
    • The safe mode is meant to be used only to debug for issues with songs, not for your release ROMs! The safe mode reduces performance and adds more memory usage for the sound driver, meaning that it is most effectively used only when necessary. You can use safe mode for releases without a problem, but it is not recommended.
    • The sound driver does use considerably more ROM space, than other drivers. This is a lot to do with the optimizations I've applied, and Dual PCM FlexEd. Unfortunately, there is not a lot I can do about this currently.

    Future plans

    I have a few things I wanna add in the future into AMPS. Here they are, in no specific order:
    • Clean up the source code more, and make it easier to modify.
    • Add support for PSG4 as a standalone channel.
    • Add support for special FM3 mode, along with dedicated trackers for each of them.
    • Add support for TL modulation and envelopes.
    • Improve underwater mode.
    • Few performance optimizations I have in mind.
    • Better support for volume filters.
    Follow the development of AMPS at its GitHub page!
    Come talk to other users and the devs on Discord!

    • AURORA☆FIELDS - The creator and main programmer behind AMPS, and creator and porting of the example music.
    • MarkeyJester - The creator of Dual PCM FlexEd, help with documentation for Sonic 1's sound driver, helping with bug fixes, documentation, hardware testing, and creating the logo.
    • ValleyBell - Provided the code for underwater mode, and is the creator of SMPS Research Pack.
    • Vladikcomper - The creator of the error debugger used for AMPS, and for helping me learn about sound drivers.
    • LuigiXHero - Help with porting many new additions between branches.
    • Stardust Gear - Small additions and bug fixes.
    • Death Rapunzel - Help with bug fixes.
    • Nat The Porcupine - Help with the documentation and hardware testing.
    • FoxConED - Playtesting and suggestions, teaser video, hardware testing.
    • VAdaPEGA - Suggestions and helping with documentation.
    • Hyper - Helping with documentation.
    • Selbi - Help with the documentation.
    • Ozaleto - Help with testing.
    • Kurk - Help with testing.
    • SEGA & Sonic Team - Original Sound-Source 68k driver that AMPS is based upon.
    Sorry if I missed anyone, I realized I forgot keep notes of everyone who's helped, so I hope my memory doesn't fail me...
    Last edited: Jul 22, 2020
  2. EMK-20218

    EMK-20218 The Fuss Maker Member

    Aug 8, 2008
    Jardim Capelinha, São Paulo
    Nats... seriously, marry me. (just kidding)

    I need to use this. Although I'm not sure about how I could insert it in my hack or if it would even be compatible with it due to certain internal modifications that my hack's engine suffered accross the years. As for what did I read, it seems very flexible and seems to show a bunch of functions that would be very useful to me. I'm not sure if I'll be able to implement it with the very low ASM knowledge I have, but I'll give it a try. This is a real great present for music lovers like me. Thank you very much! :)
    Trickster and AURORA☆FIELDS like this.
  3. Nat The Porcupine

    Nat The Porcupine Active Member Member

    Jun 23, 2017
    Alright, so I gave the driver a quick glance & I have to say that I'm very excited to play around with it. Nicely done, it was definitely worth the wait.
    Trickster likes this.

    AURORA☆FIELDS the cute one here Member

    Oct 7, 2011
    Nat's lap
    So, as I am working on the next release of AMPS, I realize something. To bring the best experience and compromise to everyone, I need to have more options for the user to fine-tune their driver to their liking. This presents a big problem: I will need considerably more time to test each configuration, along with the new features and changes... This will add a lot more time to development only focused on testing and fixing all the immediate bugs, and will make it more likely for bugs to be present in the driver upon release. Given I am going to college again in just over a week, I will have even less time to work on anything. Additionally, keeping documentation up-to-date will be difficult because of this. So what I am thinking is, as I release updates to Github for the driver, I could have you guys help me stress-test it, and report bugs back to me. I also need someone who is willing to re-write the documentation in a nicer format and keep it updated.

    So here is the deal, anyone wanting to help me with testing and bugfixes, you can download the latest source code from Github and play around with it. I will not provide installation instructions nor support for these versions, so use at your own risk! But I will take care of any bugs you report. Preferably, file an issue through the Github website itself on the repository, but you can also DM them to me directly if you don't have an account. I will credit you accordingly on the next release, and will have it out sooner.

    As far as writing documentation, I am afraid, I need someone who actually knows a thing or two about how sound drivers work. I do not have the time to essentially tell you what to write, so I would like that you do your research and I can nitpick what you have written and provide additional details. The documentation should be written in some nice looking format (as opposed to the dodgy solution with text files like currently), and from where you can copy code that preserves formatting (tabs etc). I will provide my help and guidance however, but you'll also need to be able to work independently in a reasonable timeframe.

    By the way, making some progress towards some of the new features currently, so that's something to look forward to.
  5. SMS Alfredo

    SMS Alfredo Compact Disc Enthusiast Member

    Sep 3, 2018
    Little Planet
    Not sure if this is the correct place to put this, but I have a bug in AMPS I would like to report.

    So, I am attempting to create a streamed song using 3 DAC samples strung together and repeated. The samples are long enough that they don't fit into the $7F range of waiting time. Normally this wouldn't be a problem, as adding more wait time afterwards usually works and the sample continues as long as I meant it to. However, it seems that in this driver, adding extra wait time beyond the initial one set by the sample itself does not work. Instead, for every extra value of wait time, the sample restarts itself. Not sure if this is how it acts in vanilla Sonic 1, but I know for certain this is not how it acted in the MegaPCM Driver.

    Here's the asm file if you want to try replicating the problem yourself.

    Hope this will be helpful.

    AURORA☆FIELDS the cute one here Member

    Oct 7, 2011
    Nat's lap
    I don't have access to the ASM file because of Google drive, however I think I know the issue. DAC channel is bit of a special case in Sonic 1, it does not act like a normal channel, it follows slightly different rules. I am not 100% clear on the rules but likely playing note, delay, delay will not restart a sample. AMPS adheres to the rules of FM and PSG channels, note, delay, delay causes 2 notes to play in succession. This is why the sHold flag exists, it skips a few steps in playing a note, notably the part where the note is restarted, resetting a few variables, and other channel-specific things. For DAC, this means that your sample will keep playing despite playing more delays. You want to add sHold before each additional delay beyond the initial delay.
  7. ValleyBell

    ValleyBell Well-Known Member Member

    Dec 23, 2011
    On the DAC channel, note, delay, delay always plays 2 notes. In SMPS 68k/Sonic 1, the only difference to FM and PSG channels is, that the sHold flag doesn't work.
    Instead you're unable to stop a sample, because playing a rest doesn't do anything.

    You can have longer DAC samples by playing: note, delay, rest, delay, delay, ...

    AURORA☆FIELDS the cute one here Member

    Oct 7, 2011
    Nat's lap
    So, an update to AMPS. As you've no doubt seen during the contest week, I released AMPS in Sonic 2 to the SHC Expo. This has been something that has been requested from me for a long time, and I never really felt up to the task of porting AMPS to AS. However, because people asked me nicely and promised to help, I decided to go for it. Of course, as it turns out, porting it was a huge mess and some fundamental things about the driver had to change in order to suit a correct port. There are still some kinks to work out (I am really NOT having fun with AS at all), but I am confident that the current release of the driver works competently enough that I can release it for everyone to enjoy! That being said, this is a pre-release version and there may be severe bugs! Use at your own risk as they say. I will work over time to find and fix these issues, so I definitely suggest keeping up-to-date with the Github repo.

    Also, here is a quick rundown of the changes from previous AMPS versions:
    • PSG volumes are now 7-bit as opposed to 4-bit. This means you have to convert them in songs and sound effects, but it allows for far more intercompatibility with FM
    • There is support for FM6 channels. These can be enabled with simultaneously with DAC too, though DAC will always override FM6.
    • Fixed underwater mode algorithm
    • Support for modulation envelopes
    • Support for FM and DAC volume envelopes
    • Portamento flag
    • Support for backing up songs (such as the 1UP-jingle from Sonic games
    • Optimized YM command code which should make the driver noticeably faster to process
    • Fixed some SFX sounding wrong because of bad timings regarding YM writes (Dual PCM technically writes the cue too fast to YM, so some sounds are different as a result. Fixed by adding more "delay").
    • Updated register setup in such a way that the driver does not use d7 or a6 anywhere
    • Some other bugfixes or tiny feature not worth mentioning right now
    As you can see, AMPS has evolved quite far. The normal 68k version also has kept up with the AS version and should have parity with features. I still need help with bugtesting and documentation, as those are mostly the things left before I can do a full release. Unfortunately, as I don't have massive amounts of time, it may still take me a few months to get everything ready for a release without any help. Furthermore, I am running into some.... Limitations with AS to put it nicely. It does not like to cooperate with me on a few issues that I think are really gonna be a problem regarding full release. Solving that may take some time...

    Anyway, here is the repository link
    ProjectFM, Crash, Aier and 6 others like this.

    AURORA☆FIELDS the cute one here Member

    Oct 7, 2011
    Nat's lap
    I know I've half-promised AMPS for the new year, but because of real life stuff, I haven't been able to finish it. Its not far from being release-worthy, but some things still need to be worked out. Unfortunately, this real life situation is getting more complicated and I have less time to work on this, and because of coronavirus, now I have also less energy to work on things too. I am hoping to get this released ASAP, but there is absolutely no guarantee I will be able to. AMPS is pretty much ready to be used though, the official release will likely not be all that different from what you can see on Github. Please be patient as I work out this situation and add the finishing touches. It's unfortunate things like this happens, but real life comes first, always.
    Iso Kilo, Samey, EMK-20218 and 9 others like this.

    AURORA☆FIELDS the cute one here Member

    Oct 7, 2011
    Nat's lap
    It's here folks! The latest AMPS version. The first post has been edited with the new details, so be sure to have a look.

    A lot has changed since the last time. Because of a lot of people requesting it, there is now an AS port and a Sonic 2 branch. 1-up sounds work correctly again, a lot of optimizations have been done, volume envelopes are supported for DAC and FM, modulation envelopes are supported, and FM6 can be enabled as much channel (even while DAC is running! Though, no DAC sample must be played until FM6 can be heard). There are a few custom features, such as portamento and 7-bit PSG volume. A lot of the rough edges from the last version have been smoothed out, and few customizations has been added. Overall, if I can say so myself, its worth using the new version. It's much better than the first release, and there is now a comprehensive documentation included!

    AURORA☆FIELDS the cute one here Member

    Oct 7, 2011
    Nat's lap
    Here is the next version of AMPS. The post, again, has been updated.

    Again, a fair bit has changed. AMPS now uses a generator to assemble the sound drivers, so they're easy to update. Modulation has drastically been changed to further support Z80 versions, and plenty of bugs have been fixed. The documentation is updated to contain all this new information. You may have to edit your music in order to update to 2.1. See the changelog here:
    • sFreqOn and sFreqOff are no longer tracker commands.
    • New tracker commands: ssModFreq and sModReset.
    • Changes to sModAMPS: Only the <wait> and <step> parameters are loaded initially. This only makes a difference when note is held. The modulation parameters are not reset, which allows the user to change how modulation works mid-note without resetting the offset. In order for the old behaviour to work, sModReset can be used after sModAMPS is used. The <count> is also changed. Now, the value is subtracted before being checked, meaning value of $00 will not start by negating the <step>. Additionally, now it is treated as infinite, meaning modulation up and down is possible for unlimited time. If <count> is $01, the value initially is set to $01 instead of $00, making short modulations still possible. When <wait> is counting down, modulation frequency is still accounted for.
    • The frame a note is played, modulation, portamento and modulation envelope are all updated.
    • mfbNoPAL flag is used to check whether or not PAL mode is enabled, instead of checking for the region. The flag is updated based on song header and PAL region by dPlaySnd_Music.
    • Fixed a bug where DAC panning was not reset correctly for music channels, leading to issues with panning.
    • Fixed a bug with modulation envelopes not working as intended.
    • Added a new PSG frequency to match the PSG table exactly with Sound-Source Z80.
    • Added a new FM frequency to help with Sound-Source Z80.
    • Added a feature that allows easier integration with sound test engines.
    • Speed shoes tempo algorithm now works by running the sound driver twice when the timeout occurs. This also means speed shoes has its own timeout instead of using the main tempo.
    • AMPS Includer can list the names of all music and sfx tracks (not commands however!) now.
    Edit: Some stuff is still to come! Wait patiently! Also, portamento algorithm is changing in the next release to be more consistent with how Sound-Source games did it.
    Last edited: Jul 22, 2020