├── .gitignore ├── LICENSE ├── README.md ├── adc_module.ino ├── config.h ├── data └── song.mid ├── doc ├── board_info.md └── schematic_v01.png ├── easySynth.ino ├── esp32_basic_synth.ino ├── img └── splash.jpg ├── mcp23_module.ino ├── ml_inline.ino ├── status_module.ino ├── targets.csv └── z_config.ino /.gitignore: -------------------------------------------------------------------------------- 1 | # These are some examples of commonly ignored file patterns. 2 | # You should customize this list as applicable to your project. 3 | # Learn more about .gitignore: 4 | # https://www.atlassian.com/git/tutorials/saving-changes/gitignore 5 | 6 | # Node artifact files 7 | node_modules/ 8 | dist/ 9 | 10 | # Compiled Java class files 11 | *.class 12 | 13 | # Compiled Python bytecode 14 | *.py[cod] 15 | 16 | # Log files 17 | *.log 18 | 19 | # Package files 20 | *.jar 21 | 22 | # Maven 23 | target/ 24 | dist/ 25 | 26 | # JetBrains IDE 27 | .idea/ 28 | 29 | # Unit test reports 30 | TEST*.xml 31 | 32 | # Generated by MacOS 33 | .DS_Store 34 | 35 | # Generated by Windows 36 | Thumbs.db 37 | 38 | # Applications 39 | *.app 40 | *.exe 41 | *.war 42 | 43 | # Large media files 44 | *.mp4 45 | *.tiff 46 | *.avi 47 | *.flv 48 | *.mov 49 | *.wmv 50 | 51 | arduino_build 52 | arduino_cache 53 | bld* 54 | *build 55 | /.cproject 56 | /.project 57 | 58 | *.bat 59 | makefile* 60 | *.mk -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

esp32_basic_synth

2 |

ESP32 based DIY polyphonic MIDI synthesizer module Arduino project

3 |

4 | project picture
5 | link to the video 6 |

7 | More infos: 8 | - little quick start guide to get started with arduino synthesizer / music projects: https://youtu.be/ZNxGCB-d68g 9 | 10 | 11 | > **⚠️ Note:** This project might be outdated and is no longer actively maintained. Development has continued in a new repository, which covers the **ESP32** and other boards as well. Please check out the latest version of the project here: **[ml_synth_basic_example](https://github.com/marcel-licence/ml_synth_basic_example)** 12 | 13 | --- 14 | The project has been tested on 15 | - ESP32 Audio Kit V2.2 (using ESP32-A1S) 16 | - ESP32 DEVKIT - DOIT (actually only supporting esp32\1.0.4 library) 17 | 18 | # ESP32 Audio Kit V2.2 19 | To compile set board to: ESP32 Dev Module 20 | Ensure "#define ESP32_AUDIO_KIT" is set in config.h 21 | IO22 will be used for MIDI in. 22 | 23 | The ADC multiplexer can be used (other wise please remove #define ADC_TO_MIDI_ENABLED from config.h) 24 | Connection of the ADC multiplexer: 25 | - EN -> Ground 26 | - S0 -> IO23 27 | - S1 -> IO18 28 | - S2 -> IO14 29 | - S3 -> Ground 30 | - Sig -> IO12 31 | 32 | # ESP32 DEVKIT - DOIT 33 | To compile set the board to: DOIT ESP32 DEVKIT V1 34 | Ensure that "#define ESP32_AUDIO_KIT" has been removed from config.h 35 | 36 | ## Using a DAC 37 | An external audio DAC is recommended for this setup: 38 | - BCLK -> IO25 39 | - WLCK -> IO27 40 | - DOUT -> IO26 41 | 42 | ## Using no DAC 43 | You can also get a sound without a DAC. 44 | Add '#define I2S_NODAC' to config.h 45 | 46 | The default output pin is IO22. Add a capacitor in series of the audio line (10µF for example) 47 | 48 | ## Using an ADC multiplexer 49 | Connection of the ADC multiplexer: 50 | - EN -> Ground 51 | - S0 -> IO33 52 | - S1 -> IO32 53 | - S2 -> IO13 54 | - S3 -> Ground 55 | - Sig -> IO12 56 | Here is the related video: https://youtu.be/l8GrNxElRkc 57 | 58 | ### ADC Mapping 59 | The adc module has been only tested with the ESP32 Audio Kit V2.2. 60 | In z_config.ino you can define your own mapping. Actually only 8 channels are read from the multiplexer. 61 | The adc lookup is used to define a channel and cc per analog input (C0..C7). 62 | By changing adc values a MIDI messages will generated internally. 63 | It should be also mapped int the MIDI mapping. 64 | 65 | # MIDI Mapping 66 | A controller mapping can be found in z_config.ino. 67 | You can define your own controller mapping if your controller does support CC messages. 68 | 69 | ## MIDI via USB 70 | MIDI can be received via USB activating the MACRO "MIDI_VIA_USB_ENABLED" in config.h. 71 | 72 | Default PIN Mapping is: 73 | - CS: IO5 74 | - INT: IO17 (not used) 75 | - SCK: IO18 76 | - MISO: IO19 77 | - MOSI: IO23 78 | 79 | For more information refer to the MIDI related project: https://github.com/marcel-licence/esp32_usb_midi 80 | Using USB can be seen here: https://youtu.be/Mt3rT-SVZww 81 | 82 | --- 83 | If you have questions or ideas please feel free to use the discussion area! 84 | 85 | Derived projects 86 | --- 87 | 88 | MichaelPNolan added a phyicial interface, knobs etc. to make it standalone: https://github.com/MichaelPNolan/StandAloneSynth37key/tree/main/esp32_alone_synth 89 | 90 | 91 | # Support & Donations 92 | 93 | If you appreciate the work done on this project and would like to support its development, I would be more than happy to accept donations! 94 | 95 | For more information on how to donate, please send an email to: 96 | 97 | 📧 **marcel.licence.o@gmail.com** 98 | 99 | Thank you for your support! 100 | -------------------------------------------------------------------------------- /adc_module.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This module is run adc with a multiplexer 3 | * tested with ESP32 Audio Kit V2.2 4 | * Only tested with 8 inputs 5 | * 6 | * Define your adc mapping in the lookup table 7 | * 8 | * Reference: https://youtu.be/l8GrNxElRkc 9 | * 10 | Copyright (C) 2021 Marcel Licence 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program. If not, see . 24 | */ 25 | 26 | #ifdef __CDT_PARSER__ 27 | #include 28 | #endif 29 | 30 | #ifdef ADC_TO_MIDI_ENABLED 31 | 32 | struct adc_to_midi_s 33 | { 34 | uint8_t ch; 35 | uint8_t cc; 36 | }; 37 | 38 | struct adc_to_midi_mapping_s 39 | { 40 | struct adc_to_midi_s *adcToMidi; 41 | int adcToMidiCount; 42 | void(*callback)(uint8_t ch, uint8_t cc, uint8_t value); 43 | }; 44 | 45 | /* 46 | * the following structure is for directly linking an ADC input to 47 | * a control change with a specific channel number and control number 48 | * 49 | * adcToMidiLookUp shall be defined as an array with the size of ADC_TO_MIDI_LOOKUP_SIZE 50 | * 51 | * the entries are directly mapped to the ADC input 52 | * 53 | * example: 54 | * in case ADC_TO_MIDI_LOOKUP_SIZE = 4 you can define 4 entries. 55 | * struct adc_to_midi_s adcToMidiLookUp[ADC_TO_MIDI_LOOKUP_SIZE] = 56 | * { 57 | * {0, 0x10}, 58 | * {0, 0x11}, 59 | * {0, 0x12}, 60 | * {1, 0x13}, 61 | * }; 62 | * 63 | * The ADC input 0 will be mapped to channel 0, control change number 0x10 (16). 64 | * The connected function should be defined in the MIDI map finally to get an effect. 65 | * 66 | * ADC input 1 will be mapped to channel 0, control change number 0x11 (17) 67 | * ADC input 2 will be mapped to channel 0, control change number 0x12 (18) 68 | * ADC input 3 will be mapped to channel 1, control change number 0x13 (19) 69 | * 70 | * Finally there is no direct linking from ADC to the synthesizer. It creates only the control change messages. 71 | */ 72 | extern struct adc_to_midi_s adcToMidiLookUp[]; /* definition in z_config.ino */ 73 | extern struct adc_to_midi_mapping_s adcToMidiMapping; 74 | 75 | uint8_t lastSendVal[ADC_TO_MIDI_LOOKUP_SIZE]; /* define ADC_TO_MIDI_LOOKUP_SIZE in top level file */ 76 | #define ADC_INVERT 77 | #define ADC_THRESHOLD (1.0f/200.0f) 78 | #ifdef ADC_MCP_CTRL_ENABLED 79 | #define ADC_OVERSAMPLING 16 80 | #else 81 | #endif 82 | 83 | //#define ADC_DYNAMIC_RANGE 84 | //#define ADC_DEBUG_CHANNEL0_DATA 85 | 86 | static float adcChannelValue[ADC_INPUTS]; 87 | 88 | void AdcMul_Init(void) 89 | { 90 | for (int i = 0; i < ADC_INPUTS; i++) 91 | { 92 | adcChannelValue[i] = 0.5f; 93 | } 94 | 95 | memset(lastSendVal, 0xFF, sizeof(lastSendVal)); 96 | 97 | analogReadResolution(10); 98 | analogSetAttenuation(ADC_11db); 99 | #if 0 100 | analogSetCycles(1); 101 | #endif 102 | analogSetClockDiv(1); 103 | 104 | adcAttachPin(ADC_MUL_SIG_PIN); 105 | 106 | #ifndef ADC_MCP_CTRL_ENABLED 107 | pinMode(ADC_MUL_S0_PIN, OUTPUT); 108 | #if ADC_INPUTS > 2 109 | pinMode(ADC_MUL_S1_PIN, OUTPUT); 110 | #endif 111 | #if ADC_INPUTS > 4 112 | pinMode(ADC_MUL_S2_PIN, OUTPUT); 113 | #endif 114 | #if ADC_INPUTS > 8 115 | pinMode(ADC_MUL_S3_PIN, OUTPUT); 116 | #endif 117 | #endif 118 | } 119 | 120 | void AdcMul_Process(void) 121 | { 122 | static float readAccu = 0; 123 | static float adcMin = 0;//4000; 124 | #ifdef ADC_MCP_CTRL_ENABLED 125 | static float adcMax = 16350; 126 | #else 127 | static float adcMax = 420453;//410000; 128 | #endif 129 | 130 | #ifdef ADC_MCP_CTRL_ENABLED 131 | MCP23_Select(SPI_SEL_MCP23S17); 132 | #endif 133 | for (int j = 0; j < ADC_INPUTS; j++) 134 | { 135 | #ifdef ADC_MCP_CTRL_ENABLED 136 | MCP23_SelAdc(j); 137 | #else 138 | digitalWrite(ADC_MUL_S0_PIN, ((j & (1 << 0)) > 0) ? HIGH : LOW); 139 | #if ADC_INPUTS > 2 140 | digitalWrite(ADC_MUL_S1_PIN, ((j & (1 << 1)) > 0) ? HIGH : LOW); 141 | #endif 142 | #if ADC_INPUTS > 4 143 | digitalWrite(ADC_MUL_S2_PIN, ((j & (1 << 2)) > 0) ? HIGH : LOW); 144 | #endif 145 | #if ADC_INPUTS > 8 146 | digitalWrite(ADC_MUL_S3_PIN, ((j & (1 << 3)) > 0) ? HIGH : LOW); 147 | #endif 148 | 149 | /* give some time for transition */ 150 | delay(1); 151 | #endif 152 | 153 | readAccu = 0; 154 | #if 0 155 | adcStart(ADC_MUL_SIG_PIN); 156 | for (int i = 0 ; i < ADC_OVERSAMPLING; i++) 157 | { 158 | 159 | if (adcBusy(ADC_MUL_SIG_PIN) == false) 160 | { 161 | readAccu += adcEnd(ADC_MUL_SIG_PIN); 162 | adcStart(ADC_MUL_SIG_PIN); 163 | } 164 | } 165 | adcEnd(ADC_MUL_SIG_PIN); 166 | #else 167 | for (int i = 0 ; i < ADC_OVERSAMPLING; i++) 168 | { 169 | readAccu += analogRead(ADC_MUL_SIG_PIN); 170 | } 171 | #endif 172 | 173 | #ifdef ADC_DYNAMIC_RANGE 174 | if (readAccu < adcMin - 0.5f) 175 | { 176 | adcMin = readAccu + 0.5f; 177 | Serial.printf("adcMin: %0.3f\n", readAccu); 178 | } 179 | 180 | if (readAccu > adcMax + 0.5f) 181 | { 182 | adcMax = readAccu - 0.5f; 183 | Serial.printf("adcMax: %0.3f\n", readAccu); 184 | } 185 | #endif 186 | 187 | if (adcMax > adcMin) 188 | { 189 | /* 190 | * normalize value to range from 0.0 to 1.0 191 | */ 192 | float readValF = (readAccu - adcMin) / ((adcMax - adcMin)); 193 | readValF *= (1 + 2.0f * ADC_THRESHOLD); /* extend to go over thresholds */ 194 | readValF -= ADC_THRESHOLD; /* shift down to allow go under low threshold */ 195 | 196 | bool midiMsg = false; 197 | 198 | /* check if value has been changed */ 199 | if (readValF > adcChannelValue[j] + ADC_THRESHOLD) 200 | { 201 | adcChannelValue[j] = (readValF - ADC_THRESHOLD); 202 | midiMsg = true; 203 | } 204 | if (readValF < adcChannelValue[j] - ADC_THRESHOLD) 205 | { 206 | adcChannelValue[j] = (readValF + ADC_THRESHOLD); 207 | midiMsg = true; 208 | } 209 | 210 | /* keep value in range from 0 to 1 */ 211 | if (adcChannelValue[j] < 0.0f) 212 | { 213 | adcChannelValue[j] = 0.0f; 214 | } 215 | if (adcChannelValue[j] > 1.0f) 216 | { 217 | adcChannelValue[j] = 1.0f; 218 | } 219 | 220 | /* MIDI adoption */ 221 | if (midiMsg) 222 | { 223 | uint32_t midiValueU7 = (adcChannelValue[j] * 127.999); 224 | if (j < ADC_TO_MIDI_LOOKUP_SIZE) 225 | { 226 | #ifdef ADC_INVERT 227 | uint8_t idx = (ADC_INPUTS - 1) - j; 228 | #else 229 | uint8_t idx = j; 230 | #endif 231 | if (lastSendVal[idx] != midiValueU7) 232 | { 233 | if (adcToMidiMapping.callback != NULL) 234 | { 235 | adcToMidiMapping.callback(adcToMidiLookUp[idx].ch, adcToMidiLookUp[idx].cc, midiValueU7); 236 | } 237 | // Midi_ControlChange(adcToMidiLookUp[idx].ch, adcToMidiLookUp[idx].cc, midiValueU7); 238 | lastSendVal[idx] = midiValueU7; 239 | } 240 | } 241 | #ifdef ADC_DEBUG_CHANNEL0_DATA 242 | if (j == 0) 243 | { 244 | float adcValFrac = (adcChannelValue[j] * 127.999) - midiValueU7; 245 | Serial.printf("adcChannelValue[j]: %f -> %0.3f -> %0.3f-> %d, %0.3f\n", readAccu, readValF, adcChannelValue[j], midiValueU7, adcValFrac); 246 | } 247 | #endif 248 | } 249 | } 250 | } 251 | } 252 | 253 | float *AdcMul_GetValues(void) 254 | { 255 | return adcChannelValue; 256 | } 257 | 258 | #endif /* ADC_TO_MIDI_ENABLED */ 259 | 260 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Marcel Licence 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Dieses Programm ist Freie Software: Sie können es unter den Bedingungen 18 | * der GNU General Public License, wie von der Free Software Foundation, 19 | * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren 20 | * veröffentlichten Version, weiter verteilen und/oder modifizieren. 21 | * 22 | * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch 23 | * OHNE JEDE GEWÄHR,; sogar ohne die implizite 24 | * Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. 25 | * Siehe die GNU General Public License für weitere Einzelheiten. 26 | * 27 | * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem 28 | * Programm erhalten haben. Wenn nicht, siehe . 29 | */ 30 | 31 | /** 32 | * @file config.h 33 | * @author Marcel Licence 34 | * @date 12.05.2021 35 | * 36 | * @brief This file contains the project configuration 37 | * 38 | * All definitions are visible in the entire project 39 | * 40 | * Put all your project settings here (defines, numbers, etc.) 41 | * configurations which are requiring knowledge of types etc. 42 | * shall be placed in z_config.ino (will be included at the end) 43 | */ 44 | 45 | 46 | #ifndef CONFIG_H_ 47 | #define CONFIG_H_ 48 | 49 | 50 | #ifdef __CDT_PARSER__ 51 | #include 52 | #endif 53 | 54 | 55 | //#define NOTE_ON_AFTER_SETUP /* used to get a test tone without MIDI input. Can be deactivated */ 56 | 57 | 58 | #define SERIAL_BAUDRATE 115200 59 | 60 | //#define OUTPUT_SAW_TEST /*!< enable this to test the codec only. Should result in a saw wav with length of SAMPLE_BFFER_SIZE samples */ 61 | 62 | #ifdef ESP32 63 | /* 64 | * you can select one of the pre-defined boards 65 | * look into ML_SynthTools in ml_boards.h for more information 66 | * @see https://github.com/marcel-licence/ML_SynthTools 67 | */ 68 | //#define BOARD_ML_V1 /* activate this when using the ML PCB V1 */ 69 | //#define BOARD_ESP32_AUDIO_KIT_AC101 /* activate this when using the ESP32 Audio Kit v2.2 with the AC101 codec */ 70 | //#define BOARD_ESP32_AUDIO_KIT_ES8388 /* activate this when using the ESP32 Audio Kit v2.2 with the ES8388 codec */ 71 | #define BOARD_ESP32_DOIT /* activate this when using the DOIT ESP32 DEVKIT V1 board */ 72 | 73 | /* can be used to pass line in through audio processing to output */ 74 | //#define AUDIO_PASS_THROUGH 75 | 76 | /* this changes latency but also speed of processing */ 77 | #define SAMPLE_BUFFER_SIZE 48 78 | 79 | /* this will force using const velocity for all notes, remove this to get dynamic velocity */ 80 | #define MIDI_USE_CONST_VELOCITY 81 | 82 | /* this variable defines the max length of the delay and also the memory consumption */ 83 | #define MAX_DELAY (SAMPLE_RATE/2) /* 1/2s -> @ 44100 samples */ 84 | 85 | //#define PRESSURE_SENSOR_ENABLED 86 | 87 | /* you can receive MIDI messages via serial-USB connection */ 88 | /* 89 | * you could use for example https://projectgus.github.io/hairless-midiserial/ 90 | * to connect your MIDI device via computer to the serial port 91 | */ 92 | #define MIDI_RECV_FROM_SERIAL 93 | 94 | /* MIDI_VIA_USB_ENABLED activates MIDI via USB (please look into usbMidiHost.ino for more information) */ 95 | //#define MIDI_VIA_USB_ENABLED 96 | 97 | /* use this to display a scope on the oled display */ 98 | //#define OLED_OSC_DISP_ENABLED 99 | 100 | /* 101 | * keep in mind that activation of adc will also change your controls on startup! 102 | */ 103 | //#define ADC_TO_MIDI_ENABLED /* this will enable the adc module */ 104 | #define ADC_TO_MIDI_LOOKUP_SIZE 8 /* should match ADC_INPUTS */ 105 | 106 | //#define ARP_MODULE_ENABLED /* allow using arp module */ 107 | //#define MIDI_SYNC_MASTER /* turn this off to use external midi clock signal */ 108 | //#define MIDI_CTRL_ENABLED /* used for virtual split point */ 109 | 110 | 111 | //#define MIDI_STREAM_PLAYER_ENABLED /* activate this to use the midi stream playback module */ 112 | 113 | 114 | /* 115 | * include the board configuration 116 | * there you will find the most hardware depending pin settings 117 | */ 118 | #include /* requires library ML_SynthTools from https://github.com/marcel-licence/ML_SynthTools */ 119 | 120 | #ifdef BOARD_ML_V1 121 | #elif (defined BOARD_ESP32_AUDIO_KIT_AC101) 122 | #elif (defined BOARD_ESP32_AUDIO_KIT_ES8388) 123 | #elif (defined BOARD_ESP32_DOIT) 124 | 125 | #define MIDI_PORT2_ACTIVE 126 | #define MIDI_RX2_PIN RXD2 /* U2RRXD */ 127 | #define MIDI_TX2_PIN TXD2 128 | 129 | #else 130 | /* there is room left for other configurations */ 131 | 132 | /* 133 | * DIN MIDI Pinout 134 | */ 135 | #define MIDI_PORT2_ACTIVE 136 | #define MIDI_RX2_PIN 16 /* U2RRXD */ 137 | #define MIDI_TX2_PIN 17 138 | 139 | #endif 140 | 141 | /* 142 | * You can modify the sample rate as you want 143 | */ 144 | #ifdef ESP32_AUDIO_KIT 145 | #define SAMPLE_RATE 44100 146 | #define SAMPLE_SIZE_16BIT 147 | #else 148 | #define SAMPLE_RATE 48000 149 | #define SAMPLE_SIZE_16BIT /* 32 bit seems not to work at the moment */ 150 | #endif 151 | 152 | //#define BLE_MIDI 153 | //#define BLE_MIDI_HOST "MIDI HOST" 154 | 155 | #endif /* ESP32 */ 156 | 157 | 158 | /* 159 | * Configuration for 160 | * Board: "Rapsberry Pi Pico" 161 | * 162 | * BCK: 26 163 | * DIN: 28 164 | * LCK: 27 (always BCK + 1) 165 | * 166 | * MIDI_RX: 12 (GP9) 167 | * 168 | * Pinout @see https://www.raspberrypi-spy.co.uk/2021/01/pi-pico-pinout-and-power-pins/#prettyPhoto 169 | */ 170 | #ifdef ARDUINO_RASPBERRY_PI_PICO 171 | 172 | #define LED_PIN LED_BUILTIN 173 | #define SAMPLE_BUFFER_SIZE 48 174 | #define SAMPLE_RATE 44100 175 | 176 | #define MIDI_PORT2_ACTIVE 177 | 178 | #endif /* ARDUINO_RASPBERRY_PI_PICO */ 179 | 180 | 181 | #endif /* CONFIG_H_ */ 182 | 183 | -------------------------------------------------------------------------------- /data/song.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcel-licence/esp32_basic_synth/5452e5bc64fa0854b944ef32c7f220f84652d68b/data/song.mid -------------------------------------------------------------------------------- /doc/board_info.md: -------------------------------------------------------------------------------- 1 |

Board Build Variants

2 | 3 | Below you will find a list of build which can be configured and should compile without any problems 4 | 5 |
6 | Core: ESP32 Arduino
7 | Version: 1.0.6
8 | Board: ESP32 Dev Module
9 |
10 | Program storage space: 694394 bytes
11 | Dynamic memory: 49476 bytes
12 |
13 | PSRAM: Disabled
14 | Partition Scheme: Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
15 | CPU Frequency: 240MHz (WiFi/BT)
16 | Flash Mode: QIO
17 | Flash Frequency: 80MHz
18 | Flash Size: 4MB (32Mb)
19 | Upload Speed: 921600
20 | Core Debug Level: None
21 |
22 | Used libraries:
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 |
NameVersionUrlGitCore library
ML SynthTools1.3.1https://github.com/marcel-licence/ML_SynthToolshttps://github.com/marcel-licence/ML_SynthTools.gitFalse
SPI1.0http://arduino.cc/en/Reference/SPITrue
Wire1.0.1http://arduino.cc/en/Reference/WireTrue
WiFi1.0True
FS1.0True
LittleFS_esp321.0.6https://github.com/lorol/LITTLEFShttps://github.com/lorol/LITTLEFSFalse
SD_MMC1.0True

81 | Core: ESP32 Arduino
82 | Version: 2.0.7
83 | Board: ESP32 Dev Module
84 |
85 | Program storage space: 760313 bytes
86 | Dynamic memory: 54052 bytes
87 |
88 | JTAG Adapter: Disabled
89 | PSRAM: Disabled
90 | Partition Scheme: Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
91 | CPU Frequency: 240MHz (WiFi/BT)
92 | Flash Mode: QIO
93 | Flash Frequency: 80MHz
94 | Flash Size: 4MB (32Mb)
95 | Upload Speed: 921600
96 | Arduino Runs On: Core 1
97 | Events Run On: Core 1
98 | Core Debug Level: None
99 | Erase All Flash Before Sketch Upload: Disabled
100 |
101 | Used libraries:
102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 |
NameVersionUrlGitCore library
ML SynthTools1.3.1https://github.com/marcel-licence/ML_SynthToolshttps://github.com/marcel-licence/ML_SynthTools.gitFalse
SPI2.0.0http://arduino.cc/en/Reference/SPIhttps://github.com/espressif/arduino-esp32.gitTrue
Wire2.0.0http://arduino.cc/en/Reference/Wirehttps://github.com/espressif/arduino-esp32.gitTrue
WiFi2.0.0https://github.com/espressif/arduino-esp32.gitTrue
FS2.0.0https://github.com/espressif/arduino-esp32.gitTrue
LittleFS2.0.0https://github.com/espressif/arduino-esp32.gitTrue
SD_MMC2.0.0https://github.com/espressif/arduino-esp32.gitTrue
-------------------------------------------------------------------------------- /doc/schematic_v01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcel-licence/esp32_basic_synth/5452e5bc64fa0854b944ef32c7f220f84652d68b/doc/schematic_v01.png -------------------------------------------------------------------------------- /easySynth.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Marcel Licence 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Dieses Programm ist Freie Software: Sie können es unter den Bedingungen 18 | * der GNU General Public License, wie von der Free Software Foundation, 19 | * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren 20 | * veröffentlichten Version, weiter verteilen und/oder modifizieren. 21 | * 22 | * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch 23 | * OHNE JEDE GEWÄHR,; sogar ohne die implizite 24 | * Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. 25 | * Siehe die GNU General Public License für weitere Einzelheiten. 26 | * 27 | * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem 28 | * Programm erhalten haben. Wenn nicht, siehe . 29 | */ 30 | 31 | /* 32 | * Implementation of a simple polyphonic synthesizer module 33 | * - it supports different waveforms 34 | * - it supports polyphony 35 | * - implemented ADSR for velocity and filter 36 | * - allows usage of multiple oscillators per voice 37 | * 38 | */ 39 | 40 | 41 | #ifdef __CDT_PARSER__ 42 | #include "cdt.h" 43 | #endif 44 | 45 | 46 | /* requires the ML_SynthTools library: https://github.com/marcel-licence/ML_SynthTools */ 47 | #include 48 | #include 49 | 50 | /* 51 | * activate the following macro to enable unison mode 52 | * by default the saw wave form will be used 53 | * the waveform controllers are remapped to 54 | * - waveform1 -> detune 55 | * - waveform2 -> oscillator count 56 | */ 57 | //#define USE_UNISON 58 | 59 | #define CHANNEL_MAX 16 60 | 61 | /* 62 | * Param indices for Synth_SetParam function 63 | */ 64 | #define SYNTH_PARAM_VEL_ENV_ATTACK 0 65 | #define SYNTH_PARAM_VEL_ENV_DECAY 1 66 | #define SYNTH_PARAM_VEL_ENV_SUSTAIN 2 67 | #define SYNTH_PARAM_VEL_ENV_RELEASE 3 68 | #define SYNTH_PARAM_FIL_ENV_ATTACK 4 69 | #define SYNTH_PARAM_FIL_ENV_DECAY 5 70 | #define SYNTH_PARAM_FIL_ENV_SUSTAIN 6 71 | #define SYNTH_PARAM_FIL_ENV_RELEASE 7 72 | #ifdef USE_UNISON 73 | #define SYNTH_PARAM_DETUNE_1 8 74 | #define SYNTH_PARAM_UNISON_2 9 75 | #else 76 | #define SYNTH_PARAM_WAVEFORM_1 8 77 | #define SYNTH_PARAM_WAVEFORM_2 9 78 | #endif 79 | #define SYNTH_PARAM_MAIN_FILT_CUTOFF 10 80 | #define SYNTH_PARAM_MAIN_FILT_RESO 11 81 | #define SYNTH_PARAM_VOICE_FILT_RESO 12 82 | #define SYNTH_PARAM_VOICE_NOISE_LEVEL 13 83 | 84 | #define SYNTH_PARAM_VOICE_PORT_TIME 14 85 | 86 | /* 87 | * Following defines can be changed for different puprposes 88 | */ 89 | #ifdef USE_UNISON 90 | /* use another setting, because unison supports more than 2 osc per voice */ 91 | #define MAX_DETUNE 12 /* 1 + 11 additional tones */ 92 | #define MAX_POLY_OSC 36 /* osc polyphony, always active reduces single voices max poly */ 93 | #define MAX_POLY_VOICE 3 /* max single voices, can use multiple osc */ 94 | #else 95 | #define MAX_POLY_OSC 22 /* osc polyphony, always active reduces single voices max poly */ 96 | #define MAX_POLY_VOICE 11 /* max single voices, can use multiple osc */ 97 | #endif 98 | 99 | 100 | #define MIDI_NOTE_CNT 128 101 | static uint32_t midi_note_to_add[MIDI_NOTE_CNT]; /* lookup to playback waveforms with correct frequency */ 102 | 103 | #ifdef USE_UNISON 104 | uint32_t midi_note_to_add50c[MIDI_NOTE_CNT]; /* lookup for detuning */ 105 | #endif 106 | 107 | /* 108 | * set the correct count of available waveforms 109 | */ 110 | #define WAVEFORM_TYPE_COUNT 7 111 | 112 | /* 113 | * add here your waveforms 114 | */ 115 | #if 0 116 | float *sine = NULL; 117 | #else 118 | float static_sine[WAVEFORM_CNT]; 119 | float *sine = static_sine; 120 | #endif 121 | float *saw = NULL; 122 | float *square = NULL; 123 | float *pulse = NULL; 124 | float *tri = NULL; 125 | float *crappy_noise = NULL; 126 | float *silence = NULL; 127 | 128 | /* 129 | * do not forget to enter the waveform pointer addresses here 130 | */ 131 | float *waveFormLookUp[WAVEFORM_TYPE_COUNT]; 132 | 133 | struct adsrT 134 | { 135 | float a; 136 | float d; 137 | float s; 138 | float r; 139 | }; 140 | 141 | typedef enum 142 | { 143 | attack, decay, sustain, release 144 | } adsr_phaseT; 145 | 146 | /* this prototype is required .. others not - i still do not know what magic arduino is doing */ 147 | inline bool ADSR_Process(const struct adsrT *ctrl, float *ctrlSig, adsr_phaseT *phase); 148 | 149 | 150 | static struct filterCoeffT filterGlobalC; 151 | static struct filterProcT mainFilterL, mainFilterR; 152 | 153 | 154 | #define NOTE_STACK_MAX 8 155 | 156 | 157 | struct channelSetting_s 158 | { 159 | #ifdef USE_UNISON 160 | float detune; /* detune parameter */ 161 | uint8_t unison; /* additional osc per voice count */ 162 | float *selectedWaveForm; 163 | float *selectedWaveForm2; 164 | #else 165 | float *selectedWaveForm; 166 | float *selectedWaveForm2; 167 | #endif 168 | 169 | float soundFiltReso; 170 | float soundNoiseLevel; 171 | 172 | struct adsrT adsr_vol; 173 | struct adsrT adsr_fil; 174 | 175 | /* modulation */ 176 | float modulationDepth; 177 | float modulationSpeed; 178 | float modulationPitch; 179 | 180 | /* pitchbend */ 181 | float pitchBendValue; 182 | float pitchMultiplier; 183 | 184 | /* mono mode variables */ 185 | bool mono; 186 | 187 | float portAdd; 188 | float port; 189 | float noteA; 190 | float noteB; 191 | 192 | uint32_t noteCnt; 193 | uint32_t noteStack[NOTE_STACK_MAX]; 194 | }; 195 | 196 | static struct channelSetting_s chCfg[CHANNEL_MAX]; 197 | static struct channelSetting_s *curChCfg = &chCfg[1]; 198 | 199 | struct oscillatorT 200 | { 201 | float **waveForm; 202 | float *dest; 203 | uint32_t samplePos; 204 | uint32_t addVal; 205 | float pan_l; 206 | float pan_r; 207 | struct channelSetting_s *cfg; 208 | }; 209 | 210 | float voiceSink[2]; 211 | struct oscillatorT oscPlayer[MAX_POLY_OSC]; 212 | 213 | static uint32_t osc_act = 0; 214 | 215 | struct notePlayerT 216 | { 217 | float lastSample[2]; 218 | 219 | float velocity; 220 | bool active; 221 | adsr_phaseT phase; 222 | 223 | uint8_t midiCh; 224 | uint8_t midiNote; 225 | 226 | float control_sign; 227 | float out_level; 228 | 229 | struct filterCoeffT filterC; 230 | struct filterProcT filterL; 231 | struct filterProcT filterR; 232 | float f_control_sign; 233 | float f_control_sign_slow; 234 | adsr_phaseT f_phase; 235 | 236 | struct channelSetting_s *cfg; 237 | }; 238 | 239 | 240 | struct notePlayerT voicePlayer[MAX_POLY_VOICE]; 241 | 242 | uint32_t voc_act = 0; 243 | 244 | 245 | static float filtCutoff = 1.0f; 246 | static float filtReso = 0.5f; 247 | 248 | 249 | void Synth_Init() 250 | { 251 | #ifdef ESP32 252 | randomSeed(34547379); 253 | #endif 254 | 255 | /* 256 | * we do not check if malloc was successful 257 | * if there is not enough memory left the application will crash 258 | */ 259 | #if 0 260 | sine = (float *)malloc(sizeof(float) * WAVEFORM_CNT); 261 | #endif 262 | saw = (float *)malloc(sizeof(float) * WAVEFORM_CNT); 263 | square = (float *)malloc(sizeof(float) * WAVEFORM_CNT); 264 | pulse = (float *)malloc(sizeof(float) * WAVEFORM_CNT); 265 | tri = (float *)malloc(sizeof(float) * WAVEFORM_CNT); 266 | crappy_noise = (float *)malloc(sizeof(float) * WAVEFORM_CNT); 267 | silence = (float *)malloc(sizeof(float) * WAVEFORM_CNT); 268 | 269 | 270 | /* 271 | * let us calculate some waveforms 272 | * - using lookup tables can save a lot of processing power later 273 | * - but it does consume memory 274 | */ 275 | for (int i = 0; i < WAVEFORM_CNT; i++) 276 | { 277 | float val = (float)sin(i * 2.0 * PI / WAVEFORM_CNT); 278 | sine[i] = val; 279 | saw[i] = (2.0f * ((float)i) / ((float)WAVEFORM_CNT)) - 1.0f; 280 | square[i] = (i > (WAVEFORM_CNT / 2)) ? 1 : -1; 281 | pulse[i] = (i > (WAVEFORM_CNT / 4)) ? 1.0f / 4.0f : -3.0f / 4.0f; 282 | tri[i] = ((i > (WAVEFORM_CNT / 2)) ? (((4.0f * (float)i) / ((float)WAVEFORM_CNT)) - 1.0f) : (3.0f - ((4.0f * (float)i) / ((float)WAVEFORM_CNT)))) - 2.0f; 283 | crappy_noise[i] = (random(1024) / 512.0f) - 1.0f; 284 | silence[i] = 0; 285 | } 286 | 287 | waveFormLookUp[0] = sine; 288 | waveFormLookUp[1] = saw; 289 | waveFormLookUp[2] = square; 290 | waveFormLookUp[3] = pulse; 291 | waveFormLookUp[4] = tri; 292 | waveFormLookUp[5] = crappy_noise; 293 | waveFormLookUp[6] = silence; 294 | 295 | /* 296 | * initialize all oscillators 297 | */ 298 | for (int i = 0; i < MAX_POLY_OSC; i++) 299 | { 300 | oscillatorT *osc = &oscPlayer[i]; 301 | osc->waveForm = &silence; 302 | osc->dest = voiceSink; 303 | osc->cfg = &chCfg[0]; 304 | } 305 | 306 | /* 307 | * initialize all voices 308 | */ 309 | for (int i = 0; i < MAX_POLY_VOICE; i++) 310 | { 311 | notePlayerT *voice = &voicePlayer[i]; 312 | voice->active = false; 313 | voice->lastSample[0] = 0.0f; 314 | voice->lastSample[1] = 0.0f; 315 | voice->filterL.filterCoeff = &voice->filterC; 316 | voice->filterR.filterCoeff = &voice->filterC; 317 | voice->cfg = &chCfg[0]; 318 | } 319 | 320 | /* 321 | * prepare lookup for constants to drive oscillators 322 | */ 323 | for (int i = 0; i < MIDI_NOTE_CNT; i++) 324 | { 325 | float f = ((pow(2.0f, (float)(i - 69) / 12.0f) * 440.0f)); 326 | uint32_t add = (uint32_t)(f * ((float)(1ULL << 32ULL) / ((float)SAMPLE_RATE))); 327 | midi_note_to_add[i] = add; 328 | #ifdef USE_UNISON 329 | /* filling the table which will be used for detuning */ 330 | float f1 = (pow(2.0f, ((float)(i - 69) + 0.5f) / 12.0f) * 440.0f); 331 | float f2 = (pow(2.0f, ((float)(i - 69) - 0.5f) / 12.0f) * 440.0f); 332 | 333 | midi_note_to_add50c[i] = (uint32_t)((f1 - f2) * ((float)(1ULL << 32ULL) / ((float)SAMPLE_RATE))); 334 | #endif 335 | } 336 | 337 | /* 338 | * assign main filter 339 | */ 340 | mainFilterL.filterCoeff = &filterGlobalC; 341 | mainFilterR.filterCoeff = &filterGlobalC; 342 | 343 | Filter_Proc_Init(&mainFilterL); 344 | Filter_Proc_Init(&mainFilterR); 345 | Filter_Coeff_Init(mainFilterL.filterCoeff); 346 | 347 | Filter_Calculate(filtCutoff, filtReso, &filterGlobalC); 348 | 349 | for (int i = 0; i < CHANNEL_MAX; i++) 350 | { 351 | Synth_ChannelSettingInit(&chCfg[i]); 352 | } 353 | } 354 | 355 | 356 | static void Synth_ChannelSettingInit(struct channelSetting_s *setting) 357 | { 358 | #ifdef USE_UNISON 359 | setting->detune = 0.1; /* detune parameter */ 360 | setting->unison = 0; /* additional osc per voice count */ 361 | setting->selectedWaveForm = saw; 362 | setting->selectedWaveForm2 = saw; 363 | #else 364 | setting->selectedWaveForm = pulse; 365 | setting->selectedWaveForm2 = silence; 366 | #endif 367 | 368 | setting->soundFiltReso = 0.5f; 369 | setting->soundNoiseLevel = 0.0f; 370 | 371 | struct adsrT adsr_vol_def = {1.0f, 0.25f, 1.0f, 0.01f}; 372 | struct adsrT adsr_fil_def = {1.0f, 0.25f, 1.0f, 0.01f}; 373 | 374 | memcpy(&setting->adsr_vol, &adsr_vol_def, sizeof(adsr_vol_def)); 375 | memcpy(&setting->adsr_fil, &adsr_fil_def, sizeof(adsr_vol_def)); 376 | 377 | setting->modulationDepth = 0.0f; 378 | setting->modulationSpeed = 5.0f; 379 | setting->modulationPitch = 1.0f; 380 | 381 | setting->pitchBendValue = 0.0f; 382 | setting->pitchMultiplier = 1.0f; 383 | 384 | setting->mono = false; 385 | setting->portAdd = 0.01f; /*!< speed of portamento */ 386 | setting->port = 1.0f; 387 | setting->noteA = 0; 388 | setting->noteB = 0; 389 | 390 | setting->noteCnt = 0; 391 | /* setting->noteStack[NOTE_STACK_MAX]; can be left uninitialized */ 392 | } 393 | 394 | /* 395 | * very bad and simple implementation of ADSR 396 | * - but it works for the start 397 | */ 398 | inline bool ADSR_Process(const struct adsrT *ctrl, float *ctrlSig, adsr_phaseT *phase) 399 | { 400 | switch (*phase) 401 | { 402 | case attack: 403 | *ctrlSig += ctrl->a; 404 | if (*ctrlSig > 1.0f) 405 | { 406 | *ctrlSig = 1.0f; 407 | *phase = decay; 408 | } 409 | break; 410 | case decay: 411 | *ctrlSig -= ctrl->d; 412 | if (*ctrlSig < ctrl->s) 413 | { 414 | *ctrlSig = ctrl->s; 415 | *phase = sustain; 416 | } 417 | break; 418 | case sustain: 419 | break; 420 | case release: 421 | *ctrlSig -= ctrl->r; 422 | if (*ctrlSig < 0.0f) 423 | { 424 | *ctrlSig = 0.0f; 425 | //voice->active = false; 426 | return false; 427 | } 428 | } 429 | return true; 430 | } 431 | 432 | void Voice_Off(uint32_t i) 433 | { 434 | notePlayerT *voice = &voicePlayer[i]; 435 | for (int f = 0; f < MAX_POLY_OSC; f++) 436 | { 437 | oscillatorT *osc = &oscPlayer[f]; 438 | if (osc->dest == voice->lastSample) 439 | { 440 | osc->dest = voiceSink; 441 | osc_act -= 1; 442 | } 443 | } 444 | voc_act -= 1; 445 | } 446 | 447 | inline 448 | float SineNorm(float alpha_div2pi) 449 | { 450 | uint32_t index = ((uint32_t)(alpha_div2pi * ((float)WAVEFORM_CNT))) % WAVEFORM_CNT; 451 | return sine[index]; 452 | } 453 | 454 | inline 455 | float GetModulation(uint8_t ch) 456 | { 457 | float modSpeed = chCfg[ch].modulationSpeed; 458 | return chCfg[ch].modulationDepth * chCfg[ch].modulationPitch * (SineNorm((modSpeed * ((float)millis()) / 1000.0f))); 459 | } 460 | 461 | static uint32_t count = 0; 462 | 463 | //[[gnu::noinline, gnu::optimize ("fast-math")]] 464 | inline void Synth_Process(float *left, float *right, uint32_t len) 465 | { 466 | /* 467 | * update pitch bending / modulation 468 | */ 469 | { 470 | 471 | for (int i = 0; i < CHANNEL_MAX; i++) 472 | { 473 | float modulation = GetModulation(i); 474 | 475 | chCfg[i].port += chCfg[i].portAdd; /* active portamento */ 476 | chCfg[i].port = chCfg[i].port > 1.0f ? 1.0f : chCfg[i].port; /* limit value to max of 1.0f */ 477 | 478 | float portVal = (((float)(chCfg[i].noteA)) * (1.0f - chCfg[i].port) + ((float)(chCfg[i].noteB)) * chCfg[i].port); 479 | 480 | float pitchVar = chCfg[i].pitchBendValue + modulation + portVal; 481 | #if 0 482 | static float lastPitchVar = 0; 483 | #endif 484 | chCfg[i].pitchMultiplier = pow(2.0f, pitchVar / 12.0f); 485 | } 486 | } 487 | 488 | for (uint32_t n = 0; n < len; n++) 489 | { 490 | 491 | /* gerenate a noise signal */ 492 | float noise_signal = ((random(1024) / 512.0f) - 1.0f); 493 | 494 | /* counter required to optimize processing */ 495 | count += 1; 496 | 497 | /* 498 | * destination for unused oscillators 499 | */ 500 | voiceSink[0] = 0; 501 | voiceSink[1] = 0; 502 | 503 | /* 504 | * oscillator processing -> mix to voice 505 | */ 506 | for (int i = 0; i < MAX_POLY_OSC; i++) 507 | { 508 | oscillatorT *osc = &oscPlayer[i]; 509 | { 510 | osc->samplePos += (uint32_t)(osc->cfg->pitchMultiplier * ((float)osc->addVal)); 511 | float sig = (*osc->waveForm)[WAVEFORM_I(osc->samplePos)]; 512 | osc->dest[0] += osc->pan_l * sig; 513 | osc->dest[1] += osc->pan_r * sig; 514 | } 515 | } 516 | 517 | /* 518 | * voice processing 519 | */ 520 | for (int i = 0; i < MAX_POLY_VOICE; i++) /* one loop is faster than two loops */ 521 | { 522 | notePlayerT *voice = &voicePlayer[i]; 523 | if (voice->active) 524 | { 525 | if (n % 4 == 0) 526 | { 527 | voice->active = ADSR_Process(&voice->cfg->adsr_vol, &voice->control_sign, &voice->phase); 528 | if (voice->active == false) 529 | { 530 | Voice_Off(i); 531 | } 532 | /* 533 | * make is slow to avoid bad things .. or crying ears 534 | */ 535 | (void)ADSR_Process(&voice->cfg->adsr_fil, &voice->f_control_sign, &voice->f_phase); 536 | } 537 | 538 | /* add some noise to the voice */ 539 | voice->lastSample[0] += noise_signal * voice->cfg->soundNoiseLevel; 540 | voice->lastSample[1] += noise_signal * voice->cfg->soundNoiseLevel; 541 | 542 | voice->lastSample[0] *= voice->control_sign * voice->velocity; 543 | voice->lastSample[1] *= voice->control_sign * voice->velocity; 544 | 545 | if (count % 32 == 0) 546 | { 547 | voice->f_control_sign_slow = 0.05 * voice->f_control_sign + 0.95 * voice->f_control_sign_slow; 548 | Filter_Calculate(voice->f_control_sign_slow, voice->cfg->soundFiltReso, &voice->filterC); 549 | } 550 | 551 | Filter_Process(&voice->lastSample[0], &voice->filterL); 552 | Filter_Process(&voice->lastSample[1], &voice->filterR); 553 | 554 | left[n] += voice->lastSample[0]; 555 | right[n] += voice->lastSample[1]; 556 | voice->lastSample[0] = 0.0f; 557 | voice->lastSample[1] = 0.0f; 558 | } 559 | } 560 | } 561 | 562 | /* 563 | * process main filter 564 | */ 565 | Filter_Process_Buffer(left, &mainFilterL, len); 566 | Filter_Process_Buffer(right, &mainFilterR, len); 567 | 568 | /* 569 | * reduce level a bit to avoid distortion 570 | */ 571 | for (int i = 0; i < SAMPLE_BUFFER_SIZE; i++) 572 | { 573 | left[i] *= 0.4f * 0.25f; 574 | right[i] *= 0.4f * 0.25f; 575 | } 576 | 577 | #ifdef LIMITER_ACTIVE 578 | for (int i = 0; i < SAMPLE_BUFFER_SIZE; i++) 579 | { 580 | left[i] = left[i] > 0.5f ? 0.5 : left[i]; 581 | left[i] = left[i] < -0.5f ? -0.5 : left[i]; 582 | right[i] = right[i] > 0.5f ? 0.5 : right[i]; 583 | right[i] = right[i] < -0.5f ? -0.5 : right[i]; 584 | } 585 | #endif 586 | } 587 | 588 | struct oscillatorT *getFreeOsc() 589 | { 590 | for (int i = 0; i < MAX_POLY_OSC ; i++) 591 | { 592 | if (oscPlayer[i].dest == voiceSink) 593 | { 594 | return &oscPlayer[i]; 595 | } 596 | } 597 | return NULL; 598 | } 599 | 600 | static struct notePlayerT *getFreeVoice(void) 601 | { 602 | for (int i = 0; i < MAX_POLY_VOICE ; i++) 603 | { 604 | if (voicePlayer[i].active == false) 605 | { 606 | return &voicePlayer[i]; 607 | } 608 | } 609 | return NULL; 610 | } 611 | 612 | inline void Synth_NoteOn(uint8_t ch, uint8_t note, float vel) 613 | { 614 | struct notePlayerT *voice = getFreeVoice(); 615 | struct oscillatorT *osc = getFreeOsc(); 616 | 617 | /* put note onto stack */ 618 | if (chCfg[ch].mono) 619 | { 620 | if (chCfg[ch].noteCnt < (NOTE_STACK_MAX - 1)) 621 | { 622 | chCfg[ch].noteStack[chCfg[ch].noteCnt] = note; 623 | chCfg[ch].noteCnt++; 624 | //Status_ValueChangedIntArr("noteCnt", chCfg[ch].noteCnt, ch); 625 | } 626 | 627 | if (chCfg[ch].noteCnt > 1) 628 | { 629 | for (int i = 0; i < MAX_POLY_VOICE ; i++) 630 | { 631 | if ((voicePlayer[i].active) && (voicePlayer[i].midiCh == ch)) 632 | { 633 | float diff = note - voicePlayer[i].midiNote; 634 | 635 | voicePlayer[i].cfg->noteA = voicePlayer[i].cfg->port * ((float)voicePlayer[i].cfg->noteB) + (1.0f - voicePlayer[i].cfg->port) * voicePlayer[i].cfg->noteA; 636 | voicePlayer[i].cfg->port = 0.0f; 637 | 638 | voicePlayer[i].cfg->noteB += diff; 639 | voicePlayer[i].midiNote = note; 640 | 641 | return; 642 | } 643 | } 644 | } 645 | } 646 | 647 | /* 648 | * No free voice found, return otherwise crash xD 649 | */ 650 | if ((voice == NULL) || (osc == NULL)) 651 | { 652 | //Serial.printf("voc: %d, osc: %d\n", voc_act, osc_act); 653 | return ; 654 | } 655 | 656 | voice->cfg = &chCfg[ch]; 657 | voice->midiCh = ch; 658 | voice->midiNote = note; 659 | #ifdef MIDI_USE_CONST_VELOCITY 660 | voice->velocity = 1.0f; 661 | #else 662 | voice->velocity = vel; 663 | #endif 664 | voice->lastSample[0] = 0.0f; 665 | voice->lastSample[1] = 0.0f; 666 | voice->control_sign = 0.0f; 667 | 668 | /* default values to avoid portamento */ 669 | voice->cfg->port = 1.0f; 670 | voice->cfg->noteB = 0; 671 | 672 | #if 1 673 | voice->f_phase = attack; 674 | if (voice->cfg->adsr_fil.a == 1) 675 | { 676 | voice->f_phase = decay; 677 | } 678 | #else 679 | if (voice->cfg->adsr_fil.a < voice->cfg->adsr_fil.s) 680 | { 681 | voice->cfg->adsr_fil.a = voice->cfg->adsr_fil.s; 682 | } 683 | voice->f_phase = decay; 684 | #endif 685 | voice->f_control_sign = voice->cfg->adsr_fil.a; 686 | voice->f_control_sign_slow = voice->cfg->adsr_fil.a; 687 | voice->active = true; 688 | voice->phase = attack; 689 | 690 | /* update all values to avoid audible artifacts */ 691 | ADSR_Process(&voice->cfg->adsr_vol, &voice->control_sign, &voice->phase); 692 | ADSR_Process(&voice->cfg->adsr_fil, &voice->f_control_sign, &voice->f_phase); 693 | 694 | Filter_Calculate(voice->f_control_sign_slow, voice->cfg->soundFiltReso, &voice->filterC); 695 | 696 | voc_act += 1; 697 | 698 | /* 699 | * add oscillator 700 | */ 701 | #ifdef USE_UNISON 702 | if (voice->cfg->unison > 0) 703 | { 704 | /* 705 | * shift first oscillator down 706 | */ 707 | osc->addVal = midi_note_to_add[note] + ((0 - (voice->cfg->unison * 0.5)) * midi_note_to_add50c[note] * voice->cfg->detune / voice->cfg->unison); 708 | } 709 | else 710 | #endif 711 | { 712 | osc->addVal = midi_note_to_add[note]; 713 | } 714 | osc->samplePos = 0; 715 | osc->waveForm = &chCfg[ch].selectedWaveForm; 716 | osc->dest = voice->lastSample; 717 | osc->pan_l = 1; 718 | osc->pan_r = 1; 719 | 720 | osc->cfg = &chCfg[ch]; 721 | 722 | osc_act += 1; 723 | 724 | #ifdef USE_UNISON 725 | 726 | int8_t pan = 1; 727 | 728 | /* 729 | * attach more oscillators to voice 730 | */ 731 | for (int i = 0; i < voice->cfg->unison; i++) 732 | { 733 | osc = getFreeOsc(); 734 | if (osc == NULL) 735 | { 736 | //Serial.printf("voc: %d, osc: %d\n", voc_act, osc_act); 737 | return ; 738 | } 739 | 740 | osc->addVal = midi_note_to_add[note] + ((i + 1 - (voice->cfg->unison * 0.5)) * midi_note_to_add50c[note] * voice->cfg->detune / voice->cfg->unison); 741 | osc->samplePos = (uint32_t)random(1 << 31); /* otherwise it sounds ... bad!? */ 742 | osc->waveForm = &chCfg[ch].selectedWaveForm2; 743 | osc->dest = voice->lastSample; 744 | 745 | /* 746 | * put last osc in the middle 747 | */ 748 | if ((voice->cfg->unison - 1) == i) 749 | { 750 | osc->pan_l = 1; 751 | osc->pan_r = 1; 752 | } 753 | else if (pan == 1) 754 | { 755 | osc->pan_l = 1; 756 | osc->pan_r = 0.5; 757 | } 758 | else 759 | { 760 | osc->pan_l = 0.5; 761 | osc->pan_r = 1; 762 | } 763 | pan = -pan; /* make a stereo sound by putting the oscillator left/right */ 764 | 765 | osc->cfg = &chCfg[ch]; 766 | 767 | osc_act += 1; 768 | } 769 | #else 770 | osc = getFreeOsc(); 771 | if (osc != NULL) 772 | { 773 | if (note + 12 < 128) 774 | { 775 | osc->addVal = midi_note_to_add[note + 12]; 776 | osc->samplePos = 0; /* we could add some offset maybe */ 777 | osc->waveForm = &chCfg[ch].selectedWaveForm2; 778 | osc->dest = voice->lastSample; 779 | osc->pan_l = 1; 780 | osc->pan_r = 1; 781 | 782 | osc->cfg = &chCfg[ch]; 783 | 784 | osc_act += 1; 785 | } 786 | } 787 | #endif 788 | 789 | /* 790 | * trying to avoid audible suprises 791 | */ 792 | Filter_Reset(&voice->filterL); 793 | Filter_Reset(&voice->filterR); 794 | Filter_Process(&voice->lastSample[0], &voice->filterL); 795 | Filter_Process(&voice->lastSample[0], &voice->filterL); 796 | Filter_Process(&voice->lastSample[0], &voice->filterL); 797 | 798 | Filter_Process(&voice->lastSample[1], &voice->filterR); 799 | Filter_Process(&voice->lastSample[1], &voice->filterR); 800 | Filter_Process(&voice->lastSample[1], &voice->filterR); 801 | } 802 | 803 | inline void Synth_NoteOff(uint8_t ch, uint8_t note) 804 | { 805 | for (uint32_t j = 0; j < chCfg[ch].noteCnt; j++) 806 | { 807 | if (chCfg[ch].noteStack[j] == note) 808 | { 809 | for (int k = j; k < NOTE_STACK_MAX - 1; k++) 810 | { 811 | chCfg[ch].noteStack[k] = chCfg[ch].noteStack[k + 1]; 812 | } 813 | chCfg[ch].noteCnt = (chCfg[ch].noteCnt > 0) ? (chCfg[ch].noteCnt - 1) : 0; 814 | Status_ValueChangedIntArr("noteCnt-", chCfg[ch].noteCnt, ch); 815 | } 816 | } 817 | 818 | for (int i = 0; i < MAX_POLY_VOICE ; i++) 819 | { 820 | if ((voicePlayer[i].active) && (voicePlayer[i].midiNote == note) && (voicePlayer[i].midiCh == ch)) 821 | { 822 | if ((voicePlayer[i].cfg->noteCnt > 0) && (voicePlayer[i].cfg->mono)) 823 | { 824 | uint8_t midiNote = voicePlayer[i].cfg->noteStack[voicePlayer[i].cfg->noteCnt - 1]; 825 | 826 | float diff = midiNote - voicePlayer[i].midiNote; 827 | 828 | voicePlayer[i].cfg->noteA = voicePlayer[i].cfg->port * ((float)voicePlayer[i].cfg->noteB) + (1.0f - voicePlayer[i].cfg->port) * voicePlayer[i].cfg->noteA; 829 | voicePlayer[i].cfg->port = 0.0f; 830 | 831 | voicePlayer[i].cfg->noteB += diff; 832 | voicePlayer[i].midiNote = midiNote; 833 | } 834 | else 835 | { 836 | voicePlayer[i].phase = release; 837 | } 838 | } 839 | } 840 | } 841 | 842 | void Synth_ModulationWheel(uint8_t ch, float value) 843 | { 844 | chCfg[ch].modulationDepth = value; 845 | } 846 | 847 | void Synth_ModulationSpeed(uint8_t ch, float value) 848 | { 849 | chCfg[ch].modulationSpeed = value * 10; 850 | //Status_ValueChangedFloat("ModulationSpeed", modulationSpeed); 851 | } 852 | 853 | void Synth_ModulationPitch(uint8_t ch, float value) 854 | { 855 | chCfg[ch].modulationPitch = value * 5; 856 | //Status_ValueChangedFloat("ModulationDepth", modulationPitch); 857 | } 858 | 859 | void Synth_PitchBend(uint8_t ch, float bend) 860 | { 861 | chCfg[ch].pitchBendValue = bend; 862 | //Serial.printf("pitchBendValue: %0.3f\n", chCfg[ch].pitchBendValue); 863 | } 864 | 865 | void Synth_PortTime(float value) 866 | { 867 | float min = 0.02f; /* 1/(0.02 * 1000) -> 0.05s */ 868 | float max = 0.0002f; /* 1/(0.0002 * 1000) -> 5s */ 869 | 870 | curChCfg->portAdd = (pow(2.0f, value) - 1.0f) * (max - min) + min; 871 | } 872 | 873 | void Synth_SetCurCh(uint8_t ch, float value) 874 | { 875 | if (value > 0) 876 | { 877 | if (ch < 16) 878 | { 879 | curChCfg = &chCfg[ch]; 880 | Status_ValueChangedInt("Current ch", ch); 881 | } 882 | } 883 | } 884 | 885 | void Synth_ToggleMono(uint8_t ch __attribute__((unused)), float value) 886 | { 887 | if (value > 0) 888 | { 889 | curChCfg->mono = !curChCfg->mono; 890 | Status_LogMessage(curChCfg->mono ? "Mono" : "Poly"); 891 | } 892 | } 893 | 894 | void Synth_SetParam(uint8_t slider, float value) 895 | { 896 | switch (slider) 897 | { 898 | case SYNTH_PARAM_VEL_ENV_ATTACK: 899 | if (value == 0) 900 | { 901 | curChCfg->adsr_vol.a = 1.0f; 902 | } 903 | else 904 | { 905 | curChCfg->adsr_vol.a = (0.00005 * pow(5000, 1.0f - value)); 906 | } 907 | Serial.printf("voice volume attack: %0.6f\n", curChCfg->adsr_vol.a); 908 | break; 909 | case SYNTH_PARAM_VEL_ENV_DECAY: 910 | curChCfg->adsr_vol.d = (0.00005 * pow(5000, 1.0f - value)); 911 | Serial.printf("voice volume decay: %0.6f\n", curChCfg->adsr_vol.d); 912 | break; 913 | case SYNTH_PARAM_VEL_ENV_SUSTAIN: 914 | curChCfg->adsr_vol.s = (0.01 * pow(100, value)); 915 | Serial.printf("voice volume sustain: %0.6f\n", curChCfg->adsr_vol.s); 916 | break; 917 | case SYNTH_PARAM_VEL_ENV_RELEASE: 918 | curChCfg->adsr_vol.r = (0.0001 * pow(100, 1.0f - value)); 919 | Serial.printf("voice volume release: %0.6f\n", curChCfg->adsr_vol.r); 920 | break; 921 | 922 | case SYNTH_PARAM_FIL_ENV_ATTACK: 923 | #if 1 924 | if (value == 0) 925 | { 926 | curChCfg->adsr_fil.a = 1.0f; 927 | } 928 | else 929 | { 930 | curChCfg->adsr_fil.a = (0.00005 * pow(5000, 1.0f - value)); 931 | } 932 | #else 933 | curChCfg->adsr_fil.a = value; 934 | #endif 935 | Serial.printf("voice filter attack: %0.6f\n", curChCfg->adsr_fil.a); 936 | break; 937 | case SYNTH_PARAM_FIL_ENV_DECAY: 938 | curChCfg->adsr_fil.d = (0.00005 * pow(5000, 1.0f - value)); 939 | Serial.printf("voice filter decay: %0.6f\n", curChCfg->adsr_fil.d); 940 | break; 941 | case SYNTH_PARAM_FIL_ENV_SUSTAIN: 942 | curChCfg->adsr_fil.s = value; 943 | Serial.printf("voice filter sustain: %0.6f\n", curChCfg->adsr_fil.s); 944 | break; 945 | case SYNTH_PARAM_FIL_ENV_RELEASE: 946 | curChCfg->adsr_fil.r = (0.0001 * pow(100, 1.0f - value)); 947 | Serial.printf("voice filter release: %0.6f\n", curChCfg->adsr_fil.r); 948 | break; 949 | 950 | #ifdef USE_UNISON 951 | case SYNTH_PARAM_DETUNE_1: 952 | curChCfg->detune = value; 953 | Serial.printf("detune: %0.3f cent\n", curChCfg->detune * 50); 954 | break; 955 | case SYNTH_PARAM_UNISON_2: 956 | curChCfg->unison = (uint8_t)(MAX_DETUNE * value); 957 | Serial.printf("unison: 1 + %d\n", curChCfg->unison); 958 | break; 959 | #else 960 | case SYNTH_PARAM_WAVEFORM_1: 961 | { 962 | uint8_t selWaveForm = (value) * (WAVEFORM_TYPE_COUNT); 963 | curChCfg->selectedWaveForm = waveFormLookUp[selWaveForm]; 964 | Serial.printf("selWaveForm: %d\n", selWaveForm); 965 | } 966 | break; 967 | case SYNTH_PARAM_WAVEFORM_2: 968 | { 969 | uint8_t selWaveForm = (value) * (WAVEFORM_TYPE_COUNT); 970 | curChCfg->selectedWaveForm2 = waveFormLookUp[selWaveForm]; 971 | Serial.printf("selWaveForm2: %d\n", selWaveForm); 972 | } 973 | break; 974 | #endif 975 | case SYNTH_PARAM_MAIN_FILT_CUTOFF: 976 | filtCutoff = value; 977 | Serial.printf("main filter cutoff: %0.3f\n", filtCutoff); 978 | Filter_Calculate(filtCutoff, filtReso, &filterGlobalC); 979 | break; 980 | case SYNTH_PARAM_MAIN_FILT_RESO: 981 | filtReso = 0.5f + 10 * value * value * value; /* min q is 0.5 here */ 982 | Serial.printf("main filter reso: %0.3f\n", filtReso); 983 | Filter_Calculate(filtCutoff, filtReso, &filterGlobalC); 984 | break; 985 | 986 | case SYNTH_PARAM_VOICE_FILT_RESO: 987 | curChCfg->soundFiltReso = 0.5f + 10 * value * value * value; /* min q is 0.5 here */ 988 | Serial.printf("voice filter reso: %0.3f\n", curChCfg->soundFiltReso); 989 | break; 990 | 991 | case SYNTH_PARAM_VOICE_NOISE_LEVEL: 992 | curChCfg->soundNoiseLevel = value; 993 | Serial.printf("voice noise level: %0.3f\n", curChCfg->soundNoiseLevel); 994 | break; 995 | 996 | case SYNTH_PARAM_VOICE_PORT_TIME: 997 | curChCfg->portAdd = value * value * value * value; 998 | Serial.printf("voice port time: %0.3f\n", curChCfg->portAdd); 999 | break; 1000 | 1001 | default: 1002 | /* not connected */ 1003 | break; 1004 | } 1005 | } 1006 | 1007 | -------------------------------------------------------------------------------- /esp32_basic_synth.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Marcel Licence 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Dieses Programm ist Freie Software: Sie können es unter den Bedingungen 18 | * der GNU General Public License, wie von der Free Software Foundation, 19 | * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren 20 | * veröffentlichten Version, weiter verteilen und/oder modifizieren. 21 | * 22 | * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch 23 | * OHNE JEDE GEWÄHR,; sogar ohne die implizite 24 | * Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. 25 | * Siehe die GNU General Public License für weitere Einzelheiten. 26 | * 27 | * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem 28 | * Programm erhalten haben. Wenn nicht, siehe . 29 | */ 30 | 31 | /** 32 | * @file esp32_basic_synth.ino 33 | * @author Marcel Licence 34 | * @date 06.03.2021 35 | * 36 | * @brief This is the main project file of the basic synthesizer 37 | * It should be compatible with ESP32 and ESP8266 38 | * 39 | * pinout of ESP32 DevKit found here: 40 | * @see https://circuits4you.com/2018/12/31/esp32-devkit-esp32-wroom-gpio-pinout/ 41 | */ 42 | 43 | 44 | #ifdef __CDT_PARSER__ 45 | #include 46 | #endif 47 | 48 | 49 | #include "config.h" 50 | 51 | /* 52 | * required include files 53 | * add also includes used for other modules 54 | * otherwise arduino generated declaration may cause errors 55 | */ 56 | #include 57 | 58 | #include 59 | #include 60 | #include 61 | 62 | /* requires the ml_Synth library */ 63 | #include 64 | #include 65 | #include 66 | #include 67 | #ifdef OLED_OSC_DISP_ENABLED 68 | #include 69 | #endif 70 | 71 | #include 72 | 73 | #define ML_SYNTH_INLINE_DECLARATION 74 | #include 75 | #undef ML_SYNTH_INLINE_DECLARATION 76 | 77 | 78 | void setup() 79 | { 80 | /* 81 | * this code runs once 82 | */ 83 | delay(500); 84 | 85 | Serial.begin(SERIAL_BAUDRATE); 86 | 87 | Serial.println(); 88 | 89 | Serial.printf("esp32_basic_synth Copyright (c) 2023 Marcel Licence\n"); 90 | Serial.printf("This program comes with ABSOLUTELY NO WARRANTY;\n"); 91 | Serial.printf("This is free software, and you are welcome to redistribute it\n"); 92 | Serial.printf("under certain conditions; \n"); 93 | 94 | Serial.printf("Initialize Synth Module\n"); 95 | Synth_Init(); 96 | 97 | #ifdef BLE_MIDI 98 | Serial.printf("Initialize MIDI over Bluetooth\n"); 99 | BLE_setup(); 100 | #endif 101 | 102 | Serial.printf("Initialize I2S Module\n"); 103 | 104 | #ifdef BLINK_LED_PIN 105 | Blink_Setup(); 106 | #endif 107 | 108 | Audio_Setup(); 109 | 110 | 111 | /* 112 | * Initialize reverb 113 | * The buffer shall be static to ensure that 114 | * the memory will be exclusive available for the reverb module 115 | */ 116 | //static float revBuffer[REV_BUFF_SIZE]; 117 | static float *revBuffer = (float *)malloc(sizeof(float) * REV_BUFF_SIZE); 118 | Reverb_Setup(revBuffer); 119 | 120 | /* 121 | * Prepare a buffer which can be used for the delay 122 | */ 123 | #ifdef MAX_DELAY 124 | static int16_t *delBuffer1 = (int16_t *)malloc(sizeof(int16_t) * MAX_DELAY); 125 | static int16_t *delBuffer2 = (int16_t *)malloc(sizeof(int16_t) * MAX_DELAY); 126 | Delay_Init2(delBuffer1, delBuffer2, MAX_DELAY); 127 | #endif 128 | 129 | /* 130 | * setup midi module / rx port 131 | */ 132 | Midi_Setup(); 133 | 134 | #ifdef ARP_MODULE_ENABLED 135 | Arp_Init(24 * 4); /* slowest tempo one step per bar */ 136 | #endif 137 | 138 | #ifdef ESP32 139 | Serial.printf("ESP.getFreeHeap() %d\n", ESP.getFreeHeap()); 140 | Serial.printf("ESP.getMinFreeHeap() %d\n", ESP.getMinFreeHeap()); 141 | Serial.printf("ESP.getHeapSize() %d\n", ESP.getHeapSize()); 142 | Serial.printf("ESP.getMaxAllocHeap() %d\n", ESP.getMaxAllocHeap()); 143 | 144 | Serial.printf("Total heap: %d\n", ESP.getHeapSize()); 145 | Serial.printf("Free heap: %d\n", ESP.getFreeHeap()); 146 | 147 | /* PSRAM will be fully used by the looper */ 148 | Serial.printf("Total PSRAM: %d\n", ESP.getPsramSize()); 149 | Serial.printf("Free PSRAM: %d\n", ESP.getFreePsram()); 150 | #endif 151 | 152 | Serial.printf("Firmware started successfully\n"); 153 | 154 | #ifdef NOTE_ON_AFTER_SETUP /* activate this line to get a tone on startup to test the DAC */ 155 | Synth_NoteOn(0, 64, 1.0f); 156 | #endif 157 | 158 | #ifdef MIDI_STREAM_PLAYER_ENABLED 159 | MidiStreamPlayer_Init(); 160 | 161 | char midiFile[] = "/song.mid"; 162 | MidiStreamPlayer_PlayMidiFile_fromLittleFS(midiFile, 1); 163 | #endif 164 | 165 | #if (defined ADC_TO_MIDI_ENABLED) || (defined MIDI_VIA_USB_ENABLED) || (defined OLED_OSC_DISP_ENABLED) 166 | #ifdef ESP32 167 | Core0TaskInit(); 168 | #else 169 | #error only supported by ESP32 platform 170 | #endif 171 | #endif 172 | } 173 | 174 | #ifdef ESP32 175 | /* 176 | * Core 0 177 | */ 178 | /* this is used to add a task to core 0 */ 179 | TaskHandle_t Core0TaskHnd; 180 | 181 | inline 182 | void Core0TaskInit() 183 | { 184 | /* we need a second task for the terminal output */ 185 | xTaskCreatePinnedToCore(Core0Task, "CoreTask0", 8000, NULL, 999, &Core0TaskHnd, 0); 186 | } 187 | 188 | inline 189 | void Core0TaskSetup() 190 | { 191 | /* 192 | * init your stuff for core0 here 193 | */ 194 | 195 | #ifdef OLED_OSC_DISP_ENABLED 196 | ScopeOled_Setup(); 197 | #endif 198 | 199 | #ifdef ADC_TO_MIDI_ENABLED 200 | AdcMul_Init(); 201 | #endif 202 | 203 | #ifdef MIDI_VIA_USB_ENABLED 204 | UsbMidi_Setup(); 205 | #endif 206 | } 207 | 208 | #ifdef ADC_TO_MIDI_ENABLED 209 | static uint8_t adc_prescaler = 0; 210 | #endif 211 | 212 | void Core0TaskLoop() 213 | { 214 | /* 215 | * put your loop stuff for core0 here 216 | */ 217 | #ifdef ADC_TO_MIDI_ENABLED 218 | #ifdef MIDI_VIA_USB_ENABLED 219 | adc_prescaler++; 220 | if (adc_prescaler > 15) /* use prescaler when USB is active because it is very time consuming */ 221 | #endif /* MIDI_VIA_USB_ENABLED */ 222 | { 223 | adc_prescaler = 0; 224 | AdcMul_Process(); 225 | } 226 | #endif /* ADC_TO_MIDI_ENABLED */ 227 | #ifdef MIDI_VIA_USB_ENABLED 228 | UsbMidi_Loop(); 229 | #endif 230 | 231 | #ifdef MCP23_MODULE_ENABLED 232 | MCP23_Loop(); 233 | #endif 234 | 235 | #ifdef OLED_OSC_DISP_ENABLED 236 | ScopeOled_Process(); 237 | #endif 238 | } 239 | 240 | void Core0Task(void *parameter) 241 | { 242 | Core0TaskSetup(); 243 | 244 | while (true) 245 | { 246 | Core0TaskLoop(); 247 | 248 | /* this seems necessary to trigger the watchdog */ 249 | delay(1); 250 | yield(); 251 | } 252 | } 253 | #endif /* ESP32 */ 254 | 255 | static uint32_t midiSyncCount = 0; 256 | 257 | void Midi_SyncRecvd() 258 | { 259 | midiSyncCount += 1; 260 | } 261 | 262 | void Synth_RealTimeMsg(uint8_t msg) 263 | { 264 | #ifndef MIDI_SYNC_MASTER 265 | switch (msg) 266 | { 267 | case 0xfa: /* start */ 268 | Arp_Reset(); 269 | break; 270 | case 0xf8: /* Timing Clock */ 271 | Midi_SyncRecvd(); 272 | break; 273 | } 274 | #endif 275 | } 276 | 277 | #ifdef MIDI_SYNC_MASTER 278 | 279 | #define MIDI_PPQ 24 280 | #define SAMPLES_PER_MIN (SAMPLE_RATE*60) 281 | 282 | static float midi_tempo = 120.0f; 283 | 284 | void MidiSyncMasterLoop(void) 285 | { 286 | static float midiDiv = 0; 287 | midiDiv += SAMPLE_BUFFER_SIZE; 288 | if (midiDiv >= (SAMPLES_PER_MIN) / (MIDI_PPQ * midi_tempo)) 289 | { 290 | midiDiv -= (SAMPLES_PER_MIN) / (MIDI_PPQ * midi_tempo); 291 | Midi_SyncRecvd(); 292 | } 293 | } 294 | 295 | void Synth_SetMidiMasterTempo(uint8_t unused, float val) 296 | { 297 | midi_tempo = 60.0f + val * (240.0f - 60.0f); 298 | } 299 | 300 | #endif 301 | 302 | void Synth_SongPosition(uint16_t pos) 303 | { 304 | Serial.printf("Songpos: %d\n", pos); 305 | if (pos == 0) 306 | { 307 | Arp_Reset(); 308 | } 309 | } 310 | 311 | void Synth_SongPosReset(uint8_t unused __attribute__((unused)), float var) 312 | { 313 | if (var > 0) 314 | { 315 | Synth_SongPosition(0); 316 | } 317 | } 318 | 319 | /* 320 | * use this if something should happen every second 321 | * - you can drive a blinking LED for example 322 | */ 323 | inline void Loop_1Hz(void) 324 | { 325 | #ifdef BLINK_LED_PIN 326 | Blink_Process(); 327 | #endif 328 | } 329 | 330 | 331 | /* 332 | * our main loop 333 | * - all is done in a blocking context 334 | * - do not block the loop otherwise you will get problems with your audio 335 | */ 336 | static float fl_sample[SAMPLE_BUFFER_SIZE]; 337 | static float fr_sample[SAMPLE_BUFFER_SIZE]; 338 | 339 | void loop() 340 | { 341 | static uint32_t loop_cnt_1hz; 342 | 343 | loop_cnt_1hz += SAMPLE_BUFFER_SIZE; 344 | if (loop_cnt_1hz >= SAMPLE_RATE) 345 | { 346 | Loop_1Hz(); 347 | loop_cnt_1hz = 0; 348 | } 349 | 350 | /* 351 | * Midi does not required to be checked after every processed sample 352 | * - we divide our operation by 8 353 | */ 354 | Midi_Process(); 355 | 356 | #ifdef MIDI_STREAM_PLAYER_ENABLED 357 | MidiStreamPlayer_Tick(SAMPLE_BUFFER_SIZE); 358 | #endif 359 | 360 | #ifdef MIDI_VIA_USB_ENABLED 361 | UsbMidi_ProcessSync(); 362 | #endif 363 | #ifdef BLE_MIDI 364 | BleMidiProc(); 365 | #endif 366 | 367 | #ifdef MIDI_SYNC_MASTER 368 | MidiSyncMasterLoop(); 369 | #endif 370 | 371 | #ifdef ARP_MODULE_ENABLED 372 | Arp_Process(midiSyncCount); 373 | midiSyncCount = 0; 374 | #endif 375 | 376 | /* zero buffer, otherwise you can pass trough an input signal */ 377 | memset(fl_sample, 0, sizeof(fl_sample)); 378 | memset(fr_sample, 0, sizeof(fr_sample)); 379 | 380 | #ifdef AUDIO_PASS_THROUGH 381 | Audio_Input(left, right); 382 | #endif 383 | 384 | Synth_Process(fl_sample, fr_sample, SAMPLE_BUFFER_SIZE); 385 | 386 | /* 387 | * process delay line 388 | */ 389 | #ifdef MAX_DELAY 390 | Delay_Process_Buff2(fl_sample, fr_sample, SAMPLE_BUFFER_SIZE); 391 | #endif 392 | 393 | /* 394 | * add some mono reverb 395 | */ 396 | Reverb_Process(fl_sample, SAMPLE_BUFFER_SIZE); 397 | 398 | #ifdef ESP32 399 | memcpy(fr_sample, fl_sample, sizeof(fr_sample)); 400 | 401 | /* 402 | * Output the audio 403 | */ 404 | Audio_Output(fl_sample, fr_sample); 405 | #else /* project was made for ESP32 but it might work on other devices too */ 406 | Audio_OutputMono(fl_sample); 407 | #endif 408 | 409 | #ifdef OLED_OSC_DISP_ENABLED 410 | ScopeOled_AddSamples(fl_sample, fr_sample, SAMPLE_BUFFER_SIZE); 411 | #endif 412 | } 413 | 414 | /* 415 | * Callbacks 416 | */ 417 | void MidiCtrl_Cb_NoteOn(uint8_t ch, uint8_t note, float vel) 418 | { 419 | Arp_NoteOn(ch, note, vel); 420 | } 421 | 422 | void MidiCtrl_Cb_NoteOff(uint8_t ch, uint8_t note) 423 | { 424 | Arp_NoteOff(ch, note); 425 | } 426 | 427 | void MidiCtrl_Status_ValueChangedIntArr(const char *descr, int value, int index) 428 | { 429 | Status_ValueChangedIntArr(descr, value, index); 430 | } 431 | 432 | void Arp_Cb_NoteOn(uint8_t ch, uint8_t note, float vel) 433 | { 434 | Synth_NoteOn(ch, note, vel); 435 | } 436 | 437 | void Arp_Cb_NoteOff(uint8_t ch, uint8_t note) 438 | { 439 | Synth_NoteOff(ch, note); 440 | } 441 | 442 | void Arp_Status_ValueChangedInt(const char *msg, int value) 443 | { 444 | Status_ValueChangedInt(msg, value); 445 | } 446 | 447 | void Arp_Status_LogMessage(const char *msg) 448 | { 449 | Status_LogMessage(msg); 450 | } 451 | 452 | void Arp_Status_ValueChangedFloat(const char *msg, float value) 453 | { 454 | Status_ValueChangedFloat(msg, value); 455 | } 456 | 457 | /* not used yet */ 458 | void Arp_Cb_Step(uint8_t step __attribute__((unused))) 459 | { 460 | /* ignore */ 461 | } 462 | 463 | /* 464 | * MIDI via USB Host Module 465 | */ 466 | #ifdef MIDI_VIA_USB_ENABLED 467 | void App_UsbMidiShortMsgReceived(uint8_t *msg) 468 | { 469 | #ifdef MIDI_TX2_PIN 470 | Midi_SendShortMessage(msg); 471 | #endif 472 | Midi_HandleShortMsg(msg, 8); 473 | } 474 | #endif 475 | 476 | /* 477 | * Test functions 478 | */ 479 | #if defined(I2C_SCL) && defined (I2C_SDA) 480 | void ScanI2C(void) 481 | { 482 | Wire.begin(I2C_SDA, I2C_SCL); 483 | 484 | byte error, address; 485 | int nDevices; 486 | 487 | Serial.printf("Scanning...\nSDA: %d\nSCL: %d\n", I2C_SDA, I2C_SCL); 488 | 489 | nDevices = 0; 490 | for (address = 1; address < 127; address++) 491 | { 492 | // The i2c_scanner uses the return value of 493 | // the Write.endTransmisstion to see if 494 | // a device did acknowledge to the address. 495 | Wire.beginTransmission(address); 496 | error = Wire.endTransmission(); 497 | 498 | if (error == 0) 499 | { 500 | Serial.print("I2C device found at address 0x"); 501 | if (address < 16) 502 | { 503 | Serial.print("0"); 504 | } 505 | Serial.print(address, HEX); 506 | Serial.println(" !"); 507 | 508 | nDevices++; 509 | } 510 | else if (error == 4) 511 | { 512 | Serial.print("Unknown error at address 0x"); 513 | if (address < 16) 514 | { 515 | Serial.print("0"); 516 | } 517 | Serial.println(address, HEX); 518 | } 519 | } 520 | if (nDevices == 0) 521 | { 522 | Serial.println("No I2C devices found\n"); 523 | } 524 | else 525 | { 526 | Serial.println("done\n"); 527 | } 528 | } 529 | #endif 530 | 531 | -------------------------------------------------------------------------------- /img/splash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcel-licence/esp32_basic_synth/5452e5bc64fa0854b944ef32c7f220f84652d68b/img/splash.jpg -------------------------------------------------------------------------------- /mcp23_module.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Marcel Licence 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Dieses Programm ist Freie Software: Sie können es unter den Bedingungen 18 | * der GNU General Public License, wie von der Free Software Foundation, 19 | * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren 20 | * veröffentlichten Version, weiter verteilen und/oder modifizieren. 21 | * 22 | * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch 23 | * OHNE JEDE GEWÄHR,; sogar ohne die implizite 24 | * Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. 25 | * Siehe die GNU General Public License für weitere Einzelheiten. 26 | * 27 | * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem 28 | * Programm erhalten haben. Wenn nicht, siehe . 29 | */ 30 | 31 | /** 32 | * @file mcp23_module.ino 33 | * @author Marcel Licence 34 | * @date 08.07.2021 35 | * 36 | * @brief This module is used to control the MCP23017 and MCP23S17 37 | * 38 | * @see My first PCB for arduino based synthesizer projects - a quick look at the HW for ESP32/DaisySeed - https://youtu.be/Lp65Urhy1-U 39 | * @see ESP32 / ESP8266 playground arduino project (using switches, encoders, displays, etc..) - https://youtu.be/juwm6o3j8XA 40 | */ 41 | 42 | 43 | #ifdef __CDT_PARSER__ 44 | #include 45 | #endif 46 | 47 | 48 | #ifdef MCP23_MODULE_ENABLED 49 | 50 | 51 | #include 52 | #include 53 | 54 | 55 | /* 56 | * nice ressource for using mcp and wire 57 | * 58 | * https://elektro.turanis.de/html/prj128/index.html 59 | */ 60 | 61 | #define MCP32_ADDR 0x20 62 | 63 | #define IODIRA 0x00 64 | #define IODIRB 0x01 65 | #define IPOLA 0x02 66 | #define IPOLB 0x03 67 | #define GPINTENA 0x04 68 | #define GPINTENB 0x05 69 | #define DEFVALA 0x06 70 | #define DEFVALB 0x07 71 | #define INTCONA 0x08 72 | #define INTCONB 0x09 73 | #define GPPUA 0x0C 74 | #define GPPUB 0x0D 75 | #define INTFA 0x0E 76 | #define INTFB 0x0F 77 | #define INTCAPA 0x10 78 | #define INTCAPB 0x11 79 | #define REG_GPIOA 0x12 80 | #define REG_GPIOB 0x13 81 | 82 | #define IODIR_INPUT 0xFF 83 | #define IODIR_OUTPUT 0x00 84 | 85 | #define GPPU_PULLUP_ENABLED 0xFF 86 | #define GPPU_PULLUP_DISABLED 0x00 87 | 88 | 89 | inline 90 | void MCP23_WriteReg(uint8_t reg, uint8_t value) 91 | { 92 | Wire.beginTransmission(MCP32_ADDR); 93 | Wire.write(reg); // IODIRA register 94 | Wire.write(value); 95 | Wire.endTransmission(); 96 | } 97 | 98 | uint8_t MCP23_ReadReg(uint8_t reg) 99 | { 100 | Wire.beginTransmission(MCP32_ADDR); 101 | Wire.write(reg); // set MCP23017 memory pointer to reg address 102 | Wire.endTransmission(); 103 | 104 | Wire.requestFrom(MCP32_ADDR, 1); // request one byte of data from MCP20317 105 | return Wire.read(); // store the incoming byte into "inputs" 106 | } 107 | 108 | #define OPCODEW (0b01000000) // Opcode for MCP23S17 with LSB (bit0) set to write (0), address OR'd in later, bits 1-3 109 | #define OPCODER (0b01000001) // Opcode for MCP23S17 with LSB (bit0) set to read (1), address OR'd in later, bits 1-3 110 | #define ADDR_ENABLE (0b00001000) // Configuration register for MCP23S17, the only thing we change is enabling hardware addressing 111 | 112 | #define ENC_CLK_1 (1<<5) 113 | #define ENC_DIR_1 (1<<6) 114 | #define ENC_BTN_1 (1<<7) 115 | 116 | 117 | #define ENC_CLK_2 (1<<2) 118 | #define ENC_DIR_2 (1<<1) 119 | #if 1 120 | #define MCP_CS SPI_CS 121 | void MCP23_SpiWriteReg(uint8_t reg, uint8_t value) 122 | { 123 | digitalWrite(MCP_CS, LOW); 124 | SPI.transfer(OPCODEW | (MCP32_ADDR << 1)); // Send the MCP23S17 opcode, chip address, and write bit 125 | SPI.transfer(reg); // Send the register we want to write 126 | SPI.transfer(value); // Send the byte 127 | digitalWrite(MCP_CS, HIGH); 128 | } 129 | 130 | uint8_t MSP23_SpiReadReg(uint8_t reg) 131 | { 132 | digitalWrite(MCP_CS, LOW); 133 | SPI.transfer(OPCODER | (MCP32_ADDR << 1)); // Send the MCP23S17 opcode, chip address, and write bit 134 | SPI.transfer(reg); // Send the register we want to write 135 | uint8_t res = SPI.transfer(0x00); // Send the byte 136 | digitalWrite(MCP_CS, HIGH); 137 | return res; 138 | } 139 | 140 | void MCP23_Setup(void) 141 | { 142 | MCP23_WriteReg(IODIRA, IODIR_INPUT); 143 | 144 | MCP23_Select(1); 145 | MCP23_WriteReg(IODIRB, IODIR_OUTPUT); 146 | 147 | MCP23_Select(1); 148 | MCP23_SpiWriteReg(IODIRA, IODIR_OUTPUT); 149 | MCP23_SpiWriteReg(IODIRA, IODIR_OUTPUT); 150 | 151 | MCP23_WriteReg(GPPUA, GPPU_PULLUP_ENABLED); 152 | 153 | for (int i = 0; i < 10; i++) 154 | { 155 | #if 0 156 | MCP23_WriteReg(REG_GPIOA, 0x00); 157 | MCP23_WriteReg(REG_GPIOB, 0x00); 158 | #endif 159 | MCP23_SpiWriteReg(REG_GPIOA, 0x00); 160 | 161 | delay(50); 162 | 163 | #if 0 164 | MCP23_WriteReg(REG_GPIOA, 0xFF); 165 | MCP23_WriteReg(REG_GPIOB, 0xFF); 166 | #endif 167 | MCP23_SpiWriteReg(REG_GPIOA, 0xFF); 168 | 169 | delay(50); 170 | } 171 | 172 | MCP23_WriteReg(GPINTENA, ENC_CLK_1 + ENC_CLK_2 + ENC_BTN_1); /* enable interrupts for enc1, enc2 and button press */ 173 | MCP23_WriteReg(INTCONA, 0x00); /* Interrupt on 0: pin change */ 174 | } 175 | 176 | uint8_t valu8 = 0; 177 | uint8_t valu8b = 0; 178 | bool btnDown = false; 179 | 180 | 181 | //#define HALF_CLOCK_PER_STEP1 182 | //#define MCP23_ENC_DEBUG 183 | 184 | #define mcp23_printf(...) Serial.printf(__VA_ARGS__) 185 | 186 | void MCP23_Loop() 187 | { 188 | static uint8_t lastInput = 0xCC; 189 | 190 | 191 | uint8_t intfa = MCP23_ReadReg(INTFA); 192 | uint8_t intcapa = MCP23_ReadReg(INTCAPA); 193 | 194 | #ifdef MCP23_CHECK_PORT /* check PORT a only */ 195 | uint8_t inputs = MCP23_ReadReg(REG_GPIOA); 196 | 197 | if (inputs != lastInput) 198 | { 199 | lastInput = inputs; 200 | Status_ValueChangedInt("I2C_IOA", lastInput); 201 | } 202 | #endif 203 | 204 | #if 0 205 | if (inputs > 0) 206 | { 207 | // if a button was pressed 208 | Serial.println(inputs, BIN); // display the contents of the REG_GPIOB register in binary 209 | delay(200); // for debounce 210 | } 211 | #else 212 | #if 0 213 | if (/*(lastInput != intcapa) && */(intcapa != 00)) 214 | #else 215 | if (intfa != 0) 216 | #endif 217 | { 218 | 219 | 220 | btnDown = ((intcapa & ENC_BTN_1) == 0); 221 | 222 | 223 | if (((lastInput & ENC_CLK_1) != (intcapa & ENC_CLK_1)) && ((intfa & ENC_CLK_1) > 0)) 224 | { 225 | mcp23_printf("in: 0x%02x 0x%02x 0x%02x %s\n", intfa & ENC_CLK_1, intcapa & ENC_DIR_1, intcapa & ENC_CLK_1, btnDown ? "down" : "up"); 226 | if (intcapa & ENC_DIR_1) 227 | { 228 | if (!(intcapa & ENC_CLK_1)) 229 | { 230 | #ifdef HALF_CLOCK_PER_STEP1 231 | valu8++; 232 | mcp23_printf("%d right1\n", valu8); 233 | #endif 234 | } 235 | else 236 | { 237 | valu8--; 238 | mcp23_printf("%d left2\n", valu8); 239 | } 240 | } 241 | else 242 | { 243 | if ((intcapa & ENC_CLK_1)) 244 | { 245 | valu8++; 246 | mcp23_printf("%d right3\n", valu8); 247 | } 248 | else 249 | { 250 | #ifdef HALF_CLOCK_PER_STEP1 251 | valu8--; 252 | mcp23_printf("%d left4\n", valu8); 253 | #endif 254 | } 255 | } 256 | 257 | Status_ValueChangedInt("valu8", valu8); 258 | } 259 | 260 | 261 | if (((lastInput & ENC_CLK_2) != (intcapa & ENC_CLK_2)) && ((intfa & ENC_CLK_2) > 0)) 262 | { 263 | mcp23_printf("in: 0x%02x 0x%02x 0x%02x %s\n", intfa & ENC_CLK_2, intcapa & ENC_DIR_2, intcapa & ENC_CLK_2, btnDown ? "down" : "up"); 264 | if (intcapa & ENC_DIR_2) 265 | { 266 | if ((intcapa & ENC_CLK_2)) 267 | { 268 | valu8b++; 269 | mcp23_printf("%d right1b\n", valu8b); 270 | } 271 | else 272 | { 273 | valu8b--; 274 | mcp23_printf("%d left2b\n", valu8b); 275 | } 276 | } 277 | else 278 | { 279 | if (!(intcapa & ENC_CLK_2)) 280 | { 281 | valu8b++; 282 | mcp23_printf("%d right3b\n", valu8b); 283 | } 284 | else 285 | { 286 | valu8b--; 287 | mcp23_printf("%d left4b\n", valu8b); 288 | } 289 | } 290 | Status_ValueChangedInt("valu8b", valu8b); 291 | } 292 | 293 | //Status_ValueChangedInt("lastInput", lastInput); 294 | lastInput = intcapa; 295 | } 296 | #endif 297 | } 298 | 299 | static uint8_t adcCnt = 0; 300 | static bool ledOn = true; 301 | 302 | void MCP23_SetAdcCh(uint8_t adcCh) 303 | { 304 | adcCnt = adcCh; 305 | MCP23_UpdateOutput(); 306 | } 307 | 308 | void MCP23_UpdateOutput() 309 | { 310 | MCP23_Select(1); 311 | MCP23_SpiWriteReg(IODIRA, IODIR_OUTPUT); /* shouldn't be necessary but it looks like we do not have the output active otherwise */ 312 | if (ledOn) 313 | { 314 | MCP23_SpiWriteReg(REG_GPIOA, 0x00 + adcCnt); 315 | #ifdef SHOW_MCP_READBACK 316 | mcp23_printf("spi: 0x%02x\n", MSP23_SpiReadReg(REG_GPIOA)); 317 | #endif 318 | } 319 | else 320 | { 321 | MCP23_SpiWriteReg(REG_GPIOA, 0xF0 + adcCnt); 322 | #ifdef SHOW_MCP_READBACK 323 | mcp23_printf("spi: 0x%02x\n", MSP23_SpiReadReg(REG_GPIOA)); 324 | #endif 325 | } 326 | } 327 | 328 | void MCP23_loop1Hz(void) 329 | { 330 | ledOn = !ledOn; 331 | MCP23_UpdateOutput(); 332 | } 333 | #endif 334 | void MCP23_Select(uint8_t id) 335 | { 336 | if (id < 8) 337 | { 338 | MCP23_WriteReg(REG_GPIOB, (1 << id)); 339 | } 340 | else 341 | { 342 | Serial.printf("id invalid!\n"); 343 | } 344 | } 345 | 346 | void MCP23017_Test() 347 | { 348 | static uint8_t gpioa_in = 0xCC; 349 | static uint8_t gpiob_in = 0xCC; 350 | 351 | uint8_t input; 352 | 353 | MCP23_WriteReg(GPPUA, GPPU_PULLUP_ENABLED); 354 | MCP23_WriteReg(GPPUB, GPPU_PULLUP_ENABLED); 355 | 356 | input = MCP23_ReadReg(REG_GPIOA); 357 | if (input != gpioa_in) 358 | { 359 | gpioa_in = input; 360 | Serial.printf("gpioa_in: 0x%02x\n", gpioa_in); 361 | } 362 | 363 | input = MCP23_ReadReg(REG_GPIOB); 364 | if (input != gpiob_in) 365 | { 366 | gpiob_in = input; 367 | Serial.printf("gpiob_in: 0x%02x\n", gpiob_in); 368 | } 369 | } 370 | 371 | void MCP23017_TestCS() 372 | { 373 | static uint8_t gpioa_in = 0xCC; 374 | static uint8_t gpiob_in = 0xCC; 375 | 376 | uint8_t input; 377 | 378 | MCP23_WriteReg(GPPUA, GPPU_PULLUP_ENABLED); 379 | MCP23_WriteReg(GPPUB, GPPU_PULLUP_DISABLED); 380 | MCP23_WriteReg(IODIRB, IODIR_OUTPUT); 381 | 382 | 383 | digitalWrite(SPI_CS, HIGH); 384 | pinMode(SPI_CS, OUTPUT); 385 | 386 | #if 0 387 | for (int id = 0; id < 8; id++) 388 | { 389 | MCP23_WriteReg(REG_GPIOB, (1 << id)); 390 | delay(100); 391 | digitalWrite(SPI_CS, LOW); 392 | delay(200); 393 | digitalWrite(SPI_CS, HIGH); 394 | delay(100); 395 | } 396 | #endif 397 | 398 | //MCP23_WriteReg(REG_GPIOB, 0xFF); 399 | MCP23_Select(SPI_SEL_MCP23S17); 400 | 401 | MCP23_SpiWriteReg(IODIRA, IODIR_OUTPUT); 402 | MCP23_SpiWriteReg(IODIRB, IODIR_OUTPUT); 403 | static uint8_t outVar = 0xAA; 404 | 405 | MCP23_SpiWriteReg(REG_GPIOA, outVar); 406 | outVar = ~outVar; 407 | MCP23_SpiWriteReg(REG_GPIOB, outVar); 408 | 409 | input = MSP23_SpiReadReg(REG_GPIOA); 410 | if (input != gpioa_in) 411 | { 412 | gpioa_in = input; 413 | Serial.printf("gpioa_in: 0x%02x\n", gpioa_in); 414 | } 415 | 416 | input = MSP23_SpiReadReg(REG_GPIOB); 417 | if (input != gpiob_in) 418 | { 419 | gpiob_in = input; 420 | Serial.printf("gpiob_in: 0x%02x\n", gpiob_in); 421 | } 422 | 423 | 424 | /* 425 | * setup int for encoder 426 | */ 427 | MCP23_WriteReg(GPINTENA, ENC_CLK_1 + ENC_CLK_2 + ENC_BTN_1); /* enable interrupts for enc1, enc2 and button press */ 428 | MCP23_WriteReg(INTCONA, 0x00); /* Interrupt on 0: pin change */ 429 | } 430 | 431 | void MCP23_SelAdc(uint8_t i) 432 | { 433 | uint32_t var = 0; 434 | var &= 0xF0; 435 | var |= i; 436 | MCP23_SpiWriteReg(REG_GPIOB, var); 437 | } 438 | 439 | #endif /* MCP23_MODULE_ENABLED */ 440 | 441 | -------------------------------------------------------------------------------- /ml_inline.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | #define ML_SYNTH_INLINE_DEFINITION 4 | #include 5 | #undef ML_SYNTH_INLINE_DEFINITION -------------------------------------------------------------------------------- /status_module.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Marcel Licence 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Dieses Programm ist Freie Software: Sie können es unter den Bedingungen 18 | * der GNU General Public License, wie von der Free Software Foundation, 19 | * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren 20 | * veröffentlichten Version, weiter verteilen und/oder modifizieren. 21 | * 22 | * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch 23 | * OHNE JEDE GEWÄHR,; sogar ohne die implizite 24 | * Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. 25 | * Siehe die GNU General Public License für weitere Einzelheiten. 26 | * 27 | * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem 28 | * Programm erhalten haben. Wenn nicht, siehe . 29 | */ 30 | 31 | /** 32 | * @file status_module.ino 33 | * @author Marcel Licence 34 | * @date 04.10.2021 35 | * 36 | * @brief This file contains the implementation of the terminal output 37 | * the output is vt100 compatible and you should use a terminal like teraTerm 38 | * 39 | * @see VT100 mode used here: https://youtu.be/r0af0DB1R68 40 | * @see TeraTerm pro https://ttssh2.osdn.jp/index.html.en​ 41 | */ 42 | 43 | 44 | #ifdef __CDT_PARSER__ 45 | #include 46 | #endif 47 | 48 | 49 | bool triggerTerminalOutput = true; /*!< necessary for usage without vt100 compliant terminal */ 50 | 51 | char statusMsg[128] = ""; /*!< buffer for top line message */ 52 | 53 | uint32_t statusMsgShowTimer = 0; /*!< counter for timeout to reset top line */ 54 | 55 | #define VU_MAX 24 /*!< character length of vu meter */ 56 | 57 | float statusVuLookup[VU_MAX]; /*!< precalculated lookup */ 58 | 59 | /* 60 | * prepares the module 61 | */ 62 | void Status_Setup(void) 63 | { 64 | /* 65 | * prepare lookup for log vu meters 66 | */ 67 | float vuValue = 1.0f; 68 | for (int i = VU_MAX; i > 0; i--) 69 | { 70 | int n = i - 1; 71 | 72 | statusVuLookup[n] = vuValue; 73 | 74 | vuValue *= 1.0f / sqrt(2.0f); /* div by 1/sqrt(2) means 3db */ 75 | vuValue *= 1.0f / sqrt(2.0f); 76 | } 77 | } 78 | 79 | /* 80 | * function which prints the vu meter "line" 81 | */ 82 | void Status_PrintVu(float *value, uint8_t vuMax) 83 | { 84 | /* 85 | * first pick a color 86 | */ 87 | if (*value >= 0.7071f) /* -3dB */ 88 | { 89 | Serial.printf("\033[0;31m"); /* red */ 90 | } 91 | else if (*value >= 0.5) /* -6dB */ 92 | { 93 | Serial.printf("\033[0;33m"); /* yellow */ 94 | } 95 | else 96 | { 97 | Serial.printf("\033[0;32m"); /* green */ 98 | } 99 | 100 | for (int i = 0; i < vuMax; i++) 101 | { 102 | 103 | if (statusVuLookup[i + (VU_MAX - vuMax)] <= *value) 104 | { 105 | Serial.printf("#"); 106 | } 107 | else 108 | { 109 | Serial.printf(" "); 110 | } 111 | } 112 | 113 | Serial.printf("\033[0m"); /* switch back to default */ 114 | 115 | *value *= 0.5; /* slowly lower the value */ 116 | } 117 | 118 | 119 | /* 120 | * refresh complete output 121 | * 32 character width 122 | * 14 character height 123 | */ 124 | void Status_PrintAll(void) 125 | { 126 | char emptyLine[] = " "; 127 | #if 0 128 | char emptyLineMin[] = " "; 129 | char emptyLineLong[] = " "; 130 | #endif 131 | Serial.printf("\033[?25l"); 132 | Serial.printf("\033[%d;%dH", 0, 0); 133 | //Serial.printf("--------------------------------\n"); 134 | Serial.printf("%s%s\n", statusMsg, &emptyLine[strlen(statusMsg)]); 135 | #ifdef VT100_ENABLED 136 | Serial.printf("--------------------------------\n"); 137 | 138 | Serial.printf("inL "); 139 | Status_PrintVu(vuInL, 8); 140 | 141 | Serial.printf(" outL "); 142 | Status_PrintVu(vuOutL, 8); 143 | Serial.printf("\n"); 144 | 145 | Serial.printf("inR "); 146 | Status_PrintVu(vuInR, 8); 147 | Serial.printf(" outR "); 148 | Status_PrintVu(vuOutR, 8); 149 | Serial.printf("\n"); 150 | 151 | 152 | Serial.printf("--------------------------------\n"); 153 | char memoryUsedMsg[64]; 154 | sprintf(memoryUsedMsg, "%d of %d bytes used", sampleStorageInPos, sampleStorageLen); 155 | Serial.printf("%s%s\n", memoryUsedMsg, &emptyLine[strlen(memoryUsedMsg)]); 156 | 157 | float relativeStorageUsage = ((float)sampleStorageInPos) / ((float)sampleStorageLen); 158 | for (int i = 0; i < 32; i++) 159 | { 160 | if (i == (int)(relativeStorageUsage * 32.0f)) 161 | { 162 | Serial.printf("O"); 163 | } 164 | else 165 | { 166 | if (i > (int)(relativeStorageUsage * 32.0f)) 167 | { 168 | Serial.printf("_"); 169 | } 170 | else 171 | { 172 | Serial.printf("="); 173 | } 174 | } 175 | } 176 | Serial.println(); 177 | 178 | Serial.printf("%s%s%s", emptyLine, currentFile, &emptyLineLong[strlen(currentFile)]); 179 | #endif 180 | } 181 | 182 | 183 | void Status_Process_Sample(uint32_t inc) 184 | { 185 | statusMsgShowTimer += inc; 186 | if (statusMsgShowTimer == SAMPLE_RATE * 3) 187 | { 188 | statusMsgShowTimer = SAMPLE_RATE * 3 + 1; 189 | statusMsg[0] = 0; 190 | #if 1 191 | triggerTerminalOutput = true; 192 | #else 193 | #ifndef VT100_ENABLED 194 | Status_PrintAll(); 195 | #endif 196 | #endif 197 | } 198 | } 199 | 200 | void Status_Process(void) 201 | { 202 | #ifdef _DISPLAY_FROM_STATUS_ENABLED 203 | if (triggerTerminalOutput) 204 | { 205 | if (statusMsg[0] == 0) 206 | { 207 | Display_ShowClear(); 208 | } 209 | Display_DisplayMessage(); 210 | } 211 | #endif 212 | 213 | #ifndef VT100_ENABLED 214 | if (triggerTerminalOutput) 215 | #endif 216 | { 217 | Status_PrintAll(); 218 | triggerTerminalOutput = false; 219 | } 220 | 221 | #ifndef VT100_ENABLED 222 | if (triggerTerminalOutput) 223 | #endif 224 | { 225 | Status_PrintAll(); 226 | triggerTerminalOutput = false; 227 | } 228 | } 229 | 230 | /* 231 | * update top line message including a float value 232 | */ 233 | void Status_ValueChangedFloat(const char *group, const char *descr, float value) 234 | { 235 | statusMsgShowTimer = 0; 236 | sprintf(statusMsg, "%s - %s: %0.3f", group, descr, value); 237 | triggerTerminalOutput = true; 238 | #ifdef _DISPLAY_FROM_STATUS_ENABLED 239 | Display_ShowValueFloat(descr, value); 240 | #endif 241 | } 242 | 243 | void Status_ValueChangedFloat(const char *descr, float value) 244 | { 245 | statusMsgShowTimer = 0; 246 | sprintf(statusMsg, "%s: %0.3f", descr, value); 247 | triggerTerminalOutput = true; 248 | #ifdef _DISPLAY_FROM_STATUS_ENABLED 249 | Display_ShowValueFloat(descr, value); 250 | #endif 251 | } 252 | 253 | /* 254 | * update top line message including a float value 255 | */ 256 | void Status_ValueChangedFloatArr(const char *descr, float value, int index) 257 | { 258 | statusMsgShowTimer = 0; 259 | sprintf(statusMsg, "%s[%d]: %0.3f", descr, index, value); 260 | triggerTerminalOutput = true; 261 | #ifdef _DISPLAY_FROM_STATUS_ENABLED 262 | Display_ShowValueFloatArr(descr, value, index); 263 | #endif 264 | } 265 | 266 | void Status_ValueChangedIntArr(const char *descr, int value, int index) 267 | { 268 | statusMsgShowTimer = 0; 269 | sprintf(statusMsg, "%s[%d]: %d", descr, index, value); 270 | triggerTerminalOutput = true; 271 | #ifdef _DISPLAY_FROM_STATUS_ENABLED 272 | Display_ShowValueIntArr(descr, value, index); 273 | #endif 274 | } 275 | /* 276 | * update top line message including an integer value 277 | */ 278 | void Status_ValueChangedInt(const char *group, const char *descr, int value) 279 | { 280 | statusMsgShowTimer = 0; 281 | sprintf(statusMsg, "%s - %s: %d", group, descr, value); 282 | triggerTerminalOutput = true; 283 | #ifdef _DISPLAY_FROM_STATUS_ENABLED 284 | Display_ShowValueInt(descr, value); 285 | #endif 286 | } 287 | 288 | void Status_ValueChangedInt(const char *descr, int value) 289 | { 290 | statusMsgShowTimer = 0; 291 | sprintf(statusMsg, "%s: %d", descr, value); 292 | triggerTerminalOutput = true; 293 | #ifdef _DISPLAY_FROM_STATUS_ENABLED 294 | Display_ShowValueInt(descr, value); 295 | #endif 296 | } 297 | 298 | /* 299 | * update top line message 300 | */ 301 | void Status_TestMsg(const char *text) 302 | { 303 | statusMsgShowTimer = 0; 304 | sprintf(statusMsg, "%s", text); 305 | triggerTerminalOutput = true; 306 | } 307 | 308 | void Status_LogMessage(const char *text) 309 | { 310 | statusMsgShowTimer = 0; 311 | sprintf(statusMsg, "%s", text); 312 | triggerTerminalOutput = true; 313 | } 314 | 315 | -------------------------------------------------------------------------------- /targets.csv: -------------------------------------------------------------------------------- 1 | fqbn;version;config 2 | espressif:esp32:esp32;1.0.6;PSRAM=disabled\nPARTITION_SCHEME=default 3 | espressif:esp32:esp32;2.0.0;PSRAM=disabled\nPARTITION_SCHEME=default 4 | espressif:esp32:esp32;2.0.7;PSRAM=disabled\nPARTITION_SCHEME=default 5 | -------------------------------------------------------------------------------- /z_config.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Marcel Licence 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | * 17 | * Dieses Programm ist Freie Software: Sie können es unter den Bedingungen 18 | * der GNU General Public License, wie von der Free Software Foundation, 19 | * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren 20 | * veröffentlichten Version, weiter verteilen und/oder modifizieren. 21 | * 22 | * Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch 23 | * OHNE JEDE GEWÄHR,; sogar ohne die implizite 24 | * Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. 25 | * Siehe die GNU General Public License für weitere Einzelheiten. 26 | * 27 | * Sie sollten eine Kopie der GNU General Public License zusammen mit diesem 28 | * Programm erhalten haben. Wenn nicht, siehe . 29 | */ 30 | 31 | /** 32 | * @file z_config.ino 33 | * @author Marcel Licence 34 | * @date 12.05.2021 35 | * 36 | * @brief This file contains the mapping configuration 37 | * Put all your project configuration here (no defines etc) 38 | * This file will be included at the and can access all 39 | * declarations and type definitions 40 | * 41 | * @see ESP32 Arduino DIY Synthesizer Projects - Little startup guide to get your MIDI synth working - https://youtu.be/ZNxGCB-d68g 42 | */ 43 | 44 | 45 | #ifdef __CDT_PARSER__ 46 | #include 47 | #endif 48 | 49 | 50 | #ifdef AUDIO_KIT_BUTTON_ANALOG 51 | audioKitButtonCb audioKitButtonCallback = App_ButtonCb; 52 | #endif 53 | 54 | /* 55 | * adc to midi mapping 56 | */ 57 | #ifdef ADC_TO_MIDI_ENABLED 58 | struct adc_to_midi_s adcToMidiLookUp[ADC_TO_MIDI_LOOKUP_SIZE] = 59 | { 60 | {0, 0x10}, 61 | {1, 0x10}, 62 | {2, 0x10}, 63 | {3, 0x10}, 64 | {4, 0x10}, 65 | {5, 0x10}, 66 | {6, 0x10}, 67 | {7, 0x10}, 68 | }; 69 | 70 | 71 | struct adc_to_midi_mapping_s adcToMidiMapping = 72 | { 73 | adcToMidiLookUp, 74 | sizeof(adcToMidiLookUp) / sizeof(adcToMidiLookUp[0]), 75 | //Midi_ControlChange, 76 | #ifdef MIDI_VIA_USB_ENABLED 77 | UsbMidi_SendControlChange, 78 | #else 79 | Midi_ControlChange, 80 | #endif 81 | }; 82 | 83 | #endif 84 | 85 | /* 86 | * this mapping is used for the edirol pcr-800 87 | * this should be changed when using another controller 88 | */ 89 | struct midiControllerMapping edirolMapping[] = 90 | { 91 | /* transport buttons */ 92 | { 0x8, 0x52, "back", NULL, Synth_SongPosReset, 0}, 93 | { 0xD, 0x52, "stop", NULL, NULL, 0}, 94 | { 0xe, 0x52, "start", NULL, NULL, 0}, 95 | { 0xe, 0x52, "start", NULL, NULL, 0}, 96 | { 0xa, 0x52, "rec", NULL, NULL, 0}, 97 | 98 | /* upper row of buttons */ 99 | { 0x0, 0x50, "A1", NULL, Synth_SetCurCh, 0}, 100 | { 0x1, 0x50, "A2", NULL, Synth_SetCurCh, 1}, 101 | { 0x2, 0x50, "A3", NULL, NULL, 2}, 102 | { 0x3, 0x50, "A4", NULL, NULL, 3}, 103 | 104 | { 0x4, 0x50, "A5", NULL, Synth_SetCurCh, 0}, 105 | { 0x5, 0x50, "A6", NULL, Synth_SetCurCh, 1}, 106 | { 0x6, 0x50, "A7", NULL, MidiCtrl_TransposeUp, 0}, 107 | { 0x7, 0x50, "A8", NULL, MidiCtrl_TransposeDown, 0}, 108 | 109 | { 0x0, 0x53, "A9", NULL, Synth_ToggleMono, 0}, 110 | 111 | /* lower row of buttons */ 112 | #ifdef ARP_MODULE_ENABLED 113 | { 0x0, 0x51, "B1", NULL, Arp_SelectSequence, 0}, 114 | { 0x1, 0x51, "B2", NULL, Arp_SelectSequence, 1}, 115 | { 0x2, 0x51, "B3", NULL, Arp_SelectSequence, 2}, 116 | { 0x3, 0x51, "B4", NULL, Arp_SelectSequence, 3}, 117 | 118 | { 0x4, 0x51, "B5", NULL, Arp_SelectSequence, 4}, 119 | { 0x5, 0x51, "B6", NULL, Arp_SelectSequence, 5}, 120 | { 0x6, 0x51, "B7", NULL, Arp_SelectSequence, 6}, 121 | { 0x7, 0x51, "B8", NULL, Arp_SelectSequence, 7}, 122 | 123 | { 0x1, 0x53, "B9", NULL, Arp_StartRecord, 8}, 124 | #else 125 | { 0x0, 0x51, "B1", NULL, NULL, 0}, 126 | { 0x1, 0x51, "B2", NULL, NULL, 1}, 127 | { 0x2, 0x51, "B3", NULL, NULL, 2}, 128 | { 0x3, 0x51, "B4", NULL, NULL, 3}, 129 | 130 | { 0x4, 0x51, "B5", NULL, NULL, 4}, 131 | { 0x5, 0x51, "B6", NULL, NULL, 5}, 132 | { 0x6, 0x51, "B7", NULL, NULL, 6}, 133 | { 0x7, 0x51, "B8", NULL, NULL, 7}, 134 | 135 | { 0x1, 0x53, "B9", NULL, NULL, 8}, 136 | #endif 137 | 138 | /* pedal */ 139 | { 0x0, 0x0b, "VolumePedal", NULL, NULL, 0}, 140 | 141 | /* slider */ 142 | { 0x0, 0x11, "S1", NULL, Synth_SetParam, SYNTH_PARAM_VEL_ENV_ATTACK}, 143 | { 0x1, 0x11, "S2", NULL, Synth_SetParam, SYNTH_PARAM_VEL_ENV_DECAY}, 144 | { 0x2, 0x11, "S3", NULL, Synth_SetParam, SYNTH_PARAM_VEL_ENV_SUSTAIN}, 145 | { 0x3, 0x11, "S4", NULL, Synth_SetParam, SYNTH_PARAM_VEL_ENV_RELEASE}, 146 | 147 | { 0x4, 0x11, "S5", NULL, Synth_SetParam, SYNTH_PARAM_FIL_ENV_ATTACK}, 148 | { 0x5, 0x11, "S6", NULL, Synth_SetParam, SYNTH_PARAM_FIL_ENV_DECAY}, 149 | { 0x6, 0x11, "S7", NULL, Synth_SetParam, SYNTH_PARAM_FIL_ENV_SUSTAIN}, 150 | { 0x7, 0x11, "S8", NULL, Synth_SetParam, SYNTH_PARAM_FIL_ENV_RELEASE}, 151 | 152 | #ifdef ARP_MODULE_ENABLED 153 | { 0x1, 0x12, "S9", NULL, Arp_Tempo, 0}, 154 | #else 155 | { 0x1, 0x12, "S9", NULL, Synth_SetParam, 8}, 156 | #endif 157 | 158 | /* rotary */ 159 | #ifdef USE_UNISON 160 | { 0x0, 0x10, "R1", NULL, Synth_SetParam, SYNTH_PARAM_DETUNE_1}, 161 | { 0x1, 0x10, "R2", NULL, Synth_SetParam, SYNTH_PARAM_UNISON_2}, 162 | #else 163 | { 0x0, 0x10, "R1", NULL, Synth_SetParam, SYNTH_PARAM_WAVEFORM_1}, 164 | { 0x1, 0x10, "R2", NULL, Synth_SetParam, SYNTH_PARAM_WAVEFORM_2}, 165 | #endif 166 | { 0x2, 0x10, "R3", NULL, Delay_SetLength, 2}, 167 | { 0x3, 0x10, "R4", NULL, Delay_SetOutputLevel, 3}, 168 | 169 | { 0x4, 0x10, "R5", NULL, Delay_SetFeedback, 4}, 170 | { 0x5, 0x10, "R6", NULL, Synth_SetParam, SYNTH_PARAM_MAIN_FILT_CUTOFF}, 171 | { 0x6, 0x10, "R7", NULL, Synth_SetParam, SYNTH_PARAM_MAIN_FILT_RESO}, 172 | //{ 0x7, 0x10, "R8", NULL, Synth_SetParam, SYNTH_PARAM_VOICE_FILT_RESO}, 173 | { 0x7, 0x10, "R8", NULL, Synth_SetParam, SYNTH_PARAM_VOICE_PORT_TIME}, 174 | 175 | //{ 0x0, 0x12, "R9", NULL, Synth_SetParam, SYNTH_PARAM_VOICE_NOISE_LEVEL}, 176 | { 0x0, 0x12, "R9", NULL, Reverb_SetLevel, SYNTH_PARAM_VOICE_NOISE_LEVEL}, 177 | 178 | /* Central slider */ 179 | #ifdef MIDI_SYNC_MASTER 180 | { 0x0, 0x13, "H1", NULL, Synth_SetMidiMasterTempo, 0}, 181 | #endif 182 | }; 183 | 184 | struct midiMapping_s midiMapping = 185 | { 186 | NULL, 187 | #ifdef MIDI_CTRL_ENABLED 188 | MidiCtrl_NoteOn, 189 | MidiCtrl_NoteOff, 190 | #else 191 | Synth_NoteOn, 192 | Synth_NoteOff, 193 | #endif 194 | Synth_PitchBend, 195 | Synth_ModulationWheel, 196 | NULL, /* assign program change callback here! */ 197 | Synth_RealTimeMsg, 198 | Synth_SongPosition, 199 | edirolMapping, 200 | sizeof(edirolMapping) / sizeof(edirolMapping[0]), 201 | }; 202 | 203 | #ifdef MIDI_VIA_USB_ENABLED 204 | struct usbMidiMappingEntry_s usbMidiMappingEntries[] = 205 | { 206 | { 207 | NULL, 208 | App_UsbMidiShortMsgReceived, 209 | NULL, 210 | NULL, 211 | 0xFF, 212 | }, 213 | }; 214 | 215 | struct usbMidiMapping_s usbMidiMapping = 216 | { 217 | NULL, 218 | NULL, 219 | usbMidiMappingEntries, 220 | sizeof(usbMidiMappingEntries) / sizeof(usbMidiMappingEntries[0]), 221 | }; 222 | #endif /* MIDI_VIA_USB_ENABLED */ 223 | --------------------------------------------------------------------------------