initial import

This commit is contained in:
Stefano D'Angelo 2022-11-16 00:49:51 +01:00
commit 61d0c690e9
79 changed files with 9223 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build
node_modules
package-lock.json

674
LICENSE Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

25
README.md Normal file
View File

@ -0,0 +1,25 @@
# Brickworks
Brickworks is a music DSP toolkit that supplies you with the fundamental building blocks for creating and enhancing audio engines on any platform.
You can find information and documentation [on the official web page](https://www.orastron.com/brickworks).
## Subfolders
* examples: a synth and an effect example in VST3 and Web Audio formats;
* include: header files;
* src: source files.
## Legal
Copyright (C) 2021, 2022 Orastron srl unipersonale.
Authors: Stefano D'Angelo, Paolo Marrone.
All the code in the repo is released under GPLv3. See the LICENSE file. Alternatively, we offer a commercial license that doesn't restrict usage with respect to time, projects, or developers involved. More details [on the official web page](https://www.orastron.com/brickworks#license-pricing).
The file examples/common/vst3/plugin.cpp contains code from sse2neon (https://github.com/DLTcollab/sse2neon/), which is released under the MIT license. Details in said file.
VST is a registered trademark of Steinberg Media Technologies GmbH.
All trademarks and registered marks are properties of their respective owners. All company, product, and service names used are for identification purposes only. Use of these names, trademarks, and brands does not imply endorsement.

18
TODO Normal file
View File

@ -0,0 +1,18 @@
code:
* blep etc in a module?
* osc post filter init val? osc post filter and one pole init val from input?
* audio rate optional pulse width/slope inputs?
* one pole process const input? (return also if const out)
* optimize triangle generation for constant pulse width
* naming type suffixes math.h vs random.h
* API for buffer fill, scale, offset, zero, copy...?
* web examples construction/destruction
* web effect multichannel in?
build system:
* make makefiles handle paths with spaces etc
* can run su on windows? (system-wide install)
* make autodependencies (.d?)
* make from... directories
* order-only prerequisites to avoid multiple make updates? (https://interrupt.memfault.com/blog/gnu-make-guidelines#order-only-prerequisites)
* clang + Ofast & bulk memory (maybe using old binaryen)

View File

@ -0,0 +1,63 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include "controller.h"
#include "pluginterfaces/base/conststringtable.h"
#include "base/source/fstreamer.h"
tresult PLUGIN_API Controller::initialize(FUnknown *context) {
tresult r = EditController::initialize(context);
if (r != kResultTrue)
return r;
// add parameters
for (int i = 0; i < NUM_PARAMETERS; i++)
parameters.addParameter(
ConstStringTable::instance()->getString(config_parameters[i].name),
config_parameters[i].units ? ConstStringTable::instance()->getString(config_parameters[i].units) : nullptr,
config_parameters[i].steps,
config_parameters[i].defaultValueUnmapped,
(config_parameters[i].out ? ParameterInfo::kIsReadOnly | ParameterInfo::kIsHidden : ParameterInfo::kCanAutomate)
| (config_parameters[i].bypass ? ParameterInfo::kIsBypass : 0),
i,
0,
config_parameters[i].shortName ? ConstStringTable::instance()->getString(config_parameters[i].shortName) : nullptr
);
return kResultTrue;
}
tresult PLUGIN_API Controller::setComponentState(IBStream *state) {
if (!state)
return kResultFalse;
IBStreamer streamer(state, kLittleEndian);
float f;
for (int i = 0; i < NUM_PARAMETERS; i++) {
if (config_parameters[i].out)
continue;
if (streamer.readFloat(f) == false)
return kResultFalse;
setParamNormalized(i, f);
}
return kResultTrue;
}

View File

@ -0,0 +1,44 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#ifndef _VST3_CONTROLLER_H
#define _VST3_CONTROLLER_H
#include "config.h"
#include "config_vst3.h"
#include "public.sdk/source/vst/vsteditcontroller.h"
using namespace Steinberg;
using namespace Steinberg::Vst;
class Controller : EditController {
public:
static FUnknown *createInstance(void *context) {
return (IEditController *) new Controller();
}
tresult PLUGIN_API initialize(FUnknown *context) SMTG_OVERRIDE;
tresult PLUGIN_API setComponentState(IBStream *state) SMTG_OVERRIDE;
private:
};
#endif

View File

@ -0,0 +1,52 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include "plugin.h"
#include "controller.h"
#include "pluginterfaces/vst/ivstaudioprocessor.h"
#include "pluginterfaces/vst/ivsteditcontroller.h"
#include "public.sdk/source/main/pluginfactory.h"
BEGIN_FACTORY_DEF(COMPANY_NAME, COMPANY_WEBSITE, COMPANY_MAILTO)
DEF_CLASS2(
INLINE_UID(PLUGIN_GUID_1, PLUGIN_GUID_2, PLUGIN_GUID_3, PLUGIN_GUID_4), // GUID
PClassInfo::kManyInstances, // cardinality
kVstAudioEffectClass, // VST component class
PLUGIN_NAME, // plugin name
Vst::kDistributable, // plugin and controller can work on different computers
PLUGIN_SUBCATEGORY, // VST subcategory
PLUGIN_VERSION, // plugin version
kVstVersionString, // VST version
Plugin::createInstance // instatiation function pointer
)
DEF_CLASS2(
INLINE_UID(CTRL_GUID_1, CTRL_GUID_2, CTRL_GUID_3, CTRL_GUID_4), // GUID
PClassInfo::kManyInstances, // cardinality
kVstComponentControllerClass, // VST component class
PLUGIN_NAME "Controller", // controller name
0, // unused
"", // unused
PLUGIN_VERSION, // plugin version
kVstVersionString, // VST version
Controller::createInstance // instatiation function pointer
)
END_FACTORY

View File

@ -0,0 +1,366 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo, Paolo Marrone
*
* This file contains code from sse2neon (https://github.com/DLTcollab/sse2neon/),
* which is released under the following licensing conditions.
*
* sse2neon is freely redistributable under the MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "plugin.h"
#include "pluginterfaces/base/conststringtable.h"
#include "pluginterfaces/vst/ivstparameterchanges.h"
#include "pluginterfaces/vst/ivstevents.h"
#include "base/source/fstreamer.h"
#include <algorithm>
#if defined(__aarch64__)
/* Beginning of sse2neon code */
/* Denormals are zeros mode macros. */
#define _MM_DENORMALS_ZERO_MASK 0x0040
#define _MM_DENORMALS_ZERO_ON 0x0040
#define _MM_DENORMALS_ZERO_OFF 0x0000
#define _MM_GET_DENORMALS_ZERO_MODE _sse2neon_mm_get_denormals_zero_mode
#define _MM_SET_DENORMALS_ZERO_MODE _sse2neon_mm_set_denormals_zero_mode
/* Flush zero mode macros. */
#define _MM_FLUSH_ZERO_MASK 0x8000
#define _MM_FLUSH_ZERO_ON 0x8000
#define _MM_FLUSH_ZERO_OFF 0x0000
#define _MM_GET_FLUSH_ZERO_MODE _sse2neon_mm_get_flush_zero_mode
#define _MM_SET_FLUSH_ZERO_MODE _sse2neon_mm_set_flush_zero_mode
typedef struct {
uint16_t res0;
uint8_t res1 : 6;
uint8_t bit22 : 1;
uint8_t bit23 : 1;
uint8_t bit24 : 1;
uint8_t res2 : 7;
uint32_t res3;
} fpcr_bitfield;
static inline unsigned int _sse2neon_mm_get_denormals_zero_mode()
{
union {
fpcr_bitfield field;
uint64_t value;
} r;
__asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value));
return r.field.bit24 ? _MM_DENORMALS_ZERO_ON : _MM_DENORMALS_ZERO_OFF;
}
static inline void _sse2neon_mm_set_denormals_zero_mode(unsigned int flag)
{
union {
fpcr_bitfield field;
uint64_t value;
} r;
__asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value));
r.field.bit24 = (flag & _MM_DENORMALS_ZERO_MASK) == _MM_DENORMALS_ZERO_ON;
__asm__ __volatile__("msr FPCR, %0" ::"r"(r));
}
static inline unsigned int _sse2neon_mm_get_flush_zero_mode()
{
union {
fpcr_bitfield field;
uint64_t value;
} r;
__asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value));
return r.field.bit24 ? _MM_FLUSH_ZERO_ON : _MM_FLUSH_ZERO_OFF;
}
static inline void _sse2neon_mm_set_flush_zero_mode(unsigned int flag)
{
union {
fpcr_bitfield field;
uint64_t value;
} r;
__asm__ __volatile__("mrs %0, FPCR" : "=r"(r.value));
r.field.bit24 = (flag & _MM_FLUSH_ZERO_MASK) == _MM_FLUSH_ZERO_ON;
__asm__ __volatile__("msr FPCR, %0" ::"r"(r));
}
/* End of sse2neon code */
#elif defined(__i386__) || defined(__x86_64__)
#include <xmmintrin.h>
#include <pmmintrin.h>
#else
#define NO_DAZ_FTZ
#endif
Plugin::Plugin() {
setControllerClass(FUID(CTRL_GUID_1, CTRL_GUID_2, CTRL_GUID_3, CTRL_GUID_4));
}
tresult PLUGIN_API Plugin::initialize(FUnknown *context) {
instance = P_NEW();
if (instance == nullptr)
return kResultFalse;
tresult r = AudioEffect::initialize(context);
if (r != kResultTrue) {
P_FREE(instance);
return r;
}
#ifdef P_NOTE_ON
addEventInput(ConstStringTable::instance()->getString("MIDI Input"));
#endif
// FIXME: vst3 sdk validator always seem to get kDefaultActive even in sdk plugins - it's probably broken, but let's check
#if NUM_BUSES_IN != 0
for (int i = 0; i < NUM_BUSES_IN; i++)
addAudioInput(
ConstStringTable::instance()->getString(config_buses_in[i].name),
config_buses_in[i].configs & IO_STEREO ? SpeakerArr::kStereo : SpeakerArr::kMono,
config_buses_in[i].aux ? kAux : kMain,
(config_buses_in[i].cv ? BusInfo::kIsControlVoltage : 0)
| (config_buses_in[i].aux ? 0 : BusInfo::kDefaultActive)
);
#endif
#if NUM_BUSES_OUT != 0
for (int i = 0; i < NUM_BUSES_OUT; i++)
addAudioOutput(
ConstStringTable::instance()->getString(config_buses_out[i].name),
config_buses_out[i].configs & IO_STEREO ? SpeakerArr::kStereo : SpeakerArr::kMono,
config_buses_out[i].aux ? kAux : kMain,
(config_buses_out[i].cv ? BusInfo::kIsControlVoltage : 0)
| (config_buses_out[i].aux ? 0 : BusInfo::kDefaultActive)
);
#endif
#if NUM_PARAMETERS != 0
for (int i = 0; i < NUM_PARAMETERS; i++) {
parameters[i] = config_parameters[i].defaultValueUnmapped;
P_SET_PARAMETER(instance, i, parameters[i]);
}
#endif
return kResultTrue;
}
tresult PLUGIN_API Plugin::terminate() {
P_FREE(instance);
return AudioEffect::terminate();
}
tresult PLUGIN_API Plugin::setActive(TBool state) {
if (state) {
P_SET_SAMPLE_RATE(instance, sampleRate);
P_RESET(instance);
}
return AudioEffect::setActive(state);
}
tresult PLUGIN_API Plugin::setupProcessing(ProcessSetup &setup) {
sampleRate = static_cast<float>(setup.sampleRate);
return AudioEffect::setupProcessing(setup);
}
tresult PLUGIN_API Plugin::process(ProcessData &data) {
if (data.numInputs != NUM_BUSES_IN || data.numOutputs != NUM_BUSES_OUT)
return kResultFalse;
#if NUM_PARAMETERS != 0
if (data.inputParameterChanges) {
int32 n = data.inputParameterChanges->getParameterCount();
for (int32 i = 0; i < n; i++) {
IParamValueQueue *q = data.inputParameterChanges->getParameterData(i);
if (!q)
continue;
ParamValue v;
int32 o;
if (q->getPoint(q->getPointCount() - 1, o, v) == kResultTrue) {
int32 pi = q->getParameterId();
parameters[pi] = v;
P_SET_PARAMETER(instance, pi, std::min(std::max(static_cast<float>(v), 0.f), 1.f));
}
}
}
#endif
#ifdef P_NOTE_ON
if (data.inputEvents) {
int32 n = data.inputEvents->getEventCount();
for (int i = 0; i < n; i++) {
Event e;
if (data.inputEvents->getEvent(i, e) != kResultOk)
continue;
switch (e.type) {
case Event::kNoteOnEvent:
P_NOTE_ON(instance, e.noteOn.pitch, e.noteOn.velocity);
break;
case Event::kNoteOffEvent:
P_NOTE_OFF(instance, e.noteOn.pitch);
break;
}
}
}
#endif
#if NUM_BUSES_IN != 0
int ki = 0;
for (int i = 0; i < data.numInputs; i++)
for (int j = 0; j < data.inputs[i].numChannels; j++, ki++)
inputs[ki] = (const float *)data.inputs[i].channelBuffers32[j];
#endif
#if NUM_BUSES_OUT != 0
int ko = 0;
for (int i = 0; i < data.numOutputs; i++)
for (int j = 0; j < data.outputs[i].numChannels; j++, ko++)
outputs[ko] = data.outputs[i].channelBuffers32[j];
#endif
const unsigned int flush_zero_mode = _MM_GET_FLUSH_ZERO_MODE();
const unsigned int denormals_zero_mode = _MM_GET_DENORMALS_ZERO_MODE();
#ifndef NO_DAZ_FTZ
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
#endif
#if NUM_BUSES_IN == 0
const float **inputs = nullptr;
#endif
#if NUM_BUSES_OUT == 0
float **outputs = nullptr;
#endif
P_PROCESS(instance, inputs, outputs, data.numSamples);
#ifndef NO_DAZ_FTZ
_MM_SET_FLUSH_ZERO_MODE(flush_zero_mode);
_MM_SET_DENORMALS_ZERO_MODE(denormals_zero_mode);
#endif
#if NUM_PARAMETERS != 0
for (int i = 0; i < NUM_PARAMETERS; i++) {
if (!config_parameters[i].out)
continue;
float v = P_GET_PARAMETER(instance, i);
if (parameters[i] == v)
continue;
parameters[i] = v;
if (data.outputParameterChanges) {
int32 index;
IParamValueQueue* paramQueue = data.outputParameterChanges->addParameterData(i, index);
if (paramQueue)
paramQueue->addPoint(0, v, index);
}
}
#endif
return kResultTrue;
}
tresult PLUGIN_API Plugin::setBusArrangements(SpeakerArrangement *inputs, int32 numIns, SpeakerArrangement *outputs, int32 numOuts) {
if (numIns != NUM_BUSES_IN || numOuts != NUM_BUSES_OUT)
return kResultFalse;
#if NUM_BUSES_IN != 0
for (int32 i = 0; i < numIns; i++)
if ((config_buses_in[i].configs == IO_MONO && inputs[i] != SpeakerArr::kMono)
|| (config_buses_in[i].configs == IO_STEREO && inputs[i] != SpeakerArr::kStereo))
return kResultFalse;
#endif
#if NUM_BUSES_OUT != 0
for (int32 i = 0; i < numOuts; i++)
if ((config_buses_out[i].configs == IO_MONO && outputs[i] != SpeakerArr::kMono)
|| (config_buses_out[i].configs == IO_STEREO && outputs[i] != SpeakerArr::kStereo))
return kResultFalse;
#endif
return kResultTrue;
}
tresult PLUGIN_API Plugin::setState(IBStream *state) {
if (!state)
return kResultFalse;
#if NUM_PARAMETERS != 0
IBStreamer streamer(state, kLittleEndian);
float f;
for (int i = 0; i < NUM_PARAMETERS; i++) {
if (config_parameters[i].out)
continue;
if (streamer.readFloat(f) == false)
return kResultFalse;
parameters[i] = f;
P_SET_PARAMETER(instance, i, f);
}
#endif
return kResultTrue;
}
tresult PLUGIN_API Plugin::getState(IBStream *state) {
#if NUM_PARAMETERS != 0
IBStreamer streamer(state, kLittleEndian);
for (int i = 0; i < NUM_PARAMETERS; i++)
if (!config_parameters[i].out)
streamer.writeFloat(parameters[i]);
#endif
return kResultTrue;
}

View File

@ -0,0 +1,64 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#ifndef _VST3_PLUGIN_H
#define _VST3_PLUGIN_H
#include "config.h"
#include "config_vst3.h"
#include "public.sdk/source/vst/vstaudioeffect.h"
using namespace Steinberg;
using namespace Steinberg::Vst;
class Plugin : AudioEffect {
public:
Plugin();
static FUnknown *createInstance(void *context) {
return (IAudioProcessor *) new Plugin();
}
tresult PLUGIN_API initialize(FUnknown *context) SMTG_OVERRIDE;
tresult PLUGIN_API terminate() SMTG_OVERRIDE;
tresult PLUGIN_API setActive(TBool state) SMTG_OVERRIDE;
tresult PLUGIN_API setupProcessing(ProcessSetup &setup) SMTG_OVERRIDE;
tresult PLUGIN_API process(ProcessData &data) SMTG_OVERRIDE;
tresult PLUGIN_API setBusArrangements(SpeakerArrangement *inputs, int32 numIns, SpeakerArrangement *outputs, int32 numOuts) SMTG_OVERRIDE;
tresult PLUGIN_API setState(IBStream *state) SMTG_OVERRIDE;
tresult PLUGIN_API getState(IBStream *state) SMTG_OVERRIDE;
private:
float sampleRate;
#if NUM_PARAMETERS != 0
float parameters[NUM_PARAMETERS];
#endif
P_TYPE instance;
#if NUM_BUSES_IN != 0
const float *inputs[NUM_CHANNELS_IN];
#endif
#if NUM_BUSES_OUT != 0
float *outputs[NUM_CHANNELS_OUT];
#endif
};
#endif

View File

@ -0,0 +1,31 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#ifndef _BW_CONFIG_H
#define _BW_CONFIG_H
#include "walloc.h"
#define BW_MALLOC malloc
#define BW_REALLOC realloc
#define BW_FREE free
#define INFINITY (__builtin_inff())
#endif

View File

@ -0,0 +1,141 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
class BWExample extends AudioWorkletProcessor {
constructor(options) {
super();
var module = new WebAssembly.Module(options.processorOptions.wasmBytes);
var instance = new WebAssembly.Instance(module, { env: {} });
this.module = instance.exports;
this.instance = this.module.wrapper_new(sampleRate);
if (!this.instance)
// TODO: what to do if this is the case?
throw "Could not instantiate";
function getBuffers(p, output) {
var ret = [];
for (var i = 0; i < buses.length; i++) {
if ((!output && buses[i].output) || (output && !buses[i].output))
continue;
var b = [ new Float32Array(this.module.memory.buffer, p, 128) ];
p += 128 * 4;
if (buses[i].stereo) {
b.push(new Float32Array(this.module.memory.buffer, p, 128));
p += 128 * 4;
}
ret.push(b);
}
return ret;
}
this.ins = getBuffers.call(this, this.module.wrapper_get_ins(this.instance), false);
this.outs = getBuffers.call(this, this.module.wrapper_get_outs(this.instance), true);
if (parameters.length) {
this.paramValues = new Float32Array(this.module.memory.buffer, this.module.wrapper_get_param_values(this.instance), parameters.length);
this.paramValuesPrev = new Float32Array(this.paramValues);
} else {
this.paramValues = [];
this.paramValuesPrev = [];
}
var self = this;
this.port.onmessage = function (e) {
switch (e.data.type) {
case "noteOn":
self.module.wrapper_note_on(self.instance, e.data.note, e.data.velocity);
break;
case "noteOff":
self.module.wrapper_note_off(self.instance, e.data.note);
break;
}
};
}
// TODO: "destructor"
process(inputs, outputs, params) {
for (var i = 0; i < parameters.length; i++) {
if (parameters[i].output)
continue;
var n = parameters[i].name;
var v = params[n][0];
if (v != this.paramValues[n]) {
this.module.wrapper_set_parameter(this.instance, i, v);
this.paramValues[n] = v;
}
}
//mmm...
var n = outputs[0][0].length;
var i = 0;
while (i < n) {
var s = Math.min(n - i, 128);
for (var j = 0; j < this.ins.length; j++) {
var input = inputs[j];
if (!input.length) {
for (var k = 0; k < this.ins[j].length; k++)
this.ins[j][k].fill(0);
} else {
if (this.ins[j].length != input.length)
throw "input " + j + " has " + this.ins[j].length + " channels, not " + input.length;
for (var k = 0; k < this.ins[j].length; k++)
for (var l = 0; l < s; l++)
this.ins[j][k][l] = input[k][i + l];
}
}
this.module.wrapper_process(this.instance, s);
for (var j = 0; j < this.outs.length; j++) {
var output = outputs[j];
for (var k = 0; k < output.length; k++)
for (var l = 0; l < s; l++)
output[k][i + l] = this.outs[j][k][l];
}
i += s;
}
for (var i = 0; i < parameters.length; i++) {
if (!parameters[i].output)
continue;
if (this.paramValuesPrev[i] != this.paramValues[i])
this.port.postMessage({ index: i, value: this.paramValues[i] });
}
this.paramValuesPrev.set(this.paramValues);
return true;
}
static get parameterDescriptors() {
var ret = [];
for (var i = 0; i < parameters.length; i++) {
var p = parameters[i];
if (p.output)
continue;
ret.push({ name: p.name, minValue: 0.0, maxValue: 1.0, defaultValue: p.defaultValue, automationRate: "k-rate" });
}
return ret;
}
}
registerProcessor("BWExample", BWExample);

View File

@ -0,0 +1,142 @@
/*
* Brickworks
*
* Copyright (C) 2021, 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <stdint.h>
#include "walloc.h"
extern unsigned char __heap_base;
typedef struct _header {
struct _header *next;
struct _header *prev;
char free;
} header;
static char inited = 0;
static size_t get_size(header *h) {
char *n = (char *)h->next;
return (n ? n : (char *)(__builtin_wasm_memory_size(0) << 16)) - (char *)h - sizeof(header);
}
static void split_if_possible(header *h, size_t s, size_t size) {
if (s <= size + sizeof(header) + sizeof(header))
return;
header *hn = (header *)((char *)h + sizeof(header) + size);
hn->prev = h;
hn->next = h->next;
hn->free = 1;
h->next = hn;
if (hn->next)
hn->next->prev = hn;
}
void *malloc(size_t size) {
if (size == 0)
return NULL;
header *h = (header *)&__heap_base;
if (!inited) {
h->next = NULL;
h->prev = NULL;
h->free = 1;
inited = 1;
}
header *p;
for (; h; p = h, h = h->next) {
if (!h->free)
continue;
size_t s = get_size(h);
if (s < size)
continue;
split_if_possible(h, s, size);
h->free = 0;
return (char *)h + sizeof(header);
}
int32_t n = __builtin_wasm_memory_grow(0, ((size + sizeof(header) - 1) >> 16) + 1);
if (n < 0)
return NULL;
if (p->free)
h = p;
else {
h = (header *)(n << 16);
p->next = h;
h->prev = p;
h->next = NULL;
}
split_if_possible(h, get_size(h), size);
h->free = 0;
return (char *)h + sizeof(header);
}
void *realloc(void *ptr, size_t size) {
if (ptr == NULL)
return malloc(size);
if (size == 0) {
free(ptr);
return NULL;
}
header *h = (header *)((char *)ptr - sizeof(header));
size_t s = get_size(h);
if (s >= size)
return ptr;
void *p = malloc(size);
if (p == NULL)
return NULL;
char *src = (char *)ptr;
char *dest = (char *)p;
for (size_t i = 0; i < s; i++)
dest[i] = src[i];
free(ptr);
return p;
}
void free(void *ptr) {
header *h = (header *)((char *)ptr - sizeof(header));
h->free = 1;
if (h->next && h->next->free) {
h->next = h->next->next;
if (h->next)
h->next->prev = h;
}
if (h->prev && h->prev->free) {
h->prev->next = h->next;
if (h->next)
h->next->prev = h->prev;
}
}

View File

@ -0,0 +1,29 @@
/*
* Brickworks
*
* Copyright (C) 2021, 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#ifndef _WALLOC_H
#define _WALLOC_H
#include <stddef.h>
void *malloc(size_t size);
void *realloc(void *ptr, size_t size);
void free(void *ptr);
#endif

View File

@ -0,0 +1,153 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File authors: Stefano D'Angelo
*/
#include "config.h"
#include "walloc.h"
struct _wrapper {
P_TYPE instance;
// wasting a little bit of memory if buses are mono, but let's KISS
#if NUM_BUSES_IN != 0
float ins[NUM_BUSES_IN * 2 * 128];
const float *x[NUM_BUSES_IN * 2];
#endif
#if NUM_BUSES_OUT != 0
float outs[NUM_BUSES_OUT * 2 * 128];
float *y[NUM_BUSES_OUT * 2];
#endif
#if NUM_PARAMETERS != 0
float param_values[NUM_PARAMETERS];
#endif
};
typedef struct _wrapper *wrapper;
void wrapper_set_parameter(wrapper w, int index, float value);
wrapper wrapper_new(float sample_rate) {
wrapper ret = malloc(sizeof(struct _wrapper));
if (ret == NULL)
return NULL;
ret->instance = P_NEW();
if (ret->instance == NULL) {
free(ret);
return NULL;
}
#if NUM_BUSES_IN != 0
int dx = 0;
for (int i = 0; i < NUM_BUSES_IN; i++) {
ret->x[i] = ret->ins + dx;
dx += 128;
if (config_buses_in[i].configs & IO_STEREO) {
ret->x[i] = ret->ins + dx;
dx += 128;
}
}
#endif
#if NUM_BUSES_OUT != 0
int dy = 0;
for (int i = 0; i < NUM_BUSES_OUT; i++) {
ret->y[i] = ret->outs + dy;
dy += 128;
if (config_buses_out[i].configs & IO_STEREO) {
ret->y[i] = ret->outs + dy;
dy += 128;
}
}
#endif
#if NUM_PARAMETERS != 0
for (int i = 0; i < NUM_PARAMETERS; i++)
wrapper_set_parameter(ret, i, config_parameters[i].defaultValueUnmapped);
#endif
P_SET_SAMPLE_RATE(ret->instance, sample_rate);
P_RESET(ret->instance);
return ret;
}
void wrapper_free(wrapper w) {
P_FREE(w->instance);
free(w);
}
float *wrapper_get_ins(wrapper w) {
#if NUM_BUSES_IN != 0
return w->ins;
#else
return NULL;
#endif
}
float *wrapper_get_outs(wrapper w) {
#if NUM_BUSES_OUT != 0
return w->outs;
#else
return NULL;
#endif
}
float *wrapper_get_param_values(wrapper w) {
#if NUM_PARAMETERS != 0
return w->param_values;
#else
return NULL;
#endif
}
void wrapper_process(wrapper w, int n_samples) {
#if NUM_BUSES_IN != 0
const float **x = w->x;
#else
const float **x = NULL;
#endif
#if NUM_BUSES_OUT != 0
float **y = w->y;
#else
float **y = NULL;
#endif
P_PROCESS(w->instance, x, y, n_samples);
#if NUM_PARAMETERS != 0
for (int i = 0; i < NUM_PARAMETERS; i++)
w->param_values[i] = P_GET_PARAMETER(w->instance, i);
#endif
}
void wrapper_set_parameter(wrapper w, int index, float value) {
#if NUM_PARAMETERS != 0
P_SET_PARAMETER(w->instance, index, value);
w->param_values[index] = value;
#endif
}
void wrapper_note_on(wrapper w, int note, int velocity) {
#ifdef P_NOTE_ON
P_NOTE_ON(w->instance, note, velocity);
#endif
}
void wrapper_note_off(wrapper w, int note) {
#ifdef P_NOTE_OFF
P_NOTE_OFF(w->instance, note);
#endif
}

View File

@ -0,0 +1,113 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include "bw_example_fx.h"
#include <bw_math.h>
#include <bw_svf.h>
#include <bw_env_follow.h>
enum {
p_cutoff,
p_Q,
p_n
};
#define BUFFER_SIZE 128
struct _bw_example_fx {
// Sub-components
bw_svf svf;
bw_env_follow env_follow;
// Parameters
float params[p_n];
// States
float level;
// Buffers
float buf[BUFFER_SIZE];
};
bw_example_fx bw_example_fx_new() {
bw_example_fx instance = (bw_example_fx)BW_MALLOC(sizeof(struct _bw_example_fx));
if (instance == NULL)
return NULL;
instance->svf = bw_svf_new();
if (instance->svf == NULL) {
BW_FREE(instance);
return NULL;
}
instance->env_follow = bw_env_follow_new();
if (instance->env_follow == NULL) {
bw_svf_free(instance->svf);
BW_FREE(instance);
return NULL;
}
bw_one_pole_set_cutoff_down(bw_env_follow_get_one_pole(instance->env_follow), 1.f);
return instance;
}
void bw_example_fx_free(bw_example_fx instance) {
bw_env_follow_free(instance->env_follow);
bw_svf_free(instance->svf);
BW_FREE(instance);
}
void bw_example_fx_set_sample_rate(bw_example_fx instance, float sample_rate) {
bw_svf_set_sample_rate(instance->svf, sample_rate);
bw_env_follow_set_sample_rate(instance->env_follow, sample_rate);
}
void bw_example_fx_reset(bw_example_fx instance) {
bw_svf_reset(instance->svf);
bw_env_follow_reset(instance->env_follow);
}
void bw_example_fx_process(bw_example_fx instance, const float** x, float** y, int n_samples) {
float a[n_samples];
bw_svf_process(instance->svf, x[0], y[0], NULL, NULL, n_samples);
for (int i = 0; i < n_samples; i += BUFFER_SIZE) {
const uint32_t n = bw_minu32(n_samples - i, BUFFER_SIZE);
bw_env_follow_process(instance->env_follow, y[0] + i, instance->buf, n);
instance->level = instance->buf[i + n - 1];
}
}
void bw_example_fx_set_parameter(bw_example_fx instance, int index, float value) {
switch (index) {
case p_cutoff:
bw_svf_set_cutoff(instance->svf, (20e3f - 20.f) * value * value * value + 20.f);
break;
case p_Q:
bw_svf_set_Q(instance->svf, 0.5f + 9.5f * value);
break;
}
}
float bw_example_fx_get_parameter(bw_example_fx instance, int index) {
return index == 0 ? instance->params[0] : instance->level;
}

View File

@ -0,0 +1,41 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#ifndef _BW_EXAMPLE_FX_H
#define _BW_EXAMPLE_FX_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _bw_example_fx* bw_example_fx;
bw_example_fx bw_example_fx_new();
void bw_example_fx_free(bw_example_fx instance);
void bw_example_fx_set_sample_rate(bw_example_fx instance, float sample_rate);
void bw_example_fx_reset(bw_example_fx instance);
void bw_example_fx_process(bw_example_fx instance, const float** x, float** y, int n_samples);
void bw_example_fx_set_parameter(bw_example_fx instance, int index, float value);
float bw_example_fx_get_parameter(bw_example_fx instance, int index);
#ifdef __cplusplus
}
#endif
#endif

89
examples/fx/src/config.h Normal file
View File

@ -0,0 +1,89 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File authors: Stefano D'Angelo
*/
#ifndef _CONFIG_H
#define _CONFIG_H
// Definitions
#define IO_MONO 1
#define IO_STEREO (1<<1)
struct config_io_bus {
const char *name;
char out;
char aux;
char cv;
char configs;
};
struct config_parameter {
const char *name;
const char *shortName;
const char *units;
char out;
char bypass;
int steps;
float defaultValueUnmapped;
};
// Data
#define COMPANY_NAME "Orastron"
#define COMPANY_WEBSITE "https://www.orastron.com/"
#define COMPANY_MAILTO "mailto:info@orastron.com"
#define PLUGIN_NAME "bw_example_fx"
#define PLUGIN_VERSION "0.1.0"
#define NUM_BUSES_IN 1
#define NUM_BUSES_OUT 1
#define NUM_CHANNELS_IN 1
#define NUM_CHANNELS_OUT 1
static struct config_io_bus config_buses_in[NUM_BUSES_IN] = {
{ "Audio in", 0, 0, 0, IO_MONO }
};
static struct config_io_bus config_buses_out[NUM_BUSES_OUT] = {
{ "Audio out", 1, 0, 0, IO_MONO }
};
#define NUM_PARAMETERS 3
static struct config_parameter config_parameters[NUM_PARAMETERS] = {
{ "Cutoff", "Cutoff", "", 0, 0, 0, 0.5f },
{ "Q", "Q", "", 0, 0, 0, 0.f },
{ "Level", "Level", "", 1, 0, 0, 0.f }
};
// Internal API
#include "bw_example_fx.h"
#define P_TYPE bw_example_fx
#define P_NEW bw_example_fx_new
#define P_FREE bw_example_fx_free
#define P_SET_SAMPLE_RATE bw_example_fx_set_sample_rate
#define P_RESET bw_example_fx_reset
#define P_PROCESS bw_example_fx_process
#define P_SET_PARAMETER bw_example_fx_set_parameter
#define P_GET_PARAMETER bw_example_fx_get_parameter
#endif

View File

@ -0,0 +1,89 @@
VST3_SDK_DIR=${ROOT_DIR}/../../../../VST_SDK/vst3sdk
CXX=g++
CXXFLAGS= \
-DRELEASE=1 \
-I${ROOT_DIR} \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/vst3 \
-I${ROOT_DIR}/../../../include \
-I${VST3_SDK_DIR} \
-fPIC \
-O3
LDFLAGS= \
-shared \
-static-libgcc \
-static-libstdc++
INSTALL_PREFIX=/usr/local
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_fx.c \
\
${ROOT_DIR}/../../common/vst3/entry.cpp \
${ROOT_DIR}/../../common/vst3/plugin.cpp \
${ROOT_DIR}/../../common/vst3/controller.cpp \
\
${VST3_SDK_DIR}/base/source/fobject.cpp \
${VST3_SDK_DIR}/base/source/baseiids.cpp \
${VST3_SDK_DIR}/base/source/fstreamer.cpp \
${VST3_SDK_DIR}/base/source/fstring.cpp \
${VST3_SDK_DIR}/base/source/fbuffer.cpp \
${VST3_SDK_DIR}/base/source/updatehandler.cpp \
${VST3_SDK_DIR}/base/thread/source/flock.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/coreiids.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/funknown.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/ustring.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/conststringtable.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/linuxmain.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/pluginfactory.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/moduleinit.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/commoniids.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/pluginview.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponentbase.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponent.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstaudioeffect.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstinitiids.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstbus.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vsteditcontroller.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstparameters.cpp
SO_DIR=build/bw_example_fx.vst3/Contents/$(shell uname -m)-linux
all: build/bw_example_fx.vst3/Contents/Resources ${SO_DIR}/bw_example_fx.so
${SO_DIR}/bw_example_fx.so: ${SOURCES}
mkdir -p ${SO_DIR}
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -o $@
build/bw_example_fx.vst3/Contents/Resources: build/bw_example_fx.vst3/Contents ${ROOT_DIR}/bw_example_fx.vst3/Contents/Resources
cp -R ${ROOT_DIR}/bw_example_fx.vst3/Contents/Resources build/bw_example_fx.vst3/Contents
build/bw_example_fx.vst3/Contents:
mkdir -p $@
install-user: all
mkdir -p ${HOME}/.vst3
@echo mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:${HOME}/.vst3/:g`
@mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:${HOME}/.vst3/:g`
@for f in `find build/bw_example_fx.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/.vst3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/.vst3/$$d; \
done
install: all
mkdir -p ${INSTALL_PREFIX}/lib/vst3
@echo mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:${INSTALL_PREFIX}/vst3/:g`
@mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:${INSTALL_PREFIX}/vst3/:g`
@for f in `find build/bw_example_fx.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${INSTALL_PREFIX}/vst3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${INSTALL_PREFIX}/vst3/$$d; \
done
clean:
rm -fr build/bw_example_fx.vst3

View File

@ -0,0 +1,97 @@
VST3_SDK_DIR=${ROOT_DIR}/../../../../VST_SDK/vst3sdk
CXX=clang++
CXXFLAGS= \
-std=c++11 \
-DRELEASE=1 \
-I${ROOT_DIR}/src \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/vst3 \
-I${ROOT_DIR}/../../../include \
-I${VST3_SDK_DIR} \
-fPIC \
-O3
LDFLAGS= \
-framework Cocoa \
-shared
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_fx.c \
\
${ROOT_DIR}/../../common/vst3/entry.cpp \
${ROOT_DIR}/../../common/vst3/plugin.cpp \
${ROOT_DIR}/../../common/vst3/controller.cpp \
\
${VST3_SDK_DIR}/base/source/fobject.cpp \
${VST3_SDK_DIR}/base/source/baseiids.cpp \
${VST3_SDK_DIR}/base/source/fstreamer.cpp \
${VST3_SDK_DIR}/base/source/fstring.cpp \
${VST3_SDK_DIR}/base/source/fbuffer.cpp \
${VST3_SDK_DIR}/base/source/updatehandler.cpp \
${VST3_SDK_DIR}/base/thread/source/flock.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/coreiids.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/funknown.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/ustring.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/conststringtable.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/macmain.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/pluginfactory.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/moduleinit.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/commoniids.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/pluginview.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponentbase.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponent.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstaudioeffect.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstinitiids.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstbus.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vsteditcontroller.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstparameters.cpp
all: build/bw_example_fx.vst3/Contents/Info.plist build/bw_example_fx.vst3/Contents/PkgInfo build/bw_example_fx.vst3/Contents/MacOS/bw_example_fx
build/bw_example_fx.vst3/Contents/MacOS/bw_example_fx: build/tmp/bw_example_fx-x86_64 build/tmp/bw_example_fx-arm64
mkdir -p build/bw_example_fx.vst3/Contents/MacOS
lipo -create -output $@ $^
build/bw_example_fx.vst3/Contents/Info.plist: build/bw_example_fx.vst3/Contents ${ROOT_DIR}/bw_example_fx.vst3/Contents/Info.plist
cp ${ROOT_DIR}/bw_example_fx.vst3/Contents/Info.plist build/bw_example_fx.vst3/Contents/Info.plist
build/bw_example_fx.vst3/Contents/PkgInfo: build/bw_example_fx.vst3/Contents ${ROOT_DIR}/bw_example_fx.vst3/Contents/PkgInfo
cp ${ROOT_DIR}/bw_example_fx.vst3/Contents/PkgInfo build/bw_example_fx.vst3/Contents/PkgInfo
build/bw_example_fx.vst3/Contents:
mkdir -p $@
build/tmp/bw_example_fx-x86_64: ${SOURCES}
mkdir -p build/tmp
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -arch x86_64 -o $@
build/tmp/bw_example_fx-arm64: ${SOURCES}
mkdir -p build/tmp
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -arch arm64 -o $@
install-user: all
mkdir -p ${HOME}/Library/Audio/Plug-Ins/VST3
@echo mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:${HOME}/Library/Audio/Plug-Ins/VST3/:g`
@mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:${HOME}/Library/Audio/Plug-Ins/VST3/:g`
@for f in `find build/bw_example_fx.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/Library/Audio/Plug-Ins/VST3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/Library/Audio/Plug-Ins/VST3/$$d; \
done
install: all
mkdir -p /Library/Audio/Plug-Ins/VST3
@echo mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:/Library/Audio/Plug-Ins/VST3/:g`
@mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s:^build/:/Library/Audio/Plug-Ins/VST3/:g`
@for f in `find build/bw_example_fx.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f /Library/Audio/Plug-Ins/VST3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f /Library/Audio/Plug-Ins/VST3/$$d; \
done
clean:
rm -fr build/bw_example_fx.vst3 build/tmp

View File

@ -0,0 +1,95 @@
VST3_SDK_DIR=${ROOT_DIR}/../../../../VST_SDK/vst3sdk
CXX=g++
CXXFLAGS= \
-DRELEASE=1 \
-I${ROOT_DIR}/src \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/vst3 \
-I${ROOT_DIR}/../../../include \
-I${VST3_SDK_DIR} \
-fPIC \
-O3
LDFLAGS= \
-shared \
-static \
-static-libgcc \
-static-libstdc++ \
-lole32
#ARCH=x86
ARCH=x86_64
#ARCH=arm64ec
#ARCH=arm
#ARCH=arm64
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_fx.c \
\
${ROOT_DIR}/../../common/vst3/entry.cpp \
${ROOT_DIR}/../../common/vst3/plugin.cpp \
${ROOT_DIR}/../../common/vst3/controller.cpp \
\
${VST3_SDK_DIR}/base/source/fobject.cpp \
${VST3_SDK_DIR}/base/source/baseiids.cpp \
${VST3_SDK_DIR}/base/source/fstreamer.cpp \
${VST3_SDK_DIR}/base/source/fstring.cpp \
${VST3_SDK_DIR}/base/source/fbuffer.cpp \
${VST3_SDK_DIR}/base/source/updatehandler.cpp \
${VST3_SDK_DIR}/base/thread/source/flock.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/coreiids.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/funknown.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/ustring.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/conststringtable.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/dllmain.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/pluginfactory.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/moduleinit.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/commoniids.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/pluginview.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponentbase.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponent.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstaudioeffect.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstinitiids.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstbus.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vsteditcontroller.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstparameters.cpp
DLL_DIR=build/bw_example_fx.vst3/Contents/${ARCH}-win
USER_PREFIX=$(shell echo '${LOCALAPPDATA}' | sed 's:\\:/:g')
all: build/bw_example_fx.vst3/desktop.ini build/bw_example_fx.vst3/Plugin.ico build/bw_example_fx.vst3/Contents/Resources ${DLL_DIR}/bw_example_fx.vst3
${DLL_DIR}/bw_example_fx.vst3: ${SOURCES}
mkdir -p ${DLL_DIR}
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -o $@
build/bw_example_fx.vst3/desktop.ini: build/bw_example_fx.vst3 ${ROOT_DIR}/bw_example_fx.vst3/desktop.ini
cp ${ROOT_DIR}/bw_example_fx.vst3/desktop.ini build/bw_example_fx.vst3
build/bw_example_fx.vst3/Plugin.ico: build/bw_example_fx.vst3 ${ROOT_DIR}/bw_example_fx.vst3/Plugin.ico
cp ${ROOT_DIR}/bw_example_fx.vst3/Plugin.ico build/bw_example_fx.vst3
build/bw_example_fx.vst3/Contents/Resources: build/bw_example_fx.vst3/Contents ${ROOT_DIR}/bw_example_fx.vst3/Contents/Resources
cp -R ${ROOT_DIR}/bw_example_fx.vst3/Contents/Resources build/bw_example_fx.vst3/Contents
build/bw_example_fx.vst3/Contents: build/bw_example_fx.vst3
mkdir -p $@
build/bw_example_fx.vst3:
mkdir -p $@
install-user: all
mkdir -p ${USER_PREFIX}/Programs/Common/VST3
@echo mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s?^build/?${USER_PREFIX}/Programs/Common/VST3/?g`
@mkdir -p -m 0755 `find build/bw_example_fx.vst3 -type d | sed s?^build/?${USER_PREFIX}/Programs/Common/VST3/?g`
@for f in `find build/bw_example_fx.vst3 -type f | sed s?^build/??g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${USER_PREFIX}/Programs/Common/VST3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${USER_PREFIX}/Programs/Common/VST3/$$d; \
done
clean:
rm -fr build/bw_example_fx.vst3

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>bw_example_fx</string>
<key>CFBundleExecutable</key>
<string>bw_example_fx</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
BNDL????

View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@ -0,0 +1,19 @@
sse2neon is freely redistributable under the MIT License.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=Plugin.ico,0

View File

@ -0,0 +1,35 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File authors: Stefano D'Angelo, Paolo Marrone
*/
#ifndef _VST3_CONFIG_H
#define _VST3_CONFIG_H
#define PLUGIN_SUBCATEGORY "Fx|Tools"
#define PLUGIN_GUID_1 0x38ebec3f
#define PLUGIN_GUID_2 0x24fe43e7
#define PLUGIN_GUID_3 0x94ff4552
#define PLUGIN_GUID_4 0xd09f9716
#define CTRL_GUID_1 0x41a5db7d
#define CTRL_GUID_2 0x15af468f
#define CTRL_GUID_3 0x9e63697f
#define CTRL_GUID_4 0x21facb4f
#endif

58
examples/fx/web/Makefile Normal file
View File

@ -0,0 +1,58 @@
CC=clang
CFLAGS= \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/web \
-I${ROOT_DIR}/../../../include \
--target=wasm32 \
-flto \
-fvisibility=hidden \
-Ofast
LDFLAGS= \
-Wl,--allow-undefined \
-Wl,--no-entry \
-Wl,--lto-O3 \
-Wl,-strip-all \
-Wl,--export-table \
-Wl,--export=wrapper_new \
-Wl,--export=wrapper_free \
-Wl,--export=wrapper_get_ins \
-Wl,--export=wrapper_get_outs \
-Wl,--export=wrapper_get_param_values \
-Wl,--export=wrapper_process \
-Wl,--export=wrapper_set_parameter \
-Wl,-z,stack-size=$$((8*1024*1024)) \
-nostdlib
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_fx.c \
${ROOT_DIR}/../../common/web/walloc.c \
${ROOT_DIR}/../../common/web/wrapper.c
all: build/web/module.wasm build/web/index.html build/web/config.js build/web/processor.js build/web/cert.pem build/web/key.pem
build/web/module.wasm: build/web ${SOURCES}
${CC} ${SOURCES} ${CFLAGS} ${LDFLAGS} -o $@
build/web/index.html: build/web ${ROOT_DIR}/index.html
cp ${ROOT_DIR}/index.html $@
build/web/processor.js: build/web ${ROOT_DIR}/config.js ${ROOT_DIR}/../../common/web/processor.js
cat ${ROOT_DIR}/config.js ${ROOT_DIR}/../../common/web//processor.js > $@
build/web/config.js: build/web ${ROOT_DIR}/config.js
cp ${ROOT_DIR}/config.js $@
build/web/key.pem: build/web/cert.pem
build/web/cert.pem: build/web
yes "" | openssl req -x509 -newkey rsa:2048 -keyout build/web/key.pem -out build/web/cert.pem -days 365 -nodes 2>/dev/null
build/web:
mkdir -p build/web
clean:
rm -fr build/web

47
examples/fx/web/config.js Normal file
View File

@ -0,0 +1,47 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
var buses = [
{
stereo: false,
output: false
},
{
stereo: false,
output: true
}
];
var parameters = [
{
name: "Cutoff",
output: false,
defaultValue: 0.5
},
{
name: "Q",
output: false,
defaultValue: 0.0
},
{
name: "Level",
output: true,
defaultValue: 0.0
}
];

206
examples/fx/web/index.html Normal file
View File

@ -0,0 +1,206 @@
<!DOCTYPE html>
<!--
Brickworks
Copyright (C) 2022 Orastron Srl unipersonale
Brickworks is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
Brickworks is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
File author: Stefano D'Angelo
-->
<html>
<head>
<title>Brickworks web effect example</title>
<script src="config.js"></script>
<script>
var audioCtx;
var Effect = {
node: null,
moduleAdded: false,
wasmBytes: null,
init: async function () {
if (!this.moduleAdded) {
await audioCtx.audioWorklet.addModule("processor.js");
this.moduleAdded = true;
}
if (!this.wasmBytes)
this.wasmBytes = await fetch("module.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => bytes);
if (!this.wasmBytes.byteLength) {
this.wasmBytes = null;
throw "could not fetch WebAssembly module";
}
if (!this.node)
this.node = new AudioWorkletNode(audioCtx, "BWExample",
{
numberOfInputs: 1,
numberOfOutputs: 1,
outputChannelCount: [ 1 ],
processorOptions: {
wasmBytes: this.wasmBytes
}
});
this.node.connect(audioCtx.destination);
}
};
var Player = {
sourceBuffer: null,
playing: false,
started: false,
load: function (buffer, successCb, errorCb) {
let t = this;
audioCtx.decodeAudioData(buffer,
function (data) {
if (t.started)
t.sourceBuffer.stop();
if (t.playing)
t.sourceBuffer.disconnect();
t.sourceBuffer = audioCtx.createBufferSource();
t.sourceBuffer.buffer = data;
t.sourceBuffer.loop = true;
if (t.started)
t.sourceBuffer.start();
if (t.playing) {
t.started = true;
t.sourceBuffer.connect(Effect.node);
}
successCb();
},
function () { errorCb(); });
},
togglePlayPause: function () {
if (this.playing) {
this.sourceBuffer.disconnect();
this.playing = false;
} else {
if (!this.started) {
this.sourceBuffer.start();
this.started = true;
}
this.sourceBuffer.connect(Effect.node);
this.playing = true;
}
}
};
var initState = 0; // 0 = not inited, 1 = in progress, 2 = inited
window.addEventListener("load", function (e) {
var start = document.getElementById("start");
var starting = document.getElementById("starting");
var main = document.getElementById("main");
var file = document.getElementById("file");
var playPause = document.getElementById("playPause");
var controls = document.getElementById("controls");
// reset on refresh
file.value = "";
playPause.disabled = true;
for (var i = 0; i < parameters.length; i++) {
var div = document.createElement("div");
controls.appendChild(div);
var label = document.createElement("label");
label.setAttribute("for", "p" + i);
label.innerText = parameters[i].name;
div.appendChild(label);
var range = document.createElement("input");
range.setAttribute("type", "range");
range.setAttribute("id", "p" + i);
range.setAttribute("name", "p" + i);
range.setAttribute("min", "0");
range.setAttribute("max", "1");
range.setAttribute("step", "any");
range.value = parameters[i].defaultValue;
if (parameters[i].output)
range.setAttribute("readonly", "true");
else {
let index = i;
range.addEventListener("input", function (e) {
var p = Effect.node.parameters.get(parameters[index].name);
p.setValueAtTime(e.target.value, 0);
});
}
div.appendChild(range);
}
start.addEventListener("click", async function () {
initState = 1;
start.disabled = true;
starting.hidden = false;
try {
if (!audioCtx)
audioCtx = new AudioContext();
await Effect.init();
Effect.node.port.onmessage = function (e) { document.getElementById("p" + e.data.index).value = e.data.value; };
initState = 2;
start.hidden = true;
starting.hidden = true;
main.hidden = false;
} catch (err) {
alert("Colud not initialize: " + err);
initState = 0;
start.disabled = false;
starting.hidden = true;
}
});
file.addEventListener("change", function () {
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(this.files[0]);
fileReader.onload = function (e) {
Player.load(e.target.result,
function () { playPause.disabled = false; },
function () { alert("Could not decode the chosen file"); });
};
fileReader.onerror = function (e) { alert("Could not read file"); };
});
playPause.addEventListener("click", function () {
Player.togglePlayPause();
playPause.innerText = Player.playing ? "Pause" : "Play";
});
});
</script>
</head>
<body>
<h1>Brickworks web effect example</h1>
<input id="start" type="button" value="Start">
<p id="starting" hidden>Starting...</p>
<div id="main" hidden>
<h2>Player</h2>
<label for="file">Choose a file:</label>
<input type="file" id="file" name="file" accept="audio/*">
<br>
<button id="playPause" disabled>Play</button>
<h2>Effect</h2>
<div id="controls">
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,225 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include "bw_example_synth.h"
#include <bw_math.h>
#include <bw_phase_gen.h>
#include <bw_osc_pulse.h>
#include <bw_osc_filt.h>
#include <bw_svf.h>
#include <bw_env_gen.h>
#include <bw_vol.h>
#include <bw_env_follow.h>
enum {
p_volume,
p_master_tune,
p_portamento,
p_pulse_width,
p_cutoff,
p_Q,
p_attack,
p_decay,
p_sustain,
p_release,
p_n
};
#define BUFFER_SIZE 128
struct _bw_example_synth {
// Sub-components
bw_phase_gen phase_gen;
bw_osc_pulse osc_pulse;
bw_osc_filt osc_filt;
bw_svf svf;
bw_env_gen env_gen;
bw_vol vol;
bw_env_follow env_follow;
// Parameters
float params[p_n];
// States
int note;
float level;
// Buffers
float buf[BUFFER_SIZE];
};
bw_example_synth bw_example_synth_new() {
bw_example_synth instance = (bw_example_synth)BW_MALLOC(sizeof(struct _bw_example_synth));
if (instance == NULL)
return NULL;
instance->phase_gen = bw_phase_gen_new();
if (instance->phase_gen == NULL)
goto err_phase_gen;
instance->osc_pulse = bw_osc_pulse_new();
if (instance->osc_pulse == NULL)
goto err_osc_pulse;
instance->osc_filt = bw_osc_filt_new();
if (instance->osc_filt == NULL)
goto err_osc_filt;
instance->svf = bw_svf_new();
if (instance->svf == NULL)
goto err_svf;
instance->env_gen = bw_env_gen_new();
if (instance->env_gen == NULL)
goto err_env_gen;
instance->vol = bw_vol_new();
if (instance->vol == NULL)
goto err_vol;
instance->env_follow = bw_env_follow_new();
if (instance->env_follow == NULL)
goto err_env_follow;
bw_osc_pulse_set_antialiasing(instance->osc_pulse, 1);
bw_one_pole_set_cutoff_down(bw_env_follow_get_one_pole(instance->env_follow), 1.f);
return instance;
err_env_follow:
bw_vol_free(instance->vol);
err_vol:
bw_env_gen_free(instance->env_gen);
err_env_gen:
bw_svf_free(instance->svf);
err_svf:
bw_osc_filt_free(instance->osc_filt);
err_osc_filt:
bw_osc_pulse_free(instance->osc_pulse);
err_osc_pulse:
bw_phase_gen_free(instance->phase_gen);
err_phase_gen:
BW_FREE(instance);
return NULL;
}
void bw_example_synth_free(bw_example_synth instance) {
bw_env_follow_free(instance->env_follow);
bw_vol_free(instance->vol);
bw_env_gen_free(instance->env_gen);
bw_svf_free(instance->svf);
bw_osc_filt_free(instance->osc_filt);
bw_osc_pulse_free(instance->osc_pulse);
bw_phase_gen_free(instance->phase_gen);
BW_FREE(instance);
}
void bw_example_synth_set_sample_rate(bw_example_synth instance, float sample_rate) {
bw_phase_gen_set_sample_rate(instance->phase_gen, sample_rate);
bw_osc_pulse_set_sample_rate(instance->osc_pulse, sample_rate);
bw_svf_set_sample_rate(instance->svf, sample_rate);
bw_env_gen_set_sample_rate(instance->env_gen, sample_rate);
bw_vol_set_sample_rate(instance->vol, sample_rate);
bw_env_follow_set_sample_rate(instance->env_follow, sample_rate);
}
void bw_example_synth_reset(bw_example_synth instance) {
bw_phase_gen_reset(instance->phase_gen);
bw_osc_pulse_reset(instance->osc_pulse);
bw_osc_filt_reset(instance->osc_filt);
bw_svf_reset(instance->svf);
bw_env_gen_reset(instance->env_gen);
bw_vol_reset(instance->vol);
bw_env_follow_reset(instance->env_follow);
instance->note = -1;
}
void bw_example_synth_process(bw_example_synth instance, const float** x, float** y, int n_samples) {
// TODO: I was too lazy to keep track of master tune and note and only update when needed, could be improved
if (instance->note != -1) {
bw_phase_gen_set_frequency(instance->phase_gen,
440.f * bw_pow2f_3(8.333333333333333e-2f * ((instance->note - 69) + 2.f * instance->params[p_master_tune] - 1.f)));
bw_env_gen_set_gate(instance->env_gen, 1);
} else
bw_env_gen_set_gate(instance->env_gen, 0);
for (int i = 0; i < n_samples; i += BUFFER_SIZE) {
float *out = y[0] + i;
const uint32_t n = bw_minu32(n_samples - i, BUFFER_SIZE);
bw_phase_gen_process(instance->phase_gen, NULL, out, instance->buf, n);
bw_osc_pulse_process(instance->osc_pulse, out, instance->buf, out, n);
bw_osc_filt_process(instance->osc_filt, out, out, n);
bw_svf_process(instance->svf, out, out, NULL, NULL, n);
bw_env_gen_process(instance->env_gen, instance->buf, n);
for (int j = 0; j < n; j++)
out[j] *= instance->buf[j];
bw_vol_process(instance->vol, (const float **)&out, &out, 1, n);
bw_env_follow_process(instance->env_follow, out, instance->buf, n);
instance->level = instance->buf[i + n - 1];
}
}
void bw_example_synth_set_parameter(bw_example_synth instance, int index, float value) {
switch (index) {
case p_volume:
bw_vol_set_volume(instance->vol, value);
break;
case p_master_tune:
instance->params[p_master_tune] = value;
break;
case p_portamento:
bw_phase_gen_set_portamento_tau(instance->phase_gen, value);
break;
case p_pulse_width:
bw_osc_pulse_set_pulse_width(instance->osc_pulse, value);
break;
case p_cutoff:
bw_svf_set_cutoff(instance->svf, 20.f + (20e3f - 20.f) * value * value * value);
break;
case p_Q:
bw_svf_set_Q(instance->svf, 0.5f + 9.5f * value);
break;
case p_attack:
bw_env_gen_set_attack(instance->env_gen, value);
break;
case p_decay:
bw_env_gen_set_decay(instance->env_gen, value);
break;
case p_sustain:
bw_env_gen_set_sustain(instance->env_gen, value);
break;
case p_release:
bw_env_gen_set_release(instance->env_gen, value);
break;
}
}
float bw_example_synth_get_parameter(bw_example_synth instance, int index) {
return index < p_n ? instance->params[index] : instance->level;
}
void bw_example_synth_note_on(bw_example_synth instance, char note, char velocity) {
instance->note = note;
}
void bw_example_synth_note_off(bw_example_synth instance, char note) {
if (note == instance->note)
instance->note = -1;
}

View File

@ -0,0 +1,43 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#ifndef _BW_EXAMPLE_SYNTH_H
#define _BW_EXAMPLE_SYNTH_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _bw_example_synth* bw_example_synth;
bw_example_synth bw_example_synth_new();
void bw_example_synth_free(bw_example_synth instance);
void bw_example_synth_set_sample_rate(bw_example_synth instance, float sample_rate);
void bw_example_synth_reset(bw_example_synth instance);
void bw_example_synth_process(bw_example_synth instance, const float** x, float** y, int n_samples);
void bw_example_synth_set_parameter(bw_example_synth instance, int index, float value);
float bw_example_synth_get_parameter(bw_example_synth instance, int index);
void bw_example_synth_note_on(bw_example_synth instance, char note, char velocity);
void bw_example_synth_note_off(bw_example_synth instance, char note);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,95 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File authors: Stefano D'Angelo
*/
#ifndef _CONFIG_H
#define _CONFIG_H
// Definitions
#define IO_MONO 1
#define IO_STEREO (1<<1)
struct config_io_bus {
const char *name;
char out;
char aux;
char cv;
char configs;
};
struct config_parameter {
const char *name;
const char *shortName;
const char *units;
char out;
char bypass;
int steps;
float defaultValueUnmapped;
};
// Data
#define COMPANY_NAME "Orastron"
#define COMPANY_WEBSITE "https://www.orastron.com/"
#define COMPANY_MAILTO "mailto:info@orastron.com"
#define PLUGIN_NAME "bw_example_synth"
#define PLUGIN_VERSION "0.1.0"
#define NUM_BUSES_IN 0
#define NUM_BUSES_OUT 1
#define NUM_CHANNELS_IN 0
#define NUM_CHANNELS_OUT 1
static struct config_io_bus config_buses_out[NUM_BUSES_OUT] = {
{ "Audio out", 1, 0, 0, IO_MONO }
};
#define NUM_PARAMETERS 11
static struct config_parameter config_parameters[NUM_PARAMETERS] = {
{ "Volume", "Volume", "", 0, 0, 0, 0.5f },
{ "Master tune", "Master tune", "st", 0, 0, 0, 0.5f },
{ "Portamento", "Portamento", "s", 0, 0, 0, 0.f },
{ "Pulse width", "PW", "%", 0, 0, 0, 0.5f },
{ "Cutoff", "Cutoff", "Hz", 0, 0, 0, 1.f },
{ "Q", "Q", "", 0, 0, 0, 0.f },
{ "Attack", "Attack", "s", 0, 0, 0, 0.f },
{ "Decay", "Decay", "s", 0, 0, 0, 0.f },
{ "Sustain", "Sustain", "%", 0, 0, 0, 1.f },
{ "Release", "Release", "0", 0, 0, 0, 0.f },
{ "Level", "Level", "", 1, 0, 0, 0.f }
};
// Internal API
#include "bw_example_synth.h"
#define P_TYPE bw_example_synth
#define P_NEW bw_example_synth_new
#define P_FREE bw_example_synth_free
#define P_SET_SAMPLE_RATE bw_example_synth_set_sample_rate
#define P_RESET bw_example_synth_reset
#define P_PROCESS bw_example_synth_process
#define P_SET_PARAMETER bw_example_synth_set_parameter
#define P_GET_PARAMETER bw_example_synth_get_parameter
#define P_NOTE_ON bw_example_synth_note_on
#define P_NOTE_OFF bw_example_synth_note_off
#endif

View File

@ -0,0 +1,94 @@
VST3_SDK_DIR=${ROOT_DIR}/../../../../VST_SDK/vst3sdk
CXX=g++
CXXFLAGS= \
-DRELEASE=1 \
-I${ROOT_DIR} \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/vst3 \
-I${ROOT_DIR}/../../../include \
-I${VST3_SDK_DIR} \
-fPIC \
-O3
LDFLAGS= \
-shared \
-static-libgcc \
-static-libstdc++
INSTALL_PREFIX=/usr/local
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_phase_gen.c \
${ROOT_DIR}/../../../src/bw_osc_pulse.c \
${ROOT_DIR}/../../../src/bw_osc_filt.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_gen.c \
${ROOT_DIR}/../../../src/bw_vol.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_synth.c \
\
${ROOT_DIR}/../../common/vst3/entry.cpp \
${ROOT_DIR}/../../common/vst3/plugin.cpp \
${ROOT_DIR}/../../common/vst3/controller.cpp \
\
${VST3_SDK_DIR}/base/source/fobject.cpp \
${VST3_SDK_DIR}/base/source/baseiids.cpp \
${VST3_SDK_DIR}/base/source/fstreamer.cpp \
${VST3_SDK_DIR}/base/source/fstring.cpp \
${VST3_SDK_DIR}/base/source/fbuffer.cpp \
${VST3_SDK_DIR}/base/source/updatehandler.cpp \
${VST3_SDK_DIR}/base/thread/source/flock.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/coreiids.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/funknown.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/ustring.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/conststringtable.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/linuxmain.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/pluginfactory.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/moduleinit.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/commoniids.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/pluginview.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponentbase.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponent.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstaudioeffect.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstinitiids.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstbus.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vsteditcontroller.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstparameters.cpp
SO_DIR=build/bw_example_synth.vst3/Contents/$(shell uname -m)-linux
all: build/bw_example_synth.vst3/Contents/Resources ${SO_DIR}/bw_example_synth.so
${SO_DIR}/bw_example_synth.so: ${SOURCES}
mkdir -p ${SO_DIR}
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -o $@
build/bw_example_synth.vst3/Contents/Resources: build/bw_example_synth.vst3/Contents ${ROOT_DIR}/bw_example_synth.vst3/Contents/Resources
cp -R ${ROOT_DIR}/bw_example_synth.vst3/Contents/Resources build/bw_example_synth.vst3/Contents
build/bw_example_synth.vst3/Contents:
mkdir -p $@
install-user: all
mkdir -p ${HOME}/.vst3
@echo mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:${HOME}/.vst3/:g`
@mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:${HOME}/.vst3/:g`
@for f in `find build/bw_example_synth.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/.vst3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/.vst3/$$d; \
done
install: all
mkdir -p ${INSTALL_PREFIX}/lib/vst3
@echo mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:${INSTALL_PREFIX}/vst3/:g`
@mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:${INSTALL_PREFIX}/vst3/:g`
@for f in `find build/bw_example_synth.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${INSTALL_PREFIX}/vst3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${INSTALL_PREFIX}/vst3/$$d; \
done
clean:
rm -fr build/bw_example_synth.vst3

View File

@ -0,0 +1,101 @@
VST3_SDK_DIR=${ROOT_DIR}/../../../../VST_SDK/vst3sdk
CXX=clang++
CXXFLAGS= \
-std=c++11 \
-DRELEASE=1 \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/vst3 \
-I${ROOT_DIR}/../../../include \
-I${VST3_SDK_DIR} \
-fPIC \
-O3
LDFLAGS= \
-framework Cocoa \
-shared
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_phase_gen.c \
${ROOT_DIR}/../../../src/bw_osc_pulse.c \
${ROOT_DIR}/../../../src/bw_osc_post_filter.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_gen.c \
${ROOT_DIR}/../../../src/bw_vol.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_synth.c \
\
${ROOT_DIR}/../../common/vst3/entry.cpp \
${ROOT_DIR}/../../common/vst3/plugin.cpp \
${ROOT_DIR}/../../common/vst3/controller.cpp \
\
${VST3_SDK_DIR}/base/source/fobject.cpp \
${VST3_SDK_DIR}/base/source/baseiids.cpp \
${VST3_SDK_DIR}/base/source/fstreamer.cpp \
${VST3_SDK_DIR}/base/source/fstring.cpp \
${VST3_SDK_DIR}/base/source/fbuffer.cpp \
${VST3_SDK_DIR}/base/source/updatehandler.cpp \
${VST3_SDK_DIR}/base/thread/source/flock.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/coreiids.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/funknown.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/ustring.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/conststringtable.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/macmain.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/pluginfactory.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/moduleinit.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/commoniids.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/pluginview.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponentbase.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponent.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstaudioeffect.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstinitiids.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstbus.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vsteditcontroller.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstparameters.cpp
all: build/bw_example_synth.vst3/Contents/Info.plist build/bw_example_synth.vst3/Contents/PkgInfo build/bw_example_synth.vst3/Contents/MacOS/bw_example_synth
build/bw_example_synth.vst3/Contents/MacOS/bw_example_synth: build/tmp/bw_example_synth-x86_64 build/tmp/bw_example_synth-arm64
mkdir -p build/bw_example_synth.vst3/Contents/MacOS
lipo -create -output $@ $^
build/bw_example_synth.vst3/Contents/Info.plist: build/bw_example_synth.vst3/Contents ${ROOT_DIR}/bw_example_synth.vst3/Contents/Info.plist
cp ${ROOT_DIR}/bw_example_synth.vst3/Contents/Info.plist build/bw_example_synth.vst3/Contents/Info.plist
build/bw_example_synth.vst3/Contents/PkgInfo: build/bw_example_synth.vst3/Contents ${ROOT_DIR}/bw_example_synth.vst3/Contents/PkgInfo
cp ${ROOT_DIR}/bw_example_synth.vst3/Contents/PkgInfo build/bw_example_synth.vst3/Contents/PkgInfo
build/bw_example_synth.vst3/Contents:
mkdir -p $@
build/tmp/bw_example_synth-x86_64: ${SOURCES}
mkdir -p build/tmp
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -arch x86_64 -o $@
build/tmp/bw_example_synth-arm64: ${SOURCES}
mkdir -p build/tmp
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -arch arm64 -o $@
install-user: all
mkdir -p ${HOME}/Library/Audio/Plug-Ins/VST3
@echo mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:${HOME}/Library/Audio/Plug-Ins/VST3/:g`
@mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:${HOME}/Library/Audio/Plug-Ins/VST3/:g`
@for f in `find build/bw_example_synth.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/Library/Audio/Plug-Ins/VST3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${HOME}/Library/Audio/Plug-Ins/VST3/$$d; \
done
install: all
mkdir -p /Library/Audio/Plug-Ins/VST3
@echo mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:/Library/Audio/Plug-Ins/VST3/:g`
@mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s:^build/:/Library/Audio/Plug-Ins/VST3/:g`
@for f in `find build/bw_example_synth.vst3 -type f | sed s:^build/::g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f /Library/Audio/Plug-Ins/VST3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f /Library/Audio/Plug-Ins/VST3/$$d; \
done
clean:
rm -fr build/bw_example_synth.vst3 build/tmp

View File

@ -0,0 +1,99 @@
VST3_SDK_DIR=${ROOT_DIR}/../../../../VST_SDK/vst3sdk
CXX=g++
CXXFLAGS= \
-DRELEASE=1 \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/vst3 \
-I${ROOT_DIR}/../../../include \
-I${VST3_SDK_DIR} \
-fPIC \
-O3
LDFLAGS= \
-shared \
-static \
-static-libgcc \
-static-libstdc++ \
-lole32
#ARCH=x86
ARCH=x86_64
#ARCH=arm64ec
#ARCH=arm
#ARCH=arm64
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_phase_gen.c \
${ROOT_DIR}/../../../src/bw_osc_pulse.c \
${ROOT_DIR}/../../../src/bw_osc_post_filter.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_gen.c \
${ROOT_DIR}/../../../src/bw_vol.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_synth.c \
\
${ROOT_DIR}/../../common/vst3/entry.cpp \
${ROOT_DIR}/../../common/vst3/plugin.cpp \
${ROOT_DIR}/../../common/vst3/controller.cpp \
\
${VST3_SDK_DIR}/base/source/fobject.cpp \
${VST3_SDK_DIR}/base/source/baseiids.cpp \
${VST3_SDK_DIR}/base/source/fstreamer.cpp \
${VST3_SDK_DIR}/base/source/fstring.cpp \
${VST3_SDK_DIR}/base/source/fbuffer.cpp \
${VST3_SDK_DIR}/base/source/updatehandler.cpp \
${VST3_SDK_DIR}/base/thread/source/flock.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/coreiids.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/funknown.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/ustring.cpp \
${VST3_SDK_DIR}/pluginterfaces/base/conststringtable.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/dllmain.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/pluginfactory.cpp \
${VST3_SDK_DIR}/public.sdk/source/main/moduleinit.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/commoniids.cpp \
${VST3_SDK_DIR}/public.sdk/source/common/pluginview.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponentbase.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstcomponent.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstaudioeffect.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstinitiids.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstbus.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vsteditcontroller.cpp \
${VST3_SDK_DIR}/public.sdk/source/vst/vstparameters.cpp
DLL_DIR=build/bw_example_synth.vst3/Contents/${ARCH}-win
USER_PREFIX=$(shell echo '${LOCALAPPDATA}' | sed 's:\\:/:g')
all: build/bw_example_synth.vst3/desktop.ini build/bw_example_synth.vst3/Plugin.ico build/bw_example_synth.vst3/Contents/Resources ${DLL_DIR}/bw_example_synth.vst3
${DLL_DIR}/bw_example_synth.vst3: ${SOURCES}
mkdir -p ${DLL_DIR}
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -o $@
build/bw_example_synth.vst3/desktop.ini: build/bw_example_synth.vst3 ${ROOT_DIR}/bw_example_synth.vst3/desktop.ini
cp ${ROOT_DIR}/bw_example_synth.vst3/desktop.ini build/bw_example_synth.vst3
build/bw_example_synth.vst3/Plugin.ico: build/bw_example_synth.vst3 ${ROOT_DIR}/bw_example_synth.vst3/Plugin.ico
cp ${ROOT_DIR}/bw_example_synth.vst3/Plugin.ico build/bw_example_synth.vst3
build/bw_example_synth.vst3/Contents/Resources: build/bw_example_synth.vst3/Contents ${ROOT_DIR}/bw_example_synth.vst3/Contents/Resources
cp -R ${ROOT_DIR}/bw_example_synth.vst3/Contents/Resources build/bw_example_synth.vst3/Contents
build/bw_example_synth.vst3/Contents: build/bw_example_synth.vst3
mkdir -p $@
build/bw_example_synth.vst3:
mkdir -p $@
install-user: all
mkdir -p ${USER_PREFIX}/Programs/Common/VST3
@echo mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s?^build/?${USER_PREFIX}/Programs/Common/VST3/?g`
@mkdir -p -m 0755 `find build/bw_example_synth.vst3 -type d | sed s?^build/?${USER_PREFIX}/Programs/Common/VST3/?g`
@for f in `find build/bw_example_synth.vst3 -type f | sed s?^build/??g`; do \
d=`dirname $$f`; \
echo install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${USER_PREFIX}/Programs/Common/VST3/$$d; \
install -m `[ -x build/$$f ] && echo 0755 || echo 0644` build/$$f ${USER_PREFIX}/Programs/Common/VST3/$$d; \
done
clean:
rm -fr build/bw_example_synth.vst3

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>bw_example_synth</string>
<key>CFBundleExecutable</key>
<string>bw_example_synth</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
BNDL????

View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@ -0,0 +1,19 @@
sse2neon is freely redistributable under the MIT License.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=Plugin.ico,0

View File

@ -0,0 +1,35 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File authors: Stefano D'Angelo, Paolo Marrone
*/
#ifndef _VST3_CONFIG_H
#define _VST3_CONFIG_H
#define PLUGIN_SUBCATEGORY "Instrument|Synth"
#define PLUGIN_GUID_1 0x78a77ca9
#define PLUGIN_GUID_2 0xab3d4655
#define PLUGIN_GUID_3 0x8840a961
#define PLUGIN_GUID_4 0x51f2a6f9
#define CTRL_GUID_1 0xe44829aa
#define CTRL_GUID_2 0xb0e046ae
#define CTRL_GUID_3 0x9e9195a0
#define CTRL_GUID_4 0x83867d48
#endif

View File

@ -0,0 +1,65 @@
CC=clang
CFLAGS= \
-I${ROOT_DIR}/../src \
-I${ROOT_DIR}/../../common/web \
-I${ROOT_DIR}/../../../include \
--target=wasm32 \
-flto \
-fvisibility=hidden \
#-Ofast - had to turn this off as there are issues with wasm bulk memory
LDFLAGS= \
-Wl,--allow-undefined \
-Wl,--no-entry \
-Wl,--lto-O3 \
-Wl,-strip-all \
-Wl,--export-table \
-Wl,--export=wrapper_new \
-Wl,--export=wrapper_free \
-Wl,--export=wrapper_get_ins \
-Wl,--export=wrapper_get_outs \
-Wl,--export=wrapper_get_param_values \
-Wl,--export=wrapper_process \
-Wl,--export=wrapper_set_parameter \
-Wl,--export=wrapper_note_on \
-Wl,--export=wrapper_note_off \
-Wl,-z,stack-size=$$((8*1024*1024)) \
-nostdlib
ROOT_DIR=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES= \
${ROOT_DIR}/../../../src/bw_phase_gen.c \
${ROOT_DIR}/../../../src/bw_osc_pulse.c \
${ROOT_DIR}/../../../src/bw_osc_filt.c \
${ROOT_DIR}/../../../src/bw_svf.c \
${ROOT_DIR}/../../../src/bw_env_gen.c \
${ROOT_DIR}/../../../src/bw_vol.c \
${ROOT_DIR}/../../../src/bw_env_follow.c \
${ROOT_DIR}/../../../src/bw_one_pole.c \
${ROOT_DIR}/../src/bw_example_synth.c \
${ROOT_DIR}/../../common/web/walloc.c \
${ROOT_DIR}/../../common/web/wrapper.c
all: build/web/module.wasm build/web/index.html build/web/config.js build/web/processor.js build/web/cert.pem build/web/key.pem
build/web/module.wasm: build/web ${SOURCES}
${CC} ${SOURCES} ${CFLAGS} ${LDFLAGS} -o $@
build/web/index.html: build/web ${ROOT_DIR}/index.html
cp ${ROOT_DIR}/index.html $@
build/web/processor.js: build/web ${ROOT_DIR}/config.js ${ROOT_DIR}/../../common/web/processor.js
cat ${ROOT_DIR}/config.js ${ROOT_DIR}/../../common/web//processor.js > $@
build/web/config.js: build/web ${ROOT_DIR}/config.js
cp ${ROOT_DIR}/config.js $@
build/web/key.pem: build/web/cert.pem
build/web/cert.pem: build/web
yes "" | openssl req -x509 -newkey rsa:2048 -keyout build/web/key.pem -out build/web/cert.pem -days 365 -nodes 2>/dev/null
build/web:
mkdir -p build/web
clean:
rm -fr build/web

View File

@ -0,0 +1,83 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
var buses = [
{
stereo: false,
output: true
}
];
var parameters = [
{
name: "Volume",
output: false,
defaultValue: 0.5
},
{
name: "Master tune",
output: false,
defaultValue: 0.5
},
{
name: "Portamento",
output: false,
defaultValue: 0.0
},
{
name: "Pulse width",
output: false,
defaultValue: 0.5
},
{
name: "Cutoff",
output: false,
defaultValue: 1.0
},
{
name: "Q",
output: false,
defaultValue: 0.0
},
{
name: "Attack",
output: false,
defaultValue: 0.0
},
{
name: "Decay",
output: false,
defaultValue: 0.0
},
{
name: "Sustain",
output: false,
defaultValue: 1.0
},
{
name: "Release",
output: false,
defaultValue: 0.0
},
{
name: "Level",
output: true,
defaultValue: 0.0
}
];

View File

@ -0,0 +1,142 @@
<!DOCTYPE html>
<html>
<head>
<title>Brickworks web synth example</title>
<script src="config.js"></script>
<script>
var audioCtx;
var midi;
var Synth = {
node: null,
moduleAdded: false,
wasmBytes: null,
init: async function () {
if (!this.moduleAdded) {
await audioCtx.audioWorklet.addModule("processor.js");
this.moduleAdded = true;
}
if (!this.wasmBytes)
this.wasmBytes = await fetch("module.wasm")
.then((response) => response.arrayBuffer())
.then((bytes) => bytes);
if (!this.wasmBytes.byteLength) {
this.wasmBytes = null;
throw "could not fetch WebAssembly module";
}
if (!this.node)
this.node = new AudioWorkletNode(audioCtx, "BWExample",
{
numberOfInputs: 0,
numberOfOutputs: 1,
outputChannelCount: [ 1 ],
processorOptions: { wasmBytes: this.wasmBytes }
});
this.node.connect(audioCtx.destination);
},
noteOn: function (note, velocity) {
this.node.port.postMessage({ type: "noteOn", note: note, velocity: velocity });
},
noteOff: function (note) {
this.node.port.postMessage({ type: "noteOff", note: note });
}
};
var initState = 0; // 0 = not inited, 1 = in progress, 2 = inited
window.addEventListener("load", async function (e) {
var start = document.getElementById("start");
var starting = document.getElementById("starting");
var main = document.getElementById("main");
var controls = document.getElementById("controls");
if (!navigator.requestMIDIAccess) {
alert("This won't work. Your browser doesn't support the Web MIDI API.");
return;
}
for (var i = 0; i < parameters.length; i++) {
var div = document.createElement("div");
controls.appendChild(div);
var label = document.createElement("label");
label.setAttribute("for", "p" + i);
label.innerText = parameters[i].name;
div.appendChild(label);
var range = document.createElement("input");
range.setAttribute("type", "range");
range.setAttribute("id", "p" + i);
range.setAttribute("name", "p" + i);
range.setAttribute("min", "0");
range.setAttribute("max", "1");
range.setAttribute("step", "any");
range.value = parameters[i].defaultValue;
if (parameters[i].output)
range.setAttribute("readonly", "true");
else {
let index = i;
range.addEventListener("input", function (e) {
var p = Synth.node.parameters.get(parameters[index].name);
p.setValueAtTime(e.target.value, 0);
});
}
div.appendChild(range);
}
start.addEventListener("click", async function () {
initState = 1;
start.disabled = true;
starting.hidden = false;
try {
if (!audioCtx)
audioCtx = new AudioContext();
midi = await navigator.requestMIDIAccess();
await Synth.init();
Synth.node.port.onmessage = function (e) { document.getElementById("p" + e.data.index).value = e.data.value; };
function onMIDIMessage(e) {
switch (e.data[0] & 0xf0) {
case 0x90:
Synth.noteOn(e.data[1], e.data[2]);
break;
case 0x80:
Synth.noteOff(e.data[1]);
break;
}
}
midi.inputs.forEach((entry) => { entry.onmidimessage = onMIDIMessage; });
initState = 2;
start.hidden = true;
starting.hidden = true;
main.hidden = false;
} catch (err) {
alert("Colud not initialize: " + err);
initState = 0;
start.disabled = false;
starting.hidden = true;
}
});
});
</script>
</head>
<body>
<h1>Brickworks web synth example</h1>
<input id="start" type="button" value="Start">
<p id="starting" hidden>Starting...</p>
<div id="main" hidden>
<p>Just play notes on your MIDI device.</p>
<div id="controls">
</div>
</div>
</body>
</html>

100
include/bw_common.h Normal file
View File

@ -0,0 +1,100 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ foundation }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config }}}
* description {{{
* A common header to make sure that a bunch of basic definitions are
* available and consistent for all Brickworks modules.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_COMMON_H
#define _BW_COMMON_H
/*! api {{{
* #### bw_config
* At its very beginning, this header `#include`s `<bw_config.h>`, which is
* a file you can use to supply custom `#include`s and `#define`s that
* override defaults (see [bw_config](bw_config)).
*
* Alternatively, your compiler probably allows you to specify definitions on
* the command line.
* >>> */
#include <bw_config.h>
/*! ...
* #### NULL
* If `NULL` is not defined, then `stddef.h` is `#include`d.
* >>> */
#ifndef NULL
# include <stddef.h>
#endif
/*! ...
* #### Exact-width integer types
* If <code class="hljs">(u)int{8,16,32,64}_t</code>,
* `INT{8,16,32,64}_{MIN,MAX}`, and `UINT{8,16,32,64}_MAX` are not defined,
* then `stdint.h` is `#include`d (actually, only testing against
* `INT32_MAX` but expecting the others to be finally defined).
* >>> */
#ifndef INT32_MAX
# include <stdint.h>
#endif
/*! ...
* #### INFINITY
* If `INFINITY` is not defined, then `math.h` is `#include`d.
* >>> */
#ifndef INFINITY
# include <math.h>
#endif
/*! ...
* #### BW_MALLOC, BW_REALLOC, BW_FREE
* If any of these is not defined, then `stdlib.h` is `#include`d and the
* missing ones are defined as `malloc`, `realloc`, or `free`, respectively.
* >>> */
#if !defined(BW_MALLOC) || !defined(BW_REALLOC) || !defined(BW_FREE)
# include <stdlib.h>
# ifndef BW_MALLOC
# define BW_MALLOC malloc
# endif
# ifndef BW_REALLOC
# define BW_REALLOC realloc
# endif
# ifndef BW_FREE
# define BW_FREE free
# endif
#endif
/*! ... }}} */
#endif

52
include/bw_config.h Normal file
View File

@ -0,0 +1,52 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ foundation }}}
* version {{{ 0.1.0 }}}
* description {{{
* Just an empty header file that is always included at the beginning of
* [bw_common.h](bw_common).
*
* Such inclusion is done with angle brackets (i.e.,
* `#include <bw_config.h>`), so you can "override" such file with a custom
* one you provide and appropriately set compiler include path order, or
* otherwise just modify it to your needs.
*
* Its intended purpose is to allow you to `#include` needed files and
* `#define` values/macros that affect Brickworks modules
* (see [bw_common](bw_common)).
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_CONFIG_H
#define _BW_CONFIG_H
// Your definitions here
#endif

128
include/bw_env_follow.h Normal file
View File

@ -0,0 +1,128 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math bw_one_pole }}}
* description {{{
* Envelope follower made of a full-wave rectifier followed by
* [bw_one_pole](bw_one_pole) one-pole filter (6 dB/oct).
*
* Unlike other dsp modules, you can directly access the parameters of the
* internal one-pole filter via the `bw_env_follow_get_one_pole()` function.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_ENV_FOLLOW_H
#define _BW_ENV_FOLLOW_H
#include <bw_one_pole.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_env_follow
* ```>>> */
typedef struct _bw_env_follow *bw_env_follow;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_env_follow_new()
* ```>>> */
bw_env_follow bw_env_follow_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_env_follow_free()
* ```>>> */
void bw_env_follow_free(bw_env_follow instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_env_follow_set_sample_rate()
* ```>>> */
void bw_env_follow_set_sample_rate(bw_env_follow instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_env_follow_reset()
* ```>>> */
void bw_env_follow_reset(bw_env_follow instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_env_follow_process()
* ```>>> */
void bw_env_follow_process(bw_env_follow instance, const float *x, float *y, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` and fills the corresponding `n_samples` samples in the output
* buffer `y`.
* >>> */
/*! ...
* #### bw_env_follow_get_one_pole()
* ```>>> */
bw_one_pole bw_env_follow_get_one_pole(bw_env_follow instance);
/*! <<<```
* Returns the handle to the internal one-pole filter of the given
* `instance`.
*
* The returned handle must not be used for any other purpose than setting
* its parameters.
*
* This is **NOT** a function that gets an output parameter as described in
* the [documentation for DSP modules](api#dsp).
*
* This function is [reentrant](api#reentrant-function),
* [RT-safe](api#rt-safe-function),
* [**NOT** thread-safe](api#thread-safe-function), and has
* [no side effects](api#no-side-effects).
* }}} */
#ifdef __cplusplus
}
#endif
#endif

179
include/bw_env_gen.h Normal file
View File

@ -0,0 +1,179 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_inline_one_pole bw_math }}}
* description {{{
* Linear ADSR envelope generator.
*
* * In the off state (gate off and possible previous release phase ended),
* the output is `0.f`;
* * in the attack phase the output increases from `0.f` to `1.f`;
* * in the decay phase the output decreases from `1.f` to the given sustain
* level;
* * in the sustain phase the output stays constant;
* * in the release phase the output decreases from the current level to
* `0.f`.
*
* Attack, decay, and release time parameters are not actually controlling
* times but rather slopes. If all phases of the ADSR fully execute, then the
* actual times will match the parameter settings.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_ENV_GEN_H
#define _BW_ENV_GEN_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_env_gen
* ```>>> */
typedef struct _bw_env_gen *bw_env_gen;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_env_gen_new()
* ```>>> */
bw_env_gen bw_env_gen_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_env_gen_free()
* ```>>> */
void bw_env_gen_free(bw_env_gen instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_env_gen_set_sample_rate()
* ```>>> */
void bw_env_gen_set_sample_rate(bw_env_gen instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_env_gen_reset()
* ```>>> */
void bw_env_gen_reset(bw_env_gen instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_env_gen_process()
* ```>>> */
void bw_env_gen_process(bw_env_gen instance, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` generate `n_samples` samples and puts them in
* the output buffer `y`.
* >>> */
/*! ...
* #### bw_env_gen_set_gate()
* ```>>> */
void bw_env_gen_set_gate(bw_env_gen instance, char value);
/*! <<<```
* Sets the input gate to be either off (`0`) or on (non-`0`) for the given
* `instance`.
*
* Default value: `0` (off).
* >>> */
/*! ...
* #### bw_env_gen_set_attack()
* ```>>> */
void bw_env_gen_set_attack(bw_env_gen instance, float value);
/*! <<<```
* Sets the attack time to `value` (s) for the given `instance`.
*
* `value` must be smaller than `1e9f`.
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_env_gen_set_decay()
* ```>>> */
void bw_env_gen_set_decay(bw_env_gen instance, float value);
/*! <<<```
* Sets the decay time to `value` (s) for the given `instance`.
*
* `value` must be smaller than `1e9f`.
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_env_gen_set_sustain()
* ```>>> */
void bw_env_gen_set_sustain(bw_env_gen instance, float value);
/*! <<<```
* Sets the sustain level to `value` for the given `instance`.
*
* Default value: `1.f`.
* >>> */
/*! ...
* #### bw_env_gen_set_release()
* ```>>> */
void bw_env_gen_set_release(bw_env_gen instance, float value);
/*! <<<```
* Sets the release time to `value` (s) for the given `instance`.
*
* `value` must be smaller than `1e9f`.
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_env_gen_get_is_off()
* ```>>> */
char bw_env_gen_get_is_off(bw_env_gen instance);
/*! <<<```
* Returns `0` if the given `instance` is in the off state, non-`0` otherwise.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,118 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ utility }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math }}}
* description {{{
* Inline one-pole (6 dB/oct) lowpass filter with unitary DC gain and sticky
* target-reach threshold.
*
* This is similar to [bw_one_pole](bw_one_pole) but can be used to process
* on a sample-by-sample basis without buffers.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_INLINE_ONE_POLE_H
#define _BW_INLINE_ONE_POLE_H
#include <bw_math.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_inline_one_pole_get_mA1()
* ```>>> */
static inline float bw_inline_one_pole_get_mA1(float sample_rate, float tau);
/*! <<<```
* Computes the `mA1` coefficient requested by other functions in this
* module, corresponding to the given `sample_rate` (Hz) and time constant
* `tau` (s) values.
* >>> */
/*! ...
* #### bw_inline_one_pole()
* ```>>> */
static inline float bw_inline_one_pole(float x, float y_z1, float mA1);
/*! <<<```
* Processes one input sample `x`, using the previous output value `y_z1` and
* the `mA1` coefficient, and returns the corresponding output sample.
*
* This function does not feature sticky target-reach threshold.
* >>> */
/*! ...
* #### bw_inline_one_pole_sticky_abs()
* ```>>> */
static inline float bw_inline_one_pole_sticky_abs(float x, float y_z1, float mA1, float thresh_sq);
/*! <<<```
* Like `bw_inline_one_pole()` but when the absolute difference between the
* output and the input (|*value to be returned* - `x`|) would be smaller
* than the square root of `thresh_sq`, it just returns `x`.
* >>> */
/*! ...
* #### bw_inline_one_pole_sticky_rel()
* ```>>> */
static inline float bw_inline_one_pole_sticky_rel(float x, float y_z1, float mA1, float thresh_sq);
/*! <<<```
* Like `bw_inline_one_pole()` but when the relative difference of the output
* with respect to the input (|*value to be returned* - `x`| / |`x`|) would
* be smaller than the square root of `thresh_sq`, it just returns `x`.
* }}} */
/* Implementation */
static inline float bw_inline_one_pole_get_mA1(float sample_rate, float tau) {
return bw_expf_3(-bw_rcpf_2(sample_rate * tau));
}
static inline float bw_inline_one_pole(float x, float y_z1, float mA1) {
return x + mA1 * (y_z1 - x);
}
static inline float bw_inline_one_pole_sticky_abs(float x, float y_z1, float mA1, float thresh_sq) {
float y = bw_inline_one_pole(x, y_z1, mA1);
const float d = x - y;
return d * d < thresh_sq ? x : y;
}
static inline float bw_inline_one_pole_sticky_rel(float x, float y_z1, float mA1, float thresh_sq) {
float y = bw_inline_one_pole(x, y_z1, mA1);
const float d = x - y;
return d * d < thresh_sq * (x * x) ? x : y;
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,89 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ utility }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math }}}
* description {{{
* Inline slew-rate limiter.
*
* This is similar to [bw_slew_lim](bw_slew_lim) but can be used to process
* on a sample-by-sample basis without buffers.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_INLINE_SLEW_LIM_H
#define _BW_INLINE_SLEW_LIM_H
#include <bw_math.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_inline_slew_lim_get_max_var()
* ```>>> */
static inline float bw_inline_slew_lim_get_max_var(float sample_rate, float rate);
/*! <<<```
* Computes a maximum variation coefficient to be used with
* `bw_inline_slew_lim()` corresponding to the given `sample_rate` (Hz) and
* `rate` (1/s) values.
*
* `rate` represents the maximum variation per second and must be finite and
* non-negative.
* >>> */
/*! ...
* #### bw_inline_slew_lim()
* ```>>> */
static inline float bw_inline_slew_lim(float x, float y_z1, float max_inc, float max_dec);
/*! <<<```
* Processes one input sample `x`, using the previous output value `y_z1` and
* the maximum variation coefficients `max_inc` and `max_dec`, and returns
* the corresponding output sample.
*
* Both `max_inc` and `max_dec` must be finite and non-negative.
* }}} */
/* Implementation */
static inline float bw_inline_slew_lim_get_max_var(float sample_rate, float rate) {
return rate * bw_rcpf_2(sample_rate);
}
static inline float bw_inline_slew_lim(float x, float y_z1, float max_inc, float max_dec) {
return bw_clipf(x, y_z1 - max_dec, y_z1 + max_inc);
}
#ifdef __cplusplus
}
#endif
#endif

553
include/bw_math.h Normal file
View File

@ -0,0 +1,553 @@
/*
* Brickworks
*
* Copyright (C) 2021, 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*
* Part of the code in this file is derived from omega.h by Stefano D'Angelo,
* which is released under the following conditions:
*
* Copyright (C) 2019 Stefano D'Angelo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Such part is itself based on the theory in
*
* S. D'Angelo, L. Gabrielli, and L. Turchet, "Fast Approximation of the
* Lambert W Function for Virtual Analog Modeling", 22nd Intl. Conf. Digital
* Audio Effects (DAFx-19), Birmingham, UK, September 2019.
*/
/*!
* module_type {{{ utility }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_common bw_config }}}
* description {{{
* A collection of mathematical routines that strive to be better suited to
* DSP than, e.g., those supplied by your C standard library.
*
* Such a goal is hopefully accomplished by:
* * being as branchless as reasonable/convenient;
* * not handling uninteresting corner cases, such as invalid,
* infinity, and NaN input values;
* * returning approximated results (indicated in this documentation).
*
* In practice they should guarantee fast and consistent performance, but
* always do your own benchmarking.
*
* All functions in this module are [reentrant](api#reentrant-function),
* [RT-safe](api#rt-safe-function), [thread-safe](api#thread-safe-function),
* and have [no side effects](api#no-side-effects).
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_MATH_H
#define _BW_MATH_H
#include <bw_common.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_signfilli32()
* ```>>> */
static inline int32_t bw_signfilli32(int32_t x);
/*! <<<```
* Returns `~0` if `x` is negative, `0` otherwise.
* >>> */
/*! ...
* #### bw_mini32()
* ```>>> */
static inline int32_t bw_mini32(int32_t a, int32_t b);
/*! <<<```
* Returns the minimum of `a` and `b`.
* >>> */
/*! ...
* #### bw_maxi32()
* ```>>> */
static inline int32_t bw_maxi32(int32_t a, int32_t b);
/*! <<<```
* Returns the maximum of `a` and `b`.
* >>> */
/*! ...
* #### bw_clipi32()
* ```>>> */
static inline int32_t bw_clipi32(int32_t x, int32_t m, int32_t M);
/*! <<<```
* Returns `x` unless it is smaller than `m`, in which case it returns `m`,
* or bigger than `M`, in which case it returns `M`.
* >>> */
/*! ...
* #### bw_minu32()
* ```>>> */
static inline uint32_t bw_minu32(uint32_t a, uint32_t b);
/*! <<<```
* Returns the minimum of `a` and `b`.
* >>> */
/*! ...
* #### bw_maxu32()
* ```>>> */
static inline uint32_t bw_maxu32(uint32_t a, uint32_t b);
/*! <<<```
* Returns the maximum of `a` and `b`.
* >>> */
/*! ...
* #### bw_clipu32()
* ```>>> */
static inline uint32_t bw_clipu32(uint32_t x, uint32_t m, uint32_t M);
/*! <<<```
* Returns `x` unless it is smaller than `m`, in which case it returns `m`,
* or bigger than `M`, in which case it returns `M`.
* >>> */
/*! ...
* #### bw_copysignf()
* ```>>> */
static inline float bw_copysignf(float x, float y);
/*! <<<```
* Returns a value that has the absolute value of `x` and the sign of `y`.
* >>> */
/*! ...
* #### bw_signf()
* ```>>> */
static inline float bw_signf(float x);
/*! <<<```
* Returns `1.f` if `x > 0.f`, `-1.f` if `x < 0.f` and `0.f` if `x == 0.f`.
* >>> */
/*! ...
* #### bw_absf()
* ```>>> */
static inline float bw_absf(float x);
/*! <<<```
* Returns the absolute value of `x`.
* >>> */
/*! ...
* #### bw_min0xf()
* ```>>> */
static inline float bw_min0xf(float x);
/*! <<<```
* Returns the minimum of `0.f` and `x`.
*
* `x` must be finite.
* >>> */
/*! ...
* #### bw_max0xf()
* ```>>> */
static inline float bw_max0xf(float x);
/*! <<<```
* Returns the maximum of `0.f` and `x`.
*
* `x` must be finite.
* >>> */
/*! ...
* #### bw_minf()
* ```>>> */
static inline float bw_minf(float a, float b);
/*! <<<```
* Returns the minimum of `a` and `b`.
*
* `a` and `b` must be finite.
* >>> */
/*! ...
* #### bw_maxf()
* ```>>> */
static inline float bw_maxf(float a, float b);
/*! <<<```
* Returns the maximum of `a` and `b`.
*
* `a` and `b` must be finite.
* >>> */
/*! ...
* #### bw_clipf()
* ```>>> */
static inline float bw_clipf(float x, float m, float M);
/*! <<<```
* Returns `x` unless it is smaller than `m`, in which case it returns `m`,
* or bigger than `M`, in which case it returns `M`.
*
* `x`, `m`, and `M` must be finite.
* >>> */
/*! ...
* #### bw_truncf()
* ```>>> */
static inline float bw_truncf(float x);
/*! <<<```
* Returns `x` with its fractional part set to zero (i.e., rounded towards
* zero).
* >>> */
/*! ...
* #### bw_roundf()
* ```>>> */
static inline float bw_roundf(float x);
/*! <<<```
* Returns `x` rounded to the nearest integer.
*
* Halfway cases are rounded away from zero. E.g., `bw_roundf(0.5f)` gives
* `1.f` and `bw_roundf(-0.5f)` gives `-1.f`.
* >>> */
/*! ...
* #### bw_floorf()
* ```>>> */
static inline float bw_floorf(float x);
/*! <<<```
* Returns the biggest integer lower or equal than `x` (i.e., `x` is rounded
* down).
* >>> */
/*! ...
* #### bw_rcpf_2()
* ```>>> */
static inline float bw_rcpf_2(float x);
/*! <<<```
* Returns the reciprocal of `x` (i.e., `1.f / x`).
*
* Not guaranteed to work for `x` having exponent too big or too small. Safe
* range: |`x`| in [2^-90, 2^90].
*
* Relative error < 0.0013%.
* >>> */
/*! ...
* #### bw_sinf_3()
* ```>>> */
static inline float bw_sinf_3(float x);
/*! <<<```
* Returns an approximation of the sine of `x`, where `x` is given in
* radians.
*
* Absolute error < 0.011, relative error < 1.7%.
* >>> */
/*! ...
* #### bw_cosf_3()
* ```>>> */
static inline float bw_cosf_3(float x);
/*! <<<```
* Returns an approximation of the cosine of `x`, where `x` is given in
* radians.
*
* Absolute error < 0.011, relative error < 1.7%.
* >>> */
/*! ...
* #### bw_tanf_div_3()
* ```>>> */
static inline float bw_tanf_3(float x);
/*! <<<```
* Returns an approximation of the tangent of `x`, where `x` is given in
* radians.
*
* Not guaranteed to work for `x` too close to singularities. Safe
* range: `x` in [-pi/2 + 1e-3f, pi/2 - 1e-3f] + k * pi, where k is any
* integer number.
*
* Absolute error < 0.06, relative error < 0.8%.
* >>> */
/*! ...
* #### bw_log2f_3()
* ```>>> */
static inline float bw_log2f_3(float x);
/*! <<<```
* Returns an approximation of the base-2 logarithm of `x`.
*
* Absolute error < 0.0055, relative error < 1.5%.
* >>> */
/*! ...
* #### bw_logf_3()
* ```>>> */
static inline float bw_logf_3(float x);
/*! <<<```
* Returns an approximation of the natural logarithm of `x`.
*
* Absolute error < 0.0039, relative error < 1.5%.
* >>> */
/*! ...
* #### bw_pow2f_3()
* ```>>> */
static inline float bw_pow2f_3(float x);
/*! <<<```
* Returns an approximation of 2 raised to the power of `x`.
*
* Relative error < 0.062%.
* >>> */
/*! ...
* #### bw_expf_3()
* ```>>> */
static inline float bw_expf_3(float x);
/*! <<<```
* Returns an approximation of e (Euler's number) raised to the power of `x`.
*
* Relative error < 0.062%.
* >>> */
/*! ...
* #### bw_omega_3log()
* ```>>> */
static inline float bw_omega_3log(float x);
/*! <<<```
* Returns an approximation of `omega(x)`, where `omega` is the <a
* href="https://en.wikipedia.org/wiki/Wright_omega_function"
* target="_blank">Wright omega function</a>.
*
* Absolute error < 0.027, relative error < 12% for non-negative input and
* decreasing with increasing input, goes rapidly to 100% for progressively
* more negative input.
* >>> */
/*! ...
* #### bw_sqrtf_2()
* ```>>> */
static inline float bw_sqrtf_2(float x);
/*! <<<```
* Returns an approximation of the square root of `x`.
*
* Relative error < 0.0007%.
* }}} */
/* Implementation */
typedef union {
float f;
int32_t i;
uint32_t u;
} _bw_floatint;
// I hope the target architecture and compiler will use conditional ops here
static inline int32_t bw_signfilli32(int32_t x) {
return x < 0 ? ~0 : 0;
}
static inline int32_t bw_mini32(int32_t a, int32_t b) {
return a < b ? a : b;
}
static inline int32_t bw_maxi32(int32_t a, int32_t b) {
return a > b ? a : b;
}
static inline int32_t bw_clipi32(int32_t x, int32_t m, int32_t M) {
return x < m ? m : (x > M ? M : x);
}
static inline uint32_t bw_minu32(uint32_t a, uint32_t b) {
return a < b ? a : b;
}
static inline uint32_t bw_maxu32(uint32_t a, uint32_t b) {
return a > b ? a : b;
}
static inline uint32_t bw_clipu32(uint32_t x, uint32_t m, uint32_t M) {
return x < m ? m : (x > M ? M : x);
}
// Here instead I don't trust C semantics to get close to conditional ops for
// floating point numbers
static inline float bw_copysignf(float x, float y) {
_bw_floatint v = {.f = x};
_bw_floatint s = {.f = y};
v.i = (v.i & 0x7fffffff) | (s.i & 0x80000000);
return v.f;
}
static inline float bw_signf(float x) {
static const float y[4] = { 0.f, 1.f, 0.f, -1.f };
_bw_floatint v = {.f = x};
return y[bw_minu32(v.u & 0x7fffffff, 1) | ((v.u >> 30) & 0x2)];
}
static inline float bw_absf(float x) {
_bw_floatint v = {.f = x};
v.i = v.i & 0x7fffffff;
return v.f;
}
static inline float bw_min0xf(float x) {
return 0.5f * (x - bw_absf(x));
}
static inline float bw_max0xf(float x) {
return 0.5f * (x + bw_absf(x));
}
static inline float bw_minf(float a, float b) {
return a + bw_min0xf(b - a);
}
static inline float bw_maxf(float a, float b) {
return a + bw_max0xf(b - a);
}
static inline float bw_clipf(float x, float m, float M) {
return bw_minf(bw_maxf(x, m), M);
}
static inline float bw_truncf(float x) {
_bw_floatint v = {.f = x};
int32_t ex = (v.i & 0x7f800000) >> 23;
int32_t m = (~0) << bw_clipi32(150 - ex, 0, 23);
m &= bw_signfilli32(126 - ex) | 0x80000000;
v.i &= m;
return v.f;
}
static inline float bw_roundf(float x) {
_bw_floatint v = {.f = x};
int32_t ex = (v.i & 0x7f800000) >> 23;
int32_t sh = bw_clipi32(150 - ex, 0, 23);
int32_t mt = (~0) << sh;
mt &= bw_signfilli32(126 - ex) | 0x80000000;
int32_t mr = (1 << sh) >> 1;
mr &= bw_signfilli32(125 - ex);
_bw_floatint s = {.f = bw_copysignf(1.f, x)};
int32_t ms = bw_signfilli32((v.i & mr) << (32 - sh));
v.i &= mt;
s.i &= ms;
return v.f + s.f;
}
static inline float bw_floorf(float x) {
_bw_floatint t = {.f = bw_truncf(x)}; // first bit set when t < 0
_bw_floatint y = {.f = x - t.f}; // first bit set when t > x
_bw_floatint s = {.f = 1.f};
s.i &= bw_signfilli32(t.i & y.i);
return t.f - s.f;
}
static inline float bw_rcpf_2(float x) {
_bw_floatint v = {.f = x};
v.i = 0x7ef0e840 - v.i;
v.f = v.f + v.f - x * v.f * v.f;
v.f = v.f + v.f - x * v.f * v.f;
return v.f;
}
static inline float bw_sinf_3(float x) {
x = 0.1591549430918953f * x;
x = x - bw_floorf(x);
float xp1 = x + x - 1.f;
float xp2 = bw_absf(xp1);
float xp = 1.570796326794897f - 1.570796326794897f * bw_absf(xp2 + xp2 - 1.f);
return -bw_copysignf(1.f, xp1) * (xp + xp * xp * (-0.05738534102710938f - 0.1107398163618408f * xp));
}
static inline float bw_cosf_3(float x) {
return bw_sinf_3(x + 1.570796326794896f);
}
static inline float bw_tanf_3(float x) {
return bw_sinf_3(x) * bw_rcpf_2(bw_cosf_3(x));
}
static inline float bw_log2f_3(float x) {
_bw_floatint v = {.f = x};
int e = v.i >> 23;
v.i = (v.i & 0x007fffff) | 0x3f800000;
return (float)e - 129.213475204444817f + v.f * (3.148297929334117f + v.f * (-1.098865286222744f + v.f * 0.1640425613334452f));
}
static inline float bw_logf_3(float x) {
return 0.693147180559945f * bw_log2f_3(x);
}
static inline float bw_pow2f_3(float x) {
if (x < -126.f)
return 0.f;
_bw_floatint v = {.f = x};
int xi = (int)x;
int l = xi - ((v.i >> 31) & 1);
float f = x - (float)l;
v.i = (l + 127) << 23;
return v.f + v.f * f * (0.6931471805599453f + f * (0.2274112777602189f + f * 0.07944154167983575f));
}
static inline float bw_expf_3(float x) {
return bw_pow2f_3(1.442695040888963f * x);
}
static inline float bw_omega_3log(float x) {
static const float x1 = -3.341459552768620f;
static const float x2 = 8.f;
static const float a = -1.314293149877800e-3f;
static const float b = 4.775931364975583e-2f;
static const float c = 3.631952663804445e-1f;
static const float d = 6.313183464296682e-1f;
x = bw_maxf(x, x1);
return x <= x2 ? d + x * (c + x * (b + x * a)) : x - bw_logf_3(x);
}
static inline float bw_sqrtf_2(float x) {
_bw_floatint v = {.f = x};
v.u = ((v.u - 0x3f82a127) >> 1) + 0x3f7d8fc7;
float r = bw_rcpf_2(x);
v.f = v.f + v.f * (0.5f + 0.5f * r * v.f * v.f);
v.f = v.f + v.f * (0.5f + 0.5f * r * v.f * v.f);
return v.f;
}
#ifdef __cplusplus
}
#endif
#endif

118
include/bw_noise_gen.h Normal file
View File

@ -0,0 +1,118 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math bw_rand }}}
* description {{{
* Generator of white noise with uniform distribution.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_NOISE_GEN_H
#define _BW_NOISE_GEN_H
#include <bw_common.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_noise_gen
* ```>>> */
typedef struct _bw_noise_gen *bw_noise_gen;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_noise_gen_new()
* ```>>> */
bw_noise_gen bw_noise_gen_new(uint64_t *state);
/*! <<<```
* Creates a new instance which uses the given `state` pointer to obtain
* pseudo-random numbers.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_noise_gen_free()
* ```>>> */
void bw_noise_gen_free(bw_noise_gen instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_noise_gen_set_sample_rate()
* ```>>> */
void bw_noise_gen_set_sample_rate(bw_noise_gen instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` value for the given `instance`.
* >>> */
/*! ...
* #### bw_noise_gen_reset()
*
* There is none (not needed).
* >>> */
/*! ...
* #### bw_noise_gen_process()
* ```>>> */
void bw_noise_gen_process(bw_noise_gen instance, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` generate `n_samples` samples and puts them in
* the output buffer `y`.
* >>> */
/*! ...
* #### bw_noise_gen_set_sample_rate_scaling()
* ```>>> */
void bw_noise_gen_set_sample_rate_scaling(bw_noise_gen instance, char value);
/*! <<<```
* Sets whether the output should be scaled (`value` non-`0`) or not (`0`)
* according to the sample rate by the given `instance`.
*
* In order to maintain the perceived loudness at different sample rates, a
* white noise signal with uniform distribution should be accordingly scaled.
* In this module the 44100 Hz sample rate is used as a reference (that is,
* the scaling factor at that sample rate is `1.f`).
*
* Default value: `0`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

243
include/bw_one_pole.h Normal file
View File

@ -0,0 +1,243 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math }}}
* description {{{
* One-pole (6 dB/oct) lowpass filter with unitary DC gain, separate attack
* and decay time constants, and sticky target-reach threshold.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_ONE_POLE_H
#define _BW_ONE_POLE_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_one_pole
* ```>>> */
typedef struct _bw_one_pole *bw_one_pole;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_one_pole_sticky_mode
* ```>>> */
typedef enum {
bw_one_pole_sticky_mode_abs,
bw_one_pole_sticky_mode_rel
} bw_one_pole_sticky_mode;
/*! <<<```
* Distance metrics for sticky behavior:
* * `bw_one_pole_sticky_mode_abs`: absolute difference (|`out` - `in`|);
* * `bw_one_pole_sticky_mode_rel`: relative difference with respect to
* input (|`out` - `in`| / |`in`|);
* >>> */
/*! ...
* #### bw_one_pole_new()
* ```>>> */
bw_one_pole bw_one_pole_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_one_pole_free()
* ```>>> */
void bw_one_pole_free(bw_one_pole instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_one_pole_set_sample_rate()
* ```>>> */
void bw_one_pole_set_sample_rate(bw_one_pole instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_one_pole_reset()
* ```>>> */
void bw_one_pole_reset(bw_one_pole instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_one_pole_process()
* ```>>> */
void bw_one_pole_process(bw_one_pole instance, const float* x, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` and fills the corresponding `n_samples` samples in the output
* buffer `y`.
* >>> */
/*! ...
* #### bw_one_pole_set_init_val()
* ```>>> */
void bw_one_pole_set_init_val(bw_one_pole instance, float value);
/*! <<<```
* Sets the initial/quiescent `value` for the given `instance`.
*
* In practice, when processing the first buffer after a reset, the past
* input and output are both assumed to have virtually been constant and of
* the specified `value`.
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_one_pole_set_cutoff()
* ```>>> */
void bw_one_pole_set_cutoff(bw_one_pole instance, float value);
/*! <<<```
* Sets both the upgoing (attack) and downgoing (decay) cutoff frequency to
* the given `value` (Hz) for the given `instance`.
*
* This is equivalent to calling both `bw_one_pole_set_cutoff_up()` and
* `bw_one_pole_set_cutoff_down()` with same `instance` and `value` or
* calling `bw_one_pole_set_tau()` with same `instance` and
* value = 1 / (2 * pi * `value`) (net of numerical errors).
*
* Default value: `INFINITY`.
* >>> */
/*! ...
* #### bw_one_pole_set_cutoff_up()
* ```>>> */
void bw_one_pole_set_cutoff_up(bw_one_pole instance, float value);
/*! <<<```
* Sets the upgoing (attack) cutoff frequency to the given `value` (Hz) for
* the given `instance`.
*
* This is equivalent to calling `bw_one_pole_set_tau_up()` with same
* `instance` and value = 1 / (2 * pi * `value`) (net of numerical errors).
*
* Default value: `INFINITY`.
* >>> */
/*! ...
* #### bw_one_pole_set_cutoff_down()
* ```>>> */
void bw_one_pole_set_cutoff_down(bw_one_pole instance, float value);
/*! <<<```
* Sets the downgoing (attack) cutoff frequency to the given `value` (Hz)
* for the given `instance`.
*
* This is equivalent to calling `bw_one_pole_set_tau_down()` with same
* `instance` and value = 1 / (2 * pi * `value`) (net of numerical errors).
*
* Default value: `INFINITY`.
* >>> */
/*! ...
* #### bw_one_pole_set_tau()
* ```>>> */
void bw_one_pole_set_tau(bw_one_pole instance, float value);
/*! <<<```
* Sets both the upgoing (attack) and downgoing (decay) time constant to the
* given `value` (s) for the given `instance`.
*
* This is equivalent to calling both `bw_one_pole_set_tau_up()` and
* `bw_one_pole_set_tau_down()` with same `instance` and `value` or calling
* `bw_one_pole_set_cutoff()` with same `instance` and
* value = 1 / (2 * pi * `value`) (net of numerical errors).
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_one_pole_set_tau_up()
* ```>>> */
void bw_one_pole_set_tau_up(bw_one_pole instance, float value);
/*! <<<```
* Sets the upgoing (attack) time constant to the given `value` (s) for the
* given `instance`.
*
* This is equivalent to calling `bw_one_pole_set_cutoff_up()` with same
* `instance` and value = 1 / (2 * pi * `value`) (net of numerical errors).
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_one_pole_set_tau_down()
* ```>>> */
void bw_one_pole_set_tau_down(bw_one_pole instance, float value);
/*! <<<```
* Sets the downgoing (decay) time constant to the given `value` (s) for the
* given `instance`.
*
* This is equivalent to calling `bw_one_pole_set_cutoff_down()` with same
* `instance` and value = 1 / (2 * pi * `value`) (net of numerical errors).
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_one_pole_set_sticky_thresh()
* ```>>> */
void bw_one_pole_set_sticky_thresh(bw_one_pole instance, float value);
/*! <<<```
* Sets the target-reach threshold specified by `value` for the given
* `instance`.
*
* When the difference between the output and the input would fall under such
* threshold according to the current distance metric (see
* `bw_one_pole_set_sticky_mode()`), the output is forcefully set to be equal
* to the input value.
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_one_pole_set_sticky_mode()
* ```>>> */
void bw_one_pole_set_sticky_mode(bw_one_pole instance, bw_one_pole_sticky_mode value);
/*! <<<```
* Sets the current distance metric for sticky behavior.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

116
include/bw_osc_filt.h Normal file
View File

@ -0,0 +1,116 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common }}}
* description {{{
* Post-filter to decolorate oscillator waveshapers when antialiasing is on.
*
* This filter can be added in series of oscillator waveshapers that use
* PolyBLEP antialiasing (i.e., [bw_osc_saw](bw_osc_saw),
* [bw_osc_pulse](bw_osc_pulse), [bw_osc_tri](bw_osc_tri)) to compensate for
* high-frequency attenuation.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_OSC_FILT_H
#define _BW_OSC_FILT_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_osc_filt
* ```>>> */
typedef struct _bw_osc_filt *bw_osc_filt;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_osc_filt_new()
* ```>>> */
bw_osc_filt bw_osc_filt_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_osc_filt_free()
* ```>>> */
void bw_osc_filt_free(bw_osc_filt instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_osc_filt_set_sample_rate()
*
* There is none (not needed).
* >>> */
/*! ...
* #### bw_osc_filt_reset()
* ```>>> */
void bw_osc_filt_reset(bw_osc_filt instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_osc_filt_process()
* ```>>> */
void bw_osc_filt_process(bw_osc_filt instance, const float *x, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` and fills the corresponding `n_samples` samples in the output
* buffer `y`.
* >>> */
/*! ...
* #### bw_osc_filt_set_enabled()
* ```>>> */
void bw_osc_filt_set_enabled(bw_osc_filt instance, char value);
/*! <<<```
* Sets whether the filter is enabled (`value` non-`0`) or bypassed (`0`)
* for the given `instance`.
*
* Default value: non-`0`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

128
include/bw_osc_pulse.h Normal file
View File

@ -0,0 +1,128 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_inline_one_pole bw_math }}}
* description {{{
* Pulse oscillator waveshaper with variable pulse width (actually, duty
* cycle) and PolyBLEP antialiasing.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_OSC_PULSE_H
#define _BW_OSC_PULSE_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_osc_pulse
* ```>>> */
typedef struct _bw_osc_pulse *bw_osc_pulse;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_osc_pulse_new()
* ```>>> */
bw_osc_pulse bw_osc_pulse_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_osc_pulse_free()
* ```>>> */
void bw_osc_pulse_free(bw_osc_pulse instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_osc_pulse_set_sample_rate()
* ```>>> */
void bw_osc_pulse_set_sample_rate(bw_osc_pulse instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_osc_pulse_reset()
* ```>>> */
void bw_osc_pulse_reset(bw_osc_pulse instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_osc_pulse_process()
* ```>>> */
void bw_osc_pulse_process(bw_osc_pulse instance, const float *x, const float *x_phase_inc, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` containing the normalized phase signal and fills the
* corresponding `n_samples` samples in the output buffer `y`.
*
* If antialiasing is on, `x_phase_inc` must contain phase increment values,
* otherwise it is ignored and can be `NULL`.
* >>> */
/*! ...
* #### bw_osc_pulse_set_antialiasing()
* ```>>> */
void bw_osc_pulse_set_antialiasing(bw_osc_pulse instance, char value);
/*! <<<```
* Sets whether the antialiasing is on (`value` non-`0`) or off (`0`) for the
* given `instance`.
*
* Default value: `0`.
* >>> */
/*! ...
* #### bw_osc_pulse_set_pulse_width()
* ```>>> */
void bw_osc_pulse_set_pulse_width(bw_osc_pulse instance, float value);
/*! <<<```
* Sets the pulse width (actually, the duty cycle) to `value` (range
* [`0.f`, `1.f`]) for the given `instance`.
*
* Default value: `0.5f`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

103
include/bw_osc_saw.h Normal file
View File

@ -0,0 +1,103 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math }}}
* description {{{
* Sawtooth oscillator waveshaper with PolyBLEP antialiasing.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_OSC_SAW_H
#define _BW_OSC_SAW_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_osc_saw
* ```>>> */
typedef struct _bw_osc_saw *bw_osc_saw;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_osc_saw_new()
* ```>>> */
bw_osc_saw bw_osc_saw_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_osc_saw_free()
* ```>>> */
void bw_osc_saw_free(bw_osc_saw instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_osc_saw_set_sample_rate() and bw_osc_saw_reset()
*
* These do not exist (not needed).
* >>> */
/*! ...
* #### bw_osc_saw_process()
* ```>>> */
void bw_osc_saw_process(bw_osc_saw instance, const float *x, const float *x_phase_inc, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` containing the normalized phase signal and fills the
* corresponding `n_samples` samples in the output buffer `y`.
* >>> */
/*! ...
* #### bw_osc_saw_set_antialiasing()
* ```>>> */
void bw_osc_saw_set_antialiasing(bw_osc_saw instance, char value);
/*! <<<```
* Sets whether the antialiasing is on (`value` non-`0`) or off (`0`) for the
* given `instance`.
*
* Default value: `0`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

61
include/bw_osc_sin.h Normal file
View File

@ -0,0 +1,61 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math }}}
* description {{{
* Sinusoidal oscillator waveshaper.
*
* This module only consists of the signal processing function.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_OSC_SIN_H
#define _BW_OSC_SIN_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_osc_sin_process()
* ```>>> */
void bw_osc_sin_process(const float *x, float* y, int n_samples);
/*! <<<```
* Turns `n_samples` samples of the normalized phase signal in the `x` buffer
* into a sinusoidal signal, filling the corresponding `n_samples` in the
* output buffer `y`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

128
include/bw_osc_tri.h Normal file
View File

@ -0,0 +1,128 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_inline_one_pole bw_math }}}
* description {{{
* Triangle oscillator waveshaper with variable slope (increasing time over
* period) and PolyBLEP antialiasing.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_OSC_TRI_H
#define _BW_OSC_TRI_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_osc_tri
* ```>>> */
typedef struct _bw_osc_tri *bw_osc_tri;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_osc_tri_new()
* ```>>> */
bw_osc_tri bw_osc_tri_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_osc_tri_free()
* ```>>> */
void bw_osc_tri_free(bw_osc_tri instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_osc_tri_set_sample_rate()
* ```>>> */
void bw_osc_tri_set_sample_rate(bw_osc_tri instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_osc_tri_reset()
* ```>>> */
void bw_osc_tri_reset(bw_osc_tri instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_osc_tri_process()
* ```>>> */
void bw_osc_tri_process(bw_osc_tri instance, const float *x, const float *x_phase_inc, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` containing the normalized phase signal and fills the
* corresponding `n_samples` samples in the output buffer `y`.
*
* If antialiasing is on, `x_phase_inc` must contain phase increment values,
* otherwise it is ignored and can be `NULL`.
* >>> */
/*! ...
* #### bw_osc_tri_set_antialiasing()
* ```>>> */
void bw_osc_tri_set_antialiasing(bw_osc_tri instance, char value);
/*! <<<```
* Sets whether the antialiasing is on (`value` non-`0`) or off (`0`) for the
* given `instance`.
*
* Default value: `0`.
* >>> */
/*! ...
* #### bw_osc_tri_set_slope()
* ```>>> */
void bw_osc_tri_set_slope(bw_osc_tri instance, float value);
/*! <<<```
* Sets the slope (increasing time over period) to `value` (range [`0.f`,
* `1.f`]) for the given `instance`.
*
* Default value: `0.5f`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

128
include/bw_phase_gen.h Normal file
View File

@ -0,0 +1,128 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math }}}
* description {{{
* Phase generator with portamento and exponential frequency modulation.
*
* It outputs a normalized phase signal (range [`0.f`, `1.f`]).
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_PHASE_GEN_H
#define _BW_PHASE_GEN_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_phase_gen
* ```>>> */
typedef struct _bw_phase_gen *bw_phase_gen;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_phase_gen_new()
* ```>>> */
bw_phase_gen bw_phase_gen_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_phase_gen_free()
* ```>>> */
void bw_phase_gen_free(bw_phase_gen instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_phase_gen_set_sample_rate()
* ```>>> */
void bw_phase_gen_set_sample_rate(bw_phase_gen instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_phase_gen_reset()
* ```>>> */
void bw_phase_gen_reset(bw_phase_gen instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_phase_gen_process()
* ```>>> */
void bw_phase_gen_process(bw_phase_gen instance, const float *x_mod, float* y, float *y_phase_inc, int n_samples);
/*! <<<```
* Lets the given `instance` generate `n_samples` samples and puts them in
* the output buffer `y`.
*
* If `x_mod` is not `NULL`, it is used as a source of exponential frequency
* modulation (scale `1.f`/octave).
*
* If `y_inc` is not `NULL`, it is filled with phase increment values.
* >>> */
/*! ...
* #### bw_phase_gen_set_frequency()
* ```>>> */
void bw_phase_gen_set_frequency(bw_phase_gen instance, float value);
/*! <<<```
* Sets the base frequency to `value` (Hz) for the given `instance`.
*
* Default value: `1.f`.
* >>> */
/*! ...
* #### bw_phase_gen_set_portamento_tau()
* ```>>> */
void bw_phase_gen_set_portamento_tau(bw_phase_gen instance, float value);
/*! <<<```
* Sets the portamento time constant `value` (s) for the given `instance`.
*
* Default value: `0.f`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

82
include/bw_rand.h Normal file
View File

@ -0,0 +1,82 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ utility }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common }}}
* description {{{
* Pseudo-random number generators.
*
* These are good enough for music DSP applications but should not be
* considered crypthographically secure.
*
* All functions in this module are [reentrant](api#reentrant-function),
* [RT-safe](api#rt-safe-function), [thread-safe](api#thread-safe-function),
* and have [no side effects](api#no-side-effects).
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_RAND_H
#define _BW_RAND_H
#include <bw_common.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_rand_u32()
* ```>>> */
uint32_t bw_rand_u32(uint64_t *state);
/*! <<<```
* Returns a pseudo-random unsigned 32-bit integer in the range
* [`0`, `UINT32_MAX`].
*
* `state` is a pointer to a 64-bit unsigned integer storing the state
* between calls, and which gets updated by calls to this function.
* >>> */
/*! ...
* #### bw_rand_f()
* ```>>> */
float bw_rand_f(uint64_t *state);
/*! <<<```
* Returns a pseudo-random unsigned 32-bit floating point number in the range
* [`-1.f`, `1.f`].
*
* `state` is a pointer to a 64-bit unsigned integer storing the state
* between calls, and which gets updated by calls to this function.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

161
include/bw_slew_lim.h Normal file
View File

@ -0,0 +1,161 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_math }}}
* description {{{
* Slew-rate limiter with separate maximum increasing and decreasing rates.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_SLEW_LIM_H
#define _BW_SLEW_LIM_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_slew_lim
* ```>>> */
typedef struct _bw_slew_lim *bw_slew_lim;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_slew_lim_new()
* ```>>> */
bw_slew_lim bw_slew_lim_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_slew_lim_free()
* ```>>> */
void bw_slew_lim_free(bw_slew_lim instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_slew_lim_set_sample_rate()
* ```>>> */
void bw_slew_lim_set_sample_rate(bw_slew_lim instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_slew_lim_reset()
* ```>>> */
void bw_slew_lim_reset(bw_slew_lim instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_slew_lim_process()
* ```>>> */
void bw_slew_lim_process(bw_slew_lim instance, const float* x, float* y, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` and fills the corresponding `n_samples` samples in the output
* buffer `y`.
* >>> */
/*! ...
* #### bw_slew_lim_set_init_val()
* ```>>> */
void bw_slew_lim_set_init_val(bw_slew_lim instance, float value);
/*! <<<```
* Sets the initial/quiescent `value` for the given `instance`.
*
* In practice, when processing the first buffer after a reset, the past
* input and output are both assumed to have virtually been constant and of
* the specified `value`.
*
* Default value: `0.f`.
* >>> */
/*! ...
* #### bw_slew_lim_set_max_rate()
* ```>>> */
void bw_slew_lim_set_max_rate(bw_slew_lim instance, float value);
/*! <<<```
* Sets both the maximum increasing and decreasing variation rate to the
* given `value` (1/s) for the given `instance`.
*
* `value` represents the maximum variation per second and must be
* non-negative.
*
* This is equivalent to calling both `bw_slew_lim_set_max_inc_rate()` and
* `bw_slew_lim_set_max_dec_rate()` with same `instance` and `value`.
*
* Default value: `INFINITY`.
* >>> */
/*! ...
* #### bw_slew_lim_set_max_inc_rate()
* ```>>> */
void bw_slew_lim_set_max_inc_rate(bw_slew_lim instance, float value);
/*! <<<```
* Sets the maximum increasing variation rate to the given `value` (1/s) for
* the given `instance`.
*
* `value` represents the maximum variation per second and must be
* non-negative.
*
* Default value: `INFINITY`.
* >>> */
/*! ...
* #### bw_slew_lim_set_max_inc_rate()
* ```>>> */
void bw_slew_lim_set_max_dec_rate(bw_slew_lim instance, float value);
/*! <<<```
* Sets the maximum decreasing variation rate to the given `value` (1/s) for
* the given `instance`.
*
* `value` represents the maximum variation per second and must be
* non-negative.
*
* Default value: `INFINITY`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

126
include/bw_svf.h Normal file
View File

@ -0,0 +1,126 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_inline_one_pole bw_math }}}
* description {{{
* State variable filter (2nd order, 12 dB/oct) model with separated lowpass,
* bandpass, and highpass outputs.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_SVF_H
#define _BW_SVF_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_svf
* ```>>> */
typedef struct _bw_svf *bw_svf;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_svf_new()
* ```>>> */
bw_svf bw_svf_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_svf_free()
* ```>>> */
void bw_svf_free(bw_svf instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_svf_set_sample_rate()
* ```>>> */
void bw_svf_set_sample_rate(bw_svf instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_svf_reset()
* ```>>> */
void bw_svf_reset(bw_svf instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_svf_process()
* ```>>> */
void bw_svf_process(bw_svf instance, const float *x, float* y_lp, float *y_bp, float *y_hp, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from the input
* buffer `x` and fills the corresponding `n_samples` samples in the output
* buffers `y_lp` (lowpass), `y_bp` (bandpass), and `y_hp` (highpass), if
* they are not `NULL`.
* >>> */
/*! ...
* #### bw_svf_set_cutoff()
* ```>>> */
void bw_svf_set_cutoff(bw_svf instance, float value);
/*! <<<```
* Sets the cutoff frequency to the given `value` (Hz) for the given
* `instance`.
*
* Default value: `1e3f`.
* >>> */
/*! ...
* #### bw_svf_set_Q()
* ```>>> */
void bw_svf_set_Q(bw_svf instance, float value);
/*! <<<```
* Sets the quality factor to the given `value` (Hz) for the given
* `instance`.
*
* Default value: `0.5f`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

119
include/bw_vol.h Normal file
View File

@ -0,0 +1,119 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
/*!
* module_type {{{ dsp }}}
* version {{{ 0.1.0 }}}
* requires {{{ bw_config bw_common bw_inline_slew_lim bw_math }}}
* description {{{
* Volume control for an arbitrary number of channels.
* }}}
* changelog {{{
* <ul>
* <li>Version <strong>0.1.0</strong>:
* <ul>
* <li>First release.</li>
* </ul>
* </li>
* </ul>
* }}}
*/
#ifndef _BW_VOL_H
#define _BW_VOL_H
#ifdef __cplusplus
extern "C" {
#endif
/*! api {{{
* #### bw_vol
* ```>>> */
typedef struct _bw_vol *bw_vol;
/*! <<<```
* Instance handle.
* >>> */
/*! ...
* #### bw_vol_new()
* ```>>> */
bw_vol bw_vol_new();
/*! <<<```
* Creates a new instance.
*
* Returns the newly-created instance handle or `NULL` if there was not
* enough memory.
* >>> */
/*! ...
* #### bw_vol_free()
* ```>>> */
void bw_vol_free(bw_vol instance);
/*! <<<```
* Destroys an `instance`.
* >>> */
/*! ...
* #### bw_vol_set_sample_rate()
* ```>>> */
void bw_vol_set_sample_rate(bw_vol instance, float sample_rate);
/*! <<<```
* Sets the `sample_rate` (Hz) value for the given `instance`.
* >>> */
/*! ...
* #### bw_vol_reset()
* ```>>> */
void bw_vol_reset(bw_vol instance);
/*! <<<```
* Resets the given `instance` to its initial state.
* >>> */
/*! ...
* #### bw_vol_process()
* ```>>> */
void bw_vol_process(bw_vol instance, const float **x, float **y, int n_channels, int n_samples);
/*! <<<```
* Lets the given `instance` process `n_samples` samples from each of the
* `n_channels` input buffers and fills the corresponding `n_samples` samples
* in each of the `n_channels` output buffers.
*
* `x` is an array of `n_channels` input buffers and similarly `y` is an
* array of `n_channels` output buffers.
* >>> */
/*! ...
* #### bw_vol_set_volume()
* ```>>> */
void bw_vol_set_volume(bw_vol instance, float value);
/*! <<<```
* Sets the volume parameter to the given `value` (range [`0.f`, `1.f`]) for
* the given `instance`.
*
* This parameter is not linearly mapped, but the range extremes correspond
* to silence (gain = `0.f`) and bypass (gain = `1.f`).
*
* Default value: `1.f`.
* }}} */
#ifdef __cplusplus
}
#endif
#endif

64
src/bw_env_follow.c Normal file
View File

@ -0,0 +1,64 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_env_follow.h>
#include <bw_math.h>
struct _bw_env_follow {
// Sub-components
bw_one_pole one_pole;
};
bw_env_follow bw_env_follow_new() {
bw_env_follow instance = (bw_env_follow)BW_MALLOC(sizeof(struct _bw_env_follow));
if (instance == NULL)
return NULL;
instance->one_pole = bw_one_pole_new();
if (instance->one_pole == NULL) {
BW_FREE(instance);
return NULL;
}
return instance;
}
void bw_env_follow_free(bw_env_follow instance) {
bw_one_pole_free(instance->one_pole);
BW_FREE(instance);
}
void bw_env_follow_set_sample_rate(bw_env_follow instance, float sample_rate) {
bw_one_pole_set_sample_rate(instance->one_pole, sample_rate);
}
void bw_env_follow_reset(bw_env_follow instance) {
bw_one_pole_reset(instance->one_pole);
}
void bw_env_follow_process(bw_env_follow instance, const float *x, float *y, int n_samples) {
for (int i = 0; i < n_samples; i++)
y[i] = bw_absf(x[i]);
bw_one_pole_process(instance->one_pole, y, y, n_samples);
}
bw_one_pole bw_env_follow_get_one_pole(bw_env_follow instance) {
return instance->one_pole;
}

185
src/bw_env_gen.c Normal file
View File

@ -0,0 +1,185 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_env_gen.h>
#include <bw_math.h>
#include <bw_inline_one_pole.h>
typedef enum {
state_off,
state_attack,
state_decay,
state_sustain,
state_release
} state_t;
struct _bw_env_gen {
// Coefficients
float T;
float smooth_mA1;
float attack_inc;
float decay_inc;
float release_inc;
// Parameters
char gate;
float attack;
float decay;
float sustain;
float release;
int param_changed;
// State
char first_run;
state_t state;
float y_z1;
};
bw_env_gen bw_env_gen_new() {
bw_env_gen instance = (bw_env_gen)BW_MALLOC(sizeof(struct _bw_env_gen));
if (instance == NULL)
return NULL;
instance->gate = 0;
instance->attack = 0.f;
instance->decay = 0.f;
instance->sustain = 1.f;
instance->release = 0.f;
return instance;
}
void bw_env_gen_free(bw_env_gen instance) {
BW_FREE(instance);
}
void bw_env_gen_set_sample_rate(bw_env_gen instance, float sample_rate) {
instance->T = 1.f / sample_rate;
instance->smooth_mA1 = bw_inline_one_pole_get_mA1(sample_rate, 0.05f);
}
void bw_env_gen_reset(bw_env_gen instance) {
instance->first_run = 1;
instance->param_changed = ~0;
}
#define PARAM_ATTACK 1
#define PARAM_DECAY (1<<1)
#define PARAM_SUSTAIN (1<<2)
#define PARAM_RELEASE (1<<3)
void bw_env_gen_process(bw_env_gen instance, float* y, int n_samples) {
if (instance->param_changed) {
// 1 ns considered instantaneous
if (instance->param_changed & PARAM_ATTACK)
instance->attack_inc = instance->attack > 1e-9f ? instance->T * bw_rcpf_2(instance->attack) : INFINITY;
if (instance->param_changed & (PARAM_DECAY | PARAM_SUSTAIN))
instance->decay_inc = instance->decay > 1e-9f ? (instance->sustain - 1.f) * instance->T * bw_rcpf_2(instance->decay) : -INFINITY;
if (instance->param_changed & (PARAM_SUSTAIN | PARAM_RELEASE))
instance->release_inc = instance->release > 1e-9f ? -instance->sustain * instance->T * bw_rcpf_2(instance->release) : -INFINITY;
}
if (instance->first_run) {
instance->state = state_off;
instance->y_z1 = 0.f;
instance->first_run = 0;
}
if (instance->gate) {
if (instance->state == state_off || instance->state == state_release)
instance->state = state_attack;
} else {
if (instance->state != state_off)
instance->state = state_release;
}
for (int i = 0; i < n_samples; i++) {
float v;
switch (instance->state) {
case state_attack:
v = instance->y_z1 + instance->attack_inc;
if (v >= 1.f) {
v = 1.f;
instance->state = state_decay;
}
break;
case state_decay:
v = instance->y_z1 + instance->decay_inc;
if (v <= instance->sustain) {
v = instance->sustain;
instance->state = state_sustain;
}
break;
case state_sustain:
v = bw_inline_one_pole(instance->sustain, instance->y_z1, instance->smooth_mA1);
break;
case state_release:
v = instance->y_z1 + instance->release_inc;
if (v <= 0.f) {
v = 0.f;
instance->state = state_off;
}
break;
case state_off:
v = 0.f;
break;
}
y[i] = v;
instance->y_z1 = y[i];
}
}
void bw_env_gen_set_gate(bw_env_gen instance, char value) {
instance->gate = value;
}
void bw_env_gen_set_attack(bw_env_gen instance, float value) {
if (instance->attack != value) {
instance->attack = value;
instance->param_changed |= PARAM_ATTACK;
}
}
void bw_env_gen_set_decay(bw_env_gen instance, float value) {
if (instance->decay != value) {
instance->decay = value;
instance->param_changed |= PARAM_DECAY;
}
}
void bw_env_gen_set_sustain(bw_env_gen instance, float value) {
if (instance->sustain != value) {
instance->sustain = value;
instance->param_changed |= PARAM_SUSTAIN;
}
}
void bw_env_gen_set_release(bw_env_gen instance, float value) {
if (instance->release != value) {
instance->release = value;
instance->param_changed |= PARAM_RELEASE;
}
}
char bw_env_gen_get_is_off(bw_env_gen instance) {
return instance->state == state_off;
}

65
src/bw_noise_gen.c Normal file
View File

@ -0,0 +1,65 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_noise_gen.h>
#include <bw_rand.h>
#include <bw_math.h>
struct _bw_noise_gen {
// Coefficients
float scaling_k;
// Parameters
char sample_rate_scaling;
// State
uint64_t *state;
};
bw_noise_gen bw_noise_gen_new(uint64_t *state) {
bw_noise_gen instance = (bw_noise_gen)BW_MALLOC(sizeof(struct _bw_noise_gen));
if (instance == NULL)
return NULL;
instance->state = state;
instance->sample_rate_scaling = 0;
return instance;
}
void bw_noise_gen_free(bw_noise_gen instance) {
BW_FREE(instance);
}
void bw_noise_gen_set_sample_rate(bw_noise_gen instance, float sample_rate) {
instance->scaling_k = 0.004761904761904762f * bw_sqrtf_2(sample_rate);
}
void bw_noise_gen_process(bw_noise_gen instance, float* y, int n_samples) {
for (int i = 0; i < n_samples; i++)
y[i] = bw_rand_f(instance->state);
if (instance->sample_rate_scaling)
for (int i = 0; i < n_samples; i++)
y[i] *= instance->scaling_k;
}
void bw_noise_gen_set_sample_rate_scaling(bw_noise_gen instance, char value) {
instance->sample_rate_scaling = value;
}

210
src/bw_one_pole.c Normal file
View File

@ -0,0 +1,210 @@
/*
* Brickworks
*
* Copyright (C) 2021, 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_one_pole.h>
#include <bw_math.h>
struct _bw_one_pole {
// Coefficients
float Ttm2pi;
float mA1u;
float mA1d;
float st2;
// Parameters
float init_val;
float cutoff_up;
float cutoff_down;
float sticky_thresh;
bw_one_pole_sticky_mode sticky_mode;
int param_changed;
// State
char first_run;
float x_z1;
float y_z1;
};
bw_one_pole bw_one_pole_new() {
bw_one_pole instance = (bw_one_pole)BW_MALLOC(sizeof(struct _bw_one_pole));
if (instance != NULL) {
instance->init_val = 0.f;
instance->cutoff_up = INFINITY;
instance->cutoff_down = INFINITY;
instance->sticky_thresh = 0.f;
}
return instance;
}
void bw_one_pole_free(bw_one_pole instance) {
BW_FREE(instance);
}
void bw_one_pole_set_sample_rate(bw_one_pole instance, float sample_rate) {
instance->Ttm2pi = -6.283185307179586f / sample_rate;
}
void bw_one_pole_reset(bw_one_pole instance) {
instance->first_run = 1;
instance->param_changed = ~0;
}
#define PARAM_CUTOFF_UP 1
#define PARAM_CUTOFF_DOWN (1<<1)
#define PARAM_STICKY_THRESH (1<<2)
void bw_one_pole_process(bw_one_pole instance, const float* x, float* y, int n_samples) {
if (instance->param_changed) {
if (instance->param_changed & PARAM_CUTOFF_UP)
instance->mA1u = bw_expf_3(instance->Ttm2pi * instance->cutoff_up);
if (instance->param_changed & PARAM_CUTOFF_DOWN)
instance->mA1d = bw_expf_3(instance->Ttm2pi * instance->cutoff_down);
if (instance->param_changed & PARAM_STICKY_THRESH)
instance->st2 = instance->sticky_thresh * instance->sticky_thresh;
instance->param_changed = 0;
}
if (instance->first_run) {
instance->x_z1 = instance->init_val;
instance->y_z1 = instance->init_val;
instance->first_run = 0;
}
if (instance->mA1u != instance->mA1d) {
if (instance->st2 != 0.f) {
if (instance->sticky_mode == bw_one_pole_sticky_mode_abs)
for (int i = 0; i < n_samples; i++) {
const float in = x[i];
float out = in + (in >= instance->y_z1 ? instance->mA1u : instance->mA1d) * (instance->y_z1 - in);
const float d = out - in;
if (d * d <= instance->st2)
out = in;
instance->x_z1 = in;
instance->y_z1 = out;
y[i] = out;
}
else
for (int i = 0; i < n_samples; i++) {
const float in = x[i];
float out = in + (in >= instance->y_z1 ? instance->mA1u : instance->mA1d) * (instance->y_z1 - in);
const float d = out - in;
if (d * d <= instance->st2 * in * in)
out = in;
instance->x_z1 = in;
instance->y_z1 = out;
y[i] = out;
}
}
else {
for (int i = 0; i < n_samples; i++) {
const float in = x[i];
const float out = in + (in >= instance->y_z1 ? instance->mA1u : instance->mA1d) * (instance->y_z1 - in);
instance->x_z1 = in;
instance->y_z1 = out;
y[i] = out;
}
}
}
else {
if (instance->st2 != 0.f) {
if (instance->sticky_mode == bw_one_pole_sticky_mode_abs)
for (int i = 0; i < n_samples; i++) {
const float in = x[i];
float out = in + instance->mA1u * (instance->y_z1 - in);
const float d = out - in;
if (d * d <= instance->st2)
out = in;
instance->x_z1 = in;
instance->y_z1 = out;
y[i] = out;
}
else
for (int i = 0; i < n_samples; i++) {
const float in = x[i];
float out = in + instance->mA1u * (instance->y_z1 - in);
const float d = out - in;
if (d * d <= instance->st2 * in * in)
out = in;
instance->x_z1 = in;
instance->y_z1 = out;
y[i] = out;
}
}
else {
for (int i = 0; i < n_samples; i++) {
const float in = x[i];
const float out = in + instance->mA1u * (instance->y_z1 - in);
instance->x_z1 = in;
instance->y_z1 = out;
y[i] = out;
}
}
}
}
void bw_one_pole_set_init_val(bw_one_pole instance, float value) {
instance->init_val = value;
}
void bw_one_pole_set_cutoff(bw_one_pole instance, float value) {
bw_one_pole_set_cutoff_up(instance, value);
bw_one_pole_set_cutoff_down(instance, value);
}
void bw_one_pole_set_cutoff_up(bw_one_pole instance, float value) {
if (instance->cutoff_up != value) {
instance->cutoff_up = value;
instance->param_changed |= PARAM_CUTOFF_UP;
}
}
void bw_one_pole_set_cutoff_down(bw_one_pole instance, float value) {
if (instance->cutoff_down != value) {
instance->cutoff_down = value;
instance->param_changed |= PARAM_CUTOFF_DOWN;
}
}
void bw_one_pole_set_tau(bw_one_pole instance, float value) {
bw_one_pole_set_tau_up(instance, value);
bw_one_pole_set_tau_down(instance, value);
}
void bw_one_pole_set_tau_up(bw_one_pole instance, float value) {
bw_one_pole_set_cutoff_up(instance, value < 1e-9f ? INFINITY : 0.1591549430918953f * bw_rcpf_2(value));
// tau < 1 ns is instantaneous for any practical purpose
}
void bw_one_pole_set_tau_down(bw_one_pole instance, float value) {
bw_one_pole_set_cutoff_down(instance, value < 1e-9f ? INFINITY : 0.1591549430918953f * bw_rcpf_2(value));
// as before
}
void bw_one_pole_set_sticky_thresh(bw_one_pole instance, float value) {
if (instance->sticky_thresh != value) {
instance->sticky_thresh = value;
instance->param_changed |= PARAM_STICKY_THRESH;
}
}
void bw_one_pole_set_sticky_mode(bw_one_pole instance, bw_one_pole_sticky_mode value) {
instance->sticky_mode = value;
}

70
src/bw_osc_filt.c Normal file
View File

@ -0,0 +1,70 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_osc_filt.h>
#include <bw_common.h>
struct _bw_osc_filt {
// Parameters
char enabled;
// State
float x_z1;
float y_z1;
};
bw_osc_filt bw_osc_filt_new() {
bw_osc_filt instance = (bw_osc_filt)BW_MALLOC(sizeof(struct _bw_osc_filt));
if (instance == NULL)
return NULL;
instance->enabled = 1;
return instance;
}
void bw_osc_filt_free(bw_osc_filt instance) {
BW_FREE(instance);
}
void bw_osc_filt_reset(bw_osc_filt instance) {
instance->x_z1 = 0.f;
instance->y_z1 = 0.f;
}
void bw_osc_filt_process(bw_osc_filt instance, const float *x, float* y, int n_samples) {
if (instance->enabled)
for (int i = 0; i < n_samples; i++) {
const float v = 1.371308261611209f * x[i] + 0.08785458027104826f * instance->x_z1 - 4.591628418822578e-1f * instance->y_z1;
instance->x_z1 = x[i];
instance->y_z1 = y[i];
y[i] = v;
}
else {
for (int i = 0; i < n_samples; i++)
y[i] = x[i];
instance->x_z1 = instance->y_z1 = x[n_samples - 1];
}
}
void bw_osc_filt_set_enabled(bw_osc_filt instance, char value) {
instance->enabled = value;
}

116
src/bw_osc_pulse.c Normal file
View File

@ -0,0 +1,116 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_osc_pulse.h>
#include <bw_math.h>
#include <bw_inline_one_pole.h>
struct _bw_osc_pulse {
// Coefficients
float smooth_mA1;
// Parameters
char first_run;
char antialiasing;
float pulse_width;
// State
float pw_z1;
};
bw_osc_pulse bw_osc_pulse_new() {
bw_osc_pulse instance = (bw_osc_pulse)BW_MALLOC(sizeof(struct _bw_osc_pulse));
if (instance == NULL)
return NULL;
instance->antialiasing = 0;
instance->pulse_width = 0.5f;
return instance;
}
void bw_osc_pulse_free(bw_osc_pulse instance) {
BW_FREE(instance);
}
void bw_osc_pulse_set_sample_rate(bw_osc_pulse instance, float sample_rate) {
instance->smooth_mA1 = bw_inline_one_pole_get_mA1(sample_rate, 0.005f);
}
void bw_osc_pulse_reset(bw_osc_pulse instance) {
instance->first_run = 1;
}
// PolyBLEP residual based on Parzen window (4th-order B-spline), one-sided (x in [0, 2])
static inline float blep_diff(float x) {
return x < 1.f
? x * ((0.25f * x - 0.6666666666666666f) * x * x + 1.333333333333333f) - 1.f
: x * (x * ((0.6666666666666666f - 0.08333333333333333f * x) * x - 2.0f) + 2.666666666666667f) - 1.333333333333333f;
}
void bw_osc_pulse_process(bw_osc_pulse instance, const float *x, const float *x_phase_inc, float* y, int n_samples) {
if (instance->first_run) {
instance->pw_z1 = instance->pulse_width;
instance->first_run = 0;
}
if (instance->antialiasing) {
for (int i = 0; i < n_samples; i++) {
const float pw = bw_inline_one_pole(instance->pulse_width, instance->pw_z1, instance->smooth_mA1);
instance->pw_z1 = pw;
const float pw_m_phase = pw - x[i];
float v = bw_copysignf(1.f, pw_m_phase); // pw = phase case should be properly compensated by the AA
if (x_phase_inc[i] != 0.f) {
const float phase_inc_2 = x_phase_inc[i] + x_phase_inc[i];
const float phase_inc_rcp = bw_rcpf_2(x_phase_inc[i]);
const float phase_2 = 0.5f * v + 0.5f - pw_m_phase;
const float s_1_m_phase = 1.f - x[i];
const float s_1_m_phase_2 = 1.f - phase_2;
if (s_1_m_phase < phase_inc_2)
v -= blep_diff(s_1_m_phase * phase_inc_rcp);
if (s_1_m_phase_2 < phase_inc_2)
v += blep_diff(s_1_m_phase_2 * phase_inc_rcp);
if (x[i] < phase_inc_2)
v += blep_diff(x[i] * phase_inc_rcp);
if (phase_2 < phase_inc_2)
v -= blep_diff(phase_2 * phase_inc_rcp);
}
y[i] = v;
}
} else {
for (int i = 0; i < n_samples; i++) {
const float pw = bw_inline_one_pole(instance->pulse_width, instance->pw_z1, instance->smooth_mA1);
instance->pw_z1 = pw;
y[i] = bw_signf(pw - x[i]);
}
}
}
void bw_osc_pulse_set_antialiasing(bw_osc_pulse instance, char value) {
instance->antialiasing = value;
}
void bw_osc_pulse_set_pulse_width(bw_osc_pulse instance, float value) {
instance->pulse_width = value;
}

75
src/bw_osc_saw.c Normal file
View File

@ -0,0 +1,75 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_osc_saw.h>
#include <bw_math.h>
struct _bw_osc_saw {
// Parameters
char antialiasing;
};
bw_osc_saw bw_osc_saw_new() {
bw_osc_saw instance = (bw_osc_saw)BW_MALLOC(sizeof(struct _bw_osc_saw));
if (instance == NULL)
return NULL;
instance->antialiasing = 0;
return instance;
}
void bw_osc_saw_free(bw_osc_saw instance) {
BW_FREE(instance);
}
// PolyBLEP residual based on Parzen window (4th-order B-spline), one-sided (x in [0, 2])
static inline float blep_diff(float x) {
return x < 1.f
? x * ((0.25f * x - 0.6666666666666666f) * x * x + 1.333333333333333f) - 1.f
: x * (x * ((0.6666666666666666f - 0.08333333333333333f * x) * x - 2.0f) + 2.666666666666667f) - 1.333333333333333f;
}
void bw_osc_saw_process(bw_osc_saw instance, const float *x, const float *x_phase_inc, float* y, int n_samples) {
if (instance->antialiasing) {
for (int i = 0; i < n_samples; i++) {
const float s_1_m_phase = 1.f - x[i];
float v = x[i] - s_1_m_phase;
if (x_phase_inc[i] != 0.f) {
const float phase_inc_2 = x_phase_inc[i] + x_phase_inc[i];
const float phase_inc_rcp = bw_rcpf_2(x_phase_inc[i]);
if (s_1_m_phase < phase_inc_2)
v += blep_diff(s_1_m_phase * phase_inc_rcp);
if (x[i] < phase_inc_2)
v -= blep_diff(x[i] * phase_inc_rcp);
}
y[i] = v;
}
} else {
for (int i = 0; i < n_samples; i++)
y[i] = x[i] + x[i] - 1.f;
}
}
void bw_osc_saw_set_antialiasing(bw_osc_saw instance, char value) {
instance->antialiasing = value;
}

27
src/bw_osc_sin.c Normal file
View File

@ -0,0 +1,27 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_osc_sin.h>
#include <bw_math.h>
void bw_osc_sin_process(const float *x, float* y, int n_samples) {
for (int i = 0; i < n_samples; i++)
y[i] = bw_sinf_3(6.283185307179586f * x[i]);
}

122
src/bw_osc_tri.c Normal file
View File

@ -0,0 +1,122 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_osc_tri.h>
#include <bw_math.h>
#include <bw_inline_one_pole.h>
struct _bw_osc_tri {
// Coefficients
float smooth_mA1;
// Parameters
char first_run;
char antialiasing;
float slope;
// State
float slope_z1;
};
bw_osc_tri bw_osc_tri_new() {
bw_osc_tri instance = (bw_osc_tri)BW_MALLOC(sizeof(struct _bw_osc_tri));
if (instance == NULL)
return NULL;
instance->antialiasing = 0;
instance->slope = 0.5f;
return instance;
}
void bw_osc_tri_free(bw_osc_tri instance) {
BW_FREE(instance);
}
void bw_osc_tri_set_sample_rate(bw_osc_tri instance, float sample_rate) {
instance->smooth_mA1 = bw_inline_one_pole_get_mA1(sample_rate, 0.005f);
}
void bw_osc_tri_reset(bw_osc_tri instance) {
instance->first_run = 1;
}
// PolyBLAMP residual based on Parzen window (4th-order B-spline), one-sided (x in [0, 2])
static inline float blamp_diff(float x) {
return x < 1.f
? x * (x * ((0.05f * x - 0.1666666666666667f) * x * x + 0.6666666666666666f) - 1.0f) + 0.4666666666666667f
: x * (x * (x * ((0.1666666666666667f - 0.01666666666666667f * x) * x - 0.6666666666666666f) + 1.333333333333333f) - 1.333333333333333f) + 0.5333333333333333f;
}
void bw_osc_tri_process(bw_osc_tri instance, const float *x, const float *x_phase_inc, float* y, int n_samples) {
if (instance->first_run) {
instance->slope_z1 = instance->slope;
instance->first_run = 0;
}
if (instance->antialiasing) {
for (int i = 0; i < n_samples; i++) {
const float slope = bw_inline_one_pole(instance->slope, instance->slope_z1, instance->smooth_mA1);
instance->slope_z1 = slope;
const float s_1_p_pw = 1.f + slope;
const float s_1_m_pw = 1.f - slope;
const float phase_d = x[i] + x[i];
float v = x[i] < slope ? (phase_d - slope) * bw_rcpf_2(slope) : (s_1_p_pw - phase_d) * bw_rcpf_2(s_1_m_pw);
if (x_phase_inc[i] != 0.f) {
const float phase_inc_2 = x_phase_inc[i] + x_phase_inc[i];
const float phase_inc_rcp = bw_rcpf_2(x_phase_inc[i]);
const float pw_m_phase = slope - x[i];
const float phase_2 = bw_copysignf(0.5f, pw_m_phase) + 0.5f - pw_m_phase;
const float s_1_m_phase = 1.f - x[i];
const float s_1_m_phase_2 = 1.f - phase_2;
float blamp = 0.f;
if (s_1_m_phase_2 < phase_inc_2)
blamp += blamp_diff(s_1_m_phase_2 * phase_inc_rcp);
if (s_1_m_phase < phase_inc_2)
blamp -= blamp_diff(s_1_m_phase * phase_inc_rcp);
if (x[i] < phase_inc_2)
blamp -= blamp_diff(x[i] * phase_inc_rcp);
if (phase_2 < phase_inc_2)
blamp += blamp_diff(phase_2 * phase_inc_rcp);
v -= bw_rcpf_2(slope * s_1_m_pw) * bw_absf(x_phase_inc[i]) * blamp;
}
y[i] = v;
}
} else {
for (int i = 0; i < n_samples; i++) {
const float slope = bw_inline_one_pole(instance->slope, instance->slope_z1, instance->smooth_mA1);
instance->slope_z1 = slope;
const float phase_d = x[i] + x[i];
y[i] = x[i] < slope ? (phase_d - slope) * bw_rcpf_2(slope) : (1.f + slope - phase_d) * bw_rcpf_2(1.f - slope);
}
}
}
void bw_osc_tri_set_antialiasing(bw_osc_tri instance, char value) {
instance->antialiasing = value;
}
void bw_osc_tri_set_slope(bw_osc_tri instance, float value) {
instance->slope = value;
}

122
src/bw_phase_gen.c Normal file
View File

@ -0,0 +1,122 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_phase_gen.h>
#include <bw_math.h>
struct _bw_phase_gen {
// Coefficients
float T;
float portamento_target;
float portamento_mA1;
// Parameters
float frequency;
float portamento_tau;
int param_changed;
// State
char first_run;
float phase;
float portamento_z1;
};
bw_phase_gen bw_phase_gen_new() {
bw_phase_gen instance = (bw_phase_gen)BW_MALLOC(sizeof(struct _bw_phase_gen));
if (instance == NULL)
return NULL;
instance->frequency = 1.f;
instance->portamento_tau = 0.f;
return instance;
}
void bw_phase_gen_free(bw_phase_gen instance) {
BW_FREE(instance);
}
void bw_phase_gen_set_sample_rate(bw_phase_gen instance, float sample_rate) {
instance->T = 1.f / sample_rate;
}
void bw_phase_gen_reset(bw_phase_gen instance) {
instance->first_run = 1;
instance->param_changed = ~0;
}
#define PARAM_FREQUENCY 1
#define PARAM_PORTAMENTO_TAU (1<<1)
void bw_phase_gen_process(bw_phase_gen instance, const float *x_mod, float* y, float *y_phase_inc, int n_samples) {
if (instance->param_changed) {
if (instance->param_changed & PARAM_FREQUENCY)
instance->portamento_target = instance->T * instance->frequency;
if (instance->param_changed & PARAM_PORTAMENTO_TAU)
instance->portamento_mA1 = bw_expf_3(-instance->T * bw_rcpf_2(instance->portamento_tau));
}
if (instance->first_run) {
instance->phase = 0.f;
instance->portamento_z1 = instance->portamento_target;
instance->first_run = 0;
}
if (y_phase_inc == NULL)
y_phase_inc = y;
if (x_mod != NULL)
for (int i = 0; i < n_samples; i++) {
const float portamento = instance->portamento_target + instance->portamento_mA1 * (instance->portamento_z1 - instance->portamento_target);
instance->portamento_z1 = portamento;
const float phase_inc = portamento * bw_pow2f_3(x_mod[i]);
instance->phase += phase_inc;
instance->phase -= bw_floorf(instance->phase);
y_phase_inc[i] = phase_inc;
y[i] = instance->phase;
}
else
for (int i = 0; i < n_samples; i++) {
const float portamento = instance->portamento_target + instance->portamento_mA1 * (instance->portamento_z1 - instance->portamento_target);
instance->portamento_z1 = portamento;
instance->phase += portamento;
instance->phase -= bw_floorf(instance->phase);
y_phase_inc[i] = portamento;
y[i] = instance->phase;
}
}
void bw_phase_gen_set_frequency(bw_phase_gen instance, float value) {
if (instance->frequency != value) {
instance->frequency = value;
instance->param_changed |= PARAM_FREQUENCY;
}
}
void bw_phase_gen_set_portamento_tau(bw_phase_gen instance, float value) {
if (instance->portamento_tau != value) {
instance->portamento_tau = value;
instance->param_changed |= PARAM_PORTAMENTO_TAU;
}
}

31
src/bw_rand.c Normal file
View File

@ -0,0 +1,31 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_rand.h>
uint32_t bw_rand_u32(uint64_t *state) {
// Permuted Congruential Generator,
// taken from https://nullprogram.com/blog/2017/09/21/
*state = *state * 0x9b60933458e17d7d + 0xd737232eeccdf7ed;
return *state >> (29 - (*state >> 61));
}
float bw_rand_f(uint64_t *state) {
return (2.f / (float)UINT32_MAX) * (float)bw_random_u32(state) - 1.f;
}

111
src/bw_slew_lim.c Normal file
View File

@ -0,0 +1,111 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_slew_lim.h>
#include <bw_math.h>
struct _bw_slew_lim {
// Coefficients
float T;
// Parameters
float init_val;
float max_inc_rate;
float max_dec_rate;
// State
char first_run;
float y_z1;
};
bw_slew_lim bw_slew_lim_new() {
bw_slew_lim instance = (bw_slew_lim)BW_MALLOC(sizeof(struct _bw_slew_lim));
if (instance != NULL) {
instance->init_val = 0.f;
instance->max_inc = INFINITY;
instance->max_dec = INFINITY;
}
return instance;
}
void bw_slew_lim_free(bw_slew_lim instance) {
BW_FREE(instance);
}
void bw_slew_lim_set_sample_rate(bw_slew_lim instance, float sample_rate) {
instance->T = 1.f / sample_rate;
}
void bw_slew_lim_reset(bw_slew_lim instance) {
instance->first_run = 1;
instance->param_changed = ~0;
}
void bw_slew_lim_process(bw_slew_lim instance, const float* x, float* y, int n_samples) {
if (instance->first_run) {
instance->y_z1 = instance->init_val;
instance->first_run = 0;
}
if (instance->max_inc_rate != INFINITY) {
const float max_inc = instance->T * instance->max_inc_rate;
if (instance->max_dec_rate != INFINITY) {
const float max_dec = instance->T * instance->max_dec_rate;
for (int i = 0; i < n_samples; i++) {
y[i] = bw_clipf(x[i], instance->y_z1 - max_dec, instance->y_z1 + max_inc);
instance->y_z1 = y[i];
}
} else {
for (int i = 0; i < n_samples; i++) {
y[i] = bw_minf(x[i], instance->y_z1 + max_inc);
instance->y_z1 = y[i];
}
}
} else {
if (instance->max_dec_rate != INFINITY) {
const float max_dec = instance->T * instance->max_dec_rate;
for (int i = 0; i < n_samples; i++) {
y[i] = bw_maxf(x[i], instance->y_z1 - max_dec);
instance->y_z1 = y[i];
}
} else {
for (int i = 0; i < n_samples; i++) {
y[i] = x[i];
instance->y_z1 = y[n_samples - 1];
}
}
}
void bw_slew_lim_set_init_val(bw_slew_lim instance, float value) {
instance->init_val = value;
}
void bw_slew_lim_set_max_rate(bw_slew_lim instance, float value) {
instance->max_inc_rate = value;
instance->max_dec_rate = value;
}
void bw_slew_lim_set_max_inc_rate(bw_slew_lim instance, float value) {
instance->max_inc_rate = value;
}
void bw_slew_lim_set_max_dec_rate(bw_slew_lim instance, float value) {
instance->max_dec_rate = value;
}

131
src/bw_svf.c Normal file
View File

@ -0,0 +1,131 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_svf.h>
#include <bw_math.h>
#include <bw_inline_one_pole.h>
struct _bw_svf {
// Coefficients
float t_k;
float smooth_mA1;
float t;
float k;
float hp_hp_z1;
float hp_bp_z1;
float hp_x;
// Parameters
float cutoff;
float Q;
float cutoff_cur;
float Q_cur;
// State
char first_run;
float hp_z1;
float lp_z1;
float bp_z1;
};
bw_svf bw_svf_new() {
bw_svf instance = (bw_svf)BW_MALLOC(sizeof(struct _bw_svf));
if (instance == NULL)
return NULL;
instance->cutoff = 1e3f;
instance->Q = 0.5f;
return instance;
}
void bw_svf_free(bw_svf instance) {
BW_FREE(instance);
}
void bw_svf_set_sample_rate(bw_svf instance, float sample_rate) {
instance->t_k = 3.141592653589793f / sample_rate;
instance->smooth_mA1 = bw_inline_one_pole_get_mA1(sample_rate, 0.05f);
}
void bw_svf_reset(bw_svf instance) {
instance->first_run = 1;
}
#define PARAM_CUTOFF 1
#define PARAM_Q (1<<1)
static inline void update_coefficients(bw_svf instance) {
const char cutoff_changed = instance->cutoff != instance->cutoff_cur || instance->first_run;
const char Q_changed = instance->Q != instance->Q_cur || instance->first_run;
if (cutoff_changed || Q_changed) {
if (cutoff_changed) {
instance->cutoff_cur = bw_inline_one_pole_sticky_rel(instance->cutoff, instance->cutoff_cur, instance->smooth_mA1, 1e-6f);
instance->t = bw_tanf_3(instance->t_k * instance->cutoff_cur);
}
if (Q_changed) {
instance->Q_cur = bw_inline_one_pole_sticky_abs(instance->Q, instance->Q_cur, instance->smooth_mA1, 1e-6f);
instance->k = bw_rcpf_2(instance->Q_cur);
}
const float kpt = instance->k + instance->t;
instance->hp_hp_z1 = instance->t * kpt;
instance->hp_bp_z1 = instance->t + kpt;
instance->hp_x = bw_rcpf_2(1.f + instance->hp_hp_z1);
}
}
void bw_svf_process(bw_svf instance, const float *x, float *y_lp, float *y_bp, float *y_hp, int n_samples) {
if (instance->first_run) {
instance->cutoff_cur = instance->cutoff;
instance->Q_cur = instance->Q;
update_coefficients(instance);
instance->hp_z1 = 0.f;
instance->lp_z1 = 0.f;
instance->bp_z1 = 0.f;
instance->first_run = 0;
}
for (int i = 0; i < n_samples; i++) {
update_coefficients(instance);
const float hp = instance->hp_x * (x[i] - instance->lp_z1 + instance->hp_bp_z1 * instance->bp_z1 - instance->hp_hp_z1 * instance->hp_z1);
const float bp = instance->bp_z1 - instance->t * (hp + instance->hp_z1);
const float lp = instance->lp_z1 - instance->t * (bp + instance->bp_z1);
instance->hp_z1 = hp;
instance->lp_z1 = lp;
instance->bp_z1 = bp;
if (y_lp)
y_lp[i] = lp;
if (y_bp)
y_bp[i] = bp;
if (y_hp)
y_hp[i] = hp;
}
}
void bw_svf_set_cutoff(bw_svf instance, float value) {
instance->cutoff = value;
}
void bw_svf_set_Q(bw_svf instance, float value) {
instance->Q = value;
}

89
src/bw_vol.c Normal file
View File

@ -0,0 +1,89 @@
/*
* Brickworks
*
* Copyright (C) 2022 Orastron Srl unipersonale
*
* Brickworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* Brickworks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* File author: Stefano D'Angelo
*/
#include <bw_vol.h>
#include <bw_inline_slew_lim.h>
#define BUFFER_SIZE 32
struct _bw_vol {
// Coefficients
float max_var;
// Parameters
float volume;
float volume_cur;
// State
char first_run;
// Buffers
float buf[BUFFER_SIZE];
};
bw_vol bw_vol_new() {
bw_vol instance = (bw_vol)BW_MALLOC(sizeof(struct _bw_vol));
if (instance == NULL)
return NULL;
instance->volume = 1.f;
return instance;
}
void bw_vol_free(bw_vol instance) {
BW_FREE(instance);
}
void bw_vol_set_sample_rate(bw_vol instance, float sample_rate) {
instance->max_var = bw_inline_slew_lim_get_max_var(sample_rate, 1.f / 0.05f);
}
void bw_vol_reset(bw_vol instance) {
instance->first_run = 1;
}
void bw_vol_process(bw_vol instance, const float **x, float **y, int n_channels, int n_samples) {
if (instance->first_run) {
instance->volume_cur = instance->volume;
instance->first_run = 0;
}
for (int i = 0; i < n_samples; i += BUFFER_SIZE) {
const uint32_t n = bw_minu32(n_samples - i, BUFFER_SIZE);
for (int j = 0; j < BUFFER_SIZE; j++) {
instance->volume_cur = bw_inline_slew_lim(instance->volume, instance->volume_cur, instance->max_var, instance->max_var);
instance->buf[j] = instance->volume_cur * instance->volume_cur * instance->volume_cur;
}
for (int j = 0; j < n_channels; j++) {
const float *in = x[j] + i;
float *out = y[j] + i;
for (int k = 0; k < BUFFER_SIZE; k++)
out[k] = instance->buf[k] * in[k];
}
}
}
void bw_vol_set_volume(bw_vol instance, float value) {
instance->volume = value;
}