| @@ -1269,7 +1269,6 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 1268 unmodified lines |
| 1269 | 1269 | |
| 1270 | 1270 | sync = c->sync; |
| 1271 | 1271 | |
| 1272 | | − |
| 1273 | 1272 | p = c->_p; /* phase [0, 1) */ |
| 1274 | 1273 | w = c->_w; /* phase increment */ |
| 1275 | 1274 | b = c->_b; /* duty cycle (0, 1) */ |
| @@ -1482,6 +1481,7 @@ void tMBTriangle_setFreq(tMBTriangle* const osc, float f) · 206 unmodified lines |
| 1482 | 1481 | void tMBTriangle_setWidth(tMBTriangle* const osc, float w) |
| 1483 | 1482 | { |
| 1484 | 1483 | _tMBTriangle* c = *osc; |
| 1484 | + w = LEAF_clip(0.0f, w, 0.99f); |
| 1485 | 1485 | c->waveform = w; |
| 1486 | 1486 | } |
| 1487 | 1487 | |
| @@ -1846,10 +1846,13 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 358 unmodified lines |
| 1846 | 1846 | } |
| 1847 | 1847 | |
| 1848 | 1848 | |
| 1849 | | − /* now place reset DD for pulse */ |
| 1849 | + |
| 1850 | 1850 | if (sw > 0) |
| 1851 | 1851 | { |
| 1852 | | − if (k) { |
| 1852 | + /* now place reset DD for saw*/ |
| 1853 | + place_step_dd(c->_f, j, p, sw, p_at_reset * sawShape); |
| 1854 | + /* now place reset DD for pulse */ |
| 1855 | + if (k) { |
| 1853 | 1856 | place_step_dd(c->_f, j, p, sw, 1.0f * shape); |
| 1854 | 1857 | k = 0; |
| 1855 | 1858 | x = 0.5f; |
| @@ -1862,6 +1865,9 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 6 unmodified lines |
| 1862 | 1865 | } |
| 1863 | 1866 | else if (sw < 0) |
| 1864 | 1867 | { |
| 1868 | + /* now place reset DD for saw*/ |
| 1869 | + place_step_dd(c->_f, j, 1.0f - p, -sw, -p_at_reset * sawShape); |
| 1870 | + /* now place reset DD for pulse */ |
| 1865 | 1871 | if (!k) { |
| 1866 | 1872 | place_step_dd(c->_f, j, 1.0f - p, -sw, -1.0f * shape); |
| 1867 | 1873 | k = 1; |
| @@ -1873,11 +1879,7 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 5 unmodified lines |
| 1873 | 1879 | x = 0.5f; |
| 1874 | 1880 | } |
| 1875 | 1881 | } |
| 1876 | | − /* now place reset DD for saw*/ |
| 1877 | | − if (sw > 0) |
| 1878 | | − place_step_dd(c->_f, j, p, sw, p_at_reset * sawShape); |
| 1879 | | − else if (sw < 0) |
| 1880 | | − place_step_dd(c->_f, j, 1.0f - p, -sw, -p_at_reset * sawShape); |
| 1882 | + |
| 1881 | 1883 | |
| 1882 | 1884 | } |
| 1883 | 1885 | |
| @@ -2835,7 +2837,6 @@ void tIntPhasor_initToPool (tIntPhasor* const cy, tMempool* const mp) · 951 unmodified lines |
| 2835 | 2837 | |
| 2836 | 2838 | c->phase = 0; |
| 2837 | 2839 | c->invSampleRateTimesTwoTo32 = (leaf->invSampleRate * TWO_TO_32); |
| 2838 | | − c->mask = 0x7FFFFFFF; |
| 2839 | 2840 | } |
| 2840 | 2841 | |
| 2841 | 2842 | void tIntPhasor_free (tIntPhasor* const cy) |
| @@ -2850,7 +2851,7 @@ float tIntPhasor_tick(tIntPhasor* const cy) · 8 unmodified lines |
| 2850 | 2851 | { |
| 2851 | 2852 | _tIntPhasor* c = *cy; |
| 2852 | 2853 | // Phasor increment |
| 2853 | | − c->phase = (c->phase + c->inc);//& c->mask; |
| 2854 | + c->phase = (c->phase + c->inc); |
| 2854 | 2855 | |
| 2855 | 2856 | return c->phase * INV_TWO_TO_32; |
| 2856 | 2857 | } |
| @@ -2891,10 +2892,9 @@ void tSquareLFO_initToPool (tSquareLFO* const cy, tMempool* const mp) · 34 unmodified lines |
| 2891 | 2892 | _tMempool* m = *mp; |
| 2892 | 2893 | _tSquareLFO* c = *cy = (_tSquareLFO*) mpool_alloc(sizeof(_tSquareLFO), m); |
| 2893 | 2894 | c->mempool = m; |
| 2894 | | − LEAF* leaf = c->mempool->leaf; |
| 2895 | 2895 | tIntPhasor_initToPool(&c->phasor,mp); |
| 2896 | 2896 | tIntPhasor_initToPool(&c->invPhasor,mp); |
| 2897 | | − tSquareLFO_setPulseWidth(cy, 0.5); |
| 2897 | + tSquareLFO_setPulseWidth(cy, 0.5f); |
| 2898 | 2898 | } |
| 2899 | 2899 | |
| 2900 | 2900 | void tSquareLFO_free (tSquareLFO* const cy) |
| @@ -2937,7 +2937,6 @@ void tSquareLFO_setPulseWidth(tSquareLFO* const cy, float pw) · 36 unmodified lines |
| 2937 | 2937 | _tSquareLFO *c = *cy; |
| 2938 | 2938 | |
| 2939 | 2939 | c->pulsewidth = pw; |
| 2940 | | − //c->delay = c->pulsewidth * INV_TWO_TO_32; |
| 2941 | 2940 | tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth + (c->phasor->phase * INV_TWO_TO_32)); |
| 2942 | 2941 | } |
| 2943 | 2942 | |
| @@ -2951,7 +2950,7 @@ void tSquareLFO_setPhase(tSquareLFO* const cy, float phase) · 7 unmodified lines |
| 2951 | 2950 | void tSawSquareLFO_init (tSawSquareLFO* const cy, LEAF* const leaf) |
| 2952 | 2951 | { |
| 2953 | 2952 | tSawSquareLFO_initToPool(cy, &leaf->mempool); |
| 2954 | | − _tSawSquareLFO* c = *cy; |
| 2953 | + |
| 2955 | 2954 | } |
| 2956 | 2955 | |
| 2957 | 2956 | void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp) |
| @@ -2959,7 +2958,6 @@ void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp) · 1 unmodified line |
| 2959 | 2958 | _tMempool* m = *mp; |
| 2960 | 2959 | _tSawSquareLFO* c = *cy = (_tSawSquareLFO*) mpool_alloc(sizeof(_tSawSquareLFO), m); |
| 2961 | 2960 | c->mempool = m; |
| 2962 | | − LEAF* leaf = c->mempool->leaf; |
| 2963 | 2961 | tSquareLFO_initToPool(&c->square,mp); |
| 2964 | 2962 | tIntPhasor_initToPool(&c->saw,mp); |
| 2965 | 2963 | } |
| @@ -3024,8 +3022,7 @@ void tTriLFO_initToPool (tTriLFO* const cy, tMempool* const mp) · 58 unmodified lines |
| 3024 | 3022 | c->phase = 0; |
| 3025 | 3023 | c->invSampleRate = leaf->invSampleRate; |
| 3026 | 3024 | c->invSampleRateTimesTwoTo32 = (c->invSampleRate * TWO_TO_32); |
| 3027 | | − //c->mask = TRI_TABLE_SIZE - 1; |
| 3028 | | − tTriLFO_setFreq(cy, 220); |
| 3025 | + tTriLFO_setFreq(cy, 220.0f); |
| 3029 | 3026 | } |
| 3030 | 3027 | |
| 3031 | 3028 | void tTriLFO_free (tTriLFO* const cy) |
| @@ -3039,35 +3036,16 @@ void tTriLFO_free (tTriLFO* const cy) · 7 unmodified lines |
| 3039 | 3036 | float tTriLFO_tick(tTriLFO* const cy) |
| 3040 | 3037 | { |
| 3041 | 3038 | _tTriLFO* c = *cy; |
| 3042 | | − //uint32_t idx; |
| 3043 | | − //float frac, samp0, samp1; |
| 3044 | | − // Phasor increment |
| 3045 | 3039 | c->phase += c->inc; |
| 3046 | 3040 | |
| 3047 | 3041 | //bitmask fun |
| 3048 | | − // |
| 3049 | 3042 | int32_t shiftedPhase = c->phase + 1073741824; // offset by 1/4" wave by adding 2^30 to get things in phase with the other LFO oscillators |
| 3050 | | − uint32_t mask = shiftedPhase >> 31; |
| 3051 | | − int32_t val2 = shiftedPhase + mask; |
| 3052 | | − int32_t test = val2 ^ mask; |
| 3053 | | − float output =( ((float)test * INV_TWO_TO_31)-0.5f) * 2.0f; |
| 3043 | + uint32_t mask = shiftedPhase >> 31; //get the sign bit |
| 3044 | + shiftedPhase = shiftedPhase + mask; // add 1 if negative, zero if positive, to balance |
| 3045 | + shiftedPhase = shiftedPhase ^ mask; //invert the value to get absolute value of integer |
| 3046 | + float output = (((float)shiftedPhase * INV_TWO_TO_31) - 0.5f) * 2.0f; //scale it to -1.0f to 1.0f float |
| 3054 | 3047 | return output; |
| 3055 | 3048 | |
| 3056 | | − /* |
| 3057 | | − // Wavetable synthesis |
| 3058 | | − idx = c->phase >> 21; |
| 3059 | | − uint32_t idx2 = (idx + 1) & c->mask; |
| 3060 | | − uint32_t tempFrac = (c->phase & 2097151); |
| 3061 | | − frac = (float)tempFrac * 0.000000476837386f;// 1/2097151 (2097151 is the 21 bits after the 11 bits that represent the main index) |
| 3062 | | − |
| 3063 | | − samp0 = __leaf_table_triangle[0][idx]; |
| 3064 | | − samp1 = __leaf_table_triangle[0][idx2]; |
| 3065 | | − float oct0 = (samp0 + (samp1 - samp0) * frac); |
| 3066 | | − |
| 3067 | | − |
| 3068 | | − return oct0; |
| 3069 | | − */ |
| 3070 | | − |
| 3071 | 3049 | } |
| 3072 | 3050 | |
| 3073 | 3051 | void tTriLFO_setFreq(tTriLFO* const cy, float freq) |
| @@ -3081,7 +3059,6 @@ void tTriLFO_setFreq(tTriLFO* const cy, float freq) · 7 unmodified lines |
| 3081 | 3059 | void tTriLFO_setPhase(tTriLFO* const cy, float phase) |
| 3082 | 3060 | { |
| 3083 | 3061 | _tTriLFO* c = *cy; |
| 3084 | | − phase = (phase + 0.5f); |
| 3085 | 3062 | int i = phase; |
| 3086 | 3063 | phase -= i; |
| 3087 | 3064 | c->phase = phase * TWO_TO_32_INT; |
| @@ -3090,8 +3067,8 @@ void tTriLFO_setPhase(tTriLFO* const cy, float phase) · 2 unmodified lines |
| 3090 | 3067 | void tTriLFO_setSampleRate (tTriLFO* const cy, float sr) |
| 3091 | 3068 | { |
| 3092 | 3069 | _tTriLFO* c = *cy; |
| 3093 | | − |
| 3094 | | − c->invSampleRateTimesTwoTo32 = (1.0f/sr) * TWO_TO_32; |
| 3070 | + c->invSampleRate = (1.0f/sr); |
| 3071 | + c->invSampleRateTimesTwoTo32 = c->invSampleRate * TWO_TO_32; |
| 3095 | 3072 | tTriLFO_setFreq(cy, c->freq); |
| 3096 | 3073 | } |
| 3097 | 3074 | ///sinetri |
| @@ -3099,7 +3076,6 @@ void tTriLFO_setSampleRate (tTriLFO* const cy, float sr) · 1 unmodified line |
| 3099 | 3076 | void tSineTriLFO_init (tSineTriLFO* const cy, LEAF* const leaf) |
| 3100 | 3077 | { |
| 3101 | 3078 | tSineTriLFO_initToPool(cy, &leaf->mempool); |
| 3102 | | − _tSineTriLFO* c = *cy; |
| 3103 | 3079 | } |
| 3104 | 3080 | |
| 3105 | 3081 | void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp) |
| @@ -3107,7 +3083,6 @@ void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp) · 1 unmodified line |
| 3107 | 3083 | _tMempool* m = *mp; |
| 3108 | 3084 | _tSineTriLFO* c = *cy = (_tSineTriLFO*) mpool_alloc(sizeof(_tSineTriLFO), m); |
| 3109 | 3085 | c->mempool = m; |
| 3110 | | − LEAF* leaf = c->mempool->leaf; |
| 3111 | 3086 | tTriLFO_initToPool(&c->tri,mp); |
| 3112 | 3087 | tCycle_initToPool(&c->sine,mp); |
| 3113 | 3088 | |