From 779afcb97ae836a42181f5fee06cc29a318c82c7 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sat, 14 Oct 2023 08:10:37 -0300 Subject: [PATCH 01/34] WIP: adding ESFM (ESS ES1488/ESS ES1868 etc.) system --- .gitignore | 1 + CMakeLists.txt | 5 + extern/ESFMu/.clangd | 2 + extern/ESFMu/.gitignore | 1 + extern/ESFMu/LICENSE | 504 +++++++++++++ extern/ESFMu/MODIFIED.md | 6 + extern/ESFMu/README.md | 67 ++ extern/ESFMu/esfm.c | 1164 ++++++++++++++++++++++++++++++ extern/ESFMu/esfm.h | 305 ++++++++ extern/ESFMu/esfm_registers.c | 995 +++++++++++++++++++++++++ src/engine/dispatchContainer.cpp | 4 + src/engine/engine.cpp | 6 + src/engine/instrument.cpp | 77 +- src/engine/instrument.h | 110 +++ src/engine/platform/esfm.cpp | 854 ++++++++++++++++++++++ src/engine/platform/esfm.h | 144 ++++ src/engine/song.h | 45 +- src/engine/sysDef.cpp | 12 + src/gui/fmPreview.cpp | 57 ++ src/gui/gui.h | 3 + src/gui/guiConst.cpp | 5 + src/gui/insEdit.cpp | 501 ++++++++----- src/gui/intConst.cpp | 2 + src/gui/intConst.h | 2 + 24 files changed, 4705 insertions(+), 167 deletions(-) create mode 100644 extern/ESFMu/.clangd create mode 100644 extern/ESFMu/.gitignore create mode 100644 extern/ESFMu/LICENSE create mode 100644 extern/ESFMu/MODIFIED.md create mode 100644 extern/ESFMu/README.md create mode 100644 extern/ESFMu/esfm.c create mode 100644 extern/ESFMu/esfm.h create mode 100644 extern/ESFMu/esfm_registers.c create mode 100644 src/engine/platform/esfm.cpp create mode 100644 src/engine/platform/esfm.h diff --git a/.gitignore b/.gitignore index 09314bb24..06812e61e 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ res/docpdf/manual.pdf res/docpdf/.venv res/docpdf/htmldoc/ res/furnace.appdata.xml +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 6278184b5..f7a2a3dd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.0) +set(CMAKE_EXPORT_COMPILE_COMMANDS on) + if (APPLE) set(MACOSX_DEPLOYMENT_TARGET 10.9) endif() @@ -454,6 +456,8 @@ extern/Nuked-PSG/ympsg.c extern/opm/opm.c extern/Nuked-OPLL/opll.c extern/opl/opl3.c +extern/ESFMu/esfm.c +extern/ESFMu/esfm_registers.c src/pch.cpp @@ -660,6 +664,7 @@ src/engine/platform/pv1000.cpp src/engine/platform/k053260.cpp src/engine/platform/ted.cpp src/engine/platform/c140.cpp +src/engine/platform/esfm.cpp src/engine/platform/pcmdac.cpp src/engine/platform/dummy.cpp diff --git a/extern/ESFMu/.clangd b/extern/ESFMu/.clangd new file mode 100644 index 000000000..f6023d41f --- /dev/null +++ b/extern/ESFMu/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: ["-xc", "-Wall", "-Wextra"] diff --git a/extern/ESFMu/.gitignore b/extern/ESFMu/.gitignore new file mode 100644 index 000000000..7cb2b78a0 --- /dev/null +++ b/extern/ESFMu/.gitignore @@ -0,0 +1 @@ +test_scripts/* diff --git a/extern/ESFMu/LICENSE b/extern/ESFMu/LICENSE new file mode 100644 index 000000000..8000a6faa --- /dev/null +++ b/extern/ESFMu/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/extern/ESFMu/MODIFIED.md b/extern/ESFMu/MODIFIED.md new file mode 100644 index 000000000..78625584c --- /dev/null +++ b/extern/ESFMu/MODIFIED.md @@ -0,0 +1,6 @@ +# Modification disclaimer + +This is a modified version of ESFMu v1.0.1 which implements a function for reading the waveform output of the individual FM channels. The modification was made by Kagamiin~ (original author of ESFMu) herself. + +Kagamiin~ notes: +> In hindsight, I might merge back this functionality into a future version of the core, as it could be be useful for generating oscilloscope views in other tools. diff --git a/extern/ESFMu/README.md b/extern/ESFMu/README.md new file mode 100644 index 000000000..5e04ef6fb --- /dev/null +++ b/extern/ESFMu/README.md @@ -0,0 +1,67 @@ +# ESFMu + +An emulator for the ESS "ESFM" enhanced OPL3 clone, based on Nuke.YKT's **Nuked OPL3** and reverse-engineering efforts from the community. + +## Acknowledgements + +I'd like to thank: + +- **Nuke.YKT** + - Developer of **Nuked OPL3**, which was the basis for **ESFMu**'s code and also a great learning resource on Yamaha FM synthesis for myself. + - Nuke.YKT also gives shoutouts on behalf of **Nuked OPL3** to: + >- MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): + > - Feedback and Rhythm part calculation information. + >- forums.submarine.org.uk(carbon14, opl3): + > - Tremolo and phase generator calculation information. + >- OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): + > - OPL2 ROMs. + >- siliconpr0n.org(John McMaster, digshadow): + > - YMF262 and VRC VII decaps and die shots. +- **rainwarrior** + - For performing the initial research on ESFM drivers and documenting ESS's patent on native mode operator organization. +- **jwt27** + - For kickstarting the ESFM research project and compiling rainwarrior's findings and more in an accessible document ("ESFM Demystified"). +- **pachuco/CatButts** + - For documenting ESS's patent on ESFM's feedback implementation, which was vital in getting **ESFMu**'s sound output to be accurate. +- And everybody who helped out with real hardware testing + +## Usage + +To use **ESFMu**: + +- include the **esfm.h** header file into your source code +- include the **esfm.c** and **esfm_registers.c** files into your build and link process +- declare or allocate a variable of type `esfm_chip` somewhere in your code - this will hold the chip's state +- use the function interface defined in **esfm.h** to interact with the `esfm_chip` structure + +## Function interface + +If you're familiar with **Nuked OPL3**, you'll find many similarities in the function interface provided by **ESFMu**. There are a few things to point out, however: + +### Buffered writes + +Just like **Nuked OPL3**, **ESFMu** offers buffered register writes. However, it offers them in two flavors: "legacy" and fast. + +The fast buffered register writes (`ESFM_write_reg_buffered_fast`) are recommended, since they offer minimal latency which is close to the behavior you'd get with the actual ESS drivers on Windows. + +The "legacy" buffered register writes are only recommended for specific cases, such as programs seeking for a shortcut to emulate the write delays from some sound drivers. + +### Port-level access + +Unlike **Nuked OPL3**, **ESFMu** actually allows port-level access to the ESFM interface. This is relevant because the ESFM port interface is actually modal, meaning that its behavior changes depending on whether the chip is set to emulation (OPL3 compatibility) mode or native (ESFM) mode. + +Using port-level access allows for applications to not need to keep track of whether the chip is in native mode or not, nor to perform the port handling logic on their side. + +Applications that use the register-level access, on the other hand, need to take care to either stick to only one of the operating modes (either native or emulation), or handle the port mapping logic on their own side. + +### Register readback + +ESFM allows for register contents to be read back through its ports, and **ESFMu** implements this functionality, both via dedicated register read functions and via the port read interface. + +Note that in ESFM, register contents can only be read back when the chip is set to native (ESFM) mode, not when the chip is in emulation mode (i.e. OPL3 compatibility mode). + +## Licensing + +**ESFMu** is highly based on **Nuked OPL3**, which is licensed under the GNU Lesser General Public License version 2.1 or later. Therefore, **ESFMu** is licensed under the same license. + +If you'd like to obtain a grant to use **ESFMu** under different terms, you should get in contact with [Nuke.YKT](https://github.com/nukeykt) (author of **Nuked OPL3**) as well as with [Kagamiin~](https://github.com/Kagamiin) (yours truly). diff --git a/extern/ESFMu/esfm.c b/extern/ESFMu/esfm.c new file mode 100644 index 000000000..f1979f8e6 --- /dev/null +++ b/extern/ESFMu/esfm.c @@ -0,0 +1,1164 @@ +/* + * ESFMu: emulator for the ESS "ESFM" enhanced OPL3 clone + * Copyright (C) 2023 Kagamiin~ + * + * This file includes code and data from the Nuked OPL3 project, copyright (C) + * 2013-2023 Nuke.YKT. Its usage, modification and redistribution is allowed + * under the terms of the GNU Lesser General Public License version 2.1 or + * later. + * + * ESFMu is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 + * of the License, or (at your option) any later version. + * + * ESFMu is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ESFMu. If not, see . + */ + +/* + * ESFMu wouldn't have been possible without the hard work and dedication of + * the retro computer hardware research and preservation community. + * + * I'd like to thank: + * - Nuke.YKT + * Developer of Nuked OPL3, which was the basis for ESFMu's code and + * also a great learning resource on Yamaha FM synthesis for myself. + * Nuke.YKT also gives shoutouts on behalf of Nuked OPL3 to: + * - MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): + * Feedback and Rhythm part calculation information. + * - forums.submarine.org.uk(carbon14, opl3): + * Tremolo and phase generator calculation information. + * - OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): + * OPL2 ROMs. + * - siliconpr0n.org(John McMaster, digshadow): + * YMF262 and VRC VII decaps and die shots. + * - rainwarrior + * For performing the initial research on ESFM drivers and documenting + * ESS's patent on native mode operator organization. + * - jwt27 + * For kickstarting the ESFM research project and compiling rainwarrior's + * findings and more in an accessible document ("ESFM Demystified"). + * - pachuco/CatButts + * For documenting ESS's patent on ESFM's feedback implementation, which + * was vital in getting ESFMu's sound output to be accurate. + * - And everybody who helped out with real hardware testing + */ + +#include "esfm.h" +#include +#include +#include +#include +#include + +/* + * Log-scale quarter sine table extracted from OPL3 ROM; taken straight from + * Nuked OPL3 source code. + * TODO: Extract sine table from ESFM die scans... does ESFM even use a sine + * table? Patent documents give a hint to a possible method of generating sine + * waves using some sort of boolean logic wizardry (lol) + */ +static const uint16_t logsinrom[256] = { + 0x859, 0x6c3, 0x607, 0x58b, 0x52e, 0x4e4, 0x4a6, 0x471, + 0x443, 0x41a, 0x3f5, 0x3d3, 0x3b5, 0x398, 0x37e, 0x365, + 0x34e, 0x339, 0x324, 0x311, 0x2ff, 0x2ed, 0x2dc, 0x2cd, + 0x2bd, 0x2af, 0x2a0, 0x293, 0x286, 0x279, 0x26d, 0x261, + 0x256, 0x24b, 0x240, 0x236, 0x22c, 0x222, 0x218, 0x20f, + 0x206, 0x1fd, 0x1f5, 0x1ec, 0x1e4, 0x1dc, 0x1d4, 0x1cd, + 0x1c5, 0x1be, 0x1b7, 0x1b0, 0x1a9, 0x1a2, 0x19b, 0x195, + 0x18f, 0x188, 0x182, 0x17c, 0x177, 0x171, 0x16b, 0x166, + 0x160, 0x15b, 0x155, 0x150, 0x14b, 0x146, 0x141, 0x13c, + 0x137, 0x133, 0x12e, 0x129, 0x125, 0x121, 0x11c, 0x118, + 0x114, 0x10f, 0x10b, 0x107, 0x103, 0x0ff, 0x0fb, 0x0f8, + 0x0f4, 0x0f0, 0x0ec, 0x0e9, 0x0e5, 0x0e2, 0x0de, 0x0db, + 0x0d7, 0x0d4, 0x0d1, 0x0cd, 0x0ca, 0x0c7, 0x0c4, 0x0c1, + 0x0be, 0x0bb, 0x0b8, 0x0b5, 0x0b2, 0x0af, 0x0ac, 0x0a9, + 0x0a7, 0x0a4, 0x0a1, 0x09f, 0x09c, 0x099, 0x097, 0x094, + 0x092, 0x08f, 0x08d, 0x08a, 0x088, 0x086, 0x083, 0x081, + 0x07f, 0x07d, 0x07a, 0x078, 0x076, 0x074, 0x072, 0x070, + 0x06e, 0x06c, 0x06a, 0x068, 0x066, 0x064, 0x062, 0x060, + 0x05e, 0x05c, 0x05b, 0x059, 0x057, 0x055, 0x053, 0x052, + 0x050, 0x04e, 0x04d, 0x04b, 0x04a, 0x048, 0x046, 0x045, + 0x043, 0x042, 0x040, 0x03f, 0x03e, 0x03c, 0x03b, 0x039, + 0x038, 0x037, 0x035, 0x034, 0x033, 0x031, 0x030, 0x02f, + 0x02e, 0x02d, 0x02b, 0x02a, 0x029, 0x028, 0x027, 0x026, + 0x025, 0x024, 0x023, 0x022, 0x021, 0x020, 0x01f, 0x01e, + 0x01d, 0x01c, 0x01b, 0x01a, 0x019, 0x018, 0x017, 0x017, + 0x016, 0x015, 0x014, 0x014, 0x013, 0x012, 0x011, 0x011, + 0x010, 0x00f, 0x00f, 0x00e, 0x00d, 0x00d, 0x00c, 0x00c, + 0x00b, 0x00a, 0x00a, 0x009, 0x009, 0x008, 0x008, 0x007, + 0x007, 0x007, 0x006, 0x006, 0x005, 0x005, 0x005, 0x004, + 0x004, 0x004, 0x003, 0x003, 0x003, 0x002, 0x002, 0x002, + 0x002, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, + 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 +}; + +/* + * Inverse exponent table extracted from OPL3 ROM; taken straight from + * Nuked OPL3 source code. + * TODO: Verify if ESFM uses an exponent table or if it possibly uses another + * method to skirt around Yamaha's patents? + */ +static const uint16_t exprom[256] = { + 0x7fa, 0x7f5, 0x7ef, 0x7ea, 0x7e4, 0x7df, 0x7da, 0x7d4, + 0x7cf, 0x7c9, 0x7c4, 0x7bf, 0x7b9, 0x7b4, 0x7ae, 0x7a9, + 0x7a4, 0x79f, 0x799, 0x794, 0x78f, 0x78a, 0x784, 0x77f, + 0x77a, 0x775, 0x770, 0x76a, 0x765, 0x760, 0x75b, 0x756, + 0x751, 0x74c, 0x747, 0x742, 0x73d, 0x738, 0x733, 0x72e, + 0x729, 0x724, 0x71f, 0x71a, 0x715, 0x710, 0x70b, 0x706, + 0x702, 0x6fd, 0x6f8, 0x6f3, 0x6ee, 0x6e9, 0x6e5, 0x6e0, + 0x6db, 0x6d6, 0x6d2, 0x6cd, 0x6c8, 0x6c4, 0x6bf, 0x6ba, + 0x6b5, 0x6b1, 0x6ac, 0x6a8, 0x6a3, 0x69e, 0x69a, 0x695, + 0x691, 0x68c, 0x688, 0x683, 0x67f, 0x67a, 0x676, 0x671, + 0x66d, 0x668, 0x664, 0x65f, 0x65b, 0x657, 0x652, 0x64e, + 0x649, 0x645, 0x641, 0x63c, 0x638, 0x634, 0x630, 0x62b, + 0x627, 0x623, 0x61e, 0x61a, 0x616, 0x612, 0x60e, 0x609, + 0x605, 0x601, 0x5fd, 0x5f9, 0x5f5, 0x5f0, 0x5ec, 0x5e8, + 0x5e4, 0x5e0, 0x5dc, 0x5d8, 0x5d4, 0x5d0, 0x5cc, 0x5c8, + 0x5c4, 0x5c0, 0x5bc, 0x5b8, 0x5b4, 0x5b0, 0x5ac, 0x5a8, + 0x5a4, 0x5a0, 0x59c, 0x599, 0x595, 0x591, 0x58d, 0x589, + 0x585, 0x581, 0x57e, 0x57a, 0x576, 0x572, 0x56f, 0x56b, + 0x567, 0x563, 0x560, 0x55c, 0x558, 0x554, 0x551, 0x54d, + 0x549, 0x546, 0x542, 0x53e, 0x53b, 0x537, 0x534, 0x530, + 0x52c, 0x529, 0x525, 0x522, 0x51e, 0x51b, 0x517, 0x514, + 0x510, 0x50c, 0x509, 0x506, 0x502, 0x4ff, 0x4fb, 0x4f8, + 0x4f4, 0x4f1, 0x4ed, 0x4ea, 0x4e7, 0x4e3, 0x4e0, 0x4dc, + 0x4d9, 0x4d6, 0x4d2, 0x4cf, 0x4cc, 0x4c8, 0x4c5, 0x4c2, + 0x4be, 0x4bb, 0x4b8, 0x4b5, 0x4b1, 0x4ae, 0x4ab, 0x4a8, + 0x4a4, 0x4a1, 0x49e, 0x49b, 0x498, 0x494, 0x491, 0x48e, + 0x48b, 0x488, 0x485, 0x482, 0x47e, 0x47b, 0x478, 0x475, + 0x472, 0x46f, 0x46c, 0x469, 0x466, 0x463, 0x460, 0x45d, + 0x45a, 0x457, 0x454, 0x451, 0x44e, 0x44b, 0x448, 0x445, + 0x442, 0x43f, 0x43c, 0x439, 0x436, 0x433, 0x430, 0x42d, + 0x42a, 0x428, 0x425, 0x422, 0x41f, 0x41c, 0x419, 0x416, + 0x414, 0x411, 0x40e, 0x40b, 0x408, 0x406, 0x403, 0x400 +}; + +/* + * Frequency multiplier table multiplied by 2; taken straight from Nuked OPL3 + * source code. + */ +static const uint8_t mt[16] = { + 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 20, 24, 24, 30, 30 +}; + +/* + * This is used during the envelope generation to apply KSL to the envelope by + * determining how much to shift right the keyscale attenuation value before + * adding it to the envelope level. + */ +static const uint8_t kslshift[4] = { + 8, 1, 2, 0 +}; + +/* + * This encodes which emulation mode channels are the secondary channel in a + * 4-op channel pair (where the entry is non-negative), and which is the + * corresponding primary channel for that secondary channel. + */ +static const int emu_4op_secondary_to_primary[18] = +{ + -1, -1, -1, 0, 1, 2, -1, -1, -1, + -1, -1, -1, 9, 10, 11, -1, -1, -1 +}; + +/* + * Envelope generator dither table, taken straight from Nuked OPL3 source code. + */ +static const uint8_t eg_incstep[4][4] = { + { 0, 0, 0, 0 }, + { 1, 0, 0, 0 }, + { 1, 0, 1, 0 }, + { 1, 1, 1, 0 } +}; + +typedef int13(*envelope_sinfunc)(uint10 phase, uint10 envelope); + +/* ------------------------------------------------------------------------- */ +static uint12 +ESFM_envelope_calc_exp(uint16 level) +{ + if (level > 0x1fff) + { + level = 0x1fff; + } + return (exprom[level & 0xff] << 1) >> (level >> 8); +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin0(uint10 phase, uint10 envelope) +{ + uint16 out = 0; + int13 neg = 0; + phase &= 0x3ff; + if (phase & 0x200) + { + neg = ~(0); + } + if (phase & 0x100) + { + out = logsinrom[(phase & 0xff) ^ 0xff]; + } + else + { + out = logsinrom[phase & 0xff]; + } + return ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg; +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin1(uint10 phase, uint10 envelope) +{ + uint16 out = 0; + phase &= 0x3ff; + if (phase & 0x200) + { + out = 0x1000; + } + else if (phase & 0x100) + { + out = logsinrom[(phase & 0xff) ^ 0xff]; + } + else + { + out = logsinrom[phase & 0xff]; + } + return ESFM_envelope_calc_exp(out + (envelope << 3)); +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin2(uint10 phase, uint10 envelope) +{ + uint16 out = 0; + phase &= 0x3ff; + if (phase & 0x100) + { + out = logsinrom[(phase & 0xff) ^ 0xff]; + } + else + { + out = logsinrom[phase & 0xff]; + } + return ESFM_envelope_calc_exp(out + (envelope << 3)); +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin3(uint10 phase, uint10 envelope) +{ + uint16 out = 0; + phase &= 0x3ff; + if (phase & 0x100) + { + out = 0x1000; + } + else + { + out = logsinrom[phase & 0xff]; + } + return ESFM_envelope_calc_exp(out + (envelope << 3)); +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin4(uint10 phase, uint10 envelope) +{ + uint16 out = 0; + int13 neg = 0; + phase &= 0x3ff; + if ((phase & 0x300) == 0x100) + { + neg = ~(0); + } + if (phase & 0x200) + { + out = 0x1000; + } + else if (phase & 0x80) + { + out = logsinrom[((phase ^ 0xff) << 1) & 0xff]; + } + else + { + out = logsinrom[(phase << 1) & 0xff]; + } + return ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg; +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin5(uint10 phase, uint10 envelope) +{ + uint16 out = 0; + phase &= 0x3ff; + if (phase & 0x200) + { + out = 0x1000; + } + else if (phase & 0x80) + { + out = logsinrom[((phase ^ 0xff) << 1) & 0xff]; + } + else + { + out = logsinrom[(phase << 1) & 0xff]; + } + return ESFM_envelope_calc_exp(out + (envelope << 3)); +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin6(uint10 phase, uint10 envelope) +{ + int13 neg = 0; + phase &= 0x3ff; + if (phase & 0x200) + { + neg = ~(0); + } + return ESFM_envelope_calc_exp(envelope << 3) ^ neg; +} + +/* ------------------------------------------------------------------------- */ +static int13 +ESFM_envelope_calc_sin7(uint10 phase, uint10 envelope) +{ + uint16 out = 0; + int13 neg = 0; + phase &= 0x3ff; + if (phase & 0x200) + { + neg = ~(0); + phase = (phase & 0x1ff) ^ 0x1ff; + } + out = phase << 3; + return ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg; +} + +/* ------------------------------------------------------------------------- */ +static const envelope_sinfunc envelope_sin[8] = +{ + ESFM_envelope_calc_sin0, + ESFM_envelope_calc_sin1, + ESFM_envelope_calc_sin2, + ESFM_envelope_calc_sin3, + ESFM_envelope_calc_sin4, + ESFM_envelope_calc_sin5, + ESFM_envelope_calc_sin6, + ESFM_envelope_calc_sin7 +}; + +/* ------------------------------------------------------------------------- */ +static void +ESFM_envelope_calc(esfm_slot *slot) +{ + uint8 nonzero; + uint8 rate; + uint5 rate_hi; + uint2 rate_lo; + uint4 reg_rate = 0; + uint4 ks; + uint8 eg_shift, shift; + bool eg_off; + uint9 eg_rout; + int16 eg_inc; + bool reset = 0; + bool key_on; + + key_on = *slot->in.key_on; + if (!slot->chip->native_mode) + { + int pair_primary_idx = emu_4op_secondary_to_primary[slot->channel->channel_idx]; + if (pair_primary_idx >= 0) + { + esfm_channel *pair_primary = &slot->channel->chip->channels[pair_primary_idx]; + if (pair_primary->emu_mode_4op_enable) + { + key_on = *pair_primary->slots[0].in.key_on; + } + } + else if ((slot->channel->channel_idx == 7 || slot->channel->channel_idx == 8) + && slot->slot_idx == 1) + { + key_on = slot->channel->key_on_2; + } + } + + slot->in.eg_output = slot->in.eg_position + (slot->t_level << 2) + + (slot->in.eg_ksl_offset >> kslshift[slot->ksl]); + if (slot->tremolo_en) + { + uint8 tremolo; + if (slot->chip->native_mode) + { + tremolo = slot->channel->chip->tremolo >> ((!slot->tremolo_deep << 1) + 2); + } + else + { + tremolo = slot->channel->chip->tremolo >> ((!slot->chip->emu_tremolo_deep << 1) + 2); + } + slot->in.eg_output += tremolo; + } + if (key_on && slot->in.eg_state == EG_RELEASE) + { + if (!slot->in.eg_delay_run && slot->chip->native_mode) + { + slot->in.eg_delay_run = 1; + slot->in.eg_delay_counter = slot->env_delay ? 0x100 : 0; + } + + if (slot->in.eg_delay_counter == 0 || !slot->chip->native_mode) + { + slot->in.eg_delay_run = 0; + reset = 1; + reg_rate = slot->attack_rate; + } + else + { + if ((slot->chip->global_timer & ((1 << slot->env_delay) - 1)) == 0) + { + slot->in.eg_delay_counter--; + } + reg_rate = slot->release_rate; + } + } + else + { + switch (slot->in.eg_state) + { + case EG_ATTACK: + reg_rate = slot->attack_rate; + break; + case EG_DECAY: + reg_rate = slot->decay_rate; + break; + case EG_SUSTAIN: + if (!slot->env_sustaining) + { + reg_rate = slot->release_rate; + } + break; + case EG_RELEASE: + reg_rate = slot->release_rate; + break; + } + } + slot->in.phase_reset = reset; + ks = slot->in.keyscale >> ((!slot->ksr) << 1); + nonzero = (reg_rate != 0); + rate = ks + (reg_rate << 2); + rate_hi = rate >> 2; + rate_lo = rate & 0x03; + if (rate_hi & 0x10) + { + rate_hi = 0x0f; + } + eg_shift = rate_hi + slot->chip->eg_clocks; + shift = 0; + if (nonzero) + { + if (rate_hi < 12) + { + if (slot->chip->eg_tick) + { + switch (eg_shift) + { + case 12: + shift = 1; + break; + case 13: + shift = (rate_lo >> 1) & 0x01; + break; + case 14: + shift = rate_lo & 0x01; + break; + default: + break; + } + } + } + else + { + shift = (rate_hi & 0x03) + + eg_incstep[rate_lo][slot->chip->global_timer & 0x03]; + if (shift & 0x04) + { + shift = 0x03; + } + if (!shift) + { + shift = slot->chip->eg_tick; + } + } + } + eg_rout = slot->in.eg_position; + eg_inc = 0; + eg_off = 0; + /* Instant attack */ + if (reset && rate_hi == 0x0f) + { + eg_rout = 0x00; + } + /* Envelope off */ + if ((slot->in.eg_position & 0x1f8) == 0x1f8) + { + eg_off = 1; + } + if (slot->in.eg_state != EG_ATTACK && !reset && eg_off) + { + eg_rout = 0x1ff; + } + switch (slot->in.eg_state) + { + case EG_ATTACK: + if (slot->in.eg_position == 0) + { + slot->in.eg_state = EG_DECAY; + } + else if (key_on && shift > 0 && rate_hi != 0x0f) + { + eg_inc = ~slot->in.eg_position >> (4 - shift); + } + break; + case EG_DECAY: + if ((slot->in.eg_position >> 4) == slot->sustain_lvl) + { + slot->in.eg_state = EG_SUSTAIN; + } + else if (!eg_off && !reset && shift > 0) + { + eg_inc = 1 << (shift - 1); + } + break; + case EG_SUSTAIN: + case EG_RELEASE: + if (!eg_off && !reset && shift > 0) + { + eg_inc = 1 << (shift - 1); + } + break; + } + slot->in.eg_position = (eg_rout + eg_inc) & 0x1ff; + /* Key off */ + if (reset) + { + slot->in.eg_state = EG_ATTACK; + } + if (!key_on) + { + slot->in.eg_state = EG_RELEASE; + slot->in.eg_delay_run = 0; + } +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_phase_generate(esfm_slot *slot) +{ + esfm_chip *chip; + uint10 f_num; + uint32 basefreq; + bool rm_xor, n_bit; + uint23 noise; + uint10 phase; + + chip = slot->chip; + f_num = slot->f_num; + if (slot->vibrato_en) + { + int8_t range; + uint8_t vibpos; + + range = (f_num >> 7) & 7; + vibpos = chip->vibrato_pos; + + if (!(vibpos & 3)) + { + range = 0; + } + else if (vibpos & 1) + { + range >>= 1; + } + range >>= !slot->vibrato_deep; + + if (vibpos & 4) + { + range = -range; + } + f_num += range; + } + basefreq = (f_num << slot->block) >> 1; + phase = (uint10)(slot->in.phase_acc >> 9); + if (slot->in.phase_reset) + { + slot->in.phase_acc = 0; + } + slot->in.phase_acc += (basefreq * mt[slot->mult]) >> 1; + slot->in.phase_acc &= (1 << 19) - 1; + slot->in.phase_out = phase; + /* Noise mode (rhythm) sounds */ + noise = chip->lfsr; + if (slot->slot_idx == 3 && slot->rhy_noise) + { + esfm_slot *prev_slot = &slot->channel->slots[2]; + + chip->rm_hh_bit2 = (phase >> 2) & 1; + chip->rm_hh_bit3 = (phase >> 3) & 1; + chip->rm_hh_bit7 = (phase >> 7) & 1; + chip->rm_hh_bit8 = (phase >> 8) & 1; + + chip->rm_tc_bit3 = (prev_slot->in.phase_out >> 3) & 1; + chip->rm_tc_bit5 = (prev_slot->in.phase_out >> 5) & 1; + + rm_xor = (chip->rm_hh_bit2 ^ chip->rm_hh_bit7) + | (chip->rm_hh_bit3 ^ chip->rm_tc_bit5) + | (chip->rm_tc_bit3 ^ chip->rm_tc_bit5); + + switch(slot->rhy_noise) + { + case 1: + // SD + slot->in.phase_out = (chip->rm_hh_bit8 << 9) + | ((chip->rm_hh_bit8 ^ (noise & 1)) << 8); + break; + case 2: + // HH + slot->in.phase_out = rm_xor << 9; + if (rm_xor ^ (noise & 1)) + { + slot->in.phase_out |= 0xd0; + } + else + { + slot->in.phase_out |= 0x34; + } + break; + case 3: + // TC + slot->in.phase_out = (rm_xor << 9) | 0x80; + break; + } + } + + n_bit = ((noise >> 14) ^ noise) & 0x01; + chip->lfsr = (noise >> 1) | (n_bit << 22); +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_phase_generate_emu(esfm_slot *slot) +{ + esfm_chip *chip; + uint3 block; + uint10 f_num; + uint32 basefreq; + bool rm_xor, n_bit; + uint23 noise; + uint10 phase; + int pair_primary_idx; + + chip = slot->chip; + block = slot->channel->slots[0].block; + f_num = slot->channel->slots[0].f_num; + + pair_primary_idx = emu_4op_secondary_to_primary[slot->channel->channel_idx]; + if (pair_primary_idx >= 0) + { + esfm_channel *pair_primary = &slot->channel->chip->channels[pair_primary_idx]; + if (pair_primary->emu_mode_4op_enable) + { + block = pair_primary->slots[0].block; + f_num = pair_primary->slots[0].f_num; + } + } + + if (slot->vibrato_en) + { + int8_t range; + uint8_t vibpos; + + range = (f_num >> 7) & 7; + vibpos = chip->vibrato_pos; + + if (!(vibpos & 3)) + { + range = 0; + } + else if (vibpos & 1) + { + range >>= 1; + } + range >>= !chip->emu_vibrato_deep; + + if (vibpos & 4) + { + range = -range; + } + f_num += range; + } + basefreq = (f_num << block) >> 1; + phase = (uint10)(slot->in.phase_acc >> 9); + if (slot->in.phase_reset) + { + slot->in.phase_acc = 0; + } + slot->in.phase_acc += (basefreq * mt[slot->mult]) >> 1; + slot->in.phase_acc &= (1 << 19) - 1; + slot->in.phase_out = phase; + + /* Noise mode (rhythm) sounds */ + noise = chip->lfsr; + // HH + if (slot->channel->channel_idx == 7 && slot->slot_idx == 0) + { + chip->rm_hh_bit2 = (phase >> 2) & 1; + chip->rm_hh_bit3 = (phase >> 3) & 1; + chip->rm_hh_bit7 = (phase >> 7) & 1; + chip->rm_hh_bit8 = (phase >> 8) & 1; + } + // TC + if (slot->channel->channel_idx == 8 && slot->slot_idx == 1) + { + chip->rm_tc_bit3 = (phase >> 3) & 1; + chip->rm_tc_bit5 = (phase >> 5) & 1; + } + if (chip->emu_rhy_mode_flags & 0x20) + { + rm_xor = (chip->rm_hh_bit2 ^ chip->rm_hh_bit7) + | (chip->rm_hh_bit3 ^ chip->rm_tc_bit5) + | (chip->rm_tc_bit3 ^ chip->rm_tc_bit5); + if (slot->channel->channel_idx == 7) + { + if (slot->slot_idx == 0) { + // HH + slot->in.phase_out = rm_xor << 9; + if (rm_xor ^ (noise & 1)) + { + slot->in.phase_out |= 0xd0; + } + else + { + slot->in.phase_out |= 0x34; + } + } + else if (slot->slot_idx == 1) + { + // SD + slot->in.phase_out = (chip->rm_hh_bit8 << 9) + | ((chip->rm_hh_bit8 ^ (noise & 1)) << 8); + } + } + else if (slot->channel->channel_idx == 8 && slot->slot_idx == 1) + { + // TC + slot->in.phase_out = (rm_xor << 9) | 0x80; + } + } + + n_bit = ((noise >> 14) ^ noise) & 0x01; + chip->lfsr = (noise >> 1) | (n_bit << 22); +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_slot_generate(esfm_slot *slot) +{ + envelope_sinfunc wavegen = envelope_sin[slot->waveform]; + int16 phase = slot->in.phase_out; + if (slot->mod_in_level) + { + phase += *slot->in.mod_input >> (7 - slot->mod_in_level); + } + slot->in.output = wavegen((uint10)(phase & 0x3ff), slot->in.eg_output); + if (slot->output_level) + { + int13 output_value = slot->in.output >> (7 - slot->output_level); + slot->channel->output[0] += output_value & slot->out_enable[0]; + slot->channel->output[1] += output_value & slot->out_enable[1]; + } +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_slot_generate_emu(esfm_slot *slot) +{ + esfm_chip *chip = slot->chip; + envelope_sinfunc wavegen = envelope_sin[ + slot->waveform & (chip->emu_newmode != 0 ? 0x07 : 0x03)]; + bool rhythm_slot_double_volume = (slot->chip->emu_rhy_mode_flags & 0x20) != 0 + && slot->channel->channel_idx >= 6 && slot->channel->channel_idx < 9; + int16 phase = slot->in.phase_out; + int14 output_value; + + phase += *slot->in.mod_input & slot->in.emu_mod_enable; + slot->in.output = wavegen((uint10)(phase & 0x3ff), slot->in.eg_output); + output_value = (slot->in.output & slot->in.emu_output_enable) << rhythm_slot_double_volume; + if (chip->emu_newmode) + { + slot->channel->output[0] += output_value & slot->channel->slots[0].out_enable[0]; + slot->channel->output[1] += output_value & slot->channel->slots[0].out_enable[1]; + } + else + { + slot->channel->output[0] += output_value; + slot->channel->output[1] += output_value; + } +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_slot_calc_feedback(esfm_slot *slot) +{ + esfm_chip *chip = slot->chip; + uint32 basefreq, phase_offset; + uint3 block; + uint10 f_num; + int13 in1 = 0, in2 = 0, wave_out; + int16 phase, phase_feedback; + uint19 regressed_phase; + int iter_counter; + envelope_sinfunc wavegen; + + if (slot->mod_in_level) + { + if (chip->native_mode) + { + wavegen = envelope_sin[slot->waveform]; + } + else + { + wavegen = envelope_sin[slot->waveform & (0x03 | (0x02 << (chip->emu_newmode != 0)))]; + } + f_num = slot->f_num; + block = slot->block; + basefreq = (f_num << block) >> 1; + phase_offset = (basefreq * mt[slot->mult]) >> 1; + + for (iter_counter = 28; iter_counter >= 0; iter_counter--) + { + regressed_phase = (uint19)((uint32)slot->in.phase_acc - iter_counter * phase_offset) & ((1 << 19) - 1); + phase = (int16)(regressed_phase >> 9); + phase_feedback = (in1 + in2) >> 2; + phase += phase_feedback >> (7 - slot->mod_in_level); + wave_out = wavegen((uint10)(phase & 0x3ff), slot->in.eg_output); + in2 = in1; + in1 = wave_out; + } + + // TODO: Figure out - is this how the ESFM chip does it, like the + // patent literally says? (it's really hacky...) + // slot->in.output = wave_out; + + // This would be the more canonical way to do it, reusing the rest of + // the synthesis pipeline to finish the calculation: + if (chip->native_mode) + { + slot->in.feedback_buf = phase_feedback; + } + else + { + slot->in.feedback_buf = phase_feedback >> (7 - slot->mod_in_level); + } + } +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_process_channel(esfm_channel *channel) +{ + int slot_idx; + channel->output[0] = channel->output[1] = 0; + for (slot_idx = 0; slot_idx < 4; slot_idx++) + { + esfm_slot *slot = &channel->slots[slot_idx]; + ESFM_envelope_calc(slot); + ESFM_phase_generate(slot); + if(slot_idx > 0) + { + ESFM_slot_generate(slot); + } + } + // ESFM feedback calculation takes a large number of clock cycles, so + // defer slot 0 generation to the end + // TODO: verify this behavior on real hardware + ESFM_slot_calc_feedback(&channel->slots[0]); + ESFM_slot_generate(&channel->slots[0]); +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_process_channel_emu(esfm_channel *channel) +{ + int slot_idx; + channel->output[0] = channel->output[1] = 0; + for (slot_idx = 0; slot_idx < 2; slot_idx++) + { + esfm_slot *slot = &channel->slots[slot_idx]; + ESFM_envelope_calc(slot); + ESFM_phase_generate_emu(slot); + if(slot_idx > 0) + { + ESFM_slot_generate_emu(slot); + } + } + // ESFM feedback calculation takes a large number of clock cycles, so + // defer slot 0 generation to the end + // TODO: verify this behavior on real hardware + if (channel->slots[0].in.mod_input == &channel->slots[0].in.feedback_buf) + { + ESFM_slot_calc_feedback(&channel->slots[0]); + } + ESFM_slot_generate_emu(&channel->slots[0]); +} + +/* ------------------------------------------------------------------------- */ +static int16_t +ESFM_clip_sample(int32 sample) +{ + // TODO: Supposedly, the real ESFM chip actually overflows rather than + // clipping. Verify that. + if (sample > 32767) + { + sample = 32767; + } + else if (sample < -32768) + { + sample = -32768; + } + return (int16_t)sample; +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_update_timers(esfm_chip *chip) +{ + // Tremolo + if ((chip->global_timer & 0x3f) == 0x3f) + { + chip->tremolo_pos = (chip->tremolo_pos + 1) % 210; + if (chip->tremolo_pos < 105) + { + chip->tremolo = chip->tremolo_pos; + } + else + { + chip->tremolo = (210 - chip->tremolo_pos); + } + } + + // Vibrato + if ((chip->global_timer & 0x3ff) == 0x3ff) + { + chip->vibrato_pos = (chip->vibrato_pos + 1) & 0x07; + } + + chip->global_timer = (chip->global_timer + 1) & 0x3ff; + + // Envelope generator dither clocks + chip->eg_clocks = 0; + if (chip->eg_timer) + { + uint8 shift = 0; + while (shift < 36 && ((chip->eg_timer >> shift) & 1) == 0) + { + shift++; + } + + if (shift <= 12) + { + chip->eg_clocks = shift + 1; + } + } + + if (chip->eg_tick || chip->eg_timer_overflow) + { + if (chip->eg_timer == (1llu << 36) - 1) + { + chip->eg_timer = 0; + chip->eg_timer_overflow = 1; + } + else + { + chip->eg_timer++; + chip->eg_timer_overflow = 0; + } + } + + chip->eg_tick ^= 1; +} + +#define KEY_ON_REGS_START (18 * 4 * 8) +/* ------------------------------------------------------------------------- */ +int +ESFM_reg_write_chan_idx(esfm_chip *chip, uint16_t reg) +{ + int which_reg = -1; + if (chip->native_mode) + { + bool is_key_on_reg = reg >= KEY_ON_REGS_START && reg < (KEY_ON_REGS_START + 20); + if (is_key_on_reg) + { + which_reg = reg - KEY_ON_REGS_START; + } + } + else + { + uint8_t reg_low = reg & 0xff; + bool high = reg & 0x100; + bool is_key_on_reg = reg_low >= 0xb0 && reg_low < 0xb9; + if (is_key_on_reg) + { + which_reg = (reg_low & 0x0f) + high * 9; + } + } + + return which_reg; +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_update_write_buffer(esfm_chip *chip) +{ + esfm_write_buf *write_buf; + bool note_off_written[20]; + bool bassdrum_written = false; + int i; + for (i = 0; i < 20; i++) + { + note_off_written[i] = false; + } + while((write_buf = &chip->write_buf[chip->write_buf_start]), + write_buf->valid && write_buf->timestamp <= chip->write_buf_timestamp) + { + int is_which_note_on_reg = + ESFM_reg_write_chan_idx(chip, write_buf->address); + if (is_which_note_on_reg >= 0) + { + if ((chip->native_mode && (write_buf->data & 0x01) == 0) + || (!chip->native_mode && (write_buf->data & 0x20) == 0) + ) + { + // this is a note off command; note down that we got note off for this channel + note_off_written[is_which_note_on_reg] = true; + } + else + { + // this is a note on command; have we gotten a note off for this channel in this cycle? + if (note_off_written[is_which_note_on_reg]) + { + // we have a conflict; let the note off be processed first and defer the + // rest of the buffer to the next cycle + break; + } + } + } + if ((chip->native_mode && write_buf->address == 0x4bd) + || (!chip->native_mode && (write_buf->address & 0xff) == 0xbd) + ) + { + // bassdrum register write (rhythm mode note-on/off control) + // have we already written to the bassdrum register in this cycle + if (bassdrum_written) { + // we have a conflict + break; + } + bassdrum_written = true; + } + + write_buf->valid = 0; + ESFM_write_reg(chip, write_buf->address, write_buf->data); + chip->write_buf_start = (chip->write_buf_start + 1) % ESFM_WRITEBUF_SIZE; + } + + chip->write_buf_timestamp++; +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_generate(esfm_chip *chip, int16_t *buf) +{ + int channel_idx; + + chip->output_accm[0] = chip->output_accm[1] = 0; + for (channel_idx = 0; channel_idx < 18; channel_idx++) + { + esfm_channel *channel = &chip->channels[channel_idx]; + if (chip->native_mode) + { + ESFM_process_channel(channel); + } + else + { + ESFM_process_channel_emu(channel); + } + + chip->output_accm[0] += channel->output[0]; + chip->output_accm[1] += channel->output[1]; + } + + buf[0] = ESFM_clip_sample(chip->output_accm[0]); + buf[1] = ESFM_clip_sample(chip->output_accm[1]); + + ESFM_update_timers(chip); + ESFM_update_write_buffer(chip); +} + +/* ------------------------------------------------------------------------- */ +int16_t +ESFM_get_channel_output_native(esfm_chip *chip, int channel_idx) +{ + int16_t result; + int32_t temp_mix = 0; + int i; + + if (channel_idx < 0 || channel_idx >= 18) + { + return 0; + } + + for (i = 0; i < 4; i++) + { + esfm_slot *slot = &chip->channels[channel_idx].slots[i]; + + if (slot->output_level) + { + int13 output_value = slot->in.output >> (7 - slot->output_level); + temp_mix += output_value & slot->out_enable[0]; + temp_mix += output_value & slot->out_enable[1]; + } + } + + if (temp_mix > 32767) + { + temp_mix = 32767; + } + else if (temp_mix < -32768) + { + temp_mix = -32768; + } + result = temp_mix; + return result; +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_generate_stream(esfm_chip *chip, int16_t *sndptr, uint32_t num_samples) +{ + uint32_t i; + + for (i = 0; i < num_samples; i++) + { + ESFM_generate(chip, sndptr); + sndptr += 2; + } +} diff --git a/extern/ESFMu/esfm.h b/extern/ESFMu/esfm.h new file mode 100644 index 000000000..a37300ca0 --- /dev/null +++ b/extern/ESFMu/esfm.h @@ -0,0 +1,305 @@ +/* + * ESFMu: emulator for the ESS "ESFM" enhanced OPL3 clone + * Copyright (C) 2023 Kagamiin~ + * + * ESFMu is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 + * of the License, or (at your option) any later version. + * + * ESFMu is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ESFMu. If not, see . + */ + +/* + * ESFMu wouldn't have been possible without the hard work and dedication of + * the retro computer hardware research and preservation community. + * + * I'd like to thank: + * - Nuke.YKT + * Developer of Nuked OPL3, which was the basis for ESFMu's code and + * also a great learning resource on Yamaha FM synthesis for myself. + * Nuke.YKT also gives shoutouts on behalf of Nuked OPL3 to: + * - MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): + * Feedback and Rhythm part calculation information. + * - forums.submarine.org.uk(carbon14, opl3): + * Tremolo and phase generator calculation information. + * - OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): + * OPL2 ROMs. + * - siliconpr0n.org(John McMaster, digshadow): + * YMF262 and VRC VII decaps and die shots. + * - rainwarrior + * For performing the initial research on ESFM drivers and documenting + * ESS's patent on native mode operator organization. + * - jwt27 + * For kickstarting the ESFM research project and compiling rainwarrior's + * findings and more in an accessible document ("ESFM Demystified"). + * - pachuco/CatButts + * For documenting ESS's patent on ESFM's feedback implementation, which + * was vital in getting ESFMu's sound output to be accurate. + * - And everybody who helped out with real hardware testing + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _esfm_slot esfm_slot; +typedef struct _esfm_slot_internal esfm_slot_internal; +typedef struct _esfm_channel esfm_channel; +typedef struct _esfm_chip esfm_chip; + + +void ESFM_init (esfm_chip *chip); +void ESFM_write_reg (esfm_chip *chip, uint16_t address, uint8_t data); +void ESFM_write_reg_buffered (esfm_chip *chip, uint16_t address, uint8_t data); +void ESFM_write_reg_buffered_fast (esfm_chip *chip, uint16_t address, uint8_t data); +void ESFM_write_port (esfm_chip *chip, uint8_t offset, uint8_t data); +uint8_t ESFM_readback_reg (esfm_chip *chip, uint16_t address); +uint8_t ESFM_read_port (esfm_chip *chip, uint8_t offset); +void ESFM_generate(esfm_chip *chip, int16_t *buf); +void ESFM_generate_stream(esfm_chip *chip, int16_t *sndptr, uint32_t num_samples); +// Modification by Kagamiin~: +int16_t ESFM_get_channel_output_native(esfm_chip *chip, int channel_idx); + + +// These are fake types just for syntax sugar. +// Beware of their underlying types when reading/writing to them. +#ifndef __NO_ESFM_FAST_TYPES +#ifndef __ESFM_FAST_TYPES +#define __ESFM_FAST_TYPES +#endif +#endif + +#ifdef __ESFM_FAST_TYPES + +typedef uint_fast8_t flag; +typedef uint_fast8_t uint2; +typedef uint_fast8_t uint3; +typedef uint_fast8_t uint4; +typedef uint_fast8_t uint5; +typedef uint_fast8_t uint6; +typedef uint_fast8_t uint8; +typedef uint_fast16_t uint9; +typedef uint_fast16_t uint10; +typedef uint_fast16_t uint11; +typedef uint_fast16_t uint12; +typedef uint_fast16_t uint16; +typedef uint_fast32_t uint19; +typedef uint_fast32_t uint23; +typedef uint_fast32_t uint32; +typedef uint_fast64_t uint36; + +typedef int_fast16_t int13; +typedef int_fast16_t int14; +typedef int_fast16_t int16; +typedef int_fast32_t int32; + +#else +typedef uint8_t flag; +typedef uint8_t uint2; +typedef uint8_t uint3; +typedef uint8_t uint4; +typedef uint8_t uint5; +typedef uint8_t uint6; +typedef uint8_t uint8; +typedef uint16_t uint9; +typedef uint16_t uint10; +typedef uint16_t uint11; +typedef uint16_t uint12; +typedef uint16_t uint16; +typedef uint32_t uint19; +typedef uint32_t uint23; +typedef uint32_t uint32; +typedef uint64_t uint36; + +typedef int16_t int13; +typedef int16_t int14; +typedef int16_t int16; +typedef int32_t int32; + +#endif + +enum eg_states +{ + EG_ATTACK, + EG_DECAY, + EG_SUSTAIN, + EG_RELEASE +}; + + +typedef struct _esfm_write_buf +{ + uint64_t timestamp; + uint16_t address; + uint8_t data; + flag valid; + +} esfm_write_buf; + +typedef struct _emu_slot_channel_mapping +{ + int channel_idx; + int slot_idx; + +} emu_slot_channel_mapping; + +typedef struct _esfm_slot_internal +{ + uint9 eg_position; + uint9 eg_ksl_offset; + uint10 eg_output; + + uint4 keyscale; + + int13 output; + int13 emu_output_enable; + int13 emu_mod_enable; + int13 feedback_buf; + int13 *mod_input; + + uint19 phase_acc; + uint10 phase_out; + flag phase_reset; + flag *key_on; + + uint2 eg_state; + flag eg_delay_run; + uint9 eg_delay_counter; + +} esfm_slot_internal; + +struct _esfm_slot +{ + // Metadata + esfm_channel *channel; + esfm_chip *chip; + uint2 slot_idx; + + // Register data + int13 out_enable[2]; + uint10 f_num; + uint3 block; + uint3 output_level; + // a.k.a. feedback level in emu mode + uint3 mod_in_level; + + uint6 t_level; + uint4 mult; + uint3 waveform; + // Only for 4th slot + uint2 rhy_noise; + + uint4 attack_rate; + uint4 decay_rate; + uint4 sustain_lvl; + uint4 release_rate; + + flag tremolo_en; + flag tremolo_deep; + flag vibrato_en; + flag vibrato_deep; + flag emu_connection_typ; + flag env_sustaining; + flag ksr; + uint2 ksl; + uint3 env_delay; + // overlaps with env_delay bit 0 + // TODO: check if emu mode only uses this, or if it actually overwrites the channel field used by native mode + flag emu_key_on; + + // Internal state + esfm_slot_internal in; +}; + +struct _esfm_channel +{ + esfm_chip *chip; + esfm_slot slots[4]; + uint5 channel_idx; + int16 output[2]; + flag key_on; + flag emu_mode_4op_enable; + // Only for 17th and 18th channels + flag key_on_2; + flag emu_mode_4op_enable_2; +}; + +#define ESFM_WRITEBUF_SIZE 1024 +#define ESFM_WRITEBUF_DELAY 2 + +struct _esfm_chip +{ + esfm_channel channels[18]; + int32 output_accm[2]; + uint_fast16_t addr_latch; + + flag emu_wavesel_enable; + flag emu_newmode; + flag native_mode; + + flag keyscale_mode; + + // Global state + uint36 eg_timer; + uint10 global_timer; + uint8 eg_clocks; + flag eg_tick; + flag eg_timer_overflow; + uint8 tremolo; + uint8 tremolo_pos; + uint8 vibrato_pos; + uint23 lfsr; + + flag rm_hh_bit2; + flag rm_hh_bit3; + flag rm_hh_bit7; + flag rm_hh_bit8; + flag rm_tc_bit3; + flag rm_tc_bit5; + + // 0xbd register in emulation mode, exposed in 0x4bd in native mode + // ("bass drum" register) + uint8 emu_rhy_mode_flags; + + flag emu_vibrato_deep; + flag emu_tremolo_deep; + + uint8 timer_reload[2]; + uint8 timer_counter[2]; + flag timer_enable[2]; + flag timer_mask[2]; + flag timer_overflow[2]; + flag irq_bit; + + // Halts the envelope generators from advancing. + flag test_bit_eg_halt; + /* + * Activates some sort of waveform test mode that amplifies the output volume greatly + * and continuously shifts the waveform table downwards, possibly also outputting the + * waveform's derivative? (it's so weird!) + */ + flag test_bit_distort; + // Appears to attenuate the output by about 3 dB. + flag test_bit_attenuate; + // Resets all phase generators and holds them in the reset state while this bit is set. + flag test_bit_phase_stop_reset; + + esfm_write_buf write_buf[ESFM_WRITEBUF_SIZE]; + size_t write_buf_start; + size_t write_buf_end; + uint64_t write_buf_timestamp; +}; + +#ifdef __cplusplus +} +#endif diff --git a/extern/ESFMu/esfm_registers.c b/extern/ESFMu/esfm_registers.c new file mode 100644 index 000000000..789c68ea7 --- /dev/null +++ b/extern/ESFMu/esfm_registers.c @@ -0,0 +1,995 @@ +/* + * ESFMu: emulator for the ESS "ESFM" enhanced OPL3 clone + * Copyright (C) 2023 Kagamiin~ + * + * This file includes code and data from the Nuked OPL3 project, copyright (C) + * 2013-2023 Nuke.YKT. Its usage, modification and redistribution is allowed + * under the terms of the GNU Lesser General Public License version 2.1 or + * later. + * + * ESFMu is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 + * of the License, or (at your option) any later version. + * + * ESFMu is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with ESFMu. If not, see . + */ + +/* + * ESFMu wouldn't have been possible without the hard work and dedication of + * the retro computer hardware research and preservation community. + * + * I'd like to thank: + * - Nuke.YKT + * Developer of Nuked OPL3, which was the basis for ESFMu's code and + * also a great learning resource on Yamaha FM synthesis for myself. + * Nuke.YKT also gives shoutouts on behalf of Nuked OPL3 to: + * - MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): + * Feedback and Rhythm part calculation information. + * - forums.submarine.org.uk(carbon14, opl3): + * Tremolo and phase generator calculation information. + * - OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): + * OPL2 ROMs. + * - siliconpr0n.org(John McMaster, digshadow): + * YMF262 and VRC VII decaps and die shots. + * - rainwarrior + * For performing the initial research on ESFM drivers and documenting + * ESS's patent on native mode operator organization. + * - jwt27 + * For kickstarting the ESFM research project and compiling rainwarrior's + * findings and more in an accessible document ("ESFM Demystified"). + * - pachuco/CatButts + * For documenting ESS's patent on ESFM's feedback implementation, which + * was vital in getting ESFMu's sound output to be accurate. + * - And everybody who helped out with real hardware testing + */ + +#include "esfm.h" +#include +#include +#include +#include + + +/* + * Table of KSL values extracted from OPL3 ROM; taken straight from Nuked OPL3 + * source code. + * TODO: Check if ESFM uses the same KSL values. + */ + +static const int16 kslrom[16] = { + 0, 32, 40, 45, 48, 51, 53, 55, 56, 58, 59, 60, 61, 62, 63, 64 +}; + +/* + * This maps the low 5 bits of emulation mode address to an emulation mode + * slot; taken straight from Nuked OPL3. Used for decoding certain emulation + * mode address ranges. + */ +static const int8_t ad_slot[0x20] = { + 0, 1, 2, 3, 4, 5, -1, -1, 6, 7, 8, 9, 10, 11, -1, -1, + 12, 13, 14, 15, 16, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 +}; + +/* + * This maps an emulation mode slot index to a tuple representing the + * corresponding native mode channel and slot. + */ +static const emu_slot_channel_mapping emu_slot_map[36] = +{ + { 0, 0}, { 1, 0}, { 2, 0}, { 0, 1}, { 1, 1}, { 2, 1}, + { 3, 0}, { 4, 0}, { 5, 0}, { 3, 1}, { 4, 1}, { 5, 1}, + { 6, 0}, { 7, 0}, { 8, 0}, { 6, 1}, { 7, 1}, { 8, 1}, + { 9, 0}, {10, 0}, {11, 0}, { 9, 1}, {10, 1}, {11, 1}, + {12, 0}, {13, 0}, {14, 0}, {12, 1}, {13, 1}, {14, 1}, + {15, 0}, {16, 0}, {17, 0}, {15, 1}, {16, 1}, {17, 1} +}; + +/* + * This encodes which emulation mode channels are the secondary channel in a + * 4-op channel pair (where the entry is non-negative), and which is the + * corresponding primary channel for that secondary channel. + */ +static const int emu_4op_secondary_to_primary[18] = +{ + -1, -1, -1, 0, 1, 2, -1, -1, -1, + -1, -1, -1, 9, 10, 11, -1, -1, -1 +}; + +/* + * This encodes the operator outputs to be enabled or disabled for + * each 4-op algorithm in emulation mode. + * Indices: FM+FM, FM+AM, AM+FM, AM+AM (lower channel MSB, upper channel LSB) + * Values: enable OP1, OP2, OP3, OP4 + */ +static const bool emu_4op_alg_output_enable[4][4] = +{ + {0, 0, 0, 1}, + {0, 1, 0, 1}, + {1, 0, 0, 1}, + {1, 0, 1, 1} +}; + +/* + * This encodes the operator interconnections to be enabled or disabled for + * each 4-op algorithm in emulation mode. + * Indices: FM+FM, FM+AM, AM+FM, AM+AM (lower channel MSB, upper channel LSB) + * Values: enable OP1FB, OP1->2, OP2->3, OP3->4 + */ +static const bool emu_4op_alg_mod_enable[4][4] = +{ + {1, 1, 1, 1}, + {1, 1, 0, 1}, + {1, 0, 1, 1}, + {1, 0, 1, 0} +}; + + +/* ------------------------------------------------------------------------- */ +static void +ESFM_emu_rearrange_connections(esfm_channel *channel) +{ + int secondary_to_primary; + + secondary_to_primary = emu_4op_secondary_to_primary[channel->channel_idx]; + if (secondary_to_primary >= 0) + { + esfm_channel *pair_primary = &channel->chip->channels[secondary_to_primary]; + if (pair_primary->emu_mode_4op_enable) + { + // always work from primary channel in pair when dealing with 4-op + channel = pair_primary; + } + } + + if (channel->emu_mode_4op_enable && (channel->channel_idx % 9) < 3 && channel->chip->emu_newmode) + { + esfm_channel *secondary = &channel->chip->channels[channel->channel_idx + 3]; + uint2 algorithm = ((channel->slots[0].emu_connection_typ != 0) << 1) + | (secondary->slots[0].emu_connection_typ != 0); + int i; + + secondary->slots[0].in.mod_input = &channel->slots[1].in.output; + + for (i = 0; i < 2; i++) + { + channel->slots[i].in.emu_mod_enable = + emu_4op_alg_mod_enable[algorithm][i] ? ~((int13) 0) : 0; + channel->slots[i].in.emu_output_enable = + emu_4op_alg_output_enable[algorithm][i] ? ~((int13) 0) : 0; + + secondary->slots[i].in.emu_mod_enable = + emu_4op_alg_mod_enable[algorithm][i + 2] ? ~((int13) 0) : 0; + secondary->slots[i].in.emu_output_enable = + emu_4op_alg_output_enable[algorithm][i + 2] ? ~((int13) 0) : 0; + } + } + else if ((channel->chip->emu_rhy_mode_flags & 0x20) != 0 + && (channel->channel_idx == 7 || channel->channel_idx == 8)) + { + channel->slots[0].in.emu_mod_enable = 0; + channel->slots[1].in.emu_mod_enable = 0; + channel->slots[0].in.emu_output_enable = ~((int13) 0); + channel->slots[1].in.emu_output_enable = ~((int13) 0); + } + else + { + channel->slots[0].in.mod_input = &channel->slots[0].in.feedback_buf; + + channel->slots[0].in.emu_mod_enable = ~((int13) 0); + channel->slots[0].in.emu_output_enable = + (channel->slots[0].emu_connection_typ != 0) ? ~((int13) 0) : 0; + channel->slots[1].in.emu_output_enable = ~((int13) 0); + channel->slots[1].in.emu_mod_enable = + (channel->slots[0].emu_connection_typ != 0) ? 0 : ~((int13) 0); + } +} + + +/* ------------------------------------------------------------------------- */ +static void +ESFM_emu_to_native_switch(esfm_chip *chip) +{ + size_t channel_idx, slot_idx; + for (channel_idx = 0; channel_idx < 18; channel_idx++) + { + for (slot_idx = 0; slot_idx < 4; slot_idx++) + { + esfm_channel *channel = &chip->channels[channel_idx]; + esfm_slot *slot = &channel->slots[slot_idx]; + + if (slot_idx == 0) + { + slot->in.mod_input = &slot->in.feedback_buf; + } + else + { + esfm_slot *prev_slot = &channel->slots[slot_idx - 1]; + slot->in.mod_input = &prev_slot->in.output; + } + } + } +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_native_to_emu_switch(esfm_chip *chip) +{ + size_t channel_idx; + for (channel_idx = 0; channel_idx < 18; channel_idx++) + { + ESFM_emu_rearrange_connections(&chip->channels[channel_idx]); + } +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_slot_update_keyscale(esfm_slot *slot) +{ + if (slot->slot_idx > 0 && !slot->chip->native_mode) + { + return; + } + + int16 ksl = (kslrom[slot->f_num >> 6] << 2) - ((0x08 - slot->block) << 5); + if (ksl < 0) + { + ksl = 0; + } + slot->in.eg_ksl_offset = ksl; + slot->in.keyscale = (slot->block << 1) + | ((slot->f_num >> (8 + !slot->chip->keyscale_mode)) & 0x01); +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_emu_channel_update_keyscale(esfm_channel *channel) +{ + int secondary_to_primary; + + secondary_to_primary = emu_4op_secondary_to_primary[channel->channel_idx]; + if (secondary_to_primary >= 0) + { + esfm_channel *pair_primary = &channel->chip->channels[secondary_to_primary]; + if (pair_primary->emu_mode_4op_enable) + { + // always work from primary channel in pair when dealing with 4-op + channel = pair_primary; + } + } + + ESFM_slot_update_keyscale(&channel->slots[0]); + channel->slots[1].in.eg_ksl_offset = channel->slots[0].in.eg_ksl_offset; + channel->slots[1].in.keyscale = channel->slots[0].in.keyscale; + + if (channel->emu_mode_4op_enable && (channel->channel_idx % 9) < 3 && channel->chip->emu_newmode) + { + int i; + esfm_channel *secondary = &channel->chip->channels[channel->channel_idx + 3]; + secondary->slots[0].f_num = channel->slots[0].f_num; + secondary->slots[0].block = channel->slots[0].block; + + for (i = 0; i < 2; i++) + { + secondary->slots[i].in.eg_ksl_offset = channel->slots[0].in.eg_ksl_offset; + secondary->slots[i].in.keyscale = channel->slots[0].in.keyscale; + } + } +} + +/* ------------------------------------------------------------------------- */ +static inline uint8_t +ESFM_slot_readback (esfm_slot *slot, uint8_t register_idx) +{ + uint8_t data = 0; + switch (register_idx & 0x07) + { + case 0x00: + data |= (slot->tremolo_en != 0) << 7; + data |= (slot->vibrato_en != 0) << 6; + data |= (slot->env_sustaining != 0) << 5; + data |= (slot->vibrato_en != 0) << 4; + data |= slot->mult & 0x0f; + break; + case 0x01: + data |= slot->ksl << 6; + data |= slot->t_level & 0x3f; + break; + case 0x02: + data |= slot->attack_rate << 4; + data |= slot->decay_rate & 0x0f; + break; + case 0x03: + data |= slot->sustain_lvl << 4; + data |= slot->release_rate & 0x0f; + break; + case 0x04: + data = slot->f_num & 0xff; + break; + case 0x05: + data |= slot->env_delay << 5; + data |= (slot->block & 0x07) << 2; + data |= (slot->f_num >> 8) & 0x03; + break; + case 0x06: + data |= (slot->tremolo_deep != 0) << 7; + data |= (slot->vibrato_deep != 0) << 6; + data |= (slot->out_enable[1] != 0) << 5; + data |= (slot->out_enable[0] != 0) << 4; + data |= (slot->mod_in_level & 0x07) << 1; + data |= slot->emu_connection_typ & 0x01; + break; + case 0x07: + data |= slot->output_level << 5; + data |= (slot->rhy_noise & 0x03) << 3; + data |= slot->waveform & 0x07; + break; + } + return data; +} + +/* ------------------------------------------------------------------------- */ +static inline void +ESFM_slot_write (esfm_slot *slot, uint8_t register_idx, uint8_t data) +{ + switch (register_idx & 0x07) + { + case 0x00: + slot->tremolo_en = (data & 0x80) != 0; + slot->vibrato_en = (data & 0x40) != 0; + slot->env_sustaining = (data & 0x20) != 0; + slot->ksr = (data & 0x10) != 0; + slot->mult = data & 0x0f; + break; + case 0x01: + slot->ksl = data >> 6; + slot->t_level = data & 0x3f; + ESFM_slot_update_keyscale(slot); + break; + case 0x02: + slot->attack_rate = data >> 4; + slot->decay_rate = data & 0x0f; + break; + case 0x03: + slot->sustain_lvl = data >> 4; + slot->release_rate = data & 0x0f; + break; + case 0x04: + slot->f_num = (slot->f_num & 0x300) | data; + ESFM_slot_update_keyscale(slot); + break; + case 0x05: + slot->env_delay = data >> 5; + slot->emu_key_on = (data >> 5) & 0x01; + slot->block = (data >> 2) & 0x07; + slot->f_num = (slot->f_num & 0xff) | ((data & 0x03) << 8); + ESFM_slot_update_keyscale(slot); + break; + case 0x06: + slot->tremolo_deep = (data & 0x80) != 0; + slot->vibrato_deep = (data & 0x40) != 0; + slot->out_enable[1] = (data & 0x20) ? ~((int13) 0) : 0; + slot->out_enable[0] = (data & 0x10) ? ~((int13) 0) : 0; + slot->mod_in_level = (data >> 1) & 0x07; + slot->emu_connection_typ = data & 0x01; + break; + case 0x07: + slot->output_level = data >> 5; + slot->rhy_noise = (data >> 3) & 0x03; + slot->waveform = data & 0x07; + break; + } +} + +#define KEY_ON_REGS_START (18 * 4 * 8) +#define TIMER1_REG (0x402) +#define TIMER2_REG (0x403) +#define TIMER_SETUP_REG (0x404) +#define CONFIG_REG (0x408) +#define BASSDRUM_REG (0x4bd) +#define TEST_REG (0x501) +#define FOUROP_CONN_REG (0x504) +#define NATIVE_MODE_REG (0x505) + +/* ------------------------------------------------------------------------- */ +static void +ESFM_write_reg_native (esfm_chip *chip, uint16_t address, uint8_t data) +{ + int i; + address = address & 0x7ff; + + if (address < KEY_ON_REGS_START) + { + // Slot register write + size_t channel_idx = address >> 5; + size_t slot_idx = (address >> 3) & 0x03; + size_t register_idx = address & 0x07; + esfm_slot *slot = &chip->channels[channel_idx].slots[slot_idx]; + + ESFM_slot_write(slot, register_idx, data); + } + else if (address < KEY_ON_REGS_START + 16) + { + // Key-on registers + size_t channel_idx = (address - KEY_ON_REGS_START); + esfm_channel *channel = &chip->channels[channel_idx]; + channel->key_on = data & 0x01; + channel->emu_mode_4op_enable = (data & 0x02) != 0; + } + else if (address < KEY_ON_REGS_START + 20) + { + // Key-on channels 17 and 18 (each half) + size_t channel_idx = 16 + ((address & 0x02) >> 1); + bool second_half = address & 0x01; + esfm_channel *channel = &chip->channels[channel_idx]; + if (second_half) + { + channel->key_on_2 = data & 0x01; + channel->emu_mode_4op_enable_2 = (data & 0x02) != 0; + } + else + { + channel->key_on = data & 0x01; + channel->emu_mode_4op_enable = (data & 0x02) != 0; + } + } + else + { + switch (address & 0x5ff) + { + case TIMER1_REG: + chip->timer_reload[0] = data; + break; + case TIMER2_REG: + chip->timer_reload[1] = data; + break; + case TIMER_SETUP_REG: + if (data & 0x80) + { + chip->timer_overflow[0] = 0; + chip->timer_overflow[1] = 0; + chip->irq_bit = 0; + } + chip->timer_enable[0] = (data & 0x01) != 0; + chip->timer_enable[1] = (data & 0x02) != 0; + chip->timer_mask[0] = (data & 0x20) != 0; + chip->timer_mask[1] = (data & 0x40) != 0; + break; + case CONFIG_REG: + chip->keyscale_mode = (data & 0x40) != 0; + break; + case BASSDRUM_REG: + chip->emu_rhy_mode_flags = data & 0x3f; + chip->emu_vibrato_deep = (data & 0x40) != 0; + chip->emu_tremolo_deep = (data & 0x80) != 0; + break; + case FOUROP_CONN_REG: + for (i = 0; i < 3; i++) + { + chip->channels[i].emu_mode_4op_enable = (data >> i) & 0x01; + chip->channels[i + 9].emu_mode_4op_enable = (data >> (i + 3)) & 0x01; + } + break; + case TEST_REG: + chip->test_bit_eg_halt = (data & 0x01) | ((data & 0x20) != 0); + chip->test_bit_distort = (data & 0x02) != 0; + chip->test_bit_attenuate = (data & 0x10) != 0; + chip->test_bit_phase_stop_reset = (data & 0x40) != 0; + break; + } + } +} + +/* ------------------------------------------------------------------------- */ +static uint8_t +ESFM_readback_reg_native (esfm_chip *chip, uint16_t address) +{ + int i; + uint8_t data = 0; + address = address & 0x7ff; + + if (address < KEY_ON_REGS_START) + { + // Slot register read + size_t channel_idx = address >> 5; + size_t slot_idx = (address >> 3) & 0x03; + size_t register_idx = address & 0x07; + esfm_slot *slot = &chip->channels[channel_idx].slots[slot_idx]; + + data = ESFM_slot_readback(slot, register_idx); + } + else if (address < KEY_ON_REGS_START + 16) + { + // Key-on registers + size_t channel_idx = (address - KEY_ON_REGS_START); + esfm_channel *channel = &chip->channels[channel_idx]; + + data |= channel->key_on != 0; + data |= (channel->emu_mode_4op_enable != 0) << 1; + } + else if (address < KEY_ON_REGS_START + 20) + { + // Key-on channels 17 and 18 (each half) + size_t channel_idx = 16 + ((address & 0x02) >> 1); + bool second_half = address & 0x01; + esfm_channel *channel = &chip->channels[channel_idx]; + if (second_half) + { + data |= channel->key_on_2 != 0; + data |= (channel->emu_mode_4op_enable_2 != 0) << 1; + } + else + { + data |= channel->key_on != 0; + data |= (channel->emu_mode_4op_enable != 0) << 1; + } + } + else + { + switch (address & 0x5ff) + { + case TIMER1_REG: + data = chip->timer_reload[0]; + break; + case TIMER2_REG: + data = chip->timer_reload[1]; + break; + case TIMER_SETUP_REG: + data |= chip->timer_enable[0] != 0; + data |= (chip->timer_enable[1] != 0) << 1; + data |= (chip->timer_mask[0] != 0) << 5; + data |= (chip->timer_mask[1] != 0) << 6; + break; + case CONFIG_REG: + data |= (chip->keyscale_mode != 0) << 6; + break; + case BASSDRUM_REG: + data |= chip->emu_rhy_mode_flags; + data |= chip->emu_vibrato_deep << 6; + data |= chip->emu_tremolo_deep << 7; + break; + case TEST_REG: + data |= chip->test_bit_eg_halt != 0; + data |= (chip->test_bit_distort != 0) << 1; + data |= (chip->test_bit_attenuate != 0) << 4; + data |= (chip->test_bit_eg_halt != 0) << 5; + data |= (chip->test_bit_phase_stop_reset != 0) << 6; + break; + case FOUROP_CONN_REG: + for (i = 0; i < 3; i++) + { + data |= (chip->channels[i].emu_mode_4op_enable != 0) << i; + data |= (chip->channels[i + 9].emu_mode_4op_enable != 0) << (i + 3); + } + break; + case NATIVE_MODE_REG: + data |= (chip->native_mode != 0) << 7; + break; + } + } + return data; +} + +/* ------------------------------------------------------------------------- */ +static void +ESFM_write_reg_emu (esfm_chip *chip, uint16_t address, uint8_t data) +{ + bool high = (address & 0x100) != 0; + uint8_t reg = address & 0xff; + int emu_slot_idx = ad_slot[address & 0x1f]; + int natv_chan_idx = -1; + int natv_slot_idx = -1; + int emu_chan_idx = (reg & 0x0f) > 8 ? -1 : ((reg & 0x0f) + high * 9); + + if (emu_slot_idx >= 0) + { + if (high) + { + emu_slot_idx += 18; + } + + natv_chan_idx = emu_slot_map[emu_slot_idx].channel_idx; + natv_slot_idx = emu_slot_map[emu_slot_idx].slot_idx; + } + + if (reg == 0xbd) + { + chip->emu_rhy_mode_flags = data & 0x3f; + chip->emu_vibrato_deep = (data & 0x40) != 0; + chip->emu_tremolo_deep = (data & 0x80) != 0; + if (chip->emu_rhy_mode_flags & 0x20) + { + // TODO: check if writes to 0xbd actually affect the readable key-on flags at + // 0x246, 0x247, 0x248; and if there's any visible effect from the SD and TC flags + chip->channels[6].key_on = (data & 0x10) != 0; + chip->channels[7].key_on = (data & 0x01) != 0; + chip->channels[8].key_on = (data & 0x04) != 0; + chip->channels[7].key_on_2 = (data & 0x08) != 0; + chip->channels[8].key_on_2 = (data & 0x02) != 0; + } + ESFM_emu_rearrange_connections(&chip->channels[7]); + ESFM_emu_rearrange_connections(&chip->channels[8]); + return; + } + + switch(reg & 0xf0) + { + case 0x00: + if (high) + { + int i; + switch(reg & 0x0f) + { + case 0x01: + chip->emu_wavesel_enable = (data & 0x20) != 0; + break; + case 0x02: + chip->timer_reload[0] = data; + break; + case 0x03: + chip->timer_reload[1] = data; + break; + case 0x04: + for (i = 0; i < 3; i++) + { + chip->channels[i].emu_mode_4op_enable = (data >> i) & 0x01; + chip->channels[i + 9].emu_mode_4op_enable = (data >> (i + 3)) & 0x01; + } + for (i = 0; i < 6; i++) + { + ESFM_emu_rearrange_connections(&chip->channels[i]); + ESFM_emu_rearrange_connections(&chip->channels[i + 9]); + } + break; + case 0x05: + chip->emu_newmode = data & 0x01; + if ((data & 0x80) != 0) + { + chip->native_mode = 1; + ESFM_emu_to_native_switch(chip); + } + break; + case 0x08: + chip->keyscale_mode = (data & 0x40) != 0; + break; + } + } + else + { + switch(reg & 0x0f) + { + case 0x01: + chip->emu_wavesel_enable = (data & 0x20) != 0; + break; + case 0x02: + chip->timer_reload[0] = data; + break; + case 0x03: + chip->timer_reload[1] = data; + break; + case 0x04: + chip->timer_enable[0] = data & 0x01; + chip->timer_enable[1] = (data & 0x02) != 0; + chip->timer_mask[0] = (data & 0x20) != 0; + chip->timer_mask[1] = (data & 0x40) != 0; + if (data & 0x80) + { + chip->irq_bit = 0; + } + break; + case 0x08: + chip->keyscale_mode = (data & 0x40) != 0; + break; + } + } + break; + case 0x20: case 0x30: + if (emu_slot_idx >= 0) + { + ESFM_slot_write(&chip->channels[natv_chan_idx].slots[natv_slot_idx], 0x0, data); + } + break; + case 0x40: case 0x50: + if (emu_slot_idx >= 0) + { + ESFM_slot_write(&chip->channels[natv_chan_idx].slots[natv_slot_idx], 0x1, data); + ESFM_emu_channel_update_keyscale(&chip->channels[natv_chan_idx]); + } + break; + case 0x60: case 0x70: + if (emu_slot_idx >= 0) + { + ESFM_slot_write(&chip->channels[natv_chan_idx].slots[natv_slot_idx], 0x2, data); + } + break; + case 0x80: case 0x90: + if (emu_slot_idx >= 0) + { + ESFM_slot_write(&chip->channels[natv_chan_idx].slots[natv_slot_idx], 0x3, data); + } + break; + case 0xa0: + if (emu_chan_idx >= 0) + { + ESFM_slot_write(&chip->channels[emu_chan_idx].slots[0], 0x4, data); + ESFM_emu_channel_update_keyscale(&chip->channels[emu_chan_idx]); + } + break; + case 0xb0: + if (emu_chan_idx >= 0) + { + esfm_channel *channel = &chip->channels[emu_chan_idx]; + // TODO: check if emulation mode actually writes to the native mode key on registers + // it might only use slot 0's emu key on field... + channel->key_on = (data & 0x20) != 0; + if (channel->channel_idx == 7 || channel->channel_idx == 8) + { + channel->key_on_2 = (data & 0x20) != 0; + } + ESFM_slot_write(&channel->slots[0], 0x5, data); + ESFM_emu_channel_update_keyscale(&chip->channels[emu_chan_idx]); + } + break; + case 0xc0: + if (emu_chan_idx >= 0) + { + ESFM_slot_write(&chip->channels[emu_chan_idx].slots[0], 0x6, data); + ESFM_emu_rearrange_connections(&chip->channels[emu_chan_idx]); + } + break; + case 0xe0: case 0xf0: + if (emu_slot_idx >= 0) + { + ESFM_slot_write(&chip->channels[natv_chan_idx].slots[natv_slot_idx], 0x7, data); + } + break; + } +} + + +/* ------------------------------------------------------------------------- */ +void +ESFM_write_reg (esfm_chip *chip, uint16_t address, uint8_t data) +{ + if (chip->native_mode) + { + ESFM_write_reg_native(chip, address, data); + return; + } + else + { + ESFM_write_reg_emu(chip, address, data); + return; + } +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_write_reg_buffered (esfm_chip *chip, uint16_t address, uint8_t data) +{ + uint64_t timestamp; + esfm_write_buf *new_entry, *last_entry; + + new_entry = &chip->write_buf[chip->write_buf_end]; + last_entry = &chip->write_buf[(chip->write_buf_end - 1) % ESFM_WRITEBUF_SIZE]; + + if (new_entry->valid) { + ESFM_write_reg(chip, new_entry->address, new_entry->data); + chip->write_buf_start = (chip->write_buf_end + 1) % ESFM_WRITEBUF_SIZE; + } + + new_entry->valid = 1; + new_entry->address = address; + new_entry->data = data; + timestamp = last_entry->timestamp + ESFM_WRITEBUF_DELAY; + if (timestamp < chip->write_buf_timestamp) + { + timestamp = chip->write_buf_timestamp; + } + + new_entry->timestamp = timestamp; + chip->write_buf_end = (chip->write_buf_end + 1) % ESFM_WRITEBUF_SIZE; +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_write_reg_buffered_fast (esfm_chip *chip, uint16_t address, uint8_t data) +{ + esfm_write_buf *new_entry; + + new_entry = &chip->write_buf[chip->write_buf_end]; + + if (new_entry->valid) { + ESFM_write_reg(chip, new_entry->address, new_entry->data); + chip->write_buf_start = (chip->write_buf_end + 1) % ESFM_WRITEBUF_SIZE; + } + + new_entry->valid = 1; + new_entry->address = address; + new_entry->data = data; + new_entry->timestamp = chip->write_buf_timestamp; + chip->write_buf_end = (chip->write_buf_end + 1) % ESFM_WRITEBUF_SIZE; +} + +/* ------------------------------------------------------------------------- */ +uint8_t +ESFM_readback_reg (esfm_chip *chip, uint16_t address) +{ + if (chip->native_mode) + { + return ESFM_readback_reg_native(chip, address); + } + else + { + return 0; + } +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_write_port (esfm_chip *chip, uint8_t offset, uint8_t data) +{ + if (chip->native_mode) + { + switch(offset) + { + case 0: + chip->native_mode = 0; + ESFM_native_to_emu_switch(chip); + chip->addr_latch = data; + break; + case 1: + ESFM_write_reg_native(chip, chip->addr_latch, data); + break; + case 2: + chip->addr_latch = (chip->addr_latch & 0xff00) | data; + break; + case 3: + chip->addr_latch = chip->addr_latch & 0xff; + chip->addr_latch |= (uint16)data << 8; + break; + } + } + else + { + switch(offset) + { + case 0: + chip->addr_latch = data; + break; + case 1: case 3: + ESFM_write_reg_emu(chip, chip->addr_latch, data); + break; + case 2: + chip->addr_latch = (uint16)data | 0x100; + break; + } + } +} + +/* ------------------------------------------------------------------------- */ +uint8_t +ESFM_read_port (esfm_chip *chip, uint8_t offset) +{ + uint8_t data = 0; + if (chip->native_mode) + { + switch(offset) + { + case 0: + // TODO: actually implement timer count, trigger and reset + data |= (chip->irq_bit != 0) << 7; + data |= (chip->timer_overflow[0] != 0) << 6; + data |= (chip->timer_overflow[1] != 0) << 5; + break; + case 1: + data = ESFM_readback_reg_native(chip, chip->addr_latch); + break; + // TODO: verify what the ESFM chip actually returns when reading + // from the other address ports + } + } + else + { + switch(offset) + { + case 0: + data |= (chip->irq_bit != 0) << 7; + data |= (chip->timer_overflow[0] != 0) << 6; + data |= (chip->timer_overflow[1] != 0) << 5; + break; + case 1: + data = 0; + break; + case 2: case 3: + // This matches OPL3 behavior. + // TODO: verify what the ESFM chip actually returns when reading + // from address ports in emulation mode + data = 0xff; + break; + } + } + return data; +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_set_mode (esfm_chip *chip, bool native_mode) +{ + native_mode = native_mode != 0; + + if (native_mode != (chip->native_mode != 0)) + { + chip->native_mode = native_mode; + if (native_mode) + { + ESFM_emu_to_native_switch(chip); + } + else + { + ESFM_native_to_emu_switch(chip); + } + } +} + +/* ------------------------------------------------------------------------- */ +void +ESFM_init (esfm_chip *chip) +{ + esfm_slot *slot; + esfm_channel *channel; + size_t channel_idx, slot_idx; + + memset(chip, 0, sizeof(esfm_chip)); + for (channel_idx = 0; channel_idx < 18; channel_idx++) + { + for (slot_idx = 0; slot_idx < 4; slot_idx++) + { + channel = &chip->channels[channel_idx]; + slot = &channel->slots[slot_idx]; + + channel->chip = chip; + channel->channel_idx = channel_idx; + slot->channel = channel; + slot->chip = chip; + slot->slot_idx = slot_idx; + slot->in.eg_position = slot->in.eg_output = 0x1ff; + slot->in.eg_state = EG_RELEASE; + slot->in.emu_mod_enable = ~((int13) 0); + if (slot_idx == 0) + { + slot->in.mod_input = &slot->in.feedback_buf; + } + else + { + esfm_slot *prev_slot = &channel->slots[slot_idx - 1]; + slot->in.mod_input = &prev_slot->in.output; + } + + if (slot_idx == 1) + { + slot->in.emu_output_enable = ~((int13) 0); + } + + if (channel_idx > 15 && slot_idx & 0x02) + { + slot->in.key_on = &channel->key_on_2; + } + else + { + slot->in.key_on = &channel->key_on; + } + + slot->out_enable[0] = slot->out_enable[1] = ~((int13) 0); + } + } + + chip->lfsr = 1; +} + diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 8ff1a33c7..cf4349887 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -82,6 +82,7 @@ #include "platform/ted.h" #include "platform/c140.h" #include "platform/pcmdac.h" +#include "platform/esfm.h" #include "platform/dummy.h" #include "../ta-log.h" #include "song.h" @@ -596,6 +597,9 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do case DIV_SYSTEM_PCM_DAC: dispatch=new DivPlatformPCMDAC; break; + case DIV_SYSTEM_ESFM: + dispatch=new DivPlatformESFM; + break; case DIV_SYSTEM_DUMMY: dispatch=new DivPlatformDummy; break; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 1467377c1..b8c2eb62a 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1371,6 +1371,9 @@ DivInstrument* DivEngine::getIns(int index, DivInstrumentType fallbackType) { case DIV_INS_OPL_DRUMS: return &song.nullInsOPLDrums; break; + case DIV_INS_ESFM: + return &song.nullInsESFM; + break; default: break; } @@ -2328,6 +2331,9 @@ int DivEngine::addInstrument(int refChan, DivInstrumentType fallbackType) { case DIV_INS_OPL_DRUMS: *ins=song.nullInsOPLDrums; break; + case DIV_INS_ESFM: + *ins=song.nullInsESFM; + break; default: break; } diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index abd06a26a..0e1340e90 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -228,6 +228,28 @@ bool DivInstrumentSNES::operator==(const DivInstrumentSNES& other) { ); } +bool DivInstrumentESFM::operator==(const DivInstrumentESFM& other) { + return ( + _C(noise) && + _C(op[0]) && + _C(op[1]) && + _C(op[2]) && + _C(op[3]) + ); +} + +bool DivInstrumentESFM::Operator::operator==(const DivInstrumentESFM::Operator& other) { + return ( + _C(delay) && + _C(outLvl) && + _C(modIn) && + _C(left) && + _C(right) && + _C(ct) && + _C(dt) + ); +} + #undef _C #define FEATURE_BEGIN(x) \ @@ -734,6 +756,22 @@ void DivInstrument::writeFeatureNE(SafeWriter* w) { FEATURE_END; } +void DivInstrument::writeFeatureEF(SafeWriter* w) { + FEATURE_BEGIN("EF"); + + w->writeC(esfm.noise&3); + for (int i=0; i<4; i++) { + DivInstrumentESFM::Operator& op=esfm.op[i]; + + w->writeC(((op.delay&7)<<5)|((op.outLvl&7)<<2)|((op.right&1)<<1)|(op.left&1)); + w->writeC(op.modIn&7); + w->writeC(op.ct); + w->writeC(op.dt); + } + + FEATURE_END; +} + void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bool insName) { size_t blockStartSeek=0; size_t blockEndSeek=0; @@ -777,6 +815,7 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo bool featureES=false; bool featureX1=false; bool featureNE=false; + bool featureEF=false; bool checkForWL=false; @@ -990,7 +1029,10 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo featureSM=true; featureSL=true; break; - + case DIV_INS_ESFM: + featureFM=true; + featureEF=true; + break; case DIV_INS_MAX: break; case DIV_INS_NULL: @@ -1038,6 +1080,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo if (x1_010!=defaultIns.x1_010) { featureX1=true; } + if (esfm!=defaultIns.esfm) { + featureEF=true; + } } // check ins name @@ -1180,6 +1225,9 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song, bo if (featureNE) { writeFeatureNE(w); } + if (featureEF) { + writeFeatureEF(w); + } if (fui && (featureSL || featureWL)) { w->write("EN",2); @@ -2579,6 +2627,31 @@ void DivInstrument::readFeatureNE(SafeReader& reader, short version) { READ_FEAT_END; } +void DivInstrument::readFeatureEF(SafeReader& reader, short version) { + READ_FEAT_BEGIN; + + unsigned char next=reader.readC(); + esfm.noise = next&3; + + for (int i=0; i<4; i++) { + DivInstrumentESFM::Operator& op=esfm.op[i]; + + next=reader.readC(); + op.delay=(next>>5)&7; + op.outLvl=(next>>2)&7; + op.right=(next>>1)&1; + op.left=next&1; + + next=reader.readC(); + op.modIn=next&7; + + op.ct=reader.readC(); + op.dt=reader.readC(); + } + + READ_FEAT_END; +} + DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, bool fui, DivSong* song) { unsigned char featCode[2]; @@ -2646,6 +2719,8 @@ DivDataErrors DivInstrument::readInsDataNew(SafeReader& reader, short version, b readFeatureX1(reader,version); } else if (memcmp(featCode,"NE",2)==0) { // NES (DPCM) readFeatureNE(reader,version); + } else if (memcmp(featCode,"EF",2)==0) { // ESFM + readFeatureEF(reader,version); } else { if (song==NULL && (memcmp(featCode,"SL",2)==0 || (memcmp(featCode,"WL",2)==0))) { // nothing diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 477962dfa..91a6d2a6b 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -85,6 +85,8 @@ enum DivInstrumentType: unsigned short { DIV_INS_TED=52, DIV_INS_C140=53, DIV_INS_C219=54, + // TODO: Ask tilde to standardize this!!! + DIV_INS_ESFM=55, DIV_INS_MAX, DIV_INS_NULL }; @@ -150,6 +152,8 @@ enum DivMacroTypeOp: unsigned char { // - AM, AR, DR, MULT (CRS), RR, SL, TL, DT2, RS, DT, D2R // - WS, DVB = MULT (FINE), DAM = REV, KSL = EGShift, EGT = Fixed + + struct DivInstrumentFM { unsigned char alg, fb, fms, ams, fms2, ams2, ops, opllPreset; bool fixedDrums; @@ -750,6 +754,108 @@ struct DivInstrumentSNES { d2(0) {} }; +// ESFM operator structure: +// - DELAY, OUT, MOD, L, R, NOISE +// - Virtual: CT, DT, DTRAW +// - In FM struct: AM, DAM, AR, DR, MULT, RR, SL, TL +// - In FM struct: KSL, VIB, DVB, WS, SUS, KSR +// - Not in struct: FNUML, FNUMH, BLOCK + +struct DivInstrumentESFM { + bool operator==(const DivInstrumentESFM& other); + bool operator!=(const DivInstrumentESFM& other) { + return !(*this==other); + } + + // Only works on OP4, so putting it outside the Operator struct instead + unsigned char noise; + struct Operator { + unsigned char delay, outLvl, modIn, left, right; + signed char ct, dt; + + bool operator==(const Operator& other); + bool operator!=(const Operator& other) { + return !(*this==other); + } + Operator(): + delay(0), + outLvl(0), + modIn(0), + left(true), + right(true), + ct(0), + dt(0) {} + } op[4]; + DivInstrumentESFM(): + noise(0) + { + op[0].modIn=4; + op[0].outLvl=0; + + op[1].modIn=7; + op[1].outLvl=0; + + op[2].modIn=7; + op[2].outLvl=0; + + op[3].modIn=7; + op[3].outLvl=7; + } + +#if 0 + void syncFrom(DivInstrumentFM &other) { + for (int i=0; i<4; i++) { + this->op[i].am=other.op[i].am; + this->op[i].dam=other.op[i].dam; + this->op[i].ar=other.op[i].ar; + this->op[i].dr=other.op[i].dr; + this->op[i].mult=other.op[i].mult; + this->op[i].rr=other.op[i].rr; + this->op[i].sl=other.op[i].sl; + this->op[i].tl=other.op[i].tl; + this->op[i].ssgEnv=other.op[i].ssgEnv; + this->op[i].ksl=other.op[i].ksl; + this->op[i].vib=other.op[i].vib; + this->op[i].dvb=other.op[i].dvb; + this->op[i].ws=other.op[i].ws; + this->op[i].ksr=other.op[i].ksr; + this->op[i].ct=0; + // from dtTable at fmsharedbase.h + if (other.op[i].dt>=7){ + // trap out of range dt values + // TODO: check if any systems legitimately use dt values higher than 7 + this->op[i].dt=0; + } else { + this->op[i].dt=other.op[i].dt - 3; + } + } + } + + void syncTo(DivInstrumentFM &other) { + for (int i=0; i<4; i++) { + other.op[i].am=this->op[i].am; + other.op[i].dam=this->op[i].dam; + other.op[i].ar=this->op[i].ar; + other.op[i].dr=this->op[i].dr; + other.op[i].mult=this->op[i].mult; + other.op[i].rr=this->op[i].rr; + other.op[i].sl=this->op[i].sl; + other.op[i].tl=this->op[i].tl; + other.op[i].ssgEnv=this->op[i].ssgEnv; + other.op[i].ksl=this->op[i].ksl; + other.op[i].vib=this->op[i].vib; + other.op[i].dvb=this->op[i].dvb; + other.op[i].ws=this->op[i].ws; + other.op[i].ksr=this->op[i].ksr; + // dt field conversion is unfortunately lossy, as the dt field on DivInstrumentFM + // spans from 0..6 (eff. -3..3), while on DivInstrumentESFM it spans from -128..127. + other.op[i].dt=CLAMP(this->op[i].dt, -3, 3) + 3; + } + } +#endif + +}; + struct DivInstrument { String name; DivInstrumentType type; @@ -766,6 +872,8 @@ struct DivInstrument { DivInstrumentSoundUnit su; DivInstrumentES5506 es5506; DivInstrumentSNES snes; + DivInstrumentESFM esfm; + // TODO I only added the esfm member here, still need to implement everything else related /** * these are internal functions. @@ -790,6 +898,7 @@ struct DivInstrument { void writeFeatureES(SafeWriter* w); void writeFeatureX1(SafeWriter* w); void writeFeatureNE(SafeWriter* w); + void writeFeatureEF(SafeWriter* w); void readFeatureNA(SafeReader& reader, short version); void readFeatureFM(SafeReader& reader, short version); @@ -810,6 +919,7 @@ struct DivInstrument { void readFeatureES(SafeReader& reader, short version); void readFeatureX1(SafeReader& reader, short version); void readFeatureNE(SafeReader& reader, short version); + void readFeatureEF(SafeReader& reader, short version); DivDataErrors readInsDataOld(SafeReader& reader, short version); DivDataErrors readInsDataNew(SafeReader& reader, short version, bool fui, DivSong* song); diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp new file mode 100644 index 000000000..0c1a11e97 --- /dev/null +++ b/src/engine/platform/esfm.cpp @@ -0,0 +1,854 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "esfm.h" +#include "../engine.h" +#include "../../ta-log.h" +#include +#include +#include + +#define CHIP_FREQBASE (32768*288) + +#define OFFSET_AM_VIB_SUS_KSR_MULT 0x00 +#define OFFSET_KSL_TL 0x01 +#define OFFSET_AR_DR 0x02 +#define OFFSET_SL_RR 0x03 +#define OFFSET_FREQL 0x04 +#define OFFSET_FREQH_BLOCK_DELAY 0x05 +#define OFFSET_DAM_DVB_LEFT_RIGHT_MODIN 0x06 +#define OFFSET_OUTLVL_NOISE_WS 0x07 + +#define KEY_ON_REGS_START (18 * 8 * 4) + +void DivPlatformESFM::acquire(short** buf, size_t len) { + thread_local short o[2]; + for (size_t h=0; hdata[oscBuf[c]->needle++]=ESFM_get_channel_output_native(&chip,c); + } + + buf[0][h]=o[0]; + buf[1][h]=o[1]; + } +} + +void DivPlatformESFM::tick(bool sysTick) { + for (int i=0; i<18; i++) { + chan[i].std.next(); + + if (chan[i].std.vol.had) { + chan[i].outVol=VOL_SCALE_LOG_BROKEN(chan[i].vol,MIN(63,chan[i].std.vol.val),63); + for (int o=0; o<4; o++) { + unsigned short baseAddr=i*32 + o*8; + DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; + unsigned char noise=chan[i].state.esfm.noise&3; + + if (isMuted[i]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + if (KVS(i, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[i].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + } + } + } + + if (NEW_ARP_STRAT) { + chan[i].handleArp(); + } else if (chan[i].std.arp.had) { + if (!chan[i].inPorta) { + chan[i].baseFreq=NOTE_FREQUENCY(parent->calcArp(chan[i].note,chan[i].std.arp.val)); + } + chan[i].freqChanged=true; + } + + // TODO: check why I disabled globalPan here? +#if 0 + if (chan[i].std.panL.had) { + chan[i].globalPan=((chan[i].std.panL.val&1)<<1)|((chan[i].std.panL.val&2)>>1); + } +#endif + + if (chan[i].std.pitch.had) { + if (chan[i].std.pitch.mode) { + chan[i].pitch2+=chan[i].std.pitch.val; + CLAMP_VAR(chan[i].pitch2,-131071,131071); + } else { + chan[i].pitch2=chan[i].std.pitch.val; + } + chan[i].freqChanged=true; + } + + if (chan[i].std.phaseReset.had) { + if (chan[i].std.phaseReset.val==1 && chan[i].active) { + chan[i].keyOn=true; + } + } + + for (int o=0; o<4; o++) { + unsigned short baseAddr=i*32 + o*8; + DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; + DivMacroInt::IntOp& m=chan[i].std.op[o]; + + if (m.am.had) { + op.am=m.am.val; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + if (m.vib.had) { + op.vib=m.vib.val; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + if (m.sus.had) { + op.sus=m.sus.val; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + if (m.ksr.had) { + op.ksr=m.ksr.val; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + if (m.mult.had) { + op.mult=m.mult.val; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + + if (m.ar.had) { + op.ar=m.ar.val; + rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + } + if (m.dr.had) { + op.dr=m.dr.val; + rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + } + if (m.sl.had) { + op.sl=m.sl.val; + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + } + if (m.rr.had) { + op.rr=m.rr.val; + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + } + + if (m.tl.had || m.ksl.had) { + if (m.tl.had) { + op.tl=m.tl.val&63; + } + if (m.ksl.had) { + op.ksl=m.ksl.val; + } + + if (KVS(i, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[i].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + } + } + } + + for (int i=0; icalcFreq(chan[i].baseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride:chan[i].arpOff,chan[i].fixedArp,false,octave(chan[i].baseFreq)*2,chan[i].pitch2,chipClock,CHIP_FREQBASE); + if (chan[i].freq<0) chan[i].freq=0; + if (chan[i].freq>131071) chan[i].freq=131071; + + for (int o=0; o<4; o++) { + unsigned short baseAddr=i*32 + o*8; + DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; + int ct=(int)opE.ct; + int dt=(int)opE.dt; + int opFreq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride+ct:chan[i].arpOff+ct,chan[i].fixedArp,false,octave(chan[i].baseFreq)*2,chan[i].pitch2+dt,chipClock,CHIP_FREQBASE); + if (opFreq<0) opFreq=0; + if (opFreq>131071) opFreq=131071; + int freqt=toFreq(opFreq); + chan[i].freqL[o]=freqt&0xff; + chan[i].freqH[o]=freqt>>8; + immWrite(baseAddr+OFFSET_FREQL,chan[i].freqL[o]); + immWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); + } + chan[i].freqChanged=false; + } + if (chan[i].keyOn && !chan[i].hardReset) { + // logI("chan[%d] soft key on", i); + if (i<16) { + immWrite(KEY_ON_REGS_START+i, 1); + } else { + // Handle writing to the split key-on registers of channels 16 and 17 + immWrite(KEY_ON_REGS_START+16+(i-16)*2, 1); + immWrite(KEY_ON_REGS_START+16+1+(i-16)*2, 1); + } + chan[i].keyOn=false; + } + } + + if (mustHardReset) { + for (int i=0; i<18; i++) { + if (chan[i].hardReset && chan[i].keyOn) { + // logI("chan[%d] hard reset key on, writing original slrr back", i); + for (int o=0; o<4; o++) { + unsigned short baseAddr=i*32 + o*8; + DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; + immWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + } + if (i<16) { + immWrite(KEY_ON_REGS_START+i, 1); + } else { + // Handle writing to the split key-on registers of channels 16 and 17 + immWrite(KEY_ON_REGS_START+16+(i-16)*2, 1); + immWrite(KEY_ON_REGS_START+16+1+(i-16)*2, 1); + } + chan[i].keyOn=false; + } + } + } +} + +int DivPlatformESFM::octave(int freq) { + if (freq>=0x3ff<<6) { + return 1<<7; + } else if (freq>=0x3ff<<5) { + return 1<<6; + } else if (freq>=0x3ff<<4) { + return 1<<5; + } else if (freq>=0x3ff<<3) { + return 1<<4; + } else if (freq>=0x3ff<<2) { + return 1<<3; + } else if (freq>=0x3ff<<1) { + return 1<<2; + } else if (freq>=0x3ff) { + return 1<<1; + } else { + return 1<<0; + } + return 1<<0; +} + +int DivPlatformESFM::toFreq(int freq) { + if (freq>=0x3ff<<6) { + return 0x1c00|((freq>>7)&0x3ff); + } else if (freq>=0x3ff<<5) { + return 0x1800|((freq>>6)&0x3ff); + } else if (freq>=0x3ff<<4) { + return 0x1400|((freq>>5)&0x3ff); + } else if (freq>=0x3ff<<3) { + return 0x1000|((freq>>4)&0x3ff); + } else if (freq>=0x3ff<<2) { + return 0xc00|((freq>>3)&0x3ff); + } else if (freq>=0x3ff<<1) { + return 0x800|((freq>>2)&0x3ff); + } else if (freq>=0x3ff<<0) { + return 0x400|((freq>>1)&0x3ff); + } else { + return freq&0x3ff; + } +} + +void DivPlatformESFM::muteChannel(int ch, bool mute) { + isMuted[ch]=mute; + + for (int o=0; o<4; o++) { + unsigned short baseAddr=ch*32 + o*8; + DivInstrumentFM::Operator& op=chan[ch].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[ch].state.esfm.op[o]; + unsigned char noise=chan[ch].state.esfm.noise&3; + + if (isMuted[ch]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + if (KVS(ch, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[ch].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + } + } +} + +void DivPlatformESFM::commitState(int ch, DivInstrument* ins) { + if (chan[ch].insChanged) { + chan[ch].state.fm=ins->fm; + chan[ch].state.esfm=ins->esfm; + for (int o=0; o<4; o++) { + unsigned short baseAddr=ch*32 + o*8; + DivInstrumentFM::Operator& op=chan[ch].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[ch].state.esfm.op[o]; + unsigned char noise=chan[ch].state.esfm.noise&3; + + if (isMuted[ch]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + if (KVS(ch, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[ch].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + } + + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[ch].freqH[o]|(opE.delay<<5)); + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[ch].globalPan)&1)<<4)|(((opE.right&(chan[ch].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + } +} + +int DivPlatformESFM::dispatch(DivCommand c) { + switch (c.cmd) { + case DIV_CMD_NOTE_ON: { + DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_ESFM); + + chan[c.chan].macroInit(ins); + if (!chan[c.chan].std.vol.will) { + chan[c.chan].outVol=chan[c.chan].vol; + } + + commitState(c.chan,ins); + chan[c.chan].insChanged=false; + + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value); + chan[c.chan].note=c.value; + chan[c.chan].freqChanged=true; + } + chan[c.chan].keyOn=true; + chan[c.chan].active=true; + break; + } + case DIV_CMD_NOTE_OFF: + chan[c.chan].keyOff=true; + chan[c.chan].keyOn=false; + chan[c.chan].active=false; + break; + case DIV_CMD_NOTE_OFF_ENV: + chan[c.chan].keyOff=true; + chan[c.chan].keyOn=false; + chan[c.chan].active=false; + chan[c.chan].std.release(); + break; + case DIV_CMD_ENV_RELEASE: + chan[c.chan].std.release(); + break; + case DIV_CMD_VOLUME: { + chan[c.chan].vol=c.value; + if (!chan[c.chan].std.vol.has) { + chan[c.chan].outVol=c.value; + } + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + if (KVS(c.chan, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + } + break; + } + case DIV_CMD_GET_VOLUME: + return chan[c.chan].vol; + break; + case DIV_CMD_INSTRUMENT: + if (chan[c.chan].ins!=c.value || c.value2==1) { + chan[c.chan].insChanged=true; + } + chan[c.chan].ins=c.value; + break; + case DIV_CMD_PANNING: { + chan[c.chan].globalPan=(c.value>0)|((c.value2>0)<<1); + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + break; + } + case DIV_CMD_PITCH: + chan[c.chan].pitch=c.value; + chan[c.chan].freqChanged=true; + break; + case DIV_CMD_NOTE_PORTA: { + int destFreq=NOTE_FREQUENCY(c.value2); + int newFreq; + bool return2=false; + if (destFreq>chan[c.chan].baseFreq) { + newFreq=chan[c.chan].baseFreq+c.value*((parent->song.linearPitch==2)?1:octave(chan[c.chan].baseFreq)); + if (newFreq>=destFreq) { + newFreq=destFreq; + return2=true; + } + } else { + newFreq=chan[c.chan].baseFreq-c.value*((parent->song.linearPitch==2)?1:octave(chan[c.chan].baseFreq)); + if (newFreq<=destFreq) { + newFreq=destFreq; + return2=true; + } + } + if (!chan[c.chan].portaPause && parent->song.linearPitch!=2) { + if (octave(chan[c.chan].baseFreq)!=octave(newFreq)) { + chan[c.chan].portaPause=true; + break; + } + } + chan[c.chan].baseFreq=newFreq; + chan[c.chan].portaPause=false; + chan[c.chan].freqChanged=true; + if (return2) { + chan[c.chan].inPorta=false; + return 2; + } + break; + } + case DIV_CMD_LEGATO: { + if (chan[c.chan].insChanged) { + DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_ESFM); + commitState(c.chan,ins); + chan[c.chan].insChanged=false; + } + chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value); + chan[c.chan].note=c.value; + chan[c.chan].freqChanged=true; + break; + } + case DIV_CMD_FM_MULT: { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.mult=c.value2&15; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + break; + } + case DIV_CMD_FM_TL: { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.tl=c.value2&63; + if (KVS(c.chan, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + break; + } + case DIV_CMD_FM_AR: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.ar=c.value2&15; + rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.ar=c.value2&15; + rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + } + break; + } + case DIV_CMD_FM_DR: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.dr=c.value2&15; + rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.dr=c.value2&15; + rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + } + break; + } + case DIV_CMD_FM_SL: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.sl=c.value2&15; + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.sl=c.value2&15; + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + } + break; + } + case DIV_CMD_FM_RR: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.rr=c.value2&15; + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|op.rr); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.rr=c.value2&15; + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|op.rr); + } + break; + } + case DIV_CMD_FM_AM: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.am=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.am=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + break; + } + case DIV_CMD_FM_VIB: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.vib=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.vib=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + break; + } + case DIV_CMD_FM_SUS: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.sus=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.sus=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + break; + } + case DIV_CMD_FM_KSR: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.ksr=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.ksr=c.value2&1; + rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + } + break; + } + case DIV_CMD_FM_WS: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + unsigned char noise=chan[c.chan].state.esfm.noise&3; + op.ws=c.value2&7; + if (isMuted[c.chan]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + } + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + unsigned char noise=chan[c.chan].state.esfm.noise&3; + op.ws=c.value2&7; + if (isMuted[c.chan]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + } + } + break; + } + // KSL + case DIV_CMD_FM_RS: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.ksl=c.value2&3; + if (KVS(c.chan, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + op.ksl=c.value2&3; + if (KVS(c.chan, o)) { + rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + } else { + rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + } + } + break; + } + case DIV_CMD_FM_HARD_RESET: + chan[c.chan].hardReset=c.value; + break; + case DIV_CMD_MACRO_OFF: + chan[c.chan].std.mask(c.value,true); + break; + case DIV_CMD_MACRO_ON: + chan[c.chan].std.mask(c.value,false); + break; + case DIV_ALWAYS_SET_VOLUME: + return 0; + break; + case DIV_CMD_GET_VOLMAX: + return 63; + break; + case DIV_CMD_PRE_PORTA: + if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will && !NEW_ARP_STRAT) { + chan[c.chan].baseFreq=NOTE_FREQUENCY(chan[c.chan].note); + } + chan[c.chan].inPorta=c.value; + break; + default: + break; + } + return 1; +} + +void DivPlatformESFM::forceIns() { + for (int i=0; i<18; i++) { + chan[i].insChanged=true; + chan[i].freqChanged=true; + } + for (int i=0; i>1); +} + +DivDispatchOscBuffer* DivPlatformESFM::getOscBuffer(int ch) { + return oscBuf[ch]; +} + +unsigned char* DivPlatformESFM::getRegisterPool() { + // TODO: DEBUG, remove this, it impacts performance + for (int i=0; i& wlist) { + for (DivRegWrite& i: wlist) immWrite(i.addr,i.val); +} + +void DivPlatformESFM::setFlags(const DivConfig& flags) { + rate=49716; + chipClock=COLOR_NTSC*4.0; +} + +int DivPlatformESFM::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { + parent=p; + dumpWrites=false; + skipRegisterWrites=false; + for (int i=0; i<18; i++) { + isMuted[i]=false; + oscBuf[i]=new DivDispatchOscBuffer; + } + setFlags(flags); + reset(); + + return 18; +} + +void DivPlatformESFM::quit() { + for (int i=0; i<18; i++) { + delete oscBuf[i]; + } +} + +DivPlatformESFM::~DivPlatformESFM() { +} diff --git a/src/engine/platform/esfm.h b/src/engine/platform/esfm.h new file mode 100644 index 000000000..558571a84 --- /dev/null +++ b/src/engine/platform/esfm.h @@ -0,0 +1,144 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2023 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "../dispatch.h" +#include "../../fixedQueue.h" +#include "../../../extern/ESFMu/esfm.h" + +// ESFM register address space technically spans 0x800 (2048) bytes, +// but we only need the first 0x254 (596) during normal use. +// Rounding it up to 0x260 (608) bytes, the nearest multiple of 16. +#define ESFM_REG_POOL_SIZE 0x260 + +class DivPlatformESFM: public DivDispatch { + struct Channel: public SharedChannel { + struct { + DivInstrumentFM fm; + DivInstrumentESFM esfm; + } state; + unsigned char freqL[4], freqH[4]; + bool hardReset; + unsigned char globalPan; + int macroVolMul; + Channel(): + SharedChannel(0), + freqL{0, 0, 0, 0}, + freqH{0, 0, 0, 0}, + globalPan(3), + macroVolMul(64) {} + }; + Channel chan[18]; + DivDispatchOscBuffer* oscBuf[18]; + bool isMuted[18]; + struct QueuedWrite { + unsigned short addr; + unsigned char val; + bool addrOrVal; + QueuedWrite(): addr(0), val(0), addrOrVal(false) {} + QueuedWrite(unsigned short a, unsigned char v): addr(a), val(v), addrOrVal(false) {} + }; + FixedQueue writes; + esfm_chip chip; + + unsigned char regPool[ESFM_REG_POOL_SIZE]; + short oldWrites[ESFM_REG_POOL_SIZE]; + short pendingWrites[ESFM_REG_POOL_SIZE]; + + int octave(int freq); + int toFreq(int freq); + void commitState(int ch, DivInstrument* ins); + + friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); + + inline void rWrite(unsigned short a, short v) { + if (!skipRegisterWrites && a 0 and o == 3 (last operator), + * or op[o].outLvl > 0 and (op[o].outLvl - op[o + 1].modIn) >= 2, + * or op[o].outLvl > 0 and op[o + 1].modIn == 0. + */ + inline bool KVS(int c, int o) { + if (c < 0 || c >= 18 || o < 0 || o >= 4) return false; + + if (chan[c].state.fm.op[o].kvs==1) return true; + + if (chan[c].state.fm.op[o].kvs==2) { + if (chan[c].state.esfm.op[o].outLvl==7) return true; + else if (chan[c].state.esfm.op[o].outLvl>0) { + if (o==3) return true; + else if ((chan[c].state.esfm.op[o].outLvl-chan[c].state.esfm.op[o+1].modIn) >= 2) { + return true; + } + else if (chan[c].state.esfm.op[o+1].modIn==0) { + return true; + } + } + } + return false; + } + + public: + void acquire(short** buf, size_t len); + int dispatch(DivCommand c); + void* getChanState(int chan); + DivMacroInt* getChanMacroInt(int ch); + unsigned short getPan(int ch); + DivDispatchOscBuffer* getOscBuffer(int chan); + unsigned char* getRegisterPool(); + int getRegisterPoolSize(); + int getOutputCount(); + void reset(); + void forceIns(); + void tick(bool sysTick=true); + void muteChannel(int ch, bool mute); + bool keyOffAffectsArp(int ch); + bool keyOffAffectsPorta(int ch); + void toggleRegisterDump(bool enable); + void notifyInsChange(int ins); + void notifyInsDeletion(void* ins); + void poke(unsigned int addr, unsigned short val); + void poke(std::vector& wlist); + void setFlags(const DivConfig& flags); + int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); + void quit(); + ~DivPlatformESFM(); +}; diff --git a/src/engine/song.h b/src/engine/song.h index 7a7e267c2..3a1c9baf4 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -131,7 +131,9 @@ enum DivSystem { DIV_SYSTEM_K053260, DIV_SYSTEM_TED, DIV_SYSTEM_C140, - DIV_SYSTEM_C219 + DIV_SYSTEM_C219, + // TODO: Ask Tilde to standardize! + DIV_SYSTEM_ESFM, }; enum DivEffectType: unsigned short { @@ -394,7 +396,7 @@ struct DivSong { std::vector effects; - DivInstrument nullIns, nullInsOPLL, nullInsOPL, nullInsOPLDrums, nullInsQSound; + DivInstrument nullIns, nullInsOPLL, nullInsOPL, nullInsOPLDrums, nullInsQSound, nullInsESFM; DivWavetable nullWave; DivSample nullSample; @@ -603,6 +605,45 @@ struct DivSong { nullInsOPLDrums.fm.op[3].mult=2; nullInsQSound.std.panLMacro.mode=true; + + // ESFM default instrument - port of OPM default instrument? + // TODO: adjust these values so they actually match + nullInsESFM.esfm.noise=0; + nullInsESFM.esfm.op[0].outLvl=0; + nullInsESFM.esfm.op[0].modIn=4; + nullInsESFM.fm.op[0].tl=21; + nullInsESFM.fm.op[0].ar=15; + nullInsESFM.fm.op[0].dr=9; + nullInsESFM.fm.op[0].sl=7; + nullInsESFM.fm.op[0].rr=3; + nullInsESFM.fm.op[0].mult=7; + + nullInsESFM.esfm.op[1].outLvl=0; + nullInsESFM.esfm.op[1].modIn=7; + nullInsESFM.fm.op[1].tl=24; + nullInsESFM.fm.op[1].ar=15; + nullInsESFM.fm.op[1].dr=2; + nullInsESFM.fm.op[1].sl=11; + nullInsESFM.fm.op[1].rr=2; + nullInsESFM.fm.op[1].mult=1; + + nullInsESFM.esfm.op[2].outLvl=0; + nullInsESFM.esfm.op[2].modIn=7; + nullInsESFM.fm.op[2].tl=17; + nullInsESFM.fm.op[2].ar=15; + nullInsESFM.fm.op[2].dr=4; + nullInsESFM.fm.op[2].sl=15; + nullInsESFM.fm.op[2].rr=3; + nullInsESFM.fm.op[2].mult=2; + + nullInsESFM.esfm.op[3].outLvl=7; + nullInsESFM.esfm.op[3].modIn=7; + nullInsESFM.fm.op[3].tl=0; + nullInsESFM.fm.op[3].ar=15; + nullInsESFM.fm.op[3].dr=3; + nullInsESFM.fm.op[3].sl=15; + nullInsESFM.fm.op[3].rr=9; + nullInsESFM.fm.op[3].mult=1; } }; diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index aee338493..769650723 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1917,6 +1917,18 @@ void DivEngine::registerSystems() { {0x12, {DIV_CMD_SNES_INVERT, "12xy: Set invert mode (x: surround; y: invert)"}}, } ); + + // TODO: ask Tilde to standardize! + sysDefs[DIV_SYSTEM_ESFM]=new DivSysDef( + "ESFM (TODO: gimme a better name)", NULL, 0xd0, 0, 18, true, false, 0, false, 0, + "TODO: give ESFM the beautiful description it deserves", + {"FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "FM 7", "FM 8", "FM 9", "FM 10", "FM 11", "FM 12", "FM 13", "FM 14", "FM 15", "FM 16", "FM 17", "FM 18"}, + {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, + {DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM}, + {DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM}, + {}, + {} + ); sysDefs[DIV_SYSTEM_DUMMY]=new DivSysDef( "Dummy System", NULL, 0xfd, 0, 8, false, true, 0, false, 0, diff --git a/src/gui/fmPreview.cpp b/src/gui/fmPreview.cpp index 5586d1c20..14b21e018 100644 --- a/src/gui/fmPreview.cpp +++ b/src/gui/fmPreview.cpp @@ -22,6 +22,7 @@ #include "../../extern/opn/ym3438.h" #include "../../extern/opm/opm.h" #include "../../extern/opl/opl3.h" +#include "../../extern/ESFMu/esfm.h" extern "C" { #include "../../extern/Nuked-OPLL/opll.h" } @@ -337,6 +338,60 @@ void FurnaceGUI::renderFMPreviewOPZ(const DivInstrumentFM& params, int pos) { } } +#define ESFM_WRITE(addr,val) \ + ESFM_write_reg_buffered_fast((esfm_chip*)fmPreviewESFM,(addr),(val)) + +void FurnaceGUI::renderFMPreviewESFM(const DivInstrumentFM& params, const DivInstrumentESFM& esfmParams, int pos) { + if (fmPreviewESFM==NULL) { + fmPreviewESFM=new esfm_chip; + pos=0; + } + short out[4]; + bool mult0=false; + + if (pos==0) { + ESFM_init((esfm_chip*)fmPreviewESFM); + // set native mode + ESFM_WRITE(0x105, 0x80); + + // set params + for (int i=0; i<4; i++) { + if ((params.op[i].mult&15)==0) { + mult0=true; + break; + } + } + + for (int i=0; i<4; i++) { + const DivInstrumentFM::Operator& op=params.op[i]; + const DivInstrumentESFM::Operator& opE=esfmParams.op[i]; + unsigned short baseAddr=i*8; + + ESFM_WRITE(baseAddr+0,(op.am<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0x0f)); + ESFM_WRITE(baseAddr+1,(op.ksl<<6)|(op.tl&0x3f)); + ESFM_WRITE(baseAddr+2,(op.ar<<4)|(op.dr&0x0f)); + ESFM_WRITE(baseAddr+3,(op.sl<<4)|(op.rr&0x0f)); + + // TODO: implement ct/dt detune... how will we do that? + ESFM_WRITE(baseAddr+4,0); + ESFM_WRITE(baseAddr+5,(opE.delay<<5)|(mult0?0x0a:0x06)); + + ESFM_WRITE(baseAddr+6,(op.dam<<7)|((op.dvb&1)<<6)|((opE.right&1)<<5)|((opE.left&1)<<4)|((opE.modIn&7)<<1)); + ESFM_WRITE(baseAddr+7,(opE.outLvl<<5)|((i==3?esfmParams.noise:0)<<3)|(op.ws&7)); + } + } + + // note on + ESFM_WRITE(0x240, 1); + + // render + for (int i=0; itype) { case DIV_INS_FM: @@ -354,6 +409,8 @@ void FurnaceGUI::renderFMPreview(const DivInstrument* ins, int pos) { case DIV_INS_OPZ: renderFMPreviewOPZ(ins->fm,pos); break; + case DIV_INS_ESFM: + renderFMPreviewESFM(ins->fm,ins->esfm,pos); default: break; } diff --git a/src/gui/gui.h b/src/gui/gui.h index a7b1f3ac1..0cff7b595 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -258,6 +258,7 @@ enum FurnaceGUIColors { GUI_COLOR_INSTR_TED, GUI_COLOR_INSTR_C140, GUI_COLOR_INSTR_C219, + GUI_COLOR_INSTR_ESFM, GUI_COLOR_INSTR_UNKNOWN, GUI_COLOR_CHANNEL_BG, @@ -1379,6 +1380,7 @@ class FurnaceGUI { void* fmPreviewOPLL; void* fmPreviewOPZ; void* fmPreviewOPZInterface; + void* fmPreviewESFM; String* editString; SDL_Event userEvent; @@ -2218,6 +2220,7 @@ class FurnaceGUI { void renderFMPreviewOPLL(const DivInstrumentFM& params, int pos=0); void renderFMPreviewOPL(const DivInstrumentFM& params, int pos=0); void renderFMPreviewOPZ(const DivInstrumentFM& params, int pos=0); + void renderFMPreviewESFM(const DivInstrumentFM& params, const DivInstrumentESFM& esfmParams, int pos=0); // these ones offer ctrl-wheel fine value changes. bool CWSliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format=NULL, ImGuiSliderFlags flags=0); diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index e2874c31c..4c3c7646c 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -175,6 +175,8 @@ const char* insTypes[DIV_INS_MAX+1][3]={ {"TED",ICON_FA_BAR_CHART,ICON_FUR_INS_TED}, {"C140",ICON_FA_VOLUME_UP,ICON_FUR_INS_C140}, {"C219",ICON_FA_VOLUME_UP,ICON_FUR_INS_C219}, + // TODO: add ICON_FUR_INS_ESFM to furIcons.h and font_furicon.cpp and update here + {"FM (ESFM)",ICON_FA_AREA_CHART,ICON_FA_AREA_CHART}, {NULL,ICON_FA_QUESTION,ICON_FA_QUESTION} }; @@ -941,6 +943,7 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={ D(GUI_COLOR_INSTR_TED,"",ImVec4(0.7f,0.6f,1.0f,1.0f)), D(GUI_COLOR_INSTR_C140,"",ImVec4(1.0f,1.0f,0.0f,1.0f)), D(GUI_COLOR_INSTR_C219,"",ImVec4(1.0f,0.8f,0.0f,1.0f)), + D(GUI_COLOR_INSTR_ESFM,"",ImVec4(0.3f,1.0f,0.9f,1.0f)), D(GUI_COLOR_INSTR_UNKNOWN,"",ImVec4(0.3f,0.3f,0.3f,1.0f)), D(GUI_COLOR_CHANNEL_BG,"",ImVec4(0.4f,0.6f,0.8f,1.0f)), @@ -1136,6 +1139,7 @@ const int availableSystems[]={ DIV_SYSTEM_C140, DIV_SYSTEM_C219, DIV_SYSTEM_PCM_DAC, + DIV_SYSTEM_ESFM, DIV_SYSTEM_PONG, 0 // don't remove this last one! }; @@ -1171,6 +1175,7 @@ const int chipsFM[]={ DIV_SYSTEM_OPL3, DIV_SYSTEM_OPL3_DRUMS, DIV_SYSTEM_OPZ, + DIV_SYSTEM_ESFM, 0 // don't remove this last one! }; diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index f6c6310eb..61c815c9d 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -44,6 +44,14 @@ const char* fmParamNames[3][32]={ {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "D2R", "RR", "SL", "TL", "RS", "MULT", "DT", "DT2", "SSG-EG", "AM", "DAM", "DVB", "EGT", "EGS", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM", "EGS", "REV", "Fine", "FMS/PMS2", "AMS2"} }; +const char* esfmParamNames[8]={ + "OP4 Noise Mode", "Envelope Delay", "Output Level", "Modulation Input Level", "Left Output", "Right Output", "Coarse Tune (semitones)", "Detune" +}; + +const char* esfmParamShortNames[8]={ + "RHY", "DLY", "OL", "MI", "L", "R", "CT", "DT" +}; + const char* fmParamShortNames[3][32]={ {"ALG", "FB", "FMS", "AMS", "A", "D", "D2", "R", "S", "TL", "RS", "ML", "DT", "DT2", "SSG", "AM", "DAM", "DVB", "SUS", "SUS", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM", "EGS", "REV", "Fine", "FMS2", "AMS2"}, {"ALG", "FB", "FMS", "AMS", "A", "D", "SR", "R", "S", "TL", "KS", "ML", "DT", "DT2", "SSG", "AM", "AMD", "FMD", "EGT", "EGT", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM", "EGS", "REV", "Fine", "FMS2", "AMS2"}, @@ -153,6 +161,10 @@ const char* oplDrumNames[4]={ "Snare", "Tom", "Top", "HiHat" }; +const char* esfmNoiseModeNames[4]={ + "Noise disabled", "Snare (square + noise)", "HiHat (ringmod from OP3, + noise)", "Top (ringmod from OP3)" +}; + const bool opIsOutput[8][4]={ {false,false,false,true}, {false,false,false,true}, @@ -206,8 +218,21 @@ enum FMParams { FM_AMS2=31 }; +enum ESFMParams { + ESFM_NOISE=0, + ESFM_DELAY=1, + ESFM_OUTLVL=2, + ESFM_MODIN=3, + ESFM_LEFT=4, + ESFM_RIGHT=5, + ESFM_CT=6, + ESFM_DT=7 +}; + #define FM_NAME(x) fmParamNames[settings.fmNames][x] #define FM_SHORT_NAME(x) fmParamShortNames[settings.fmNames][x] +#define ESFM_NAME(x) (esfmParamNames[x]) +#define ESFM_SHORT_NAME(x) (esfmParamShortNames[x]) const char* macroTypeLabels[4]={ ICON_FA_BAR_CHART "##IMacroType", @@ -2951,7 +2976,7 @@ void FurnaceGUI::drawInsEdit() { if (ImGui::BeginTabBar("insEditTab")) { std::vector macroList; - if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPM) { + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPM || ins->type==DIV_INS_ESFM) { char label[32]; int opCount=4; if (ins->type==DIV_INS_OPLL) opCount=2; @@ -2985,171 +3010,205 @@ void FurnaceGUI::drawInsEdit() { } } - if (ImGui::BeginTable("fmDetails",3,ImGuiTableFlags_SizingStretchSame)) { - ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); - ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); - ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.0); + if (ins->type!=DIV_INS_ESFM) { + if (ImGui::BeginTable("fmDetails",3,ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); + ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.0); - ImGui::TableNextRow(); - switch (ins->type) { - case DIV_INS_FM: - case DIV_INS_OPM: - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - } - kvsConfig(ins); - break; - case DIV_INS_OPZ: - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_FMS2),ImGuiDataType_U8,&ins->fm.fms2,&_ZERO,&_SEVEN)); rightClickable - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable - P(CWSliderScalar(FM_NAME(FM_AMS2),ImGuiDataType_U8,&ins->fm.ams2,&_ZERO,&_THREE)); rightClickable - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - } - kvsConfig(ins); - - if (ImGui::Button("Request from TX81Z")) { - doAction(GUI_ACTION_TX81Z_REQUEST); - } - /* - ImGui::SameLine(); - if (ImGui::Button("Send to TX81Z")) { - showError("Coming soon!"); - } - */ - break; - case DIV_INS_OPL: - case DIV_INS_OPL_DRUMS: { - bool fourOp=(ins->fm.ops==4 || ins->type==DIV_INS_OPL_DRUMS); - bool drums=ins->fm.opllPreset==16; - int algMax=fourOp?3:1; - ImGui::TableNextColumn(); - ins->fm.alg&=algMax; - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable - if (ins->type==DIV_INS_OPL) { - ImGui::BeginDisabled(ins->fm.opllPreset==16); - if (ImGui::Checkbox("4-op",&fourOp)) { PARAMETER - ins->fm.ops=fourOp?4:2; - } - ImGui::EndDisabled(); - } - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&algMax)); rightClickable - if (ins->type==DIV_INS_OPL) { - if (ImGui::Checkbox("Drums",&drums)) { PARAMETER - ins->fm.opllPreset=drums?16:0; - } - } - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(ins->fm.alg&algMax,fourOp?FM_ALGS_4OP_OPL:FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - } - kvsConfig(ins); - break; - } - case DIV_INS_OPLL: { - bool dc=fmOrigin.fms; - bool dm=fmOrigin.ams; - bool sus=ins->fm.alg; - ImGui::TableNextColumn(); - ImGui::BeginDisabled(ins->fm.opllPreset!=0); - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&fmOrigin.fb,&_ZERO,&_SEVEN)); rightClickable - if (ImGui::Checkbox(FM_NAME(FM_DC),&dc)) { PARAMETER - fmOrigin.fms=dc; - } - ImGui::EndDisabled(); - ImGui::TableNextColumn(); - if (ImGui::Checkbox(FM_NAME(FM_SUS),&sus)) { PARAMETER - ins->fm.alg=sus; - } - ImGui::BeginDisabled(ins->fm.opllPreset!=0); - if (ImGui::Checkbox(FM_NAME(FM_DM),&dm)) { PARAMETER - fmOrigin.ams=dm; - } - ImGui::EndDisabled(); - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(0,FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); - } - kvsConfig(ins,false); - - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - - if (ImGui::BeginCombo("##LLPreset",opllInsNames[presentWhich][ins->fm.opllPreset])) { - if (isPresentCount>1) { - if (ImGui::BeginTable("LLPresetList",isPresentCount)) { - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - for (int i=0; i<4; i++) { - if (!isPresent[i]) continue; - ImGui::TableNextColumn(); - ImGui::Text("%s name",opllVariants[i]); - } - for (int i=0; i<17; i++) { - ImGui::TableNextRow(); - for (int j=0; j<4; j++) { - if (!isPresent[j]) continue; - ImGui::TableNextColumn(); - ImGui::PushID(j*17+i); - if (ImGui::Selectable(opllInsNames[j][i])) { - ins->fm.opllPreset=i; - } - ImGui::PopID(); - } - } - ImGui::EndTable(); + ImGui::TableNextRow(); + switch (ins->type) { + case DIV_INS_FM: + case DIV_INS_OPM: + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; } } else { - for (int i=0; i<17; i++) { - if (ImGui::Selectable(opllInsNames[presentWhich][i])) { - ins->fm.opllPreset=i; - } + drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + } + kvsConfig(ins); + break; + case DIV_INS_OPZ: + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_FMS2),ImGuiDataType_U8,&ins->fm.fms2,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable + P(CWSliderScalar(FM_NAME(FM_AMS2),ImGuiDataType_U8,&ins->fm.ams2,&_ZERO,&_THREE)); rightClickable + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; + } + } else { + drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + } + kvsConfig(ins); + + if (ImGui::Button("Request from TX81Z")) { + doAction(GUI_ACTION_TX81Z_REQUEST); + } + /* + ImGui::SameLine(); + if (ImGui::Button("Send to TX81Z")) { + showError("Coming soon!"); + } + */ + break; + case DIV_INS_OPL: + case DIV_INS_OPL_DRUMS: { + bool fourOp=(ins->fm.ops==4 || ins->type==DIV_INS_OPL_DRUMS); + bool drums=ins->fm.opllPreset==16; + int algMax=fourOp?3:1; + ImGui::TableNextColumn(); + ins->fm.alg&=algMax; + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable + if (ins->type==DIV_INS_OPL) { + ImGui::BeginDisabled(ins->fm.opllPreset==16); + if (ImGui::Checkbox("4-op",&fourOp)) { PARAMETER + ins->fm.ops=fourOp?4:2; + } + ImGui::EndDisabled(); + } + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&algMax)); rightClickable + if (ins->type==DIV_INS_OPL) { + if (ImGui::Checkbox("Drums",&drums)) { PARAMETER + ins->fm.opllPreset=drums?16:0; } } - ImGui::EndCombo(); + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; + } + } else { + drawAlgorithm(ins->fm.alg&algMax,fourOp?FM_ALGS_4OP_OPL:FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + } + kvsConfig(ins); + break; } - break; + case DIV_INS_OPLL: { + bool dc=fmOrigin.fms; + bool dm=fmOrigin.ams; + bool sus=ins->fm.alg; + ImGui::TableNextColumn(); + ImGui::BeginDisabled(ins->fm.opllPreset!=0); + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&fmOrigin.fb,&_ZERO,&_SEVEN)); rightClickable + if (ImGui::Checkbox(FM_NAME(FM_DC),&dc)) { PARAMETER + fmOrigin.fms=dc; + } + ImGui::EndDisabled(); + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_NAME(FM_SUS),&sus)) { PARAMETER + ins->fm.alg=sus; + } + ImGui::BeginDisabled(ins->fm.opllPreset!=0); + if (ImGui::Checkbox(FM_NAME(FM_DM),&dm)) { PARAMETER + fmOrigin.ams=dm; + } + ImGui::EndDisabled(); + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; + } + } else { + drawAlgorithm(0,FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); + } + kvsConfig(ins,false); + + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + + if (ImGui::BeginCombo("##LLPreset",opllInsNames[presentWhich][ins->fm.opllPreset])) { + if (isPresentCount>1) { + if (ImGui::BeginTable("LLPresetList",isPresentCount)) { + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + for (int i=0; i<4; i++) { + if (!isPresent[i]) continue; + ImGui::TableNextColumn(); + ImGui::Text("%s name",opllVariants[i]); + } + for (int i=0; i<17; i++) { + ImGui::TableNextRow(); + for (int j=0; j<4; j++) { + if (!isPresent[j]) continue; + ImGui::TableNextColumn(); + ImGui::PushID(j*17+i); + if (ImGui::Selectable(opllInsNames[j][i])) { + ins->fm.opllPreset=i; + } + ImGui::PopID(); + } + } + ImGui::EndTable(); + } + } else { + for (int i=0; i<17; i++) { + if (ImGui::Selectable(opllInsNames[presentWhich][i])) { + ins->fm.opllPreset=i; + } + } + } + ImGui::EndCombo(); + } + break; + } + case DIV_INS_ESFM: { + // unreachable + break; + } + default: + break; } - default: - break; + ImGui::EndTable(); + } + } else { + // ESFM + if (ImGui::BeginTable("fmDetails",3,ImGuiTableFlags_SizingStretchProp)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.50f); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.15f); + ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.35f); + + ImGui::TableNextRow(); + { + ImGui::TableNextColumn(); + P(CWSliderScalar(ESFM_NAME(ESFM_NOISE),ImGuiDataType_U8,&ins->esfm.noise,&_ZERO,&_THREE)); rightClickable + ImGui::TextUnformatted(esfmNoiseModeNames[ins->esfm.noise&3]); + ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; + } + } else { + //drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + ImGui::TextUnformatted("TODO: implement fancy ESFM\nauto algorithm drawing"); + } + kvsConfig(ins); + } + ImGui::EndTable(); } - ImGui::EndTable(); } if (((ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPL) && ins->fm.opllPreset==16) || ins->type==DIV_INS_OPL_DRUMS) { @@ -3236,9 +3295,15 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_OPL ||ins->type==DIV_INS_OPL_DRUMS) numCols=13; if (ins->type==DIV_INS_OPLL) numCols=12; if (ins->type==DIV_INS_OPZ) numCols=19; + if (ins->type==DIV_INS_ESFM) numCols=19; if (ImGui::BeginTable("FMOperators",numCols,ImGuiTableFlags_SizingStretchProp|ImGuiTableFlags_BordersH|ImGuiTableFlags_BordersOuterV)) { // configure columns ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed); // op name + if (ins->type==DIV_INS_ESFM) { + ImGui::TableSetupColumn("c0e0",ImGuiTableColumnFlags_WidthStretch,0.05f); // outLvl + ImGui::TableSetupColumn("c0e1",ImGuiTableColumnFlags_WidthFixed); // -separator- + ImGui::TableSetupColumn("c0e2",ImGuiTableColumnFlags_WidthStretch,0.05f); // delay + } ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.05f); // ar ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.05f); // dr ImGui::TableSetupColumn("c3",ImGuiTableColumnFlags_WidthStretch,0.05f); // sl @@ -3253,13 +3318,20 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableSetupColumn("c8z0",ImGuiTableColumnFlags_WidthStretch,0.05f); // egs ImGui::TableSetupColumn("c8z1",ImGuiTableColumnFlags_WidthStretch,0.05f); // rev } + if (ins->type==DIV_INS_ESFM) { + ImGui::TableSetupColumn("c8e0",ImGuiTableColumnFlags_WidthStretch,0.05f); // outLvl + } ImGui::TableSetupColumn("c9",ImGuiTableColumnFlags_WidthStretch,0.05f); // mult if (ins->type==DIV_INS_OPZ) { ImGui::TableSetupColumn("c9z",ImGuiTableColumnFlags_WidthStretch,0.05f); // fine } - if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { + if (ins->type==DIV_INS_ESFM) { + ImGui::TableSetupColumn("c9e",ImGuiTableColumnFlags_WidthStretch,0.05f); // ct + } + + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM || ins->type==DIV_INS_ESFM) { ImGui::TableSetupColumn("c10",ImGuiTableColumnFlags_WidthStretch,0.05f); // dt } if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { @@ -3276,7 +3348,17 @@ void FurnaceGUI::drawInsEdit() { // header ImGui::TableNextRow(ImGuiTableRowFlags_Headers); ImGui::TableNextColumn(); - + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextColumn(); + CENTER_TEXT(ESFM_SHORT_NAME(ESFM_MODIN)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_MODIN)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_MODIN)); + ImGui::TableNextColumn(); + ImGui::TableNextColumn(); + CENTER_TEXT(ESFM_SHORT_NAME(ESFM_DELAY)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_DELAY)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_DELAY)); + } ImGui::TableNextColumn(); CENTER_TEXT(FM_SHORT_NAME(FM_AR)); ImGui::TextUnformatted(FM_SHORT_NAME(FM_AR)); @@ -3332,6 +3414,12 @@ void FurnaceGUI::drawInsEdit() { ImGui::TextUnformatted(FM_SHORT_NAME(FM_REV)); TOOLTIP_TEXT(FM_NAME(FM_REV)); } + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextColumn(); + CENTER_TEXT(ESFM_SHORT_NAME(ESFM_OUTLVL)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_OUTLVL)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_OUTLVL)); + } ImGui::TableNextColumn(); CENTER_TEXT(FM_SHORT_NAME(FM_MULT)); ImGui::TextUnformatted(FM_SHORT_NAME(FM_MULT)); @@ -3342,6 +3430,12 @@ void FurnaceGUI::drawInsEdit() { ImGui::TextUnformatted(FM_SHORT_NAME(FM_FINE)); TOOLTIP_TEXT(FM_NAME(FM_FINE)); } + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextColumn(); + CENTER_TEXT(ESFM_SHORT_NAME(ESFM_CT)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_CT)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_CT)); + } ImGui::TableNextColumn(); if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { CENTER_TEXT(FM_SHORT_NAME(FM_DT)); @@ -3349,6 +3443,12 @@ void FurnaceGUI::drawInsEdit() { TOOLTIP_TEXT(FM_NAME(FM_DT)); ImGui::TableNextColumn(); } + if (ins->type==DIV_INS_ESFM) { + CENTER_TEXT(ESFM_SHORT_NAME(ESFM_DT)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_DT)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_DT)); + ImGui::TableNextColumn(); + } if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { CENTER_TEXT(FM_SHORT_NAME(FM_DT2)); ImGui::TextUnformatted(FM_SHORT_NAME(FM_DT2)); @@ -3364,7 +3464,7 @@ void FurnaceGUI::drawInsEdit() { ImGui::TextUnformatted("Other"); } ImGui::TableNextColumn(); - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_ESFM) { ImGui::TableNextColumn(); CENTER_TEXT(FM_NAME(FM_WS)); ImGui::TextUnformatted(FM_NAME(FM_WS)); @@ -3381,6 +3481,8 @@ void FurnaceGUI::drawInsEdit() { for (int i=0; itype!=DIV_INS_OPL_DRUMS)?opOrder[i]:i]; + DivInstrumentESFM::Operator& opE=ins->esfm.op[i]; + ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -3389,6 +3491,17 @@ void FurnaceGUI::drawInsEdit() { bool mod=true; if (ins->type==DIV_INS_OPL_DRUMS) { mod=false; + } else if (ins->type==DIV_INS_ESFM) { + // this is the same as the KVS heuristic in platform/esfm.h + if (opE.outLvl==7) mod=false; + else if (opE.outLvl>0) { + if (i==3) mod=false; + else { + DivInstrumentESFM::Operator& opENext=ins->esfm.op[i+1]; + if (opENext.modIn==0) mod=false; + else if ((opE.outLvl-opENext.modIn) >= 2) mod=false; + } + } } else if (opCount==4) { if (ins->type==DIV_INS_OPL) { if (opIsOutputOPL[fmOrigin.alg&3][i]) mod=false; @@ -3440,7 +3553,7 @@ void FurnaceGUI::drawInsEdit() { } else { ImGui::TextUnformatted(opNameLabel.c_str()); } - + // drag point OP_DRAG_POINT; @@ -3452,7 +3565,7 @@ void FurnaceGUI::drawInsEdit() { maxTl=63; } } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_ESFM) { maxTl=63; } int maxArDr=(ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM)?31:15; @@ -3461,6 +3574,18 @@ void FurnaceGUI::drawInsEdit() { bool vibOn=op.vib; bool susOn=op.sus; unsigned char ssgEnv=op.ssgEnv&7; + + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextColumn(); + CENTER_VSLIDER; + P(CWVSliderScalar("##MODIN",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&opE.modIn,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + ImGui::Dummy(ImVec2(4.0f*dpiScale,2.0f*dpiScale)); + ImGui::TableNextColumn(); + opE.delay&=7; + CENTER_VSLIDER; + P(CWVSliderScalar("##DELAY",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&opE.delay,&_ZERO,&_SEVEN)); rightClickable + } ImGui::TableNextColumn(); op.ar&=maxArDr; @@ -3528,6 +3653,12 @@ void FurnaceGUI::drawInsEdit() { P(CWVSliderScalar("##REV",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&op.dam,&_ZERO,&_SEVEN)); rightClickable } + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextColumn(); + CENTER_VSLIDER; + P(CWVSliderScalar("##OUTLVL",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&opE.outLvl,&_ZERO,&_SEVEN)); rightClickable + } + ImGui::TableNextColumn(); CENTER_VSLIDER; P(CWVSliderScalar("##MULT",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&op.mult,&_ZERO,&_FIFTEEN)); rightClickable @@ -3538,6 +3669,12 @@ void FurnaceGUI::drawInsEdit() { P(CWVSliderScalar("##FINE",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&op.dvb,&_ZERO,&_FIFTEEN)); rightClickable } + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextColumn(); + CENTER_VSLIDER; + P(CWVSliderScalar("##CT",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_S8,&opE.ct,&_MINUS_TWELVE,&_TWELVE)); rightClickable + } + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { int detune=detuneMap[settings.unsignedDetune?1:0][op.dt&7]; ImGui::TableNextColumn(); @@ -3608,6 +3745,42 @@ void FurnaceGUI::drawInsEdit() { op.ssgEnv=(op.ssgEnv&8)|(ssgEnv&7); } } + } else if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextColumn(); + CENTER_VSLIDER; + P(CWVSliderScalar("##DT",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_S8,&opE.dt,&_MINUS_ONE_HUNDRED_TWENTY_EIGHT,&_ONE_HUNDRED_TWENTY_SEVEN)); rightClickable + + ImGui::TableNextColumn(); + bool amOn=op.am; + bool leftOn=opE.left; + bool rightOn=opE.right; + if (ImGui::BeginTable("panCheckboxes",2,ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::Checkbox(ESFM_SHORT_NAME(ESFM_LEFT),&leftOn)) { PARAMETER + opE.left=leftOn; + } + ImGui::TableNextColumn(); + if (ImGui::Checkbox(ESFM_SHORT_NAME(ESFM_RIGHT),&rightOn)) { PARAMETER + opE.right=rightOn; + } + ImGui::EndTable(); + } + if (ImGui::Checkbox(FM_NAME(FM_AM),&amOn)) { PARAMETER + op.am=amOn; + } + if (ImGui::Checkbox(FM_NAME(FM_VIB),&vibOn)) { PARAMETER + op.vib=vibOn; + } + if (ImGui::Checkbox(FM_NAME(FM_KSR),&ksrOn)) { PARAMETER + op.ksr=ksrOn; + } + if (ImGui::Checkbox(FM_NAME(FM_SUS),&susOn)) { PARAMETER + op.sus=susOn; + } } else if (ins->type!=DIV_INS_OPM) { ImGui::TableNextColumn(); bool amOn=op.am; @@ -3632,7 +3805,7 @@ void FurnaceGUI::drawInsEdit() { } } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_ESFM) { ImGui::TableNextColumn(); ImGui::Dummy(ImVec2(4.0f*dpiScale,2.0f*dpiScale)); ImGui::TableNextColumn(); diff --git a/src/gui/intConst.cpp b/src/gui/intConst.cpp index 167fdd7e8..cf0140e23 100644 --- a/src/gui/intConst.cpp +++ b/src/gui/intConst.cpp @@ -24,6 +24,7 @@ const int _ONE=1; const int _THREE=3; const int _SEVEN=7; const int _TEN=10; +const int _TWELVE=12; const int _FIFTEEN=15; const int _SIXTEEN=16; const int _THIRTY_ONE=31; @@ -35,5 +36,6 @@ const int _FIVE_HUNDRED_ELEVEN=511; const int _TWO_THOUSAND_FORTY_SEVEN=2047; const int _FOUR_THOUSAND_NINETY_FIVE=4095; const int _SIXTY_FIVE_THOUSAND_FIVE_HUNDRED_THIRTY_FIVE=65535; +const int _MINUS_TWELVE=-12; const int _MINUS_ONE_HUNDRED_TWENTY_SEVEN=-127; const int _MINUS_ONE_HUNDRED_TWENTY_EIGHT=-128; diff --git a/src/gui/intConst.h b/src/gui/intConst.h index 082f421a7..18c4ae556 100644 --- a/src/gui/intConst.h +++ b/src/gui/intConst.h @@ -26,6 +26,7 @@ extern const int _ONE; extern const int _THREE; extern const int _SEVEN; extern const int _TEN; +extern const int _TWELVE; extern const int _FIFTEEN; extern const int _SIXTEEN; extern const int _THIRTY_ONE; @@ -37,5 +38,6 @@ extern const int _FIVE_HUNDRED_ELEVEN; extern const int _TWO_THOUSAND_FORTY_SEVEN; extern const int _FOUR_THOUSAND_NINETY_FIVE; extern const int _SIXTY_FIVE_THOUSAND_FIVE_HUNDRED_THIRTY_FIVE; +extern const int _MINUS_TWELVE; extern const int _MINUS_ONE_HUNDRED_TWENTY_SEVEN; extern const int _MINUS_ONE_HUNDRED_TWENTY_EIGHT; From 696433c7846cba7b9f3ab1a405889ab9064e2462 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sat, 14 Oct 2023 09:10:42 -0300 Subject: [PATCH 02/34] Fix operator order in GUI for ESFM --- CMakeLists.txt | 2 -- src/gui/insEdit.cpp | 16 ++++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7a2a3dd9..57dec2fc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,5 @@ cmake_minimum_required(VERSION 3.0) -set(CMAKE_EXPORT_COMPILE_COMMANDS on) - if (APPLE) set(MACOSX_DEPLOYMENT_TARGET 10.9) endif() diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 61c815c9d..c861d93b6 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -3480,7 +3480,7 @@ void FurnaceGUI::drawInsEdit() { float sliderHeight=32.0f*dpiScale; for (int i=0; itype!=DIV_INS_OPL_DRUMS)?opOrder[i]:i]; + DivInstrumentFM::Operator& op=fmOrigin.op[(opCount==4 && ins->type!=DIV_INS_OPL_DRUMS && ins->type!=DIV_INS_ESFM)?opOrder[i]:i]; DivInstrumentESFM::Operator& opE=ins->esfm.op[i]; ImGui::TableNextRow(); @@ -3851,7 +3851,8 @@ void FurnaceGUI::drawInsEdit() { ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(8.0f*dpiScale,4.0f*dpiScale)); if (ImGui::BeginTable("AltFMOperators",columns,ImGuiTableFlags_SizingStretchSame|ImGuiTableFlags_BordersInner)) { for (int i=0; itype!=DIV_INS_OPL_DRUMS)?opOrder[i]:i]; + DivInstrumentFM::Operator& op=fmOrigin.op[(opCount==4 && ins->type!=DIV_INS_OPL_DRUMS && ins->type!=DIV_INS_ESFM)?opOrder[i]:i]; + DivInstrumentESFM::Operator& opE=ins->esfm.op[i]; if ((settings.fmLayout!=6 && ((i+1)&1)) || i==0 || settings.fmLayout==5) ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::PushID(fmt::sprintf("op%d",i).c_str()); @@ -3861,6 +3862,17 @@ void FurnaceGUI::drawInsEdit() { bool mod=true; if (ins->type==DIV_INS_OPL_DRUMS) { mod=false; + } else if (ins->type==DIV_INS_ESFM) { + // this is the same as the KVS heuristic in platform/esfm.h + if (opE.outLvl==7) mod=false; + else if (opE.outLvl>0) { + if (i==3) mod=false; + else { + DivInstrumentESFM::Operator& opENext=ins->esfm.op[i+1]; + if (opENext.modIn==0) mod=false; + else if ((opE.outLvl-opENext.modIn) >= 2) mod=false; + } + } } else if (opCount==4) { if (ins->type==DIV_INS_OPL) { if (opIsOutputOPL[fmOrigin.alg&3][i]) mod=false; From 6733f4d1f4bd640023c1b3208caee696b5f5ea16 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sat, 14 Oct 2023 14:00:31 -0300 Subject: [PATCH 03/34] Adding alternate layout for ESFM --- src/gui/insEdit.cpp | 178 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 161 insertions(+), 17 deletions(-) diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index c861d93b6..002d6d9af 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -44,12 +44,12 @@ const char* fmParamNames[3][32]={ {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "D2R", "RR", "SL", "TL", "RS", "MULT", "DT", "DT2", "SSG-EG", "AM", "DAM", "DVB", "EGT", "EGS", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM", "EGS", "REV", "Fine", "FMS/PMS2", "AMS2"} }; -const char* esfmParamNames[8]={ - "OP4 Noise Mode", "Envelope Delay", "Output Level", "Modulation Input Level", "Left Output", "Right Output", "Coarse Tune (semitones)", "Detune" +const char* esfmParamNames[9]={ + "OP4 Noise Mode", "Envelope Delay", "Output Level", "Modulation Input Level", "Left Output", "Right Output", "Coarse Tune (semitones)", "Coarse Tn.", "Detune" }; -const char* esfmParamShortNames[8]={ - "RHY", "DLY", "OL", "MI", "L", "R", "CT", "DT" +const char* esfmParamShortNames[9]={ + "RHY", "DL", "OL", "MI", "L", "R", "CT", "CT", "DT" }; const char* fmParamShortNames[3][32]={ @@ -226,7 +226,8 @@ enum ESFMParams { ESFM_LEFT=4, ESFM_RIGHT=5, ESFM_CT=6, - ESFM_DT=7 + ESFM_CT_SHORT=7, + ESFM_DT=8 }; #define FM_NAME(x) fmParamNames[settings.fmNames][x] @@ -3927,8 +3928,8 @@ void FurnaceGUI::drawInsEdit() { } float sliderHeight=200.0f*dpiScale; - float waveWidth=140.0*dpiScale; - float waveHeight=sliderHeight-ImGui::GetFrameHeightWithSpacing()*((ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPL)?5.0f:4.5f); + float waveWidth=140.0*dpiScale*((ins->type==DIV_INS_ESFM)?0.8f:1.0f); + float waveHeight=sliderHeight-ImGui::GetFrameHeightWithSpacing()*((ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPL || ins->type==DIV_INS_ESFM)?5.0f:4.5f); int maxTl=127; if (ins->type==DIV_INS_OPLL) { @@ -3938,7 +3939,7 @@ void FurnaceGUI::drawInsEdit() { maxTl=63; } } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_ESFM) { maxTl=63; } int maxArDr=(ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM)?31:15; @@ -3960,9 +3961,15 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextRow(); ImGui::TableNextColumn(); float textY=ImGui::GetCursorPosY(); - CENTER_TEXT_20(FM_SHORT_NAME(FM_AR)); - ImGui::TextUnformatted(FM_SHORT_NAME(FM_AR)); - TOOLTIP_TEXT(FM_NAME(FM_AR)); + if (ins->type==DIV_INS_ESFM) { + CENTER_TEXT_20(ESFM_SHORT_NAME(ESFM_DELAY)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_DELAY)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_DELAY)); + } else { + CENTER_TEXT_20(FM_SHORT_NAME(FM_AR)); + ImGui::TextUnformatted(FM_SHORT_NAME(FM_AR)); + TOOLTIP_TEXT(FM_NAME(FM_AR)); + } ImGui::TableNextColumn(); if (ins->type==DIV_INS_FM) { ImGui::Text("SSG-EG"); @@ -3972,14 +3979,18 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); ImGui::Text("Envelope"); ImGui::TableNextColumn(); - CENTER_TEXT(FM_SHORT_NAME(FM_TL)); - ImGui::TextUnformatted(FM_SHORT_NAME(FM_TL)); - TOOLTIP_TEXT(FM_NAME(FM_TL)); // A/D/S/R ImGui::TableNextColumn(); + if (ins->type==DIV_INS_ESFM) { + opE.delay&=7; + P(CWVSliderScalar("##DELAY",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&opE.delay,&_ZERO,&_SEVEN)); rightClickable + ImGui::SameLine(); + } + op.ar&=maxArDr; + float textX_AR=ImGui::GetCursorPosX(); P(CWVSliderScalar("##AR",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_U8,&op.ar,&maxArDr,&_ZERO)); rightClickable ImGui::SameLine(); @@ -4016,8 +4027,15 @@ void FurnaceGUI::drawInsEdit() { } ImVec2 prevCurPos=ImGui::GetCursorPos(); - + // labels + if (ins->type==DIV_INS_ESFM) { + ImGui::SetCursorPos(ImVec2(textX_AR,textY)); + CENTER_TEXT_20(FM_SHORT_NAME(FM_AR)); + ImGui::TextUnformatted(FM_SHORT_NAME(FM_AR)); + TOOLTIP_TEXT(FM_NAME(FM_AR)); + } + ImGui::SetCursorPos(ImVec2(textX_DR,textY)); CENTER_TEXT_20(FM_SHORT_NAME(FM_DR)); ImGui::TextUnformatted(FM_SHORT_NAME(FM_DR)); @@ -4259,13 +4277,54 @@ void FurnaceGUI::drawInsEdit() { P(CWSliderScalar("##RS",ImGuiDataType_U8,&op.rs,&_ZERO,&_THREE,tempID)); rightClickable break; } + case DIV_INS_ESFM: + // waveform + drawWaveform(op.ws&7,ins->type==DIV_INS_OPZ,ImVec2(waveWidth,waveHeight)); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(CWSliderScalar("##WS",ImGuiDataType_U8,&op.ws,&_ZERO,&_SEVEN,(ins->type==DIV_INS_OPZ)?opzWaveforms[op.ws&7]:(settings.oplStandardWaveNames?oplWaveformsStandard[op.ws&7]:oplWaveforms[op.ws&7]))); rightClickable + + // params + ImGui::Separator(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + snprintf(tempID,1024,"%s: %%d",FM_NAME(FM_MULT)); + P(CWSliderScalar("##MULT",ImGuiDataType_U8,&op.mult,&_ZERO,&_FIFTEEN,tempID)); rightClickable + + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_CT_SHORT)); + P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWELVE,&_TWELVE,tempID)); rightClickable + + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_DT)); + P(CWSliderScalar("##DT",ImGuiDataType_S8,&opE.dt,&_MINUS_ONE_HUNDRED_TWENTY_EIGHT,&_ONE_HUNDRED_TWENTY_SEVEN,tempID)); rightClickable + + if (ImGui::BeginTable("panCheckboxes",2,ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0f); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0f); + + float yPosOutsideTablePadding=ImGui::GetCursorPosY(); + bool leftOn=opE.left; + bool rightOn=opE.right; + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yPosOutsideTablePadding); + if (ImGui::Checkbox(ESFM_SHORT_NAME(ESFM_LEFT),&leftOn)) { PARAMETER + opE.left=leftOn; + } + ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yPosOutsideTablePadding); + if (ImGui::Checkbox(ESFM_SHORT_NAME(ESFM_RIGHT),&rightOn)) { PARAMETER + opE.right=rightOn; + } + ImGui::EndTable(); + } + break; default: break; } ImGui::TableNextColumn(); float envHeight=sliderHeight;//-ImGui::GetStyle().ItemSpacing.y*2.0f; - if (ins->type==DIV_INS_OPZ) { + if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_ESFM) { envHeight-=ImGui::GetFrameHeightWithSpacing()*2.0f; } drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,envHeight),ins->type); @@ -4309,9 +4368,58 @@ void FurnaceGUI::drawInsEdit() { } } + if (ins->type==DIV_INS_ESFM) { + ImGui::Separator(); + if (ImGui::BeginTable("FMParamsInnerESFM",2)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.64f); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.36f); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + snprintf(tempID,1024,"%s: %%d",FM_SHORT_NAME(FM_KSL)); + P(CWSliderScalar("##KSL",ImGuiDataType_U8,&op.ksl,&_ZERO,&_THREE,tempID)); rightClickable + + bool amOn=op.am; + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_KSR),&ksrOn)) { PARAMETER + op.ksr=ksrOn; + } + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::BeginTable("vibAmCheckboxes",2)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0f); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0f); + + float yPosOutsideTablePadding=ImGui::GetCursorPosY(); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yPosOutsideTablePadding); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_VIB),&vibOn)) { PARAMETER + op.vib=vibOn; + } + ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yPosOutsideTablePadding); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_AM),&amOn)) { PARAMETER + op.am=amOn; + } + ImGui::EndTable(); + } + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_SUS),&susOn)) { PARAMETER + op.sus=susOn; + } + + ImGui::EndTable(); + } + } + ImGui::TableNextColumn(); op.tl&=maxTl; - P(CWVSliderScalar("##TL",ImVec2(ImGui::GetFrameHeight(),sliderHeight-((ins->type==DIV_INS_FM || ins->type==DIV_INS_OPM)?(ImGui::GetFrameHeightWithSpacing()+ImGui::CalcTextSize(FM_SHORT_NAME(FM_AM)).y+ImGui::GetStyle().ItemSpacing.y):0.0f)),ImGuiDataType_U8,&op.tl,&maxTl,&_ZERO)); rightClickable + float tlSliderWidth=(ins->type==DIV_INS_ESFM)?20.0f*dpiScale:ImGui::GetFrameHeight(); + float tlSliderHeight=sliderHeight-((ins->type==DIV_INS_FM || ins->type==DIV_INS_OPM)?(ImGui::GetFrameHeightWithSpacing()+ImGui::CalcTextSize(FM_SHORT_NAME(FM_AM)).y+ImGui::GetStyle().ItemSpacing.y):0.0f); + float textX_tl=ImGui::GetCursorPosX(); + P(CWVSliderScalar("##TL",ImVec2(tlSliderWidth,tlSliderHeight),ImGuiDataType_U8,&op.tl,&maxTl,&_ZERO)); rightClickable if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPM) { CENTER_TEXT(FM_SHORT_NAME(FM_AM)); @@ -4323,6 +4431,42 @@ void FurnaceGUI::drawInsEdit() { } } + if (ins->type==DIV_INS_ESFM) { + ImGui::SameLine(); + float textX_outLvl=ImGui::GetCursorPosX(); + P(CWVSliderScalar("##OUTLVL",ImVec2(tlSliderWidth,tlSliderHeight),ImGuiDataType_U8,&opE.outLvl,&_ZERO,&_SEVEN)); rightClickable + + ImGui::SameLine(); + float textX_modIn=ImGui::GetCursorPosX(); + P(CWVSliderScalar("##MODIN",ImVec2(tlSliderWidth,tlSliderHeight),ImGuiDataType_U8,&opE.modIn,&_ZERO,&_SEVEN)); rightClickable + + prevCurPos=ImGui::GetCursorPos(); + ImGui::SetCursorPos(ImVec2(textX_tl,textY)); + CENTER_TEXT_20(FM_SHORT_NAME(FM_TL)); + ImGui::TextUnformatted(FM_SHORT_NAME(FM_TL)); + TOOLTIP_TEXT(FM_NAME(FM_TL)); + + ImGui::SetCursorPos(ImVec2(textX_outLvl,textY)); + CENTER_TEXT_20(ESFM_SHORT_NAME(ESFM_OUTLVL)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_OUTLVL)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_OUTLVL)); + + ImGui::SetCursorPos(ImVec2(textX_modIn,textY)); + CENTER_TEXT_20(ESFM_SHORT_NAME(ESFM_MODIN)); + ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_MODIN)); + TOOLTIP_TEXT(ESFM_NAME(ESFM_MODIN)); + + ImGui::SetCursorPos(prevCurPos); + } else { + prevCurPos=ImGui::GetCursorPos(); + ImGui::SetCursorPos(ImVec2(textX_tl,textY)); + CENTER_TEXT(FM_SHORT_NAME(FM_TL)); + ImGui::TextUnformatted(FM_SHORT_NAME(FM_TL)); + TOOLTIP_TEXT(FM_NAME(FM_TL)); + + ImGui::SetCursorPos(prevCurPos); + } + ImGui::EndTable(); } ImGui::PopStyleVar(); From cfa0628a32127fbb1b3b85276ad709e3a5eec8b9 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sat, 14 Oct 2023 17:07:34 -0300 Subject: [PATCH 04/34] Removing unused code --- src/engine/instrument.h | 53 ----------------------------------------- 1 file changed, 53 deletions(-) diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 91a6d2a6b..4c1778304 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -802,58 +802,6 @@ struct DivInstrumentESFM { op[3].outLvl=7; } -#if 0 - void syncFrom(DivInstrumentFM &other) { - for (int i=0; i<4; i++) { - this->op[i].am=other.op[i].am; - this->op[i].dam=other.op[i].dam; - this->op[i].ar=other.op[i].ar; - this->op[i].dr=other.op[i].dr; - this->op[i].mult=other.op[i].mult; - this->op[i].rr=other.op[i].rr; - this->op[i].sl=other.op[i].sl; - this->op[i].tl=other.op[i].tl; - this->op[i].ssgEnv=other.op[i].ssgEnv; - this->op[i].ksl=other.op[i].ksl; - this->op[i].vib=other.op[i].vib; - this->op[i].dvb=other.op[i].dvb; - this->op[i].ws=other.op[i].ws; - this->op[i].ksr=other.op[i].ksr; - this->op[i].ct=0; - // from dtTable at fmsharedbase.h - if (other.op[i].dt>=7){ - // trap out of range dt values - // TODO: check if any systems legitimately use dt values higher than 7 - this->op[i].dt=0; - } else { - this->op[i].dt=other.op[i].dt - 3; - } - } - } - - void syncTo(DivInstrumentFM &other) { - for (int i=0; i<4; i++) { - other.op[i].am=this->op[i].am; - other.op[i].dam=this->op[i].dam; - other.op[i].ar=this->op[i].ar; - other.op[i].dr=this->op[i].dr; - other.op[i].mult=this->op[i].mult; - other.op[i].rr=this->op[i].rr; - other.op[i].sl=this->op[i].sl; - other.op[i].tl=this->op[i].tl; - other.op[i].ssgEnv=this->op[i].ssgEnv; - other.op[i].ksl=this->op[i].ksl; - other.op[i].vib=this->op[i].vib; - other.op[i].dvb=this->op[i].dvb; - other.op[i].ws=this->op[i].ws; - other.op[i].ksr=this->op[i].ksr; - // dt field conversion is unfortunately lossy, as the dt field on DivInstrumentFM - // spans from 0..6 (eff. -3..3), while on DivInstrumentESFM it spans from -128..127. - other.op[i].dt=CLAMP(this->op[i].dt, -3, 3) + 3; - } - } -#endif - }; struct DivInstrument { @@ -873,7 +821,6 @@ struct DivInstrument { DivInstrumentES5506 es5506; DivInstrumentSNES snes; DivInstrumentESFM esfm; - // TODO I only added the esfm member here, still need to implement everything else related /** * these are internal functions. From 484b6f4411c43f3d4d71bbf752107f1c9a2daa84 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sat, 14 Oct 2023 17:09:18 -0300 Subject: [PATCH 05/34] Adding classic layout; fixing operator swapping and KSL bit order --- src/gui/insEdit.cpp | 145 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 115 insertions(+), 30 deletions(-) diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 002d6d9af..48b72b72f 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -44,12 +44,16 @@ const char* fmParamNames[3][32]={ {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "D2R", "RR", "SL", "TL", "RS", "MULT", "DT", "DT2", "SSG-EG", "AM", "DAM", "DVB", "EGT", "EGS", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM", "EGS", "REV", "Fine", "FMS/PMS2", "AMS2"} }; -const char* esfmParamNames[9]={ - "OP4 Noise Mode", "Envelope Delay", "Output Level", "Modulation Input Level", "Left Output", "Right Output", "Coarse Tune (semitones)", "Coarse Tn.", "Detune" +const char* esfmParamLongNames[8]={ + "OP4 Noise Mode", "Envelope Delay", "Output Level", "Modulation Input Level", "Left Output", "Right Output", "Coarse Tune (semitones)", "Detune" }; -const char* esfmParamShortNames[9]={ - "RHY", "DL", "OL", "MI", "L", "R", "CT", "CT", "DT" +const char* esfmParamNames[8]={ + "OP4 Noise Mode", "Env. Delay", "Output Level", "ModInput", "Left", "Right", "Coarse Tn.", "Detune" +}; + +const char* esfmParamShortNames[8]={ + "RHY", "DL", "OL", "MI", "L", "R", "CT", "DT" }; const char* fmParamShortNames[3][32]={ @@ -226,12 +230,12 @@ enum ESFMParams { ESFM_LEFT=4, ESFM_RIGHT=5, ESFM_CT=6, - ESFM_CT_SHORT=7, - ESFM_DT=8 + ESFM_DT=7 }; #define FM_NAME(x) fmParamNames[settings.fmNames][x] #define FM_SHORT_NAME(x) fmParamShortNames[settings.fmNames][x] +#define ESFM_LONG_NAME(x) (esfmParamLongNames[x]) #define ESFM_NAME(x) (esfmParamNames[x]) #define ESFM_SHORT_NAME(x) (esfmParamShortNames[x]) @@ -2313,17 +2317,21 @@ void FurnaceGUI::alterSampleMap(int column, int val) { if (dragItem!=NULL) { \ if (dragItem->IsDataType("FUR_OP")) { \ if (opToMove!=i && opToMove>=0) { \ - int destOp=(opCount==4 && ins->type!=DIV_INS_OPL_DRUMS)?opOrder[i]:i; \ - int sourceOp=(opCount==4 && ins->type!=DIV_INS_OPL_DRUMS)?opOrder[opToMove]:opToMove; \ + int destOp=(opCount==4 && ins->type!=DIV_INS_OPL_DRUMS && ins->type!=DIV_INS_ESFM)?opOrder[i]:i; \ + int sourceOp=(opCount==4 && ins->type!=DIV_INS_OPL_DRUMS && ins->type!=DIV_INS_ESFM)?opOrder[opToMove]:opToMove; \ if (ImGui::IsKeyDown(ImGuiKey_LeftShift) || ImGui::IsKeyDown(ImGuiKey_RightShift)) { \ e->lockEngine([ins,destOp,sourceOp]() { \ ins->fm.op[destOp]=ins->fm.op[sourceOp]; \ + ins->esfm.op[destOp]=ins->esfm.op[sourceOp]; \ }); \ } else { \ e->lockEngine([ins,destOp,sourceOp]() { \ DivInstrumentFM::Operator origOp=ins->fm.op[sourceOp]; \ + DivInstrumentESFM::Operator origOpE=ins->esfm.op[sourceOp]; \ ins->fm.op[sourceOp]=ins->fm.op[destOp]; \ + ins->esfm.op[sourceOp]=ins->esfm.op[destOp]; \ ins->fm.op[destOp]=origOp; \ + ins->esfm.op[destOp]=origOpE; \ }); \ } \ PARAMETER; \ @@ -3192,7 +3200,7 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextRow(); { ImGui::TableNextColumn(); - P(CWSliderScalar(ESFM_NAME(ESFM_NOISE),ImGuiDataType_U8,&ins->esfm.noise,&_ZERO,&_THREE)); rightClickable + P(CWSliderScalar(ESFM_LONG_NAME(ESFM_NOISE),ImGuiDataType_U8,&ins->esfm.noise,&_ZERO,&_THREE)); rightClickable ImGui::TextUnformatted(esfmNoiseModeNames[ins->esfm.noise&3]); ImGui::TableNextColumn(); ImGui::TableNextColumn(); @@ -3353,12 +3361,12 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); CENTER_TEXT(ESFM_SHORT_NAME(ESFM_MODIN)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_MODIN)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_MODIN)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_MODIN)); ImGui::TableNextColumn(); ImGui::TableNextColumn(); CENTER_TEXT(ESFM_SHORT_NAME(ESFM_DELAY)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_DELAY)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_DELAY)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_DELAY)); } ImGui::TableNextColumn(); CENTER_TEXT(FM_SHORT_NAME(FM_AR)); @@ -3419,7 +3427,7 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); CENTER_TEXT(ESFM_SHORT_NAME(ESFM_OUTLVL)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_OUTLVL)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_OUTLVL)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_OUTLVL)); } ImGui::TableNextColumn(); CENTER_TEXT(FM_SHORT_NAME(FM_MULT)); @@ -3435,7 +3443,7 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); CENTER_TEXT(ESFM_SHORT_NAME(ESFM_CT)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_CT)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_CT)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_CT)); } ImGui::TableNextColumn(); if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { @@ -3447,7 +3455,7 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_ESFM) { CENTER_TEXT(ESFM_SHORT_NAME(ESFM_DT)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_DT)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_DT)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_DT)); ImGui::TableNextColumn(); } if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { @@ -3823,7 +3831,7 @@ void FurnaceGUI::drawInsEdit() { } ImGui::TableNextColumn(); - drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,sliderHeight),ins->type); + drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_ESFM)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,sliderHeight),ins->type); if (settings.separateFMColors) { popAccentColors(); @@ -3964,7 +3972,7 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_ESFM) { CENTER_TEXT_20(ESFM_SHORT_NAME(ESFM_DELAY)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_DELAY)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_DELAY)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_DELAY)); } else { CENTER_TEXT_20(FM_SHORT_NAME(FM_AR)); ImGui::TextUnformatted(FM_SHORT_NAME(FM_AR)); @@ -4290,7 +4298,7 @@ void FurnaceGUI::drawInsEdit() { P(CWSliderScalar("##MULT",ImGuiDataType_U8,&op.mult,&_ZERO,&_FIFTEEN,tempID)); rightClickable ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_CT_SHORT)); + snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_CT)); P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWELVE,&_TWELVE,tempID)); rightClickable ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); @@ -4327,7 +4335,7 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_ESFM) { envHeight-=ImGui::GetFrameHeightWithSpacing()*2.0f; } - drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,envHeight),ins->type); + drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_ESFM)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,envHeight),ins->type); if (ins->type==DIV_INS_OPZ) { ImGui::Separator(); @@ -4377,8 +4385,12 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - snprintf(tempID,1024,"%s: %%d",FM_SHORT_NAME(FM_KSL)); - P(CWSliderScalar("##KSL",ImGuiDataType_U8,&op.ksl,&_ZERO,&_THREE,tempID)); rightClickable + snprintf(tempID,1024,"%s: %%d",FM_NAME(FM_KSL)); + int ksl=kslMap[op.ksl&3]; + if (CWSliderInt("##KSL",&ksl,0,3,tempID)) { + op.ksl=kslMap[ksl&3]; + PARAMETER; + } rightClickable bool amOn=op.am; ImGui::TableNextColumn(); @@ -4449,12 +4461,12 @@ void FurnaceGUI::drawInsEdit() { ImGui::SetCursorPos(ImVec2(textX_outLvl,textY)); CENTER_TEXT_20(ESFM_SHORT_NAME(ESFM_OUTLVL)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_OUTLVL)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_OUTLVL)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_OUTLVL)); ImGui::SetCursorPos(ImVec2(textX_modIn,textY)); CENTER_TEXT_20(ESFM_SHORT_NAME(ESFM_MODIN)); ImGui::TextUnformatted(ESFM_SHORT_NAME(ESFM_MODIN)); - TOOLTIP_TEXT(ESFM_NAME(ESFM_MODIN)); + TOOLTIP_TEXT(ESFM_LONG_NAME(ESFM_MODIN)); ImGui::SetCursorPos(prevCurPos); } else { @@ -4495,7 +4507,8 @@ void FurnaceGUI::drawInsEdit() { } if (ImGui::BeginTable("FMOperators",columns,ImGuiTableFlags_SizingStretchSame)) { for (int i=0; itype!=DIV_INS_OPL_DRUMS)?opOrder[i]:i]; + DivInstrumentFM::Operator& op=fmOrigin.op[(opCount==4 && ins->type!=DIV_INS_OPL_DRUMS && ins->type!=DIV_INS_ESFM)?opOrder[i]:i]; + DivInstrumentESFM::Operator& opE=ins->esfm.op[i]; if ((settings.fmLayout!=3 && ((i+1)&1)) || i==0 || settings.fmLayout==2) ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Separator(); @@ -4506,6 +4519,17 @@ void FurnaceGUI::drawInsEdit() { bool mod=true; if (ins->type==DIV_INS_OPL_DRUMS) { mod=false; + } else if (ins->type==DIV_INS_ESFM) { + // this is the same as the KVS heuristic in platform/esfm.h + if (opE.outLvl==7) mod=false; + else if (opE.outLvl>0) { + if (i==3) mod=false; + else { + DivInstrumentESFM::Operator& opENext=ins->esfm.op[i+1]; + if (opENext.modIn==0) mod=false; + else if ((opE.outLvl-opENext.modIn) >= 2) mod=false; + } + } } else if (opCount==4) { if (ins->type==DIV_INS_OPL) { if (opIsOutputOPL[fmOrigin.alg&3][i]) mod=false; @@ -4573,7 +4597,7 @@ void FurnaceGUI::drawInsEdit() { maxTl=63; } } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_ESFM) { maxTl=63; } int maxArDr=(ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM)?31:15; @@ -4583,14 +4607,14 @@ void FurnaceGUI::drawInsEdit() { bool vibOn=op.vib; bool susOn=op.sus; // don't you make fun of this one unsigned char ssgEnv=op.ssgEnv&7; - if (ins->type!=DIV_INS_OPL && ins->type!=DIV_INS_OPL_DRUMS && ins->type!=DIV_INS_OPZ && ins->type!=DIV_INS_OPM) { + if (ins->type!=DIV_INS_OPL && ins->type!=DIV_INS_OPL_DRUMS && ins->type!=DIV_INS_OPZ && ins->type!=DIV_INS_OPM && ins->type!=DIV_INS_ESFM) { ImGui::SameLine(); if (ImGui::Checkbox((ins->type==DIV_INS_OPLL)?FM_NAME(FM_EGS):"SSG On",&ssgOn)) { PARAMETER op.ssgEnv=(op.ssgEnv&7)|(ssgOn<<3); } } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_ESFM) { ImGui::SameLine(); if (ImGui::Checkbox(FM_NAME(FM_SUS),&susOn)) { PARAMETER op.sus=susOn; @@ -4606,12 +4630,22 @@ void FurnaceGUI::drawInsEdit() { } //52.0 controls vert scaling; default 96 - drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,52.0*dpiScale),ins->type); + drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_ESFM)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,52.0*dpiScale),ins->type); //P(CWSliderScalar(FM_NAME(FM_AR),ImGuiDataType_U8,&op.ar,&_ZERO,&_THIRTY_ONE)); rightClickable if (ImGui::BeginTable("opParams",2,ImGuiTableFlags_SizingStretchProp)) { ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); \ ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed,0.0); \ + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + opE.delay&=7; + P(CWSliderScalar("##DELAY",ImGuiDataType_U8,&opE.delay,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + ImGui::Text("%s",ESFM_NAME(ESFM_DELAY)); + } + ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); @@ -4796,7 +4830,24 @@ void FurnaceGUI::drawInsEdit() { } } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ) { + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWELVE,&_TWELVE)); rightClickable + ImGui::TableNextColumn(); + ImGui::Text("%s",ESFM_NAME(ESFM_CT)); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(CWSliderScalar("##DT",ImGuiDataType_S8,&opE.dt,&_MINUS_ONE_HUNDRED_TWENTY_EIGHT,&_ONE_HUNDRED_TWENTY_SEVEN)); rightClickable + ImGui::TableNextColumn(); + ImGui::Text("%s",ESFM_NAME(ESFM_DT)); + + } + + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_ESFM) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); @@ -4807,11 +4858,33 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); ImGui::Text("%s",FM_NAME(FM_WS)); } - + + if (ins->type==DIV_INS_ESFM) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Separator(); + ImGui::TableNextColumn(); + ImGui::Separator(); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(CWSliderScalar("##OUTLVL",ImGuiDataType_U8,&opE.outLvl,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + ImGui::Text("%s",ESFM_NAME(ESFM_OUTLVL)); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(CWSliderScalar("##MODIN",ImGuiDataType_U8,&opE.modIn,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + ImGui::Text("%s",ESFM_NAME(ESFM_MODIN)); + } + ImGui::EndTable(); } - if (ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS) { + if (ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_ESFM) { if (ImGui::Checkbox(FM_NAME(FM_VIB),&vibOn)) { PARAMETER op.vib=vibOn; } @@ -4820,6 +4893,18 @@ void FurnaceGUI::drawInsEdit() { op.ksr=ksrOn; } } + + if (ins->type==DIV_INS_ESFM) { + bool leftOn=opE.left; + bool rightOn=opE.right; + if (ImGui::Checkbox(ESFM_NAME(ESFM_LEFT),&leftOn)) { PARAMETER + opE.left=leftOn; + } + ImGui::SameLine(); + if (ImGui::Checkbox(ESFM_NAME(ESFM_RIGHT),&rightOn)) { PARAMETER + opE.right=rightOn; + } + } if (settings.separateFMColors) { popAccentColors(); From 84e0ec9dae70ebcd85f86458c510df3991edaace Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 15 Oct 2023 11:44:12 -0300 Subject: [PATCH 06/34] bump ct range to 24; fix bug in modern layout for OPL and ESFM --- src/gui/insEdit.cpp | 25 ++++++++++++++++++++----- src/gui/intConst.cpp | 4 ++-- src/gui/intConst.h | 4 ++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 48b72b72f..8ff7735d8 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -3537,7 +3537,17 @@ void FurnaceGUI::drawInsEdit() { } } - if (i==0) sliderHeight=(ImGui::GetContentRegionAvail().y/opCount)-ImGui::GetStyle().ItemSpacing.y; + if (i==0) { + sliderHeight=(ImGui::GetContentRegionAvail().y/opCount)-ImGui::GetStyle().ItemSpacing.y; + float sliderMinHeightOPL=ImGui::GetFrameHeight()*4.0+ImGui::GetStyle().ItemSpacing.y*3.0; + float sliderMinHeightESFM=ImGui::GetFrameHeight()*5.0+ImGui::GetStyle().ItemSpacing.y*4.0; + if ((ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL) && sliderHeighttype==DIV_INS_ESFM && sliderHeighttype==DIV_INS_ESFM) { ImGui::TableNextColumn(); CENTER_VSLIDER; - P(CWVSliderScalar("##CT",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_S8,&opE.ct,&_MINUS_TWELVE,&_TWELVE)); rightClickable + P(CWVSliderScalar("##CT",ImVec2(20.0f*dpiScale,sliderHeight),ImGuiDataType_S8,&opE.ct,&_MINUS_TWENTY_FOUR,&_TWENTY_FOUR)); rightClickable } if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { @@ -3763,21 +3773,26 @@ void FurnaceGUI::drawInsEdit() { bool amOn=op.am; bool leftOn=opE.left; bool rightOn=opE.right; + ImGui::SetCursorPosY(ImGui::GetCursorPosY()+0.5*(sliderHeight-ImGui::GetFrameHeight()*5.0-ImGui::GetStyle().ItemSpacing.y*4.0)); if (ImGui::BeginTable("panCheckboxes",2,ImGuiTableFlags_SizingStretchSame)) { ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); + float yCoordBeforeTablePadding=ImGui::GetCursorPosY(); ImGui::TableNextRow(); ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yCoordBeforeTablePadding); if (ImGui::Checkbox(ESFM_SHORT_NAME(ESFM_LEFT),&leftOn)) { PARAMETER opE.left=leftOn; } ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yCoordBeforeTablePadding); if (ImGui::Checkbox(ESFM_SHORT_NAME(ESFM_RIGHT),&rightOn)) { PARAMETER opE.right=rightOn; } ImGui::EndTable(); } + ImGui::SetCursorPosY(ImGui::GetCursorPosY()-0.5*ImGui::GetStyle().ItemSpacing.y); if (ImGui::Checkbox(FM_NAME(FM_AM),&amOn)) { PARAMETER op.am=amOn; } @@ -4299,7 +4314,7 @@ void FurnaceGUI::drawInsEdit() { ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_CT)); - P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWELVE,&_TWELVE,tempID)); rightClickable + P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWENTY_FOUR,&_TWENTY_FOUR,tempID)); rightClickable ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_DT)); @@ -4834,7 +4849,7 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWELVE,&_TWELVE)); rightClickable + P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWENTY_FOUR,&_TWENTY_FOUR)); rightClickable ImGui::TableNextColumn(); ImGui::Text("%s",ESFM_NAME(ESFM_CT)); @@ -4893,7 +4908,7 @@ void FurnaceGUI::drawInsEdit() { op.ksr=ksrOn; } } - + if (ins->type==DIV_INS_ESFM) { bool leftOn=opE.left; bool rightOn=opE.right; diff --git a/src/gui/intConst.cpp b/src/gui/intConst.cpp index cf0140e23..da5c6065e 100644 --- a/src/gui/intConst.cpp +++ b/src/gui/intConst.cpp @@ -24,9 +24,9 @@ const int _ONE=1; const int _THREE=3; const int _SEVEN=7; const int _TEN=10; -const int _TWELVE=12; const int _FIFTEEN=15; const int _SIXTEEN=16; +const int _TWENTY_FOUR=24; const int _THIRTY_ONE=31; const int _SIXTY_FOUR=64; const int _ONE_HUNDRED=100; @@ -36,6 +36,6 @@ const int _FIVE_HUNDRED_ELEVEN=511; const int _TWO_THOUSAND_FORTY_SEVEN=2047; const int _FOUR_THOUSAND_NINETY_FIVE=4095; const int _SIXTY_FIVE_THOUSAND_FIVE_HUNDRED_THIRTY_FIVE=65535; -const int _MINUS_TWELVE=-12; +const int _MINUS_TWENTY_FOUR=-24; const int _MINUS_ONE_HUNDRED_TWENTY_SEVEN=-127; const int _MINUS_ONE_HUNDRED_TWENTY_EIGHT=-128; diff --git a/src/gui/intConst.h b/src/gui/intConst.h index 18c4ae556..7acbbcf6b 100644 --- a/src/gui/intConst.h +++ b/src/gui/intConst.h @@ -26,9 +26,9 @@ extern const int _ONE; extern const int _THREE; extern const int _SEVEN; extern const int _TEN; -extern const int _TWELVE; extern const int _FIFTEEN; extern const int _SIXTEEN; +extern const int _TWENTY_FOUR; extern const int _THIRTY_ONE; extern const int _SIXTY_FOUR; extern const int _ONE_HUNDRED; @@ -38,6 +38,6 @@ extern const int _FIVE_HUNDRED_ELEVEN; extern const int _TWO_THOUSAND_FORTY_SEVEN; extern const int _FOUR_THOUSAND_NINETY_FIVE; extern const int _SIXTY_FIVE_THOUSAND_FIVE_HUNDRED_THIRTY_FIVE; -extern const int _MINUS_TWELVE; +extern const int _MINUS_TWENTY_FOUR; extern const int _MINUS_ONE_HUNDRED_TWENTY_SEVEN; extern const int _MINUS_ONE_HUNDRED_TWENTY_EIGHT; From 4a0295fd1f4eb34990d45c23bf1dfa55e27be644 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 15 Oct 2023 19:46:07 -0300 Subject: [PATCH 07/34] WIP: adding fixed pitch mode; fix UB in ESFM driver --- src/engine/instrument.cpp | 4 +- src/engine/instrument.h | 9 ++-- src/engine/platform/esfm.cpp | 21 ++++++---- src/engine/platform/esfm.h | 1 + src/gui/insEdit.cpp | 81 +++++++++++++++++++++++++++++------- 5 files changed, 88 insertions(+), 28 deletions(-) diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index 0e1340e90..d92fe4504 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -245,6 +245,7 @@ bool DivInstrumentESFM::Operator::operator==(const DivInstrumentESFM::Operator& _C(modIn) && _C(left) && _C(right) && + _C(fixed) && _C(ct) && _C(dt) ); @@ -764,7 +765,7 @@ void DivInstrument::writeFeatureEF(SafeWriter* w) { DivInstrumentESFM::Operator& op=esfm.op[i]; w->writeC(((op.delay&7)<<5)|((op.outLvl&7)<<2)|((op.right&1)<<1)|(op.left&1)); - w->writeC(op.modIn&7); + w->writeC((op.fixed&1)<<3|(op.modIn&7)); w->writeC(op.ct); w->writeC(op.dt); } @@ -2644,6 +2645,7 @@ void DivInstrument::readFeatureEF(SafeReader& reader, short version) { next=reader.readC(); op.modIn=next&7; + op.fixed=(next>>3)&1; op.ct=reader.readC(); op.dt=reader.readC(); diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 4c1778304..6dfb49716 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -756,7 +756,7 @@ struct DivInstrumentSNES { // ESFM operator structure: // - DELAY, OUT, MOD, L, R, NOISE -// - Virtual: CT, DT, DTRAW +// - Virtual: CT, DT, FIXED // - In FM struct: AM, DAM, AR, DR, MULT, RR, SL, TL // - In FM struct: KSL, VIB, DVB, WS, SUS, KSR // - Not in struct: FNUML, FNUMH, BLOCK @@ -770,7 +770,7 @@ struct DivInstrumentESFM { // Only works on OP4, so putting it outside the Operator struct instead unsigned char noise; struct Operator { - unsigned char delay, outLvl, modIn, left, right; + unsigned char delay, outLvl, modIn, left, right, fixed; signed char ct, dt; bool operator==(const Operator& other); @@ -781,8 +781,9 @@ struct DivInstrumentESFM { delay(0), outLvl(0), modIn(0), - left(true), - right(true), + left(1), + right(1), + fixed(0), ct(0), dt(0) {} } op[4]; diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 0c1a11e97..5d08205c3 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -218,12 +218,17 @@ void DivPlatformESFM::tick(bool sysTick) { DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; int ct=(int)opE.ct; int dt=(int)opE.dt; - int opFreq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride+ct:chan[i].arpOff+ct,chan[i].fixedArp,false,octave(chan[i].baseFreq)*2,chan[i].pitch2+dt,chipClock,CHIP_FREQBASE); - if (opFreq<0) opFreq=0; - if (opFreq>131071) opFreq=131071; - int freqt=toFreq(opFreq); - chan[i].freqL[o]=freqt&0xff; - chan[i].freqH[o]=freqt>>8; + if (opE.fixed) { + chan[i].freqL[o]=opE.dt; + chan[i].freqH[o]=opE.ct&0x1f; + } else { + int opFreq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride+ct:chan[i].arpOff+ct,chan[i].fixedArp,false,octave(chan[i].baseFreq)*2,chan[i].pitch2+dt,chipClock,CHIP_FREQBASE); + if (opFreq<0) opFreq=0; + if (opFreq>131071) opFreq=131071; + int freqt=toFreq(opFreq); + chan[i].freqL[o]=freqt&0xff; + chan[i].freqH[o]=freqt>>8; + } immWrite(baseAddr+OFFSET_FREQL,chan[i].freqL[o]); immWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); } @@ -558,7 +563,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.rr=c.value2&15; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|op.rr); + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); } } else { unsigned int o = c.value; @@ -566,7 +571,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.rr=c.value2&15; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|op.rr); + rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); } break; } diff --git a/src/engine/platform/esfm.h b/src/engine/platform/esfm.h index 558571a84..2c4a8c982 100644 --- a/src/engine/platform/esfm.h +++ b/src/engine/platform/esfm.h @@ -40,6 +40,7 @@ class DivPlatformESFM: public DivDispatch { SharedChannel(0), freqL{0, 0, 0, 0}, freqH{0, 0, 0, 0}, + hardReset(false), globalPan(3), macroVolMul(64) {} }; diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 8ff7735d8..63600289e 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -44,16 +44,16 @@ const char* fmParamNames[3][32]={ {"ALG", "FB", "FMS/PMS", "AMS", "AR", "DR", "D2R", "RR", "SL", "TL", "RS", "MULT", "DT", "DT2", "SSG-EG", "AM", "DAM", "DVB", "EGT", "EGS", "KSL", "SUS", "VIB", "WS", "KSR", "DC", "DM", "EGS", "REV", "Fine", "FMS/PMS2", "AMS2"} }; -const char* esfmParamLongNames[8]={ - "OP4 Noise Mode", "Envelope Delay", "Output Level", "Modulation Input Level", "Left Output", "Right Output", "Coarse Tune (semitones)", "Detune" +const char* esfmParamLongNames[9]={ + "OP4 Noise Mode", "Envelope Delay", "Output Level", "Modulation Input Level", "Left Output", "Right Output", "Coarse Tune (semitones)", "Detune", "Fixed Frequency Mode" }; -const char* esfmParamNames[8]={ - "OP4 Noise Mode", "Env. Delay", "Output Level", "ModInput", "Left", "Right", "Coarse Tn.", "Detune" +const char* esfmParamNames[9]={ + "OP4 Noise Mode", "Env. Delay", "Output Level", "ModInput", "Left", "Right", "Coarse Tn.", "Detune", "Fixed" }; -const char* esfmParamShortNames[8]={ - "RHY", "DL", "OL", "MI", "L", "R", "CT", "DT" +const char* esfmParamShortNames[9]={ + "RHY", "DL", "OL", "MI", "L", "R", "CT", "DT", "FIX" }; const char* fmParamShortNames[3][32]={ @@ -230,7 +230,8 @@ enum ESFMParams { ESFM_LEFT=4, ESFM_RIGHT=5, ESFM_CT=6, - ESFM_DT=7 + ESFM_DT=7, + ESFM_FIXED=8 }; #define FM_NAME(x) fmParamNames[settings.fmNames][x] @@ -3951,7 +3952,7 @@ void FurnaceGUI::drawInsEdit() { } float sliderHeight=200.0f*dpiScale; - float waveWidth=140.0*dpiScale*((ins->type==DIV_INS_ESFM)?0.8f:1.0f); + float waveWidth=140.0*dpiScale*((ins->type==DIV_INS_ESFM)?0.85f:1.0f); float waveHeight=sliderHeight-ImGui::GetFrameHeightWithSpacing()*((ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPL || ins->type==DIV_INS_ESFM)?5.0f:4.5f); int maxTl=127; @@ -4312,13 +4313,44 @@ void FurnaceGUI::drawInsEdit() { snprintf(tempID,1024,"%s: %%d",FM_NAME(FM_MULT)); P(CWSliderScalar("##MULT",ImGuiDataType_U8,&op.mult,&_ZERO,&_FIFTEEN,tempID)); rightClickable - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_CT)); - P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWENTY_FOUR,&_TWENTY_FOUR,tempID)); rightClickable + if (opE.fixed) { + int block=(opE.ct>>2)&7; + int freqNum=((opE.ct&3)<<8)|((unsigned char)opE.dt); + ImGui::Text("Blk"); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Block"); + } + ImGui::SameLine(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + //ImVec2 cursorAlign=ImGui::GetCursorPos(); + if (ImGui::InputInt("##Block",&block,1,1)) { + if (block<0) block=0; + if (block>7) block=7; + opE.ct=(opE.ct&(~(7<<2)))|(block<<2); + } + + ImGui::Text("F"); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Frequency (F-Num)"); + } + ImGui::SameLine(); + //ImGui::SetCursorPos(ImVec2(cursorAlign.x,ImGui::GetCursorPosY())); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::InputInt("##FreqNum",&freqNum,1,16)) { + if (freqNum<0) freqNum=0; + if (freqNum>1023) freqNum=1023; + opE.dt=freqNum&0xff; + opE.ct=(opE.ct&(~3))|(freqNum>>8); + } + } else { + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_CT)); + P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWENTY_FOUR,&_TWENTY_FOUR,tempID)); rightClickable - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_DT)); - P(CWSliderScalar("##DT",ImGuiDataType_S8,&opE.dt,&_MINUS_ONE_HUNDRED_TWENTY_EIGHT,&_ONE_HUNDRED_TWENTY_SEVEN,tempID)); rightClickable + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + snprintf(tempID,1024,"%s: %%d",ESFM_NAME(ESFM_DT)); + P(CWSliderScalar("##DT",ImGuiDataType_S8,&opE.dt,&_MINUS_ONE_HUNDRED_TWENTY_EIGHT,&_ONE_HUNDRED_TWENTY_SEVEN,tempID)); rightClickable + } if (ImGui::BeginTable("panCheckboxes",2,ImGuiTableFlags_SizingStretchSame)) { ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0f); @@ -4347,9 +4379,12 @@ void FurnaceGUI::drawInsEdit() { ImGui::TableNextColumn(); float envHeight=sliderHeight;//-ImGui::GetStyle().ItemSpacing.y*2.0f; - if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_ESFM) { + if (ins->type==DIV_INS_OPZ) { envHeight-=ImGui::GetFrameHeightWithSpacing()*2.0f; } + if (ins->type==DIV_INS_ESFM) { + envHeight-=ImGui::GetFrameHeightWithSpacing()*3.0f; + } drawFMEnv(op.tl&maxTl,op.ar&maxArDr,op.dr&maxArDr,(ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_ESFM)?((op.rr&15)*2):op.d2r&31,op.rr&15,op.sl&15,op.sus,op.ssgEnv&8,fmOrigin.alg,maxTl,maxArDr,15,ImVec2(ImGui::GetContentRegionAvail().x,envHeight),ins->type); if (ins->type==DIV_INS_OPZ) { @@ -4408,6 +4443,7 @@ void FurnaceGUI::drawInsEdit() { } rightClickable bool amOn=op.am; + bool fixedOn=opE.fixed; ImGui::TableNextColumn(); if (ImGui::Checkbox(FM_SHORT_NAME(FM_KSR),&ksrOn)) { PARAMETER op.ksr=ksrOn; @@ -4430,12 +4466,27 @@ void FurnaceGUI::drawInsEdit() { if (ImGui::Checkbox(FM_SHORT_NAME(FM_AM),&amOn)) { PARAMETER op.am=amOn; } + + bool damOn=op.dam; + bool dvbOn=op.dvb; + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_DVB),&dvbOn)) { PARAMETER + op.dvb=dvbOn; + } + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_DAM),&damOn)) { PARAMETER + op.dam=damOn; + } ImGui::EndTable(); } ImGui::TableNextColumn(); if (ImGui::Checkbox(FM_SHORT_NAME(FM_SUS),&susOn)) { PARAMETER op.sus=susOn; } + if (ImGui::Checkbox(ESFM_NAME(ESFM_FIXED),&fixedOn)) { PARAMETER + opE.fixed=fixedOn; + } ImGui::EndTable(); } From 39001dcb6a53f7a9a299b84180729876f6b1d4e4 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Mon, 16 Oct 2023 16:57:04 -0300 Subject: [PATCH 08/34] Adding operator routing visualization --- src/engine/sysDef.cpp | 4 +- src/gui/gui.h | 1 + src/gui/insEdit.cpp | 111 +++++++++++++++++++++++++++++++++++--- src/gui/sysConf.cpp | 1 + src/gui/sysPartNumber.cpp | 2 + 5 files changed, 111 insertions(+), 8 deletions(-) diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 769650723..1773ad4a6 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1920,8 +1920,8 @@ void DivEngine::registerSystems() { // TODO: ask Tilde to standardize! sysDefs[DIV_SYSTEM_ESFM]=new DivSysDef( - "ESFM (TODO: gimme a better name)", NULL, 0xd0, 0, 18, true, false, 0, false, 0, - "TODO: give ESFM the beautiful description it deserves", + "ESS ES1xxx-series (ESFM)", NULL, 0xd0, 0, 18, true, false, 0, false, 0, + "A unique FM synth featured in PC sound cards.\nBased on the OPL3 design, but with lots of its features extended.", {"FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "FM 7", "FM 8", "FM 9", "FM 10", "FM 11", "FM 12", "FM 13", "FM 14", "FM 15", "FM 16", "FM 17", "FM 18"}, {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, {DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM}, diff --git a/src/gui/gui.h b/src/gui/gui.h index 0cff7b595..b450be196 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2209,6 +2209,7 @@ class FurnaceGUI { void drawSSGEnv(unsigned char type, const ImVec2& size); void drawWaveform(unsigned char type, bool opz, const ImVec2& size); void drawAlgorithm(unsigned char alg, FurnaceGUIFMAlgs algType, const ImVec2& size); + void drawESFMAlgorithm(DivInstrumentESFM& esfm, const ImVec2& size); void drawFMEnv(unsigned char tl, unsigned char ar, unsigned char dr, unsigned char d2r, unsigned char rr, unsigned char sl, unsigned char sus, unsigned char egt, unsigned char algOrGlobalSus, float maxTl, float maxArDr, float maxRr, const ImVec2& size, unsigned short instType); void drawGBEnv(unsigned char vol, unsigned char len, unsigned char sLen, bool dir, const ImVec2& size); bool drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& flags, bool modifyOnChange, bool fromMenu=false); diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 63600289e..f1b8ecabe 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -1164,6 +1164,110 @@ void FurnaceGUI::drawAlgorithm(unsigned char alg, FurnaceGUIFMAlgs algType, cons } } +void FurnaceGUI::drawESFMAlgorithm(DivInstrumentESFM& esfm, const ImVec2& size) { + ImDrawList* dl=ImGui::GetWindowDrawList(); + ImGuiWindow* window=ImGui::GetCurrentWindow(); + + ImVec2 minArea=window->DC.CursorPos; + ImVec2 maxArea=ImVec2( + minArea.x+size.x, + minArea.y+size.y + ); + ImRect rect=ImRect(minArea,maxArea); + ImGuiStyle& style=ImGui::GetStyle(); + ImU32 colorM=ImGui::GetColorU32(uiColors[GUI_COLOR_FM_MOD]); + ImU32 colorC=ImGui::GetColorU32(uiColors[GUI_COLOR_FM_CAR]); + ImU32 colorsL[8]; + for (int i=0; i<8; i++){ + float alpha=(float)i/7.0f; + ImVec4 color=uiColors[GUI_COLOR_FM_ALG_LINE]; + color.w *= alpha; + colorsL[i]=ImGui::GetColorU32(color); + } + ImGui::ItemSize(size,style.FramePadding.y); + if (ImGui::ItemAdd(rect,ImGui::GetID("alg"))) { + ImGui::RenderFrame(rect.Min,rect.Max,ImGui::GetColorU32(uiColors[GUI_COLOR_FM_ALG_BG]),true,style.FrameRounding); + const float circleRadius=6.0f*dpiScale+1.0f; + //int modFb = esfm.op[0].modIn&7; + int mod12 = esfm.op[1].modIn&7; + int mod23 = esfm.op[2].modIn&7; + int mod34 = esfm.op[3].modIn&7; + int out1 = esfm.op[0].outLvl&7; + int out2 = esfm.op[1].outLvl&7; + int out3 = esfm.op[2].outLvl&7; + int out4 = esfm.op[3].outLvl&7; + bool isMod[4]; + for (int i=0; i<4; i++) { + DivInstrumentESFM::Operator& opE = esfm.op[i]; + isMod[i]=true; + if (opE.outLvl==7) isMod[i]=false; + else if (opE.outLvl>0) { + if (i==3) isMod[i]=false; + else { + DivInstrumentESFM::Operator& opENext=esfm.op[i+1]; + if (opENext.modIn==0) isMod[i]=false; + else if ((opE.outLvl-opENext.modIn) >= 2) isMod[i]=false; + } + } + } + + ImVec2 posOp1=ImLerp(rect.Min,rect.Max,ImVec2(0.2f,0.25f)); + ImVec2 posOp2=ImLerp(rect.Min,rect.Max,ImVec2(0.4f,0.25f)); + ImVec2 posOp3=ImLerp(rect.Min,rect.Max,ImVec2(0.6f,0.25f)); + ImVec2 posOp4=ImLerp(rect.Min,rect.Max,ImVec2(0.8f,0.25f)); + ImVec2 posBusbarOp1=ImLerp(rect.Min,rect.Max,ImVec2(0.2f,0.75f)); + ImVec2 posBusbarOp2=ImLerp(rect.Min,rect.Max,ImVec2(0.4f,0.75f)); + ImVec2 posBusbarOp3=ImLerp(rect.Min,rect.Max,ImVec2(0.6f,0.75f)); + ImVec2 posBusbarOp4=ImLerp(rect.Min,rect.Max,ImVec2(0.8f,0.75f)); + + ImVec2 posBusbarStart=ImLerp(rect.Min,rect.Max,ImVec2(0.15f,0.75f)); + ImVec2 posBusbarEnd=ImLerp(rect.Min,rect.Max,ImVec2(0.85f,0.75f)); + bool busbarStartSeen=false; + for (int i=0; i<4; i++) { + DivInstrumentESFM::Operator& opE=esfm.op[i]; + if (opE.outLvl>0) { + if (!busbarStartSeen) { + busbarStartSeen=true; + posBusbarStart=ImLerp(rect.Min,rect.Max,ImVec2(0.15f+0.2f*i,0.75f)); + } + posBusbarEnd=ImLerp(rect.Min,rect.Max,ImVec2(0.25f+0.2f*i,0.75f)); + } + } + + if (mod12) addAALine(dl,posOp1,posOp2,colorsL[mod12]); + if (mod23) addAALine(dl,posOp2,posOp3,colorsL[mod23]); + if (mod34) addAALine(dl,posOp3,posOp4,colorsL[mod34]); + if (out1) addAALine(dl,posOp1,posBusbarOp1,colorsL[out1]); + if (out2) addAALine(dl,posOp2,posBusbarOp2,colorsL[out2]); + if (out3) addAALine(dl,posOp3,posBusbarOp3,colorsL[out3]); + if (out4) addAALine(dl,posOp4,posBusbarOp4,colorsL[out4]); + + addAALine(dl,posBusbarStart,posBusbarEnd,colorsL[2]); + // addAALine(dl,posBusbarEnd,posBusbarEnd+ImVec2(-8.0f*dpiScale,-4.0f*dpiScale),colorsL[2]); + // addAALine(dl,posBusbarEnd,posBusbarEnd+ImVec2(-8.0f*dpiScale,4.0f*dpiScale),colorsL[2]); + // addAALine(dl,posBusbarStart+ImVec2(4.0f*dpiScale,-4.0f*dpiScale),posBusbarStart+ImVec2(4.0f*dpiScale,4.0f*dpiScale),colorsL[2]); + + dl->AddCircle(posOp1,6.0f*dpiScale+1.0f,isMod[0]?colorM:colorC); + dl->AddCircleFilled(posOp1,4.0f*dpiScale+1.0f,isMod[0]?colorM:colorC); + dl->AddCircleFilled(posOp2,4.0f*dpiScale+1.0f,isMod[1]?colorM:colorC); + dl->AddCircleFilled(posOp3,4.0f*dpiScale+1.0f,isMod[2]?colorM:colorC); + dl->AddCircleFilled(posOp4,4.0f*dpiScale+1.0f,isMod[3]?colorM:colorC); + + posOp1.x-=ImGui::CalcTextSize("1").x+circleRadius+3.0f*dpiScale; + posOp2.x-=ImGui::CalcTextSize("2").x+circleRadius+3.0f*dpiScale; + posOp3.x-=ImGui::CalcTextSize("3").x+circleRadius+3.0f*dpiScale; + posOp4.x-=ImGui::CalcTextSize("4").x+circleRadius+3.0f*dpiScale; + posOp1.y-=ImGui::CalcTextSize("1").y*0.5f; + posOp2.y-=ImGui::CalcTextSize("2").y*0.5f; + posOp3.y-=ImGui::CalcTextSize("3").y*0.5f; + posOp4.y-=ImGui::CalcTextSize("4").y*0.5f; + dl->AddText(posOp1,isMod[0]?colorM:colorC,"1"); + dl->AddText(posOp2,isMod[1]?colorM:colorC,"2"); + dl->AddText(posOp3,isMod[2]?colorM:colorC,"3"); + dl->AddText(posOp4,isMod[3]?colorM:colorC,"4"); + } +} + void FurnaceGUI::drawFMEnv(unsigned char tl, unsigned char ar, unsigned char dr, unsigned char d2r, unsigned char rr, unsigned char sl, unsigned char sus, unsigned char egt, unsigned char algOrGlobalSus, float maxTl, float maxArDr, float maxRr, const ImVec2& size, unsigned short instType) { ImDrawList* dl=ImGui::GetWindowDrawList(); ImGuiWindow* window=ImGui::GetCurrentWindow(); @@ -3182,10 +3286,6 @@ void FurnaceGUI::drawInsEdit() { } break; } - case DIV_INS_ESFM: { - // unreachable - break; - } default: break; } @@ -3212,8 +3312,7 @@ void FurnaceGUI::drawInsEdit() { WAKE_UP; } } else { - //drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - ImGui::TextUnformatted("TODO: implement fancy ESFM\nauto algorithm drawing"); + drawESFMAlgorithm(ins->esfm, ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); } kvsConfig(ins); } diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index b8caa7390..813942d0c 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -2225,6 +2225,7 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl case DIV_SYSTEM_C219: break; case DIV_SYSTEM_YMU759: + case DIV_SYSTEM_ESFM: supportsCustomRate=false; ImGui::Text("nothing to configure"); break; diff --git a/src/gui/sysPartNumber.cpp b/src/gui/sysPartNumber.cpp index d71e65a98..3facab9cd 100644 --- a/src/gui/sysPartNumber.cpp +++ b/src/gui/sysPartNumber.cpp @@ -277,6 +277,8 @@ const char* FurnaceGUI::getSystemPartNumber(DivSystem sys, DivConfig& flags) { case DIV_SYSTEM_C219: return "C219"; break; + case DIV_SYSTEM_ESFM: + return "ES1xxx"; default: return FurnaceGUI::getSystemName(sys); break; From aee939bd3e441cb90c9dd8aec6785eaa7d0ee390 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Tue, 17 Oct 2023 15:47:08 -0300 Subject: [PATCH 09/34] Implement fixed frequency mode for modern and classic layouts --- src/gui/insEdit.cpp | 172 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 146 insertions(+), 26 deletions(-) diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index f1b8ecabe..2565e9355 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -3692,6 +3692,7 @@ void FurnaceGUI::drawInsEdit() { bool ksrOn=op.ksr; bool vibOn=op.vib; bool susOn=op.sus; + bool fixedOn=opE.fixed; unsigned char ssgEnv=op.ssgEnv&7; if (ins->type==DIV_INS_ESFM) { @@ -3873,10 +3874,18 @@ void FurnaceGUI::drawInsEdit() { bool amOn=op.am; bool leftOn=opE.left; bool rightOn=opE.right; + ImGui::SetCursorPosY(ImGui::GetCursorPosY()+0.5*(sliderHeight-ImGui::GetFrameHeight()*5.0-ImGui::GetStyle().ItemSpacing.y*4.0)); - if (ImGui::BeginTable("panCheckboxes",2,ImGuiTableFlags_SizingStretchSame)) { - ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); - ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); + ImVec2 curPosBeforeDummy = ImGui::GetCursorPos(); + ImGui::Dummy(ImVec2(ImGui::GetFrameHeightWithSpacing()*2.0f+ImGui::CalcTextSize(FM_SHORT_NAME(FM_DAM)).x*2.0f,1.0f)); + ImGui::SetCursorPos(curPosBeforeDummy); + + if (ImGui::BeginTable("panCheckboxes",(fixedOn)?3:2,ImGuiTableFlags_SizingStretchProp)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,1.0); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,1.0); + if (fixedOn) { + ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,1.2); + } float yCoordBeforeTablePadding=ImGui::GetCursorPosY(); ImGui::TableNextRow(); @@ -3890,20 +3899,81 @@ void FurnaceGUI::drawInsEdit() { if (ImGui::Checkbox(ESFM_SHORT_NAME(ESFM_RIGHT),&rightOn)) { PARAMETER opE.right=rightOn; } + if (fixedOn) { + ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yCoordBeforeTablePadding); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_AM),&amOn)) { PARAMETER + op.am=amOn; + } + } + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_KSR),&ksrOn)) { PARAMETER + op.ksr=ksrOn; + } + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_SUS),&susOn)) { PARAMETER + op.sus=susOn; + } + if (fixedOn) { + bool damOn=op.dam; + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_DAM),&damOn)) { PARAMETER + op.dam=damOn; + } + } ImGui::EndTable(); } ImGui::SetCursorPosY(ImGui::GetCursorPosY()-0.5*ImGui::GetStyle().ItemSpacing.y); - if (ImGui::Checkbox(FM_NAME(FM_AM),&amOn)) { PARAMETER - op.am=amOn; + if (ImGui::Checkbox(ESFM_NAME(ESFM_FIXED),&fixedOn)) { PARAMETER + opE.fixed=fixedOn; } - if (ImGui::Checkbox(FM_NAME(FM_VIB),&vibOn)) { PARAMETER - op.vib=vibOn; - } - if (ImGui::Checkbox(FM_NAME(FM_KSR),&ksrOn)) { PARAMETER - op.ksr=ksrOn; - } - if (ImGui::Checkbox(FM_NAME(FM_SUS),&susOn)) { PARAMETER - op.sus=susOn; + if (ins->type==DIV_INS_ESFM) { + if (fixedOn) { + int block=(opE.ct>>2)&7; + int freqNum=((opE.ct&3)<<8)|((unsigned char)opE.dt); + if (ImGui::InputInt("Block",&block,1,1)) { + if (block<0) block=0; + if (block>7) block=7; + opE.ct=(opE.ct&(~(7<<2)))|(block<<2); + } + if (ImGui::InputInt("FreqNum",&freqNum,1,16)) { + if (freqNum<0) freqNum=0; + if (freqNum>1023) freqNum=1023; + opE.dt=freqNum&0xff; + opE.ct=(opE.ct&(~3))|(freqNum>>8); + } + } else { + if (ImGui::BeginTable("amVibCheckboxes",2,ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); + + float yCoordBeforeTablePadding=ImGui::GetCursorPosY(); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yCoordBeforeTablePadding); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_AM),&amOn)) { PARAMETER + op.am=amOn; + } + ImGui::TableNextColumn(); + ImGui::SetCursorPosY(yCoordBeforeTablePadding); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_VIB),&vibOn)) { PARAMETER + op.vib=vibOn; + } + bool damOn=op.dam; + bool dvbOn=op.dvb; + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_DAM),&damOn)) { PARAMETER + op.dam=damOn; + } + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_SHORT_NAME(FM_DVB),&dvbOn)) { PARAMETER + op.dvb=dvbOn; + } + ImGui::EndTable(); + } + } } } else if (ins->type!=DIV_INS_OPM) { ImGui::TableNextColumn(); @@ -3934,12 +4004,21 @@ void FurnaceGUI::drawInsEdit() { ImGui::Dummy(ImVec2(4.0f*dpiScale,2.0f*dpiScale)); ImGui::TableNextColumn(); - drawWaveform(op.ws&7,ins->type==DIV_INS_OPZ,ImVec2(ImGui::GetContentRegionAvail().x,sliderHeight-ImGui::GetFrameHeightWithSpacing())); + drawWaveform(op.ws&7,ins->type==DIV_INS_OPZ,ImVec2(ImGui::GetContentRegionAvail().x,sliderHeight-ImGui::GetFrameHeightWithSpacing()*((ins->type==DIV_INS_ESFM && fixedOn)?3.0f:1.0f))); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); P(CWSliderScalar("##WS",ImGuiDataType_U8,&op.ws,&_ZERO,&_SEVEN,(ins->type==DIV_INS_OPZ)?opzWaveforms[op.ws&7]:(settings.oplStandardWaveNames?oplWaveformsStandard[op.ws&7]:oplWaveforms[op.ws&7]))); rightClickable if ((ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS) && ImGui::IsItemHovered()) { ImGui::SetTooltip("OPL2/3 only (last 4 waveforms are OPL3 only)"); } + if (ins->type==DIV_INS_ESFM && fixedOn) { + if (ImGui::Checkbox(FM_SHORT_NAME(FM_VIB),&vibOn)) { PARAMETER + op.vib=vibOn; + } + bool dvbOn=op.dvb; + if (ImGui::Checkbox(FM_SHORT_NAME(FM_DVB),&dvbOn)) { PARAMETER + op.dvb=dvbOn; + } + } } else if (ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPM) { ImGui::TableNextColumn(); ImGui::Dummy(ImVec2(4.0f*dpiScale,2.0f*dpiScale)); @@ -4996,19 +5075,46 @@ void FurnaceGUI::drawInsEdit() { } if (ins->type==DIV_INS_ESFM) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWENTY_FOUR,&_TWENTY_FOUR)); rightClickable - ImGui::TableNextColumn(); - ImGui::Text("%s",ESFM_NAME(ESFM_CT)); + bool fixedOn=opE.fixed; + if (fixedOn) { + int block=(opE.ct>>2)&7; + int freqNum=((opE.ct&3)<<8)|((unsigned char)opE.dt); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::InputInt("##Block",&block,1,1)) { + if (block<0) block=0; + if (block>7) block=7; + opE.ct=(opE.ct&(~(7<<2)))|(block<<2); + } + ImGui::TableNextColumn(); + ImGui::Text("Block"); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + if (ImGui::InputInt("##FreqNum",&freqNum,1,16)) { + if (freqNum<0) freqNum=0; + if (freqNum>1023) freqNum=1023; + opE.dt=freqNum&0xff; + opE.ct=(opE.ct&(~3))|(freqNum>>8); + } + ImGui::TableNextColumn(); + ImGui::Text("FreqNum"); + } else { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(CWSliderScalar("##CT",ImGuiDataType_S8,&opE.ct,&_MINUS_TWENTY_FOUR,&_TWENTY_FOUR)); rightClickable + ImGui::TableNextColumn(); + ImGui::Text("%s",ESFM_NAME(ESFM_CT)); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - P(CWSliderScalar("##DT",ImGuiDataType_S8,&opE.dt,&_MINUS_ONE_HUNDRED_TWENTY_EIGHT,&_ONE_HUNDRED_TWENTY_SEVEN)); rightClickable - ImGui::TableNextColumn(); - ImGui::Text("%s",ESFM_NAME(ESFM_DT)); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + P(CWSliderScalar("##DT",ImGuiDataType_S8,&opE.dt,&_MINUS_ONE_HUNDRED_TWENTY_EIGHT,&_ONE_HUNDRED_TWENTY_SEVEN)); rightClickable + ImGui::TableNextColumn(); + ImGui::Text("%s",ESFM_NAME(ESFM_DT)); + } } @@ -5060,8 +5166,18 @@ void FurnaceGUI::drawInsEdit() { } if (ins->type==DIV_INS_ESFM) { + bool dvbOn=op.dvb; + bool damOn=op.dam; bool leftOn=opE.left; bool rightOn=opE.right; + bool fixedOn=opE.fixed; + if (ImGui::Checkbox(FM_NAME(FM_DVB),&dvbOn)) { PARAMETER + op.dvb=dvbOn; + } + ImGui::SameLine(); + if (ImGui::Checkbox(FM_NAME(FM_DAM),&damOn)) { PARAMETER + op.dam=damOn; + } if (ImGui::Checkbox(ESFM_NAME(ESFM_LEFT),&leftOn)) { PARAMETER opE.left=leftOn; } @@ -5069,6 +5185,10 @@ void FurnaceGUI::drawInsEdit() { if (ImGui::Checkbox(ESFM_NAME(ESFM_RIGHT),&rightOn)) { PARAMETER opE.right=rightOn; } + ImGui::SameLine(); + if (ImGui::Checkbox(ESFM_NAME(ESFM_FIXED),&fixedOn)) { PARAMETER + opE.fixed=fixedOn; + } } if (settings.separateFMColors) { From a01ddd381e347413d44f81b01230490ed3082b10 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Tue, 17 Oct 2023 19:24:57 -0300 Subject: [PATCH 10/34] Implement ESFM macros --- src/engine/instrument.h | 1 - src/engine/platform/esfm.cpp | 91 +++++++++++++++++++++++++-- src/gui/insEdit.cpp | 119 ++++++++++++++++++++++------------- 3 files changed, 163 insertions(+), 48 deletions(-) diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 6dfb49716..80c5dc3a6 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -802,7 +802,6 @@ struct DivInstrumentESFM { op[3].modIn=7; op[3].outLvl=7; } - }; struct DivInstrument { diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 5d08205c3..92f32c78d 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -93,12 +93,15 @@ void DivPlatformESFM::tick(bool sysTick) { chan[i].freqChanged=true; } - // TODO: check why I disabled globalPan here? -#if 0 if (chan[i].std.panL.had) { chan[i].globalPan=((chan[i].std.panL.val&1)<<1)|((chan[i].std.panL.val&2)>>1); + for (int o=0; o<4; o++) { + unsigned short baseAddr=i*32 + o*8; + DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } } -#endif if (chan[i].std.pitch.had) { if (chan[i].std.pitch.mode) { @@ -115,12 +118,28 @@ void DivPlatformESFM::tick(bool sysTick) { chan[i].keyOn=true; } } - + + if (chan[i].std.duty.had) { + int o=3; + unsigned short baseAddr=i*32 + o*8; + DivInstrumentESFM& ins=chan[i].state.esfm; + DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; + ins.noise=chan[i].std.duty.val; + + if (isMuted[i]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?ins.noise&3:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?ins.noise&3:0)<<3)|((opE.outLvl&7)<<5)); + } + } + for (int o=0; o<4; o++) { unsigned short baseAddr=i*32 + o*8; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; DivMacroInt::IntOp& m=chan[i].std.op[o]; - + if (m.am.had) { op.am=m.am.val; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); @@ -173,6 +192,68 @@ void DivPlatformESFM::tick(bool sysTick) { rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } + + if (m.dam.had) { + op.dam=m.dam.val; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + if (m.dvb.had) { + op.dvb=m.dvb.val; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + if (m.rs.had) { + // operator panning + opE.left=(m.rs.val&2)!=0; + opE.right=(m.rs.val&1)!=0; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + if (m.d2r.had) { + // modIn + opE.modIn=m.d2r.val; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + + if (m.egt.had | m.ws.had) { + unsigned char noise=chan[i].state.esfm.noise&3; + if (m.egt.had) { + // outLvl + opE.outLvl=m.egt.val; + } + if (m.ws.had) { + op.ws=m.ws.val; + } + + if (isMuted[i]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + } + } + + if (opE.fixed) { + if (m.ssg.had) { + opE.ct=(opE.ct&(~(7<<2)))|((m.ssg.val&7)<<2); + chan[i].freqChanged=true; + } + if (m.dt.had) { + opE.dt=m.dt.val&0xff; + opE.ct=(opE.ct&(~3))|((m.dt.val>>8)&3); + chan[i].freqChanged=true; + } + } else { + if (m.ssg.had) { + opE.ct=(signed char)m.ssg.val; + chan[i].freqChanged=true; + } + if (m.dt.had) { + opE.dt=(signed char)m.dt.val; + chan[i].freqChanged=true; + } + } + if (m.dt2.had) { + opE.delay=m.dt2.val; + rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); + } } } diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 0a08bc93c..14648e33c 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -5216,46 +5216,48 @@ void FurnaceGUI::drawInsEdit() { ImGui::EndDisabled(); ImGui::EndTabItem(); } - if (ImGui::BeginTabItem("FM Macros")) { - if (ins->type==DIV_INS_OPLL) { - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_SUS),&ins->std.algMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FB),&ins->std.fbMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_DC),&ins->std.fmsMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_DM),&ins->std.amsMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); - } else { - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_ALG),&ins->std.algMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FB),&ins->std.fbMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); - if (ins->type!=DIV_INS_OPL && ins->type!=DIV_INS_OPL_DRUMS) { - if (ins->type==DIV_INS_OPZ) { - // TODO: FMS2/AMS2 macros - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FMS),&ins->std.fmsMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AMS),&ins->std.amsMacro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER])); - } else { - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FMS),&ins->std.fmsMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AMS),&ins->std.amsMacro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER])); + if (ins->type!=DIV_INS_ESFM) { + if (ImGui::BeginTabItem("FM Macros")) { + if (ins->type==DIV_INS_OPLL) { + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_SUS),&ins->std.algMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FB),&ins->std.fbMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_DC),&ins->std.fmsMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_DM),&ins->std.amsMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + } else { + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_ALG),&ins->std.algMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FB),&ins->std.fbMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); + if (ins->type!=DIV_INS_OPL && ins->type!=DIV_INS_OPL_DRUMS) { + if (ins->type==DIV_INS_OPZ) { + // TODO: FMS2/AMS2 macros + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FMS),&ins->std.fmsMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AMS),&ins->std.amsMacro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER])); + } else { + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_FMS),&ins->std.fmsMacro,0,7,96,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AMS),&ins->std.amsMacro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER])); + } } } + + if (ins->type==DIV_INS_FM) { + macroList.push_back(FurnaceGUIMacroDesc("LFO Speed",&ins->std.ex3Macro,0,8,96,uiColors[GUI_COLOR_MACRO_OTHER])); + } + if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { + macroList.push_back(FurnaceGUIMacroDesc("AM Depth",&ins->std.ex1Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc("PM Depth",&ins->std.ex2Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc("LFO Speed",&ins->std.ex3Macro,0,255,128,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc("LFO Shape",&ins->std.waveMacro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,macroLFOWaves)); + } + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPM) { + macroList.push_back(FurnaceGUIMacroDesc("OpMask",&ins->std.ex4Macro,0,4,128,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true,fmOperatorBits)); + } else if (ins->type==DIV_INS_OPZ) { + macroList.push_back(FurnaceGUIMacroDesc("AM Depth 2",&ins->std.ex5Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc("PM Depth 2",&ins->std.ex6Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc("LFO2 Speed",&ins->std.ex7Macro,0,255,128,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc("LFO2 Shape",&ins->std.ex8Macro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,macroLFOWaves)); + } + drawMacros(macroList,macroEditStateFM); + ImGui::EndTabItem(); } - - if (ins->type==DIV_INS_FM) { - macroList.push_back(FurnaceGUIMacroDesc("LFO Speed",&ins->std.ex3Macro,0,8,96,uiColors[GUI_COLOR_MACRO_OTHER])); - } - if (ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) { - macroList.push_back(FurnaceGUIMacroDesc("AM Depth",&ins->std.ex1Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc("PM Depth",&ins->std.ex2Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc("LFO Speed",&ins->std.ex3Macro,0,255,128,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc("LFO Shape",&ins->std.waveMacro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,macroLFOWaves)); - } - if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPM) { - macroList.push_back(FurnaceGUIMacroDesc("OpMask",&ins->std.ex4Macro,0,4,128,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true,fmOperatorBits)); - } else if (ins->type==DIV_INS_OPZ) { - macroList.push_back(FurnaceGUIMacroDesc("AM Depth 2",&ins->std.ex5Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc("PM Depth 2",&ins->std.ex6Macro,0,127,128,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc("LFO2 Speed",&ins->std.ex7Macro,0,255,128,uiColors[GUI_COLOR_MACRO_OTHER])); - macroList.push_back(FurnaceGUIMacroDesc("LFO2 Shape",&ins->std.ex8Macro,0,3,48,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,macroLFOWaves)); - } - drawMacros(macroList,macroEditStateFM); - ImGui::EndTabItem(); } for (int i=0; itype==DIV_INS_OPL_DRUMS) { @@ -5275,7 +5277,7 @@ void FurnaceGUI::drawInsEdit() { maxTl=63; } } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_ESFM) { maxTl=63; } int maxArDr=(ins->type==DIV_INS_FM || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM)?31:15; @@ -5307,6 +5309,33 @@ void FurnaceGUI::drawInsEdit() { macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_VIB),&ins->std.opMacros[ordi].vibMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_KSR),&ins->std.opMacros[ordi].ksrMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_EGS),&ins->std.opMacros[ordi].egtMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + } else if (ins->type==DIV_INS_ESFM) { + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_TL),&ins->std.opMacros[ordi].tlMacro,0,maxTl,128,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(ESFM_NAME(ESFM_DELAY),&ins->std.opMacros[ordi].dt2Macro,0,7,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AR),&ins->std.opMacros[ordi].arMacro,0,maxArDr,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_DR),&ins->std.opMacros[ordi].drMacro,0,maxArDr,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_SL),&ins->std.opMacros[ordi].slMacro,0,15,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_RR),&ins->std.opMacros[ordi].rrMacro,0,15,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_KSL),&ins->std.opMacros[ordi].kslMacro,0,3,32,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_MULT),&ins->std.opMacros[ordi].multMacro,0,15,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_WS),&ins->std.opMacros[ordi].wsMacro,0,7,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(ESFM_NAME(ESFM_OUTLVL),&ins->std.opMacros[ordi].egtMacro,0,7,64,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc(ESFM_NAME(ESFM_MODIN),&ins->std.opMacros[ordi].d2rMacro,0,7,64,uiColors[GUI_COLOR_MACRO_OTHER])); + if (ins->esfm.op[ordi].fixed) { + macroList.push_back(FurnaceGUIMacroDesc("Block",&ins->std.opMacros[ordi].ssgMacro,0,7,64,uiColors[GUI_COLOR_MACRO_OTHER],true)); + macroList.push_back(FurnaceGUIMacroDesc("FreqNum",&ins->std.opMacros[ordi].dtMacro,0,1023,160,uiColors[GUI_COLOR_MACRO_OTHER])); + } else { + macroList.push_back(FurnaceGUIMacroDesc(ESFM_NAME(ESFM_CT),&ins->std.opMacros[ordi].ssgMacro,-24,24,128,uiColors[GUI_COLOR_MACRO_OTHER],true)); + macroList.push_back(FurnaceGUIMacroDesc(ESFM_NAME(ESFM_DT),&ins->std.opMacros[ordi].dtMacro,-128,127,160,uiColors[GUI_COLOR_MACRO_OTHER])); + } + + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AM),&ins->std.opMacros[ordi].amMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_VIB),&ins->std.opMacros[ordi].vibMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_DAM),&ins->std.opMacros[ordi].damMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_DVB),&ins->std.opMacros[ordi].dvbMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_KSR),&ins->std.opMacros[ordi].ksrMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_SUS),&ins->std.opMacros[ordi].susMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); + macroList.push_back(FurnaceGUIMacroDesc("Op. Panning",&ins->std.opMacros[ordi].rsMacro,0,2,40,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true,panBits)); } else { macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_TL),&ins->std.opMacros[ordi].tlMacro,0,maxTl,128,uiColors[GUI_COLOR_MACRO_OTHER])); macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AR),&ins->std.opMacros[ordi].arMacro,0,maxArDr,64,uiColors[GUI_COLOR_MACRO_OTHER])); @@ -6448,7 +6477,7 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_PCE || ins->type==DIV_INS_AY8930 || ins->type==DIV_INS_SM8521) { volMax=31; } - if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_VERA || ins->type==DIV_INS_VRC6_SAW) { + if (ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_VERA || ins->type==DIV_INS_VRC6_SAW || ins->type==DIV_INS_ESFM) { volMax=63; } if (ins->type==DIV_INS_AMIGA) { @@ -6628,6 +6657,10 @@ void FurnaceGUI::drawInsEdit() { dutyLabel="Echo Level"; dutyMax=32767; } + if (ins->type==DIV_INS_ESFM) { + dutyLabel="OP4 Noise Mode"; + dutyMax=3; + } const char* waveLabel="Waveform"; int waveMax=(ins->type==DIV_INS_VERA)?3:(MAX(1,e->song.waveLen-1)); @@ -6641,7 +6674,7 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_TIA || ins->type==DIV_INS_VIC || ins->type==DIV_INS_OPLL) waveMax=15; if (ins->type==DIV_INS_C64) waveMax=4; if (ins->type==DIV_INS_SAA1099) waveMax=2; - if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM) waveMax=0; + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPM || ins->type==DIV_INS_ESFM) waveMax=0; if (ins->type==DIV_INS_MIKEY) waveMax=0; if (ins->type==DIV_INS_MULTIPCM) waveMax=0; if (ins->type==DIV_INS_ADPCMA) waveMax=0; @@ -6742,7 +6775,8 @@ void FurnaceGUI::drawInsEdit() { ins->type==DIV_INS_MSM6258 || ins->type==DIV_INS_VERA || ins->type==DIV_INS_ADPCMA || - ins->type==DIV_INS_ADPCMB) { + ins->type==DIV_INS_ADPCMB || + ins->type==DIV_INS_ESFM) { panMax=2; panSingle=true; } @@ -6885,7 +6919,8 @@ void FurnaceGUI::drawInsEdit() { ins->type==DIV_INS_K053260 || ins->type==DIV_INS_C140 || ins->type==DIV_INS_C219 || - ins->type==DIV_INS_TED) { + ins->type==DIV_INS_TED || + ins->type==DIV_INS_ESFM) { macroList.push_back(FurnaceGUIMacroDesc("Phase Reset",&ins->std.phaseResetMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); } if (ex1Max>0) { From 6ce2fd0c9a710633353670eda3fc53da621df00a Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Tue, 17 Oct 2023 20:16:38 -0300 Subject: [PATCH 11/34] Adding ESFM letter-style instrument icon Thanks to Electric Keet for providing me with the icon! --- res/icons.sfd | 457 +++++++++++++++++++++++++++- res/icons.ttf | Bin 28552 -> 28880 bytes src/gui/font_furicon.cpp | 628 ++++++++++++++++++++------------------- src/gui/furIcons.h | 3 +- src/gui/guiConst.cpp | 3 +- 5 files changed, 762 insertions(+), 329 deletions(-) diff --git a/res/icons.sfd b/res/icons.sfd index f8e0f1efb..01fda2f2b 100644 --- a/res/icons.sfd +++ b/res/icons.sfd @@ -21,7 +21,7 @@ OS2Version: 0 OS2_WeightWidthSlopeOnly: 0 OS2_UseTypoMetrics: 0 CreationTime: 1691897631 -ModificationTime: 1693208149 +ModificationTime: 1697583349 PfmFamily: 81 TTFWeight: 400 TTFWidth: 5 @@ -47,13 +47,13 @@ LangName: 1033 Encoding: UnicodeBmp UnicodeInterp: none NameList: AGL For New Fonts -DisplaySize: -24 +DisplaySize: -48 AntiAlias: 1 FitToEm: 0 WinInfo: 57568 16 10 BeginPrivate: 0 EndPrivate -BeginChars: 65536 73 +BeginChars: 65536 74 StartChar: space Encoding: 32 32 0 @@ -4902,12 +4902,12 @@ Flags: HW LayerCount: 2 Fore SplineSet --717.389648438 -10.8251953125 m 8 +-717.389648438 -10.8251953125 m 12 NamedP: "baseline 2" - 717.249023438 -10.8251953125 l 1024 --896 0 m 8 + 717.249023438 -10.8251953125 l 1028 +-896 0 m 12 NamedP: "baseline 1" - 896 0 l 1024 + 896 0 l 1028 EndSplineSet Comment: "O" Colour: ff00ff @@ -5844,13 +5844,6 @@ LBearingChange: 0 UnicodeEnc: 0 InstructionsLength: 0 EndUndoOperation -UndoOperation -Index: 1 -Type: 3 -WasModified: 0 -WasOrder2: 0 -Layer: 2 -EndUndoOperation EndUndoes Redoes EndRedoes @@ -5965,5 +5958,441 @@ SplineSet 1449.28027344 618.5 l 1 EndSplineSet EndChar + +StartChar: uniE143 +Encoding: 57667 57667 73 +Width: 1792 +Flags: HW +LayerCount: 2 +UndoRedoHistory +Layer: 1 +Undoes +UndoOperation +Index: 0 +Type: 1 +WasModified: 1 +WasOrder2: 0 +Layer: 2 +Width: 1792 +VWidth: 1792 +LBearingChange: 0 +UnicodeEnc: 0 +InstructionsLength: 0 +SplineSet +-7.4218750005 -10.8251953125 m 5 + -7.4218750005 -8.033203125 -7.4218750005 -5.2412109375 -7.4218750005 -2.44921875 c 5 + -5.67805989633 -2.44921875 -3.93424479217 -2.44921875 -2.190429688 -2.44921875 c 5 + -2.190429688 -2.84928385417 -2.190429688 -3.24934895833 -2.190429688 -3.6494140625 c 5 + -3.4824218755 -3.6494140625 -4.774414063 -3.6494140625 -6.0664062505 -3.6494140625 c 5 + -6.0664062505 -4.42545572917 -6.0664062505 -5.20149739583 -6.0664062505 -5.9775390625 c 5 + -4.91829427133 -5.9775390625 -3.77018229217 -5.9775390625 -2.622070313 -5.9775390625 c 5 + -2.622070313 -6.37727864583 -2.622070313 -6.77701822917 -2.622070313 -7.1767578125 c 5 + -3.77018229217 -7.1767578125 -4.91829427133 -7.1767578125 -6.0664062505 -7.1767578125 c 5 + -6.0664062505 -8.39290364583 -6.0664062505 -9.60904947917 -6.0664062505 -10.8251953125 c 5 + -6.51822916717 -10.8251953125 -6.97005208383 -10.8251953125 -7.4218750005 -10.8251953125 c 5 +5.9863281245 -4.4169921875 m 5 + 5.96614583283 -4.4169921875 5.94596354117 -4.4169921875 5.9257812495 -4.4169921875 c 5 + 5.70572916617 -4.869140625 5.48567708283 -5.3212890625 5.2656249995 -5.7734375 c 5 + 4.65364583283 -6.88932291667 4.04166666617 -8.00520833333 3.4296874995 -9.12109375 c 5 + 2.81770833283 -8.00520833333 2.20572916617 -6.88932291667 1.5937499995 -5.7734375 c 5 + 1.37369791617 -5.3212890625 1.15364583283 -4.869140625 0.9335937495 -4.4169921875 c 5 + 0.913736978667 -4.4169921875 0.893880207833 -4.4169921875 0.874023437 -4.4169921875 c 5 + 0.874023437 -6.55305989583 0.874023437 -8.68912760417 0.874023437 -10.8251953125 c 5 + 0.442057291167 -10.8251953125 0.0100911453333 -10.8251953125 -0.4218750005 -10.8251953125 c 5 + -0.4218750005 -8.033203125 -0.4218750005 -5.2412109375 -0.4218750005 -2.44921875 c 5 + 0.113932291167 -2.44921875 0.649739582833 -2.44921875 1.1855468745 -2.44921875 c 5 + 1.9335937495 -3.869140625 2.6816406245 -5.2890625 3.4296874995 -6.708984375 c 5 + 3.45377604117 -6.708984375 3.47786458283 -6.708984375 3.5019531245 -6.708984375 c 5 + 4.2499999995 -5.2890625 4.9980468745 -3.869140625 5.7460937495 -2.44921875 c 5 + 6.25813802033 -2.44921875 6.77018229117 -2.44921875 7.282226562 -2.44921875 c 5 + 7.282226562 -5.2412109375 7.282226562 -8.033203125 7.282226562 -10.8251953125 c 5 + 6.85026041617 -10.8251953125 6.41829427033 -10.8251953125 5.9863281245 -10.8251953125 c 5 + 5.9863281245 -8.68912760417 5.9863281245 -6.55305989583 5.9863281245 -4.4169921875 c 5 +-6.271484375 0 m 5 + -6.271484375 2.7919921875 -6.271484375 5.583984375 -6.271484375 8.3759765625 c 5 + -4.48372395833 8.3759765625 -2.69596354167 8.3759765625 -0.908203125 8.3759765625 c 5 + -0.908203125 7.97591145833 -0.908203125 7.57584635417 -0.908203125 7.17578125 c 5 + -2.244140625 7.17578125 -3.580078125 7.17578125 -4.916015625 7.17578125 c 5 + -4.916015625 6.39973958333 -4.916015625 5.62369791667 -4.916015625 4.84765625 c 5 + -3.70377604167 4.84765625 -2.49153645833 4.84765625 -1.279296875 4.84765625 c 5 + -1.279296875 4.44791666667 -1.279296875 4.04817708333 -1.279296875 3.6484375 c 5 + -2.49153645833 3.6484375 -3.70377604167 3.6484375 -4.916015625 3.6484375 c 5 + -4.916015625 2.83235677083 -4.916015625 2.01627604167 -4.916015625 1.2001953125 c 5 + -3.580078125 1.2001953125 -2.244140625 1.2001953125 -0.908203125 1.2001953125 c 5 + -0.908203125 0.800130208333 -0.908203125 0.400065104167 -0.908203125 0 c 5 + -2.69596354167 -0 -4.48372395833 0 -6.271484375 0 c 5 +3.236328125 -0.1435546875 m 4 + 2.53125 -0.1435546875 1.93359375 -0.0156250000001 1.44140625 0.240234375 c 132 + 0.94921875 0.49609375 0.52734375 0.83984375 0.17578125 1.2724609375 c 5 + 0.487630208334 1.564453125 0.799479166666 1.8564453125 1.111328125 2.1484375 c 5 + 1.408203125 1.7880859375 1.734375 1.515625 2.08984375 1.33203125 c 132 + 2.4453125 1.1484375 2.8515625 1.0556640625 3.30859375 1.0556640625 c 4 + 3.84375 1.0556640625 4.248046875 1.17578125 4.51953125 1.416015625 c 132 + 4.791015625 1.65625 4.927734375 1.98046875 4.927734375 2.3876953125 c 4 + 4.927734375 2.7158203125 4.83203125 2.9755859375 4.640625 3.16796875 c 132 + 4.447265625 3.3603515625 4.107421875 3.50390625 3.619140625 3.599609375 c 5 + 3.37109375 3.64388020833 3.123046875 3.68815104167 2.875 3.732421875 c 5 + 2.060546875 3.8837890625 1.447265625 4.15234375 1.0390625 4.5361328125 c 132 + 0.630859375 4.919921875 0.427734375 5.4482421875 0.427734375 6.1201171875 c 4 + 0.427734375 6.48828125 0.498046875 6.822265625 0.638671875 7.1220703125 c 132 + 0.77734375 7.421875 0.974609375 7.673828125 1.2265625 7.8779296875 c 132 + 1.478515625 8.08203125 1.783203125 8.240234375 2.14453125 8.3515625 c 132 + 2.50390625 8.4638671875 2.908203125 8.51953125 3.35546875 8.51953125 c 4 + 3.98828125 8.51953125 4.53515625 8.41015625 5 8.1904296875 c 132 + 5.462890625 7.9697265625 5.859375 7.65234375 6.1875 7.236328125 c 5 + 5.87174479167 6.95638020833 5.55598958333 6.67643229167 5.240234375 6.396484375 c 5 + 5.0234375 6.67578125 4.759765625 6.900390625 4.447265625 7.068359375 c 132 + 4.13671875 7.236328125 3.748046875 7.3203125 3.283203125 7.3203125 c 4 + 2.8046875 7.3203125 2.431640625 7.2236328125 2.16796875 7.0322265625 c 132 + 1.904296875 6.83984375 1.771484375 6.5595703125 1.771484375 6.1923828125 c 4 + 1.771484375 5.83984375 1.87890625 5.578125 2.095703125 5.40625 c 132 + 2.3125 5.234375 2.6484375 5.103515625 3.103515625 5.015625 c 5 + 3.3515625 4.9638671875 3.599609375 4.912109375 3.84765625 4.8603515625 c 5 + 4.6875 4.7001953125 5.302734375 4.427734375 5.689453125 4.0439453125 c 132 + 6.078125 3.66015625 6.271484375 3.1318359375 6.271484375 2.4599609375 c 4 + 6.271484375 2.068359375 6.203125 1.7119140625 6.068359375 1.3916015625 c 132 + 5.931640625 1.072265625 5.734375 0.7978515625 5.474609375 0.5703125 c 132 + 5.212890625 0.341796875 4.896484375 0.166015625 4.51953125 0.0419921875 c 132 + 4.14453125 -0.0820312500001 3.71484375 -0.1435546875 3.236328125 -0.1435546875 c 4 +EndSplineSet +EndUndoOperation +UndoOperation +Index: 1 +Type: 3 +WasModified: 1 +WasOrder2: 0 +Layer: 2 +EndUndoOperation +UndoOperation +Index: 2 +Type: 1 +WasModified: 1 +WasOrder2: 0 +Layer: 2 +Width: 1792 +VWidth: 1792 +LBearingChange: 0 +UnicodeEnc: 0 +InstructionsLength: 0 +SplineSet +-7.4218750005 -10.8251953125 m 1 + -7.4218750005 -8.033203125 -7.4218750005 -5.2412109375 -7.4218750005 -2.44921875 c 1 + -5.67805989633 -2.44921875 -3.93424479217 -2.44921875 -2.190429688 -2.44921875 c 1 + -2.190429688 -2.84928385417 -2.190429688 -3.24934895833 -2.190429688 -3.6494140625 c 1 + -3.4824218755 -3.6494140625 -4.774414063 -3.6494140625 -6.0664062505 -3.6494140625 c 1 + -6.0664062505 -4.42545572917 -6.0664062505 -5.20149739583 -6.0664062505 -5.9775390625 c 1 + -4.91829427133 -5.9775390625 -3.77018229217 -5.9775390625 -2.622070313 -5.9775390625 c 1 + -2.622070313 -6.37727864583 -2.622070313 -6.77701822917 -2.622070313 -7.1767578125 c 1 + -3.77018229217 -7.1767578125 -4.91829427133 -7.1767578125 -6.0664062505 -7.1767578125 c 1 + -6.0664062505 -8.39290364583 -6.0664062505 -9.60904947917 -6.0664062505 -10.8251953125 c 1 + -6.51822916717 -10.8251953125 -6.97005208383 -10.8251953125 -7.4218750005 -10.8251953125 c 1 +5.9863281245 -4.4169921875 m 1 + 5.96614583283 -4.4169921875 5.94596354117 -4.4169921875 5.9257812495 -4.4169921875 c 1 + 5.70572916617 -4.869140625 5.48567708283 -5.3212890625 5.2656249995 -5.7734375 c 1 + 4.65364583283 -6.88932291667 4.04166666617 -8.00520833333 3.4296874995 -9.12109375 c 1 + 2.81770833283 -8.00520833333 2.20572916617 -6.88932291667 1.5937499995 -5.7734375 c 1 + 1.37369791617 -5.3212890625 1.15364583283 -4.869140625 0.9335937495 -4.4169921875 c 1 + 0.913736978667 -4.4169921875 0.893880207833 -4.4169921875 0.874023437 -4.4169921875 c 1 + 0.874023437 -6.55305989583 0.874023437 -8.68912760417 0.874023437 -10.8251953125 c 1 + 0.442057291167 -10.8251953125 0.0100911453333 -10.8251953125 -0.4218750005 -10.8251953125 c 1 + -0.4218750005 -8.033203125 -0.4218750005 -5.2412109375 -0.4218750005 -2.44921875 c 1 + 0.113932291167 -2.44921875 0.649739582833 -2.44921875 1.1855468745 -2.44921875 c 1 + 1.9335937495 -3.869140625 2.6816406245 -5.2890625 3.4296874995 -6.708984375 c 1 + 3.45377604117 -6.708984375 3.47786458283 -6.708984375 3.5019531245 -6.708984375 c 1 + 4.2499999995 -5.2890625 4.9980468745 -3.869140625 5.7460937495 -2.44921875 c 1 + 6.25813802033 -2.44921875 6.77018229117 -2.44921875 7.282226562 -2.44921875 c 1 + 7.282226562 -5.2412109375 7.282226562 -8.033203125 7.282226562 -10.8251953125 c 1 + 6.85026041617 -10.8251953125 6.41829427033 -10.8251953125 5.9863281245 -10.8251953125 c 1 + 5.9863281245 -8.68912760417 5.9863281245 -6.55305989583 5.9863281245 -4.4169921875 c 1 +-6.271484375 0 m 1 + -6.271484375 2.7919921875 -6.271484375 5.583984375 -6.271484375 8.3759765625 c 1 + -4.48372395833 8.3759765625 -2.69596354167 8.3759765625 -0.908203125 8.3759765625 c 1 + -0.908203125 7.97591145833 -0.908203125 7.57584635417 -0.908203125 7.17578125 c 1 + -2.244140625 7.17578125 -3.580078125 7.17578125 -4.916015625 7.17578125 c 1 + -4.916015625 6.39973958333 -4.916015625 5.62369791667 -4.916015625 4.84765625 c 1 + -3.70377604167 4.84765625 -2.49153645833 4.84765625 -1.279296875 4.84765625 c 1 + -1.279296875 4.44791666667 -1.279296875 4.04817708333 -1.279296875 3.6484375 c 1 + -2.49153645833 3.6484375 -3.70377604167 3.6484375 -4.916015625 3.6484375 c 1 + -4.916015625 2.83235677083 -4.916015625 2.01627604167 -4.916015625 1.2001953125 c 1 + -3.580078125 1.2001953125 -2.244140625 1.2001953125 -0.908203125 1.2001953125 c 1 + -0.908203125 0.800130208333 -0.908203125 0.400065104167 -0.908203125 0 c 1 + -2.69596354167 -0 -4.48372395833 0 -6.271484375 0 c 1 +3.236328125 -0.1435546875 m 0 + 2.53125 -0.1435546875 1.93359375 -0.0156250000001 1.44140625 0.240234375 c 128 + 0.94921875 0.49609375 0.52734375 0.83984375 0.17578125 1.2724609375 c 1 + 0.487630208334 1.564453125 0.799479166666 1.8564453125 1.111328125 2.1484375 c 1 + 1.408203125 1.7880859375 1.734375 1.515625 2.08984375 1.33203125 c 128 + 2.4453125 1.1484375 2.8515625 1.0556640625 3.30859375 1.0556640625 c 0 + 3.84375 1.0556640625 4.248046875 1.17578125 4.51953125 1.416015625 c 128 + 4.791015625 1.65625 4.927734375 1.98046875 4.927734375 2.3876953125 c 0 + 4.927734375 2.7158203125 4.83203125 2.9755859375 4.640625 3.16796875 c 128 + 4.447265625 3.3603515625 4.107421875 3.50390625 3.619140625 3.599609375 c 1 + 3.37109375 3.64388020833 3.123046875 3.68815104167 2.875 3.732421875 c 1 + 2.060546875 3.8837890625 1.447265625 4.15234375 1.0390625 4.5361328125 c 128 + 0.630859375 4.919921875 0.427734375 5.4482421875 0.427734375 6.1201171875 c 0 + 0.427734375 6.48828125 0.498046875 6.822265625 0.638671875 7.1220703125 c 128 + 0.77734375 7.421875 0.974609375 7.673828125 1.2265625 7.8779296875 c 128 + 1.478515625 8.08203125 1.783203125 8.240234375 2.14453125 8.3515625 c 128 + 2.50390625 8.4638671875 2.908203125 8.51953125 3.35546875 8.51953125 c 0 + 3.98828125 8.51953125 4.53515625 8.41015625 5 8.1904296875 c 128 + 5.462890625 7.9697265625 5.859375 7.65234375 6.1875 7.236328125 c 1 + 5.87174479167 6.95638020833 5.55598958333 6.67643229167 5.240234375 6.396484375 c 1 + 5.0234375 6.67578125 4.759765625 6.900390625 4.447265625 7.068359375 c 128 + 4.13671875 7.236328125 3.748046875 7.3203125 3.283203125 7.3203125 c 0 + 2.8046875 7.3203125 2.431640625 7.2236328125 2.16796875 7.0322265625 c 128 + 1.904296875 6.83984375 1.771484375 6.5595703125 1.771484375 6.1923828125 c 0 + 1.771484375 5.83984375 1.87890625 5.578125 2.095703125 5.40625 c 128 + 2.3125 5.234375 2.6484375 5.103515625 3.103515625 5.015625 c 1 + 3.3515625 4.9638671875 3.599609375 4.912109375 3.84765625 4.8603515625 c 1 + 4.6875 4.7001953125 5.302734375 4.427734375 5.689453125 4.0439453125 c 128 + 6.078125 3.66015625 6.271484375 3.1318359375 6.271484375 2.4599609375 c 0 + 6.271484375 2.068359375 6.203125 1.7119140625 6.068359375 1.3916015625 c 128 + 5.931640625 1.072265625 5.734375 0.7978515625 5.474609375 0.5703125 c 128 + 5.212890625 0.341796875 4.896484375 0.166015625 4.51953125 0.0419921875 c 128 + 4.14453125 -0.0820312500001 3.71484375 -0.1435546875 3.236328125 -0.1435546875 c 0 +-717.389648438 -10.8251953125 m 12 +NamedP: "baseline 2" + 717.249023438 -10.8251953125 l 1028 +EndSplineSet +EndUndoOperation +UndoOperation +Index: 3 +Type: 1 +WasModified: 1 +WasOrder2: 0 +Layer: 2 +Width: 1792 +VWidth: 1792 +LBearingChange: 0 +UnicodeEnc: 0 +InstructionsLength: 0 +SplineSet +-6.271484375 0 m 1 + -6.271484375 2.7919921875 -6.271484375 5.583984375 -6.271484375 8.3759765625 c 1 + -4.48372395833 8.3759765625 -2.69596354167 8.3759765625 -0.908203125 8.3759765625 c 1 + -0.908203125 7.97591145833 -0.908203125 7.57584635417 -0.908203125 7.17578125 c 1 + -2.244140625 7.17578125 -3.580078125 7.17578125 -4.916015625 7.17578125 c 1 + -4.916015625 6.39973958333 -4.916015625 5.62369791667 -4.916015625 4.84765625 c 1 + -3.70377604167 4.84765625 -2.49153645833 4.84765625 -1.279296875 4.84765625 c 1 + -1.279296875 4.44791666667 -1.279296875 4.04817708333 -1.279296875 3.6484375 c 1 + -2.49153645833 3.6484375 -3.70377604167 3.6484375 -4.916015625 3.6484375 c 1 + -4.916015625 2.83235677083 -4.916015625 2.01627604167 -4.916015625 1.2001953125 c 1 + -3.580078125 1.2001953125 -2.244140625 1.2001953125 -0.908203125 1.2001953125 c 1 + -0.908203125 0.800130208333 -0.908203125 0.400065104167 -0.908203125 0 c 1 + -2.69596354167 -0 -4.48372395833 0 -6.271484375 0 c 1 +3.236328125 -0.1435546875 m 0 + 2.53125 -0.1435546875 1.93359375 -0.0156250000001 1.44140625 0.240234375 c 128 + 0.94921875 0.49609375 0.52734375 0.83984375 0.17578125 1.2724609375 c 1 + 0.487630208334 1.564453125 0.799479166666 1.8564453125 1.111328125 2.1484375 c 1 + 1.408203125 1.7880859375 1.734375 1.515625 2.08984375 1.33203125 c 128 + 2.4453125 1.1484375 2.8515625 1.0556640625 3.30859375 1.0556640625 c 0 + 3.84375 1.0556640625 4.248046875 1.17578125 4.51953125 1.416015625 c 128 + 4.791015625 1.65625 4.927734375 1.98046875 4.927734375 2.3876953125 c 0 + 4.927734375 2.7158203125 4.83203125 2.9755859375 4.640625 3.16796875 c 128 + 4.447265625 3.3603515625 4.107421875 3.50390625 3.619140625 3.599609375 c 1 + 3.37109375 3.64388020833 3.123046875 3.68815104167 2.875 3.732421875 c 1 + 2.060546875 3.8837890625 1.447265625 4.15234375 1.0390625 4.5361328125 c 128 + 0.630859375 4.919921875 0.427734375 5.4482421875 0.427734375 6.1201171875 c 0 + 0.427734375 6.48828125 0.498046875 6.822265625 0.638671875 7.1220703125 c 128 + 0.77734375 7.421875 0.974609375 7.673828125 1.2265625 7.8779296875 c 128 + 1.478515625 8.08203125 1.783203125 8.240234375 2.14453125 8.3515625 c 128 + 2.50390625 8.4638671875 2.908203125 8.51953125 3.35546875 8.51953125 c 0 + 3.98828125 8.51953125 4.53515625 8.41015625 5 8.1904296875 c 128 + 5.462890625 7.9697265625 5.859375 7.65234375 6.1875 7.236328125 c 1 + 5.87174479167 6.95638020833 5.55598958333 6.67643229167 5.240234375 6.396484375 c 1 + 5.0234375 6.67578125 4.759765625 6.900390625 4.447265625 7.068359375 c 128 + 4.13671875 7.236328125 3.748046875 7.3203125 3.283203125 7.3203125 c 0 + 2.8046875 7.3203125 2.431640625 7.2236328125 2.16796875 7.0322265625 c 128 + 1.904296875 6.83984375 1.771484375 6.5595703125 1.771484375 6.1923828125 c 0 + 1.771484375 5.83984375 1.87890625 5.578125 2.095703125 5.40625 c 128 + 2.3125 5.234375 2.6484375 5.103515625 3.103515625 5.015625 c 1 + 3.3515625 4.9638671875 3.599609375 4.912109375 3.84765625 4.8603515625 c 1 + 4.6875 4.7001953125 5.302734375 4.427734375 5.689453125 4.0439453125 c 128 + 6.078125 3.66015625 6.271484375 3.1318359375 6.271484375 2.4599609375 c 0 + 6.271484375 2.068359375 6.203125 1.7119140625 6.068359375 1.3916015625 c 128 + 5.931640625 1.072265625 5.734375 0.7978515625 5.474609375 0.5703125 c 128 + 5.212890625 0.341796875 4.896484375 0.166015625 4.51953125 0.0419921875 c 128 + 4.14453125 -0.0820312500001 3.71484375 -0.1435546875 3.236328125 -0.1435546875 c 0 +-717.389648438 -10.8251953125 m 12 +NamedP: "baseline 2" + 717.249023438 -10.8251953125 l 1028 +EndSplineSet +EndUndoOperation +UndoOperation +Index: 4 +Type: 1 +WasModified: 1 +WasOrder2: 0 +Layer: 2 +Width: 1792 +VWidth: 1792 +LBearingChange: 0 +UnicodeEnc: 0 +InstructionsLength: 0 +SplineSet +-6.271484375 0 m 1 + -6.271484375 2.7919921875 -6.271484375 5.583984375 -6.271484375 8.3759765625 c 1 + -4.48372395833 8.3759765625 -2.69596354167 8.3759765625 -0.908203125 8.3759765625 c 1 + -0.908203125 7.97591145833 -0.908203125 7.57584635417 -0.908203125 7.17578125 c 1 + -2.244140625 7.17578125 -3.580078125 7.17578125 -4.916015625 7.17578125 c 1 + -4.916015625 6.39973958333 -4.916015625 5.62369791667 -4.916015625 4.84765625 c 1 + -3.70377604167 4.84765625 -2.49153645833 4.84765625 -1.279296875 4.84765625 c 1 + -1.279296875 4.44791666667 -1.279296875 4.04817708333 -1.279296875 3.6484375 c 1 + -2.49153645833 3.6484375 -3.70377604167 3.6484375 -4.916015625 3.6484375 c 1 + -4.916015625 2.83235677083 -4.916015625 2.01627604167 -4.916015625 1.2001953125 c 1 + -3.580078125 1.2001953125 -2.244140625 1.2001953125 -0.908203125 1.2001953125 c 1 + -0.908203125 0.800130208333 -0.908203125 0.400065104167 -0.908203125 0 c 1 + -2.69596354167 -0 -4.48372395833 0 -6.271484375 0 c 1 +3.236328125 -0.1435546875 m 0 + 2.53125 -0.1435546875 1.93359375 -0.0156250000001 1.44140625 0.240234375 c 128 + 0.94921875 0.49609375 0.52734375 0.83984375 0.17578125 1.2724609375 c 1 + 0.487630208334 1.564453125 0.799479166666 1.8564453125 1.111328125 2.1484375 c 1 + 1.408203125 1.7880859375 1.734375 1.515625 2.08984375 1.33203125 c 128 + 2.4453125 1.1484375 2.8515625 1.0556640625 3.30859375 1.0556640625 c 0 + 3.84375 1.0556640625 4.248046875 1.17578125 4.51953125 1.416015625 c 128 + 4.791015625 1.65625 4.927734375 1.98046875 4.927734375 2.3876953125 c 0 + 4.927734375 2.7158203125 4.83203125 2.9755859375 4.640625 3.16796875 c 128 + 4.447265625 3.3603515625 4.107421875 3.50390625 3.619140625 3.599609375 c 1 + 3.37109375 3.64388020833 3.123046875 3.68815104167 2.875 3.732421875 c 1 + 2.060546875 3.8837890625 1.447265625 4.15234375 1.0390625 4.5361328125 c 128 + 0.630859375 4.919921875 0.427734375 5.4482421875 0.427734375 6.1201171875 c 0 + 0.427734375 6.48828125 0.498046875 6.822265625 0.638671875 7.1220703125 c 128 + 0.77734375 7.421875 0.974609375 7.673828125 1.2265625 7.8779296875 c 128 + 1.478515625 8.08203125 1.783203125 8.240234375 2.14453125 8.3515625 c 128 + 2.50390625 8.4638671875 2.908203125 8.51953125 3.35546875 8.51953125 c 0 + 3.98828125 8.51953125 4.53515625 8.41015625 5 8.1904296875 c 128 + 5.462890625 7.9697265625 5.859375 7.65234375 6.1875 7.236328125 c 1 + 5.87174479167 6.95638020833 5.55598958333 6.67643229167 5.240234375 6.396484375 c 1 + 5.0234375 6.67578125 4.759765625 6.900390625 4.447265625 7.068359375 c 128 + 4.13671875 7.236328125 3.748046875 7.3203125 3.283203125 7.3203125 c 0 + 2.8046875 7.3203125 2.431640625 7.2236328125 2.16796875 7.0322265625 c 128 + 1.904296875 6.83984375 1.771484375 6.5595703125 1.771484375 6.1923828125 c 0 + 1.771484375 5.83984375 1.87890625 5.578125 2.095703125 5.40625 c 128 + 2.3125 5.234375 2.6484375 5.103515625 3.103515625 5.015625 c 1 + 3.3515625 4.9638671875 3.599609375 4.912109375 3.84765625 4.8603515625 c 1 + 4.6875 4.7001953125 5.302734375 4.427734375 5.689453125 4.0439453125 c 128 + 6.078125 3.66015625 6.271484375 3.1318359375 6.271484375 2.4599609375 c 0 + 6.271484375 2.068359375 6.203125 1.7119140625 6.068359375 1.3916015625 c 128 + 5.931640625 1.072265625 5.734375 0.7978515625 5.474609375 0.5703125 c 128 + 5.212890625 0.341796875 4.896484375 0.166015625 4.51953125 0.0419921875 c 128 + 4.14453125 -0.0820312500001 3.71484375 -0.1435546875 3.236328125 -0.1435546875 c 0 +-717.389648438 -10.8251953125 m 8 +NamedP: "baseline 2" + 717.249023438 -10.8251953125 l 1024 +-896 0 m 12 +NamedP: "baseline 1" + 896 0 l 1028 +EndSplineSet +EndUndoOperation +UndoOperation +Index: 5 +Type: 1 +WasModified: 1 +WasOrder2: 0 +Layer: 2 +Width: 1792 +VWidth: 1792 +LBearingChange: 0 +UnicodeEnc: 0 +InstructionsLength: 0 +SplineSet +-717.389648438 -10.8251953125 m 8 +NamedP: "baseline 2" + 717.249023438 -10.8251953125 l 1024 +-896 0 m 12 +NamedP: "baseline 1" + 896 0 l 1028 +EndSplineSet +EndUndoOperation +UndoOperation +Index: 6 +Type: 3 +WasModified: 0 +WasOrder2: 0 +Layer: 2 +EndUndoOperation +EndUndoes +Redoes +EndRedoes +EndUndoRedoHistory +Fore +SplineSet +302.25 -247.515625 m 5 + 302.25 -24.15625 302.25 199.203125 302.25 422.5625 c 5 + 441.754882812 422.5625 581.260742188 422.5625 720.765625 422.5625 c 5 + 720.765625 390.557617188 720.765625 358.551757812 720.765625 326.546875 c 5 + 617.40625 326.546875 514.046875 326.546875 410.6875 326.546875 c 5 + 410.6875 264.463867188 410.6875 202.379882812 410.6875 140.296875 c 5 + 502.536132812 140.296875 594.385742188 140.296875 686.234375 140.296875 c 5 + 686.234375 108.317382812 686.234375 76.3388671875 686.234375 44.359375 c 5 + 594.385742188 44.359375 502.536132812 44.359375 410.6875 44.359375 c 5 + 410.6875 -52.9326171875 410.6875 -150.223632812 410.6875 -247.515625 c 5 + 374.541992188 -247.515625 338.395507812 -247.515625 302.25 -247.515625 c 5 +1374.90625 265.140625 m 5 + 1373.29199219 265.140625 1371.67675781 265.140625 1370.0625 265.140625 c 5 + 1352.45800781 228.96875 1334.85449219 192.796875 1317.25 156.625 c 5 + 1268.29199219 67.3544921875 1219.33300781 -21.9169921875 1170.375 -111.1875 c 5 + 1121.41699219 -21.9169921875 1072.45800781 67.3544921875 1023.5 156.625 c 5 + 1005.89550781 192.796875 988.291992188 228.96875 970.6875 265.140625 c 5 + 969.098632812 265.140625 967.510742188 265.140625 965.921875 265.140625 c 5 + 965.921875 94.2548828125 965.921875 -76.6298828125 965.921875 -247.515625 c 5 + 931.364257812 -247.515625 896.807617188 -247.515625 862.25 -247.515625 c 5 + 862.25 -24.15625 862.25 199.203125 862.25 422.5625 c 5 + 905.114257812 422.5625 947.979492188 422.5625 990.84375 422.5625 c 5 + 1050.6875 308.96875 1110.53125 195.375 1170.375 81.78125 c 5 + 1172.30175781 81.78125 1174.22949219 81.78125 1176.15625 81.78125 c 5 + 1236 195.375 1295.84375 308.96875 1355.6875 422.5625 c 5 + 1396.65136719 422.5625 1437.61425781 422.5625 1478.578125 422.5625 c 5 + 1478.578125 199.203125 1478.578125 -24.15625 1478.578125 -247.515625 c 5 + 1444.02050781 -247.515625 1409.46386719 -247.515625 1374.90625 -247.515625 c 5 + 1374.90625 -76.6298828125 1374.90625 94.2548828125 1374.90625 265.140625 c 5 +394.28125 618.5 m 5 + 394.28125 841.859375 394.28125 1065.21875 394.28125 1288.578125 c 5 + 537.301757812 1288.578125 680.323242188 1288.578125 823.34375 1288.578125 c 5 + 823.34375 1256.57324219 823.34375 1224.56738281 823.34375 1192.5625 c 5 + 716.46875 1192.5625 609.59375 1192.5625 502.71875 1192.5625 c 5 + 502.71875 1130.47949219 502.71875 1068.39550781 502.71875 1006.3125 c 5 + 599.698242188 1006.3125 696.676757812 1006.3125 793.65625 1006.3125 c 5 + 793.65625 974.333007812 793.65625 942.354492188 793.65625 910.375 c 5 + 696.676757812 910.375 599.698242188 910.375 502.71875 910.375 c 5 + 502.71875 845.088867188 502.71875 779.801757812 502.71875 714.515625 c 5 + 609.59375 714.515625 716.46875 714.515625 823.34375 714.515625 c 5 + 823.34375 682.510742188 823.34375 650.504882812 823.34375 618.5 c 5 + 680.323242188 618.5 537.301757812 618.5 394.28125 618.5 c 5 +1154.90625 607.015625 m 4 + 1098.5 607.015625 1050.6875 617.25 1011.3125 637.71875 c 132 + 971.9375 658.1875 938.1875 685.6875 910.0625 720.296875 c 5 + 935.010742188 743.65625 959.958007812 767.015625 984.90625 790.375 c 5 + 1008.65625 761.546875 1034.75 739.75 1063.1875 725.0625 c 132 + 1091.625 710.375 1124.125 702.953125 1160.6875 702.953125 c 4 + 1203.5 702.953125 1235.84375 712.5625 1257.5625 731.78125 c 132 + 1279.28125 751 1290.21875 776.9375 1290.21875 809.515625 c 4 + 1290.21875 835.765625 1282.5625 856.546875 1267.25 871.9375 c 132 + 1251.78125 887.328125 1224.59375 898.8125 1185.53125 906.46875 c 5 + 1165.6875 910.010742188 1145.84375 913.551757812 1126 917.09375 c 5 + 1060.84375 929.203125 1011.78125 950.6875 979.125 981.390625 c 132 + 946.46875 1012.09375 930.21875 1054.359375 930.21875 1108.109375 c 4 + 930.21875 1137.5625 935.84375 1164.28125 947.09375 1188.265625 c 132 + 958.1875 1212.25 973.96875 1232.40625 994.125 1248.734375 c 132 + 1014.28125 1265.0625 1038.65625 1277.71875 1067.5625 1286.625 c 132 + 1096.3125 1295.609375 1128.65625 1300.0625 1164.4375 1300.0625 c 4 + 1215.0625 1300.0625 1258.8125 1291.3125 1296 1273.734375 c 132 + 1333.03125 1256.078125 1364.75 1230.6875 1391 1197.40625 c 5 + 1365.73925781 1175.01074219 1340.47949219 1152.61425781 1315.21875 1130.21875 c 5 + 1297.875 1152.5625 1276.78125 1170.53125 1251.78125 1183.96875 c 132 + 1226.9375 1197.40625 1195.84375 1204.125 1158.65625 1204.125 c 4 + 1120.375 1204.125 1090.53125 1196.390625 1069.4375 1181.078125 c 132 + 1048.34375 1165.6875 1037.71875 1143.265625 1037.71875 1113.890625 c 4 + 1037.71875 1085.6875 1046.3125 1064.75 1063.65625 1051 c 132 + 1081 1037.25 1107.875 1026.78125 1144.28125 1019.75 c 5 + 1164.125 1015.609375 1183.96875 1011.46875 1203.8125 1007.328125 c 5 + 1271 994.515625 1320.21875 972.71875 1351.15625 942.015625 c 132 + 1382.25 911.3125 1397.71875 869.046875 1397.71875 815.296875 c 4 + 1397.71875 783.96875 1392.25 755.453125 1381.46875 729.828125 c 132 + 1370.53125 704.28125 1354.75 682.328125 1333.96875 664.125 c 132 + 1313.03125 645.84375 1287.71875 631.78125 1257.5625 621.859375 c 132 + 1227.5625 611.9375 1193.1875 607.015625 1154.90625 607.015625 c 4 +EndSplineSet +EndChar EndChars EndSplineFont diff --git a/res/icons.ttf b/res/icons.ttf index 028b424afcdc06dd1308e590dd4a3a87247046d5..217d1714a2e62a22739f361f475710d0df8d4c64 100644 GIT binary patch delta 741 zcmYLGT}YEr7=F(8v!6aqolchCgDmPn_mGZM4Jb;Hq1L$&MTGFe}Mp@s0EIyGSXp+8OL7VQIJQuNm} zGBvXiw}oTlleH_w=ZQZfem5HLSKoJU-lql~#Bayc$pmhSbeClww2rE=!9~x5Iv{d` zwCzNEY+SatJ^^AgfGA~$rGbxJv3SoG__m=Kv~&+x-AT`9>RQk930}zjtdk#OXIKkg zU`vh6m9a8oWVa>T1^7%X6P^VUUQpH15~x~Nf3CIgSz(cNBz>Zm@qlzk@CK6`(!^ke z#9V2e{8~0bk1Dt@49G>5#_TF${86xkubz^Xe-asd+HK@tt<}}c#qOovvf|V?aaq<^ z>rH)oOnoN3O(%!1CN)c!!++}dN58N4moOiC8cKZohLa@dW=UHQemUG;lw%;pO4 z;K=?OJ8tD7kdTk{9F|eQ3UgS4Jl4z~k2vi;2xMZC^b}G#UgfZi3VhFD4NS~RvGGX6 z%zaTEcSJ&ZH=5vt8x5RC9E!Wi>27d(8a&?rr?w(0?}%2?M~z131a>s3i5(Jj+KJI~ O0e7R9x5xb={pDXS`mLt` delta 512 zcmccckg?-FV?6^S0|NseLjwadLxP)Ii0{H@CzmlWBzTP#FUQV+N2PmYkbdaD3AF7Yqzc2|%$&$z>%94Aw093=AwTKzWw*#NvYg|A8hm zh(Be?d-ua^m^mZ9vDcfDD|Kn^;l6FpU|gml4EQ$V<#kt#04b!N8Ce0TlaG zkY8M~FlPHB28J9Tpd){QJqz@(A%lBQJipCX25upCpgsnM2Y>(12hk4&|6QFdz-Y_p zGue+ZmeFbQ8pbUKKyjcKz*q)s0t3SxAP*F9G7KyX2Y@sO5HbO2g$G|AI!&I!w05&I zGaKV%cb54;(akSdN>e9K%{EfkWS9vxfQ5mV;Xahj%D~Ua3uUu0@GzQBewVGQ8N}cU zvV?^bXoVERVJMrGL5|@ql+DH Date: Wed, 18 Oct 2023 17:01:46 -0300 Subject: [PATCH 12/34] Updating ESFMu with envelope delay fix; fixing macro op ordering --- extern/ESFMu/esfm.c | 50 ++++++++++++++++++++++++++++++++------------- extern/ESFMu/esfm.h | 4 ++-- src/gui/insEdit.cpp | 2 +- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/extern/ESFMu/esfm.c b/extern/ESFMu/esfm.c index f1979f8e6..f0043fba6 100644 --- a/extern/ESFMu/esfm.c +++ b/extern/ESFMu/esfm.c @@ -373,6 +373,8 @@ ESFM_envelope_calc(esfm_slot *slot) int16 eg_inc; bool reset = 0; bool key_on; + bool key_on_signal; + uint16 delay_counter_compare; key_on = *slot->in.key_on; if (!slot->chip->native_mode) @@ -408,26 +410,46 @@ ESFM_envelope_calc(esfm_slot *slot) } slot->in.eg_output += tremolo; } + + if (slot->in.eg_delay_run && slot->in.eg_delay_counter < 32768) + { + slot->in.eg_delay_counter++; + } + + // triggers on key-on edge + if (key_on && !slot->in.key_on_gate) + { + slot->in.eg_delay_run = 1; + slot->in.eg_delay_counter = 0; + } + else if (!key_on) + { + slot->in.eg_delay_run = 0; + } + + delay_counter_compare = 0; + if (slot->env_delay > 0) + { + delay_counter_compare = 256 << slot->env_delay; + } + + if (key_on && ((slot->in.eg_delay_counter >= delay_counter_compare) || !slot->chip->native_mode)) + { + key_on_signal = 1; + } else { + key_on_signal = 0; + } + if (key_on && slot->in.eg_state == EG_RELEASE) { - if (!slot->in.eg_delay_run && slot->chip->native_mode) - { - slot->in.eg_delay_run = 1; - slot->in.eg_delay_counter = slot->env_delay ? 0x100 : 0; - } - if (slot->in.eg_delay_counter == 0 || !slot->chip->native_mode) + if ((slot->in.eg_delay_counter >= delay_counter_compare) || !slot->chip->native_mode) { - slot->in.eg_delay_run = 0; reset = 1; reg_rate = slot->attack_rate; } else { - if ((slot->chip->global_timer & ((1 << slot->env_delay) - 1)) == 0) - { - slot->in.eg_delay_counter--; - } reg_rate = slot->release_rate; } } @@ -452,6 +474,7 @@ ESFM_envelope_calc(esfm_slot *slot) break; } } + slot->in.key_on_gate = key_on; slot->in.phase_reset = reset; ks = slot->in.keyscale >> ((!slot->ksr) << 1); nonzero = (reg_rate != 0); @@ -524,7 +547,7 @@ ESFM_envelope_calc(esfm_slot *slot) { slot->in.eg_state = EG_DECAY; } - else if (key_on && shift > 0 && rate_hi != 0x0f) + else if (key_on_signal && shift > 0 && rate_hi != 0x0f) { eg_inc = ~slot->in.eg_position >> (4 - shift); } @@ -553,10 +576,9 @@ ESFM_envelope_calc(esfm_slot *slot) { slot->in.eg_state = EG_ATTACK; } - if (!key_on) + if (!key_on_signal) { slot->in.eg_state = EG_RELEASE; - slot->in.eg_delay_run = 0; } } diff --git a/extern/ESFMu/esfm.h b/extern/ESFMu/esfm.h index a37300ca0..d5c734b49 100644 --- a/extern/ESFMu/esfm.h +++ b/extern/ESFMu/esfm.h @@ -67,7 +67,6 @@ uint8_t ESFM_readback_reg (esfm_chip *chip, uint16_t address); uint8_t ESFM_read_port (esfm_chip *chip, uint8_t offset); void ESFM_generate(esfm_chip *chip, int16_t *buf); void ESFM_generate_stream(esfm_chip *chip, int16_t *sndptr, uint32_t num_samples); -// Modification by Kagamiin~: int16_t ESFM_get_channel_output_native(esfm_chip *chip, int channel_idx); @@ -171,10 +170,11 @@ typedef struct _esfm_slot_internal uint10 phase_out; flag phase_reset; flag *key_on; + flag key_on_gate; uint2 eg_state; flag eg_delay_run; - uint9 eg_delay_counter; + uint16 eg_delay_counter; } esfm_slot_internal; diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 14648e33c..874d3e4f4 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -5268,7 +5268,7 @@ void FurnaceGUI::drawInsEdit() { } if (ImGui::BeginTabItem(label)) { ImGui::PushID(i); - int ordi=(opCount==4)?orderedOps[i]:i; + int ordi=(opCount==4 && ins->type!=DIV_INS_ESFM)?orderedOps[i]:i; int maxTl=127; if (ins->type==DIV_INS_OPLL) { if (i==1) { From a1b7e524676bfa0777d7b6acad94e6e94fe3b503 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sat, 21 Oct 2023 14:35:20 -0300 Subject: [PATCH 13/34] Implementing pattern effects, detune on FM preview, default instrument --- src/engine/dispatch.h | 5 + src/engine/instrument.h | 1 - src/engine/platform/esfm.cpp | 201 ++++++++++++++++++++++++++--------- src/engine/playback.cpp | 7 +- src/engine/song.h | 37 ++++--- src/engine/sysDef.cpp | 58 +++++++++- src/gui/fmPreview.cpp | 22 +++- 7 files changed, 258 insertions(+), 73 deletions(-) diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 3f2dda6b1..72cb8a3a8 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -240,6 +240,11 @@ enum DivDispatchCmds { DIV_ALWAYS_SET_VOLUME, // () -> alwaysSetVol + DIV_CMD_ESFM_OP_PANNING, // (op, value) + DIV_CMD_ESFM_OUTLVL, // (op, value) + DIV_CMD_ESFM_MODIN, // (op, value) + DIV_CMD_ESFM_ENV_DELAY, // (op, value) + DIV_CMD_MAX }; diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 80c5dc3a6..0f9329a59 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -85,7 +85,6 @@ enum DivInstrumentType: unsigned short { DIV_INS_TED=52, DIV_INS_C140=53, DIV_INS_C219=54, - // TODO: Ask tilde to standardize this!!! DIV_INS_ESFM=55, DIV_INS_MAX, DIV_INS_NULL diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 92f32c78d..a54043a8a 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -230,6 +230,7 @@ void DivPlatformESFM::tick(bool sysTick) { } } + // detune/fixed pitch if (opE.fixed) { if (m.ssg.had) { opE.ct=(opE.ct&(~(7<<2)))|((m.ssg.val&7)<<2); @@ -351,44 +352,21 @@ void DivPlatformESFM::tick(bool sysTick) { } int DivPlatformESFM::octave(int freq) { - if (freq>=0x3ff<<6) { - return 1<<7; - } else if (freq>=0x3ff<<5) { - return 1<<6; - } else if (freq>=0x3ff<<4) { - return 1<<5; - } else if (freq>=0x3ff<<3) { - return 1<<4; - } else if (freq>=0x3ff<<2) { - return 1<<3; - } else if (freq>=0x3ff<<1) { - return 1<<2; - } else if (freq>=0x3ff) { - return 1<<1; - } else { - return 1<<0; + int result=1; + while (freq>0x3ff) { + freq>>=1; + result<<=1; } - return 1<<0; + return result; } int DivPlatformESFM::toFreq(int freq) { - if (freq>=0x3ff<<6) { - return 0x1c00|((freq>>7)&0x3ff); - } else if (freq>=0x3ff<<5) { - return 0x1800|((freq>>6)&0x3ff); - } else if (freq>=0x3ff<<4) { - return 0x1400|((freq>>5)&0x3ff); - } else if (freq>=0x3ff<<3) { - return 0x1000|((freq>>4)&0x3ff); - } else if (freq>=0x3ff<<2) { - return 0xc00|((freq>>3)&0x3ff); - } else if (freq>=0x3ff<<1) { - return 0x800|((freq>>2)&0x3ff); - } else if (freq>=0x3ff<<0) { - return 0x400|((freq>>1)&0x3ff); - } else { - return freq&0x3ff; + int block=0; + while (freq>0x3ff) { + freq>>=1; + block++; } + return ((block&7)<<10)|(freq&0x3ff); } void DivPlatformESFM::muteChannel(int ch, bool mute) { @@ -510,7 +488,6 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } break; @@ -585,7 +562,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_AR: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -603,7 +580,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_DR: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -621,7 +598,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_SL: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -639,7 +616,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_RR: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -657,7 +634,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_AM: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -675,7 +652,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_VIB: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -693,7 +670,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_SUS: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -711,7 +688,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_KSR: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -729,7 +706,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_WS: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -760,7 +737,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { } // KSL case DIV_CMD_FM_RS: { - if (c.value<0) { + if (c.value<0) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32 + o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; @@ -785,6 +762,134 @@ int DivPlatformESFM::dispatch(DivCommand c) { } break; } + case DIV_CMD_FM_AM_DEPTH: { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + op.dam=c.value2&1; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + break; + } + case DIV_CMD_FM_PM_DEPTH: { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + op.dvb=c.value2&1; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + break; + } + case DIV_CMD_FM_FIXFREQ: { + unsigned int o=c.value&3; + bool isFNum=c.value&4; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + if (!opE.fixed) break; + if (isFNum) { + opE.dt=(c.value2)&0xff; + opE.ct=(opE.ct&(~3))|((c.value2>>8)&3); + chan[c.chan].freqChanged=true; + } else { + opE.ct=(opE.ct&(~(7<<2)))|((c.value2&7)<<2); + chan[c.chan].freqChanged=true; + } + break; + } + case DIV_CMD_ESFM_OP_PANNING: { + unsigned int o=c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + opE.left=c.value2&1; + opE.right=(c.value2&2)>>1; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + break; + } + case DIV_CMD_ESFM_OUTLVL: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + unsigned char noise=chan[c.chan].state.esfm.noise&3; + opE.outLvl=c.value2&7; + if (isMuted[c.chan]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + } + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + unsigned char noise=chan[c.chan].state.esfm.noise&3; + opE.outLvl=c.value2&7; + if (isMuted[c.chan]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + } + } + break; + } + case DIV_CMD_ESFM_MODIN: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + opE.modIn=c.value2&7; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + opE.modIn=c.value2&7; + rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + } + break; + } + case DIV_CMD_ESFM_ENV_DELAY: { + if (c.value<0) { + for (int o=0; o<4; o++) { + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + opE.delay=c.value2&7; + rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); + } + } else { + unsigned int o = c.value; + if (o >= 4) break; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + opE.delay=c.value2&7; + rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); + } + break; + } + case DIV_CMD_STD_NOISE_MODE: { + unsigned int o=3; + unsigned short baseAddr=c.chan*32 + o*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + DivInstrumentESFM insE=chan[c.chan].state.esfm; + insE.noise=c.value&3; + if (isMuted[c.chan]) { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|(insE.noise<<3)|0); + } else { + rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|(insE.noise<<3)|((opE.outLvl&7)<<5)); + } + break; + } case DIV_CMD_FM_HARD_RESET: chan[c.chan].hardReset=c.value; break; @@ -843,10 +948,10 @@ DivDispatchOscBuffer* DivPlatformESFM::getOscBuffer(int ch) { } unsigned char* DivPlatformESFM::getRegisterPool() { - // TODO: DEBUG, remove this, it impacts performance - for (int i=0; i int effectValAnd(unsigned char, unsigned char val) { return val&mask; }; @@ -612,6 +616,52 @@ void DivEngine::registerSystems() { {0x20, {DIV_CMD_SAMPLE_FREQ, "20xx: Set PCM frequency"}} }; + EffectHandlerMap fmESFMPostEffectHandlerMap={ + {0x12, {DIV_CMD_FM_TL, "12xx: Set level of operator 1 (0 highest, 3F lowest)", constVal<0>, effectVal}}, + {0x13, {DIV_CMD_FM_TL, "13xx: Set level of operator 2 (0 highest, 3F lowest)", constVal<1>, effectVal}}, + {0x14, {DIV_CMD_FM_TL, "14xx: Set level of operator 3 (0 highest, 3F lowest)", constVal<2>, effectVal}}, + {0x15, {DIV_CMD_FM_TL, "15xx: Set level of operator 4 (0 highest, 3F lowest)", constVal<3>, effectVal}}, + {0x16, {DIV_CMD_FM_MULT, "16xy: Set operator multiplier (x: operator from 1 to 4; y: multiplier)", effectOpValNoZero<4>, effectValAnd<15>}}, + {0x19, {DIV_CMD_FM_AR, "19xx: Set attack of all operators (0 to F)", constVal<-1>, effectValAnd<15>}}, + {0x1a, {DIV_CMD_FM_AR, "1Axx: Set attack of operator 1 (0 to F)", constVal<0>, effectValAnd<15>}}, + {0x1b, {DIV_CMD_FM_AR, "1Bxx: Set attack of operator 2 (0 to F)", constVal<1>, effectValAnd<15>}}, + {0x1c, {DIV_CMD_FM_AR, "1Cxx: Set attack of operator 3 (0 to F)", constVal<2>, effectValAnd<15>}}, + {0x1d, {DIV_CMD_FM_AR, "1Dxx: Set attack of operator 4 (0 to F)", constVal<3>, effectValAnd<15>}}, + {0x1e, {DIV_CMD_FM_AM_DEPTH, "1Exy: Set AM depth (x: operator from 1 to 4 (0 for all ops); y: depth (0: 1dB, 1: 4.8dB))", effectOpVal<4>, effectValAnd<1>}}, + {0x1f, {DIV_CMD_FM_PM_DEPTH, "1Fxy: Set vibrato depth (x: operator from 1 to 4 (0 for all ops); y: depth (0: normal, 1: double))", effectOpVal<4>, effectValAnd<1>}}, + {0x20, {DIV_CMD_ESFM_OP_PANNING, "20xy: Set panning of operator 1 (x: left; y: right)", constVal<0>, effectValNibbleFlagPackReversed}}, + {0x21, {DIV_CMD_ESFM_OP_PANNING, "21xy: Set panning of operator 2 (x: left; y: right)", constVal<1>, effectValNibbleFlagPackReversed}}, + {0x22, {DIV_CMD_ESFM_OP_PANNING, "22xy: Set panning of operator 3 (x: left; y: right)", constVal<2>, effectValNibbleFlagPackReversed}}, + {0x23, {DIV_CMD_ESFM_OP_PANNING, "23xy: Set panning of operator 4 (x: left; y: right)", constVal<3>, effectValNibbleFlagPackReversed}}, + {0x24, {DIV_CMD_ESFM_OUTLVL, "24xy: Set output level register (x: operator from 1 to 4 (0 for all ops); y: level from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, + {0x25, {DIV_CMD_ESFM_MODIN, "25xy: Set modulation input level (x: operator from 1 to 4 (0 for all ops); y: level from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, + {0x26, {DIV_CMD_ESFM_ENV_DELAY, "26xy: Set envelope delay (x: operator from 1 to 4 (0 for all ops); y: delay from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, + {0x27, {DIV_CMD_STD_NOISE_MODE, "27xx: Set noise mode for operator 4 (x: mode from 0 to 3)", effectValAnd<3>}}, + {0x2a, {DIV_CMD_FM_WS, "2Axy: Set waveform (x: operator from 1 to 4 (0 for all ops); y: waveform from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, + {0x2f, {DIV_CMD_FM_FIXFREQ, "2Fxy: Set fixed frequency block (x: operator from 1 to 4; y: octave from 0 to 7)", effectOpValNoZero<4>, effectValAnd<7>}}, + {0x50, {DIV_CMD_FM_AM, "50xy: Set AM (x: operator from 1 to 4 (0 for all ops); y: AM)", effectOpVal<4>, effectValAnd<1>}}, + {0x51, {DIV_CMD_FM_SL, "51xy: Set sustain level (x: operator from 1 to 4 (0 for all ops); y: sustain)", effectOpVal<4>, effectValAnd<15>}}, + {0x52, {DIV_CMD_FM_RR, "52xy: Set release (x: operator from 1 to 4 (0 for all ops); y: release)", effectOpVal<4>, effectValAnd<15>}}, + {0x53, {DIV_CMD_FM_VIB, "53xy: Set vibrato (x: operator from 1 to 4 (0 for all ops); y: enabled)", effectOpVal<4>, effectValAnd<1>}}, + {0x54, {DIV_CMD_FM_RS, "54xy: Set envelope scale (x: operator from 1 to 4 (0 for all ops); y: scale from 0 to 3)", effectOpVal<4>, effectValAnd<3>}}, + {0x55, {DIV_CMD_FM_SUS, "55xy: Set envelope sustain (x: operator from 1 to 4 (0 for all ops); y: enabled)", effectOpVal<4>, effectValAnd<1>}}, + {0x56, {DIV_CMD_FM_DR, "56xx: Set decay of all operators (0 to F)", constVal<-1>, effectValAnd<15>}}, + {0x57, {DIV_CMD_FM_DR, "57xx: Set decay of operator 1 (0 to F)", constVal<0>, effectValAnd<15>}}, + {0x58, {DIV_CMD_FM_DR, "58xx: Set decay of operator 2 (0 to F)", constVal<1>, effectValAnd<15>}}, + {0x59, {DIV_CMD_FM_DR, "59xx: Set decay of operator 3 (0 to F)", constVal<2>, effectValAnd<15>}}, + {0x5a, {DIV_CMD_FM_DR, "5Axx: Set decay of operator 4 (0 to F)", constVal<3>, effectValAnd<15>}}, + {0x5b, {DIV_CMD_FM_KSR, "5Bxy: Set whether key will scale envelope (x: operator from 1 to 4 (0 for all ops); y: enabled)", effectOpVal<4>, effectValAnd<1>}} + }; + const EffectHandler fmESFMFixFreqFNumHandler[4]={ + {DIV_CMD_FM_FIXFREQ, "3xyy: Set fixed frequency F-num of operator 1 (x: high 2 bits from 0 to 3; y: low 8 bits of F-num)", constVal<4>, effectValLong<10>}, + {DIV_CMD_FM_FIXFREQ, "3xyy: Set fixed frequency F-num of operator 2 (x: high 2 bits from 4 to 7; y: low 8 bits of F-num)", constVal<5>, effectValLong<10>}, + {DIV_CMD_FM_FIXFREQ, "3xyy: Set fixed frequency F-num of operator 3 (x: high 2 bits from 8 to B; y: low 8 bits of F-num)", constVal<6>, effectValLong<10>}, + {DIV_CMD_FM_FIXFREQ, "3xyy: Set fixed frequency F-num of operator 4 (x: high 2 bits from C to F; y: low 8 bits of F-num)", constVal<7>, effectValLong<10>}, + }; + for (int i=0; i<16; i++) { + fmESFMPostEffectHandlerMap.emplace(0x30+i,fmESFMFixFreqFNumHandler[i/4]); + } + // SysDefs // this chip uses YMZ ADPCM, but the emulator uses ADPCM-B because I got it wrong back then. @@ -1917,8 +1967,7 @@ void DivEngine::registerSystems() { {0x12, {DIV_CMD_SNES_INVERT, "12xy: Set invert mode (x: surround; y: invert)"}}, } ); - - // TODO: ask Tilde to standardize! + sysDefs[DIV_SYSTEM_ESFM]=new DivSysDef( "ESS ES1xxx-series (ESFM)", NULL, 0xd0, 0, 18, true, false, 0, false, 0, "A unique FM synth featured in PC sound cards.\nBased on the OPL3 design, but with lots of its features extended.", @@ -1927,7 +1976,10 @@ void DivEngine::registerSystems() { {DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM}, {DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM, DIV_INS_ESFM}, {}, - {} + { + {0x2e, {DIV_CMD_FM_HARD_RESET, "2Exx: Toggle hard envelope reset on new notes"}}, + }, + fmESFMPostEffectHandlerMap ); sysDefs[DIV_SYSTEM_DUMMY]=new DivSysDef( diff --git a/src/gui/fmPreview.cpp b/src/gui/fmPreview.cpp index 14b21e018..290175e23 100644 --- a/src/gui/fmPreview.cpp +++ b/src/gui/fmPreview.cpp @@ -366,15 +366,31 @@ void FurnaceGUI::renderFMPreviewESFM(const DivInstrumentFM& params, const DivIns const DivInstrumentFM::Operator& op=params.op[i]; const DivInstrumentESFM::Operator& opE=esfmParams.op[i]; unsigned short baseAddr=i*8; + unsigned char freqL, freqH; + if (opE.fixed) { + freqL=opE.dt; + freqH=opE.ct&0x1f; + } else { + // perform detune calculation + int offset=(opE.ct<<7)+opE.dt; + double fbase=(mult0?2048.0:1024.0)*pow(2.0,(float)offset/(128.0*12.0)); + int bf=round(fbase); + int block=0; + while (bf>0x3ff) { + bf>>=1; + block++; + } + freqL=bf&0xff; + freqH=((block&7)<<2)|((bf>>8)&3); + } ESFM_WRITE(baseAddr+0,(op.am<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0x0f)); ESFM_WRITE(baseAddr+1,(op.ksl<<6)|(op.tl&0x3f)); ESFM_WRITE(baseAddr+2,(op.ar<<4)|(op.dr&0x0f)); ESFM_WRITE(baseAddr+3,(op.sl<<4)|(op.rr&0x0f)); - // TODO: implement ct/dt detune... how will we do that? - ESFM_WRITE(baseAddr+4,0); - ESFM_WRITE(baseAddr+5,(opE.delay<<5)|(mult0?0x0a:0x06)); + ESFM_WRITE(baseAddr+4,freqL); + ESFM_WRITE(baseAddr+5,(opE.delay<<5)|freqH); ESFM_WRITE(baseAddr+6,(op.dam<<7)|((op.dvb&1)<<6)|((opE.right&1)<<5)|((opE.left&1)<<4)|((opE.modIn&7)<<1)); ESFM_WRITE(baseAddr+7,(opE.outLvl<<5)|((i==3?esfmParams.noise:0)<<3)|(op.ws&7)); From 64baa7c97fad88893b29ef0fe34b8120559616bf Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 22 Oct 2023 11:46:34 -0300 Subject: [PATCH 14/34] Some refactoring --- src/engine/instrument.cpp | 2 +- src/engine/platform/esfm.cpp | 132 +++++++------- src/engine/platform/esfm.h | 4 +- src/gui/insEdit.cpp | 344 +++++++++++++++++------------------ src/gui/sysConf.cpp | 22 ++- 5 files changed, 256 insertions(+), 248 deletions(-) diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index d92fe4504..918a9a3fe 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -2632,7 +2632,7 @@ void DivInstrument::readFeatureEF(SafeReader& reader, short version) { READ_FEAT_BEGIN; unsigned char next=reader.readC(); - esfm.noise = next&3; + esfm.noise=next&3; for (int i=0; i<4; i++) { DivInstrumentESFM::Operator& op=esfm.op[i]; diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index a54043a8a..59a91d05b 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -35,7 +35,7 @@ #define OFFSET_DAM_DVB_LEFT_RIGHT_MODIN 0x06 #define OFFSET_OUTLVL_NOISE_WS 0x07 -#define KEY_ON_REGS_START (18 * 8 * 4) +#define KEY_ON_REGS_START (18*8*4) void DivPlatformESFM::acquire(short** buf, size_t len) { thread_local short o[2]; @@ -66,7 +66,7 @@ void DivPlatformESFM::tick(bool sysTick) { if (chan[i].std.vol.had) { chan[i].outVol=VOL_SCALE_LOG_BROKEN(chan[i].vol,MIN(63,chan[i].std.vol.val),63); for (int o=0; o<4; o++) { - unsigned short baseAddr=i*32 + o*8; + unsigned short baseAddr=i*32+o*8; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; unsigned char noise=chan[i].state.esfm.noise&3; @@ -96,7 +96,7 @@ void DivPlatformESFM::tick(bool sysTick) { if (chan[i].std.panL.had) { chan[i].globalPan=((chan[i].std.panL.val&1)<<1)|((chan[i].std.panL.val&2)>>1); for (int o=0; o<4; o++) { - unsigned short baseAddr=i*32 + o*8; + unsigned short baseAddr=i*32+o*8; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); @@ -121,7 +121,7 @@ void DivPlatformESFM::tick(bool sysTick) { if (chan[i].std.duty.had) { int o=3; - unsigned short baseAddr=i*32 + o*8; + unsigned short baseAddr=i*32+o*8; DivInstrumentESFM& ins=chan[i].state.esfm; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; @@ -135,7 +135,7 @@ void DivPlatformESFM::tick(bool sysTick) { } for (int o=0; o<4; o++) { - unsigned short baseAddr=i*32 + o*8; + unsigned short baseAddr=i*32+o*8; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; DivMacroInt::IntOp& m=chan[i].std.op[o]; @@ -283,7 +283,7 @@ void DivPlatformESFM::tick(bool sysTick) { mustHardReset=true; // logI("chan[%d] hard reset, slrr := 0x0f", i); for (int o=0; o<4; o++) { - unsigned short baseAddr=i*32 + o*8; + unsigned short baseAddr=i*32+o*8; immWrite(baseAddr+OFFSET_SL_RR,0x0f); } } @@ -296,7 +296,7 @@ void DivPlatformESFM::tick(bool sysTick) { if (chan[i].freq>131071) chan[i].freq=131071; for (int o=0; o<4; o++) { - unsigned short baseAddr=i*32 + o*8; + unsigned short baseAddr=i*32+o*8; DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; int ct=(int)opE.ct; int dt=(int)opE.dt; @@ -334,7 +334,7 @@ void DivPlatformESFM::tick(bool sysTick) { if (chan[i].hardReset && chan[i].keyOn) { // logI("chan[%d] hard reset key on, writing original slrr back", i); for (int o=0; o<4; o++) { - unsigned short baseAddr=i*32 + o*8; + unsigned short baseAddr=i*32+o*8; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; immWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); } @@ -371,13 +371,13 @@ int DivPlatformESFM::toFreq(int freq) { void DivPlatformESFM::muteChannel(int ch, bool mute) { isMuted[ch]=mute; - + for (int o=0; o<4; o++) { - unsigned short baseAddr=ch*32 + o*8; + unsigned short baseAddr=ch*32+o*8; DivInstrumentFM::Operator& op=chan[ch].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[ch].state.esfm.op[o]; unsigned char noise=chan[ch].state.esfm.noise&3; - + if (isMuted[ch]) { rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { @@ -396,7 +396,7 @@ void DivPlatformESFM::commitState(int ch, DivInstrument* ins) { chan[ch].state.fm=ins->fm; chan[ch].state.esfm=ins->esfm; for (int o=0; o<4; o++) { - unsigned short baseAddr=ch*32 + o*8; + unsigned short baseAddr=ch*32+o*8; DivInstrumentFM::Operator& op=chan[ch].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[ch].state.esfm.op[o]; unsigned char noise=chan[ch].state.esfm.noise&3; @@ -463,7 +463,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { chan[c.chan].outVol=c.value; } for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; if (KVS(c.chan, o)) { rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); @@ -485,7 +485,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_PANNING: { chan[c.chan].globalPan=(c.value>0)|((c.value2>0)<<1); for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); @@ -540,18 +540,18 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_MULT: { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.mult=c.value2&15; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); break; } case DIV_CMD_FM_TL: { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.tl=c.value2&63; if (KVS(c.chan, o)) { @@ -564,15 +564,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_AR: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ar=c.value2&15; rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ar=c.value2&15; rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); @@ -582,15 +582,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_DR: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.dr=c.value2&15; rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.dr=c.value2&15; rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); @@ -600,15 +600,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_SL: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sl=c.value2&15; rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sl=c.value2&15; rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); @@ -618,15 +618,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_RR: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.rr=c.value2&15; rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.rr=c.value2&15; rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); @@ -636,15 +636,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_AM: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.am=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.am=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); @@ -654,15 +654,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_VIB: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.vib=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.vib=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); @@ -672,15 +672,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_SUS: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sus=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sus=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); @@ -690,15 +690,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_KSR: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksr=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksr=c.value2&1; rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); @@ -708,7 +708,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_WS: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; unsigned char noise=chan[c.chan].state.esfm.noise&3; @@ -720,9 +720,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { } } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; unsigned char noise=chan[c.chan].state.esfm.noise&3; @@ -739,7 +739,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_FM_RS: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksl=c.value2&3; if (KVS(c.chan, o)) { @@ -749,9 +749,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { } } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksl=c.value2&3; if (KVS(c.chan, o)) { @@ -763,9 +763,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_AM_DEPTH: { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; op.dam=c.value2&1; @@ -773,9 +773,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { break; } case DIV_CMD_FM_PM_DEPTH: { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; op.dvb=c.value2&1; @@ -800,7 +800,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_ESFM_OP_PANNING: { unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.left=c.value2&1; @@ -811,7 +811,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_ESFM_OUTLVL: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; unsigned char noise=chan[c.chan].state.esfm.noise&3; @@ -823,9 +823,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { } } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; unsigned char noise=chan[c.chan].state.esfm.noise&3; @@ -841,16 +841,16 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_ESFM_MODIN: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.modIn=c.value2&7; rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.modIn=c.value2&7; @@ -861,15 +861,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_ESFM_ENV_DELAY: { if (c.value<0) { for (int o=0; o<4; o++) { - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.delay=c.value2&7; rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); } } else { - unsigned int o = c.value; + unsigned int o=c.value; if (o >= 4) break; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.delay=c.value2&7; rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); @@ -878,7 +878,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { } case DIV_CMD_STD_NOISE_MODE: { unsigned int o=3; - unsigned short baseAddr=c.chan*32 + o*8; + unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; DivInstrumentESFM insE=chan[c.chan].state.esfm; @@ -969,9 +969,9 @@ void DivPlatformESFM::reset() { ESFM_write_reg(&chip, 0x408, 0x00); for (int i=0; i 0 and op[o + 1].modIn == 0. */ inline bool KVS(int c, int o) { - if (c < 0 || c >= 18 || o < 0 || o >= 4) return false; + if (c<0 || c>=18 || o<0 || o>=4) return false; if (chan[c].state.fm.op[o].kvs==1) return true; @@ -106,7 +106,7 @@ class DivPlatformESFM: public DivDispatch { if (chan[c].state.esfm.op[o].outLvl==7) return true; else if (chan[c].state.esfm.op[o].outLvl>0) { if (o==3) return true; - else if ((chan[c].state.esfm.op[o].outLvl-chan[c].state.esfm.op[o+1].modIn) >= 2) { + else if ((chan[c].state.esfm.op[o].outLvl-chan[c].state.esfm.op[o+1].modIn)>=2) { return true; } else if (chan[c].state.esfm.op[o+1].modIn==0) { diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 874d3e4f4..873760d85 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -166,7 +166,7 @@ const char* oplDrumNames[4]={ }; const char* esfmNoiseModeNames[4]={ - "Noise disabled", "Snare (square + noise)", "HiHat (ringmod from OP3, + noise)", "Top (ringmod from OP3)" + "Noise disabled", "Snare (square + noise)", "HiHat (ringmod from OP3, + noise)", "Top (ringmod from OP3)\nWARNING - not emulated properly! Will change in future versions." }; const bool opIsOutput[8][4]={ @@ -1198,7 +1198,7 @@ void FurnaceGUI::drawESFMAlgorithm(DivInstrumentESFM& esfm, const ImVec2& size) int out4 = esfm.op[3].outLvl&7; bool isMod[4]; for (int i=0; i<4; i++) { - DivInstrumentESFM::Operator& opE = esfm.op[i]; + DivInstrumentESFM::Operator& opE=esfm.op[i]; isMod[i]=true; if (opE.outLvl==7) isMod[i]=false; else if (opE.outLvl>0) { @@ -1206,7 +1206,7 @@ void FurnaceGUI::drawESFMAlgorithm(DivInstrumentESFM& esfm, const ImVec2& size) else { DivInstrumentESFM::Operator& opENext=esfm.op[i+1]; if (opENext.modIn==0) isMod[i]=false; - else if ((opE.outLvl-opENext.modIn) >= 2) isMod[i]=false; + else if ((opE.outLvl-opENext.modIn)>=2) isMod[i]=false; } } } @@ -3137,182 +3137,168 @@ void FurnaceGUI::drawInsEdit() { } } - if (ins->type!=DIV_INS_ESFM) { - if (ImGui::BeginTable("fmDetails",3,ImGuiTableFlags_SizingStretchSame)) { - ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.0); - ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0); - ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.0); + if (ImGui::BeginTable("fmDetails",3,(ins->type==DIV_INS_ESFM)?ImGuiTableFlags_SizingStretchProp:ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,((ins->type==DIV_INS_ESFM)?0.50f:0.0f)); + ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,((ins->type==DIV_INS_ESFM)?0.15f:0.0f)); + ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,((ins->type==DIV_INS_ESFM)?0.35f:0.0f)); - ImGui::TableNextRow(); - switch (ins->type) { - case DIV_INS_FM: - case DIV_INS_OPM: - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + ImGui::TableNextRow(); + switch (ins->type) { + case DIV_INS_FM: + case DIV_INS_OPM: + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; } - kvsConfig(ins); - break; - case DIV_INS_OPZ: - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_FMS2),ImGuiDataType_U8,&ins->fm.fms2,&_ZERO,&_SEVEN)); rightClickable - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable - P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable - P(CWSliderScalar(FM_NAME(FM_AMS2),ImGuiDataType_U8,&ins->fm.ams2,&_ZERO,&_THREE)); rightClickable - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - } - kvsConfig(ins); - - if (ImGui::Button("Request from TX81Z")) { - doAction(GUI_ACTION_TX81Z_REQUEST); - } - /* - ImGui::SameLine(); - if (ImGui::Button("Send to TX81Z")) { - showError("Coming soon!"); - } - */ - break; - case DIV_INS_OPL: - case DIV_INS_OPL_DRUMS: { - bool fourOp=(ins->fm.ops==4 || ins->type==DIV_INS_OPL_DRUMS); - bool drums=ins->fm.opllPreset==16; - int algMax=fourOp?3:1; - ImGui::TableNextColumn(); - ins->fm.alg&=algMax; - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable - if (ins->type==DIV_INS_OPL) { - ImGui::BeginDisabled(ins->fm.opllPreset==16); - if (ImGui::Checkbox("4-op",&fourOp)) { PARAMETER - ins->fm.ops=fourOp?4:2; - } - ImGui::EndDisabled(); - } - ImGui::TableNextColumn(); - P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&algMax)); rightClickable - if (ins->type==DIV_INS_OPL) { - if (ImGui::Checkbox("Drums",&drums)) { PARAMETER - ins->fm.opllPreset=drums?16:0; - } - } - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(ins->fm.alg&algMax,fourOp?FM_ALGS_4OP_OPL:FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); - } - kvsConfig(ins); - break; + } else { + drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); } - case DIV_INS_OPLL: { - bool dc=fmOrigin.fms; - bool dm=fmOrigin.ams; - bool sus=ins->fm.alg; - ImGui::TableNextColumn(); - ImGui::BeginDisabled(ins->fm.opllPreset!=0); - P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&fmOrigin.fb,&_ZERO,&_SEVEN)); rightClickable - if (ImGui::Checkbox(FM_NAME(FM_DC),&dc)) { PARAMETER - fmOrigin.fms=dc; + kvsConfig(ins); + break; + case DIV_INS_OPZ: + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_FMS),ImGuiDataType_U8,&ins->fm.fms,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_FMS2),ImGuiDataType_U8,&ins->fm.fms2,&_ZERO,&_SEVEN)); rightClickable + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&_SEVEN)); rightClickable + P(CWSliderScalar(FM_NAME(FM_AMS),ImGuiDataType_U8,&ins->fm.ams,&_ZERO,&_THREE)); rightClickable + P(CWSliderScalar(FM_NAME(FM_AMS2),ImGuiDataType_U8,&ins->fm.ams2,&_ZERO,&_THREE)); rightClickable + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; + } + } else { + drawAlgorithm(ins->fm.alg,FM_ALGS_4OP,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + } + kvsConfig(ins); + + if (ImGui::Button("Request from TX81Z")) { + doAction(GUI_ACTION_TX81Z_REQUEST); + } + /* + ImGui::SameLine(); + if (ImGui::Button("Send to TX81Z")) { + showError("Coming soon!"); + } + */ + break; + case DIV_INS_OPL: + case DIV_INS_OPL_DRUMS: { + bool fourOp=(ins->fm.ops==4 || ins->type==DIV_INS_OPL_DRUMS); + bool drums=ins->fm.opllPreset==16; + int algMax=fourOp?3:1; + ImGui::TableNextColumn(); + ins->fm.alg&=algMax; + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&ins->fm.fb,&_ZERO,&_SEVEN)); rightClickable + if (ins->type==DIV_INS_OPL) { + ImGui::BeginDisabled(ins->fm.opllPreset==16); + if (ImGui::Checkbox("4-op",&fourOp)) { PARAMETER + ins->fm.ops=fourOp?4:2; } ImGui::EndDisabled(); - ImGui::TableNextColumn(); - if (ImGui::Checkbox(FM_NAME(FM_SUS),&sus)) { PARAMETER - ins->fm.alg=sus; - } - ImGui::BeginDisabled(ins->fm.opllPreset!=0); - if (ImGui::Checkbox(FM_NAME(FM_DM),&dm)) { PARAMETER - fmOrigin.ams=dm; - } - ImGui::EndDisabled(); - ImGui::TableNextColumn(); - if (fmPreviewOn) { - drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); - if (!fmPreviewPaused) { - renderFMPreview(ins,1); - WAKE_UP; - } - } else { - drawAlgorithm(0,FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); - } - kvsConfig(ins,false); - - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); - - if (ImGui::BeginCombo("##LLPreset",opllInsNames[presentWhich][ins->fm.opllPreset])) { - if (isPresentCount>1) { - if (ImGui::BeginTable("LLPresetList",isPresentCount)) { - ImGui::TableNextRow(ImGuiTableRowFlags_Headers); - for (int i=0; i<4; i++) { - if (!isPresent[i]) continue; - ImGui::TableNextColumn(); - ImGui::Text("%s name",opllVariants[i]); - } - for (int i=0; i<17; i++) { - ImGui::TableNextRow(); - for (int j=0; j<4; j++) { - if (!isPresent[j]) continue; - ImGui::TableNextColumn(); - ImGui::PushID(j*17+i); - if (ImGui::Selectable(opllInsNames[j][i])) { - ins->fm.opllPreset=i; - } - ImGui::PopID(); - } - } - ImGui::EndTable(); - } - } else { - for (int i=0; i<17; i++) { - if (ImGui::Selectable(opllInsNames[presentWhich][i])) { - ins->fm.opllPreset=i; - } - } - } - ImGui::EndCombo(); - } - break; } - default: - break; + ImGui::TableNextColumn(); + P(CWSliderScalar(FM_NAME(FM_ALG),ImGuiDataType_U8,&ins->fm.alg,&_ZERO,&algMax)); rightClickable + if (ins->type==DIV_INS_OPL) { + if (ImGui::Checkbox("Drums",&drums)) { PARAMETER + ins->fm.opllPreset=drums?16:0; + } + } + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; + } + } else { + drawAlgorithm(ins->fm.alg&algMax,fourOp?FM_ALGS_4OP_OPL:FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,48.0*dpiScale)); + } + kvsConfig(ins); + break; } - ImGui::EndTable(); - } - } else { - // ESFM - if (ImGui::BeginTable("fmDetails",3,ImGuiTableFlags_SizingStretchProp)) { - ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthStretch,0.50f); - ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.15f); - ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.35f); - - ImGui::TableNextRow(); - { + case DIV_INS_OPLL: { + bool dc=fmOrigin.fms; + bool dm=fmOrigin.ams; + bool sus=ins->fm.alg; + ImGui::TableNextColumn(); + ImGui::BeginDisabled(ins->fm.opllPreset!=0); + P(CWSliderScalar(FM_NAME(FM_FB),ImGuiDataType_U8,&fmOrigin.fb,&_ZERO,&_SEVEN)); rightClickable + if (ImGui::Checkbox(FM_NAME(FM_DC),&dc)) { PARAMETER + fmOrigin.fms=dc; + } + ImGui::EndDisabled(); + ImGui::TableNextColumn(); + if (ImGui::Checkbox(FM_NAME(FM_SUS),&sus)) { PARAMETER + ins->fm.alg=sus; + } + ImGui::BeginDisabled(ins->fm.opllPreset!=0); + if (ImGui::Checkbox(FM_NAME(FM_DM),&dm)) { PARAMETER + fmOrigin.ams=dm; + } + ImGui::EndDisabled(); + ImGui::TableNextColumn(); + if (fmPreviewOn) { + drawFMPreview(ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); + if (!fmPreviewPaused) { + renderFMPreview(ins,1); + WAKE_UP; + } + } else { + drawAlgorithm(0,FM_ALGS_2OP_OPL,ImVec2(ImGui::GetContentRegionAvail().x,24.0*dpiScale)); + } + kvsConfig(ins,false); + + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + + if (ImGui::BeginCombo("##LLPreset",opllInsNames[presentWhich][ins->fm.opllPreset])) { + if (isPresentCount>1) { + if (ImGui::BeginTable("LLPresetList",isPresentCount)) { + ImGui::TableNextRow(ImGuiTableRowFlags_Headers); + for (int i=0; i<4; i++) { + if (!isPresent[i]) continue; + ImGui::TableNextColumn(); + ImGui::Text("%s name",opllVariants[i]); + } + for (int i=0; i<17; i++) { + ImGui::TableNextRow(); + for (int j=0; j<4; j++) { + if (!isPresent[j]) continue; + ImGui::TableNextColumn(); + ImGui::PushID(j*17+i); + if (ImGui::Selectable(opllInsNames[j][i])) { + ins->fm.opllPreset=i; + } + ImGui::PopID(); + } + } + ImGui::EndTable(); + } + } else { + for (int i=0; i<17; i++) { + if (ImGui::Selectable(opllInsNames[presentWhich][i])) { + ins->fm.opllPreset=i; + } + } + } + ImGui::EndCombo(); + } + break; + } + case DIV_INS_ESFM: { ImGui::TableNextColumn(); P(CWSliderScalar(ESFM_LONG_NAME(ESFM_NOISE),ImGuiDataType_U8,&ins->esfm.noise,&_ZERO,&_THREE)); rightClickable ImGui::TextUnformatted(esfmNoiseModeNames[ins->esfm.noise&3]); @@ -3329,8 +3315,10 @@ void FurnaceGUI::drawInsEdit() { } kvsConfig(ins); } - ImGui::EndTable(); + default: + break; } + ImGui::EndTable(); } if (((ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPL) && ins->fm.opllPreset==16) || ins->type==DIV_INS_OPL_DRUMS) { @@ -3621,7 +3609,7 @@ void FurnaceGUI::drawInsEdit() { else { DivInstrumentESFM::Operator& opENext=ins->esfm.op[i+1]; if (opENext.modIn==0) mod=false; - else if ((opE.outLvl-opENext.modIn) >= 2) mod=false; + else if ((opE.outLvl-opENext.modIn)>=2) mod=false; } } } else if (opCount==4) { @@ -3707,7 +3695,7 @@ void FurnaceGUI::drawInsEdit() { bool susOn=op.sus; bool fixedOn=opE.fixed; unsigned char ssgEnv=op.ssgEnv&7; - + if (ins->type==DIV_INS_ESFM) { ImGui::TableNextColumn(); CENTER_VSLIDER; @@ -4086,7 +4074,7 @@ void FurnaceGUI::drawInsEdit() { else { DivInstrumentESFM::Operator& opENext=ins->esfm.op[i+1]; if (opENext.modIn==0) mod=false; - else if ((opE.outLvl-opENext.modIn) >= 2) mod=false; + else if ((opE.outLvl-opENext.modIn)>=2) mod=false; } } } else if (opCount==4) { @@ -4519,7 +4507,7 @@ void FurnaceGUI::drawInsEdit() { if (block>7) block=7; opE.ct=(opE.ct&(~(7<<2)))|(block<<2); } - + ImGui::Text("F"); if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Frequency (F-Num)"); @@ -4784,7 +4772,7 @@ void FurnaceGUI::drawInsEdit() { else { DivInstrumentESFM::Operator& opENext=ins->esfm.op[i+1]; if (opENext.modIn==0) mod=false; - else if ((opE.outLvl-opENext.modIn) >= 2) mod=false; + else if ((opE.outLvl-opENext.modIn)>=2) mod=false; } } } else if (opCount==4) { diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 813942d0c..edfdc6730 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -2215,6 +2215,27 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl } break; } + case DIV_SYSTEM_ESFM: { + supportsCustomRate=false; + + // TODO: Remove the text below and uncomment the rest when overflow emulation is added to ESFMu + // (still under research) + ImGui::Text("nothing to configure"); + + // bool emulateOverflow=flags.getBool("emulateOverflow", false); + // + // if (ImGui::Checkbox("Enable overflow emulation", &emulateOverflow)) { + // altered=true; + // mustRender=true; + // } + // + // if (altered) { + // e->lockSave([&]() { + // flags.set("emulateOverflow", emulateOverflow); + // }); + // } + break; + } case DIV_SYSTEM_SWAN: case DIV_SYSTEM_BUBSYS_WSG: case DIV_SYSTEM_PET: @@ -2225,7 +2246,6 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl case DIV_SYSTEM_C219: break; case DIV_SYSTEM_YMU759: - case DIV_SYSTEM_ESFM: supportsCustomRate=false; ImGui::Text("nothing to configure"); break; From 96fbd1524a32ce567dc0ec2ffc15a361abbb36fb Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 22 Oct 2023 16:49:23 -0300 Subject: [PATCH 15/34] Updating ESFMu - accuracy improvements for noise mode --- extern/ESFMu/MODIFIED.md | 6 ----- extern/ESFMu/esfm.c | 58 +++++++++++++++++++++++++++++++++++----- extern/ESFMu/esfm.h | 2 ++ 3 files changed, 54 insertions(+), 12 deletions(-) delete mode 100644 extern/ESFMu/MODIFIED.md diff --git a/extern/ESFMu/MODIFIED.md b/extern/ESFMu/MODIFIED.md deleted file mode 100644 index 78625584c..000000000 --- a/extern/ESFMu/MODIFIED.md +++ /dev/null @@ -1,6 +0,0 @@ -# Modification disclaimer - -This is a modified version of ESFMu v1.0.1 which implements a function for reading the waveform output of the individual FM channels. The modification was made by Kagamiin~ (original author of ESFMu) herself. - -Kagamiin~ notes: -> In hindsight, I might merge back this functionality into a future version of the core, as it could be be useful for generating oscilloscope views in other tools. diff --git a/extern/ESFMu/esfm.c b/extern/ESFMu/esfm.c index f0043fba6..2d1c9afdb 100644 --- a/extern/ESFMu/esfm.c +++ b/extern/ESFMu/esfm.c @@ -196,11 +196,13 @@ static int13 ESFM_envelope_calc_sin0(uint10 phase, uint10 envelope) { uint16 out = 0; - int13 neg = 0; + uint13 neg = 0; + bool inc = 0; phase &= 0x3ff; if (phase & 0x200) { neg = ~(0); + inc = 1; } if (phase & 0x100) { @@ -210,7 +212,7 @@ ESFM_envelope_calc_sin0(uint10 phase, uint10 envelope) { out = logsinrom[phase & 0xff]; } - return ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg; + return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc); } /* ------------------------------------------------------------------------- */ @@ -274,10 +276,12 @@ ESFM_envelope_calc_sin4(uint10 phase, uint10 envelope) { uint16 out = 0; int13 neg = 0; + bool inc = 0; phase &= 0x3ff; if ((phase & 0x300) == 0x100) { neg = ~(0); + inc = 1; } if (phase & 0x200) { @@ -291,7 +295,7 @@ ESFM_envelope_calc_sin4(uint10 phase, uint10 envelope) { out = logsinrom[(phase << 1) & 0xff]; } - return ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg; + return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc); } /* ------------------------------------------------------------------------- */ @@ -320,12 +324,14 @@ static int13 ESFM_envelope_calc_sin6(uint10 phase, uint10 envelope) { int13 neg = 0; + bool inc = 0; phase &= 0x3ff; if (phase & 0x200) { neg = ~(0); + inc = 1; } - return ESFM_envelope_calc_exp(envelope << 3) ^ neg; + return (int13)(((uint13)ESFM_envelope_calc_exp(envelope << 3) ^ neg) + inc); } /* ------------------------------------------------------------------------- */ @@ -334,14 +340,16 @@ ESFM_envelope_calc_sin7(uint10 phase, uint10 envelope) { uint16 out = 0; int13 neg = 0; + bool inc = 0; phase &= 0x3ff; if (phase & 0x200) { neg = ~(0); + inc = 1; phase = (phase & 0x1ff) ^ 0x1ff; } out = phase << 3; - return ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg; + return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc); } /* ------------------------------------------------------------------------- */ @@ -791,6 +799,37 @@ ESFM_phase_generate_emu(esfm_slot *slot) chip->lfsr = (noise >> 1) | (n_bit << 22); } +/** + * TODO: Figure out what's ACTUALLY going on inside the real chip! + * This is not accurate at all, but it's the closest I was able to get with + * empirical testing (and it's closer than nothing). + */ +/* ------------------------------------------------------------------------- */ +static int16 +ESFM_slot3_noise3_mod_input_calc(esfm_slot *slot) +{ + esfm_channel *channel = slot->channel; + envelope_sinfunc wavegen = envelope_sin[channel->slots[2].waveform]; + int16 phase; + int13 output_buf = *channel->slots[1].in.mod_input; + int i; + + // Go through previous slots' partial results and recalculate outputs + // (we skip slot 0 because its calculation happens at the end, not at the beginning) + for (i = 1; i < 3; i++) + { + // double the pitch + phase = channel->slots[i].in.phase_acc >> 8; + if (channel->slots[i].mod_in_level) + { + phase += output_buf >> (7 - channel->slots[i].mod_in_level); + } + output_buf = wavegen((uint10)(phase & 0x3ff), channel->slots[i].in.eg_output); + } + + return output_buf >> (8 - slot->mod_in_level); +} + /* ------------------------------------------------------------------------- */ static void ESFM_slot_generate(esfm_slot *slot) @@ -799,7 +838,14 @@ ESFM_slot_generate(esfm_slot *slot) int16 phase = slot->in.phase_out; if (slot->mod_in_level) { - phase += *slot->in.mod_input >> (7 - slot->mod_in_level); + if (slot->slot_idx == 3 && slot->rhy_noise == 3) + { + phase += ESFM_slot3_noise3_mod_input_calc(slot); + } + else + { + phase += *slot->in.mod_input >> (7 - slot->mod_in_level); + } } slot->in.output = wavegen((uint10)(phase & 0x3ff), slot->in.eg_output); if (slot->output_level) diff --git a/extern/ESFMu/esfm.h b/extern/ESFMu/esfm.h index d5c734b49..70897990b 100644 --- a/extern/ESFMu/esfm.h +++ b/extern/ESFMu/esfm.h @@ -91,6 +91,7 @@ typedef uint_fast16_t uint9; typedef uint_fast16_t uint10; typedef uint_fast16_t uint11; typedef uint_fast16_t uint12; +typedef uint_fast16_t uint13; typedef uint_fast16_t uint16; typedef uint_fast32_t uint19; typedef uint_fast32_t uint23; @@ -114,6 +115,7 @@ typedef uint16_t uint9; typedef uint16_t uint10; typedef uint16_t uint11; typedef uint16_t uint12; +typedef uint16_t uint13; typedef uint16_t uint16; typedef uint32_t uint19; typedef uint32_t uint23; From 39f29f49c34ddc8ff4579978b8ef3d8a22ace674 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 22 Oct 2023 17:28:50 -0300 Subject: [PATCH 16/34] Small fix for potential undefined behavior in ESFM emulator --- extern/ESFMu/esfm.c | 32 ++++++++++++-------------------- extern/ESFMu/esfm.h | 2 -- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/extern/ESFMu/esfm.c b/extern/ESFMu/esfm.c index 2d1c9afdb..54af9cc30 100644 --- a/extern/ESFMu/esfm.c +++ b/extern/ESFMu/esfm.c @@ -196,13 +196,11 @@ static int13 ESFM_envelope_calc_sin0(uint10 phase, uint10 envelope) { uint16 out = 0; - uint13 neg = 0; - bool inc = 0; + int13 neg = 1; phase &= 0x3ff; if (phase & 0x200) { - neg = ~(0); - inc = 1; + neg = -1; } if (phase & 0x100) { @@ -212,7 +210,7 @@ ESFM_envelope_calc_sin0(uint10 phase, uint10 envelope) { out = logsinrom[phase & 0xff]; } - return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc); + return ESFM_envelope_calc_exp(out + (envelope << 3)) * neg; } /* ------------------------------------------------------------------------- */ @@ -275,13 +273,11 @@ static int13 ESFM_envelope_calc_sin4(uint10 phase, uint10 envelope) { uint16 out = 0; - int13 neg = 0; - bool inc = 0; + int13 neg = 1; phase &= 0x3ff; if ((phase & 0x300) == 0x100) { - neg = ~(0); - inc = 1; + neg = -1; } if (phase & 0x200) { @@ -295,7 +291,7 @@ ESFM_envelope_calc_sin4(uint10 phase, uint10 envelope) { out = logsinrom[(phase << 1) & 0xff]; } - return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc); + return ESFM_envelope_calc_exp(out + (envelope << 3)) * neg; } /* ------------------------------------------------------------------------- */ @@ -323,15 +319,13 @@ ESFM_envelope_calc_sin5(uint10 phase, uint10 envelope) static int13 ESFM_envelope_calc_sin6(uint10 phase, uint10 envelope) { - int13 neg = 0; - bool inc = 0; + int13 neg = 1; phase &= 0x3ff; if (phase & 0x200) { - neg = ~(0); - inc = 1; + neg = -1; } - return (int13)(((uint13)ESFM_envelope_calc_exp(envelope << 3) ^ neg) + inc); + return ESFM_envelope_calc_exp(envelope << 3) * neg; } /* ------------------------------------------------------------------------- */ @@ -339,17 +333,15 @@ static int13 ESFM_envelope_calc_sin7(uint10 phase, uint10 envelope) { uint16 out = 0; - int13 neg = 0; - bool inc = 0; + int13 neg = 1; phase &= 0x3ff; if (phase & 0x200) { - neg = ~(0); - inc = 1; + neg = -1; phase = (phase & 0x1ff) ^ 0x1ff; } out = phase << 3; - return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc); + return ESFM_envelope_calc_exp(out + (envelope << 3)) * neg; } /* ------------------------------------------------------------------------- */ diff --git a/extern/ESFMu/esfm.h b/extern/ESFMu/esfm.h index 70897990b..d5c734b49 100644 --- a/extern/ESFMu/esfm.h +++ b/extern/ESFMu/esfm.h @@ -91,7 +91,6 @@ typedef uint_fast16_t uint9; typedef uint_fast16_t uint10; typedef uint_fast16_t uint11; typedef uint_fast16_t uint12; -typedef uint_fast16_t uint13; typedef uint_fast16_t uint16; typedef uint_fast32_t uint19; typedef uint_fast32_t uint23; @@ -115,7 +114,6 @@ typedef uint16_t uint9; typedef uint16_t uint10; typedef uint16_t uint11; typedef uint16_t uint12; -typedef uint16_t uint13; typedef uint16_t uint16; typedef uint32_t uint19; typedef uint32_t uint23; From 23b1c4107ea436ad54f252d80821573d53514c78 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Tue, 24 Oct 2023 14:29:37 -0300 Subject: [PATCH 17/34] Fix hard reset handling; add detune effect; change some labels --- src/engine/platform/esfm.cpp | 15 +++++++++++++++ src/engine/sysDef.cpp | 12 ++++++++++-- src/gui/insEdit.cpp | 10 +++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 59a91d05b..88d7a8051 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -265,6 +265,7 @@ void DivPlatformESFM::tick(bool sysTick) { } } + int hardResetElapsed=0; bool mustHardReset=false; for (int i=0; i<18; i++) { @@ -285,6 +286,7 @@ void DivPlatformESFM::tick(bool sysTick) { for (int o=0; o<4; o++) { unsigned short baseAddr=i*32+o*8; immWrite(baseAddr+OFFSET_SL_RR,0x0f); + hardResetElapsed++; } } } @@ -313,6 +315,7 @@ void DivPlatformESFM::tick(bool sysTick) { } immWrite(baseAddr+OFFSET_FREQL,chan[i].freqL[o]); immWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); + hardResetElapsed+=2; } chan[i].freqChanged=false; } @@ -330,6 +333,9 @@ void DivPlatformESFM::tick(bool sysTick) { } if (mustHardReset) { + for (unsigned int i=hardResetElapsed; i<128; i++) { + immWrite(0x25f, i&0xff); + } for (int i=0; i<18; i++) { if (chan[i].hardReset && chan[i].keyOn) { // logI("chan[%d] hard reset key on, writing original slrr back", i); @@ -890,6 +896,15 @@ int DivPlatformESFM::dispatch(DivCommand c) { } break; } + case DIV_CMD_FM_DT: { + unsigned int o=c.value; + if (o >= 4) break; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + if (opE.fixed) break; + opE.dt=c.value2; + chan[c.chan].freqChanged=true; + break; + } case DIV_CMD_FM_HARD_RESET: chan[c.chan].hardReset=c.value; break; diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 8ae4ab357..9e086a425 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -396,6 +396,10 @@ int effectValNibbleFlagPackReversed(unsigned char, unsigned char val) { return (((val&0x0f)!=0)<<1)|((val&0xf0)!=0); } +int effectValExcessOf80Hex(unsigned char, unsigned char val) { + return val-0x80; +} + template int effectValAnd(unsigned char, unsigned char val) { return val&mask; }; @@ -617,18 +621,18 @@ void DivEngine::registerSystems() { }; EffectHandlerMap fmESFMPostEffectHandlerMap={ + {0x10, {DIV_CMD_FM_AM_DEPTH, "10xy: Set AM depth (x: operator from 1 to 4 (0 for all ops); y: depth (0: 1dB, 1: 4.8dB))", effectOpVal<4>, effectValAnd<1>}}, {0x12, {DIV_CMD_FM_TL, "12xx: Set level of operator 1 (0 highest, 3F lowest)", constVal<0>, effectVal}}, {0x13, {DIV_CMD_FM_TL, "13xx: Set level of operator 2 (0 highest, 3F lowest)", constVal<1>, effectVal}}, {0x14, {DIV_CMD_FM_TL, "14xx: Set level of operator 3 (0 highest, 3F lowest)", constVal<2>, effectVal}}, {0x15, {DIV_CMD_FM_TL, "15xx: Set level of operator 4 (0 highest, 3F lowest)", constVal<3>, effectVal}}, {0x16, {DIV_CMD_FM_MULT, "16xy: Set operator multiplier (x: operator from 1 to 4; y: multiplier)", effectOpValNoZero<4>, effectValAnd<15>}}, + {0x17, {DIV_CMD_FM_PM_DEPTH, "17xy: Set vibrato depth (x: operator from 1 to 4 (0 for all ops); y: depth (0: normal, 1: double))", effectOpVal<4>, effectValAnd<1>}}, {0x19, {DIV_CMD_FM_AR, "19xx: Set attack of all operators (0 to F)", constVal<-1>, effectValAnd<15>}}, {0x1a, {DIV_CMD_FM_AR, "1Axx: Set attack of operator 1 (0 to F)", constVal<0>, effectValAnd<15>}}, {0x1b, {DIV_CMD_FM_AR, "1Bxx: Set attack of operator 2 (0 to F)", constVal<1>, effectValAnd<15>}}, {0x1c, {DIV_CMD_FM_AR, "1Cxx: Set attack of operator 3 (0 to F)", constVal<2>, effectValAnd<15>}}, {0x1d, {DIV_CMD_FM_AR, "1Dxx: Set attack of operator 4 (0 to F)", constVal<3>, effectValAnd<15>}}, - {0x1e, {DIV_CMD_FM_AM_DEPTH, "1Exy: Set AM depth (x: operator from 1 to 4 (0 for all ops); y: depth (0: 1dB, 1: 4.8dB))", effectOpVal<4>, effectValAnd<1>}}, - {0x1f, {DIV_CMD_FM_PM_DEPTH, "1Fxy: Set vibrato depth (x: operator from 1 to 4 (0 for all ops); y: depth (0: normal, 1: double))", effectOpVal<4>, effectValAnd<1>}}, {0x20, {DIV_CMD_ESFM_OP_PANNING, "20xy: Set panning of operator 1 (x: left; y: right)", constVal<0>, effectValNibbleFlagPackReversed}}, {0x21, {DIV_CMD_ESFM_OP_PANNING, "21xy: Set panning of operator 2 (x: left; y: right)", constVal<1>, effectValNibbleFlagPackReversed}}, {0x22, {DIV_CMD_ESFM_OP_PANNING, "22xy: Set panning of operator 3 (x: left; y: right)", constVal<2>, effectValNibbleFlagPackReversed}}, @@ -639,6 +643,10 @@ void DivEngine::registerSystems() { {0x27, {DIV_CMD_STD_NOISE_MODE, "27xx: Set noise mode for operator 4 (x: mode from 0 to 3)", effectValAnd<3>}}, {0x2a, {DIV_CMD_FM_WS, "2Axy: Set waveform (x: operator from 1 to 4 (0 for all ops); y: waveform from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, {0x2f, {DIV_CMD_FM_FIXFREQ, "2Fxy: Set fixed frequency block (x: operator from 1 to 4; y: octave from 0 to 7)", effectOpValNoZero<4>, effectValAnd<7>}}, + {0x40, {DIV_CMD_FM_DT, "40xx: Set detune of operator 1 (80 = base pitch)", constVal<0>, effectValExcessOf80Hex}}, + {0x41, {DIV_CMD_FM_DT, "41xx: Set detune of operator 2 (80 = base pitch)", constVal<1>, effectValExcessOf80Hex}}, + {0x42, {DIV_CMD_FM_DT, "42xx: Set detune of operator 3 (80 = base pitch)", constVal<2>, effectValExcessOf80Hex}}, + {0x43, {DIV_CMD_FM_DT, "43xx: Set detune of operator 4 (80 = base pitch)", constVal<3>, effectValExcessOf80Hex}}, {0x50, {DIV_CMD_FM_AM, "50xy: Set AM (x: operator from 1 to 4 (0 for all ops); y: AM)", effectOpVal<4>, effectValAnd<1>}}, {0x51, {DIV_CMD_FM_SL, "51xy: Set sustain level (x: operator from 1 to 4 (0 for all ops); y: sustain)", effectOpVal<4>, effectValAnd<15>}}, {0x52, {DIV_CMD_FM_RR, "52xy: Set release (x: operator from 1 to 4 (0 for all ops); y: release)", effectOpVal<4>, effectValAnd<15>}}, diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 873760d85..fbc054b0b 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -166,7 +166,11 @@ const char* oplDrumNames[4]={ }; const char* esfmNoiseModeNames[4]={ - "Noise disabled", "Snare (square + noise)", "HiHat (ringmod from OP3, + noise)", "Top (ringmod from OP3)\nWARNING - not emulated properly! Will change in future versions." + "Normal", "Snare", "HiHat", "Top" +}; + +const char* esfmNoiseModeDescriptions[4]={ + "Noise disabled", "Square + noise", "Ringmod from OP3 + noise", "Ringmod from OP3 + double pitch ModInput\nWARNING - has emulation issues, subject to change" }; const bool opIsOutput[8][4]={ @@ -3300,8 +3304,8 @@ void FurnaceGUI::drawInsEdit() { } case DIV_INS_ESFM: { ImGui::TableNextColumn(); - P(CWSliderScalar(ESFM_LONG_NAME(ESFM_NOISE),ImGuiDataType_U8,&ins->esfm.noise,&_ZERO,&_THREE)); rightClickable - ImGui::TextUnformatted(esfmNoiseModeNames[ins->esfm.noise&3]); + P(CWSliderScalar(ESFM_LONG_NAME(ESFM_NOISE),ImGuiDataType_U8,&ins->esfm.noise,&_ZERO,&_THREE,esfmNoiseModeNames[ins->esfm.noise&3])); rightClickable + ImGui::TextUnformatted(esfmNoiseModeDescriptions[ins->esfm.noise&3]); ImGui::TableNextColumn(); ImGui::TableNextColumn(); if (fmPreviewOn) { From b79938335155e8d436b16245071380e2388c1042 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Tue, 24 Oct 2023 14:34:26 -0300 Subject: [PATCH 18/34] Changing detune effect description for consistency --- src/engine/sysDef.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 9e086a425..8f6aa6021 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -643,10 +643,10 @@ void DivEngine::registerSystems() { {0x27, {DIV_CMD_STD_NOISE_MODE, "27xx: Set noise mode for operator 4 (x: mode from 0 to 3)", effectValAnd<3>}}, {0x2a, {DIV_CMD_FM_WS, "2Axy: Set waveform (x: operator from 1 to 4 (0 for all ops); y: waveform from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, {0x2f, {DIV_CMD_FM_FIXFREQ, "2Fxy: Set fixed frequency block (x: operator from 1 to 4; y: octave from 0 to 7)", effectOpValNoZero<4>, effectValAnd<7>}}, - {0x40, {DIV_CMD_FM_DT, "40xx: Set detune of operator 1 (80 = base pitch)", constVal<0>, effectValExcessOf80Hex}}, - {0x41, {DIV_CMD_FM_DT, "41xx: Set detune of operator 2 (80 = base pitch)", constVal<1>, effectValExcessOf80Hex}}, - {0x42, {DIV_CMD_FM_DT, "42xx: Set detune of operator 3 (80 = base pitch)", constVal<2>, effectValExcessOf80Hex}}, - {0x43, {DIV_CMD_FM_DT, "43xx: Set detune of operator 4 (80 = base pitch)", constVal<3>, effectValExcessOf80Hex}}, + {0x40, {DIV_CMD_FM_DT, "40xx: Set detune of operator 1 (80: center)", constVal<0>, effectValExcessOf80Hex}}, + {0x41, {DIV_CMD_FM_DT, "41xx: Set detune of operator 2 (80: center)", constVal<1>, effectValExcessOf80Hex}}, + {0x42, {DIV_CMD_FM_DT, "42xx: Set detune of operator 3 (80: center)", constVal<2>, effectValExcessOf80Hex}}, + {0x43, {DIV_CMD_FM_DT, "43xx: Set detune of operator 4 (80: center)", constVal<3>, effectValExcessOf80Hex}}, {0x50, {DIV_CMD_FM_AM, "50xy: Set AM (x: operator from 1 to 4 (0 for all ops); y: AM)", effectOpVal<4>, effectValAnd<1>}}, {0x51, {DIV_CMD_FM_SL, "51xy: Set sustain level (x: operator from 1 to 4 (0 for all ops); y: sustain)", effectOpVal<4>, effectValAnd<15>}}, {0x52, {DIV_CMD_FM_RR, "52xy: Set release (x: operator from 1 to 4 (0 for all ops); y: release)", effectOpVal<4>, effectValAnd<15>}}, From 7d0eee7a95026843c45716c6305827e41ead4989 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Tue, 24 Oct 2023 14:49:12 -0300 Subject: [PATCH 19/34] Removing dash from system name Because it causes problems with e.g. KDE in the window title. --- src/engine/sysDef.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 8f6aa6021..7c92997fa 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1977,7 +1977,7 @@ void DivEngine::registerSystems() { ); sysDefs[DIV_SYSTEM_ESFM]=new DivSysDef( - "ESS ES1xxx-series (ESFM)", NULL, 0xd0, 0, 18, true, false, 0, false, 0, + "ESS ES1xxx series (ESFM)", NULL, 0xd0, 0, 18, true, false, 0, false, 0, "A unique FM synth featured in PC sound cards.\nBased on the OPL3 design, but with lots of its features extended.", {"FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "FM 7", "FM 8", "FM 9", "FM 10", "FM 11", "FM 12", "FM 13", "FM 14", "FM 15", "FM 16", "FM 17", "FM 18"}, {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, From 928ff5c2d8cf199665f94eacb9bfda8751c794c4 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Tue, 24 Oct 2023 14:59:00 -0300 Subject: [PATCH 20/34] Removing placeholder --- src/gui/sysConf.cpp | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index edfdc6730..813942d0c 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -2215,27 +2215,6 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl } break; } - case DIV_SYSTEM_ESFM: { - supportsCustomRate=false; - - // TODO: Remove the text below and uncomment the rest when overflow emulation is added to ESFMu - // (still under research) - ImGui::Text("nothing to configure"); - - // bool emulateOverflow=flags.getBool("emulateOverflow", false); - // - // if (ImGui::Checkbox("Enable overflow emulation", &emulateOverflow)) { - // altered=true; - // mustRender=true; - // } - // - // if (altered) { - // e->lockSave([&]() { - // flags.set("emulateOverflow", emulateOverflow); - // }); - // } - break; - } case DIV_SYSTEM_SWAN: case DIV_SYSTEM_BUBSYS_WSG: case DIV_SYSTEM_PET: @@ -2246,6 +2225,7 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl case DIV_SYSTEM_C219: break; case DIV_SYSTEM_YMU759: + case DIV_SYSTEM_ESFM: supportsCustomRate=false; ImGui::Text("nothing to configure"); break; From f25d254eea82695358eaaf31ad408ad2a807ecc7 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Wed, 25 Oct 2023 10:10:59 -0300 Subject: [PATCH 21/34] Adding system presets for ESFM --- src/gui/presets.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index b83794638..74599b4ba 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -1070,6 +1070,17 @@ void FurnaceGUI::initSystemPresets() { CH(DIV_SYSTEM_PCSPKR, 1.0f, 0, "") } ); + ENTRY( + "PC + ESS ES1488 (native ESFM mode)", { + CH(DIV_SYSTEM_ESFM, 1.0f, 0, ""), + CH(DIV_SYSTEM_PCM_DAC, 1.0f, 0, + "rate=44100\n" + "outDepth=15\n" + "stereo=true\n" + ), + CH(DIV_SYSTEM_PCSPKR, 1.0f, 0, "") + } + ); ENTRY( "PC + PC-FXGA", { CH(DIV_SYSTEM_PCE, 1.0f, 0, ""), // HuC6230 (WSG from HuC6280 but with built in 2 OKI ADPCM playback engines) @@ -2364,6 +2375,11 @@ void FurnaceGUI::initSystemPresets() { ) } ); + ENTRY( + "ESS ES1xxx series (ESFM)", { + CH(DIV_SYSTEM_ESFM, 1.0f, 0, "") + } + ); if (settings.hiddenSystems) { ENTRY( "Yamaha YMU759 (MA-2)", { From 6ae49e4985c41976d220a6be0dce4b466f81ecda Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Wed, 25 Oct 2023 12:32:58 -0300 Subject: [PATCH 22/34] Rectifying ESFM preset name --- src/gui/presets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index 74599b4ba..9947f29c7 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -1071,7 +1071,7 @@ void FurnaceGUI::initSystemPresets() { } ); ENTRY( - "PC + ESS ES1488 (native ESFM mode)", { + "PC + ESS AudioDrive ES1488 (native ESFM mode)", { CH(DIV_SYSTEM_ESFM, 1.0f, 0, ""), CH(DIV_SYSTEM_PCM_DAC, 1.0f, 0, "rate=44100\n" From 91e6d848e60724511966b439692ba9657e01d880 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Wed, 25 Oct 2023 13:49:57 -0300 Subject: [PATCH 23/34] Changing ESFM chip ID (0xd0 is taken) --- src/engine/sysDef.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 7c92997fa..f676b62d2 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1977,7 +1977,7 @@ void DivEngine::registerSystems() { ); sysDefs[DIV_SYSTEM_ESFM]=new DivSysDef( - "ESS ES1xxx series (ESFM)", NULL, 0xd0, 0, 18, true, false, 0, false, 0, + "ESS ES1xxx series (ESFM)", NULL, 0xd1, 0, 18, true, false, 0, false, 0, "A unique FM synth featured in PC sound cards.\nBased on the OPL3 design, but with lots of its features extended.", {"FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "FM 7", "FM 8", "FM 9", "FM 10", "FM 11", "FM 12", "FM 13", "FM 14", "FM 15", "FM 16", "FM 17", "FM 18"}, {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, From d47fcd96168c64acb9dd4c76af222c14f1770e63 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Wed, 25 Oct 2023 14:02:52 -0300 Subject: [PATCH 24/34] Adding placeholder for Namco C352 --- src/engine/song.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine/song.h b/src/engine/song.h index 4545ed126..fd7304050 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -132,6 +132,7 @@ enum DivSystem { DIV_SYSTEM_TED, DIV_SYSTEM_C140, DIV_SYSTEM_C219, + DIV_SYSTEM_C352, DIV_SYSTEM_ESFM }; From 59d56b169bed9989a519c9007f3b78a0bb304630 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Wed, 25 Oct 2023 17:33:57 -0300 Subject: [PATCH 25/34] Removing stray space --- src/engine/instrument.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 40559cf59..244b104c0 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -151,8 +151,6 @@ enum DivMacroTypeOp: unsigned char { // - AM, AR, DR, MULT (CRS), RR, SL, TL, DT2, RS, DT, D2R // - WS, DVB = MULT (FINE), DAM = REV, KSL = EGShift, EGT = Fixed - - struct DivInstrumentFM { unsigned char alg, fb, fms, ams, fms2, ams2, ops, opllPreset; bool fixedDrums; From 170248e61a65c1953da707a854a6e0192a394a86 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Thu, 26 Oct 2023 09:43:01 -0300 Subject: [PATCH 26/34] Code review suggestions Haven't had a good peer review in ages. --- .gitignore | 1 - extern/ESFMu/.clangd | 2 - src/engine/platform/esfm.cpp | 222 +++++++++++++++++------------------ src/engine/platform/esfm.h | 4 +- src/engine/song.h | 1 - src/engine/sysDef.cpp | 26 ++-- src/gui/insEdit.cpp | 2 +- 7 files changed, 122 insertions(+), 136 deletions(-) delete mode 100644 extern/ESFMu/.clangd diff --git a/.gitignore b/.gitignore index 06812e61e..09314bb24 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,3 @@ res/docpdf/manual.pdf res/docpdf/.venv res/docpdf/htmldoc/ res/furnace.appdata.xml -compile_commands.json diff --git a/extern/ESFMu/.clangd b/extern/ESFMu/.clangd deleted file mode 100644 index f6023d41f..000000000 --- a/extern/ESFMu/.clangd +++ /dev/null @@ -1,2 +0,0 @@ -CompileFlags: - Add: ["-xc", "-Wall", "-Wextra"] diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 88d7a8051..f02fd6ef5 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -26,14 +26,14 @@ #define CHIP_FREQBASE (32768*288) -#define OFFSET_AM_VIB_SUS_KSR_MULT 0x00 -#define OFFSET_KSL_TL 0x01 -#define OFFSET_AR_DR 0x02 -#define OFFSET_SL_RR 0x03 -#define OFFSET_FREQL 0x04 -#define OFFSET_FREQH_BLOCK_DELAY 0x05 -#define OFFSET_DAM_DVB_LEFT_RIGHT_MODIN 0x06 -#define OFFSET_OUTLVL_NOISE_WS 0x07 +#define ADDR_AM_VIB_SUS_KSR_MULT 0x00 +#define ADDR_KSL_TL 0x01 +#define ADDR_AR_DR 0x02 +#define ADDR_SL_RR 0x03 +#define ADDR_FREQL 0x04 +#define ADDR_FREQH_BLOCK_DELAY 0x05 +#define ADDR_DAM_DVB_LEFT_RIGHT_MODIN 0x06 +#define ADDR_OUTLVL_NOISE_WS 0x07 #define KEY_ON_REGS_START (18*8*4) @@ -72,13 +72,13 @@ void DivPlatformESFM::tick(bool sysTick) { unsigned char noise=chan[i].state.esfm.noise&3; if (isMuted[i]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); - if (KVS(i, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[i].outVol&0x3f,63))|(op.ksl<<6)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + if (KVS(i,o)) { + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[i].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } } @@ -99,7 +99,7 @@ void DivPlatformESFM::tick(bool sysTick) { unsigned short baseAddr=i*32+o*8; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } } @@ -120,17 +120,16 @@ void DivPlatformESFM::tick(bool sysTick) { } if (chan[i].std.duty.had) { - int o=3; - unsigned short baseAddr=i*32+o*8; + unsigned short baseAddr=i*32+3*8; DivInstrumentESFM& ins=chan[i].state.esfm; - DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; - DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[o]; + DivInstrumentFM::Operator& op=chan[i].state.fm.op[3]; + DivInstrumentESFM::Operator& opE=chan[i].state.esfm.op[3]; ins.noise=chan[i].std.duty.val; if (isMuted[i]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?ins.noise&3:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((ins.noise&3)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?ins.noise&3:0)<<3)|((opE.outLvl&7)<<5)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((ins.noise&3)<<3)|((opE.outLvl&7)<<5)); } } @@ -142,40 +141,40 @@ void DivPlatformESFM::tick(bool sysTick) { if (m.am.had) { op.am=m.am.val; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } if (m.vib.had) { op.vib=m.vib.val; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } if (m.sus.had) { op.sus=m.sus.val; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } if (m.ksr.had) { op.ksr=m.ksr.val; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } if (m.mult.had) { op.mult=m.mult.val; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } if (m.ar.had) { op.ar=m.ar.val; - rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+ADDR_AR_DR,(op.ar<<4)|(op.dr&0xf)); } if (m.dr.had) { op.dr=m.dr.val; - rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+ADDR_AR_DR,(op.ar<<4)|(op.dr&0xf)); } if (m.sl.had) { op.sl=m.sl.val; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); } if (m.rr.had) { op.rr=m.rr.val; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); } if (m.tl.had || m.ksl.had) { @@ -187,30 +186,30 @@ void DivPlatformESFM::tick(bool sysTick) { } if (KVS(i, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[i].outVol&0x3f,63))|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[i].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } if (m.dam.had) { op.dam=m.dam.val; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } if (m.dvb.had) { op.dvb=m.dvb.val; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } if (m.rs.had) { // operator panning opE.left=(m.rs.val&2)!=0; opE.right=(m.rs.val&1)!=0; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } if (m.d2r.had) { // modIn opE.modIn=m.d2r.val; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[i].globalPan)&1)<<4)|(((opE.right&(chan[i].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } if (m.egt.had | m.ws.had) { @@ -224,9 +223,9 @@ void DivPlatformESFM::tick(bool sysTick) { } if (isMuted[i]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); } } @@ -253,7 +252,7 @@ void DivPlatformESFM::tick(bool sysTick) { } if (m.dt2.had) { opE.delay=m.dt2.val; - rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); + rWrite(baseAddr+ADDR_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); } } } @@ -285,7 +284,7 @@ void DivPlatformESFM::tick(bool sysTick) { // logI("chan[%d] hard reset, slrr := 0x0f", i); for (int o=0; o<4; o++) { unsigned short baseAddr=i*32+o*8; - immWrite(baseAddr+OFFSET_SL_RR,0x0f); + immWrite(baseAddr+ADDR_SL_RR,0x0f); hardResetElapsed++; } } @@ -313,8 +312,8 @@ void DivPlatformESFM::tick(bool sysTick) { chan[i].freqL[o]=freqt&0xff; chan[i].freqH[o]=freqt>>8; } - immWrite(baseAddr+OFFSET_FREQL,chan[i].freqL[o]); - immWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); + immWrite(baseAddr+ADDR_FREQL,chan[i].freqL[o]); + immWrite(baseAddr+ADDR_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); hardResetElapsed+=2; } chan[i].freqChanged=false; @@ -342,7 +341,7 @@ void DivPlatformESFM::tick(bool sysTick) { for (int o=0; o<4; o++) { unsigned short baseAddr=i*32+o*8; DivInstrumentFM::Operator& op=chan[i].state.fm.op[o]; - immWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + immWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); } if (i<16) { immWrite(KEY_ON_REGS_START+i, 1); @@ -385,13 +384,13 @@ void DivPlatformESFM::muteChannel(int ch, bool mute) { unsigned char noise=chan[ch].state.esfm.noise&3; if (isMuted[ch]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); - if (KVS(ch, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[ch].outVol&0x3f,63))|(op.ksl<<6)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + if (KVS(ch,o)) { + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[ch].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } } @@ -408,21 +407,21 @@ void DivPlatformESFM::commitState(int ch, DivInstrument* ins) { unsigned char noise=chan[ch].state.esfm.noise&3; if (isMuted[ch]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); - if (KVS(ch, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[ch].outVol&0x3f,63))|(op.ksl<<6)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + if (KVS(ch,o)) { + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[ch].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); - rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); - rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[ch].freqH[o]|(opE.delay<<5)); - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[ch].globalPan)&1)<<4)|(((opE.right&(chan[ch].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+ADDR_FREQH_BLOCK_DELAY,chan[ch].freqH[o]|(opE.delay<<5)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[ch].globalPan)&1)<<4)|(((opE.right&(chan[ch].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } } } @@ -471,10 +470,10 @@ int DivPlatformESFM::dispatch(DivCommand c) { for (int o=0; o<4; o++) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; - if (KVS(c.chan, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + if (KVS(c.chan,o)) { + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } break; @@ -494,7 +493,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } break; } @@ -551,7 +550,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.mult=c.value2&15; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); break; } case DIV_CMD_FM_TL: { @@ -560,10 +559,10 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.tl=c.value2&63; - if (KVS(c.chan, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + if (KVS(c.chan,o)) { + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } break; } @@ -573,7 +572,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ar=c.value2&15; - rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+ADDR_AR_DR,(op.ar<<4)|(op.dr&0xf)); } } else { unsigned int o=c.value; @@ -581,7 +580,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ar=c.value2&15; - rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+ADDR_AR_DR,(op.ar<<4)|(op.dr&0xf)); } break; } @@ -591,7 +590,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.dr=c.value2&15; - rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+ADDR_AR_DR,(op.ar<<4)|(op.dr&0xf)); } } else { unsigned int o=c.value; @@ -599,7 +598,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.dr=c.value2&15; - rWrite(baseAddr+OFFSET_AR_DR,(op.ar<<4)|(op.dr&0xf)); + rWrite(baseAddr+ADDR_AR_DR,(op.ar<<4)|(op.dr&0xf)); } break; } @@ -609,7 +608,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sl=c.value2&15; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); } } else { unsigned int o=c.value; @@ -617,7 +616,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sl=c.value2&15; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); } break; } @@ -627,7 +626,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.rr=c.value2&15; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); } } else { unsigned int o=c.value; @@ -635,7 +634,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.rr=c.value2&15; - rWrite(baseAddr+OFFSET_SL_RR,(op.sl<<4)|(op.rr&0xf)); + rWrite(baseAddr+ADDR_SL_RR,(op.sl<<4)|(op.rr&0xf)); } break; } @@ -645,7 +644,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.am=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { unsigned int o=c.value; @@ -653,7 +652,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.am=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } break; } @@ -663,7 +662,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.vib=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { unsigned int o=c.value; @@ -671,7 +670,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.vib=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } break; } @@ -681,7 +680,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sus=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { unsigned int o=c.value; @@ -689,7 +688,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.sus=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } break; } @@ -699,7 +698,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksr=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } } else { unsigned int o=c.value; @@ -707,7 +706,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksr=c.value2&1; - rWrite(baseAddr+OFFSET_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); + rWrite(baseAddr+ADDR_AM_VIB_SUS_KSR_MULT,((op.am&1)<<7)|((op.vib&1)<<6)|((op.sus&1)<<5)|((op.ksr&1)<<4)|(op.mult&0xf)); } break; } @@ -720,9 +719,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned char noise=chan[c.chan].state.esfm.noise&3; op.ws=c.value2&7; if (isMuted[c.chan]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); } } } else { @@ -734,9 +733,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned char noise=chan[c.chan].state.esfm.noise&3; op.ws=c.value2&7; if (isMuted[c.chan]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); } } break; @@ -748,10 +747,10 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksl=c.value2&3; - if (KVS(c.chan, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + if (KVS(c.chan,o)) { + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } } else { @@ -760,10 +759,10 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; op.ksl=c.value2&3; - if (KVS(c.chan, o)) { - rWrite(baseAddr+OFFSET_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); + if (KVS(c.chan,o)) { + rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[c.chan].outVol&0x3f,63))|(op.ksl<<6)); } else { - rWrite(baseAddr+OFFSET_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); + rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); } } break; @@ -775,7 +774,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; op.dam=c.value2&1; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); break; } case DIV_CMD_FM_PM_DEPTH: { @@ -785,7 +784,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; op.dvb=c.value2&1; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); break; } case DIV_CMD_FM_FIXFREQ: { @@ -809,9 +808,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; - opE.left=c.value2&1; - opE.right=(c.value2&2)>>1; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + opE.left=(c.value2&0xf0)!=0; + opE.right=(c.value2&0x0f)!=0; + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); break; } case DIV_CMD_ESFM_OUTLVL: { @@ -823,9 +822,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned char noise=chan[c.chan].state.esfm.noise&3; opE.outLvl=c.value2&7; if (isMuted[c.chan]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); } } } else { @@ -837,9 +836,9 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned char noise=chan[c.chan].state.esfm.noise&3; opE.outLvl=c.value2&7; if (isMuted[c.chan]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|((o==3?noise:0)<<3)|((opE.outLvl&7)<<5)); } } break; @@ -851,7 +850,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.modIn=c.value2&7; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } } else { unsigned int o=c.value; @@ -860,7 +859,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.modIn=c.value2&7; - rWrite(baseAddr+OFFSET_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); + rWrite(baseAddr+ADDR_DAM_DVB_LEFT_RIGHT_MODIN,((opE.modIn&7)<<1)|(((opE.left&chan[c.chan].globalPan)&1)<<4)|(((opE.right&(chan[c.chan].globalPan>>1))&1)<<5)|((op.dvb&1)<<6)|(op.dam<<7)); } break; } @@ -870,7 +869,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.delay=c.value2&7; - rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); + rWrite(baseAddr+ADDR_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); } } else { unsigned int o=c.value; @@ -878,21 +877,20 @@ int DivPlatformESFM::dispatch(DivCommand c) { unsigned short baseAddr=c.chan*32+o*8; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; opE.delay=c.value2&7; - rWrite(baseAddr+OFFSET_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); + rWrite(baseAddr+ADDR_FREQH_BLOCK_DELAY,chan[c.chan].freqH[o]|(opE.delay<<5)); } break; } case DIV_CMD_STD_NOISE_MODE: { - unsigned int o=3; - unsigned short baseAddr=c.chan*32+o*8; - DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[o]; - DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; + unsigned short baseAddr=c.chan*32+3*8; + DivInstrumentFM::Operator& op=chan[c.chan].state.fm.op[3]; + DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[3]; DivInstrumentESFM insE=chan[c.chan].state.esfm; insE.noise=c.value&3; if (isMuted[c.chan]) { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|(insE.noise<<3)|0); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|(insE.noise<<3)|0); } else { - rWrite(baseAddr+OFFSET_OUTLVL_NOISE_WS,(op.ws&7)|(insE.noise<<3)|((opE.outLvl&7)<<5)); + rWrite(baseAddr+ADDR_OUTLVL_NOISE_WS,(op.ws&7)|(insE.noise<<3)|((opE.outLvl&7)<<5)); } break; } @@ -901,7 +899,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { if (o >= 4) break; DivInstrumentESFM::Operator& opE=chan[c.chan].state.esfm.op[o]; if (opE.fixed) break; - opE.dt=c.value2; + opE.dt=c.value2-0x80; chan[c.chan].freqChanged=true; break; } @@ -1032,8 +1030,8 @@ void DivPlatformESFM::poke(std::vector& wlist) { } void DivPlatformESFM::setFlags(const DivConfig& flags) { - rate=49716; chipClock=COLOR_NTSC*4.0; + rate=chipClock/288.0; } int DivPlatformESFM::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { diff --git a/src/engine/platform/esfm.h b/src/engine/platform/esfm.h index 5fc000c20..698313ad8 100644 --- a/src/engine/platform/esfm.h +++ b/src/engine/platform/esfm.h @@ -23,8 +23,8 @@ // ESFM register address space technically spans 0x800 (2048) bytes, // but we only need the first 0x254 (596) during normal use. -// Rounding it up to 0x260 (608) bytes, the nearest multiple of 16. -#define ESFM_REG_POOL_SIZE 0x260 +// Rounding it up to 0x400 bytes, the nearest power of 2. +#define ESFM_REG_POOL_SIZE 0x400 class DivPlatformESFM: public DivDispatch { struct Channel: public SharedChannel { diff --git a/src/engine/song.h b/src/engine/song.h index fd7304050..4545ed126 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -132,7 +132,6 @@ enum DivSystem { DIV_SYSTEM_TED, DIV_SYSTEM_C140, DIV_SYSTEM_C219, - DIV_SYSTEM_C352, DIV_SYSTEM_ESFM }; diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index ae25e6673..c348de34c 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -392,14 +392,6 @@ int negEffectVal(unsigned char, unsigned char val) { return -(int)val; }; -int effectValNibbleFlagPackReversed(unsigned char, unsigned char val) { - return (((val&0x0f)!=0)<<1)|((val&0xf0)!=0); -} - -int effectValExcessOf80Hex(unsigned char, unsigned char val) { - return val-0x80; -} - template int effectValAnd(unsigned char, unsigned char val) { return val&mask; }; @@ -635,20 +627,20 @@ void DivEngine::registerSystems() { {0x1b, {DIV_CMD_FM_AR, "1Bxx: Set attack of operator 2 (0 to F)", constVal<1>, effectValAnd<15>}}, {0x1c, {DIV_CMD_FM_AR, "1Cxx: Set attack of operator 3 (0 to F)", constVal<2>, effectValAnd<15>}}, {0x1d, {DIV_CMD_FM_AR, "1Dxx: Set attack of operator 4 (0 to F)", constVal<3>, effectValAnd<15>}}, - {0x20, {DIV_CMD_ESFM_OP_PANNING, "20xy: Set panning of operator 1 (x: left; y: right)", constVal<0>, effectValNibbleFlagPackReversed}}, - {0x21, {DIV_CMD_ESFM_OP_PANNING, "21xy: Set panning of operator 2 (x: left; y: right)", constVal<1>, effectValNibbleFlagPackReversed}}, - {0x22, {DIV_CMD_ESFM_OP_PANNING, "22xy: Set panning of operator 3 (x: left; y: right)", constVal<2>, effectValNibbleFlagPackReversed}}, - {0x23, {DIV_CMD_ESFM_OP_PANNING, "23xy: Set panning of operator 4 (x: left; y: right)", constVal<3>, effectValNibbleFlagPackReversed}}, + {0x20, {DIV_CMD_ESFM_OP_PANNING, "20xy: Set panning of operator 1 (x: left; y: right)", constVal<0>, effectVal}}, + {0x21, {DIV_CMD_ESFM_OP_PANNING, "21xy: Set panning of operator 2 (x: left; y: right)", constVal<1>, effectVal}}, + {0x22, {DIV_CMD_ESFM_OP_PANNING, "22xy: Set panning of operator 3 (x: left; y: right)", constVal<2>, effectVal}}, + {0x23, {DIV_CMD_ESFM_OP_PANNING, "23xy: Set panning of operator 4 (x: left; y: right)", constVal<3>, effectVal}}, {0x24, {DIV_CMD_ESFM_OUTLVL, "24xy: Set output level register (x: operator from 1 to 4 (0 for all ops); y: level from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, {0x25, {DIV_CMD_ESFM_MODIN, "25xy: Set modulation input level (x: operator from 1 to 4 (0 for all ops); y: level from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, {0x26, {DIV_CMD_ESFM_ENV_DELAY, "26xy: Set envelope delay (x: operator from 1 to 4 (0 for all ops); y: delay from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, {0x27, {DIV_CMD_STD_NOISE_MODE, "27xx: Set noise mode for operator 4 (x: mode from 0 to 3)", effectValAnd<3>}}, {0x2a, {DIV_CMD_FM_WS, "2Axy: Set waveform (x: operator from 1 to 4 (0 for all ops); y: waveform from 0 to 7)", effectOpVal<4>, effectValAnd<7>}}, {0x2f, {DIV_CMD_FM_FIXFREQ, "2Fxy: Set fixed frequency block (x: operator from 1 to 4; y: octave from 0 to 7)", effectOpValNoZero<4>, effectValAnd<7>}}, - {0x40, {DIV_CMD_FM_DT, "40xx: Set detune of operator 1 (80: center)", constVal<0>, effectValExcessOf80Hex}}, - {0x41, {DIV_CMD_FM_DT, "41xx: Set detune of operator 2 (80: center)", constVal<1>, effectValExcessOf80Hex}}, - {0x42, {DIV_CMD_FM_DT, "42xx: Set detune of operator 3 (80: center)", constVal<2>, effectValExcessOf80Hex}}, - {0x43, {DIV_CMD_FM_DT, "43xx: Set detune of operator 4 (80: center)", constVal<3>, effectValExcessOf80Hex}}, + {0x40, {DIV_CMD_FM_DT, "40xx: Set detune of operator 1 (80: center)", constVal<0>, effectVal}}, + {0x41, {DIV_CMD_FM_DT, "41xx: Set detune of operator 2 (80: center)", constVal<1>, effectVal}}, + {0x42, {DIV_CMD_FM_DT, "42xx: Set detune of operator 3 (80: center)", constVal<2>, effectVal}}, + {0x43, {DIV_CMD_FM_DT, "43xx: Set detune of operator 4 (80: center)", constVal<3>, effectVal}}, {0x50, {DIV_CMD_FM_AM, "50xy: Set AM (x: operator from 1 to 4 (0 for all ops); y: AM)", effectOpVal<4>, effectValAnd<1>}}, {0x51, {DIV_CMD_FM_SL, "51xy: Set sustain level (x: operator from 1 to 4 (0 for all ops); y: sustain)", effectOpVal<4>, effectValAnd<15>}}, {0x52, {DIV_CMD_FM_RR, "52xy: Set release (x: operator from 1 to 4 (0 for all ops); y: release)", effectOpVal<4>, effectValAnd<15>}}, @@ -1980,7 +1972,7 @@ void DivEngine::registerSystems() { sysDefs[DIV_SYSTEM_ESFM]=new DivSysDef( "ESS ES1xxx series (ESFM)", NULL, 0xd1, 0, 18, true, false, 0, false, 0, - "A unique FM synth featured in PC sound cards.\nBased on the OPL3 design, but with lots of its features extended.", + "a unique FM synth featured in PC sound cards.\nbased on the OPL3 design, but with lots of its features extended.", {"FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "FM 7", "FM 8", "FM 9", "FM 10", "FM 11", "FM 12", "FM 13", "FM 14", "FM 15", "FM 16", "FM 17", "FM 18"}, {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, {DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM, DIV_CH_FM}, diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 3e7dffbec..ef3b35c8c 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -49,7 +49,7 @@ const char* esfmParamLongNames[9]={ }; const char* esfmParamNames[9]={ - "OP4 Noise Mode", "Env. Delay", "Output Level", "ModInput", "Left", "Right", "Coarse Tn.", "Detune", "Fixed" + "OP4 Noise Mode", "Env. Delay", "Output Level", "ModInput", "Left", "Right", "Tune", "Detune", "Fixed" }; const char* esfmParamShortNames[9]={ From 47c4273e5cb7155aa5143c62f85f142f7ecf6f9b Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Thu, 26 Oct 2023 09:45:46 -0300 Subject: [PATCH 27/34] Code review suggestions 2 --- src/engine/platform/esfm.cpp | 2 +- src/gui/insEdit.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index f02fd6ef5..30143ba1e 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -185,7 +185,7 @@ void DivPlatformESFM::tick(bool sysTick) { op.ksl=m.ksl.val; } - if (KVS(i, o)) { + if (KVS(i,o)) { rWrite(baseAddr+ADDR_KSL_TL,(63-VOL_SCALE_LOG_BROKEN(63-op.tl,chan[i].outVol&0x3f,63))|(op.ksl<<6)); } else { rWrite(baseAddr+ADDR_KSL_TL,(op.tl&0x3f)|(op.ksl<<6)); diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index ef3b35c8c..fbd513a57 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -53,7 +53,7 @@ const char* esfmParamNames[9]={ }; const char* esfmParamShortNames[9]={ - "RHY", "DL", "OL", "MI", "L", "R", "CT", "DT", "FIX" + "NOI", "DL", "OL", "MI", "L", "R", "CT", "DT", "FIX" }; const char* fmParamShortNames[3][32]={ From 46024277b2470a618b954494b0116eda1f02fe7f Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Fri, 27 Oct 2023 12:01:39 -0300 Subject: [PATCH 28/34] Removing channel deactivaton upon note off --- src/engine/platform/esfm.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 30143ba1e..961c84f39 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -451,12 +451,10 @@ int DivPlatformESFM::dispatch(DivCommand c) { case DIV_CMD_NOTE_OFF: chan[c.chan].keyOff=true; chan[c.chan].keyOn=false; - chan[c.chan].active=false; break; case DIV_CMD_NOTE_OFF_ENV: chan[c.chan].keyOff=true; chan[c.chan].keyOn=false; - chan[c.chan].active=false; chan[c.chan].std.release(); break; case DIV_CMD_ENV_RELEASE: From 403799d1a32285eff09ba320c65aa8beee4e37c2 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Fri, 15 Dec 2023 14:20:56 -0300 Subject: [PATCH 29/34] Updating sysDef; implementing mapVelocity --- src/engine/platform/esfm.cpp | 7 +++++++ src/engine/platform/esfm.h | 1 + src/engine/sysDef.cpp | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 961c84f39..baefa1291 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -1019,6 +1019,13 @@ void DivPlatformESFM::notifyInsDeletion(void* ins) { } } +int DivPlatformESFM::mapVelocity(int ch, unsigned char vel) { + const int volMax=MAX(1,dispatch(DivCommand(DIV_CMD_GET_VOLMAX,MAX(ch,0)))); + double attenDb=40*log10(vel/127); + double attenUnits=attenDb*(8.0/6.0); // negative + return MAX(0,volMax+attenUnits); +} + void DivPlatformESFM::poke(unsigned int addr, unsigned short val) { immWrite(addr,val); } diff --git a/src/engine/platform/esfm.h b/src/engine/platform/esfm.h index 698313ad8..8ec29fb8c 100644 --- a/src/engine/platform/esfm.h +++ b/src/engine/platform/esfm.h @@ -136,6 +136,7 @@ class DivPlatformESFM: public DivDispatch { void toggleRegisterDump(bool enable); void notifyInsChange(int ins); void notifyInsDeletion(void* ins); + int mapVelocity(int ch, unsigned char vel); void poke(unsigned int addr, unsigned short val); void poke(std::vector& wlist); void setFlags(const DivConfig& flags); diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 5420dbf77..792b731c3 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1972,7 +1972,7 @@ void DivEngine::registerSystems() { ); sysDefs[DIV_SYSTEM_ESFM]=new DivSysDef( - "ESS ES1xxx series (ESFM)", NULL, 0xd1, 0, 18, true, false, 0, false, 0, + "ESS ES1xxx series (ESFM)", NULL, 0xd1, 0, 18, true, false, 0, false, 0, 0, 0, "a unique FM synth featured in PC sound cards.\nbased on the OPL3 design, but with lots of its features extended.", {"FM 1", "FM 2", "FM 3", "FM 4", "FM 5", "FM 6", "FM 7", "FM 8", "FM 9", "FM 10", "FM 11", "FM 12", "FM 13", "FM 14", "FM 15", "FM 16", "FM 17", "FM 18"}, {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"}, From e32b45a1ebe9fe7a085506393e2f0ef2bae82dfe Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Fri, 15 Dec 2023 14:57:12 -0300 Subject: [PATCH 30/34] Changing mapVelocity to linear mapping --- src/engine/platform/esfm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index baefa1291..4b23522fd 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -1021,8 +1021,8 @@ void DivPlatformESFM::notifyInsDeletion(void* ins) { int DivPlatformESFM::mapVelocity(int ch, unsigned char vel) { const int volMax=MAX(1,dispatch(DivCommand(DIV_CMD_GET_VOLMAX,MAX(ch,0)))); - double attenDb=40*log10(vel/127); - double attenUnits=attenDb*(8.0/6.0); // negative + double attenDb=20*log10(vel/127); // 20dB/decade for a linear mapping + double attenUnits=attenDb*(8.0/6.0); return MAX(0,volMax+attenUnits); } From 71841aaf4f9759069a8e82f30d0a2278f279b5b2 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 17 Dec 2023 09:05:46 -0300 Subject: [PATCH 31/34] Updated mapVelocity; also changed back to MIDI standard --- src/engine/platform/esfm.cpp | 6 +++--- src/engine/platform/esfm.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 4b23522fd..13604abf4 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -1019,10 +1019,10 @@ void DivPlatformESFM::notifyInsDeletion(void* ins) { } } -int DivPlatformESFM::mapVelocity(int ch, unsigned char vel) { +int DivPlatformESFM::mapVelocity(int ch, float vel) { const int volMax=MAX(1,dispatch(DivCommand(DIV_CMD_GET_VOLMAX,MAX(ch,0)))); - double attenDb=20*log10(vel/127); // 20dB/decade for a linear mapping - double attenUnits=attenDb*(8.0/6.0); + double attenDb=40*log10(vel); // 40dB/decade for a quadratic mapping, per MIDI standard + double attenUnits=attenDb/0.75; // 0.75dB/unit return MAX(0,volMax+attenUnits); } diff --git a/src/engine/platform/esfm.h b/src/engine/platform/esfm.h index 8ec29fb8c..fbb971003 100644 --- a/src/engine/platform/esfm.h +++ b/src/engine/platform/esfm.h @@ -136,7 +136,7 @@ class DivPlatformESFM: public DivDispatch { void toggleRegisterDump(bool enable); void notifyInsChange(int ins); void notifyInsDeletion(void* ins); - int mapVelocity(int ch, unsigned char vel); + int mapVelocity(int ch, float vel); void poke(unsigned int addr, unsigned short val); void poke(std::vector& wlist); void setFlags(const DivConfig& flags); From b6d632bc9cbc3805fec6291a66d66d020f38f8fc Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 17 Dec 2023 10:40:59 -0300 Subject: [PATCH 32/34] Adding text export fixtures for ESFM instruments --- src/engine/fileOps.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index cb6f4fa90..7622662a7 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -6445,7 +6445,7 @@ SafeWriter* DivEngine::saveText(bool separatePatterns) { w->writeText(fmt::sprintf("- type: %d\n",(int)ins->type)); - if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPM) { + if (ins->type==DIV_INS_FM || ins->type==DIV_INS_OPL || ins->type==DIV_INS_OPLL || ins->type==DIV_INS_OPZ || ins->type==DIV_INS_OPL_DRUMS || ins->type==DIV_INS_OPM || ins->type==DIV_INS_ESFM) { w->writeText("- FM parameters:\n"); w->writeText(fmt::sprintf(" - ALG: %d\n",ins->fm.alg)); w->writeText(fmt::sprintf(" - FB: %d\n",ins->fm.fb)); @@ -6489,6 +6489,25 @@ SafeWriter* DivEngine::saveText(bool separatePatterns) { } } + if (ins->type==DIV_INS_ESFM) { + w->writeText("- ESFM parameters:\n"); + w->writeText(fmt::sprintf(" - noise mode: %d\n",ins->esfm.noise)); + + for (int j=0; jfm.ops; j++) { + DivInstrumentESFM::Operator& opE=ins->esfm.op[j]; + + w->writeText(fmt::sprintf(" - operator %d:\n",j)); + w->writeText(fmt::sprintf(" - DL: %d\n",opE.delay)); + w->writeText(fmt::sprintf(" - OL: %d\n",opE.outLvl)); + w->writeText(fmt::sprintf(" - MI: %d\n",opE.modIn)); + w->writeText(fmt::sprintf(" - output left: %s\n",trueFalse[opE.left?1:0])); + w->writeText(fmt::sprintf(" - output right: %s\n",trueFalse[opE.right?1:0])); + w->writeText(fmt::sprintf(" - CT: %d\n",opE.ct)); + w->writeText(fmt::sprintf(" - DT: %d\n",opE.dt)); + w->writeText(fmt::sprintf(" - fixed frequency: %s\n",trueFalse[opE.fixed?1:0])); + } + } + if (ins->type==DIV_INS_GB) { w->writeText("- Game Boy parameters:\n"); w->writeText(fmt::sprintf(" - volume: %d\n",ins->gb.envVol)); From a25bc61ff254b49aeaa7f3ad4ed30f003f00674f Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Sun, 17 Dec 2023 16:46:03 -0300 Subject: [PATCH 33/34] Reverting back to linear --- src/engine/platform/esfm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index 13604abf4..bf319fb1a 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -1021,7 +1021,7 @@ void DivPlatformESFM::notifyInsDeletion(void* ins) { int DivPlatformESFM::mapVelocity(int ch, float vel) { const int volMax=MAX(1,dispatch(DivCommand(DIV_CMD_GET_VOLMAX,MAX(ch,0)))); - double attenDb=40*log10(vel); // 40dB/decade for a quadratic mapping, per MIDI standard + double attenDb=20*log10(vel); // 20dB/decade for a linear mapping double attenUnits=attenDb/0.75; // 0.75dB/unit return MAX(0,volMax+attenUnits); } From 4459a7d6599b922e843d7e43fe1dd39acb314753 Mon Sep 17 00:00:00 2001 From: Kagamiin~ Date: Mon, 1 Jan 2024 14:59:00 -0300 Subject: [PATCH 34/34] Implementing per-op arpeggio/pitch macro Co-authored-by: LTVA1 <87536432+LTVA1@users.noreply.github.com> --- src/engine/platform/esfm.cpp | 28 ++++++++++----- src/engine/platform/esfm.h | 66 +++++++++++++++++++++++++++++++++++- src/gui/gui.h | 8 +++-- src/gui/insEdit.cpp | 17 +++++++--- 4 files changed, 103 insertions(+), 16 deletions(-) diff --git a/src/engine/platform/esfm.cpp b/src/engine/platform/esfm.cpp index bf319fb1a..c9f8a6c62 100644 --- a/src/engine/platform/esfm.cpp +++ b/src/engine/platform/esfm.cpp @@ -229,6 +229,8 @@ void DivPlatformESFM::tick(bool sysTick) { } } + + // detune/fixed pitch if (opE.fixed) { if (m.ssg.had) { @@ -241,15 +243,10 @@ void DivPlatformESFM::tick(bool sysTick) { chan[i].freqChanged=true; } } else { - if (m.ssg.had) { - opE.ct=(signed char)m.ssg.val; - chan[i].freqChanged=true; - } - if (m.dt.had) { - opE.dt=(signed char)m.dt.val; - chan[i].freqChanged=true; - } + chan[i].handleArpFmOp(0, o); + chan[i].handlePitchFmOp(o); } + if (m.dt2.had) { opE.delay=m.dt2.val; rWrite(baseAddr+ADDR_FREQH_BLOCK_DELAY,chan[i].freqH[o]|(opE.delay<<5)); @@ -257,6 +254,8 @@ void DivPlatformESFM::tick(bool sysTick) { } } + + for (int i=0; icalcFreq(chan[i].baseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride+ct:chan[i].arpOff+ct,chan[i].fixedArp,false,octave(chan[i].baseFreq)*2,chan[i].pitch2+dt,chipClock,CHIP_FREQBASE); + int arp=chan[i].fixedArp?chan[i].baseNoteOverride+ct:chan[i].arpOff+ct; + int pitch2=chan[i].pitch2+dt; + int fixedArp=chan[i].fixedArp; + if(chan[i].opsState[o].hasOpArp) { + arp=chan[i].opsState[o].fixedArp?chan[i].opsState[o].baseNoteOverride+ct:chan[i].opsState[o].arpOff+ct; + fixedArp=chan[i].opsState[o].fixedArp; + } + if(chan[i].opsState[o].hasOpPitch) { + pitch2=chan[i].opsState[o].pitch2+dt; + } + int opFreq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,arp,fixedArp,false,octave(chan[i].baseFreq)*2,pitch2,chipClock,CHIP_FREQBASE); if (opFreq<0) opFreq=0; if (opFreq>131071) opFreq=131071; int freqt=toFreq(opFreq); @@ -432,6 +441,7 @@ int DivPlatformESFM::dispatch(DivCommand c) { DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_ESFM); chan[c.chan].macroInit(ins); + memset(chan[c.chan].opsState, 0, sizeof(chan[c.chan].opsState)); if (!chan[c.chan].std.vol.will) { chan[c.chan].outVol=chan[c.chan].vol; } diff --git a/src/engine/platform/esfm.h b/src/engine/platform/esfm.h index fbb971003..a183925c7 100644 --- a/src/engine/platform/esfm.h +++ b/src/engine/platform/esfm.h @@ -36,13 +36,77 @@ class DivPlatformESFM: public DivDispatch { bool hardReset; unsigned char globalPan; int macroVolMul; + struct { + int baseNoteOverride; + bool fixedArp; + int arpOff; + int pitch2; + bool hasOpArp; + bool hasOpPitch; + } opsState[4]; + + void handleArpFmOp(int offset=0, int o=0) { + DivMacroInt::IntOp& m=this->std.op[o]; + if (m.ssg.had) { + opsState[o].hasOpArp=true; + + if (m.ssg.val<0) { + if (!(m.ssg.val&0x40000000)) { + opsState[o].baseNoteOverride=(m.ssg.val|0x40000000)+offset; + opsState[o].fixedArp=true; + } else { + opsState[o].arpOff=m.ssg.val; + opsState[o].fixedArp=false; + } + } else { + if (m.ssg.val&0x40000000) { + opsState[o].baseNoteOverride=(m.ssg.val&(~0x40000000))+offset; + opsState[o].fixedArp=true; + } else { + opsState[o].arpOff=m.ssg.val; + opsState[o].fixedArp=false; + } + } + freqChanged=true; + } + + else + { + opsState[o].hasOpArp=false; + } + } + + void handlePitchFmOp(int o) + { + DivMacroInt::IntOp& m=this->std.op[o]; + + if (m.dt.had) { + opsState[o].hasOpPitch=true; + + if (m.dt.mode) { + opsState[o].pitch2+=m.dt.val; + CLAMP_VAR(opsState[o].pitch2,-131071,131071); + } else { + opsState[o].pitch2=m.dt.val; + } + this->freqChanged=true; + } + + else + { + opsState[o].hasOpPitch=false; + } + } + Channel(): SharedChannel(0), freqL{0, 0, 0, 0}, freqH{0, 0, 0, 0}, hardReset(false), globalPan(3), - macroVolMul(64) {} + macroVolMul(64) { + memset(opsState, 0, sizeof(opsState)); + } }; Channel chan[18]; DivDispatchOscBuffer* oscBuf[18]; diff --git a/src/gui/gui.h b/src/gui/gui.h index 162ebb0ac..3e0e53137 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1245,8 +1245,10 @@ struct FurnaceGUIMacroDesc { bool isBitfield, blockMode, bit30; String (*hoverFunc)(int,float,void*); void* hoverFuncUser; + bool isArp; + bool isPitch; - FurnaceGUIMacroDesc(const char* name, DivInstrumentMacro* m, int macroMin, int macroMax, float macroHeight, ImVec4 col=ImVec4(1.0f,1.0f,1.0f,1.0f), bool block=false, const char* mName=NULL, String (*hf)(int,float,void*)=NULL, bool bitfield=false, const char** bfVal=NULL, unsigned int bitOff=0, bool bit30Special=false, void* hfu=NULL): + FurnaceGUIMacroDesc(const char* name, DivInstrumentMacro* m, int macroMin, int macroMax, float macroHeight, ImVec4 col=ImVec4(1.0f,1.0f,1.0f,1.0f), bool block=false, const char* mName=NULL, String (*hf)(int,float,void*)=NULL, bool bitfield=false, const char** bfVal=NULL, unsigned int bitOff=0, bool bit30Special=false, void* hfu=NULL, bool isArp=false, bool isPitch=false): macro(m), height(macroHeight), displayName(name), @@ -1258,7 +1260,9 @@ struct FurnaceGUIMacroDesc { blockMode(block), bit30(bit30Special), hoverFunc(hf), - hoverFuncUser(hfu) { + hoverFuncUser(hfu), + isArp(isArp), + isPitch(isPitch) { // MSVC -> hell this->min=macroMin; this->max=macroMax; diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 40515099e..bc0859811 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -1537,10 +1537,10 @@ void FurnaceGUI::drawMacroEdit(FurnaceGUIMacroDesc& i, int totalFit, float avail ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,ImVec2(0.0f,0.0f)); if (i.macro->vZoom<1) { - if (i.macro->macroType==DIV_MACRO_ARP) { + if (i.macro->macroType==DIV_MACRO_ARP || i.isArp) { i.macro->vZoom=24; i.macro->vScroll=120-12; - } else if (i.macro->macroType==DIV_MACRO_PITCH) { + } else if (i.macro->macroType==DIV_MACRO_PITCH || i.isPitch) { i.macro->vZoom=128; i.macro->vScroll=2048-64; } else { @@ -3937,6 +3937,9 @@ void FurnaceGUI::drawInsEdit() { ImGui::SetCursorPosY(ImGui::GetCursorPosY()-0.5*ImGui::GetStyle().ItemSpacing.y); if (ImGui::Checkbox(ESFM_NAME(ESFM_FIXED),&fixedOn)) { PARAMETER opE.fixed=fixedOn; + // HACK: reset zoom and scroll in fixed pitch macros so that they draw correctly + ins->std.opMacros[i].ssgMacro.vZoom=-1; + ins->std.opMacros[i].dtMacro.vZoom=-1; } if (ins->type==DIV_INS_ESFM) { if (fixedOn) { @@ -4674,6 +4677,9 @@ void FurnaceGUI::drawInsEdit() { } if (ImGui::Checkbox(ESFM_NAME(ESFM_FIXED),&fixedOn)) { PARAMETER opE.fixed=fixedOn; + // HACK: reset zoom and scroll in fixed pitch macros so that they draw correctly + ins->std.opMacros[i].ssgMacro.vZoom=-1; + ins->std.opMacros[i].dtMacro.vZoom=-1; } ImGui::EndTable(); @@ -5198,6 +5204,9 @@ void FurnaceGUI::drawInsEdit() { ImGui::SameLine(); if (ImGui::Checkbox(ESFM_NAME(ESFM_FIXED),&fixedOn)) { PARAMETER opE.fixed=fixedOn; + // HACK: reset zoom and scroll in fixed pitch macros so that they draw correctly + ins->std.opMacros[i].ssgMacro.vZoom=-1; + ins->std.opMacros[i].dtMacro.vZoom=-1; } } @@ -5322,8 +5331,8 @@ void FurnaceGUI::drawInsEdit() { macroList.push_back(FurnaceGUIMacroDesc("Block",&ins->std.opMacros[ordi].ssgMacro,0,7,64,uiColors[GUI_COLOR_MACRO_OTHER],true)); macroList.push_back(FurnaceGUIMacroDesc("FreqNum",&ins->std.opMacros[ordi].dtMacro,0,1023,160,uiColors[GUI_COLOR_MACRO_OTHER])); } else { - macroList.push_back(FurnaceGUIMacroDesc(ESFM_NAME(ESFM_CT),&ins->std.opMacros[ordi].ssgMacro,-24,24,128,uiColors[GUI_COLOR_MACRO_OTHER],true)); - macroList.push_back(FurnaceGUIMacroDesc(ESFM_NAME(ESFM_DT),&ins->std.opMacros[ordi].dtMacro,-128,127,160,uiColors[GUI_COLOR_MACRO_OTHER])); + macroList.push_back(FurnaceGUIMacroDesc("Op. Arpeggio",&ins->std.opMacros[ordi].ssgMacro,-120,120,160,uiColors[GUI_COLOR_MACRO_PITCH],true,NULL,macroHoverNote,false,NULL,0,true,ins->std.opMacros[ordi].ssgMacro.val,true)); + macroList.push_back(FurnaceGUIMacroDesc("Op. Pitch",&ins->std.opMacros[ordi].dtMacro,-2048,2047,160,uiColors[GUI_COLOR_MACRO_PITCH],true,macroRelativeMode,NULL,false,NULL,0,false,NULL,false,true)); } macroList.push_back(FurnaceGUIMacroDesc(FM_NAME(FM_AM),&ins->std.opMacros[ordi].amMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true));