Debian Codegraph @

src/objects/oscilmodule.c

raw
1 /**************************************************************************
2 * Copyright 2009-2015 Olivier Belanger *
3 * *
4 * This file is part of pyo, a python module to help digital signal *
5 * processing script creation. *
6 * *
7 * pyo is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * pyo is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with pyo. If not, see <http://www.gnu.org/licenses/>. *
19 *************************************************************************/
20
21 #include <Python.h>
22 #include "structmember.h"
23 #include <math.h>
24 #include "pyomodule.h"
25 #include "streammodule.h"
26 #include "servermodule.h"
27 #include "dummymodule.h"
28 #include "tablemodule.h"
29 #include "interpolation.h"
30
31 static MYFLT SINE_ARRAY[513] = {0.0, 0.012271538285719925, 0.024541228522912288, 0.036807222941358832, 0.049067674327418015, 0.061320736302208578, 0.073564563599667426, 0.085797312344439894, 0.098017140329560604, 0.11022220729388306, 0.1224106751992162, 0.13458070850712617, 0.14673047445536175, 0.15885814333386145, 0.17096188876030122, 0.18303988795514095, 0.19509032201612825, 0.20711137619221856, 0.2191012401568698, 0.23105810828067111, 0.24298017990326387, 0.25486565960451457, 0.26671275747489837, 0.27851968938505306, 0.29028467725446233, 0.30200594931922808, 0.31368174039889152, 0.32531029216226293, 0.33688985339222005, 0.34841868024943456, 0.35989503653498811, 0.37131719395183754, 0.38268343236508978, 0.3939920400610481, 0.40524131400498986, 0.41642956009763715, 0.42755509343028208, 0.43861623853852766, 0.44961132965460654, 0.46053871095824001, 0.47139673682599764, 0.48218377207912272, 0.49289819222978404, 0.50353838372571758, 0.51410274419322166, 0.52458968267846895, 0.53499761988709715, 0.54532498842204646, 0.55557023301960218, 0.56573181078361312, 0.57580819141784534, 0.58579785745643886, 0.59569930449243336, 0.60551104140432555, 0.61523159058062682, 0.62485948814238634, 0.63439328416364549, 0.64383154288979139, 0.65317284295377676, 0.66241577759017178, 0.67155895484701833, 0.68060099779545302, 0.68954054473706683, 0.69837624940897292, 0.70710678118654746, 0.71573082528381859, 0.72424708295146689, 0.7326542716724127, 0.74095112535495899, 0.74913639452345926, 0.75720884650648446, 0.76516726562245885, 0.77301045336273688, 0.78073722857209438, 0.78834642762660623, 0.79583690460888346, 0.80320753148064483, 0.81045719825259477, 0.81758481315158371, 0.82458930278502529, 0.83146961230254512, 0.83822470555483797, 0.84485356524970701, 0.8513551931052652, 0.85772861000027212, 0.8639728561215867, 0.87008699110871135, 0.87607009419540649, 0.88192126434835494, 0.88763962040285393, 0.89322430119551532, 0.89867446569395382, 0.90398929312344334, 0.90916798309052238, 0.91420975570353069, 0.91911385169005777, 0.92387953251128674, 0.92850608047321548, 0.93299279883473885, 0.93733901191257496, 0.94154406518302081, 0.94560732538052128, 0.94952818059303667, 0.95330604035419375, 0.95694033573220894, 0.96043051941556579, 0.96377606579543984, 0.96697647104485207, 0.97003125319454397, 0.97293995220556007, 0.97570213003852857, 0.97831737071962765, 0.98078528040323043, 0.98310548743121629, 0.98527764238894122, 0.98730141815785843, 0.98917650996478101, 0.99090263542778001, 0.99247953459870997, 0.99390697000235606, 0.99518472667219682, 0.996312612182778, 0.99729045667869021, 0.99811811290014918, 0.99879545620517241, 0.99932238458834954, 0.99969881869620425, 0.9999247018391445, 1.0, 0.9999247018391445, 0.99969881869620425, 0.99932238458834954, 0.99879545620517241, 0.99811811290014918, 0.99729045667869021, 0.996312612182778, 0.99518472667219693, 0.99390697000235606, 0.99247953459870997, 0.99090263542778001, 0.98917650996478101, 0.98730141815785843, 0.98527764238894122, 0.98310548743121629, 0.98078528040323043, 0.97831737071962765, 0.97570213003852857, 0.97293995220556018, 0.97003125319454397, 0.96697647104485207, 0.96377606579543984, 0.9604305194155659, 0.95694033573220894, 0.95330604035419386, 0.94952818059303667, 0.94560732538052139, 0.94154406518302081, 0.93733901191257496, 0.93299279883473885, 0.92850608047321559, 0.92387953251128674, 0.91911385169005777, 0.91420975570353069, 0.90916798309052249, 0.90398929312344345, 0.89867446569395393, 0.89322430119551521, 0.88763962040285393, 0.88192126434835505, 0.8760700941954066, 0.87008699110871146, 0.86397285612158681, 0.85772861000027212, 0.8513551931052652, 0.84485356524970723, 0.83822470555483819, 0.83146961230254546, 0.82458930278502529, 0.81758481315158371, 0.81045719825259477, 0.80320753148064494, 0.79583690460888357, 0.78834642762660634, 0.7807372285720946, 0.7730104533627371, 0.76516726562245907, 0.75720884650648479, 0.74913639452345926, 0.74095112535495899, 0.73265427167241282, 0.724247082951467, 0.71573082528381871, 0.70710678118654757, 0.69837624940897292, 0.68954054473706705, 0.68060099779545324, 0.67155895484701855, 0.66241577759017201, 0.65317284295377664, 0.64383154288979139, 0.63439328416364549, 0.62485948814238634, 0.61523159058062693, 0.60551104140432555, 0.59569930449243347, 0.58579785745643898, 0.57580819141784545, 0.56573181078361345, 0.55557023301960218, 0.54532498842204635, 0.53499761988709715, 0.52458968267846895, 0.51410274419322177, 0.50353838372571758, 0.49289819222978415, 0.48218377207912289, 0.47139673682599781, 0.46053871095824023, 0.44961132965460687, 0.43861623853852755, 0.42755509343028203, 0.41642956009763715, 0.40524131400498986, 0.39399204006104815, 0.38268343236508984, 0.37131719395183765, 0.35989503653498833, 0.34841868024943479, 0.33688985339222027, 0.3253102921622632, 0.31368174039889141, 0.30200594931922803, 0.29028467725446233, 0.27851968938505312, 0.26671275747489848, 0.25486565960451468, 0.24298017990326404, 0.2310581082806713, 0.21910124015687002, 0.20711137619221884, 0.19509032201612858, 0.1830398879551409, 0.17096188876030119, 0.15885814333386145, 0.1467304744553618, 0.13458070850712628, 0.12241067519921635, 0.11022220729388325, 0.09801714032956084, 0.085797312344440158, 0.073564563599667745, 0.061320736302208495, 0.049067674327417973, 0.036807222941358832, 0.024541228522912326, 0.012271538285720007, 1.2246467991473532e-16, -0.012271538285719761, -0.024541228522912083, -0.036807222941358582, -0.049067674327417724, -0.061320736302208245, -0.073564563599667496, -0.085797312344439922, -0.09801714032956059, -0.110222207293883, -0.1224106751992161, -0.13458070850712606, -0.14673047445536158, -0.15885814333386122, -0.17096188876030097, -0.18303988795514067, -0.19509032201612836, -0.20711137619221862, -0.21910124015686983, -0.23105810828067111, -0.24298017990326382, -0.25486565960451446, -0.26671275747489825, -0.27851968938505289, -0.29028467725446216, -0.30200594931922781, -0.31368174039889118, -0.32531029216226304, -0.33688985339222011, -0.34841868024943456, -0.35989503653498811, -0.37131719395183749, -0.38268343236508967, -0.39399204006104793, -0.40524131400498969, -0.41642956009763693, -0.42755509343028181, -0.43861623853852733, -0.44961132965460665, -0.46053871095824006, -0.47139673682599764, -0.48218377207912272, -0.49289819222978393, -0.50353838372571746, -0.51410274419322155, -0.52458968267846873, -0.53499761988709693, -0.54532498842204613, -0.55557023301960196, -0.56573181078361323, -0.57580819141784534, -0.58579785745643886, -0.59569930449243325, -0.60551104140432543, -0.61523159058062671, -0.62485948814238623, -0.63439328416364527, -0.64383154288979128, -0.65317284295377653, -0.66241577759017178, -0.67155895484701844, -0.68060099779545302, -0.68954054473706683, -0.6983762494089728, -0.70710678118654746, -0.71573082528381848, -0.72424708295146667, -0.73265427167241259, -0.74095112535495877, -0.74913639452345904, -0.75720884650648423, -0.76516726562245885, -0.77301045336273666, -0.78073722857209438, -0.78834642762660589, -0.79583690460888334, -0.80320753148064505, -0.81045719825259466, -0.81758481315158371, -0.82458930278502507, -0.83146961230254524, -0.83822470555483775, -0.84485356524970712, -0.85135519310526486, -0.85772861000027201, -0.86397285612158647, -0.87008699110871135, -0.87607009419540671, -0.88192126434835494, -0.88763962040285405, -0.89322430119551521, -0.89867446569395382, -0.90398929312344312, -0.90916798309052238, -0.91420975570353047, -0.91911385169005766, -0.92387953251128652, -0.92850608047321548, -0.93299279883473896, -0.93733901191257485, -0.94154406518302081, -0.94560732538052117, -0.94952818059303667, -0.95330604035419375, -0.95694033573220882, -0.96043051941556568, -0.96377606579543984, -0.96697647104485218, -0.97003125319454397, -0.97293995220556018, -0.97570213003852846, -0.97831737071962765, -0.98078528040323032, -0.98310548743121629, -0.98527764238894111, -0.98730141815785832, -0.9891765099647809, -0.99090263542778001, -0.99247953459871008, -0.99390697000235606, -0.99518472667219693, -0.996312612182778, -0.99729045667869021, -0.99811811290014918, -0.99879545620517241, -0.99932238458834943, -0.99969881869620425, -0.9999247018391445, -1.0, -0.9999247018391445, -0.99969881869620425, -0.99932238458834954, -0.99879545620517241, -0.99811811290014918, -0.99729045667869021, -0.996312612182778, -0.99518472667219693, -0.99390697000235606, -0.99247953459871008, -0.99090263542778001, -0.9891765099647809, -0.98730141815785843, -0.98527764238894122, -0.9831054874312164, -0.98078528040323043, -0.97831737071962777, -0.97570213003852857, -0.97293995220556029, -0.97003125319454397, -0.96697647104485229, -0.96377606579543995, -0.96043051941556579, -0.95694033573220894, -0.95330604035419375, -0.94952818059303679, -0.94560732538052128, -0.94154406518302092, -0.93733901191257496, -0.93299279883473907, -0.92850608047321559, -0.92387953251128663, -0.91911385169005788, -0.91420975570353058, -0.90916798309052249, -0.90398929312344334, -0.89867446569395404, -0.89322430119551532, -0.88763962040285416, -0.88192126434835505, -0.87607009419540693, -0.87008699110871146, -0.8639728561215867, -0.85772861000027223, -0.85135519310526508, -0.84485356524970734, -0.83822470555483797, -0.83146961230254557, -0.82458930278502529, -0.81758481315158404, -0.81045719825259488, -0.80320753148064528, -0.79583690460888368, -0.78834642762660612, -0.78073722857209471, -0.77301045336273688, -0.76516726562245918, -0.75720884650648457, -0.7491363945234597, -0.74095112535495922, -0.73265427167241315, -0.72424708295146711, -0.71573082528381904, -0.70710678118654768, -0.69837624940897269, -0.68954054473706716, -0.68060099779545302, -0.67155895484701866, -0.66241577759017178, -0.65317284295377709, -0.6438315428897915, -0.63439328416364593, -0.62485948814238645, -0.61523159058062737, -0.60551104140432566, -0.59569930449243325, -0.58579785745643909, -0.57580819141784523, -0.56573181078361356, -0.55557023301960218, -0.5453249884220468, -0.53499761988709726, -0.52458968267846939, -0.51410274419322188, -0.50353838372571813, -0.49289819222978426, -0.48218377207912261, -0.47139673682599792, -0.46053871095823995, -0.44961132965460698, -0.43861623853852766, -0.42755509343028253, -0.41642956009763726, -0.40524131400499042, -0.39399204006104827, -0.38268343236509039, -0.37131719395183777, -0.359895036534988, -0.3484186802494349, -0.33688985339222, -0.32531029216226331, -0.31368174039889152, -0.30200594931922853, -0.29028467725446244, -0.27851968938505367, -0.26671275747489859, -0.25486565960451435, -0.24298017990326418, -0.23105810828067103, -0.21910124015687016, -0.20711137619221853, -0.19509032201612872, -0.18303988795514103, -0.17096188876030177, -0.15885814333386158, -0.14673047445536239, -0.13458070850712642, -0.12241067519921603, -0.11022220729388338, -0.09801714032956052, -0.085797312344440282, -0.073564563599667426, -0.06132073630220905, -0.049067674327418091, -0.036807222941359394, -0.024541228522912451, -0.012271538285720572, 0.0};
32 static MYFLT COSINE_ARRAY[513] = {1.0, 0.9999247018391445, 0.9996988186962042, 0.9993223845883495, 0.9987954562051724, 0.9981181129001492, 0.9972904566786902, 0.996312612182778, 0.9951847266721969, 0.9939069700023561, 0.99247953459871, 0.99090263542778, 0.989176509964781, 0.9873014181578584, 0.9852776423889412, 0.9831054874312163, 0.9807852804032304, 0.9783173707196277, 0.9757021300385286, 0.9729399522055602, 0.970031253194544, 0.9669764710448521, 0.9637760657954398, 0.9604305194155658, 0.9569403357322088, 0.9533060403541939, 0.9495281805930367, 0.9456073253805213, 0.9415440651830208, 0.937339011912575, 0.932992798834739, 0.9285060804732156, 0.9238795325112867, 0.9191138516900578, 0.9142097557035307, 0.9091679830905224, 0.9039892931234433, 0.8986744656939538, 0.8932243011955153, 0.8876396204028539, 0.881921264348355, 0.8760700941954066, 0.8700869911087115, 0.8639728561215868, 0.8577286100002721, 0.8513551931052652, 0.8448535652497071, 0.8382247055548381, 0.8314696123025452, 0.8245893027850253, 0.8175848131515837, 0.8104571982525948, 0.8032075314806449, 0.7958369046088836, 0.7883464276266063, 0.7807372285720945, 0.773010453362737, 0.765167265622459, 0.7572088465064846, 0.7491363945234594, 0.7409511253549591, 0.7326542716724128, 0.724247082951467, 0.7157308252838186, 0.7071067811865476, 0.6983762494089729, 0.6895405447370669, 0.6806009977954531, 0.6715589548470183, 0.6624157775901718, 0.6531728429537768, 0.6438315428897915, 0.6343932841636455, 0.6248594881423865, 0.6152315905806268, 0.6055110414043255, 0.5956993044924335, 0.5857978574564389, 0.5758081914178453, 0.5657318107836132, 0.5555702330196023, 0.5453249884220465, 0.5349976198870973, 0.5245896826784688, 0.5141027441932217, 0.5035383837257176, 0.4928981922297841, 0.48218377207912283, 0.4713967368259978, 0.46053871095824, 0.4496113296546066, 0.4386162385385277, 0.4275550934302822, 0.4164295600976373, 0.40524131400498986, 0.3939920400610481, 0.38268343236508984, 0.3713171939518376, 0.3598950365349883, 0.3484186802494345, 0.33688985339222005, 0.325310292162263, 0.3136817403988916, 0.3020059493192282, 0.29028467725446233, 0.27851968938505306, 0.2667127574748984, 0.2548656596045146, 0.24298017990326398, 0.23105810828067128, 0.21910124015686977, 0.20711137619221856, 0.19509032201612833, 0.18303988795514106, 0.17096188876030136, 0.1588581433338614, 0.14673047445536175, 0.13458070850712622, 0.12241067519921628, 0.11022220729388318, 0.09801714032956077, 0.08579731234443988, 0.07356456359966745, 0.06132073630220865, 0.049067674327418126, 0.03680722294135899, 0.024541228522912264, 0.012271538285719944, 6.123031769111886e-17, -0.012271538285719823, -0.024541228522912142, -0.036807222941358866, -0.04906767432741801, -0.06132073630220853, -0.07356456359966733, -0.08579731234443976, -0.09801714032956065, -0.11022220729388306, -0.12241067519921615, -0.1345807085071261, -0.14673047445536164, -0.15885814333386128, -0.17096188876030124, -0.18303988795514092, -0.1950903220161282, -0.20711137619221845, -0.21910124015686966, -0.23105810828067114, -0.24298017990326387, -0.2548656596045145, -0.2667127574748983, -0.27851968938505295, -0.29028467725446216, -0.3020059493192281, -0.3136817403988914, -0.32531029216226287, -0.33688985339221994, -0.3484186802494344, -0.35989503653498817, -0.3713171939518375, -0.3826834323650897, -0.393992040061048, -0.40524131400498975, -0.416429560097637, -0.42755509343028186, -0.4386162385385274, -0.4496113296546067, -0.46053871095824006, -0.4713967368259977, -0.4821837720791227, -0.492898192229784, -0.5035383837257175, -0.5141027441932217, -0.5245896826784687, -0.534997619887097, -0.5453249884220462, -0.555570233019602, -0.5657318107836132, -0.5758081914178453, -0.5857978574564389, -0.5956993044924334, -0.6055110414043254, -0.6152315905806267, -0.6248594881423862, -0.6343932841636454, -0.6438315428897913, -0.6531728429537765, -0.6624157775901719, -0.6715589548470184, -0.680600997795453, -0.6895405447370669, -0.6983762494089728, -0.7071067811865475, -0.7157308252838186, -0.7242470829514668, -0.7326542716724127, -0.7409511253549589, -0.7491363945234591, -0.7572088465064846, -0.765167265622459, -0.773010453362737, -0.7807372285720945, -0.7883464276266062, -0.7958369046088835, -0.8032075314806448, -0.8104571982525947, -0.8175848131515836, -0.8245893027850251, -0.8314696123025453, -0.8382247055548381, -0.8448535652497071, -0.8513551931052652, -0.857728610000272, -0.8639728561215867, -0.8700869911087113, -0.8760700941954065, -0.8819212643483549, -0.8876396204028538, -0.8932243011955152, -0.8986744656939539, -0.9039892931234433, -0.9091679830905224, -0.9142097557035307, -0.9191138516900578, -0.9238795325112867, -0.9285060804732155, -0.9329927988347388, -0.9373390119125748, -0.9415440651830207, -0.9456073253805212, -0.9495281805930367, -0.9533060403541939, -0.9569403357322088, -0.9604305194155658,
33 -0.9637760657954398, -0.9669764710448521, -0.970031253194544, -0.9729399522055601, -0.9757021300385285, -0.9783173707196275, -0.9807852804032304, -0.9831054874312163, -0.9852776423889412, -0.9873014181578584, -0.989176509964781, -0.99090263542778, -0.99247953459871, -0.9939069700023561, -0.9951847266721968, -0.996312612182778, -0.9972904566786902, -0.9981181129001492, -0.9987954562051724, -0.9993223845883495, -0.9996988186962042, -0.9999247018391445, -1.0, -0.9999247018391445, -0.9996988186962042, -0.9993223845883495, -0.9987954562051724, -0.9981181129001492, -0.9972904566786902, -0.996312612182778, -0.9951847266721969, -0.9939069700023561, -0.99247953459871, -0.99090263542778, -0.989176509964781, -0.9873014181578584, -0.9852776423889413, -0.9831054874312164, -0.9807852804032304, -0.9783173707196277, -0.9757021300385286, -0.9729399522055602, -0.970031253194544, -0.9669764710448522, -0.96377606579544, -0.9604305194155659, -0.9569403357322089, -0.953306040354194, -0.9495281805930368, -0.9456073253805213, -0.9415440651830208, -0.937339011912575, -0.932992798834739, -0.9285060804732156, -0.9238795325112868, -0.9191138516900578, -0.9142097557035307, -0.9091679830905225, -0.9039892931234434, -0.898674465693954, -0.8932243011955153, -0.8876396204028539, -0.881921264348355, -0.8760700941954066, -0.8700869911087115, -0.8639728561215868, -0.8577286100002721, -0.8513551931052653, -0.8448535652497072, -0.8382247055548382, -0.8314696123025455, -0.8245893027850253, -0.8175848131515837, -0.8104571982525948, -0.8032075314806449, -0.7958369046088836, -0.7883464276266063, -0.7807372285720946, -0.7730104533627371, -0.7651672656224591, -0.7572088465064848, -0.7491363945234593, -0.7409511253549591, -0.7326542716724128, -0.724247082951467, -0.7157308252838187, -0.7071067811865477, -0.698376249408973, -0.689540544737067, -0.6806009977954532, -0.6715589548470187, -0.662415777590172, -0.6531728429537771, -0.6438315428897915, -0.6343932841636459, -0.6248594881423865, -0.6152315905806273, -0.6055110414043257, -0.5956993044924331, -0.5857978574564391, -0.5758081914178452, -0.5657318107836135, -0.5555702330196022, -0.5453249884220468, -0.5349976198870973, -0.5245896826784694, -0.5141027441932218, -0.503538383725718, -0.4928981922297842, -0.48218377207912255, -0.47139673682599786, -0.4605387109582399, -0.44961132965460693, -0.4386162385385276, -0.4275550934302825, -0.4164295600976372, -0.40524131400499036, -0.3939920400610482, -0.38268343236509034, -0.37131719395183777, -0.35989503653498794, -0.34841868024943484, -0.33688985339221994, -0.3253102921622633, -0.31368174039889146, -0.30200594931922853, -0.29028467725446244, -0.2785196893850536, -0.26671275747489853, -0.25486565960451435, -0.24298017990326412, -0.23105810828067094, -0.2191012401568701, -0.20711137619221848, -0.19509032201612866, -0.18303988795514095, -0.1709618887603017, -0.15885814333386153, -0.1467304744553623, -0.13458070850712636, -0.12241067519921596, -0.11022220729388331, -0.09801714032956045, -0.08579731234444023, -0.07356456359966736, -0.061320736302208995, -0.04906767432741803, -0.03680722294135933, -0.02454122852291239, -0.012271538285720512, -1.836909530733566e-16, 0.012271538285720144, 0.02454122852291202, 0.036807222941358964, 0.04906767432741766, 0.06132073630220863, 0.07356456359966698, 0.08579731234443985, 0.09801714032956009, 0.11022220729388293, 0.1224106751992156, 0.13458070850712597, 0.14673047445536194, 0.15885814333386117, 0.17096188876030133, 0.1830398879551406, 0.1950903220161283, 0.20711137619221812, 0.21910124015686974, 0.23105810828067058, 0.24298017990326376, 0.25486565960451396, 0.2667127574748982, 0.2785196893850533, 0.29028467725446205, 0.30200594931922814, 0.31368174039889113, 0.3253102921622629, 0.3368898533922196, 0.3484186802494345, 0.3598950365349876, 0.3713171939518374, 0.38268343236509, 0.3939920400610479, 0.40524131400499, 0.4164295600976369, 0.42755509343028214, 0.43861623853852727, 0.4496113296546066, 0.46053871095823956, 0.4713967368259976, 0.4821837720791222, 0.49289819222978387, 0.5035383837257178, 0.5141027441932216, 0.5245896826784691, 0.5349976198870969, 0.5453249884220465, 0.5555702330196018, 0.5657318107836131, 0.5758081914178449, 0.5857978574564388, 0.5956993044924329, 0.6055110414043253, 0.615231590580627, 0.6248594881423861, 0.6343932841636456, 0.6438315428897912, 0.6531728429537768, 0.6624157775901715, 0.6715589548470183, 0.6806009977954527, 0.6895405447370668, 0.6983762494089724, 0.7071067811865474, 0.7157308252838188, 0.7242470829514667, 0.7326542716724129, 0.7409511253549589, 0.7491363945234594, 0.7572088465064842, 0.7651672656224588, 0.7730104533627367, 0.7807372285720944, 0.7883464276266059, 0.7958369046088833, 0.803207531480645, 0.8104571982525947, 0.8175848131515837, 0.8245893027850251, 0.8314696123025452, 0.8382247055548377,
34 0.844853565249707, 0.8513551931052649, 0.857728610000272, 0.8639728561215864, 0.8700869911087113, 0.8760700941954067, 0.8819212643483548, 0.8876396204028539, 0.8932243011955151, 0.8986744656939538, 0.9039892931234431, 0.9091679830905224, 0.9142097557035305, 0.9191138516900577, 0.9238795325112865, 0.9285060804732155, 0.932992798834739, 0.9373390119125748, 0.9415440651830208, 0.9456073253805212, 0.9495281805930367, 0.9533060403541936, 0.9569403357322088, 0.9604305194155657, 0.9637760657954398, 0.9669764710448522, 0.970031253194544, 0.9729399522055602, 0.9757021300385285, 0.9783173707196277, 0.9807852804032303, 0.9831054874312163, 0.9852776423889411, 0.9873014181578583, 0.9891765099647809, 0.99090263542778, 0.99247953459871, 0.9939069700023561, 0.9951847266721969, 0.996312612182778, 0.9972904566786902, 0.9981181129001492, 0.9987954562051724, 0.9993223845883494, 0.9996988186962042, 0.9999247018391445, 1.0
35 };
36 static MYFLT ONE_OVER_512 = 1.0 / 512.0;
37 static const MYFLT ROSSLER_SCALE = 0.054;
38 static const MYFLT ROSSLER_ALT_SCALE = 0.0569;
39 static const MYFLT LORENZ_SCALE = 0.044;
40 static const MYFLT LORENZ_ALT_SCALE = 0.0328;
41 static const MYFLT CHENLEE_SCALE = 0.02;
42 static const MYFLT CHENLEE_ALT_SCALE = 0.02;
43
44 static MYFLT
45 _clip(MYFLT x)
46 {
47 if (x < 0.0)
48 return 0.0;
49 else if (x >= 1.0)
50 return 1.0;
51 else
52 return x;
53 }
54
55 static MYFLT
56 Sine_clip(MYFLT x)
57 {
58 if (x < 0)
59 {
60 x += ((int)(-x * ONE_OVER_512) + 1) * 512;
61 }
62 else if (x >= 512)
63 {
64 x -= (int)(x * ONE_OVER_512) * 512;
65 }
66
67 return x;
68 }
69
70 /* Sine object */
71 typedef struct
72 {
73 pyo_audio_HEAD
74 PyObject *freq;
75 Stream *freq_stream;
76 PyObject *phase;
77 Stream *phase_stream;
78 int modebuffer[4];
79 MYFLT pointerPos;
80 } Sine;
81
82 static void
83 Sine_readframes_ii(Sine *self)
84 {
85 MYFLT inc, fr, ph, pos;
86 int i, ipart;
87
88 fr = PyFloat_AS_DOUBLE(self->freq);
89 ph = PyFloat_AS_DOUBLE(self->phase) * 512;
90 inc = fr * 512 / self->sr;
91
92 for (i = 0; i < self->bufsize; i++)
93 {
94 self->pointerPos = Sine_clip(self->pointerPos);
95 pos = self->pointerPos + ph;
96
97 if (pos >= 512)
98 pos -= 512;
99
100 ipart = (int)pos;
101 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
102 self->pointerPos += inc;
103 }
104 }
105
106 static void
107 Sine_readframes_ai(Sine *self)
108 {
109 MYFLT inc, ph, pos, fac;
110 int i, ipart;
111
112 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
113 ph = PyFloat_AS_DOUBLE(self->phase) * 512;
114
115 fac = 512 / self->sr;
116
117 for (i = 0; i < self->bufsize; i++)
118 {
119 inc = fr[i] * fac;
120 self->pointerPos = Sine_clip(self->pointerPos);
121 pos = self->pointerPos + ph;
122
123 if (pos >= 512)
124 pos -= 512;
125
126 ipart = (int)pos;
127 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
128 self->pointerPos += inc;
129 }
130 }
131
132 static void
133 Sine_readframes_ia(Sine *self)
134 {
135 MYFLT inc, fr, pos;
136 int i, ipart;
137
138 fr = PyFloat_AS_DOUBLE(self->freq);
139 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
140 inc = fr * 512 / self->sr;
141
142 for (i = 0; i < self->bufsize; i++)
143 {
144 self->pointerPos = Sine_clip(self->pointerPos);
145 pos = self->pointerPos + ph[i] * 512;
146
147 if (pos >= 512)
148 pos -= 512;
149
150 ipart = (int)pos;
151 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
152 self->pointerPos += inc;
153 }
154 }
155
156 static void
157 Sine_readframes_aa(Sine *self)
158 {
159 MYFLT inc, pos, fac;
160 int i, ipart;
161
162 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
163 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
164
165 fac = 512 / self->sr;
166
167 for (i = 0; i < self->bufsize; i++)
168 {
169 inc = fr[i] * fac;
170 self->pointerPos = Sine_clip(self->pointerPos);
171 pos = self->pointerPos + ph[i] * 512;
172
173 if (pos >= 512)
174 pos -= 512;
175
176 ipart = (int)pos;
177 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
178 self->pointerPos += inc;
179 }
180 }
181
182 static void Sine_postprocessing_ii(Sine *self) { POST_PROCESSING_II };
183 static void Sine_postprocessing_ai(Sine *self) { POST_PROCESSING_AI };
184 static void Sine_postprocessing_ia(Sine *self) { POST_PROCESSING_IA };
185 static void Sine_postprocessing_aa(Sine *self) { POST_PROCESSING_AA };
186 static void Sine_postprocessing_ireva(Sine *self) { POST_PROCESSING_IREVA };
187 static void Sine_postprocessing_areva(Sine *self) { POST_PROCESSING_AREVA };
188 static void Sine_postprocessing_revai(Sine *self) { POST_PROCESSING_REVAI };
189 static void Sine_postprocessing_revaa(Sine *self) { POST_PROCESSING_REVAA };
190 static void Sine_postprocessing_revareva(Sine *self) { POST_PROCESSING_REVAREVA };
191
192 static void
193 Sine_setProcMode(Sine *self)
194 {
195 int procmode, muladdmode;
196 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
197 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
198
199 switch (procmode)
200 {
201 case 0:
202 self->proc_func_ptr = Sine_readframes_ii;
203 break;
204
205 case 1:
206 self->proc_func_ptr = Sine_readframes_ai;
207 break;
208
209 case 10:
210 self->proc_func_ptr = Sine_readframes_ia;
211 break;
212
213 case 11:
214 self->proc_func_ptr = Sine_readframes_aa;
215 break;
216 }
217
218 switch (muladdmode)
219 {
220 case 0:
221 self->muladd_func_ptr = Sine_postprocessing_ii;
222 break;
223
224 case 1:
225 self->muladd_func_ptr = Sine_postprocessing_ai;
226 break;
227
228 case 2:
229 self->muladd_func_ptr = Sine_postprocessing_revai;
230 break;
231
232 case 10:
233 self->muladd_func_ptr = Sine_postprocessing_ia;
234 break;
235
236 case 11:
237 self->muladd_func_ptr = Sine_postprocessing_aa;
238 break;
239
240 case 12:
241 self->muladd_func_ptr = Sine_postprocessing_revaa;
242 break;
243
244 case 20:
245 self->muladd_func_ptr = Sine_postprocessing_ireva;
246 break;
247
248 case 21:
249 self->muladd_func_ptr = Sine_postprocessing_areva;
250 break;
251
252 case 22:
253 self->muladd_func_ptr = Sine_postprocessing_revareva;
254 break;
255 }
256 }
257
258 static void
259 Sine_compute_next_data_frame(Sine *self)
260 {
261 (*self->proc_func_ptr)(self);
262 (*self->muladd_func_ptr)(self);
263 }
264
265 static int
266 Sine_traverse(Sine *self, visitproc visit, void *arg)
267 {
268 pyo_VISIT
269 Py_VISIT(self->freq);
270 Py_VISIT(self->phase);
271 return 0;
272 }
273
274 static int
275 Sine_clear(Sine *self)
276 {
277 pyo_CLEAR
278 Py_CLEAR(self->freq);
279 Py_CLEAR(self->phase);
280 return 0;
281 }
282
283 static void
284 Sine_dealloc(Sine* self)
285 {
286 pyo_DEALLOC
287 Sine_clear(self);
288 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
289 Py_TYPE(self)->tp_free((PyObject*)self);
290 }
291
292 static PyObject *
293 Sine_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
294 {
295 int i;
296 PyObject *freqtmp = NULL, *phasetmp = NULL, *multmp = NULL, *addtmp = NULL;
297
298 Sine *self;
299 self = (Sine *)type->tp_alloc(type, 0);
300
301 self->freq = PyFloat_FromDouble(1000);
302 self->phase = PyFloat_FromDouble(0.0);
303 self->modebuffer[0] = 0;
304 self->modebuffer[1] = 0;
305 self->modebuffer[2] = 0;
306 self->modebuffer[3] = 0;
307 self->pointerPos = 0.;
308
309 INIT_OBJECT_COMMON
310 Stream_setFunctionPtr(self->stream, Sine_compute_next_data_frame);
311 self->mode_func_ptr = Sine_setProcMode;
312
313 static char *kwlist[] = {"freq", "phase", "mul", "add", NULL};
314
315 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &freqtmp, &phasetmp, &multmp, &addtmp))
316 Py_RETURN_NONE;
317
318 if (freqtmp)
319 {
320 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
321 }
322
323 if (phasetmp)
324 {
325 PyObject_CallMethod((PyObject *)self, "setPhase", "O", phasetmp);
326 }
327
328 if (multmp)
329 {
330 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
331 }
332
333 if (addtmp)
334 {
335 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
336 }
337
338 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
339
340 (*self->mode_func_ptr)(self);
341
342 return (PyObject *)self;
343 }
344
345 static PyObject * Sine_getServer(Sine* self) { GET_SERVER };
346 static PyObject * Sine_getStream(Sine* self) { GET_STREAM };
347 static PyObject * Sine_setMul(Sine *self, PyObject *arg) { SET_MUL };
348 static PyObject * Sine_setAdd(Sine *self, PyObject *arg) { SET_ADD };
349 static PyObject * Sine_setSub(Sine *self, PyObject *arg) { SET_SUB };
350 static PyObject * Sine_setDiv(Sine *self, PyObject *arg) { SET_DIV };
351
352 static PyObject * Sine_play(Sine *self, PyObject *args, PyObject *kwds) { PLAY };
353 static PyObject * Sine_out(Sine *self, PyObject *args, PyObject *kwds) { OUT };
354 static PyObject * Sine_stop(Sine *self, PyObject *args, PyObject *kwds) { STOP };
355
356 static PyObject * Sine_multiply(Sine *self, PyObject *arg) { MULTIPLY };
357 static PyObject * Sine_inplace_multiply(Sine *self, PyObject *arg) { INPLACE_MULTIPLY };
358 static PyObject * Sine_add(Sine *self, PyObject *arg) { ADD };
359 static PyObject * Sine_inplace_add(Sine *self, PyObject *arg) { INPLACE_ADD };
360 static PyObject * Sine_sub(Sine *self, PyObject *arg) { SUB };
361 static PyObject * Sine_inplace_sub(Sine *self, PyObject *arg) { INPLACE_SUB };
362 static PyObject * Sine_div(Sine *self, PyObject *arg) { DIV };
363 static PyObject * Sine_inplace_div(Sine *self, PyObject *arg) { INPLACE_DIV };
364
365 static PyObject * Sine_setFreq(Sine *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2) }
366 static PyObject * Sine_setPhase(Sine *self, PyObject *arg) { SET_PARAM(self->phase, self->phase_stream, 3) }
367
368 static PyObject *
369 Sine_reset(Sine *self)
370 {
371 self->pointerPos = 0.0;
372 Py_RETURN_NONE;
373 }
374
375 static PyMemberDef Sine_members[] =
376 {
377 {"server", T_OBJECT_EX, offsetof(Sine, server), 0, "Pyo server."},
378 {"stream", T_OBJECT_EX, offsetof(Sine, stream), 0, "Stream object."},
379 {"freq", T_OBJECT_EX, offsetof(Sine, freq), 0, "Frequency in cycle per second."},
380 {"phase", T_OBJECT_EX, offsetof(Sine, phase), 0, "Phase of signal (0 -> 1)"},
381 {"mul", T_OBJECT_EX, offsetof(Sine, mul), 0, "Mul factor."},
382 {"add", T_OBJECT_EX, offsetof(Sine, add), 0, "Add factor."},
383 {NULL} /* Sentinel */
384 };
385
386 static PyMethodDef Sine_methods[] =
387 {
388 {"getServer", (PyCFunction)Sine_getServer, METH_NOARGS, "Returns server object."},
389 {"_getStream", (PyCFunction)Sine_getStream, METH_NOARGS, "Returns stream object."},
390 {"play", (PyCFunction)Sine_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
391 {"out", (PyCFunction)Sine_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
392 {"stop", (PyCFunction)Sine_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
393 {"setFreq", (PyCFunction)Sine_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
394 {"setPhase", (PyCFunction)Sine_setPhase, METH_O, "Sets oscillator phase between 0 and 1."},
395 {"reset", (PyCFunction)Sine_reset, METH_NOARGS, "Resets pointer position to 0."},
396 {"setMul", (PyCFunction)Sine_setMul, METH_O, "Sets Sine mul factor."},
397 {"setAdd", (PyCFunction)Sine_setAdd, METH_O, "Sets Sine add factor."},
398 {"setSub", (PyCFunction)Sine_setSub, METH_O, "Sets inverse add factor."},
399 {"setDiv", (PyCFunction)Sine_setDiv, METH_O, "Sets inverse mul factor."},
400 {NULL} /* Sentinel */
401 };
402
403 static PyNumberMethods Sine_as_number =
404 {
405 (binaryfunc)Sine_add, /*nb_add*/
406 (binaryfunc)Sine_sub, /*nb_subtract*/
407 (binaryfunc)Sine_multiply, /*nb_multiply*/
408 0, /*nb_remainder*/
409 0, /*nb_divmod*/
410 0, /*nb_power*/
411 0, /*nb_neg*/
412 0, /*nb_pos*/
413 0, /*(unaryfunc)array_abs*/
414 0, /*nb_nonzero*/
415 0, /*nb_invert*/
416 0, /*nb_lshift*/
417 0, /*nb_rshift*/
418 0, /*nb_and*/
419 0, /*nb_xor*/
420 0, /*nb_or*/
421 0, /*nb_int*/
422 0, /*nb_long*/
423 0, /*nb_float*/
424 (binaryfunc)Sine_inplace_add, /*inplace_add*/
425 (binaryfunc)Sine_inplace_sub, /*inplace_subtract*/
426 (binaryfunc)Sine_inplace_multiply, /*inplace_multiply*/
427 0, /*inplace_remainder*/
428 0, /*inplace_power*/
429 0, /*inplace_lshift*/
430 0, /*inplace_rshift*/
431 0, /*inplace_and*/
432 0, /*inplace_xor*/
433 0, /*inplace_or*/
434 0, /*nb_floor_divide*/
435 (binaryfunc)Sine_div, /*nb_true_divide*/
436 0, /*nb_inplace_floor_divide*/
437 (binaryfunc)Sine_inplace_div, /*nb_inplace_true_divide*/
438 0, /* nb_index */
439 };
440
441 PyTypeObject SineType =
442 {
443 PyVarObject_HEAD_INIT(NULL, 0)
444 "_pyo.Sine_base", /*tp_name*/
445 sizeof(Sine), /*tp_basicsize*/
446 0, /*tp_itemsize*/
447 (destructor)Sine_dealloc, /*tp_dealloc*/
448 0, /*tp_print*/
449 0, /*tp_getattr*/
450 0, /*tp_setattr*/
451 0, /*tp_as_async (tp_compare in Python 2)*/
452 0, /*tp_repr*/
453 &Sine_as_number, /*tp_as_number*/
454 0, /*tp_as_sequence*/
455 0, /*tp_as_mapping*/
456 0, /*tp_hash */
457 0, /*tp_call*/
458 0, /*tp_str*/
459 0, /*tp_getattro*/
460 0, /*tp_setattro*/
461 0, /*tp_as_buffer*/
462 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
463 "Sine objects. Generates a sinewave.", /* tp_doc */
464 (traverseproc)Sine_traverse, /* tp_traverse */
465 (inquiry)Sine_clear, /* tp_clear */
466 0, /* tp_richcompare */
467 0, /* tp_weaklistoffset */
468 0, /* tp_iter */
469 0, /* tp_iternext */
470 Sine_methods, /* tp_methods */
471 Sine_members, /* tp_members */
472 0, /* tp_getset */
473 0, /* tp_base */
474 0, /* tp_dict */
475 0, /* tp_descr_get */
476 0, /* tp_descr_set */
477 0, /* tp_dictoffset */
478 0, /* tp_init */
479 0, /* tp_alloc */
480 Sine_new, /* tp_new */
481 };
482
483
484 /* FastSine object */
485 typedef struct
486 {
487 pyo_audio_HEAD
488 PyObject *freq;
489 Stream *freq_stream;
490 int modebuffer[3];
491 MYFLT initphase;
492 int quality;
493 MYFLT pointerPos;
494 MYFLT twoPiOnSr;
495 MYFLT B;
496 MYFLT C;
497 } FastSine;
498
499 static void
500 FastSine_readframes_low_i(FastSine *self)
501 {
502 int i;
503 MYFLT inc, fr, pos, b, c;
504
505 fr = PyFloat_AS_DOUBLE(self->freq);
506 inc = fr * self->twoPiOnSr;
507
508 pos = self->pointerPos;
509 b = self->B;
510 c = self->C;
511
512 for (i = 0; i < self->bufsize; i++)
513 {
514 if (pos > PI)
515 pos -= TWOPI;
516
517 self->data[i] = b * pos + c * pos * MYFABS(pos);
518 pos += inc;
519 }
520
521 self->pointerPos = pos;
522 }
523
524 static void
525 FastSine_readframes_low_a(FastSine *self)
526 {
527 int i;
528 MYFLT pos, b, c;
529
530 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
531
532 pos = self->pointerPos;
533 b = self->B;
534 c = self->C;
535
536 for (i = 0; i < self->bufsize; i++)
537 {
538 if (pos > PI)
539 pos -= TWOPI;
540
541 self->data[i] = b * pos + c * pos * MYFABS(pos);
542 pos += fr[i] * self->twoPiOnSr;
543 }
544
545 self->pointerPos = pos;
546 }
547
548 static void
549 FastSine_readframes_high_i(FastSine *self)
550 {
551 int i;
552 MYFLT inc, fr, pos, b, c, y;
553
554 fr = PyFloat_AS_DOUBLE(self->freq);
555 inc = fr * self->twoPiOnSr;
556
557 pos = self->pointerPos;
558 b = self->B;
559 c = self->C;
560
561 for (i = 0; i < self->bufsize; i++)
562 {
563 if (pos > PI)
564 pos -= TWOPI;
565
566 y = b * pos + c * pos * MYFABS(pos);
567 self->data[i] = y + (y * MYFABS(y) - y) * 0.218;
568 pos += inc;
569 }
570
571 self->pointerPos = pos;
572 }
573
574 static void
575 FastSine_readframes_high_a(FastSine *self)
576 {
577 int i;
578 MYFLT pos, b, c, y;
579
580 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
581
582 pos = self->pointerPos;
583 b = self->B;
584 c = self->C;
585
586 for (i = 0; i < self->bufsize; i++)
587 {
588 if (pos > PI)
589 pos -= TWOPI;
590
591 y = b * pos + c * pos * MYFABS(pos);
592 self->data[i] = y + (y * MYFABS(y) - y) * 0.218;
593 pos += fr[i] * self->twoPiOnSr;
594 }
595
596 self->pointerPos = pos;
597 }
598
599 /*
600 static void
601 FastSine_readframes_low_i(FastSine *self) {
602 MYFLT inc, fr, pos;
603 int i;
604
605 fr = PyFloat_AS_DOUBLE(self->freq);
606 inc = fr * self->fourOnSr;
607
608 pos = self->pointerPos;
609 for (i=0; i<self->bufsize; i++) {
610 if (pos > 2.0)
611 pos -= 4.0;
612
613 if (pos < 0) {
614 self->data[i] = pos * (pos + 2.0);
615 }
616 else {
617 self->data[i] = pos * (2.0 - pos);
618 }
619 pos += inc;
620 }
621 self->pointerPos = pos;
622 }
623
624 static void
625 FastSine_readframes_low_a(FastSine *self) {
626 MYFLT inc, pos;
627 int i;
628
629 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
630
631 pos = self->pointerPos;
632 for (i=0; i<self->bufsize; i++) {
633 inc = fr[i] * self->fourOnSr;
634 if (pos > 2.0)
635 pos -= 4.0;
636
637 if (pos < 0) {
638 self->data[i] = pos * (pos + 2.0);
639 }
640 else {
641 self->data[i] = pos * (2.0 - pos);
642 }
643 pos += inc;
644 }
645 self->pointerPos = pos;
646 }
647
648 static void
649 FastSine_readframes_high_i(FastSine *self) {
650 MYFLT inc, fr, pos, sine;
651 int i;
652
653 fr = PyFloat_AS_DOUBLE(self->freq);
654 inc = fr * self->fourOnSr;
655
656 pos = self->pointerPos;
657 for (i=0; i<self->bufsize; i++) {
658 if (pos > 2.0)
659 pos -= 4.0;
660
661 if (pos < 0) {
662 sine = -pos * (pos + 2.0);
663 self->data[i] = -sine * (0.225 * (sine - 1) + 1);
664 }
665 else {
666 sine = pos * (2.0 - pos);
667 self->data[i] = sine * (0.225 * (sine - 1) + 1);
668 }
669 pos += inc;
670 }
671 self->pointerPos = pos;
672 }
673
674 static void
675 FastSine_readframes_high_a(FastSine *self) {
676 MYFLT inc, pos, sine;
677 int i;
678
679 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
680
681 pos = self->pointerPos;
682 for (i=0; i<self->bufsize; i++) {
683 inc = fr[i] * self->fourOnSr;
684 if (pos > 2.0)
685 pos -= 4.0;
686
687 if (pos < 0) {
688 sine = -pos * (pos + 2.0);
689 self->data[i] = -sine * (0.225 * (sine - 1) + 1);
690 }
691 else {
692 sine = pos * (2.0 - pos);
693 self->data[i] = sine * (0.225 * (sine - 1) + 1);
694 }
695 pos += inc;
696 }
697 self->pointerPos = pos;
698 }
699 */
700
701 static void FastSine_postprocessing_ii(FastSine *self) { POST_PROCESSING_II };
702 static void FastSine_postprocessing_ai(FastSine *self) { POST_PROCESSING_AI };
703 static void FastSine_postprocessing_ia(FastSine *self) { POST_PROCESSING_IA };
704 static void FastSine_postprocessing_aa(FastSine *self) { POST_PROCESSING_AA };
705 static void FastSine_postprocessing_ireva(FastSine *self) { POST_PROCESSING_IREVA };
706 static void FastSine_postprocessing_areva(FastSine *self) { POST_PROCESSING_AREVA };
707 static void FastSine_postprocessing_revai(FastSine *self) { POST_PROCESSING_REVAI };
708 static void FastSine_postprocessing_revaa(FastSine *self) { POST_PROCESSING_REVAA };
709 static void FastSine_postprocessing_revareva(FastSine *self) { POST_PROCESSING_REVAREVA };
710
711 static void
712 FastSine_setProcMode(FastSine *self)
713 {
714 int procmode, muladdmode;
715 procmode = self->modebuffer[2];
716 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
717
718 switch (procmode)
719 {
720 case 0:
721 if (self->quality == 0)
722 self->proc_func_ptr = FastSine_readframes_low_i;
723 else if (self->quality == 1)
724 self->proc_func_ptr = FastSine_readframes_high_i;
725
726 break;
727
728 case 1:
729 if (self->quality == 0)
730 self->proc_func_ptr = FastSine_readframes_low_a;
731 else if (self->quality == 1)
732 self->proc_func_ptr = FastSine_readframes_high_a;
733
734 break;
735 }
736
737 switch (muladdmode)
738 {
739 case 0:
740 self->muladd_func_ptr = FastSine_postprocessing_ii;
741 break;
742
743 case 1:
744 self->muladd_func_ptr = FastSine_postprocessing_ai;
745 break;
746
747 case 2:
748 self->muladd_func_ptr = FastSine_postprocessing_revai;
749 break;
750
751 case 10:
752 self->muladd_func_ptr = FastSine_postprocessing_ia;
753 break;
754
755 case 11:
756 self->muladd_func_ptr = FastSine_postprocessing_aa;
757 break;
758
759 case 12:
760 self->muladd_func_ptr = FastSine_postprocessing_revaa;
761 break;
762
763 case 20:
764 self->muladd_func_ptr = FastSine_postprocessing_ireva;
765 break;
766
767 case 21:
768 self->muladd_func_ptr = FastSine_postprocessing_areva;
769 break;
770
771 case 22:
772 self->muladd_func_ptr = FastSine_postprocessing_revareva;
773 break;
774 }
775 }
776
777 static void
778 FastSine_compute_next_data_frame(FastSine *self)
779 {
780 (*self->proc_func_ptr)(self);
781 (*self->muladd_func_ptr)(self);
782 }
783
784 static int
785 FastSine_traverse(FastSine *self, visitproc visit, void *arg)
786 {
787 pyo_VISIT
788 Py_VISIT(self->freq);
789 return 0;
790 }
791
792 static int
793 FastSine_clear(FastSine *self)
794 {
795 pyo_CLEAR
796 Py_CLEAR(self->freq);
797 return 0;
798 }
799
800 static void
801 FastSine_dealloc(FastSine* self)
802 {
803 pyo_DEALLOC
804 FastSine_clear(self);
805 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
806 Py_TYPE(self)->tp_free((PyObject*)self);
807 }
808
809 static PyObject *
810 FastSine_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
811 {
812 int i;
813 PyObject *freqtmp = NULL, *multmp = NULL, *addtmp = NULL;
814
815 FastSine *self;
816 self = (FastSine *)type->tp_alloc(type, 0);
817
818 self->freq = PyFloat_FromDouble(1000);
819 self->initphase = 0.0;
820 self->quality = 1;
821 self->modebuffer[0] = 0;
822 self->modebuffer[1] = 0;
823 self->modebuffer[2] = 0;
824
825 INIT_OBJECT_COMMON
826 Stream_setFunctionPtr(self->stream, FastSine_compute_next_data_frame);
827 self->mode_func_ptr = FastSine_setProcMode;
828
829 self->twoPiOnSr = TWOPI / self->sr;
830 self->B = 4.0 / PI;
831 self->C = -4.0 / (PI * PI);
832
833 static char *kwlist[] = {"freq", "initphase", "quality", "mul", "add", NULL};
834
835 if (! PyArg_ParseTupleAndKeywords(args, kwds, TYPE__OFIOO, kwlist, &freqtmp, &self->initphase, &self->quality, &multmp, &addtmp))
836 Py_RETURN_NONE;
837
838 if (self->initphase < 0.0)
839 self->initphase = 0.0;
840 else if (self->initphase > 1.0)
841 self->initphase = 1.0;
842
843 self->pointerPos = self->initphase * TWOPI;
844
845 if (self->quality < 0)
846 self->quality = 0;
847 else if (self->quality > 1)
848 self->quality = 1;
849
850 if (freqtmp)
851 {
852 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
853 }
854
855 if (multmp)
856 {
857 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
858 }
859
860 if (addtmp)
861 {
862 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
863 }
864
865 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
866
867
868 (*self->mode_func_ptr)(self);
869
870 return (PyObject *)self;
871 }
872
873 static PyObject * FastSine_getServer(FastSine* self) { GET_SERVER };
874 static PyObject * FastSine_getStream(FastSine* self) { GET_STREAM };
875 static PyObject * FastSine_setMul(FastSine *self, PyObject *arg) { SET_MUL };
876 static PyObject * FastSine_setAdd(FastSine *self, PyObject *arg) { SET_ADD };
877 static PyObject * FastSine_setSub(FastSine *self, PyObject *arg) { SET_SUB };
878 static PyObject * FastSine_setDiv(FastSine *self, PyObject *arg) { SET_DIV };
879
880 static PyObject * FastSine_play(FastSine *self, PyObject *args, PyObject *kwds) { PLAY };
881 static PyObject * FastSine_out(FastSine *self, PyObject *args, PyObject *kwds) { OUT };
882 static PyObject * FastSine_stop(FastSine *self, PyObject *args, PyObject *kwds) { STOP };
883
884 static PyObject * FastSine_multiply(FastSine *self, PyObject *arg) { MULTIPLY };
885 static PyObject * FastSine_inplace_multiply(FastSine *self, PyObject *arg) { INPLACE_MULTIPLY };
886 static PyObject * FastSine_add(FastSine *self, PyObject *arg) { ADD };
887 static PyObject * FastSine_inplace_add(FastSine *self, PyObject *arg) { INPLACE_ADD };
888 static PyObject * FastSine_sub(FastSine *self, PyObject *arg) { SUB };
889 static PyObject * FastSine_inplace_sub(FastSine *self, PyObject *arg) { INPLACE_SUB };
890 static PyObject * FastSine_div(FastSine *self, PyObject *arg) { DIV };
891 static PyObject * FastSine_inplace_div(FastSine *self, PyObject *arg) { INPLACE_DIV };
892
893 static PyObject * FastSine_setFreq(FastSine *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
894
895 static PyObject *
896 FastSine_setQuality(FastSine *self, PyObject *arg)
897 {
898 int tmp;
899 ASSERT_ARG_NOT_NULL
900
901 if (PyLong_Check(arg))
902 {
903 tmp = PyLong_AsLong(arg);
904
905 if (tmp >= 0 && tmp < 2)
906 self->quality = tmp;
907 }
908
909 (*self->mode_func_ptr)(self);
910
911 Py_RETURN_NONE;
912 }
913
914 static PyObject *
915 FastSine_reset(FastSine *self)
916 {
917 self->pointerPos = self->initphase * TWOPI;
918 Py_RETURN_NONE;
919 }
920
921 static PyMemberDef FastSine_members[] =
922 {
923 {"server", T_OBJECT_EX, offsetof(FastSine, server), 0, "Pyo server."},
924 {"stream", T_OBJECT_EX, offsetof(FastSine, stream), 0, "Stream object."},
925 {"freq", T_OBJECT_EX, offsetof(FastSine, freq), 0, "Frequency in cycle per second."},
926 {"mul", T_OBJECT_EX, offsetof(FastSine, mul), 0, "Mul factor."},
927 {"add", T_OBJECT_EX, offsetof(FastSine, add), 0, "Add factor."},
928 {NULL} /* Sentinel */
929 };
930
931 static PyMethodDef FastSine_methods[] =
932 {
933 {"getServer", (PyCFunction)FastSine_getServer, METH_NOARGS, "Returns server object."},
934 {"_getStream", (PyCFunction)FastSine_getStream, METH_NOARGS, "Returns stream object."},
935 {"play", (PyCFunction)FastSine_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
936 {"out", (PyCFunction)FastSine_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
937 {"stop", (PyCFunction)FastSine_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
938 {"setFreq", (PyCFunction)FastSine_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
939 {"setQuality", (PyCFunction)FastSine_setQuality, METH_O, "Sets approximation quality."},
940 {"reset", (PyCFunction)FastSine_reset, METH_NOARGS, "Resets pointer position to 0."},
941 {"setMul", (PyCFunction)FastSine_setMul, METH_O, "Sets FastSine mul factor."},
942 {"setAdd", (PyCFunction)FastSine_setAdd, METH_O, "Sets FastSine add factor."},
943 {"setSub", (PyCFunction)FastSine_setSub, METH_O, "Sets inverse add factor."},
944 {"setDiv", (PyCFunction)FastSine_setDiv, METH_O, "Sets inverse mul factor."},
945 {NULL} /* Sentinel */
946 };
947
948 static PyNumberMethods FastSine_as_number =
949 {
950 (binaryfunc)FastSine_add, /*nb_add*/
951 (binaryfunc)FastSine_sub, /*nb_subtract*/
952 (binaryfunc)FastSine_multiply, /*nb_multiply*/
953 0, /*nb_remainder*/
954 0, /*nb_divmod*/
955 0, /*nb_power*/
956 0, /*nb_neg*/
957 0, /*nb_pos*/
958 0, /*(unaryfunc)array_abs*/
959 0, /*nb_nonzero*/
960 0, /*nb_invert*/
961 0, /*nb_lshift*/
962 0, /*nb_rshift*/
963 0, /*nb_and*/
964 0, /*nb_xor*/
965 0, /*nb_or*/
966 0, /*nb_int*/
967 0, /*nb_long*/
968 0, /*nb_float*/
969 (binaryfunc)FastSine_inplace_add, /*inplace_add*/
970 (binaryfunc)FastSine_inplace_sub, /*inplace_subtract*/
971 (binaryfunc)FastSine_inplace_multiply, /*inplace_multiply*/
972 0, /*inplace_remainder*/
973 0, /*inplace_power*/
974 0, /*inplace_lshift*/
975 0, /*inplace_rshift*/
976 0, /*inplace_and*/
977 0, /*inplace_xor*/
978 0, /*inplace_or*/
979 0, /*nb_floor_divide*/
980 (binaryfunc)FastSine_div, /*nb_true_divide*/
981 0, /*nb_inplace_floor_divide*/
982 (binaryfunc)FastSine_inplace_div, /*nb_inplace_true_divide*/
983 0, /* nb_index */
984 };
985
986 PyTypeObject FastSineType =
987 {
988 PyVarObject_HEAD_INIT(NULL, 0)
989 "_pyo.FastSine_base", /*tp_name*/
990 sizeof(FastSine), /*tp_basicsize*/
991 0, /*tp_itemsize*/
992 (destructor)FastSine_dealloc, /*tp_dealloc*/
993 0, /*tp_print*/
994 0, /*tp_getattr*/
995 0, /*tp_setattr*/
996 0, /*tp_as_async (tp_compare in Python 2)*/
997 0, /*tp_repr*/
998 &FastSine_as_number, /*tp_as_number*/
999 0, /*tp_as_sequence*/
1000 0, /*tp_as_mapping*/
1001 0, /*tp_hash */
1002 0, /*tp_call*/
1003 0, /*tp_str*/
1004 0, /*tp_getattro*/
1005 0, /*tp_setattro*/
1006 0, /*tp_as_buffer*/
1007 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1008 "FastSine objects. Generates a sinewave.", /* tp_doc */
1009 (traverseproc)FastSine_traverse, /* tp_traverse */
1010 (inquiry)FastSine_clear, /* tp_clear */
1011 0, /* tp_richcompare */
1012 0, /* tp_weaklistoffset */
1013 0, /* tp_iter */
1014 0, /* tp_iternext */
1015 FastSine_methods, /* tp_methods */
1016 FastSine_members, /* tp_members */
1017 0, /* tp_getset */
1018 0, /* tp_base */
1019 0, /* tp_dict */
1020 0, /* tp_descr_get */
1021 0, /* tp_descr_set */
1022 0, /* tp_dictoffset */
1023 0, /* tp_init */
1024 0, /* tp_alloc */
1025 FastSine_new, /* tp_new */
1026 };
1027
1028 /*******************/
1029 /* SineLoop object */
1030 /*******************/
1031 typedef struct
1032 {
1033 pyo_audio_HEAD
1034 PyObject *freq;
1035 Stream *freq_stream;
1036 PyObject *feedback;
1037 Stream *feedback_stream;
1038 int modebuffer[4];
1039 MYFLT pointerPos;
1040 MYFLT lastValue;
1041 } SineLoop;
1042
1043 static void
1044 SineLoop_readframes_ii(SineLoop *self)
1045 {
1046 MYFLT inc, fr, feed, pos;
1047 int i, ipart;
1048
1049 fr = PyFloat_AS_DOUBLE(self->freq);
1050 feed = _clip(PyFloat_AS_DOUBLE(self->feedback)) * 512;
1051 inc = fr * 512 / self->sr;
1052
1053 for (i = 0; i < self->bufsize; i++)
1054 {
1055 self->pointerPos = Sine_clip(self->pointerPos);
1056 pos = Sine_clip(self->pointerPos + self->lastValue * feed);
1057 ipart = (int)pos;
1058 self->data[i] = self->lastValue = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
1059 self->pointerPos += inc;
1060 }
1061 }
1062
1063 static void
1064 SineLoop_readframes_ai(SineLoop *self)
1065 {
1066 MYFLT inc, feed, pos, fac;
1067 int i, ipart;
1068
1069 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
1070 feed = _clip(PyFloat_AS_DOUBLE(self->feedback)) * 512;
1071
1072 fac = 512 / self->sr;
1073
1074 for (i = 0; i < self->bufsize; i++)
1075 {
1076 inc = fr[i] * fac;
1077 self->pointerPos = Sine_clip(self->pointerPos);
1078 pos = Sine_clip(self->pointerPos + self->lastValue * feed);
1079 ipart = (int)pos;
1080 self->data[i] = self->lastValue = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
1081 self->pointerPos += inc;
1082 }
1083 }
1084
1085 static void
1086 SineLoop_readframes_ia(SineLoop *self)
1087 {
1088 MYFLT inc, fr, feed, pos;
1089 int i, ipart;
1090
1091 fr = PyFloat_AS_DOUBLE(self->freq);
1092 MYFLT *fd = Stream_getData((Stream *)self->feedback_stream);
1093 inc = fr * 512 / self->sr;
1094
1095 for (i = 0; i < self->bufsize; i++)
1096 {
1097 feed = _clip(fd[i]) * 512;
1098 self->pointerPos = Sine_clip(self->pointerPos);
1099 pos = Sine_clip(self->pointerPos + self->lastValue * feed);
1100 ipart = (int)pos;
1101 self->data[i] = self->lastValue = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
1102 self->pointerPos += inc;
1103 }
1104 }
1105
1106 static void
1107 SineLoop_readframes_aa(SineLoop *self)
1108 {
1109 MYFLT inc, feed, pos, fac;
1110 int i, ipart;
1111
1112 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
1113 MYFLT *fd = Stream_getData((Stream *)self->feedback_stream);
1114
1115 fac = 512 / self->sr;
1116
1117 for (i = 0; i < self->bufsize; i++)
1118 {
1119 inc = fr[i] * fac;
1120 feed = _clip(fd[i]) * 512;
1121 self->pointerPos = Sine_clip(self->pointerPos);
1122 pos = Sine_clip(self->pointerPos + self->lastValue * feed);
1123 ipart = (int)pos;
1124 self->data[i] = self->lastValue = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (pos - ipart);
1125 self->pointerPos += inc;
1126 }
1127 }
1128
1129 static void SineLoop_postprocessing_ii(SineLoop *self) { POST_PROCESSING_II };
1130 static void SineLoop_postprocessing_ai(SineLoop *self) { POST_PROCESSING_AI };
1131 static void SineLoop_postprocessing_ia(SineLoop *self) { POST_PROCESSING_IA };
1132 static void SineLoop_postprocessing_aa(SineLoop *self) { POST_PROCESSING_AA };
1133 static void SineLoop_postprocessing_ireva(SineLoop *self) { POST_PROCESSING_IREVA };
1134 static void SineLoop_postprocessing_areva(SineLoop *self) { POST_PROCESSING_AREVA };
1135 static void SineLoop_postprocessing_revai(SineLoop *self) { POST_PROCESSING_REVAI };
1136 static void SineLoop_postprocessing_revaa(SineLoop *self) { POST_PROCESSING_REVAA };
1137 static void SineLoop_postprocessing_revareva(SineLoop *self) { POST_PROCESSING_REVAREVA };
1138
1139 static void
1140 SineLoop_setProcMode(SineLoop *self)
1141 {
1142 int procmode, muladdmode;
1143 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
1144 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1145
1146 switch (procmode)
1147 {
1148 case 0:
1149 self->proc_func_ptr = SineLoop_readframes_ii;
1150 break;
1151
1152 case 1:
1153 self->proc_func_ptr = SineLoop_readframes_ai;
1154 break;
1155
1156 case 10:
1157 self->proc_func_ptr = SineLoop_readframes_ia;
1158 break;
1159
1160 case 11:
1161 self->proc_func_ptr = SineLoop_readframes_aa;
1162 break;
1163 }
1164
1165 switch (muladdmode)
1166 {
1167 case 0:
1168 self->muladd_func_ptr = SineLoop_postprocessing_ii;
1169 break;
1170
1171 case 1:
1172 self->muladd_func_ptr = SineLoop_postprocessing_ai;
1173 break;
1174
1175 case 2:
1176 self->muladd_func_ptr = SineLoop_postprocessing_revai;
1177 break;
1178
1179 case 10:
1180 self->muladd_func_ptr = SineLoop_postprocessing_ia;
1181 break;
1182
1183 case 11:
1184 self->muladd_func_ptr = SineLoop_postprocessing_aa;
1185 break;
1186
1187 case 12:
1188 self->muladd_func_ptr = SineLoop_postprocessing_revaa;
1189 break;
1190
1191 case 20:
1192 self->muladd_func_ptr = SineLoop_postprocessing_ireva;
1193 break;
1194
1195 case 21:
1196 self->muladd_func_ptr = SineLoop_postprocessing_areva;
1197 break;
1198
1199 case 22:
1200 self->muladd_func_ptr = SineLoop_postprocessing_revareva;
1201 break;
1202 }
1203 }
1204
1205 static void
1206 SineLoop_compute_next_data_frame(SineLoop *self)
1207 {
1208 (*self->proc_func_ptr)(self);
1209 (*self->muladd_func_ptr)(self);
1210 }
1211
1212 static int
1213 SineLoop_traverse(SineLoop *self, visitproc visit, void *arg)
1214 {
1215 pyo_VISIT
1216 Py_VISIT(self->freq);
1217 Py_VISIT(self->feedback);
1218 return 0;
1219 }
1220
1221 static int
1222 SineLoop_clear(SineLoop *self)
1223 {
1224 pyo_CLEAR
1225 Py_CLEAR(self->freq);
1226 Py_CLEAR(self->feedback);
1227 return 0;
1228 }
1229
1230 static void
1231 SineLoop_dealloc(SineLoop* self)
1232 {
1233 pyo_DEALLOC
1234 SineLoop_clear(self);
1235 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1236 Py_TYPE(self)->tp_free((PyObject*)self);
1237 }
1238
1239 static PyObject *
1240 SineLoop_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1241 {
1242 int i;
1243 PyObject *freqtmp = NULL, *feedbacktmp = NULL, *multmp = NULL, *addtmp = NULL;
1244 SineLoop *self;
1245 self = (SineLoop *)type->tp_alloc(type, 0);
1246
1247 self->freq = PyFloat_FromDouble(1000);
1248 self->feedback = PyFloat_FromDouble(0.0);
1249 self->modebuffer[0] = 0;
1250 self->modebuffer[1] = 0;
1251 self->modebuffer[2] = 0;
1252 self->modebuffer[3] = 0;
1253 self->pointerPos = self->lastValue = 0.;
1254
1255 INIT_OBJECT_COMMON
1256 Stream_setFunctionPtr(self->stream, SineLoop_compute_next_data_frame);
1257 self->mode_func_ptr = SineLoop_setProcMode;
1258
1259 static char *kwlist[] = {"freq", "feedback", "mul", "add", NULL};
1260
1261 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &freqtmp, &feedbacktmp, &multmp, &addtmp))
1262 Py_RETURN_NONE;
1263
1264 if (freqtmp)
1265 {
1266 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
1267 }
1268
1269 if (feedbacktmp)
1270 {
1271 PyObject_CallMethod((PyObject *)self, "setFeedback", "O", feedbacktmp);
1272 }
1273
1274 if (multmp)
1275 {
1276 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1277 }
1278
1279 if (addtmp)
1280 {
1281 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1282 }
1283
1284 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1285
1286 (*self->mode_func_ptr)(self);
1287
1288 return (PyObject *)self;
1289 }
1290
1291 static PyObject * SineLoop_getServer(SineLoop* self) { GET_SERVER };
1292 static PyObject * SineLoop_getStream(SineLoop* self) { GET_STREAM };
1293 static PyObject * SineLoop_setMul(SineLoop *self, PyObject *arg) { SET_MUL };
1294 static PyObject * SineLoop_setAdd(SineLoop *self, PyObject *arg) { SET_ADD };
1295 static PyObject * SineLoop_setSub(SineLoop *self, PyObject *arg) { SET_SUB };
1296 static PyObject * SineLoop_setDiv(SineLoop *self, PyObject *arg) { SET_DIV };
1297
1298 static PyObject * SineLoop_play(SineLoop *self, PyObject *args, PyObject *kwds) { PLAY };
1299 static PyObject * SineLoop_out(SineLoop *self, PyObject *args, PyObject *kwds) { OUT };
1300 static PyObject * SineLoop_stop(SineLoop *self, PyObject *args, PyObject *kwds) { STOP };
1301
1302 static PyObject * SineLoop_multiply(SineLoop *self, PyObject *arg) { MULTIPLY };
1303 static PyObject * SineLoop_inplace_multiply(SineLoop *self, PyObject *arg) { INPLACE_MULTIPLY };
1304 static PyObject * SineLoop_add(SineLoop *self, PyObject *arg) { ADD };
1305 static PyObject * SineLoop_inplace_add(SineLoop *self, PyObject *arg) { INPLACE_ADD };
1306 static PyObject * SineLoop_sub(SineLoop *self, PyObject *arg) { SUB };
1307 static PyObject * SineLoop_inplace_sub(SineLoop *self, PyObject *arg) { INPLACE_SUB };
1308 static PyObject * SineLoop_div(SineLoop *self, PyObject *arg) { DIV };
1309 static PyObject * SineLoop_inplace_div(SineLoop *self, PyObject *arg) { INPLACE_DIV };
1310
1311 static PyObject * SineLoop_setFreq(SineLoop *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
1312 static PyObject * SineLoop_setFeedback(SineLoop *self, PyObject *arg) { SET_PARAM(self->feedback, self->feedback_stream, 3); }
1313
1314 static PyMemberDef SineLoop_members[] =
1315 {
1316 {"server", T_OBJECT_EX, offsetof(SineLoop, server), 0, "Pyo server."},
1317 {"stream", T_OBJECT_EX, offsetof(SineLoop, stream), 0, "Stream object."},
1318 {"freq", T_OBJECT_EX, offsetof(SineLoop, freq), 0, "Frequency in cycle per second."},
1319 {"feedback", T_OBJECT_EX, offsetof(SineLoop, feedback), 0, "Phase of signal (0 -> 1)"},
1320 {"mul", T_OBJECT_EX, offsetof(SineLoop, mul), 0, "Mul factor."},
1321 {"add", T_OBJECT_EX, offsetof(SineLoop, add), 0, "Add factor."},
1322 {NULL} /* Sentinel */
1323 };
1324
1325 static PyMethodDef SineLoop_methods[] =
1326 {
1327 {"getServer", (PyCFunction)SineLoop_getServer, METH_NOARGS, "Returns server object."},
1328 {"_getStream", (PyCFunction)SineLoop_getStream, METH_NOARGS, "Returns stream object."},
1329 {"play", (PyCFunction)SineLoop_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1330 {"out", (PyCFunction)SineLoop_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1331 {"stop", (PyCFunction)SineLoop_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1332 {"setFreq", (PyCFunction)SineLoop_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
1333 {"setFeedback", (PyCFunction)SineLoop_setFeedback, METH_O, "Sets oscillator feedback between 0 and 1."},
1334 {"setMul", (PyCFunction)SineLoop_setMul, METH_O, "Sets SineLoop mul factor."},
1335 {"setAdd", (PyCFunction)SineLoop_setAdd, METH_O, "Sets SineLoop add factor."},
1336 {"setSub", (PyCFunction)SineLoop_setSub, METH_O, "Sets inverse add factor."},
1337 {"setDiv", (PyCFunction)SineLoop_setDiv, METH_O, "Sets inverse mul factor."},
1338 {NULL} /* Sentinel */
1339 };
1340
1341 static PyNumberMethods SineLoop_as_number =
1342 {
1343 (binaryfunc)SineLoop_add, /*nb_add*/
1344 (binaryfunc)SineLoop_sub, /*nb_subtract*/
1345 (binaryfunc)SineLoop_multiply, /*nb_multiply*/
1346 0, /*nb_remainder*/
1347 0, /*nb_divmod*/
1348 0, /*nb_power*/
1349 0, /*nb_neg*/
1350 0, /*nb_pos*/
1351 0, /*(unaryfunc)array_abs*/
1352 0, /*nb_nonzero*/
1353 0, /*nb_invert*/
1354 0, /*nb_lshift*/
1355 0, /*nb_rshift*/
1356 0, /*nb_and*/
1357 0, /*nb_xor*/
1358 0, /*nb_or*/
1359 0, /*nb_int*/
1360 0, /*nb_long*/
1361 0, /*nb_float*/
1362 (binaryfunc)SineLoop_inplace_add, /*inplace_add*/
1363 (binaryfunc)SineLoop_inplace_sub, /*inplace_subtract*/
1364 (binaryfunc)SineLoop_inplace_multiply, /*inplace_multiply*/
1365 0, /*inplace_remainder*/
1366 0, /*inplace_power*/
1367 0, /*inplace_lshift*/
1368 0, /*inplace_rshift*/
1369 0, /*inplace_and*/
1370 0, /*inplace_xor*/
1371 0, /*inplace_or*/
1372 0, /*nb_floor_divide*/
1373 (binaryfunc)SineLoop_div, /*nb_true_divide*/
1374 0, /*nb_inplace_floor_divide*/
1375 (binaryfunc)SineLoop_inplace_div, /*nb_inplace_true_divide*/
1376 0, /* nb_index */
1377 };
1378
1379 PyTypeObject SineLoopType =
1380 {
1381 PyVarObject_HEAD_INIT(NULL, 0)
1382 "_pyo.SineLoop_base", /*tp_name*/
1383 sizeof(SineLoop), /*tp_basicsize*/
1384 0, /*tp_itemsize*/
1385 (destructor)SineLoop_dealloc, /*tp_dealloc*/
1386 0, /*tp_print*/
1387 0, /*tp_getattr*/
1388 0, /*tp_setattr*/
1389 0, /*tp_as_async (tp_compare in Python 2)*/
1390 0, /*tp_repr*/
1391 &SineLoop_as_number, /*tp_as_number*/
1392 0, /*tp_as_sequence*/
1393 0, /*tp_as_mapping*/
1394 0, /*tp_hash */
1395 0, /*tp_call*/
1396 0, /*tp_str*/
1397 0, /*tp_getattro*/
1398 0, /*tp_setattro*/
1399 0, /*tp_as_buffer*/
1400 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1401 "SineLoop objects. Generates a looped sinewave.", /* tp_doc */
1402 (traverseproc)SineLoop_traverse, /* tp_traverse */
1403 (inquiry)SineLoop_clear, /* tp_clear */
1404 0, /* tp_richcompare */
1405 0, /* tp_weaklistoffset */
1406 0, /* tp_iter */
1407 0, /* tp_iternext */
1408 SineLoop_methods, /* tp_methods */
1409 SineLoop_members, /* tp_members */
1410 0, /* tp_getset */
1411 0, /* tp_base */
1412 0, /* tp_dict */
1413 0, /* tp_descr_get */
1414 0, /* tp_descr_set */
1415 0, /* tp_dictoffset */
1416 0, /* tp_init */
1417 0, /* tp_alloc */
1418 SineLoop_new, /* tp_new */
1419 };
1420
1421 /***************/
1422 /* Osc objects */
1423 /***************/
1424 static double
1425 Osc_clip(double x, T_SIZE_T size)
1426 {
1427 if (x < 0)
1428 {
1429 x += ((T_SIZE_T)(-x / size) + 1) * size;
1430 }
1431 else if (x >= size)
1432 {
1433 x -= (T_SIZE_T)(x / size) * size;
1434 }
1435
1436 return x;
1437 }
1438
1439 typedef struct
1440 {
1441 pyo_audio_HEAD
1442 PyObject *table;
1443 PyObject *freq;
1444 Stream *freq_stream;
1445 PyObject *phase;
1446 Stream *phase_stream;
1447 int modebuffer[4];
1448 double pointerPos;
1449 int interp; /* 0 = default to 2, 1 = nointerp, 2 = linear, 3 = cos, 4 = cubic */
1450 MYFLT (*interp_func_ptr)(MYFLT *, T_SIZE_T, MYFLT, T_SIZE_T);
1451 } Osc;
1452
1453 static void
1454 Osc_readframes_ii(Osc *self)
1455 {
1456 int i;
1457 MYFLT fr, ph, fpart;
1458 double inc, pos;
1459 T_SIZE_T ipart;
1460 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
1461 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
1462
1463 fr = PyFloat_AS_DOUBLE(self->freq);
1464 ph = PyFloat_AS_DOUBLE(self->phase);
1465 inc = fr * size / self->sr;
1466
1467 ph *= size;
1468
1469 for (i = 0; i < self->bufsize; i++)
1470 {
1471 self->pointerPos += inc;
1472 self->pointerPos = Osc_clip(self->pointerPos, size);
1473 pos = self->pointerPos + ph;
1474
1475 if (pos >= size)
1476 pos -= size;
1477
1478 ipart = (T_SIZE_T)pos;
1479 fpart = pos - ipart;
1480 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
1481 }
1482 }
1483
1484 static void
1485 Osc_readframes_ai(Osc *self)
1486 {
1487 int i;
1488 MYFLT ph, fpart, sizeOnSr;
1489 double inc, pos;
1490 T_SIZE_T ipart;
1491 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
1492 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
1493
1494 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
1495 ph = PyFloat_AS_DOUBLE(self->phase);
1496 ph *= size;
1497
1498 sizeOnSr = size / self->sr;
1499
1500 for (i = 0; i < self->bufsize; i++)
1501 {
1502 inc = fr[i] * sizeOnSr;
1503 self->pointerPos += inc;
1504 self->pointerPos = Osc_clip(self->pointerPos, size);
1505 pos = self->pointerPos + ph;
1506
1507 if (pos >= size)
1508 pos -= size;
1509
1510 ipart = (T_SIZE_T)pos;
1511 fpart = pos - ipart;
1512 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
1513 }
1514 }
1515
1516 static void
1517 Osc_readframes_ia(Osc *self)
1518 {
1519 int i;
1520 MYFLT fr, pha, fpart;
1521 double inc, pos;
1522 T_SIZE_T ipart;
1523 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
1524 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
1525
1526 fr = PyFloat_AS_DOUBLE(self->freq);
1527 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
1528 inc = fr * size / self->sr;
1529
1530 for (i = 0; i < self->bufsize; i++)
1531 {
1532 pha = ph[i] * size;
1533 self->pointerPos += inc;
1534 self->pointerPos = Osc_clip(self->pointerPos, size);
1535 pos = self->pointerPos + pha;
1536
1537 if (pos >= size)
1538 pos -= size;
1539
1540 ipart = (T_SIZE_T)pos;
1541 fpart = pos - ipart;
1542 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
1543 }
1544 }
1545
1546 static void
1547 Osc_readframes_aa(Osc *self)
1548 {
1549 int i;
1550 MYFLT pha, fpart, sizeOnSr;
1551 double inc, pos;
1552 T_SIZE_T ipart;
1553 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
1554 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
1555
1556 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
1557 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
1558
1559 sizeOnSr = size / self->sr;
1560
1561 for (i = 0; i < self->bufsize; i++)
1562 {
1563 inc = fr[i] * sizeOnSr;
1564 pha = ph[i] * size;
1565 self->pointerPos += inc;
1566 self->pointerPos = Osc_clip(self->pointerPos, size);
1567 pos = self->pointerPos + pha;
1568
1569 if (pos >= size)
1570 pos -= size;
1571
1572 ipart = (T_SIZE_T)pos;
1573 fpart = pos - ipart;
1574 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
1575 }
1576 }
1577
1578 static void Osc_postprocessing_ii(Osc *self) { POST_PROCESSING_II };
1579 static void Osc_postprocessing_ai(Osc *self) { POST_PROCESSING_AI };
1580 static void Osc_postprocessing_ia(Osc *self) { POST_PROCESSING_IA };
1581 static void Osc_postprocessing_aa(Osc *self) { POST_PROCESSING_AA };
1582 static void Osc_postprocessing_ireva(Osc *self) { POST_PROCESSING_IREVA };
1583 static void Osc_postprocessing_areva(Osc *self) { POST_PROCESSING_AREVA };
1584 static void Osc_postprocessing_revai(Osc *self) { POST_PROCESSING_REVAI };
1585 static void Osc_postprocessing_revaa(Osc *self) { POST_PROCESSING_REVAA };
1586 static void Osc_postprocessing_revareva(Osc *self) { POST_PROCESSING_REVAREVA };
1587
1588 static void
1589 Osc_setProcMode(Osc *self)
1590 {
1591 int procmode, muladdmode;
1592 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
1593 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
1594
1595 switch (procmode)
1596 {
1597 case 0:
1598 self->proc_func_ptr = Osc_readframes_ii;
1599 break;
1600
1601 case 1:
1602 self->proc_func_ptr = Osc_readframes_ai;
1603 break;
1604
1605 case 10:
1606 self->proc_func_ptr = Osc_readframes_ia;
1607 break;
1608
1609 case 11:
1610 self->proc_func_ptr = Osc_readframes_aa;
1611 break;
1612 }
1613
1614 switch (muladdmode)
1615 {
1616 case 0:
1617 self->muladd_func_ptr = Osc_postprocessing_ii;
1618 break;
1619
1620 case 1:
1621 self->muladd_func_ptr = Osc_postprocessing_ai;
1622 break;
1623
1624 case 2:
1625 self->muladd_func_ptr = Osc_postprocessing_revai;
1626 break;
1627
1628 case 10:
1629 self->muladd_func_ptr = Osc_postprocessing_ia;
1630 break;
1631
1632 case 11:
1633 self->muladd_func_ptr = Osc_postprocessing_aa;
1634 break;
1635
1636 case 12:
1637 self->muladd_func_ptr = Osc_postprocessing_revaa;
1638 break;
1639
1640 case 20:
1641 self->muladd_func_ptr = Osc_postprocessing_ireva;
1642 break;
1643
1644 case 21:
1645 self->muladd_func_ptr = Osc_postprocessing_areva;
1646 break;
1647
1648 case 22:
1649 self->muladd_func_ptr = Osc_postprocessing_revareva;
1650 break;
1651 }
1652 }
1653
1654 static void
1655 Osc_compute_next_data_frame(Osc *self)
1656 {
1657 (*self->proc_func_ptr)(self);
1658 (*self->muladd_func_ptr)(self);
1659 }
1660
1661 static int
1662 Osc_traverse(Osc *self, visitproc visit, void *arg)
1663 {
1664 pyo_VISIT
1665 Py_VISIT(self->phase);
1666 Py_VISIT(self->freq);
1667 return 0;
1668 }
1669
1670 static int
1671 Osc_clear(Osc *self)
1672 {
1673 pyo_CLEAR
1674 Py_CLEAR(self->phase);
1675 Py_CLEAR(self->freq);
1676 return 0;
1677 }
1678
1679 static void
1680 Osc_dealloc(Osc* self)
1681 {
1682 pyo_DEALLOC
1683 Osc_clear(self);
1684 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
1685 Py_TYPE(self)->tp_free((PyObject*)self);
1686 }
1687
1688 static PyObject *
1689 Osc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1690 {
1691 int i;
1692 PyObject *tabletmp, *freqtmp = NULL, *phasetmp = NULL, *multmp = NULL, *addtmp = NULL;
1693 Osc *self;
1694 self = (Osc *)type->tp_alloc(type, 0);
1695
1696 self->freq = PyFloat_FromDouble(1000);
1697 self->phase = PyFloat_FromDouble(0);
1698 self->modebuffer[0] = 0;
1699 self->modebuffer[1] = 0;
1700 self->modebuffer[2] = 0;
1701 self->modebuffer[3] = 0;
1702 self->pointerPos = 0.;
1703 self->interp = 2;
1704
1705 INIT_OBJECT_COMMON
1706 Stream_setFunctionPtr(self->stream, Osc_compute_next_data_frame);
1707 self->mode_func_ptr = Osc_setProcMode;
1708
1709 static char *kwlist[] = {"table", "freq", "phase", "interp", "mul", "add", NULL};
1710
1711 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOiOO", kwlist, &tabletmp, &freqtmp, &phasetmp, &self->interp, &multmp, &addtmp))
1712 Py_RETURN_NONE;
1713
1714 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
1715 {
1716 PyErr_SetString(PyExc_TypeError, "\"table\" argument of Osc must be a PyoTableObject.\n");
1717 Py_RETURN_NONE;
1718 }
1719
1720 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
1721
1722 if (freqtmp)
1723 {
1724 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
1725 }
1726
1727 if (phasetmp)
1728 {
1729 PyObject_CallMethod((PyObject *)self, "setPhase", "O", phasetmp);
1730 }
1731
1732 if (multmp)
1733 {
1734 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
1735 }
1736
1737 if (addtmp)
1738 {
1739 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
1740 }
1741
1742 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
1743
1744 (*self->mode_func_ptr)(self);
1745
1746 SET_INTERP_POINTER
1747
1748 return (PyObject *)self;
1749 }
1750
1751 static PyObject * Osc_getServer(Osc* self) { GET_SERVER };
1752 static PyObject * Osc_getStream(Osc* self) { GET_STREAM };
1753 static PyObject * Osc_setMul(Osc *self, PyObject *arg) { SET_MUL };
1754 static PyObject * Osc_setAdd(Osc *self, PyObject *arg) { SET_ADD };
1755 static PyObject * Osc_setSub(Osc *self, PyObject *arg) { SET_SUB };
1756 static PyObject * Osc_setDiv(Osc *self, PyObject *arg) { SET_DIV };
1757
1758 static PyObject * Osc_play(Osc *self, PyObject *args, PyObject *kwds) { PLAY };
1759 static PyObject * Osc_out(Osc *self, PyObject *args, PyObject *kwds) { OUT };
1760 static PyObject * Osc_stop(Osc *self, PyObject *args, PyObject *kwds) { STOP };
1761
1762 static PyObject * Osc_multiply(Osc *self, PyObject *arg) { MULTIPLY };
1763 static PyObject * Osc_inplace_multiply(Osc *self, PyObject *arg) { INPLACE_MULTIPLY };
1764 static PyObject * Osc_add(Osc *self, PyObject *arg) { ADD };
1765 static PyObject * Osc_inplace_add(Osc *self, PyObject *arg) { INPLACE_ADD };
1766 static PyObject * Osc_sub(Osc *self, PyObject *arg) { SUB };
1767 static PyObject * Osc_inplace_sub(Osc *self, PyObject *arg) { INPLACE_SUB };
1768 static PyObject * Osc_div(Osc *self, PyObject *arg) { DIV };
1769 static PyObject * Osc_inplace_div(Osc *self, PyObject *arg) { INPLACE_DIV };
1770
1771 static PyObject *
1772 Osc_getTable(Osc* self)
1773 {
1774 Py_INCREF(self->table);
1775 return self->table;
1776 };
1777
1778 static PyObject *
1779 Osc_setTable(Osc *self, PyObject *arg)
1780 {
1781 ASSERT_ARG_NOT_NULL
1782
1783 Py_DECREF(self->table);
1784 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
1785
1786 Py_RETURN_NONE;
1787 }
1788
1789 static PyObject * Osc_setFreq(Osc *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
1790 static PyObject * Osc_setPhase(Osc *self, PyObject *arg) { SET_PARAM(self->phase, self->phase_stream, 3); }
1791
1792 static PyObject *
1793 Osc_setInterp(Osc *self, PyObject *arg)
1794 {
1795 ASSERT_ARG_NOT_NULL
1796
1797 if (PyNumber_Check(arg))
1798 {
1799 self->interp = PyLong_AsLong(PyNumber_Long(arg));
1800 }
1801
1802 SET_INTERP_POINTER
1803
1804 Py_RETURN_NONE;
1805 }
1806
1807 static PyObject *
1808 Osc_reset(Osc *self)
1809 {
1810 self->pointerPos = 0.0;
1811 Py_RETURN_NONE;
1812 }
1813
1814 static PyMemberDef Osc_members[] =
1815 {
1816 {"server", T_OBJECT_EX, offsetof(Osc, server), 0, "Pyo server."},
1817 {"stream", T_OBJECT_EX, offsetof(Osc, stream), 0, "Stream object."},
1818 {"table", T_OBJECT_EX, offsetof(Osc, table), 0, "Waveform table."},
1819 {"freq", T_OBJECT_EX, offsetof(Osc, freq), 0, "Frequency in cycle per second."},
1820 {"phase", T_OBJECT_EX, offsetof(Osc, phase), 0, "Oscillator phase."},
1821 {"mul", T_OBJECT_EX, offsetof(Osc, mul), 0, "Mul factor."},
1822 {"add", T_OBJECT_EX, offsetof(Osc, add), 0, "Add factor."},
1823 {NULL} /* Sentinel */
1824 };
1825
1826 static PyMethodDef Osc_methods[] =
1827 {
1828 {"getTable", (PyCFunction)Osc_getTable, METH_NOARGS, "Returns waveform table object."},
1829 {"getServer", (PyCFunction)Osc_getServer, METH_NOARGS, "Returns server object."},
1830 {"_getStream", (PyCFunction)Osc_getStream, METH_NOARGS, "Returns stream object."},
1831 {"play", (PyCFunction)Osc_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
1832 {"out", (PyCFunction)Osc_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
1833 {"stop", (PyCFunction)Osc_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
1834 {"setTable", (PyCFunction)Osc_setTable, METH_O, "Sets oscillator table."},
1835 {"setFreq", (PyCFunction)Osc_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
1836 {"setPhase", (PyCFunction)Osc_setPhase, METH_O, "Sets oscillator phase."},
1837 {"setInterp", (PyCFunction)Osc_setInterp, METH_O, "Sets oscillator interpolation mode."},
1838 {"reset", (PyCFunction)Osc_reset, METH_NOARGS, "Resets pointer position to 0."},
1839 {"setMul", (PyCFunction)Osc_setMul, METH_O, "Sets oscillator mul factor."},
1840 {"setAdd", (PyCFunction)Osc_setAdd, METH_O, "Sets oscillator add factor."},
1841 {"setSub", (PyCFunction)Osc_setSub, METH_O, "Sets oscillator inverse add factor."},
1842 {"setDiv", (PyCFunction)Osc_setDiv, METH_O, "Sets inverse mul factor."},
1843 {NULL} /* Sentinel */
1844 };
1845
1846 static PyNumberMethods Osc_as_number =
1847 {
1848 (binaryfunc)Osc_add, /*nb_add*/
1849 (binaryfunc)Osc_sub, /*nb_subtract*/
1850 (binaryfunc)Osc_multiply, /*nb_multiply*/
1851 0, /*nb_remainder*/
1852 0, /*nb_divmod*/
1853 0, /*nb_power*/
1854 0, /*nb_neg*/
1855 0, /*nb_pos*/
1856 0, /*(unaryfunc)array_abs,*/
1857 0, /*nb_nonzero*/
1858 0, /*nb_invert*/
1859 0, /*nb_lshift*/
1860 0, /*nb_rshift*/
1861 0, /*nb_and*/
1862 0, /*nb_xor*/
1863 0, /*nb_or*/
1864 0, /*nb_int*/
1865 0, /*nb_long*/
1866 0, /*nb_float*/
1867 (binaryfunc)Osc_inplace_add, /*inplace_add*/
1868 (binaryfunc)Osc_inplace_sub, /*inplace_subtract*/
1869 (binaryfunc)Osc_inplace_multiply, /*inplace_multiply*/
1870 0, /*inplace_remainder*/
1871 0, /*inplace_power*/
1872 0, /*inplace_lshift*/
1873 0, /*inplace_rshift*/
1874 0, /*inplace_and*/
1875 0, /*inplace_xor*/
1876 0, /*inplace_or*/
1877 0, /*nb_floor_divide*/
1878 (binaryfunc)Osc_div, /*nb_true_divide*/
1879 0, /*nb_inplace_floor_divide*/
1880 (binaryfunc)Osc_inplace_div, /*nb_inplace_true_divide*/
1881 0, /* nb_index */
1882 };
1883
1884 PyTypeObject OscType =
1885 {
1886 PyVarObject_HEAD_INIT(NULL, 0)
1887 "_pyo.Osc_base", /*tp_name*/
1888 sizeof(Osc), /*tp_basicsize*/
1889 0, /*tp_itemsize*/
1890 (destructor)Osc_dealloc, /*tp_dealloc*/
1891 0, /*tp_print*/
1892 0, /*tp_getattr*/
1893 0, /*tp_setattr*/
1894 0, /*tp_as_async (tp_compare in Python 2)*/
1895 0, /*tp_repr*/
1896 &Osc_as_number, /*tp_as_number*/
1897 0, /*tp_as_sequence*/
1898 0, /*tp_as_mapping*/
1899 0, /*tp_hash */
1900 0, /*tp_call*/
1901 0, /*tp_str*/
1902 0, /*tp_getattro*/
1903 0, /*tp_setattro*/
1904 0, /*tp_as_buffer*/
1905 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
1906 "Osc objects. Generates an oscillatory waveform.", /* tp_doc */
1907 (traverseproc)Osc_traverse, /* tp_traverse */
1908 (inquiry)Osc_clear, /* tp_clear */
1909 0, /* tp_richcompare */
1910 0, /* tp_weaklistoffset */
1911 0, /* tp_iter */
1912 0, /* tp_iternext */
1913 Osc_methods, /* tp_methods */
1914 Osc_members, /* tp_members */
1915 0, /* tp_getset */
1916 0, /* tp_base */
1917 0, /* tp_dict */
1918 0, /* tp_descr_get */
1919 0, /* tp_descr_set */
1920 0, /* tp_dictoffset */
1921 0, /* tp_init */
1922 0, /* tp_alloc */
1923 Osc_new, /* tp_new */
1924 };
1925
1926 /**************/
1927 /* OscLoop object */
1928 /**************/
1929 typedef struct
1930 {
1931 pyo_audio_HEAD
1932 PyObject *table;
1933 PyObject *freq;
1934 Stream *freq_stream;
1935 PyObject *feedback;
1936 Stream *feedback_stream;
1937 int modebuffer[4];
1938 double pointerPos;
1939 MYFLT lastValue;
1940 } OscLoop;
1941
1942 static void
1943 OscLoop_readframes_ii(OscLoop *self)
1944 {
1945 int i;
1946 MYFLT fr, feed, pos, inc;
1947 T_SIZE_T ipart;
1948 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
1949 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
1950
1951 fr = PyFloat_AS_DOUBLE(self->freq);
1952 feed = _clip(PyFloat_AS_DOUBLE(self->feedback)) * size;
1953 inc = fr * size / self->sr;
1954
1955 for (i = 0; i < self->bufsize; i++)
1956 {
1957 self->pointerPos += inc;
1958 self->pointerPos = Osc_clip(self->pointerPos, size);
1959 pos = self->pointerPos + (self->lastValue * feed);
1960
1961 if (pos >= size)
1962 pos -= size;
1963 else if (pos < 0)
1964 pos += size;
1965
1966 ipart = (T_SIZE_T)pos;
1967 self->data[i] = self->lastValue = tablelist[ipart] + (tablelist[ipart + 1] - tablelist[ipart]) * (pos - ipart);
1968 }
1969 }
1970
1971 static void
1972 OscLoop_readframes_ai(OscLoop *self)
1973 {
1974 int i;
1975 MYFLT inc, feed, pos, sizeOnSr;
1976 T_SIZE_T ipart;
1977 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
1978 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
1979
1980 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
1981 feed = _clip(PyFloat_AS_DOUBLE(self->feedback)) * size;
1982
1983 sizeOnSr = size / self->sr;
1984
1985 for (i = 0; i < self->bufsize; i++)
1986 {
1987 inc = fr[i] * sizeOnSr;
1988 self->pointerPos += inc;
1989 self->pointerPos = Osc_clip(self->pointerPos, size);
1990 pos = self->pointerPos + (self->lastValue * feed);
1991
1992 if (pos >= size)
1993 pos -= size;
1994 else if (pos < 0)
1995 pos += size;
1996
1997 ipart = (T_SIZE_T)pos;
1998 self->data[i] = self->lastValue = tablelist[ipart] + (tablelist[ipart + 1] - tablelist[ipart]) * (pos - ipart);
1999 }
2000 }
2001
2002 static void
2003 OscLoop_readframes_ia(OscLoop *self)
2004 {
2005 int i;
2006 MYFLT fr, feed, pos, inc;
2007 T_SIZE_T ipart;
2008 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
2009 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
2010
2011 fr = PyFloat_AS_DOUBLE(self->freq);
2012 MYFLT *fd = Stream_getData((Stream *)self->feedback_stream);
2013 inc = fr * size / self->sr;
2014
2015 for (i = 0; i < self->bufsize; i++)
2016 {
2017 feed = _clip(fd[i]) * size;
2018 self->pointerPos += inc;
2019 self->pointerPos = Osc_clip(self->pointerPos, size);
2020 pos = self->pointerPos + (self->lastValue * feed);
2021
2022 if (pos >= size)
2023 pos -= size;
2024 else if (pos < 0)
2025 pos += size;
2026
2027 ipart = (T_SIZE_T)pos;
2028 self->data[i] = self->lastValue = tablelist[ipart] + (tablelist[ipart + 1] - tablelist[ipart]) * (pos - ipart);
2029 }
2030 }
2031
2032 static void
2033 OscLoop_readframes_aa(OscLoop *self)
2034 {
2035 int i;
2036 MYFLT inc, feed, pos, sizeOnSr;
2037 T_SIZE_T ipart;
2038 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
2039 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
2040
2041 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
2042 MYFLT *fd = Stream_getData((Stream *)self->feedback_stream);
2043
2044 sizeOnSr = size / self->sr;
2045
2046 for (i = 0; i < self->bufsize; i++)
2047 {
2048 inc = fr[i] * sizeOnSr;
2049 feed = _clip(fd[i]) * size;
2050 self->pointerPos += inc;
2051 self->pointerPos = Osc_clip(self->pointerPos, size);
2052 pos = self->pointerPos + (self->lastValue * feed);
2053
2054 if (pos >= size)
2055 pos -= size;
2056 else if (pos < 0)
2057 pos += size;
2058
2059 ipart = (T_SIZE_T)pos;
2060 self->data[i] = self->lastValue = tablelist[ipart] + (tablelist[ipart + 1] - tablelist[ipart]) * (pos - ipart);
2061 }
2062 }
2063
2064 static void OscLoop_postprocessing_ii(OscLoop *self) { POST_PROCESSING_II };
2065 static void OscLoop_postprocessing_ai(OscLoop *self) { POST_PROCESSING_AI };
2066 static void OscLoop_postprocessing_ia(OscLoop *self) { POST_PROCESSING_IA };
2067 static void OscLoop_postprocessing_aa(OscLoop *self) { POST_PROCESSING_AA };
2068 static void OscLoop_postprocessing_ireva(OscLoop *self) { POST_PROCESSING_IREVA };
2069 static void OscLoop_postprocessing_areva(OscLoop *self) { POST_PROCESSING_AREVA };
2070 static void OscLoop_postprocessing_revai(OscLoop *self) { POST_PROCESSING_REVAI };
2071 static void OscLoop_postprocessing_revaa(OscLoop *self) { POST_PROCESSING_REVAA };
2072 static void OscLoop_postprocessing_revareva(OscLoop *self) { POST_PROCESSING_REVAREVA };
2073
2074 static void
2075 OscLoop_setProcMode(OscLoop *self)
2076 {
2077 int procmode, muladdmode;
2078 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
2079 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2080
2081 switch (procmode)
2082 {
2083 case 0:
2084 self->proc_func_ptr = OscLoop_readframes_ii;
2085 break;
2086
2087 case 1:
2088 self->proc_func_ptr = OscLoop_readframes_ai;
2089 break;
2090
2091 case 10:
2092 self->proc_func_ptr = OscLoop_readframes_ia;
2093 break;
2094
2095 case 11:
2096 self->proc_func_ptr = OscLoop_readframes_aa;
2097 break;
2098 }
2099
2100 switch (muladdmode)
2101 {
2102 case 0:
2103 self->muladd_func_ptr = OscLoop_postprocessing_ii;
2104 break;
2105
2106 case 1:
2107 self->muladd_func_ptr = OscLoop_postprocessing_ai;
2108 break;
2109
2110 case 2:
2111 self->muladd_func_ptr = OscLoop_postprocessing_revai;
2112 break;
2113
2114 case 10:
2115 self->muladd_func_ptr = OscLoop_postprocessing_ia;
2116 break;
2117
2118 case 11:
2119 self->muladd_func_ptr = OscLoop_postprocessing_aa;
2120 break;
2121
2122 case 12:
2123 self->muladd_func_ptr = OscLoop_postprocessing_revaa;
2124 break;
2125
2126 case 20:
2127 self->muladd_func_ptr = OscLoop_postprocessing_ireva;
2128 break;
2129
2130 case 21:
2131 self->muladd_func_ptr = OscLoop_postprocessing_areva;
2132 break;
2133
2134 case 22:
2135 self->muladd_func_ptr = OscLoop_postprocessing_revareva;
2136 break;
2137 }
2138 }
2139
2140 static void
2141 OscLoop_compute_next_data_frame(OscLoop *self)
2142 {
2143 (*self->proc_func_ptr)(self);
2144 (*self->muladd_func_ptr)(self);
2145 }
2146
2147 static int
2148 OscLoop_traverse(OscLoop *self, visitproc visit, void *arg)
2149 {
2150 pyo_VISIT
2151 Py_VISIT(self->feedback);
2152 Py_VISIT(self->freq);
2153 return 0;
2154 }
2155
2156 static int
2157 OscLoop_clear(OscLoop *self)
2158 {
2159 pyo_CLEAR
2160 Py_CLEAR(self->feedback);
2161 Py_CLEAR(self->freq);
2162 return 0;
2163 }
2164
2165 static void
2166 OscLoop_dealloc(OscLoop* self)
2167 {
2168 pyo_DEALLOC
2169 OscLoop_clear(self);
2170 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2171 Py_TYPE(self)->tp_free((PyObject*)self);
2172 }
2173
2174 static PyObject *
2175 OscLoop_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2176 {
2177 int i;
2178 PyObject *tabletmp, *freqtmp = NULL, *feedbacktmp = NULL, *multmp = NULL, *addtmp = NULL;
2179 OscLoop *self;
2180 self = (OscLoop *)type->tp_alloc(type, 0);
2181
2182 self->freq = PyFloat_FromDouble(1000);
2183 self->feedback = PyFloat_FromDouble(0);
2184 self->modebuffer[0] = 0;
2185 self->modebuffer[1] = 0;
2186 self->modebuffer[2] = 0;
2187 self->modebuffer[3] = 0;
2188 self->pointerPos = self->lastValue = 0.;
2189
2190 INIT_OBJECT_COMMON
2191 Stream_setFunctionPtr(self->stream, OscLoop_compute_next_data_frame);
2192 self->mode_func_ptr = OscLoop_setProcMode;
2193
2194 static char *kwlist[] = {"table", "freq", "feedback", "mul", "add", NULL};
2195
2196 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOO", kwlist, &tabletmp, &freqtmp, &feedbacktmp, &multmp, &addtmp))
2197 Py_RETURN_NONE;
2198
2199 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
2200 {
2201 PyErr_SetString(PyExc_TypeError, "\"table\" argument of OscLoop must be a PyoTableObject.\n");
2202 Py_RETURN_NONE;
2203 }
2204
2205 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
2206
2207 if (feedbacktmp)
2208 {
2209 PyObject_CallMethod((PyObject *)self, "setFeedback", "O", feedbacktmp);
2210 }
2211
2212 if (freqtmp)
2213 {
2214 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
2215 }
2216
2217 if (multmp)
2218 {
2219 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2220 }
2221
2222 if (addtmp)
2223 {
2224 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2225 }
2226
2227 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2228
2229 (*self->mode_func_ptr)(self);
2230
2231 return (PyObject *)self;
2232 }
2233
2234 static PyObject * OscLoop_getServer(OscLoop* self) { GET_SERVER };
2235 static PyObject * OscLoop_getStream(OscLoop* self) { GET_STREAM };
2236 static PyObject * OscLoop_setMul(OscLoop *self, PyObject *arg) { SET_MUL };
2237 static PyObject * OscLoop_setAdd(OscLoop *self, PyObject *arg) { SET_ADD };
2238 static PyObject * OscLoop_setSub(OscLoop *self, PyObject *arg) { SET_SUB };
2239 static PyObject * OscLoop_setDiv(OscLoop *self, PyObject *arg) { SET_DIV };
2240
2241 static PyObject * OscLoop_play(OscLoop *self, PyObject *args, PyObject *kwds) { PLAY };
2242 static PyObject * OscLoop_out(OscLoop *self, PyObject *args, PyObject *kwds) { OUT };
2243 static PyObject * OscLoop_stop(OscLoop *self, PyObject *args, PyObject *kwds) { STOP };
2244
2245 static PyObject * OscLoop_multiply(OscLoop *self, PyObject *arg) { MULTIPLY };
2246 static PyObject * OscLoop_inplace_multiply(OscLoop *self, PyObject *arg) { INPLACE_MULTIPLY };
2247 static PyObject * OscLoop_add(OscLoop *self, PyObject *arg) { ADD };
2248 static PyObject * OscLoop_inplace_add(OscLoop *self, PyObject *arg) { INPLACE_ADD };
2249 static PyObject * OscLoop_sub(OscLoop *self, PyObject *arg) { SUB };
2250 static PyObject * OscLoop_inplace_sub(OscLoop *self, PyObject *arg) { INPLACE_SUB };
2251 static PyObject * OscLoop_div(OscLoop *self, PyObject *arg) { DIV };
2252 static PyObject * OscLoop_inplace_div(OscLoop *self, PyObject *arg) { INPLACE_DIV };
2253
2254 static PyObject *
2255 OscLoop_getTable(OscLoop* self)
2256 {
2257 Py_INCREF(self->table);
2258 return self->table;
2259 };
2260
2261 static PyObject *
2262 OscLoop_setTable(OscLoop *self, PyObject *arg)
2263 {
2264 ASSERT_ARG_NOT_NULL
2265
2266 Py_DECREF(self->table);
2267 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
2268
2269 Py_RETURN_NONE;
2270 }
2271
2272 static PyObject * OscLoop_setFreq(OscLoop *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
2273 static PyObject * OscLoop_setFeedback(OscLoop *self, PyObject *arg) { SET_PARAM(self->feedback, self->feedback_stream, 3); }
2274
2275 static PyMemberDef OscLoop_members[] =
2276 {
2277 {"server", T_OBJECT_EX, offsetof(OscLoop, server), 0, "Pyo server."},
2278 {"stream", T_OBJECT_EX, offsetof(OscLoop, stream), 0, "Stream object."},
2279 {"table", T_OBJECT_EX, offsetof(OscLoop, table), 0, "Waveform table."},
2280 {"freq", T_OBJECT_EX, offsetof(OscLoop, freq), 0, "Frequency in cycle per second."},
2281 {"feedback", T_OBJECT_EX, offsetof(OscLoop, feedback), 0, "Oscillator feedback."},
2282 {"mul", T_OBJECT_EX, offsetof(OscLoop, mul), 0, "Mul factor."},
2283 {"add", T_OBJECT_EX, offsetof(OscLoop, add), 0, "Add factor."},
2284 {NULL} /* Sentinel */
2285 };
2286
2287 static PyMethodDef OscLoop_methods[] =
2288 {
2289 {"getTable", (PyCFunction)OscLoop_getTable, METH_NOARGS, "Returns waveform table object."},
2290 {"getServer", (PyCFunction)OscLoop_getServer, METH_NOARGS, "Returns server object."},
2291 {"_getStream", (PyCFunction)OscLoop_getStream, METH_NOARGS, "Returns stream object."},
2292 {"play", (PyCFunction)OscLoop_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2293 {"out", (PyCFunction)OscLoop_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2294 {"stop", (PyCFunction)OscLoop_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2295 {"setTable", (PyCFunction)OscLoop_setTable, METH_O, "Sets oscillator table."},
2296 {"setFreq", (PyCFunction)OscLoop_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
2297 {"setFeedback", (PyCFunction)OscLoop_setFeedback, METH_O, "Sets oscillator feedback."},
2298 {"setMul", (PyCFunction)OscLoop_setMul, METH_O, "Sets oscillator mul factor."},
2299 {"setAdd", (PyCFunction)OscLoop_setAdd, METH_O, "Sets oscillator add factor."},
2300 {"setSub", (PyCFunction)OscLoop_setSub, METH_O, "Sets oscillator inverse add factor."},
2301 {"setDiv", (PyCFunction)OscLoop_setDiv, METH_O, "Sets inverse mul factor."},
2302 {NULL} /* Sentinel */
2303 };
2304
2305 static PyNumberMethods OscLoop_as_number =
2306 {
2307 (binaryfunc)OscLoop_add, /*nb_add*/
2308 (binaryfunc)OscLoop_sub, /*nb_subtract*/
2309 (binaryfunc)OscLoop_multiply, /*nb_multiply*/
2310 0, /*nb_remainder*/
2311 0, /*nb_divmod*/
2312 0, /*nb_power*/
2313 0, /*nb_neg*/
2314 0, /*nb_pos*/
2315 0, /*(unaryfunc)array_abs,*/
2316 0, /*nb_nonzero*/
2317 0, /*nb_invert*/
2318 0, /*nb_lshift*/
2319 0, /*nb_rshift*/
2320 0, /*nb_and*/
2321 0, /*nb_xor*/
2322 0, /*nb_or*/
2323 0, /*nb_int*/
2324 0, /*nb_long*/
2325 0, /*nb_float*/
2326 (binaryfunc)OscLoop_inplace_add, /*inplace_add*/
2327 (binaryfunc)OscLoop_inplace_sub, /*inplace_subtract*/
2328 (binaryfunc)OscLoop_inplace_multiply, /*inplace_multiply*/
2329 0, /*inplace_remainder*/
2330 0, /*inplace_power*/
2331 0, /*inplace_lshift*/
2332 0, /*inplace_rshift*/
2333 0, /*inplace_and*/
2334 0, /*inplace_xor*/
2335 0, /*inplace_or*/
2336 0, /*nb_floor_divide*/
2337 (binaryfunc)OscLoop_div, /*nb_true_divide*/
2338 0, /*nb_inplace_floor_divide*/
2339 (binaryfunc)OscLoop_inplace_div, /*nb_inplace_true_divide*/
2340 0, /* nb_index */
2341 };
2342
2343 PyTypeObject OscLoopType =
2344 {
2345 PyVarObject_HEAD_INIT(NULL, 0)
2346 "_pyo.OscLoop_base", /*tp_name*/
2347 sizeof(OscLoop), /*tp_basicsize*/
2348 0, /*tp_itemsize*/
2349 (destructor)OscLoop_dealloc, /*tp_dealloc*/
2350 0, /*tp_print*/
2351 0, /*tp_getattr*/
2352 0, /*tp_setattr*/
2353 0, /*tp_as_async (tp_compare in Python 2)*/
2354 0, /*tp_repr*/
2355 &OscLoop_as_number, /*tp_as_number*/
2356 0, /*tp_as_sequence*/
2357 0, /*tp_as_mapping*/
2358 0, /*tp_hash */
2359 0, /*tp_call*/
2360 0, /*tp_str*/
2361 0, /*tp_getattro*/
2362 0, /*tp_setattro*/
2363 0, /*tp_as_buffer*/
2364 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2365 "OscLoop objects. Generates an oscillatory waveform.", /* tp_doc */
2366 (traverseproc)OscLoop_traverse, /* tp_traverse */
2367 (inquiry)OscLoop_clear, /* tp_clear */
2368 0, /* tp_richcompare */
2369 0, /* tp_weaklistoffset */
2370 0, /* tp_iter */
2371 0, /* tp_iternext */
2372 OscLoop_methods, /* tp_methods */
2373 OscLoop_members, /* tp_members */
2374 0, /* tp_getset */
2375 0, /* tp_base */
2376 0, /* tp_dict */
2377 0, /* tp_descr_get */
2378 0, /* tp_descr_set */
2379 0, /* tp_dictoffset */
2380 0, /* tp_init */
2381 0, /* tp_alloc */
2382 OscLoop_new, /* tp_new */
2383 };
2384
2385 typedef struct
2386 {
2387 pyo_audio_HEAD
2388 PyObject *table;
2389 PyObject *freq;
2390 Stream *freq_stream;
2391 PyObject *phase;
2392 Stream *phase_stream;
2393 PyObject *trig;
2394 Stream *trig_stream;
2395 int modebuffer[4];
2396 double pointerPos;
2397 int interp; /* 0 = default to 2, 1 = nointerp, 2 = linear, 3 = cos, 4 = cubic */
2398 MYFLT (*interp_func_ptr)(MYFLT *, T_SIZE_T, MYFLT, T_SIZE_T);
2399 } OscTrig;
2400
2401 static void
2402 OscTrig_readframes_ii(OscTrig *self)
2403 {
2404 int i;
2405 MYFLT fr, ph, fpart;
2406 double inc, pos;
2407 T_SIZE_T ipart;
2408 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
2409 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
2410
2411 fr = PyFloat_AS_DOUBLE(self->freq);
2412 ph = PyFloat_AS_DOUBLE(self->phase);
2413 MYFLT *tr = Stream_getData((Stream *)self->trig_stream);
2414 inc = fr * size / self->sr;
2415
2416 ph *= size;
2417
2418 for (i = 0; i < self->bufsize; i++)
2419 {
2420 if (tr[i] == 1)
2421 self->pointerPos = 0.0;
2422 else
2423 {
2424 self->pointerPos += inc;
2425 self->pointerPos = Osc_clip(self->pointerPos, size);
2426 }
2427
2428 pos = self->pointerPos + ph;
2429
2430 if (pos >= size)
2431 pos -= size;
2432
2433 ipart = (T_SIZE_T)pos;
2434 fpart = pos - ipart;
2435 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
2436 }
2437 }
2438
2439 static void
2440 OscTrig_readframes_ai(OscTrig *self)
2441 {
2442 int i;
2443 MYFLT ph, fpart, sizeOnSr;
2444 double inc, pos;
2445 T_SIZE_T ipart;
2446 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
2447 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
2448
2449 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
2450 ph = PyFloat_AS_DOUBLE(self->phase);
2451 MYFLT *tr = Stream_getData((Stream *)self->trig_stream);
2452 ph *= size;
2453
2454 sizeOnSr = size / self->sr;
2455
2456 for (i = 0; i < self->bufsize; i++)
2457 {
2458 inc = fr[i] * sizeOnSr;
2459
2460 if (tr[i] == 1)
2461 self->pointerPos = 0.0;
2462 else
2463 {
2464 self->pointerPos += inc;
2465 self->pointerPos = Osc_clip(self->pointerPos, size);
2466 }
2467
2468 pos = self->pointerPos + ph;
2469
2470 if (pos >= size)
2471 pos -= size;
2472
2473 ipart = (T_SIZE_T)pos;
2474 fpart = pos - ipart;
2475 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
2476 }
2477 }
2478
2479 static void
2480 OscTrig_readframes_ia(OscTrig *self)
2481 {
2482 int i;
2483 MYFLT fr, pha, fpart;
2484 double inc, pos;
2485 T_SIZE_T ipart;
2486 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
2487 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
2488
2489 fr = PyFloat_AS_DOUBLE(self->freq);
2490 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
2491 MYFLT *tr = Stream_getData((Stream *)self->trig_stream);
2492 inc = fr * size / self->sr;
2493
2494 for (i = 0; i < self->bufsize; i++)
2495 {
2496 pha = ph[i] * size;
2497
2498 if (tr[i] == 1)
2499 self->pointerPos = 0.0;
2500 else
2501 {
2502 self->pointerPos += inc;
2503 self->pointerPos = Osc_clip(self->pointerPos, size);
2504 }
2505
2506 pos = self->pointerPos + pha;
2507
2508 if (pos >= size)
2509 pos -= size;
2510
2511 ipart = (T_SIZE_T)pos;
2512 fpart = pos - ipart;
2513 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
2514 }
2515 }
2516
2517 static void
2518 OscTrig_readframes_aa(OscTrig *self)
2519 {
2520 int i;
2521 MYFLT pha, fpart, sizeOnSr;
2522 double inc, pos;
2523 T_SIZE_T ipart;
2524 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
2525 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
2526
2527 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
2528 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
2529 MYFLT *tr = Stream_getData((Stream *)self->trig_stream);
2530
2531 sizeOnSr = size / self->sr;
2532
2533 for (i = 0; i < self->bufsize; i++)
2534 {
2535 inc = fr[i] * sizeOnSr;
2536 pha = ph[i] * size;
2537
2538 if (tr[i] == 1)
2539 self->pointerPos = 0.0;
2540 else
2541 {
2542 self->pointerPos += inc;
2543 self->pointerPos = Osc_clip(self->pointerPos, size);
2544 }
2545
2546 pos = self->pointerPos + pha;
2547
2548 if (pos >= size)
2549 pos -= size;
2550
2551 ipart = (T_SIZE_T)pos;
2552 fpart = pos - ipart;
2553 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
2554 }
2555 }
2556
2557 static void OscTrig_postprocessing_ii(OscTrig *self) { POST_PROCESSING_II };
2558 static void OscTrig_postprocessing_ai(OscTrig *self) { POST_PROCESSING_AI };
2559 static void OscTrig_postprocessing_ia(OscTrig *self) { POST_PROCESSING_IA };
2560 static void OscTrig_postprocessing_aa(OscTrig *self) { POST_PROCESSING_AA };
2561 static void OscTrig_postprocessing_ireva(OscTrig *self) { POST_PROCESSING_IREVA };
2562 static void OscTrig_postprocessing_areva(OscTrig *self) { POST_PROCESSING_AREVA };
2563 static void OscTrig_postprocessing_revai(OscTrig *self) { POST_PROCESSING_REVAI };
2564 static void OscTrig_postprocessing_revaa(OscTrig *self) { POST_PROCESSING_REVAA };
2565 static void OscTrig_postprocessing_revareva(OscTrig *self) { POST_PROCESSING_REVAREVA };
2566
2567 static void
2568 OscTrig_setProcMode(OscTrig *self)
2569 {
2570 int procmode, muladdmode;
2571 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
2572 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
2573
2574 switch (procmode)
2575 {
2576 case 0:
2577 self->proc_func_ptr = OscTrig_readframes_ii;
2578 break;
2579
2580 case 1:
2581 self->proc_func_ptr = OscTrig_readframes_ai;
2582 break;
2583
2584 case 10:
2585 self->proc_func_ptr = OscTrig_readframes_ia;
2586 break;
2587
2588 case 11:
2589 self->proc_func_ptr = OscTrig_readframes_aa;
2590 break;
2591 }
2592
2593 switch (muladdmode)
2594 {
2595 case 0:
2596 self->muladd_func_ptr = OscTrig_postprocessing_ii;
2597 break;
2598
2599 case 1:
2600 self->muladd_func_ptr = OscTrig_postprocessing_ai;
2601 break;
2602
2603 case 2:
2604 self->muladd_func_ptr = OscTrig_postprocessing_revai;
2605 break;
2606
2607 case 10:
2608 self->muladd_func_ptr = OscTrig_postprocessing_ia;
2609 break;
2610
2611 case 11:
2612 self->muladd_func_ptr = OscTrig_postprocessing_aa;
2613 break;
2614
2615 case 12:
2616 self->muladd_func_ptr = OscTrig_postprocessing_revaa;
2617 break;
2618
2619 case 20:
2620 self->muladd_func_ptr = OscTrig_postprocessing_ireva;
2621 break;
2622
2623 case 21:
2624 self->muladd_func_ptr = OscTrig_postprocessing_areva;
2625 break;
2626
2627 case 22:
2628 self->muladd_func_ptr = OscTrig_postprocessing_revareva;
2629 break;
2630 }
2631 }
2632
2633 static void
2634 OscTrig_compute_next_data_frame(OscTrig *self)
2635 {
2636 (*self->proc_func_ptr)(self);
2637 (*self->muladd_func_ptr)(self);
2638 }
2639
2640 static int
2641 OscTrig_traverse(OscTrig *self, visitproc visit, void *arg)
2642 {
2643 pyo_VISIT
2644 Py_VISIT(self->phase);
2645 Py_VISIT(self->freq);
2646 Py_VISIT(self->trig);
2647 return 0;
2648 }
2649
2650 static int
2651 OscTrig_clear(OscTrig *self)
2652 {
2653 pyo_CLEAR
2654 Py_CLEAR(self->phase);
2655 Py_CLEAR(self->freq);
2656 Py_CLEAR(self->trig);
2657 return 0;
2658 }
2659
2660 static void
2661 OscTrig_dealloc(OscTrig* self)
2662 {
2663 pyo_DEALLOC
2664 OscTrig_clear(self);
2665 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
2666 Py_TYPE(self)->tp_free((PyObject*)self);
2667 }
2668
2669 static PyObject *
2670 OscTrig_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2671 {
2672 int i;
2673 PyObject *tabletmp, *trigtmp, *freqtmp = NULL, *phasetmp = NULL, *multmp = NULL, *addtmp = NULL;
2674 OscTrig *self;
2675 self = (OscTrig *)type->tp_alloc(type, 0);
2676
2677 self->trig = PyFloat_FromDouble(0.0);
2678 self->freq = PyFloat_FromDouble(1000);
2679 self->phase = PyFloat_FromDouble(0);
2680 self->modebuffer[0] = 0;
2681 self->modebuffer[1] = 0;
2682 self->modebuffer[2] = 0;
2683 self->modebuffer[3] = 0;
2684 self->pointerPos = 0.;
2685 self->interp = 2;
2686
2687 INIT_OBJECT_COMMON
2688 Stream_setFunctionPtr(self->stream, OscTrig_compute_next_data_frame);
2689 self->mode_func_ptr = OscTrig_setProcMode;
2690
2691 static char *kwlist[] = {"table", "trig", "freq", "phase", "interp", "mul", "add", NULL};
2692
2693 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOiOO", kwlist, &tabletmp, &trigtmp, &freqtmp, &phasetmp, &self->interp, &multmp, &addtmp))
2694 Py_RETURN_NONE;
2695
2696 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
2697 {
2698 PyErr_SetString(PyExc_TypeError, "\"table\" argument of OscTrig must be a PyoTableObject.\n");
2699 Py_RETURN_NONE;
2700 }
2701
2702 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
2703
2704 if (trigtmp)
2705 {
2706 PyObject_CallMethod((PyObject *)self, "setTrig", "O", trigtmp);
2707 }
2708
2709 if (phasetmp)
2710 {
2711 PyObject_CallMethod((PyObject *)self, "setPhase", "O", phasetmp);
2712 }
2713
2714 if (freqtmp)
2715 {
2716 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
2717 }
2718
2719 if (multmp)
2720 {
2721 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
2722 }
2723
2724 if (addtmp)
2725 {
2726 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
2727 }
2728
2729 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
2730
2731 (*self->mode_func_ptr)(self);
2732
2733 SET_INTERP_POINTER
2734
2735 return (PyObject *)self;
2736 }
2737
2738 static PyObject * OscTrig_getServer(OscTrig* self) { GET_SERVER };
2739 static PyObject * OscTrig_getStream(OscTrig* self) { GET_STREAM };
2740 static PyObject * OscTrig_setMul(OscTrig *self, PyObject *arg) { SET_MUL };
2741 static PyObject * OscTrig_setAdd(OscTrig *self, PyObject *arg) { SET_ADD };
2742 static PyObject * OscTrig_setSub(OscTrig *self, PyObject *arg) { SET_SUB };
2743 static PyObject * OscTrig_setDiv(OscTrig *self, PyObject *arg) { SET_DIV };
2744
2745 static PyObject * OscTrig_play(OscTrig *self, PyObject *args, PyObject *kwds) { PLAY };
2746 static PyObject * OscTrig_out(OscTrig *self, PyObject *args, PyObject *kwds) { OUT };
2747 static PyObject * OscTrig_stop(OscTrig *self, PyObject *args, PyObject *kwds) { STOP };
2748
2749 static PyObject * OscTrig_multiply(OscTrig *self, PyObject *arg) { MULTIPLY };
2750 static PyObject * OscTrig_inplace_multiply(OscTrig *self, PyObject *arg) { INPLACE_MULTIPLY };
2751 static PyObject * OscTrig_add(OscTrig *self, PyObject *arg) { ADD };
2752 static PyObject * OscTrig_inplace_add(OscTrig *self, PyObject *arg) { INPLACE_ADD };
2753 static PyObject * OscTrig_sub(OscTrig *self, PyObject *arg) { SUB };
2754 static PyObject * OscTrig_inplace_sub(OscTrig *self, PyObject *arg) { INPLACE_SUB };
2755 static PyObject * OscTrig_div(OscTrig *self, PyObject *arg) { DIV };
2756 static PyObject * OscTrig_inplace_div(OscTrig *self, PyObject *arg) { INPLACE_DIV };
2757
2758 static PyObject *
2759 OscTrig_getTable(OscTrig* self)
2760 {
2761 Py_INCREF(self->table);
2762 return self->table;
2763 };
2764
2765 static PyObject *
2766 OscTrig_setTable(OscTrig *self, PyObject *arg)
2767 {
2768 ASSERT_ARG_NOT_NULL
2769
2770 Py_DECREF(self->table);
2771 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
2772
2773 Py_RETURN_NONE;
2774 }
2775
2776 static PyObject *
2777 OscTrig_setTrig(OscTrig *self, PyObject *arg)
2778 {
2779 ASSERT_ARG_NOT_NULL
2780
2781 if (PyObject_HasAttrString((PyObject *)arg, "server") == 0)
2782 {
2783 PyErr_SetString(PyExc_TypeError, "\"trig\" attribute of OscTrig must be a PyoObject.\n");
2784 Py_RETURN_NONE;
2785 }
2786
2787 Py_DECREF(self->trig);
2788
2789 self->trig = arg;
2790 Py_INCREF(self->trig);
2791 PyObject *streamtmp = PyObject_CallMethod((PyObject *)self->trig, "_getStream", NULL);
2792 self->trig_stream = (Stream *)streamtmp;
2793 Py_INCREF(self->trig_stream);
2794
2795 Py_RETURN_NONE;
2796 }
2797
2798 static PyObject * OscTrig_setFreq(OscTrig *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
2799 static PyObject * OscTrig_setPhase(OscTrig *self, PyObject *arg) { SET_PARAM(self->phase, self->phase_stream, 3); }
2800
2801 static PyObject *
2802 OscTrig_setInterp(OscTrig *self, PyObject *arg)
2803 {
2804 ASSERT_ARG_NOT_NULL
2805
2806 if (PyNumber_Check(arg))
2807 {
2808 self->interp = PyLong_AsLong(PyNumber_Long(arg));
2809 }
2810
2811 SET_INTERP_POINTER
2812
2813 Py_RETURN_NONE;
2814 }
2815
2816 static PyObject *
2817 OscTrig_reset(OscTrig *self)
2818 {
2819 self->pointerPos = 0.0;
2820 Py_RETURN_NONE;
2821 }
2822
2823 static PyMemberDef OscTrig_members[] =
2824 {
2825 {"server", T_OBJECT_EX, offsetof(OscTrig, server), 0, "Pyo server."},
2826 {"stream", T_OBJECT_EX, offsetof(OscTrig, stream), 0, "Stream object."},
2827 {"table", T_OBJECT_EX, offsetof(OscTrig, table), 0, "Waveform table."},
2828 {"trig", T_OBJECT_EX, offsetof(OscTrig, trig), 0, "Trigger signal."},
2829 {"freq", T_OBJECT_EX, offsetof(OscTrig, freq), 0, "Frequency in cycle per second."},
2830 {"phase", T_OBJECT_EX, offsetof(OscTrig, phase), 0, "OscTrigillator phase."},
2831 {"mul", T_OBJECT_EX, offsetof(OscTrig, mul), 0, "Mul factor."},
2832 {"add", T_OBJECT_EX, offsetof(OscTrig, add), 0, "Add factor."},
2833 {NULL} /* Sentinel */
2834 };
2835
2836 static PyMethodDef OscTrig_methods[] =
2837 {
2838 {"getTable", (PyCFunction)OscTrig_getTable, METH_NOARGS, "Returns waveform table object."},
2839 {"getServer", (PyCFunction)OscTrig_getServer, METH_NOARGS, "Returns server object."},
2840 {"_getStream", (PyCFunction)OscTrig_getStream, METH_NOARGS, "Returns stream object."},
2841 {"play", (PyCFunction)OscTrig_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
2842 {"out", (PyCFunction)OscTrig_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
2843 {"stop", (PyCFunction)OscTrig_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
2844 {"setTable", (PyCFunction)OscTrig_setTable, METH_O, "Sets oscillator table."},
2845 {"setTrig", (PyCFunction)OscTrig_setTrig, METH_O, "Sets the reset trigger signal."},
2846 {"setFreq", (PyCFunction)OscTrig_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
2847 {"setPhase", (PyCFunction)OscTrig_setPhase, METH_O, "Sets oscillator phase."},
2848 {"setInterp", (PyCFunction)OscTrig_setInterp, METH_O, "Sets oscillator interpolation mode."},
2849 {"reset", (PyCFunction)OscTrig_reset, METH_NOARGS, "Resets pointer position to 0."},
2850 {"setMul", (PyCFunction)OscTrig_setMul, METH_O, "Sets oscillator mul factor."},
2851 {"setAdd", (PyCFunction)OscTrig_setAdd, METH_O, "Sets oscillator add factor."},
2852 {"setSub", (PyCFunction)OscTrig_setSub, METH_O, "Sets oscillator inverse add factor."},
2853 {"setDiv", (PyCFunction)OscTrig_setDiv, METH_O, "Sets inverse mul factor."},
2854 {NULL} /* Sentinel */
2855 };
2856
2857 static PyNumberMethods OscTrig_as_number =
2858 {
2859 (binaryfunc)OscTrig_add, /*nb_add*/
2860 (binaryfunc)OscTrig_sub, /*nb_subtract*/
2861 (binaryfunc)OscTrig_multiply, /*nb_multiply*/
2862 0, /*nb_remainder*/
2863 0, /*nb_divmod*/
2864 0, /*nb_power*/
2865 0, /*nb_neg*/
2866 0, /*nb_pos*/
2867 0, /*(unaryfunc)array_abs,*/
2868 0, /*nb_nonzero*/
2869 0, /*nb_invert*/
2870 0, /*nb_lshift*/
2871 0, /*nb_rshift*/
2872 0, /*nb_and*/
2873 0, /*nb_xor*/
2874 0, /*nb_or*/
2875 0, /*nb_int*/
2876 0, /*nb_long*/
2877 0, /*nb_float*/
2878 (binaryfunc)OscTrig_inplace_add, /*inplace_add*/
2879 (binaryfunc)OscTrig_inplace_sub, /*inplace_subtract*/
2880 (binaryfunc)OscTrig_inplace_multiply, /*inplace_multiply*/
2881 0, /*inplace_remainder*/
2882 0, /*inplace_power*/
2883 0, /*inplace_lshift*/
2884 0, /*inplace_rshift*/
2885 0, /*inplace_and*/
2886 0, /*inplace_xor*/
2887 0, /*inplace_or*/
2888 0, /*nb_floor_divide*/
2889 (binaryfunc)OscTrig_div, /*nb_true_divide*/
2890 0, /*nb_inplace_floor_divide*/
2891 (binaryfunc)OscTrig_inplace_div, /*nb_inplace_true_divide*/
2892 0, /* nb_index */
2893 };
2894
2895 PyTypeObject OscTrigType =
2896 {
2897 PyVarObject_HEAD_INIT(NULL, 0)
2898 "_pyo.OscTrig_base", /*tp_name*/
2899 sizeof(OscTrig), /*tp_basicsize*/
2900 0, /*tp_itemsize*/
2901 (destructor)OscTrig_dealloc, /*tp_dealloc*/
2902 0, /*tp_print*/
2903 0, /*tp_getattr*/
2904 0, /*tp_setattr*/
2905 0, /*tp_as_async (tp_compare in Python 2)*/
2906 0, /*tp_repr*/
2907 &OscTrig_as_number, /*tp_as_number*/
2908 0, /*tp_as_sequence*/
2909 0, /*tp_as_mapping*/
2910 0, /*tp_hash */
2911 0, /*tp_call*/
2912 0, /*tp_str*/
2913 0, /*tp_getattro*/
2914 0, /*tp_setattro*/
2915 0, /*tp_as_buffer*/
2916 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2917 "OscTrig objects. Generates an oscillatory waveform with sample accurate reset signal.", /* tp_doc */
2918 (traverseproc)OscTrig_traverse, /* tp_traverse */
2919 (inquiry)OscTrig_clear, /* tp_clear */
2920 0, /* tp_richcompare */
2921 0, /* tp_weaklistoffset */
2922 0, /* tp_iter */
2923 0, /* tp_iternext */
2924 OscTrig_methods, /* tp_methods */
2925 OscTrig_members, /* tp_members */
2926 0, /* tp_getset */
2927 0, /* tp_base */
2928 0, /* tp_dict */
2929 0, /* tp_descr_get */
2930 0, /* tp_descr_set */
2931 0, /* tp_dictoffset */
2932 0, /* tp_init */
2933 0, /* tp_alloc */
2934 OscTrig_new, /* tp_new */
2935 };
2936
2937 /**************/
2938 /* Phasor object */
2939 /**************/
2940 typedef struct
2941 {
2942 pyo_audio_HEAD
2943 PyObject *freq;
2944 Stream *freq_stream;
2945 PyObject *phase;
2946 Stream *phase_stream;
2947 int modebuffer[4];
2948 double pointerPos;
2949 } Phasor;
2950
2951 static void
2952 Phasor_readframes_ii(Phasor *self)
2953 {
2954 MYFLT fr, ph;
2955 double inc, pos;
2956 int i;
2957
2958 fr = PyFloat_AS_DOUBLE(self->freq);
2959 ph = _clip(PyFloat_AS_DOUBLE(self->phase));
2960 inc = fr / self->sr;
2961
2962 for (i = 0; i < self->bufsize; i++)
2963 {
2964 pos = self->pointerPos + ph;
2965
2966 if (pos > 1)
2967 pos -= 1.0;
2968
2969 self->data[i] = pos;
2970
2971 self->pointerPos += inc;
2972
2973 if (self->pointerPos < 0)
2974 self->pointerPos += 1.0;
2975 else if (self->pointerPos >= 1)
2976 self->pointerPos -= 1.0;
2977 }
2978 }
2979
2980 static void
2981 Phasor_readframes_ai(Phasor *self)
2982 {
2983 MYFLT ph, oneOnSr;
2984 double inc, pos;
2985 int i;
2986
2987 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
2988 ph = _clip(PyFloat_AS_DOUBLE(self->phase));
2989
2990 oneOnSr = 1.0 / self->sr;
2991
2992 for (i = 0; i < self->bufsize; i++)
2993 {
2994 pos = self->pointerPos + ph;
2995
2996 if (pos > 1)
2997 pos -= 1.0;
2998
2999 self->data[i] = pos;
3000
3001 inc = fr[i] * oneOnSr;
3002 self->pointerPos += inc;
3003
3004 if (self->pointerPos < 0)
3005 self->pointerPos += 1.0;
3006 else if (self->pointerPos >= 1)
3007 self->pointerPos -= 1.0;
3008 }
3009 }
3010
3011 static void
3012 Phasor_readframes_ia(Phasor *self)
3013 {
3014 MYFLT fr, pha;
3015 double inc, pos;
3016 int i;
3017
3018 fr = PyFloat_AS_DOUBLE(self->freq);
3019 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
3020
3021 inc = fr / self->sr;
3022
3023 for (i = 0; i < self->bufsize; i++)
3024 {
3025 pha = _clip(ph[i]);
3026
3027 pos = self->pointerPos + pha;
3028
3029 if (pos > 1)
3030 pos -= 1.0;
3031
3032 self->data[i] = pos;
3033
3034 self->pointerPos += inc;
3035
3036 if (self->pointerPos < 0)
3037 self->pointerPos += 1.0;
3038 else if (self->pointerPos >= 1)
3039 self->pointerPos -= 1.0;
3040 }
3041 }
3042
3043 static void
3044 Phasor_readframes_aa(Phasor *self)
3045 {
3046 MYFLT pha, oneOnSr;
3047 double inc, pos;
3048 int i;
3049
3050 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
3051 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
3052
3053 oneOnSr = 1.0 / self->sr;
3054
3055 for (i = 0; i < self->bufsize; i++)
3056 {
3057 pha = _clip(ph[i]);
3058
3059 pos = self->pointerPos + pha;
3060
3061 if (pos > 1)
3062 pos -= 1.0;
3063
3064 self->data[i] = pos;
3065
3066 inc = fr[i] * oneOnSr;
3067 self->pointerPos += inc;
3068
3069 if (self->pointerPos < 0)
3070 self->pointerPos += 1.0;
3071 else if (self->pointerPos >= 1)
3072 self->pointerPos -= 1.0;
3073 }
3074 }
3075
3076 static void Phasor_postprocessing_ii(Phasor *self) { POST_PROCESSING_II };
3077 static void Phasor_postprocessing_ai(Phasor *self) { POST_PROCESSING_AI };
3078 static void Phasor_postprocessing_ia(Phasor *self) { POST_PROCESSING_IA };
3079 static void Phasor_postprocessing_aa(Phasor *self) { POST_PROCESSING_AA };
3080 static void Phasor_postprocessing_ireva(Phasor *self) { POST_PROCESSING_IREVA };
3081 static void Phasor_postprocessing_areva(Phasor *self) { POST_PROCESSING_AREVA };
3082 static void Phasor_postprocessing_revai(Phasor *self) { POST_PROCESSING_REVAI };
3083 static void Phasor_postprocessing_revaa(Phasor *self) { POST_PROCESSING_REVAA };
3084 static void Phasor_postprocessing_revareva(Phasor *self) { POST_PROCESSING_REVAREVA };
3085
3086 static void
3087 Phasor_setProcMode(Phasor *self)
3088 {
3089 int procmode, muladdmode;
3090 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
3091 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3092
3093 switch (procmode)
3094 {
3095 case 0:
3096 self->proc_func_ptr = Phasor_readframes_ii;
3097 break;
3098
3099 case 1:
3100 self->proc_func_ptr = Phasor_readframes_ai;
3101 break;
3102
3103 case 10:
3104 self->proc_func_ptr = Phasor_readframes_ia;
3105 break;
3106
3107 case 11:
3108 self->proc_func_ptr = Phasor_readframes_aa;
3109 break;
3110 }
3111
3112 switch (muladdmode)
3113 {
3114 case 0:
3115 self->muladd_func_ptr = Phasor_postprocessing_ii;
3116 break;
3117
3118 case 1:
3119 self->muladd_func_ptr = Phasor_postprocessing_ai;
3120 break;
3121
3122 case 2:
3123 self->muladd_func_ptr = Phasor_postprocessing_revai;
3124 break;
3125
3126 case 10:
3127 self->muladd_func_ptr = Phasor_postprocessing_ia;
3128 break;
3129
3130 case 11:
3131 self->muladd_func_ptr = Phasor_postprocessing_aa;
3132 break;
3133
3134 case 12:
3135 self->muladd_func_ptr = Phasor_postprocessing_revaa;
3136 break;
3137
3138 case 20:
3139 self->muladd_func_ptr = Phasor_postprocessing_ireva;
3140 break;
3141
3142 case 21:
3143 self->muladd_func_ptr = Phasor_postprocessing_areva;
3144 break;
3145
3146 case 22:
3147 self->muladd_func_ptr = Phasor_postprocessing_revareva;
3148 break;
3149 }
3150 }
3151
3152 static void
3153 Phasor_compute_next_data_frame(Phasor *self)
3154 {
3155 (*self->proc_func_ptr)(self);
3156 (*self->muladd_func_ptr)(self);
3157 }
3158
3159 static int
3160 Phasor_traverse(Phasor *self, visitproc visit, void *arg)
3161 {
3162 pyo_VISIT
3163 Py_VISIT(self->phase);
3164 Py_VISIT(self->freq);
3165 return 0;
3166 }
3167
3168 static int
3169 Phasor_clear(Phasor *self)
3170 {
3171 pyo_CLEAR
3172 Py_CLEAR(self->phase);
3173 Py_CLEAR(self->freq);
3174 return 0;
3175 }
3176
3177 static void
3178 Phasor_dealloc(Phasor* self)
3179 {
3180 pyo_DEALLOC
3181 Phasor_clear(self);
3182 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3183 Py_TYPE(self)->tp_free((PyObject*)self);
3184 }
3185
3186 static PyObject *
3187 Phasor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3188 {
3189 int i;
3190 PyObject *freqtmp = NULL, *phasetmp = NULL, *multmp = NULL, *addtmp = NULL;
3191 Phasor *self;
3192 self = (Phasor *)type->tp_alloc(type, 0);
3193
3194 self->freq = PyFloat_FromDouble(100);
3195 self->phase = PyFloat_FromDouble(0);
3196 self->modebuffer[0] = 0;
3197 self->modebuffer[1] = 0;
3198 self->modebuffer[2] = 0;
3199 self->modebuffer[3] = 0;
3200 self->pointerPos = 0.;
3201
3202 INIT_OBJECT_COMMON
3203 Stream_setFunctionPtr(self->stream, Phasor_compute_next_data_frame);
3204 self->mode_func_ptr = Phasor_setProcMode;
3205
3206 static char *kwlist[] = {"freq", "phase", "mul", "add", NULL};
3207
3208 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &freqtmp, &phasetmp, &multmp, &addtmp))
3209 Py_RETURN_NONE;
3210
3211 if (freqtmp)
3212 {
3213 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
3214 }
3215
3216 if (phasetmp)
3217 {
3218 PyObject_CallMethod((PyObject *)self, "setPhase", "O", phasetmp);
3219 }
3220
3221 if (multmp)
3222 {
3223 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3224 }
3225
3226 if (addtmp)
3227 {
3228 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3229 }
3230
3231 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3232
3233 (*self->mode_func_ptr)(self);
3234
3235 return (PyObject *)self;
3236 }
3237
3238 static PyObject * Phasor_getServer(Phasor* self) { GET_SERVER };
3239 static PyObject * Phasor_getStream(Phasor* self) { GET_STREAM };
3240 static PyObject * Phasor_setMul(Phasor *self, PyObject *arg) { SET_MUL };
3241 static PyObject * Phasor_setAdd(Phasor *self, PyObject *arg) { SET_ADD };
3242 static PyObject * Phasor_setSub(Phasor *self, PyObject *arg) { SET_SUB };
3243 static PyObject * Phasor_setDiv(Phasor *self, PyObject *arg) { SET_DIV };
3244
3245 static PyObject * Phasor_play(Phasor *self, PyObject *args, PyObject *kwds) { PLAY };
3246 static PyObject * Phasor_out(Phasor *self, PyObject *args, PyObject *kwds) { OUT };
3247 static PyObject * Phasor_stop(Phasor *self, PyObject *args, PyObject *kwds) { STOP };
3248
3249 static PyObject * Phasor_multiply(Phasor *self, PyObject *arg) { MULTIPLY };
3250 static PyObject * Phasor_inplace_multiply(Phasor *self, PyObject *arg) { INPLACE_MULTIPLY };
3251 static PyObject * Phasor_add(Phasor *self, PyObject *arg) { ADD };
3252 static PyObject * Phasor_inplace_add(Phasor *self, PyObject *arg) { INPLACE_ADD };
3253 static PyObject * Phasor_sub(Phasor *self, PyObject *arg) { SUB };
3254 static PyObject * Phasor_inplace_sub(Phasor *self, PyObject *arg) { INPLACE_SUB };
3255 static PyObject * Phasor_div(Phasor *self, PyObject *arg) { DIV };
3256 static PyObject * Phasor_inplace_div(Phasor *self, PyObject *arg) { INPLACE_DIV };
3257
3258 static PyObject * Phasor_setFreq(Phasor *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
3259 static PyObject * Phasor_setPhase(Phasor *self, PyObject *arg) { SET_PARAM(self->phase, self->phase_stream, 3); }
3260
3261 static PyObject *
3262 Phasor_reset(Phasor *self)
3263 {
3264 self->pointerPos = 0.0;
3265 Py_RETURN_NONE;
3266 }
3267
3268 static PyMemberDef Phasor_members[] =
3269 {
3270 {"server", T_OBJECT_EX, offsetof(Phasor, server), 0, "Pyo server."},
3271 {"stream", T_OBJECT_EX, offsetof(Phasor, stream), 0, "Stream object."},
3272 {"freq", T_OBJECT_EX, offsetof(Phasor, freq), 0, "Frequency in cycle per second."},
3273 {"phase", T_OBJECT_EX, offsetof(Phasor, phase), 0, "Phasorillator phase."},
3274 {"mul", T_OBJECT_EX, offsetof(Phasor, mul), 0, "Mul factor."},
3275 {"add", T_OBJECT_EX, offsetof(Phasor, add), 0, "Add factor."},
3276 {NULL} /* Sentinel */
3277 };
3278
3279 static PyMethodDef Phasor_methods[] =
3280 {
3281 {"getServer", (PyCFunction)Phasor_getServer, METH_NOARGS, "Returns server object."},
3282 {"_getStream", (PyCFunction)Phasor_getStream, METH_NOARGS, "Returns stream object."},
3283 {"play", (PyCFunction)Phasor_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3284 {"out", (PyCFunction)Phasor_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3285 {"stop", (PyCFunction)Phasor_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3286 {"setFreq", (PyCFunction)Phasor_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
3287 {"setPhase", (PyCFunction)Phasor_setPhase, METH_O, "Sets oscillator phase."},
3288 {"reset", (PyCFunction)Phasor_reset, METH_NOARGS, "Resets pointer position to 0."},
3289 {"setMul", (PyCFunction)Phasor_setMul, METH_O, "Sets oscillator mul factor."},
3290 {"setAdd", (PyCFunction)Phasor_setAdd, METH_O, "Sets oscillator add factor."},
3291 {"setSub", (PyCFunction)Phasor_setSub, METH_O, "Sets oscillator inverse add factor."},
3292 {"setDiv", (PyCFunction)Phasor_setDiv, METH_O, "Sets inverse mul factor."},
3293 {NULL} /* Sentinel */
3294 };
3295
3296 static PyNumberMethods Phasor_as_number =
3297 {
3298 (binaryfunc)Phasor_add, /*nb_add*/
3299 (binaryfunc)Phasor_sub, /*nb_subtract*/
3300 (binaryfunc)Phasor_multiply, /*nb_multiply*/
3301 0, /*nb_remainder*/
3302 0, /*nb_divmod*/
3303 0, /*nb_power*/
3304 0, /*nb_neg*/
3305 0, /*nb_pos*/
3306 0, /*(unaryfunc)array_abs,*/
3307 0, /*nb_nonzero*/
3308 0, /*nb_invert*/
3309 0, /*nb_lshift*/
3310 0, /*nb_rshift*/
3311 0, /*nb_and*/
3312 0, /*nb_xor*/
3313 0, /*nb_or*/
3314 0, /*nb_int*/
3315 0, /*nb_long*/
3316 0, /*nb_float*/
3317 (binaryfunc)Phasor_inplace_add, /*inplace_add*/
3318 (binaryfunc)Phasor_inplace_sub, /*inplace_subtract*/
3319 (binaryfunc)Phasor_inplace_multiply, /*inplace_multiply*/
3320 0, /*inplace_remainder*/
3321 0, /*inplace_power*/
3322 0, /*inplace_lshift*/
3323 0, /*inplace_rshift*/
3324 0, /*inplace_and*/
3325 0, /*inplace_xor*/
3326 0, /*inplace_or*/
3327 0, /*nb_floor_divide*/
3328 (binaryfunc)Phasor_div, /*nb_true_divide*/
3329 0, /*nb_inplace_floor_divide*/
3330 (binaryfunc)Phasor_inplace_div, /*nb_inplace_true_divide*/
3331 0, /* nb_index */
3332 };
3333
3334 PyTypeObject PhasorType =
3335 {
3336 PyVarObject_HEAD_INIT(NULL, 0)
3337 "_pyo.Phasor_base", /*tp_name*/
3338 sizeof(Phasor), /*tp_basicsize*/
3339 0, /*tp_itemsize*/
3340 (destructor)Phasor_dealloc, /*tp_dealloc*/
3341 0, /*tp_print*/
3342 0, /*tp_getattr*/
3343 0, /*tp_setattr*/
3344 0, /*tp_as_async (tp_compare in Python 2)*/
3345 0, /*tp_repr*/
3346 &Phasor_as_number, /*tp_as_number*/
3347 0, /*tp_as_sequence*/
3348 0, /*tp_as_mapping*/
3349 0, /*tp_hash */
3350 0, /*tp_call*/
3351 0, /*tp_str*/
3352 0, /*tp_getattro*/
3353 0, /*tp_setattro*/
3354 0, /*tp_as_buffer*/
3355 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3356 "Phasor objects. Phase incrementor from 0 to 1.", /* tp_doc */
3357 (traverseproc)Phasor_traverse, /* tp_traverse */
3358 (inquiry)Phasor_clear, /* tp_clear */
3359 0, /* tp_richcompare */
3360 0, /* tp_weaklistoffset */
3361 0, /* tp_iter */
3362 0, /* tp_iternext */
3363 Phasor_methods, /* tp_methods */
3364 Phasor_members, /* tp_members */
3365 0, /* tp_getset */
3366 0, /* tp_base */
3367 0, /* tp_dict */
3368 0, /* tp_descr_get */
3369 0, /* tp_descr_set */
3370 0, /* tp_dictoffset */
3371 0, /* tp_init */
3372 0, /* tp_alloc */
3373 Phasor_new, /* tp_new */
3374 };
3375
3376 /**************/
3377 /* Pointer object */
3378 /**************/
3379 typedef struct
3380 {
3381 pyo_audio_HEAD
3382 PyObject *table;
3383 PyObject *index;
3384 Stream *index_stream;
3385 int modebuffer[2];
3386 } Pointer;
3387
3388 static void
3389 Pointer_readframes_a(Pointer *self)
3390 {
3391 int i;
3392 MYFLT fpart;
3393 double ph;
3394 T_SIZE_T ipart;
3395 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
3396 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
3397
3398 MYFLT *pha = Stream_getData((Stream *)self->index_stream);
3399
3400 for (i = 0; i < self->bufsize; i++)
3401 {
3402 ph = Osc_clip(pha[i] * size, size);
3403 ipart = (T_SIZE_T)ph;
3404 fpart = ph - ipart;
3405 self->data[i] = tablelist[ipart] + (tablelist[ipart + 1] - tablelist[ipart]) * fpart;
3406 }
3407 }
3408
3409 static void Pointer_postprocessing_ii(Pointer *self) { POST_PROCESSING_II };
3410 static void Pointer_postprocessing_ai(Pointer *self) { POST_PROCESSING_AI };
3411 static void Pointer_postprocessing_ia(Pointer *self) { POST_PROCESSING_IA };
3412 static void Pointer_postprocessing_aa(Pointer *self) { POST_PROCESSING_AA };
3413 static void Pointer_postprocessing_ireva(Pointer *self) { POST_PROCESSING_IREVA };
3414 static void Pointer_postprocessing_areva(Pointer *self) { POST_PROCESSING_AREVA };
3415 static void Pointer_postprocessing_revai(Pointer *self) { POST_PROCESSING_REVAI };
3416 static void Pointer_postprocessing_revaa(Pointer *self) { POST_PROCESSING_REVAA };
3417 static void Pointer_postprocessing_revareva(Pointer *self) { POST_PROCESSING_REVAREVA };
3418
3419 static void
3420 Pointer_setProcMode(Pointer *self)
3421 {
3422 int muladdmode;
3423 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3424
3425 self->proc_func_ptr = Pointer_readframes_a;
3426
3427 switch (muladdmode)
3428 {
3429 case 0:
3430 self->muladd_func_ptr = Pointer_postprocessing_ii;
3431 break;
3432
3433 case 1:
3434 self->muladd_func_ptr = Pointer_postprocessing_ai;
3435 break;
3436
3437 case 2:
3438 self->muladd_func_ptr = Pointer_postprocessing_revai;
3439 break;
3440
3441 case 10:
3442 self->muladd_func_ptr = Pointer_postprocessing_ia;
3443 break;
3444
3445 case 11:
3446 self->muladd_func_ptr = Pointer_postprocessing_aa;
3447 break;
3448
3449 case 12:
3450 self->muladd_func_ptr = Pointer_postprocessing_revaa;
3451 break;
3452
3453 case 20:
3454 self->muladd_func_ptr = Pointer_postprocessing_ireva;
3455 break;
3456
3457 case 21:
3458 self->muladd_func_ptr = Pointer_postprocessing_areva;
3459 break;
3460
3461 case 22:
3462 self->muladd_func_ptr = Pointer_postprocessing_revareva;
3463 break;
3464 }
3465 }
3466
3467 static void
3468 Pointer_compute_next_data_frame(Pointer *self)
3469 {
3470 (*self->proc_func_ptr)(self);
3471 (*self->muladd_func_ptr)(self);
3472 }
3473
3474 static int
3475 Pointer_traverse(Pointer *self, visitproc visit, void *arg)
3476 {
3477 pyo_VISIT
3478 Py_VISIT(self->index);
3479 return 0;
3480 }
3481
3482 static int
3483 Pointer_clear(Pointer *self)
3484 {
3485 pyo_CLEAR
3486 Py_CLEAR(self->index);
3487 return 0;
3488 }
3489
3490 static void
3491 Pointer_dealloc(Pointer* self)
3492 {
3493 pyo_DEALLOC
3494 Pointer_clear(self);
3495 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3496 Py_TYPE(self)->tp_free((PyObject*)self);
3497 }
3498
3499 static PyObject *
3500 Pointer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3501 {
3502 int i;
3503 PyObject *tabletmp, *indextmp, *multmp = NULL, *addtmp = NULL;
3504 Pointer *self;
3505 self = (Pointer *)type->tp_alloc(type, 0);
3506
3507 self->index = PyFloat_FromDouble(0.0);
3508
3509 self->modebuffer[0] = 0;
3510 self->modebuffer[1] = 0;
3511
3512 INIT_OBJECT_COMMON
3513 Stream_setFunctionPtr(self->stream, Pointer_compute_next_data_frame);
3514 self->mode_func_ptr = Pointer_setProcMode;
3515
3516 static char *kwlist[] = {"table", "index", "mul", "add", NULL};
3517
3518 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO", kwlist, &tabletmp, &indextmp, &multmp, &addtmp))
3519 Py_RETURN_NONE;
3520
3521 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
3522 {
3523 PyErr_SetString(PyExc_TypeError, "\"table\" argument of Pointer must be a PyoTableObject.\n");
3524 Py_RETURN_NONE;
3525 }
3526
3527 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
3528
3529 if (indextmp)
3530 {
3531 PyObject_CallMethod((PyObject *)self, "setIndex", "O", indextmp);
3532 }
3533
3534 if (multmp)
3535 {
3536 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3537 }
3538
3539 if (addtmp)
3540 {
3541 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3542 }
3543
3544 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3545
3546 (*self->mode_func_ptr)(self);
3547
3548 return (PyObject *)self;
3549 }
3550
3551 static PyObject * Pointer_getServer(Pointer* self) { GET_SERVER };
3552 static PyObject * Pointer_getStream(Pointer* self) { GET_STREAM };
3553 static PyObject * Pointer_setMul(Pointer *self, PyObject *arg) { SET_MUL };
3554 static PyObject * Pointer_setAdd(Pointer *self, PyObject *arg) { SET_ADD };
3555 static PyObject * Pointer_setSub(Pointer *self, PyObject *arg) { SET_SUB };
3556 static PyObject * Pointer_setDiv(Pointer *self, PyObject *arg) { SET_DIV };
3557
3558 static PyObject * Pointer_play(Pointer *self, PyObject *args, PyObject *kwds) { PLAY };
3559 static PyObject * Pointer_out(Pointer *self, PyObject *args, PyObject *kwds) { OUT };
3560 static PyObject * Pointer_stop(Pointer *self, PyObject *args, PyObject *kwds) { STOP };
3561
3562 static PyObject * Pointer_multiply(Pointer *self, PyObject *arg) { MULTIPLY };
3563 static PyObject * Pointer_inplace_multiply(Pointer *self, PyObject *arg) { INPLACE_MULTIPLY };
3564 static PyObject * Pointer_add(Pointer *self, PyObject *arg) { ADD };
3565 static PyObject * Pointer_inplace_add(Pointer *self, PyObject *arg) { INPLACE_ADD };
3566 static PyObject * Pointer_sub(Pointer *self, PyObject *arg) { SUB };
3567 static PyObject * Pointer_inplace_sub(Pointer *self, PyObject *arg) { INPLACE_SUB };
3568 static PyObject * Pointer_div(Pointer *self, PyObject *arg) { DIV };
3569 static PyObject * Pointer_inplace_div(Pointer *self, PyObject *arg) { INPLACE_DIV };
3570
3571 static PyObject *
3572 Pointer_getTable(Pointer* self)
3573 {
3574 Py_INCREF(self->table);
3575 return self->table;
3576 };
3577
3578 static PyObject *
3579 Pointer_setTable(Pointer *self, PyObject *arg)
3580 {
3581 ASSERT_ARG_NOT_NULL
3582
3583 Py_DECREF(self->table);
3584 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
3585
3586 Py_RETURN_NONE;
3587 }
3588
3589 static PyObject *
3590 Pointer_setIndex(Pointer *self, PyObject *arg)
3591 {
3592 ASSERT_ARG_NOT_NULL
3593
3594 if (PyObject_HasAttrString((PyObject *)arg, "server") == 0)
3595 {
3596 PyErr_SetString(PyExc_TypeError, "\"index\" argument of Pointer must be a PyoObject.\n");
3597 Py_RETURN_NONE;
3598 }
3599
3600 Py_DECREF(self->index);
3601
3602 self->index = arg;
3603 Py_INCREF(self->index);
3604 PyObject *streamtmp = PyObject_CallMethod((PyObject *)self->index, "_getStream", NULL);
3605 self->index_stream = (Stream *)streamtmp;
3606 Py_INCREF(self->index_stream);
3607
3608 Py_RETURN_NONE;
3609 }
3610
3611 static PyMemberDef Pointer_members[] =
3612 {
3613 {"server", T_OBJECT_EX, offsetof(Pointer, server), 0, "Pyo server."},
3614 {"stream", T_OBJECT_EX, offsetof(Pointer, stream), 0, "Stream object."},
3615 {"table", T_OBJECT_EX, offsetof(Pointer, table), 0, "Waveform table."},
3616 {"index", T_OBJECT_EX, offsetof(Pointer, index), 0, "Reader index."},
3617 {"mul", T_OBJECT_EX, offsetof(Pointer, mul), 0, "Mul factor."},
3618 {"add", T_OBJECT_EX, offsetof(Pointer, add), 0, "Add factor."},
3619 {NULL} /* Sentinel */
3620 };
3621
3622 static PyMethodDef Pointer_methods[] =
3623 {
3624 {"getTable", (PyCFunction)Pointer_getTable, METH_NOARGS, "Returns waveform table object."},
3625 {"getServer", (PyCFunction)Pointer_getServer, METH_NOARGS, "Returns server object."},
3626 {"_getStream", (PyCFunction)Pointer_getStream, METH_NOARGS, "Returns stream object."},
3627 {"play", (PyCFunction)Pointer_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
3628 {"out", (PyCFunction)Pointer_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
3629 {"stop", (PyCFunction)Pointer_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
3630 {"setTable", (PyCFunction)Pointer_setTable, METH_O, "Sets oscillator table."},
3631 {"setIndex", (PyCFunction)Pointer_setIndex, METH_O, "Sets reader index."},
3632 {"setMul", (PyCFunction)Pointer_setMul, METH_O, "Sets oscillator mul factor."},
3633 {"setAdd", (PyCFunction)Pointer_setAdd, METH_O, "Sets oscillator add factor."},
3634 {"setSub", (PyCFunction)Pointer_setSub, METH_O, "Sets oscillator inverse add factor."},
3635 {"setDiv", (PyCFunction)Pointer_setDiv, METH_O, "Sets inverse mul factor."},
3636 {NULL} /* Sentinel */
3637 };
3638
3639 static PyNumberMethods Pointer_as_number =
3640 {
3641 (binaryfunc)Pointer_add, /*nb_add*/
3642 (binaryfunc)Pointer_sub, /*nb_subtract*/
3643 (binaryfunc)Pointer_multiply, /*nb_multiply*/
3644 0, /*nb_remainder*/
3645 0, /*nb_divmod*/
3646 0, /*nb_power*/
3647 0, /*nb_neg*/
3648 0, /*nb_pos*/
3649 0, /*(unaryfunc)array_abs,*/
3650 0, /*nb_nonzero*/
3651 0, /*nb_invert*/
3652 0, /*nb_lshift*/
3653 0, /*nb_rshift*/
3654 0, /*nb_and*/
3655 0, /*nb_xor*/
3656 0, /*nb_or*/
3657 0, /*nb_int*/
3658 0, /*nb_long*/
3659 0, /*nb_float*/
3660 (binaryfunc)Pointer_inplace_add, /*inplace_add*/
3661 (binaryfunc)Pointer_inplace_sub, /*inplace_subtract*/
3662 (binaryfunc)Pointer_inplace_multiply, /*inplace_multiply*/
3663 0, /*inplace_remainder*/
3664 0, /*inplace_power*/
3665 0, /*inplace_lshift*/
3666 0, /*inplace_rshift*/
3667 0, /*inplace_and*/
3668 0, /*inplace_xor*/
3669 0, /*inplace_or*/
3670 0, /*nb_floor_divide*/
3671 (binaryfunc)Pointer_div, /*nb_true_divide*/
3672 0, /*nb_inplace_floor_divide*/
3673 (binaryfunc)Pointer_inplace_div, /*nb_inplace_true_divide*/
3674 0, /* nb_index */
3675 };
3676
3677 PyTypeObject PointerType =
3678 {
3679 PyVarObject_HEAD_INIT(NULL, 0)
3680 "_pyo.Pointer_base", /*tp_name*/
3681 sizeof(Pointer), /*tp_basicsize*/
3682 0, /*tp_itemsize*/
3683 (destructor)Pointer_dealloc, /*tp_dealloc*/
3684 0, /*tp_print*/
3685 0, /*tp_getattr*/
3686 0, /*tp_setattr*/
3687 0, /*tp_as_async (tp_compare in Python 2)*/
3688 0, /*tp_repr*/
3689 &Pointer_as_number, /*tp_as_number*/
3690 0, /*tp_as_sequence*/
3691 0, /*tp_as_mapping*/
3692 0, /*tp_hash */
3693 0, /*tp_call*/
3694 0, /*tp_str*/
3695 0, /*tp_getattro*/
3696 0, /*tp_setattro*/
3697 0, /*tp_as_buffer*/
3698 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3699 "Pointer objects. Read a waveform table with a pointer index.", /* tp_doc */
3700 (traverseproc)Pointer_traverse, /* tp_traverse */
3701 (inquiry)Pointer_clear, /* tp_clear */
3702 0, /* tp_richcompare */
3703 0, /* tp_weaklistoffset */
3704 0, /* tp_iter */
3705 0, /* tp_iternext */
3706 Pointer_methods, /* tp_methods */
3707 Pointer_members, /* tp_members */
3708 0, /* tp_getset */
3709 0, /* tp_base */
3710 0, /* tp_dict */
3711 0, /* tp_descr_get */
3712 0, /* tp_descr_set */
3713 0, /* tp_dictoffset */
3714 0, /* tp_init */
3715 0, /* tp_alloc */
3716 Pointer_new, /* tp_new */
3717 };
3718
3719 /**************/
3720 /* Pointer2 object */
3721 /**************/
3722 typedef struct
3723 {
3724 pyo_audio_HEAD
3725 PyObject *table;
3726 PyObject *index;
3727 Stream *index_stream;
3728 int modebuffer[2];
3729 int interp; /* 0 = default to 2, 1 = nointerp, 2 = linear, 3 = cos, 4 = cubic */
3730 int autosmooth; /* 0 = off, > 0 = on */
3731 MYFLT y1;
3732 MYFLT y2;
3733 MYFLT lastPh;
3734 MYFLT mTwoPiOverSr;
3735 MYFLT (*interp_func_ptr)(MYFLT *, T_SIZE_T, MYFLT, T_SIZE_T);
3736 } Pointer2;
3737
3738 static void
3739 Pointer2_readframes_a(Pointer2 *self)
3740 {
3741 int i;
3742 MYFLT fpart, phdiff, c, fr;
3743 double ph;
3744 T_SIZE_T ipart;
3745 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
3746 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
3747 double tableSr = TableStream_getSamplingRate((TableStream *)self->table);
3748
3749 MYFLT *pha = Stream_getData((Stream *)self->index_stream);
3750
3751 if (!self->autosmooth)
3752 {
3753 for (i = 0; i < self->bufsize; i++)
3754 {
3755 ph = Osc_clip(pha[i] * size, size);
3756 ipart = (T_SIZE_T)ph;
3757 fpart = ph - ipart;
3758 self->y1 = self->y2 = self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
3759 }
3760 }
3761 else
3762 {
3763 for (i = 0; i < self->bufsize; i++)
3764 {
3765 ph = Osc_clip(pha[i] * size, size);
3766 ipart = (T_SIZE_T)ph;
3767 fpart = ph - ipart;
3768 self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
3769 phdiff = fabs(ph - self->lastPh);
3770 self->lastPh = ph;
3771
3772 if (phdiff < 1)
3773 {
3774 fr = phdiff * tableSr * 0.45;
3775 c = MYEXP(self->mTwoPiOverSr * fr);
3776 self->y1 = self->data[i] + (self->y1 - self->data[i]) * c;
3777 self->data[i] = self->y2 = self->y1 + (self->y2 - self->y1) * c;
3778 }
3779 else
3780 self->y1 = self->y2 = self->data[i];
3781 }
3782 }
3783 }
3784
3785 static void Pointer2_postprocessing_ii(Pointer2 *self) { POST_PROCESSING_II };
3786 static void Pointer2_postprocessing_ai(Pointer2 *self) { POST_PROCESSING_AI };
3787 static void Pointer2_postprocessing_ia(Pointer2 *self) { POST_PROCESSING_IA };
3788 static void Pointer2_postprocessing_aa(Pointer2 *self) { POST_PROCESSING_AA };
3789 static void Pointer2_postprocessing_ireva(Pointer2 *self) { POST_PROCESSING_IREVA };
3790 static void Pointer2_postprocessing_areva(Pointer2 *self) { POST_PROCESSING_AREVA };
3791 static void Pointer2_postprocessing_revai(Pointer2 *self) { POST_PROCESSING_REVAI };
3792 static void Pointer2_postprocessing_revaa(Pointer2 *self) { POST_PROCESSING_REVAA };
3793 static void Pointer2_postprocessing_revareva(Pointer2 *self) { POST_PROCESSING_REVAREVA };
3794
3795 static void
3796 Pointer2_setProcMode(Pointer2 *self)
3797 {
3798 int muladdmode;
3799 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
3800
3801 self->proc_func_ptr = Pointer2_readframes_a;
3802
3803 switch (muladdmode)
3804 {
3805 case 0:
3806 self->muladd_func_ptr = Pointer2_postprocessing_ii;
3807 break;
3808
3809 case 1:
3810 self->muladd_func_ptr = Pointer2_postprocessing_ai;
3811 break;
3812
3813 case 2:
3814 self->muladd_func_ptr = Pointer2_postprocessing_revai;
3815 break;
3816
3817 case 10:
3818 self->muladd_func_ptr = Pointer2_postprocessing_ia;
3819 break;
3820
3821 case 11:
3822 self->muladd_func_ptr = Pointer2_postprocessing_aa;
3823 break;
3824
3825 case 12:
3826 self->muladd_func_ptr = Pointer2_postprocessing_revaa;
3827 break;
3828
3829 case 20:
3830 self->muladd_func_ptr = Pointer2_postprocessing_ireva;
3831 break;
3832
3833 case 21:
3834 self->muladd_func_ptr = Pointer2_postprocessing_areva;
3835 break;
3836
3837 case 22:
3838 self->muladd_func_ptr = Pointer2_postprocessing_revareva;
3839 break;
3840 }
3841 }
3842
3843 static void
3844 Pointer2_compute_next_data_frame(Pointer2 *self)
3845 {
3846 (*self->proc_func_ptr)(self);
3847 (*self->muladd_func_ptr)(self);
3848 }
3849
3850 static int
3851 Pointer2_traverse(Pointer2 *self, visitproc visit, void *arg)
3852 {
3853 pyo_VISIT
3854 Py_VISIT(self->index);
3855 return 0;
3856 }
3857
3858 static int
3859 Pointer2_clear(Pointer2 *self)
3860 {
3861 pyo_CLEAR
3862 Py_CLEAR(self->index);
3863 return 0;
3864 }
3865
3866 static void
3867 Pointer2_dealloc(Pointer2* self)
3868 {
3869 pyo_DEALLOC
3870 Pointer2_clear(self);
3871 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
3872 Py_TYPE(self)->tp_free((PyObject*)self);
3873 }
3874
3875 static PyObject *
3876 Pointer2_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3877 {
3878 int i;
3879 PyObject *tabletmp, *indextmp, *multmp = NULL, *addtmp = NULL;
3880 Pointer2 *self;
3881 self = (Pointer2 *)type->tp_alloc(type, 0);
3882
3883 self->index = PyFloat_FromDouble(0.0);
3884
3885 self->modebuffer[0] = 0;
3886 self->modebuffer[1] = 0;
3887 self->interp = 4;
3888 self->autosmooth = 1;
3889 self->y1 = self->y2 = self->lastPh = 0.0;
3890
3891 INIT_OBJECT_COMMON
3892 Stream_setFunctionPtr(self->stream, Pointer2_compute_next_data_frame);
3893 self->mode_func_ptr = Pointer2_setProcMode;
3894
3895 self->mTwoPiOverSr = -TWOPI / self->sr;
3896
3897 static char *kwlist[] = {"table", "index", "interp", "autosmooth", "mul", "add", NULL};
3898
3899 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|iiOO", kwlist, &tabletmp, &indextmp, &self->interp, &self->autosmooth, &multmp, &addtmp))
3900 Py_RETURN_NONE;
3901
3902 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
3903 {
3904 PyErr_SetString(PyExc_TypeError, "\"table\" argument of Pointer2 must be a PyoTableObject.\n");
3905 Py_RETURN_NONE;
3906 }
3907
3908 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
3909
3910 if (indextmp)
3911 {
3912 PyObject_CallMethod((PyObject *)self, "setIndex", "O", indextmp);
3913 }
3914
3915 if (multmp)
3916 {
3917 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
3918 }
3919
3920 if (addtmp)
3921 {
3922 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
3923 }
3924
3925 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
3926
3927 (*self->mode_func_ptr)(self);
3928
3929 SET_INTERP_POINTER
3930
3931 return (PyObject *)self;
3932 }
3933
3934 static PyObject * Pointer2_getServer(Pointer2* self) { GET_SERVER };
3935 static PyObject * Pointer2_getStream(Pointer2* self) { GET_STREAM };
3936 static PyObject * Pointer2_setMul(Pointer2 *self, PyObject *arg) { SET_MUL };
3937 static PyObject * Pointer2_setAdd(Pointer2 *self, PyObject *arg) { SET_ADD };
3938 static PyObject * Pointer2_setSub(Pointer2 *self, PyObject *arg) { SET_SUB };
3939 static PyObject * Pointer2_setDiv(Pointer2 *self, PyObject *arg) { SET_DIV };
3940
3941 static PyObject * Pointer2_play(Pointer2 *self, PyObject *args, PyObject *kwds) { PLAY };
3942 static PyObject * Pointer2_out(Pointer2 *self, PyObject *args, PyObject *kwds) { OUT };
3943 static PyObject * Pointer2_stop(Pointer2 *self, PyObject *args, PyObject *kwds) { STOP };
3944
3945 static PyObject * Pointer2_multiply(Pointer2 *self, PyObject *arg) { MULTIPLY };
3946 static PyObject * Pointer2_inplace_multiply(Pointer2 *self, PyObject *arg) { INPLACE_MULTIPLY };
3947 static PyObject * Pointer2_add(Pointer2 *self, PyObject *arg) { ADD };
3948 static PyObject * Pointer2_inplace_add(Pointer2 *self, PyObject *arg) { INPLACE_ADD };
3949 static PyObject * Pointer2_sub(Pointer2 *self, PyObject *arg) { SUB };
3950 static PyObject * Pointer2_inplace_sub(Pointer2 *self, PyObject *arg) { INPLACE_SUB };
3951 static PyObject * Pointer2_div(Pointer2 *self, PyObject *arg) { DIV };
3952 static PyObject * Pointer2_inplace_div(Pointer2 *self, PyObject *arg) { INPLACE_DIV };
3953
3954 static PyObject *
3955 Pointer2_getTable(Pointer2* self)
3956 {
3957 Py_INCREF(self->table);
3958 return self->table;
3959 };
3960
3961 static PyObject *
3962 Pointer2_setTable(Pointer2 *self, PyObject *arg)
3963 {
3964 ASSERT_ARG_NOT_NULL
3965
3966 Py_DECREF(self->table);
3967 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
3968
3969 Py_RETURN_NONE;
3970 }
3971
3972 static PyObject *
3973 Pointer2_setIndex(Pointer2 *self, PyObject *arg)
3974 {
3975 ASSERT_ARG_NOT_NULL
3976
3977 if (PyObject_HasAttrString((PyObject *)arg, "server") == 0)
3978 {
3979 PyErr_SetString(PyExc_TypeError, "\"index\" argument of Pointer2 must be a PyoObject.\n");
3980 Py_RETURN_NONE;
3981 }
3982
3983 Py_DECREF(self->index);
3984
3985 self->index = arg;
3986 Py_INCREF(self->index);
3987 PyObject *streamtmp = PyObject_CallMethod((PyObject *)self->index, "_getStream", NULL);
3988 self->index_stream = (Stream *)streamtmp;
3989 Py_INCREF(self->index_stream);
3990
3991 Py_RETURN_NONE;
3992 }
3993
3994 static PyObject *
3995 Pointer2_setInterp(Pointer2 *self, PyObject *arg)
3996 {
3997 ASSERT_ARG_NOT_NULL
3998
3999 if (PyNumber_Check(arg))
4000 {
4001 self->interp = PyLong_AsLong(PyNumber_Long(arg));
4002 }
4003
4004 SET_INTERP_POINTER
4005
4006 Py_RETURN_NONE;
4007 }
4008
4009 static PyObject *
4010 Pointer2_setAutoSmooth(Pointer2 *self, PyObject *arg)
4011 {
4012 ASSERT_ARG_NOT_NULL
4013
4014 if (PyNumber_Check(arg))
4015 {
4016 self->autosmooth = PyLong_AsLong(PyNumber_Long(arg));
4017 }
4018
4019 Py_RETURN_NONE;
4020 }
4021
4022 static PyMemberDef Pointer2_members[] =
4023 {
4024 {"server", T_OBJECT_EX, offsetof(Pointer2, server), 0, "Pyo server."},
4025 {"stream", T_OBJECT_EX, offsetof(Pointer2, stream), 0, "Stream object."},
4026 {"table", T_OBJECT_EX, offsetof(Pointer2, table), 0, "Waveform table."},
4027 {"index", T_OBJECT_EX, offsetof(Pointer2, index), 0, "Reader index."},
4028 {"mul", T_OBJECT_EX, offsetof(Pointer2, mul), 0, "Mul factor."},
4029 {"add", T_OBJECT_EX, offsetof(Pointer2, add), 0, "Add factor."},
4030 {NULL} /* Sentinel */
4031 };
4032
4033 static PyMethodDef Pointer2_methods[] =
4034 {
4035 {"getTable", (PyCFunction)Pointer2_getTable, METH_NOARGS, "Returns waveform table object."},
4036 {"getServer", (PyCFunction)Pointer2_getServer, METH_NOARGS, "Returns server object."},
4037 {"_getStream", (PyCFunction)Pointer2_getStream, METH_NOARGS, "Returns stream object."},
4038 {"play", (PyCFunction)Pointer2_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4039 {"out", (PyCFunction)Pointer2_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4040 {"stop", (PyCFunction)Pointer2_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4041 {"setTable", (PyCFunction)Pointer2_setTable, METH_O, "Sets oscillator table."},
4042 {"setIndex", (PyCFunction)Pointer2_setIndex, METH_O, "Sets reader index."},
4043 {"setInterp", (PyCFunction)Pointer2_setInterp, METH_O, "Sets oscillator interpolation mode."},
4044 {"setAutoSmooth", (PyCFunction)Pointer2_setAutoSmooth, METH_O, "Activates auto smoother filter."},
4045 {"setMul", (PyCFunction)Pointer2_setMul, METH_O, "Sets oscillator mul factor."},
4046 {"setAdd", (PyCFunction)Pointer2_setAdd, METH_O, "Sets oscillator add factor."},
4047 {"setSub", (PyCFunction)Pointer2_setSub, METH_O, "Sets oscillator inverse add factor."},
4048 {"setDiv", (PyCFunction)Pointer2_setDiv, METH_O, "Sets inverse mul factor."},
4049 {NULL} /* Sentinel */
4050 };
4051
4052 static PyNumberMethods Pointer2_as_number =
4053 {
4054 (binaryfunc)Pointer2_add, /*nb_add*/
4055 (binaryfunc)Pointer2_sub, /*nb_subtract*/
4056 (binaryfunc)Pointer2_multiply, /*nb_multiply*/
4057 0, /*nb_remainder*/
4058 0, /*nb_divmod*/
4059 0, /*nb_power*/
4060 0, /*nb_neg*/
4061 0, /*nb_pos*/
4062 0, /*(unaryfunc)array_abs,*/
4063 0, /*nb_nonzero*/
4064 0, /*nb_invert*/
4065 0, /*nb_lshift*/
4066 0, /*nb_rshift*/
4067 0, /*nb_and*/
4068 0, /*nb_xor*/
4069 0, /*nb_or*/
4070 0, /*nb_int*/
4071 0, /*nb_long*/
4072 0, /*nb_float*/
4073 (binaryfunc)Pointer2_inplace_add, /*inplace_add*/
4074 (binaryfunc)Pointer2_inplace_sub, /*inplace_subtract*/
4075 (binaryfunc)Pointer2_inplace_multiply, /*inplace_multiply*/
4076 0, /*inplace_remainder*/
4077 0, /*inplace_power*/
4078 0, /*inplace_lshift*/
4079 0, /*inplace_rshift*/
4080 0, /*inplace_and*/
4081 0, /*inplace_xor*/
4082 0, /*inplace_or*/
4083 0, /*nb_floor_divide*/
4084 (binaryfunc)Pointer2_div, /*nb_true_divide*/
4085 0, /*nb_inplace_floor_divide*/
4086 (binaryfunc)Pointer2_inplace_div, /*nb_inplace_true_divide*/
4087 0, /* nb_index */
4088 };
4089
4090 PyTypeObject Pointer2Type =
4091 {
4092 PyVarObject_HEAD_INIT(NULL, 0)
4093 "_pyo.Pointer2_base", /*tp_name*/
4094 sizeof(Pointer2), /*tp_basicsize*/
4095 0, /*tp_itemsize*/
4096 (destructor)Pointer2_dealloc, /*tp_dealloc*/
4097 0, /*tp_print*/
4098 0, /*tp_getattr*/
4099 0, /*tp_setattr*/
4100 0, /*tp_as_async (tp_compare in Python 2)*/
4101 0, /*tp_repr*/
4102 &Pointer2_as_number, /*tp_as_number*/
4103 0, /*tp_as_sequence*/
4104 0, /*tp_as_mapping*/
4105 0, /*tp_hash */
4106 0, /*tp_call*/
4107 0, /*tp_str*/
4108 0, /*tp_getattro*/
4109 0, /*tp_setattro*/
4110 0, /*tp_as_buffer*/
4111 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4112 "Pointer2 objects. High quality table reader with a pointer index.", /* tp_doc */
4113 (traverseproc)Pointer2_traverse, /* tp_traverse */
4114 (inquiry)Pointer2_clear, /* tp_clear */
4115 0, /* tp_richcompare */
4116 0, /* tp_weaklistoffset */
4117 0, /* tp_iter */
4118 0, /* tp_iternext */
4119 Pointer2_methods, /* tp_methods */
4120 Pointer2_members, /* tp_members */
4121 0, /* tp_getset */
4122 0, /* tp_base */
4123 0, /* tp_dict */
4124 0, /* tp_descr_get */
4125 0, /* tp_descr_set */
4126 0, /* tp_dictoffset */
4127 0, /* tp_init */
4128 0, /* tp_alloc */
4129 Pointer2_new, /* tp_new */
4130 };
4131
4132 /**************/
4133 /* TableIndex object */
4134 /**************/
4135 typedef struct
4136 {
4137 pyo_audio_HEAD
4138 PyObject *table;
4139 PyObject *index;
4140 Stream *index_stream;
4141 int modebuffer[2];
4142 } TableIndex;
4143
4144 static void
4145 TableIndex_readframes_a(TableIndex *self)
4146 {
4147 int i;
4148 T_SIZE_T ind;
4149 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
4150 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
4151
4152 MYFLT *phase = Stream_getData((Stream *)self->index_stream);
4153
4154 for (i = 0; i < self->bufsize; i++)
4155 {
4156 ind = (T_SIZE_T)phase[i];
4157
4158 if (ind < 0)
4159 ind = 0;
4160 else if (ind >= size)
4161 ind = size - 1;
4162
4163 self->data[i] = tablelist[ind];
4164 }
4165 }
4166
4167 static void TableIndex_postprocessing_ii(TableIndex *self) { POST_PROCESSING_II };
4168 static void TableIndex_postprocessing_ai(TableIndex *self) { POST_PROCESSING_AI };
4169 static void TableIndex_postprocessing_ia(TableIndex *self) { POST_PROCESSING_IA };
4170 static void TableIndex_postprocessing_aa(TableIndex *self) { POST_PROCESSING_AA };
4171 static void TableIndex_postprocessing_ireva(TableIndex *self) { POST_PROCESSING_IREVA };
4172 static void TableIndex_postprocessing_areva(TableIndex *self) { POST_PROCESSING_AREVA };
4173 static void TableIndex_postprocessing_revai(TableIndex *self) { POST_PROCESSING_REVAI };
4174 static void TableIndex_postprocessing_revaa(TableIndex *self) { POST_PROCESSING_REVAA };
4175 static void TableIndex_postprocessing_revareva(TableIndex *self) { POST_PROCESSING_REVAREVA };
4176
4177 static void
4178 TableIndex_setProcMode(TableIndex *self)
4179 {
4180 int muladdmode;
4181 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4182
4183 self->proc_func_ptr = TableIndex_readframes_a;
4184
4185 switch (muladdmode)
4186 {
4187 case 0:
4188 self->muladd_func_ptr = TableIndex_postprocessing_ii;
4189 break;
4190
4191 case 1:
4192 self->muladd_func_ptr = TableIndex_postprocessing_ai;
4193 break;
4194
4195 case 2:
4196 self->muladd_func_ptr = TableIndex_postprocessing_revai;
4197 break;
4198
4199 case 10:
4200 self->muladd_func_ptr = TableIndex_postprocessing_ia;
4201 break;
4202
4203 case 11:
4204 self->muladd_func_ptr = TableIndex_postprocessing_aa;
4205 break;
4206
4207 case 12:
4208 self->muladd_func_ptr = TableIndex_postprocessing_revaa;
4209 break;
4210
4211 case 20:
4212 self->muladd_func_ptr = TableIndex_postprocessing_ireva;
4213 break;
4214
4215 case 21:
4216 self->muladd_func_ptr = TableIndex_postprocessing_areva;
4217 break;
4218
4219 case 22:
4220 self->muladd_func_ptr = TableIndex_postprocessing_revareva;
4221 break;
4222 }
4223 }
4224
4225 static void
4226 TableIndex_compute_next_data_frame(TableIndex *self)
4227 {
4228 (*self->proc_func_ptr)(self);
4229 (*self->muladd_func_ptr)(self);
4230 }
4231
4232 static int
4233 TableIndex_traverse(TableIndex *self, visitproc visit, void *arg)
4234 {
4235 pyo_VISIT
4236 Py_VISIT(self->index);
4237 return 0;
4238 }
4239
4240 static int
4241 TableIndex_clear(TableIndex *self)
4242 {
4243 pyo_CLEAR
4244 Py_CLEAR(self->index);
4245 return 0;
4246 }
4247
4248 static void
4249 TableIndex_dealloc(TableIndex* self)
4250 {
4251 pyo_DEALLOC
4252 TableIndex_clear(self);
4253 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4254 Py_TYPE(self)->tp_free((PyObject*)self);
4255 }
4256
4257 static PyObject *
4258 TableIndex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4259 {
4260 int i;
4261 PyObject *tabletmp, *indextmp, *multmp = NULL, *addtmp = NULL;
4262 TableIndex *self;
4263 self = (TableIndex *)type->tp_alloc(type, 0);
4264
4265 self->index = PyFloat_FromDouble(0.0);
4266
4267 self->modebuffer[0] = 0;
4268 self->modebuffer[1] = 0;
4269
4270 INIT_OBJECT_COMMON
4271 Stream_setFunctionPtr(self->stream, TableIndex_compute_next_data_frame);
4272 self->mode_func_ptr = TableIndex_setProcMode;
4273
4274 static char *kwlist[] = {"table", "index", "mul", "add", NULL};
4275
4276 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO", kwlist, &tabletmp, &indextmp, &multmp, &addtmp))
4277 Py_RETURN_NONE;
4278
4279 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
4280 {
4281 PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableIndex must be a PyoTableObject.\n");
4282 Py_RETURN_NONE;
4283 }
4284
4285 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
4286
4287 if (indextmp)
4288 {
4289 PyObject_CallMethod((PyObject *)self, "setIndex", "O", indextmp);
4290 }
4291
4292 if (multmp)
4293 {
4294 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4295 }
4296
4297 if (addtmp)
4298 {
4299 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4300 }
4301
4302 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4303
4304 (*self->mode_func_ptr)(self);
4305
4306 return (PyObject *)self;
4307 }
4308
4309 static PyObject * TableIndex_getServer(TableIndex* self) { GET_SERVER };
4310 static PyObject * TableIndex_getStream(TableIndex* self) { GET_STREAM };
4311 static PyObject * TableIndex_setMul(TableIndex *self, PyObject *arg) { SET_MUL };
4312 static PyObject * TableIndex_setAdd(TableIndex *self, PyObject *arg) { SET_ADD };
4313 static PyObject * TableIndex_setSub(TableIndex *self, PyObject *arg) { SET_SUB };
4314 static PyObject * TableIndex_setDiv(TableIndex *self, PyObject *arg) { SET_DIV };
4315
4316 static PyObject * TableIndex_play(TableIndex *self, PyObject *args, PyObject *kwds) { PLAY };
4317 static PyObject * TableIndex_out(TableIndex *self, PyObject *args, PyObject *kwds) { OUT };
4318 static PyObject * TableIndex_stop(TableIndex *self, PyObject *args, PyObject *kwds) { STOP };
4319
4320 static PyObject * TableIndex_multiply(TableIndex *self, PyObject *arg) { MULTIPLY };
4321 static PyObject * TableIndex_inplace_multiply(TableIndex *self, PyObject *arg) { INPLACE_MULTIPLY };
4322 static PyObject * TableIndex_add(TableIndex *self, PyObject *arg) { ADD };
4323 static PyObject * TableIndex_inplace_add(TableIndex *self, PyObject *arg) { INPLACE_ADD };
4324 static PyObject * TableIndex_sub(TableIndex *self, PyObject *arg) { SUB };
4325 static PyObject * TableIndex_inplace_sub(TableIndex *self, PyObject *arg) { INPLACE_SUB };
4326 static PyObject * TableIndex_div(TableIndex *self, PyObject *arg) { DIV };
4327 static PyObject * TableIndex_inplace_div(TableIndex *self, PyObject *arg) { INPLACE_DIV };
4328
4329 static PyObject *
4330 TableIndex_getTable(TableIndex* self)
4331 {
4332 Py_INCREF(self->table);
4333 return self->table;
4334 };
4335
4336 static PyObject *
4337 TableIndex_setTable(TableIndex *self, PyObject *arg)
4338 {
4339 ASSERT_ARG_NOT_NULL
4340
4341 Py_DECREF(self->table);
4342 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
4343
4344 Py_RETURN_NONE;
4345 }
4346
4347 static PyObject *
4348 TableIndex_setIndex(TableIndex *self, PyObject *arg)
4349 {
4350 ASSERT_ARG_NOT_NULL
4351
4352 if (PyObject_HasAttrString((PyObject *)arg, "server") == 0)
4353 {
4354 PyErr_SetString(PyExc_TypeError, "\"index\" argument of TableIndex must be a PyoObject.\n");
4355 Py_RETURN_NONE;
4356 }
4357
4358 Py_DECREF(self->index);
4359
4360 self->index = arg;
4361 Py_INCREF(self->index);
4362 PyObject *streamtmp = PyObject_CallMethod((PyObject *)self->index, "_getStream", NULL);
4363 self->index_stream = (Stream *)streamtmp;
4364 Py_INCREF(self->index_stream);
4365
4366 Py_RETURN_NONE;
4367 }
4368
4369 static PyMemberDef TableIndex_members[] =
4370 {
4371 {"server", T_OBJECT_EX, offsetof(TableIndex, server), 0, "Pyo server."},
4372 {"stream", T_OBJECT_EX, offsetof(TableIndex, stream), 0, "Stream object."},
4373 {"table", T_OBJECT_EX, offsetof(TableIndex, table), 0, "Waveform table."},
4374 {"index", T_OBJECT_EX, offsetof(TableIndex, index), 0, "Reader index."},
4375 {"mul", T_OBJECT_EX, offsetof(TableIndex, mul), 0, "Mul factor."},
4376 {"add", T_OBJECT_EX, offsetof(TableIndex, add), 0, "Add factor."},
4377 {NULL} /* Sentinel */
4378 };
4379
4380 static PyMethodDef TableIndex_methods[] =
4381 {
4382 {"getTable", (PyCFunction)TableIndex_getTable, METH_NOARGS, "Returns waveform table object."},
4383 {"getServer", (PyCFunction)TableIndex_getServer, METH_NOARGS, "Returns server object."},
4384 {"_getStream", (PyCFunction)TableIndex_getStream, METH_NOARGS, "Returns stream object."},
4385 {"play", (PyCFunction)TableIndex_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4386 {"out", (PyCFunction)TableIndex_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4387 {"stop", (PyCFunction)TableIndex_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4388 {"setTable", (PyCFunction)TableIndex_setTable, METH_O, "Sets oscillator table."},
4389 {"setIndex", (PyCFunction)TableIndex_setIndex, METH_O, "Sets reader index."},
4390 {"setMul", (PyCFunction)TableIndex_setMul, METH_O, "Sets oscillator mul factor."},
4391 {"setAdd", (PyCFunction)TableIndex_setAdd, METH_O, "Sets oscillator add factor."},
4392 {"setSub", (PyCFunction)TableIndex_setSub, METH_O, "Sets oscillator inverse add factor."},
4393 {"setDiv", (PyCFunction)TableIndex_setDiv, METH_O, "Sets inverse mul factor."},
4394 {NULL} /* Sentinel */
4395 };
4396
4397 static PyNumberMethods TableIndex_as_number =
4398 {
4399 (binaryfunc)TableIndex_add, /*nb_add*/
4400 (binaryfunc)TableIndex_sub, /*nb_subtract*/
4401 (binaryfunc)TableIndex_multiply, /*nb_multiply*/
4402 0, /*nb_remainder*/
4403 0, /*nb_divmod*/
4404 0, /*nb_power*/
4405 0, /*nb_neg*/
4406 0, /*nb_pos*/
4407 0, /*(unaryfunc)array_abs,*/
4408 0, /*nb_nonzero*/
4409 0, /*nb_invert*/
4410 0, /*nb_lshift*/
4411 0, /*nb_rshift*/
4412 0, /*nb_and*/
4413 0, /*nb_xor*/
4414 0, /*nb_or*/
4415 0, /*nb_int*/
4416 0, /*nb_long*/
4417 0, /*nb_float*/
4418 (binaryfunc)TableIndex_inplace_add, /*inplace_add*/
4419 (binaryfunc)TableIndex_inplace_sub, /*inplace_subtract*/
4420 (binaryfunc)TableIndex_inplace_multiply, /*inplace_multiply*/
4421 0, /*inplace_remainder*/
4422 0, /*inplace_power*/
4423 0, /*inplace_lshift*/
4424 0, /*inplace_rshift*/
4425 0, /*inplace_and*/
4426 0, /*inplace_xor*/
4427 0, /*inplace_or*/
4428 0, /*nb_floor_divide*/
4429 (binaryfunc)TableIndex_div, /*nb_true_divide*/
4430 0, /*nb_inplace_floor_divide*/
4431 (binaryfunc)TableIndex_inplace_div, /*nb_inplace_true_divide*/
4432 0, /* nb_index */
4433 };
4434
4435 PyTypeObject TableIndexType =
4436 {
4437 PyVarObject_HEAD_INIT(NULL, 0)
4438 "_pyo.TableIndex_base", /*tp_name*/
4439 sizeof(TableIndex), /*tp_basicsize*/
4440 0, /*tp_itemsize*/
4441 (destructor)TableIndex_dealloc, /*tp_dealloc*/
4442 0, /*tp_print*/
4443 0, /*tp_getattr*/
4444 0, /*tp_setattr*/
4445 0, /*tp_as_async (tp_compare in Python 2)*/
4446 0, /*tp_repr*/
4447 &TableIndex_as_number, /*tp_as_number*/
4448 0, /*tp_as_sequence*/
4449 0, /*tp_as_mapping*/
4450 0, /*tp_hash */
4451 0, /*tp_call*/
4452 0, /*tp_str*/
4453 0, /*tp_getattro*/
4454 0, /*tp_setattro*/
4455 0, /*tp_as_buffer*/
4456 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4457 "TableIndex objects. Read a table by indexing without interpolation.", /* tp_doc */
4458 (traverseproc)TableIndex_traverse, /* tp_traverse */
4459 (inquiry)TableIndex_clear, /* tp_clear */
4460 0, /* tp_richcompare */
4461 0, /* tp_weaklistoffset */
4462 0, /* tp_iter */
4463 0, /* tp_iternext */
4464 TableIndex_methods, /* tp_methods */
4465 TableIndex_members, /* tp_members */
4466 0, /* tp_getset */
4467 0, /* tp_base */
4468 0, /* tp_dict */
4469 0, /* tp_descr_get */
4470 0, /* tp_descr_set */
4471 0, /* tp_dictoffset */
4472 0, /* tp_init */
4473 0, /* tp_alloc */
4474 TableIndex_new, /* tp_new */
4475 };
4476
4477 /**************/
4478 /* Lookup object */
4479 /**************/
4480 typedef struct
4481 {
4482 pyo_audio_HEAD
4483 PyObject *table;
4484 PyObject *index;
4485 Stream *index_stream;
4486 int modebuffer[2];
4487 } Lookup;
4488
4489 static MYFLT
4490 Lookup_clip(MYFLT x)
4491 {
4492 if (x < -1.0)
4493 return -1.0;
4494 else if (x > 1.0)
4495 return 1.0;
4496 else
4497 return x;
4498 }
4499
4500 static void
4501 Lookup_readframes_a(Lookup *self)
4502 {
4503 int i;
4504 MYFLT ph, fpart;
4505 T_SIZE_T ipart;
4506 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
4507 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
4508
4509 MYFLT *pha = Stream_getData((Stream *)self->index_stream);
4510
4511 for (i = 0; i < self->bufsize; i++)
4512 {
4513 ph = (Lookup_clip(pha[i]) * 0.495 + 0.5) * size;
4514 ipart = (T_SIZE_T)ph;
4515 fpart = ph - ipart;
4516 self->data[i] = tablelist[ipart] + (tablelist[ipart + 1] - tablelist[ipart]) * fpart;
4517 }
4518 }
4519
4520 static void Lookup_postprocessing_ii(Lookup *self) { POST_PROCESSING_II };
4521 static void Lookup_postprocessing_ai(Lookup *self) { POST_PROCESSING_AI };
4522 static void Lookup_postprocessing_ia(Lookup *self) { POST_PROCESSING_IA };
4523 static void Lookup_postprocessing_aa(Lookup *self) { POST_PROCESSING_AA };
4524 static void Lookup_postprocessing_ireva(Lookup *self) { POST_PROCESSING_IREVA };
4525 static void Lookup_postprocessing_areva(Lookup *self) { POST_PROCESSING_AREVA };
4526 static void Lookup_postprocessing_revai(Lookup *self) { POST_PROCESSING_REVAI };
4527 static void Lookup_postprocessing_revaa(Lookup *self) { POST_PROCESSING_REVAA };
4528 static void Lookup_postprocessing_revareva(Lookup *self) { POST_PROCESSING_REVAREVA };
4529
4530 static void
4531 Lookup_setProcMode(Lookup *self)
4532 {
4533 int muladdmode;
4534 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
4535
4536 self->proc_func_ptr = Lookup_readframes_a;
4537
4538 switch (muladdmode)
4539 {
4540 case 0:
4541 self->muladd_func_ptr = Lookup_postprocessing_ii;
4542 break;
4543
4544 case 1:
4545 self->muladd_func_ptr = Lookup_postprocessing_ai;
4546 break;
4547
4548 case 2:
4549 self->muladd_func_ptr = Lookup_postprocessing_revai;
4550 break;
4551
4552 case 10:
4553 self->muladd_func_ptr = Lookup_postprocessing_ia;
4554 break;
4555
4556 case 11:
4557 self->muladd_func_ptr = Lookup_postprocessing_aa;
4558 break;
4559
4560 case 12:
4561 self->muladd_func_ptr = Lookup_postprocessing_revaa;
4562 break;
4563
4564 case 20:
4565 self->muladd_func_ptr = Lookup_postprocessing_ireva;
4566 break;
4567
4568 case 21:
4569 self->muladd_func_ptr = Lookup_postprocessing_areva;
4570 break;
4571
4572 case 22:
4573 self->muladd_func_ptr = Lookup_postprocessing_revareva;
4574 break;
4575 }
4576 }
4577
4578 static void
4579 Lookup_compute_next_data_frame(Lookup *self)
4580 {
4581 (*self->proc_func_ptr)(self);
4582 (*self->muladd_func_ptr)(self);
4583 }
4584
4585 static int
4586 Lookup_traverse(Lookup *self, visitproc visit, void *arg)
4587 {
4588 pyo_VISIT
4589 Py_VISIT(self->index);
4590 return 0;
4591 }
4592
4593 static int
4594 Lookup_clear(Lookup *self)
4595 {
4596 pyo_CLEAR
4597 Py_CLEAR(self->index);
4598 return 0;
4599 }
4600
4601 static void
4602 Lookup_dealloc(Lookup* self)
4603 {
4604 pyo_DEALLOC
4605 Lookup_clear(self);
4606 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
4607 Py_TYPE(self)->tp_free((PyObject*)self);
4608 }
4609
4610 static PyObject *
4611 Lookup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4612 {
4613 int i;
4614 PyObject *tabletmp, *indextmp, *multmp = NULL, *addtmp = NULL;
4615 Lookup *self;
4616 self = (Lookup *)type->tp_alloc(type, 0);
4617
4618 self->index = PyFloat_FromDouble(0.0);
4619
4620 self->modebuffer[0] = 0;
4621 self->modebuffer[1] = 0;
4622
4623 INIT_OBJECT_COMMON
4624 Stream_setFunctionPtr(self->stream, Lookup_compute_next_data_frame);
4625 self->mode_func_ptr = Lookup_setProcMode;
4626
4627 static char *kwlist[] = {"table", "index", "mul", "add", NULL};
4628
4629 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO", kwlist, &tabletmp, &indextmp, &multmp, &addtmp))
4630 Py_RETURN_NONE;
4631
4632 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
4633 {
4634 PyErr_SetString(PyExc_TypeError, "\"table\" argument of Lookup must be a PyoTableObject.\n");
4635 Py_RETURN_NONE;
4636 }
4637
4638 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
4639
4640 if (indextmp)
4641 {
4642 PyObject_CallMethod((PyObject *)self, "setIndex", "O", indextmp);
4643 }
4644
4645 if (multmp)
4646 {
4647 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
4648 }
4649
4650 if (addtmp)
4651 {
4652 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
4653 }
4654
4655 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
4656
4657 (*self->mode_func_ptr)(self);
4658
4659 return (PyObject *)self;
4660 }
4661
4662 static PyObject * Lookup_getServer(Lookup* self) { GET_SERVER };
4663 static PyObject * Lookup_getStream(Lookup* self) { GET_STREAM };
4664 static PyObject * Lookup_setMul(Lookup *self, PyObject *arg) { SET_MUL };
4665 static PyObject * Lookup_setAdd(Lookup *self, PyObject *arg) { SET_ADD };
4666 static PyObject * Lookup_setSub(Lookup *self, PyObject *arg) { SET_SUB };
4667 static PyObject * Lookup_setDiv(Lookup *self, PyObject *arg) { SET_DIV };
4668
4669 static PyObject * Lookup_play(Lookup *self, PyObject *args, PyObject *kwds) { PLAY };
4670 static PyObject * Lookup_out(Lookup *self, PyObject *args, PyObject *kwds) { OUT };
4671 static PyObject * Lookup_stop(Lookup *self, PyObject *args, PyObject *kwds) { STOP };
4672
4673 static PyObject * Lookup_multiply(Lookup *self, PyObject *arg) { MULTIPLY };
4674 static PyObject * Lookup_inplace_multiply(Lookup *self, PyObject *arg) { INPLACE_MULTIPLY };
4675 static PyObject * Lookup_add(Lookup *self, PyObject *arg) { ADD };
4676 static PyObject * Lookup_inplace_add(Lookup *self, PyObject *arg) { INPLACE_ADD };
4677 static PyObject * Lookup_sub(Lookup *self, PyObject *arg) { SUB };
4678 static PyObject * Lookup_inplace_sub(Lookup *self, PyObject *arg) { INPLACE_SUB };
4679 static PyObject * Lookup_div(Lookup *self, PyObject *arg) { DIV };
4680 static PyObject * Lookup_inplace_div(Lookup *self, PyObject *arg) { INPLACE_DIV };
4681
4682 static PyObject *
4683 Lookup_getTable(Lookup* self)
4684 {
4685 Py_INCREF(self->table);
4686 return self->table;
4687 };
4688
4689 static PyObject *
4690 Lookup_setTable(Lookup *self, PyObject *arg)
4691 {
4692 ASSERT_ARG_NOT_NULL
4693
4694 Py_DECREF(self->table);
4695 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
4696
4697 Py_RETURN_NONE;
4698 }
4699
4700 static PyObject *
4701 Lookup_setIndex(Lookup *self, PyObject *arg)
4702 {
4703 ASSERT_ARG_NOT_NULL
4704
4705 if (PyObject_HasAttrString((PyObject *)arg, "server") == 0)
4706 {
4707 PyErr_SetString(PyExc_TypeError, "\"index\" argument of Lookup must be a PyoObject.\n");
4708 Py_RETURN_NONE;
4709 }
4710
4711 Py_DECREF(self->index);
4712
4713 self->index = arg;
4714 Py_INCREF(self->index);
4715 PyObject *streamtmp = PyObject_CallMethod((PyObject *)self->index, "_getStream", NULL);
4716 self->index_stream = (Stream *)streamtmp;
4717 Py_INCREF(self->index_stream);
4718
4719 Py_RETURN_NONE;
4720 }
4721
4722 static PyMemberDef Lookup_members[] =
4723 {
4724 {"server", T_OBJECT_EX, offsetof(Lookup, server), 0, "Pyo server."},
4725 {"stream", T_OBJECT_EX, offsetof(Lookup, stream), 0, "Stream object."},
4726 {"table", T_OBJECT_EX, offsetof(Lookup, table), 0, "Waveform table."},
4727 {"index", T_OBJECT_EX, offsetof(Lookup, index), 0, "Reader index."},
4728 {"mul", T_OBJECT_EX, offsetof(Lookup, mul), 0, "Mul factor."},
4729 {"add", T_OBJECT_EX, offsetof(Lookup, add), 0, "Add factor."},
4730 {NULL} /* Sentinel */
4731 };
4732
4733 static PyMethodDef Lookup_methods[] =
4734 {
4735 {"getTable", (PyCFunction)Lookup_getTable, METH_NOARGS, "Returns waveform table object."},
4736 {"getServer", (PyCFunction)Lookup_getServer, METH_NOARGS, "Returns server object."},
4737 {"_getStream", (PyCFunction)Lookup_getStream, METH_NOARGS, "Returns stream object."},
4738 {"play", (PyCFunction)Lookup_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
4739 {"out", (PyCFunction)Lookup_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
4740 {"stop", (PyCFunction)Lookup_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
4741 {"setTable", (PyCFunction)Lookup_setTable, METH_O, "Sets oscillator table."},
4742 {"setIndex", (PyCFunction)Lookup_setIndex, METH_O, "Sets reader index."},
4743 {"setMul", (PyCFunction)Lookup_setMul, METH_O, "Sets oscillator mul factor."},
4744 {"setAdd", (PyCFunction)Lookup_setAdd, METH_O, "Sets oscillator add factor."},
4745 {"setSub", (PyCFunction)Lookup_setSub, METH_O, "Sets oscillator inverse add factor."},
4746 {"setDiv", (PyCFunction)Lookup_setDiv, METH_O, "Sets inverse mul factor."},
4747 {NULL} /* Sentinel */
4748 };
4749
4750 static PyNumberMethods Lookup_as_number =
4751 {
4752 (binaryfunc)Lookup_add, /*nb_add*/
4753 (binaryfunc)Lookup_sub, /*nb_subtract*/
4754 (binaryfunc)Lookup_multiply, /*nb_multiply*/
4755 0, /*nb_remainder*/
4756 0, /*nb_divmod*/
4757 0, /*nb_power*/
4758 0, /*nb_neg*/
4759 0, /*nb_pos*/
4760 0, /*(unaryfunc)array_abs,*/
4761 0, /*nb_nonzero*/
4762 0, /*nb_invert*/
4763 0, /*nb_lshift*/
4764 0, /*nb_rshift*/
4765 0, /*nb_and*/
4766 0, /*nb_xor*/
4767 0, /*nb_or*/
4768 0, /*nb_int*/
4769 0, /*nb_long*/
4770 0, /*nb_float*/
4771 (binaryfunc)Lookup_inplace_add, /*inplace_add*/
4772 (binaryfunc)Lookup_inplace_sub, /*inplace_subtract*/
4773 (binaryfunc)Lookup_inplace_multiply, /*inplace_multiply*/
4774 0, /*inplace_remainder*/
4775 0, /*inplace_power*/
4776 0, /*inplace_lshift*/
4777 0, /*inplace_rshift*/
4778 0, /*inplace_and*/
4779 0, /*inplace_xor*/
4780 0, /*inplace_or*/
4781 0, /*nb_floor_divide*/
4782 (binaryfunc)Lookup_div, /*nb_true_divide*/
4783 0, /*nb_inplace_floor_divide*/
4784 (binaryfunc)Lookup_inplace_div, /*nb_inplace_true_divide*/
4785 0, /* nb_index */
4786 };
4787
4788 PyTypeObject LookupType =
4789 {
4790 PyVarObject_HEAD_INIT(NULL, 0)
4791 "_pyo.Lookup_base", /*tp_name*/
4792 sizeof(Lookup), /*tp_basicsize*/
4793 0, /*tp_itemsize*/
4794 (destructor)Lookup_dealloc, /*tp_dealloc*/
4795 0, /*tp_print*/
4796 0, /*tp_getattr*/
4797 0, /*tp_setattr*/
4798 0, /*tp_as_async (tp_compare in Python 2)*/
4799 0, /*tp_repr*/
4800 &Lookup_as_number, /*tp_as_number*/
4801 0, /*tp_as_sequence*/
4802 0, /*tp_as_mapping*/
4803 0, /*tp_hash */
4804 0, /*tp_call*/
4805 0, /*tp_str*/
4806 0, /*tp_getattro*/
4807 0, /*tp_setattro*/
4808 0, /*tp_as_buffer*/
4809 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
4810 "Lookup objects. Modify a signal by reading a table with the signal as the index.", /* tp_doc */
4811 (traverseproc)Lookup_traverse, /* tp_traverse */
4812 (inquiry)Lookup_clear, /* tp_clear */
4813 0, /* tp_richcompare */
4814 0, /* tp_weaklistoffset */
4815 0, /* tp_iter */
4816 0, /* tp_iternext */
4817 Lookup_methods, /* tp_methods */
4818 Lookup_members, /* tp_members */
4819 0, /* tp_getset */
4820 0, /* tp_base */
4821 0, /* tp_dict */
4822 0, /* tp_descr_get */
4823 0, /* tp_descr_set */
4824 0, /* tp_dictoffset */
4825 0, /* tp_init */
4826 0, /* tp_alloc */
4827 Lookup_new, /* tp_new */
4828 };
4829
4830 /**************/
4831 /* Pulsar object */
4832 /**************/
4833 typedef struct
4834 {
4835 pyo_audio_HEAD
4836 PyObject *table;
4837 PyObject *env;
4838 PyObject *freq;
4839 Stream *freq_stream;
4840 PyObject *phase;
4841 Stream *phase_stream;
4842 PyObject *frac;
4843 Stream *frac_stream;
4844 int modebuffer[5];
4845 MYFLT pointerPos;
4846 int interp; /* 0 = default to 2, 1 = nointerp, 2 = linear, 3 = cos, 4 = cubic */
4847 MYFLT (*interp_func_ptr)(MYFLT *, T_SIZE_T, MYFLT, T_SIZE_T);
4848 } Pulsar;
4849
4850 static void
4851 Pulsar_readframes_iii(Pulsar *self)
4852 {
4853 int i;
4854 MYFLT fr, ph, frac, invfrac, pos, scl_pos, t_pos, e_pos, fpart, tmp;
4855 double inc;
4856 T_SIZE_T ipart;
4857 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
4858 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
4859 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
4860 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
4861
4862 fr = PyFloat_AS_DOUBLE(self->freq);
4863 ph = PyFloat_AS_DOUBLE(self->phase);
4864 frac = _clip(PyFloat_AS_DOUBLE(self->frac));
4865 invfrac = 1.0 / frac;
4866 inc = fr / self->sr;
4867
4868 for (i = 0; i < self->bufsize; i++)
4869 {
4870 self->pointerPos += inc;
4871
4872 if (self->pointerPos < 0)
4873 self->pointerPos = 1.0 + self->pointerPos;
4874 else if (self->pointerPos >= 1.0)
4875 self->pointerPos -= 1.0;
4876
4877 pos = self->pointerPos + ph;
4878
4879 if (pos >= 1.0)
4880 pos -= 1.0;
4881
4882 if (pos < frac)
4883 {
4884 scl_pos = pos * invfrac;
4885 t_pos = scl_pos * size;
4886 ipart = (T_SIZE_T)t_pos;
4887 fpart = t_pos - ipart;
4888 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
4889
4890 e_pos = scl_pos * envsize;
4891 ipart = (T_SIZE_T)e_pos;
4892 fpart = e_pos - ipart;
4893 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
4894 }
4895 else
4896 {
4897 self->data[i] = 0.0;
4898 }
4899 }
4900 }
4901
4902 static void
4903 Pulsar_readframes_aii(Pulsar *self)
4904 {
4905 int i;
4906 MYFLT ph, frac, invfrac, pos, scl_pos, t_pos, e_pos, fpart, tmp, oneOnSr;
4907 double inc;
4908 T_SIZE_T ipart;
4909 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
4910 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
4911 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
4912 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
4913
4914 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
4915 ph = PyFloat_AS_DOUBLE(self->phase);
4916 frac = _clip(PyFloat_AS_DOUBLE(self->frac));
4917 invfrac = 1.0 / frac;
4918
4919 oneOnSr = 1.0 / self->sr;
4920
4921 for (i = 0; i < self->bufsize; i++)
4922 {
4923 inc = fr[i] * oneOnSr;
4924 self->pointerPos += inc;
4925
4926 if (self->pointerPos < 0)
4927 self->pointerPos = 1.0 + self->pointerPos;
4928 else if (self->pointerPos >= 1.0)
4929 self->pointerPos -= 1.0;
4930
4931 pos = self->pointerPos + ph;
4932
4933 if (pos >= 1.0)
4934 pos -= 1.0;
4935
4936 if (pos < frac)
4937 {
4938 scl_pos = pos * invfrac;
4939 t_pos = scl_pos * size;
4940 ipart = (T_SIZE_T)t_pos;
4941 fpart = t_pos - ipart;
4942 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
4943
4944 e_pos = scl_pos * envsize;
4945 ipart = (T_SIZE_T)e_pos;
4946 fpart = e_pos - ipart;
4947 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
4948 }
4949 else
4950 {
4951 self->data[i] = 0.0;
4952 }
4953 }
4954 }
4955
4956 static void
4957 Pulsar_readframes_iai(Pulsar *self)
4958 {
4959 int i;
4960 MYFLT fr, frac, invfrac, pos, scl_pos, t_pos, e_pos, fpart, tmp;
4961 double inc;
4962 T_SIZE_T ipart;
4963 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
4964 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
4965 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
4966 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
4967
4968 fr = PyFloat_AS_DOUBLE(self->freq);
4969 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
4970 frac = _clip(PyFloat_AS_DOUBLE(self->frac));
4971 invfrac = 1.0 / frac;
4972 inc = fr / self->sr;
4973
4974 for (i = 0; i < self->bufsize; i++)
4975 {
4976 self->pointerPos += inc;
4977
4978 if (self->pointerPos < 0)
4979 self->pointerPos = 1.0 + self->pointerPos;
4980 else if (self->pointerPos >= 1.0)
4981 self->pointerPos -= 1.0;
4982
4983 pos = self->pointerPos + ph[i];
4984
4985 if (pos >= 1.0)
4986 pos -= 1.0;
4987
4988 if (pos < frac)
4989 {
4990 scl_pos = pos * invfrac;
4991 t_pos = scl_pos * size;
4992 ipart = (T_SIZE_T)t_pos;
4993 fpart = t_pos - ipart;
4994 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
4995
4996 e_pos = scl_pos * envsize;
4997 ipart = (T_SIZE_T)e_pos;
4998 fpart = e_pos - ipart;
4999 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
5000 }
5001 else
5002 {
5003 self->data[i] = 0.0;
5004 }
5005 }
5006 }
5007
5008 static void
5009 Pulsar_readframes_aai(Pulsar *self)
5010 {
5011 int i;
5012 MYFLT frac, invfrac, pos, scl_pos, t_pos, e_pos, fpart, tmp, oneOnSr;
5013 double inc;
5014 T_SIZE_T ipart;
5015 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
5016 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
5017 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
5018 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
5019
5020 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
5021 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
5022 frac = _clip(PyFloat_AS_DOUBLE(self->frac));
5023 invfrac = 1.0 / frac;
5024
5025 oneOnSr = 1.0 / self->sr;
5026
5027 for (i = 0; i < self->bufsize; i++)
5028 {
5029 inc = fr[i] * oneOnSr;
5030 self->pointerPos += inc;
5031
5032 if (self->pointerPos < 0)
5033 self->pointerPos = 1.0 + self->pointerPos;
5034 else if (self->pointerPos >= 1.0)
5035 self->pointerPos -= 1.0;
5036
5037 pos = self->pointerPos + ph[i];
5038
5039 if (pos >= 1.0)
5040 pos -= 1.0;
5041
5042 if (pos < frac)
5043 {
5044 scl_pos = pos * invfrac;
5045 t_pos = scl_pos * size;
5046 ipart = (T_SIZE_T)t_pos;
5047 fpart = t_pos - ipart;
5048 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
5049
5050 e_pos = scl_pos * envsize;
5051 ipart = (T_SIZE_T)e_pos;
5052 fpart = e_pos - ipart;
5053 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
5054 }
5055 else
5056 {
5057 self->data[i] = 0.0;
5058 }
5059 }
5060 }
5061
5062 static void
5063 Pulsar_readframes_iia(Pulsar *self)
5064 {
5065 int i;
5066 MYFLT fr, ph, pos, curfrac, scl_pos, t_pos, e_pos, fpart, tmp;
5067 double inc;
5068 T_SIZE_T ipart;
5069 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
5070 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
5071 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
5072 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
5073
5074 fr = PyFloat_AS_DOUBLE(self->freq);
5075 ph = PyFloat_AS_DOUBLE(self->phase);
5076 MYFLT *frac = Stream_getData((Stream *)self->frac_stream);
5077 inc = fr / self->sr;
5078
5079 for (i = 0; i < self->bufsize; i++)
5080 {
5081 curfrac = frac[i];
5082 self->pointerPos += inc;
5083
5084 if (self->pointerPos < 0)
5085 self->pointerPos = 1.0 + self->pointerPos;
5086 else if (self->pointerPos >= 1.0)
5087 self->pointerPos -= 1.0;
5088
5089 pos = self->pointerPos + ph;
5090
5091 if (pos >= 1.0)
5092 pos -= 1.0;
5093
5094 if (pos < curfrac)
5095 {
5096 scl_pos = pos / curfrac;
5097 t_pos = scl_pos * size;
5098 ipart = (T_SIZE_T)t_pos;
5099 fpart = t_pos - ipart;
5100 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
5101
5102 e_pos = scl_pos * envsize;
5103 ipart = (T_SIZE_T)e_pos;
5104 fpart = e_pos - ipart;
5105 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
5106 }
5107 else
5108 {
5109 self->data[i] = 0.0;
5110 }
5111 }
5112 }
5113
5114 static void
5115 Pulsar_readframes_aia(Pulsar *self)
5116 {
5117 int i;
5118 MYFLT ph, pos, curfrac, scl_pos, t_pos, e_pos, fpart, tmp, oneOnSr;
5119 double inc;
5120 T_SIZE_T ipart;
5121 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
5122 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
5123 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
5124 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
5125
5126 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
5127 ph = PyFloat_AS_DOUBLE(self->phase);
5128 MYFLT *frac = Stream_getData((Stream *)self->frac_stream);
5129
5130 oneOnSr = 1.0 / self->sr;
5131
5132 for (i = 0; i < self->bufsize; i++)
5133 {
5134 curfrac = frac[i];
5135 inc = fr[i] * oneOnSr;
5136 self->pointerPos += inc;
5137
5138 if (self->pointerPos < 0)
5139 self->pointerPos = 1.0 + self->pointerPos;
5140 else if (self->pointerPos >= 1.0)
5141 self->pointerPos -= 1.0;
5142
5143 pos = self->pointerPos + ph;
5144
5145 if (pos >= 1.0)
5146 pos -= 1.0;
5147
5148 if (pos < curfrac)
5149 {
5150 scl_pos = pos / curfrac;
5151 t_pos = scl_pos * size;
5152 ipart = (T_SIZE_T)t_pos;
5153 fpart = t_pos - ipart;
5154 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
5155
5156 e_pos = scl_pos * envsize;
5157 ipart = (T_SIZE_T)e_pos;
5158 fpart = e_pos - ipart;
5159 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
5160 }
5161 else
5162 {
5163 self->data[i] = 0.0;
5164 }
5165 }
5166 }
5167
5168 static void
5169 Pulsar_readframes_iaa(Pulsar *self)
5170 {
5171 int i;
5172 MYFLT fr, pos, curfrac, scl_pos, t_pos, e_pos, fpart, tmp;
5173 double inc;
5174 T_SIZE_T ipart;
5175 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
5176 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
5177 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
5178 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
5179
5180 fr = PyFloat_AS_DOUBLE(self->freq);
5181 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
5182 MYFLT *frac = Stream_getData((Stream *)self->frac_stream);
5183 inc = fr / self->sr;
5184
5185 for (i = 0; i < self->bufsize; i++)
5186 {
5187 curfrac = frac[i];
5188 self->pointerPos += inc;
5189
5190 if (self->pointerPos < 0)
5191 self->pointerPos = 1.0 + self->pointerPos;
5192 else if (self->pointerPos >= 1.0)
5193 self->pointerPos -= 1.0;
5194
5195 pos = self->pointerPos + ph[i];
5196
5197 if (pos >= 1.0)
5198 pos -= 1.0;
5199
5200 if (pos < curfrac)
5201 {
5202 scl_pos = pos / curfrac;
5203 t_pos = scl_pos * size;
5204 ipart = (T_SIZE_T)t_pos;
5205 fpart = t_pos - ipart;
5206 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
5207
5208 e_pos = scl_pos * envsize;
5209 ipart = (T_SIZE_T)e_pos;
5210 fpart = e_pos - ipart;
5211 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
5212 }
5213 else
5214 {
5215 self->data[i] = 0.0;
5216 }
5217 }
5218 }
5219
5220 static void
5221 Pulsar_readframes_aaa(Pulsar *self)
5222 {
5223 int i;
5224 MYFLT pos, curfrac, scl_pos, t_pos, e_pos, fpart, tmp, oneOnSr;
5225 double inc;
5226 T_SIZE_T ipart;
5227 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
5228 MYFLT *envlist = TableStream_getData((TableStream *)self->env);
5229 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
5230 T_SIZE_T envsize = TableStream_getSize((TableStream *)self->env);
5231
5232 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
5233 MYFLT *ph = Stream_getData((Stream *)self->phase_stream);
5234 MYFLT *frac = Stream_getData((Stream *)self->frac_stream);
5235
5236 oneOnSr = 1.0 / self->sr;
5237
5238 for (i = 0; i < self->bufsize; i++)
5239 {
5240 curfrac = frac[i];
5241 inc = fr[i] * oneOnSr;
5242 self->pointerPos += inc;
5243
5244 if (self->pointerPos < 0)
5245 self->pointerPos = 1.0 + self->pointerPos;
5246 else if (self->pointerPos >= 1.0)
5247 self->pointerPos -= 1.0;
5248
5249 pos = self->pointerPos + ph[i];
5250
5251 if (pos >= 1.0)
5252 pos -= 1.0;
5253
5254 if (pos < curfrac)
5255 {
5256 scl_pos = pos / curfrac;
5257 t_pos = scl_pos * size;
5258 ipart = (T_SIZE_T)t_pos;
5259 fpart = t_pos - ipart;
5260 tmp = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
5261
5262 e_pos = scl_pos * envsize;
5263 ipart = (T_SIZE_T)e_pos;
5264 fpart = e_pos - ipart;
5265 self->data[i] = tmp * (envlist[ipart] + (envlist[ipart + 1] - envlist[ipart]) * fpart);
5266 }
5267 else
5268 {
5269 self->data[i] = 0.0;
5270 }
5271 }
5272 }
5273
5274 static void Pulsar_postprocessing_ii(Pulsar *self) { POST_PROCESSING_II };
5275 static void Pulsar_postprocessing_ai(Pulsar *self) { POST_PROCESSING_AI };
5276 static void Pulsar_postprocessing_ia(Pulsar *self) { POST_PROCESSING_IA };
5277 static void Pulsar_postprocessing_aa(Pulsar *self) { POST_PROCESSING_AA };
5278 static void Pulsar_postprocessing_ireva(Pulsar *self) { POST_PROCESSING_IREVA };
5279 static void Pulsar_postprocessing_areva(Pulsar *self) { POST_PROCESSING_AREVA };
5280 static void Pulsar_postprocessing_revai(Pulsar *self) { POST_PROCESSING_REVAI };
5281 static void Pulsar_postprocessing_revaa(Pulsar *self) { POST_PROCESSING_REVAA };
5282 static void Pulsar_postprocessing_revareva(Pulsar *self) { POST_PROCESSING_REVAREVA };
5283
5284 static void
5285 Pulsar_setProcMode(Pulsar *self)
5286 {
5287 int procmode, muladdmode;
5288 procmode = self->modebuffer[2] + self->modebuffer[3] * 10 + self->modebuffer[4] * 100;
5289 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
5290
5291 switch (procmode)
5292 {
5293 case 0:
5294 self->proc_func_ptr = Pulsar_readframes_iii;
5295 break;
5296
5297 case 1:
5298 self->proc_func_ptr = Pulsar_readframes_aii;
5299 break;
5300
5301 case 10:
5302 self->proc_func_ptr = Pulsar_readframes_iai;
5303 break;
5304
5305 case 11:
5306 self->proc_func_ptr = Pulsar_readframes_aai;
5307 break;
5308
5309 case 100:
5310 self->proc_func_ptr = Pulsar_readframes_iia;
5311 break;
5312
5313 case 101:
5314 self->proc_func_ptr = Pulsar_readframes_aia;
5315 break;
5316
5317 case 110:
5318 self->proc_func_ptr = Pulsar_readframes_iaa;
5319 break;
5320
5321 case 111:
5322 self->proc_func_ptr = Pulsar_readframes_aaa;
5323 break;
5324 }
5325
5326 switch (muladdmode)
5327 {
5328 case 0:
5329 self->muladd_func_ptr = Pulsar_postprocessing_ii;
5330 break;
5331
5332 case 1:
5333 self->muladd_func_ptr = Pulsar_postprocessing_ai;
5334 break;
5335
5336 case 2:
5337 self->muladd_func_ptr = Pulsar_postprocessing_revai;
5338 break;
5339
5340 case 10:
5341 self->muladd_func_ptr = Pulsar_postprocessing_ia;
5342 break;
5343
5344 case 11:
5345 self->muladd_func_ptr = Pulsar_postprocessing_aa;
5346 break;
5347
5348 case 12:
5349 self->muladd_func_ptr = Pulsar_postprocessing_revaa;
5350 break;
5351
5352 case 20:
5353 self->muladd_func_ptr = Pulsar_postprocessing_ireva;
5354 break;
5355
5356 case 21:
5357 self->muladd_func_ptr = Pulsar_postprocessing_areva;
5358 break;
5359
5360 case 22:
5361 self->muladd_func_ptr = Pulsar_postprocessing_revareva;
5362 break;
5363 }
5364 }
5365
5366 static void
5367 Pulsar_compute_next_data_frame(Pulsar *self)
5368 {
5369 (*self->proc_func_ptr)(self);
5370 (*self->muladd_func_ptr)(self);
5371 }
5372
5373 static int
5374 Pulsar_traverse(Pulsar *self, visitproc visit, void *arg)
5375 {
5376 pyo_VISIT
5377 Py_VISIT(self->phase);
5378 Py_VISIT(self->freq);
5379 Py_VISIT(self->frac);
5380 return 0;
5381 }
5382
5383 static int
5384 Pulsar_clear(Pulsar *self)
5385 {
5386 pyo_CLEAR
5387 Py_CLEAR(self->phase);
5388 Py_CLEAR(self->freq);
5389 Py_CLEAR(self->frac);
5390 return 0;
5391 }
5392
5393 static void
5394 Pulsar_dealloc(Pulsar* self)
5395 {
5396 pyo_DEALLOC
5397 Pulsar_clear(self);
5398 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
5399 Py_TYPE(self)->tp_free((PyObject*)self);
5400 }
5401
5402 static PyObject *
5403 Pulsar_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5404 {
5405 int i;
5406 PyObject *tabletmp, *envtmp, *freqtmp = NULL, *phasetmp = NULL, *fractmp = NULL, *multmp = NULL, *addtmp = NULL;
5407 Pulsar *self;
5408 self = (Pulsar *)type->tp_alloc(type, 0);
5409
5410 self->freq = PyFloat_FromDouble(100);
5411 self->phase = PyFloat_FromDouble(0);
5412 self->frac = PyFloat_FromDouble(0.5);
5413 self->interp = 2;
5414 self->modebuffer[0] = 0;
5415 self->modebuffer[1] = 0;
5416 self->modebuffer[2] = 0;
5417 self->modebuffer[3] = 0;
5418 self->modebuffer[4] = 0;
5419 self->pointerPos = 0.;
5420
5421 INIT_OBJECT_COMMON
5422 Stream_setFunctionPtr(self->stream, Pulsar_compute_next_data_frame);
5423 self->mode_func_ptr = Pulsar_setProcMode;
5424
5425 static char *kwlist[] = {"table", "env", "freq", "frac", "phase", "interp", "mul", "add", NULL};
5426
5427 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OOOiOO", kwlist, &tabletmp, &envtmp, &freqtmp, &fractmp, &phasetmp, &self->interp, &multmp, &addtmp))
5428 Py_RETURN_NONE;
5429
5430 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
5431 {
5432 PyErr_SetString(PyExc_TypeError, "\"table\" argument of Pulsar must be a PyoTableObject.\n");
5433 Py_RETURN_NONE;
5434 }
5435
5436 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
5437
5438 if ( PyObject_HasAttrString((PyObject *)envtmp, "getTableStream") == 0 )
5439 {
5440 PyErr_SetString(PyExc_TypeError, "\"env\" argument of Pulsar must be a PyoTableObject.\n");
5441 Py_RETURN_NONE;
5442 }
5443
5444 self->env = PyObject_CallMethod((PyObject *)envtmp, "getTableStream", "");
5445
5446 if (phasetmp)
5447 {
5448 PyObject_CallMethod((PyObject *)self, "setPhase", "O", phasetmp);
5449 }
5450
5451 if (freqtmp)
5452 {
5453 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
5454 }
5455
5456 if (fractmp)
5457 {
5458 PyObject_CallMethod((PyObject *)self, "setFrac", "O", fractmp);
5459 }
5460
5461 if (multmp)
5462 {
5463 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
5464 }
5465
5466 if (addtmp)
5467 {
5468 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
5469 }
5470
5471 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
5472
5473 (*self->mode_func_ptr)(self);
5474
5475 SET_INTERP_POINTER
5476
5477 return (PyObject *)self;
5478 }
5479
5480 static PyObject * Pulsar_getServer(Pulsar* self) { GET_SERVER };
5481 static PyObject * Pulsar_getStream(Pulsar* self) { GET_STREAM };
5482 static PyObject * Pulsar_setMul(Pulsar *self, PyObject *arg) { SET_MUL };
5483 static PyObject * Pulsar_setAdd(Pulsar *self, PyObject *arg) { SET_ADD };
5484 static PyObject * Pulsar_setSub(Pulsar *self, PyObject *arg) { SET_SUB };
5485 static PyObject * Pulsar_setDiv(Pulsar *self, PyObject *arg) { SET_DIV };
5486
5487 static PyObject * Pulsar_play(Pulsar *self, PyObject *args, PyObject *kwds) { PLAY };
5488 static PyObject * Pulsar_out(Pulsar *self, PyObject *args, PyObject *kwds) { OUT };
5489 static PyObject * Pulsar_stop(Pulsar *self, PyObject *args, PyObject *kwds) { STOP };
5490
5491 static PyObject * Pulsar_multiply(Pulsar *self, PyObject *arg) { MULTIPLY };
5492 static PyObject * Pulsar_inplace_multiply(Pulsar *self, PyObject *arg) { INPLACE_MULTIPLY };
5493 static PyObject * Pulsar_add(Pulsar *self, PyObject *arg) { ADD };
5494 static PyObject * Pulsar_inplace_add(Pulsar *self, PyObject *arg) { INPLACE_ADD };
5495 static PyObject * Pulsar_sub(Pulsar *self, PyObject *arg) { SUB };
5496 static PyObject * Pulsar_inplace_sub(Pulsar *self, PyObject *arg) { INPLACE_SUB };
5497 static PyObject * Pulsar_div(Pulsar *self, PyObject *arg) { DIV };
5498 static PyObject * Pulsar_inplace_div(Pulsar *self, PyObject *arg) { INPLACE_DIV };
5499
5500 static PyObject *
5501 Pulsar_getTable(Pulsar* self)
5502 {
5503 Py_INCREF(self->table);
5504 return self->table;
5505 };
5506
5507 static PyObject *
5508 Pulsar_getEnv(Pulsar* self)
5509 {
5510 Py_INCREF(self->env);
5511 return self->env;
5512 };
5513
5514 static PyObject *
5515 Pulsar_setTable(Pulsar *self, PyObject *arg)
5516 {
5517 ASSERT_ARG_NOT_NULL
5518
5519 Py_DECREF(self->table);
5520 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
5521
5522 Py_RETURN_NONE;
5523 }
5524
5525 static PyObject *
5526 Pulsar_setEnv(Pulsar *self, PyObject *arg)
5527 {
5528 ASSERT_ARG_NOT_NULL
5529
5530 Py_DECREF(self->env);
5531 self->env = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
5532
5533 Py_RETURN_NONE;
5534 }
5535
5536 static PyObject * Pulsar_setFreq(Pulsar *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
5537 static PyObject * Pulsar_setPhase(Pulsar *self, PyObject *arg) { SET_PARAM(self->phase, self->phase_stream, 3); }
5538 static PyObject * Pulsar_setFrac(Pulsar *self, PyObject *arg) { SET_PARAM(self->frac, self->frac_stream, 4); }
5539
5540 static PyObject *
5541 Pulsar_setInterp(Pulsar *self, PyObject *arg)
5542 {
5543 ASSERT_ARG_NOT_NULL
5544
5545 if (PyNumber_Check(arg))
5546 {
5547 self->interp = PyLong_AsLong(PyNumber_Long(arg));
5548 }
5549
5550 SET_INTERP_POINTER
5551
5552 Py_RETURN_NONE;
5553 }
5554
5555 static PyMemberDef Pulsar_members[] =
5556 {
5557 {"server", T_OBJECT_EX, offsetof(Pulsar, server), 0, "Pyo server."},
5558 {"stream", T_OBJECT_EX, offsetof(Pulsar, stream), 0, "Stream object."},
5559 {"table", T_OBJECT_EX, offsetof(Pulsar, table), 0, "Waveform table."},
5560 {"freq", T_OBJECT_EX, offsetof(Pulsar, freq), 0, "Frequency in cycle per second."},
5561 {"phase", T_OBJECT_EX, offsetof(Pulsar, phase), 0, "Oscillator phase."},
5562 {"frac", T_OBJECT_EX, offsetof(Pulsar, frac), 0, "Table width inside whole length."},
5563 {"mul", T_OBJECT_EX, offsetof(Pulsar, mul), 0, "Mul factor."},
5564 {"add", T_OBJECT_EX, offsetof(Pulsar, add), 0, "Add factor."},
5565 {NULL} /* Sentinel */
5566 };
5567
5568 static PyMethodDef Pulsar_methods[] =
5569 {
5570 {"getTable", (PyCFunction)Pulsar_getTable, METH_NOARGS, "Returns waveform table object."},
5571 {"getEnv", (PyCFunction)Pulsar_getEnv, METH_NOARGS, "Returns object envelope."},
5572 {"getServer", (PyCFunction)Pulsar_getServer, METH_NOARGS, "Returns server object."},
5573 {"_getStream", (PyCFunction)Pulsar_getStream, METH_NOARGS, "Returns stream object."},
5574 {"play", (PyCFunction)Pulsar_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
5575 {"out", (PyCFunction)Pulsar_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
5576 {"stop", (PyCFunction)Pulsar_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
5577 {"setTable", (PyCFunction)Pulsar_setTable, METH_O, "Sets oscillator table."},
5578 {"setEnv", (PyCFunction)Pulsar_setEnv, METH_O, "Sets envelope table."},
5579 {"setFreq", (PyCFunction)Pulsar_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
5580 {"setPhase", (PyCFunction)Pulsar_setPhase, METH_O, "Sets oscillator phase."},
5581 {"setFrac", (PyCFunction)Pulsar_setFrac, METH_O, "Sets waveform width inside whole period length."},
5582 {"setInterp", (PyCFunction)Pulsar_setInterp, METH_O, "Sets Pulsar interpolation mode."},
5583 {"setMul", (PyCFunction)Pulsar_setMul, METH_O, "Sets oscillator mul factor."},
5584 {"setAdd", (PyCFunction)Pulsar_setAdd, METH_O, "Sets oscillator add factor."},
5585 {"setSub", (PyCFunction)Pulsar_setSub, METH_O, "Sets oscillator inverse add factor."},
5586 {"setDiv", (PyCFunction)Pulsar_setDiv, METH_O, "Sets inverse mul factor."},
5587 {NULL} /* Sentinel */
5588 };
5589
5590 static PyNumberMethods Pulsar_as_number =
5591 {
5592 (binaryfunc)Pulsar_add, /*nb_add*/
5593 (binaryfunc)Pulsar_sub, /*nb_subtract*/
5594 (binaryfunc)Pulsar_multiply, /*nb_multiply*/
5595 0, /*nb_remainder*/
5596 0, /*nb_divmod*/
5597 0, /*nb_power*/
5598 0, /*nb_neg*/
5599 0, /*nb_pos*/
5600 0, /*(unaryfunc)array_abs,*/
5601 0, /*nb_nonzero*/
5602 0, /*nb_invert*/
5603 0, /*nb_lshift*/
5604 0, /*nb_rshift*/
5605 0, /*nb_and*/
5606 0, /*nb_xor*/
5607 0, /*nb_or*/
5608 0, /*nb_int*/
5609 0, /*nb_long*/
5610 0, /*nb_float*/
5611 (binaryfunc)Pulsar_inplace_add, /*inplace_add*/
5612 (binaryfunc)Pulsar_inplace_sub, /*inplace_subtract*/
5613 (binaryfunc)Pulsar_inplace_multiply, /*inplace_multiply*/
5614 0, /*inplace_remainder*/
5615 0, /*inplace_power*/
5616 0, /*inplace_lshift*/
5617 0, /*inplace_rshift*/
5618 0, /*inplace_and*/
5619 0, /*inplace_xor*/
5620 0, /*inplace_or*/
5621 0, /*nb_floor_divide*/
5622 (binaryfunc)Pulsar_div, /*nb_true_divide*/
5623 0, /*nb_inplace_floor_divide*/
5624 (binaryfunc)Pulsar_inplace_div, /*nb_inplace_true_divide*/
5625 0, /* nb_index */
5626 };
5627
5628 PyTypeObject PulsarType =
5629 {
5630 PyVarObject_HEAD_INIT(NULL, 0)
5631 "_pyo.Pulsar_base", /*tp_name*/
5632 sizeof(Pulsar), /*tp_basicsize*/
5633 0, /*tp_itemsize*/
5634 (destructor)Pulsar_dealloc, /*tp_dealloc*/
5635 0, /*tp_print*/
5636 0, /*tp_getattr*/
5637 0, /*tp_setattr*/
5638 0, /*tp_as_async (tp_compare in Python 2)*/
5639 0, /*tp_repr*/
5640 &Pulsar_as_number, /*tp_as_number*/
5641 0, /*tp_as_sequence*/
5642 0, /*tp_as_mapping*/
5643 0, /*tp_hash */
5644 0, /*tp_call*/
5645 0, /*tp_str*/
5646 0, /*tp_getattro*/
5647 0, /*tp_setattro*/
5648 0, /*tp_as_buffer*/
5649 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
5650 "Pulsar objects. Generates pulsar synthesis oscillator.", /* tp_doc */
5651 (traverseproc)Pulsar_traverse, /* tp_traverse */
5652 (inquiry)Pulsar_clear, /* tp_clear */
5653 0, /* tp_richcompare */
5654 0, /* tp_weaklistoffset */
5655 0, /* tp_iter */
5656 0, /* tp_iternext */
5657 Pulsar_methods, /* tp_methods */
5658 Pulsar_members, /* tp_members */
5659 0, /* tp_getset */
5660 0, /* tp_base */
5661 0, /* tp_dict */
5662 0, /* tp_descr_get */
5663 0, /* tp_descr_set */
5664 0, /* tp_dictoffset */
5665 0, /* tp_init */
5666 0, /* tp_alloc */
5667 Pulsar_new, /* tp_new */
5668 };
5669
5670 /**************/
5671 /* TableRead object */
5672 /**************/
5673 typedef struct
5674 {
5675 pyo_audio_HEAD
5676 PyObject *table;
5677 PyObject *freq;
5678 Stream *freq_stream;
5679 int loop;
5680 int go;
5681 int modebuffer[3];
5682 double pointerPos;
5683 MYFLT lastValue;
5684 int keepLast;
5685 MYFLT *trigsBuffer;
5686 TriggerStream *trig_stream;
5687 int init;
5688 int interp; /* 0 = default to 2, 1 = nointerp, 2 = linear, 3 = cos, 4 = cubic */
5689 MYFLT (*interp_func_ptr)(MYFLT *, T_SIZE_T, MYFLT, T_SIZE_T);
5690 } TableRead;
5691
5692 static void
5693 TableRead_readframes_i(TableRead *self)
5694 {
5695 int i;
5696 MYFLT fr, inc, fpart;
5697 T_SIZE_T ipart;
5698 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
5699 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
5700
5701 fr = PyFloat_AS_DOUBLE(self->freq);
5702 inc = fr * size / self->sr;
5703
5704 if (self->go == 0)
5705 PyObject_CallMethod((PyObject *)self, "stop", NULL);
5706
5707 for (i = 0; i < self->bufsize; i++)
5708 {
5709 self->trigsBuffer[i] = 0.0;
5710
5711 if (self->pointerPos < 0)
5712 {
5713 if (self->init == 0)
5714 {
5715 self->trigsBuffer[i] = 1.0;
5716
5717 if (self->loop == 0)
5718 self->go = 0;
5719 }
5720 else
5721 self->init = 0;
5722
5723 self->pointerPos = size + self->pointerPos;
5724 }
5725 else if (self->pointerPos >= size && self->go)
5726 {
5727 self->trigsBuffer[i] = 1.0;
5728
5729 if (self->loop == 1)
5730 self->pointerPos -= size;
5731 else
5732 self->go = 0;
5733 }
5734
5735 if (self->go == 1)
5736 {
5737 ipart = (T_SIZE_T)self->pointerPos;
5738 fpart = self->pointerPos - ipart;
5739 self->lastValue = self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
5740 }
5741 else
5742 {
5743 if (self->keepLast == 0)
5744 self->data[i] = 0.0;
5745 else
5746 self->data[i] = self->lastValue;
5747 }
5748
5749 self->pointerPos += inc;
5750 }
5751 }
5752
5753 static void
5754 TableRead_readframes_a(TableRead *self)
5755 {
5756 int i;
5757 MYFLT inc, fpart, sizeOnSr;
5758 T_SIZE_T ipart;
5759 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
5760 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
5761
5762 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
5763
5764 sizeOnSr = size / self->sr;
5765
5766 if (self->go == 0)
5767 PyObject_CallMethod((PyObject *)self, "stop", NULL);
5768
5769 for (i = 0; i < self->bufsize; i++)
5770 {
5771 self->trigsBuffer[i] = 0.0;
5772
5773 if (self->pointerPos < 0)
5774 {
5775 if (self->init == 0)
5776 {
5777 self->trigsBuffer[i] = 1.0;
5778
5779 if (self->loop == 0)
5780 self->go = 0;
5781 }
5782 else
5783 self->init = 0;
5784
5785 self->pointerPos = size + self->pointerPos;
5786 }
5787 else if (self->pointerPos >= size && self->go)
5788 {
5789 self->trigsBuffer[i] = 1.0;
5790
5791 if (self->loop == 1)
5792 self->pointerPos -= size;
5793 else
5794 self->go = 0;
5795 }
5796
5797 if (self->go == 1)
5798 {
5799 ipart = (T_SIZE_T)self->pointerPos;
5800 fpart = self->pointerPos - ipart;
5801 self->lastValue = self->data[i] = (*self->interp_func_ptr)(tablelist, ipart, fpart, size);
5802 }
5803 else
5804 {
5805 if (self->keepLast == 0)
5806 self->data[i] = 0.0;
5807 else
5808 self->data[i] = self->lastValue;
5809 }
5810
5811 inc = fr[i] * sizeOnSr;
5812 self->pointerPos += inc;
5813 }
5814 }
5815
5816 static void TableRead_postprocessing_ii(TableRead *self) { POST_PROCESSING_II };
5817 static void TableRead_postprocessing_ai(TableRead *self) { POST_PROCESSING_AI };
5818 static void TableRead_postprocessing_ia(TableRead *self) { POST_PROCESSING_IA };
5819 static void TableRead_postprocessing_aa(TableRead *self) { POST_PROCESSING_AA };
5820 static void TableRead_postprocessing_ireva(TableRead *self) { POST_PROCESSING_IREVA };
5821 static void TableRead_postprocessing_areva(TableRead *self) { POST_PROCESSING_AREVA };
5822 static void TableRead_postprocessing_revai(TableRead *self) { POST_PROCESSING_REVAI };
5823 static void TableRead_postprocessing_revaa(TableRead *self) { POST_PROCESSING_REVAA };
5824 static void TableRead_postprocessing_revareva(TableRead *self) { POST_PROCESSING_REVAREVA };
5825
5826 static void
5827 TableRead_setProcMode(TableRead *self)
5828 {
5829 int procmode, muladdmode;
5830 procmode = self->modebuffer[2];
5831 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
5832
5833 switch (procmode)
5834 {
5835 case 0:
5836 self->proc_func_ptr = TableRead_readframes_i;
5837 break;
5838
5839 case 1:
5840 self->proc_func_ptr = TableRead_readframes_a;
5841 break;
5842 }
5843
5844 switch (muladdmode)
5845 {
5846 case 0:
5847 self->muladd_func_ptr = TableRead_postprocessing_ii;
5848 break;
5849
5850 case 1:
5851 self->muladd_func_ptr = TableRead_postprocessing_ai;
5852 break;
5853
5854 case 2:
5855 self->muladd_func_ptr = TableRead_postprocessing_revai;
5856 break;
5857
5858 case 10:
5859 self->muladd_func_ptr = TableRead_postprocessing_ia;
5860 break;
5861
5862 case 11:
5863 self->muladd_func_ptr = TableRead_postprocessing_aa;
5864 break;
5865
5866 case 12:
5867 self->muladd_func_ptr = TableRead_postprocessing_revaa;
5868 break;
5869
5870 case 20:
5871 self->muladd_func_ptr = TableRead_postprocessing_ireva;
5872 break;
5873
5874 case 21:
5875 self->muladd_func_ptr = TableRead_postprocessing_areva;
5876 break;
5877
5878 case 22:
5879 self->muladd_func_ptr = TableRead_postprocessing_revareva;
5880 break;
5881 }
5882 }
5883
5884 static void
5885 TableRead_compute_next_data_frame(TableRead *self)
5886 {
5887 (*self->proc_func_ptr)(self);
5888 (*self->muladd_func_ptr)(self);
5889 }
5890
5891 static int
5892 TableRead_traverse(TableRead *self, visitproc visit, void *arg)
5893 {
5894 pyo_VISIT
5895 Py_VISIT(self->freq);
5896 return 0;
5897 }
5898
5899 static int
5900 TableRead_clear(TableRead *self)
5901 {
5902 pyo_CLEAR
5903 Py_CLEAR(self->freq);
5904 return 0;
5905 }
5906
5907 static void
5908 TableRead_dealloc(TableRead* self)
5909 {
5910 pyo_DEALLOC
5911 PyMem_RawFree(self->trigsBuffer);
5912 TableRead_clear(self);
5913 Py_TYPE(self->trig_stream)->tp_free((PyObject*)self->trig_stream);
5914 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
5915 Py_TYPE(self)->tp_free((PyObject*)self);
5916 }
5917
5918 static PyObject *
5919 TableRead_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
5920 {
5921 int i;
5922 MYFLT *tablelist;
5923 PyObject *tabletmp, *freqtmp = NULL, *multmp = NULL, *addtmp = NULL;
5924 TableRead *self;
5925 self = (TableRead *)type->tp_alloc(type, 0);
5926
5927 self->freq = PyFloat_FromDouble(1);
5928 self->loop = 0;
5929 self->init = 1;
5930 self->keepLast = 0;
5931 self->lastValue = 0.0;
5932 self->modebuffer[0] = 0;
5933 self->modebuffer[1] = 0;
5934 self->modebuffer[2] = 0;
5935 self->pointerPos = 0.;
5936 self->interp = 2;
5937
5938 INIT_OBJECT_COMMON
5939 Stream_setFunctionPtr(self->stream, TableRead_compute_next_data_frame);
5940 self->mode_func_ptr = TableRead_setProcMode;
5941
5942 static char *kwlist[] = {"table", "freq", "loop", "interp", "mul", "add", NULL};
5943
5944 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OiiOO", kwlist, &tabletmp, &freqtmp, &self->loop, &self->interp, &multmp, &addtmp))
5945 Py_RETURN_NONE;
5946
5947 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
5948 {
5949 PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableRead must be a PyoTableObject.\n");
5950 Py_RETURN_NONE;
5951 }
5952
5953 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
5954
5955 if (freqtmp)
5956 {
5957 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
5958 }
5959
5960 if (multmp)
5961 {
5962 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
5963 }
5964
5965 if (addtmp)
5966 {
5967 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
5968 }
5969
5970 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
5971
5972 self->trigsBuffer = (MYFLT *)PyMem_RawRealloc(self->trigsBuffer, self->bufsize * sizeof(MYFLT));
5973
5974 tablelist = TableStream_getData((TableStream *)self->table);
5975
5976 for (i = 0; i < self->bufsize; i++)
5977 {
5978 self->trigsBuffer[i] = 0.0;
5979 self->data[i] = tablelist[0];
5980 }
5981
5982 MAKE_NEW_TRIGGER_STREAM(self->trig_stream, &TriggerStreamType, NULL);
5983 TriggerStream_setData(self->trig_stream, self->trigsBuffer);
5984
5985 (*self->mode_func_ptr)(self);
5986
5987 SET_INTERP_POINTER
5988
5989 self->init = 1;
5990
5991 return (PyObject *)self;
5992 }
5993
5994 static PyObject * TableRead_getServer(TableRead* self) { GET_SERVER };
5995 static PyObject * TableRead_getStream(TableRead* self) { GET_STREAM };
5996 static PyObject * TableRead_getTriggerStream(TableRead* self) { GET_TRIGGER_STREAM };
5997 static PyObject * TableRead_setMul(TableRead *self, PyObject *arg) { SET_MUL };
5998 static PyObject * TableRead_setAdd(TableRead *self, PyObject *arg) { SET_ADD };
5999 static PyObject * TableRead_setSub(TableRead *self, PyObject *arg) { SET_SUB };
6000 static PyObject * TableRead_setDiv(TableRead *self, PyObject *arg) { SET_DIV };
6001
6002 static PyObject * TableRead_play(TableRead *self, PyObject *args, PyObject *kwds)
6003 {
6004 self->pointerPos = 0.0;
6005 self->init = 1;
6006 self->go = 1;
6007 PLAY
6008 };
6009
6010 static PyObject * TableRead_out(TableRead *self, PyObject *args, PyObject *kwds)
6011 {
6012 self->pointerPos = 0.0;
6013 self->init = 1;
6014 self->go = 1;
6015 OUT
6016 };
6017 static PyObject * TableRead_stop(TableRead *self, PyObject *args, PyObject *kwds)
6018 {
6019 int i, nearestBuf = 0;
6020 float wait = 0.0;
6021
6022 static char *kwlist[] = {"wait", NULL};
6023
6024 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|f", kwlist, &wait))
6025 return PyLong_FromLong(-1);
6026
6027 if (wait == 0)
6028 {
6029 self->go = 0;
6030 Stream_setStreamActive(self->stream, 0);
6031 Stream_setStreamChnl(self->stream, 0);
6032 Stream_setStreamToDac(self->stream, 0);
6033
6034 if (self->keepLast == 0)
6035 {
6036 for (i = 0; i < self->bufsize; i++)
6037 {
6038 self->data[i] = 0;
6039 }
6040 }
6041 else
6042 {
6043 for (i = 0; i < self->bufsize; i++)
6044 {
6045 self->data[i] = self->lastValue;
6046 }
6047 }
6048 }
6049 else
6050 {
6051 Stream_resetBufferCount(self->stream);
6052 nearestBuf = (int)roundf((wait * self->sr) / self->bufsize + 0.5);
6053 Stream_setDuration(self->stream, nearestBuf);
6054 }
6055
6056 Py_RETURN_NONE;
6057 };
6058
6059 static PyObject * TableRead_multiply(TableRead *self, PyObject *arg) { MULTIPLY };
6060 static PyObject * TableRead_inplace_multiply(TableRead *self, PyObject *arg) { INPLACE_MULTIPLY };
6061 static PyObject * TableRead_add(TableRead *self, PyObject *arg) { ADD };
6062 static PyObject * TableRead_inplace_add(TableRead *self, PyObject *arg) { INPLACE_ADD };
6063 static PyObject * TableRead_sub(TableRead *self, PyObject *arg) { SUB };
6064 static PyObject * TableRead_inplace_sub(TableRead *self, PyObject *arg) { INPLACE_SUB };
6065 static PyObject * TableRead_div(TableRead *self, PyObject *arg) { DIV };
6066 static PyObject * TableRead_inplace_div(TableRead *self, PyObject *arg) { INPLACE_DIV };
6067
6068 static PyObject *
6069 TableRead_getTable(TableRead* self)
6070 {
6071 Py_INCREF(self->table);
6072 return self->table;
6073 };
6074
6075 static PyObject *
6076 TableRead_setTable(TableRead *self, PyObject *arg)
6077 {
6078 ASSERT_ARG_NOT_NULL
6079
6080 Py_DECREF(self->table);
6081 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
6082
6083 Py_RETURN_NONE;
6084 }
6085
6086 static PyObject * TableRead_setFreq(TableRead *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
6087
6088 static PyObject *
6089 TableRead_setLoop(TableRead *self, PyObject *arg)
6090 {
6091 ASSERT_ARG_NOT_NULL
6092
6093 self->loop = PyLong_AsLong(arg);
6094
6095 Py_RETURN_NONE;
6096 }
6097
6098 static PyObject *
6099 TableRead_setInterp(TableRead *self, PyObject *arg)
6100 {
6101 ASSERT_ARG_NOT_NULL
6102
6103 if (PyNumber_Check(arg))
6104 {
6105 self->interp = PyLong_AsLong(PyNumber_Long(arg));
6106 }
6107
6108 SET_INTERP_POINTER
6109
6110 Py_RETURN_NONE;
6111 }
6112
6113 static PyObject *
6114 TableRead_setKeepLast(TableRead *self, PyObject *arg)
6115 {
6116 ASSERT_ARG_NOT_NULL
6117
6118 self->keepLast = PyLong_AsLong(arg);
6119
6120 Py_RETURN_NONE;
6121 }
6122
6123 static PyObject *
6124 TableRead_reset(TableRead *self)
6125 {
6126 self->pointerPos = 0.0;
6127 Py_RETURN_NONE;
6128 }
6129
6130 static PyMemberDef TableRead_members[] =
6131 {
6132 {"server", T_OBJECT_EX, offsetof(TableRead, server), 0, "Pyo server."},
6133 {"stream", T_OBJECT_EX, offsetof(TableRead, stream), 0, "Stream object."},
6134 {"trig_stream", T_OBJECT_EX, offsetof(TableRead, trig_stream), 0, "Trigger Stream object."},
6135 {"table", T_OBJECT_EX, offsetof(TableRead, table), 0, "Waveform table."},
6136 {"freq", T_OBJECT_EX, offsetof(TableRead, freq), 0, "Frequency in cycle per second."},
6137 {"mul", T_OBJECT_EX, offsetof(TableRead, mul), 0, "Mul factor."},
6138 {"add", T_OBJECT_EX, offsetof(TableRead, add), 0, "Add factor."},
6139 {NULL} /* Sentinel */
6140 };
6141
6142 static PyMethodDef TableRead_methods[] =
6143 {
6144 {"getTable", (PyCFunction)TableRead_getTable, METH_NOARGS, "Returns waveform table object."},
6145 {"getServer", (PyCFunction)TableRead_getServer, METH_NOARGS, "Returns server object."},
6146 {"_getStream", (PyCFunction)TableRead_getStream, METH_NOARGS, "Returns stream object."},
6147 {"_getTriggerStream", (PyCFunction)TableRead_getTriggerStream, METH_NOARGS, "Returns trigger stream object."},
6148 {"play", (PyCFunction)TableRead_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
6149 {"out", (PyCFunction)TableRead_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
6150 {"stop", (PyCFunction)TableRead_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
6151 {"setTable", (PyCFunction)TableRead_setTable, METH_O, "Sets oscillator table."},
6152 {"setFreq", (PyCFunction)TableRead_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
6153 {"setLoop", (PyCFunction)TableRead_setLoop, METH_O, "Sets the looping mode."},
6154 {"setInterp", (PyCFunction)TableRead_setInterp, METH_O, "Sets reader interpolation mode."},
6155 {"setKeepLast", (PyCFunction)TableRead_setKeepLast, METH_O, "Sets keepLast mode."},
6156 {"reset", (PyCFunction)TableRead_reset, METH_NOARGS, "Resets pointer position to 0."},
6157 {"setMul", (PyCFunction)TableRead_setMul, METH_O, "Sets oscillator mul factor."},
6158 {"setAdd", (PyCFunction)TableRead_setAdd, METH_O, "Sets oscillator add factor."},
6159 {"setSub", (PyCFunction)TableRead_setSub, METH_O, "Sets oscillator inverse add factor."},
6160 {"setDiv", (PyCFunction)TableRead_setDiv, METH_O, "Sets inverse mul factor."},
6161 {NULL} /* Sentinel */
6162 };
6163
6164 static PyNumberMethods TableRead_as_number =
6165 {
6166 (binaryfunc)TableRead_add, /*nb_add*/
6167 (binaryfunc)TableRead_sub, /*nb_subtract*/
6168 (binaryfunc)TableRead_multiply, /*nb_multiply*/
6169 0, /*nb_remainder*/
6170 0, /*nb_divmod*/
6171 0, /*nb_power*/
6172 0, /*nb_neg*/
6173 0, /*nb_pos*/
6174 0, /*(unaryfunc)array_abs,*/
6175 0, /*nb_nonzero*/
6176 0, /*nb_invert*/
6177 0, /*nb_lshift*/
6178 0, /*nb_rshift*/
6179 0, /*nb_and*/
6180 0, /*nb_xor*/
6181 0, /*nb_or*/
6182 0, /*nb_int*/
6183 0, /*nb_long*/
6184 0, /*nb_float*/
6185 (binaryfunc)TableRead_inplace_add, /*inplace_add*/
6186 (binaryfunc)TableRead_inplace_sub, /*inplace_subtract*/
6187 (binaryfunc)TableRead_inplace_multiply, /*inplace_multiply*/
6188 0, /*inplace_remainder*/
6189 0, /*inplace_power*/
6190 0, /*inplace_lshift*/
6191 0, /*inplace_rshift*/
6192 0, /*inplace_and*/
6193 0, /*inplace_xor*/
6194 0, /*inplace_or*/
6195 0, /*nb_floor_divide*/
6196 (binaryfunc)TableRead_div, /*nb_true_divide*/
6197 0, /*nb_inplace_floor_divide*/
6198 (binaryfunc)TableRead_inplace_div, /*nb_inplace_true_divide*/
6199 0, /* nb_index */
6200 };
6201
6202 PyTypeObject TableReadType =
6203 {
6204 PyVarObject_HEAD_INIT(NULL, 0)
6205 "_pyo.TableRead_base", /*tp_name*/
6206 sizeof(TableRead), /*tp_basicsize*/
6207 0, /*tp_itemsize*/
6208 (destructor)TableRead_dealloc, /*tp_dealloc*/
6209 0, /*tp_print*/
6210 0, /*tp_getattr*/
6211 0, /*tp_setattr*/
6212 0, /*tp_as_async (tp_compare in Python 2)*/
6213 0, /*tp_repr*/
6214 &TableRead_as_number, /*tp_as_number*/
6215 0, /*tp_as_sequence*/
6216 0, /*tp_as_mapping*/
6217 0, /*tp_hash */
6218 0, /*tp_call*/
6219 0, /*tp_str*/
6220 0, /*tp_getattro*/
6221 0, /*tp_setattro*/
6222 0, /*tp_as_buffer*/
6223 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
6224 "TableRead objects. Generates an oscillatory waveform.", /* tp_doc */
6225 (traverseproc)TableRead_traverse, /* tp_traverse */
6226 (inquiry)TableRead_clear, /* tp_clear */
6227 0, /* tp_richcompare */
6228 0, /* tp_weaklistoffset */
6229 0, /* tp_iter */
6230 0, /* tp_iternext */
6231 TableRead_methods, /* tp_methods */
6232 TableRead_members, /* tp_members */
6233 0, /* tp_getset */
6234 0, /* tp_base */
6235 0, /* tp_dict */
6236 0, /* tp_descr_get */
6237 0, /* tp_descr_set */
6238 0, /* tp_dictoffset */
6239 0, /* tp_init */
6240 0, /* tp_alloc */
6241 TableRead_new, /* tp_new */
6242 };
6243
6244 /*************/
6245 /* Fm object */
6246 /*************/
6247 typedef struct
6248 {
6249 pyo_audio_HEAD
6250 PyObject *car;
6251 Stream *car_stream;
6252 PyObject *ratio;
6253 Stream *ratio_stream;
6254 PyObject *index;
6255 Stream *index_stream;
6256 int modebuffer[5];
6257 MYFLT pointerPos_car;
6258 MYFLT pointerPos_mod;
6259 MYFLT scaleFactor;
6260 } Fm;
6261
6262 static void
6263 Fm_readframes_iii(Fm *self)
6264 {
6265 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6266 int i, ipart;
6267
6268 MYFLT car = PyFloat_AS_DOUBLE(self->car);
6269 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
6270 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
6271
6272 mod_freq = car * rat;
6273 mod_amp = mod_freq * ind;
6274 mod_delta = mod_freq * self->scaleFactor;
6275
6276 for (i = 0; i < self->bufsize; i++)
6277 {
6278 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6279 ipart = (int)self->pointerPos_mod;
6280 fpart = self->pointerPos_mod - ipart;
6281 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6282 self->pointerPos_mod += mod_delta;
6283
6284 car_freq = car + mod_val;
6285 car_delta = car_freq * self->scaleFactor;
6286 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6287 ipart = (int)self->pointerPos_car;
6288 fpart = self->pointerPos_car - ipart;
6289 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6290 self->pointerPos_car += car_delta;
6291 }
6292 }
6293
6294 static void
6295 Fm_readframes_aii(Fm *self)
6296 {
6297 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6298 int i, ipart;
6299
6300 MYFLT *car = Stream_getData((Stream *)self->car_stream);
6301 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
6302 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
6303
6304 for (i = 0; i < self->bufsize; i++)
6305 {
6306 mod_freq = car[i] * rat;
6307 mod_amp = mod_freq * ind;
6308 mod_delta = mod_freq * self->scaleFactor;
6309 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6310 ipart = (int)self->pointerPos_mod;
6311 fpart = self->pointerPos_mod - ipart;
6312 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6313 self->pointerPos_mod += mod_delta;
6314
6315 car_freq = car[i] + mod_val;
6316 car_delta = car_freq * self->scaleFactor;
6317 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6318 ipart = (int)self->pointerPos_car;
6319 fpart = self->pointerPos_car - ipart;
6320 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6321 self->pointerPos_car += car_delta;
6322 }
6323 }
6324
6325 static void
6326 Fm_readframes_iai(Fm *self)
6327 {
6328 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6329 int i, ipart;
6330
6331 MYFLT car = PyFloat_AS_DOUBLE(self->car);
6332 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
6333 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
6334
6335 for (i = 0; i < self->bufsize; i++)
6336 {
6337 mod_freq = car * rat[i];
6338 mod_amp = mod_freq * ind;
6339 mod_delta = mod_freq * self->scaleFactor;
6340 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6341 ipart = (int)self->pointerPos_mod;
6342 fpart = self->pointerPos_mod - ipart;
6343 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6344 self->pointerPos_mod += mod_delta;
6345
6346 car_freq = car + mod_val;
6347 car_delta = car_freq * self->scaleFactor;
6348 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6349 ipart = (int)self->pointerPos_car;
6350 fpart = self->pointerPos_car - ipart;
6351 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6352 self->pointerPos_car += car_delta;
6353 }
6354 }
6355
6356 static void
6357 Fm_readframes_aai(Fm *self)
6358 {
6359 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6360 int i, ipart;
6361
6362 MYFLT *car = Stream_getData((Stream *)self->car_stream);
6363 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
6364 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
6365
6366 for (i = 0; i < self->bufsize; i++)
6367 {
6368 mod_freq = car[i] * rat[i];
6369 mod_amp = mod_freq * ind;
6370 mod_delta = mod_freq * self->scaleFactor;
6371 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6372 ipart = (int)self->pointerPos_mod;
6373 fpart = self->pointerPos_mod - ipart;
6374 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6375 self->pointerPos_mod += mod_delta;
6376
6377 car_freq = car[i] + mod_val;
6378 car_delta = car_freq * self->scaleFactor;
6379 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6380 ipart = (int)self->pointerPos_car;
6381 fpart = self->pointerPos_car - ipart;
6382 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6383 self->pointerPos_car += car_delta;
6384 }
6385 }
6386
6387 static void
6388 Fm_readframes_iia(Fm *self)
6389 {
6390 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6391 int i, ipart;
6392
6393 MYFLT car = PyFloat_AS_DOUBLE(self->car);
6394 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
6395 MYFLT *ind = Stream_getData((Stream *)self->index_stream);
6396
6397 mod_freq = car * rat;
6398 mod_delta = mod_freq * self->scaleFactor;
6399
6400 for (i = 0; i < self->bufsize; i++)
6401 {
6402 mod_amp = mod_freq * ind[i];
6403 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6404 ipart = (int)self->pointerPos_mod;
6405 fpart = self->pointerPos_mod - ipart;
6406 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6407 self->pointerPos_mod += mod_delta;
6408
6409 car_freq = car + mod_val;
6410 car_delta = car_freq * self->scaleFactor;
6411 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6412 ipart = (int)self->pointerPos_car;
6413 fpart = self->pointerPos_car - ipart;
6414 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6415 self->pointerPos_car += car_delta;
6416 }
6417 }
6418
6419 static void
6420 Fm_readframes_aia(Fm *self)
6421 {
6422 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6423 int i, ipart;
6424
6425 MYFLT *car = Stream_getData((Stream *)self->car_stream);
6426 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
6427 MYFLT *ind = Stream_getData((Stream *)self->index_stream);
6428
6429 for (i = 0; i < self->bufsize; i++)
6430 {
6431 mod_freq = car[i] * rat;
6432 mod_amp = mod_freq * ind[i];
6433 mod_delta = mod_freq * self->scaleFactor;
6434 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6435 ipart = (int)self->pointerPos_mod;
6436 fpart = self->pointerPos_mod - ipart;
6437 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6438 self->pointerPos_mod += mod_delta;
6439
6440 car_freq = car[i] + mod_val;
6441 car_delta = car_freq * self->scaleFactor;
6442 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6443 ipart = (int)self->pointerPos_car;
6444 fpart = self->pointerPos_car - ipart;
6445 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6446 self->pointerPos_car += car_delta;
6447 }
6448 }
6449
6450 static void
6451 Fm_readframes_iaa(Fm *self)
6452 {
6453 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6454 int i, ipart;
6455
6456 MYFLT car = PyFloat_AS_DOUBLE(self->car);
6457 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
6458 MYFLT *ind = Stream_getData((Stream *)self->index_stream);
6459
6460 for (i = 0; i < self->bufsize; i++)
6461 {
6462 mod_freq = car * rat[i];
6463 mod_amp = mod_freq * ind[i];
6464 mod_delta = mod_freq * self->scaleFactor;
6465 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6466 ipart = (int)self->pointerPos_mod;
6467 fpart = self->pointerPos_mod - ipart;
6468 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6469 self->pointerPos_mod += mod_delta;
6470
6471 car_freq = car + mod_val;
6472 car_delta = car_freq * self->scaleFactor;
6473 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6474 ipart = (int)self->pointerPos_car;
6475 fpart = self->pointerPos_car - ipart;
6476 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6477 self->pointerPos_car += car_delta;
6478 }
6479 }
6480
6481 static void
6482 Fm_readframes_aaa(Fm *self)
6483 {
6484 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_delta, fpart;
6485 int i, ipart;
6486
6487 MYFLT *car = Stream_getData((Stream *)self->car_stream);
6488 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
6489 MYFLT *ind = Stream_getData((Stream *)self->index_stream);
6490
6491 for (i = 0; i < self->bufsize; i++)
6492 {
6493 mod_freq = car[i] * rat[i];
6494 mod_amp = mod_freq * ind[i];
6495 mod_delta = mod_freq * self->scaleFactor;
6496 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6497 ipart = (int)self->pointerPos_mod;
6498 fpart = self->pointerPos_mod - ipart;
6499 mod_val = mod_amp * (SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart);
6500 self->pointerPos_mod += mod_delta;
6501
6502 car_freq = car[i] + mod_val;
6503 car_delta = car_freq * self->scaleFactor;
6504 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6505 ipart = (int)self->pointerPos_car;
6506 fpart = self->pointerPos_car - ipart;
6507 self->data[i] = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6508 self->pointerPos_car += car_delta;
6509 }
6510 }
6511
6512 static void Fm_postprocessing_ii(Fm *self) { POST_PROCESSING_II };
6513 static void Fm_postprocessing_ai(Fm *self) { POST_PROCESSING_AI };
6514 static void Fm_postprocessing_ia(Fm *self) { POST_PROCESSING_IA };
6515 static void Fm_postprocessing_aa(Fm *self) { POST_PROCESSING_AA };
6516 static void Fm_postprocessing_ireva(Fm *self) { POST_PROCESSING_IREVA };
6517 static void Fm_postprocessing_areva(Fm *self) { POST_PROCESSING_AREVA };
6518 static void Fm_postprocessing_revai(Fm *self) { POST_PROCESSING_REVAI };
6519 static void Fm_postprocessing_revaa(Fm *self) { POST_PROCESSING_REVAA };
6520 static void Fm_postprocessing_revareva(Fm *self) { POST_PROCESSING_REVAREVA };
6521
6522 static void
6523 Fm_setProcMode(Fm *self)
6524 {
6525 int procmode, muladdmode;
6526 procmode = self->modebuffer[2] + self->modebuffer[3] * 10 + self->modebuffer[4] * 100;
6527 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
6528
6529 switch (procmode)
6530 {
6531 case 0:
6532 self->proc_func_ptr = Fm_readframes_iii;
6533 break;
6534
6535 case 1:
6536 self->proc_func_ptr = Fm_readframes_aii;
6537 break;
6538
6539 case 10:
6540 self->proc_func_ptr = Fm_readframes_iai;
6541 break;
6542
6543 case 11:
6544 self->proc_func_ptr = Fm_readframes_aai;
6545 break;
6546
6547 case 100:
6548 self->proc_func_ptr = Fm_readframes_iia;
6549 break;
6550
6551 case 101:
6552 self->proc_func_ptr = Fm_readframes_aia;
6553 break;
6554
6555 case 110:
6556 self->proc_func_ptr = Fm_readframes_iaa;
6557 break;
6558
6559 case 111:
6560 self->proc_func_ptr = Fm_readframes_aaa;
6561 break;
6562 }
6563
6564 switch (muladdmode)
6565 {
6566 case 0:
6567 self->muladd_func_ptr = Fm_postprocessing_ii;
6568 break;
6569
6570 case 1:
6571 self->muladd_func_ptr = Fm_postprocessing_ai;
6572 break;
6573
6574 case 2:
6575 self->muladd_func_ptr = Fm_postprocessing_revai;
6576 break;
6577
6578 case 10:
6579 self->muladd_func_ptr = Fm_postprocessing_ia;
6580 break;
6581
6582 case 11:
6583 self->muladd_func_ptr = Fm_postprocessing_aa;
6584 break;
6585
6586 case 12:
6587 self->muladd_func_ptr = Fm_postprocessing_revaa;
6588 break;
6589
6590 case 20:
6591 self->muladd_func_ptr = Fm_postprocessing_ireva;
6592 break;
6593
6594 case 21:
6595 self->muladd_func_ptr = Fm_postprocessing_areva;
6596 break;
6597
6598 case 22:
6599 self->muladd_func_ptr = Fm_postprocessing_revareva;
6600 break;
6601 }
6602 }
6603
6604 static void
6605 Fm_compute_next_data_frame(Fm *self)
6606 {
6607 (*self->proc_func_ptr)(self);
6608 (*self->muladd_func_ptr)(self);
6609 }
6610
6611 static int
6612 Fm_traverse(Fm *self, visitproc visit, void *arg)
6613 {
6614 pyo_VISIT
6615 Py_VISIT(self->car);
6616 Py_VISIT(self->ratio);
6617 Py_VISIT(self->index);
6618 return 0;
6619 }
6620
6621 static int
6622 Fm_clear(Fm *self)
6623 {
6624 pyo_CLEAR
6625 Py_CLEAR(self->car);
6626 Py_CLEAR(self->ratio);
6627 Py_CLEAR(self->index);
6628 return 0;
6629 }
6630
6631 static void
6632 Fm_dealloc(Fm* self)
6633 {
6634 pyo_DEALLOC
6635 Fm_clear(self);
6636 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
6637 Py_TYPE(self)->tp_free((PyObject*)self);
6638 }
6639
6640 static PyObject *
6641 Fm_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
6642 {
6643 int i;
6644 PyObject *cartmp = NULL, *ratiotmp = NULL, *indextmp = NULL, *multmp = NULL, *addtmp = NULL;
6645 Fm *self;
6646 self = (Fm *)type->tp_alloc(type, 0);
6647
6648 self->car = PyFloat_FromDouble(100);
6649 self->ratio = PyFloat_FromDouble(0.5);
6650 self->index = PyFloat_FromDouble(5);
6651 self->modebuffer[0] = 0;
6652 self->modebuffer[1] = 0;
6653 self->modebuffer[2] = 0;
6654 self->modebuffer[3] = 0;
6655 self->modebuffer[4] = 0;
6656 self->pointerPos_car = self->pointerPos_mod = 0.;
6657
6658 INIT_OBJECT_COMMON
6659 Stream_setFunctionPtr(self->stream, Fm_compute_next_data_frame);
6660 self->mode_func_ptr = Fm_setProcMode;
6661
6662 self->scaleFactor = 512.0 / self->sr;
6663
6664 static char *kwlist[] = {"carrier", "ratio", "index", "mul", "add", NULL};
6665
6666 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", kwlist, &cartmp, &ratiotmp, &indextmp, &multmp, &addtmp))
6667 Py_RETURN_NONE;
6668
6669 if (cartmp)
6670 {
6671 PyObject_CallMethod((PyObject *)self, "setCarrier", "O", cartmp);
6672 }
6673
6674 if (ratiotmp)
6675 {
6676 PyObject_CallMethod((PyObject *)self, "setRatio", "O", ratiotmp);
6677 }
6678
6679 if (indextmp)
6680 {
6681 PyObject_CallMethod((PyObject *)self, "setIndex", "O", indextmp);
6682 }
6683
6684 if (multmp)
6685 {
6686 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
6687 }
6688
6689 if (addtmp)
6690 {
6691 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
6692 }
6693
6694 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
6695
6696 (*self->mode_func_ptr)(self);
6697
6698 return (PyObject *)self;
6699 }
6700
6701 static PyObject * Fm_getServer(Fm* self) { GET_SERVER };
6702 static PyObject * Fm_getStream(Fm* self) { GET_STREAM };
6703 static PyObject * Fm_setMul(Fm *self, PyObject *arg) { SET_MUL };
6704 static PyObject * Fm_setAdd(Fm *self, PyObject *arg) { SET_ADD };
6705 static PyObject * Fm_setSub(Fm *self, PyObject *arg) { SET_SUB };
6706 static PyObject * Fm_setDiv(Fm *self, PyObject *arg) { SET_DIV };
6707
6708 static PyObject * Fm_play(Fm *self, PyObject *args, PyObject *kwds) { PLAY };
6709 static PyObject * Fm_out(Fm *self, PyObject *args, PyObject *kwds) { OUT };
6710 static PyObject * Fm_stop(Fm *self, PyObject *args, PyObject *kwds) { STOP };
6711
6712 static PyObject * Fm_multiply(Fm *self, PyObject *arg) { MULTIPLY };
6713 static PyObject * Fm_inplace_multiply(Fm *self, PyObject *arg) { INPLACE_MULTIPLY };
6714 static PyObject * Fm_add(Fm *self, PyObject *arg) { ADD };
6715 static PyObject * Fm_inplace_add(Fm *self, PyObject *arg) { INPLACE_ADD };
6716 static PyObject * Fm_sub(Fm *self, PyObject *arg) { SUB };
6717 static PyObject * Fm_inplace_sub(Fm *self, PyObject *arg) { INPLACE_SUB };
6718 static PyObject * Fm_div(Fm *self, PyObject *arg) { DIV };
6719 static PyObject * Fm_inplace_div(Fm *self, PyObject *arg) { INPLACE_DIV };
6720
6721 static PyObject * Fm_setCarrier(Fm *self, PyObject *arg) { SET_PARAM(self->car, self->car_stream, 2); }
6722 static PyObject * Fm_setRatio(Fm *self, PyObject *arg) { SET_PARAM(self->ratio, self->ratio_stream, 3); }
6723 static PyObject * Fm_setIndex(Fm *self, PyObject *arg) { SET_PARAM(self->index, self->index_stream, 4); }
6724
6725 static PyMemberDef Fm_members[] =
6726 {
6727 {"server", T_OBJECT_EX, offsetof(Fm, server), 0, "Pyo server."},
6728 {"stream", T_OBJECT_EX, offsetof(Fm, stream), 0, "Stream object."},
6729 {"carrier", T_OBJECT_EX, offsetof(Fm, car), 0, "Frequency in cycle per second."},
6730 {"ratio", T_OBJECT_EX, offsetof(Fm, ratio), 0, "Ratio carrier:modulator (mod freq = car*mod)."},
6731 {"index", T_OBJECT_EX, offsetof(Fm, index), 0, "Modulation index (mod amp = mod freq*index)."},
6732 {"mul", T_OBJECT_EX, offsetof(Fm, mul), 0, "Mul factor."},
6733 {"add", T_OBJECT_EX, offsetof(Fm, add), 0, "Add factor."},
6734 {NULL} /* Sentinel */
6735 };
6736
6737 static PyMethodDef Fm_methods[] =
6738 {
6739 {"getServer", (PyCFunction)Fm_getServer, METH_NOARGS, "Returns server object."},
6740 {"_getStream", (PyCFunction)Fm_getStream, METH_NOARGS, "Returns stream object."},
6741 {"play", (PyCFunction)Fm_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
6742 {"out", (PyCFunction)Fm_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
6743 {"stop", (PyCFunction)Fm_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
6744 {"setCarrier", (PyCFunction)Fm_setCarrier, METH_O, "Sets carrier frequency in cycle per second."},
6745 {"setRatio", (PyCFunction)Fm_setRatio, METH_O, "Sets car:mod ratio."},
6746 {"setIndex", (PyCFunction)Fm_setIndex, METH_O, "Sets modulation index."},
6747 {"setMul", (PyCFunction)Fm_setMul, METH_O, "Sets Fm mul factor."},
6748 {"setAdd", (PyCFunction)Fm_setAdd, METH_O, "Sets Fm add factor."},
6749 {"setSub", (PyCFunction)Fm_setSub, METH_O, "Sets inverse add factor."},
6750 {"setDiv", (PyCFunction)Fm_setDiv, METH_O, "Sets inverse mul factor."},
6751 {NULL} /* Sentinel */
6752 };
6753
6754 static PyNumberMethods Fm_as_number =
6755 {
6756 (binaryfunc)Fm_add, /*nb_add*/
6757 (binaryfunc)Fm_sub, /*nb_subtract*/
6758 (binaryfunc)Fm_multiply, /*nb_multiply*/
6759 0, /*nb_remainder*/
6760 0, /*nb_divmod*/
6761 0, /*nb_power*/
6762 0, /*nb_neg*/
6763 0, /*nb_pos*/
6764 0, /*(unaryfunc)array_abs*/
6765 0, /*nb_nonzero*/
6766 0, /*nb_invert*/
6767 0, /*nb_lshift*/
6768 0, /*nb_rshift*/
6769 0, /*nb_and*/
6770 0, /*nb_xor*/
6771 0, /*nb_or*/
6772 0, /*nb_int*/
6773 0, /*nb_long*/
6774 0, /*nb_float*/
6775 (binaryfunc)Fm_inplace_add, /*inplace_add*/
6776 (binaryfunc)Fm_inplace_sub, /*inplace_subtract*/
6777 (binaryfunc)Fm_inplace_multiply, /*inplace_multiply*/
6778 0, /*inplace_remainder*/
6779 0, /*inplace_power*/
6780 0, /*inplace_lshift*/
6781 0, /*inplace_rshift*/
6782 0, /*inplace_and*/
6783 0, /*inplace_xor*/
6784 0, /*inplace_or*/
6785 0, /*nb_floor_divide*/
6786 (binaryfunc)Fm_div, /*nb_true_divide*/
6787 0, /*nb_inplace_floor_divide*/
6788 (binaryfunc)Fm_inplace_div, /*nb_inplace_true_divide*/
6789 0, /* nb_index */
6790 };
6791
6792 PyTypeObject FmType =
6793 {
6794 PyVarObject_HEAD_INIT(NULL, 0)
6795 "_pyo.Fm_base", /*tp_name*/
6796 sizeof(Fm), /*tp_basicsize*/
6797 0, /*tp_itemsize*/
6798 (destructor)Fm_dealloc, /*tp_dealloc*/
6799 0, /*tp_print*/
6800 0, /*tp_getattr*/
6801 0, /*tp_setattr*/
6802 0, /*tp_as_async (tp_compare in Python 2)*/
6803 0, /*tp_repr*/
6804 &Fm_as_number, /*tp_as_number*/
6805 0, /*tp_as_sequence*/
6806 0, /*tp_as_mapping*/
6807 0, /*tp_hash */
6808 0, /*tp_call*/
6809 0, /*tp_str*/
6810 0, /*tp_getattro*/
6811 0, /*tp_setattro*/
6812 0, /*tp_as_buffer*/
6813 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
6814 "Fm objects. Generates a frequency modulation synthesis.", /* tp_doc */
6815 (traverseproc)Fm_traverse, /* tp_traverse */
6816 (inquiry)Fm_clear, /* tp_clear */
6817 0, /* tp_richcompare */
6818 0, /* tp_weaklistoffset */
6819 0, /* tp_iter */
6820 0, /* tp_iternext */
6821 Fm_methods, /* tp_methods */
6822 Fm_members, /* tp_members */
6823 0, /* tp_getset */
6824 0, /* tp_base */
6825 0, /* tp_dict */
6826 0, /* tp_descr_get */
6827 0, /* tp_descr_set */
6828 0, /* tp_dictoffset */
6829 0, /* tp_init */
6830 0, /* tp_alloc */
6831 Fm_new, /* tp_new */
6832 };
6833
6834 /*************/
6835 /* CrossFm object */
6836 /*************/
6837 typedef struct
6838 {
6839 pyo_audio_HEAD
6840 PyObject *car;
6841 Stream *car_stream;
6842 PyObject *ratio;
6843 Stream *ratio_stream;
6844 PyObject *ind1;
6845 Stream *ind1_stream;
6846 PyObject *ind2;
6847 Stream *ind2_stream;
6848 int modebuffer[6];
6849 MYFLT pointerPos_car;
6850 MYFLT pointerPos_mod;
6851 MYFLT scaleFactor;
6852 MYFLT car_val;
6853 } CrossFm;
6854
6855 static void
6856 CrossFm_readframes(CrossFm *self)
6857 {
6858 MYFLT mod_freq, mod_amp, mod_delta, mod_val, car_freq, car_amp, car_delta, fpart;
6859 int i, ipart;
6860 MYFLT car[self->bufsize];
6861 MYFLT rat[self->bufsize];
6862 MYFLT ind1[self->bufsize];
6863 MYFLT ind2[self->bufsize];
6864
6865 if (self->modebuffer[2] == 0)
6866 {
6867 MYFLT tmpcar = PyFloat_AS_DOUBLE(self->car);
6868
6869 for (i = 0; i < self->bufsize; i++)
6870 {
6871 car[i] = tmpcar;
6872 }
6873 }
6874 else
6875 {
6876 MYFLT *tmpcar = Stream_getData((Stream *)self->car_stream);
6877
6878 for (i = 0; i < self->bufsize; i++)
6879 {
6880 car[i] = tmpcar[i];
6881 }
6882 }
6883
6884 if (self->modebuffer[3] == 0)
6885 {
6886 MYFLT tmprat = PyFloat_AS_DOUBLE(self->ratio);
6887
6888 for (i = 0; i < self->bufsize; i++)
6889 {
6890 rat[i] = tmprat;
6891 }
6892 }
6893 else
6894 {
6895 MYFLT *tmprat = Stream_getData((Stream *)self->ratio_stream);
6896
6897 for (i = 0; i < self->bufsize; i++)
6898 {
6899 rat[i] = tmprat[i];
6900 }
6901 }
6902
6903 if (self->modebuffer[4] == 0)
6904 {
6905 MYFLT tmpind1 = PyFloat_AS_DOUBLE(self->ind1);
6906
6907 for (i = 0; i < self->bufsize; i++)
6908 {
6909 ind1[i] = tmpind1;
6910 }
6911 }
6912 else
6913 {
6914 MYFLT *tmpind1 = Stream_getData((Stream *)self->ind1_stream);
6915
6916 for (i = 0; i < self->bufsize; i++)
6917 {
6918 ind1[i] = tmpind1[i];
6919 }
6920 }
6921
6922 if (self->modebuffer[5] == 0)
6923 {
6924 MYFLT tmpind2 = PyFloat_AS_DOUBLE(self->ind2);
6925
6926 for (i = 0; i < self->bufsize; i++)
6927 {
6928 ind2[i] = tmpind2;
6929 }
6930 }
6931 else
6932 {
6933 MYFLT *tmpind2 = Stream_getData((Stream *)self->ind2_stream);
6934
6935 for (i = 0; i < self->bufsize; i++)
6936 {
6937 ind2[i] = tmpind2[i];
6938 }
6939 }
6940
6941 for (i = 0; i < self->bufsize; i++)
6942 {
6943 car_amp = car[i] * ind1[i];
6944 mod_freq = car[i] * rat[i];
6945 mod_amp = mod_freq * ind2[i];
6946 mod_delta = (mod_freq + self->car_val * car_amp) * self->scaleFactor;
6947 self->pointerPos_mod = Sine_clip(self->pointerPos_mod);
6948 ipart = (int)self->pointerPos_mod;
6949 fpart = self->pointerPos_mod - ipart;
6950 mod_val = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6951 self->pointerPos_mod += mod_delta;
6952
6953 car_freq = car[i] + (mod_val * mod_amp);
6954 car_delta = car_freq * self->scaleFactor;
6955 self->pointerPos_car = Sine_clip(self->pointerPos_car);
6956 ipart = (int)self->pointerPos_car;
6957 fpart = self->pointerPos_car - ipart;
6958 self->car_val = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * fpart;
6959 self->pointerPos_car += car_delta;
6960 self->data[i] = (self->car_val + mod_val) * 0.5;
6961 }
6962 }
6963
6964 static void CrossFm_postprocessing_ii(CrossFm *self) { POST_PROCESSING_II };
6965 static void CrossFm_postprocessing_ai(CrossFm *self) { POST_PROCESSING_AI };
6966 static void CrossFm_postprocessing_ia(CrossFm *self) { POST_PROCESSING_IA };
6967 static void CrossFm_postprocessing_aa(CrossFm *self) { POST_PROCESSING_AA };
6968 static void CrossFm_postprocessing_ireva(CrossFm *self) { POST_PROCESSING_IREVA };
6969 static void CrossFm_postprocessing_areva(CrossFm *self) { POST_PROCESSING_AREVA };
6970 static void CrossFm_postprocessing_revai(CrossFm *self) { POST_PROCESSING_REVAI };
6971 static void CrossFm_postprocessing_revaa(CrossFm *self) { POST_PROCESSING_REVAA };
6972 static void CrossFm_postprocessing_revareva(CrossFm *self) { POST_PROCESSING_REVAREVA };
6973
6974 static void
6975 CrossFm_setProcMode(CrossFm *self)
6976 {
6977 int muladdmode;
6978 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
6979
6980 self->proc_func_ptr = CrossFm_readframes;
6981
6982 switch (muladdmode)
6983 {
6984 case 0:
6985 self->muladd_func_ptr = CrossFm_postprocessing_ii;
6986 break;
6987
6988 case 1:
6989 self->muladd_func_ptr = CrossFm_postprocessing_ai;
6990 break;
6991
6992 case 2:
6993 self->muladd_func_ptr = CrossFm_postprocessing_revai;
6994 break;
6995
6996 case 10:
6997 self->muladd_func_ptr = CrossFm_postprocessing_ia;
6998 break;
6999
7000 case 11:
7001 self->muladd_func_ptr = CrossFm_postprocessing_aa;
7002 break;
7003
7004 case 12:
7005 self->muladd_func_ptr = CrossFm_postprocessing_revaa;
7006 break;
7007
7008 case 20:
7009 self->muladd_func_ptr = CrossFm_postprocessing_ireva;
7010 break;
7011
7012 case 21:
7013 self->muladd_func_ptr = CrossFm_postprocessing_areva;
7014 break;
7015
7016 case 22:
7017 self->muladd_func_ptr = CrossFm_postprocessing_revareva;
7018 break;
7019 }
7020 }
7021
7022 static void
7023 CrossFm_compute_next_data_frame(CrossFm *self)
7024 {
7025 (*self->proc_func_ptr)(self);
7026 (*self->muladd_func_ptr)(self);
7027 }
7028
7029 static int
7030 CrossFm_traverse(CrossFm *self, visitproc visit, void *arg)
7031 {
7032 pyo_VISIT
7033 Py_VISIT(self->car);
7034 Py_VISIT(self->ratio);
7035 Py_VISIT(self->ind1);
7036 Py_VISIT(self->ind2);
7037 return 0;
7038 }
7039
7040 static int
7041 CrossFm_clear(CrossFm *self)
7042 {
7043 pyo_CLEAR
7044 Py_CLEAR(self->car);
7045 Py_CLEAR(self->ratio);
7046 Py_CLEAR(self->ind1);
7047 Py_CLEAR(self->ind2);
7048 return 0;
7049 }
7050
7051 static void
7052 CrossFm_dealloc(CrossFm* self)
7053 {
7054 pyo_DEALLOC
7055 CrossFm_clear(self);
7056 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
7057 Py_TYPE(self)->tp_free((PyObject*)self);
7058 }
7059
7060 static PyObject *
7061 CrossFm_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
7062 {
7063 int i;
7064 PyObject *cartmp = NULL, *ratiotmp = NULL, *ind1tmp = NULL, *ind2tmp = NULL, *multmp = NULL, *addtmp = NULL;
7065 CrossFm *self;
7066 self = (CrossFm *)type->tp_alloc(type, 0);
7067
7068 self->car = PyFloat_FromDouble(100);
7069 self->ratio = PyFloat_FromDouble(0.5);
7070 self->ind1 = PyFloat_FromDouble(2);
7071 self->ind2 = PyFloat_FromDouble(2);
7072 self->modebuffer[0] = 0;
7073 self->modebuffer[1] = 0;
7074 self->modebuffer[2] = 0;
7075 self->modebuffer[3] = 0;
7076 self->modebuffer[4] = 0;
7077 self->modebuffer[5] = 0;
7078 self->pointerPos_car = self->pointerPos_mod = 0.;
7079 self->car_val = 0.;
7080
7081 INIT_OBJECT_COMMON
7082 Stream_setFunctionPtr(self->stream, CrossFm_compute_next_data_frame);
7083 self->mode_func_ptr = CrossFm_setProcMode;
7084
7085 self->scaleFactor = 512.0 / self->sr;
7086
7087 static char *kwlist[] = {"carrier", "ratio", "ind1", "ind2", "mul", "add", NULL};
7088
7089 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOOO", kwlist, &cartmp, &ratiotmp, &ind1tmp, &ind2tmp, &multmp, &addtmp))
7090 Py_RETURN_NONE;
7091
7092 if (cartmp)
7093 {
7094 PyObject_CallMethod((PyObject *)self, "setCarrier", "O", cartmp);
7095 }
7096
7097 if (ratiotmp)
7098 {
7099 PyObject_CallMethod((PyObject *)self, "setRatio", "O", ratiotmp);
7100 }
7101
7102 if (ind1tmp)
7103 {
7104 PyObject_CallMethod((PyObject *)self, "setInd1", "O", ind1tmp);
7105 }
7106
7107 if (ind2tmp)
7108 {
7109 PyObject_CallMethod((PyObject *)self, "setInd2", "O", ind2tmp);
7110 }
7111
7112 if (multmp)
7113 {
7114 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
7115 }
7116
7117 if (addtmp)
7118 {
7119 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
7120 }
7121
7122 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
7123
7124 (*self->mode_func_ptr)(self);
7125
7126 return (PyObject *)self;
7127 }
7128
7129 static PyObject * CrossFm_getServer(CrossFm* self) { GET_SERVER };
7130 static PyObject * CrossFm_getStream(CrossFm* self) { GET_STREAM };
7131 static PyObject * CrossFm_setMul(CrossFm *self, PyObject *arg) { SET_MUL };
7132 static PyObject * CrossFm_setAdd(CrossFm *self, PyObject *arg) { SET_ADD };
7133 static PyObject * CrossFm_setSub(CrossFm *self, PyObject *arg) { SET_SUB };
7134 static PyObject * CrossFm_setDiv(CrossFm *self, PyObject *arg) { SET_DIV };
7135
7136 static PyObject * CrossFm_play(CrossFm *self, PyObject *args, PyObject *kwds) { PLAY };
7137 static PyObject * CrossFm_out(CrossFm *self, PyObject *args, PyObject *kwds) { OUT };
7138 static PyObject * CrossFm_stop(CrossFm *self, PyObject *args, PyObject *kwds) { STOP };
7139
7140 static PyObject * CrossFm_multiply(CrossFm *self, PyObject *arg) { MULTIPLY };
7141 static PyObject * CrossFm_inplace_multiply(CrossFm *self, PyObject *arg) { INPLACE_MULTIPLY };
7142 static PyObject * CrossFm_add(CrossFm *self, PyObject *arg) { ADD };
7143 static PyObject * CrossFm_inplace_add(CrossFm *self, PyObject *arg) { INPLACE_ADD };
7144 static PyObject * CrossFm_sub(CrossFm *self, PyObject *arg) { SUB };
7145 static PyObject * CrossFm_inplace_sub(CrossFm *self, PyObject *arg) { INPLACE_SUB };
7146 static PyObject * CrossFm_div(CrossFm *self, PyObject *arg) { DIV };
7147 static PyObject * CrossFm_inplace_div(CrossFm *self, PyObject *arg) { INPLACE_DIV };
7148
7149 static PyObject * CrossFm_setCarrier(CrossFm *self, PyObject *arg) { SET_PARAM(self->car, self->car_stream, 2); }
7150 static PyObject * CrossFm_setRatio(CrossFm *self, PyObject *arg) { SET_PARAM(self->ratio, self->ratio_stream, 3); }
7151 static PyObject * CrossFm_setInd1(CrossFm *self, PyObject *arg) { SET_PARAM(self->ind1, self->ind1_stream, 4); }
7152 static PyObject * CrossFm_setInd2(CrossFm *self, PyObject *arg) { SET_PARAM(self->ind2, self->ind2_stream, 5); }
7153
7154 static PyMemberDef CrossFm_members[] =
7155 {
7156 {"server", T_OBJECT_EX, offsetof(CrossFm, server), 0, "Pyo server."},
7157 {"stream", T_OBJECT_EX, offsetof(CrossFm, stream), 0, "Stream object."},
7158 {"carrier", T_OBJECT_EX, offsetof(CrossFm, car), 0, "Frequency in cycle per second."},
7159 {"ratio", T_OBJECT_EX, offsetof(CrossFm, ratio), 0, "Ratio carrier:modulator (mod freq = car*mod)."},
7160 {"ind1", T_OBJECT_EX, offsetof(CrossFm, ind1), 0, "Modulation ind1 (car amp = car freq*ind1)."},
7161 {"ind2", T_OBJECT_EX, offsetof(CrossFm, ind2), 0, "Modulation ind2 (mod amp = mod freq*ind2)."},
7162 {"mul", T_OBJECT_EX, offsetof(CrossFm, mul), 0, "Mul factor."},
7163 {"add", T_OBJECT_EX, offsetof(CrossFm, add), 0, "Add factor."},
7164 {NULL} /* Sentinel */
7165 };
7166
7167 static PyMethodDef CrossFm_methods[] =
7168 {
7169 {"getServer", (PyCFunction)CrossFm_getServer, METH_NOARGS, "Returns server object."},
7170 {"_getStream", (PyCFunction)CrossFm_getStream, METH_NOARGS, "Returns stream object."},
7171 {"play", (PyCFunction)CrossFm_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
7172 {"out", (PyCFunction)CrossFm_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
7173 {"stop", (PyCFunction)CrossFm_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
7174 {"setCarrier", (PyCFunction)CrossFm_setCarrier, METH_O, "Sets carrier frequency in cycle per second."},
7175 {"setRatio", (PyCFunction)CrossFm_setRatio, METH_O, "Sets car:mod ratio."},
7176 {"setInd1", (PyCFunction)CrossFm_setInd1, METH_O, "Sets carrier index."},
7177 {"setInd2", (PyCFunction)CrossFm_setInd2, METH_O, "Sets modulation index."},
7178 {"setMul", (PyCFunction)CrossFm_setMul, METH_O, "Sets CrossFm mul factor."},
7179 {"setAdd", (PyCFunction)CrossFm_setAdd, METH_O, "Sets CrossFm add factor."},
7180 {"setSub", (PyCFunction)CrossFm_setSub, METH_O, "Sets inverse add factor."},
7181 {"setDiv", (PyCFunction)CrossFm_setDiv, METH_O, "Sets inverse mul factor."},
7182 {NULL} /* Sentinel */
7183 };
7184
7185 static PyNumberMethods CrossFm_as_number =
7186 {
7187 (binaryfunc)CrossFm_add, /*nb_add*/
7188 (binaryfunc)CrossFm_sub, /*nb_subtract*/
7189 (binaryfunc)CrossFm_multiply, /*nb_multiply*/
7190 0, /*nb_remainder*/
7191 0, /*nb_divmod*/
7192 0, /*nb_power*/
7193 0, /*nb_neg*/
7194 0, /*nb_pos*/
7195 0, /*(unaryfunc)array_abs*/
7196 0, /*nb_nonzero*/
7197 0, /*nb_invert*/
7198 0, /*nb_lshift*/
7199 0, /*nb_rshift*/
7200 0, /*nb_and*/
7201 0, /*nb_xor*/
7202 0, /*nb_or*/
7203 0, /*nb_int*/
7204 0, /*nb_long*/
7205 0, /*nb_float*/
7206 (binaryfunc)CrossFm_inplace_add, /*inplace_add*/
7207 (binaryfunc)CrossFm_inplace_sub, /*inplace_subtract*/
7208 (binaryfunc)CrossFm_inplace_multiply, /*inplace_multiply*/
7209 0, /*inplace_remainder*/
7210 0, /*inplace_power*/
7211 0, /*inplace_lshift*/
7212 0, /*inplace_rshift*/
7213 0, /*inplace_and*/
7214 0, /*inplace_xor*/
7215 0, /*inplace_or*/
7216 0, /*nb_floor_divide*/
7217 (binaryfunc)CrossFm_div, /*nb_true_divide*/
7218 0, /*nb_inplace_floor_divide*/
7219 (binaryfunc)CrossFm_inplace_div, /*nb_inplace_true_divide*/
7220 0, /* nb_ind1 */
7221 };
7222
7223 PyTypeObject CrossFmType =
7224 {
7225 PyVarObject_HEAD_INIT(NULL, 0)
7226 "_pyo.CrossFm_base", /*tp_name*/
7227 sizeof(CrossFm), /*tp_basicsize*/
7228 0, /*tp_itemsize*/
7229 (destructor)CrossFm_dealloc, /*tp_dealloc*/
7230 0, /*tp_print*/
7231 0, /*tp_getattr*/
7232 0, /*tp_setattr*/
7233 0, /*tp_as_async (tp_compare in Python 2)*/
7234 0, /*tp_repr*/
7235 &CrossFm_as_number, /*tp_as_number*/
7236 0, /*tp_as_sequence*/
7237 0, /*tp_as_mapping*/
7238 0, /*tp_hash */
7239 0, /*tp_call*/
7240 0, /*tp_str*/
7241 0, /*tp_getattro*/
7242 0, /*tp_setattro*/
7243 0, /*tp_as_buffer*/
7244 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
7245 "CrossFm objects. Generates a cross frequency modulation synthesis.", /* tp_doc */
7246 (traverseproc)CrossFm_traverse, /* tp_traverse */
7247 (inquiry)CrossFm_clear, /* tp_clear */
7248 0, /* tp_richcompare */
7249 0, /* tp_weaklistoffset */
7250 0, /* tp_iter */
7251 0, /* tp_iternext */
7252 CrossFm_methods, /* tp_methods */
7253 CrossFm_members, /* tp_members */
7254 0, /* tp_getset */
7255 0, /* tp_base */
7256 0, /* tp_dict */
7257 0, /* tp_descr_get */
7258 0, /* tp_descr_set */
7259 0, /* tp_dictoffset */
7260 0, /* tp_init */
7261 0, /* tp_alloc */
7262 CrossFm_new, /* tp_new */
7263 };
7264
7265 /*************/
7266 /* Blit object */
7267 /*************/
7268 typedef struct
7269 {
7270 pyo_audio_HEAD
7271 PyObject *freq;
7272 Stream *freq_stream;
7273 PyObject *harms;
7274 Stream *harms_stream;
7275 int modebuffer[4];
7276 MYFLT phase;
7277
7278 } Blit;
7279
7280 static void
7281 Blit_readframes_ii(Blit *self)
7282 {
7283 MYFLT p, m, rate, val;
7284 int i, nHarms;
7285
7286 MYFLT freq = PyFloat_AS_DOUBLE(self->freq);
7287 MYFLT hrms = PyFloat_AS_DOUBLE(self->harms);
7288
7289 nHarms = (int)hrms;
7290 m = 2.0 * nHarms + 1.0;
7291 p = self->sr / freq;
7292 rate = PI / p;
7293
7294 for (i = 0; i < self->bufsize; i++)
7295 {
7296 if (self->phase <= 0.0)
7297 val = 1.0;
7298 else
7299 {
7300 val = MYSIN(m * self->phase);
7301 val /= m * MYSIN(self->phase);
7302 }
7303
7304 self->phase += rate;
7305
7306 if (self->phase >= PI)
7307 self->phase -= PI;
7308
7309 self->data[i] = val;
7310 }
7311 }
7312
7313 static void
7314 Blit_readframes_ai(Blit *self)
7315 {
7316 MYFLT p, m, rate, val;
7317 int i, nHarms;
7318
7319 MYFLT *freq = Stream_getData((Stream *)self->freq_stream);
7320 MYFLT hrms = PyFloat_AS_DOUBLE(self->harms);
7321
7322 nHarms = (int)hrms;
7323 m = 2.0 * nHarms + 1.0;
7324
7325 for (i = 0; i < self->bufsize; i++)
7326 {
7327 p = self->sr / freq[i];
7328 rate = PI / p;
7329
7330 if (self->phase <= 0.0)
7331 val = 1.0;
7332 else
7333 {
7334 val = MYSIN(m * self->phase);
7335 val /= m * MYSIN(self->phase);
7336 }
7337
7338 self->phase += rate;
7339
7340 if (self->phase >= PI)
7341 self->phase -= PI;
7342
7343 self->data[i] = val;
7344 }
7345 }
7346
7347 static void
7348 Blit_readframes_ia(Blit *self)
7349 {
7350 MYFLT p, m, rate, val;
7351 int i, nHarms;
7352
7353 MYFLT freq = PyFloat_AS_DOUBLE(self->freq);
7354 MYFLT *hrms = Stream_getData((Stream *)self->harms_stream);
7355
7356 p = self->sr / freq;
7357 rate = PI / p;
7358
7359 for (i = 0; i < self->bufsize; i++)
7360 {
7361 nHarms = (int)hrms[i];
7362 m = 2.0 * nHarms + 1.0;
7363
7364 if (self->phase <= 0.0)
7365 val = 1.0;
7366 else
7367 {
7368 val = MYSIN(m * self->phase);
7369 val /= m * MYSIN(self->phase);
7370 }
7371
7372 self->phase += rate;
7373
7374 if (self->phase >= PI)
7375 self->phase -= PI;
7376
7377 self->data[i] = val;
7378 }
7379 }
7380
7381 static void
7382 Blit_readframes_aa(Blit *self)
7383 {
7384 MYFLT p, m, rate, val;
7385 int i, nHarms;
7386
7387 MYFLT *freq = Stream_getData((Stream *)self->freq_stream);
7388 MYFLT *hrms = Stream_getData((Stream *)self->harms_stream);
7389
7390 for (i = 0; i < self->bufsize; i++)
7391 {
7392 nHarms = (int)hrms[i];
7393 m = 2.0 * nHarms + 1.0;
7394 p = self->sr / freq[i];
7395 rate = PI / p;
7396
7397 if (self->phase <= 0.0)
7398 val = 1.0;
7399 else
7400 {
7401 val = MYSIN(m * self->phase);
7402 val /= m * MYSIN(self->phase);
7403 }
7404
7405 self->phase += rate;
7406
7407 if (self->phase >= PI)
7408 self->phase -= PI;
7409
7410 self->data[i] = val;
7411 }
7412 }
7413
7414 static void Blit_postprocessing_ii(Blit *self) { POST_PROCESSING_II };
7415 static void Blit_postprocessing_ai(Blit *self) { POST_PROCESSING_AI };
7416 static void Blit_postprocessing_ia(Blit *self) { POST_PROCESSING_IA };
7417 static void Blit_postprocessing_aa(Blit *self) { POST_PROCESSING_AA };
7418 static void Blit_postprocessing_ireva(Blit *self) { POST_PROCESSING_IREVA };
7419 static void Blit_postprocessing_areva(Blit *self) { POST_PROCESSING_AREVA };
7420 static void Blit_postprocessing_revai(Blit *self) { POST_PROCESSING_REVAI };
7421 static void Blit_postprocessing_revaa(Blit *self) { POST_PROCESSING_REVAA };
7422 static void Blit_postprocessing_revareva(Blit *self) { POST_PROCESSING_REVAREVA };
7423
7424 static void
7425 Blit_setProcMode(Blit *self)
7426 {
7427 int procmode, muladdmode;
7428 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
7429 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
7430
7431 switch (procmode)
7432 {
7433 case 0:
7434 self->proc_func_ptr = Blit_readframes_ii;
7435 break;
7436
7437 case 1:
7438 self->proc_func_ptr = Blit_readframes_ai;
7439 break;
7440
7441 case 10:
7442 self->proc_func_ptr = Blit_readframes_ia;
7443 break;
7444
7445 case 11:
7446 self->proc_func_ptr = Blit_readframes_aa;
7447 break;
7448 }
7449
7450 switch (muladdmode)
7451 {
7452 case 0:
7453 self->muladd_func_ptr = Blit_postprocessing_ii;
7454 break;
7455
7456 case 1:
7457 self->muladd_func_ptr = Blit_postprocessing_ai;
7458 break;
7459
7460 case 2:
7461 self->muladd_func_ptr = Blit_postprocessing_revai;
7462 break;
7463
7464 case 10:
7465 self->muladd_func_ptr = Blit_postprocessing_ia;
7466 break;
7467
7468 case 11:
7469 self->muladd_func_ptr = Blit_postprocessing_aa;
7470 break;
7471
7472 case 12:
7473 self->muladd_func_ptr = Blit_postprocessing_revaa;
7474 break;
7475
7476 case 20:
7477 self->muladd_func_ptr = Blit_postprocessing_ireva;
7478 break;
7479
7480 case 21:
7481 self->muladd_func_ptr = Blit_postprocessing_areva;
7482 break;
7483
7484 case 22:
7485 self->muladd_func_ptr = Blit_postprocessing_revareva;
7486 break;
7487 }
7488 }
7489
7490 static void
7491 Blit_compute_next_data_frame(Blit *self)
7492 {
7493 (*self->proc_func_ptr)(self);
7494 (*self->muladd_func_ptr)(self);
7495 }
7496
7497 static int
7498 Blit_traverse(Blit *self, visitproc visit, void *arg)
7499 {
7500 pyo_VISIT
7501 Py_VISIT(self->freq);
7502 Py_VISIT(self->harms);
7503 return 0;
7504 }
7505
7506 static int
7507 Blit_clear(Blit *self)
7508 {
7509 pyo_CLEAR
7510 Py_CLEAR(self->freq);
7511 Py_CLEAR(self->harms);
7512 return 0;
7513 }
7514
7515 static void
7516 Blit_dealloc(Blit* self)
7517 {
7518 pyo_DEALLOC
7519 Blit_clear(self);
7520 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
7521 Py_TYPE(self)->tp_free((PyObject*)self);
7522 }
7523
7524 static PyObject *
7525 Blit_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
7526 {
7527 int i;
7528 PyObject *freqtmp = NULL, *harmstmp = NULL, *multmp = NULL, *addtmp = NULL;
7529 Blit *self;
7530 self = (Blit *)type->tp_alloc(type, 0);
7531
7532 self->freq = PyFloat_FromDouble(100);
7533 self->harms = PyFloat_FromDouble(40);
7534 self->modebuffer[0] = 0;
7535 self->modebuffer[1] = 0;
7536 self->modebuffer[2] = 0;
7537 self->modebuffer[3] = 0;
7538 self->phase = 0.0;
7539
7540 INIT_OBJECT_COMMON
7541 Stream_setFunctionPtr(self->stream, Blit_compute_next_data_frame);
7542 self->mode_func_ptr = Blit_setProcMode;
7543
7544 static char *kwlist[] = {"freq", "harms", "mul", "add", NULL};
7545
7546 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &freqtmp, &harmstmp, &multmp, &addtmp))
7547 Py_RETURN_NONE;
7548
7549 if (freqtmp)
7550 {
7551 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
7552 }
7553
7554 if (harmstmp)
7555 {
7556 PyObject_CallMethod((PyObject *)self, "setHarms", "O", harmstmp);
7557 }
7558
7559 if (multmp)
7560 {
7561 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
7562 }
7563
7564 if (addtmp)
7565 {
7566 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
7567 }
7568
7569 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
7570
7571 (*self->mode_func_ptr)(self);
7572
7573 return (PyObject *)self;
7574 }
7575
7576 static PyObject * Blit_getServer(Blit* self) { GET_SERVER };
7577 static PyObject * Blit_getStream(Blit* self) { GET_STREAM };
7578 static PyObject * Blit_setMul(Blit *self, PyObject *arg) { SET_MUL };
7579 static PyObject * Blit_setAdd(Blit *self, PyObject *arg) { SET_ADD };
7580 static PyObject * Blit_setSub(Blit *self, PyObject *arg) { SET_SUB };
7581 static PyObject * Blit_setDiv(Blit *self, PyObject *arg) { SET_DIV };
7582
7583 static PyObject * Blit_play(Blit *self, PyObject *args, PyObject *kwds) { PLAY };
7584 static PyObject * Blit_out(Blit *self, PyObject *args, PyObject *kwds) { OUT };
7585 static PyObject * Blit_stop(Blit *self, PyObject *args, PyObject *kwds) { STOP };
7586
7587 static PyObject * Blit_multiply(Blit *self, PyObject *arg) { MULTIPLY };
7588 static PyObject * Blit_inplace_multiply(Blit *self, PyObject *arg) { INPLACE_MULTIPLY };
7589 static PyObject * Blit_add(Blit *self, PyObject *arg) { ADD };
7590 static PyObject * Blit_inplace_add(Blit *self, PyObject *arg) { INPLACE_ADD };
7591 static PyObject * Blit_sub(Blit *self, PyObject *arg) { SUB };
7592 static PyObject * Blit_inplace_sub(Blit *self, PyObject *arg) { INPLACE_SUB };
7593 static PyObject * Blit_div(Blit *self, PyObject *arg) { DIV };
7594 static PyObject * Blit_inplace_div(Blit *self, PyObject *arg) { INPLACE_DIV };
7595
7596 static PyObject * Blit_setFreq(Blit *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
7597 static PyObject * Blit_setHarms(Blit *self, PyObject *arg) { SET_PARAM(self->harms, self->harms_stream, 3); }
7598
7599 static PyMemberDef Blit_members[] =
7600 {
7601 {"server", T_OBJECT_EX, offsetof(Blit, server), 0, "Pyo server."},
7602 {"stream", T_OBJECT_EX, offsetof(Blit, stream), 0, "Stream object."},
7603 {"freq", T_OBJECT_EX, offsetof(Blit, freq), 0, "Frequency in cycle per second."},
7604 {"harms", T_OBJECT_EX, offsetof(Blit, harms), 0, "Number of harmonics."},
7605 {"mul", T_OBJECT_EX, offsetof(Blit, mul), 0, "Mul factor."},
7606 {"add", T_OBJECT_EX, offsetof(Blit, add), 0, "Add factor."},
7607 {NULL} /* Sentinel */
7608 };
7609
7610 static PyMethodDef Blit_methods[] =
7611 {
7612 {"getServer", (PyCFunction)Blit_getServer, METH_NOARGS, "Returns server object."},
7613 {"_getStream", (PyCFunction)Blit_getStream, METH_NOARGS, "Returns stream object."},
7614 {"play", (PyCFunction)Blit_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundfreqd."},
7615 {"out", (PyCFunction)Blit_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundfreqd channel speficied by argument."},
7616 {"stop", (PyCFunction)Blit_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
7617 {"setFreq", (PyCFunction)Blit_setFreq, METH_O, "Sets frequency in cycle per second."},
7618 {"setHarms", (PyCFunction)Blit_setHarms, METH_O, "Sets the number of harmonics."},
7619 {"setMul", (PyCFunction)Blit_setMul, METH_O, "Sets Blit mul factor."},
7620 {"setAdd", (PyCFunction)Blit_setAdd, METH_O, "Sets Blit add factor."},
7621 {"setSub", (PyCFunction)Blit_setSub, METH_O, "Sets inverse add factor."},
7622 {"setDiv", (PyCFunction)Blit_setDiv, METH_O, "Sets inverse mul factor."},
7623 {NULL} /* Sentinel */
7624 };
7625
7626 static PyNumberMethods Blit_as_number =
7627 {
7628 (binaryfunc)Blit_add, /*nb_add*/
7629 (binaryfunc)Blit_sub, /*nb_subtract*/
7630 (binaryfunc)Blit_multiply, /*nb_multiply*/
7631 0, /*nb_remainder*/
7632 0, /*nb_divmod*/
7633 0, /*nb_power*/
7634 0, /*nb_neg*/
7635 0, /*nb_pos*/
7636 0, /*(unaryfunc)array_abs*/
7637 0, /*nb_nonzero*/
7638 0, /*nb_invert*/
7639 0, /*nb_lshift*/
7640 0, /*nb_rshift*/
7641 0, /*nb_and*/
7642 0, /*nb_xor*/
7643 0, /*nb_or*/
7644 0, /*nb_int*/
7645 0, /*nb_long*/
7646 0, /*nb_float*/
7647 (binaryfunc)Blit_inplace_add, /*inplace_add*/
7648 (binaryfunc)Blit_inplace_sub, /*inplace_subtract*/
7649 (binaryfunc)Blit_inplace_multiply, /*inplace_multiply*/
7650 0, /*inplace_remainder*/
7651 0, /*inplace_power*/
7652 0, /*inplace_lshift*/
7653 0, /*inplace_rshift*/
7654 0, /*inplace_and*/
7655 0, /*inplace_xor*/
7656 0, /*inplace_or*/
7657 0, /*nb_floor_divide*/
7658 (binaryfunc)Blit_div, /*nb_true_divide*/
7659 0, /*nb_inplace_floor_divide*/
7660 (binaryfunc)Blit_inplace_div, /*nb_inplace_true_divide*/
7661 0, /* nb_cutoff */
7662 };
7663
7664 PyTypeObject BlitType =
7665 {
7666 PyVarObject_HEAD_INIT(NULL, 0)
7667 "_pyo.Blit_base", /*tp_name*/
7668 sizeof(Blit), /*tp_basicsize*/
7669 0, /*tp_itemsize*/
7670 (destructor)Blit_dealloc, /*tp_dealloc*/
7671 0, /*tp_print*/
7672 0, /*tp_getattr*/
7673 0, /*tp_setattr*/
7674 0, /*tp_as_async (tp_compare in Python 2)*/
7675 0, /*tp_repr*/
7676 &Blit_as_number, /*tp_as_number*/
7677 0, /*tp_as_sequence*/
7678 0, /*tp_as_mapping*/
7679 0, /*tp_hash */
7680 0, /*tp_call*/
7681 0, /*tp_str*/
7682 0, /*tp_getattro*/
7683 0, /*tp_setattro*/
7684 0, /*tp_as_buffer*/
7685 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
7686 "Blit objects. Generates a band limited impulse train.", /* tp_doc */
7687 (traverseproc)Blit_traverse, /* tp_traverse */
7688 (inquiry)Blit_clear, /* tp_clear */
7689 0, /* tp_richcompare */
7690 0, /* tp_weaklistoffset */
7691 0, /* tp_iter */
7692 0, /* tp_iternext */
7693 Blit_methods, /* tp_methods */
7694 Blit_members, /* tp_members */
7695 0, /* tp_getset */
7696 0, /* tp_base */
7697 0, /* tp_dict */
7698 0, /* tp_descr_get */
7699 0, /* tp_descr_set */
7700 0, /* tp_dictoffset */
7701 0, /* tp_init */
7702 0, /* tp_alloc */
7703 Blit_new, /* tp_new */
7704 };
7705
7706 /* Rossler object */
7707 typedef struct
7708 {
7709 pyo_audio_HEAD
7710 PyObject *pitch;
7711 Stream *pitch_stream;
7712 PyObject *chaos;
7713 Stream *chaos_stream;
7714 MYFLT *altBuffer;
7715 MYFLT vDX;
7716 MYFLT vDY;
7717 MYFLT vDZ;
7718 MYFLT vX;
7719 MYFLT vY;
7720 MYFLT vZ;
7721 MYFLT pA;
7722 MYFLT pB;
7723 MYFLT scalePitch;
7724 int modebuffer[4];
7725 } Rossler;
7726
7727 static void
7728 Rossler_readframes_ii(Rossler *self)
7729 {
7730 MYFLT delta, pit, chao;
7731 int i;
7732
7733 pit = PyFloat_AS_DOUBLE(self->pitch);
7734 chao = PyFloat_AS_DOUBLE(self->chaos);
7735
7736 if (pit < 0.0)
7737 pit = 1.0;
7738 else if (pit > 1.0)
7739 pit = 1000.0;
7740 else
7741 pit = pit * 999.0 + 1.0;
7742
7743 delta = self->scalePitch * pit;
7744
7745 if (chao < 0.0)
7746 chao = 3.0;
7747 else if (chao > 1.0)
7748 chao = 10.0;
7749 else
7750 chao = chao * 7.0 + 3.0;
7751
7752 for (i = 0; i < self->bufsize; i++)
7753 {
7754 self->vDX = -self->vY - self->vZ;
7755 self->vDY = self->vX + self->pA * self->vY;
7756 self->vDZ = self->pB + self->vZ * (self->vX - chao);
7757
7758 self->vX += self->vDX * delta;
7759 self->vY += self->vDY * delta;
7760 self->vZ += self->vDZ * delta;
7761
7762 self->data[i] = self->vX * ROSSLER_SCALE;
7763 self->altBuffer[i] = self->vY * ROSSLER_ALT_SCALE;
7764 }
7765 }
7766
7767 static void
7768 Rossler_readframes_ai(Rossler *self)
7769 {
7770 MYFLT delta, pit, chao;
7771 int i;
7772
7773 MYFLT *fr = Stream_getData((Stream *)self->pitch_stream);
7774 chao = PyFloat_AS_DOUBLE(self->chaos);
7775
7776 if (chao < 0.0)
7777 chao = 3.0;
7778 else if (chao > 1.0)
7779 chao = 10.0;
7780 else
7781 chao = chao * 7.0 + 3.0;
7782
7783 for (i = 0; i < self->bufsize; i++)
7784 {
7785 pit = fr[i];
7786
7787 if (pit < 0.0)
7788 pit = 1.0;
7789 else if (pit > 1.0)
7790 pit = 1000.0;
7791 else
7792 pit = pit * 999.0 + 1.0;
7793
7794 delta = self->scalePitch * pit;
7795 self->vDX = -self->vY - self->vZ;
7796 self->vDY = self->vX + self->pA * self->vY;
7797 self->vDZ = self->pB + self->vZ * (self->vX - chao);
7798
7799 self->vX += self->vDX * delta;
7800 self->vY += self->vDY * delta;
7801 self->vZ += self->vDZ * delta;
7802
7803 self->data[i] = self->vX * ROSSLER_SCALE;
7804 self->altBuffer[i] = self->vY * ROSSLER_ALT_SCALE;
7805 }
7806 }
7807
7808 static void
7809 Rossler_readframes_ia(Rossler *self)
7810 {
7811 MYFLT delta, pit, chao;
7812 int i;
7813
7814 pit = PyFloat_AS_DOUBLE(self->pitch);
7815 MYFLT *ch = Stream_getData((Stream *)self->chaos_stream);
7816
7817 if (pit < 0.0)
7818 pit = 1.0;
7819 else if (pit > 1.0)
7820 pit = 1000.0;
7821 else
7822 pit = pit * 999.0 + 1.0;
7823
7824 delta = self->scalePitch * pit;
7825
7826 for (i = 0; i < self->bufsize; i++)
7827 {
7828 chao = ch[i];
7829
7830 if (chao < 0.0)
7831 chao = 3.0;
7832 else if (chao > 1.0)
7833 chao = 10.0;
7834 else
7835 chao = chao * 7.0 + 3.0;
7836
7837 self->vDX = -self->vY - self->vZ;
7838 self->vDY = self->vX + self->pA * self->vY;
7839 self->vDZ = self->pB + self->vZ * (self->vX - chao);
7840
7841 self->vX += self->vDX * delta;
7842 self->vY += self->vDY * delta;
7843 self->vZ += self->vDZ * delta;
7844
7845 self->data[i] = self->vX * ROSSLER_SCALE;
7846 self->altBuffer[i] = self->vY * ROSSLER_ALT_SCALE;
7847 }
7848 }
7849
7850 static void
7851 Rossler_readframes_aa(Rossler *self)
7852 {
7853 MYFLT delta, pit, chao;
7854 int i;
7855
7856 MYFLT *fr = Stream_getData((Stream *)self->pitch_stream);
7857 MYFLT *ch = Stream_getData((Stream *)self->chaos_stream);
7858
7859 for (i = 0; i < self->bufsize; i++)
7860 {
7861 pit = fr[i];
7862
7863 if (pit < 0.0)
7864 pit = 1.0;
7865 else if (pit > 1.0)
7866 pit = 1000.0;
7867 else
7868 pit = pit * 999.0 + 1.0;
7869
7870 delta = self->scalePitch * pit;
7871
7872 chao = ch[i];
7873
7874 if (chao < 0.0)
7875 chao = 3.0;
7876 else if (chao > 1.0)
7877 chao = 10.0;
7878 else
7879 chao = chao * 7.0 + 3.0;
7880
7881 self->vDX = -self->vY - self->vZ;
7882 self->vDY = self->vX + self->pA * self->vY;
7883 self->vDZ = self->pB + self->vZ * (self->vX - chao);
7884
7885 self->vX += self->vDX * delta;
7886 self->vY += self->vDY * delta;
7887 self->vZ += self->vDZ * delta;
7888
7889 self->data[i] = self->vX * ROSSLER_SCALE;
7890 self->altBuffer[i] = self->vY * ROSSLER_ALT_SCALE;
7891 }
7892 }
7893
7894 static void Rossler_postprocessing_ii(Rossler *self) { POST_PROCESSING_II };
7895 static void Rossler_postprocessing_ai(Rossler *self) { POST_PROCESSING_AI };
7896 static void Rossler_postprocessing_ia(Rossler *self) { POST_PROCESSING_IA };
7897 static void Rossler_postprocessing_aa(Rossler *self) { POST_PROCESSING_AA };
7898 static void Rossler_postprocessing_ireva(Rossler *self) { POST_PROCESSING_IREVA };
7899 static void Rossler_postprocessing_areva(Rossler *self) { POST_PROCESSING_AREVA };
7900 static void Rossler_postprocessing_revai(Rossler *self) { POST_PROCESSING_REVAI };
7901 static void Rossler_postprocessing_revaa(Rossler *self) { POST_PROCESSING_REVAA };
7902 static void Rossler_postprocessing_revareva(Rossler *self) { POST_PROCESSING_REVAREVA };
7903
7904 static void
7905 Rossler_setProcMode(Rossler *self)
7906 {
7907 int procmode, muladdmode;
7908 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
7909 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
7910
7911 switch (procmode)
7912 {
7913 case 0:
7914 self->proc_func_ptr = Rossler_readframes_ii;
7915 break;
7916
7917 case 1:
7918 self->proc_func_ptr = Rossler_readframes_ai;
7919 break;
7920
7921 case 10:
7922 self->proc_func_ptr = Rossler_readframes_ia;
7923 break;
7924
7925 case 11:
7926 self->proc_func_ptr = Rossler_readframes_aa;
7927 break;
7928 }
7929
7930 switch (muladdmode)
7931 {
7932 case 0:
7933 self->muladd_func_ptr = Rossler_postprocessing_ii;
7934 break;
7935
7936 case 1:
7937 self->muladd_func_ptr = Rossler_postprocessing_ai;
7938 break;
7939
7940 case 2:
7941 self->muladd_func_ptr = Rossler_postprocessing_revai;
7942 break;
7943
7944 case 10:
7945 self->muladd_func_ptr = Rossler_postprocessing_ia;
7946 break;
7947
7948 case 11:
7949 self->muladd_func_ptr = Rossler_postprocessing_aa;
7950 break;
7951
7952 case 12:
7953 self->muladd_func_ptr = Rossler_postprocessing_revaa;
7954 break;
7955
7956 case 20:
7957 self->muladd_func_ptr = Rossler_postprocessing_ireva;
7958 break;
7959
7960 case 21:
7961 self->muladd_func_ptr = Rossler_postprocessing_areva;
7962 break;
7963
7964 case 22:
7965 self->muladd_func_ptr = Rossler_postprocessing_revareva;
7966 break;
7967 }
7968 }
7969
7970 static void
7971 Rossler_compute_next_data_frame(Rossler *self)
7972 {
7973 (*self->proc_func_ptr)(self);
7974 (*self->muladd_func_ptr)(self);
7975 }
7976
7977 static int
7978 Rossler_traverse(Rossler *self, visitproc visit, void *arg)
7979 {
7980 pyo_VISIT
7981 Py_VISIT(self->pitch);
7982 Py_VISIT(self->chaos);
7983 return 0;
7984 }
7985
7986 static int
7987 Rossler_clear(Rossler *self)
7988 {
7989 pyo_CLEAR
7990 Py_CLEAR(self->pitch);
7991 Py_CLEAR(self->chaos);
7992 return 0;
7993 }
7994
7995 static void
7996 Rossler_dealloc(Rossler* self)
7997 {
7998 pyo_DEALLOC
7999 PyMem_RawFree(self->altBuffer);
8000 Rossler_clear(self);
8001 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
8002 Py_TYPE(self)->tp_free((PyObject*)self);
8003 }
8004
8005 static PyObject *
8006 Rossler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
8007 {
8008 int i;
8009 PyObject *pitchtmp = NULL, *chaostmp = NULL, *multmp = NULL, *addtmp = NULL;
8010 Rossler *self;
8011 self = (Rossler *)type->tp_alloc(type, 0);
8012
8013 self->pitch = PyFloat_FromDouble(0.25);
8014 self->chaos = PyFloat_FromDouble(0.5);
8015 self->pA = 0.15;
8016 self->pB = 0.20;
8017 self->vDX = self->vDY = self->vDZ = 0.0;
8018 self->vX = self->vY = self->vZ = 1.0;
8019 self->modebuffer[0] = 0;
8020 self->modebuffer[1] = 0;
8021 self->modebuffer[2] = 0;
8022 self->modebuffer[3] = 0;
8023
8024 INIT_OBJECT_COMMON
8025 Stream_setFunctionPtr(self->stream, Rossler_compute_next_data_frame);
8026 self->mode_func_ptr = Rossler_setProcMode;
8027
8028 self->scalePitch = 2.91 / self->sr;
8029
8030 static char *kwlist[] = {"pitch", "chaos", "mul", "add", NULL};
8031
8032 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &pitchtmp, &chaostmp, &multmp, &addtmp))
8033 Py_RETURN_NONE;
8034
8035 if (pitchtmp)
8036 {
8037 PyObject_CallMethod((PyObject *)self, "setPitch", "O", pitchtmp);
8038 }
8039
8040 if (chaostmp)
8041 {
8042 PyObject_CallMethod((PyObject *)self, "setChaos", "O", chaostmp);
8043 }
8044
8045 if (multmp)
8046 {
8047 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
8048 }
8049
8050 if (addtmp)
8051 {
8052 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
8053 }
8054
8055 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
8056
8057 self->altBuffer = (MYFLT *)PyMem_RawRealloc(self->altBuffer, self->bufsize * sizeof(MYFLT));
8058
8059 for (i = 0; i < self->bufsize; i++)
8060 {
8061 self->altBuffer[i] = 0.0;
8062 }
8063
8064 (*self->mode_func_ptr)(self);
8065
8066 return (PyObject *)self;
8067 }
8068
8069 static PyObject * Rossler_getServer(Rossler* self) { GET_SERVER };
8070 static PyObject * Rossler_getStream(Rossler* self) { GET_STREAM };
8071 static PyObject * Rossler_setMul(Rossler *self, PyObject *arg) { SET_MUL };
8072 static PyObject * Rossler_setAdd(Rossler *self, PyObject *arg) { SET_ADD };
8073 static PyObject * Rossler_setSub(Rossler *self, PyObject *arg) { SET_SUB };
8074 static PyObject * Rossler_setDiv(Rossler *self, PyObject *arg) { SET_DIV };
8075
8076 static PyObject * Rossler_play(Rossler *self, PyObject *args, PyObject *kwds) { PLAY };
8077 static PyObject * Rossler_out(Rossler *self, PyObject *args, PyObject *kwds) { OUT };
8078 static PyObject * Rossler_stop(Rossler *self, PyObject *args, PyObject *kwds) { STOP };
8079
8080 static PyObject * Rossler_multiply(Rossler *self, PyObject *arg) { MULTIPLY };
8081 static PyObject * Rossler_inplace_multiply(Rossler *self, PyObject *arg) { INPLACE_MULTIPLY };
8082 static PyObject * Rossler_add(Rossler *self, PyObject *arg) { ADD };
8083 static PyObject * Rossler_inplace_add(Rossler *self, PyObject *arg) { INPLACE_ADD };
8084 static PyObject * Rossler_sub(Rossler *self, PyObject *arg) { SUB };
8085 static PyObject * Rossler_inplace_sub(Rossler *self, PyObject *arg) { INPLACE_SUB };
8086 static PyObject * Rossler_div(Rossler *self, PyObject *arg) { DIV };
8087 static PyObject * Rossler_inplace_div(Rossler *self, PyObject *arg) { INPLACE_DIV };
8088
8089 static PyObject * Rossler_setPitch(Rossler *self, PyObject *arg) { SET_PARAM(self->pitch, self->pitch_stream, 2); }
8090 static PyObject * Rossler_setChaos(Rossler *self, PyObject *arg) { SET_PARAM(self->chaos, self->chaos_stream, 3); }
8091
8092 MYFLT *
8093 Rossler_getAltBuffer(Rossler *self)
8094 {
8095 return (MYFLT *)self->altBuffer;
8096 }
8097
8098 static PyMemberDef Rossler_members[] =
8099 {
8100 {"server", T_OBJECT_EX, offsetof(Rossler, server), 0, "Pyo server."},
8101 {"stream", T_OBJECT_EX, offsetof(Rossler, stream), 0, "Stream object."},
8102 {"pitch", T_OBJECT_EX, offsetof(Rossler, pitch), 0, "Pitch."},
8103 {"chaos", T_OBJECT_EX, offsetof(Rossler, chaos), 0, "Chaotic behavior."},
8104 {"mul", T_OBJECT_EX, offsetof(Rossler, mul), 0, "Mul factor."},
8105 {"add", T_OBJECT_EX, offsetof(Rossler, add), 0, "Add factor."},
8106 {NULL} /* Sentinel */
8107 };
8108
8109 static PyMethodDef Rossler_methods[] =
8110 {
8111 {"getServer", (PyCFunction)Rossler_getServer, METH_NOARGS, "Returns server object."},
8112 {"_getStream", (PyCFunction)Rossler_getStream, METH_NOARGS, "Returns stream object."},
8113 {"play", (PyCFunction)Rossler_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
8114 {"out", (PyCFunction)Rossler_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
8115 {"stop", (PyCFunction)Rossler_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
8116 {"setPitch", (PyCFunction)Rossler_setPitch, METH_O, "Sets oscillator pitch."},
8117 {"setChaos", (PyCFunction)Rossler_setChaos, METH_O, "Sets oscillator chaotic behavior."},
8118 {"setMul", (PyCFunction)Rossler_setMul, METH_O, "Sets Rossler mul factor."},
8119 {"setAdd", (PyCFunction)Rossler_setAdd, METH_O, "Sets Rossler add factor."},
8120 {"setSub", (PyCFunction)Rossler_setSub, METH_O, "Sets inverse add factor."},
8121 {"setDiv", (PyCFunction)Rossler_setDiv, METH_O, "Sets inverse mul factor."},
8122 {NULL} /* Sentinel */
8123 };
8124
8125 static PyNumberMethods Rossler_as_number =
8126 {
8127 (binaryfunc)Rossler_add, /*nb_add*/
8128 (binaryfunc)Rossler_sub, /*nb_subtract*/
8129 (binaryfunc)Rossler_multiply, /*nb_multiply*/
8130 0, /*nb_remainder*/
8131 0, /*nb_divmod*/
8132 0, /*nb_power*/
8133 0, /*nb_neg*/
8134 0, /*nb_pos*/
8135 0, /*(unaryfunc)array_abs*/
8136 0, /*nb_nonzero*/
8137 0, /*nb_invert*/
8138 0, /*nb_lshift*/
8139 0, /*nb_rshift*/
8140 0, /*nb_and*/
8141 0, /*nb_xor*/
8142 0, /*nb_or*/
8143 0, /*nb_int*/
8144 0, /*nb_long*/
8145 0, /*nb_float*/
8146 (binaryfunc)Rossler_inplace_add, /*inplace_add*/
8147 (binaryfunc)Rossler_inplace_sub, /*inplace_subtract*/
8148 (binaryfunc)Rossler_inplace_multiply, /*inplace_multiply*/
8149 0, /*inplace_remainder*/
8150 0, /*inplace_power*/
8151 0, /*inplace_lshift*/
8152 0, /*inplace_rshift*/
8153 0, /*inplace_and*/
8154 0, /*inplace_xor*/
8155 0, /*inplace_or*/
8156 0, /*nb_floor_divide*/
8157 (binaryfunc)Rossler_div, /*nb_true_divide*/
8158 0, /*nb_inplace_floor_divide*/
8159 (binaryfunc)Rossler_inplace_div, /*nb_inplace_true_divide*/
8160 0, /* nb_index */
8161 };
8162
8163 PyTypeObject RosslerType =
8164 {
8165 PyVarObject_HEAD_INIT(NULL, 0)
8166 "_pyo.Rossler_base", /*tp_name*/
8167 sizeof(Rossler), /*tp_basicsize*/
8168 0, /*tp_itemsize*/
8169 (destructor)Rossler_dealloc, /*tp_dealloc*/
8170 0, /*tp_print*/
8171 0, /*tp_getattr*/
8172 0, /*tp_setattr*/
8173 0, /*tp_as_async (tp_compare in Python 2)*/
8174 0, /*tp_repr*/
8175 &Rossler_as_number, /*tp_as_number*/
8176 0, /*tp_as_sequence*/
8177 0, /*tp_as_mapping*/
8178 0, /*tp_hash */
8179 0, /*tp_call*/
8180 0, /*tp_str*/
8181 0, /*tp_getattro*/
8182 0, /*tp_setattro*/
8183 0, /*tp_as_buffer*/
8184 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
8185 "Rossler objects. Rossler attractor.", /* tp_doc */
8186 (traverseproc)Rossler_traverse, /* tp_traverse */
8187 (inquiry)Rossler_clear, /* tp_clear */
8188 0, /* tp_richcompare */
8189 0, /* tp_weaklistoffset */
8190 0, /* tp_iter */
8191 0, /* tp_iternext */
8192 Rossler_methods, /* tp_methods */
8193 Rossler_members, /* tp_members */
8194 0, /* tp_getset */
8195 0, /* tp_base */
8196 0, /* tp_dict */
8197 0, /* tp_descr_get */
8198 0, /* tp_descr_set */
8199 0, /* tp_dictoffset */
8200 0, /* tp_init */
8201 0, /* tp_alloc */
8202 Rossler_new, /* tp_new */
8203 };
8204
8205 typedef struct
8206 {
8207 pyo_audio_HEAD
8208 Rossler *mainRossler;
8209 int modebuffer[2];
8210 } RosslerAlt;
8211
8212 static void RosslerAlt_postprocessing_ii(RosslerAlt *self) { POST_PROCESSING_II };
8213 static void RosslerAlt_postprocessing_ai(RosslerAlt *self) { POST_PROCESSING_AI };
8214 static void RosslerAlt_postprocessing_ia(RosslerAlt *self) { POST_PROCESSING_IA };
8215 static void RosslerAlt_postprocessing_aa(RosslerAlt *self) { POST_PROCESSING_AA };
8216 static void RosslerAlt_postprocessing_ireva(RosslerAlt *self) { POST_PROCESSING_IREVA };
8217 static void RosslerAlt_postprocessing_areva(RosslerAlt *self) { POST_PROCESSING_AREVA };
8218 static void RosslerAlt_postprocessing_revai(RosslerAlt *self) { POST_PROCESSING_REVAI };
8219 static void RosslerAlt_postprocessing_revaa(RosslerAlt *self) { POST_PROCESSING_REVAA };
8220 static void RosslerAlt_postprocessing_revareva(RosslerAlt *self) { POST_PROCESSING_REVAREVA };
8221
8222 static void
8223 RosslerAlt_setProcMode(RosslerAlt *self)
8224 {
8225 int muladdmode;
8226 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
8227
8228 switch (muladdmode)
8229 {
8230 case 0:
8231 self->muladd_func_ptr = RosslerAlt_postprocessing_ii;
8232 break;
8233
8234 case 1:
8235 self->muladd_func_ptr = RosslerAlt_postprocessing_ai;
8236 break;
8237
8238 case 2:
8239 self->muladd_func_ptr = RosslerAlt_postprocessing_revai;
8240 break;
8241
8242 case 10:
8243 self->muladd_func_ptr = RosslerAlt_postprocessing_ia;
8244 break;
8245
8246 case 11:
8247 self->muladd_func_ptr = RosslerAlt_postprocessing_aa;
8248 break;
8249
8250 case 12:
8251 self->muladd_func_ptr = RosslerAlt_postprocessing_revaa;
8252 break;
8253
8254 case 20:
8255 self->muladd_func_ptr = RosslerAlt_postprocessing_ireva;
8256 break;
8257
8258 case 21:
8259 self->muladd_func_ptr = RosslerAlt_postprocessing_areva;
8260 break;
8261
8262 case 22:
8263 self->muladd_func_ptr = RosslerAlt_postprocessing_revareva;
8264 break;
8265 }
8266 }
8267
8268 static void
8269 RosslerAlt_compute_next_data_frame(RosslerAlt *self)
8270 {
8271 int i;
8272 MYFLT *tmp;
8273 tmp = Rossler_getAltBuffer((Rossler *)self->mainRossler);
8274
8275 for (i = 0; i < self->bufsize; i++)
8276 {
8277 self->data[i] = tmp[i];
8278 }
8279
8280 (*self->muladd_func_ptr)(self);
8281 }
8282
8283 static int
8284 RosslerAlt_traverse(RosslerAlt *self, visitproc visit, void *arg)
8285 {
8286 pyo_VISIT
8287 Py_VISIT(self->mainRossler);
8288 return 0;
8289 }
8290
8291 static int
8292 RosslerAlt_clear(RosslerAlt *self)
8293 {
8294 pyo_CLEAR
8295 Py_CLEAR(self->mainRossler);
8296 return 0;
8297 }
8298
8299 static void
8300 RosslerAlt_dealloc(RosslerAlt* self)
8301 {
8302 pyo_DEALLOC
8303 RosslerAlt_clear(self);
8304 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
8305 Py_TYPE(self)->tp_free((PyObject*)self);
8306 }
8307
8308 static PyObject *
8309 RosslerAlt_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
8310 {
8311 int i;
8312 PyObject *maintmp = NULL, *multmp = NULL, *addtmp = NULL;
8313 RosslerAlt *self;
8314 self = (RosslerAlt *)type->tp_alloc(type, 0);
8315
8316 self->modebuffer[0] = 0;
8317 self->modebuffer[1] = 0;
8318
8319 INIT_OBJECT_COMMON
8320 Stream_setFunctionPtr(self->stream, RosslerAlt_compute_next_data_frame);
8321 self->mode_func_ptr = RosslerAlt_setProcMode;
8322
8323 static char *kwlist[] = {"mainRossler", "mul", "alt", NULL};
8324
8325 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &maintmp, &multmp, &addtmp))
8326 Py_RETURN_NONE;
8327
8328 self->mainRossler = (Rossler *)maintmp;
8329 Py_INCREF(self->mainRossler);
8330
8331 if (multmp)
8332 {
8333 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
8334 }
8335
8336 if (addtmp)
8337 {
8338 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
8339 }
8340
8341 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
8342
8343 (*self->mode_func_ptr)(self);
8344
8345 return (PyObject *)self;
8346 }
8347
8348 static PyObject * RosslerAlt_getServer(RosslerAlt* self) { GET_SERVER };
8349 static PyObject * RosslerAlt_getStream(RosslerAlt* self) { GET_STREAM };
8350 static PyObject * RosslerAlt_setMul(RosslerAlt *self, PyObject *arg) { SET_MUL };
8351 static PyObject * RosslerAlt_setAdd(RosslerAlt *self, PyObject *arg) { SET_ADD };
8352 static PyObject * RosslerAlt_setSub(RosslerAlt *self, PyObject *arg) { SET_SUB };
8353 static PyObject * RosslerAlt_setDiv(RosslerAlt *self, PyObject *arg) { SET_DIV };
8354
8355 static PyObject * RosslerAlt_play(RosslerAlt *self, PyObject *args, PyObject *kwds) { PLAY };
8356 static PyObject * RosslerAlt_out(RosslerAlt *self, PyObject *args, PyObject *kwds) { OUT };
8357 static PyObject * RosslerAlt_stop(RosslerAlt *self, PyObject *args, PyObject *kwds) { STOP };
8358
8359 static PyObject * RosslerAlt_multiply(RosslerAlt *self, PyObject *arg) { MULTIPLY };
8360 static PyObject * RosslerAlt_inplace_multiply(RosslerAlt *self, PyObject *arg) { INPLACE_MULTIPLY };
8361 static PyObject * RosslerAlt_add(RosslerAlt *self, PyObject *arg) { ADD };
8362 static PyObject * RosslerAlt_inplace_add(RosslerAlt *self, PyObject *arg) { INPLACE_ADD };
8363 static PyObject * RosslerAlt_sub(RosslerAlt *self, PyObject *arg) { SUB };
8364 static PyObject * RosslerAlt_inplace_sub(RosslerAlt *self, PyObject *arg) { INPLACE_SUB };
8365 static PyObject * RosslerAlt_div(RosslerAlt *self, PyObject *arg) { DIV };
8366 static PyObject * RosslerAlt_inplace_div(RosslerAlt *self, PyObject *arg) { INPLACE_DIV };
8367
8368 static PyMemberDef RosslerAlt_members[] =
8369 {
8370 {"server", T_OBJECT_EX, offsetof(RosslerAlt, server), 0, "Pyo server."},
8371 {"stream", T_OBJECT_EX, offsetof(RosslerAlt, stream), 0, "Stream object."},
8372 {"mul", T_OBJECT_EX, offsetof(RosslerAlt, mul), 0, "Mul factor."},
8373 {"add", T_OBJECT_EX, offsetof(RosslerAlt, add), 0, "Add factor."},
8374 {NULL} /* Sentinel */
8375 };
8376
8377 static PyMethodDef RosslerAlt_methods[] =
8378 {
8379 {"getServer", (PyCFunction)RosslerAlt_getServer, METH_NOARGS, "Returns server object."},
8380 {"_getStream", (PyCFunction)RosslerAlt_getStream, METH_NOARGS, "Returns stream object."},
8381 {"play", (PyCFunction)RosslerAlt_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
8382 {"out", (PyCFunction)RosslerAlt_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
8383 {"stop", (PyCFunction)RosslerAlt_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
8384 {"setMul", (PyCFunction)RosslerAlt_setMul, METH_O, "Sets oscillator mul factor."},
8385 {"setAdd", (PyCFunction)RosslerAlt_setAdd, METH_O, "Sets oscillator add factor."},
8386 {"setSub", (PyCFunction)RosslerAlt_setSub, METH_O, "Sets inverse add factor."},
8387 {"setDiv", (PyCFunction)RosslerAlt_setDiv, METH_O, "Sets inverse mul factor."},
8388 {NULL} /* Sentinel */
8389 };
8390 static PyNumberMethods RosslerAlt_as_number =
8391 {
8392 (binaryfunc)RosslerAlt_add, /*nb_add*/
8393 (binaryfunc)RosslerAlt_sub, /*nb_subtract*/
8394 (binaryfunc)RosslerAlt_multiply, /*nb_multiply*/
8395 0, /*nb_remainder*/
8396 0, /*nb_divmod*/
8397 0, /*nb_power*/
8398 0, /*nb_neg*/
8399 0, /*nb_pos*/
8400 0, /*(unaryfunc)array_abs,*/
8401 0, /*nb_nonzero*/
8402 0, /*nb_invert*/
8403 0, /*nb_lshift*/
8404 0, /*nb_rshift*/
8405 0, /*nb_and*/
8406 0, /*nb_xor*/
8407 0, /*nb_or*/
8408 0, /*nb_int*/
8409 0, /*nb_long*/
8410 0, /*nb_float*/
8411 (binaryfunc)RosslerAlt_inplace_add, /*inplace_add*/
8412 (binaryfunc)RosslerAlt_inplace_sub, /*inplace_subtract*/
8413 (binaryfunc)RosslerAlt_inplace_multiply, /*inplace_multiply*/
8414 0, /*inplace_remainder*/
8415 0, /*inplace_power*/
8416 0, /*inplace_lshift*/
8417 0, /*inplace_rshift*/
8418 0, /*inplace_and*/
8419 0, /*inplace_xor*/
8420 0, /*inplace_or*/
8421 0, /*nb_floor_divide*/
8422 (binaryfunc)RosslerAlt_div, /*nb_true_divide*/
8423 0, /*nb_inplace_floor_divide*/
8424 (binaryfunc)RosslerAlt_inplace_div, /*nb_inplace_true_divide*/
8425 0, /* nb_index */
8426 };
8427
8428 PyTypeObject RosslerAltType =
8429 {
8430 PyVarObject_HEAD_INIT(NULL, 0)
8431 "_pyo.RosslerAlt_base", /*tp_name*/
8432 sizeof(RosslerAlt), /*tp_basicsize*/
8433 0, /*tp_itemsize*/
8434 (destructor)RosslerAlt_dealloc, /*tp_dealloc*/
8435 0, /*tp_print*/
8436 0, /*tp_getattr*/
8437 0, /*tp_setattr*/
8438 0, /*tp_as_async (tp_compare in Python 2)*/
8439 0, /*tp_repr*/
8440 &RosslerAlt_as_number, /*tp_as_number*/
8441 0, /*tp_as_sequence*/
8442 0, /*tp_as_mapping*/
8443 0, /*tp_hash */
8444 0, /*tp_call*/
8445 0, /*tp_str*/
8446 0, /*tp_getattro*/
8447 0, /*tp_setattro*/
8448 0, /*tp_as_buffer*/
8449 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
8450 "RosslerAlt objects. Sends the alternate signal of a Rossler attractor.", /* tp_doc */
8451 (traverseproc)RosslerAlt_traverse, /* tp_traverse */
8452 (inquiry)RosslerAlt_clear, /* tp_clear */
8453 0, /* tp_richcompare */
8454 0, /* tp_weaklistoffset */
8455 0, /* tp_iter */
8456 0, /* tp_iternext */
8457 RosslerAlt_methods, /* tp_methods */
8458 RosslerAlt_members, /* tp_members */
8459 0, /* tp_getset */
8460 0, /* tp_base */
8461 0, /* tp_dict */
8462 0, /* tp_descr_get */
8463 0, /* tp_descr_set */
8464 0, /* tp_dictoffset */
8465 0, /* tp_init */
8466 0, /* tp_alloc */
8467 RosslerAlt_new, /* tp_new */
8468 };
8469
8470 /* Lorenz object */
8471 typedef struct
8472 {
8473 pyo_audio_HEAD
8474 PyObject *pitch;
8475 Stream *pitch_stream;
8476 PyObject *chaos;
8477 Stream *chaos_stream;
8478 MYFLT *altBuffer;
8479 MYFLT vDX;
8480 MYFLT vDY;
8481 MYFLT vDZ;
8482 MYFLT vX;
8483 MYFLT vY;
8484 MYFLT vZ;
8485 MYFLT pA;
8486 MYFLT pB;
8487 MYFLT oneOnSr;
8488 int modebuffer[4];
8489 } Lorenz;
8490
8491 static void
8492 Lorenz_readframes_ii(Lorenz *self)
8493 {
8494 MYFLT delta, pit, chao;
8495 int i;
8496
8497 pit = PyFloat_AS_DOUBLE(self->pitch);
8498 chao = PyFloat_AS_DOUBLE(self->chaos);
8499
8500 if (pit < 0.0)
8501 pit = 1.0;
8502 else if (pit > 1.0)
8503 pit = 750.0;
8504 else
8505 pit = pit * 749.0 + 1.0;
8506
8507 delta = self->oneOnSr * pit;
8508
8509 if (chao < 0.0)
8510 chao = 0.5;
8511 else if (chao > 1.0)
8512 chao = 3.0;
8513 else
8514 chao = chao * 2.5 + 0.5;
8515
8516 for (i = 0; i < self->bufsize; i++)
8517 {
8518 self->vDX = self->pA * (self->vY - self->vX);
8519 self->vDY = self->vX * (self->pB - self->vZ) - self->vY;
8520 self->vDZ = self->vX * self->vY - chao * self->vZ;
8521
8522 self->vX += self->vDX * delta;
8523 self->vY += self->vDY * delta;
8524 self->vZ += self->vDZ * delta;
8525
8526 self->data[i] = self->vX * LORENZ_SCALE;
8527 self->altBuffer[i] = self->vY * LORENZ_ALT_SCALE;
8528 }
8529 }
8530
8531 static void
8532 Lorenz_readframes_ai(Lorenz *self)
8533 {
8534 MYFLT delta, pit, chao;
8535 int i;
8536
8537 MYFLT *fr = Stream_getData((Stream *)self->pitch_stream);
8538 chao = PyFloat_AS_DOUBLE(self->chaos);
8539
8540 if (chao < 0.0)
8541 chao = 0.5;
8542 else if (chao > 1.0)
8543 chao = 3.0;
8544 else
8545 chao = chao * 2.5 + 0.5;
8546
8547 for (i = 0; i < self->bufsize; i++)
8548 {
8549 pit = fr[i];
8550
8551 if (pit < 0.0)
8552 pit = 1.0;
8553 else if (pit > 1.0)
8554 pit = 750.0;
8555 else
8556 pit = pit * 749.0 + 1.0;
8557
8558 delta = self->oneOnSr * pit;
8559 self->vDX = self->pA * (self->vY - self->vX);
8560 self->vDY = self->vX * (self->pB - self->vZ) - self->vY;
8561 self->vDZ = self->vX * self->vY - chao * self->vZ;
8562
8563 self->vX += self->vDX * delta;
8564 self->vY += self->vDY * delta;
8565 self->vZ += self->vDZ * delta;
8566
8567 self->data[i] = self->vX * LORENZ_SCALE;
8568 self->altBuffer[i] = self->vY * LORENZ_ALT_SCALE;
8569 }
8570 }
8571
8572 static void
8573 Lorenz_readframes_ia(Lorenz *self)
8574 {
8575 MYFLT delta, pit, chao;
8576 int i;
8577
8578 pit = PyFloat_AS_DOUBLE(self->pitch);
8579 MYFLT *ch = Stream_getData((Stream *)self->chaos_stream);
8580
8581 if (pit < 0.0)
8582 pit = 1.0;
8583 else if (pit > 1.0)
8584 pit = 750.0;
8585 else
8586 pit = pit * 749.0 + 1.0;
8587
8588 delta = self->oneOnSr * pit;
8589
8590 for (i = 0; i < self->bufsize; i++)
8591 {
8592 chao = ch[i];
8593
8594 if (chao < 0.0)
8595 chao = 0.5;
8596 else if (chao > 1.0)
8597 chao = 3.0;
8598 else
8599 chao = chao * 2.5 + 0.5;
8600
8601 self->vDX = self->pA * (self->vY - self->vX);
8602 self->vDY = self->vX * (self->pB - self->vZ) - self->vY;
8603 self->vDZ = self->vX * self->vY - chao * self->vZ;
8604
8605 self->vX += self->vDX * delta;
8606 self->vY += self->vDY * delta;
8607 self->vZ += self->vDZ * delta;
8608
8609 self->data[i] = self->vX * LORENZ_SCALE;
8610 self->altBuffer[i] = self->vY * LORENZ_ALT_SCALE;
8611 }
8612 }
8613
8614 static void
8615 Lorenz_readframes_aa(Lorenz *self)
8616 {
8617 MYFLT delta, pit, chao;
8618 int i;
8619
8620 MYFLT *fr = Stream_getData((Stream *)self->pitch_stream);
8621 MYFLT *ch = Stream_getData((Stream *)self->chaos_stream);
8622
8623 for (i = 0; i < self->bufsize; i++)
8624 {
8625 pit = fr[i];
8626
8627 if (pit < 0.0)
8628 pit = 1.0;
8629 else if (pit > 1.0)
8630 pit = 750.0;
8631 else
8632 pit = pit * 749.0 + 1.0;
8633
8634 delta = self->oneOnSr * pit;
8635
8636 chao = ch[i];
8637
8638 if (chao < 0.0)
8639 chao = 0.5;
8640 else if (chao > 1.0)
8641 chao = 3.0;
8642 else
8643 chao = chao * 2.5 + 0.5;
8644
8645 self->vDX = self->pA * (self->vY - self->vX);
8646 self->vDY = self->vX * (self->pB - self->vZ) - self->vY;
8647 self->vDZ = self->vX * self->vY - chao * self->vZ;
8648
8649 self->vX += self->vDX * delta;
8650 self->vY += self->vDY * delta;
8651 self->vZ += self->vDZ * delta;
8652
8653 self->data[i] = self->vX * LORENZ_SCALE;
8654 self->altBuffer[i] = self->vY * LORENZ_ALT_SCALE;
8655 }
8656 }
8657
8658 static void Lorenz_postprocessing_ii(Lorenz *self) { POST_PROCESSING_II };
8659 static void Lorenz_postprocessing_ai(Lorenz *self) { POST_PROCESSING_AI };
8660 static void Lorenz_postprocessing_ia(Lorenz *self) { POST_PROCESSING_IA };
8661 static void Lorenz_postprocessing_aa(Lorenz *self) { POST_PROCESSING_AA };
8662 static void Lorenz_postprocessing_ireva(Lorenz *self) { POST_PROCESSING_IREVA };
8663 static void Lorenz_postprocessing_areva(Lorenz *self) { POST_PROCESSING_AREVA };
8664 static void Lorenz_postprocessing_revai(Lorenz *self) { POST_PROCESSING_REVAI };
8665 static void Lorenz_postprocessing_revaa(Lorenz *self) { POST_PROCESSING_REVAA };
8666 static void Lorenz_postprocessing_revareva(Lorenz *self) { POST_PROCESSING_REVAREVA };
8667
8668 static void
8669 Lorenz_setProcMode(Lorenz *self)
8670 {
8671 int procmode, muladdmode;
8672 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
8673 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
8674
8675 switch (procmode)
8676 {
8677 case 0:
8678 self->proc_func_ptr = Lorenz_readframes_ii;
8679 break;
8680
8681 case 1:
8682 self->proc_func_ptr = Lorenz_readframes_ai;
8683 break;
8684
8685 case 10:
8686 self->proc_func_ptr = Lorenz_readframes_ia;
8687 break;
8688
8689 case 11:
8690 self->proc_func_ptr = Lorenz_readframes_aa;
8691 break;
8692 }
8693
8694 switch (muladdmode)
8695 {
8696 case 0:
8697 self->muladd_func_ptr = Lorenz_postprocessing_ii;
8698 break;
8699
8700 case 1:
8701 self->muladd_func_ptr = Lorenz_postprocessing_ai;
8702 break;
8703
8704 case 2:
8705 self->muladd_func_ptr = Lorenz_postprocessing_revai;
8706 break;
8707
8708 case 10:
8709 self->muladd_func_ptr = Lorenz_postprocessing_ia;
8710 break;
8711
8712 case 11:
8713 self->muladd_func_ptr = Lorenz_postprocessing_aa;
8714 break;
8715
8716 case 12:
8717 self->muladd_func_ptr = Lorenz_postprocessing_revaa;
8718 break;
8719
8720 case 20:
8721 self->muladd_func_ptr = Lorenz_postprocessing_ireva;
8722 break;
8723
8724 case 21:
8725 self->muladd_func_ptr = Lorenz_postprocessing_areva;
8726 break;
8727
8728 case 22:
8729 self->muladd_func_ptr = Lorenz_postprocessing_revareva;
8730 break;
8731 }
8732 }
8733
8734 static void
8735 Lorenz_compute_next_data_frame(Lorenz *self)
8736 {
8737 (*self->proc_func_ptr)(self);
8738 (*self->muladd_func_ptr)(self);
8739 }
8740
8741 static int
8742 Lorenz_traverse(Lorenz *self, visitproc visit, void *arg)
8743 {
8744 pyo_VISIT
8745 Py_VISIT(self->pitch);
8746 Py_VISIT(self->chaos);
8747 return 0;
8748 }
8749
8750 static int
8751 Lorenz_clear(Lorenz *self)
8752 {
8753 pyo_CLEAR
8754 Py_CLEAR(self->pitch);
8755 Py_CLEAR(self->chaos);
8756 return 0;
8757 }
8758
8759 static void
8760 Lorenz_dealloc(Lorenz* self)
8761 {
8762 pyo_DEALLOC
8763 PyMem_RawFree(self->altBuffer);
8764 Lorenz_clear(self);
8765 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
8766 Py_TYPE(self)->tp_free((PyObject*)self);
8767 }
8768
8769 static PyObject *
8770 Lorenz_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
8771 {
8772 int i;
8773 PyObject *pitchtmp = NULL, *chaostmp = NULL, *multmp = NULL, *addtmp = NULL;
8774 Lorenz *self;
8775 self = (Lorenz *)type->tp_alloc(type, 0);
8776
8777 self->pitch = PyFloat_FromDouble(0.25);
8778 self->chaos = PyFloat_FromDouble(0.5);
8779 self->pA = 10.0;
8780 self->pB = 28.0;
8781 self->vDX = self->vDY = self->vDZ = 0.0;
8782 self->vX = self->vY = self->vZ = 1.0;
8783 self->modebuffer[0] = 0;
8784 self->modebuffer[1] = 0;
8785 self->modebuffer[2] = 0;
8786 self->modebuffer[3] = 0;
8787
8788 INIT_OBJECT_COMMON
8789 Stream_setFunctionPtr(self->stream, Lorenz_compute_next_data_frame);
8790 self->mode_func_ptr = Lorenz_setProcMode;
8791
8792 self->oneOnSr = 1.0 / self->sr;
8793
8794 static char *kwlist[] = {"pitch", "chaos", "mul", "add", NULL};
8795
8796 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &pitchtmp, &chaostmp, &multmp, &addtmp))
8797 Py_RETURN_NONE;
8798
8799 if (pitchtmp)
8800 {
8801 PyObject_CallMethod((PyObject *)self, "setPitch", "O", pitchtmp);
8802 }
8803
8804 if (chaostmp)
8805 {
8806 PyObject_CallMethod((PyObject *)self, "setChaos", "O", chaostmp);
8807 }
8808
8809 if (multmp)
8810 {
8811 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
8812 }
8813
8814 if (addtmp)
8815 {
8816 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
8817 }
8818
8819 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
8820
8821 self->altBuffer = (MYFLT *)PyMem_RawRealloc(self->altBuffer, self->bufsize * sizeof(MYFLT));
8822
8823 for (i = 0; i < self->bufsize; i++)
8824 {
8825 self->altBuffer[i] = 0.0;
8826 }
8827
8828 (*self->mode_func_ptr)(self);
8829
8830 return (PyObject *)self;
8831 }
8832
8833 static PyObject * Lorenz_getServer(Lorenz* self) { GET_SERVER };
8834 static PyObject * Lorenz_getStream(Lorenz* self) { GET_STREAM };
8835 static PyObject * Lorenz_setMul(Lorenz *self, PyObject *arg) { SET_MUL };
8836 static PyObject * Lorenz_setAdd(Lorenz *self, PyObject *arg) { SET_ADD };
8837 static PyObject * Lorenz_setSub(Lorenz *self, PyObject *arg) { SET_SUB };
8838 static PyObject * Lorenz_setDiv(Lorenz *self, PyObject *arg) { SET_DIV };
8839
8840 static PyObject * Lorenz_play(Lorenz *self, PyObject *args, PyObject *kwds) { PLAY };
8841 static PyObject * Lorenz_out(Lorenz *self, PyObject *args, PyObject *kwds) { OUT };
8842 static PyObject * Lorenz_stop(Lorenz *self, PyObject *args, PyObject *kwds) { STOP };
8843
8844 static PyObject * Lorenz_multiply(Lorenz *self, PyObject *arg) { MULTIPLY };
8845 static PyObject * Lorenz_inplace_multiply(Lorenz *self, PyObject *arg) { INPLACE_MULTIPLY };
8846 static PyObject * Lorenz_add(Lorenz *self, PyObject *arg) { ADD };
8847 static PyObject * Lorenz_inplace_add(Lorenz *self, PyObject *arg) { INPLACE_ADD };
8848 static PyObject * Lorenz_sub(Lorenz *self, PyObject *arg) { SUB };
8849 static PyObject * Lorenz_inplace_sub(Lorenz *self, PyObject *arg) { INPLACE_SUB };
8850 static PyObject * Lorenz_div(Lorenz *self, PyObject *arg) { DIV };
8851 static PyObject * Lorenz_inplace_div(Lorenz *self, PyObject *arg) { INPLACE_DIV };
8852
8853 static PyObject * Lorenz_setPitch(Lorenz *self, PyObject *arg) { SET_PARAM(self->pitch, self->pitch_stream, 2); }
8854 static PyObject * Lorenz_setChaos(Lorenz *self, PyObject *arg) { SET_PARAM(self->chaos, self->chaos_stream, 3); }
8855
8856 MYFLT *
8857 Lorenz_getAltBuffer(Lorenz *self)
8858 {
8859 return (MYFLT *)self->altBuffer;
8860 }
8861
8862 static PyMemberDef Lorenz_members[] =
8863 {
8864 {"server", T_OBJECT_EX, offsetof(Lorenz, server), 0, "Pyo server."},
8865 {"stream", T_OBJECT_EX, offsetof(Lorenz, stream), 0, "Stream object."},
8866 {"pitch", T_OBJECT_EX, offsetof(Lorenz, pitch), 0, "Pitch."},
8867 {"chaos", T_OBJECT_EX, offsetof(Lorenz, chaos), 0, "Chaotic behavior."},
8868 {"mul", T_OBJECT_EX, offsetof(Lorenz, mul), 0, "Mul factor."},
8869 {"add", T_OBJECT_EX, offsetof(Lorenz, add), 0, "Add factor."},
8870 {NULL} /* Sentinel */
8871 };
8872
8873 static PyMethodDef Lorenz_methods[] =
8874 {
8875 {"getServer", (PyCFunction)Lorenz_getServer, METH_NOARGS, "Returns server object."},
8876 {"_getStream", (PyCFunction)Lorenz_getStream, METH_NOARGS, "Returns stream object."},
8877 {"play", (PyCFunction)Lorenz_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
8878 {"out", (PyCFunction)Lorenz_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
8879 {"stop", (PyCFunction)Lorenz_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
8880 {"setPitch", (PyCFunction)Lorenz_setPitch, METH_O, "Sets oscillator pitch."},
8881 {"setChaos", (PyCFunction)Lorenz_setChaos, METH_O, "Sets oscillator chaotic behavior."},
8882 {"setMul", (PyCFunction)Lorenz_setMul, METH_O, "Sets Lorenz mul factor."},
8883 {"setAdd", (PyCFunction)Lorenz_setAdd, METH_O, "Sets Lorenz add factor."},
8884 {"setSub", (PyCFunction)Lorenz_setSub, METH_O, "Sets inverse add factor."},
8885 {"setDiv", (PyCFunction)Lorenz_setDiv, METH_O, "Sets inverse mul factor."},
8886 {NULL} /* Sentinel */
8887 };
8888
8889 static PyNumberMethods Lorenz_as_number =
8890 {
8891 (binaryfunc)Lorenz_add, /*nb_add*/
8892 (binaryfunc)Lorenz_sub, /*nb_subtract*/
8893 (binaryfunc)Lorenz_multiply, /*nb_multiply*/
8894 0, /*nb_remainder*/
8895 0, /*nb_divmod*/
8896 0, /*nb_power*/
8897 0, /*nb_neg*/
8898 0, /*nb_pos*/
8899 0, /*(unaryfunc)array_abs*/
8900 0, /*nb_nonzero*/
8901 0, /*nb_invert*/
8902 0, /*nb_lshift*/
8903 0, /*nb_rshift*/
8904 0, /*nb_and*/
8905 0, /*nb_xor*/
8906 0, /*nb_or*/
8907 0, /*nb_int*/
8908 0, /*nb_long*/
8909 0, /*nb_float*/
8910 (binaryfunc)Lorenz_inplace_add, /*inplace_add*/
8911 (binaryfunc)Lorenz_inplace_sub, /*inplace_subtract*/
8912 (binaryfunc)Lorenz_inplace_multiply, /*inplace_multiply*/
8913 0, /*inplace_remainder*/
8914 0, /*inplace_power*/
8915 0, /*inplace_lshift*/
8916 0, /*inplace_rshift*/
8917 0, /*inplace_and*/
8918 0, /*inplace_xor*/
8919 0, /*inplace_or*/
8920 0, /*nb_floor_divide*/
8921 (binaryfunc)Lorenz_div, /*nb_true_divide*/
8922 0, /*nb_inplace_floor_divide*/
8923 (binaryfunc)Lorenz_inplace_div, /*nb_inplace_true_divide*/
8924 0, /* nb_index */
8925 };
8926
8927 PyTypeObject LorenzType =
8928 {
8929 PyVarObject_HEAD_INIT(NULL, 0)
8930 "_pyo.Lorenz_base", /*tp_name*/
8931 sizeof(Lorenz), /*tp_basicsize*/
8932 0, /*tp_itemsize*/
8933 (destructor)Lorenz_dealloc, /*tp_dealloc*/
8934 0, /*tp_print*/
8935 0, /*tp_getattr*/
8936 0, /*tp_setattr*/
8937 0, /*tp_as_async (tp_compare in Python 2)*/
8938 0, /*tp_repr*/
8939 &Lorenz_as_number, /*tp_as_number*/
8940 0, /*tp_as_sequence*/
8941 0, /*tp_as_mapping*/
8942 0, /*tp_hash */
8943 0, /*tp_call*/
8944 0, /*tp_str*/
8945 0, /*tp_getattro*/
8946 0, /*tp_setattro*/
8947 0, /*tp_as_buffer*/
8948 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
8949 "Lorenz objects. Lorenz attractor.", /* tp_doc */
8950 (traverseproc)Lorenz_traverse, /* tp_traverse */
8951 (inquiry)Lorenz_clear, /* tp_clear */
8952 0, /* tp_richcompare */
8953 0, /* tp_weaklistoffset */
8954 0, /* tp_iter */
8955 0, /* tp_iternext */
8956 Lorenz_methods, /* tp_methods */
8957 Lorenz_members, /* tp_members */
8958 0, /* tp_getset */
8959 0, /* tp_base */
8960 0, /* tp_dict */
8961 0, /* tp_descr_get */
8962 0, /* tp_descr_set */
8963 0, /* tp_dictoffset */
8964 0, /* tp_init */
8965 0, /* tp_alloc */
8966 Lorenz_new, /* tp_new */
8967 };
8968
8969 typedef struct
8970 {
8971 pyo_audio_HEAD
8972 Lorenz *mainLorenz;
8973 int modebuffer[2];
8974 } LorenzAlt;
8975
8976 static void LorenzAlt_postprocessing_ii(LorenzAlt *self) { POST_PROCESSING_II };
8977 static void LorenzAlt_postprocessing_ai(LorenzAlt *self) { POST_PROCESSING_AI };
8978 static void LorenzAlt_postprocessing_ia(LorenzAlt *self) { POST_PROCESSING_IA };
8979 static void LorenzAlt_postprocessing_aa(LorenzAlt *self) { POST_PROCESSING_AA };
8980 static void LorenzAlt_postprocessing_ireva(LorenzAlt *self) { POST_PROCESSING_IREVA };
8981 static void LorenzAlt_postprocessing_areva(LorenzAlt *self) { POST_PROCESSING_AREVA };
8982 static void LorenzAlt_postprocessing_revai(LorenzAlt *self) { POST_PROCESSING_REVAI };
8983 static void LorenzAlt_postprocessing_revaa(LorenzAlt *self) { POST_PROCESSING_REVAA };
8984 static void LorenzAlt_postprocessing_revareva(LorenzAlt *self) { POST_PROCESSING_REVAREVA };
8985
8986 static void
8987 LorenzAlt_setProcMode(LorenzAlt *self)
8988 {
8989 int muladdmode;
8990 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
8991
8992 switch (muladdmode)
8993 {
8994 case 0:
8995 self->muladd_func_ptr = LorenzAlt_postprocessing_ii;
8996 break;
8997
8998 case 1:
8999 self->muladd_func_ptr = LorenzAlt_postprocessing_ai;
9000 break;
9001
9002 case 2:
9003 self->muladd_func_ptr = LorenzAlt_postprocessing_revai;
9004 break;
9005
9006 case 10:
9007 self->muladd_func_ptr = LorenzAlt_postprocessing_ia;
9008 break;
9009
9010 case 11:
9011 self->muladd_func_ptr = LorenzAlt_postprocessing_aa;
9012 break;
9013
9014 case 12:
9015 self->muladd_func_ptr = LorenzAlt_postprocessing_revaa;
9016 break;
9017
9018 case 20:
9019 self->muladd_func_ptr = LorenzAlt_postprocessing_ireva;
9020 break;
9021
9022 case 21:
9023 self->muladd_func_ptr = LorenzAlt_postprocessing_areva;
9024 break;
9025
9026 case 22:
9027 self->muladd_func_ptr = LorenzAlt_postprocessing_revareva;
9028 break;
9029 }
9030 }
9031
9032 static void
9033 LorenzAlt_compute_next_data_frame(LorenzAlt *self)
9034 {
9035 int i;
9036 MYFLT *tmp;
9037 tmp = Lorenz_getAltBuffer((Lorenz *)self->mainLorenz);
9038
9039 for (i = 0; i < self->bufsize; i++)
9040 {
9041 self->data[i] = tmp[i];
9042 }
9043
9044 (*self->muladd_func_ptr)(self);
9045 }
9046
9047 static int
9048 LorenzAlt_traverse(LorenzAlt *self, visitproc visit, void *arg)
9049 {
9050 pyo_VISIT
9051 Py_VISIT(self->mainLorenz);
9052 return 0;
9053 }
9054
9055 static int
9056 LorenzAlt_clear(LorenzAlt *self)
9057 {
9058 pyo_CLEAR
9059 Py_CLEAR(self->mainLorenz);
9060 return 0;
9061 }
9062
9063 static void
9064 LorenzAlt_dealloc(LorenzAlt* self)
9065 {
9066 pyo_DEALLOC
9067 LorenzAlt_clear(self);
9068 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
9069 Py_TYPE(self)->tp_free((PyObject*)self);
9070 }
9071
9072 static PyObject *
9073 LorenzAlt_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
9074 {
9075 int i;
9076 PyObject *maintmp = NULL, *multmp = NULL, *addtmp = NULL;
9077 LorenzAlt *self;
9078 self = (LorenzAlt *)type->tp_alloc(type, 0);
9079
9080 self->modebuffer[0] = 0;
9081 self->modebuffer[1] = 0;
9082
9083 INIT_OBJECT_COMMON
9084 Stream_setFunctionPtr(self->stream, LorenzAlt_compute_next_data_frame);
9085 self->mode_func_ptr = LorenzAlt_setProcMode;
9086
9087 static char *kwlist[] = {"mainLorenz", "mul", "alt", NULL};
9088
9089 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &maintmp, &multmp, &addtmp))
9090 Py_RETURN_NONE;
9091
9092 self->mainLorenz = (Lorenz *)maintmp;
9093 Py_INCREF(self->mainLorenz);
9094
9095 if (multmp)
9096 {
9097 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
9098 }
9099
9100 if (addtmp)
9101 {
9102 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
9103 }
9104
9105 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
9106
9107 (*self->mode_func_ptr)(self);
9108
9109 return (PyObject *)self;
9110 }
9111
9112 static PyObject * LorenzAlt_getServer(LorenzAlt* self) { GET_SERVER };
9113 static PyObject * LorenzAlt_getStream(LorenzAlt* self) { GET_STREAM };
9114 static PyObject * LorenzAlt_setMul(LorenzAlt *self, PyObject *arg) { SET_MUL };
9115 static PyObject * LorenzAlt_setAdd(LorenzAlt *self, PyObject *arg) { SET_ADD };
9116 static PyObject * LorenzAlt_setSub(LorenzAlt *self, PyObject *arg) { SET_SUB };
9117 static PyObject * LorenzAlt_setDiv(LorenzAlt *self, PyObject *arg) { SET_DIV };
9118
9119 static PyObject * LorenzAlt_play(LorenzAlt *self, PyObject *args, PyObject *kwds) { PLAY };
9120 static PyObject * LorenzAlt_out(LorenzAlt *self, PyObject *args, PyObject *kwds) { OUT };
9121 static PyObject * LorenzAlt_stop(LorenzAlt *self, PyObject *args, PyObject *kwds) { STOP };
9122
9123 static PyObject * LorenzAlt_multiply(LorenzAlt *self, PyObject *arg) { MULTIPLY };
9124 static PyObject * LorenzAlt_inplace_multiply(LorenzAlt *self, PyObject *arg) { INPLACE_MULTIPLY };
9125 static PyObject * LorenzAlt_add(LorenzAlt *self, PyObject *arg) { ADD };
9126 static PyObject * LorenzAlt_inplace_add(LorenzAlt *self, PyObject *arg) { INPLACE_ADD };
9127 static PyObject * LorenzAlt_sub(LorenzAlt *self, PyObject *arg) { SUB };
9128 static PyObject * LorenzAlt_inplace_sub(LorenzAlt *self, PyObject *arg) { INPLACE_SUB };
9129 static PyObject * LorenzAlt_div(LorenzAlt *self, PyObject *arg) { DIV };
9130 static PyObject * LorenzAlt_inplace_div(LorenzAlt *self, PyObject *arg) { INPLACE_DIV };
9131
9132 static PyMemberDef LorenzAlt_members[] =
9133 {
9134 {"server", T_OBJECT_EX, offsetof(LorenzAlt, server), 0, "Pyo server."},
9135 {"stream", T_OBJECT_EX, offsetof(LorenzAlt, stream), 0, "Stream object."},
9136 {"mul", T_OBJECT_EX, offsetof(LorenzAlt, mul), 0, "Mul factor."},
9137 {"add", T_OBJECT_EX, offsetof(LorenzAlt, add), 0, "Add factor."},
9138 {NULL} /* Sentinel */
9139 };
9140
9141 static PyMethodDef LorenzAlt_methods[] =
9142 {
9143 {"getServer", (PyCFunction)LorenzAlt_getServer, METH_NOARGS, "Returns server object."},
9144 {"_getStream", (PyCFunction)LorenzAlt_getStream, METH_NOARGS, "Returns stream object."},
9145 {"play", (PyCFunction)LorenzAlt_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
9146 {"out", (PyCFunction)LorenzAlt_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
9147 {"stop", (PyCFunction)LorenzAlt_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
9148 {"setMul", (PyCFunction)LorenzAlt_setMul, METH_O, "Sets oscillator mul factor."},
9149 {"setAdd", (PyCFunction)LorenzAlt_setAdd, METH_O, "Sets oscillator add factor."},
9150 {"setSub", (PyCFunction)LorenzAlt_setSub, METH_O, "Sets inverse add factor."},
9151 {"setDiv", (PyCFunction)LorenzAlt_setDiv, METH_O, "Sets inverse mul factor."},
9152 {NULL} /* Sentinel */
9153 };
9154 static PyNumberMethods LorenzAlt_as_number =
9155 {
9156 (binaryfunc)LorenzAlt_add, /*nb_add*/
9157 (binaryfunc)LorenzAlt_sub, /*nb_subtract*/
9158 (binaryfunc)LorenzAlt_multiply, /*nb_multiply*/
9159 0, /*nb_remainder*/
9160 0, /*nb_divmod*/
9161 0, /*nb_power*/
9162 0, /*nb_neg*/
9163 0, /*nb_pos*/
9164 0, /*(unaryfunc)array_abs,*/
9165 0, /*nb_nonzero*/
9166 0, /*nb_invert*/
9167 0, /*nb_lshift*/
9168 0, /*nb_rshift*/
9169 0, /*nb_and*/
9170 0, /*nb_xor*/
9171 0, /*nb_or*/
9172 0, /*nb_int*/
9173 0, /*nb_long*/
9174 0, /*nb_float*/
9175 (binaryfunc)LorenzAlt_inplace_add, /*inplace_add*/
9176 (binaryfunc)LorenzAlt_inplace_sub, /*inplace_subtract*/
9177 (binaryfunc)LorenzAlt_inplace_multiply, /*inplace_multiply*/
9178 0, /*inplace_remainder*/
9179 0, /*inplace_power*/
9180 0, /*inplace_lshift*/
9181 0, /*inplace_rshift*/
9182 0, /*inplace_and*/
9183 0, /*inplace_xor*/
9184 0, /*inplace_or*/
9185 0, /*nb_floor_divide*/
9186 (binaryfunc)LorenzAlt_div, /*nb_true_divide*/
9187 0, /*nb_inplace_floor_divide*/
9188 (binaryfunc)LorenzAlt_inplace_div, /*nb_inplace_true_divide*/
9189 0, /* nb_index */
9190 };
9191
9192 PyTypeObject LorenzAltType =
9193 {
9194 PyVarObject_HEAD_INIT(NULL, 0)
9195 "_pyo.LorenzAlt_base", /*tp_name*/
9196 sizeof(LorenzAlt), /*tp_basicsize*/
9197 0, /*tp_itemsize*/
9198 (destructor)LorenzAlt_dealloc, /*tp_dealloc*/
9199 0, /*tp_print*/
9200 0, /*tp_getattr*/
9201 0, /*tp_setattr*/
9202 0, /*tp_as_async (tp_compare in Python 2)*/
9203 0, /*tp_repr*/
9204 &LorenzAlt_as_number, /*tp_as_number*/
9205 0, /*tp_as_sequence*/
9206 0, /*tp_as_mapping*/
9207 0, /*tp_hash */
9208 0, /*tp_call*/
9209 0, /*tp_str*/
9210 0, /*tp_getattro*/
9211 0, /*tp_setattro*/
9212 0, /*tp_as_buffer*/
9213 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
9214 "LorenzAlt objects. Sends the alternate signal of a Lorenz attractor.", /* tp_doc */
9215 (traverseproc)LorenzAlt_traverse, /* tp_traverse */
9216 (inquiry)LorenzAlt_clear, /* tp_clear */
9217 0, /* tp_richcompare */
9218 0, /* tp_weaklistoffset */
9219 0, /* tp_iter */
9220 0, /* tp_iternext */
9221 LorenzAlt_methods, /* tp_methods */
9222 LorenzAlt_members, /* tp_members */
9223 0, /* tp_getset */
9224 0, /* tp_base */
9225 0, /* tp_dict */
9226 0, /* tp_descr_get */
9227 0, /* tp_descr_set */
9228 0, /* tp_dictoffset */
9229 0, /* tp_init */
9230 0, /* tp_alloc */
9231 LorenzAlt_new, /* tp_new */
9232 };
9233
9234 /* ChenLee object */
9235 typedef struct
9236 {
9237 pyo_audio_HEAD
9238 PyObject *pitch;
9239 Stream *pitch_stream;
9240 PyObject *chaos;
9241 Stream *chaos_stream;
9242 MYFLT *altBuffer;
9243 MYFLT vDX;
9244 MYFLT vDY;
9245 MYFLT vDZ;
9246 MYFLT vX;
9247 MYFLT vY;
9248 MYFLT vZ;
9249 MYFLT pA;
9250 MYFLT pB;
9251 MYFLT oneOnSr;
9252 int modebuffer[4];
9253 } ChenLee;
9254
9255 static void
9256 ChenLee_readframes_ii(ChenLee *self)
9257 {
9258 MYFLT delta, pit, chao;
9259 int i;
9260
9261 pit = PyFloat_AS_DOUBLE(self->pitch);
9262 chao = PyFloat_AS_DOUBLE(self->chaos);
9263
9264 if (pit < 0.0)
9265 pit = 1.0;
9266 else if (pit > 1.0)
9267 pit = 125.0;
9268 else
9269 pit = pit * 124.0 + 1.0;
9270
9271 delta = self->oneOnSr * pit;
9272
9273 if (chao < 0.0)
9274 chao = 4.0;
9275 else if (chao > 1.0)
9276 chao = 2.51;
9277 else
9278 chao = (1.0 - chao) * 1.49 + 2.51;
9279
9280 for (i = 0; i < self->bufsize; i++)
9281 {
9282 self->vDX = -self->vY * self->vZ + self->pA * self->vX;
9283 self->vDY = self->vX * self->vZ - self->pB * self->vY;
9284 self->vDZ = self->vX * self->vY / 3.0 - chao * self->vZ;
9285
9286 self->vX += self->vDX * delta;
9287 self->vX = (self->vX > 50.0) ? 50.0 : (self->vX < -50.0) ? -50.0 : self->vX;
9288 self->vY += self->vDY * delta;
9289 self->vY = (self->vY > 50.0) ? 50.0 : (self->vY < -50.0) ? -50.0 : self->vY;
9290 self->vZ += self->vDZ * delta;
9291
9292 self->data[i] = self->vX * CHENLEE_SCALE;
9293 self->altBuffer[i] = self->vY * CHENLEE_ALT_SCALE;
9294 }
9295 }
9296
9297 static void
9298 ChenLee_readframes_ai(ChenLee *self)
9299 {
9300 MYFLT delta, pit, chao;
9301 int i;
9302
9303 MYFLT *fr = Stream_getData((Stream *)self->pitch_stream);
9304 chao = PyFloat_AS_DOUBLE(self->chaos);
9305
9306 if (chao < 0.0)
9307 chao = 4.0;
9308 else if (chao > 1.0)
9309 chao = 2.51;
9310 else
9311 chao = (1.0 - chao) * 1.49 + 2.51;
9312
9313 for (i = 0; i < self->bufsize; i++)
9314 {
9315 pit = fr[i];
9316
9317 if (pit < 0.0)
9318 pit = 1.0;
9319 else if (pit > 1.0)
9320 pit = 125.0;
9321 else
9322 pit = pit * 124.0 + 1.0;
9323
9324 delta = self->oneOnSr * pit;
9325 self->vDX = -self->vY * self->vZ + self->pA * self->vX;
9326 self->vDY = self->vX * self->vZ - self->pB * self->vY;
9327 self->vDZ = self->vX * self->vY / 3.0 - chao * self->vZ;
9328
9329 self->vX += self->vDX * delta;
9330 self->vX = (self->vX > 50.0) ? 50.0 : (self->vX < -50.0) ? -50.0 : self->vX;
9331 self->vY += self->vDY * delta;
9332 self->vY = (self->vY > 50.0) ? 50.0 : (self->vY < -50.0) ? -50.0 : self->vY;
9333 self->vZ += self->vDZ * delta;
9334
9335 self->data[i] = self->vX * CHENLEE_SCALE;
9336 self->altBuffer[i] = self->vY * CHENLEE_ALT_SCALE;
9337 }
9338 }
9339
9340 static void
9341 ChenLee_readframes_ia(ChenLee *self)
9342 {
9343 MYFLT delta, pit, chao;
9344 int i;
9345
9346 pit = PyFloat_AS_DOUBLE(self->pitch);
9347 MYFLT *ch = Stream_getData((Stream *)self->chaos_stream);
9348
9349 if (pit < 0.0)
9350 pit = 1.0;
9351 else if (pit > 1.0)
9352 pit = 125.0;
9353 else
9354 pit = pit * 124.0 + 1.0;
9355
9356 delta = self->oneOnSr * pit;
9357
9358 for (i = 0; i < self->bufsize; i++)
9359 {
9360 chao = ch[i];
9361
9362 if (chao < 0.0)
9363 chao = 4.0;
9364 else if (chao > 1.0)
9365 chao = 2.51;
9366 else
9367 chao = (1.0 - chao) * 1.49 + 2.51;
9368
9369 self->vDX = -self->vY * self->vZ + self->pA * self->vX;
9370 self->vDY = self->vX * self->vZ - self->pB * self->vY;
9371 self->vDZ = self->vX * self->vY / 3.0 - chao * self->vZ;
9372
9373 self->vX += self->vDX * delta;
9374 self->vX = (self->vX > 50.0) ? 50.0 : (self->vX < -50.0) ? -50.0 : self->vX;
9375 self->vY += self->vDY * delta;
9376 self->vY = (self->vY > 50.0) ? 50.0 : (self->vY < -50.0) ? -50.0 : self->vY;
9377 self->vZ += self->vDZ * delta;
9378
9379 self->data[i] = self->vX * CHENLEE_SCALE;
9380 self->altBuffer[i] = self->vY * CHENLEE_ALT_SCALE;
9381 }
9382 }
9383
9384 static void
9385 ChenLee_readframes_aa(ChenLee *self)
9386 {
9387 MYFLT delta, pit, chao;
9388 int i;
9389
9390 MYFLT *fr = Stream_getData((Stream *)self->pitch_stream);
9391 MYFLT *ch = Stream_getData((Stream *)self->chaos_stream);
9392
9393 for (i = 0; i < self->bufsize; i++)
9394 {
9395 pit = fr[i];
9396
9397 if (pit < 0.0)
9398 pit = 1.0;
9399 else if (pit > 1.0)
9400 pit = 125.0;
9401 else
9402 pit = pit * 124.0 + 1.0;
9403
9404 delta = self->oneOnSr * pit;
9405
9406 chao = ch[i];
9407
9408 if (chao < 0.0)
9409 chao = 4.0;
9410 else if (chao > 1.0)
9411 chao = 2.51;
9412 else
9413 chao = (1.0 - chao) * 1.49 + 2.51;
9414
9415 self->vDX = -self->vY * self->vZ + self->pA * self->vX;
9416 self->vDY = self->vX * self->vZ - self->pB * self->vY;
9417 self->vDZ = self->vX * self->vY / 3.0 - chao * self->vZ;
9418
9419 self->vX += self->vDX * delta;
9420 self->vX = (self->vX > 50.0) ? 50.0 : (self->vX < -50.0) ? -50.0 : self->vX;
9421 self->vY += self->vDY * delta;
9422 self->vY = (self->vY > 50.0) ? 50.0 : (self->vY < -50.0) ? -50.0 : self->vY;
9423 self->vZ += self->vDZ * delta;
9424
9425 self->data[i] = self->vX * CHENLEE_SCALE;
9426 self->altBuffer[i] = self->vY * CHENLEE_ALT_SCALE;
9427 }
9428 }
9429
9430 static void ChenLee_postprocessing_ii(ChenLee *self) { POST_PROCESSING_II };
9431 static void ChenLee_postprocessing_ai(ChenLee *self) { POST_PROCESSING_AI };
9432 static void ChenLee_postprocessing_ia(ChenLee *self) { POST_PROCESSING_IA };
9433 static void ChenLee_postprocessing_aa(ChenLee *self) { POST_PROCESSING_AA };
9434 static void ChenLee_postprocessing_ireva(ChenLee *self) { POST_PROCESSING_IREVA };
9435 static void ChenLee_postprocessing_areva(ChenLee *self) { POST_PROCESSING_AREVA };
9436 static void ChenLee_postprocessing_revai(ChenLee *self) { POST_PROCESSING_REVAI };
9437 static void ChenLee_postprocessing_revaa(ChenLee *self) { POST_PROCESSING_REVAA };
9438 static void ChenLee_postprocessing_revareva(ChenLee *self) { POST_PROCESSING_REVAREVA };
9439
9440 static void
9441 ChenLee_setProcMode(ChenLee *self)
9442 {
9443 int procmode, muladdmode;
9444 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
9445 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
9446
9447 switch (procmode)
9448 {
9449 case 0:
9450 self->proc_func_ptr = ChenLee_readframes_ii;
9451 break;
9452
9453 case 1:
9454 self->proc_func_ptr = ChenLee_readframes_ai;
9455 break;
9456
9457 case 10:
9458 self->proc_func_ptr = ChenLee_readframes_ia;
9459 break;
9460
9461 case 11:
9462 self->proc_func_ptr = ChenLee_readframes_aa;
9463 break;
9464 }
9465
9466 switch (muladdmode)
9467 {
9468 case 0:
9469 self->muladd_func_ptr = ChenLee_postprocessing_ii;
9470 break;
9471
9472 case 1:
9473 self->muladd_func_ptr = ChenLee_postprocessing_ai;
9474 break;
9475
9476 case 2:
9477 self->muladd_func_ptr = ChenLee_postprocessing_revai;
9478 break;
9479
9480 case 10:
9481 self->muladd_func_ptr = ChenLee_postprocessing_ia;
9482 break;
9483
9484 case 11:
9485 self->muladd_func_ptr = ChenLee_postprocessing_aa;
9486 break;
9487
9488 case 12:
9489 self->muladd_func_ptr = ChenLee_postprocessing_revaa;
9490 break;
9491
9492 case 20:
9493 self->muladd_func_ptr = ChenLee_postprocessing_ireva;
9494 break;
9495
9496 case 21:
9497 self->muladd_func_ptr = ChenLee_postprocessing_areva;
9498 break;
9499
9500 case 22:
9501 self->muladd_func_ptr = ChenLee_postprocessing_revareva;
9502 break;
9503 }
9504 }
9505
9506 static void
9507 ChenLee_compute_next_data_frame(ChenLee *self)
9508 {
9509 (*self->proc_func_ptr)(self);
9510 (*self->muladd_func_ptr)(self);
9511 }
9512
9513 static int
9514 ChenLee_traverse(ChenLee *self, visitproc visit, void *arg)
9515 {
9516 pyo_VISIT
9517 Py_VISIT(self->pitch);
9518 Py_VISIT(self->chaos);
9519 return 0;
9520 }
9521
9522 static int
9523 ChenLee_clear(ChenLee *self)
9524 {
9525 pyo_CLEAR
9526 Py_CLEAR(self->pitch);
9527 Py_CLEAR(self->chaos);
9528 return 0;
9529 }
9530
9531 static void
9532 ChenLee_dealloc(ChenLee* self)
9533 {
9534 pyo_DEALLOC
9535 PyMem_RawFree(self->altBuffer);
9536 ChenLee_clear(self);
9537 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
9538 Py_TYPE(self)->tp_free((PyObject*)self);
9539 }
9540
9541 static PyObject *
9542 ChenLee_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
9543 {
9544 int i;
9545 PyObject *pitchtmp = NULL, *chaostmp = NULL, *multmp = NULL, *addtmp = NULL;
9546 ChenLee *self;
9547 self = (ChenLee *)type->tp_alloc(type, 0);
9548
9549 self->pitch = PyFloat_FromDouble(0.25);
9550 self->chaos = PyFloat_FromDouble(0.5);
9551 self->pA = 5.0;
9552 self->pB = 10.0;
9553 self->vDX = self->vDY = self->vDZ = 0.0;
9554 self->vX = self->vY = self->vZ = 1.0;
9555 self->modebuffer[0] = 0;
9556 self->modebuffer[1] = 0;
9557 self->modebuffer[2] = 0;
9558 self->modebuffer[3] = 0;
9559
9560 INIT_OBJECT_COMMON
9561 Stream_setFunctionPtr(self->stream, ChenLee_compute_next_data_frame);
9562 self->mode_func_ptr = ChenLee_setProcMode;
9563
9564 self->oneOnSr = 1.0 / self->sr;
9565
9566 static char *kwlist[] = {"pitch", "chaos", "mul", "add", NULL};
9567
9568 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &pitchtmp, &chaostmp, &multmp, &addtmp))
9569 Py_RETURN_NONE;
9570
9571 if (pitchtmp)
9572 {
9573 PyObject_CallMethod((PyObject *)self, "setPitch", "O", pitchtmp);
9574 }
9575
9576 if (chaostmp)
9577 {
9578 PyObject_CallMethod((PyObject *)self, "setChaos", "O", chaostmp);
9579 }
9580
9581 if (multmp)
9582 {
9583 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
9584 }
9585
9586 if (addtmp)
9587 {
9588 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
9589 }
9590
9591 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
9592
9593 self->altBuffer = (MYFLT *)PyMem_RawRealloc(self->altBuffer, self->bufsize * sizeof(MYFLT));
9594
9595 for (i = 0; i < self->bufsize; i++)
9596 {
9597 self->altBuffer[i] = 0.0;
9598 }
9599
9600 (*self->mode_func_ptr)(self);
9601
9602 return (PyObject *)self;
9603 }
9604
9605 static PyObject * ChenLee_getServer(ChenLee* self) { GET_SERVER };
9606 static PyObject * ChenLee_getStream(ChenLee* self) { GET_STREAM };
9607 static PyObject * ChenLee_setMul(ChenLee *self, PyObject *arg) { SET_MUL };
9608 static PyObject * ChenLee_setAdd(ChenLee *self, PyObject *arg) { SET_ADD };
9609 static PyObject * ChenLee_setSub(ChenLee *self, PyObject *arg) { SET_SUB };
9610 static PyObject * ChenLee_setDiv(ChenLee *self, PyObject *arg) { SET_DIV };
9611
9612 static PyObject * ChenLee_play(ChenLee *self, PyObject *args, PyObject *kwds) { PLAY };
9613 static PyObject * ChenLee_out(ChenLee *self, PyObject *args, PyObject *kwds) { OUT };
9614 static PyObject * ChenLee_stop(ChenLee *self, PyObject *args, PyObject *kwds) { STOP };
9615
9616 static PyObject * ChenLee_multiply(ChenLee *self, PyObject *arg) { MULTIPLY };
9617 static PyObject * ChenLee_inplace_multiply(ChenLee *self, PyObject *arg) { INPLACE_MULTIPLY };
9618 static PyObject * ChenLee_add(ChenLee *self, PyObject *arg) { ADD };
9619 static PyObject * ChenLee_inplace_add(ChenLee *self, PyObject *arg) { INPLACE_ADD };
9620 static PyObject * ChenLee_sub(ChenLee *self, PyObject *arg) { SUB };
9621 static PyObject * ChenLee_inplace_sub(ChenLee *self, PyObject *arg) { INPLACE_SUB };
9622 static PyObject * ChenLee_div(ChenLee *self, PyObject *arg) { DIV };
9623 static PyObject * ChenLee_inplace_div(ChenLee *self, PyObject *arg) { INPLACE_DIV };
9624
9625 static PyObject * ChenLee_setPitch(ChenLee *self, PyObject *arg) { SET_PARAM(self->pitch, self->pitch_stream, 2); }
9626 static PyObject * ChenLee_setChaos(ChenLee *self, PyObject *arg) { SET_PARAM(self->chaos, self->chaos_stream, 3); }
9627
9628 MYFLT *
9629 ChenLee_getAltBuffer(ChenLee *self)
9630 {
9631 return (MYFLT *)self->altBuffer;
9632 }
9633
9634 static PyMemberDef ChenLee_members[] =
9635 {
9636 {"server", T_OBJECT_EX, offsetof(ChenLee, server), 0, "Pyo server."},
9637 {"stream", T_OBJECT_EX, offsetof(ChenLee, stream), 0, "Stream object."},
9638 {"pitch", T_OBJECT_EX, offsetof(ChenLee, pitch), 0, "Pitch."},
9639 {"chaos", T_OBJECT_EX, offsetof(ChenLee, chaos), 0, "Chaotic behavior."},
9640 {"mul", T_OBJECT_EX, offsetof(ChenLee, mul), 0, "Mul factor."},
9641 {"add", T_OBJECT_EX, offsetof(ChenLee, add), 0, "Add factor."},
9642 {NULL} /* Sentinel */
9643 };
9644
9645 static PyMethodDef ChenLee_methods[] =
9646 {
9647 {"getServer", (PyCFunction)ChenLee_getServer, METH_NOARGS, "Returns server object."},
9648 {"_getStream", (PyCFunction)ChenLee_getStream, METH_NOARGS, "Returns stream object."},
9649 {"play", (PyCFunction)ChenLee_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
9650 {"out", (PyCFunction)ChenLee_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
9651 {"stop", (PyCFunction)ChenLee_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
9652 {"setPitch", (PyCFunction)ChenLee_setPitch, METH_O, "Sets oscillator pitch."},
9653 {"setChaos", (PyCFunction)ChenLee_setChaos, METH_O, "Sets oscillator chaotic behavior."},
9654 {"setMul", (PyCFunction)ChenLee_setMul, METH_O, "Sets ChenLee mul factor."},
9655 {"setAdd", (PyCFunction)ChenLee_setAdd, METH_O, "Sets ChenLee add factor."},
9656 {"setSub", (PyCFunction)ChenLee_setSub, METH_O, "Sets inverse add factor."},
9657 {"setDiv", (PyCFunction)ChenLee_setDiv, METH_O, "Sets inverse mul factor."},
9658 {NULL} /* Sentinel */
9659 };
9660
9661 static PyNumberMethods ChenLee_as_number =
9662 {
9663 (binaryfunc)ChenLee_add, /*nb_add*/
9664 (binaryfunc)ChenLee_sub, /*nb_subtract*/
9665 (binaryfunc)ChenLee_multiply, /*nb_multiply*/
9666 0, /*nb_remainder*/
9667 0, /*nb_divmod*/
9668 0, /*nb_power*/
9669 0, /*nb_neg*/
9670 0, /*nb_pos*/
9671 0, /*(unaryfunc)array_abs*/
9672 0, /*nb_nonzero*/
9673 0, /*nb_invert*/
9674 0, /*nb_lshift*/
9675 0, /*nb_rshift*/
9676 0, /*nb_and*/
9677 0, /*nb_xor*/
9678 0, /*nb_or*/
9679 0, /*nb_int*/
9680 0, /*nb_long*/
9681 0, /*nb_float*/
9682 (binaryfunc)ChenLee_inplace_add, /*inplace_add*/
9683 (binaryfunc)ChenLee_inplace_sub, /*inplace_subtract*/
9684 (binaryfunc)ChenLee_inplace_multiply, /*inplace_multiply*/
9685 0, /*inplace_remainder*/
9686 0, /*inplace_power*/
9687 0, /*inplace_lshift*/
9688 0, /*inplace_rshift*/
9689 0, /*inplace_and*/
9690 0, /*inplace_xor*/
9691 0, /*inplace_or*/
9692 0, /*nb_floor_divide*/
9693 (binaryfunc)ChenLee_div, /*nb_true_divide*/
9694 0, /*nb_inplace_floor_divide*/
9695 (binaryfunc)ChenLee_inplace_div, /*nb_inplace_true_divide*/
9696 0, /* nb_index */
9697 };
9698
9699 PyTypeObject ChenLeeType =
9700 {
9701 PyVarObject_HEAD_INIT(NULL, 0)
9702 "_pyo.ChenLee_base", /*tp_name*/
9703 sizeof(ChenLee), /*tp_basicsize*/
9704 0, /*tp_itemsize*/
9705 (destructor)ChenLee_dealloc, /*tp_dealloc*/
9706 0, /*tp_print*/
9707 0, /*tp_getattr*/
9708 0, /*tp_setattr*/
9709 0, /*tp_as_async (tp_compare in Python 2)*/
9710 0, /*tp_repr*/
9711 &ChenLee_as_number, /*tp_as_number*/
9712 0, /*tp_as_sequence*/
9713 0, /*tp_as_mapping*/
9714 0, /*tp_hash */
9715 0, /*tp_call*/
9716 0, /*tp_str*/
9717 0, /*tp_getattro*/
9718 0, /*tp_setattro*/
9719 0, /*tp_as_buffer*/
9720 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
9721 "ChenLee objects. ChenLee attractor.", /* tp_doc */
9722 (traverseproc)ChenLee_traverse, /* tp_traverse */
9723 (inquiry)ChenLee_clear, /* tp_clear */
9724 0, /* tp_richcompare */
9725 0, /* tp_weaklistoffset */
9726 0, /* tp_iter */
9727 0, /* tp_iternext */
9728 ChenLee_methods, /* tp_methods */
9729 ChenLee_members, /* tp_members */
9730 0, /* tp_getset */
9731 0, /* tp_base */
9732 0, /* tp_dict */
9733 0, /* tp_descr_get */
9734 0, /* tp_descr_set */
9735 0, /* tp_dictoffset */
9736 0, /* tp_init */
9737 0, /* tp_alloc */
9738 ChenLee_new, /* tp_new */
9739 };
9740
9741 typedef struct
9742 {
9743 pyo_audio_HEAD
9744 ChenLee *mainChenLee;
9745 int modebuffer[2];
9746 } ChenLeeAlt;
9747
9748 static void ChenLeeAlt_postprocessing_ii(ChenLeeAlt *self) { POST_PROCESSING_II };
9749 static void ChenLeeAlt_postprocessing_ai(ChenLeeAlt *self) { POST_PROCESSING_AI };
9750 static void ChenLeeAlt_postprocessing_ia(ChenLeeAlt *self) { POST_PROCESSING_IA };
9751 static void ChenLeeAlt_postprocessing_aa(ChenLeeAlt *self) { POST_PROCESSING_AA };
9752 static void ChenLeeAlt_postprocessing_ireva(ChenLeeAlt *self) { POST_PROCESSING_IREVA };
9753 static void ChenLeeAlt_postprocessing_areva(ChenLeeAlt *self) { POST_PROCESSING_AREVA };
9754 static void ChenLeeAlt_postprocessing_revai(ChenLeeAlt *self) { POST_PROCESSING_REVAI };
9755 static void ChenLeeAlt_postprocessing_revaa(ChenLeeAlt *self) { POST_PROCESSING_REVAA };
9756 static void ChenLeeAlt_postprocessing_revareva(ChenLeeAlt *self) { POST_PROCESSING_REVAREVA };
9757
9758 static void
9759 ChenLeeAlt_setProcMode(ChenLeeAlt *self)
9760 {
9761 int muladdmode;
9762 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
9763
9764 switch (muladdmode)
9765 {
9766 case 0:
9767 self->muladd_func_ptr = ChenLeeAlt_postprocessing_ii;
9768 break;
9769
9770 case 1:
9771 self->muladd_func_ptr = ChenLeeAlt_postprocessing_ai;
9772 break;
9773
9774 case 2:
9775 self->muladd_func_ptr = ChenLeeAlt_postprocessing_revai;
9776 break;
9777
9778 case 10:
9779 self->muladd_func_ptr = ChenLeeAlt_postprocessing_ia;
9780 break;
9781
9782 case 11:
9783 self->muladd_func_ptr = ChenLeeAlt_postprocessing_aa;
9784 break;
9785
9786 case 12:
9787 self->muladd_func_ptr = ChenLeeAlt_postprocessing_revaa;
9788 break;
9789
9790 case 20:
9791 self->muladd_func_ptr = ChenLeeAlt_postprocessing_ireva;
9792 break;
9793
9794 case 21:
9795 self->muladd_func_ptr = ChenLeeAlt_postprocessing_areva;
9796 break;
9797
9798 case 22:
9799 self->muladd_func_ptr = ChenLeeAlt_postprocessing_revareva;
9800 break;
9801 }
9802 }
9803
9804 static void
9805 ChenLeeAlt_compute_next_data_frame(ChenLeeAlt *self)
9806 {
9807 int i;
9808 MYFLT *tmp;
9809 tmp = ChenLee_getAltBuffer((ChenLee *)self->mainChenLee);
9810
9811 for (i = 0; i < self->bufsize; i++)
9812 {
9813 self->data[i] = tmp[i];
9814 }
9815
9816 (*self->muladd_func_ptr)(self);
9817 }
9818
9819 static int
9820 ChenLeeAlt_traverse(ChenLeeAlt *self, visitproc visit, void *arg)
9821 {
9822 pyo_VISIT
9823 Py_VISIT(self->mainChenLee);
9824 return 0;
9825 }
9826
9827 static int
9828 ChenLeeAlt_clear(ChenLeeAlt *self)
9829 {
9830 pyo_CLEAR
9831 Py_CLEAR(self->mainChenLee);
9832 return 0;
9833 }
9834
9835 static void
9836 ChenLeeAlt_dealloc(ChenLeeAlt* self)
9837 {
9838 pyo_DEALLOC
9839 ChenLeeAlt_clear(self);
9840 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
9841 Py_TYPE(self)->tp_free((PyObject*)self);
9842 }
9843
9844 static PyObject *
9845 ChenLeeAlt_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
9846 {
9847 int i;
9848 PyObject *maintmp = NULL, *multmp = NULL, *addtmp = NULL;
9849 ChenLeeAlt *self;
9850 self = (ChenLeeAlt *)type->tp_alloc(type, 0);
9851
9852 self->modebuffer[0] = 0;
9853 self->modebuffer[1] = 0;
9854
9855 INIT_OBJECT_COMMON
9856 Stream_setFunctionPtr(self->stream, ChenLeeAlt_compute_next_data_frame);
9857 self->mode_func_ptr = ChenLeeAlt_setProcMode;
9858
9859 static char *kwlist[] = {"mainChenLee", "mul", "alt", NULL};
9860
9861 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &maintmp, &multmp, &addtmp))
9862 Py_RETURN_NONE;
9863
9864 self->mainChenLee = (ChenLee *)maintmp;
9865 Py_INCREF(self->mainChenLee);
9866
9867 if (multmp)
9868 {
9869 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
9870 }
9871
9872 if (addtmp)
9873 {
9874 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
9875 }
9876
9877 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
9878
9879 (*self->mode_func_ptr)(self);
9880
9881 return (PyObject *)self;
9882 }
9883
9884 static PyObject * ChenLeeAlt_getServer(ChenLeeAlt* self) { GET_SERVER };
9885 static PyObject * ChenLeeAlt_getStream(ChenLeeAlt* self) { GET_STREAM };
9886 static PyObject * ChenLeeAlt_setMul(ChenLeeAlt *self, PyObject *arg) { SET_MUL };
9887 static PyObject * ChenLeeAlt_setAdd(ChenLeeAlt *self, PyObject *arg) { SET_ADD };
9888 static PyObject * ChenLeeAlt_setSub(ChenLeeAlt *self, PyObject *arg) { SET_SUB };
9889 static PyObject * ChenLeeAlt_setDiv(ChenLeeAlt *self, PyObject *arg) { SET_DIV };
9890
9891 static PyObject * ChenLeeAlt_play(ChenLeeAlt *self, PyObject *args, PyObject *kwds) { PLAY };
9892 static PyObject * ChenLeeAlt_out(ChenLeeAlt *self, PyObject *args, PyObject *kwds) { OUT };
9893 static PyObject * ChenLeeAlt_stop(ChenLeeAlt *self, PyObject *args, PyObject *kwds) { STOP };
9894
9895 static PyObject * ChenLeeAlt_multiply(ChenLeeAlt *self, PyObject *arg) { MULTIPLY };
9896 static PyObject * ChenLeeAlt_inplace_multiply(ChenLeeAlt *self, PyObject *arg) { INPLACE_MULTIPLY };
9897 static PyObject * ChenLeeAlt_add(ChenLeeAlt *self, PyObject *arg) { ADD };
9898 static PyObject * ChenLeeAlt_inplace_add(ChenLeeAlt *self, PyObject *arg) { INPLACE_ADD };
9899 static PyObject * ChenLeeAlt_sub(ChenLeeAlt *self, PyObject *arg) { SUB };
9900 static PyObject * ChenLeeAlt_inplace_sub(ChenLeeAlt *self, PyObject *arg) { INPLACE_SUB };
9901 static PyObject * ChenLeeAlt_div(ChenLeeAlt *self, PyObject *arg) { DIV };
9902 static PyObject * ChenLeeAlt_inplace_div(ChenLeeAlt *self, PyObject *arg) { INPLACE_DIV };
9903
9904 static PyMemberDef ChenLeeAlt_members[] =
9905 {
9906 {"server", T_OBJECT_EX, offsetof(ChenLeeAlt, server), 0, "Pyo server."},
9907 {"stream", T_OBJECT_EX, offsetof(ChenLeeAlt, stream), 0, "Stream object."},
9908 {"mul", T_OBJECT_EX, offsetof(ChenLeeAlt, mul), 0, "Mul factor."},
9909 {"add", T_OBJECT_EX, offsetof(ChenLeeAlt, add), 0, "Add factor."},
9910 {NULL} /* Sentinel */
9911 };
9912
9913 static PyMethodDef ChenLeeAlt_methods[] =
9914 {
9915 {"getServer", (PyCFunction)ChenLeeAlt_getServer, METH_NOARGS, "Returns server object."},
9916 {"_getStream", (PyCFunction)ChenLeeAlt_getStream, METH_NOARGS, "Returns stream object."},
9917 {"play", (PyCFunction)ChenLeeAlt_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
9918 {"out", (PyCFunction)ChenLeeAlt_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
9919 {"stop", (PyCFunction)ChenLeeAlt_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
9920 {"setMul", (PyCFunction)ChenLeeAlt_setMul, METH_O, "Sets oscillator mul factor."},
9921 {"setAdd", (PyCFunction)ChenLeeAlt_setAdd, METH_O, "Sets oscillator add factor."},
9922 {"setSub", (PyCFunction)ChenLeeAlt_setSub, METH_O, "Sets inverse add factor."},
9923 {"setDiv", (PyCFunction)ChenLeeAlt_setDiv, METH_O, "Sets inverse mul factor."},
9924 {NULL} /* Sentinel */
9925 };
9926 static PyNumberMethods ChenLeeAlt_as_number =
9927 {
9928 (binaryfunc)ChenLeeAlt_add, /*nb_add*/
9929 (binaryfunc)ChenLeeAlt_sub, /*nb_subtract*/
9930 (binaryfunc)ChenLeeAlt_multiply, /*nb_multiply*/
9931 0, /*nb_remainder*/
9932 0, /*nb_divmod*/
9933 0, /*nb_power*/
9934 0, /*nb_neg*/
9935 0, /*nb_pos*/
9936 0, /*(unaryfunc)array_abs,*/
9937 0, /*nb_nonzero*/
9938 0, /*nb_invert*/
9939 0, /*nb_lshift*/
9940 0, /*nb_rshift*/
9941 0, /*nb_and*/
9942 0, /*nb_xor*/
9943 0, /*nb_or*/
9944 0, /*nb_int*/
9945 0, /*nb_long*/
9946 0, /*nb_float*/
9947 (binaryfunc)ChenLeeAlt_inplace_add, /*inplace_add*/
9948 (binaryfunc)ChenLeeAlt_inplace_sub, /*inplace_subtract*/
9949 (binaryfunc)ChenLeeAlt_inplace_multiply, /*inplace_multiply*/
9950 0, /*inplace_remainder*/
9951 0, /*inplace_power*/
9952 0, /*inplace_lshift*/
9953 0, /*inplace_rshift*/
9954 0, /*inplace_and*/
9955 0, /*inplace_xor*/
9956 0, /*inplace_or*/
9957 0, /*nb_floor_divide*/
9958 (binaryfunc)ChenLeeAlt_div, /*nb_true_divide*/
9959 0, /*nb_inplace_floor_divide*/
9960 (binaryfunc)ChenLeeAlt_inplace_div, /*nb_inplace_true_divide*/
9961 0, /* nb_index */
9962 };
9963
9964 PyTypeObject ChenLeeAltType =
9965 {
9966 PyVarObject_HEAD_INIT(NULL, 0)
9967 "_pyo.ChenLeeAlt_base", /*tp_name*/
9968 sizeof(ChenLeeAlt), /*tp_basicsize*/
9969 0, /*tp_itemsize*/
9970 (destructor)ChenLeeAlt_dealloc, /*tp_dealloc*/
9971 0, /*tp_print*/
9972 0, /*tp_getattr*/
9973 0, /*tp_setattr*/
9974 0, /*tp_as_async (tp_compare in Python 2)*/
9975 0, /*tp_repr*/
9976 &ChenLeeAlt_as_number, /*tp_as_number*/
9977 0, /*tp_as_sequence*/
9978 0, /*tp_as_mapping*/
9979 0, /*tp_hash */
9980 0, /*tp_call*/
9981 0, /*tp_str*/
9982 0, /*tp_getattro*/
9983 0, /*tp_setattro*/
9984 0, /*tp_as_buffer*/
9985 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
9986 "ChenLeeAlt objects. Sends the alternate signal of a ChenLee attractor.", /* tp_doc */
9987 (traverseproc)ChenLeeAlt_traverse, /* tp_traverse */
9988 (inquiry)ChenLeeAlt_clear, /* tp_clear */
9989 0, /* tp_richcompare */
9990 0, /* tp_weaklistoffset */
9991 0, /* tp_iter */
9992 0, /* tp_iternext */
9993 ChenLeeAlt_methods, /* tp_methods */
9994 ChenLeeAlt_members, /* tp_members */
9995 0, /* tp_getset */
9996 0, /* tp_base */
9997 0, /* tp_dict */
9998 0, /* tp_descr_get */
9999 0, /* tp_descr_set */
10000 0, /* tp_dictoffset */
10001 0, /* tp_init */
10002 0, /* tp_alloc */
10003 ChenLeeAlt_new, /* tp_new */
10004 };
10005
10006 /*************/
10007 /* SumOsc object */
10008 /*************/
10009 typedef struct
10010 {
10011 pyo_audio_HEAD
10012 PyObject *freq;
10013 Stream *freq_stream;
10014 PyObject *ratio;
10015 Stream *ratio_stream;
10016 PyObject *index;
10017 Stream *index_stream;
10018 int modebuffer[5];
10019 MYFLT theta;
10020 MYFLT beta;
10021 MYFLT scaleFactor;
10022 MYFLT xn1; // dc block input delay
10023 MYFLT yn1; // dc block output delay
10024 } SumOsc;
10025
10026 static void
10027 SumOsc_readframes_iii(SumOsc *self)
10028 {
10029 MYFLT mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10030 int i, ipart;
10031
10032 MYFLT freq = PyFloat_AS_DOUBLE(self->freq);
10033 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
10034 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
10035
10036 freq_delta = freq * self->scaleFactor;
10037 mod_freq = freq * rat;
10038 mod_delta = mod_freq * self->scaleFactor;
10039
10040 if (ind < 0)
10041 ind = 0;
10042 else if (ind > 0.999)
10043 ind = 0.999;
10044
10045 ind2 = ind * ind;
10046
10047 for (i = 0; i < self->bufsize; i++)
10048 {
10049 ipart = (int)self->theta;
10050 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10051 theta_minus_beta = Sine_clip(self->theta - self->beta);
10052 ipart = (int)theta_minus_beta;
10053 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10054 ipart = (int)self->beta;
10055 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10056 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10057 self->theta += freq_delta;
10058 self->beta += mod_delta;
10059 self->theta = Sine_clip(self->theta);
10060 self->beta = Sine_clip(self->beta);
10061
10062 /* DC filtering */
10063 y = x - self->xn1 + 0.995 * self->yn1;
10064 self->xn1 = x;
10065 self->yn1 = y;
10066
10067 self->data[i] = y * (1 - ind2);
10068 }
10069 }
10070
10071 static void
10072 SumOsc_readframes_aii(SumOsc *self)
10073 {
10074 MYFLT freq, mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10075 int i, ipart;
10076
10077 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
10078 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
10079 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
10080
10081 if (ind < 0)
10082 ind = 0;
10083 else if (ind > 0.999)
10084 ind = 0.999;
10085
10086 ind2 = ind * ind;
10087
10088 for (i = 0; i < self->bufsize; i++)
10089 {
10090 freq = fr[i];
10091 freq_delta = freq * self->scaleFactor;
10092 mod_freq = freq * rat;
10093 mod_delta = mod_freq * self->scaleFactor;
10094 ipart = (int)self->theta;
10095 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10096 theta_minus_beta = Sine_clip(self->theta - self->beta);
10097 ipart = (int)theta_minus_beta;
10098 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10099 ipart = (int)self->beta;
10100 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10101 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10102 self->theta += freq_delta;
10103 self->beta += mod_delta;
10104 self->theta = Sine_clip(self->theta);
10105 self->beta = Sine_clip(self->beta);
10106
10107 y = x - self->xn1 + 0.995 * self->yn1;
10108 self->xn1 = x;
10109 self->yn1 = y;
10110
10111 self->data[i] = y * (1 - ind2);
10112 }
10113 }
10114
10115 static void
10116 SumOsc_readframes_iai(SumOsc *self)
10117 {
10118 MYFLT ratio, mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10119 int i, ipart;
10120
10121 MYFLT freq = PyFloat_AS_DOUBLE(self->freq);
10122 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
10123 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
10124
10125 freq_delta = freq * self->scaleFactor;
10126
10127 if (ind < 0)
10128 ind = 0;
10129 else if (ind > 0.999)
10130 ind = 0.999;
10131
10132 ind2 = ind * ind;
10133
10134 for (i = 0; i < self->bufsize; i++)
10135 {
10136 ratio = rat[i];
10137 mod_freq = freq * ratio;
10138 mod_delta = mod_freq * self->scaleFactor;
10139 ipart = (int)self->theta;
10140 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10141 theta_minus_beta = Sine_clip(self->theta - self->beta);
10142 ipart = (int)theta_minus_beta;
10143 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10144 ipart = (int)self->beta;
10145 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10146 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10147 self->theta += freq_delta;
10148 self->beta += mod_delta;
10149 self->theta = Sine_clip(self->theta);
10150 self->beta = Sine_clip(self->beta);
10151
10152 y = x - self->xn1 + 0.995 * self->yn1;
10153 self->xn1 = x;
10154 self->yn1 = y;
10155
10156 self->data[i] = y * (1 - ind2);
10157 }
10158 }
10159
10160 static void
10161 SumOsc_readframes_aai(SumOsc *self)
10162 {
10163 MYFLT freq, ratio, mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10164 int i, ipart;
10165
10166 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
10167 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
10168 MYFLT ind = PyFloat_AS_DOUBLE(self->index);
10169
10170 if (ind < 0)
10171 ind = 0;
10172 else if (ind > 0.999)
10173 ind = 0.999;
10174
10175 ind2 = ind * ind;
10176
10177 for (i = 0; i < self->bufsize; i++)
10178 {
10179 freq = fr[i];
10180 ratio = rat[i];
10181 freq_delta = freq * self->scaleFactor;
10182 mod_freq = freq * ratio;
10183 mod_delta = mod_freq * self->scaleFactor;
10184 ipart = (int)self->theta;
10185 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10186 theta_minus_beta = Sine_clip(self->theta - self->beta);
10187 ipart = (int)theta_minus_beta;
10188 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10189 ipart = (int)self->beta;
10190 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10191 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10192 self->theta += freq_delta;
10193 self->beta += mod_delta;
10194 self->theta = Sine_clip(self->theta);
10195 self->beta = Sine_clip(self->beta);
10196
10197 y = x - self->xn1 + 0.995 * self->yn1;
10198 self->xn1 = x;
10199 self->yn1 = y;
10200
10201 self->data[i] = y * (1 - ind2);
10202 }
10203 }
10204
10205 static void
10206 SumOsc_readframes_iia(SumOsc *self)
10207 {
10208 MYFLT ind, mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10209 int i, ipart;
10210
10211 MYFLT freq = PyFloat_AS_DOUBLE(self->freq);
10212 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
10213 MYFLT *index = Stream_getData((Stream *)self->index_stream);
10214
10215 freq_delta = freq * self->scaleFactor;
10216 mod_freq = freq * rat;
10217 mod_delta = mod_freq * self->scaleFactor;
10218
10219 for (i = 0; i < self->bufsize; i++)
10220 {
10221 ind = index[i];
10222
10223 if (ind < 0)
10224 ind = 0;
10225 else if (ind > 0.999)
10226 ind = 0.999;
10227
10228 ind2 = ind * ind;
10229 ipart = (int)self->theta;
10230 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10231 theta_minus_beta = Sine_clip(self->theta - self->beta);
10232 ipart = (int)theta_minus_beta;
10233 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10234 ipart = (int)self->beta;
10235 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10236 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10237 self->theta += freq_delta;
10238 self->beta += mod_delta;
10239 self->theta = Sine_clip(self->theta);
10240 self->beta = Sine_clip(self->beta);
10241
10242 y = x - self->xn1 + 0.995 * self->yn1;
10243 self->xn1 = x;
10244 self->yn1 = y;
10245
10246 self->data[i] = y * (1 - ind2);
10247 }
10248 }
10249
10250 static void
10251 SumOsc_readframes_aia(SumOsc *self)
10252 {
10253 MYFLT freq, ind, mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10254 int i, ipart;
10255
10256 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
10257 MYFLT rat = PyFloat_AS_DOUBLE(self->ratio);
10258 MYFLT *index = Stream_getData((Stream *)self->index_stream);
10259
10260 for (i = 0; i < self->bufsize; i++)
10261 {
10262 freq = fr[i];
10263 ind = index[i];
10264 freq_delta = freq * self->scaleFactor;
10265 mod_freq = freq * rat;
10266 mod_delta = mod_freq * self->scaleFactor;
10267
10268 if (ind < 0)
10269 ind = 0;
10270 else if (ind > 0.999)
10271 ind = 0.999;
10272
10273 ind2 = ind * ind;
10274 ipart = (int)self->theta;
10275 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10276 theta_minus_beta = Sine_clip(self->theta - self->beta);
10277 ipart = (int)theta_minus_beta;
10278 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10279 ipart = (int)self->beta;
10280 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10281 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10282 self->theta += freq_delta;
10283 self->beta += mod_delta;
10284 self->theta = Sine_clip(self->theta);
10285 self->beta = Sine_clip(self->beta);
10286
10287 y = x - self->xn1 + 0.995 * self->yn1;
10288 self->xn1 = x;
10289 self->yn1 = y;
10290
10291 self->data[i] = y * (1 - ind2);
10292 }
10293 }
10294
10295 static void
10296 SumOsc_readframes_iaa(SumOsc *self)
10297 {
10298 MYFLT ratio, ind, mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10299 int i, ipart;
10300
10301 MYFLT freq = PyFloat_AS_DOUBLE(self->freq);
10302 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
10303 MYFLT *index = Stream_getData((Stream *)self->index_stream);
10304
10305 freq_delta = freq * self->scaleFactor;
10306
10307 for (i = 0; i < self->bufsize; i++)
10308 {
10309 ind = index[i];
10310 ratio = rat[i];
10311 mod_freq = freq * ratio;
10312 mod_delta = mod_freq * self->scaleFactor;
10313
10314 if (ind < 0)
10315 ind = 0;
10316 else if (ind > 0.999)
10317 ind = 0.999;
10318
10319 ind2 = ind * ind;
10320 ipart = (int)self->theta;
10321 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10322 theta_minus_beta = Sine_clip(self->theta - self->beta);
10323 ipart = (int)theta_minus_beta;
10324 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10325 ipart = (int)self->beta;
10326 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10327 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10328 self->theta += freq_delta;
10329 self->beta += mod_delta;
10330 self->theta = Sine_clip(self->theta);
10331 self->beta = Sine_clip(self->beta);
10332
10333 y = x - self->xn1 + 0.995 * self->yn1;
10334 self->xn1 = x;
10335 self->yn1 = y;
10336
10337 self->data[i] = y * (1 - ind2);
10338 }
10339 }
10340
10341 static void
10342 SumOsc_readframes_aaa(SumOsc *self)
10343 {
10344 MYFLT freq, ratio, ind, mod_freq, mod_delta, freq_delta, x, y, ind2, theta_minus_beta, sin1, sin2, cos1;
10345 int i, ipart;
10346
10347 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
10348 MYFLT *rat = Stream_getData((Stream *)self->ratio_stream);
10349 MYFLT *index = Stream_getData((Stream *)self->index_stream);
10350
10351 for (i = 0; i < self->bufsize; i++)
10352 {
10353 freq = fr[i];
10354 ind = index[i];
10355 ratio = rat[i];
10356 freq_delta = freq * self->scaleFactor;
10357 mod_freq = freq * ratio;
10358 mod_delta = mod_freq * self->scaleFactor;
10359
10360 if (ind < 0)
10361 ind = 0;
10362 else if (ind > 0.999)
10363 ind = 0.999;
10364
10365 ind2 = ind * ind;
10366 ipart = (int)self->theta;
10367 sin1 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (self->theta - ipart);
10368 theta_minus_beta = Sine_clip(self->theta - self->beta);
10369 ipart = (int)theta_minus_beta;
10370 sin2 = SINE_ARRAY[ipart] + (SINE_ARRAY[ipart + 1] - SINE_ARRAY[ipart]) * (theta_minus_beta - ipart);
10371 ipart = (int)self->beta;
10372 cos1 = COSINE_ARRAY[ipart] + (COSINE_ARRAY[ipart + 1] - COSINE_ARRAY[ipart]) * (self->beta - ipart);
10373 x = (sin1 - ind * sin2) / (1 + ind2 - 2 * ind * cos1);
10374 self->theta += freq_delta;
10375 self->beta += mod_delta;
10376 self->theta = Sine_clip(self->theta);
10377 self->beta = Sine_clip(self->beta);
10378
10379 y = x - self->xn1 + 0.995 * self->yn1;
10380 self->xn1 = x;
10381 self->yn1 = y;
10382
10383 self->data[i] = y * (1 - ind2);
10384 }
10385 }
10386
10387 static void SumOsc_postprocessing_ii(SumOsc *self) { POST_PROCESSING_II };
10388 static void SumOsc_postprocessing_ai(SumOsc *self) { POST_PROCESSING_AI };
10389 static void SumOsc_postprocessing_ia(SumOsc *self) { POST_PROCESSING_IA };
10390 static void SumOsc_postprocessing_aa(SumOsc *self) { POST_PROCESSING_AA };
10391 static void SumOsc_postprocessing_ireva(SumOsc *self) { POST_PROCESSING_IREVA };
10392 static void SumOsc_postprocessing_areva(SumOsc *self) { POST_PROCESSING_AREVA };
10393 static void SumOsc_postprocessing_revai(SumOsc *self) { POST_PROCESSING_REVAI };
10394 static void SumOsc_postprocessing_revaa(SumOsc *self) { POST_PROCESSING_REVAA };
10395 static void SumOsc_postprocessing_revareva(SumOsc *self) { POST_PROCESSING_REVAREVA };
10396
10397 static void
10398 SumOsc_setProcMode(SumOsc *self)
10399 {
10400 int procmode, muladdmode;
10401 procmode = self->modebuffer[2] + self->modebuffer[3] * 10 + self->modebuffer[4] * 100;
10402 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
10403
10404 switch (procmode)
10405 {
10406 case 0:
10407 self->proc_func_ptr = SumOsc_readframes_iii;
10408 break;
10409
10410 case 1:
10411 self->proc_func_ptr = SumOsc_readframes_aii;
10412 break;
10413
10414 case 10:
10415 self->proc_func_ptr = SumOsc_readframes_iai;
10416 break;
10417
10418 case 11:
10419 self->proc_func_ptr = SumOsc_readframes_aai;
10420 break;
10421
10422 case 100:
10423 self->proc_func_ptr = SumOsc_readframes_iia;
10424 break;
10425
10426 case 101:
10427 self->proc_func_ptr = SumOsc_readframes_aia;
10428 break;
10429
10430 case 110:
10431 self->proc_func_ptr = SumOsc_readframes_iaa;
10432 break;
10433
10434 case 111:
10435 self->proc_func_ptr = SumOsc_readframes_aaa;
10436 break;
10437 }
10438
10439 switch (muladdmode)
10440 {
10441 case 0:
10442 self->muladd_func_ptr = SumOsc_postprocessing_ii;
10443 break;
10444
10445 case 1:
10446 self->muladd_func_ptr = SumOsc_postprocessing_ai;
10447 break;
10448
10449 case 2:
10450 self->muladd_func_ptr = SumOsc_postprocessing_revai;
10451 break;
10452
10453 case 10:
10454 self->muladd_func_ptr = SumOsc_postprocessing_ia;
10455 break;
10456
10457 case 11:
10458 self->muladd_func_ptr = SumOsc_postprocessing_aa;
10459 break;
10460
10461 case 12:
10462 self->muladd_func_ptr = SumOsc_postprocessing_revaa;
10463 break;
10464
10465 case 20:
10466 self->muladd_func_ptr = SumOsc_postprocessing_ireva;
10467 break;
10468
10469 case 21:
10470 self->muladd_func_ptr = SumOsc_postprocessing_areva;
10471 break;
10472
10473 case 22:
10474 self->muladd_func_ptr = SumOsc_postprocessing_revareva;
10475 break;
10476 }
10477 }
10478
10479 static void
10480 SumOsc_compute_next_data_frame(SumOsc *self)
10481 {
10482 (*self->proc_func_ptr)(self);
10483 (*self->muladd_func_ptr)(self);
10484 }
10485
10486 static int
10487 SumOsc_traverse(SumOsc *self, visitproc visit, void *arg)
10488 {
10489 pyo_VISIT
10490 Py_VISIT(self->freq);
10491 Py_VISIT(self->ratio);
10492 Py_VISIT(self->index);
10493 return 0;
10494 }
10495
10496 static int
10497 SumOsc_clear(SumOsc *self)
10498 {
10499 pyo_CLEAR
10500 Py_CLEAR(self->freq);
10501 Py_CLEAR(self->ratio);
10502 Py_CLEAR(self->index);
10503 return 0;
10504 }
10505
10506 static void
10507 SumOsc_dealloc(SumOsc* self)
10508 {
10509 pyo_DEALLOC
10510 SumOsc_clear(self);
10511 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
10512 Py_TYPE(self)->tp_free((PyObject*)self);
10513 }
10514
10515 static PyObject *
10516 SumOsc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
10517 {
10518 int i;
10519 PyObject *freqtmp = NULL, *ratiotmp = NULL, *indextmp = NULL, *multmp = NULL, *addtmp = NULL;
10520 SumOsc *self;
10521 self = (SumOsc *)type->tp_alloc(type, 0);
10522
10523 self->freq = PyFloat_FromDouble(100);
10524 self->ratio = PyFloat_FromDouble(0.5);
10525 self->index = PyFloat_FromDouble(0.5);
10526 self->modebuffer[0] = 0;
10527 self->modebuffer[1] = 0;
10528 self->modebuffer[2] = 0;
10529 self->modebuffer[3] = 0;
10530 self->modebuffer[4] = 0;
10531 self->theta = self->beta = 0.;
10532 self->xn1 = self->yn1 = 0.0;
10533
10534 INIT_OBJECT_COMMON
10535 Stream_setFunctionPtr(self->stream, SumOsc_compute_next_data_frame);
10536 self->mode_func_ptr = SumOsc_setProcMode;
10537
10538 self->scaleFactor = 512.0 / self->sr;
10539
10540 static char *kwlist[] = {"freq", "ratio", "index", "mul", "add", NULL};
10541
10542 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", kwlist, &freqtmp, &ratiotmp, &indextmp, &multmp, &addtmp))
10543 Py_RETURN_NONE;
10544
10545 if (freqtmp)
10546 {
10547 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
10548 }
10549
10550 if (ratiotmp)
10551 {
10552 PyObject_CallMethod((PyObject *)self, "setRatio", "O", ratiotmp);
10553 }
10554
10555 if (indextmp)
10556 {
10557 PyObject_CallMethod((PyObject *)self, "setIndex", "O", indextmp);
10558 }
10559
10560 if (multmp)
10561 {
10562 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
10563 }
10564
10565 if (addtmp)
10566 {
10567 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
10568 }
10569
10570 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
10571
10572 (*self->mode_func_ptr)(self);
10573
10574 return (PyObject *)self;
10575 }
10576
10577 static PyObject * SumOsc_getServer(SumOsc* self) { GET_SERVER };
10578 static PyObject * SumOsc_getStream(SumOsc* self) { GET_STREAM };
10579 static PyObject * SumOsc_setMul(SumOsc *self, PyObject *arg) { SET_MUL };
10580 static PyObject * SumOsc_setAdd(SumOsc *self, PyObject *arg) { SET_ADD };
10581 static PyObject * SumOsc_setSub(SumOsc *self, PyObject *arg) { SET_SUB };
10582 static PyObject * SumOsc_setDiv(SumOsc *self, PyObject *arg) { SET_DIV };
10583
10584 static PyObject * SumOsc_play(SumOsc *self, PyObject *args, PyObject *kwds) { PLAY };
10585 static PyObject * SumOsc_out(SumOsc *self, PyObject *args, PyObject *kwds) { OUT };
10586 static PyObject * SumOsc_stop(SumOsc *self, PyObject *args, PyObject *kwds) { STOP };
10587
10588 static PyObject * SumOsc_multiply(SumOsc *self, PyObject *arg) { MULTIPLY };
10589 static PyObject * SumOsc_inplace_multiply(SumOsc *self, PyObject *arg) { INPLACE_MULTIPLY };
10590 static PyObject * SumOsc_add(SumOsc *self, PyObject *arg) { ADD };
10591 static PyObject * SumOsc_inplace_add(SumOsc *self, PyObject *arg) { INPLACE_ADD };
10592 static PyObject * SumOsc_sub(SumOsc *self, PyObject *arg) { SUB };
10593 static PyObject * SumOsc_inplace_sub(SumOsc *self, PyObject *arg) { INPLACE_SUB };
10594 static PyObject * SumOsc_div(SumOsc *self, PyObject *arg) { DIV };
10595 static PyObject * SumOsc_inplace_div(SumOsc *self, PyObject *arg) { INPLACE_DIV };
10596
10597 static PyObject * SumOsc_setFreq(SumOsc *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
10598 static PyObject * SumOsc_setRatio(SumOsc *self, PyObject *arg) { SET_PARAM(self->ratio, self->ratio_stream, 3); }
10599 static PyObject * SumOsc_setIndex(SumOsc *self, PyObject *arg) { SET_PARAM(self->index, self->index_stream, 4); }
10600
10601 static PyMemberDef SumOsc_members[] =
10602 {
10603 {"server", T_OBJECT_EX, offsetof(SumOsc, server), 0, "Pyo server."},
10604 {"stream", T_OBJECT_EX, offsetof(SumOsc, stream), 0, "Stream object."},
10605 {"freq", T_OBJECT_EX, offsetof(SumOsc, freq), 0, "Frequency in cycle per second."},
10606 {"ratio", T_OBJECT_EX, offsetof(SumOsc, ratio), 0, "Ratio freq:modulator (mod freq = freq*ratio)."},
10607 {"index", T_OBJECT_EX, offsetof(SumOsc, index), 0, "Index, high frequency damping."},
10608 {"mul", T_OBJECT_EX, offsetof(SumOsc, mul), 0, "Mul factor."},
10609 {"add", T_OBJECT_EX, offsetof(SumOsc, add), 0, "Add factor."},
10610 {NULL} /* Sentinel */
10611 };
10612
10613 static PyMethodDef SumOsc_methods[] =
10614 {
10615 {"getServer", (PyCFunction)SumOsc_getServer, METH_NOARGS, "Returns server object."},
10616 {"_getStream", (PyCFunction)SumOsc_getStream, METH_NOARGS, "Returns stream object."},
10617 {"play", (PyCFunction)SumOsc_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundfreqd."},
10618 {"out", (PyCFunction)SumOsc_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundfreqd channel speficied by argument."},
10619 {"stop", (PyCFunction)SumOsc_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
10620 {"setFreq", (PyCFunction)SumOsc_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
10621 {"setRatio", (PyCFunction)SumOsc_setRatio, METH_O, "Sets freq:mod ratio."},
10622 {"setIndex", (PyCFunction)SumOsc_setIndex, METH_O, "Sets high frequency damping."},
10623 {"setMul", (PyCFunction)SumOsc_setMul, METH_O, "Sets SumOsc mul factor."},
10624 {"setAdd", (PyCFunction)SumOsc_setAdd, METH_O, "Sets SumOsc add factor."},
10625 {"setSub", (PyCFunction)SumOsc_setSub, METH_O, "Sets inverse add factor."},
10626 {"setDiv", (PyCFunction)SumOsc_setDiv, METH_O, "Sets inverse mul factor."},
10627 {NULL} /* Sentinel */
10628 };
10629
10630 static PyNumberMethods SumOsc_as_number =
10631 {
10632 (binaryfunc)SumOsc_add, /*nb_add*/
10633 (binaryfunc)SumOsc_sub, /*nb_subtract*/
10634 (binaryfunc)SumOsc_multiply, /*nb_multiply*/
10635 0, /*nb_remainder*/
10636 0, /*nb_divmod*/
10637 0, /*nb_power*/
10638 0, /*nb_neg*/
10639 0, /*nb_pos*/
10640 0, /*(unaryfunc)array_abs*/
10641 0, /*nb_nonzero*/
10642 0, /*nb_invert*/
10643 0, /*nb_lshift*/
10644 0, /*nb_rshift*/
10645 0, /*nb_and*/
10646 0, /*nb_xor*/
10647 0, /*nb_or*/
10648 0, /*nb_int*/
10649 0, /*nb_long*/
10650 0, /*nb_float*/
10651 (binaryfunc)SumOsc_inplace_add, /*inplace_add*/
10652 (binaryfunc)SumOsc_inplace_sub, /*inplace_subtract*/
10653 (binaryfunc)SumOsc_inplace_multiply, /*inplace_multiply*/
10654 0, /*inplace_remainder*/
10655 0, /*inplace_power*/
10656 0, /*inplace_lshift*/
10657 0, /*inplace_rshift*/
10658 0, /*inplace_and*/
10659 0, /*inplace_xor*/
10660 0, /*inplace_or*/
10661 0, /*nb_floor_divide*/
10662 (binaryfunc)SumOsc_div, /*nb_true_divide*/
10663 0, /*nb_inplace_floor_divide*/
10664 (binaryfunc)SumOsc_inplace_div, /*nb_inplace_true_divide*/
10665 0, /* nb_index */
10666 };
10667
10668 PyTypeObject SumOscType =
10669 {
10670 PyVarObject_HEAD_INIT(NULL, 0)
10671 "_pyo.SumOsc_base", /*tp_name*/
10672 sizeof(SumOsc), /*tp_basicsize*/
10673 0, /*tp_itemsize*/
10674 (destructor)SumOsc_dealloc, /*tp_dealloc*/
10675 0, /*tp_print*/
10676 0, /*tp_getattr*/
10677 0, /*tp_setattr*/
10678 0, /*tp_as_async (tp_compare in Python 2)*/
10679 0, /*tp_repr*/
10680 &SumOsc_as_number, /*tp_as_number*/
10681 0, /*tp_as_sequence*/
10682 0, /*tp_as_mapping*/
10683 0, /*tp_hash */
10684 0, /*tp_call*/
10685 0, /*tp_str*/
10686 0, /*tp_getattro*/
10687 0, /*tp_setattro*/
10688 0, /*tp_as_buffer*/
10689 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
10690 "SumOsc objects. Infite summation oscillator.", /* tp_doc */
10691 (traverseproc)SumOsc_traverse, /* tp_traverse */
10692 (inquiry)SumOsc_clear, /* tp_clear */
10693 0, /* tp_richcompare */
10694 0, /* tp_weaklistoffset */
10695 0, /* tp_iter */
10696 0, /* tp_iternext */
10697 SumOsc_methods, /* tp_methods */
10698 SumOsc_members, /* tp_members */
10699 0, /* tp_getset */
10700 0, /* tp_base */
10701 0, /* tp_dict */
10702 0, /* tp_descr_get */
10703 0, /* tp_descr_set */
10704 0, /* tp_dictoffset */
10705 0, /* tp_init */
10706 0, /* tp_alloc */
10707 SumOsc_new, /* tp_new */
10708 };
10709
10710 static MYFLT SUPERSAW_DETUNES[7][128] = {{1.0, 0.9999999999999738, 0.9999999999983218, 0.9999999999808844, 0.9999999998925958, 0.9999999995902856, 0.9999999987765995, 0.999999996915041, 0.9999999931261337, 0.9999999860647035, 0.9999999737782811, 0.9999999535466255, 0.999999921702367, 0.9999998734327713, 0.9999998025626238, 0.9999997013182335, 0.9999995600725585, 0.9999993670714514, 0.999999108141024, 0.9999987663761343, 0.999998321809992, 0.9999977510648862, 0.9999970269840314, 0.9999961182445354, 0.9999949889514873, 0.9999935982131656, 0.999991899697366, 0.9999898411688514, 0.9999873640079204, 0.999984402710097, 0.9999808843669409, 0.9999767281279772, 0.9999718446437478, 0.9999661354899821, 0.9999594925728883, 0.9999517975155655, 0.9999429210255355, 0.9999327222433956, 0.9999210480725913, 0.9999077324903094, 0.9998925958394921, 0.9998754441019703, 0.9998560681527183, 0.9998342429952286, 0.9998097269780065, 0.9997822609921857, 0.9997515676502643, 0.9997173504459607, 0.99967929289519, 0.9996370576581611, 0.9995902856425938, 0.9995385950880562, 0.999481580631423, 0.9994188123534535, 0.9993498348064905, 0.9992741660232791, 0.999191296506906, 0.9991006882018598, 0.9990017734462106, 0.9988939539049104, 0.9987765994842147, 0.9986490472272227, 0.9985106001905395, 0.9983605263020577, 0.9981980571998603, 0.9980223870522424, 0.9978326713588549, 0.9976280257329677, 0.9974075246648535, 0.9971702002662917, 0.996915040996193, 0.9966409903673441, 0.9963469456342734, 0.9960317564622357, 0.995694223577319, 0.9953330973976697, 0.9949470766458405, 0.9945348069422566, 0.994094879379803, 0.9936258290795327, 0.9931261337274945, 0.9925942120926815, 0.9920284225260998, 0.9914270614409579, 0.9907883617739762, 0.9901104914278165, 0.9893915516946329, 0.988629575660742, 0.9878225265924139, 0.9869682963027838, 0.9860647034998833, 0.985109492115793, 0.9841003296169146, 0.9830348052953636, 0.9819104285414826, 0.9807246270974751, 0.9794747452921589, 0.9781580422568408, 0.9767716901223106, 0.9753127721969568, 0.9737782811260014, 0.9721651170318559, 0.9704700856355972, 0.9686898963595642, 0.9668211604110741, 0.9648603888472602, 0.9628039906210292, 0.9606482706081385, 0.9583894276153956, 0.9560235523699754, 0.9535466254898602, 0.9509545154353983, 0.9482429764419842, 0.9454076464338582, 0.9424440449190272, 0.9393475708653054, 0.9361135005574749, 0.9327369854355683, 0.9292130499142693, 0.9255365891834358, 0.9217023669897422, 0.9177050133994422, 0.9135390225422524, 0.9091987503363557, 0.9046784121945255, 0.8999720807113701, 0.8950736833316975, 0.889977},
10711 {1.0, 0.999999999999985, 0.9999999999990408, 0.9999999999890743, 0.9999999999386124, 0.999999999765825, 0.999999999300757, 0.9999999982367705, 0.9999999960711946, 0.9999999920351857, 0.9999999850127967, 0.9999999734492553, 0.999999955248451, 0.9999999276596326, 0.9999998871533139, 0.9999998292863885, 0.9999997485564546, 0.9999996382453485, 0.9999994902518874, 0.9999992949138214, 0.9999990408189948, 0.9999987146057163, 0.9999983007523392, 0.9999977813560498, 0.9999971359008654, 0.9999963410148422, 0.9999953702164914, 0.9999941936504051, 0.9999927778120908, 0.9999910852620164, 0.9999890743288626, 0.9999866988019865, 0.9999839076130926, 0.9999806445071142, 0.9999768477023036, 0.9999724495395311, 0.9999673761207947, 0.9999615469369367, 0.999954874484572, 0.9999472638722232, 0.9999386124156673, 0.9999288092224893, 0.9999177347658472, 0.9999052604474442, 0.9998912481497119, 0.9998755497772012, 0.9998580067871834, 0.9998384497094605, 0.9998166976553837, 0.9997925578160827, 0.9997658249499025, 0.999736280859051, 0.9997036938554544, 0.9996678182158232, 0.9996283936259261, 0.9995851446140742, 0.9995377799738134, 0.9994859921758271, 0.9994294567690473, 0.9993678317709748, 0.9993007570472097, 0.9992278536801902, 0.9991487233271403, 0.9990629475672279, 0.9989700872379311, 0.998869681760614, 0.9987612484553119, 0.9986442818447255, 0.9985182529474248, 0.998382608560261, 0.9982367705299892, 0.998080135014099, 0.9979120717308554, 0.9977319231985478, 0.9975390039639489, 0.9973325998199832, 0.9971119670126036, 0.996876331436878, 0.9966248878222852, 0.9963567989072191, 0.9960711946027035, 0.9957671711453152, 0.9954437902393161, 0.9951000781879951, 0.9947350250142191, 0.9943475835701934, 0.9939366686364304, 0.9935011560099285, 0.9930398815815602, 0.9925516404026683, 0.9920351857408729, 0.9914892281250863, 0.9909124343797379, 0.9903034266482077, 0.9896607814054699, 0.9889830284599445, 0.9882686499445592, 0.9875160792970205, 0.9867237002292923, 0.9858898456862866, 0.9850127967937606, 0.984090781795425, 0.9831219749792602, 0.982104495593043, 0.9810364067490811, 0.9799157143181576, 0.978740365812685, 0.9775082492590679, 0.9762171920592747, 0.9748649598416194, 0.9734492553007513, 0.9719677170268558, 0.9704179183240623, 0.9687973660180627, 0.9671034992529387, 0.9653336882771985, 0.9634852332190221, 0.9615553628507172, 0.9595412333423818, 0.9574399270047795, 0.9552484510214205, 0.9529637361698543, 0.9505826355321707, 0.9481019231947095, 0.9455182929369806, 0.9428283569097924, 0.9400286443025894, 0.9371156},
10712 {1.0, 0.9999999999999953, 0.9999999999997022, 0.9999999999966079, 0.9999999999809411, 0.9999999999272962, 0.9999999997829073, 0.9999999994525735, 0.9999999987802313, 0.9999999975271793, 0.9999999953469515, 0.9999999917568408, 0.9999999861060718, 0.9999999775406239, 0.9999999649647041, 0.9999999469988698, 0.9999999219348009, 0.9999998876867218, 0.9999998417394735, 0.999999781093236, 0.9999997022048986, 0.9999996009260829, 0.9999994724378124, 0.9999993111818348, 0.999999110788592, 0.999998864001841, 0.9999985625999245, 0.9999981973136907, 0.9999977577410636, 0.9999972322582629, 0.9999966079276733, 0.9999958704023647, 0.9999950038272605, 0.9999939907369569, 0.9999928119501926, 0.9999914464609663, 0.9999898713263058, 0.9999880615506863, 0.9999859899670982, 0.9999836271147652, 0.9999809411135118, 0.9999778975347812, 0.999974459269302, 0.9999705863914059, 0.999966236019994, 0.9999613621761544, 0.9999559156374276, 0.9999498437887238, 0.9999430904698884, 0.9999355958199183, 0.9999272961178276, 0.9999181236201629, 0.9999080063951687, 0.9998968681536032, 0.9998846280762023, 0.9998712006377948, 0.9998564954280671, 0.9998404169689776, 0.9998228645288206, 0.9998037319329405, 0.9997829073710953, 0.9997602732014707, 0.9997357057513431, 0.999709075114393, 0.9996802449446679, 0.9996490722471952, 0.9996154071652449, 0.9995790927642417, 0.9995399648123278, 0.9994978515575741, 0.999452573501843, 0.9994039431712994, 0.9993517648835726, 0.9992958345115667, 0.9992359392439231, 0.9991718573421298, 0.9991033578942833, 0.9990302005654985, 0.998952135344969, 0.9988689022896773, 0.9987802312647548, 0.9986858416804911, 0.9985854422259942, 0.9984787305994991, 0.9983653932353271, 0.9982451050274953, 0.9981175290499744, 0.9979823162735979, 0.9978391052796202, 0.9976875219699247, 0.997527179273882, 0.9973576768518573, 0.9971786007953681, 0.9969895233238919, 0.9967900024783226, 0.9965795818110783, 0.9963577900728574, 0.9961241408960458, 0.995878132474773, 0.9956192472416178, 0.9953469515409651, 0.9950606952990115, 0.9947599116904207, 0.9944440168016286, 0.9941124092907996, 0.9937644700444305, 0.9933995618306056, 0.9930170289489021, 0.9926161968769434, 0.992196371913604, 0.9917568408188636, 0.9912968704503108, 0.9908157073962964, 0.9903125776057377, 0.9897866860145708, 0.9892372161688545, 0.9886633298445227, 0.9880641666637873, 0.9874388437081904, 0.9867864551283071, 0.9861060717500971, 0.985396740677907, 0.9846574848941214, 0.9838873028554654, 0.9830851680859551, 0.9822500287664989, 0.9813808073211485, 0.9804764},
10713 {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0},
10714 {1.0, 1.0000000000000047, 1.0000000000003038, 1.0000000000034597, 1.0000000000194382, 1.000000000074151, 1.0000000002214138, 1.0000000005583225, 1.000000001244047, 1.0000000025220401, 1.0000000047456632, 1.000000008407232, 1.0000000141704746, 1.00000002290641, 1.0000000357326424, 1.0000000540560707, 1.0000000796190178, 1.0000001145487747, 1.0000001614105622, 1.0000002232639098, 1.0000003037224496, 1.0000004070171307, 1.0000005380628465, 1.0000007025284818, 1.000000906910375, 1.0000011586091981, 1.0000014660102534, 1.000001838567187, 1.0000022868891185, 1.00000282283119, 1.0000034595885279, 1.0000042117936259, 1.0000050956171416, 1.000006128872112, 1.000007331121585, 1.0000087237896673, 1.0000103302759908, 1.0000121760735943, 1.0000142888902226, 1.0000166987730426, 1.0000194382367766, 1.0000225423952513, 1.0000260490963657, 1.0000299990604729, 1.000034436022182, 1.0000394068755751, 1.0000449618228406, 1.0000511545263258, 1.0000580422640029, 1.0000656860883557, 1.0000741509886801, 1.0000835060568027, 1.0000938246562172, 1.0001051845946354, 1.0001176682999573, 1.000131362999657, 1.0001463609035854, 1.0001627593901905, 1.0001806611961532, 1.000200174609442, 1.0002214136657828, 1.0002444983485461, 1.000269554792052, 1.0002967154882902, 1.0003261194970592, 1.0003579126595197, 1.000392247815168, 1.0004292850222227, 1.0004691917814321, 1.0005121432632953, 1.000558322538702, 1.0006079208129879, 1.0006611376634087, 1.0007181812800294, 1.0007792687100308, 1.0008446261054336, 1.000914488974239, 1.0009891024349855, 1.0010687214747234, 1.0011536112104062, 1.0012440471536985, 1.0013403154792009, 1.0014427132960908, 1.001551548923183, 1.0016671421674035, 1.0017898246056827, 1.0019199398702647, 1.0020578439374328, 1.0022039054196534, 1.0023585058611355, 1.0025220400368071, 1.0026949162547094, 1.0028775566618078, 1.0030703975532176, 1.0032738896848503, 1.0034884985894736, 1.0037147048961896, 1.00395300465333, 1.004203909654768, 1.0044679477696459, 1.0047456632755227, 1.0050376171949345, 1.005344387635375, 1.0056665701326912, 1.006004777997897, 1.0063596426674022, 1.0067318140566603, 1.0071219609172322, 1.0075307711972652, 1.0079589524053931, 1.0084072319780484, 1.0088763576501938, 1.0093670978294713, 1.0098802419737667, 1.0104166009721909, 1.010977007529479, 1.0115623165538064, 1.0121734055480207, 1.0128111750042907, 1.013476548802174, 1.0141704746100983, 1.0148939242902633, 1.0156478943069556, 1.016433406138284, 1.0172515066913297, 1.0181032687207134, 1.01898979125058, 1.0199122},
10715 {1.0, 1.0000000000000149, 1.0000000000009481, 1.0000000000108007, 1.0000000000606857, 1.0000000002314975, 1.000000000691248, 1.0000000017430692, 1.0000000038838848, 1.0000000078737472, 1.0000000148158443, 1.000000026247172, 1.0000000442398742, 1.0000000715132509, 1.0000001115564334, 1.000000168761727, 1.0000002485686208, 1.0000003576184653, 1.0000005039198165, 1.00000069702445, 1.0000009482140382, 1.000001270697499, 1.0000016798190097, 1.0000021932766892, 1.0000028313519465, 1.0000036171494986, 1.0000045768480532, 1.0000057399616615, 1.000007139611736, 1.0000088128097373, 1.0000108007505284, 1.0000131491163944, 1.0000159083917324, 1.0000191341884066, 1.0000228875817727, 1.0000272354573667, 1.0000322508682655, 1.0000380134031104, 1.0000446095648012, 1.0000521331598566, 1.0000606856984415, 1.0000703768050623, 1.0000813246399298, 1.000093656330989, 1.0001075084166169, 1.0001230272989865, 1.0001403697080997, 1.0001597031764875, 1.0001812065245754, 1.0002050703567196, 1.0002314975679076, 1.0002607038611286, 1.000292918275409, 1.0003283837245178, 1.0003673575463365, 1.0004101120629, 1.000456935151101, 1.000508130824065, 1.000564019823191, 1.00062494022086, 1.000691248033811, 1.0007633178471849, 1.0008415434492337, 1.0009263384767009, 1.0010181370708653, 1.0011173945442546, 1.0012245880580264, 1.0013402173100148, 1.0014648052334467, 1.0015988987063238, 1.0017430692714728, 1.0018979138672632, 1.0020640555689915, 1.0022421443409335, 1.002432857799065, 1.0026369019844479, 1.0028550121472843, 1.00308795354164, 1.0033365222308317, 1.0036015459034857, 1.003883884700261, 1.0041844320512403, 1.0045041155239904, 1.004843897682287, 1.00520477695551, 1.0055877885187026, 1.0059940051833023, 1.0064245382985348, 1.006880538663479, 1.0073631974497963, 1.0078737471351296, 1.008413462447169, 1.008983661318385, 1.0095857058514275, 1.0102210032951957, 1.0108910070315718, 1.011597217572824, 1.0123411835696772, 1.0131245028300493, 1.0139488233484573, 1.0148158443460882, 1.0157273173215406, 1.0166850471122297, 1.017690892966463, 1.018746769626182, 1.0198546484203714, 1.0210165583691362, 1.022234587298445, 1.0235108829655426, 1.0248476541950278, 1.0262471720256006, 1.027711770867476, 1.0292438496704641, 1.0308458731027206, 1.0325203727401608, 1.0342699482665438, 1.0360972686842238, 1.0380050735355673, 1.0399961741350399, 1.042073454811958, 1.04423987416391, 1.0464984663208448, 1.0488523422198255, 1.051304690890453, 1.053858780750956, 1.0565179609149487, 1.0592856625088545, 1.0621654},
10716 {1.0, 1.0000000000000255, 1.000000000001639, 1.0000000000186688, 1.0000000001048943, 1.0000000004001401, 1.0000000011948122, 1.0000000030128702, 1.0000000067132389, 1.0000000136096587, 1.0000000256089738, 1.0000000453678595, 1.0000000764679864, 1.0000001236096256, 1.000000192823691, 1.0000002917022184, 1.0000004296472869, 1.0000006181383747, 1.000000871018157, 1.000001204796739, 1.0000016389743303, 1.000002196382355, 1.0000029035430034, 1.000003791047219, 1.0000048939511264, 1.000006252190896, 1.0000079110160478, 1.0000099214411948, 1.0000123407162225, 1.0000152328149083, 1.00001866894198, 1.0000227280586114, 1.0000274974263563, 1.000033073169523, 1.0000395608559847, 1.0000470760964295, 1.0000557451620493, 1.000065705620667, 1.000077106991301, 1.0000901114171699, 1.0001048943571336, 1.0001216452955755, 1.0001405684707207, 1.0001618836213946, 1.0001858267522177, 1.0002126509172415, 1.0002426270220208, 1.0002760446441257, 1.0003132128720909, 1.0003544611628048, 1.0004001402173366, 1.0004506228752006, 1.000506305027061, 1.0005676065458742, 1.0006349722364685, 1.000708872803565, 1.0007898058382332, 1.0008782968227894, 1.0009749001541295, 1.0010802001855026, 1.0011948122867234, 1.0013193839228205, 1.001454595751126, 1.001601162736803, 1.0017598352868091, 1.0019314004023019, 1.0021166828494799, 1.0023165463488648, 1.0025318947830195, 1.0027636734227063, 1.003012870171483, 1.003280516828737, 1.0035676903711592, 1.0038755142526548, 1.0042051597226938, 1.0045578471630987, 1.0049348474432722, 1.0053374832938626, 1.0057671306988667, 1.0062252203061728, 1.0067132388565414, 1.0072327306310243, 1.0077852989168221, 1.0083726074915806, 1.0089963821261256, 1.009658412105635, 1.010360551769251, 1.0111047220681308, 1.0118929121419333, 1.012727180913748, 1.0136096587034578, 1.0145425488595459, 1.0155281294093352, 1.0165687547276714, 1.0176668572240406, 1.0188249490481271, 1.0200456238138111, 1.0213315583416007, 1.0226855144195075, 1.0241103405823564, 1.0256089739095362, 1.027184441841188, 1.028839864012832, 1.0305784541084329, 1.0324035217319039, 1.0343184742970488, 1.0363268189359423, 1.0384321644257501, 1.0406382231339857, 1.0429488129822073, 1.0453678594281517, 1.0478993974663078, 1.0505475736469276, 1.053316648113477, 1.0562109966585231, 1.0592351127980624, 1.0623936098642848, 1.0656912231167786, 1.0691328118721717, 1.0727233616522132, 1.0764679863502924, 1.080371930416396, 1.0844405710605045, 1.0886794204744272, 1.0930941280720745, 1.0976904827481695, 1.102474415155399, 1.107452}
10717 };
10718 static MYFLT SUPERSAW_BALANCES[7][128] = {{0.044372, 0.0540113055986112, 0.0635591436542873, 0.07301551416702834, 0.08238041713683428, 0.09165385256370512, 0.10083582044764089, 0.10992632078864159, 0.11892535358670717, 0.12783291884183767, 0.1366490165540331, 0.14537364672329345, 0.1540068093496187, 0.16254850443300886, 0.17099873197346394, 0.17935749197098394, 0.18762478442556885, 0.19580060933721868, 0.2038849667059334, 0.21187785653171307, 0.2197792788145576, 0.2275892335544671, 0.2353077207514415, 0.24293474040548083, 0.25047029251658504, 0.2579143770847542, 0.2652669941099882, 0.2725281435922872, 0.27969782553165107, 0.2867760399280799, 0.2937627867815736, 0.30065806609213225, 0.3074618778597557, 0.3141742220844442, 0.32079509876619755, 0.3273245079050158, 0.333762449500899, 0.34010892355384714, 0.3463639300638601, 0.35252746903093807, 0.3585995404550809, 0.36458014433628866, 0.3704692806745614, 0.37626694946989897, 0.3819731507223015, 0.3875878844317689, 0.39311115059830126, 0.3985429492218985, 0.40388328030256065, 0.4091321438402877, 0.4142895398350797, 0.4193554682869366, 0.4243299291958584, 0.4292129225618452, 0.4340044483848969, 0.4387045066650134, 0.4433130974021948, 0.4478302205964412, 0.4522558762477525, 0.45659006435612876, 0.4608327849215699, 0.4649840379440759, 0.4690438234236469, 0.47301214136028275, 0.4768889917539835, 0.4806743746047492, 0.4843682899125799, 0.4879707376774754, 0.4914817178994358, 0.4949012305784613, 0.4982292757145515, 0.5014658533077067, 0.5046109633579267, 0.5076646058652117, 0.5106267808295617, 0.5134974882509765, 0.5162767281294562, 0.518964500465001, 0.5215608052576105, 0.524065642507285, 0.5264790122140244, 0.5288009143778287, 0.531031348998698, 0.5331703160766321, 0.5352178156116313, 0.5371738476036952, 0.5390384120528241, 0.5408115089590179, 0.5424931383222766, 0.5440833001426003, 0.5455819944199888, 0.5469892211544423, 0.5483049803459606, 0.549529271994544, 0.5506620961001921, 0.5517034526629053, 0.5526533416826834, 0.5535117631595262, 0.5542787170934341, 0.5549542034844069, 0.5555382223324447, 0.5560307736375473, 0.5564318573997148, 0.5567414736189472, 0.5569596222952445, 0.557086303428607, 0.5571215170190341, 0.5570652630665262, 0.5569175415710832, 0.5566783525327051, 0.556347695951392, 0.5559255718271436, 0.5554119801599603, 0.5548069209498419, 0.5541103941967883, 0.5533223999007997, 0.552442938061876, 0.5514720086800173, 0.5504096117552235, 0.5492557472874944, 0.5480104152768307, 0.5466736157232315, 0.5452453486266973, 0.543725613987228, 0.5421144118048237, 0.5404117420794842, 0.5386176048112096, 0.536732},
10719 {0.044372, 0.0540113055986112, 0.0635591436542873, 0.07301551416702834, 0.08238041713683428, 0.09165385256370512, 0.10083582044764089, 0.10992632078864159, 0.11892535358670717, 0.12783291884183767, 0.1366490165540331, 0.14537364672329345, 0.1540068093496187, 0.16254850443300886, 0.17099873197346394, 0.17935749197098394, 0.18762478442556885, 0.19580060933721868, 0.2038849667059334, 0.21187785653171307, 0.2197792788145576, 0.2275892335544671, 0.2353077207514415, 0.24293474040548083, 0.25047029251658504, 0.2579143770847542, 0.2652669941099882, 0.2725281435922872, 0.27969782553165107, 0.2867760399280799, 0.2937627867815736, 0.30065806609213225, 0.3074618778597557, 0.3141742220844442, 0.32079509876619755, 0.3273245079050158, 0.333762449500899, 0.34010892355384714, 0.3463639300638601, 0.35252746903093807, 0.3585995404550809, 0.36458014433628866, 0.3704692806745614, 0.37626694946989897, 0.3819731507223015, 0.3875878844317689, 0.39311115059830126, 0.3985429492218985, 0.40388328030256065, 0.4091321438402877, 0.4142895398350797, 0.4193554682869366, 0.4243299291958584, 0.4292129225618452, 0.4340044483848969, 0.4387045066650134, 0.4433130974021948, 0.4478302205964412, 0.4522558762477525, 0.45659006435612876, 0.4608327849215699, 0.4649840379440759, 0.4690438234236469, 0.47301214136028275, 0.4768889917539835, 0.4806743746047492, 0.4843682899125799, 0.4879707376774754, 0.4914817178994358, 0.4949012305784613, 0.4982292757145515, 0.5014658533077067, 0.5046109633579267, 0.5076646058652117, 0.5106267808295617, 0.5134974882509765, 0.5162767281294562, 0.518964500465001, 0.5215608052576105, 0.524065642507285, 0.5264790122140244, 0.5288009143778287, 0.531031348998698, 0.5331703160766321, 0.5352178156116313, 0.5371738476036952, 0.5390384120528241, 0.5408115089590179, 0.5424931383222766, 0.5440833001426003, 0.5455819944199888, 0.5469892211544423, 0.5483049803459606, 0.549529271994544, 0.5506620961001921, 0.5517034526629053, 0.5526533416826834, 0.5535117631595262, 0.5542787170934341, 0.5549542034844069, 0.5555382223324447, 0.5560307736375473, 0.5564318573997148, 0.5567414736189472, 0.5569596222952445, 0.557086303428607, 0.5571215170190341, 0.5570652630665262, 0.5569175415710832, 0.5566783525327051, 0.556347695951392, 0.5559255718271436, 0.5554119801599603, 0.5548069209498419, 0.5541103941967883, 0.5533223999007997, 0.552442938061876, 0.5514720086800173, 0.5504096117552235, 0.5492557472874944, 0.5480104152768307, 0.5466736157232315, 0.5452453486266973, 0.543725613987228, 0.5421144118048237, 0.5404117420794842, 0.5386176048112096, 0.536732},
10720 {0.044372, 0.0540113055986112, 0.0635591436542873, 0.07301551416702834, 0.08238041713683428, 0.09165385256370512, 0.10083582044764089, 0.10992632078864159, 0.11892535358670717, 0.12783291884183767, 0.1366490165540331, 0.14537364672329345, 0.1540068093496187, 0.16254850443300886, 0.17099873197346394, 0.17935749197098394, 0.18762478442556885, 0.19580060933721868, 0.2038849667059334, 0.21187785653171307, 0.2197792788145576, 0.2275892335544671, 0.2353077207514415, 0.24293474040548083, 0.25047029251658504, 0.2579143770847542, 0.2652669941099882, 0.2725281435922872, 0.27969782553165107, 0.2867760399280799, 0.2937627867815736, 0.30065806609213225, 0.3074618778597557, 0.3141742220844442, 0.32079509876619755, 0.3273245079050158, 0.333762449500899, 0.34010892355384714, 0.3463639300638601, 0.35252746903093807, 0.3585995404550809, 0.36458014433628866, 0.3704692806745614, 0.37626694946989897, 0.3819731507223015, 0.3875878844317689, 0.39311115059830126, 0.3985429492218985, 0.40388328030256065, 0.4091321438402877, 0.4142895398350797, 0.4193554682869366, 0.4243299291958584, 0.4292129225618452, 0.4340044483848969, 0.4387045066650134, 0.4433130974021948, 0.4478302205964412, 0.4522558762477525, 0.45659006435612876, 0.4608327849215699, 0.4649840379440759, 0.4690438234236469, 0.47301214136028275, 0.4768889917539835, 0.4806743746047492, 0.4843682899125799, 0.4879707376774754, 0.4914817178994358, 0.4949012305784613, 0.4982292757145515, 0.5014658533077067, 0.5046109633579267, 0.5076646058652117, 0.5106267808295617, 0.5134974882509765, 0.5162767281294562, 0.518964500465001, 0.5215608052576105, 0.524065642507285, 0.5264790122140244, 0.5288009143778287, 0.531031348998698, 0.5331703160766321, 0.5352178156116313, 0.5371738476036952, 0.5390384120528241, 0.5408115089590179, 0.5424931383222766, 0.5440833001426003, 0.5455819944199888, 0.5469892211544423, 0.5483049803459606, 0.549529271994544, 0.5506620961001921, 0.5517034526629053, 0.5526533416826834, 0.5535117631595262, 0.5542787170934341, 0.5549542034844069, 0.5555382223324447, 0.5560307736375473, 0.5564318573997148, 0.5567414736189472, 0.5569596222952445, 0.557086303428607, 0.5571215170190341, 0.5570652630665262, 0.5569175415710832, 0.5566783525327051, 0.556347695951392, 0.5559255718271436, 0.5554119801599603, 0.5548069209498419, 0.5541103941967883, 0.5533223999007997, 0.552442938061876, 0.5514720086800173, 0.5504096117552235, 0.5492557472874944, 0.5480104152768307, 0.5466736157232315, 0.5452453486266973, 0.543725613987228, 0.5421144118048237, 0.5404117420794842, 0.5386176048112096, 0.536732},
10721 {0.99785, 0.9934904251968504, 0.9891308503937009, 0.9847712755905512, 0.9804117007874016, 0.976052125984252, 0.9716925511811024, 0.9673329763779528, 0.9629734015748032, 0.9586138267716535, 0.954254251968504, 0.9498946771653544, 0.9455351023622047, 0.9411755275590551, 0.9368159527559056, 0.9324563779527559, 0.9280968031496063, 0.9237372283464567, 0.9193776535433071, 0.9150180787401575, 0.9106585039370079, 0.9062989291338582, 0.9019393543307087, 0.8975797795275591, 0.8932202047244094, 0.8888606299212598, 0.8845010551181103, 0.8801414803149606, 0.875781905511811, 0.8714223307086615, 0.8670627559055119, 0.8627031811023622, 0.8583436062992126, 0.8539840314960631, 0.8496244566929134, 0.8452648818897638, 0.8409053070866142, 0.8365457322834646, 0.832186157480315, 0.8278265826771654, 0.8234670078740158, 0.8191074330708662, 0.8147478582677166, 0.8103882834645669, 0.8060287086614173, 0.8016691338582678, 0.7973095590551181, 0.7929499842519685, 0.788590409448819, 0.7842308346456693, 0.7798712598425197, 0.7755116850393701, 0.7711521102362204, 0.7667925354330709, 0.7624329606299213, 0.7580733858267716, 0.7537138110236221, 0.7493542362204725, 0.7449946614173228, 0.7406350866141733, 0.7362755118110236, 0.731915937007874, 0.7275563622047244, 0.7231967874015748, 0.7188372125984253, 0.7144776377952756, 0.710118062992126, 0.7057584881889765, 0.7013989133858267, 0.6970393385826772, 0.6926797637795276, 0.6883201889763779, 0.6839606141732284, 0.6796010393700788, 0.6752414645669291, 0.6708818897637796, 0.6665223149606299, 0.6621627401574803, 0.6578031653543307, 0.6534435905511811, 0.6490840157480315, 0.6447244409448819, 0.6403648661417323, 0.6360052913385827, 0.631645716535433, 0.6272861417322835, 0.622926566929134, 0.6185669921259842, 0.6142074173228347, 0.609847842519685, 0.6054882677165354, 0.6011286929133859, 0.5967691181102361, 0.5924095433070866, 0.5880499685039371, 0.5836903937007873, 0.5793308188976378, 0.5749712440944883, 0.5706116692913386, 0.566252094488189, 0.5618925196850394, 0.5575329448818898, 0.5531733700787402, 0.5488137952755906, 0.544454220472441, 0.5400946456692914, 0.5357350708661417, 0.5313754960629922, 0.5270159212598425, 0.5226563464566929, 0.5182967716535434, 0.5139371968503937, 0.5095776220472441, 0.5052180472440946, 0.500858472440945, 0.4964988976377953, 0.4921393228346457, 0.48777974803149604, 0.4834201732283465, 0.4790605984251969, 0.47470102362204725, 0.4703414488188977, 0.4659818740157481, 0.46162229921259845, 0.4572627244094488, 0.4529031496062992, 0.44854357480314966, 0.444184},
10722 {0.044372, 0.054437289850579704, 0.06441111215822432, 0.07429346692293384, 0.08408435414470829, 0.09378377382354765, 0.10339172595945192, 0.11290821055242112, 0.12233322760245521, 0.1316667771095542, 0.14090885907371814, 0.150059473494947, 0.15911862037324073, 0.16808629970859942, 0.176962511501023, 0.1857472557505115, 0.1944405324570649, 0.20304234162068327, 0.21155268324136647, 0.21997155731911466, 0.2282989638539277, 0.23653490284580572, 0.2446793742947486, 0.25273237820075645, 0.2606939145638291, 0.26856398338396675, 0.27634258466116934, 0.2840297183954368, 0.2916253845867692, 0.2991295832351665, 0.3065423143406287, 0.31386357790315583, 0.3210933739227479, 0.3282317023994048, 0.3352785633331267, 0.3422339567239135, 0.34909788257176516, 0.3558703408766818, 0.3625513316386633, 0.3691408548577098, 0.3756389105338211, 0.3820454986669974, 0.3883606192572386, 0.3945842723045447, 0.4007164578089156, 0.4067571757703516, 0.41270642618885245, 0.4185642090644182, 0.4243305243970488, 0.4300053721867444, 0.43558875243350487, 0.44108066513733035, 0.44648111029822063, 0.4517900879161758, 0.457007597991196, 0.46213364052328115, 0.46716821551243104, 0.4721113229586459, 0.4769629628619257, 0.48172313522227056, 0.4863918400396801, 0.4909690773141547, 0.4954548470456941, 0.4998491492342985, 0.5041519838799677, 0.508363350982702, 0.5124832505425011, 0.5165116825593651, 0.5204486470332941, 0.524294143964288, 0.5280481733523468, 0.5317107351974705, 0.535281829499659, 0.5387614562589126, 0.542149615475231, 0.5454463071486143, 0.5486515312790626, 0.5517652878665756, 0.5547875769111539, 0.5577183984127968, 0.5605577523715047, 0.5633056387872776, 0.5659620576601153, 0.568527008990018, 0.5710004927769856, 0.5733825090210181, 0.5756730577221155, 0.5778721388802778, 0.5799797524955049, 0.5819958985677972, 0.5839205770971542, 0.5857537880835761, 0.587495531527063, 0.5891458074276149, 0.5907046157852317, 0.5921719565999132, 0.5935478298716598, 0.5948322356004713, 0.5960251737863476, 0.597126644429289, 0.598136647529295, 0.5990551830863663, 0.5998822511005023, 0.6006178515717031, 0.601261984499969, 0.6018146498852998, 0.6022758477276954, 0.6026455780271561, 0.6029238407836814, 0.6031106359972721, 0.6032059636679274, 0.6032098237956476, 0.6031222163804327, 0.6029431414222828, 0.6026725989211977, 0.6023105888771778, 0.6018571112902225, 0.6013121661603325, 0.6006757534875071, 0.5999478732717465, 0.5991285255130511, 0.5982177102114203, 0.5972154273668548, 0.596121676979354, 0.594936459048918, 0.5936597735755472, 0.5922916205592411, 0.590832},
10723 {0.044372, 0.054437289850579704, 0.06441111215822432, 0.07429346692293384, 0.08408435414470829, 0.09378377382354765, 0.10339172595945192, 0.11290821055242112, 0.12233322760245521, 0.1316667771095542, 0.14090885907371814, 0.150059473494947, 0.15911862037324073, 0.16808629970859942, 0.176962511501023, 0.1857472557505115, 0.1944405324570649, 0.20304234162068327, 0.21155268324136647, 0.21997155731911466, 0.2282989638539277, 0.23653490284580572, 0.2446793742947486, 0.25273237820075645, 0.2606939145638291, 0.26856398338396675, 0.27634258466116934, 0.2840297183954368, 0.2916253845867692, 0.2991295832351665, 0.3065423143406287, 0.31386357790315583, 0.3210933739227479, 0.3282317023994048, 0.3352785633331267, 0.3422339567239135, 0.34909788257176516, 0.3558703408766818, 0.3625513316386633, 0.3691408548577098, 0.3756389105338211, 0.3820454986669974, 0.3883606192572386, 0.3945842723045447, 0.4007164578089156, 0.4067571757703516, 0.41270642618885245, 0.4185642090644182, 0.4243305243970488, 0.4300053721867444, 0.43558875243350487, 0.44108066513733035, 0.44648111029822063, 0.4517900879161758, 0.457007597991196, 0.46213364052328115, 0.46716821551243104, 0.4721113229586459, 0.4769629628619257, 0.48172313522227056, 0.4863918400396801, 0.4909690773141547, 0.4954548470456941, 0.4998491492342985, 0.5041519838799677, 0.508363350982702, 0.5124832505425011, 0.5165116825593651, 0.5204486470332941, 0.524294143964288, 0.5280481733523468, 0.5317107351974705, 0.535281829499659, 0.5387614562589126, 0.542149615475231, 0.5454463071486143, 0.5486515312790626, 0.5517652878665756, 0.5547875769111539, 0.5577183984127968, 0.5605577523715047, 0.5633056387872776, 0.5659620576601153, 0.568527008990018, 0.5710004927769856, 0.5733825090210181, 0.5756730577221155, 0.5778721388802778, 0.5799797524955049, 0.5819958985677972, 0.5839205770971542, 0.5857537880835761, 0.587495531527063, 0.5891458074276149, 0.5907046157852317, 0.5921719565999132, 0.5935478298716598, 0.5948322356004713, 0.5960251737863476, 0.597126644429289, 0.598136647529295, 0.5990551830863663, 0.5998822511005023, 0.6006178515717031, 0.601261984499969, 0.6018146498852998, 0.6022758477276954, 0.6026455780271561, 0.6029238407836814, 0.6031106359972721, 0.6032059636679274, 0.6032098237956476, 0.6031222163804327, 0.6029431414222828, 0.6026725989211977, 0.6023105888771778, 0.6018571112902225, 0.6013121661603325, 0.6006757534875071, 0.5999478732717465, 0.5991285255130511, 0.5982177102114203, 0.5972154273668548, 0.596121676979354, 0.594936459048918, 0.5936597735755472, 0.5922916205592411, 0.590832},
10724 {0.044372, 0.054437289850579704, 0.06441111215822432, 0.07429346692293384, 0.08408435414470829, 0.09378377382354765, 0.10339172595945192, 0.11290821055242112, 0.12233322760245521, 0.1316667771095542, 0.14090885907371814, 0.150059473494947, 0.15911862037324073, 0.16808629970859942, 0.176962511501023, 0.1857472557505115, 0.1944405324570649, 0.20304234162068327, 0.21155268324136647, 0.21997155731911466, 0.2282989638539277, 0.23653490284580572, 0.2446793742947486, 0.25273237820075645, 0.2606939145638291, 0.26856398338396675, 0.27634258466116934, 0.2840297183954368, 0.2916253845867692, 0.2991295832351665, 0.3065423143406287, 0.31386357790315583, 0.3210933739227479, 0.3282317023994048, 0.3352785633331267, 0.3422339567239135, 0.34909788257176516, 0.3558703408766818, 0.3625513316386633, 0.3691408548577098, 0.3756389105338211, 0.3820454986669974, 0.3883606192572386, 0.3945842723045447, 0.4007164578089156, 0.4067571757703516, 0.41270642618885245, 0.4185642090644182, 0.4243305243970488, 0.4300053721867444, 0.43558875243350487, 0.44108066513733035, 0.44648111029822063, 0.4517900879161758, 0.457007597991196, 0.46213364052328115, 0.46716821551243104, 0.4721113229586459, 0.4769629628619257, 0.48172313522227056, 0.4863918400396801, 0.4909690773141547, 0.4954548470456941, 0.4998491492342985, 0.5041519838799677, 0.508363350982702, 0.5124832505425011, 0.5165116825593651, 0.5204486470332941, 0.524294143964288, 0.5280481733523468, 0.5317107351974705, 0.535281829499659, 0.5387614562589126, 0.542149615475231, 0.5454463071486143, 0.5486515312790626, 0.5517652878665756, 0.5547875769111539, 0.5577183984127968, 0.5605577523715047, 0.5633056387872776, 0.5659620576601153, 0.568527008990018, 0.5710004927769856, 0.5733825090210181, 0.5756730577221155, 0.5778721388802778, 0.5799797524955049, 0.5819958985677972, 0.5839205770971542, 0.5857537880835761, 0.587495531527063, 0.5891458074276149, 0.5907046157852317, 0.5921719565999132, 0.5935478298716598, 0.5948322356004713, 0.5960251737863476, 0.597126644429289, 0.598136647529295, 0.5990551830863663, 0.5998822511005023, 0.6006178515717031, 0.601261984499969, 0.6018146498852998, 0.6022758477276954, 0.6026455780271561, 0.6029238407836814, 0.6031106359972721, 0.6032059636679274, 0.6032098237956476, 0.6031222163804327, 0.6029431414222828, 0.6026725989211977, 0.6023105888771778, 0.6018571112902225, 0.6013121661603325, 0.6006757534875071, 0.5999478732717465, 0.5991285255130511, 0.5982177102114203, 0.5972154273668548, 0.596121676979354, 0.594936459048918, 0.5936597735755472, 0.5922916205592411, 0.590832}
10725 };
10726
10727 /**************/
10728 /* SuperSaw object */
10729 /**************/
10730 typedef struct
10731 {
10732 pyo_audio_HEAD
10733 PyObject *freq;
10734 Stream *freq_stream;
10735 PyObject *detune;
10736 Stream *detune_stream;
10737 PyObject *bal;
10738 Stream *bal_stream;
10739 int modebuffer[5];
10740 double pointerPos[7];
10741 // sample memories
10742 MYFLT x1;
10743 MYFLT x2;
10744 MYFLT y1;
10745 MYFLT y2;
10746 // variables
10747 MYFLT c;
10748 MYFLT w0;
10749 MYFLT alpha;
10750 // coefficients
10751 MYFLT b0;
10752 MYFLT b1;
10753 MYFLT b2;
10754 MYFLT a0;
10755 MYFLT a1;
10756 MYFLT a2;
10757 MYFLT lastFilterFreq;
10758 MYFLT nyquist;
10759 } SuperSaw;
10760
10761 static void
10762 SuperSaw_readframes_iii(SuperSaw *self)
10763 {
10764 MYFLT fr, det, bal, twoOnSr, val;
10765 int i, j, det_ind, bal_ind;
10766 MYFLT inc[7];
10767 MYFLT amp[7];
10768
10769 fr = PyFloat_AS_DOUBLE(self->freq);
10770 det = _clip(PyFloat_AS_DOUBLE(self->detune));
10771 bal = _clip(PyFloat_AS_DOUBLE(self->bal));
10772 twoOnSr = 2.0 / self->sr;
10773
10774 if (fr <= 1.0)
10775 fr = 1.0;
10776 else if (fr >= self->nyquist)
10777 fr = self->nyquist;
10778
10779 det_ind = (int)(det * 126);
10780 bal_ind = (int)(bal * 126);
10781
10782 if (fr != self->lastFilterFreq)
10783 {
10784 self->lastFilterFreq = fr;
10785 self->w0 = TWOPI * fr / self->sr;
10786 self->c = MYCOS(self->w0);
10787 self->alpha = MYSIN(self->w0) * 0.5;
10788 self->b0 = self->b2 = (1 + self->c) * 0.5;
10789 self->b1 = -(1 + self->c);
10790 self->a0 = 1 + self->alpha;
10791 self->a1 = -2 * self->c;
10792 self->a2 = 1 - self->alpha;
10793 }
10794
10795 for (j = 0; j < 7; j++)
10796 {
10797 inc[j] = fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
10798 amp[j] = SUPERSAW_BALANCES[j][bal_ind];
10799 }
10800
10801 for (i = 0; i < self->bufsize; i++)
10802 {
10803 val = 0.0;
10804
10805 for (j = 0; j < 7; j++)
10806 {
10807 val += self->pointerPos[j] * amp[j];
10808 self->pointerPos[j] += inc[j];
10809
10810 if (self->pointerPos[j] < -1.0)
10811 self->pointerPos[j] += 2.0;
10812 else if (self->pointerPos[j] >= 1.0)
10813 self->pointerPos[j] -= 2.0;
10814 }
10815
10816 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
10817 self->y2 = self->y1;
10818 self->y1 = self->data[i];
10819 self->x2 = self->x1;
10820 self->x1 = val;
10821 self->data[i] *= 0.2;
10822 }
10823 }
10824
10825 static void
10826 SuperSaw_readframes_aii(SuperSaw *self)
10827 {
10828 MYFLT fr, det, bal, twoOnSr, val;
10829 int i, j, det_ind, bal_ind;
10830
10831 MYFLT *freq = Stream_getData((Stream *)self->freq_stream);
10832 det = _clip(PyFloat_AS_DOUBLE(self->detune));
10833 bal = _clip(PyFloat_AS_DOUBLE(self->bal));
10834 twoOnSr = 2.0 / self->sr;
10835
10836 det_ind = (int)(det * 126);
10837 bal_ind = (int)(bal * 126);
10838
10839 for (i = 0; i < self->bufsize; i++)
10840 {
10841 fr = freq[i];
10842
10843 if (fr <= 1.0)
10844 fr = 1.0;
10845 else if (fr >= self->nyquist)
10846 fr = self->nyquist;
10847
10848 if (fr != self->lastFilterFreq)
10849 {
10850 self->lastFilterFreq = fr;
10851 self->w0 = TWOPI * fr / self->sr;
10852 self->c = MYCOS(self->w0);
10853 self->alpha = MYSIN(self->w0) * 0.5;
10854 self->b0 = self->b2 = (1 + self->c) * 0.5;
10855 self->b1 = -(1 + self->c);
10856 self->a0 = 1 + self->alpha;
10857 self->a1 = -2 * self->c;
10858 self->a2 = 1 - self->alpha;
10859 }
10860
10861 val = 0.0;
10862
10863 for (j = 0; j < 7; j++)
10864 {
10865 val += self->pointerPos[j] * SUPERSAW_BALANCES[j][bal_ind];
10866 self->pointerPos[j] += fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
10867
10868 if (self->pointerPos[j] < -1.0)
10869 self->pointerPos[j] += 2.0;
10870 else if (self->pointerPos[j] >= 1.0)
10871 self->pointerPos[j] -= 2.0;
10872 }
10873
10874 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
10875 self->y2 = self->y1;
10876 self->y1 = self->data[i];
10877 self->x2 = self->x1;
10878 self->x1 = val;
10879 self->data[i] *= 0.2;
10880 }
10881 }
10882
10883 static void
10884 SuperSaw_readframes_iai(SuperSaw *self)
10885 {
10886 MYFLT fr, bal, twoOnSr, val;
10887 int i, j, det_ind, bal_ind;
10888
10889 fr = PyFloat_AS_DOUBLE(self->freq);
10890 MYFLT *detune = Stream_getData((Stream *)self->detune_stream);
10891 bal = _clip(PyFloat_AS_DOUBLE(self->bal));
10892 twoOnSr = 2.0 / self->sr;
10893
10894 if (fr <= 1.0)
10895 fr = 1.0;
10896 else if (fr >= self->nyquist)
10897 fr = self->nyquist;
10898
10899 bal_ind = (int)(bal * 126);
10900
10901 if (fr != self->lastFilterFreq)
10902 {
10903 self->lastFilterFreq = fr;
10904 self->w0 = TWOPI * fr / self->sr;
10905 self->c = MYCOS(self->w0);
10906 self->alpha = MYSIN(self->w0) * 0.5;
10907 self->b0 = self->b2 = (1 + self->c) * 0.5;
10908 self->b1 = -(1 + self->c);
10909 self->a0 = 1 + self->alpha;
10910 self->a1 = -2 * self->c;
10911 self->a2 = 1 - self->alpha;
10912 }
10913
10914 for (i = 0; i < self->bufsize; i++)
10915 {
10916 det_ind = (int)(_clip(detune[i]) * 126);
10917 val = 0.0;
10918
10919 for (j = 0; j < 7; j++)
10920 {
10921 val += self->pointerPos[j] * SUPERSAW_BALANCES[j][bal_ind];
10922 self->pointerPos[j] += fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
10923
10924 if (self->pointerPos[j] < -1.0)
10925 self->pointerPos[j] += 2.0;
10926 else if (self->pointerPos[j] >= 1.0)
10927 self->pointerPos[j] -= 2.0;
10928 }
10929
10930 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
10931 self->y2 = self->y1;
10932 self->y1 = self->data[i];
10933 self->x2 = self->x1;
10934 self->x1 = val;
10935 self->data[i] *= 0.2;
10936 }
10937 }
10938
10939 static void
10940 SuperSaw_readframes_aai(SuperSaw *self)
10941 {
10942 MYFLT fr, bal, twoOnSr, val;
10943 int i, j, det_ind, bal_ind;
10944
10945 MYFLT *freq = Stream_getData((Stream *)self->freq_stream);
10946 MYFLT *detune = Stream_getData((Stream *)self->detune_stream);
10947 bal = _clip(PyFloat_AS_DOUBLE(self->bal));
10948 twoOnSr = 2.0 / self->sr;
10949
10950 bal_ind = (int)(bal * 126);
10951
10952 for (i = 0; i < self->bufsize; i++)
10953 {
10954 fr = freq[i];
10955
10956 if (fr <= 1.0)
10957 fr = 1.0;
10958 else if (fr >= self->nyquist)
10959 fr = self->nyquist;
10960
10961 if (fr != self->lastFilterFreq)
10962 {
10963 self->lastFilterFreq = fr;
10964 self->w0 = TWOPI * fr / self->sr;
10965 self->c = MYCOS(self->w0);
10966 self->alpha = MYSIN(self->w0) * 0.5;
10967 self->b0 = self->b2 = (1 + self->c) * 0.5;
10968 self->b1 = -(1 + self->c);
10969 self->a0 = 1 + self->alpha;
10970 self->a1 = -2 * self->c;
10971 self->a2 = 1 - self->alpha;
10972 }
10973
10974 det_ind = (int)(_clip(detune[i]) * 126);
10975 val = 0.0;
10976
10977 for (j = 0; j < 7; j++)
10978 {
10979 val += self->pointerPos[j] * SUPERSAW_BALANCES[j][bal_ind];
10980 self->pointerPos[j] += fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
10981
10982 if (self->pointerPos[j] < -1.0)
10983 self->pointerPos[j] += 2.0;
10984 else if (self->pointerPos[j] >= 1.0)
10985 self->pointerPos[j] -= 2.0;
10986 }
10987
10988 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
10989 self->y2 = self->y1;
10990 self->y1 = self->data[i];
10991 self->x2 = self->x1;
10992 self->x1 = val;
10993 self->data[i] *= 0.2;
10994 }
10995 }
10996
10997 static void
10998 SuperSaw_readframes_iia(SuperSaw *self)
10999 {
11000 MYFLT fr, det, twoOnSr, val;
11001 int i, j, det_ind, bal_ind;
11002 MYFLT inc[7];
11003
11004 fr = PyFloat_AS_DOUBLE(self->freq);
11005 det = _clip(PyFloat_AS_DOUBLE(self->detune));
11006 MYFLT *balance = Stream_getData((Stream *)self->bal_stream);
11007 twoOnSr = 2.0 / self->sr;
11008
11009 if (fr <= 1.0)
11010 fr = 1.0;
11011 else if (fr >= self->nyquist)
11012 fr = self->nyquist;
11013
11014 det_ind = (int)(det * 126);
11015
11016 if (fr != self->lastFilterFreq)
11017 {
11018 self->lastFilterFreq = fr;
11019 self->w0 = TWOPI * fr / self->sr;
11020 self->c = MYCOS(self->w0);
11021 self->alpha = MYSIN(self->w0) * 0.5;
11022 self->b0 = self->b2 = (1 + self->c) * 0.5;
11023 self->b1 = -(1 + self->c);
11024 self->a0 = 1 + self->alpha;
11025 self->a1 = -2 * self->c;
11026 self->a2 = 1 - self->alpha;
11027 }
11028
11029 for (j = 0; j < 7; j++)
11030 {
11031 inc[j] = fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
11032 }
11033
11034 for (i = 0; i < self->bufsize; i++)
11035 {
11036 bal_ind = (int)(_clip(balance[i]) * 126);
11037 val = 0.0;
11038
11039 for (j = 0; j < 7; j++)
11040 {
11041 val += self->pointerPos[j] * SUPERSAW_BALANCES[j][bal_ind];
11042 self->pointerPos[j] += inc[j];
11043
11044 if (self->pointerPos[j] < -1.0)
11045 self->pointerPos[j] += 2.0;
11046 else if (self->pointerPos[j] >= 1.0)
11047 self->pointerPos[j] -= 2.0;
11048 }
11049
11050 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
11051 self->y2 = self->y1;
11052 self->y1 = self->data[i];
11053 self->x2 = self->x1;
11054 self->x1 = val;
11055 self->data[i] *= 0.2;
11056 }
11057 }
11058
11059 static void
11060 SuperSaw_readframes_aia(SuperSaw *self)
11061 {
11062 MYFLT fr, det, twoOnSr, val;
11063 int i, j, det_ind, bal_ind;
11064
11065 MYFLT *freq = Stream_getData((Stream *)self->freq_stream);
11066 det = _clip(PyFloat_AS_DOUBLE(self->detune));
11067 MYFLT *balance = Stream_getData((Stream *)self->bal_stream);
11068 twoOnSr = 2.0 / self->sr;
11069
11070 det_ind = (int)(det * 126);
11071
11072 for (i = 0; i < self->bufsize; i++)
11073 {
11074 fr = freq[i];
11075
11076 if (fr <= 1.0)
11077 fr = 1.0;
11078 else if (fr >= self->nyquist)
11079 fr = self->nyquist;
11080
11081 if (fr != self->lastFilterFreq)
11082 {
11083 self->lastFilterFreq = fr;
11084 self->w0 = TWOPI * fr / self->sr;
11085 self->c = MYCOS(self->w0);
11086 self->alpha = MYSIN(self->w0) * 0.5;
11087 self->b0 = self->b2 = (1 + self->c) * 0.5;
11088 self->b1 = -(1 + self->c);
11089 self->a0 = 1 + self->alpha;
11090 self->a1 = -2 * self->c;
11091 self->a2 = 1 - self->alpha;
11092 }
11093
11094 bal_ind = (int)(_clip(balance[i]) * 126);
11095 val = 0.0;
11096
11097 for (j = 0; j < 7; j++)
11098 {
11099 val += self->pointerPos[j] * SUPERSAW_BALANCES[j][bal_ind];
11100 self->pointerPos[j] += fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
11101
11102 if (self->pointerPos[j] < -1.0)
11103 self->pointerPos[j] += 2.0;
11104 else if (self->pointerPos[j] >= 1.0)
11105 self->pointerPos[j] -= 2.0;
11106 }
11107
11108 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
11109 self->y2 = self->y1;
11110 self->y1 = self->data[i];
11111 self->x2 = self->x1;
11112 self->x1 = val;
11113 self->data[i] *= 0.2;
11114 }
11115 }
11116
11117 static void
11118 SuperSaw_readframes_iaa(SuperSaw *self)
11119 {
11120 MYFLT fr, twoOnSr, val;
11121 int i, j, det_ind, bal_ind;
11122
11123 fr = PyFloat_AS_DOUBLE(self->freq);
11124 MYFLT *detune = Stream_getData((Stream *)self->detune_stream);
11125 MYFLT *balance = Stream_getData((Stream *)self->bal_stream);
11126 twoOnSr = 2.0 / self->sr;
11127
11128 if (fr <= 1.0)
11129 fr = 1.0;
11130 else if (fr >= self->nyquist)
11131 fr = self->nyquist;
11132
11133 if (fr != self->lastFilterFreq)
11134 {
11135 self->lastFilterFreq = fr;
11136 self->w0 = TWOPI * fr / self->sr;
11137 self->c = MYCOS(self->w0);
11138 self->alpha = MYSIN(self->w0) * 0.5;
11139 self->b0 = self->b2 = (1 + self->c) * 0.5;
11140 self->b1 = -(1 + self->c);
11141 self->a0 = 1 + self->alpha;
11142 self->a1 = -2 * self->c;
11143 self->a2 = 1 - self->alpha;
11144 }
11145
11146 for (i = 0; i < self->bufsize; i++)
11147 {
11148 det_ind = (int)(_clip(detune[i]) * 126);
11149 bal_ind = (int)(_clip(balance[i]) * 126);
11150 val = 0.0;
11151
11152 for (j = 0; j < 7; j++)
11153 {
11154 val += self->pointerPos[j] * SUPERSAW_BALANCES[j][bal_ind];
11155 self->pointerPos[j] += fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
11156
11157 if (self->pointerPos[j] < -1.0)
11158 self->pointerPos[j] += 2.0;
11159 else if (self->pointerPos[j] >= 1.0)
11160 self->pointerPos[j] -= 2.0;
11161 }
11162
11163 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
11164 self->y2 = self->y1;
11165 self->y1 = self->data[i];
11166 self->x2 = self->x1;
11167 self->x1 = val;
11168 self->data[i] *= 0.2;
11169 }
11170 }
11171
11172 static void
11173 SuperSaw_readframes_aaa(SuperSaw *self)
11174 {
11175 MYFLT fr, twoOnSr, val;
11176 int i, j, det_ind, bal_ind;
11177
11178 MYFLT *freq = Stream_getData((Stream *)self->freq_stream);
11179 MYFLT *detune = Stream_getData((Stream *)self->detune_stream);
11180 MYFLT *balance = Stream_getData((Stream *)self->bal_stream);
11181 twoOnSr = 2.0 / self->sr;
11182
11183 for (i = 0; i < self->bufsize; i++)
11184 {
11185 fr = freq[i];
11186
11187 if (fr <= 1.0)
11188 fr = 1.0;
11189 else if (fr >= self->nyquist)
11190 fr = self->nyquist;
11191
11192 if (fr != self->lastFilterFreq)
11193 {
11194 self->lastFilterFreq = fr;
11195 self->w0 = TWOPI * fr / self->sr;
11196 self->c = MYCOS(self->w0);
11197 self->alpha = MYSIN(self->w0) * 0.5;
11198 self->b0 = self->b2 = (1 + self->c) * 0.5;
11199 self->b1 = -(1 + self->c);
11200 self->a0 = 1 + self->alpha;
11201 self->a1 = -2 * self->c;
11202 self->a2 = 1 - self->alpha;
11203 }
11204
11205 det_ind = (int)(_clip(detune[i]) * 126);
11206 bal_ind = (int)(_clip(balance[i]) * 126);
11207
11208 val = 0.0;
11209
11210 for (j = 0; j < 7; j++)
11211 {
11212 val += self->pointerPos[j] * SUPERSAW_BALANCES[j][bal_ind];
11213 self->pointerPos[j] += fr * SUPERSAW_DETUNES[j][det_ind] * twoOnSr;
11214
11215 if (self->pointerPos[j] < -1.0)
11216 self->pointerPos[j] += 2.0;
11217 else if (self->pointerPos[j] >= 1.0)
11218 self->pointerPos[j] -= 2.0;
11219 }
11220
11221 self->data[i] = ( (self->b0 * val) + (self->b1 * self->x1) + (self->b2 * self->x2) - (self->a1 * self->y1) - (self->a2 * self->y2) ) / self->a0;
11222 self->y2 = self->y1;
11223 self->y1 = self->data[i];
11224 self->x2 = self->x1;
11225 self->x1 = val;
11226 self->data[i] *= 0.2;
11227 }
11228 }
11229
11230 static void SuperSaw_postprocessing_ii(SuperSaw *self) { POST_PROCESSING_II };
11231 static void SuperSaw_postprocessing_ai(SuperSaw *self) { POST_PROCESSING_AI };
11232 static void SuperSaw_postprocessing_ia(SuperSaw *self) { POST_PROCESSING_IA };
11233 static void SuperSaw_postprocessing_aa(SuperSaw *self) { POST_PROCESSING_AA };
11234 static void SuperSaw_postprocessing_ireva(SuperSaw *self) { POST_PROCESSING_IREVA };
11235 static void SuperSaw_postprocessing_areva(SuperSaw *self) { POST_PROCESSING_AREVA };
11236 static void SuperSaw_postprocessing_revai(SuperSaw *self) { POST_PROCESSING_REVAI };
11237 static void SuperSaw_postprocessing_revaa(SuperSaw *self) { POST_PROCESSING_REVAA };
11238 static void SuperSaw_postprocessing_revareva(SuperSaw *self) { POST_PROCESSING_REVAREVA };
11239
11240 static void
11241 SuperSaw_setProcMode(SuperSaw *self)
11242 {
11243 int procmode, muladdmode;
11244 procmode = self->modebuffer[2] + self->modebuffer[3] * 10 + self->modebuffer[4] * 100;
11245 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
11246
11247 switch (procmode)
11248 {
11249 case 0:
11250 self->proc_func_ptr = SuperSaw_readframes_iii;
11251 break;
11252
11253 case 1:
11254 self->proc_func_ptr = SuperSaw_readframes_aii;
11255 break;
11256
11257 case 10:
11258 self->proc_func_ptr = SuperSaw_readframes_iai;
11259 break;
11260
11261 case 11:
11262 self->proc_func_ptr = SuperSaw_readframes_aai;
11263 break;
11264
11265 case 100:
11266 self->proc_func_ptr = SuperSaw_readframes_iia;
11267 break;
11268
11269 case 101:
11270 self->proc_func_ptr = SuperSaw_readframes_aia;
11271 break;
11272
11273 case 110:
11274 self->proc_func_ptr = SuperSaw_readframes_iaa;
11275 break;
11276
11277 case 111:
11278 self->proc_func_ptr = SuperSaw_readframes_aaa;
11279 break;
11280 }
11281
11282 switch (muladdmode)
11283 {
11284 case 0:
11285 self->muladd_func_ptr = SuperSaw_postprocessing_ii;
11286 break;
11287
11288 case 1:
11289 self->muladd_func_ptr = SuperSaw_postprocessing_ai;
11290 break;
11291
11292 case 2:
11293 self->muladd_func_ptr = SuperSaw_postprocessing_revai;
11294 break;
11295
11296 case 10:
11297 self->muladd_func_ptr = SuperSaw_postprocessing_ia;
11298 break;
11299
11300 case 11:
11301 self->muladd_func_ptr = SuperSaw_postprocessing_aa;
11302 break;
11303
11304 case 12:
11305 self->muladd_func_ptr = SuperSaw_postprocessing_revaa;
11306 break;
11307
11308 case 20:
11309 self->muladd_func_ptr = SuperSaw_postprocessing_ireva;
11310 break;
11311
11312 case 21:
11313 self->muladd_func_ptr = SuperSaw_postprocessing_areva;
11314 break;
11315
11316 case 22:
11317 self->muladd_func_ptr = SuperSaw_postprocessing_revareva;
11318 break;
11319 }
11320 }
11321
11322 static void
11323 SuperSaw_compute_next_data_frame(SuperSaw *self)
11324 {
11325 (*self->proc_func_ptr)(self);
11326 (*self->muladd_func_ptr)(self);
11327 }
11328
11329 static int
11330 SuperSaw_traverse(SuperSaw *self, visitproc visit, void *arg)
11331 {
11332 pyo_VISIT
11333 Py_VISIT(self->freq);
11334 Py_VISIT(self->detune);
11335 Py_VISIT(self->bal);
11336 return 0;
11337 }
11338
11339 static int
11340 SuperSaw_clear(SuperSaw *self)
11341 {
11342 pyo_CLEAR
11343 Py_CLEAR(self->freq);
11344 Py_CLEAR(self->detune);
11345 Py_CLEAR(self->bal);
11346 return 0;
11347 }
11348
11349 static void
11350 SuperSaw_dealloc(SuperSaw* self)
11351 {
11352 pyo_DEALLOC
11353 SuperSaw_clear(self);
11354 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
11355 Py_TYPE(self)->tp_free((PyObject*)self);
11356 }
11357
11358 static PyObject *
11359 SuperSaw_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
11360 {
11361 int i;
11362 PyObject *freqtmp = NULL, *detunetmp = NULL, *baltmp = NULL, *multmp = NULL, *addtmp = NULL;
11363 SuperSaw *self;
11364 self = (SuperSaw *)type->tp_alloc(type, 0);
11365
11366 self->freq = PyFloat_FromDouble(100);
11367 self->detune = PyFloat_FromDouble(0.5);
11368 self->bal = PyFloat_FromDouble(0.7);
11369 self->modebuffer[0] = 0;
11370 self->modebuffer[1] = 0;
11371 self->modebuffer[2] = 0;
11372 self->modebuffer[3] = 0;
11373 self->modebuffer[4] = 0;
11374 self->pointerPos[0] = -0.75;
11375 self->pointerPos[1] = -0.5;
11376 self->pointerPos[2] = -0.25;
11377 self->pointerPos[3] = 0.0;
11378 self->pointerPos[4] = 0.25;
11379 self->pointerPos[5] = 0.5;
11380 self->pointerPos[6] = 0.75;
11381 self->lastFilterFreq = -1.0;
11382 self->x1 = self->x2 = self->y1 = self->y2 = 0.0;
11383
11384 INIT_OBJECT_COMMON
11385
11386 self->nyquist = (MYFLT)self->sr * 0.49;
11387
11388 Stream_setFunctionPtr(self->stream, SuperSaw_compute_next_data_frame);
11389 self->mode_func_ptr = SuperSaw_setProcMode;
11390
11391 static char *kwlist[] = {"freq", "detune", "bal", "mul", "add", NULL};
11392
11393 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOOO", kwlist, &freqtmp, &detunetmp, &baltmp, &multmp, &addtmp))
11394 Py_RETURN_NONE;
11395
11396 if (freqtmp)
11397 {
11398 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
11399 }
11400
11401 if (detunetmp)
11402 {
11403 PyObject_CallMethod((PyObject *)self, "setDetune", "O", detunetmp);
11404 }
11405
11406 if (baltmp)
11407 {
11408 PyObject_CallMethod((PyObject *)self, "setBal", "O", baltmp);
11409 }
11410
11411 if (multmp)
11412 {
11413 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
11414 }
11415
11416 if (addtmp)
11417 {
11418 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
11419 }
11420
11421 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
11422
11423 (*self->mode_func_ptr)(self);
11424
11425 return (PyObject *)self;
11426 }
11427
11428 static PyObject * SuperSaw_getServer(SuperSaw* self) { GET_SERVER };
11429 static PyObject * SuperSaw_getStream(SuperSaw* self) { GET_STREAM };
11430 static PyObject * SuperSaw_setMul(SuperSaw *self, PyObject *arg) { SET_MUL };
11431 static PyObject * SuperSaw_setAdd(SuperSaw *self, PyObject *arg) { SET_ADD };
11432 static PyObject * SuperSaw_setSub(SuperSaw *self, PyObject *arg) { SET_SUB };
11433 static PyObject * SuperSaw_setDiv(SuperSaw *self, PyObject *arg) { SET_DIV };
11434
11435 static PyObject * SuperSaw_play(SuperSaw *self, PyObject *args, PyObject *kwds) { PLAY };
11436 static PyObject * SuperSaw_out(SuperSaw *self, PyObject *args, PyObject *kwds) { OUT };
11437 static PyObject * SuperSaw_stop(SuperSaw *self, PyObject *args, PyObject *kwds) { STOP };
11438
11439 static PyObject * SuperSaw_multiply(SuperSaw *self, PyObject *arg) { MULTIPLY };
11440 static PyObject * SuperSaw_inplace_multiply(SuperSaw *self, PyObject *arg) { INPLACE_MULTIPLY };
11441 static PyObject * SuperSaw_add(SuperSaw *self, PyObject *arg) { ADD };
11442 static PyObject * SuperSaw_inplace_add(SuperSaw *self, PyObject *arg) { INPLACE_ADD };
11443 static PyObject * SuperSaw_sub(SuperSaw *self, PyObject *arg) { SUB };
11444 static PyObject * SuperSaw_inplace_sub(SuperSaw *self, PyObject *arg) { INPLACE_SUB };
11445 static PyObject * SuperSaw_div(SuperSaw *self, PyObject *arg) { DIV };
11446 static PyObject * SuperSaw_inplace_div(SuperSaw *self, PyObject *arg) { INPLACE_DIV };
11447
11448 static PyObject * SuperSaw_setFreq(SuperSaw *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
11449 static PyObject * SuperSaw_setDetune(SuperSaw *self, PyObject *arg) { SET_PARAM(self->detune, self->detune_stream, 3); }
11450 static PyObject * SuperSaw_setBal(SuperSaw *self, PyObject *arg) { SET_PARAM(self->bal, self->bal_stream, 4); }
11451
11452 static PyMemberDef SuperSaw_members[] =
11453 {
11454 {"server", T_OBJECT_EX, offsetof(SuperSaw, server), 0, "Pyo server."},
11455 {"stream", T_OBJECT_EX, offsetof(SuperSaw, stream), 0, "Stream object."},
11456 {"freq", T_OBJECT_EX, offsetof(SuperSaw, freq), 0, "Frequency in cycle per second."},
11457 {"detune", T_OBJECT_EX, offsetof(SuperSaw, detune), 0, "Detune factor."},
11458 {"bal", T_OBJECT_EX, offsetof(SuperSaw, bal), 0, "Mix factor."},
11459 {"mul", T_OBJECT_EX, offsetof(SuperSaw, mul), 0, "Mul factor."},
11460 {"add", T_OBJECT_EX, offsetof(SuperSaw, add), 0, "Add factor."},
11461 {NULL} /* Sentinel */
11462 };
11463
11464 static PyMethodDef SuperSaw_methods[] =
11465 {
11466 {"getServer", (PyCFunction)SuperSaw_getServer, METH_NOARGS, "Returns server object."},
11467 {"_getStream", (PyCFunction)SuperSaw_getStream, METH_NOARGS, "Returns stream object."},
11468 {"play", (PyCFunction)SuperSaw_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
11469 {"out", (PyCFunction)SuperSaw_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
11470 {"stop", (PyCFunction)SuperSaw_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
11471 {"setFreq", (PyCFunction)SuperSaw_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
11472 {"setDetune", (PyCFunction)SuperSaw_setDetune, METH_O, "Sets oscillator detune factor."},
11473 {"setBal", (PyCFunction)SuperSaw_setBal, METH_O, "Sets oscillator mix factor."},
11474 {"setMul", (PyCFunction)SuperSaw_setMul, METH_O, "Sets oscillator mul factor."},
11475 {"setAdd", (PyCFunction)SuperSaw_setAdd, METH_O, "Sets oscillator add factor."},
11476 {"setSub", (PyCFunction)SuperSaw_setSub, METH_O, "Sets oscillator inverse add factor."},
11477 {"setDiv", (PyCFunction)SuperSaw_setDiv, METH_O, "Sets inverse mul factor."},
11478 {NULL} /* Sentinel */
11479 };
11480
11481 static PyNumberMethods SuperSaw_as_number =
11482 {
11483 (binaryfunc)SuperSaw_add, /*nb_add*/
11484 (binaryfunc)SuperSaw_sub, /*nb_subtract*/
11485 (binaryfunc)SuperSaw_multiply, /*nb_multiply*/
11486 0, /*nb_remainder*/
11487 0, /*nb_divmod*/
11488 0, /*nb_power*/
11489 0, /*nb_neg*/
11490 0, /*nb_pos*/
11491 0, /*(unaryfunc)array_abs,*/
11492 0, /*nb_nonzero*/
11493 0, /*nb_invert*/
11494 0, /*nb_lshift*/
11495 0, /*nb_rshift*/
11496 0, /*nb_and*/
11497 0, /*nb_xor*/
11498 0, /*nb_or*/
11499 0, /*nb_int*/
11500 0, /*nb_long*/
11501 0, /*nb_float*/
11502 (binaryfunc)SuperSaw_inplace_add, /*inplace_add*/
11503 (binaryfunc)SuperSaw_inplace_sub, /*inplace_subtract*/
11504 (binaryfunc)SuperSaw_inplace_multiply, /*inplace_multiply*/
11505 0, /*inplace_remainder*/
11506 0, /*inplace_power*/
11507 0, /*inplace_lshift*/
11508 0, /*inplace_rshift*/
11509 0, /*inplace_and*/
11510 0, /*inplace_xor*/
11511 0, /*inplace_or*/
11512 0, /*nb_floor_divide*/
11513 (binaryfunc)SuperSaw_div, /*nb_true_divide*/
11514 0, /*nb_inplace_floor_divide*/
11515 (binaryfunc)SuperSaw_inplace_div, /*nb_inplace_true_divide*/
11516 0, /* nb_index */
11517 };
11518
11519 PyTypeObject SuperSawType =
11520 {
11521 PyVarObject_HEAD_INIT(NULL, 0)
11522 "_pyo.SuperSaw_base", /*tp_name*/
11523 sizeof(SuperSaw), /*tp_basicsize*/
11524 0, /*tp_itemsize*/
11525 (destructor)SuperSaw_dealloc, /*tp_dealloc*/
11526 0, /*tp_print*/
11527 0, /*tp_getattr*/
11528 0, /*tp_setattr*/
11529 0, /*tp_as_async (tp_compare in Python 2)*/
11530 0, /*tp_repr*/
11531 &SuperSaw_as_number, /*tp_as_number*/
11532 0, /*tp_as_sequence*/
11533 0, /*tp_as_mapping*/
11534 0, /*tp_hash */
11535 0, /*tp_call*/
11536 0, /*tp_str*/
11537 0, /*tp_getattro*/
11538 0, /*tp_setattro*/
11539 0, /*tp_as_buffer*/
11540 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
11541 "SuperSaw objects. detune incrementor from 0 to 1.", /* tp_doc */
11542 (traverseproc)SuperSaw_traverse, /* tp_traverse */
11543 (inquiry)SuperSaw_clear, /* tp_clear */
11544 0, /* tp_richcompare */
11545 0, /* tp_weaklistoffset */
11546 0, /* tp_iter */
11547 0, /* tp_iternext */
11548 SuperSaw_methods, /* tp_methods */
11549 SuperSaw_members, /* tp_members */
11550 0, /* tp_getset */
11551 0, /* tp_base */
11552 0, /* tp_dict */
11553 0, /* tp_descr_get */
11554 0, /* tp_descr_set */
11555 0, /* tp_dictoffset */
11556 0, /* tp_init */
11557 0, /* tp_alloc */
11558 SuperSaw_new, /* tp_new */
11559 };
11560
11561 /**************/
11562 /* RCOsc object */
11563 /**************/
11564 typedef struct
11565 {
11566 pyo_audio_HEAD
11567 PyObject *freq;
11568 Stream *freq_stream;
11569 PyObject *sharp;
11570 Stream *sharp_stream;
11571 int modebuffer[4];
11572 MYFLT pointerPos;
11573 } RCOsc;
11574
11575 static void
11576 RCOsc_readframes_ii(RCOsc *self)
11577 {
11578 MYFLT fr, sh, inc, down_phase, up_phase;
11579 int i;
11580
11581 fr = PyFloat_AS_DOUBLE(self->freq);
11582 sh = _clip(PyFloat_AS_DOUBLE(self->sharp));
11583 sh = sh * sh * 99.0 + 1.0;
11584 inc = fr * 2 / self->sr;
11585
11586 for (i = 0; i < self->bufsize; i++)
11587 {
11588 if (self->pointerPos < 1)
11589 {
11590 down_phase = 1.0 - self->pointerPos;
11591 up_phase = 1.0;
11592 }
11593 else
11594 {
11595 down_phase = 0.0;
11596 up_phase = 2.0 - self->pointerPos;
11597 }
11598
11599 self->data[i] = ( (1.0 - MYPOW(down_phase, sh)) + (MYPOW(up_phase, sh)) ) * 2.0 - 3.0;
11600 self->pointerPos += inc;
11601
11602 if (self->pointerPos < 0)
11603 self->pointerPos += 2.0;
11604 else if (self->pointerPos >= 2)
11605 self->pointerPos -= 2.0;
11606 }
11607 }
11608
11609 static void
11610 RCOsc_readframes_ai(RCOsc *self)
11611 {
11612 MYFLT sh, down_phase, up_phase, twoOverSr;
11613 int i;
11614
11615 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
11616 sh = _clip(PyFloat_AS_DOUBLE(self->sharp));
11617 sh = sh * sh * 99.0 + 1.0;
11618
11619 twoOverSr = 2.0 / self->sr;
11620
11621 for (i = 0; i < self->bufsize; i++)
11622 {
11623 if (self->pointerPos < 1)
11624 {
11625 down_phase = 1.0 - self->pointerPos;
11626 up_phase = 1.0;
11627 }
11628 else
11629 {
11630 down_phase = 0.0;
11631 up_phase = 2.0 - self->pointerPos;
11632 }
11633
11634 self->data[i] = ( (1.0 - MYPOW(down_phase, sh)) + (MYPOW(up_phase, sh)) ) * 2.0 - 3.0;
11635 self->pointerPos += fr[i] * twoOverSr;
11636
11637 if (self->pointerPos < 0)
11638 self->pointerPos += 2.0;
11639 else if (self->pointerPos >= 2)
11640 self->pointerPos -= 2.0;
11641 }
11642 }
11643
11644 static void
11645 RCOsc_readframes_ia(RCOsc *self)
11646 {
11647 MYFLT fr, sh, inc, down_phase, up_phase;
11648 int i;
11649
11650 fr = PyFloat_AS_DOUBLE(self->freq);
11651 MYFLT *sharp = Stream_getData((Stream *)self->sharp_stream);
11652 inc = fr * 2 / self->sr;
11653
11654 for (i = 0; i < self->bufsize; i++)
11655 {
11656 sh = _clip(sharp[i]);
11657 sh = sh * sh * 99.0 + 1.0;
11658
11659 if (self->pointerPos < 1)
11660 {
11661 down_phase = 1.0 - self->pointerPos;
11662 up_phase = 1.0;
11663 }
11664 else
11665 {
11666 down_phase = 0.0;
11667 up_phase = 2.0 - self->pointerPos;
11668 }
11669
11670 self->data[i] = ( (1.0 - MYPOW(down_phase, sh)) + (MYPOW(up_phase, sh)) ) * 2.0 - 3.0;
11671 self->pointerPos += inc;
11672
11673 if (self->pointerPos < 0)
11674 self->pointerPos += 2.0;
11675 else if (self->pointerPos >= 2)
11676 self->pointerPos -= 2.0;
11677 }
11678 }
11679
11680 static void
11681 RCOsc_readframes_aa(RCOsc *self)
11682 {
11683 MYFLT sh, down_phase, up_phase, twoOverSr;
11684 int i;
11685
11686 MYFLT *fr = Stream_getData((Stream *)self->freq_stream);
11687 MYFLT *sharp = Stream_getData((Stream *)self->sharp_stream);
11688
11689 twoOverSr = 2.0 / self->sr;
11690
11691 for (i = 0; i < self->bufsize; i++)
11692 {
11693 sh = _clip(sharp[i]);
11694 sh = sh * sh * 99.0 + 1.0;
11695
11696 if (self->pointerPos < 1)
11697 {
11698 down_phase = 1.0 - self->pointerPos;
11699 up_phase = 1.0;
11700 }
11701 else
11702 {
11703 down_phase = 0.0;
11704 up_phase = 2.0 - self->pointerPos;
11705 }
11706
11707 self->data[i] = ( (1.0 - MYPOW(down_phase, sh)) + (MYPOW(up_phase, sh)) ) * 2.0 - 3.0;
11708 self->pointerPos += fr[i] * twoOverSr;
11709
11710 if (self->pointerPos < 0)
11711 self->pointerPos += 2.0;
11712 else if (self->pointerPos >= 2)
11713 self->pointerPos -= 2.0;
11714 }
11715 }
11716
11717 static void RCOsc_postprocessing_ii(RCOsc *self) { POST_PROCESSING_II };
11718 static void RCOsc_postprocessing_ai(RCOsc *self) { POST_PROCESSING_AI };
11719 static void RCOsc_postprocessing_ia(RCOsc *self) { POST_PROCESSING_IA };
11720 static void RCOsc_postprocessing_aa(RCOsc *self) { POST_PROCESSING_AA };
11721 static void RCOsc_postprocessing_ireva(RCOsc *self) { POST_PROCESSING_IREVA };
11722 static void RCOsc_postprocessing_areva(RCOsc *self) { POST_PROCESSING_AREVA };
11723 static void RCOsc_postprocessing_revai(RCOsc *self) { POST_PROCESSING_REVAI };
11724 static void RCOsc_postprocessing_revaa(RCOsc *self) { POST_PROCESSING_REVAA };
11725 static void RCOsc_postprocessing_revareva(RCOsc *self) { POST_PROCESSING_REVAREVA };
11726
11727 static void
11728 RCOsc_setProcMode(RCOsc *self)
11729 {
11730 int procmode, muladdmode;
11731 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
11732 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
11733
11734 switch (procmode)
11735 {
11736 case 0:
11737 self->proc_func_ptr = RCOsc_readframes_ii;
11738 break;
11739
11740 case 1:
11741 self->proc_func_ptr = RCOsc_readframes_ai;
11742 break;
11743
11744 case 10:
11745 self->proc_func_ptr = RCOsc_readframes_ia;
11746 break;
11747
11748 case 11:
11749 self->proc_func_ptr = RCOsc_readframes_aa;
11750 break;
11751 }
11752
11753 switch (muladdmode)
11754 {
11755 case 0:
11756 self->muladd_func_ptr = RCOsc_postprocessing_ii;
11757 break;
11758
11759 case 1:
11760 self->muladd_func_ptr = RCOsc_postprocessing_ai;
11761 break;
11762
11763 case 2:
11764 self->muladd_func_ptr = RCOsc_postprocessing_revai;
11765 break;
11766
11767 case 10:
11768 self->muladd_func_ptr = RCOsc_postprocessing_ia;
11769 break;
11770
11771 case 11:
11772 self->muladd_func_ptr = RCOsc_postprocessing_aa;
11773 break;
11774
11775 case 12:
11776 self->muladd_func_ptr = RCOsc_postprocessing_revaa;
11777 break;
11778
11779 case 20:
11780 self->muladd_func_ptr = RCOsc_postprocessing_ireva;
11781 break;
11782
11783 case 21:
11784 self->muladd_func_ptr = RCOsc_postprocessing_areva;
11785 break;
11786
11787 case 22:
11788 self->muladd_func_ptr = RCOsc_postprocessing_revareva;
11789 break;
11790 }
11791 }
11792
11793 static void
11794 RCOsc_compute_next_data_frame(RCOsc *self)
11795 {
11796 (*self->proc_func_ptr)(self);
11797 (*self->muladd_func_ptr)(self);
11798 }
11799
11800 static int
11801 RCOsc_traverse(RCOsc *self, visitproc visit, void *arg)
11802 {
11803 pyo_VISIT
11804 Py_VISIT(self->sharp);
11805 Py_VISIT(self->freq);
11806 return 0;
11807 }
11808
11809 static int
11810 RCOsc_clear(RCOsc *self)
11811 {
11812 pyo_CLEAR
11813 Py_CLEAR(self->sharp);
11814 Py_CLEAR(self->freq);
11815 return 0;
11816 }
11817
11818 static void
11819 RCOsc_dealloc(RCOsc* self)
11820 {
11821 pyo_DEALLOC
11822 RCOsc_clear(self);
11823 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
11824 Py_TYPE(self)->tp_free((PyObject*)self);
11825 }
11826
11827 static PyObject *
11828 RCOsc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
11829 {
11830 int i;
11831 PyObject *freqtmp = NULL, *sharptmp = NULL, *multmp = NULL, *addtmp = NULL;
11832 RCOsc *self;
11833 self = (RCOsc *)type->tp_alloc(type, 0);
11834
11835 self->freq = PyFloat_FromDouble(100);
11836 self->sharp = PyFloat_FromDouble(0.25);
11837 self->modebuffer[0] = 0;
11838 self->modebuffer[1] = 0;
11839 self->modebuffer[2] = 0;
11840 self->modebuffer[3] = 0;
11841 self->pointerPos = 0.;
11842
11843 INIT_OBJECT_COMMON
11844 Stream_setFunctionPtr(self->stream, RCOsc_compute_next_data_frame);
11845 self->mode_func_ptr = RCOsc_setProcMode;
11846
11847 static char *kwlist[] = {"freq", "sharp", "mul", "add", NULL};
11848
11849 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist, &freqtmp, &sharptmp, &multmp, &addtmp))
11850 Py_RETURN_NONE;
11851
11852 if (freqtmp)
11853 {
11854 PyObject_CallMethod((PyObject *)self, "setFreq", "O", freqtmp);
11855 }
11856
11857 if (sharptmp)
11858 {
11859 PyObject_CallMethod((PyObject *)self, "setSharp", "O", sharptmp);
11860 }
11861
11862 if (multmp)
11863 {
11864 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
11865 }
11866
11867 if (addtmp)
11868 {
11869 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
11870 }
11871
11872 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
11873
11874 (*self->mode_func_ptr)(self);
11875
11876 return (PyObject *)self;
11877 }
11878
11879 static PyObject * RCOsc_getServer(RCOsc* self) { GET_SERVER };
11880 static PyObject * RCOsc_getStream(RCOsc* self) { GET_STREAM };
11881 static PyObject * RCOsc_setMul(RCOsc *self, PyObject *arg) { SET_MUL };
11882 static PyObject * RCOsc_setAdd(RCOsc *self, PyObject *arg) { SET_ADD };
11883 static PyObject * RCOsc_setSub(RCOsc *self, PyObject *arg) { SET_SUB };
11884 static PyObject * RCOsc_setDiv(RCOsc *self, PyObject *arg) { SET_DIV };
11885
11886 static PyObject * RCOsc_play(RCOsc *self, PyObject *args, PyObject *kwds) { PLAY };
11887 static PyObject * RCOsc_out(RCOsc *self, PyObject *args, PyObject *kwds) { OUT };
11888 static PyObject * RCOsc_stop(RCOsc *self, PyObject *args, PyObject *kwds) { STOP };
11889
11890 static PyObject * RCOsc_multiply(RCOsc *self, PyObject *arg) { MULTIPLY };
11891 static PyObject * RCOsc_inplace_multiply(RCOsc *self, PyObject *arg) { INPLACE_MULTIPLY };
11892 static PyObject * RCOsc_add(RCOsc *self, PyObject *arg) { ADD };
11893 static PyObject * RCOsc_inplace_add(RCOsc *self, PyObject *arg) { INPLACE_ADD };
11894 static PyObject * RCOsc_sub(RCOsc *self, PyObject *arg) { SUB };
11895 static PyObject * RCOsc_inplace_sub(RCOsc *self, PyObject *arg) { INPLACE_SUB };
11896 static PyObject * RCOsc_div(RCOsc *self, PyObject *arg) { DIV };
11897 static PyObject * RCOsc_inplace_div(RCOsc *self, PyObject *arg) { INPLACE_DIV };
11898
11899 static PyObject * RCOsc_setFreq(RCOsc *self, PyObject *arg) { SET_PARAM(self->freq, self->freq_stream, 2); }
11900 static PyObject * RCOsc_setSharp(RCOsc *self, PyObject *arg) { SET_PARAM(self->sharp, self->sharp_stream, 3); }
11901
11902 static PyObject *
11903 RCOsc_reset(RCOsc *self)
11904 {
11905 self->pointerPos = 0.0;
11906 Py_RETURN_NONE;
11907 }
11908
11909 static PyMemberDef RCOsc_members[] =
11910 {
11911 {"server", T_OBJECT_EX, offsetof(RCOsc, server), 0, "Pyo server."},
11912 {"stream", T_OBJECT_EX, offsetof(RCOsc, stream), 0, "Stream object."},
11913 {"freq", T_OBJECT_EX, offsetof(RCOsc, freq), 0, "Frequency in cycle per second."},
11914 {"sharp", T_OBJECT_EX, offsetof(RCOsc, sharp), 0, "RCOscillator sharp."},
11915 {"mul", T_OBJECT_EX, offsetof(RCOsc, mul), 0, "Mul factor."},
11916 {"add", T_OBJECT_EX, offsetof(RCOsc, add), 0, "Add factor."},
11917 {NULL} /* Sentinel */
11918 };
11919
11920 static PyMethodDef RCOsc_methods[] =
11921 {
11922 {"getServer", (PyCFunction)RCOsc_getServer, METH_NOARGS, "Returns server object."},
11923 {"_getStream", (PyCFunction)RCOsc_getStream, METH_NOARGS, "Returns stream object."},
11924 {"play", (PyCFunction)RCOsc_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
11925 {"out", (PyCFunction)RCOsc_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
11926 {"stop", (PyCFunction)RCOsc_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
11927 {"setFreq", (PyCFunction)RCOsc_setFreq, METH_O, "Sets oscillator frequency in cycle per second."},
11928 {"setSharp", (PyCFunction)RCOsc_setSharp, METH_O, "Sets oscillator sharp."},
11929 {"reset", (PyCFunction)RCOsc_reset, METH_NOARGS, "Resets pointer position to 0."},
11930 {"setMul", (PyCFunction)RCOsc_setMul, METH_O, "Sets oscillator mul factor."},
11931 {"setAdd", (PyCFunction)RCOsc_setAdd, METH_O, "Sets oscillator add factor."},
11932 {"setSub", (PyCFunction)RCOsc_setSub, METH_O, "Sets oscillator inverse add factor."},
11933 {"setDiv", (PyCFunction)RCOsc_setDiv, METH_O, "Sets inverse mul factor."},
11934 {NULL} /* Sentinel */
11935 };
11936
11937 static PyNumberMethods RCOsc_as_number =
11938 {
11939 (binaryfunc)RCOsc_add, /*nb_add*/
11940 (binaryfunc)RCOsc_sub, /*nb_subtract*/
11941 (binaryfunc)RCOsc_multiply, /*nb_multiply*/
11942 0, /*nb_remainder*/
11943 0, /*nb_divmod*/
11944 0, /*nb_power*/
11945 0, /*nb_neg*/
11946 0, /*nb_pos*/
11947 0, /*(unaryfunc)array_abs,*/
11948 0, /*nb_nonzero*/
11949 0, /*nb_invert*/
11950 0, /*nb_lshift*/
11951 0, /*nb_rshift*/
11952 0, /*nb_and*/
11953 0, /*nb_xor*/
11954 0, /*nb_or*/
11955 0, /*nb_int*/
11956 0, /*nb_long*/
11957 0, /*nb_float*/
11958 (binaryfunc)RCOsc_inplace_add, /*inplace_add*/
11959 (binaryfunc)RCOsc_inplace_sub, /*inplace_subtract*/
11960 (binaryfunc)RCOsc_inplace_multiply, /*inplace_multiply*/
11961 0, /*inplace_remainder*/
11962 0, /*inplace_power*/
11963 0, /*inplace_lshift*/
11964 0, /*inplace_rshift*/
11965 0, /*inplace_and*/
11966 0, /*inplace_xor*/
11967 0, /*inplace_or*/
11968 0, /*nb_floor_divide*/
11969 (binaryfunc)RCOsc_div, /*nb_true_divide*/
11970 0, /*nb_inplace_floor_divide*/
11971 (binaryfunc)RCOsc_inplace_div, /*nb_inplace_true_divide*/
11972 0, /* nb_index */
11973 };
11974
11975 PyTypeObject RCOscType =
11976 {
11977 PyVarObject_HEAD_INIT(NULL, 0)
11978 "_pyo.RCOsc_base", /*tp_name*/
11979 sizeof(RCOsc), /*tp_basicsize*/
11980 0, /*tp_itemsize*/
11981 (destructor)RCOsc_dealloc, /*tp_dealloc*/
11982 0, /*tp_print*/
11983 0, /*tp_getattr*/
11984 0, /*tp_setattr*/
11985 0, /*tp_as_async (tp_compare in Python 2)*/
11986 0, /*tp_repr*/
11987 &RCOsc_as_number, /*tp_as_number*/
11988 0, /*tp_as_sequence*/
11989 0, /*tp_as_mapping*/
11990 0, /*tp_hash */
11991 0, /*tp_call*/
11992 0, /*tp_str*/
11993 0, /*tp_getattro*/
11994 0, /*tp_setattro*/
11995 0, /*tp_as_buffer*/
11996 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
11997 "RCOsc objects. Waveform simulation of of a RC circuit.", /* tp_doc */
11998 (traverseproc)RCOsc_traverse, /* tp_traverse */
11999 (inquiry)RCOsc_clear, /* tp_clear */
12000 0, /* tp_richcompare */
12001 0, /* tp_weaklistoffset */
12002 0, /* tp_iter */
12003 0, /* tp_iternext */
12004 RCOsc_methods, /* tp_methods */
12005 RCOsc_members, /* tp_members */
12006 0, /* tp_getset */
12007 0, /* tp_base */
12008 0, /* tp_dict */
12009 0, /* tp_descr_get */
12010 0, /* tp_descr_set */
12011 0, /* tp_dictoffset */
12012 0, /* tp_init */
12013 0, /* tp_alloc */
12014 RCOsc_new, /* tp_new */
12015 };
12016
12017 /**************/
12018 /* TableScale object */
12019 /**************/
12020 typedef struct
12021 {
12022 pyo_audio_HEAD
12023 PyObject *table;
12024 PyObject *outtable;
12025 int modebuffer[2];
12026 } TableScale;
12027
12028 static void
12029 TableScale_readframes_ii(TableScale *self)
12030 {
12031 T_SIZE_T i, num;
12032 MYFLT mul, add;
12033 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
12034 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
12035 MYFLT *outlist = TableStream_getData((TableStream *)self->outtable);
12036 T_SIZE_T osize = TableStream_getSize((TableStream *)self->outtable);
12037
12038 mul = PyFloat_AS_DOUBLE(self->mul);
12039 add = PyFloat_AS_DOUBLE(self->add);
12040
12041 num = size < osize ? size : osize;
12042
12043 for (i = 0; i < num; i++)
12044 {
12045 outlist[i] = tablelist[i] * mul + add;
12046 }
12047 }
12048
12049 static void
12050 TableScale_readframes_ai(TableScale *self)
12051 {
12052 T_SIZE_T i, num;
12053 MYFLT add;
12054 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
12055 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
12056 MYFLT *outlist = TableStream_getData((TableStream *)self->outtable);
12057 T_SIZE_T osize = TableStream_getSize((TableStream *)self->outtable);
12058
12059 MYFLT *mul = Stream_getData((Stream *)self->mul_stream);
12060 add = PyFloat_AS_DOUBLE(self->add);
12061
12062 num = size < osize ? size : osize;
12063
12064 for (i = 0; i < num; i++)
12065 {
12066 outlist[i] = tablelist[i] * mul[i] + add;
12067 }
12068 }
12069
12070 static void
12071 TableScale_readframes_ia(TableScale *self)
12072 {
12073 T_SIZE_T i, num;
12074 MYFLT mul;
12075 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
12076 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
12077 MYFLT *outlist = TableStream_getData((TableStream *)self->outtable);
12078 T_SIZE_T osize = TableStream_getSize((TableStream *)self->outtable);
12079
12080 mul = PyFloat_AS_DOUBLE(self->mul);
12081 MYFLT *add = Stream_getData((Stream *)self->add_stream);
12082
12083 num = size < osize ? size : osize;
12084
12085 for (i = 0; i < num; i++)
12086 {
12087 outlist[i] = tablelist[i] * mul + add[i];
12088 }
12089 }
12090
12091 static void
12092 TableScale_readframes_aa(TableScale *self)
12093 {
12094 T_SIZE_T i, num;
12095 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
12096 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
12097 MYFLT *outlist = TableStream_getData((TableStream *)self->outtable);
12098 T_SIZE_T osize = TableStream_getSize((TableStream *)self->outtable);
12099
12100 MYFLT *mul = Stream_getData((Stream *)self->mul_stream);
12101 MYFLT *add = Stream_getData((Stream *)self->add_stream);
12102
12103 num = size < osize ? size : osize;
12104
12105 for (i = 0; i < num; i++)
12106 {
12107 outlist[i] = tablelist[i] * mul[i] + add[i];
12108 }
12109 }
12110
12111 static void
12112 TableScale_setProcMode(TableScale *self)
12113 {
12114 int muladdmode;
12115 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
12116
12117 switch (muladdmode)
12118 {
12119 case 0:
12120 self->proc_func_ptr = TableScale_readframes_ii;
12121 break;
12122
12123 case 1:
12124 self->proc_func_ptr = TableScale_readframes_ai;
12125 break;
12126
12127 case 10:
12128 self->proc_func_ptr = TableScale_readframes_ia;
12129 break;
12130
12131 case 11:
12132 self->proc_func_ptr = TableScale_readframes_aa;
12133 break;
12134 }
12135 }
12136
12137 static void
12138 TableScale_compute_next_data_frame(TableScale *self)
12139 {
12140 (*self->proc_func_ptr)(self);
12141 }
12142
12143 static int
12144 TableScale_traverse(TableScale *self, visitproc visit, void *arg)
12145 {
12146 pyo_VISIT
12147 return 0;
12148 }
12149
12150 static int
12151 TableScale_clear(TableScale *self)
12152 {
12153 pyo_CLEAR
12154 return 0;
12155 }
12156
12157 static void
12158 TableScale_dealloc(TableScale* self)
12159 {
12160 pyo_DEALLOC
12161 TableScale_clear(self);
12162 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
12163 Py_TYPE(self)->tp_free((PyObject*)self);
12164 }
12165
12166 static PyObject *
12167 TableScale_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12168 {
12169 int i;
12170 PyObject *tabletmp, *outtabletmp, *multmp = NULL, *addtmp = NULL;
12171 TableScale *self;
12172 self = (TableScale *)type->tp_alloc(type, 0);
12173
12174 self->modebuffer[0] = 0;
12175 self->modebuffer[1] = 0;
12176
12177 INIT_OBJECT_COMMON
12178 Stream_setFunctionPtr(self->stream, TableScale_compute_next_data_frame);
12179 self->mode_func_ptr = TableScale_setProcMode;
12180
12181 static char *kwlist[] = {"table", "outtable", "mul", "add", NULL};
12182
12183 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO", kwlist, &tabletmp, &outtabletmp, &multmp, &addtmp))
12184 Py_RETURN_NONE;
12185
12186 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
12187 {
12188 PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableScale must be a PyoTableObject.\n");
12189 Py_RETURN_NONE;
12190 }
12191
12192 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
12193
12194 if ( PyObject_HasAttrString((PyObject *)outtabletmp, "getTableStream") == 0 )
12195 {
12196 PyErr_SetString(PyExc_TypeError, "\"outtable\" argument of TableScale must be a PyoTableObject.\n");
12197 Py_RETURN_NONE;
12198 }
12199
12200 self->outtable = PyObject_CallMethod((PyObject *)outtabletmp, "getTableStream", "");
12201
12202 if (multmp)
12203 {
12204 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
12205 }
12206
12207 if (addtmp)
12208 {
12209 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
12210 }
12211
12212 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
12213
12214 (*self->mode_func_ptr)(self);
12215
12216 return (PyObject *)self;
12217 }
12218
12219 static PyObject * TableScale_getServer(TableScale* self) { GET_SERVER };
12220 static PyObject * TableScale_getStream(TableScale* self) { GET_STREAM };
12221 static PyObject * TableScale_setMul(TableScale *self, PyObject *arg) { SET_MUL };
12222 static PyObject * TableScale_setAdd(TableScale *self, PyObject *arg) { SET_ADD };
12223 static PyObject * TableScale_setSub(TableScale *self, PyObject *arg) { SET_SUB };
12224 static PyObject * TableScale_setDiv(TableScale *self, PyObject *arg) { SET_DIV };
12225
12226 static PyObject * TableScale_play(TableScale *self, PyObject *args, PyObject *kwds) { PLAY };
12227 static PyObject * TableScale_out(TableScale *self, PyObject *args, PyObject *kwds) { OUT };
12228 static PyObject * TableScale_stop(TableScale *self, PyObject *args, PyObject *kwds) { STOP };
12229
12230 static PyObject * TableScale_multiply(TableScale *self, PyObject *arg) { MULTIPLY };
12231 static PyObject * TableScale_inplace_multiply(TableScale *self, PyObject *arg) { INPLACE_MULTIPLY };
12232 static PyObject * TableScale_add(TableScale *self, PyObject *arg) { ADD };
12233 static PyObject * TableScale_inplace_add(TableScale *self, PyObject *arg) { INPLACE_ADD };
12234 static PyObject * TableScale_sub(TableScale *self, PyObject *arg) { SUB };
12235 static PyObject * TableScale_inplace_sub(TableScale *self, PyObject *arg) { INPLACE_SUB };
12236 static PyObject * TableScale_div(TableScale *self, PyObject *arg) { DIV };
12237 static PyObject * TableScale_inplace_div(TableScale *self, PyObject *arg) { INPLACE_DIV };
12238
12239 static PyObject *
12240 TableScale_getTable(TableScale* self)
12241 {
12242 Py_INCREF(self->table);
12243 return self->table;
12244 };
12245
12246 static PyObject *
12247 TableScale_setTable(TableScale *self, PyObject *arg)
12248 {
12249 ASSERT_ARG_NOT_NULL
12250
12251 Py_DECREF(self->table);
12252 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
12253
12254 Py_RETURN_NONE;
12255 }
12256
12257 static PyObject *
12258 TableScale_getOuttable(TableScale* self)
12259 {
12260 Py_INCREF(self->outtable);
12261 return self->outtable;
12262 };
12263
12264 static PyObject *
12265 TableScale_setOuttable(TableScale *self, PyObject *arg)
12266 {
12267 ASSERT_ARG_NOT_NULL
12268
12269 Py_DECREF(self->outtable);
12270 self->outtable = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
12271
12272 Py_RETURN_NONE;
12273 }
12274
12275 static PyMemberDef TableScale_members[] =
12276 {
12277 {"server", T_OBJECT_EX, offsetof(TableScale, server), 0, "Pyo server."},
12278 {"stream", T_OBJECT_EX, offsetof(TableScale, stream), 0, "Stream object."},
12279 {"table", T_OBJECT_EX, offsetof(TableScale, table), 0, "Waveform table."},
12280 {"outtable", T_OBJECT_EX, offsetof(TableScale, outtable), 0, "Output table."},
12281 {"mul", T_OBJECT_EX, offsetof(TableScale, mul), 0, "Mul factor."},
12282 {"add", T_OBJECT_EX, offsetof(TableScale, add), 0, "Add factor."},
12283 {NULL} /* Sentinel */
12284 };
12285
12286 static PyMethodDef TableScale_methods[] =
12287 {
12288 {"getTable", (PyCFunction)TableScale_getTable, METH_NOARGS, "Returns waveform table object."},
12289 {"getOuttable", (PyCFunction)TableScale_getOuttable, METH_NOARGS, "Returns output table object."},
12290 {"getServer", (PyCFunction)TableScale_getServer, METH_NOARGS, "Returns server object."},
12291 {"_getStream", (PyCFunction)TableScale_getStream, METH_NOARGS, "Returns stream object."},
12292 {"play", (PyCFunction)TableScale_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
12293 {"out", (PyCFunction)TableScale_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
12294 {"stop", (PyCFunction)TableScale_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
12295 {"setTable", (PyCFunction)TableScale_setTable, METH_O, "Sets oscillator table."},
12296 {"setOuttable", (PyCFunction)TableScale_setOuttable, METH_O, "Sets output table."},
12297 {"setMul", (PyCFunction)TableScale_setMul, METH_O, "Sets oscillator mul factor."},
12298 {"setAdd", (PyCFunction)TableScale_setAdd, METH_O, "Sets oscillator add factor."},
12299 {"setSub", (PyCFunction)TableScale_setSub, METH_O, "Sets oscillator inverse add factor."},
12300 {"setDiv", (PyCFunction)TableScale_setDiv, METH_O, "Sets inverse mul factor."},
12301 {NULL} /* Sentinel */
12302 };
12303
12304 static PyNumberMethods TableScale_as_number =
12305 {
12306 (binaryfunc)TableScale_add, /*nb_add*/
12307 (binaryfunc)TableScale_sub, /*nb_subtract*/
12308 (binaryfunc)TableScale_multiply, /*nb_multiply*/
12309 0, /*nb_remainder*/
12310 0, /*nb_divmod*/
12311 0, /*nb_power*/
12312 0, /*nb_neg*/
12313 0, /*nb_pos*/
12314 0, /*(unaryfunc)array_abs,*/
12315 0, /*nb_nonzero*/
12316 0, /*nb_invert*/
12317 0, /*nb_lshift*/
12318 0, /*nb_rshift*/
12319 0, /*nb_and*/
12320 0, /*nb_xor*/
12321 0, /*nb_or*/
12322 0, /*nb_int*/
12323 0, /*nb_long*/
12324 0, /*nb_float*/
12325 (binaryfunc)TableScale_inplace_add, /*inplace_add*/
12326 (binaryfunc)TableScale_inplace_sub, /*inplace_subtract*/
12327 (binaryfunc)TableScale_inplace_multiply, /*inplace_multiply*/
12328 0, /*inplace_remainder*/
12329 0, /*inplace_power*/
12330 0, /*inplace_lshift*/
12331 0, /*inplace_rshift*/
12332 0, /*inplace_and*/
12333 0, /*inplace_xor*/
12334 0, /*inplace_or*/
12335 0, /*nb_floor_divide*/
12336 (binaryfunc)TableScale_div, /*nb_true_divide*/
12337 0, /*nb_inplace_floor_divide*/
12338 (binaryfunc)TableScale_inplace_div, /*nb_inplace_true_divide*/
12339 0, /* nb_index */
12340 };
12341
12342 PyTypeObject TableScaleType =
12343 {
12344 PyVarObject_HEAD_INIT(NULL, 0)
12345 "_pyo.TableScale_base", /*tp_name*/
12346 sizeof(TableScale), /*tp_basicsize*/
12347 0, /*tp_itemsize*/
12348 (destructor)TableScale_dealloc, /*tp_dealloc*/
12349 0, /*tp_print*/
12350 0, /*tp_getattr*/
12351 0, /*tp_setattr*/
12352 0, /*tp_as_async (tp_compare in Python 2)*/
12353 0, /*tp_repr*/
12354 &TableScale_as_number, /*tp_as_number*/
12355 0, /*tp_as_sequence*/
12356 0, /*tp_as_mapping*/
12357 0, /*tp_hash */
12358 0, /*tp_call*/
12359 0, /*tp_str*/
12360 0, /*tp_getattro*/
12361 0, /*tp_setattro*/
12362 0, /*tp_as_buffer*/
12363 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
12364 "TableScale objects. Scale a PyoTable and save the result in another table.", /* tp_doc */
12365 (traverseproc)TableScale_traverse, /* tp_traverse */
12366 (inquiry)TableScale_clear, /* tp_clear */
12367 0, /* tp_richcompare */
12368 0, /* tp_weaklistoffset */
12369 0, /* tp_iter */
12370 0, /* tp_iternext */
12371 TableScale_methods, /* tp_methods */
12372 TableScale_members, /* tp_members */
12373 0, /* tp_getset */
12374 0, /* tp_base */
12375 0, /* tp_dict */
12376 0, /* tp_descr_get */
12377 0, /* tp_descr_set */
12378 0, /* tp_dictoffset */
12379 0, /* tp_init */
12380 0, /* tp_alloc */
12381 TableScale_new, /* tp_new */
12382 };
12383
12384 /******************************/
12385 /* TableFill object definition */
12386 /******************************/
12387 typedef struct
12388 {
12389 pyo_audio_HEAD
12390 PyObject *input;
12391 Stream *input_stream;
12392 PyObject *table;
12393 T_SIZE_T pointer;
12394 } TableFill;
12395
12396 static void
12397 TableFill_compute_next_data_frame(TableFill *self)
12398 {
12399 int i;
12400 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
12401 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
12402 MYFLT *in = Stream_getData((Stream *)self->input_stream);
12403
12404 for (i = 0; i < self->bufsize; i++)
12405 {
12406 tablelist[self->pointer++] = in[i];
12407
12408 if (self->pointer >= size)
12409 self->pointer = 0;
12410 }
12411 }
12412
12413 static int
12414 TableFill_traverse(TableFill *self, visitproc visit, void *arg)
12415 {
12416 pyo_VISIT
12417 Py_VISIT(self->input);
12418 return 0;
12419 }
12420
12421 static int
12422 TableFill_clear(TableFill *self)
12423 {
12424 pyo_CLEAR
12425 Py_CLEAR(self->input);
12426 return 0;
12427 }
12428
12429 static void
12430 TableFill_dealloc(TableFill* self)
12431 {
12432 pyo_DEALLOC
12433 TableFill_clear(self);
12434 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
12435 Py_TYPE(self)->tp_free((PyObject*)self);
12436 }
12437
12438 static PyObject *
12439 TableFill_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12440 {
12441 int i;
12442 PyObject *inputtmp, *input_streamtmp, *tabletmp;
12443 TableFill *self;
12444 self = (TableFill *)type->tp_alloc(type, 0);
12445
12446 self->pointer = 0;
12447
12448 INIT_OBJECT_COMMON
12449
12450 Stream_setFunctionPtr(self->stream, TableFill_compute_next_data_frame);
12451
12452 static char *kwlist[] = {"input", "table", NULL};
12453
12454 if (! PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &inputtmp, &tabletmp))
12455 Py_RETURN_NONE;
12456
12457 INIT_INPUT_STREAM
12458
12459 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
12460 {
12461 PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableFill must be a PyoTableObject.\n");
12462 Py_RETURN_NONE;
12463 }
12464
12465 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
12466
12467 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
12468
12469 return (PyObject *)self;
12470 }
12471
12472 static PyObject * TableFill_getServer(TableFill* self) { GET_SERVER };
12473 static PyObject * TableFill_getStream(TableFill* self) { GET_STREAM };
12474
12475 static PyObject * TableFill_play(TableFill *self, PyObject *args, PyObject *kwds)
12476 {
12477 self->pointer = 0;
12478 PLAY
12479 };
12480
12481 static PyObject * TableFill_stop(TableFill *self, PyObject *args, PyObject *kwds) { STOP };
12482
12483 static PyObject *
12484 TableFill_setTable(TableFill *self, PyObject *arg)
12485 {
12486 ASSERT_ARG_NOT_NULL
12487
12488 Py_DECREF(self->table);
12489 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
12490 Py_INCREF(self->table);
12491
12492 Py_RETURN_NONE;
12493 }
12494
12495 static PyObject * TableFill_getCurrentPos(TableFill *self)
12496 {
12497 return PyLong_FromLong(self->pointer);
12498 };
12499
12500 static PyMemberDef TableFill_members[] =
12501 {
12502 {"server", T_OBJECT_EX, offsetof(TableFill, server), 0, "Pyo server."},
12503 {"stream", T_OBJECT_EX, offsetof(TableFill, stream), 0, "Stream object."},
12504 {"input", T_OBJECT_EX, offsetof(TableFill, input), 0, "Input sound object."},
12505 {"table", T_OBJECT_EX, offsetof(TableFill, table), 0, "Table to record in."},
12506 {NULL} /* Sentinel */
12507 };
12508
12509 static PyMethodDef TableFill_methods[] =
12510 {
12511 {"getServer", (PyCFunction)TableFill_getServer, METH_NOARGS, "Returns server object."},
12512 {"_getStream", (PyCFunction)TableFill_getStream, METH_NOARGS, "Returns stream object."},
12513 {"setTable", (PyCFunction)TableFill_setTable, METH_O, "Sets a new table to fill."},
12514 {"play", (PyCFunction)TableFill_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
12515 {"stop", (PyCFunction)TableFill_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
12516 {"getCurrentPos", (PyCFunction)TableFill_getCurrentPos, METH_NOARGS, "Returns the current position."},
12517 {NULL} /* Sentinel */
12518 };
12519
12520 PyTypeObject TableFillType =
12521 {
12522 PyVarObject_HEAD_INIT(NULL, 0)
12523 "_pyo.TableFill_base", /*tp_name*/
12524 sizeof(TableFill), /*tp_basicsize*/
12525 0, /*tp_itemsize*/
12526 (destructor)TableFill_dealloc, /*tp_dealloc*/
12527 0, /*tp_print*/
12528 0, /*tp_getattr*/
12529 0, /*tp_setattr*/
12530 0, /*tp_as_async (tp_compare in Python 2)*/
12531 0, /*tp_repr*/
12532 0, /*tp_as_number*/
12533 0, /*tp_as_sequence*/
12534 0, /*tp_as_mapping*/
12535 0, /*tp_hash */
12536 0, /*tp_call*/
12537 0, /*tp_str*/
12538 0, /*tp_getattro*/
12539 0, /*tp_setattro*/
12540 0, /*tp_as_buffer*/
12541 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
12542 "TableFill objects. Fill a table object with values in input.", /* tp_doc */
12543 (traverseproc)TableFill_traverse, /* tp_traverse */
12544 (inquiry)TableFill_clear, /* tp_clear */
12545 0, /* tp_richcompare */
12546 0, /* tp_weaklistoffset */
12547 0, /* tp_iter */
12548 0, /* tp_iternext */
12549 TableFill_methods, /* tp_methods */
12550 TableFill_members, /* tp_members */
12551 0, /* tp_getset */
12552 0, /* tp_base */
12553 0, /* tp_dict */
12554 0, /* tp_descr_get */
12555 0, /* tp_descr_set */
12556 0, /* tp_dictoffset */
12557 0, /* tp_init */
12558 0, /* tp_alloc */
12559 TableFill_new, /* tp_new */
12560 };
12561
12562 /**************/
12563 /* TableScan object */
12564 /**************/
12565 typedef struct
12566 {
12567 pyo_audio_HEAD
12568 PyObject *table;
12569 int modebuffer[2];
12570 T_SIZE_T pointerPos;
12571 } TableScan;
12572
12573 static void
12574 TableScan_readframes(TableScan *self)
12575 {
12576 int i;
12577 MYFLT *tablelist = TableStream_getData((TableStream *)self->table);
12578 T_SIZE_T size = TableStream_getSize((TableStream *)self->table);
12579
12580 for (i = 0; i < self->bufsize; i++)
12581 {
12582 self->data[i] = tablelist[self->pointerPos++];
12583
12584 if (self->pointerPos >= size)
12585 self->pointerPos = 0;
12586 }
12587 }
12588
12589 static void TableScan_postprocessing_ii(TableScan *self) { POST_PROCESSING_II };
12590 static void TableScan_postprocessing_ai(TableScan *self) { POST_PROCESSING_AI };
12591 static void TableScan_postprocessing_ia(TableScan *self) { POST_PROCESSING_IA };
12592 static void TableScan_postprocessing_aa(TableScan *self) { POST_PROCESSING_AA };
12593 static void TableScan_postprocessing_ireva(TableScan *self) { POST_PROCESSING_IREVA };
12594 static void TableScan_postprocessing_areva(TableScan *self) { POST_PROCESSING_AREVA };
12595 static void TableScan_postprocessing_revai(TableScan *self) { POST_PROCESSING_REVAI };
12596 static void TableScan_postprocessing_revaa(TableScan *self) { POST_PROCESSING_REVAA };
12597 static void TableScan_postprocessing_revareva(TableScan *self) { POST_PROCESSING_REVAREVA };
12598
12599 static void
12600 TableScan_setProcMode(TableScan *self)
12601 {
12602 int muladdmode;
12603 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
12604
12605 self->proc_func_ptr = TableScan_readframes;
12606
12607 switch (muladdmode)
12608 {
12609 case 0:
12610 self->muladd_func_ptr = TableScan_postprocessing_ii;
12611 break;
12612
12613 case 1:
12614 self->muladd_func_ptr = TableScan_postprocessing_ai;
12615 break;
12616
12617 case 2:
12618 self->muladd_func_ptr = TableScan_postprocessing_revai;
12619 break;
12620
12621 case 10:
12622 self->muladd_func_ptr = TableScan_postprocessing_ia;
12623 break;
12624
12625 case 11:
12626 self->muladd_func_ptr = TableScan_postprocessing_aa;
12627 break;
12628
12629 case 12:
12630 self->muladd_func_ptr = TableScan_postprocessing_revaa;
12631 break;
12632
12633 case 20:
12634 self->muladd_func_ptr = TableScan_postprocessing_ireva;
12635 break;
12636
12637 case 21:
12638 self->muladd_func_ptr = TableScan_postprocessing_areva;
12639 break;
12640
12641 case 22:
12642 self->muladd_func_ptr = TableScan_postprocessing_revareva;
12643 break;
12644 }
12645 }
12646
12647 static void
12648 TableScan_compute_next_data_frame(TableScan *self)
12649 {
12650 (*self->proc_func_ptr)(self);
12651 (*self->muladd_func_ptr)(self);
12652 }
12653
12654 static int
12655 TableScan_traverse(TableScan *self, visitproc visit, void *arg)
12656 {
12657 pyo_VISIT
12658 return 0;
12659 }
12660
12661 static int
12662 TableScan_clear(TableScan *self)
12663 {
12664 pyo_CLEAR
12665 return 0;
12666 }
12667
12668 static void
12669 TableScan_dealloc(TableScan* self)
12670 {
12671 pyo_DEALLOC
12672 TableScan_clear(self);
12673 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
12674 Py_TYPE(self)->tp_free((PyObject*)self);
12675 }
12676
12677 static PyObject *
12678 TableScan_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12679 {
12680 int i;
12681 PyObject *tabletmp, *multmp = NULL, *addtmp = NULL;
12682 TableScan *self;
12683 self = (TableScan *)type->tp_alloc(type, 0);
12684
12685 self->modebuffer[0] = 0;
12686 self->modebuffer[1] = 0;
12687 self->pointerPos = 0;
12688
12689 INIT_OBJECT_COMMON
12690 Stream_setFunctionPtr(self->stream, TableScan_compute_next_data_frame);
12691 self->mode_func_ptr = TableScan_setProcMode;
12692
12693 static char *kwlist[] = {"table", "mul", "add", NULL};
12694
12695 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &tabletmp, &multmp, &addtmp))
12696 Py_RETURN_NONE;
12697
12698 if ( PyObject_HasAttrString((PyObject *)tabletmp, "getTableStream") == 0 )
12699 {
12700 PyErr_SetString(PyExc_TypeError, "\"table\" argument of TableScan must be a PyoTableObject.\n");
12701 Py_RETURN_NONE;
12702 }
12703
12704 self->table = PyObject_CallMethod((PyObject *)tabletmp, "getTableStream", "");
12705
12706 if (multmp)
12707 {
12708 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
12709 }
12710
12711 if (addtmp)
12712 {
12713 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
12714 }
12715
12716 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
12717
12718 (*self->mode_func_ptr)(self);
12719
12720 return (PyObject *)self;
12721 }
12722
12723 static PyObject * TableScan_getServer(TableScan* self) { GET_SERVER };
12724 static PyObject * TableScan_getStream(TableScan* self) { GET_STREAM };
12725 static PyObject * TableScan_setMul(TableScan *self, PyObject *arg) { SET_MUL };
12726 static PyObject * TableScan_setAdd(TableScan *self, PyObject *arg) { SET_ADD };
12727 static PyObject * TableScan_setSub(TableScan *self, PyObject *arg) { SET_SUB };
12728 static PyObject * TableScan_setDiv(TableScan *self, PyObject *arg) { SET_DIV };
12729
12730 static PyObject * TableScan_play(TableScan *self, PyObject *args, PyObject *kwds)
12731 {
12732 self->pointerPos = 0;
12733 PLAY
12734 };
12735
12736 static PyObject * TableScan_out(TableScan *self, PyObject *args, PyObject *kwds)
12737 {
12738 self->pointerPos = 0;
12739 OUT
12740 };
12741 static PyObject * TableScan_stop(TableScan *self, PyObject *args, PyObject *kwds) { STOP };
12742
12743 static PyObject * TableScan_multiply(TableScan *self, PyObject *arg) { MULTIPLY };
12744 static PyObject * TableScan_inplace_multiply(TableScan *self, PyObject *arg) { INPLACE_MULTIPLY };
12745 static PyObject * TableScan_add(TableScan *self, PyObject *arg) { ADD };
12746 static PyObject * TableScan_inplace_add(TableScan *self, PyObject *arg) { INPLACE_ADD };
12747 static PyObject * TableScan_sub(TableScan *self, PyObject *arg) { SUB };
12748 static PyObject * TableScan_inplace_sub(TableScan *self, PyObject *arg) { INPLACE_SUB };
12749 static PyObject * TableScan_div(TableScan *self, PyObject *arg) { DIV };
12750 static PyObject * TableScan_inplace_div(TableScan *self, PyObject *arg) { INPLACE_DIV };
12751
12752 static PyObject *
12753 TableScan_getTable(TableScan* self)
12754 {
12755 Py_INCREF(self->table);
12756 return self->table;
12757 };
12758
12759 static PyObject *
12760 TableScan_setTable(TableScan *self, PyObject *arg)
12761 {
12762 ASSERT_ARG_NOT_NULL
12763
12764 Py_DECREF(self->table);
12765 self->table = PyObject_CallMethod((PyObject *)arg, "getTableStream", "");
12766
12767 Py_RETURN_NONE;
12768 }
12769
12770 static PyObject *
12771 TableScan_reset(TableScan *self)
12772 {
12773 self->pointerPos = 0;
12774 Py_RETURN_NONE;
12775 }
12776
12777 static PyMemberDef TableScan_members[] =
12778 {
12779 {"server", T_OBJECT_EX, offsetof(TableScan, server), 0, "Pyo server."},
12780 {"stream", T_OBJECT_EX, offsetof(TableScan, stream), 0, "Stream object."},
12781 {"table", T_OBJECT_EX, offsetof(TableScan, table), 0, "Waveform table."},
12782 {"mul", T_OBJECT_EX, offsetof(TableScan, mul), 0, "Mul factor."},
12783 {"add", T_OBJECT_EX, offsetof(TableScan, add), 0, "Add factor."},
12784 {NULL} /* Sentinel */
12785 };
12786
12787 static PyMethodDef TableScan_methods[] =
12788 {
12789 {"getTable", (PyCFunction)TableScan_getTable, METH_NOARGS, "Returns waveform table object."},
12790 {"getServer", (PyCFunction)TableScan_getServer, METH_NOARGS, "Returns server object."},
12791 {"_getStream", (PyCFunction)TableScan_getStream, METH_NOARGS, "Returns stream object."},
12792 {"play", (PyCFunction)TableScan_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
12793 {"out", (PyCFunction)TableScan_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
12794 {"stop", (PyCFunction)TableScan_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
12795 {"setTable", (PyCFunction)TableScan_setTable, METH_O, "Sets oscillator table."},
12796 {"reset", (PyCFunction)TableScan_reset, METH_NOARGS, "Resets pointer position to 0."},
12797 {"setMul", (PyCFunction)TableScan_setMul, METH_O, "Sets oscillator mul factor."},
12798 {"setAdd", (PyCFunction)TableScan_setAdd, METH_O, "Sets oscillator add factor."},
12799 {"setSub", (PyCFunction)TableScan_setSub, METH_O, "Sets oscillator inverse add factor."},
12800 {"setDiv", (PyCFunction)TableScan_setDiv, METH_O, "Sets inverse mul factor."},
12801 {NULL} /* Sentinel */
12802 };
12803
12804 static PyNumberMethods TableScan_as_number =
12805 {
12806 (binaryfunc)TableScan_add, /*nb_add*/
12807 (binaryfunc)TableScan_sub, /*nb_subtract*/
12808 (binaryfunc)TableScan_multiply, /*nb_multiply*/
12809 0, /*nb_remainder*/
12810 0, /*nb_divmod*/
12811 0, /*nb_power*/
12812 0, /*nb_neg*/
12813 0, /*nb_pos*/
12814 0, /*(unaryfunc)array_abs,*/
12815 0, /*nb_nonzero*/
12816 0, /*nb_invert*/
12817 0, /*nb_lshift*/
12818 0, /*nb_rshift*/
12819 0, /*nb_and*/
12820 0, /*nb_xor*/
12821 0, /*nb_or*/
12822 0, /*nb_int*/
12823 0, /*nb_long*/
12824 0, /*nb_float*/
12825 (binaryfunc)TableScan_inplace_add, /*inplace_add*/
12826 (binaryfunc)TableScan_inplace_sub, /*inplace_subtract*/
12827 (binaryfunc)TableScan_inplace_multiply, /*inplace_multiply*/
12828 0, /*inplace_remainder*/
12829 0, /*inplace_power*/
12830 0, /*inplace_lshift*/
12831 0, /*inplace_rshift*/
12832 0, /*inplace_and*/
12833 0, /*inplace_xor*/
12834 0, /*inplace_or*/
12835 0, /*nb_floor_divide*/
12836 (binaryfunc)TableScan_div, /*nb_true_divide*/
12837 0, /*nb_inplace_floor_divide*/
12838 (binaryfunc)TableScan_inplace_div, /*nb_inplace_true_divide*/
12839 0, /* nb_index */
12840 };
12841
12842 PyTypeObject TableScanType =
12843 {
12844 PyVarObject_HEAD_INIT(NULL, 0)
12845 "_pyo.TableScan_base", /*tp_name*/
12846 sizeof(TableScan), /*tp_basicsize*/
12847 0, /*tp_itemsize*/
12848 (destructor)TableScan_dealloc, /*tp_dealloc*/
12849 0, /*tp_print*/
12850 0, /*tp_getattr*/
12851 0, /*tp_setattr*/
12852 0, /*tp_as_async (tp_compare in Python 2)*/
12853 0, /*tp_repr*/
12854 &TableScan_as_number, /*tp_as_number*/
12855 0, /*tp_as_sequence*/
12856 0, /*tp_as_mapping*/
12857 0, /*tp_hash */
12858 0, /*tp_call*/
12859 0, /*tp_str*/
12860 0, /*tp_getattro*/
12861 0, /*tp_setattro*/
12862 0, /*tp_as_buffer*/
12863 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
12864 "TableScan objects. Scan the content of a table in loop.", /* tp_doc */
12865 (traverseproc)TableScan_traverse, /* tp_traverse */
12866 (inquiry)TableScan_clear, /* tp_clear */
12867 0, /* tp_richcompare */
12868 0, /* tp_weaklistoffset */
12869 0, /* tp_iter */
12870 0, /* tp_iternext */
12871 TableScan_methods, /* tp_methods */
12872 TableScan_members, /* tp_members */
12873 0, /* tp_getset */
12874 0, /* tp_base */
12875 0, /* tp_dict */
12876 0, /* tp_descr_get */
12877 0, /* tp_descr_set */
12878 0, /* tp_dictoffset */
12879 0, /* tp_init */
12880 0, /* tp_alloc */
12881 TableScan_new, /* tp_new */
12882 };