├── .gitattributes ├── .gitignore ├── INSTALL.txt ├── LICENSE ├── Makefile ├── README.md ├── audio ├── ir-cym.wav ├── ir-large-chamber.wav ├── ir-tam.wav └── ir-tunnel.wav ├── convolve~-help.pd ├── pd-lib-builder └── Makefile.pdlibbuilder └── src └── convolve~.c /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | audio/.DS_Store 3 | src/convolve~.o 4 | convolve~.* 5 | libfftw3f-3.dll 6 | -------------------------------------------------------------------------------- /INSTALL.txt: -------------------------------------------------------------------------------- 1 | ******** DEPENDENCIES: 2 | As of version 0.10, [convolve~] requires FFTW 3.3.5 or greater, available at http://www.fftw.org. 3 | 4 | FFTW is included pre-compiled with convolve~'s Windows binary package available via deken. Simply leave libfftw3f-3.dll in the convolve~ directory for use as a shared library. For Linux and Macintosh, the FFTW library is statically linked with the convolve~ binary file, so there is no need for compiling or obtaining FFTW if you installed convolve~ via deken. 5 | 6 | 7 | ******** COMPILING FFTW: 8 | If you are compliling FFTW yourself, it must be done in single precision for use with convolve~. To do so in Linux, configure FFTW like this: 9 | 10 | ./configure CFLAGS="-fPIC" --enable-float 11 | 12 | and like this on a Macintosh: 13 | 14 | ./configure CFLAGS="-arch i386 -arch x86_64" --enable-float 15 | 16 | and like this on a Raspberry Pi: 17 | 18 | ./configure CFLAGS="-fPIC" --enable-float 19 | 20 | Then execute: 21 | 22 | make 23 | sudo make install 24 | 25 | On Linux and Macintosh, the FFTW library files should be installed to /usr/local/lib by default. 26 | 27 | 28 | ******** COMPILING CONVOLVE~ FOR LINUX AND MACOS: 29 | Once FFTW is properly built and installed, you can compile convolve~ using the included Makefile by executing: 30 | 31 | make 32 | 33 | On Linux and Macintosh, convolve~ will be statically linked the FFTW library. 34 | 35 | 36 | ******** COMPILING CONVOLVE~ FOR WINDOWS: 37 | convolve~ can be compiled on Windows with the included Makefile if you use MSYS2/MinGW: https://www.msys2.org/ and install base development tools as described in the MSYS2 installation guide. 38 | 39 | You will first need to install The FFTW library for Windows, which is available precompiled at: 40 | 41 | http://www.fftw.org/install/windows.html 42 | 43 | The fftw-3.3.5-dll64.zip file contains headers and several compiled versions of FFTW, but only fftw3.h and libfftw3f-3.dll are required for convolve~. Place fftw3.h in your msys64/usr/local/include directory, and libfftw3f-3.dll in your msys64/usr/local/lib directory. Because the Windows version of the FFTW library is named differently than the Linux and MacOS versions, you'll have to make one edit to the Makefile, appending "-3" to the end of the library name on this line: 44 | 45 | ldlibs = -L/usr/local/lib -lfftw3f-3 46 | 47 | Finally, place a copy of libfftw3f-3.dll in the same directory containing convolve~.dll, and convolve~ should run successfully in Pd. 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) 2018 {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | convolve_tilde Copyright (C) 2018 William Brent 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for [convolve~] 2 | 3 | # specify a location for Pd if desired 4 | # PDDIR = /home/yourname/somedirectory/pd-0.51-4 5 | 6 | lib.name = convolve~ 7 | 8 | # specify the location and name of the FFTW library 9 | # for Linux and MacOS, use: 10 | ldlibs = -L/usr/local/lib -lfftw3f 11 | # for Windows, use: 12 | # ldlibs = -L/usr/local/lib -lfftw3f-3 13 | 14 | # specify the location of FFTW header file 15 | cflags = -Iinclude -I/usr/local/include 16 | 17 | $(lib.name).class.sources = ./src/convolve~.c 18 | 19 | datafiles = $(lib.name)-help.pd 20 | 21 | # provide the path to pd-lib-builder 22 | PDLIBBUILDER_DIR=./pd-lib-builder/ 23 | include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # convolve_tilde 2 | 3 | [convolve~] is a partitioned impulse response (IR) convolution external for Pure Data. The only creation argument is the partition size, which also determines the amount of delay between the dry and wet signal (i.e., pre-delay). Partition size must be a multiple of Pd's default block size: 64 samples (1.4512ms @ 44100Hz). 4 | -------------------------------------------------------------------------------- /audio/ir-cym.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbrent/convolve_tilde/b1be0aab0cd181b2b928a170ff749bebe7f7dc76/audio/ir-cym.wav -------------------------------------------------------------------------------- /audio/ir-large-chamber.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbrent/convolve_tilde/b1be0aab0cd181b2b928a170ff749bebe7f7dc76/audio/ir-large-chamber.wav -------------------------------------------------------------------------------- /audio/ir-tam.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbrent/convolve_tilde/b1be0aab0cd181b2b928a170ff749bebe7f7dc76/audio/ir-tam.wav -------------------------------------------------------------------------------- /audio/ir-tunnel.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wbrent/convolve_tilde/b1be0aab0cd181b2b928a170ff749bebe7f7dc76/audio/ir-tunnel.wav -------------------------------------------------------------------------------- /convolve~-help.pd: -------------------------------------------------------------------------------- 1 | #N canvas 256 136 1030 663 10; 2 | #N canvas 641 50 679 463 init 0; 3 | #X obj 246 318 soundfiler; 4 | #X msg 357 133 \; \$1-dry-volume-set 0 \; \$1-wet-volume-set 0 \; \$1-master-volume-set 5 | 0 \;; 6 | #X obj 357 113 f \$0; 7 | #X obj 407 38 f \$0; 8 | #X obj 46 58 loadbang; 9 | #X obj 23 79 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 10 | -1; 11 | #X obj 46 190 s \$0-lb4; 12 | #X obj 46 79 t b b b b; 13 | #X obj 136 130 s \$0-lb1; 14 | #X obj 106 150 s \$0-lb2; 15 | #X obj 76 170 s \$0-lb3; 16 | #X obj 246 27 r \$0-lb2; 17 | #X msg 246 208 read -resize ./audio/ir-large-chamber.wav \$1-largeChamber 18 | ; 19 | #X msg 286 228 read -resize ./audio/ir-tunnel.wav \$1-tunnel; 20 | #X msg 326 248 read -resize ./audio/ir-tam.wav \$1-tamTam; 21 | #X msg 366 268 read -resize ./audio/ir-cym.wav \$1-cymbal; 22 | #X obj 246 159 f \$0; 23 | #X obj 246 180 t f f f f; 24 | #X obj 246 48 t b b b; 25 | #X msg 407 58 \; \$1-25-band-eq const 1 \;; 26 | #X connect 2 0 1 0; 27 | #X connect 3 0 19 0; 28 | #X connect 4 0 7 0; 29 | #X connect 5 0 7 0; 30 | #X connect 7 0 6 0; 31 | #X connect 7 1 10 0; 32 | #X connect 7 2 9 0; 33 | #X connect 7 3 8 0; 34 | #X connect 11 0 18 0; 35 | #X connect 12 0 0 0; 36 | #X connect 13 0 0 0; 37 | #X connect 14 0 0 0; 38 | #X connect 15 0 0 0; 39 | #X connect 16 0 17 0; 40 | #X connect 17 0 12 0; 41 | #X connect 17 1 13 0; 42 | #X connect 17 2 14 0; 43 | #X connect 17 3 15 0; 44 | #X connect 18 0 16 0; 45 | #X connect 18 1 2 0; 46 | #X connect 18 2 3 0; 47 | #X restore 301 90 pd init; 48 | #X floatatom 361 348 5 0 0 0 - #0-master-volume -, f 5; 49 | #X obj 110 91 readsf~; 50 | #X msg 132 62 stop; 51 | #X obj 34 55 *~; 52 | #X obj 34 126 +~; 53 | #X obj 64 55 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1 54 | ; 55 | #X obj 158 246 env~; 56 | #X floatatom 158 267 5 0 0 1 dB - -, f 5; 57 | #X obj 224 348 hsl 128 15 0 100 0 0 \$0-master-volume \$0-master-volume-set 58 | master-volume 8 8 0 12 -228856 -1 -1 8700 1; 59 | #X obj 481 37 cnv 15 400 220 empty empty empty 20 12 0 14 -233017 -66577 60 | 0; 61 | #X obj 481 352 cnv 15 220 220 empty empty empty 20 12 0 14 -233017 62 | -66577 0; 63 | #X text 490 360 Try these different IRs; 64 | #X floatatom 361 328 5 0 0 0 - #0-wet-volume -, f 5; 65 | #X obj 224 328 hsl 128 15 0 100 0 0 \$0-wet-volume \$0-wet-volume-set 66 | wet-volume 8 8 0 12 -228856 -1 -1 12700 1; 67 | #X floatatom 361 308 5 0 0 0 - #0-dry-volume -, f 5; 68 | #X obj 224 308 hsl 128 15 0 100 0 0 \$0-dry-volume \$0-dry-volume-set 69 | dry-volume 8 8 0 12 -228856 -1 -1 0 1; 70 | #N canvas 190 207 521 438 mix-dry-and-wet 0; 71 | #X obj 46 24 inlet~; 72 | #X obj 46 364 outlet~; 73 | #X obj 46 289 *~; 74 | #X obj 346 247 dbtorms; 75 | #X obj 346 289 line~; 76 | #X obj 346 268 pack f 40; 77 | #X obj 46 159 *~; 78 | #X obj 96 117 dbtorms; 79 | #X obj 96 159 line~; 80 | #X obj 96 138 pack f 40; 81 | #X obj 46 230 +~; 82 | #X obj 236 24 inlet~; 83 | #X obj 236 159 *~; 84 | #X obj 286 117 dbtorms; 85 | #X obj 286 159 line~; 86 | #X obj 286 138 pack f 40; 87 | #X obj 96 96 r \$0-dry-volume; 88 | #X obj 286 96 r \$0-wet-volume; 89 | #X obj 346 226 r \$0-master-volume; 90 | #X connect 0 0 6 0; 91 | #X connect 2 0 1 0; 92 | #X connect 3 0 5 0; 93 | #X connect 4 0 2 1; 94 | #X connect 5 0 4 0; 95 | #X connect 6 0 10 0; 96 | #X connect 7 0 9 0; 97 | #X connect 8 0 6 1; 98 | #X connect 9 0 8 0; 99 | #X connect 10 0 2 0; 100 | #X connect 11 0 12 0; 101 | #X connect 12 0 10 1; 102 | #X connect 13 0 15 0; 103 | #X connect 14 0 12 1; 104 | #X connect 15 0 14 0; 105 | #X connect 16 0 7 0; 106 | #X connect 17 0 13 0; 107 | #X connect 18 0 3 0; 108 | #X restore 34 302 pd mix-dry-and-wet; 109 | #N canvas 0 23 487 359 cpu-meter 0; 110 | #X floatatom 103 122 5 0 0 1 % - -, f 5; 111 | #X obj 272 158 cputime; 112 | #X obj 272 102 metro 1000; 113 | #X msg 272 66 1; 114 | #X obj 272 130 t b b; 115 | #X obj 272 218 * 0.1; 116 | #X obj 272 187 int; 117 | #X obj 272 38 r \$0-lb1; 118 | #X connect 1 0 6 0; 119 | #X connect 2 0 4 0; 120 | #X connect 3 0 2 0; 121 | #X connect 4 0 1 0; 122 | #X connect 4 1 1 1; 123 | #X connect 5 0 0 0; 124 | #X connect 6 0 5 0; 125 | #X connect 7 0 3 0; 126 | #X coords 0 -1 1 1 85 40 1 100 100; 127 | #X restore 731 280 pd cpu-meter; 128 | #X obj 159 158 r \$0-convolve; 129 | #X obj 513 548 s \$0-convolve; 130 | #X text 834 624 William Brent \, March 2018; 131 | #X obj 4 4 cnv 10 400 10 empty empty empty 20 12 0 14 -233017 -66577 132 | 0; 133 | #X obj 4 4 cnv 10 10 400 empty empty empty 20 12 0 14 -233017 -66577 134 | 0; 135 | #X obj 731 352 cnv 15 220 220 empty empty empty 20 12 0 14 -233017 136 | -66577 0; 137 | #X obj 753 539 s \$0-convolve; 138 | #X msg 793 503 window 64; 139 | #X msg 773 473 window 1920; 140 | #N canvas 740 104 913 453 partitioned-convolution-explained 0; 141 | #X text 38 177 This is the standard frequency domain method \, which 142 | is much faster than performing convolution in the time domain. In either 143 | case \, the result is that a scaled and time shifted copy of one file 144 | takes the place of every single sample in the other. So \, if you have 145 | an impulse response (IR) of a room - that is \, a burst of noise followed 146 | by the natural echos the room produces - you can graft that pattern 147 | of echos onto every single sample in your input file.; 148 | #X text 38 297 With real-time input \, the situation becomes more complicated. 149 | We can have an IR prepared in advance \, but the other sound source 150 | only shows up bit by bit. Typically \, it will arrive in chunks of 151 | 64 \, 128 \, 256 \, or some other number of samples. Partitioned convolution 152 | solves this problem by breaking up the IR into some number of partitions 153 | that is each M samples long. M should be the same size as the chunks 154 | of input that arrive in real time. Then \, each of the partitions is 155 | Fourier transformed and stored as frequency domain data.; 156 | #X text 488 247 The last point to make is that the size of the Fourier 157 | transform must be M*2. That is \, when we get the latest M samples 158 | \, we pad it out with zeros to M*2 samples \, then transform it. All 159 | of the IR partitions are padded to this same size. When any one chunk 160 | is inverse Fourier transformed \, its main content will be over the 161 | first M samples \, trailed by low amplitude samples or zeros. A process 162 | of overlapping and adding is then performed so that the first M samples 163 | of the most recently processed M*2 samples is mixed down with the last 164 | M samples of the previous chunk of processed M*2 samples.; 165 | #X text 488 27 When each new input chunk arrives (the M most recent 166 | samples) \, it is Fourier transformed into complex frequency domain 167 | data. The new chunk of frequency domain data is multiplied against 168 | each of the pre-prepared IR partitions that are also in the frequency 169 | domain. We can immediately do an inverse Fourier transform on the most 170 | recently available chunk to hear that portion of the processed input 171 | in the time domain \, but the other chunks will wait in a buffer to 172 | be output in the future. The crucial point to understand is that as 173 | new input chunks come in and are transformed and multiplied in the 174 | frequency domain \, we sum that new data with whatever other frequency 175 | domain data was waiting in that part of the buffer. Thus \, we save 176 | numerous FFT calls by summing in the frequency domain.; 177 | #X text 38 27 With two pre-recorded sound files \, convolution is pretty 178 | simple. We determine which file is longer \, find the next highest 179 | power of 2 (we'll call it N) \, and then pad each of the files with 180 | addiontal zeros up to N. Next \, we do a forward Fourier transform 181 | on each of them \, and multiply the transformed data sets point by 182 | point. Because the data contain complex values \, we must do a complex 183 | multiply vis FOIL. After multiplication \, all that is left to do is 184 | an inverse Fourier transform on the frequency domain product. Depending 185 | on the specific FFT algorithm being used \, you may also have to scale 186 | the amplitude by the reciprocal of N.; 187 | #X restore 481 267 pd partitioned-convolution-explained; 188 | #X text 218 364 ** Beware of hot output!! **; 189 | #X text 728 326 Small partition sizes are expensive, f 36; 190 | #X msg 110 40 open ../doc/sound/voice.wav \, start; 191 | #X obj 301 224 cnv 15 150 60 empty empty empty 20 12 0 14 -233017 -66577 192 | 0; 193 | #X text 310 232 Other messages; 194 | #N canvas 550 54 468 228 other-messages 0; 195 | #X obj 54 158 s \$0-convolve; 196 | #X msg 54 62 flush; 197 | #X msg 74 112 print; 198 | #X text 136 111 Print internal settings to the post window; 199 | #X text 116 61 Flush all internal buffer contents; 200 | #X connect 1 0 0 0; 201 | #X connect 2 0 0 0; 202 | #X restore 312 256 pd other-messages; 203 | #X text 740 360 Change window/partition size (and therefore delay) 204 | in samples. Window sizes do not need to be powers of two \, but they 205 | must be multiples of Pd's default block size (64)., f 31; 206 | #X text 478 578 It's ok to analyze different IRs and change window 207 | size on the fly \, although audio will be interrupted., f 35; 208 | #X obj 493 383 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 209 | -1 -1; 210 | #X obj 513 383 f \$0; 211 | #X msg 513 403 analyze \$1-largeChamber; 212 | #X msg 513 443 analyze \$1-tunnel; 213 | #X msg 513 483 analyze \$1-tamTam; 214 | #X msg 513 523 analyze \$1-cymbal; 215 | #X obj 301 111 table \$0-largeChamber; 216 | #X obj 301 153 table \$0-tamTam; 217 | #X obj 301 174 table \$0-cymbal; 218 | #X obj 493 423 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 219 | -1 -1; 220 | #X obj 513 423 f \$0; 221 | #X obj 493 463 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 222 | -1 -1; 223 | #X obj 513 463 f \$0; 224 | #X obj 493 503 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 225 | -1 -1; 226 | #X obj 513 503 f \$0; 227 | #X msg 753 443 window 320; 228 | #X text 834 604 [convolve~] version 0.11; 229 | #X obj 34 351 dac~; 230 | #X obj 34 34 adc~; 231 | #X obj 139 208 convolve~ 640 \$0-tunnel; 232 | #X text 490 51 [convolve~] is a partitioned impulse response (IR) convolution 233 | object. The 1st creation argument is the partition size \, which also 234 | determines the amount of delay between the dry and wet signal (i.e. 235 | \, pre-delay). Partition size must be a multiple of Pd's default block 236 | size: 64 samples (1.4512ms @ 44100Hz).; 237 | #X text 490 131 Optionally \, you can also supply the symbolic name 238 | of an array holding an IR as the 2nd creation argument so that you 239 | can begin use immediately at startup. Otherwise \, you must send [convolve~] 240 | an "analyze" message specifying the name of the table where your IR 241 | is stored.; 242 | #X text 490 201 Try playing the example voice.wav \, or listen to live 243 | input (with headphones to prevent feedback). No gain adjustments are 244 | made based on the IR in use \, so you'll have to find the right volume 245 | attenuation for your particular IR.; 246 | #X obj 301 132 table \$0-tunnel; 247 | #X text 32 400 Version 0.11 has a new "eq" method. Use the 25-band 248 | EQ table below \, which sends an "eq" messages when you click the "apply" 249 | button, f 62; 250 | #N canvas 196 114 478 333 25-band-EQ 0; 251 | #X obj 345 17 bng 15 250 50 0 empty empty unity 17 7 0 12 -262144 -1 252 | -1; 253 | #X obj 275 17 bng 15 250 50 0 empty empty mute 17 7 0 12 -262144 -1 254 | -1; 255 | #N canvas 0 22 450 278 (subpatch) 0; 256 | #X array \$0-25-band-eq 25 float 2; 257 | #X coords 0 1.25 25 0 355 64 1 0 0; 258 | #X restore 42 54 graph; 259 | #X text 39 268 Note that scalar values below 0 are clipped to 0 \, 260 | but there is no upper limit for scalars., f 67; 261 | #X obj 205 17 bng 15 250 50 0 \$0-send-eq-list empty apply 17 7 0 12 262 | -262144 -1 -1; 263 | #N canvas 548 198 650 289 mute-or-unity 0; 264 | #X obj 259 40 inlet; 265 | #X obj 49 40 inlet; 266 | #X obj 49 90 f \$0; 267 | #X obj 259 180 f \$0; 268 | #X msg 49 110 \; \$1-25-band-eq const 0 \;; 269 | #X msg 259 200 \; \$1-25-band-eq const 1 \;; 270 | #X obj 331 40 r \$0-convolve; 271 | #X obj 331 61 route analyze; 272 | #X obj 331 82 t b; 273 | #X text 330 126 With each new analysis \, [convolve~]'s internal EQ 274 | is reset to unity. Reset the EQ table here as a reminder of that., 275 | f 41; 276 | #X connect 0 0 3 0; 277 | #X connect 1 0 2 0; 278 | #X connect 2 0 4 0; 279 | #X connect 3 0 5 0; 280 | #X connect 6 0 7 0; 281 | #X connect 7 0 8 0; 282 | #X connect 8 0 3 0; 283 | #X restore 279 159 pd mute-or-unity; 284 | #N canvas 756 370 594 270 send-eq-message-from-array 0; 285 | #X obj 29 159 list prepend eq; 286 | #X obj 29 180 list trim; 287 | #X obj 29 201 s \$0-convolve; 288 | #X obj 29 62 r \$0-send-eq-list; 289 | #X obj 29 108 array get \$0-25-band-eq; 290 | #X text 218 95 Here \, we dump the scalar values out of the table and 291 | send them to [convolve~] as an "eq" message. Since working in linear 292 | frequency bins isn't very intuitive \, [convolve~] uses the Bark frequency 293 | scale to define 25 frequency bands from DC to Nyquist., f 46; 294 | #X connect 0 0 1 0; 295 | #X connect 1 0 2 0; 296 | #X connect 3 0 4 0; 297 | #X connect 4 0 0 0; 298 | #X restore 41 159 pd send-eq-message-from-array; 299 | #X text 39 189 As of version 0.11 \, you can scale the complex frequency-domain 300 | values of the IR analysis via an "eq" message. This allows you to boost 301 | or attenuate energy in any of 25 Bark-based frequency bands. The "eq" 302 | method expects a list of 25 scalar values. Here \, the values are dumped 303 | into a list using [array get]., f 67; 304 | #X connect 0 0 5 1; 305 | #X connect 1 0 5 0; 306 | #X coords 0 -1 1 1 380 120 1 30 10; 307 | #X restore 34 452 pd 25-band-EQ; 308 | #X connect 2 0 5 1; 309 | #X connect 2 1 31 0; 310 | #X connect 3 0 2 0; 311 | #X connect 4 0 5 0; 312 | #X connect 5 0 17 0; 313 | #X connect 5 0 56 0; 314 | #X connect 6 0 4 1; 315 | #X connect 7 0 8 0; 316 | #X connect 17 0 54 0; 317 | #X connect 17 0 54 1; 318 | #X connect 19 0 56 0; 319 | #X connect 26 0 25 0; 320 | #X connect 27 0 25 0; 321 | #X connect 31 0 2 0; 322 | #X connect 37 0 38 0; 323 | #X connect 38 0 39 0; 324 | #X connect 39 0 20 0; 325 | #X connect 40 0 20 0; 326 | #X connect 41 0 20 0; 327 | #X connect 42 0 20 0; 328 | #X connect 46 0 47 0; 329 | #X connect 47 0 40 0; 330 | #X connect 48 0 49 0; 331 | #X connect 49 0 41 0; 332 | #X connect 50 0 51 0; 333 | #X connect 51 0 42 0; 334 | #X connect 52 0 25 0; 335 | #X connect 55 0 4 0; 336 | #X connect 56 0 7 0; 337 | #X connect 56 0 17 1; 338 | -------------------------------------------------------------------------------- /pd-lib-builder/Makefile.pdlibbuilder: -------------------------------------------------------------------------------- 1 | # Makefile.pdlibbuilder dated 2019-12-21 2 | version = 0.6.0 3 | 4 | # Helper makefile for Pure Data external libraries. 5 | # Written by Katja Vetter March-June 2015 for the public domain. No warranties. 6 | # Inspired by Hans Christoph Steiner's Makefile Template and Stephan Beal's 7 | # ShakeNMake. 8 | # 9 | # Grab the newest version of Makefile.pdlibbuilder from 10 | # https://github.com/pure-data/pd-lib-builder/ 11 | # 12 | # GNU make version >= 3.81 required. 13 | # 14 | # 15 | #=== characteristics =========================================================== 16 | # 17 | # 18 | # - defines build settings based on autodetected OS and architecture 19 | # - defines rules to build Pd class- or lib executables from C or C++ sources 20 | # - defines rules for libdir installation 21 | # - defines convenience targets for developer and user 22 | # - evaluates implicit dependencies for non-clean builds 23 | # 24 | # 25 | #=== basic usage =============================================================== 26 | # 27 | # 28 | # In your Makefile, define your Pd lib name and class files, and include 29 | # Makefile.pdlibbuilder at the end of the Makefile. Like so: 30 | # 31 | # ________________________________________________________________________ 32 | # 33 | # # Makefile for mylib 34 | # 35 | # lib.name = mylib 36 | # 37 | # class.sources = myclass1.c myclass2.c 38 | # 39 | # datafiles = myclass1-help.pd myclass2-help.pd README.txt LICENSE.txt 40 | # 41 | # include Makefile.pdlibbuilder 42 | # ________________________________________________________________________ 43 | # 44 | # 45 | # For files in class.sources it is assumed that class basename == source file 46 | # basename. The default target builds all classes as individual executables 47 | # with Pd's default extension for the platform. For anything more than the 48 | # most basic usage, continue reading. 49 | # 50 | # 51 | #=== list of Makefile.pdlibbuilder API variables =============================== 52 | # 53 | # 54 | # Variables available for definition in your library Makefile: 55 | # 56 | # - lib.name 57 | # - lib.setup.sources 58 | # - class.sources 59 | # - common.sources 60 | # - shared.sources 61 | # - .class.sources 62 | # - .class.ldflags 63 | # - .class.ldlibs 64 | # - cflags 65 | # - ldflags 66 | # - ldlibs 67 | # - datafiles 68 | # - datadirs 69 | # - makefiles 70 | # - makefiledirs 71 | # - externalsdir 72 | # 73 | # Optional multiline defines evaluated per operating system: 74 | # 75 | # - forLinux 76 | # - forDarwin 77 | # - forWindows 78 | # 79 | # Variables available for your makefile or make command line: 80 | # 81 | # - make-lib-executable 82 | # - suppress-wunused 83 | # 84 | # Path variables for make command line or environment: 85 | # 86 | # - PDDIR 87 | # - PDINCLUDEDIR 88 | # - PDBINDIR 89 | # - PDLIBDIR 90 | # 91 | # Standard make variables for make command line or environment: 92 | # 93 | # - CPPFLAGS 94 | # - CFLAGS 95 | # - LDFLAGS 96 | # - CC 97 | # - CXX 98 | # - INSTALL 99 | # - STRIP 100 | # - DESTDIR 101 | # 102 | # Optional user variables for make command line or environment: 103 | # 104 | # - PLATFORM 105 | # 106 | # Deprecated path variables: 107 | # 108 | # - pdincludepath 109 | # - pdbinpath 110 | # - objectsdir 111 | # 112 | # 113 | #=== descriptions of Makefile.pdlibbuilder API variables ======================= 114 | # 115 | # 116 | # lib.name: 117 | # Name of the library directory as it will be installed / distributed. Also the 118 | # name of the lib executable in the case where all classes are linked into 119 | # a single binary. 120 | # 121 | # lib.setup.sources: 122 | # Source file(s) (C or C++) which must be compiled only when linking all classes 123 | # into a single lib binary. 124 | # 125 | # class.sources: 126 | # All sources files (C or C++) for which the condition holds that 127 | # class name == source file basename. 128 | # 129 | # .class.sources: 130 | # Source file(s) (C or C++) specific to class . Use this for 131 | # multiple-source classes or when class name != source file basename. 132 | # 133 | # common.sources: 134 | # Source file(s) which must be statically linked to each class in the library. 135 | # 136 | # shared.sources: 137 | # Source file(s) (C or C++) to build a shared dynamic link lib, to be linked 138 | # with all class executables. 139 | # 140 | # cflags, ldflags, ldlibs: 141 | # Define cflags (preprocessor&compiler), ldflags (linker) and ldlibs (dynamic 142 | # link libs) for the whole library. These flags are added to platform-specific 143 | # flags defined by Makefile.pdlibbuilder. 144 | # 145 | # .class.ldflags and .class.ldlibs: 146 | # Define ldflags resp. ldlibs specific to class . These flags are 147 | # added to platform-specific flags defined by Makefile.pdlibbuilder, and flags 148 | # defined in your Makefile for the whole library. Note: cflags can not be 149 | # defined per class in the current implementation. 150 | # 151 | # datafiles and datadirs: 152 | # All extra files you want to include in binary distributions of the 153 | # library: abstractions and help patches, example patches, meta patch, readme 154 | # and license texts, manuals, sound files, etcetera. Use 'datafiles' for all 155 | # files that should go into your lib rootdir and 'datadirs' for complete 156 | # directories you want to copy from source to distribution. 157 | # 158 | # forLinux, forDarwin, forWindows: 159 | # Shorthand for 'variable definitions for Linux only' etc. Use like: 160 | # define forLinux 161 | # cflags += -DLINUX 162 | # class.sources += linuxthing.c 163 | # endef 164 | # 165 | # makefiles and makefiledirs: 166 | # Extra makefiles or directories with makefiles that should be made in sub-make 167 | # processes. 168 | # 169 | # make-lib-executable: 170 | # When this variable is defined 'yes' in your makefile or as command argument, 171 | # Makefile.pdlibbuilder will try to build all classes into a single library 172 | # executable (but it will force exit if lib.setup.sources is undefined). 173 | # If your makefile defines 'make-lib-executable=yes' as the library default, 174 | # this can still be overridden with 'make-lib-executable=no' as command argument 175 | # to build individual class executables (the Makefile.pdlibbuilder default.) 176 | # 177 | # suppress-wunused: 178 | # When this variable is defined ('yes' or any other value), -Wunused-variable, 179 | # -Wunused-parameter, -Wunused-value and -Wunused-function are suppressed, 180 | # but the other warnings from -Wall are retained. 181 | # 182 | # PDDIR: 183 | # Root directory of 'portable' pd package. When defined, PDINCLUDEDIR and 184 | # PDBINDIR will be evaluated as $(PDDIR)/src and $(PDDIR)/bin. 185 | # 186 | # PDINCLUDEDIR: 187 | # Directory where Pd API m_pd.h should be found, and other Pd header files. 188 | # Overrides the default search path. 189 | # 190 | # PDBINDIR: 191 | # Directory where pd.dll should be found for linking (Windows only). Overrides 192 | # the default search path. 193 | # 194 | # PDLIBDIR: 195 | # Root directory for installation of Pd library directories. Overrides the 196 | # default install location. 197 | # 198 | # DESTDIR: 199 | # Prepended path component for staged install. 200 | # 201 | # PLATFORM: 202 | # Target platform for cross compilation in the form of GNU triplet: 203 | # cpu-vendor-os. Example: x86_64-w64-mingw32. This specifies the tool chain that 204 | # pdlibbuilder will use, if installed and locatable. System and architecture 205 | # will then be autodefined accordingly. In most cases no other variables need to 206 | # be overridden. 207 | # 208 | # CPPFLAGS: 209 | # Preprocessor flags which are not strictly required for building. 210 | # 211 | # CFLAGS: 212 | # Compiler flags which are not strictly required for building. Compiler flags 213 | # defined by Makefile.pdlibbuilder for warning, optimization and architecture 214 | # specification are overriden by CFLAGS. 215 | # 216 | # LDFLAGS: 217 | # Linker flags which are not strictly required for building. Linker flags 218 | # defined by Makefile.pdlibbuilder for architecture specification are overriden 219 | # by LDFLAGS. 220 | # 221 | # CC and CXX: 222 | # C and C++ compiler programs as defined in your build environment. 223 | # 224 | # INSTALL 225 | # Definition of install program. 226 | # 227 | # STRIP 228 | # Name of strip program. Default 'strip' can be overridden in cross compilation 229 | # environments. 230 | # 231 | # objectsdir: 232 | # Root directory for installation of Pd library directories, like PDLIBDIR but 233 | # not overridable by environment. Supported for compatibility with pd-extended 234 | # central makefile, but deprecated otherwise. 235 | # 236 | # pdincludepath, pdbinpath: 237 | # As PDINCLUDEDIR and PDBINDIR but not overridable by environment. Deprecated 238 | # as user variables. 239 | # 240 | # 241 | #=== paths ===================================================================== 242 | # 243 | # 244 | # Source files in directories other than current working directory must be 245 | # prefixed with their relative path. Do not rely on VPATH or vpath. 246 | # Object (.o) files are built in the directory of their source files. 247 | # Executables are built in current working directory. 248 | # 249 | # Default search path for m_pd.h and other API header files is platform 250 | # dependent, and overridable by PDINCLUDEDIR: 251 | # 252 | # Linux: /usr/include/pd 253 | # 254 | # OSX: /Applications/Pd*.app/Contents/Resources/src 255 | # 256 | # Windows: %PROGRAMFILES%/Pd/src 257 | # %PROGRAMFILES(X86)%/Pd/src (32 bit builds on 64 bit Windows) 258 | # 259 | # Default search path for binary pd.dll (Windows), overridable by PDBINDIR 260 | # 261 | # %PROGRAMFILES%/Pd/bin 262 | # %PROGRAMFILES(X86)%/Pd/bin (32 bit builds on 64 bit Windows) 263 | # 264 | # Default location to install pd libraries is platform dependent, and 265 | # overridable by PDLIBDIR: 266 | # 267 | # Linux: /usr/local/lib/pd-externals 268 | # OSX: ~/Library/Pd 269 | # Windows: %APPDATA%/Pd 270 | # 271 | # https://puredata.info/docs/faq/how-do-i-install-externals-and-help-files 272 | # The rationale for not installing to ~/pd-externals by default on Linux 273 | # is that some people share the home dir between 32 and 64 bit installations. 274 | # 275 | # 276 | #=== targets =================================================================== 277 | # 278 | # 279 | # all: build $(executables) plus optional post target 280 | # post: target to build after $(executables) 281 | # alldebug: build all with -g option turned on for debug symbols 282 | # : force clean build of an individual class 283 | # .pre: make preprocessor output file in current working directory 284 | # .lst: make asm/source output file in current working directory 285 | # 286 | # install: install executables and data files 287 | # clean: remove build products from source tree 288 | # 289 | # help: print help text 290 | # vars: print makefile variables 291 | # allvars: print all variables 292 | # depend: print generated prerequisites 293 | # dumpmachine: print compiler output of option '-dumpmachine' 294 | # coffee: dummy target 295 | # 296 | # Variable $(executables) expands to class executables plus optional shared lib, 297 | # or alternatively to single lib executable when make-lib-executable=true. 298 | # Targets pre and post can be defined by library makefile. Make sure to include 299 | # Makefile.pdlibbuilder first so default target all will not be redefined. 300 | # 301 | # 302 | #=== Pd-extended libdir concept ================================================ 303 | # 304 | # 305 | # For libdir layout as conceived by Hans-Christoph Steiner, see: 306 | # 307 | # https://puredata.info/docs/developer/Libdir 308 | # 309 | # Files README.txt, LICENSE.txt and -meta.pd are part of the libdir 310 | # convention. Help patches for each class and abstraction are supposed to be 311 | # available. Makefile.pdlibbuilder does not force the presence of these files 312 | # however. It does not automatically include such files in libdir installations. 313 | # Data files you want to include in distributions must be defined explicitly in 314 | # your Makefile. 315 | # 316 | # 317 | #=== Makefile.pdlibbuilder syntax conventions ================================== 318 | # 319 | # 320 | # Makefile.pdlibbuilder variable names are lower case. Default make variables, 321 | # environment variables, and standard user variables (CC, CXX, CFLAGS, DESTDIR) 322 | # are upper case. Use target 'allvars' to print all variables and their values. 323 | # 324 | # 'Fields' in data variables are separated by dots, like in 'foo.class.sources'. 325 | # Words in variables expressing a function or command are separated by dashes, 326 | # like in 'make-lib-executable'. 327 | # 328 | # 329 | #=== useful make options ======================================================= 330 | # 331 | # 332 | # Use 'make -d ' to print debug details of the make process. 333 | # Use 'make -p ' to print make's database. 334 | # 335 | # 336 | #=== TODO ====================================================================== 337 | # 338 | # 339 | # - decide whether to use -static-libgcc or shared dll in MinGW 340 | # - cygwin support 341 | # - android support 342 | # - figure out how to handle '$' in filenames 343 | # - add makefile template targets dpkg-source dist libdir distclean tags? 344 | # 345 | # 346 | #=== end of documentation sections ============================================= 347 | # 348 | # 349 | ################################################################################ 350 | ################################################################################ 351 | ################################################################################ 352 | 353 | 354 | # GNU make version 3.81 (2006) or higher is required because of the following: 355 | # - function 'info' 356 | # - variable '.DEFAULT_GOAL' 357 | 358 | # force exit when make version is < 3.81 359 | ifneq ($(firstword $(sort 3.81 $(MAKE_VERSION))), 3.81) 360 | $(error GNU make version 3.81 or higher is required) 361 | endif 362 | 363 | # Relative path to externals root dir in multi-lib source tree like 364 | # pd-extended SVN. Default is parent of current working directory. May be 365 | # defined differently in including makefile. 366 | externalsdir ?= .. 367 | 368 | # variable you can use to check if Makefile.pdlibbuilder is already included 369 | Makefile.pdlibbuilder = true 370 | 371 | 372 | ################################################################################ 373 | ### target platform detection ################################################## 374 | ################################################################################ 375 | 376 | 377 | #=== target platform =========================================================== 378 | 379 | 380 | # PLATFORM: optional user variable to define target platform for cross 381 | # compilation. Redefine build tools accordingly. PLATFORM should match 382 | # the exact target prefix of tools present in $PATH, like x86_64-w64-mingw32, 383 | # x86_64-apple-darwin12 etc. Tool definitions are exported to ensure submakes 384 | # will get the same. 385 | 386 | ifneq ($(PLATFORM),) 387 | ifneq ($(findstring darwin, $(PLATFORM)),) 388 | export CC = $(PLATFORM)-cc 389 | export CXX = $(PLATFORM)-c++ 390 | export CPP = $(PLATFORM)-cc 391 | else 392 | export CC = $(PLATFORM)-gcc 393 | export CXX = $(PLATFORM)-g++ 394 | export CPP = $(PLATFORM)-cpp 395 | endif 396 | STRIP = $(PLATFORM)-strip 397 | endif 398 | 399 | # Let (native or cross-) compiler report target triplet and isolate individual 400 | # words therein to facilitate later processing. 401 | target.triplet := $(subst -, ,$(shell $(CC) -dumpmachine)) 402 | 403 | 404 | #=== operating system ========================================================== 405 | 406 | 407 | # The following systems are defined: Linux, Darwin, Windows. GNU and 408 | # GNU/kFreeBSD are treated as Linux to get the same options. 409 | 410 | ifneq ($(filter linux gnu% kfreebsd, $(target.triplet)),) 411 | system = Linux 412 | endif 413 | 414 | ifneq ($(filter darwin%, $(target.triplet)),) 415 | system = Darwin 416 | endif 417 | 418 | ifneq ($(filter mingw% cygwin%, $(target.triplet)),) 419 | system = Windows 420 | endif 421 | 422 | # evaluate possible system-specific multiline defines from library makefile 423 | $(eval $(for$(system))) 424 | 425 | 426 | # TODO: Cygwin, Android 427 | 428 | 429 | #=== architecture ============================================================== 430 | 431 | 432 | # The following CPU names can be processed by pdlibbuilder: 433 | # i*86 Intel 32 bit 434 | # x86_64 Intel 64 bit 435 | # arm ARM 32 bit 436 | # aarch64 ARM 64 bit 437 | 438 | target.arch := $(firstword $(target.triplet)) 439 | 440 | 441 | ################################################################################ 442 | ### variables per platform ##################################################### 443 | ################################################################################ 444 | 445 | 446 | #=== flags per architecture ==================================================== 447 | 448 | 449 | # Set architecture-dependent cflags, mainly for Linux. For Mac and Windows, 450 | # arch.c.flags are overriden below. To see gcc's default architecture flags: 451 | # $ gcc -Q --help=target 452 | 453 | # ARMv6: Raspberry Pi 1st gen, not detectable from target.arch 454 | ifeq ($(shell uname), armv6l) 455 | arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard 456 | 457 | # ARMv7: Beagle, Udoo, RPi2 etc. 458 | else ifeq ($(target.arch), arm) 459 | arch.c.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard 460 | 461 | # ARMv8 64 bit, not tested yet 462 | else ifeq ($(target.arch), aarch64) 463 | arch.c.flags = -mcpu=cortex-a53 464 | 465 | # Intel 32 bit, build with SSE and SSE2 instructions 466 | else ifneq ($(filter i%86, $(target.arch)),) 467 | arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2 468 | 469 | # Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions 470 | else ifeq ($(target.arch), x86_64) 471 | arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 472 | 473 | # if none of the above architectures detected 474 | else 475 | arch.c.flags = 476 | endif 477 | 478 | 479 | #=== flags and paths for Linux ================================================= 480 | 481 | 482 | ifeq ($(system), Linux) 483 | prefix = /usr/local 484 | libdir := $(prefix)/lib 485 | pkglibdir = $(libdir)/pd-externals 486 | pdincludepath := $(wildcard /usr/include/pd) 487 | extension = pd_linux 488 | cpp.flags := -DUNIX 489 | c.flags := -fPIC 490 | c.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags 491 | c.ldlibs := -lc -lm 492 | cxx.flags := -fPIC -fcheck-new 493 | cxx.ldflags := -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags 494 | cxx.ldlibs := -lc -lm -lstdc++ 495 | shared.extension = so 496 | shared.ldflags := -rdynamic -fPIC -shared -Wl,-soname,$(shared.lib) 497 | endif 498 | 499 | 500 | #=== flags and paths for Darwin ================================================ 501 | 502 | 503 | # LLVM-clang doesn't support -fcheck-new, therefore this flag is only used when 504 | # compiling with g++. 505 | 506 | ifeq ($(system), Darwin) 507 | pkglibdir = $(HOME)/Library/Pd 508 | pdincludepath := $(firstword $(wildcard \ 509 | /Applications/Pd*.app/Contents/Resources/src)) 510 | extension = pd_darwin 511 | cpp.flags := -DUNIX -DMACOSX -I /sw/include 512 | c.flags := 513 | c.ldflags := -undefined suppress -flat_namespace -bundle 514 | c.ldlibs := -lc 515 | cxx.ldflags := -undefined suppress -flat_namespace -bundle 516 | cxx.ldlibs := -lc 517 | shared.extension = dylib 518 | shared.ldflags = -dynamiclib -undefined dynamic_lookup \ 519 | -install_name @loader_path/$(shared.lib) \ 520 | -compatibility_version 1 -current_version 1.0 521 | ifneq ($(filter %g++, $(CXX)),) 522 | cxx.flags := -fcheck-new 523 | endif 524 | ifeq ($(extension), d_fat) 525 | arch := i386 x86_64 526 | else 527 | arch := $(target.arch) 528 | endif 529 | ifneq ($(filter -mmacosx-version-min=%, $(cflags)),) 530 | version.flag := $(filter -mmacosx-version-min=%, $(cflags)) 531 | else 532 | version.flag = -mmacosx-version-min=10.6 533 | endif 534 | arch.c.flags := $(addprefix -arch , $(arch)) $(version.flag) 535 | arch.ld.flags := $(arch.c.flags) 536 | endif 537 | 538 | 539 | #=== flags and paths for Windows =============================================== 540 | 541 | 542 | # Standard paths on Windows contain spaces, and GNU make functions treat such 543 | # paths as lists, with unintended effects. Therefore we must use shell function 544 | # ls instead of make's wildcard when probing for a path, and use double quotes 545 | # when specifying a path in a command argument. 546 | 547 | # Default paths in Mingw / Mingw-w64 environments. 'PROGRAMFILES' is standard 548 | # location for builds with native architecture, 'ProgramFiles(x86)' for i686 549 | # builds on x86_64 Windows (detection method by Lucas Cordiviola). Curly braces 550 | # required because of parentheses in variable name. 551 | ifeq ($(system), Windows) 552 | pkglibdir := $(APPDATA)/Pd 553 | ifeq ($(target.arch), i686) 554 | programfiles := ${ProgramFiles(x86)} 555 | else 556 | programfiles := $(PROGRAMFILES) 557 | endif 558 | pdbinpath := $(programfiles)/Pd/bin 559 | pdincludepath := $(programfiles)/Pd/src 560 | endif 561 | 562 | # Store default path to pd.dll in PDBINDIR if the latter is not user-defined. 563 | # For include path this is done in the platform-independent paths section below, 564 | # but for PDBINDIR it is done here so ld flags can be evaluated as immediate 565 | # variables. 566 | ifeq ($(system), Windows) 567 | ifdef PDDIR 568 | PDBINDIR := $(PDDIR)/bin 569 | endif 570 | PDBINDIR ?= $(pdbinpath) 571 | endif 572 | 573 | # TODO: decide whether -mms-bitfields should be specified. 574 | ifeq ($(system), Windows) 575 | cpp.flags := -DMSW -DNT 576 | ifeq ($(target.arch), i686) 577 | arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse 578 | else ifeq ($(target.arch), x86_64) 579 | cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 580 | arch.c.flags := -march=core2 -msse -msse2 -msse3 -mfpmath=sse 581 | else 582 | arch.c.flags = 583 | endif 584 | extension = dll 585 | c.flags := 586 | c.ldflags := -static-libgcc -shared \ 587 | -Wl,--enable-auto-import "$(PDBINDIR)/pd.dll" 588 | c.ldlibs := 589 | cxx.flags := -fcheck-new 590 | cxx.ldflags := -static-libgcc -static-libstdc++ -shared \ 591 | -Wl,--enable-auto-import "$(PDBINDIR)/pd.dll" 592 | cxx.ldlibs := 593 | shared.extension = dll 594 | shared.ldflags := -static-libgcc -shared "$(PDBINDIR)/pd.dll" 595 | stripflags = --strip-all 596 | endif 597 | 598 | 599 | #=== paths ===================================================================== 600 | 601 | 602 | # Platform-dependent default paths are specified above, but overridable. 603 | # Path variables in upper case can be defined as make command argument or in the 604 | # environment. Variable 'objectsdir' is supported for compatibility with 605 | # the build system that pd-l2ork has inherited from pd-extended. 606 | 607 | PDINCLUDEDIR ?= $(pdincludepath) 608 | PDLIBDIR ?= $(firstword $(objectsdir) $(pkglibdir)) 609 | 610 | ifdef PDDIR 611 | PDINCLUDEDIR := $(wildcard $(PDDIR)/src) 612 | endif 613 | 614 | # base path where all components of the lib will be installed by default 615 | installpath := $(DESTDIR)$(PDLIBDIR)/$(lib.name) 616 | 617 | # check if include path contains spaces (as is often the case on Windows) 618 | # if so, store the path so we can later do checks with it 619 | pdincludepathwithspaces := $(if $(word 2, $(PDINCLUDEDIR)), $(PDINCLUDEDIR)) 620 | 621 | 622 | #=== accumulated build flags =================================================== 623 | 624 | 625 | # From GNU make docs: 'Users expect to be able to specify CFLAGS freely 626 | # themselves.' So we use CFLAGS to define options which are not strictly 627 | # required for compilation: optimizations, architecture specifications, and 628 | # warnings. CFLAGS can be safely overriden using a make command argument. 629 | # Variables cflags, ldflags and ldlibs may be defined in including makefile. 630 | 631 | optimization.flags = -O3 -ffast-math -funroll-loops -fomit-frame-pointer 632 | warn.flags = -Wall -Wextra -Wshadow -Winline -Wstrict-aliasing 633 | 634 | # suppress -Wunused-variable & Co if you don't want to clutter a build log 635 | ifdef suppress-wunused 636 | warn.flags += $(addprefix -Wno-unused-, function parameter value variable) 637 | endif 638 | 639 | CFLAGS = $(warn.flags) $(optimization.flags) $(arch.c.flags) 640 | 641 | # preprocessor flags 642 | cpp.flags := -DPD -I "$(PDINCLUDEDIR)" $(cpp.flags) $(CPPFLAGS) 643 | 644 | # flags for dependency checking (cflags from makefile may define -I options) 645 | depcheck.flags := $(cpp.flags) $(cflags) 646 | 647 | # architecture specifications for linker are overridable by LDFLAGS 648 | LDFLAGS := $(arch.ld.flags) 649 | 650 | # now add the same ld flags to shared dynamic lib 651 | shared.ldflags := $(shared.ldflags) $(LDFLAGS) 652 | 653 | # accumulated flags for C compiler / linker 654 | c.flags := $(cpp.flags) $(c.flags) $(cflags) $(CFLAGS) 655 | c.ldflags := $(c.ldflags) $(ldflags) $(LDFLAGS) 656 | c.ldlibs := $(c.ldlibs) $(ldlibs) 657 | 658 | # accumulated flags for C++ compiler / linker 659 | cxx.flags := $(cpp.flags) $(cxx.flags) $(cflags) $(CFLAGS) 660 | cxx.ldflags := $(cxx.ldflags) $(ldflags) $(LDFLAGS) 661 | cxx.ldlibs := $(cxx.ldlibs) $(ldlibs) 662 | 663 | 664 | ################################################################################ 665 | ### variables: library name and version ######################################## 666 | ################################################################################ 667 | 668 | 669 | # strip possibles spaces from lib.name, they mess up calculated file names 670 | lib.name := $(strip $(lib.name)) 671 | 672 | # if meta file exists, check library version 673 | metafile := $(wildcard $(lib.name)-meta.pd) 674 | 675 | ifdef metafile 676 | lib.version := $(shell sed -n \ 677 | 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' \ 678 | $(metafile)) 679 | endif 680 | 681 | 682 | ################################################################################ 683 | ### variables: files ########################################################### 684 | ################################################################################ 685 | 686 | 687 | #=== sources =================================================================== 688 | 689 | 690 | # (re)define .class.sources using file names in class.sources 691 | 692 | define add-class-source 693 | $(notdir $(basename $v)).class.sources += $v 694 | endef 695 | 696 | $(foreach v, $(class.sources), $(eval $(add-class-source))) 697 | 698 | # derive class names from .class.sources variables 699 | sourcevariables := $(filter %.class.sources, $(.VARIABLES)) 700 | classes := $(basename $(basename $(sourcevariables))) 701 | 702 | # accumulate all source files specified in makefile 703 | classes.sources := $(sort $(foreach v, $(sourcevariables), $($v))) 704 | all.sources := $(classes.sources) $(lib.setup.sources) \ 705 | $(shared.sources) $(common.sources) 706 | 707 | 708 | #=== object files ============================================================== 709 | 710 | 711 | # construct object filenames from all C and C++ source file names 712 | classes.objects := $(addsuffix .o, $(basename $(classes.sources))) 713 | common.objects := $(addsuffix .o, $(basename $(common.sources))) 714 | shared.objects := $(addsuffix .o, $(basename $(shared.sources))) 715 | lib.setup.objects := $(addsuffix .o, $(basename $(lib.setup.sources))) 716 | all.objects = $(classes.objects) $(common.objects) $(shared.objects) \ 717 | $(lib.setup.objects) 718 | 719 | 720 | #=== executables =============================================================== 721 | 722 | 723 | # construct class executable names from class names 724 | classes.executables := $(addsuffix .$(extension), $(classes)) 725 | 726 | # Construct shared lib executable name if shared sources are defined. If 727 | # extension and shared extension are not identical, use both to facilitate co- 728 | # installation for different platforms, like .m_i386.dll and .m_amd64.dll. 729 | ifdef shared.sources 730 | ifeq ($(extension), $(shared.extension)) 731 | shared.lib = lib$(lib.name).$(shared.extension) 732 | else 733 | shared.lib = lib$(lib.name).$(extension).$(shared.extension) 734 | endif 735 | else 736 | shared.lib := 737 | endif 738 | 739 | 740 | ################################################################################ 741 | ### variables: tools ########################################################### 742 | ################################################################################ 743 | 744 | 745 | # aliases so we can later define 'compile-$1' and set 'c' or 'cxx' as argument 746 | compile-c := $(CC) 747 | compile-cxx := $(CXX) 748 | 749 | 750 | ################################################################################ 751 | ### checks ##################################################################### 752 | ################################################################################ 753 | 754 | 755 | # At this point most variables are defined. Now do some checks and info's 756 | # before rules begin. 757 | 758 | # print Makefile.pdlibbuilder version before possible termination 759 | $(info ++++ info: using Makefile.pdlibbuilder version $(version)) 760 | 761 | # Terminate if target triplet remained empty, to avoid all sorts of confusing 762 | # scenarios and spurious bugs. 763 | ifeq ($(target.triplet),) 764 | $(error Command "$(CC) -dumpmachine" did not return a target triplet, \ 765 | needed for a build. \ 766 | Is compiler "$(CC)" installed in your PATH? ($(PATH)). \ 767 | Does compiler "$(CC)" support option "-dumpmachine"?) 768 | endif 769 | 770 | # 'forward declaration' of default target, needed to do checks 771 | all: 772 | 773 | # To avoid unpredictable results, make sure the default target is not redefined 774 | # by including makefile. 775 | ifneq ($(.DEFAULT_GOAL), all) 776 | $(error Default target must be 'all'.) 777 | endif 778 | 779 | # find out which target(s) will be made 780 | ifdef MAKECMDGOALS 781 | goals := $(MAKECMDGOALS) 782 | else 783 | goals := all 784 | endif 785 | 786 | # store path to Pd API m_pd.h if it is found 787 | ifdef PDINCLUDEDIR 788 | mpdh := $(shell ls "$(PDINCLUDEDIR)/m_pd.h") 789 | endif 790 | 791 | # store path to pd.dll; if not found, ls will give a useful error 792 | ifeq ($(system), Windows) 793 | pddll := $(shell ls "$(PDBINDIR)/pd.dll") 794 | endif 795 | 796 | # when making target all, check if m_pd.h is found and print info about it 797 | ifeq ($(goals), all) 798 | $(if $(mpdh), \ 799 | $(info ++++ info: using Pd API $(mpdh)), \ 800 | $(warning Where is Pd API m_pd.h? Do 'make help' for info.)) 801 | endif 802 | 803 | # print target info 804 | $(info ++++ info: making target $(goals) $(if $(lib.name),in lib $(lib.name))) 805 | 806 | # when installing, print installpath info 807 | $(if $(filter install install-lib, $(goals)), $(info ++++ info: \ 808 | installpath is '$(installpath)')) 809 | 810 | 811 | #=== define executables ======================================================== 812 | 813 | 814 | # By default we build class executables, and optionally a shared dynamic link 815 | # lib. When make-lib-executable=yes we build all classes into a single lib 816 | # executable, on the condition that variable lib.setup.sources is defined. 817 | 818 | ifeq ($(make-lib-executable),yes) 819 | $(if $(lib.setup.sources), ,\ 820 | $(error Can not build library blob because lib.setup.sources is undefined)) 821 | executables := $(lib.name).$(extension) 822 | else 823 | executables := $(classes.executables) $(shared.lib) 824 | endif 825 | 826 | 827 | ################################################################################ 828 | ### rules: special targets ##################################################### 829 | ################################################################################ 830 | 831 | 832 | # Disable built-in rules. If some target can't be built with the specified 833 | # rules, it should not be built at all. 834 | MAKEFLAGS += --no-builtin-rules 835 | 836 | .PRECIOUS: 837 | .SUFFIXES: 838 | .PHONY: all post build-lib \ 839 | $(classes) $(makefiledirs) $(makefiles) \ 840 | install install-executables install-datafiles install-datadirs \ 841 | force clean vars allvars depend help 842 | 843 | 844 | ################################################################################ 845 | ### rules: build targets ####################################################### 846 | ################################################################################ 847 | 848 | 849 | # Target all forces the build of targets [$(executables) post] in 850 | # deterministic order. Target $(executables) builds class executables plus 851 | # optional shared lib or alternatively a single lib executable when 852 | # make-lib-executable=true. Target post is optionally defined by 853 | # library makefile. 854 | 855 | all: post 856 | post: $(executables) 857 | 858 | all: 859 | $(info ++++info: target all in lib $(lib.name) completed) 860 | 861 | # build all with -g option turned on for debug symbols 862 | alldebug: c.flags += -g 863 | alldebug: cxx.flags += -g 864 | alldebug: all 865 | 866 | 867 | #=== class executable ========================================================== 868 | 869 | 870 | # recipe for linking objects in class executable 871 | # argument $1 = compiler type (c or cxx) 872 | # argument $2 = class basename 873 | define link-class 874 | $(compile-$1) \ 875 | $($1.ldflags) $($2.class.ldflags) \ 876 | -o $2.$(extension) \ 877 | $(addsuffix .o, $(basename $($2.class.sources))) \ 878 | $(addsuffix .o, $(basename $(common.sources))) \ 879 | $($1.ldlibs) $($2.class.ldlibs) $(shared.lib) 880 | endef 881 | 882 | # general rule for linking object files in class executable 883 | %.$(extension): $(shared.lib) 884 | $(info ++++ info: linking objects in $@ for lib $(lib.name)) 885 | $(if $(filter %.cc %.cpp, $($*.class.sources)), \ 886 | $(call link-class,cxx,$*), \ 887 | $(call link-class,c,$*)) 888 | 889 | 890 | #=== library blob ============================================================== 891 | 892 | 893 | # build all classes into single executable 894 | build-lib: $(lib.name).$(extension) 895 | $(info ++++ info: library blob $(lib.name).$(extension) completed) 896 | 897 | # recipe for linking objects in lib executable 898 | # argument $1 = compiler type (c or cxx) 899 | define link-lib 900 | $(compile-$1) \ 901 | $($1.ldflags) $(lib.ldflags) \ 902 | -o $(lib.name).$(extension) $(all.objects) \ 903 | $($1.ldlibs) $(lib.ldlibs) 904 | endef 905 | 906 | # rule for linking objects in lib executable 907 | # declared conditionally to avoid name clashes 908 | ifeq ($(make-lib-executable),yes) 909 | $(lib.name).$(extension): $(all.objects) 910 | $(if $(filter %.cc %.cpp, $(all.sources)), \ 911 | $(call link-lib,cxx), \ 912 | $(call link-lib,c)) 913 | endif 914 | 915 | 916 | #=== shared dynamic lib ======================================================== 917 | 918 | 919 | # recipe for linking objects in shared executable 920 | # argument $1 = compiler type (c or cxx) 921 | define link-shared 922 | $(compile-$1) \ 923 | $(shared.ldflags) \ 924 | -o $(shared.lib) $(shared.objects) \ 925 | $($1.ldlibs) $(shared.ldlibs) 926 | endef 927 | 928 | # rule for linking objects in shared executable 929 | # build recipe is in macro 'link-shared' 930 | $(shared.lib): $(shared.objects) 931 | $(info ++++ info: linking objects in shared lib $@) 932 | $(if $(filter %.cc %.cpp, $(shared.sources)), \ 933 | $(call link-shared,cxx), \ 934 | $(call link-shared,c)) 935 | 936 | 937 | #=== object files ============================================================== 938 | 939 | 940 | # recipe to make .o file from source 941 | # argument $1 is compiler type (c or cxx) 942 | define make-object-file 943 | $(info ++++ info: making $@ in lib $(lib.name)) 944 | $(compile-$1) \ 945 | $($1.flags) \ 946 | -o $@ -c $< 947 | endef 948 | 949 | # Three rules to create .o files. These are double colon 'terminal' rules, 950 | # meaning they are the last in a rules chain. 951 | 952 | %.o:: %.c 953 | $(call make-object-file,c) 954 | 955 | %.o:: %.cc 956 | $(call make-object-file,cxx) 957 | 958 | %.o:: %.cpp 959 | $(call make-object-file,cxx) 960 | 961 | 962 | #=== explicit prerequisites for class executables ============================== 963 | 964 | 965 | # For class executables, prerequisite rules are declared in run time. Target 966 | # 'depend' prints these rules for debugging purposes. 967 | 968 | # declare explicit prerequisites rule like 'class: class.extension' 969 | # argument $v is class basename 970 | define declare-class-target 971 | $v: $v.$(extension) 972 | endef 973 | 974 | # declare explicit prerequisites rule like 'class.extension: object1.o object2.o' 975 | # argument $v is class basename 976 | define declare-class-executable-target 977 | $v.$(extension): $(addsuffix .o, $(basename $($v.class.sources))) \ 978 | $(addsuffix .o, $(basename $(common.sources))) 979 | endef 980 | 981 | # evaluate explicit prerequisite rules for all classes 982 | $(foreach v, $(classes), $(eval $(declare-class-target))) 983 | $(foreach v, $(classes), $(eval $(declare-class-executable-target))) 984 | 985 | 986 | #=== implicit prerequisites for class executables ============================== 987 | 988 | 989 | # Evaluating implicit prerequisites (header files) with help from the 990 | # preprocessor is 'expensive' so this is done conditionally and selectively. 991 | # Note that it is also possible to trigger a build via install targets, in 992 | # which case implicit prerequisites are not checked. 993 | 994 | # When the Pd include path contains spaces it will mess up the implicit 995 | # prerequisites rules. 996 | disable-dependency-tracking := $(strip $(pdincludepathwithspaces)) 997 | 998 | ifndef disable-dependency-tracking 999 | must-build-everything := $(filter all, $(goals)) 1000 | must-build-class := $(filter $(classes), $(goals)) 1001 | must-build-sources := $(foreach v, $(must-build-class), $($v.class.sources)) 1002 | endif 1003 | 1004 | # declare implicit prerequisites rule like 'object.o: header1.h header2.h ...' 1005 | # argument $1 is input source file(s) 1006 | # dir is explicitly added because option -MM strips it by default 1007 | define declare-object-target 1008 | $(dir $1)$(filter %.o: %.h, $(shell $(CPP) $(depcheck.flags) -MM $1)) $(MAKEFILE_LIST) 1009 | endef 1010 | 1011 | # evaluate implicit prerequisite rules when rebuilding everything 1012 | ifdef must-build-everything 1013 | $(if $(wildcard $(all.objects)), \ 1014 | $(info ++++ info: evaluating implicit prerequisites in lib $(lib.name).....) \ 1015 | $(foreach v, $(all.sources), $(eval $(call declare-object-target, $v)))) 1016 | endif 1017 | 1018 | # evaluate implicit prerequisite rules when selectively building classes 1019 | ifdef must-build-class 1020 | $(foreach v, $(must-build-sources), \ 1021 | $(eval $(call declare-object-target, $v))) 1022 | $(foreach v, $(shared.sources), \ 1023 | $(eval $(call declare-object-target, $v))) 1024 | endif 1025 | 1026 | 1027 | ################################################################################ 1028 | ### rules: preprocessor and assembly files ##################################### 1029 | ################################################################################ 1030 | 1031 | 1032 | # Preprocessor and assembly output files for bug tracing etc. They are not part 1033 | # of the build processes for executables. By default these files are created in 1034 | # the current working directory. Dependency tracking is not performed, the build 1035 | # is forced instead to make sure it's up to date. 1036 | 1037 | force: 1038 | 1039 | 1040 | #=== preprocessor file ========================================================= 1041 | 1042 | 1043 | # make preprocessor output file with extension .pre 1044 | # argument $1 = compiler type (c or cxx) 1045 | define make-preprocessor-file 1046 | $(info ++++ info: making preprocessor output file $(notdir $*.pre) \ 1047 | in current working directory) 1048 | $(compile-$1) -E $< $(c.flags) $($1.flags) -o $(notdir $*.pre) 1049 | endef 1050 | 1051 | %.pre:: %.c force 1052 | $(call make-preprocessor-file,c) 1053 | 1054 | %.pre:: %.cc force 1055 | $(call make-preprocessor-file,cxx) 1056 | 1057 | %.pre:: %.cpp force 1058 | $(call make-preprocessor-file,cxx) 1059 | 1060 | 1061 | #=== assembly file ============================================================= 1062 | 1063 | 1064 | # make C / assembly interleaved output file with extension .lst 1065 | # argument $1 = compiler type (c or cxx) 1066 | define make-assembly-file 1067 | $(info ++++ info: making assembly output file $(notdir $*.lst) \ 1068 | in current working directory) 1069 | $(compile-$1) \ 1070 | -c -Wa,-a,-ad -fverbose-asm \ 1071 | $($1.flags) \ 1072 | $< > $(notdir $*.lst) 1073 | endef 1074 | 1075 | %.lst:: %.c force 1076 | $(call make-assembly-file,c) 1077 | 1078 | %.lst:: %.cc force 1079 | $(call make-assembly-file,cxx) 1080 | 1081 | %.lst:: %.cpp force 1082 | $(call make-assembly-file,cxx) 1083 | 1084 | 1085 | ################################################################################ 1086 | ### rules: installation targets ################################################ 1087 | ################################################################################ 1088 | 1089 | 1090 | #=== strip ===================================================================== 1091 | 1092 | 1093 | # Stripping of installed binaries will only be done when variable 'stripflags' 1094 | # is defined non-empty. No default definition is provided except for Windows 1095 | # where the unstripped binaries are large, especially in the case of Mingw-w64. 1096 | 1097 | # Note: while stripping all symbols ('-s' or '--strip-all') is possible for 1098 | # Linux and Windows, in the case of OSX only non-global symbols can be stripped 1099 | # (option '-x' or '--discard-all'). 1100 | 1101 | # Make definition of strip command overridable so it can be defined in an 1102 | # environment for cross-compilation. 1103 | STRIP ?= strip 1104 | 1105 | # Commands in 'strip-executables' will be executed conditionally in the rule for 1106 | # target 'install-executables'. 1107 | strip-executables = cd "$(installpath)" && \ 1108 | $(foreach v, $(executables), $(STRIP) $(stripflags) '$v';) 1109 | 1110 | 1111 | #=== install =================================================================== 1112 | 1113 | 1114 | # Install targets depend on successful exit status of target all because nothing 1115 | # must be installed in case of a build error. 1116 | 1117 | # -p = preserve time stamps 1118 | # -m = set permission mode (as in chmod) 1119 | # -d = create all components of specified directories 1120 | INSTALL = install 1121 | INSTALL_PROGRAM := $(INSTALL) -p -m 644 1122 | INSTALL_DATA := $(INSTALL) -p -m 644 1123 | INSTALL_DIR := $(INSTALL) -m 755 -d 1124 | 1125 | # strip spaces from file names 1126 | executables := $(strip $(executables)) 1127 | datafiles := $(strip $(datafiles)) 1128 | datadirs := $(strip $(datadirs)) 1129 | 1130 | # Do not make any install sub-target with empty variable definition because the 1131 | # install program would exit with an error. 1132 | install: $(if $(executables), install-executables) 1133 | install: $(if $(datafiles), install-datafiles) 1134 | install: $(if $(datadirs), install-datadirs) 1135 | 1136 | install-executables: all 1137 | $(INSTALL_DIR) -v "$(installpath)" 1138 | $(foreach v, $(executables), \ 1139 | $(INSTALL_PROGRAM) '$v' "$(installpath)";) 1140 | $(info ++++ info: executables of lib $(lib.name) installed \ 1141 | from $(CURDIR) to $(installpath)) 1142 | $(if $(stripflags), $(strip-executables),) 1143 | 1144 | install-datafiles: all 1145 | $(INSTALL_DIR) -v "$(installpath)" 1146 | $(foreach v, $(datafiles), \ 1147 | $(INSTALL_DATA) '$(v)' "$(installpath)";) 1148 | $(info ++++ info: data files of lib $(lib.name) installed \ 1149 | from $(CURDIR) to $(installpath)) 1150 | 1151 | install-datadirs: all 1152 | $(foreach v, $(datadirs), $(INSTALL_DIR) "$(installpath)/$v";) 1153 | $(foreach v, $(datadirs), \ 1154 | $(INSTALL_DATA) $(wildcard $v/*) "$(installpath)/$v";) 1155 | $(info ++++ info: data directories of lib $(lib.name) installed \ 1156 | from $(CURDIR) to $(installpath)) 1157 | 1158 | 1159 | ################################################################################ 1160 | ### rules: distribution targets ################################################ 1161 | ################################################################################ 1162 | 1163 | 1164 | # TODO 1165 | # These targets are implemented in Makefile Template, but I have to figure out 1166 | # how to do it under the not-so-strict conditions of Makefile.pdlibbuilder. 1167 | 1168 | # make source package 1169 | dist: 1170 | @echo "target dist not yet implemented" 1171 | 1172 | # make Debian source package 1173 | dpkg-source: 1174 | @echo "target dpkg-source not yet implemented" 1175 | 1176 | $(ORIGDIR): 1177 | 1178 | $(DISTDIR): 1179 | 1180 | 1181 | ################################################################################ 1182 | ### rules: clean targets ####################################################### 1183 | ################################################################################ 1184 | 1185 | 1186 | # delete build products from build tree 1187 | clean: 1188 | rm -f $(all.objects) 1189 | rm -f $(classes.executables) $(lib.name).$(extension) $(shared.lib) 1190 | rm -f *.pre *.lst 1191 | 1192 | # remove distribution directories and tarballs from build tree 1193 | distclean: clean 1194 | @echo "target distclean not yet implemented" 1195 | 1196 | 1197 | ################################################################################ 1198 | ### rules: submake targets ##################################################### 1199 | ################################################################################ 1200 | 1201 | 1202 | # Iterate over sub-makefiles or makefiles in other directories. 1203 | 1204 | # When 'continue-make=yes' is set, sub-makes will report 'true' to the parent 1205 | # process regardless of their real exit status. This prevents the parent make 1206 | # from being aborted by a sub-make error. Useful when you want to quickly find 1207 | # out which sub-makes from a large set will succeed. 1208 | ifeq ($(continue-make),yes) 1209 | continue = || true 1210 | endif 1211 | 1212 | # These targets will trigger sub-make processes for entries in 'makefiledirs' 1213 | # and 'makefiles'. 1214 | all alldebug install clean distclean dist dkpg-source: \ 1215 | $(makefiledirs) $(makefiles) 1216 | 1217 | # this expands to identical rules for each entry in 'makefiledirs' 1218 | $(makefiledirs): 1219 | $(MAKE) --directory=$@ $(MAKECMDGOALS) $(continue) 1220 | 1221 | # this expands to identical rules for each entry in 'makefiles' 1222 | $(makefiles): 1223 | $(MAKE) --directory=$(dir $@) --makefile=$(notdir $@) $(MAKECMDGOALS) $(continue) 1224 | 1225 | 1226 | ################################################################################ 1227 | ### rules: convenience targets ################################################# 1228 | ################################################################################ 1229 | 1230 | 1231 | #=== show variables ============================================================ 1232 | 1233 | 1234 | # Several 'function' macro's cause errors when expanded within a rule or without 1235 | # proper arguments. Variables which are set with the define directive are only 1236 | # shown by name for that reason. 1237 | functions = \ 1238 | add-class-source \ 1239 | declare-class-target \ 1240 | declare-class-executable-target \ 1241 | declare-object-target \ 1242 | link-class \ 1243 | link-lib \ 1244 | link-shared \ 1245 | make-object-file \ 1246 | make-preprocessor-file \ 1247 | make-assembly-file 1248 | 1249 | 1250 | # show variables from makefiles 1251 | vars: 1252 | $(info ++++ info: showing makefile variables:) 1253 | $(foreach v,\ 1254 | $(sort $(filter-out $(functions) functions, $(.VARIABLES))),\ 1255 | $(if $(filter file, $(origin $v)),\ 1256 | $(info variable $v = $($v)))) 1257 | $(foreach v, $(functions), $(info 'function' name: $v)) 1258 | @echo 1259 | 1260 | # show all variables 1261 | allvars: 1262 | $(info ++++ info: showing default, automatic and makefile variables:) 1263 | $(foreach v, \ 1264 | $(sort $(filter-out $(functions) functions, $(.VARIABLES))), \ 1265 | $(info variable ($(origin $v)) $v = $($v))) 1266 | $(foreach v, $(functions), $(info 'function' name: $v)) 1267 | @echo 1268 | 1269 | 1270 | #=== show dependencies ========================================================= 1271 | 1272 | 1273 | # show generated prerequisites rules 1274 | depend: 1275 | $(info ++++ info: generated prerequisite rules) 1276 | $(foreach v, $(classes), $(info $(declare-class-target))) 1277 | $(foreach v, $(classes), $(info $(declare-class-executable-target))) 1278 | $(foreach v, $(all.sources), $(info $(call declare-object-target, $v))) 1279 | @echo 1280 | 1281 | 1282 | #=== show help text ============================================================ 1283 | 1284 | 1285 | # brief info about targets and paths 1286 | 1287 | ifdef mpdh 1288 | mpdhinfo := $(mpdh) 1289 | else 1290 | mpdhinfo := m_pd.h was not found. Is Pd installed? 1291 | endif 1292 | 1293 | help: 1294 | @echo 1295 | @echo " Main targets:" 1296 | @echo " all: build executables (default target)" 1297 | @echo " install: install all components of the library" 1298 | @echo " vars: print makefile variables for troubleshooting" 1299 | @echo " allvars: print all variables for troubleshooting" 1300 | @echo " help: print this help text" 1301 | @echo 1302 | @echo " Pd API m_pd.h:" 1303 | @echo " $(mpdhinfo)" 1304 | @echo " You may specify your preferred Pd include directory as argument" 1305 | @echo " to the make command, like 'PDINCLUDEDIR=path/to/pd/src'." 1306 | @echo 1307 | @echo " Path for installation of your libdir(s):" 1308 | @echo " $(PDLIBDIR)" 1309 | @echo " Alternatively you may specify your path for installation as argument" 1310 | @echo " to the make command, like 'PDLIBDIR=path/to/pd-externals'." 1311 | @echo 1312 | @echo " Default paths are listed in the doc sections in Makefile.pdlibbuilder." 1313 | @echo 1314 | 1315 | 1316 | #=== platform test ============================================================= 1317 | 1318 | 1319 | # This target can be used to test if the compiler for specified PLATFORM is 1320 | # correctly defined and available. 1321 | 1322 | dumpmachine: 1323 | @$(CC) -dumpmachine 1324 | 1325 | 1326 | #=== dummy target ============================================================== 1327 | 1328 | 1329 | coffee: 1330 | @echo "Makefile.pdlibbuilder: Can not make coffee. Sorry." 1331 | 1332 | 1333 | ################################################################################ 1334 | ### end of rules sections ###################################################### 1335 | ################################################################################ 1336 | 1337 | 1338 | # for syntax highlighting in vim and github 1339 | # vim: set filetype=make: 1340 | 1341 | -------------------------------------------------------------------------------- /src/convolve~.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | convolve~ 4 | 5 | Copyright 2010 William Brent 6 | 7 | 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. 8 | 9 | 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. 10 | You should have received a copy of the GNU General Public License along with this program. If not, see . 11 | 12 | 13 | version 0.13.1, May 17, 2021 14 | 15 | - using FFTW as of version 0.11 16 | 17 | */ 18 | 19 | #include "m_pd.h" 20 | #include "fftw3.h" 21 | #include 22 | #include // for strcmp 23 | #define MINWIN 64 24 | #define DEFAULTWIN 2048 25 | #define NUMBARKBOUNDS 25 26 | 27 | t_float barkBounds[] = {0, 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500}; 28 | 29 | static t_class *convolve_tilde_class; 30 | 31 | typedef struct _convolve_tilde 32 | { 33 | t_object x_obj; 34 | t_symbol *x_objSymbol; 35 | t_symbol *x_arrayName; 36 | t_word *x_vec; 37 | t_clock *x_clock; 38 | t_sample *x_irSignalEq; 39 | int x_startupFlag; 40 | int x_arraySize; 41 | int x_numParts; 42 | t_float x_sr; 43 | t_float x_n; 44 | int x_dspTick; 45 | int x_bufferLimit; 46 | int x_window; 47 | int x_windowDouble; 48 | t_float x_ampScalar; 49 | t_sample *x_signalBuf; 50 | t_sample *x_signalBufPadded; 51 | t_sample *x_invOutFftwOut; 52 | t_sample *x_nonOverlappedOutput; 53 | t_sample *x_finalOutput; 54 | 55 | fftwf_complex *x_irFreqDomData; 56 | fftwf_complex *x_liveFreqDomData; 57 | fftwf_complex *x_sigBufPadFftwOut; 58 | fftwf_complex *x_invOutFftwIn; 59 | fftwf_plan x_sigBufPadFftwPlan; 60 | fftwf_plan x_invOutFftwPlan; 61 | 62 | t_float x_f; 63 | 64 | } convolve_tilde; 65 | 66 | 67 | /* ------------------------ convolve~ -------------------------------- */ 68 | 69 | static void convolve_tilde_analyze(convolve_tilde *x, t_symbol *arrayName) 70 | { 71 | t_garray *arrayPtr; 72 | int i, j, oldNonOverlappedSize, newNonOverlappedSize; 73 | t_float *fftwIn; 74 | fftwf_complex *fftwOut; 75 | fftwf_plan fftwPlan; 76 | 77 | if(x->x_numParts>0) 78 | oldNonOverlappedSize = 2*x->x_windowDouble; 79 | else 80 | oldNonOverlappedSize = 0; 81 | 82 | // if this call to _analyze() is issued from _eq(), the incoming arrayName will match x->x_arrayName. 83 | // if incoming arrayName doesn't match x->x_arrayName, load arrayName and dump its samples into x_irSignalEq 84 | if(arrayName->s_name != x->x_arrayName->s_name || x->x_startupFlag) 85 | { 86 | int oldArraySize; 87 | 88 | x->x_startupFlag = 0; 89 | 90 | oldArraySize = x->x_arraySize; 91 | 92 | if(!(arrayPtr = (t_garray *)pd_findbyclass(arrayName, garray_class))) 93 | { 94 | if(*arrayName->s_name) 95 | { 96 | pd_error(x, "%s: no array named %s", x->x_objSymbol->s_name, arrayName->s_name); 97 | 98 | // resize x_irSignalEq back to 0 99 | x->x_irSignalEq = (t_sample *)t_resizebytes( 100 | x->x_irSignalEq, 101 | oldArraySize*sizeof(t_sample), 102 | 0 103 | ); 104 | 105 | x->x_arraySize = 0; 106 | x->x_vec = 0; 107 | return; 108 | } 109 | } 110 | else if(!garray_getfloatwords(arrayPtr, &x->x_arraySize, &x->x_vec)) 111 | { 112 | pd_error(x, "%s: bad template for %s", x->x_objSymbol->s_name, arrayName->s_name); 113 | 114 | // resize x_irSignalEq back to 0 115 | x->x_irSignalEq = (t_sample *)t_resizebytes( 116 | x->x_irSignalEq, 117 | oldArraySize*sizeof(t_sample), 118 | 0 119 | ); 120 | 121 | x->x_arraySize = 0; 122 | x->x_vec = 0; 123 | return; 124 | } 125 | else 126 | x->x_arrayName = arrayName; 127 | 128 | // resize x_irSignalEq 129 | x->x_irSignalEq = (t_sample *)t_resizebytes( 130 | x->x_irSignalEq, 131 | oldArraySize*sizeof(t_sample), 132 | x->x_arraySize*sizeof(t_sample) 133 | ); 134 | 135 | // since this is first analysis of arrayName, load it into x_irSignalEq 136 | for(i=0; ix_arraySize; i++) 137 | x->x_irSignalEq[i] = x->x_vec[i].w_float; 138 | } 139 | else 140 | { 141 | t_garray *thisArrayPtr; 142 | t_word *thisVec; 143 | int thisArraySize; 144 | 145 | // if we want to assume that a 2nd call to analyze() with the same array name is safe (and we don't have to reload x_vec or update x_arraySize), we have to do some careful safety checks to make sure that the size of x_arrayName hasn't changed since the last time this was called. If it has, we should just abort for now. 146 | thisArraySize = 0; 147 | 148 | thisArrayPtr = (t_garray *)pd_findbyclass(arrayName, garray_class); 149 | garray_getfloatwords(thisArrayPtr, &thisArraySize, &thisVec); 150 | 151 | if(thisArraySize != x->x_arraySize) 152 | { 153 | pd_error(x, "%s: size of array %s has changed since previous analysis...aborting. Reload %s with previous IR contents or analyze another array.", x->x_objSymbol->s_name, arrayName->s_name, arrayName->s_name); 154 | return; 155 | } 156 | } 157 | 158 | // count how many partitions there will be for this IR 159 | x->x_numParts = 0; 160 | while((x->x_numParts*x->x_window) < x->x_arraySize) 161 | x->x_numParts++; 162 | 163 | newNonOverlappedSize = 2*x->x_windowDouble; 164 | 165 | // resize time-domain buffer 166 | // this can probably just be x_windowDouble * 2!! 167 | x->x_nonOverlappedOutput = (t_sample *)t_resizebytes( 168 | x->x_nonOverlappedOutput, 169 | oldNonOverlappedSize*sizeof(t_sample), 170 | newNonOverlappedSize*sizeof(t_sample) 171 | ); 172 | 173 | // clear time-domain buffer 174 | for(i=0; ix_nonOverlappedOutput[i] = 0.0; 176 | 177 | // free x_irFreqDomData/x_liveFreqDomData and re-alloc to new size based on x_numParts 178 | fftwf_free(x->x_irFreqDomData); 179 | fftwf_free(x->x_liveFreqDomData); 180 | x->x_irFreqDomData = (fftwf_complex *)fftwf_alloc_complex(x->x_numParts*(x->x_window+1)); 181 | x->x_liveFreqDomData = (fftwf_complex *)fftwf_alloc_complex(x->x_numParts*(x->x_window+1)); 182 | 183 | // clear x_liveFreqDomData 184 | for(i=0; ix_numParts*(x->x_window+1); i++) 185 | { 186 | x->x_liveFreqDomData[i][0] = 0.0; 187 | x->x_liveFreqDomData[i][1] = 0.0; 188 | } 189 | 190 | // set up FFTW input buffer 191 | fftwIn = (t_float *)t_getbytes(x->x_windowDouble * sizeof(t_float)); 192 | 193 | // set up the FFTW output buffer. It is N/2+1 elements long for an N-point r2c FFT 194 | // fftwOut[i][0] and fftwOut[i][1] refer to the real and imaginary parts of bin i 195 | fftwOut = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 196 | 197 | // FFT plan 198 | fftwPlan = fftwf_plan_dft_r2c_1d(x->x_windowDouble, fftwIn, fftwOut, FFTW_ESTIMATE); 199 | 200 | // we're supposed to initialize the input array after we create the plan 201 | for(i=0; ix_windowDouble; i++) 202 | fftwIn[i] = 0.0; 203 | 204 | // take FFTs of partitions, and store in x_irFreqDomData as chunks of 205 | // window+1 complex arrays 206 | for(i=0; ix_numParts; i++) 207 | { 208 | int startSpec, startVec; 209 | 210 | startSpec = i*(x->x_window+1); 211 | startVec = i*x->x_window; 212 | 213 | // we are analyzing partitions of x_irSignalEq, in case there has been any EQ 214 | for(j=0; jx_window && (startVec+j)x_arraySize; j++) 215 | fftwIn[j] = x->x_irSignalEq[startVec+j]; 216 | 217 | // zero pad 218 | for(; jx_windowDouble; j++) 219 | fftwIn[j] = 0.0; 220 | 221 | // execute FFT 222 | fftwf_execute(fftwPlan); 223 | 224 | // copy freq domain data from fft output buffer into 225 | // larger IR freq domain data buffer 226 | for(j=0; jx_window+1; j++) 227 | { 228 | x->x_irFreqDomData[startSpec+j][0] = fftwOut[j][0]; 229 | x->x_irFreqDomData[startSpec+j][1] = fftwOut[j][1]; 230 | } 231 | } 232 | 233 | t_freebytes(fftwIn, (x->x_windowDouble)*sizeof(t_float)); 234 | fftwf_free(fftwOut); 235 | fftwf_destroy_plan(fftwPlan); 236 | 237 | post("%s: analysis of IR array %s complete. Array size: %i. Partitions: %i.", x->x_objSymbol->s_name, x->x_arrayName->s_name, x->x_arraySize, x->x_numParts); 238 | } 239 | 240 | 241 | static void convolve_tilde_eq(convolve_tilde *x, t_symbol *s, int argc, t_atom *argv) 242 | { 243 | int i, j, windowTriple, windowTripleHalf, *barkBinBounds; 244 | t_float *fftwIn, *eqArray; 245 | fftwf_complex *fftwOut; 246 | fftwf_plan fftwForwardPlan, fftwInversePlan; 247 | 248 | // if no array has been analyzed yet, we can't do the EQ things below 249 | if(!strcmp(x->x_arrayName->s_name, "NOARRAYSPECIFIED")) 250 | pd_error(x, "%s: no IR array has been analyzed", x->x_objSymbol->s_name); 251 | else 252 | { 253 | // we'll pad with x->x_arraySize zeros before and after the IR signal 254 | windowTriple = x->x_arraySize*3; 255 | 256 | // FFTW documentation says the output of a r2c forward transform is floor(N/2)+1 257 | windowTripleHalf = floor(windowTriple/(t_float)2)+1; 258 | 259 | eqArray = (t_float *)getbytes(windowTripleHalf*sizeof(t_float)); 260 | 261 | // at this point, if we took in 24 bark band scalars instead of the insane x->x_arraySize*3 scalars, we could find the bin bounds for each of the Bark bands and fill eqArray with those. 262 | 263 | // array to hold bin number of each of the 25 bark bounds, plus one more for Nyquist 264 | barkBinBounds = (int *)getbytes((NUMBARKBOUNDS+1)*sizeof(int)); 265 | 266 | for(i=0; ix_sr); 268 | 269 | // the upper bound should be the Nyquist bin 270 | barkBinBounds[NUMBARKBOUNDS] = windowTripleHalf-1; 271 | 272 | if(argc != NUMBARKBOUNDS) 273 | post("%s: WARNING: \"eq\" message should contain %i frequency band scalars", x->x_objSymbol->s_name, NUMBARKBOUNDS); 274 | 275 | // need to check that argc == NUMBARKBOUNDS 276 | for(i=0; ix_arraySize; i++) 306 | fftwIn[x->x_arraySize+i] = x->x_vec[i].w_float; 307 | 308 | // execute forward FFT 309 | fftwf_execute(fftwForwardPlan); 310 | 311 | // apply bin scalars 312 | for(i=0; ix_arraySize; i++) 323 | x->x_irSignalEq[i] = fftwIn[x->x_arraySize+i]/windowTriple; 324 | 325 | t_freebytes(eqArray, windowTripleHalf*sizeof(t_float)); 326 | t_freebytes(barkBinBounds, (NUMBARKBOUNDS+1)*sizeof(int)); 327 | t_freebytes(fftwIn, windowTriple*sizeof(t_float)); 328 | fftwf_free(fftwOut); 329 | fftwf_destroy_plan(fftwForwardPlan); 330 | fftwf_destroy_plan(fftwInversePlan); 331 | 332 | post("%s: EQ scalars applied to IR array %s", x->x_objSymbol->s_name, x->x_arrayName->s_name); 333 | 334 | // re-run analysis 335 | convolve_tilde_analyze(x, x->x_arrayName); 336 | } 337 | } 338 | 339 | 340 | static void convolve_tilde_window(convolve_tilde *x, t_float w) 341 | { 342 | int i, iWin, is64, oldWindow, oldWindowDouble; 343 | 344 | iWin = w; 345 | is64 = (iWin%64)==0; 346 | 347 | oldWindow = x->x_window; 348 | oldWindowDouble = x->x_windowDouble; 349 | 350 | if(is64) 351 | { 352 | if(iWin >= MINWIN) 353 | x->x_window = iWin; 354 | else 355 | { 356 | x->x_window = MINWIN; 357 | pd_error(x, "%s: requested window size too small. minimum value of %i used instead", x->x_objSymbol->s_name, x->x_window); 358 | } 359 | } 360 | else 361 | { 362 | x->x_window = DEFAULTWIN; 363 | pd_error(x, "%s: window not a multiple of 64. default value of %i used instead", x->x_objSymbol->s_name, x->x_window); 364 | } 365 | 366 | // resize time-domain buffer to zero bytes 367 | x->x_nonOverlappedOutput = (t_sample *)t_resizebytes( 368 | x->x_nonOverlappedOutput, 369 | (2*x->x_windowDouble)*sizeof(t_sample), 370 | 0 371 | ); 372 | 373 | // update window-based terms 374 | x->x_windowDouble = x->x_window*2; 375 | x->x_ampScalar = 1.0f/x->x_windowDouble; 376 | x->x_bufferLimit = x->x_window/x->x_n; 377 | 378 | // update window-based memory 379 | fftwf_free(x->x_irFreqDomData); 380 | fftwf_free(x->x_liveFreqDomData); 381 | fftwf_free(x->x_sigBufPadFftwOut); 382 | fftwf_free(x->x_invOutFftwIn); 383 | x->x_irFreqDomData = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 384 | x->x_liveFreqDomData = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 385 | x->x_sigBufPadFftwOut = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 386 | x->x_invOutFftwIn = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 387 | 388 | x->x_signalBuf = (t_sample *)t_resizebytes(x->x_signalBuf, oldWindow*sizeof(t_sample), x->x_window*sizeof(t_sample)); 389 | x->x_finalOutput = (t_sample *)t_resizebytes(x->x_finalOutput, oldWindow*sizeof(t_sample), x->x_window*sizeof(t_sample)); 390 | 391 | x->x_signalBufPadded = (t_sample *)t_resizebytes(x->x_signalBufPadded, oldWindowDouble*sizeof(t_sample), x->x_windowDouble*sizeof(t_sample)); 392 | x->x_invOutFftwOut = (t_sample *)t_resizebytes(x->x_invOutFftwOut, oldWindowDouble*sizeof(t_sample), x->x_windowDouble*sizeof(t_sample)); 393 | 394 | // signalBufPadded plan 395 | fftwf_destroy_plan(x->x_sigBufPadFftwPlan); 396 | fftwf_destroy_plan(x->x_invOutFftwPlan); 397 | x->x_sigBufPadFftwPlan = fftwf_plan_dft_r2c_1d(x->x_windowDouble, x->x_signalBufPadded, x->x_sigBufPadFftwOut, FFTW_ESTIMATE); 398 | x->x_invOutFftwPlan = fftwf_plan_dft_c2r_1d(x->x_windowDouble, x->x_invOutFftwIn, x->x_invOutFftwOut, FFTW_ESTIMATE); 399 | 400 | // init signal buffers 401 | for(i=0; ix_window; i++) 402 | { 403 | x->x_signalBuf[i] = 0.0; 404 | x->x_finalOutput[i] = 0.0; 405 | } 406 | 407 | for(i=0; ix_windowDouble; i++) 408 | { 409 | x->x_signalBufPadded[i] = 0.0; 410 | x->x_invOutFftwOut[i] = 0.0; 411 | } 412 | 413 | post("%s: partition size: %i", x->x_objSymbol->s_name, x->x_window); 414 | 415 | // set numParts back to zero so that the IR analysis routine is initialized as if it's the first call 416 | x->x_numParts = 0; 417 | // reset DSP ticks since we're clearing a new buffer and starting to fill it with signal 418 | x->x_dspTick = 0; 419 | 420 | // re-run IR analysis routine, but only IF x->arrayName exists 421 | if(!strcmp(x->x_arrayName->s_name, "NOARRAYSPECIFIED")) 422 | ; 423 | else 424 | convolve_tilde_analyze(x, x->x_arrayName); 425 | } 426 | 427 | 428 | static void convolve_tilde_print(convolve_tilde *x) 429 | { 430 | post("%s: IR array: %s", x->x_objSymbol->s_name, x->x_arrayName->s_name); 431 | post("%s: array length: %i", x->x_objSymbol->s_name, x->x_arraySize); 432 | post("%s: window size: %i", x->x_objSymbol->s_name, x->x_window); 433 | post("%s: number of partitions: %i", x->x_objSymbol->s_name, x->x_numParts); 434 | post("%s: sampling rate: %i", x->x_objSymbol->s_name, (int)x->x_sr); 435 | post("%s: block size: %i", x->x_objSymbol->s_name, (int)x->x_n); 436 | } 437 | 438 | 439 | static void convolve_tilde_flush(convolve_tilde *x) 440 | { 441 | int i; 442 | 443 | // init signal buffers 444 | for(i=0; ix_window; i++) 445 | { 446 | x->x_signalBuf[i] = 0.0; 447 | x->x_finalOutput[i] = 0.0; 448 | } 449 | 450 | for(i=0; ix_windowDouble; i++) 451 | { 452 | x->x_signalBufPadded[i] = 0.0; 453 | x->x_invOutFftwOut[i] = 0.0; 454 | } 455 | 456 | if(x->x_numParts>0) 457 | { 458 | // clear time-domain buffer 459 | for(i=0; i<2*x->x_windowDouble; i++) 460 | x->x_nonOverlappedOutput[i] = 0.0; 461 | 462 | // clear x_liveFreqDomData 463 | for(i=0; ix_numParts*(x->x_window+1); i++) 464 | { 465 | x->x_liveFreqDomData[i][0] = 0.0; 466 | x->x_liveFreqDomData[i][1] = 0.0; 467 | } 468 | } 469 | 470 | // reset buffering process 471 | x->x_dspTick = 0; 472 | } 473 | 474 | 475 | static void convolve_tilde_initClock(convolve_tilde *x) 476 | { 477 | x->x_startupFlag = 1; 478 | 479 | // try analyzing at creation if there was a table specified 480 | if(x->x_arrayName != gensym("NOARRAYSPECIFIED")) 481 | convolve_tilde_analyze(x, x->x_arrayName); 482 | } 483 | 484 | 485 | static void *convolve_tilde_new(t_symbol *s, int argc, t_atom *argv) 486 | { 487 | convolve_tilde *x = (convolve_tilde *)pd_new(convolve_tilde_class); 488 | 489 | int i, is64, window; 490 | 491 | outlet_new(&x->x_obj, &s_signal); 492 | 493 | // store the pointer to the symbol containing the object name. Can access it for error and post functions via s->s_name 494 | x->x_objSymbol = s; 495 | 496 | switch(argc) 497 | { 498 | case 0: 499 | window = DEFAULTWIN; 500 | x->x_arrayName = gensym("NOARRAYSPECIFIED"); 501 | break; 502 | 503 | case 1: 504 | window = atom_getfloat(argv); 505 | x->x_arrayName = gensym("NOARRAYSPECIFIED"); 506 | break; 507 | 508 | case 2: 509 | window = atom_getfloat(argv); 510 | x->x_arrayName = atom_getsymbol(argv+1); 511 | break; 512 | 513 | default: 514 | pd_error(x, "%s: the only creation argument should be the window/partition size in samples", x->x_objSymbol->s_name); 515 | window = DEFAULTWIN; 516 | x->x_arrayName = gensym("NOARRAYSPECIFIED"); 517 | break; 518 | } 519 | 520 | is64 = (window%64)==0; 521 | if(is64) 522 | { 523 | if(window >= MINWIN) 524 | x->x_window = window; 525 | else 526 | { 527 | x->x_window = MINWIN; 528 | pd_error(x, "%s: requested window size too small. minimum value of %i used instead", x->x_objSymbol->s_name, x->x_window); 529 | } 530 | } 531 | else 532 | { 533 | x->x_window = DEFAULTWIN; 534 | pd_error("%s: window not a multiple of 64. default value of %i used instead", x->x_objSymbol->s_name, x->x_window); 535 | } 536 | 537 | x->x_clock = clock_new(x, (t_method)convolve_tilde_initClock); 538 | x->x_arraySize = 0; 539 | x->x_numParts = 0; 540 | x->x_sr = 44100; 541 | x->x_n = 64; 542 | x->x_dspTick = 0; 543 | x->x_windowDouble = x->x_window*2; 544 | x->x_ampScalar = 1.0f/x->x_windowDouble; 545 | 546 | x->x_bufferLimit = x->x_window/x->x_n; 547 | 548 | // these will be resized when analysis occurs 549 | 550 | x->x_nonOverlappedOutput = (t_sample *)getbytes(0); 551 | // this can probably just be x_windowDouble * 2!! 552 | 553 | x->x_irSignalEq = (t_sample *)getbytes(0); 554 | x->x_irFreqDomData = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 555 | x->x_liveFreqDomData = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 556 | 557 | x->x_signalBuf = (t_sample *)getbytes(x->x_window*sizeof(t_sample)); 558 | x->x_signalBufPadded = (t_sample *)getbytes(x->x_windowDouble*sizeof(t_sample)); 559 | x->x_invOutFftwOut = (t_sample *)getbytes(x->x_windowDouble*sizeof(t_sample)); 560 | x->x_finalOutput = (t_sample *)getbytes(x->x_window*sizeof(t_sample)); 561 | 562 | // set up the FFTW output buffer for signalBufPadded 563 | x->x_sigBufPadFftwOut = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 564 | 565 | // signalBufPadded plan 566 | x->x_sigBufPadFftwPlan = fftwf_plan_dft_r2c_1d(x->x_windowDouble, x->x_signalBufPadded, x->x_sigBufPadFftwOut, FFTW_ESTIMATE); 567 | 568 | x->x_invOutFftwIn = (fftwf_complex *)fftwf_alloc_complex(x->x_window+1); 569 | 570 | // invOut plan 571 | x->x_invOutFftwPlan = fftwf_plan_dft_c2r_1d(x->x_windowDouble, x->x_invOutFftwIn, x->x_invOutFftwOut, FFTW_ESTIMATE); 572 | 573 | // init signal buffers 574 | for(i=0; ix_window; i++) 575 | { 576 | x->x_signalBuf[i] = 0.0; 577 | x->x_finalOutput[i] = 0.0; 578 | } 579 | 580 | for(i=0; ix_windowDouble; i++) 581 | { 582 | x->x_signalBufPadded[i] = 0.0; 583 | x->x_invOutFftwOut[i] = 0.0; 584 | } 585 | 586 | post("%s: version 0.13.1", x->x_objSymbol->s_name); 587 | post("%s: partition size %i", x->x_objSymbol->s_name, x->x_window); 588 | 589 | clock_delay(x->x_clock, 0); // wait 0ms before IR analysis to give a control cycle for IR samples to be loaded 590 | 591 | return(x); 592 | } 593 | 594 | 595 | static t_int *convolve_tilde_perform(t_int *w) 596 | { 597 | int i, p, n, window, windowDouble, numParts; 598 | t_float ampScalar; 599 | 600 | convolve_tilde *x = (convolve_tilde *)(w[1]); 601 | 602 | t_sample *in = (t_float *)(w[2]); 603 | t_sample *out = (t_float *)(w[3]); 604 | 605 | n = w[4]; 606 | window = x->x_window; 607 | windowDouble = x->x_windowDouble; 608 | numParts = x->x_numParts; 609 | ampScalar = x->x_ampScalar; 610 | 611 | if(n!=64 || numParts<1) 612 | { 613 | for(i=0; ix_signalBuf[(x->x_dspTick*n)+i] = in[i]; 622 | 623 | if(++x->x_dspTick >= x->x_bufferLimit) 624 | { 625 | x->x_dspTick = 0; 626 | 627 | // don't do anything if the IR hasn't been analyzed yet 628 | if(x->x_numParts>0) 629 | { 630 | 631 | // copy the signal buffer into the transform IN buffer 632 | for(i=0; ix_signalBufPadded[i] = x->x_signalBuf[i]; 634 | 635 | // pad the rest out with zeros 636 | for(; ix_signalBufPadded[i] = 0.0; 638 | 639 | // take FT of the most recent input, padded to double window size 640 | fftwf_execute(x->x_sigBufPadFftwPlan); 641 | 642 | // multiply against partitioned IR spectra. these need to be complex multiplies 643 | // also, sum into appropriate part of the nonoverlapped buffer 644 | for(p=0; px_sigBufPadFftwOut[i][0]; 655 | imagLive = x->x_sigBufPadFftwOut[i][1]; 656 | 657 | realIR = x->x_irFreqDomData[startIdx+i][0]; 658 | imagIR = x->x_irFreqDomData[startIdx+i][1]; 659 | 660 | // MINUS the imag part because i^2 = -1 661 | real = (realLive * realIR) - (imagLive * imagIR); 662 | imag = (imagLive * realIR) + (realLive * imagIR); 663 | 664 | // sum into the live freq domain data buffer 665 | x->x_liveFreqDomData[startIdx+i][0] += real; 666 | x->x_liveFreqDomData[startIdx+i][1] += imag; 667 | } 668 | } 669 | 670 | // copy the freq dom data from head of the complex summing buffer into the inverse FFT input buffer 671 | for(i=0; i<(window+1); i++) 672 | { 673 | x->x_invOutFftwIn[i][0] = x->x_liveFreqDomData[i][0]; 674 | x->x_invOutFftwIn[i][1] = x->x_liveFreqDomData[i][1]; 675 | } 676 | 677 | // execute 678 | fftwf_execute(x->x_invOutFftwPlan); 679 | 680 | // copy the latest IFFT time-domain result into the SECOND block of x_nonOverlappedOutput. The first block contains time-domain results from last time, which we will overlap-add with 681 | for(i=0; ix_nonOverlappedOutput[windowDouble+i] = x->x_invOutFftwOut[i]; 683 | 684 | // write time domain output to x->x_finalOutput and reduce gain 685 | for(i=0; ix_finalOutput[i] = x->x_nonOverlappedOutput[window+i] + x->x_nonOverlappedOutput[windowDouble+i]; 688 | 689 | x->x_finalOutput[i] *= ampScalar; 690 | } 691 | 692 | // push the live freq domain data buffer contents backwards 693 | for(i=0; i<((numParts*(window+1))-(window+1)); i++) 694 | { 695 | x->x_liveFreqDomData[i][0] = x->x_liveFreqDomData[(window+1)+i][0]; 696 | x->x_liveFreqDomData[i][1] = x->x_liveFreqDomData[(window+1)+i][1]; 697 | } 698 | 699 | // init the newly available chunk at the end 700 | for(; i<(numParts*(window+1)); i++) 701 | { 702 | x->x_liveFreqDomData[i][0] = 0.0; 703 | x->x_liveFreqDomData[i][1] = 0.0; 704 | } 705 | 706 | // push remaining output buffer contents backwards 707 | for(i=0; ix_nonOverlappedOutput[i] = x->x_nonOverlappedOutput[windowDouble+i]; 709 | 710 | // init the newly available chunk at the end 711 | for(; i<(2*windowDouble); i++) 712 | x->x_nonOverlappedOutput[i] = 0.0; 713 | } 714 | }; 715 | 716 | // output 717 | for(i=0; ix_finalOutput[(x->x_dspTick*n)+i]; 719 | 720 | return (w+5); 721 | } 722 | 723 | 724 | // could do a check here for whether x->x_n == sp[0]->s_n 725 | // if not, could suspend DSP and throw an error. Block sizes must match 726 | static void convolve_tilde_dsp(convolve_tilde *x, t_signal **sp) 727 | { 728 | dsp_add( 729 | convolve_tilde_perform, 730 | 4, 731 | x, 732 | sp[0]->s_vec, 733 | sp[1]->s_vec, 734 | sp[0]->s_n 735 | ); 736 | 737 | // TODO: could allow for re-blocking and re-calc x_bufferLimit based on new x_n 738 | if(sp[0]->s_n != x->x_n) 739 | pd_error(x, "%s: block size must be 64. DSP suspended.", x->x_objSymbol->s_name); 740 | 741 | if(sp[0]->s_sr != x->x_sr) 742 | { 743 | x->x_sr = sp[0]->s_sr; 744 | post("%s: sample rate updated to %0.0f", x->x_objSymbol->s_name, x->x_sr); 745 | }; 746 | 747 | if(x->x_numParts<1) 748 | pd_error(x, "%s: impulse response analysis not performed yet. output will be zero.", x->x_objSymbol->s_name); 749 | }; 750 | 751 | 752 | static void convolve_tilde_free(convolve_tilde *x) 753 | { 754 | t_freebytes(x->x_irSignalEq, x->x_arraySize*sizeof(t_sample)); 755 | t_freebytes(x->x_signalBuf, x->x_window*sizeof(t_sample)); 756 | t_freebytes(x->x_signalBufPadded, x->x_windowDouble*sizeof(t_sample)); 757 | t_freebytes(x->x_invOutFftwOut, x->x_windowDouble*sizeof(t_sample)); 758 | t_freebytes(x->x_finalOutput, x->x_window*sizeof(t_sample)); 759 | 760 | // free FFTW stuff 761 | fftwf_free(x->x_irFreqDomData); 762 | fftwf_free(x->x_liveFreqDomData); 763 | fftwf_free(x->x_sigBufPadFftwOut); 764 | fftwf_free(x->x_invOutFftwIn); 765 | fftwf_destroy_plan(x->x_sigBufPadFftwPlan); 766 | fftwf_destroy_plan(x->x_invOutFftwPlan); 767 | 768 | if(x->x_numParts>0) 769 | { 770 | t_freebytes( 771 | x->x_nonOverlappedOutput, 772 | 2*x->x_windowDouble*sizeof(t_sample) 773 | ); 774 | } 775 | else 776 | t_freebytes(x->x_nonOverlappedOutput, 0); 777 | 778 | clock_free(x->x_clock); 779 | }; 780 | 781 | 782 | void convolve_tilde_setup(void) 783 | { 784 | convolve_tilde_class = 785 | class_new( 786 | gensym("convolve~"), 787 | (t_newmethod)convolve_tilde_new, 788 | (t_method)convolve_tilde_free, 789 | sizeof(convolve_tilde), 790 | CLASS_DEFAULT, 791 | A_GIMME, 792 | 0 793 | ); 794 | 795 | CLASS_MAINSIGNALIN(convolve_tilde_class, convolve_tilde, x_f); 796 | 797 | class_addcreator( 798 | (t_newmethod)convolve_tilde_new, 799 | gensym("wmbrent/convolve~"), 800 | A_GIMME, 801 | 0 802 | ); 803 | 804 | class_addmethod( 805 | convolve_tilde_class, 806 | (t_method)convolve_tilde_print, 807 | gensym("print"), 808 | 0 809 | ); 810 | 811 | class_addmethod( 812 | convolve_tilde_class, 813 | (t_method)convolve_tilde_window, 814 | gensym("window"), 815 | A_DEFFLOAT, 816 | 0 817 | ); 818 | 819 | class_addmethod( 820 | convolve_tilde_class, 821 | (t_method)convolve_tilde_analyze, 822 | gensym("analyze"), 823 | A_SYMBOL, 824 | 0 825 | ); 826 | 827 | class_addmethod( 828 | convolve_tilde_class, 829 | (t_method)convolve_tilde_eq, 830 | gensym("eq"), 831 | A_GIMME, 832 | 0 833 | ); 834 | 835 | class_addmethod( 836 | convolve_tilde_class, 837 | (t_method)convolve_tilde_flush, 838 | gensym("flush"), 839 | 0 840 | ); 841 | 842 | class_addmethod( 843 | convolve_tilde_class, 844 | (t_method)convolve_tilde_dsp, 845 | gensym("dsp"), 846 | 0 847 | ); 848 | } 849 | --------------------------------------------------------------------------------