All pastes #35534 Raw Edit

Mine

public text v1 · immutable
#35534 ·published 2006-01-02 16:02 UTC
rendered paste body
/*  
** note.h for underScore in /home/sithy/projects/underscore
** 
** Made by Guillaume Barbanchon
** Login   <barban_g@epita.fr>
** 
** Started on  Mon Jan  2 15:35:02 2006 Guillaume Barbanchon
** Last update Mon Jan  2 15:45:05 2006 Guillaume Barbanchon
*/
#include<math.h>

#define FREQ_A_STD 440

typedef enum
{
  A=0,
  A_SHARP,
  B,
  C,
  C_SHARP,
  D,
  D_SHARP,
  E,
  F,
  F_SHARP,
  G,
  G_SHARP
} t_note_name;

/*  
** note.c for underScore in /home/sithy/projects/underscore
** 
** Made by Guillaume Barbanchon
** Login   <barban_g@epita.fr>
** 
** Started on  Mon Jan  2 15:35:02 2006 Guillaume Barbanchon
** Last update Mon Jan  2 15:45:05 2006 Guillaume Barbanchon
*/
#include<stdlib.h>
#include<stdio.h>
#include"note.h"

#define freq2dist(freq_note, freq_a_ref) (log(freq_note / freq_a_ref) * 12 / log(2))

#define print_freq2dist(freq) (printf("%i Hz \t %f \t %f \t %s \n", (int) freq, freq2dist(freq,FREQ_A_STD), round(freq2dist(freq,FREQ_A_STD)), note_name2string(((((int) round(freq2dist(freq,FREQ_A_STD)))  + 99*12) % 12))))

char* note_name2string(t_note_name name)
{
  switch (name)
  {
    case A:
      return("A");
      break;
    case A_SHARP:
      return("A#");
      break;
    case B:
      return("B");
      break;
    case C:
      return("C");
      break;
    case C_SHARP:
      return("C#");
      break;
    case D:
      return("D");
      break;
    case D_SHARP:
      return("D#");
      break;
    case E:
      return("E");
      break;
    case F:
      return("F");
      break;
    case F_SHARP:
      return("F#");
      break;
    case G:
      return("G");
      break;
    case G_SHARP:
      return("G#");
      break;      
    default:
      return("NA");
  }
}

int main()
{
  printf("freq \t distance \t arrondi \t note \n");
  print_freq2dist(262.); /* C  */
  print_freq2dist(277.); /* C# */
  print_freq2dist(294.); /* D  */
  print_freq2dist(311.); /* E# */
  print_freq2dist(330.); /* E  */
  print_freq2dist(349.); /* F  */
  print_freq2dist(370.); /* F# */
  print_freq2dist(392.); /* G  */
  print_freq2dist(415.); /* G# */
  print_freq2dist(440.); /* A  */
  print_freq2dist(469.); /* A# */
  print_freq2dist(495.); /* B  */
  return EXIT_SUCCESS;
}

/* Ca donne qqch comme ca :

sithy@eddie ~/projects/underscore $ gcc -W -Wall -std=c99 -lm note.c -o note
sithy@eddie ~/projects/underscore $ ./note
freq     distance        arrondi         note
262 Hz   -8.975241       -9.000000       C
277 Hz   -8.011411       -8.000000       C#
294 Hz   -6.980248       -7.000000       D
311 Hz   -6.007067       -6.000000       D#
330 Hz   -4.980450       -5.000000       E
349 Hz   -4.011318       -4.000000       F
370 Hz   -2.999739       -3.000000       F#
392 Hz   -1.999798       -2.000000       G
415 Hz   -1.012706       -1.000000       G#
440 Hz   0.000000        0.000000        A
469 Hz   1.105013        1.000000        A#
495 Hz   2.039100        2.000000        B
sithy@eddie ~/projects/underscore $ cowsay "r0x0r :)"
 __________
< r0x0r :) >
 ----------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

*/