Download - Ulillillia's WAV file sample rate generator program

Transcript
  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    1/19

    #include // standard input/output, used for functions like sprintf#include // used for processing strings, particularly strcpy#include // used for advanced mathematical functions - log10 in this case (for base 10logarithms, used for progress indication)

    #define _CRT_SECURE_NO_DEPRECATE // gets rid of the warnings from deprecation - sprintf,fopen, etc. is standard C

    unsigned int Modifier; // adjusts sample rate in file based on source's true speed sample rate// unsigned int Steps;

    unsigned int BestSpeeds1Start; // the speed ranges of up to 3 best zones, that most listened tounsigned int BestSpeeds1End;unsigned int BestSpeeds2Start;unsigned int BestSpeeds2End;unsigned int BestSpeeds3Start;unsigned int BestSpeeds3End;unsigned int NormalSpeedsStart; // the speed ranges of the normal zone, where the song soundsreasonableunsigned int NormalSpeedsEnd;unsigned int CurrentSpeed = 0; // the current sample rate (speed)

    unsigned int FrequencyChangeover16K; // the speed (sample rate) at which the output MP3'ssample rate increases, to allow for optimizationunsigned int FrequencyChangeover24K;unsigned int FrequencyChangeover32K;unsigned int FrequencyChangeover48K;unsigned int ProcessingStage = 1; // a "flag" that indicates whether the normal zone or best zonespeeds are reached, or the endunsigned int WithinRange; // a "flag" to indicate that a speed is within the speed zoneunsigned int ZoneID; // zone identifierunsigned int ZoneLapCount[7]; // number of loops within each zone (used in the base file's name)unsigned int ReadFlag = 0; // a flag to indicate that the next zone's base file is read, for morecontrol on the displaying of text

    unsigned int SampleRateInFile; // the sample rate used in the file's infounsigned int BytesPerSecond; // equal to SampleRate*Multiplierunsigned int Multiplier; // the multiplier used for the BytesPerSecond variable, based on thenumber of bytes per sampleunsigned char FileHeadStart[24]; // for copying identical file header data

    unsigned char FileHeadEnd[7]; // for copying the last parts of the file header data

    unsigned int FileLength; // the length of the file after the header data in bytesunsigned char FileContents[250000000]; // the contents of the file for copying, since the samplesthemselves don't change at all // use array with size bigger than file size or malloc itchar FileName[128]; // the file name for the output filechar SongName[60]; // for the name of the song for easier processing

    unsigned int DebugTest[16]; // debugging variables

    FILE *FileHandle; // used for the reading and writing of files

    void FindNextSampleRate(){

    /*This function determines the next speed, sets flags and essential in-file data, and determines

    the zone afterwards.

    This function has 3 stages:Stage 1: Obtain the next speed based on the mode. Normal speeds have big gaps and "best

    zone" speeds have tiny gaps.Stage 2: Determine what zone this speed is in. If in range, set the file's sample rate and bytes

    per second values accordinglyIf at the end of the normal speeds, restart from the beginning and do the "best zone" speeds.Stage 3: Set flags and essential in-file data. This is needed to determine what file to use.*/

    if (CurrentSpeed

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    2/19

    DebugTest[1] = 0; // reset}

    // Stage 1: Obtain the next speed based on the mode.// exclusive to samplers, of which always use the best zone speedsif ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End)){

    ProcessingStage = 2;}

    if ((ProcessingStage == 1) && (NormalSpeedsStart < BestSpeeds1Start)) // the normal speeds

    and not a sampler/special version{

    if (CurrentSpeed < 20000) { CurrentSpeed = 20000; } // 1/5else if (CurrentSpeed < 20972) { CurrentSpeed = 20972; } // "speed -2"else if (CurrentSpeed < 22500) { CurrentSpeed = 22500; }else if (CurrentSpeed < 25000) { CurrentSpeed = 25000; } // 1/4; 24 semi-tones lowerelse if (CurrentSpeed < 26214) { CurrentSpeed = 26214; } // "speed -1"else if (CurrentSpeed < 27500) { CurrentSpeed = 27500; }else if (CurrentSpeed < 30000) { CurrentSpeed = 30000; }else if (CurrentSpeed < 32768) { CurrentSpeed = 32768; } // "speed 0"else if (CurrentSpeed < 33333) { CurrentSpeed = 33333; } // 1/3else if (CurrentSpeed < 35000) { CurrentSpeed = 35000; }else if (CurrentSpeed < 35355) { CurrentSpeed = 35355; } // sqrt(1/8); 18 semi-tones lowerelse if (CurrentSpeed < 40000) { CurrentSpeed = 40000; } // extended minimum; 2/5

    else if (CurrentSpeed < 40960) { CurrentSpeed = 40960; } // "speed 1"else if (CurrentSpeed < 45000) { CurrentSpeed = 45000; }else if (CurrentSpeed < 50000) { CurrentSpeed = 50000; } // standard minimum; 1/2; 12 semi-

    tones lowerelse if (CurrentSpeed < 51200) { CurrentSpeed = 51200; } // "speed 2"else if (CurrentSpeed < 55000) { CurrentSpeed = 55000; }else if (CurrentSpeed < 60000) { CurrentSpeed = 60000; }else if (CurrentSpeed < 64000) { CurrentSpeed = 64000; } // "speed 3"else if (CurrentSpeed < 66667) { CurrentSpeed = 66667; } // 2/3else if (CurrentSpeed < 70000) { CurrentSpeed = 70000; }else if (CurrentSpeed < 70711) { CurrentSpeed = 70711; } // sqrt(1/2); 6 semi-tones lowerelse if (CurrentSpeed < 75000) { CurrentSpeed = 75000; } // 3/4else if (CurrentSpeed < 80000) { CurrentSpeed = 80000; } // "speed 4"; 4/5else if (CurrentSpeed < 83333) { CurrentSpeed = 83333; } // 5/6

    else if (CurrentSpeed < 90000) { CurrentSpeed = 90000; }else if (CurrentSpeed < 100000) { CurrentSpeed = 100000; } // true speed; "speed 5"else if (CurrentSpeed < 110000) { CurrentSpeed = 110000; }else if (CurrentSpeed < 116667) { CurrentSpeed = 116667; } // 7/6else if (CurrentSpeed < 125000) { CurrentSpeed = 125000; } // standard maximum; "speed

    6"; 5/4else if (CurrentSpeed < 133333) { CurrentSpeed = 133333; } // 4/3else if (CurrentSpeed < 140000) { CurrentSpeed = 140000; } // extended maximumelse if (CurrentSpeed < 141421) { CurrentSpeed = 141421; } // sqrt(2); 6 semi-tones higherelse if (CurrentSpeed < 150000) { CurrentSpeed = 150000; } // 3/2else if (CurrentSpeed < 156250) { CurrentSpeed = 156250; } // "speed 7"else if (CurrentSpeed < 166667) { CurrentSpeed = 166667; } // 5/3else if (CurrentSpeed < 175000) { CurrentSpeed = 175000; }else if (CurrentSpeed < 195313) { CurrentSpeed = 195313; } // "speed 8"

    else if (CurrentSpeed < 200000) { CurrentSpeed = 200000; } // double; 12 semi-tones higherelse if (CurrentSpeed < 225000) { CurrentSpeed = 225000; }else if (CurrentSpeed < 244141) { CurrentSpeed = 244141; } // "speed 9"else if (CurrentSpeed < 250000) { CurrentSpeed = 250000; } // 5/2else if (CurrentSpeed < 282843) { CurrentSpeed = 282843; } // sqrt(8); 18 semi-tones higherelse if (CurrentSpeed < 300000) { CurrentSpeed = 300000; } // tripleelse if (CurrentSpeed < 305176) { CurrentSpeed = 305176; } // "speed 10"else if (CurrentSpeed < 350000) { CurrentSpeed = 350000; }else if (CurrentSpeed < 381470) { CurrentSpeed = 381470; } // "speed 11"else if (CurrentSpeed < 400000) { CurrentSpeed = 400000; } // quadruple; 24 semi-tones

    higherelse if (CurrentSpeed < 450000) { CurrentSpeed = 450000; }else if (CurrentSpeed < 476837) { CurrentSpeed = 476837; } // "speed 12"else if (CurrentSpeed < 500000) { CurrentSpeed = 500000; } // quintuple

    }

    if (DebugTest[1] == 1){

    DebugTest[3] = CurrentSpeed; // what the speed is after the normal zone}

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    3/19

    if ((ProcessingStage == 2) || (NormalSpeedsStart == BestSpeeds1Start)) // the best speeds (ora sampler/special version)

    {if (CurrentSpeed < 20000) { CurrentSpeed = 20000; } // 1/5else if (CurrentSpeed < 20250) { CurrentSpeed = 20250; }else if (CurrentSpeed < 20500) { CurrentSpeed = 20500; }else if (CurrentSpeed < 20750) { CurrentSpeed = 20750; }else if (CurrentSpeed < 20972) { CurrentSpeed = 20972; } // "speed -2"else if (CurrentSpeed < 21000) { CurrentSpeed = 21000; }else if (CurrentSpeed < 21250) { CurrentSpeed = 21250; }else if (CurrentSpeed < 21500) { CurrentSpeed = 21500; }

    else if (CurrentSpeed < 21750) { CurrentSpeed = 21750; }else if (CurrentSpeed < 22000) { CurrentSpeed = 22000; }else if (CurrentSpeed < 22222) { CurrentSpeed = 22222; } // 2/9else if (CurrentSpeed < 22250) { CurrentSpeed = 22250; }else if (CurrentSpeed < 22500) { CurrentSpeed = 22500; }else if (CurrentSpeed < 22750) { CurrentSpeed = 22750; }else if (CurrentSpeed < 23000) { CurrentSpeed = 23000; }else if (CurrentSpeed < 23250) { CurrentSpeed = 23250; }else if (CurrentSpeed < 23500) { CurrentSpeed = 23500; }else if (CurrentSpeed < 23750) { CurrentSpeed = 23750; }else if (CurrentSpeed < 24000) { CurrentSpeed = 24000; }else if (CurrentSpeed < 24250) { CurrentSpeed = 24250; }else if (CurrentSpeed < 24500) { CurrentSpeed = 24500; }else if (CurrentSpeed < 24750) { CurrentSpeed = 24750; }

    else if (CurrentSpeed < 25000) { CurrentSpeed = 25000; } // 1/4; 24 semi-tones lowerelse if (CurrentSpeed < 25250) { CurrentSpeed = 25250; }else if (CurrentSpeed < 25500) { CurrentSpeed = 25500; }else if (CurrentSpeed < 25750) { CurrentSpeed = 25750; }else if (CurrentSpeed < 26000) { CurrentSpeed = 26000; }else if (CurrentSpeed < 26214) { CurrentSpeed = 26214; } // "speed -1"else if (CurrentSpeed < 26250) { CurrentSpeed = 26250; }else if (CurrentSpeed < 26500) { CurrentSpeed = 26500; }else if (CurrentSpeed < 26667) { CurrentSpeed = 26667; } // 4/15else if (CurrentSpeed < 26750) { CurrentSpeed = 26750; }else if (CurrentSpeed < 27000) { CurrentSpeed = 27000; }else if (CurrentSpeed < 27250) { CurrentSpeed = 27250; }else if (CurrentSpeed < 27500) { CurrentSpeed = 27500; }else if (CurrentSpeed < 27750) { CurrentSpeed = 27750; }

    else if (CurrentSpeed < 28000) { CurrentSpeed = 28000; }else if (CurrentSpeed < 28250) { CurrentSpeed = 28250; }else if (CurrentSpeed < 28500) { CurrentSpeed = 28500; }else if (CurrentSpeed < 28571) { CurrentSpeed = 28571; } // 2/7else if (CurrentSpeed < 28750) { CurrentSpeed = 28750; }else if (CurrentSpeed < 29000) { CurrentSpeed = 29000; }else if (CurrentSpeed < 29250) { CurrentSpeed = 29250; }else if (CurrentSpeed < 29500) { CurrentSpeed = 29500; }else if (CurrentSpeed < 29750) { CurrentSpeed = 29750; }else if (CurrentSpeed < 30000) { CurrentSpeed = 30000; } // 3/10else if (CurrentSpeed < 30250) { CurrentSpeed = 30250; }else if (CurrentSpeed < 30500) { CurrentSpeed = 30500; }else if (CurrentSpeed < 30750) { CurrentSpeed = 30750; }else if (CurrentSpeed < 31000) { CurrentSpeed = 31000; }

    else if (CurrentSpeed < 31250) { CurrentSpeed = 31250; }else if (CurrentSpeed < 31500) { CurrentSpeed = 31500; }else if (CurrentSpeed < 32000) { CurrentSpeed = 32000; }else if (CurrentSpeed < 32500) { CurrentSpeed = 32500; }else if (CurrentSpeed < 32768) { CurrentSpeed = 32768; } // "speed 0"else if (CurrentSpeed < 33000) { CurrentSpeed = 33000; }else if (CurrentSpeed < 33333) { CurrentSpeed = 33333; } // 1/3else if (CurrentSpeed < 33500) { CurrentSpeed = 33500; }else if (CurrentSpeed < 34000) { CurrentSpeed = 34000; }else if (CurrentSpeed < 34500) { CurrentSpeed = 34500; }else if (CurrentSpeed < 35000) { CurrentSpeed = 35000; }else if (CurrentSpeed < 35355) { CurrentSpeed = 35355; } // sqrt(1/8); 18 semi-tones lowerelse if (CurrentSpeed < 35500) { CurrentSpeed = 35500; }else if (CurrentSpeed < 36000) { CurrentSpeed = 36000; }else if (CurrentSpeed < 36500) { CurrentSpeed = 36500; }else if (CurrentSpeed < 37000) { CurrentSpeed = 37000; }else if (CurrentSpeed < 37500) { CurrentSpeed = 37500; } // 3/8else if (CurrentSpeed < 38000) { CurrentSpeed = 38000; }else if (CurrentSpeed < 38500) { CurrentSpeed = 38500; }else if (CurrentSpeed < 39000) { CurrentSpeed = 39000; }else if (CurrentSpeed < 39500) { CurrentSpeed = 39500; }

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    4/19

    else if (CurrentSpeed < 40000) { CurrentSpeed = 40000; } // extended minimum; 2/5else if (CurrentSpeed < 40500) { CurrentSpeed = 40500; }else if (CurrentSpeed < 40960) { CurrentSpeed = 40960; } // "speed 1"else if (CurrentSpeed < 41000) { CurrentSpeed = 41000; }else if (CurrentSpeed < 41500) { CurrentSpeed = 41500; }else if (CurrentSpeed < 41667) { CurrentSpeed = 41667; } // 5/12else if (CurrentSpeed < 42000) { CurrentSpeed = 42000; }else if (CurrentSpeed < 42500) { CurrentSpeed = 42500; }else if (CurrentSpeed < 42857) { CurrentSpeed = 42857; } // 3/7else if (CurrentSpeed < 43000) { CurrentSpeed = 43000; }else if (CurrentSpeed < 43500) { CurrentSpeed = 43500; }

    else if (CurrentSpeed < 44000) { CurrentSpeed = 44000; }else if (CurrentSpeed < 44444) { CurrentSpeed = 44444; } // 4/9else if (CurrentSpeed < 44500) { CurrentSpeed = 44500; }else if (CurrentSpeed < 45000) { CurrentSpeed = 45000; }else if (CurrentSpeed < 45500) { CurrentSpeed = 45500; }else if (CurrentSpeed < 46000) { CurrentSpeed = 46000; }else if (CurrentSpeed < 46500) { CurrentSpeed = 46500; }else if (CurrentSpeed < 46667) { CurrentSpeed = 46667; } // 7/15else if (CurrentSpeed < 47000) { CurrentSpeed = 47000; }else if (CurrentSpeed < 47500) { CurrentSpeed = 47500; }else if (CurrentSpeed < 48000) { CurrentSpeed = 48000; }else if (CurrentSpeed < 48500) { CurrentSpeed = 48500; }else if (CurrentSpeed < 49000) { CurrentSpeed = 49000; }else if (CurrentSpeed < 49500) { CurrentSpeed = 49500; }

    else if (CurrentSpeed < 50000) { CurrentSpeed = 50000; } // standard minimum; 1/2; 12 semi-tones lower

    else if (CurrentSpeed < 50500) { CurrentSpeed = 50500; }else if (CurrentSpeed < 51000) { CurrentSpeed = 51000; }else if (CurrentSpeed < 51200) { CurrentSpeed = 51200; } // "speed 2"else if (CurrentSpeed < 51500) { CurrentSpeed = 51500; }else if (CurrentSpeed < 52000) { CurrentSpeed = 52000; }else if (CurrentSpeed < 52500) { CurrentSpeed = 52500; }else if (CurrentSpeed < 53000) { CurrentSpeed = 53000; }else if (CurrentSpeed < 53333) { CurrentSpeed = 53333; } // 8/15else if (CurrentSpeed < 53500) { CurrentSpeed = 53500; }else if (CurrentSpeed < 54000) { CurrentSpeed = 54000; }else if (CurrentSpeed < 54500) { CurrentSpeed = 54500; }else if (CurrentSpeed < 55000) { CurrentSpeed = 55000; }

    else if (CurrentSpeed < 55500) { CurrentSpeed = 55500; }else if (CurrentSpeed < 55556) { CurrentSpeed = 55556; } // 5/9else if (CurrentSpeed < 56000) { CurrentSpeed = 56000; }else if (CurrentSpeed < 56500) { CurrentSpeed = 56500; }else if (CurrentSpeed < 57000) { CurrentSpeed = 57000; }else if (CurrentSpeed < 57143) { CurrentSpeed = 57143; } // 4/7else if (CurrentSpeed < 57500) { CurrentSpeed = 57500; }else if (CurrentSpeed < 58000) { CurrentSpeed = 58000; }else if (CurrentSpeed < 58333) { CurrentSpeed = 58333; } // 7/12else if (CurrentSpeed < 58500) { CurrentSpeed = 58500; }else if (CurrentSpeed < 59000) { CurrentSpeed = 59000; }else if (CurrentSpeed < 59500) { CurrentSpeed = 59500; }else if (CurrentSpeed < 60000) { CurrentSpeed = 60000; } // 3/5else if (CurrentSpeed < 60500) { CurrentSpeed = 60500; }

    else if (CurrentSpeed < 61000) { CurrentSpeed = 61000; }else if (CurrentSpeed < 61500) { CurrentSpeed = 61500; }else if (CurrentSpeed < 62000) { CurrentSpeed = 62000; }else if (CurrentSpeed < 62500) { CurrentSpeed = 62500; } // 5/8else if (CurrentSpeed < 63000) { CurrentSpeed = 63000; }else if (CurrentSpeed < 64000) { CurrentSpeed = 64000; } // "speed 3"else if (CurrentSpeed < 65000) { CurrentSpeed = 65000; }else if (CurrentSpeed < 66000) { CurrentSpeed = 66000; }else if (CurrentSpeed < 66667) { CurrentSpeed = 66667; } // 2/3else if (CurrentSpeed < 67000) { CurrentSpeed = 67000; }else if (CurrentSpeed < 68000) { CurrentSpeed = 68000; }else if (CurrentSpeed < 69000) { CurrentSpeed = 69000; }else if (CurrentSpeed < 70000) { CurrentSpeed = 70000; } // 7/10else if (CurrentSpeed < 70711) { CurrentSpeed = 70711; } // sqrt(1/2); 6 semi-tones lowerelse if (CurrentSpeed < 71000) { CurrentSpeed = 71000; }else if (CurrentSpeed < 71429) { CurrentSpeed = 71429; } // 5/7else if (CurrentSpeed < 72000) { CurrentSpeed = 72000; }else if (CurrentSpeed < 73000) { CurrentSpeed = 73000; }else if (CurrentSpeed < 73333) { CurrentSpeed = 73333; } // 11/15else if (CurrentSpeed < 74000) { CurrentSpeed = 74000; }else if (CurrentSpeed < 75000) { CurrentSpeed = 75000; } // 3/4

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    5/19

    else if (CurrentSpeed < 76000) { CurrentSpeed = 76000; }else if (CurrentSpeed < 77000) { CurrentSpeed = 77000; }else if (CurrentSpeed < 77778) { CurrentSpeed = 77778; } // 7/8else if (CurrentSpeed < 78000) { CurrentSpeed = 78000; }else if (CurrentSpeed < 79000) { CurrentSpeed = 79000; }else if (CurrentSpeed < 80000) { CurrentSpeed = 80000; } // 4/5else if (CurrentSpeed < 81000) { CurrentSpeed = 81000; }else if (CurrentSpeed < 82000) { CurrentSpeed = 82000; }else if (CurrentSpeed < 83000) { CurrentSpeed = 83000; }else if (CurrentSpeed < 83333) { CurrentSpeed = 83333; } // 5/6else if (CurrentSpeed < 84000) { CurrentSpeed = 84000; }

    else if (CurrentSpeed < 85000) { CurrentSpeed = 85000; }else if (CurrentSpeed < 85714) { CurrentSpeed = 85714; } // 6/7else if (CurrentSpeed < 86000) { CurrentSpeed = 86000; }else if (CurrentSpeed < 86667) { CurrentSpeed = 86667; } // 13/15else if (CurrentSpeed < 87000) { CurrentSpeed = 87000; }else if (CurrentSpeed < 87500) { CurrentSpeed = 87500; } // 7/8else if (CurrentSpeed < 88000) { CurrentSpeed = 88000; }else if (CurrentSpeed < 88889) { CurrentSpeed = 88889; } // 8/9else if (CurrentSpeed < 89000) { CurrentSpeed = 89000; }else if (CurrentSpeed < 90000) { CurrentSpeed = 90000; } // 9/10else if (CurrentSpeed < 91000) { CurrentSpeed = 91000; }else if (CurrentSpeed < 91667) { CurrentSpeed = 91667; } // 11/12else if (CurrentSpeed < 92000) { CurrentSpeed = 92000; }else if (CurrentSpeed < 93000) { CurrentSpeed = 93000; }

    else if (CurrentSpeed < 93333) { CurrentSpeed = 93333; } // 14/15else if (CurrentSpeed < 94000) { CurrentSpeed = 94000; }else if (CurrentSpeed < 95000) { CurrentSpeed = 95000; }else if (CurrentSpeed < 96000) { CurrentSpeed = 96000; }else if (CurrentSpeed < 97000) { CurrentSpeed = 97000; }else if (CurrentSpeed < 98000) { CurrentSpeed = 98000; }else if (CurrentSpeed < 99000) { CurrentSpeed = 99000; }else if (CurrentSpeed < 100000) { CurrentSpeed = 100000; } // true speed; "speed 5"else if (CurrentSpeed < 101000) { CurrentSpeed = 101000; }else if (CurrentSpeed < 102000) { CurrentSpeed = 102000; }else if (CurrentSpeed < 103000) { CurrentSpeed = 103000; }else if (CurrentSpeed < 104000) { CurrentSpeed = 104000; }else if (CurrentSpeed < 105000) { CurrentSpeed = 105000; }else if (CurrentSpeed < 106000) { CurrentSpeed = 106000; }

    else if (CurrentSpeed < 106667) { CurrentSpeed = 106667; } // 16/15else if (CurrentSpeed < 107000) { CurrentSpeed = 107000; }else if (CurrentSpeed < 108000) { CurrentSpeed = 108000; }else if (CurrentSpeed < 108333) { CurrentSpeed = 108333; } // 13/12else if (CurrentSpeed < 109000) { CurrentSpeed = 109000; }else if (CurrentSpeed < 110000) { CurrentSpeed = 110000; } // 11/10else if (CurrentSpeed < 111000) { CurrentSpeed = 111000; }else if (CurrentSpeed < 111111) { CurrentSpeed = 111111; } // 10/9else if (CurrentSpeed < 112000) { CurrentSpeed = 112000; }else if (CurrentSpeed < 112500) { CurrentSpeed = 112500; } // 9/8else if (CurrentSpeed < 113000) { CurrentSpeed = 113000; }else if (CurrentSpeed < 113333) { CurrentSpeed = 113333; } // 17/15else if (CurrentSpeed < 114000) { CurrentSpeed = 114000; }else if (CurrentSpeed < 114286) { CurrentSpeed = 114286; } // 8/7

    else if (CurrentSpeed < 115000) { CurrentSpeed = 115000; }else if (CurrentSpeed < 116000) { CurrentSpeed = 116000; }else if (CurrentSpeed < 116667) { CurrentSpeed = 116667; } // 7/6else if (CurrentSpeed < 117000) { CurrentSpeed = 117000; }else if (CurrentSpeed < 118000) { CurrentSpeed = 118000; }else if (CurrentSpeed < 119000) { CurrentSpeed = 119000; }else if (CurrentSpeed < 120000) { CurrentSpeed = 120000; } // 6/5else if (CurrentSpeed < 121000) { CurrentSpeed = 121000; }else if (CurrentSpeed < 122000) { CurrentSpeed = 122000; }else if (CurrentSpeed < 122222) { CurrentSpeed = 122222; } // 11/9else if (CurrentSpeed < 123000) { CurrentSpeed = 123000; }else if (CurrentSpeed < 124000) { CurrentSpeed = 124000; }else if (CurrentSpeed < 125000) { CurrentSpeed = 125000; } // standard maximum; "speed

    6"; 5/4else if (CurrentSpeed < 127500) { CurrentSpeed = 127500; }else if (CurrentSpeed < 128571) { CurrentSpeed = 128571; } // 9/7else if (CurrentSpeed < 130000) { CurrentSpeed = 130000; }else if (CurrentSpeed < 132500) { CurrentSpeed = 132500; }else if (CurrentSpeed < 133333) { CurrentSpeed = 133333; } // 4/3else if (CurrentSpeed < 135000) { CurrentSpeed = 135000; }else if (CurrentSpeed < 137500) { CurrentSpeed = 137500; }

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    6/19

    else if (CurrentSpeed < 140000) { CurrentSpeed = 140000; } // extended maximum; 7/5else if (CurrentSpeed < 141421) { CurrentSpeed = 141421; } // sqrt(2); 6 semi-tones higherelse if (CurrentSpeed < 142500) { CurrentSpeed = 142500; }else if (CurrentSpeed < 142857) { CurrentSpeed = 142857; } // 10/7else if (CurrentSpeed < 145000) { CurrentSpeed = 145000; }else if (CurrentSpeed < 147500) { CurrentSpeed = 147500; }else if (CurrentSpeed < 150000) { CurrentSpeed = 150000; } // 3/2else if (CurrentSpeed < 152500) { CurrentSpeed = 152500; }else if (CurrentSpeed < 155000) { CurrentSpeed = 155000; }else if (CurrentSpeed < 156250) { CurrentSpeed = 156250; } // "speed 7"else if (CurrentSpeed < 157500) { CurrentSpeed = 157500; }

    else if (CurrentSpeed < 160000) { CurrentSpeed = 160000; } // 8/5else if (CurrentSpeed < 162500) { CurrentSpeed = 162500; }else if (CurrentSpeed < 165000) { CurrentSpeed = 165000; }else if (CurrentSpeed < 166667) { CurrentSpeed = 166667; } // 5/3else if (CurrentSpeed < 167500) { CurrentSpeed = 167500; }else if (CurrentSpeed < 170000) { CurrentSpeed = 170000; }else if (CurrentSpeed < 172500) { CurrentSpeed = 172500; }else if (CurrentSpeed < 175000) { CurrentSpeed = 175000; } // 7/4else if (CurrentSpeed < 177500) { CurrentSpeed = 177500; }else if (CurrentSpeed < 180000) { CurrentSpeed = 180000; } // 9/5else if (CurrentSpeed < 182500) { CurrentSpeed = 182500; }else if (CurrentSpeed < 183333) { CurrentSpeed = 183333; } // 11/6else if (CurrentSpeed < 185000) { CurrentSpeed = 185000; }else if (CurrentSpeed < 187500) { CurrentSpeed = 187500; }

    else if (CurrentSpeed < 190000) { CurrentSpeed = 190000; }else if (CurrentSpeed < 192500) { CurrentSpeed = 192500; }else if (CurrentSpeed < 195000) { CurrentSpeed = 195000; }else if (CurrentSpeed < 195313) { CurrentSpeed = 195313; } // "speed 8"else if (CurrentSpeed < 197500) { CurrentSpeed = 197500; }else if (CurrentSpeed < 200000) { CurrentSpeed = 200000; } // double; 12 semi-tones higherelse if (CurrentSpeed < 202500) { CurrentSpeed = 202500; }else if (CurrentSpeed < 205000) { CurrentSpeed = 205000; }else if (CurrentSpeed < 207500) { CurrentSpeed = 207500; }else if (CurrentSpeed < 210000) { CurrentSpeed = 210000; }else if (CurrentSpeed < 212500) { CurrentSpeed = 212500; }else if (CurrentSpeed < 215000) { CurrentSpeed = 215000; }else if (CurrentSpeed < 217500) { CurrentSpeed = 217500; }else if (CurrentSpeed < 220000) { CurrentSpeed = 220000; }

    else if (CurrentSpeed < 222500) { CurrentSpeed = 222500; }else if (CurrentSpeed < 225000) { CurrentSpeed = 225000; } // 9/4else if (CurrentSpeed < 227500) { CurrentSpeed = 227500; }else if (CurrentSpeed < 230000) { CurrentSpeed = 230000; }else if (CurrentSpeed < 232500) { CurrentSpeed = 232500; }else if (CurrentSpeed < 233333) { CurrentSpeed = 233333; } // 7/3else if (CurrentSpeed < 235000) { CurrentSpeed = 235000; }else if (CurrentSpeed < 237500) { CurrentSpeed = 237500; }else if (CurrentSpeed < 240000) { CurrentSpeed = 240000; }else if (CurrentSpeed < 242500) { CurrentSpeed = 242500; }else if (CurrentSpeed < 244141) { CurrentSpeed = 244141; } // "speed 9"else if (CurrentSpeed < 245000) { CurrentSpeed = 245000; }else if (CurrentSpeed < 247500) { CurrentSpeed = 247500; }else if (CurrentSpeed < 250000) { CurrentSpeed = 250000; } // 5/2

    else if (CurrentSpeed < 255000) { CurrentSpeed = 255000; }else if (CurrentSpeed < 260000) { CurrentSpeed = 260000; }else if (CurrentSpeed < 265000) { CurrentSpeed = 265000; }else if (CurrentSpeed < 266667) { CurrentSpeed = 266667; } // 8/3else if (CurrentSpeed < 270000) { CurrentSpeed = 270000; }else if (CurrentSpeed < 275000) { CurrentSpeed = 275000; }else if (CurrentSpeed < 280000) { CurrentSpeed = 280000; }else if (CurrentSpeed < 282843) { CurrentSpeed = 282843; } // sqrt(8); 18 semi-tones higherelse if (CurrentSpeed < 285000) { CurrentSpeed = 285000; }else if (CurrentSpeed < 290000) { CurrentSpeed = 290000; }else if (CurrentSpeed < 295000) { CurrentSpeed = 295000; }else if (CurrentSpeed < 300000) { CurrentSpeed = 300000; } // tripleelse if (CurrentSpeed < 305000) { CurrentSpeed = 305000; }else if (CurrentSpeed < 305176) { CurrentSpeed = 305176; } // "speed 10"else if (CurrentSpeed < 310000) { CurrentSpeed = 310000; }else if (CurrentSpeed < 315000) { CurrentSpeed = 315000; }else if (CurrentSpeed < 320000) { CurrentSpeed = 320000; }else if (CurrentSpeed < 325000) { CurrentSpeed = 325000; }else if (CurrentSpeed < 330000) { CurrentSpeed = 330000; }else if (CurrentSpeed < 333333) { CurrentSpeed = 333333; } // 10/3else if (CurrentSpeed < 335000) { CurrentSpeed = 335000; }

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    7/19

    else if (CurrentSpeed < 340000) { CurrentSpeed = 340000; }else if (CurrentSpeed < 345000) { CurrentSpeed = 345000; }else if (CurrentSpeed < 350000) { CurrentSpeed = 350000; } // 7/2else if (CurrentSpeed < 355000) { CurrentSpeed = 355000; }else if (CurrentSpeed < 360000) { CurrentSpeed = 360000; }else if (CurrentSpeed < 365000) { CurrentSpeed = 365000; }else if (CurrentSpeed < 370000) { CurrentSpeed = 370000; }else if (CurrentSpeed < 375000) { CurrentSpeed = 375000; }else if (CurrentSpeed < 380000) { CurrentSpeed = 380000; }else if (CurrentSpeed < 381470) { CurrentSpeed = 381470; } // "speed 11"else if (CurrentSpeed < 385000) { CurrentSpeed = 385000; }

    else if (CurrentSpeed < 390000) { CurrentSpeed = 390000; }else if (CurrentSpeed < 395000) { CurrentSpeed = 395000; }else if (CurrentSpeed < 400000) { CurrentSpeed = 400000; } // quadruple; 24-semi-tones

    higherelse if (CurrentSpeed < 405000) { CurrentSpeed = 405000; }else if (CurrentSpeed < 410000) { CurrentSpeed = 410000; }else if (CurrentSpeed < 415000) { CurrentSpeed = 415000; }else if (CurrentSpeed < 420000) { CurrentSpeed = 420000; }else if (CurrentSpeed < 425000) { CurrentSpeed = 425000; }else if (CurrentSpeed < 430000) { CurrentSpeed = 430000; }else if (CurrentSpeed < 435000) { CurrentSpeed = 435000; }else if (CurrentSpeed < 440000) { CurrentSpeed = 440000; }else if (CurrentSpeed < 445000) { CurrentSpeed = 445000; }else if (CurrentSpeed < 450000) { CurrentSpeed = 450000; } // 9/2

    else if (CurrentSpeed < 455000) { CurrentSpeed = 455000; }else if (CurrentSpeed < 460000) { CurrentSpeed = 460000; }else if (CurrentSpeed < 465000) { CurrentSpeed = 465000; }else if (CurrentSpeed < 470000) { CurrentSpeed = 470000; }else if (CurrentSpeed < 475000) { CurrentSpeed = 475000; }else if (CurrentSpeed < 476837) { CurrentSpeed = 476837; } // "speed 12"else if (CurrentSpeed < 480000) { CurrentSpeed = 480000; }else if (CurrentSpeed < 485000) { CurrentSpeed = 485000; }else if (CurrentSpeed < 490000) { CurrentSpeed = 490000; }else if (CurrentSpeed < 495000) { CurrentSpeed = 495000; }else if (CurrentSpeed < 500000) { CurrentSpeed = 500000; } // quintuple

    }

    if (CurrentSpeed > NormalSpeedsEnd)

    { ProcessingStage = 2;CurrentSpeed = BestSpeeds1Start;

    }

    if (DebugTest[1] == 1){

    DebugTest[4] = CurrentSpeed; // what the speed is after the best zone}

    if (DebugTest[1] == 1){

    DebugTest[8] = ZoneID;}

    // Stage 2: Determine what zone this speed is in.if (CurrentSpeed < NormalSpeedsStart) { ZoneID = 0;} // no zoneelse if ((CurrentSpeed >= NormalSpeedsStart) && (CurrentSpeed < BestSpeeds1Start)) {

    ZoneID = 1;}else if ((CurrentSpeed >= BestSpeeds1Start) && (CurrentSpeed BestSpeeds1End) && (CurrentSpeed < BestSpeeds2Start)) { ZoneID

    = 3;}else if ((CurrentSpeed >= BestSpeeds2Start) && (CurrentSpeed BestSpeeds2End) && (CurrentSpeed < BestSpeeds3Start)) { ZoneID

    = 5;}else if ((CurrentSpeed >= BestSpeeds3Start) && (CurrentSpeed

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    8/19

    if (CurrentSpeed < BestSpeeds1Start) // if below the initial speed{

    CurrentSpeed = BestSpeeds1Start; // make it at the initial speed}

    }

    if (DebugTest[1] == 1){

    DebugTest[9] = ZoneID;}

    if (DebugTest[1] == 1){

    DebugTest[5] = CurrentSpeed;}

    // Stage 3: Set flags and essential in-file data.if (ProcessingStage == 1) // the normal speeds{

    // those in any of the "best zone" must not be included - they should get skipped to save timeif ((ZoneID == 1) || (ZoneID == 3) || (ZoneID == 5) || (ZoneID == 7)){

    WithinRange = 1; // this indicates that the new speed is within range and should beprocessed

    // determine the sample rate as it is in the fileif (Modifier == 1) // the song's true speed is 50,000{

    SampleRateInFile = (CurrentSpeed+1)/2; // Add 1 to allow for rounding}

    else // true speed is 100,000 Hz{

    SampleRateInFile = CurrentSpeed; // set it to what this system uses}

    BytesPerSecond = SampleRateInFile * 2; // all files are 16-bit mono so this value isdoubled.

    // check if at the end - go to mode 2 if doneif (CurrentSpeed > NormalSpeedsEnd){

    ProcessingStage = 2; // change to mode 2 for doing the best speedsCurrentSpeed = BestSpeeds1Start; // return to the start for one more cycle

    }

    // a sampler - always use the best zoneif ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd ==

    BestSpeeds1End)){

    ZoneID = 2;ProcessingStage = 2;

    CurrentSpeed = BestSpeeds1Start;}}

    else // the best zone - skip it{

    WithinRange = 0; // it's not in range and the speed is ignored until the next processingstage is reached

    }}

    else if (ProcessingStage == 2){

    // only those in the "best zone" get processedif ((ZoneID == 2) || (ZoneID == 4) || (ZoneID == 6)){

    WithinRange = 1; // this indicates that the new speed is within range and should beprocessed

    if (Modifier == 1) // the song's true speed is 50,000{

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    9/19

    SampleRateInFile = (CurrentSpeed+1)/2; // Add 1 to allow for rounding}

    else // true speed is 100,000 Hz{

    SampleRateInFile = CurrentSpeed; // set it to what this system uses}

    BytesPerSecond = SampleRateInFile * 2; // all files are 16-bit mono so this value is

    doubled.}

    else // the normal zone, skip it{

    WithinRange = 0; // skip this speed without processing it and continue on until the next"best zone" occurs

    }

    if (ZoneID == 2) // if at the end of the first best zone{

    if ((CurrentSpeed == BestSpeeds1End) && (BestSpeeds2Start > NormalSpeedsEnd)) //only if at the end of the group and there aren't any other groups after this

    {ProcessingStage = 3; // done processing

    }

    }

    else if (ZoneID == 4) // if at the end of the second best zone{

    if ((CurrentSpeed == BestSpeeds2End) && (BestSpeeds3Start > NormalSpeedsEnd)) //only if at the end of the group and there aren't any other groups after this

    {ProcessingStage = 3; // done processing

    }}

    else if (ZoneID == 6) // if at the end of the third best zone{

    if (CurrentSpeed >= BestSpeeds3End) // only if at the end of the group

    { ProcessingStage = 3; // done processing}

    }}

    if (DebugTest[1] == 1){

    DebugTest[6] = CurrentSpeed;}

    }

    void CreateOutputFiles(){

    /*This function reads any input files and writes the output based on the speeds used.

    There are 4 stages:Stage 1: Obtain the speed to process. Do the normal speeds first then the "best zone" speeds.Use a while loop and the FindNextSampleRate() function for this.Stage 2: Read the source file upon a zone change.If the next speed is in the same zone as the current, don't read the source file.Stage 3: Determine the amount of progress made. The normal, best, and overall progress

    should be indicated.The actual completion is based solely on the speeds rather than the number completed since

    it's quite erratic.The formula is

    "log10(CurrentSpeed/NormalSpeedsStart)/log10(NormalSpeedsEnd/NormalSpeedsStart)".For overall, use a weighted average - 1 part normal, 5 parts best (completing normal means

    25% overall completion).The DOS filler characters are used for this, 20 (space; 0), B0 (1/2), B1 (1), B2 (1 1/2), and DB

    (2).Each "block" is 2 percentage units so 50 are needed. For 13.2% completion, 6 fulls (DB) and a

    half (B1) are used.Stage 4: Write the data to disk as a WAV file.

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    10/19

    The format is in the "[speed] [song name].wav" format where [speed] is a 6-digit number withleading zeros.

    Progress bar design:

    Completion (approximate):--------------------------------------------------

    Normal: | | 100.0%--------------------------------------------------

    Best: | | 040.0%--------------------------------------------------

    Overall: | | 055.0%--------------------------------------------------

    */

    unsigned int PreviousZone = 0;char CompletionString[51]; // used for the progress indicatorsunsigned int BaseStringPosition;double NormalCompletion;double BestCompletion;double OverallCompletion;double FileSizeMiB = 0.0;double DataWrittenGiB = 0.0;unsigned int Units; // used for progress bars

    CurrentSpeed = 0; // set the current speed here before processing anythingWithinRange = 0; // initiate it and to falsify the loop for stage 1

    DebugTest[0] = 0;

    // a sanity check, fixing a bug when large-range best zones get segmentedif (BestSpeeds1End == BestSpeeds2Start){

    BestSpeeds1End--;}

    if (BestSpeeds2End == BestSpeeds3Start){

    BestSpeeds2End--;

    }while (ProcessingStage < 3){

    // Stage 1: Obtain the speed to process.PreviousZone = ZoneID; // log the previous zone to prevent excessive rereading

    while (WithinRange != 1){

    FindNextSampleRate();}

    if (WithinRange == 1){

    // Stage 2: Read the source file upon a zone change.if ((ZoneID != PreviousZone) || (CurrentSpeed == NormalSpeedsStart) || (CurrentSpeed ==BestSpeeds1Start)) // if just starting, the zone changed, or read the source file

    {// exclusive to samplers with just one zoneif ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd ==

    BestSpeeds1End)){

    sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\%s base.wav",SongName, ZoneID); // read the contents for the zone's base file

    }

    else // standard case{

    sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\%sbase%03d.wav", SongName, ZoneLapCount[ZoneID-1]); // read the contents for the zone's basefile

    }

    FileHandle = fopen(FileName, "rb"); // read in binary mode (that's what WAV files are)

  • 7/22/2019 Ulillillia's WAV file sample rate generator program

    11/19

    if (FileHandle != 0) // if the file was found and the file contents changed{

    fread(&FileHeadStart, 1, 24, FileHandle); // read the first 24 bytes of unchangingheader data

    fseek(FileHandle, 33, SEEK_SET); // skip to byte 33 as this part gets set within thefile itself

    fread(&FileHeadEnd, 1, 7, FileHandle); // read the next 7 bytes of more unchangingheader data

    fread(&FileLength, 4, 1, Fi leHandle); // read the file length data value, to determinehow many bytes are to be read and saved

    fread(&FileContents, 1, Fi leLength, FileHandle); // read one-byte chunks for the entire

    file's length, which is the end of the filefclose(FileHandle); // close the fileReadFlag = 1; // set the read flag

    }

    FileSizeMiB = ((double)FileLength+44.0)/1048576.0; // convert file size of whole file (44bytes for header) to mebibytes, MiB

    }

    // Stage 3: Determine the amount of progress made.// samplers only use one zoneif ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd ==

    BestSpeeds1End)){

    printf("Zone: 1; Loops: 1; Size: %6.2f MiB; Written: %6.3f GiB\n", FileSizeMiB,DataWrittenGiB);

    }

    else{

    printf("Zone: %d; Loops: %3d; Size: %6.2f MiB; Written: %6.3f GiB\n", ZoneID,ZoneLapCount[ZoneID-1], Fi leSizeMiB, DataWrittenGiB);

    }

    if (CurrentSpeed < FrequencyChangeover16K) // the rare 12K versions{

    sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\to convert\\12Kfiles\\%06d %s.wav", CurrentSpeed, SongName);

    printf("Writing: ...\\12K files\\%06d %s.wav", CurrentSpeed, SongName);}

    else i f ((CurrentSpeed >= FrequencyChangeover16K) && (CurrentSpeed = FrequencyChangeover24K) && (CurrentSpeed = FrequencyChangeover32K) && (CurrentSpeed