<commit_before>// This file is part of VLevel, a dynamic volume normalizer.

//  ___         _ _         _    _     _   _        
// | _ \__ _ __| (_)___  __(_)__| |___| |_| |_ __ _ 
// |   / _` / _` | / _ \/ _| / _| / -_)  _|  _/ _` |
// |_|_\__,_\__,_|_\___/\__|_\__|_\___|\__|\__\__,_|
//           La radio sempre in bolletta.

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

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

#include <limits.h>
#include <assert.h>

#include <jack/jack.h>
#include <jack/ringbuffer.h>
#include <unistd.h>

#include "../volumeleveler/volumeleveler.h"
#include "commandline.h"

using namespace std;

typedef jack_default_audio_sample_t sample_t;

size_t sample_size = sizeof(jack_default_audio_sample_t);

size_t             channels          =  2;
value_t            strength          = .8;
value_t            max_multiplier    = 20;

jack_client_t     * client           = NULL;
VolumeLeveler     * leveler          = NULL;

jack_port_t     ** input_ports       = NULL;
jack_port_t     ** output_ports      = NULL;

value_t          * input_buffers     = NULL;
value_t          * output_buffers    = NULL;

value_t         ** input_bufferlist  = NULL;
value_t         ** output_bufferlist = NULL;


int vlevel_buffer_size_change_callback(jack_nframes_t nframes, void *arg)
{
    size_t buffer_size = sizeof(value_t) * nframes;

    if (leveler)
    {
        delete leveler;

        free(input_buffers);
        free(output_buffers);
    }

    input_bufferlist  = (value_t **) calloc(channels, sizeof(value_t *));
    output_bufferlist = (value_t **) calloc(channels, sizeof(value_t *));
    input_buffers     = (value_t  *) calloc(channels, buffer_size);
    output_buffers    = (value_t  *) calloc(channels, buffer_size);

    for (int i = 0; i < channels; i++)
    {
        input_bufferlist[i]  = &input_buffers[i];
        output_bufferlist[i] = &output_buffers[i];
    }

    leveler = new VolumeLeveler(jack_get_sample_rate(client),
                                channels,
                                strength,
                                max_multiplier);

    return 0;
}

int vlevel_process_callback(jack_nframes_t nframes, void *arg)
{
    for (int i = 0; i < channels; i++)
    {
        sample_t * jack_input = (sample_t *)jack_port_get_buffer(input_ports[i], nframes);
        ToValues((char *)jack_input, &input_buffers[i], nframes, sizeof(sample_t) * 8, true);
    }

    leveler->Exchange(input_bufferlist, output_bufferlist, nframes);

    for (int i = 0; i < channels; i++)
    {
        sample_t * jack_output = (sample_t *)jack_port_get_buffer(output_ports[i], nframes);
        FromValues(&output_buffers[i], (char *)jack_output, nframes, sizeof(sample_t) * 8, true);
    }

    return 0;
}

void jack_shutdown(void *arg)<commit_msg>"all audio data within JACK is represented as 32 bit floating point values"<commit_after>// This file is part of VLevel, a dynamic volume normalizer.

//  ___         _ _         _    _     _   _        
// | _ \__ _ __| (_)___  __(_)__| |___| |_| |_ __ _ 
// |   / _` / _` | / _ \/ _| / _| / -_)  _|  _/ _` |
// |_|_\__,_\__,_|_\___/\__|_\__|_\___|\__|\__\__,_|
//           La radio sempre in bolletta.

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

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

#include <limits.h>
#include <assert.h>

#include <jack/jack.h>
#include <jack/ringbuffer.h>
#include <unistd.h>

#include "../volumeleveler/volumeleveler.h"
#include "commandline.h"

using namespace std;

typedef jack_default_audio_sample_t sample_t;

size_t sample_size = sizeof(jack_default_audio_sample_t);

size_t             channels          =  2;
value_t            strength          = .8;
value_t            max_multiplier    = 20;

jack_client_t     * client           = NULL;
VolumeLeveler     * leveler          = NULL;

jack_port_t     ** input_ports       = NULL;
jack_port_t     ** output_ports      = NULL;

value_t         ** input_bufferlist  = NULL;
value_t         ** output_bufferlist = NULL;

int vlevel_buffer_size_change_callback(jack_nframes_t nframes, void *arg)
{
    size_t buffer_size = sizeof(value_t) * nframes;

    if (leveler)
    {
        delete leveler;

        free(input_bufferlist);
        free(output_bufferlist);
    }

    input_bufferlist  = (value_t **) calloc(channels, sizeof(value_t *));
    output_bufferlist = (value_t **) calloc(channels, sizeof(value_t *));

    leveler = new VolumeLeveler(jack_get_sample_rate(client),
                                channels,
                                strength,
                                max_multiplier);

    return 0;
}

int vlevel_process_callback(jack_nframes_t nframes, void *arg)
{
    for (int i = 0; i < channels; i++)
    {
        sample_t * jack_input  = (sample_t *)jack_port_get_buffer(input_ports[i],  nframes);
        sample_t * jack_output = (sample_t *)jack_port_get_buffer(output_ports[i], nframes);

        input_bufferlist[i]  = &jack_input[i];
        output_bufferlist[i] = &jack_output[i];
    }

    leveler->Exchange(input_bufferlist, output_bufferlist, nframes);

    return 0;
}

void jack_shutdown(void *arg)
{'fraction_non_alphanumeric': 0.12282379950258274, 'fraction_numerical': 0.003826286588865506, 'mean_word_length': 2.4440052700922266, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3920573', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1796, 'n_words': 343}