<commit_before>(function(timbre) {
    "use strict";
    
    function Oscillator(_args) {
        timbre.Object.call(this, _args);
        
        this._.phase = 0;
        this._.x     = 0;
        this._.coeff = 1024 / timbre.samplerate;

        this.once("init", function() {
            var _ = this._;
            if (!_.wave) {
                this.wave = "sin";
            }
            if (!_.freq) {
                this.freq = 440;
            }
            this._.plotData = this._.wave;
            this._.plotLineWidth = 2;
            this._.plotCyclic = true;
            this._.plotBefore = plotBefore;
        });
    }
    timbre.fn.extend(Oscillator, timbre.Object);
    
    var $ = Oscillator.prototype;
    
    Object.defineProperties($, {
        wave: {
            set: function(value) {
                if (!this._.wave) {
                    this._.wave = new Float32Array(1024);
                }
                var dx, wave = this._.wave;
                var i;
                if (typeof value === "function") {
                    for (i = 0; i < 1024; ++i) {
                        wave[i] = value(i / 1024);
                    }
                } else if (value instanceof Float32Array) {
                    if (value.length === wave.length) {
                        wave.set(value);
                    } else {
                        dx = value.length / 1024;
                        for (i = 0; i < 1024; ++i) {
                            wave[i] = value[(i * dx)|0];
                        }
                    }
                } else if (typeof value === "string") {
                    if ((dx = this.getWavetable(value)) !== undefined) {
                        this._.wave = dx;
                    }
                }
            },
            get: function() {
                return this._.wave;
            }
        },
        freq: {
            set: function(value) {
                this._.freq = timbre(value);
            },
            get: function() {
                return this._.freq;
            }
        },
        phase: {
            set: function(value) {
                if (typeof value === "number") {
                    while (value >= 1.0) {
                        value -= 1.0;
                    }
                    while (value <  0.0) {
                        value += 1.0;
                    }
                    this._.phase = value;
                    this._.x = 1024 * this._.phase;
                }
            },
            get: function() {
                return this._.phase;
            }
        }
    });
    
    $.bang = function() {
        this._.x = 1024 * this._.phase;
        this.emit("bang");
        return this;
    };

    $.seq = function(seq_id) {
        var _ = this._;
        var cell = this.cell;
        
        if (this.seq_id !== seq_id) {
            this.seq_id = seq_id;
            
            var freq = _.freq.seq(seq_id);
            var mul  = _.mul , add = _.add;
            var wave = _.wave, x   = _.x, coeff = _.coeff;
            var index, delta, x0, x1, xx, dx;
            var i, imax;
            
            if (_.ar) { // audio-rate
                if (_.freq.isAr) {
                    for (i = 0, imax = cell.length; i < imax; ++i) {
                        index = x|0;
                        delta = x - index;
                        x0 = wave[index & 1023];
                        x1 = wave[(index+1) & 1023];
                        cell[i] = ((1.0 - delta) * x0 + delta * x1) * mul + add;
                        x += freq[i] * coeff;
                    }
                } else { // _.freq.isKr
                    dx = freq[0] * coeff;
                    for (i = 0, imax = cell.length; i < imax; ++i) {
                        index = x|0;
                        delta = x - index;
                        x0 = wave[index & 1023];
                        x1 = wave[(index+1) & 1023];
                        cell[i] = ((1.0 - delta) * x0 + delta * x1) * mul + add;
                        x += dx;
                    }
                }
            } else {    // control-rate
                index = x|0;
                delta = x - index;
                x0 = wave[index & 1023];
                x1 = wave[(index+1) & 1023];
                xx = ((1.0 - delta) * x0 + delta * x1) * mul + add;
                for (i = imax = cell.length; i--; ) {
                    cell[i] = xx;
                }
                x += freq[0] * coeff * imax;
            }
            while (x > 1024) {
                x -= 1024;
            }
            _.x = x;
        }
        
        return cell;
    };

    var plotBefore;
    if (timbre.envtype === "browser") {
        plotBefore = function(context, offset_x, offset_y, width, height) {
            var y = (height >> 1) + 0.5;
            context.strokeStyle = "#ccc";
            context.lineWidth   = 1;
            context.beginPath();
            context.moveTo(offset_x, y + offset_y);
            context.lineTo(offset_x + width, y + offset_y);
            context.stroke();
        };
    }
    
    function waveshape(sign, name, shape, width) {
        var wave = Wavetables[name];
        var _wave;
        var i, imax, j, jmax;
        
        if (wave === undefined) {
            return;
        }<commit_msg>fixed T("osc").inputs<commit_after>(function(timbre) {
    "use strict";
    
    function Oscillator(_args) {
        timbre.Object.call(this, _args);
        
        this._.phase = 0;
        this._.x     = 0;
        this._.coeff = 1024 / timbre.samplerate;

        this.once("init", function() {
            var _ = this._;
            if (!_.wave) {
                this.wave = "sin";
            }
            if (!_.freq) {
                this.freq = 440;
            }
            this._.plotData = this._.wave;
            this._.plotLineWidth = 2;
            this._.plotCyclic = true;
            this._.plotBefore = plotBefore;
        });
    }
    timbre.fn.extend(Oscillator, timbre.Object);
    
    var $ = Oscillator.prototype;
    
    Object.defineProperties($, {
        wave: {
            set: function(value) {
                if (!this._.wave) {
                    this._.wave = new Float32Array(1024);
                }
                var dx, wave = this._.wave;
                var i;
                if (typeof value === "function") {
                    for (i = 0; i < 1024; ++i) {
                        wave[i] = value(i / 1024);
                    }
                } else if (value instanceof Float32Array) {
                    if (value.length === wave.length) {
                        wave.set(value);
                    } else {
                        dx = value.length / 1024;
                        for (i = 0; i < 1024; ++i) {
                            wave[i] = value[(i * dx)|0];
                        }
                    }
                } else if (typeof value === "string") {
                    if ((dx = this.getWavetable(value)) !== undefined) {
                        this._.wave = dx;
                    }
                }
            },
            get: function() {
                return this._.wave;
            }
        },
        freq: {
            set: function(value) {
                this._.freq = timbre(value);
            },
            get: function() {
                return this._.freq;
            }
        },
        phase: {
            set: function(value) {
                if (typeof value === "number") {
                    while (value >= 1.0) {
                        value -= 1.0;
                    }
                    while (value <  0.0) {
                        value += 1.0;
                    }
                    this._.phase = value;
                    this._.x = 1024 * this._.phase;
                }
            },
            get: function() {
                return this._.phase;
            }
        }
    });
    
    $.bang = function() {
        this._.x = 1024 * this._.phase;
        this.emit("bang");
        return this;
    };

    $.seq = function(seq_id) {
        var _ = this._;
        var cell = this.cell;
        
        if (this.seq_id !== seq_id) {
            this.seq_id = seq_id;

            var inputs  = this.inputs;
            var i, imax = inputs.length;
            var j, jmax = cell.length;
            var mul = _.mul, add = _.add;
            var tmp;
            
            if (inputs.length) {
                for (j = jmax; j--; ) {
                    cell[j] = 0;
                }
                for (i = 0; i < imax; ++i) {
                    tmp = inputs[i].seq(seq_id);
                    for (j = jmax; j--; ) {
                        cell[j] += tmp[j];
                    }
                }
            } else {
                for (j = jmax; j--; ) {
                    cell[j] = 1;
                }
            }
            
            var freq = _.freq.seq(seq_id);
            var wave = _.wave, x   = _.x, coeff = _.coeff;
            var index, delta, x0, x1, xx, dx;
            
            if (_.ar) { // audio-rate
                if (_.freq.isAr) {
                    for (j = 0; j < jmax; ++j) {
                        index = x|0;
                        delta = x - index;
                        x0 = wave[index & 1023];
                        x1 = wave[(index+1) & 1023];
                        cell[j] *= ((1.0 - delta) * x0 + delta * x1);
                        x += freq[j] * coeff;
                    }
                } else { // _.freq.isKr
                    dx = freq[0] * coeff;
                    for (j = 0; j < jmax; ++j) {
                        index = x|0;
                        delta = x - index;
                        x0 = wave[index & 1023];
                        x1 = wave[(index+1) & 1023];
                        cell[j] *= ((1.0 - delta) * x0 + delta * x1);
                        x += dx;
                    }
                }
            } else {    // control-rate
                index = x|0;
                delta = x - index;
                x0 = wave[index & 1023];
                x1 = wave[(index+1) & 1023];
                xx = ((1.0 - delta) * x0 + delta * x1);
                for (j = jmax; j--; ) {
                    cell[j] *= xx;
                }
                x += freq[0] * coeff * jmax;
            }
            while (x > 1024) {
                x -= 1024;
            }
            _.x = x;
            
            for (j = jmax; j--; ) {
                cell[j] = cell[j] * mul + add;
            }
        }
        
        return cell;
    };

    var plotBefore;
    if (timbre.envtype === "browser") {
        plotBefore = function(context, offset_x, offset_y, width, height) {
            var y = (height >> 1) + 0.5;
            context.strokeStyle = "#ccc";
            context.lineWidth   = 1;
            context.beginPath();
            context.moveTo(offset_x, y + offset_y);
            context.lineTo(offset_x + width, y + offset_y);
            context.stroke();
        };
    }
    
    function waveshape(sign, name, shape, width) {
        var wave = Wavetables[name];
        var _wave;
        var i, imax, j, jmax;
        
        if (wave === undefined) {
            return;
        }
{'fraction_non_alphanumeric': 0.12701915438255804, 'fraction_numerical': 0.021272839615146966, 'mean_word_length': 0.8157051282051282, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7514055', 'n_tokens_mistral': 3440, 'n_tokens_neox': 3117, 'n_words': 719}