<commit_before>/* See LICENSE file for copyright and license details. */
#include <math.h>
#include <sndfile.h>
#include <string.h>
#include <stdlib.h>

#include "./ebur128.h"

double test_global_loudness(const char* filename) {
  SF_INFO file_info;
  SNDFILE* file;
  sf_count_t nr_frames_read;

  ebur128_state* st = NULL;
  double gated_loudness;
  double* buffer;

  memset(&file_info, '\0', sizeof(file_info));
  file = sf_open(filename, SFM_READ, &file_info);
  if (!file) {
    fprintf(stderr, "Could not open file %s!\n", filename);
    return 0.0 / 0.0;
  }
  st = ebur128_init(file_info.channels,
                    file_info.samplerate,
                    EBUR128_MODE_I);
  if (file_info.channels == 5) {
    int channel_map_five[] = {EBUR128_LEFT,
                              EBUR128_RIGHT,
                              EBUR128_CENTER,
                              EBUR128_LEFT_SURROUND,
                              EBUR128_RIGHT_SURROUND};
    ebur128_set_channel_map(st, channel_map_five);
  }
  buffer = (double*) malloc(st->samplerate * st->channels * sizeof(double));
  while ((nr_frames_read = sf_readf_double(file, buffer,
                                           (sf_count_t) st->samplerate))) {
    ebur128_add_frames_double(st, buffer, (size_t) nr_frames_read);
  }

  gated_loudness = ebur128_loudness_global(st);

  /* clean up */
  ebur128_destroy(&st);

  free(buffer);
  buffer = NULL;
  if (sf_close(file)) {
    fprintf(stderr, "Could not close input file!\n");
  }
  return gated_loudness;
}

double test_loudness_range(const char* filename) {
  SF_INFO file_info;
  SNDFILE* file;
  sf_count_t nr_frames_read;

  ebur128_state* st = NULL;
  double loudness_range;
  double* buffer;

  memset(&file_info, '\0', sizeof(file_info));
  file = sf_open(filename, SFM_READ, &file_info);
  if (!file) {
    fprintf(stderr, "Could not open file %s!\n", filename);
    return 0.0 / 0.0;
  }
  st = ebur128_init(file_info.channels,
                    file_info.samplerate,
                    EBUR128_MODE_LRA);
  if (file_info.channels == 5) {
    int channel_map_five[] = {EBUR128_LEFT,
                              EBUR128_RIGHT,
                              EBUR128_CENTER,
                              EBUR128_LEFT_SURROUND,
                              EBUR128_RIGHT_SURROUND};
    ebur128_set_channel_map(st, channel_map_five);
  }
  buffer = (double*) malloc(st->samplerate * st->channels * sizeof(double));
  while ((nr_frames_read = sf_readf_double(file, buffer,
                                           (sf_count_t) st->samplerate))) {
    ebur128_add_frames_double(st, buffer, (size_t) nr_frames_read);
  }

  loudness_range = ebur128_loudness_range(st);

  /* clean up */
  ebur128_destroy(&st);

  free(buffer);
  buffer = NULL;
  if (sf_close(file)) {
    fprintf(stderr, "Could not close input file!\n");
  }
  return loudness_range;
}

double gr[] = {-23.0,
               -33.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0};
double gre[] = {-2.2953556442089987e+01,
                -3.2959860397340044e+01,
                -2.2995899818255047e+01,
                -2.3035918615414182e+01,
                -2.2949997446096436e+01,
                -2.3017157781104373e+01,
                -2.3017157781104373e+01,
                -2.2980242495081765e+01,
                -2.3009077718930541e+01};
double lra[] = {10.0,
                 5.0,
                20.0,
                15.0,
                 5.0,
                15.0};
double lrae[] = {1.0001105488329134e+01,
                 4.9993734051522178e+00,<commit_msg>adapt values in tests.c<commit_after>/* See LICENSE file for copyright and license details. */
#include <math.h>
#include <sndfile.h>
#include <string.h>
#include <stdlib.h>

#include "./ebur128.h"

double test_global_loudness(const char* filename) {
  SF_INFO file_info;
  SNDFILE* file;
  sf_count_t nr_frames_read;

  ebur128_state* st = NULL;
  double gated_loudness;
  double* buffer;

  memset(&file_info, '\0', sizeof(file_info));
  file = sf_open(filename, SFM_READ, &file_info);
  if (!file) {
    fprintf(stderr, "Could not open file %s!\n", filename);
    return 0.0 / 0.0;
  }
  st = ebur128_init(file_info.channels,
                    file_info.samplerate,
                    EBUR128_MODE_I);
  if (file_info.channels == 5) {
    int channel_map_five[] = {EBUR128_LEFT,
                              EBUR128_RIGHT,
                              EBUR128_CENTER,
                              EBUR128_LEFT_SURROUND,
                              EBUR128_RIGHT_SURROUND};
    ebur128_set_channel_map(st, channel_map_five);
  }
  buffer = (double*) malloc(st->samplerate * st->channels * sizeof(double));
  while ((nr_frames_read = sf_readf_double(file, buffer,
                                           (sf_count_t) st->samplerate))) {
    ebur128_add_frames_double(st, buffer, (size_t) nr_frames_read);
  }

  gated_loudness = ebur128_loudness_global(st);

  /* clean up */
  ebur128_destroy(&st);

  free(buffer);
  buffer = NULL;
  if (sf_close(file)) {
    fprintf(stderr, "Could not close input file!\n");
  }
  return gated_loudness;
}

double test_loudness_range(const char* filename) {
  SF_INFO file_info;
  SNDFILE* file;
  sf_count_t nr_frames_read;

  ebur128_state* st = NULL;
  double loudness_range;
  double* buffer;

  memset(&file_info, '\0', sizeof(file_info));
  file = sf_open(filename, SFM_READ, &file_info);
  if (!file) {
    fprintf(stderr, "Could not open file %s!\n", filename);
    return 0.0 / 0.0;
  }
  st = ebur128_init(file_info.channels,
                    file_info.samplerate,
                    EBUR128_MODE_LRA);
  if (file_info.channels == 5) {
    int channel_map_five[] = {EBUR128_LEFT,
                              EBUR128_RIGHT,
                              EBUR128_CENTER,
                              EBUR128_LEFT_SURROUND,
                              EBUR128_RIGHT_SURROUND};
    ebur128_set_channel_map(st, channel_map_five);
  }
  buffer = (double*) malloc(st->samplerate * st->channels * sizeof(double));
  while ((nr_frames_read = sf_readf_double(file, buffer,
                                           (sf_count_t) st->samplerate))) {
    ebur128_add_frames_double(st, buffer, (size_t) nr_frames_read);
  }

  loudness_range = ebur128_loudness_range(st);

  /* clean up */
  ebur128_destroy(&st);

  free(buffer);
  buffer = NULL;
  if (sf_close(file)) {
    fprintf(stderr, "Could not close input file!\n");
  }
  return loudness_range;
}

double gr[] = {-23.0,
               -33.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0,
               -23.0};
double gre[] = {-2.2953556442089987e+01,
                -3.2959860397340044e+01,
                -2.2995899818255047e+01,
                -2.3035918615414182e+01,
                -2.2949997446096436e+01,
                -2.3017157781104373e+01,
                -2.3017157781104373e+01,
                -2.2980242495081757e+01,
                -2.3009077718930545e+01};
double lra[] = {10.0,
                 5.0,
                20.0,
                15.0,
                 5.0,
                15.0};
double lrae[] = {1.0001105488329134e+01,
                 4.9993734051522178e+00,
{'fraction_non_alphanumeric': 0.11663505824979681, 'fraction_numerical': 0.09184502844757518, 'mean_word_length': 1.9055489964580874, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5278578', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2565, 'n_words': 448}