<commit_before>#include "cavacore.h"
#ifndef M_PI
#define M_PI 3.1415926535897932385
#endif
#include <fftw3.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

struct cava_plan *cava_init(int number_of_bars, unsigned int rate, int channels, int autosens,
                            double noise_reduction, int low_cut_off, int high_cut_off) {

    // sanity checks:
    if (channels < 1 || channels > 2) {
        fprintf(stderr,
                "cava_init called with illegal number of channels: %d, number of channels "
                "supported are "
                "1 and 2\n",
                channels);
        exit(1);
    }
    if (rate < 1 || rate > 384000) {
        fprintf(stderr, "cava_init called with illegal sample rate: %d\n", rate);
        exit(1);
    }

    int treble_buffer_size = 128;

    if (rate > 8125 && rate <= 16250)
        treble_buffer_size = 256;
    else if (rate > 16250 && rate <= 32500)
        treble_buffer_size = 512;
    else if (rate > 32500 && rate <= 75000)
        treble_buffer_size = 1024;
    else if (rate > 75000 && rate <= 150000)
        treble_buffer_size = 2048;
    else if (rate > 150000 && rate <= 300000)
        treble_buffer_size = 4096;
    else if (rate > 300000)
        treble_buffer_size = 8096;

    if (number_of_bars < 1) {
        fprintf(stderr,
                "cava_init called with illegal number of bars: %d, number of channels must be "
                "positive integer\n",
                number_of_bars);
        exit(1);
    }

    if (number_of_bars > treble_buffer_size / 2 + 1) {
        fprintf(stderr,
                "cava_init called with illegal number of bars: %d, for %d sample rate number of "
                "bars can't be more than %d "
                "positive integer\n",
                number_of_bars, rate, treble_buffer_size / 2 + 1);
        exit(1);
    }
    if (low_cut_off < 0 || high_cut_off < 0) {
        fprintf(stderr, "low_cut_off must be a positive value\n");
        exit(1);
    }
    if (low_cut_off >= high_cut_off) {
        fprintf(stderr, "high_cut_off must be a higher than low_cut_off\n");
        exit(1);
    }
    if ((unsigned int)high_cut_off > rate / 2) {<commit_msg>#445 do not allow 0 for low cut off, should be technicaly possible to visualize the the zero-frequency (DC) component, but seens as out of scope for now<commit_after>#include "cavacore.h"
#ifndef M_PI
#define M_PI 3.1415926535897932385
#endif
#include <fftw3.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

struct cava_plan *cava_init(int number_of_bars, unsigned int rate, int channels, int autosens,
                            double noise_reduction, int low_cut_off, int high_cut_off) {

    // sanity checks:
    if (channels < 1 || channels > 2) {
        fprintf(stderr,
                "cava_init called with illegal number of channels: %d, number of channels "
                "supported are "
                "1 and 2\n",
                channels);
        exit(1);
    }
    if (rate < 1 || rate > 384000) {
        fprintf(stderr, "cava_init called with illegal sample rate: %d\n", rate);
        exit(1);
    }

    int treble_buffer_size = 128;

    if (rate > 8125 && rate <= 16250)
        treble_buffer_size = 256;
    else if (rate > 16250 && rate <= 32500)
        treble_buffer_size = 512;
    else if (rate > 32500 && rate <= 75000)
        treble_buffer_size = 1024;
    else if (rate > 75000 && rate <= 150000)
        treble_buffer_size = 2048;
    else if (rate > 150000 && rate <= 300000)
        treble_buffer_size = 4096;
    else if (rate > 300000)
        treble_buffer_size = 8096;

    if (number_of_bars < 1) {
        fprintf(stderr,
                "cava_init called with illegal number of bars: %d, number of channels must be "
                "positive integer\n",
                number_of_bars);
        exit(1);
    }

    if (number_of_bars > treble_buffer_size / 2 + 1) {
        fprintf(stderr,
                "cava_init called with illegal number of bars: %d, for %d sample rate number of "
                "bars can't be more than %d "
                "positive integer\n",
                number_of_bars, rate, treble_buffer_size / 2 + 1);
        exit(1);
    }
    if (low_cut_off < 1 || high_cut_off < 1) {
        fprintf(stderr, "low_cut_off must be a positive value\n");
        exit(1);
    }
    if (low_cut_off >= high_cut_off) {
        fprintf(stderr, "high_cut_off must be a higher than low_cut_off\n");
        exit(1);
    }
    if ((unsigned int)high_cut_off > rate / 2) {
{'fraction_non_alphanumeric': 0.10357691463682248, 'fraction_numerical': 0.057493965328066714, 'mean_word_length': 2.0943652410047524, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, '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': '589219', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1460, 'n_words': 441}