{"id":1421,"date":"2018-10-24T16:55:25","date_gmt":"2018-10-24T23:55:25","guid":{"rendered":"http:\/\/tre.ucsd.edu\/wordpress\/?p=1421"},"modified":"2018-10-25T12:14:05","modified_gmt":"2018-10-25T19:14:05","slug":"mus177206-3-oscillator-examples","status":"publish","type":"post","link":"https:\/\/tre.ucsd.edu\/wordpress\/?p=1421","title":{"rendered":"mus177\/206 &#8211; 3 oscillator examples"},"content":{"rendered":"<p>a basic triangle oscillator\u00a0<a href=\"https:\/\/tre.ucsd.edu\/wordpress\/wp-content\/uploads\/2018\/10\/o1.zip\">o1<\/a><\/p>\n<p>a flexible (and probably too complicated) overtone oscillator\u00a0<a href=\"https:\/\/tre.ucsd.edu\/wordpress\/wp-content\/uploads\/2018\/10\/otosc.zip\">otosc<\/a><\/p>\n<p>a bell like oscillator, with non integer harmonics, and LCM phasor\u00a0<a href=\"https:\/\/tre.ucsd.edu\/wordpress\/wp-content\/uploads\/2018\/10\/o2.zip\">o2<\/a><\/p>\n<p>&#8212;-<\/p>\n<p>a couple extra methods to create sine waves:<\/p>\n<pre>\/\/ a resonant sin wave - based on the state variable filter\r\nResonantFilterSine(<b>float<\/b> *frequency, <b>float<\/b> *output, <b>long<\/b> samplesPerBlock)\r\n{\r\n<b>long<\/b> sample;\r\n<b>float<\/b> freqAngle;\r\n<b>for<\/b>(sample = 0; sample&lt;samplesPerBlock; sample++)\r\n{\r\n    freqAngle = twoPi * *(frequency + sample)\/sampleRate\r\n    *(output+sample) = sinZ = sinZ + freqAngle * cosZ;\r\n    cosZ = cosZ - freqAngle * sinZ;\r\n}\r\n}\r\n\r\n<\/pre>\n<pre>\/\/ method six - complex multiply sin\r\nSinComplex(float freq, float *freqBlock, float *output, long samplesPerBlock)\r\n{\r\n\tlong sample;\r\n\tfloat freqAngle, angleReal, angleImag;\r\n\t\r\n\tfreqAngle = twoPi * freq;\r\n\tangleReal = cos(freqAngle);\r\n\tangleImag = sin(freqAngle);\r\n\tfor(sample = 0; sample&lt;samplesPerBlock; sample++) \t\r\n        { \t\t\r\n            if(freqBlock) \t\t\r\n            { \t\t\t\r\n                freqAngle = twoPi * *(freqBlock + sample);\r\n                angleReal = cos(freqAngle);\r\n                angleImag = sin(freqAngle);\r\n            } \r\n            *(output+sample) = angleReal * sinZ - angleImag * cosZ;\r\n            cosZ = angleReal * cosZ + angleImag * sinZ;\r\n            sinZ = *(output+sample);\r\n            if(sinZ &gt; 1.0f) sinZ = 1.0f; \r\n        }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>a basic triangle oscillator\u00a0o1 a flexible (and probably too complicated) overtone oscillator\u00a0otosc a bell like oscillator, with non integer harmonics, and LCM phasor\u00a0o2 &#8212;- a couple extra methods to create sine waves: \/\/ a resonant sin wave &#8211; based on &hellip; <a href=\"https:\/\/tre.ucsd.edu\/wordpress\/?p=1421\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1421"}],"collection":[{"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1421"}],"version-history":[{"count":4,"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1421\/revisions"}],"predecessor-version":[{"id":1429,"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1421\/revisions\/1429"}],"wp:attachment":[{"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tre.ucsd.edu\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}