Mercurial > hg > libxtract
comparison src/scalar.c @ 211:ef80f7c52c6d
add VC2012 project to compile static and dynamic lib, also fix some C
issues
author | Q <andrea@nocte.co.uk> |
---|---|
date | Thu, 27 Mar 2014 09:48:26 +0000 |
parents | c99c00e1c508 |
children | 44401945d850 |
comparison
equal
deleted
inserted
replaced
210:c99c00e1c508 | 211:ef80f7c52c6d |
---|---|
870 | 870 |
871 sr = *(double *)argv; | 871 sr = *(double *)argv; |
872 if(sr == 0) | 872 if(sr == 0) |
873 sr = 44100.0; | 873 sr = 44100.0; |
874 | 874 |
875 input = (double *)malloc(bytes = N * sizeof(double)); | 875 input = (double*)malloc(bytes = N * sizeof(double)); |
876 input = memcpy(input, data, bytes); | 876 input = (double*)memcpy(input, data, bytes); |
877 /* threshold_peak = *((double *)argv+1); | 877 /* threshold_peak = *((double *)argv+1); |
878 threshold_centre = *((double *)argv+2); | 878 threshold_centre = *((double *)argv+2); |
879 printf("peak: %.2\tcentre: %.2\n", threshold_peak, threshold_centre);*/ | 879 printf("peak: %.2\tcentre: %.2\n", threshold_peak, threshold_centre);*/ |
880 /* add temporary dynamic control over thresholds to test clipping effects */ | 880 /* add temporary dynamic control over thresholds to test clipping effects */ |
881 | 881 |
940 } | 940 } |
941 | 941 |
942 int xtract_failsafe_f0(const double *data, const int N, const void *argv, double *result) | 942 int xtract_failsafe_f0(const double *data, const int N, const void *argv, double *result) |
943 { | 943 { |
944 | 944 |
945 double *spectrum = NULL, argf[4], *peaks = NULL, return_code, sr; | 945 double *spectrum = NULL, argf[2], *peaks = NULL, return_code, sr; |
946 | 946 |
947 return_code = xtract_f0(data, N, argv, result); | 947 return_code = xtract_f0(data, N, argv, result); |
948 | 948 |
949 if(return_code == XTRACT_NO_RESULT || *result == 0) | 949 if(return_code == XTRACT_NO_RESULT) |
950 { | 950 { |
951 sr = *(double *)argv; | 951 sr = *(double *)argv; |
952 if(sr == 0) | 952 if(sr == 0) |
953 sr = 44100.0; | 953 sr = 44100.0; |
954 spectrum = (double *)malloc(N * sizeof(double)); | 954 spectrum = (double *)malloc(N * sizeof(double)); |
955 peaks = (double *)malloc(N * sizeof(double)); | 955 peaks = (double *)malloc(N * sizeof(double)); |
956 argf[0] = sr / (double)N; | 956 argf[0] = sr; |
957 argf[1] = XTRACT_MAGNITUDE_SPECTRUM; | 957 argf[1] = XTRACT_MAGNITUDE_SPECTRUM; |
958 argf[2] = 0.f; /* DC component not Nyquist */ | |
959 argf[3] = 1.f; /* Normalize */ | |
960 xtract_spectrum(data, N, argf, spectrum); | 958 xtract_spectrum(data, N, argf, spectrum); |
961 argf[1] = 50.0; /* Peak threshold is 70% of maximum peak found */ | 959 argf[1] = 10.0; |
962 xtract_peak_spectrum(spectrum, N >> 1, argf, peaks); | 960 xtract_peak_spectrum(spectrum, N >> 1, argf, peaks); |
963 argf[0] = 0.0; | 961 argf[0] = 0.0; |
964 | |
965 /* Assume the peak with the lowest frequency is the fundamental */ | |
966 xtract_lowest_value(peaks+(N >> 1), N >> 1, argf, result); | 962 xtract_lowest_value(peaks+(N >> 1), N >> 1, argf, result); |
967 | 963 |
968 free(spectrum); | 964 free(spectrum); |
969 free(peaks); | 965 free(peaks); |
970 } | 966 } |
992 double f0 = *(double *)argv; | 988 double f0 = *(double *)argv; |
993 double note = 0.0; | 989 double note = 0.0; |
994 | 990 |
995 note = 69 + log(f0 / 440.f) * 17.31234; | 991 note = 69 + log(f0 / 440.f) * 17.31234; |
996 note *= 100; | 992 note *= 100; |
997 note = round(note); | 993 note = floor( 0.5f + note ); // replace -> round(note); |
998 | 994 |
999 *result = note; | 995 *result = note; |
1000 | 996 |
1001 if (note > 12700 || note < 0) | 997 if (note > 12700 || note < 0) |
1002 { | 998 { |