| @@ -2594,8 +2594,6 @@ void tIntPhasor_setSampleRate (tIntPhasor* const cy, float sr) · 2593 unmodified lines |
| 2594 | 2594 | void tSquareLFO_init(tSquareLFO* const cy, LEAF* const leaf) |
| 2595 | 2595 | { |
| 2596 | 2596 | tSquareLFO_initToPool(cy, &leaf->mempool); |
| 2597 | | − _tSquareLFO* c = *cy; |
| 2598 | | − |
| 2599 | 2597 | } |
| 2600 | 2598 | |
| 2601 | 2599 | void tSquareLFO_initToPool (tSquareLFO* const cy, tMempool* const mp) |
| @@ -2606,9 +2604,7 @@ void tSquareLFO_initToPool (tSquareLFO* const cy, tMempool* const mp) · 4 unmodified lines |
| 2606 | 2604 | LEAF* leaf = c->mempool->leaf; |
| 2607 | 2605 | tIntPhasor_initToPool(&c->phasor,mp); |
| 2608 | 2606 | tIntPhasor_initToPool(&c->invPhasor,mp); |
| 2609 | | − |
| 2610 | | − |
| 2611 | | − c->pulsewidth = 50.0f; |
| 2607 | + tSquareLFO_setPulseWidth(cy, 0.5); |
| 2612 | 2608 | } |
| 2613 | 2609 | |
| 2614 | 2610 | void tSquareLFO_free (tSquareLFO* const cy) |
| @@ -2654,3 +2650,202 @@ void tSquareLFO_setPulseWidth(tSquareLFO* const cy, float pw) · 39 unmodified lines |
| 2654 | 2650 | //c->delay = c->pulsewidth * INV_TWO_TO_32; |
| 2655 | 2651 | tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth + (c->phasor->phase * INV_TWO_TO_32)); |
| 2656 | 2652 | } |
| 2653 | + |
| 2654 | +void tSquareLFO_setPhase(tSquareLFO* const cy, float phase) |
| 2655 | +{ |
| 2656 | + _tSquareLFO *c = *cy; |
| 2657 | + tIntPhasor_setPhase(&c->phasor, phase); |
| 2658 | + tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth + (c->phasor->phase * INV_TWO_TO_32)); |
| 2659 | +} |
| 2660 | + |
| 2661 | +void tSawSquareLFO_init (tSawSquareLFO* const cy, LEAF* const leaf) |
| 2662 | +{ |
| 2663 | + tSawSquareLFO_initToPool(cy, &leaf->mempool); |
| 2664 | + _tSawSquareLFO* c = *cy; |
| 2665 | +} |
| 2666 | + |
| 2667 | +void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp) |
| 2668 | +{ |
| 2669 | + _tMempool* m = *mp; |
| 2670 | + _tSawSquareLFO* c = *cy = (_tSawSquareLFO*) mpool_alloc(sizeof(_tSawSquareLFO), m); |
| 2671 | + c->mempool = m; |
| 2672 | + LEAF* leaf = c->mempool->leaf; |
| 2673 | + tSquareLFO_initToPool(&c->square,mp); |
| 2674 | + tIntPhasor_initToPool(&c->saw,mp); |
| 2675 | +} |
| 2676 | +void tSawSquareLFO_free (tSawSquareLFO* const cy) |
| 2677 | +{ |
| 2678 | + _tSawSquareLFO* c = *cy; |
| 2679 | + tIntPhasor_free(&c->saw); |
| 2680 | + tSquareLFO_free(&c->square); |
| 2681 | + mpool_free((char*)c, c->mempool); |
| 2682 | +} |
| 2683 | + |
| 2684 | +float tSawSquareLFO_tick (tSawSquareLFO* const cy) |
| 2685 | +{ |
| 2686 | + _tSawSquareLFO* c = *cy; |
| 2687 | + float a = tIntPhasor_tick(&c->saw); |
| 2688 | + float b = tSquareLFO_tick(&c->square); |
| 2689 | + return (1 - c->shape) * a + c->shape * b; |
| 2690 | +} |
| 2691 | +void tSawSquareLFO_setFreq (tSawSquareLFO* const cy, float freq) |
| 2692 | +{ |
| 2693 | + _tSawSquareLFO* c = *cy; |
| 2694 | + tSquareLFO_setFreq(&c->square, freq); |
| 2695 | + tIntPhasor_setFreq(&c->saw, freq); |
| 2696 | +} |
| 2697 | +void tSawSquareLFO_setSampleRate (tSawSquareLFO* const cy, float sr) |
| 2698 | +{ |
| 2699 | + _tSawSquareLFO* c = *cy; |
| 2700 | + tSquareLFO_setSampleRate(&c->square, sr); |
| 2701 | + tIntPhasor_setSampleRate(&c->saw, sr); |
| 2702 | +} |
| 2703 | +void tSawSquareLFO_setPhase (tSawSquareLFO* const cy, float phase) |
| 2704 | +{ |
| 2705 | + _tSawSquareLFO* c = *cy; |
| 2706 | + tSquareLFO_setPhase(&c->square, phase); |
| 2707 | + tIntPhasor_setPhase(&c->saw, phase); |
| 2708 | +} |
| 2709 | + |
| 2710 | + |
| 2711 | +void tSawSquareLFO_setShape (tSawSquareLFO* const cy, float shape) |
| 2712 | +{ |
| 2713 | + _tSawSquareLFO* c = *cy; |
| 2714 | + c->shape = shape; |
| 2715 | +} |
| 2716 | + |
| 2717 | + |
| 2718 | + |
| 2719 | + |
| 2720 | +///tri |
| 2721 | +void tTriLFO_init(tTriLFO* const cy, LEAF* const leaf) |
| 2722 | +{ |
| 2723 | + tTriLFO_initToPool(cy, &leaf->mempool); |
| 2724 | +} |
| 2725 | + |
| 2726 | +void tTriLFO_initToPool (tTriLFO* const cy, tMempool* const mp) |
| 2727 | +{ |
| 2728 | + _tMempool* m = *mp; |
| 2729 | + _tTriLFO* c = *cy = (_tTriLFO*) mpool_alloc(sizeof(_tTriLFO), m); |
| 2730 | + c->mempool = m; |
| 2731 | + LEAF* leaf = c->mempool->leaf; |
| 2732 | + |
| 2733 | + c->inc = 0; |
| 2734 | + c->phase = 0; |
| 2735 | + c->invSampleRate = leaf->invSampleRate; |
| 2736 | + c->invSampleRateTimesTwoTo32 = (c->invSampleRate * TWO_TO_32); |
| 2737 | + c->mask = TRI_TABLE_SIZE - 1; |
| 2738 | + tTriLFO_setFreq(cy, 220); |
| 2739 | +} |
| 2740 | + |
| 2741 | +void tTriLFO_free (tTriLFO* const cy) |
| 2742 | +{ |
| 2743 | + _tTriLFO* c = *cy; |
| 2744 | + |
| 2745 | + mpool_free((char*)c, c->mempool); |
| 2746 | +} |
| 2747 | + |
| 2748 | +//need to check bounds and wrap table properly to allow through-zero FM |
| 2749 | +float tTriLFO_tick(tTriLFO* const cy) |
| 2750 | +{ |
| 2751 | + _tTriLFO* c = *cy; |
| 2752 | + uint32_t idx; |
| 2753 | + float frac, samp0, samp1; |
| 2754 | + // Phasor increment |
| 2755 | + c->phase += c->inc; |
| 2756 | + // Wavetable synthesis |
| 2757 | + idx = c->phase >> 21; |
| 2758 | + uint32_t idx2 = (idx + 1) & c->mask; |
| 2759 | + uint32_t tempFrac = (c->phase & 2097151); |
| 2760 | + frac = (float)tempFrac * 0.000000476837386f;// 1/2097151 (2097151 is the 21 bits after the 11 bits that represent the main index) |
| 2761 | + |
| 2762 | + samp0 = __leaf_table_triangle[0][idx]; |
| 2763 | + samp1 = __leaf_table_triangle[0][idx2]; |
| 2764 | + float oct0 = (samp0 + (samp1 - samp0) * frac); |
| 2765 | + |
| 2766 | + |
| 2767 | + return oct0; |
| 2768 | +} |
| 2769 | + |
| 2770 | +void tTriLFO_setFreq(tTriLFO* const cy, float freq) |
| 2771 | +{ |
| 2772 | + _tTriLFO* c = *cy; |
| 2773 | + |
| 2774 | + c->freq = freq; |
| 2775 | + c->inc = freq * c->invSampleRateTimesTwoTo32; |
| 2776 | +} |
| 2777 | + |
| 2778 | +void tTriLFO_setPhase(tTriLFO* const cy, float phase) |
| 2779 | +{ |
| 2780 | + _tTriLFO* c = *cy; |
| 2781 | + |
| 2782 | + int i = phase; |
| 2783 | + phase -= i; |
| 2784 | + c->phase = phase * TWO_TO_32; |
| 2785 | +} |
| 2786 | + |
| 2787 | +void tTriLFO_setSampleRate (tTriLFO* const cy, float sr) |
| 2788 | +{ |
| 2789 | + _tTriLFO* c = *cy; |
| 2790 | + |
| 2791 | + c->invSampleRateTimesTwoTo32 = (1.0f/sr) * TWO_TO_32; |
| 2792 | + tTriLFO_setFreq(cy, c->freq); |
| 2793 | +} |
| 2794 | +///sinetri |
| 2795 | + |
| 2796 | +void tSineTriLFO_init (tSineTriLFO* const cy, LEAF* const leaf) |
| 2797 | +{ |
| 2798 | + tSineTriLFO_initToPool(cy, &leaf->mempool); |
| 2799 | + _tSineTriLFO* c = *cy; |
| 2800 | +} |
| 2801 | + |
| 2802 | +void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp) |
| 2803 | +{ |
| 2804 | + _tMempool* m = *mp; |
| 2805 | + _tSineTriLFO* c = *cy = (_tSineTriLFO*) mpool_alloc(sizeof(_tSineTriLFO), m); |
| 2806 | + c->mempool = m; |
| 2807 | + LEAF* leaf = c->mempool->leaf; |
| 2808 | + tTriLFO_initToPool(&c->tri,mp); |
| 2809 | + tCycle_initToPool(&c->sine,mp); |
| 2810 | + |
| 2811 | +} |
| 2812 | +void tSineTriLFO_free (tSineTriLFO* const cy) |
| 2813 | +{ |
| 2814 | + _tSineTriLFO* c = *cy; |
| 2815 | + tCycle_free(&c->sine); |
| 2816 | + tTriLFO_free(&c->tri); |
| 2817 | + mpool_free((char*)c, c->mempool); |
| 2818 | +} |
| 2819 | + |
| 2820 | +float tSineTriLFO_tick (tSineTriLFO* const cy) |
| 2821 | +{ |
| 2822 | + _tSineTriLFO* c = *cy; |
| 2823 | + float a = tCycle_tick(&c->sine); |
| 2824 | + float b = tTriLFO_tick(&c->tri); |
| 2825 | + return (1 - c->shape) * a + c->shape * b; |
| 2826 | +} |
| 2827 | +void tSineTriLFO_setFreq (tSineTriLFO* const cy, float freq) |
| 2828 | +{ |
| 2829 | + _tSineTriLFO* c = *cy; |
| 2830 | + tTriLFO_setFreq(&c->tri, freq); |
| 2831 | + tCycle_setFreq(&c->sine, freq); |
| 2832 | +} |
| 2833 | +void tSineTriLFO_setSampleRate (tSineTriLFO* const cy, float sr) |
| 2834 | +{ |
| 2835 | + _tSineTriLFO* c = *cy; |
| 2836 | + tTriLFO_setSampleRate(&c->tri, sr); |
| 2837 | + tCycle_setSampleRate(&c->sine, sr); |
| 2838 | +} |
| 2839 | +void tSineTriLFO_setPhase (tSineTriLFO* const cy, float phase) |
| 2840 | +{ |
| 2841 | + _tSineTriLFO* c = *cy; |
| 2842 | + tTriLFO_setPhase(&c->tri, phase); |
| 2843 | + tCycle_setPhase(&c->sine, phase); |
| 2844 | +} |
| 2845 | + |
| 2846 | + void tSineTriLFO_setShape (tSineTriLFO* const cy, float shape) |
| 2847 | + { |
| 2848 | + _tSineTriLFO* c = *cy; |
| 2849 | + c->shape = shape; |
| 2850 | + |
| 2851 | + } |