<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

void column_to_PCM(FILE *sound_out, float *column_intensity, int y, int sample_rate)
{
  float top_freq = (float) sample_rate / 2;
  float y_slice =  top_freq / y;
  int column_width = sample_rate / 25;
  float *buf_out = malloc(sizeof(double) * column_width);
  float sample = 0;
  for (int i = 0; i < column_width; i++) {
    float envelope_multiplier = sin(M_PI * ((float) i /  column_width));
    for (int j = 0; j < y; j++) {
      float freq = top_freq - (y_slice * j);
      sample += (column_intensity[j] * (sin(2 * M_PI * freq *  ((float) i / sample_rate)) * envelope_multiplier)) / y;
    }
    sample *= .95;
    buf_out[i] = sample;
  }
  fwrite(buf_out, sizeof(float) * column_width, 1, sound_out);
  free(buf_out);
}

int get_point_index(int this_x, int this_y, int x, int n)
{
  return (this_y * (x * n)) + this_x * n;
}

float get_pixel_intensity(unsigned char *data, int n)
{
  int RGB_sum = 0;
  for (int i = 0; i < n; i++) {
    RGB_sum += data[i];
  }
  float intensity = ((float) RGB_sum / n) / 255;
  return intensity;
}

int main(int argc, char **argv)
{
  if (argc != 3) {
    fprintf(stderr, "Usage: spectrophoto <inputfile> <outputfile>\n");
    fprintf(stderr, "https://github.com/kylophone/spectrophoto\n");
    return(-1);
  }

  int x,y,n;
  const char *inputFile = argv[1];
  unsigned char *data = stbi_load(inputFile, &x, &y, &n, 1);
  if (!data) {
    fprintf(stderr, "Couldn't load image: %s\n", inputFile); 
    return(-1);
  }

  const char *outputFile = argv[2];
  FILE *file = fopen(outputFile, "wb");
  if (!file) {
    fprintf(stderr, "Couldn't open file: %s\n", outputFile); 
    return(-1);
  }

  float *this_column_intensity = malloc(sizeof(float) * y);
  for (int this_x = 0; this_x < x; this_x++) {
    for (int this_y = 0; this_y < y; this_y++) {
      int this_index = get_point_index(this_x, this_y, x, 1);
      float this_intensity = get_pixel_intensity(&data[this_index], 1);
      this_column_intensity[this_y] = this_intensity;
    }
    column_to_PCM(file, this_column_intensity, y, 48000);
  }

  free(this_column_intensity);
  fclose(file);
  stbi_image_free(data);
  return(0);
}
<commit_msg>do not hardcode program name into usage message<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

void column_to_PCM(FILE *sound_out, float *column_intensity, int y, int sample_rate)
{
  float top_freq = (float) sample_rate / 2;
  float y_slice =  top_freq / y;
  int column_width = sample_rate / 25;
  float *buf_out = malloc(sizeof(double) * column_width);
  float sample = 0;
  for (int i = 0; i < column_width; i++) {
    float envelope_multiplier = sin(M_PI * ((float) i /  column_width));
    for (int j = 0; j < y; j++) {
      float freq = top_freq - (y_slice * j);
      sample += (column_intensity[j] * (sin(2 * M_PI * freq *  ((float) i / sample_rate)) * envelope_multiplier)) / y;
    }
    sample *= .95;
    buf_out[i] = sample;
  }
  fwrite(buf_out, sizeof(float) * column_width, 1, sound_out);
  free(buf_out);
}

int get_point_index(int this_x, int this_y, int x, int n)
{
  return (this_y * (x * n)) + this_x * n;
}

float get_pixel_intensity(unsigned char *data, int n)
{
  int RGB_sum = 0;
  for (int i = 0; i < n; i++) {
    RGB_sum += data[i];
  }
  float intensity = ((float) RGB_sum / n) / 255;
  return intensity;
}

int main(int argc, char **argv)
{
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <inputfile> <outputfile>\n", argv[0]);
    fprintf(stderr, "https://github.com/kylophone/spectrophoto\n");
    return(-1);
  }

  int x,y,n;
  const char *inputFile = argv[1];
  unsigned char *data = stbi_load(inputFile, &x, &y, &n, 1);
  if (!data) {
    fprintf(stderr, "Couldn't load image: %s\n", inputFile); 
    return(-1);
  }

  const char *outputFile = argv[2];
  FILE *file = fopen(outputFile, "wb");
  if (!file) {
    fprintf(stderr, "Couldn't open file: %s\n", outputFile); 
    return(-1);
  }

  float *this_column_intensity = malloc(sizeof(float) * y);
  for (int this_x = 0; this_x < x; this_x++) {
    for (int this_y = 0; this_y < y; this_y++) {
      int this_index = get_point_index(this_x, this_y, x, 1);
      float this_intensity = get_pixel_intensity(&data[this_index], 1);
      this_column_intensity[this_y] = this_intensity;
    }
    column_to_PCM(file, this_column_intensity, y, 48000);
  }

  free(this_column_intensity);
  fclose(file);
  stbi_image_free(data);
  return(0);
}

{'fraction_non_alphanumeric': 0.1538788522848034, 'fraction_numerical': 0.022741764080765142, 'mean_word_length': 3.618253189401374, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '3896440', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1829, 'n_words': 458}