<commit_before><!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>

        <div>Sample</div>
        <canvas width="3000" height="128" id="buffer-sample" style="border: 1px solid red;"></canvas>
        <div>Power</div>
        <canvas width="3000" height="128" id="buffer-power" style="border: 1px solid green;"></canvas>
        <div>Phase</div>
        <canvas width="3000" height="128" id="buffer-phase" style="border: 1px solid green;"></canvas>

        <div>Constellation</div>
        <canvas width="512" height="512" id="constellation-diagram" style="border: 1px solid green;"></canvas>


        <input type="number" id="samples-per-period" onChange="onSamplesPerPeriodChange(this)" value="40" />

        <script src="../audio-util/audio-util.js"></script>
        <script src="carrier-recovery.factory.js"></script>
        <script src="carrier-recovery-builder.service.js"></script>

        <script>

            var
                samplesPerPeriod = 40,
                omegaFirst = (2 * Math.PI) / (samplesPerPeriod + 0),
                omegaSecond = (2 * Math.PI) / (samplesPerPeriod + 10),
                omegaThird = (2 * Math.PI) / (samplesPerPeriod + 20),
                carrierRecovery = CarrierRecoveryBuilder.build(samplesPerPeriod),
                bufferSample = [],
                bufferPower = [],
                bufferPhase = [],
                dataFirst = [
                    { amplitude: +0.00, phaseOffset: +0.00, omega: 1.00 * omegaFirst, duration: 5.00 * samplesPerPeriod },
                    { amplitude: +0.30, phaseOffset: +0.125, omega: 1.00 * omegaFirst, duration: 16.00 * samplesPerPeriod },
                    { amplitude: +0.00, phaseOffset: +0.00, omega: 1.00 * omegaFirst, duration: 10.00 * samplesPerPeriod }
                ],
                dataSecond = [
                    { amplitude: +0.00, phaseOffset: +0.00, omega: 1.00 * omegaSecond, duration: 5.00 * samplesPerPeriod },
                    { amplitude: +0.30, phaseOffset: +0.125 + 0.25, omega: 1.00 * omegaSecond, duration: 16.00 * samplesPerPeriod },
                    { amplitude: +0.00, phaseOffset: +0.00, omega: 1.00 * omegaSecond, duration: 10.00 * samplesPerPeriod }
                ],
                dataThird = [
                    { amplitude: +0.00, phaseOffset: +0.00, omega: 1.00 * omegaThird, duration: 5.00 * samplesPerPeriod },
                    { amplitude: +0.30, phaseOffset: +0.625, omega: 1.00 * omegaThird, duration: 16.00 * samplesPerPeriod },
                    { amplitude: +0.00, phaseOffset: +0.00, omega: 1.00 * omegaThird, duration: 10.00 * samplesPerPeriod }
                ];

            function onSamplesPerPeriodChange(input) {
                carrierRecovery.setSamplesPerPeriod(parseInt(input.value));
                nextFrame();
            }

            function fillBuffer(buffer, start, stop, sampleCallback) {
                var i, x;

                for (i = start; i < stop; i++) {
                    x = i - start;

                    if (i < buffer.length) {
                        buffer[i] += sampleCallback(x);
                    } else {
                        buffer[i] = sampleCallback(x);
                    }
                }
            }

            function fillBufferSample(bufferSample, data) {
                var start = 0, stop = 0, i, d;

                for (i = 0; i < data.length; i++) {
                    d = data[i];
                    start = stop;
                    stop = start + d.duration;
                    fillBuffer(bufferSample, start, stop, function (x) {
                        return (
                            d.amplitude *
                            Math.sin(
                              d.omega * x - 2 * Math.PI * d.phaseOffset
                            )
                        );
                    });
                }
            }

            function addNoise(buffer) {
                var i;

                for (i = 0; i < buffer.length; i++) {
                    buffer[i] += ((Math.random() * 2) - 1.0) * 0.2;
                }
            }

            function draw(canvasId, buffer) {
                var i;
                var canvas = document.getElementById(canvasId);
                var ctx = canvas.getContext("2d");
                var offsetY;

                ctx.lineWidth = 1;
                ctx.strokeStyle = 'rgba(50, 150, 250, 1)';
                ctx.clearRect(0, 0, 3000, 128);
                for (i = 0; i < buffer.length; i++) {
                    offsetY = Math.round(buffer[i] * 64);
                    ctx.beginPath();
                    ctx.moveTo(i, 64);
                    ctx.lineTo(i, 64 - (offsetY === 0 ? 1 : offsetY));
                    ctx.closePath();
                    ctx.stroke();
                }
            }

            function drawConstellationDiagram(canvasId, bufferPhase, bufferPower) {
                var i;
                var canvas = document.getElementById(canvasId);
                var ctx = canvas.getContext("2d");
                var x, y;

                ctx.lineWidth = 1;
                ctx.strokeStyle = 'rgba(50, 150, 250, 1)';
                ctx.clearRect(0, 0, 512, 512);
                ctx.beginPath();
                ctx.moveTo(0, 256);
                ctx.lineTo(512, 256);
                ctx.closePath();
                ctx.stroke();
                ctx.beginPath();
                ctx.moveTo(256, 0);
                ctx.lineTo(256, 512);
                ctx.closePath();
                ctx.stroke();
                for (i = 0; i < bufferPhase.length; i++) {

                    if (i < 512 || i > 560) {
                        continue;
                    }
                    x = 256 + 256 * 2 * bufferPower[i] * Math.cos(2 * Math.PI * bufferPhase[i]);
                    y = 256 - 256 * 2 * bufferPower[i] * Math.sin(2 * Math.PI * bufferPhase[i]);
                    ctx.fillRect(x - 1, y - 1, 3, 3);
                }
            }

            function analyzeBufferSample(bufferSample, bufferPower, bufferPhase) {
                var i, carrierSample;

                for (i = 0; i < bufferSample.length; i++) {
                    carrierRecovery.handleSample(bufferSample[i]);
                    carrierSample = carrierRecovery.getCarrier();

                    bufferPower.push(
                        carrierSample.power
                    );

                    bufferPhase.push(
                        carrierSample.phase
                    );
                }
            }

            function nextFrame() {
                bufferSample.length = 0;
                bufferPower.length = 0;
                bufferPhase.length = 0;

                fillBufferSample(bufferSample, dataFirst);
                fillBufferSample(bufferSample, dataSecond);
                fillBufferSample(bufferSample, dataThird);

                addNoise(bufferSample);

                analyzeBufferSample(bufferSample, bufferPower, bufferPhase);

                draw('buffer-sample', bufferSample);
                draw('buffer-power', bufferPower);<commit_msg>data sending tests<commit_after><!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>

        <div>Sample</div>
        <canvas width="3000" height="128" id="buffer-sample" style="border: 1px solid red;"></canvas>
        <div>Power</div>
        <canvas width="3000" height="128" id="buffer-power" style="border: 1px solid green;"></canvas>
        <div>Phase</div>
        <canvas width="3000" height="128" id="buffer-phase" style="border: 1px solid green;"></canvas>

        <div>Constellation</div>
        <canvas width="512" height="512" id="constellation-diagram" style="border: 1px solid green;"></canvas>


        <input type="number" id="samples-per-period" onChange="onSamplesPerPeriodChange(this)" value="40" />

        <script src="../audio-util/audio-util.js"></script>
        <script src="carrier-recovery.factory.js"></script>
        <script src="carrier-recovery-builder.service.js"></script>

        <script>

            var
                samplesPerPeriodFirst = 40,
                samplesPerPeriodSecond = 60,
                samplesPerPeriodThird = 80,
                omegaFirst = (2 * Math.PI) / samplesPerPeriodFirst,
                omegaSecond = (2 * Math.PI) / samplesPerPeriodSecond,
                omegaThird = (2 * Math.PI) / samplesPerPeriodThird,
                carrierRecovery = CarrierRecoveryBuilder.build(samplesPerPeriodFirst),
                bufferSample = [],
                bufferPower = [],
                bufferPhase = [],
                dataFirst = [
                    { amplitude: +0.00, phaseOffset: +0.000, omega: 1.00 * omegaFirst, duration: 5.00 * samplesPerPeriodFirst },
                    { amplitude: +0.30, phaseOffset: +0.125 + 0.000, omega: 1.00 * omegaFirst, duration: 16.00 * samplesPerPeriodFirst },
                    { amplitude: +0.00, phaseOffset: +0.000, omega: 1.00 * omegaFirst, duration: 10.00 * samplesPerPeriodFirst }
                ],
                dataSecond = [
                    { amplitude: +0.00, phaseOffset: +0.000, omega: 1.00 * omegaSecond, duration: 5.00 * samplesPerPeriodSecond },
                    { amplitude: +0.30, phaseOffset: +0.125 + 0.250, omega: 1.00 * omegaSecond, duration: 16.00 * samplesPerPeriodSecond },
                    { amplitude: +0.00, phaseOffset: +0.000, omega: 1.00 * omegaSecond, duration: 10.00 * samplesPerPeriodSecond }
                ],
                dataThird = [
                    { amplitude: +0.00, phaseOffset: +0.000, omega: 1.00 * omegaThird, duration: 5.00 * samplesPerPeriodThird },
                    { amplitude: +0.30, phaseOffset: +0.125 + 0.500, omega: 1.00 * omegaThird, duration: 16.00 * samplesPerPeriodThird },
                    { amplitude: +0.00, phaseOffset: +0.000, omega: 1.00 * omegaThird, duration: 10.00 * samplesPerPeriodThird }
                ];

            function onSamplesPerPeriodChange(input) {
                carrierRecovery.setSamplesPerPeriod(parseInt(input.value));
                nextFrame();
            }

            function fillBuffer(buffer, start, stop, sampleCallback) {
                var i, x;

                for (i = start; i < stop; i++) {
                    x = i - start;

                    if (i < buffer.length) {
                        buffer[i] += sampleCallback(x);
                    } else {
                        buffer[i] = sampleCallback(x);
                    }
                }
            }

            function fillBufferSample(bufferSample, data) {
                var start = 0, stop = 0, i, d;

                for (i = 0; i < data.length; i++) {
                    d = data[i];
                    start = stop;
                    stop = start + d.duration;
                    fillBuffer(bufferSample, start, stop, function (x) {
                        return (
                            d.amplitude *
                            Math.sin(
                              d.omega * x - 2 * Math.PI * d.phaseOffset
                            )
                        );
                    });
                }
            }

            function addNoise(buffer) {
                var i;

                for (i = 0; i < buffer.length; i++) {
                    buffer[i] += ((Math.random() * 2) - 1.0) * 0.2;
                }
            }

            function draw(canvasId, buffer) {
                var i;
                var canvas = document.getElementById(canvasId);
                var ctx = canvas.getContext("2d");
                var offsetY;

                ctx.lineWidth = 1;
                ctx.strokeStyle = 'rgba(150, 150, 250, 1)';
                ctx.clearRect(0, 0, 3000, 128);
                for (i = 0; i < buffer.length; i++) {
                    offsetY = Math.round(buffer[i] * 64);
                    ctx.beginPath();
                    ctx.moveTo(i, 64);
                    ctx.lineTo(i, 64 - (offsetY === 0 ? 1 : offsetY));
                    ctx.closePath();
                    ctx.stroke();
                }
            }

            function drawConstellationDiagram(canvasId, bufferPhase, bufferPower) {
                var i;
                var canvas = document.getElementById(canvasId);
                var ctx = canvas.getContext("2d");
                var x, y;

                ctx.fillStyle = 'rgba(130, 130, 230, 1)';

                ctx.lineWidth = 1;
                ctx.strokeStyle = 'rgba(130, 130, 230, 1)';
                ctx.clearRect(0, 0, 512, 512);
                ctx.beginPath();
                ctx.moveTo(0, 256);
                ctx.lineTo(512, 256);
                ctx.closePath();
                ctx.stroke();
                ctx.beginPath();
                ctx.moveTo(256, 0);
                ctx.lineTo(256, 512);
                ctx.closePath();
                ctx.stroke();
                for (i = 0; i < bufferPhase.length; i++) {
                    if (i < 512 || i > 560) {
                        continue;
                    }
                    x = 256 + 256 * 3 * bufferPower[i] * Math.cos(2 * Math.PI * bufferPhase[i]);
                    y = 256 - 256 * 3 * bufferPower[i] * Math.sin(2 * Math.PI * bufferPhase[i]);
                    ctx.fillRect(x - 1, y - 1, 3, 3);
                }
            }

            function analyzeBufferSample(bufferSample, bufferPower, bufferPhase) {
                var i, carrierSample;

                for (i = 0; i < bufferSample.length; i++) {
                    carrierRecovery.handleSample(bufferSample[i]);
                    carrierSample = carrierRecovery.getCarrier();

                    bufferPower.push(
                        carrierSample.power
                    );

                    bufferPhase.push(
                        carrierSample.phase
                    );
                }
            }

            function nextFrame() {
                bufferSample.length = 0;
                bufferPower.length = 0;
                bufferPhase.length = 0;

                fillBufferSample(bufferSample, dataFirst);
                fillBufferSample(bufferSample, dataSecond);
                fillBufferSample(bufferSample, dataThird);

                //addNoise(bufferSample);

                analyzeBufferSample(bufferSample, bufferPower, bufferPhase);

                draw('buffer-sample', bufferSample);
                draw('buffer-power', bufferPower);
{'fraction_non_alphanumeric': 0.12073329229085437, 'fraction_numerical': 0.03912716328066215, 'mean_word_length': 1.2994652406417113, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 69, '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': '1752336', 'n_tokens_mistral': 4462, 'n_tokens_neox': 3704, 'n_words': 839}