<commit_before>/*
    Copyright 2012-2013 Samplecount S.L.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "methc.la/plugins/sine/sine.h"

typedef enum {
    kSine_freq,
    kSine_out,
    kSinePorts
} PortIndex;

typedef struct {
    float* ports[kSinePorts];
    double phase;
    double freqToPhaseInc;
} Sine;

static const Methcla_PortDescriptor kPortDescriptors[] = {
    { .type = kMethcla_ControlPort, .direction = kMethcla_Input, .flags = kMethcla_PortFlags },
    { .type = kMethcla_AudioPort, .direction = kMethcla_Output, .flags = kMethcla_PortFlags }
};

static bool
port_descriptor( const Methcla_SynthOptions* options
               , size_t index
               , Methcla_PortDescriptor* port )
{
    if (index < kSinePorts) {
        *port = kPortDescriptors[index];
        return true;
    }
    return false;
}

static void print_freq(const Methcla_Host* host, void* data)
{
    Sine* sine = (Sine*)data;
    fprintf(stderr, "SINE_FREQ [NRT]: %f\n", *sine->ports[kSine_freq]);
}

static void
construct( const Methcla_World* world
         , const Methcla_SynthDef* synthDef
         , const Methcla_SynthOptions* options
         , Methcla_Synth* synth )
{
    Sine* sine = (Sine*)synth;
    sine->phase = 0.;
    sine->freqToPhaseInc = 2.*M_PI/methcla_world_samplerate(world);
    methcla_world_perform_command(world, print_freq, sine);
}

static void
connect( Methcla_Synth* synth
       , size_t port
       , void* data)
{
    ((Sine*)synth)->ports[port] = (float*)data;
}

static void
process(const Methcla_World* world, Methcla_Synth* synth, size_t numFrames)
{
    Sine* sine = (Sine*)synth;

    const float  freq     = *sine->ports[kSine_freq];
    double phase          = sine->phase;
    const double phaseInc = freq * sine->freqToPhaseInc;
    float* const output   = sine->ports[kSine_out];

    for (size_t k = 0; k < numFrames; k++) {<commit_msg>Don't print frequency in sine plugin<commit_after>/*
    Copyright 2012-2013 Samplecount S.L.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "methc.la/plugins/sine/sine.h"

typedef enum {
    kSine_freq,
    kSine_out,
    kSinePorts
} PortIndex;

typedef struct {
    float* ports[kSinePorts];
    double phase;
    double freqToPhaseInc;
} Sine;

static const Methcla_PortDescriptor kPortDescriptors[] = {
    { .type = kMethcla_ControlPort, .direction = kMethcla_Input, .flags = kMethcla_PortFlags },
    { .type = kMethcla_AudioPort, .direction = kMethcla_Output, .flags = kMethcla_PortFlags }
};

static bool
port_descriptor( const Methcla_SynthOptions* options
               , size_t index
               , Methcla_PortDescriptor* port )
{
    if (index < kSinePorts) {
        *port = kPortDescriptors[index];
        return true;
    }
    return false;
}

// static void print_freq(const Methcla_Host* host, void* data)
// {
//     Sine* sine = (Sine*)data;
//     fprintf(stderr, "SINE_FREQ [NRT]: %f\n", *sine->ports[kSine_freq]);
// }

static void
construct( const Methcla_World* world
         , const Methcla_SynthDef* synthDef
         , const Methcla_SynthOptions* options
         , Methcla_Synth* synth )
{
    Sine* sine = (Sine*)synth;
    sine->phase = 0.;
    sine->freqToPhaseInc = 2.*M_PI/methcla_world_samplerate(world);
    // methcla_world_perform_command(world, print_freq, sine);
}

static void
connect( Methcla_Synth* synth
       , size_t port
       , void* data)
{
    ((Sine*)synth)->ports[port] = (float*)data;
}

static void
process(const Methcla_World* world, Methcla_Synth* synth, size_t numFrames)
{
    Sine* sine = (Sine*)synth;

    const float  freq     = *sine->ports[kSine_freq];
    double phase          = sine->phase;
    const double phaseInc = freq * sine->freqToPhaseInc;
    float* const output   = sine->ports[kSine_out];

    for (size_t k = 0; k < numFrames; k++) {
{'fraction_non_alphanumeric': 0.10317301935741369, 'fraction_numerical': 0.005986828976252245, 'mean_word_length': 3.211764705882353, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6428615', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1678, 'n_words': 461}