// // Programmer: Craig Stuart Sapp // Creation Date: Sun May 13 14:00:43 PDT 2001 // Last Modified: Sun May 13 14:00:40 PDT 2001 // Filename: ...sig/src/museinfo/humdrumfileextras.cpp // Web Address: http://sig.sapp.org/src/museinfo/humdrumfileextras.cpp // Syntax: C++ // // Description: Functions useful for use with the HumdrumFile class, // but not necessarily using HumdrumFile class. // #include #ifndef OLDCPP #include using namespace std; #else #include #endif ////////////////////////////////////////////////////////////////////////// // // Krumhansl-Schmuckler key-finding algorithm functions. // ////////////////////////////// // // analyzeKeyKS -- apply the Krumhansl-Schmuckler // key-finding algorithm. Return value is the base-12 most likely // key. scores 0-11 are the major keys starting on C major. 12-23 are // the minor keys starting on C minor. input array scores must have // a size of 24 or greater. input array pitch must have a size of "size". // int analyzeKeyKS(double* scores, double* distribution, int* pitch, double* durations, int size, int rhythmQ, int binaryQ) { int i, j; int histogram[12] = {0}; double majorKey[12] = {6.35, 2.23, 3.48, 2.33, 4.38, 4.09, 2.52, 5.19, 2.39, 3.66, 2.29, 2.88}; double minorKey[12] = {6.33, 2.68, 3.52, 5.38, 2.60, 3.53, 2.54, 4.75, 3.98, 2.69, 3.34, 3.17}; // double majorKey[12] = {24.3279, -10.1283, 2.44009, -4.63092, -2.46215, // 7.58629, -8.60338, -11.5317, -24.1048, -7.61466, -26.2269, 7.95787}; // double minorKey[12] = {23.1015, -1.94184, 11.9991, 1.8769, -14.671, 7.08384, // 6.36015 -3.36218, -9.21259, -25.3657, -25.0074, -1.49362}; for (i=0; i<24; i++) { scores[i] = 0.0; } if (size == 0) { return -1; // return -1 if not data to analyze } for (i=0; i<12; i++) { distribution[i] = 0.0; } // generate a histogram of pitches for (i=0; i scores[bestkey]) { bestkey = i; } } return bestkey; } ////////////////////////////// // // analyzeKeyKS -- apply the Krumhansl-Schmuckler // key-finding algorithm. Return value is the base-12 most likely // key. scores 0-11 are the major keys starting on C major. 12-23 are // the minor keys starting on C minor. input array scores must have // a size of 24 or greater. input array pitch must have a size of "size". // int analyzeKeyKS2(double* scores, double* distribution, int* pitch, double* durations, int size, int rhythmQ, double* majorKey, double* minorKey) { int i, j; int histogram[12] = {0}; // double majorKey[12] = {6.35, 2.23, 3.48, 2.33, 4.38, 4.09, 2.52, // 5.19, 2.39, 3.66, 2.29, 2.88}; // double minorKey[12] = {6.33, 2.68, 3.52, 5.38, 2.60, 3.53, 2.54, // 4.75, 3.98, 2.69, 3.34, 3.17}; for (i=0; i<24; i++) { scores[i] = 0.0; } if (size == 0) { return -1; // return -1 if no data to analyze } for (i=0; i<12; i++) { distribution[i] = 0.0; } // generate a histogram of pitches for (i=0; i scores[bestkey]) { bestkey = i; } } return bestkey; } // md5sum: 09796ef2403c60dd1810761cafd4df11 humdrumfileextras.cpp [20050403]