From fa14fabc34f6a6a97fba01cd3e89b111a0ba96ea Mon Sep 17 00:00:00 2001 From: Rich E Date: Fri, 18 Jan 2008 20:20:04 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r9149, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/oscbank~/; revision=9150 --- GnuGPL.txt | 340 +++++++++++++++++++++++++++++++++++++++++++++++++ README.txt | 35 +++++ makefile | 62 +++++++++ oscbank~-help.pd | 382 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ oscbank~.c | 286 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1105 insertions(+) create mode 100644 GnuGPL.txt create mode 100644 README.txt create mode 100644 makefile create mode 100644 oscbank~-help.pd create mode 100644 oscbank~.c diff --git a/GnuGPL.txt b/GnuGPL.txt new file mode 100644 index 0000000..d60c31a --- /dev/null +++ b/GnuGPL.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..07fca90 --- /dev/null +++ b/README.txt @@ -0,0 +1,35 @@ +----------------------------------------------------------------------------- +oscbank~: for additive synthesis +----------------------------------------------------------------------------- + +The oscbank external is an object for Miller Pucketter's PureData +("pd"). It was written in order to synthesize sinusoidal models that +consist of hundreds of partial sinewave components. The external +takes three parameters for each partial: index(unique), frequency, and +amplitude. It then synthesizes the partial's information in a bank and +synthesizes it. If the partial's frequency or amplitude are +modified (by providing another set with the same index), the +parameters are ramped to the new values. + +note: the oscbank~ external is published under the Gnu General Public License +that is included (GnuGPL.txt). some parts of the code are taken directly +from the pd source-code, they, of course, fall under the license pd is +published under. + +installation (from this directory): +----------------------------------------------------------------------------- +linux: make pd_linux +mac: make pd_darwin +windows: make pd_nt + +author: +----------------------------------------------------------------------------- +this software is copyleft 2007-2015 by +Richie Eakin < reakinator [at] gmail [dot] com +with the kind help of Tom Erbe. + +history: +----------------------------------------------------------------------------- +10-15-2007 - v0.1 +- The code has been sitting around for a while with a bunch of bugs, + finally got around to fixing them all. So here is the first version. diff --git a/makefile b/makefile new file mode 100644 index 0000000..5cc7406 --- /dev/null +++ b/makefile @@ -0,0 +1,62 @@ +# ----------------------- LINUX i386 ----------------------- + +pd_linux: oscbank~.pd_linux + + + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I /usr/local/src/pd + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm + strip --strip-unneeded $*.pd_linux + rm $*.o + + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: oscbank~.pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +DARWIN_INCLUDE = -I /usr/local/include + +.c.pd_darwin: + cc $(DARWINCFLAGS) $(DARWIN_INCLUDE) -o $*.o -c $*.c + cc -bundle -undefined suppress -lsdif -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ----------------------- NT ----------------------- + +pd_nt: oscbank~.dll + +.SUFFIXES: .obj .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="D:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I\tcl\include /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$*_setup $*.obj $(PDNTLIB) + +# override explicitly for tilde objects like this: +dspobj~.dll: dspobj~.c; + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:dspobj_tilde_setup $*.obj $(PDNTLIB) \ No newline at end of file diff --git a/oscbank~-help.pd b/oscbank~-help.pd new file mode 100644 index 0000000..d569363 --- /dev/null +++ b/oscbank~-help.pd @@ -0,0 +1,382 @@ +#N canvas 18 38 751 538 10; +#X obj 130 437 oscbank~; +#N canvas 0 0 220 207 output 0; +#X obj 43 260 dac~; +#X obj 25 121 inlet~; +#X obj 98 203 line~; +#X obj 43 239 *~; +#X obj 106 147 dbtorms; +#X msg 106 167 \$1 25; +#X obj 103 122 nbx 5 14 -1e+37 1e+37 0 1 empty empty empty 0 -6 0 10 +-262144 -1 -1 80 256; +#X connect 1 0 3 0; +#X connect 2 0 3 1; +#X connect 3 0 0 0; +#X connect 4 0 5 0; +#X connect 5 0 2 0; +#X connect 6 0 4 0; +#X coords 0 -1 1 1 60 40 1 100 100; +#X restore 131 479 pd output; +#X floatatom 175 420 5 0 0 2 interp_ms - -; +#X text 355 403 Inlets:; +#X text 355 416 1 index (integer <= 0); +#X text 355 430 2 frequency (hz.); +#X text 355 443 3 amplitude (rms ); +#X msg 243 165 1 440 0.7; +#X msg 243 193 1 50 0; +#X text 309 173 sometimes less of a hassle to list one partial as a +list; +#X text 309 185 if done using all the float inlets \, only the leftmost +; +#X text 309 197 inlet updates the partial at the specified index; +#X text 355 456 4 interpolation time (msec.); +#X text 382 468 - default is 20ms @ 44.1k SR; +#X msg 244 221 print; +#X text 284 220 prints all partials in the bank; +#X msg 244 242 reset; +#X text 279 241 clears everything in the bank to zero; +#X msg 244 267 table OscbankWaveform; +#X text 310 161 One partial; +#X text 382 260 specify the wavetable for oscbank~ to use; +#N canvas 70 547 936 270 theTable 0; +#X text 13 40 it would be better to avoid interpolation on a few; +#X text 13 55 hundred partials and just use a gigantic table that; +#X text 12 70 is about the same fidelity as a 512n table with; +#X text 12 84 quadratic interpolation. Make a smaller one if you; +#X text 12 99 want. You can also get interesting overtones with; +#X text 13 114 wierd tables (draw in this one with a bunch of; +#N canvas 0 0 450 300 graph2 0; +#X array OscbankWaveform 1027 float 1; +#A 0 -0.00613588 0 0.00613588 0.0122715 0.0184067 0.0245412 0.0306748 +0.0368072 0.0429382 0.0490676 0.0551952 0.0613207 0.0674439 0.0735645 +0.0796824 0.0857972 0.0919089 0.0980171 0.104122 0.110222 0.116319 +0.122411 0.128498 0.134581 0.140658 0.14673 0.152797 0.158858 0.164913 +0.170962 0.177004 0.18304 0.189069 0.19509 0.201104 0.207111 0.21311 +0.219101 0.225084 0.231058 0.237023 0.24298 0.248927 0.254865 0.260794 +0.266713 0.272621 0.278519 0.284407 0.290284 0.296151 0.302006 0.307849 +0.313681 0.319502 0.32531 0.331106 0.33689 0.34266 0.348418 0.354163 +0.359895 0.365613 0.371317 0.377007 0.382683 0.388345 0.393992 0.399624 +0.405241 0.410843 0.416429 0.422 0.427555 0.433093 0.438616 0.444122 +0.449611 0.455083 0.460538 0.465976 0.471396 0.476799 0.482183 0.48755 +0.492898 0.498227 0.503538 0.50883 0.514102 0.519356 0.524589 0.529803 +0.534997 0.540171 0.545325 0.550458 0.55557 0.560661 0.565731 0.57078 +0.575808 0.580814 0.585797 0.590759 0.595699 0.600616 0.605511 0.610382 +0.615231 0.620057 0.624859 0.629638 0.634393 0.639124 0.643831 0.648514 +0.653172 0.657806 0.662415 0.666999 0.671558 0.676092 0.680601 0.685083 +0.68954 0.693971 0.698376 0.702754 0.707106 0.711432 0.71573 0.720002 +0.724247 0.728464 0.732654 0.736816 0.740951 0.745057 0.749136 0.753186 +0.757208 0.761202 0.765167 0.769103 0.77301 0.776888 0.780737 0.784556 +0.788346 0.792106 0.795836 0.799537 0.803207 0.806847 0.810457 0.814036 +0.817584 0.821102 0.824589 0.828045 0.831469 0.834862 0.838224 0.841555 +0.844853 0.84812 0.851355 0.854558 0.857728 0.860866 0.863972 0.867046 +0.870087 0.873095 0.87607 0.879012 0.881921 0.884797 0.887639 0.890448 +0.893224 0.895966 0.898674 0.901348 0.903989 0.906595 0.909168 0.911706 +0.914209 0.916679 0.919113 0.921514 0.923879 0.92621 0.928506 0.930767 +0.932992 0.935183 0.937339 0.939459 0.941544 0.943593 0.945607 0.947585 +0.949528 0.951435 0.953306 0.955141 0.95694 0.958703 0.96043 0.962121 +0.963776 0.965394 0.966976 0.968522 0.970031 0.971504 0.97294 0.974339 +0.975702 0.977028 0.978317 0.97957 0.980785 0.981964 0.983105 0.98421 +0.985277 0.986308 0.987301 0.988257 0.989176 0.990058 0.990902 0.99171 +0.992479 0.993212 0.993907 0.994564 0.995185 0.995767 0.996312 0.99682 +0.99729 0.997723 0.998118 0.998475 0.998795 0.999078 0.999322 0.999529 +0.999699 0.999831 0.999925 0.999981 1 0.999981 0.999925 0.999831 0.999699 +0.999529 0.999322 0.999078 0.998796 0.998476 0.998118 0.997723 0.997291 +0.99682 0.996313 0.995768 0.995185 0.994565 0.993907 0.993212 0.99248 +0.99171 0.990903 0.990058 0.989177 0.988258 0.987302 0.986308 0.985278 +0.98421 0.983106 0.981964 0.980786 0.97957 0.978318 0.977028 0.975702 +0.97434 0.97294 0.971504 0.970032 0.968522 0.966977 0.965395 0.963776 +0.962122 0.960431 0.958704 0.956941 0.955142 0.953306 0.951436 0.949529 +0.947586 0.945608 0.943594 0.941545 0.93946 0.93734 0.935184 0.932993 +0.930768 0.928507 0.926211 0.92388 0.921515 0.919115 0.91668 0.91421 +0.911707 0.909169 0.906596 0.90399 0.90135 0.898675 0.895967 0.893225 +0.89045 0.88764 0.884798 0.881922 0.879013 0.876071 0.873096 0.870088 +0.867047 0.863974 0.860868 0.85773 0.854559 0.851356 0.848121 0.844855 +0.841556 0.838226 0.834864 0.831471 0.828046 0.82459 0.821104 0.817586 +0.814037 0.810458 0.806849 0.803209 0.799538 0.795838 0.792108 0.788348 +0.784558 0.780738 0.77689 0.773012 0.769105 0.765168 0.761204 0.75721 +0.753188 0.749138 0.745059 0.740952 0.736818 0.732656 0.728466 0.724248 +0.720004 0.715732 0.711434 0.707108 0.702756 0.698378 0.693973 0.689542 +0.685085 0.680602 0.676094 0.67156 0.667001 0.662417 0.657808 0.653174 +0.648516 0.643833 0.639126 0.634395 0.62964 0.624861 0.620059 0.615233 +0.610384 0.605513 0.600618 0.595701 0.590761 0.5858 0.580816 0.57581 +0.570782 0.565734 0.560663 0.555572 0.55046 0.545327 0.540173 0.534999 +0.529805 0.524592 0.519358 0.514105 0.508832 0.50354 0.49823 0.4929 +0.487552 0.482186 0.476801 0.471399 0.465978 0.460541 0.455086 0.449613 +0.444124 0.438618 0.433096 0.427557 0.422002 0.416432 0.410845 0.405243 +0.399626 0.393994 0.388347 0.382686 0.37701 0.371319 0.365615 0.359897 +0.354166 0.348421 0.342663 0.336892 0.331109 0.325313 0.319504 0.313684 +0.307852 0.302008 0.296153 0.290287 0.28441 0.278522 0.272624 0.266715 +0.260796 0.254868 0.24893 0.242983 0.237026 0.231061 0.225086 0.219104 +0.213113 0.207114 0.201107 0.195093 0.189071 0.183042 0.177007 0.170964 +0.164916 0.158861 0.1528 0.146733 0.140661 0.134583 0.128501 0.122413 +0.116321 0.110225 0.104124 0.0980197 0.0919115 0.0857999 0.079685 0.0735671 +0.0674465 0.0613233 0.0551978 0.0490703 0.0429409 0.0368098 0.0306774 +0.0245439 0.0184094 0.0122742 0.00613853 2.65359e-06 -0.00613323 -0.0122689 +-0.0184041 -0.0245386 -0.0306721 -0.0368045 -0.0429356 -0.049065 -0.0551925 +-0.061318 -0.0674412 -0.0735619 -0.0796797 -0.0857946 -0.0919062 -0.0980144 +-0.104119 -0.110219 -0.116316 -0.122408 -0.128495 -0.134578 -0.140655 +-0.146728 -0.152794 -0.158855 -0.16491 -0.170959 -0.177001 -0.183037 +-0.189066 -0.195088 -0.201102 -0.207109 -0.213108 -0.219098 -0.225081 +-0.231055 -0.237021 -0.242977 -0.248925 -0.254863 -0.260791 -0.26671 +-0.272619 -0.278517 -0.284405 -0.290282 -0.296148 -0.302003 -0.307847 +-0.313679 -0.319499 -0.325308 -0.331104 -0.336887 -0.342658 -0.348416 +-0.354161 -0.359892 -0.36561 -0.371314 -0.377005 -0.382681 -0.388342 +-0.393989 -0.399621 -0.405239 -0.41084 -0.416427 -0.421998 -0.427552 +-0.433091 -0.438614 -0.444119 -0.449609 -0.455081 -0.460536 -0.465974 +-0.471394 -0.476797 -0.482181 -0.487547 -0.492896 -0.498225 -0.503536 +-0.508827 -0.5141 -0.519353 -0.524587 -0.529801 -0.534995 -0.540169 +-0.545322 -0.550455 -0.555568 -0.560659 -0.565729 -0.570778 -0.575806 +-0.580811 -0.585795 -0.590757 -0.595697 -0.600614 -0.605509 -0.61038 +-0.615229 -0.620055 -0.624857 -0.629636 -0.634391 -0.639122 -0.643829 +-0.648512 -0.65317 -0.657804 -0.662413 -0.666997 -0.671557 -0.67609 +-0.680599 -0.685081 -0.689538 -0.693969 -0.698374 -0.702752 -0.707104 +-0.71143 -0.715729 -0.72 -0.724245 -0.728462 -0.732652 -0.736814 -0.740949 +-0.745056 -0.749134 -0.753185 -0.757207 -0.7612 -0.765165 -0.769101 +-0.773008 -0.776886 -0.780735 -0.784554 -0.788344 -0.792104 -0.795835 +-0.799535 -0.803205 -0.806846 -0.810455 -0.814034 -0.817583 -0.821101 +-0.824587 -0.828043 -0.831468 -0.834861 -0.838223 -0.841553 -0.844852 +-0.848118 -0.851353 -0.854556 -0.857727 -0.860865 -0.863971 -0.867045 +-0.870085 -0.873093 -0.876068 -0.879011 -0.88192 -0.884795 -0.887638 +-0.890447 -0.893223 -0.895965 -0.898673 -0.901347 -0.903988 -0.906594 +-0.909166 -0.911705 -0.914208 -0.916678 -0.919112 -0.921513 -0.923878 +-0.926209 -0.928505 -0.930766 -0.932992 -0.935182 -0.937338 -0.939458 +-0.941543 -0.943592 -0.945606 -0.947584 -0.949527 -0.951434 -0.953305 +-0.95514 -0.956939 -0.958702 -0.960429 -0.96212 -0.963775 -0.965393 +-0.966976 -0.968521 -0.97003 -0.971503 -0.972939 -0.974339 -0.975701 +-0.977027 -0.978317 -0.979569 -0.980785 -0.981963 -0.983105 -0.984209 +-0.985277 -0.986307 -0.987301 -0.988257 -0.989176 -0.990058 -0.990902 +-0.991709 -0.992479 -0.993212 -0.993907 -0.994564 -0.995184 -0.995767 +-0.996312 -0.99682 -0.99729 -0.997723 -0.998118 -0.998475 -0.998795 +-0.999078 -0.999322 -0.999529 -0.999699 -0.99983 -0.999925 -0.999981 +-1 -0.999981 -0.999925 -0.999831 -0.999699 -0.99953 -0.999323 -0.999078 +-0.998796 -0.998476 -0.998118 -0.997723 -0.997291 -0.996821 -0.996313 +-0.995768 -0.995185 -0.994565 -0.993907 -0.993212 -0.99248 -0.99171 +-0.990903 -0.990059 -0.989177 -0.988258 -0.987302 -0.986309 -0.985278 +-0.984211 -0.983106 -0.981965 -0.980786 -0.979571 -0.978318 -0.977029 +-0.975703 -0.97434 -0.972941 -0.971505 -0.970032 -0.968523 -0.966978 +-0.965396 -0.963777 -0.962123 -0.960432 -0.958705 -0.956942 -0.955142 +-0.953307 -0.951436 -0.94953 -0.947587 -0.945609 -0.943595 -0.941545 +-0.939461 -0.93734 -0.935185 -0.932994 -0.930769 -0.928508 -0.926212 +-0.923881 -0.921516 -0.919116 -0.916681 -0.914212 -0.911708 -0.90917 +-0.906598 -0.903991 -0.901351 -0.898676 -0.895968 -0.893226 -0.890451 +-0.887642 -0.884799 -0.881923 -0.879014 -0.876072 -0.873097 -0.870089 +-0.867048 -0.863975 -0.860869 -0.857731 -0.85456 -0.851358 -0.848123 +-0.844856 -0.841557 -0.838227 -0.834865 -0.831472 -0.828048 -0.824592 +-0.821105 -0.817587 -0.814039 -0.81046 -0.80685 -0.80321 -0.79954 -0.79584 +-0.792109 -0.788349 -0.784559 -0.78074 -0.776891 -0.773013 -0.769106 +-0.76517 -0.761205 -0.757212 -0.75319 -0.749139 -0.745061 -0.740954 +-0.73682 -0.732657 -0.728468 -0.72425 -0.720006 -0.715734 -0.711435 +-0.70711 -0.702758 -0.69838 -0.693975 -0.689544 -0.685087 -0.680604 +-0.676096 -0.671562 -0.667003 -0.662419 -0.65781 -0.653176 -0.648518 +-0.643835 -0.639128 -0.634397 -0.629642 -0.624863 -0.620061 -0.615235 +-0.610387 -0.605515 -0.60062 -0.595703 -0.590764 -0.585802 -0.580818 +-0.575812 -0.570785 -0.565736 -0.560666 -0.555574 -0.550462 -0.545329 +-0.540176 -0.535002 -0.529808 -0.524594 -0.51936 -0.514107 -0.508834 +-0.503543 -0.498232 -0.492902 -0.487554 -0.482188 -0.476804 -0.471401 +-0.465981 -0.460543 -0.455088 -0.449616 -0.444127 -0.438621 -0.433098 +-0.42756 -0.422005 -0.416434 -0.410848 -0.405246 -0.399629 -0.393997 +-0.38835 -0.382688 -0.377012 -0.371322 -0.365618 -0.3599 -0.354168 +-0.348423 -0.342665 -0.336895 -0.331111 -0.325315 -0.319507 -0.313687 +-0.307854 -0.302011 -0.296156 -0.29029 -0.284412 -0.278525 -0.272626 +-0.266718 -0.260799 -0.254871 -0.248933 -0.242985 -0.237029 -0.231063 +-0.225089 -0.219106 -0.213115 -0.207116 -0.20111 -0.195095 -0.189074 +-0.183045 -0.177009 -0.170967 -0.164918 -0.158863; +#A 1000 -0.152802 -0.146736 -0.140663 -0.134586 -0.128503 -0.122416 +-0.116324 -0.110227 -0.104127 -0.0980223 -0.0919142 -0.0858025 -0.0796877 +-0.0735698 -0.0674492 -0.061326 -0.0552005 -0.0490729 -0.0429435 -0.0368125 +-0.0306801 -0.0245465 -0.018412 -0.0122768 -0.00614119 -5.30718e-06 +0.00613057; +#X coords 0 1 1026 -1 350 200 1; +#X restore 568 33 graph; +#X text 13 27 default is a sinusoid of size 2^16. I thought; +#X text 13 152 - the size of the table is figured out within the; +#X text 16 167 external.; +#X text 15 185 - CAREFUL: setting the table to a smaller size; +#X text 16 199 when DSP is on will cause oscbank~ to read out; +#X text 16 214 of the table size and crash.; +#N canvas 0 0 254 322 sqaure 0; +#X obj 20 21 inlet; +#X obj 20 93 until; +#X msg 20 70 1027; +#X obj 20 125 f; +#X obj 45 125 + 1; +#X obj 17 153 t f f; +#X obj 17 251 tabwrite OscbankWaveform; +#X obj 17 182 moses 513; +#X msg 53 213 0; +#X msg 17 213 0.9; +#X obj 20 45 t b b; +#X msg 58 93 0; +#X connect 0 0 10 0; +#X connect 1 0 3 0; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 3 0 5 0; +#X connect 4 0 3 1; +#X connect 5 0 7 0; +#X connect 5 1 6 1; +#X connect 7 0 9 0; +#X connect 7 1 8 0; +#X connect 8 0 6 0; +#X connect 9 0 6 0; +#X connect 10 0 2 0; +#X connect 10 1 11 0; +#X connect 11 0 3 1; +#X restore 393 110 pd sqaure; +#X text 338 163 sinesum will cause a small; +#X text 338 175 discont because of the +3; +#X text 338 186 guys on the end used for; +#X text 338 198 inertpolation; +#X obj 393 92 bng 15 250 50 0 empty empty empty 0 -6 0 10 -262144 -1 +-1; +#X msg 341 132 \; OscbankWaveform sinesum 1024 1; +#X obj 341 18 inlet; +#X obj 341 68 select sine square; +#X obj 341 42 symbol; +#X text 14 126 partials running to test it out).; +#X connect 18 0 13 0; +#X connect 20 0 22 0; +#X connect 21 0 19 0; +#X connect 21 1 18 0; +#X connect 22 0 21 0; +#X restore 646 266 pd theTable; +#X text 384 274 Warning! don't do when DSP is on; +#X msg 646 213 sine; +#X msg 655 234 square; +#X msg 244 304 partials 5; +#X msg 244 325 partials 500; +#X text 331 298 set the maximum numbers to store and synthesize; +#X text 331 313 if you try to load it with more \, the last one; +#X text 331 327 is stolen \, which creates a pop when the frequency +; +#X text 332 341 jumps immediately; +#N canvas 0 0 450 300 midi 0; +#X obj 18 44 notein; +#X floatatom 71 15 5 0 0 0 - - -; +#X floatatom 85 36 5 0 0 0 - - -; +#X floatatom 104 59 5 0 0 0 - - -; +#X obj 16 183 pack f f f; +#X obj 13 218 outlet; +#X obj -12 108 t f f; +#X obj 17 141 mtof; +#X obj 50 86 / 127; +#X connect 0 0 1 0; +#X connect 0 0 6 0; +#X connect 0 1 2 0; +#X connect 0 1 8 0; +#X connect 0 2 3 0; +#X connect 4 0 5 0; +#X connect 6 0 4 0; +#X connect 6 1 7 0; +#X connect 7 0 4 1; +#X connect 8 0 4 2; +#X restore 12 333 pd midi; +#X text 10 309 polyphonic keyboard synth; +#N canvas 1099 344 482 332 random 0; +#X obj 146 126 random 1000; +#X obj 356 170 / 1000; +#X obj 65 275 outlet; +#X obj 106 88 t b b b; +#X obj 86 129 + 1; +#X obj 174 23 inlet; +#X obj 230 30 inlet; +#X obj 94 12 inlet; +#X obj 260 164 / 2; +#X obj 231 90 t f f; +#X obj 188 207 +; +#X obj 323 21 inlet; +#X obj 187 184 -; +#X obj 99 50 metro 1000; +#X obj 357 141 random 100; +#X obj 69 249 pack f f f; +#X obj 51 130 f 0; +#X connect 0 0 12 0; +#X connect 1 0 15 2; +#X connect 3 0 16 0; +#X connect 3 1 0 0; +#X connect 3 2 14 0; +#X connect 4 0 16 1; +#X connect 5 0 13 1; +#X connect 6 0 9 0; +#X connect 7 0 13 0; +#X connect 8 0 12 1; +#X connect 9 0 0 1; +#X connect 9 1 8 0; +#X connect 10 0 15 1; +#X connect 11 0 10 1; +#X connect 12 0 10 0; +#X connect 13 0 3 0; +#X connect 14 0 1 0; +#X connect 15 0 2 0; +#X connect 16 0 4 0; +#X connect 16 0 15 0; +#X restore 14 205 pd random; +#X obj 14 177 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1 +; +#X floatatom 40 177 5 0 0 2 ms - -; +#X floatatom 91 178 5 0 0 2 bw - -; +#X floatatom 142 179 5 0 0 2 const - -; +#X text 239 140 Messages to first inlet:; +#X text 11 129 test how many your system; +#X text 12 141 can handle:; +#X floatatom 14 255 5 0 0 0 - - -; +#N canvas 0 22 474 324 blur 0; +#X obj 98 28 inlet; +#X obj 107 63 t b f b; +#X obj 53 103 f 1; +#X obj 88 102 + 1; +#X msg 158 89 0.01; +#X obj 50 212 pack f f f; +#X obj 46 262 outlet; +#X connect 0 0 1 0; +#X connect 1 0 2 0; +#X connect 1 1 5 1; +#X connect 1 2 4 0; +#X connect 2 0 3 0; +#X connect 2 0 5 0; +#X connect 3 0 2 1; +#X connect 4 0 5 2; +#X connect 5 0 6 0; +#X restore 14 276 pd blur; +#X obj 17 234 hsl 100 15 0 2500 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 0; +#X text 341 31 Currently \, the parameters are index (unique) \, frequency +\, and; +#X text 340 46 amplitude. Turn off a sinewave by giving it a 0 amplitude. +; +#X text 340 60 Both frequency and amplitude are interpolated.; +#X text 341 18 A bank of oscillators that is useful for additive synthesis. +; +#X obj 16 15 cnv 15 102 28 empty empty empty 20 12 0 14 -33289 -66577 +0; +#X obj 17 16 cnv 15 100 26 empty empty oscbank~ 14 12 2 20 -4160 -4034 +0; +#X text 127 26 author: Richie Eakin; +#X text 15 52 Send bugs \, comments \, suggestions to:; +#X text 15 65 reakinator@gmail.com; +#X msg 240 367 partials 1000; +#X text 327 365 - 1000 partials uses 57% cpu on my Core 2 Duo laptop +; +#X text 340 378 running Ubuntu!; +#X text 128 14 version 0.1; +#X connect 0 0 1 0; +#X connect 2 0 0 3; +#X connect 7 0 0 0; +#X connect 8 0 0 0; +#X connect 14 0 0 0; +#X connect 16 0 0 0; +#X connect 18 0 0 0; +#X connect 23 0 21 0; +#X connect 24 0 21 0; +#X connect 25 0 0 0; +#X connect 26 0 0 0; +#X connect 31 0 0 0; +#X connect 33 0 0 0; +#X connect 34 0 33 0; +#X connect 35 0 33 1; +#X connect 36 0 33 2; +#X connect 37 0 33 3; +#X connect 41 0 42 0; +#X connect 42 0 0 0; +#X connect 43 0 41 0; +#X connect 53 0 0 0; diff --git a/oscbank~.c b/oscbank~.c new file mode 100644 index 0000000..5369670 --- /dev/null +++ b/oscbank~.c @@ -0,0 +1,286 @@ +/* ------------------------ oscbank~ 0.1 ----------------------------- */ +// oscillator bank using 3 seperate float inlets with interpolation +// author - Richie Eakin reakinator@gmail.com 10-15-2007 +/* ----------------------------------------------------------------*/ + +#include "m_pd.h" +#include +#include +#include + +#ifdef NT +#pragma warning( disable : 4244 ) +#define inline +#endif + +#define WAVETABLESIZE 65536 //2^16 +#define DEFAULT_NPARTIALS 100 +#define DEFAULT_interp_incr 0.0045 //per sample, this is 20 ms @ 44k sr + +static t_class *oscbank_class; + +//t_partial represents one partial member in the bank +typedef struct _partial +{ + int index; + float fCurr; + float freq; + float fIncr; + float aCurr; + float amp; + float aIncr; + float phase; + unsigned long nInterp; +} t_partial; + +typedef struct _oscbank +{ + t_object x_obj; + float *wavetable; + int wavetablesize; + int got_a_table; + t_partial *pBank; + float infreq; + float inamp; + float sampleRate; + float sampleperiod; + float interp_incr; + long interpSamples; + int sp; + int nPartials; +} t_oscbank; + +/*----- Interpolation Time ----- + milleseconds to interpolate over; so samples = (n*SR)/1000 + divide only when converting the interp time to samples(here),since it + is only used as a denominator to find the increment proportion: + SP= 1/SR, 1/(n*SR/1000) = (1000*SP)/n +*/ +static void oscbank_interpMs(t_oscbank *x, t_floatarg n) +{ + + if(n > 0) x->interp_incr =(1000* x->sampleperiod)/ n ; + else x->interp_incr = x->sampleperiod; + + x->interpSamples = (unsigned long)((n *.001) * x->sampleRate); +} + +static void oscbank_nPartials(t_oscbank *x, t_floatarg n) +{ + x->pBank = (t_partial *)resizebytes( x->pBank, x->nPartials * sizeof(t_partial), \ + n * sizeof(t_partial)); + x->nPartials = n; + post("max partials: %d", x->nPartials); +} + +static void oscbank_index(t_oscbank *x, t_floatarg in) +{ + int i, iindex; + iindex = (int)in; + t_partial *bank = x->pBank; + + + if( iindex < 0) + { + error("negative index rejected"); + return; + } + +//TODO: find open index in first loop, use that instead of second loop +//check if continuing partial + for(i =0; i < x->nPartials; i++) + { + if( bank[i].index == iindex) + {//recaluclate increment slope from current interpolated positions and update goal + if(bank[i].aCurr == 0) bank[i].aCurr = 0.0000001; + bank[i].fIncr = (x->infreq - bank[i].fCurr) * x->interp_incr; + bank[i].aIncr = (x->inamp - bank[i].aCurr) * x->interp_incr; + bank[i].freq = x->infreq; + bank[i].amp = x->inamp; + bank[i].nInterp = x->interpSamples; + return; + } + } //end continuing partial + + //new partial, see if there is an empty slot for the new partial + for(i =0; i < x->nPartials; i++) + { + if(bank[i].aCurr == 0) + { //new partial, only ramp amp from zero, + bank[i].index = iindex; + bank[i].fCurr = x->infreq; + bank[i].fIncr = 0; + bank[i].freq = x->infreq; + bank[i].amp = x->inamp; + bank[i].nInterp = x->interpSamples; + bank[i].aCurr = 0.0000001; + bank[i].aIncr = x->inamp * x->interp_incr; + return; + } + } //end new partial for + + //oscbank is full, steal oldest partial (creates a pop) and ramp amp from zero + bank[x->sp].index = iindex; + bank[x->sp].fCurr = x->infreq; + bank[x->sp].fIncr = 0; + bank[x->sp].freq = x->infreq; + bank[x->sp].amp = x->inamp; + bank[x->sp].nInterp = x->interpSamples; + bank[x->sp].aCurr = 0.0000001; + bank[x->sp].aIncr = x->inamp * x->interp_incr; + x->sp++; + if(x->sp == x->nPartials) x->sp = 0; +} + +static void oscbank_table(t_oscbank *x, t_symbol *tablename) +{ + if(!x->got_a_table) free(x->wavetable); + + t_garray *a; + + if (!(a = (t_garray *)pd_findbyclass(tablename, garray_class))) + pd_error(x, "%s: no such array", tablename->s_name); + else if (!garray_getfloatarray(a, &x->wavetablesize, &x->wavetable)) + pd_error(x, "%s: bad template for tabread", tablename->s_name); + else //table exists + { + post("wavetablesize: %d", x->wavetablesize ); + } + x->got_a_table = 1; +} + +static void oscbank_print(t_oscbank *x) +{ + t_partial *bank = x->pBank; + + post("#. Index, Freq, Amp"); + int i; + + for(i=0; i < x->nPartials; i++)//for every partial + { + if(bank[i].aCurr) + { + post("%d. index: %d,freq: %f,amp: %f", i, bank[i].index, + bank[i].freq, bank[i].amp ); + } + } +} + +//TODO: this is crashing shit... whhhaaat +static void oscbank_reset(t_oscbank *x) +{ + memset(x->pBank, 0, x->nPartials * sizeof(t_partial)); +} + +static t_int *oscbank_perform(t_int *w) +{ + t_oscbank *x = (t_oscbank *)(w[1]); + t_float *out = (t_float *)(w[2]); + t_int n = (t_int)(w[3]); + t_int i, sample; + t_float phaseincrement; + t_float sample_sum, freq, amp; + t_int lookup; + t_partial *bank = x->pBank; + + //clear output buffer so we can add to it starting at 0 + memset( out , 0, n *sizeof( t_float )); + + for(i=0; i < x->nPartials; i++)//for every partial + { + if(bank[i].aCurr != 0) + { + for(sample = 0; sample < n; sample++)//and every sample.. + { + if(bank[i].nInterp > 0) + { + bank[i].fCurr += bank[i].fIncr; + bank[i].aCurr += bank[i].aIncr; + --bank[i].nInterp; + } + else + { + bank[i].fCurr = bank[i].freq; + bank[i].aCurr = bank[i].amp; + } + + // get the phase increment freq = cyc/sec, + //sr = samp/sec, phaseinc = cyc/samp = freq/sr = freq * sampleperiod + phaseincrement = bank[i].fCurr * x->sampleperiod; + bank[i].phase += phaseincrement; + while(bank[i].phase >= 1.0f) //..and wrap + bank[i].phase -= 1.0f; + while(bank[i].phase < 0.0f) + bank[i].phase += 1.0f; + + lookup = (int)(x->wavetablesize * bank[i].phase); + + *(out+sample) += *(x->wavetable + lookup) * bank[i].aCurr; + }//end for samples + } //end if x->index + }//end for partials + return (w+4); +} + +static void oscbank_dsp(t_oscbank *x, t_signal **sp) +{ + x->sampleRate = sp[0]->s_sr; + x->sampleperiod = 1 / x->sampleRate; + dsp_add(oscbank_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); +} + +static void *oscbank_new(void) +{ + t_oscbank *x = (t_oscbank *)pd_new(oscbank_class); + + float twopi, size; + int i; + + outlet_new(&x->x_obj, gensym("signal")); + floatinlet_new(&x->x_obj, &x->infreq); + floatinlet_new(&x->x_obj, &x->inamp); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("interp")); + + //hardcoded because dsp hasn't been turned on yet + //prevents devide by zero in oscbank_index() + x->sampleRate = 48000; + x->sampleperiod = 1 / x->sampleRate; + oscbank_interpMs( x, 20.0); + + x->got_a_table = 0; + x->sp = 0; + x->nPartials = DEFAULT_NPARTIALS; + x->pBank = (t_partial *)getbytes( x->nPartials * sizeof(t_partial)); + memset(x->pBank, 0, x->nPartials * sizeof(t_partial)); + + twopi = 8.0f * atan(1.0f); + x->wavetablesize = WAVETABLESIZE; + float *sinewave; + sinewave = (t_float *)malloc(x->wavetablesize * sizeof(t_float)); + for(i = 0; i < x->wavetablesize; i++) + sinewave[i] = sin(twopi * (float)i/ x->wavetablesize); + + x->wavetable = &sinewave[0]; + + return (x); +} + +static void oscbank_free(t_oscbank *x) +{ + free(x->pBank); + if(!x->got_a_table) + free(x->wavetable); +} + +void oscbank_tilde_setup(void) +{ + oscbank_class = class_new(gensym("oscbank~"),(t_newmethod)oscbank_new,\ + (t_method)oscbank_free,sizeof(t_oscbank), 0, A_DEFFLOAT, 0); + class_addfloat(oscbank_class, oscbank_index); + class_addmethod(oscbank_class, (t_method)oscbank_table, gensym("table"), A_SYMBOL); + class_addmethod(oscbank_class, (t_method)oscbank_interpMs, gensym("interp"), A_FLOAT, 0); + class_addmethod(oscbank_class, (t_method)oscbank_dsp, gensym("dsp"), (t_atomtype)0); + class_addmethod(oscbank_class, (t_method)oscbank_print, gensym("print"), 0); + class_addmethod(oscbank_class, (t_method)oscbank_reset, gensym("reset"), 0); + class_addmethod(oscbank_class, (t_method)oscbank_nPartials, gensym("partials"), A_FLOAT, 0); +} -- cgit v1.2.1