Advertisement
Guest User

Wav file sample rate generator.c (by ulillillia)

a guest
Aug 10th, 2012
2,313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 65.75 KB | None | 0 0
  1. #include <stdio.h> // standard input/output, used for functions like sprintf
  2. #include <string.h> // used for processing strings, particularly strcpy
  3. #include <math.h> // used for advanced mathematical functions - log10 in this case (for base 10 logarithms, used for progress indication)
  4.  
  5. #define _CRT_SECURE_NO_DEPRECATE // gets rid of the warnings from deprecation - sprintf, fopen, etc. is standard C
  6.  
  7. unsigned int Modifier; // adjusts sample rate in file based on source's true speed sample rate
  8. // unsigned int Steps;
  9. unsigned int BestSpeeds1Start; // the speed ranges of up to 3 best zones, that most listened to
  10. unsigned int BestSpeeds1End;
  11. unsigned int BestSpeeds2Start;
  12. unsigned int BestSpeeds2End;
  13. unsigned int BestSpeeds3Start;
  14. unsigned int BestSpeeds3End;
  15. unsigned int NormalSpeedsStart; // the speed ranges of the normal zone, where the song sounds reasonable
  16. unsigned int NormalSpeedsEnd;
  17. unsigned int CurrentSpeed = 0; // the current sample rate (speed)
  18.  
  19. unsigned int FrequencyChangeover16K; // the speed (sample rate) at which the output MP3's sample rate increases, to allow for optimization
  20. unsigned int FrequencyChangeover24K;
  21. unsigned int FrequencyChangeover32K;
  22. unsigned int FrequencyChangeover48K;
  23. unsigned int ProcessingStage = 1; // a "flag" that indicates whether the normal zone or best zone speeds are reached, or the end
  24. unsigned int WithinRange; // a "flag" to indicate that a speed is within the speed zone
  25. unsigned int ZoneID; // zone identifier
  26. unsigned int ZoneLapCount[7]; // number of loops within each zone (used in the base file's name)
  27. unsigned int ReadFlag = 0; // a flag to indicate that the next zone's base file is read, for more control on the displaying of text
  28.  
  29. unsigned int SampleRateInFile; // the sample rate used in the file's info
  30. unsigned int BytesPerSecond; // equal to SampleRate*Multiplier
  31. unsigned int Multiplier; // the multiplier used for the BytesPerSecond variable, based on the number of bytes per sample
  32. unsigned char FileHeadStart[24]; // for copying identical file header data
  33. unsigned char FileHeadEnd[7]; // for copying the last parts of the file header data
  34.  
  35. unsigned int FileLength; // the length of the file after the header data in bytes
  36. unsigned char FileContents[250000000]; // the contents of the file for copying, since the samples themselves don't change at all // use array with size bigger than file size or malloc it
  37. char FileName[128]; // the file name for the output file
  38. char SongName[60]; // for the name of the song for easier processing
  39.  
  40. unsigned int DebugTest[16]; // debugging variables
  41.  
  42. FILE *FileHandle; // used for the reading and writing of files
  43.  
  44. void FindNextSampleRate()
  45. {
  46.     /*
  47.     This function determines the next speed, sets flags and essential in-file data, and determines the zone afterwards.
  48.    
  49.     This function has 3 stages:
  50.     Stage 1:  Obtain the next speed based on the mode.  Normal speeds have big gaps and "best zone" speeds have tiny gaps.
  51.     Stage 2:  Determine what zone this speed is in.  If in range, set the file's sample rate and bytes per second values accordingly
  52.     If at the end of the normal speeds, restart from the beginning and do the "best zone" speeds.
  53.     Stage 3:  Set flags and essential in-file data.  This is needed to determine what file to use.
  54.     */
  55.    
  56.     if (CurrentSpeed <= 70000)
  57.     {
  58.         DebugTest[1] = 1; // a flag
  59.         DebugTest[2] = CurrentSpeed; // what the speed was originally
  60.     }
  61.    
  62.     else
  63.     {
  64.         DebugTest[1] = 0; // reset
  65.     }
  66.    
  67.     // Stage 1:  Obtain the next speed based on the mode.
  68.     // exclusive to samplers, of which always use the best zone speeds
  69.     if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  70.     {
  71.         ProcessingStage = 2;
  72.     }
  73.    
  74.     if ((ProcessingStage == 1) && (NormalSpeedsStart < BestSpeeds1Start)) // the normal speeds and not a sampler/special version
  75.     {
  76.         if (CurrentSpeed < 20000) { CurrentSpeed = 20000; } // 1/5
  77.         else if (CurrentSpeed < 20972) { CurrentSpeed = 20972; } // "speed -2"
  78.         else if (CurrentSpeed < 22500) { CurrentSpeed = 22500; }
  79.         else if (CurrentSpeed < 25000) { CurrentSpeed = 25000; } // 1/4; 24 semi-tones lower
  80.         else if (CurrentSpeed < 26214) { CurrentSpeed = 26214; } // "speed -1"
  81.         else if (CurrentSpeed < 27500) { CurrentSpeed = 27500; }
  82.         else if (CurrentSpeed < 30000) { CurrentSpeed = 30000; }
  83.         else if (CurrentSpeed < 32768) { CurrentSpeed = 32768; } // "speed 0"
  84.         else if (CurrentSpeed < 33333) { CurrentSpeed = 33333; } // 1/3
  85.         else if (CurrentSpeed < 35000) { CurrentSpeed = 35000; }
  86.         else if (CurrentSpeed < 35355) { CurrentSpeed = 35355; } // sqrt(1/8); 18 semi-tones lower
  87.         else if (CurrentSpeed < 40000) { CurrentSpeed = 40000; } // extended minimum; 2/5
  88.         else if (CurrentSpeed < 40960) { CurrentSpeed = 40960; } // "speed 1"
  89.         else if (CurrentSpeed < 45000) { CurrentSpeed = 45000; }
  90.         else if (CurrentSpeed < 50000) { CurrentSpeed = 50000; } // standard minimum; 1/2; 12 semi-tones lower
  91.         else if (CurrentSpeed < 51200) { CurrentSpeed = 51200; } // "speed 2"
  92.         else if (CurrentSpeed < 55000) { CurrentSpeed = 55000; }
  93.         else if (CurrentSpeed < 60000) { CurrentSpeed = 60000; }
  94.         else if (CurrentSpeed < 64000) { CurrentSpeed = 64000; } // "speed 3"
  95.         else if (CurrentSpeed < 66667) { CurrentSpeed = 66667; } // 2/3
  96.         else if (CurrentSpeed < 70000) { CurrentSpeed = 70000; }
  97.         else if (CurrentSpeed < 70711) { CurrentSpeed = 70711; } // sqrt(1/2); 6 semi-tones lower
  98.         else if (CurrentSpeed < 75000) { CurrentSpeed = 75000; } // 3/4
  99.         else if (CurrentSpeed < 80000) { CurrentSpeed = 80000; } // "speed 4"; 4/5
  100.         else if (CurrentSpeed < 83333) { CurrentSpeed = 83333; } // 5/6
  101.         else if (CurrentSpeed < 90000) { CurrentSpeed = 90000; }
  102.         else if (CurrentSpeed < 100000) { CurrentSpeed = 100000; } // true speed; "speed 5"
  103.         else if (CurrentSpeed < 110000) { CurrentSpeed = 110000; }
  104.         else if (CurrentSpeed < 116667) { CurrentSpeed = 116667; } // 7/6
  105.         else if (CurrentSpeed < 125000) { CurrentSpeed = 125000; } // standard maximum; "speed 6"; 5/4
  106.         else if (CurrentSpeed < 133333) { CurrentSpeed = 133333; } // 4/3
  107.         else if (CurrentSpeed < 140000) { CurrentSpeed = 140000; } // extended maximum
  108.         else if (CurrentSpeed < 141421) { CurrentSpeed = 141421; } // sqrt(2); 6 semi-tones higher
  109.         else if (CurrentSpeed < 150000) { CurrentSpeed = 150000; } // 3/2
  110.         else if (CurrentSpeed < 156250) { CurrentSpeed = 156250; } // "speed 7"
  111.         else if (CurrentSpeed < 166667) { CurrentSpeed = 166667; } // 5/3
  112.         else if (CurrentSpeed < 175000) { CurrentSpeed = 175000; }
  113.         else if (CurrentSpeed < 195313) { CurrentSpeed = 195313; } // "speed 8"
  114.         else if (CurrentSpeed < 200000) { CurrentSpeed = 200000; } // double; 12 semi-tones higher
  115.         else if (CurrentSpeed < 225000) { CurrentSpeed = 225000; }
  116.         else if (CurrentSpeed < 244141) { CurrentSpeed = 244141; } // "speed 9"
  117.         else if (CurrentSpeed < 250000) { CurrentSpeed = 250000; } // 5/2
  118.         else if (CurrentSpeed < 282843) { CurrentSpeed = 282843; } // sqrt(8); 18 semi-tones higher
  119.         else if (CurrentSpeed < 300000) { CurrentSpeed = 300000; } // triple
  120.         else if (CurrentSpeed < 305176) { CurrentSpeed = 305176; } // "speed 10"
  121.         else if (CurrentSpeed < 350000) { CurrentSpeed = 350000; }
  122.         else if (CurrentSpeed < 381470) { CurrentSpeed = 381470; } // "speed 11"
  123.         else if (CurrentSpeed < 400000) { CurrentSpeed = 400000; } // quadruple; 24 semi-tones higher
  124.         else if (CurrentSpeed < 450000) { CurrentSpeed = 450000; }
  125.         else if (CurrentSpeed < 476837) { CurrentSpeed = 476837; } // "speed 12"
  126.         else if (CurrentSpeed < 500000) { CurrentSpeed = 500000; } // quintuple
  127.     }
  128.    
  129.     if (DebugTest[1] == 1)
  130.     {
  131.         DebugTest[3] = CurrentSpeed; // what the speed is after the normal zone
  132.     }
  133.    
  134.     if ((ProcessingStage == 2) || (NormalSpeedsStart == BestSpeeds1Start)) // the best speeds (or a sampler/special version)
  135.     {
  136.         if (CurrentSpeed < 20000) { CurrentSpeed = 20000; } // 1/5
  137.         else if (CurrentSpeed < 20250) { CurrentSpeed = 20250; }
  138.         else if (CurrentSpeed < 20500) { CurrentSpeed = 20500; }
  139.         else if (CurrentSpeed < 20750) { CurrentSpeed = 20750; }
  140.         else if (CurrentSpeed < 20972) { CurrentSpeed = 20972; } // "speed -2"
  141.         else if (CurrentSpeed < 21000) { CurrentSpeed = 21000; }
  142.         else if (CurrentSpeed < 21250) { CurrentSpeed = 21250; }
  143.         else if (CurrentSpeed < 21500) { CurrentSpeed = 21500; }
  144.         else if (CurrentSpeed < 21750) { CurrentSpeed = 21750; }
  145.         else if (CurrentSpeed < 22000) { CurrentSpeed = 22000; }
  146.         else if (CurrentSpeed < 22222) { CurrentSpeed = 22222; } // 2/9
  147.         else if (CurrentSpeed < 22250) { CurrentSpeed = 22250; }
  148.         else if (CurrentSpeed < 22500) { CurrentSpeed = 22500; }
  149.         else if (CurrentSpeed < 22750) { CurrentSpeed = 22750; }
  150.         else if (CurrentSpeed < 23000) { CurrentSpeed = 23000; }
  151.         else if (CurrentSpeed < 23250) { CurrentSpeed = 23250; }
  152.         else if (CurrentSpeed < 23500) { CurrentSpeed = 23500; }
  153.         else if (CurrentSpeed < 23750) { CurrentSpeed = 23750; }
  154.         else if (CurrentSpeed < 24000) { CurrentSpeed = 24000; }
  155.         else if (CurrentSpeed < 24250) { CurrentSpeed = 24250; }
  156.         else if (CurrentSpeed < 24500) { CurrentSpeed = 24500; }
  157.         else if (CurrentSpeed < 24750) { CurrentSpeed = 24750; }
  158.         else if (CurrentSpeed < 25000) { CurrentSpeed = 25000; } // 1/4; 24 semi-tones lower
  159.         else if (CurrentSpeed < 25250) { CurrentSpeed = 25250; }
  160.         else if (CurrentSpeed < 25500) { CurrentSpeed = 25500; }
  161.         else if (CurrentSpeed < 25750) { CurrentSpeed = 25750; }
  162.         else if (CurrentSpeed < 26000) { CurrentSpeed = 26000; }
  163.         else if (CurrentSpeed < 26214) { CurrentSpeed = 26214; } // "speed -1"
  164.         else if (CurrentSpeed < 26250) { CurrentSpeed = 26250; }
  165.         else if (CurrentSpeed < 26500) { CurrentSpeed = 26500; }
  166.         else if (CurrentSpeed < 26667) { CurrentSpeed = 26667; } // 4/15
  167.         else if (CurrentSpeed < 26750) { CurrentSpeed = 26750; }
  168.         else if (CurrentSpeed < 27000) { CurrentSpeed = 27000; }
  169.         else if (CurrentSpeed < 27250) { CurrentSpeed = 27250; }
  170.         else if (CurrentSpeed < 27500) { CurrentSpeed = 27500; }
  171.         else if (CurrentSpeed < 27750) { CurrentSpeed = 27750; }
  172.         else if (CurrentSpeed < 28000) { CurrentSpeed = 28000; }
  173.         else if (CurrentSpeed < 28250) { CurrentSpeed = 28250; }
  174.         else if (CurrentSpeed < 28500) { CurrentSpeed = 28500; }
  175.         else if (CurrentSpeed < 28571) { CurrentSpeed = 28571; } // 2/7
  176.         else if (CurrentSpeed < 28750) { CurrentSpeed = 28750; }
  177.         else if (CurrentSpeed < 29000) { CurrentSpeed = 29000; }
  178.         else if (CurrentSpeed < 29250) { CurrentSpeed = 29250; }
  179.         else if (CurrentSpeed < 29500) { CurrentSpeed = 29500; }
  180.         else if (CurrentSpeed < 29750) { CurrentSpeed = 29750; }
  181.         else if (CurrentSpeed < 30000) { CurrentSpeed = 30000; } // 3/10
  182.         else if (CurrentSpeed < 30250) { CurrentSpeed = 30250; }
  183.         else if (CurrentSpeed < 30500) { CurrentSpeed = 30500; }
  184.         else if (CurrentSpeed < 30750) { CurrentSpeed = 30750; }
  185.         else if (CurrentSpeed < 31000) { CurrentSpeed = 31000; }
  186.         else if (CurrentSpeed < 31250) { CurrentSpeed = 31250; }
  187.         else if (CurrentSpeed < 31500) { CurrentSpeed = 31500; }
  188.         else if (CurrentSpeed < 32000) { CurrentSpeed = 32000; }
  189.         else if (CurrentSpeed < 32500) { CurrentSpeed = 32500; }
  190.         else if (CurrentSpeed < 32768) { CurrentSpeed = 32768; } // "speed 0"
  191.         else if (CurrentSpeed < 33000) { CurrentSpeed = 33000; }
  192.         else if (CurrentSpeed < 33333) { CurrentSpeed = 33333; } // 1/3
  193.         else if (CurrentSpeed < 33500) { CurrentSpeed = 33500; }
  194.         else if (CurrentSpeed < 34000) { CurrentSpeed = 34000; }
  195.         else if (CurrentSpeed < 34500) { CurrentSpeed = 34500; }
  196.         else if (CurrentSpeed < 35000) { CurrentSpeed = 35000; }
  197.         else if (CurrentSpeed < 35355) { CurrentSpeed = 35355; } // sqrt(1/8); 18 semi-tones lower
  198.         else if (CurrentSpeed < 35500) { CurrentSpeed = 35500; }
  199.         else if (CurrentSpeed < 36000) { CurrentSpeed = 36000; }
  200.         else if (CurrentSpeed < 36500) { CurrentSpeed = 36500; }
  201.         else if (CurrentSpeed < 37000) { CurrentSpeed = 37000; }
  202.         else if (CurrentSpeed < 37500) { CurrentSpeed = 37500; } // 3/8
  203.         else if (CurrentSpeed < 38000) { CurrentSpeed = 38000; }
  204.         else if (CurrentSpeed < 38500) { CurrentSpeed = 38500; }
  205.         else if (CurrentSpeed < 39000) { CurrentSpeed = 39000; }
  206.         else if (CurrentSpeed < 39500) { CurrentSpeed = 39500; }
  207.         else if (CurrentSpeed < 40000) { CurrentSpeed = 40000; } // extended minimum; 2/5
  208.         else if (CurrentSpeed < 40500) { CurrentSpeed = 40500; }
  209.         else if (CurrentSpeed < 40960) { CurrentSpeed = 40960; } // "speed 1"
  210.         else if (CurrentSpeed < 41000) { CurrentSpeed = 41000; }
  211.         else if (CurrentSpeed < 41500) { CurrentSpeed = 41500; }
  212.         else if (CurrentSpeed < 41667) { CurrentSpeed = 41667; } // 5/12
  213.         else if (CurrentSpeed < 42000) { CurrentSpeed = 42000; }
  214.         else if (CurrentSpeed < 42500) { CurrentSpeed = 42500; }
  215.         else if (CurrentSpeed < 42857) { CurrentSpeed = 42857; } // 3/7
  216.         else if (CurrentSpeed < 43000) { CurrentSpeed = 43000; }
  217.         else if (CurrentSpeed < 43500) { CurrentSpeed = 43500; }
  218.         else if (CurrentSpeed < 44000) { CurrentSpeed = 44000; }
  219.         else if (CurrentSpeed < 44444) { CurrentSpeed = 44444; } // 4/9
  220.         else if (CurrentSpeed < 44500) { CurrentSpeed = 44500; }
  221.         else if (CurrentSpeed < 45000) { CurrentSpeed = 45000; }
  222.         else if (CurrentSpeed < 45500) { CurrentSpeed = 45500; }
  223.         else if (CurrentSpeed < 46000) { CurrentSpeed = 46000; }
  224.         else if (CurrentSpeed < 46500) { CurrentSpeed = 46500; }
  225.         else if (CurrentSpeed < 46667) { CurrentSpeed = 46667; } // 7/15
  226.         else if (CurrentSpeed < 47000) { CurrentSpeed = 47000; }
  227.         else if (CurrentSpeed < 47500) { CurrentSpeed = 47500; }
  228.         else if (CurrentSpeed < 48000) { CurrentSpeed = 48000; }
  229.         else if (CurrentSpeed < 48500) { CurrentSpeed = 48500; }
  230.         else if (CurrentSpeed < 49000) { CurrentSpeed = 49000; }
  231.         else if (CurrentSpeed < 49500) { CurrentSpeed = 49500; }
  232.         else if (CurrentSpeed < 50000) { CurrentSpeed = 50000; } // standard minimum; 1/2; 12 semi-tones lower
  233.         else if (CurrentSpeed < 50500) { CurrentSpeed = 50500; }
  234.         else if (CurrentSpeed < 51000) { CurrentSpeed = 51000; }
  235.         else if (CurrentSpeed < 51200) { CurrentSpeed = 51200; } // "speed 2"
  236.         else if (CurrentSpeed < 51500) { CurrentSpeed = 51500; }
  237.         else if (CurrentSpeed < 52000) { CurrentSpeed = 52000; }
  238.         else if (CurrentSpeed < 52500) { CurrentSpeed = 52500; }
  239.         else if (CurrentSpeed < 53000) { CurrentSpeed = 53000; }
  240.         else if (CurrentSpeed < 53333) { CurrentSpeed = 53333; } // 8/15
  241.         else if (CurrentSpeed < 53500) { CurrentSpeed = 53500; }
  242.         else if (CurrentSpeed < 54000) { CurrentSpeed = 54000; }
  243.         else if (CurrentSpeed < 54500) { CurrentSpeed = 54500; }
  244.         else if (CurrentSpeed < 55000) { CurrentSpeed = 55000; }
  245.         else if (CurrentSpeed < 55500) { CurrentSpeed = 55500; }
  246.         else if (CurrentSpeed < 55556) { CurrentSpeed = 55556; } // 5/9
  247.         else if (CurrentSpeed < 56000) { CurrentSpeed = 56000; }
  248.         else if (CurrentSpeed < 56500) { CurrentSpeed = 56500; }
  249.         else if (CurrentSpeed < 57000) { CurrentSpeed = 57000; }
  250.         else if (CurrentSpeed < 57143) { CurrentSpeed = 57143; } // 4/7
  251.         else if (CurrentSpeed < 57500) { CurrentSpeed = 57500; }
  252.         else if (CurrentSpeed < 58000) { CurrentSpeed = 58000; }
  253.         else if (CurrentSpeed < 58333) { CurrentSpeed = 58333; } // 7/12
  254.         else if (CurrentSpeed < 58500) { CurrentSpeed = 58500; }
  255.         else if (CurrentSpeed < 59000) { CurrentSpeed = 59000; }
  256.         else if (CurrentSpeed < 59500) { CurrentSpeed = 59500; }
  257.         else if (CurrentSpeed < 60000) { CurrentSpeed = 60000; } // 3/5
  258.         else if (CurrentSpeed < 60500) { CurrentSpeed = 60500; }
  259.         else if (CurrentSpeed < 61000) { CurrentSpeed = 61000; }
  260.         else if (CurrentSpeed < 61500) { CurrentSpeed = 61500; }
  261.         else if (CurrentSpeed < 62000) { CurrentSpeed = 62000; }
  262.         else if (CurrentSpeed < 62500) { CurrentSpeed = 62500; } // 5/8
  263.         else if (CurrentSpeed < 63000) { CurrentSpeed = 63000; }
  264.         else if (CurrentSpeed < 64000) { CurrentSpeed = 64000; } // "speed 3"
  265.         else if (CurrentSpeed < 65000) { CurrentSpeed = 65000; }
  266.         else if (CurrentSpeed < 66000) { CurrentSpeed = 66000; }
  267.         else if (CurrentSpeed < 66667) { CurrentSpeed = 66667; } // 2/3
  268.         else if (CurrentSpeed < 67000) { CurrentSpeed = 67000; }
  269.         else if (CurrentSpeed < 68000) { CurrentSpeed = 68000; }
  270.         else if (CurrentSpeed < 69000) { CurrentSpeed = 69000; }
  271.         else if (CurrentSpeed < 70000) { CurrentSpeed = 70000; } // 7/10
  272.         else if (CurrentSpeed < 70711) { CurrentSpeed = 70711; } // sqrt(1/2); 6 semi-tones lower
  273.         else if (CurrentSpeed < 71000) { CurrentSpeed = 71000; }
  274.         else if (CurrentSpeed < 71429) { CurrentSpeed = 71429; } // 5/7
  275.         else if (CurrentSpeed < 72000) { CurrentSpeed = 72000; }
  276.         else if (CurrentSpeed < 73000) { CurrentSpeed = 73000; }
  277.         else if (CurrentSpeed < 73333) { CurrentSpeed = 73333; } // 11/15
  278.         else if (CurrentSpeed < 74000) { CurrentSpeed = 74000; }
  279.         else if (CurrentSpeed < 75000) { CurrentSpeed = 75000; } // 3/4
  280.         else if (CurrentSpeed < 76000) { CurrentSpeed = 76000; }
  281.         else if (CurrentSpeed < 77000) { CurrentSpeed = 77000; }
  282.         else if (CurrentSpeed < 77778) { CurrentSpeed = 77778; } // 7/8
  283.         else if (CurrentSpeed < 78000) { CurrentSpeed = 78000; }
  284.         else if (CurrentSpeed < 79000) { CurrentSpeed = 79000; }
  285.         else if (CurrentSpeed < 80000) { CurrentSpeed = 80000; } // 4/5
  286.         else if (CurrentSpeed < 81000) { CurrentSpeed = 81000; }
  287.         else if (CurrentSpeed < 82000) { CurrentSpeed = 82000; }
  288.         else if (CurrentSpeed < 83000) { CurrentSpeed = 83000; }
  289.         else if (CurrentSpeed < 83333) { CurrentSpeed = 83333; } // 5/6
  290.         else if (CurrentSpeed < 84000) { CurrentSpeed = 84000; }
  291.         else if (CurrentSpeed < 85000) { CurrentSpeed = 85000; }
  292.         else if (CurrentSpeed < 85714) { CurrentSpeed = 85714; } // 6/7
  293.         else if (CurrentSpeed < 86000) { CurrentSpeed = 86000; }
  294.         else if (CurrentSpeed < 86667) { CurrentSpeed = 86667; } // 13/15
  295.         else if (CurrentSpeed < 87000) { CurrentSpeed = 87000; }
  296.         else if (CurrentSpeed < 87500) { CurrentSpeed = 87500; } // 7/8
  297.         else if (CurrentSpeed < 88000) { CurrentSpeed = 88000; }
  298.         else if (CurrentSpeed < 88889) { CurrentSpeed = 88889; } // 8/9
  299.         else if (CurrentSpeed < 89000) { CurrentSpeed = 89000; }
  300.         else if (CurrentSpeed < 90000) { CurrentSpeed = 90000; } // 9/10
  301.         else if (CurrentSpeed < 91000) { CurrentSpeed = 91000; }
  302.         else if (CurrentSpeed < 91667) { CurrentSpeed = 91667; } // 11/12
  303.         else if (CurrentSpeed < 92000) { CurrentSpeed = 92000; }
  304.         else if (CurrentSpeed < 93000) { CurrentSpeed = 93000; }
  305.         else if (CurrentSpeed < 93333) { CurrentSpeed = 93333; } // 14/15
  306.         else if (CurrentSpeed < 94000) { CurrentSpeed = 94000; }
  307.         else if (CurrentSpeed < 95000) { CurrentSpeed = 95000; }
  308.         else if (CurrentSpeed < 96000) { CurrentSpeed = 96000; }
  309.         else if (CurrentSpeed < 97000) { CurrentSpeed = 97000; }
  310.         else if (CurrentSpeed < 98000) { CurrentSpeed = 98000; }
  311.         else if (CurrentSpeed < 99000) { CurrentSpeed = 99000; }
  312.         else if (CurrentSpeed < 100000) { CurrentSpeed = 100000; } // true speed; "speed 5"
  313.         else if (CurrentSpeed < 101000) { CurrentSpeed = 101000; }
  314.         else if (CurrentSpeed < 102000) { CurrentSpeed = 102000; }
  315.         else if (CurrentSpeed < 103000) { CurrentSpeed = 103000; }
  316.         else if (CurrentSpeed < 104000) { CurrentSpeed = 104000; }
  317.         else if (CurrentSpeed < 105000) { CurrentSpeed = 105000; }
  318.         else if (CurrentSpeed < 106000) { CurrentSpeed = 106000; }
  319.         else if (CurrentSpeed < 106667) { CurrentSpeed = 106667; } // 16/15
  320.         else if (CurrentSpeed < 107000) { CurrentSpeed = 107000; }
  321.         else if (CurrentSpeed < 108000) { CurrentSpeed = 108000; }
  322.         else if (CurrentSpeed < 108333) { CurrentSpeed = 108333; } // 13/12
  323.         else if (CurrentSpeed < 109000) { CurrentSpeed = 109000; }
  324.         else if (CurrentSpeed < 110000) { CurrentSpeed = 110000; } // 11/10
  325.         else if (CurrentSpeed < 111000) { CurrentSpeed = 111000; }
  326.         else if (CurrentSpeed < 111111) { CurrentSpeed = 111111; } // 10/9
  327.         else if (CurrentSpeed < 112000) { CurrentSpeed = 112000; }
  328.         else if (CurrentSpeed < 112500) { CurrentSpeed = 112500; } // 9/8
  329.         else if (CurrentSpeed < 113000) { CurrentSpeed = 113000; }
  330.         else if (CurrentSpeed < 113333) { CurrentSpeed = 113333; } // 17/15
  331.         else if (CurrentSpeed < 114000) { CurrentSpeed = 114000; }
  332.         else if (CurrentSpeed < 114286) { CurrentSpeed = 114286; } // 8/7
  333.         else if (CurrentSpeed < 115000) { CurrentSpeed = 115000; }
  334.         else if (CurrentSpeed < 116000) { CurrentSpeed = 116000; }
  335.         else if (CurrentSpeed < 116667) { CurrentSpeed = 116667; } // 7/6
  336.         else if (CurrentSpeed < 117000) { CurrentSpeed = 117000; }
  337.         else if (CurrentSpeed < 118000) { CurrentSpeed = 118000; }
  338.         else if (CurrentSpeed < 119000) { CurrentSpeed = 119000; }
  339.         else if (CurrentSpeed < 120000) { CurrentSpeed = 120000; } // 6/5
  340.         else if (CurrentSpeed < 121000) { CurrentSpeed = 121000; }
  341.         else if (CurrentSpeed < 122000) { CurrentSpeed = 122000; }
  342.         else if (CurrentSpeed < 122222) { CurrentSpeed = 122222; } // 11/9
  343.         else if (CurrentSpeed < 123000) { CurrentSpeed = 123000; }
  344.         else if (CurrentSpeed < 124000) { CurrentSpeed = 124000; }
  345.         else if (CurrentSpeed < 125000) { CurrentSpeed = 125000; } // standard maximum; "speed 6"; 5/4
  346.         else if (CurrentSpeed < 127500) { CurrentSpeed = 127500; }
  347.         else if (CurrentSpeed < 128571) { CurrentSpeed = 128571; } // 9/7
  348.         else if (CurrentSpeed < 130000) { CurrentSpeed = 130000; }
  349.         else if (CurrentSpeed < 132500) { CurrentSpeed = 132500; }
  350.         else if (CurrentSpeed < 133333) { CurrentSpeed = 133333; } // 4/3
  351.         else if (CurrentSpeed < 135000) { CurrentSpeed = 135000; }
  352.         else if (CurrentSpeed < 137500) { CurrentSpeed = 137500; }
  353.         else if (CurrentSpeed < 140000) { CurrentSpeed = 140000; } // extended maximum; 7/5
  354.         else if (CurrentSpeed < 141421) { CurrentSpeed = 141421; } // sqrt(2); 6 semi-tones higher
  355.         else if (CurrentSpeed < 142500) { CurrentSpeed = 142500; }
  356.         else if (CurrentSpeed < 142857) { CurrentSpeed = 142857; } // 10/7
  357.         else if (CurrentSpeed < 145000) { CurrentSpeed = 145000; }
  358.         else if (CurrentSpeed < 147500) { CurrentSpeed = 147500; }
  359.         else if (CurrentSpeed < 150000) { CurrentSpeed = 150000; } // 3/2
  360.         else if (CurrentSpeed < 152500) { CurrentSpeed = 152500; }
  361.         else if (CurrentSpeed < 155000) { CurrentSpeed = 155000; }
  362.         else if (CurrentSpeed < 156250) { CurrentSpeed = 156250; } // "speed 7"
  363.         else if (CurrentSpeed < 157500) { CurrentSpeed = 157500; }
  364.         else if (CurrentSpeed < 160000) { CurrentSpeed = 160000; } // 8/5
  365.         else if (CurrentSpeed < 162500) { CurrentSpeed = 162500; }
  366.         else if (CurrentSpeed < 165000) { CurrentSpeed = 165000; }
  367.         else if (CurrentSpeed < 166667) { CurrentSpeed = 166667; } // 5/3
  368.         else if (CurrentSpeed < 167500) { CurrentSpeed = 167500; }
  369.         else if (CurrentSpeed < 170000) { CurrentSpeed = 170000; }
  370.         else if (CurrentSpeed < 172500) { CurrentSpeed = 172500; }
  371.         else if (CurrentSpeed < 175000) { CurrentSpeed = 175000; } // 7/4
  372.         else if (CurrentSpeed < 177500) { CurrentSpeed = 177500; }
  373.         else if (CurrentSpeed < 180000) { CurrentSpeed = 180000; } // 9/5
  374.         else if (CurrentSpeed < 182500) { CurrentSpeed = 182500; }
  375.         else if (CurrentSpeed < 183333) { CurrentSpeed = 183333; } // 11/6
  376.         else if (CurrentSpeed < 185000) { CurrentSpeed = 185000; }
  377.         else if (CurrentSpeed < 187500) { CurrentSpeed = 187500; }
  378.         else if (CurrentSpeed < 190000) { CurrentSpeed = 190000; }
  379.         else if (CurrentSpeed < 192500) { CurrentSpeed = 192500; }
  380.         else if (CurrentSpeed < 195000) { CurrentSpeed = 195000; }
  381.         else if (CurrentSpeed < 195313) { CurrentSpeed = 195313; } // "speed 8"
  382.         else if (CurrentSpeed < 197500) { CurrentSpeed = 197500; }
  383.         else if (CurrentSpeed < 200000) { CurrentSpeed = 200000; } // double; 12 semi-tones higher
  384.         else if (CurrentSpeed < 202500) { CurrentSpeed = 202500; }
  385.         else if (CurrentSpeed < 205000) { CurrentSpeed = 205000; }
  386.         else if (CurrentSpeed < 207500) { CurrentSpeed = 207500; }
  387.         else if (CurrentSpeed < 210000) { CurrentSpeed = 210000; }
  388.         else if (CurrentSpeed < 212500) { CurrentSpeed = 212500; }
  389.         else if (CurrentSpeed < 215000) { CurrentSpeed = 215000; }
  390.         else if (CurrentSpeed < 217500) { CurrentSpeed = 217500; }
  391.         else if (CurrentSpeed < 220000) { CurrentSpeed = 220000; }
  392.         else if (CurrentSpeed < 222500) { CurrentSpeed = 222500; }
  393.         else if (CurrentSpeed < 225000) { CurrentSpeed = 225000; } // 9/4
  394.         else if (CurrentSpeed < 227500) { CurrentSpeed = 227500; }
  395.         else if (CurrentSpeed < 230000) { CurrentSpeed = 230000; }
  396.         else if (CurrentSpeed < 232500) { CurrentSpeed = 232500; }
  397.         else if (CurrentSpeed < 233333) { CurrentSpeed = 233333; } // 7/3
  398.         else if (CurrentSpeed < 235000) { CurrentSpeed = 235000; }
  399.         else if (CurrentSpeed < 237500) { CurrentSpeed = 237500; }
  400.         else if (CurrentSpeed < 240000) { CurrentSpeed = 240000; }
  401.         else if (CurrentSpeed < 242500) { CurrentSpeed = 242500; }
  402.         else if (CurrentSpeed < 244141) { CurrentSpeed = 244141; } // "speed 9"
  403.         else if (CurrentSpeed < 245000) { CurrentSpeed = 245000; }
  404.         else if (CurrentSpeed < 247500) { CurrentSpeed = 247500; }
  405.         else if (CurrentSpeed < 250000) { CurrentSpeed = 250000; } // 5/2
  406.         else if (CurrentSpeed < 255000) { CurrentSpeed = 255000; }
  407.         else if (CurrentSpeed < 260000) { CurrentSpeed = 260000; }
  408.         else if (CurrentSpeed < 265000) { CurrentSpeed = 265000; }
  409.         else if (CurrentSpeed < 266667) { CurrentSpeed = 266667; } // 8/3
  410.         else if (CurrentSpeed < 270000) { CurrentSpeed = 270000; }
  411.         else if (CurrentSpeed < 275000) { CurrentSpeed = 275000; }
  412.         else if (CurrentSpeed < 280000) { CurrentSpeed = 280000; }
  413.         else if (CurrentSpeed < 282843) { CurrentSpeed = 282843; } // sqrt(8); 18 semi-tones higher
  414.         else if (CurrentSpeed < 285000) { CurrentSpeed = 285000; }
  415.         else if (CurrentSpeed < 290000) { CurrentSpeed = 290000; }
  416.         else if (CurrentSpeed < 295000) { CurrentSpeed = 295000; }
  417.         else if (CurrentSpeed < 300000) { CurrentSpeed = 300000; } // triple
  418.         else if (CurrentSpeed < 305000) { CurrentSpeed = 305000; }
  419.         else if (CurrentSpeed < 305176) { CurrentSpeed = 305176; } // "speed 10"
  420.         else if (CurrentSpeed < 310000) { CurrentSpeed = 310000; }
  421.         else if (CurrentSpeed < 315000) { CurrentSpeed = 315000; }
  422.         else if (CurrentSpeed < 320000) { CurrentSpeed = 320000; }
  423.         else if (CurrentSpeed < 325000) { CurrentSpeed = 325000; }
  424.         else if (CurrentSpeed < 330000) { CurrentSpeed = 330000; }
  425.         else if (CurrentSpeed < 333333) { CurrentSpeed = 333333; } // 10/3
  426.         else if (CurrentSpeed < 335000) { CurrentSpeed = 335000; }
  427.         else if (CurrentSpeed < 340000) { CurrentSpeed = 340000; }
  428.         else if (CurrentSpeed < 345000) { CurrentSpeed = 345000; }
  429.         else if (CurrentSpeed < 350000) { CurrentSpeed = 350000; } // 7/2
  430.         else if (CurrentSpeed < 355000) { CurrentSpeed = 355000; }
  431.         else if (CurrentSpeed < 360000) { CurrentSpeed = 360000; }
  432.         else if (CurrentSpeed < 365000) { CurrentSpeed = 365000; }
  433.         else if (CurrentSpeed < 370000) { CurrentSpeed = 370000; }
  434.         else if (CurrentSpeed < 375000) { CurrentSpeed = 375000; }
  435.         else if (CurrentSpeed < 380000) { CurrentSpeed = 380000; }
  436.         else if (CurrentSpeed < 381470) { CurrentSpeed = 381470; } // "speed 11"
  437.         else if (CurrentSpeed < 385000) { CurrentSpeed = 385000; }
  438.         else if (CurrentSpeed < 390000) { CurrentSpeed = 390000; }
  439.         else if (CurrentSpeed < 395000) { CurrentSpeed = 395000; }
  440.         else if (CurrentSpeed < 400000) { CurrentSpeed = 400000; } // quadruple; 24-semi-tones higher
  441.         else if (CurrentSpeed < 405000) { CurrentSpeed = 405000; }
  442.         else if (CurrentSpeed < 410000) { CurrentSpeed = 410000; }
  443.         else if (CurrentSpeed < 415000) { CurrentSpeed = 415000; }
  444.         else if (CurrentSpeed < 420000) { CurrentSpeed = 420000; }
  445.         else if (CurrentSpeed < 425000) { CurrentSpeed = 425000; }
  446.         else if (CurrentSpeed < 430000) { CurrentSpeed = 430000; }
  447.         else if (CurrentSpeed < 435000) { CurrentSpeed = 435000; }
  448.         else if (CurrentSpeed < 440000) { CurrentSpeed = 440000; }
  449.         else if (CurrentSpeed < 445000) { CurrentSpeed = 445000; }
  450.         else if (CurrentSpeed < 450000) { CurrentSpeed = 450000; } // 9/2
  451.         else if (CurrentSpeed < 455000) { CurrentSpeed = 455000; }
  452.         else if (CurrentSpeed < 460000) { CurrentSpeed = 460000; }
  453.         else if (CurrentSpeed < 465000) { CurrentSpeed = 465000; }
  454.         else if (CurrentSpeed < 470000) { CurrentSpeed = 470000; }
  455.         else if (CurrentSpeed < 475000) { CurrentSpeed = 475000; }
  456.         else if (CurrentSpeed < 476837) { CurrentSpeed = 476837; } // "speed 12"
  457.         else if (CurrentSpeed < 480000) { CurrentSpeed = 480000; }
  458.         else if (CurrentSpeed < 485000) { CurrentSpeed = 485000; }
  459.         else if (CurrentSpeed < 490000) { CurrentSpeed = 490000; }
  460.         else if (CurrentSpeed < 495000) { CurrentSpeed = 495000; }
  461.         else if (CurrentSpeed < 500000) { CurrentSpeed = 500000; } // quintuple
  462.     }
  463.    
  464.     if (CurrentSpeed > NormalSpeedsEnd)
  465.     {
  466.         ProcessingStage = 2;
  467.         CurrentSpeed = BestSpeeds1Start;
  468.     }
  469.    
  470.     if (DebugTest[1] == 1)
  471.     {
  472.         DebugTest[4] = CurrentSpeed; // what the speed is after the best zone
  473.     }
  474.    
  475.     if (DebugTest[1] == 1)
  476.     {
  477.         DebugTest[8] = ZoneID;
  478.     }
  479.    
  480.     // Stage 2:  Determine what zone this speed is in.
  481.     if (CurrentSpeed < NormalSpeedsStart) { ZoneID = 0;} // no zone
  482.     else if ((CurrentSpeed >= NormalSpeedsStart) && (CurrentSpeed < BestSpeeds1Start)) { ZoneID = 1;}
  483.     else if ((CurrentSpeed >= BestSpeeds1Start) && (CurrentSpeed <= BestSpeeds1End)) { ZoneID = 2;}
  484.     else if ((CurrentSpeed > BestSpeeds1End) && (CurrentSpeed < BestSpeeds2Start)) { ZoneID = 3;}
  485.     else if ((CurrentSpeed >= BestSpeeds2Start) && (CurrentSpeed <= BestSpeeds2End)) { ZoneID = 4;}
  486.     else if ((CurrentSpeed > BestSpeeds2End) && (CurrentSpeed < BestSpeeds3Start)) { ZoneID = 5;}
  487.     else if ((CurrentSpeed >= BestSpeeds3Start) && (CurrentSpeed <= BestSpeeds3End)) { ZoneID = 6;}
  488.     else { ZoneID = 7;}
  489.    
  490.     if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End)) // samplers only use one zone
  491.     {
  492.         ZoneID = 2;
  493.        
  494.         if (CurrentSpeed < BestSpeeds1Start) // if below the initial speed
  495.         {
  496.             CurrentSpeed = BestSpeeds1Start; // make it at the initial speed
  497.         }
  498.     }
  499.    
  500.     if (DebugTest[1] == 1)
  501.     {
  502.         DebugTest[9] = ZoneID;
  503.     }
  504.    
  505.     if (DebugTest[1] == 1)
  506.     {
  507.         DebugTest[5] = CurrentSpeed;
  508.     }
  509.    
  510.     // Stage 3:  Set flags and essential in-file data.
  511.     if (ProcessingStage == 1) // the normal speeds
  512.     {
  513.         // those in any of the "best zone" must not be included - they should get skipped to save time
  514.         if ((ZoneID == 1) || (ZoneID == 3) || (ZoneID == 5) || (ZoneID == 7))
  515.         {
  516.             WithinRange = 1; // this indicates that the new speed is within range and should be processed
  517.            
  518.             // determine the sample rate as it is in the file
  519.             if (Modifier == 1) // the song's true speed is 50,000
  520.             {
  521.                 SampleRateInFile = (CurrentSpeed+1)/2; // Add 1 to allow for rounding
  522.             }
  523.  
  524.             else // true speed is 100,000 Hz
  525.             {
  526.                 SampleRateInFile = CurrentSpeed; // set it to what this system uses
  527.             }
  528.  
  529.             BytesPerSecond = SampleRateInFile * 2; // all files are 16-bit mono so this value is doubled.
  530.            
  531.             // check if at the end - go to mode 2 if done
  532.             if (CurrentSpeed > NormalSpeedsEnd)
  533.             {
  534.                 ProcessingStage = 2; // change to mode 2 for doing the best speeds
  535.                 CurrentSpeed = BestSpeeds1Start; // return to the start for one more cycle
  536.             }
  537.  
  538.             // a sampler - always use the best zone
  539.             if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  540.             {
  541.                 ZoneID = 2;
  542.                 ProcessingStage = 2;
  543.                 CurrentSpeed = BestSpeeds1Start;
  544.             }
  545.         }
  546.        
  547.         else // the best zone - skip it
  548.         {
  549.             WithinRange = 0; // it's not in range and the speed is ignored until the next processing stage is reached
  550.         }
  551.     }
  552.    
  553.     else if (ProcessingStage == 2)
  554.     {
  555.         // only those in the "best zone" get processed
  556.         if ((ZoneID == 2) || (ZoneID == 4) || (ZoneID == 6))
  557.         {
  558.             WithinRange = 1; // this indicates that the new speed is within range and should be processed
  559.            
  560.             if (Modifier == 1) // the song's true speed is 50,000
  561.             {
  562.                 SampleRateInFile = (CurrentSpeed+1)/2; // Add 1 to allow for rounding
  563.             }
  564.  
  565.             else // true speed is 100,000 Hz
  566.             {
  567.                 SampleRateInFile = CurrentSpeed; // set it to what this system uses
  568.             }
  569.            
  570.             BytesPerSecond = SampleRateInFile * 2; // all files are 16-bit mono so this value is doubled.
  571.         }
  572.        
  573.         else // the normal zone, skip it
  574.         {
  575.             WithinRange = 0; // skip this speed without processing it and continue on until the next "best zone" occurs
  576.         }
  577.  
  578.         if (ZoneID == 2) // if at the end of the first best zone
  579.         {
  580.             if ((CurrentSpeed == BestSpeeds1End) && (BestSpeeds2Start > NormalSpeedsEnd)) // only if at the end of the group and there aren't any other groups after this
  581.             {
  582.                 ProcessingStage = 3; // done processing
  583.             }
  584.         }
  585.        
  586.         else if (ZoneID == 4) // if at the end of the second best zone
  587.         {
  588.             if ((CurrentSpeed == BestSpeeds2End) && (BestSpeeds3Start > NormalSpeedsEnd)) // only if at the end of the group and there aren't any other groups after this
  589.             {
  590.                 ProcessingStage = 3; // done processing
  591.             }
  592.         }
  593.        
  594.         else if (ZoneID == 6) // if at the end of the third best zone
  595.         {
  596.             if (CurrentSpeed >= BestSpeeds3End) // only if at the end of the group
  597.             {
  598.                 ProcessingStage = 3; // done processing
  599.             }
  600.         }
  601.     }
  602.  
  603.     if (DebugTest[1] == 1)
  604.     {
  605.         DebugTest[6] = CurrentSpeed;
  606.     }
  607. }
  608.  
  609. void CreateOutputFiles()
  610. {
  611.     /*
  612.     This function reads any input files and writes the output based on the speeds used.
  613.  
  614.     There are 4 stages:
  615.     Stage 1:  Obtain the speed to process.  Do the normal speeds first then the "best zone" speeds.
  616.     Use a while loop and the FindNextSampleRate() function for this.
  617.     Stage 2:  Read the source file upon a zone change.
  618.     If the next speed is in the same zone as the current, don't read the source file.
  619.     Stage 3:  Determine the amount of progress made.  The normal, best, and overall progress should be indicated.
  620.     The actual completion is based solely on the speeds rather than the number completed since it's quite erratic.
  621.     The formula is "log10(CurrentSpeed/NormalSpeedsStart)/log10(NormalSpeedsEnd/NormalSpeedsStart)".
  622.     For overall, use a weighted average - 1 part normal, 5 parts best (completing normal means 25% overall completion).
  623.     The DOS filler characters are used for this, 20 (space; 0), B0 (1/2), B1 (1), B2 (1 1/2), and DB (2).
  624.     Each "block" is 2 percentage units so 50 are needed.  For 13.2% completion, 6 fulls (DB) and a half (B1) are used.
  625.     Stage 4:  Write the data to disk as a WAV file.
  626.     The format is in the "[speed] [song name].wav" format where [speed] is a 6-digit number with leading zeros.
  627.    
  628.     Progress bar design:
  629.    
  630.     Completion (approximate):
  631.                --------------------------------------------------
  632.     Normal:   |                                                  | 100.0%
  633.                --------------------------------------------------
  634.     Best:     |                                                  | 040.0%
  635.                --------------------------------------------------
  636.     Overall:  |                                                  | 055.0%
  637.                --------------------------------------------------
  638.     */
  639.    
  640.     unsigned int PreviousZone = 0;
  641.     char CompletionString[51]; // used for the progress indicators
  642.     unsigned int BaseStringPosition;
  643.     double NormalCompletion;
  644.     double BestCompletion;
  645.     double OverallCompletion;
  646.     double FileSizeMiB = 0.0;
  647.     double DataWrittenGiB = 0.0;
  648.     unsigned int Units; // used for progress bars
  649.    
  650.     CurrentSpeed = 0; // set the current speed here before processing anything
  651.     WithinRange = 0; // initiate it and to falsify the loop for stage 1
  652.    
  653.     DebugTest[0] = 0;
  654.    
  655.     // a sanity check, fixing a bug when large-range best zones get segmented
  656.     if (BestSpeeds1End == BestSpeeds2Start)
  657.     {
  658.         BestSpeeds1End--;
  659.     }
  660.    
  661.     if (BestSpeeds2End == BestSpeeds3Start)
  662.     {
  663.         BestSpeeds2End--;
  664.     }
  665.    
  666.     while (ProcessingStage < 3)
  667.     {
  668.         // Stage 1:  Obtain the speed to process.
  669.         PreviousZone = ZoneID; // log the previous zone to prevent excessive rereading
  670.        
  671.         while (WithinRange != 1)
  672.         {
  673.             FindNextSampleRate();
  674.         }
  675.        
  676.         if (WithinRange == 1)
  677.         {
  678.             // Stage 2:  Read the source file upon a zone change.
  679.             if ((ZoneID != PreviousZone) || (CurrentSpeed == NormalSpeedsStart) || (CurrentSpeed == BestSpeeds1Start)) // if just starting, the zone changed, or read the source file
  680.             {
  681.                 // exclusive to samplers with just one zone
  682.                 if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  683.                 {
  684.                     sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\%s base.wav", SongName, ZoneID); // read the contents for the zone's base file
  685.                 }
  686.                
  687.                 else // standard case
  688.                 {
  689.                     sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\%s base%03d.wav", SongName, ZoneLapCount[ZoneID-1]); // read the contents for the zone's base file
  690.                 }
  691.                
  692.                 FileHandle = fopen(FileName, "rb"); // read in binary mode (that's what WAV files are)
  693.                
  694.                 if (FileHandle != 0) // if the file was found and the file contents changed
  695.                 {
  696.                     fread(&FileHeadStart, 1, 24, FileHandle); // read the first 24 bytes of unchanging header data
  697.                     fseek(FileHandle, 33, SEEK_SET); // skip to byte 33 as this part gets set within the file itself
  698.                     fread(&FileHeadEnd, 1, 7, FileHandle); // read the next 7 bytes of more unchanging header data
  699.                     fread(&FileLength, 4, 1, FileHandle); // read the file length data value, to determine how many bytes are to be read and saved
  700.                     fread(&FileContents, 1, FileLength, FileHandle); // read one-byte chunks for the entire file's length, which is the end of the file
  701.                     fclose(FileHandle); // close the file
  702.                     ReadFlag = 1; // set the read flag
  703.                 }
  704.                
  705.                 FileSizeMiB = ((double)FileLength+44.0)/1048576.0; // convert file size of whole file (44 bytes for header) to mebibytes, MiB
  706.             }
  707.            
  708.             // Stage 3:  Determine the amount of progress made.
  709.             // samplers only use one zone
  710.             if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  711.             {
  712.                 printf("Zone:  1; Loops:    1; Size:  %6.2f MiB; Written:  %6.3f GiB\n", FileSizeMiB, DataWrittenGiB);
  713.             }
  714.            
  715.             else
  716.             {
  717.                 printf("Zone:  %d; Loops:  %3d; Size:  %6.2f MiB; Written:  %6.3f GiB\n", ZoneID, ZoneLapCount[ZoneID-1], FileSizeMiB, DataWrittenGiB);
  718.             }
  719.            
  720.             if (CurrentSpeed < FrequencyChangeover16K) // the rare 12K versions
  721.             {
  722.                 sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\to convert\\12K files\\%06d %s.wav", CurrentSpeed, SongName);
  723.                 printf("Writing:  ...\\12K files\\%06d %s.wav", CurrentSpeed, SongName);
  724.             }
  725.            
  726.             else if ((CurrentSpeed >= FrequencyChangeover16K) && (CurrentSpeed < FrequencyChangeover24K)) // the common 16K versions
  727.             {
  728.                 sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\to convert\\16K files\\%06d %s.wav", CurrentSpeed, SongName);
  729.                 printf("Writing:  ...\\16K files\\%06d %s.wav", CurrentSpeed, SongName);
  730.             }
  731.            
  732.             else if ((CurrentSpeed >= FrequencyChangeover24K) && (CurrentSpeed < FrequencyChangeover32K)) // the very common 24K versions
  733.             {
  734.                 sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\to convert\\24K files\\%06d %s.wav", CurrentSpeed, SongName);
  735.                 printf("Writing:  ...\\24K files\\%06d %s.wav", CurrentSpeed, SongName);
  736.             }
  737.            
  738.             else if ((CurrentSpeed >= FrequencyChangeover32K) && (CurrentSpeed < FrequencyChangeover48K)) // the semi-common 32K versions
  739.             {
  740.                 sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\to convert\\32K files\\%06d %s.wav", CurrentSpeed, SongName);
  741.                 printf("Writing:  ...\\32K files\\%06d %s.wav", CurrentSpeed, SongName);
  742.             }
  743.            
  744.             else // the rare 48K versions
  745.             {
  746.                 sprintf(FileName, "C:\\My Documents\\Songs for MP3\\source files\\to convert\\48K files\\%06d %s.wav", CurrentSpeed, SongName);
  747.                 printf("Writing:  ...\\32K files\\%06d %s.wav", CurrentSpeed, SongName);
  748.             }
  749.            
  750.             if (ReadFlag == 1)
  751.             {
  752.                 if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  753.                 {
  754.                     printf("\nReading base file....");
  755.                 }
  756.                
  757.                 else
  758.                 {
  759.                     printf("\nReading zone %d's base file....", ZoneID);
  760.                 }
  761.             }
  762.            
  763.             // printf("\n\nTest 2:  %d; Test 3:  %d; Test 4:  %d;\nTest 5:  %d; Test 6:  %d; Test 7:  %d;\n Test 8:  %d; Test 9:  %d;", DebugTest[2], DebugTest[3], DebugTest[4], DebugTest[5], DebugTest[6], DebugTest[7], DebugTest[8], DebugTest[9]); // debugging stuff
  764.            
  765.             // printf("\n\n\n\n\n\n\n"); // used for debug stuff
  766.            
  767.             printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); // normal usage - used to fill the whole command prompt window, like lame does
  768.            
  769.             if (ReadFlag == 0) // reading was not needed
  770.             {
  771.                 printf("\n"); // add one more line feed
  772.             }
  773.            
  774.             ReadFlag = 0; // reset since it's no longer needed
  775.            
  776.             printf("Completion (approximate):\n           --------------------------------------------------\nNormal:   |");
  777.            
  778.             // samplers don't use anything directly in the normal speeds, always the best speeds
  779.             if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  780.             {
  781.                 NormalCompletion = 100.0;
  782.                 Units = 200;
  783.             }
  784.            
  785.             else
  786.             {
  787.                 if (ProcessingStage == 1) // normal speeds
  788.                 {
  789.                     NormalCompletion = log10((double)CurrentSpeed/(double)NormalSpeedsStart)/log10((double)NormalSpeedsEnd/(double)NormalSpeedsStart)*100.0;
  790.                     Units = (unsigned int)(NormalCompletion*2.0+0.5); // up to 200 units
  791.                 }
  792.                
  793.                 else
  794.                 {
  795.                     NormalCompletion = 100.0;
  796.                     Units = 200;
  797.                 }
  798.             }
  799.            
  800.             BaseStringPosition = 0; // reset for reuse (ain't recycling nice?)
  801.            
  802.             while (BaseStringPosition < 50)
  803.             {
  804.                 if (Units >= 4) // a full block - 2%
  805.                 {
  806.                     CompletionString[BaseStringPosition] = 0xDB; // the full block character
  807.                     Units -= 4; // more is still possible so subtract it off instead
  808.                 }
  809.                
  810.                 else if (Units == 3) // 3/4 block - 1.5%
  811.                 {
  812.                     CompletionString[BaseStringPosition] = 0xB2; // the 3/4 block character
  813.                     Units = 0;
  814.                 }
  815.                
  816.                 else if (Units == 2) // 1/2 block - 1%
  817.                 {
  818.                     CompletionString[BaseStringPosition] = 0xB1; // the 1/2 block character
  819.                     Units = 0;
  820.                 }
  821.                
  822.                 else if (Units == 1) // 1/4 block 0.5%
  823.                 {
  824.                     CompletionString[BaseStringPosition] = 0xB0; // the 1/4 block character
  825.                     Units = 0;
  826.                 }
  827.                
  828.                 else // empty block 0%
  829.                 {
  830.                     CompletionString[BaseStringPosition] = 0x20; // the space character
  831.                 }
  832.                
  833.                 BaseStringPosition++;
  834.             }
  835.            
  836.             if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  837.             {
  838.                 printf("%s| XXX.X%%\n           --------------------------------------------------\nBest:     |", CompletionString, NormalCompletion);
  839.             }
  840.            
  841.             else
  842.             {
  843.                 printf("%s| %05.1f%%\n           --------------------------------------------------\nBest:     |", CompletionString, NormalCompletion);
  844.             }
  845.            
  846.             if (ProcessingStage == 1) // normal speeds
  847.             {
  848.                 BestCompletion = 0.0;
  849.                 Units = 0; // up to 200 units
  850.             }
  851.            
  852.             else
  853.             {
  854.                 if (BestSpeeds3Start < NormalSpeedsEnd) // if a third group of best speeds is involved
  855.                 {
  856.                     BestCompletion = log10((double)CurrentSpeed/(double)BestSpeeds1Start)/log10((double)BestSpeeds3End/(double)BestSpeeds1Start)*100.0;
  857.                     Units = (unsigned int)(BestCompletion*2.0+0.5); // up to 200 units
  858.                 }
  859.                
  860.                 else if (BestSpeeds2Start < NormalSpeedsEnd) // if a second group of best speeds is involved instead
  861.                 {
  862.                     BestCompletion = log10((double)CurrentSpeed/(double)BestSpeeds1Start)/log10((double)BestSpeeds2End/(double)BestSpeeds1Start)*100.0;
  863.                     Units = (unsigned int)(BestCompletion*2.0+0.5); // up to 200 units
  864.                 }
  865.                
  866.                 else // only one best zone is used
  867.                 {
  868.                     BestCompletion = log10((double)CurrentSpeed/(double)BestSpeeds1Start)/log10((double)BestSpeeds1End/(double)BestSpeeds1Start)*100.0;
  869.                     Units = (unsigned int)(BestCompletion*2.0+0.5); // up to 200 units
  870.                 }
  871.             }
  872.            
  873.             BaseStringPosition = 0; // reset for reuse (ain't recycling nice?)
  874.            
  875.             while (BaseStringPosition < 50)
  876.             {
  877.                 if (Units >= 4) // a full block - 2%
  878.                 {
  879.                     CompletionString[BaseStringPosition] = 0xDB; // the full block character
  880.                     Units -= 4; // more is still possible so subtract it off instead
  881.                 }
  882.                
  883.                 else if (Units == 3) // 3/4 block - 1.5%
  884.                 {
  885.                     CompletionString[BaseStringPosition] = 0xB2; // the 3/4 block character
  886.                     Units = 0;
  887.                 }
  888.                
  889.                 else if (Units == 2) // 1/2 block - 1%
  890.                 {
  891.                     CompletionString[BaseStringPosition] = 0xB1; // the 1/2 block character
  892.                     Units = 0;
  893.                 }
  894.                
  895.                 else if (Units == 1) // 1/4 block 0.5%
  896.                 {
  897.                     CompletionString[BaseStringPosition] = 0xB0; // the 1/4 block character
  898.                     Units = 0;
  899.                 }
  900.                
  901.                 else // empty block 0%
  902.                 {
  903.                     CompletionString[BaseStringPosition] = 0x20; // the space character
  904.                 }
  905.                
  906.                 BaseStringPosition++;
  907.             }
  908.            
  909.             printf("%s| %05.1f%%\n           --------------------------------------------------\nOverall:  |", CompletionString, BestCompletion);
  910.            
  911.             if ((NormalSpeedsStart == BestSpeeds1Start) && (NormalSpeedsEnd == BestSpeeds1End))
  912.             {
  913.                 OverallCompletion = BestCompletion; // samplers only use the best zone speeds
  914.             }
  915.            
  916.             else
  917.             {
  918.                 OverallCompletion = (NormalCompletion + BestCompletion*5.0)/6.0; // a weighted average - 3 parts best and one part normal
  919.             }
  920.            
  921.             Units = (unsigned int)(OverallCompletion*2.0+0.5); // up to 400 units
  922.             BaseStringPosition = 0; // reset for reuse (ain't recycling nice?)
  923.            
  924.             while (BaseStringPosition < 50)
  925.             {
  926.                 if (Units >= 4) // a full block - 2%
  927.                 {
  928.                     CompletionString[BaseStringPosition] = 0xDB; // the full block character
  929.                     Units -= 4; // more is still possible so subtract it off instead
  930.                 }
  931.                
  932.                 else if (Units == 3) // 3/4 block - 1.5%
  933.                 {
  934.                     CompletionString[BaseStringPosition] = 0xB2; // the 3/4 block character
  935.                     Units = 0;
  936.                 }
  937.                
  938.                 else if (Units == 2) // 1/2 block - 1%
  939.                 {
  940.                     CompletionString[BaseStringPosition] = 0xB1; // the 1/2 block character
  941.                     Units = 0;
  942.                 }
  943.                
  944.                 else if (Units == 1) // 1/4 block 0.5%
  945.                 {
  946.                     CompletionString[BaseStringPosition] = 0xB0; // the 1/4 block character
  947.                     Units = 0;
  948.                 }
  949.                
  950.                 else // empty block 0%
  951.                 {
  952.                     CompletionString[BaseStringPosition] = 0x20; // the space character
  953.                 }
  954.                
  955.                 BaseStringPosition++;
  956.             }
  957.            
  958.             printf("%s| %05.1f%%\n           --------------------------------------------------\n", CompletionString, OverallCompletion);
  959.            
  960.             // Stage 4:  Write the data to disk as a WAV file.
  961.             FileHandle = fopen(FileName, "wb"); // open the file for writing in binary mode (WAV files are binary)
  962.            
  963.             if (FileHandle != 0) // do only if the pointer is valid
  964.             {
  965.                 // write the details in the same order as it was read in but including the sample rate and bytes per second
  966.                 fwrite(&FileHeadStart, 1, 24, FileHandle);
  967.                 fwrite(&SampleRateInFile, 4, 1, FileHandle);
  968.                 fwrite(&BytesPerSecond, 4, 1, FileHandle);
  969.                 fwrite(&Multiplier, 1, 1, FileHandle);
  970.                 fwrite(&FileHeadEnd, 1, 7, FileHandle);
  971.                 fwrite(&FileLength, 4, 1, FileHandle);
  972.                 fwrite(&FileContents, 1, FileLength, FileHandle); // copies all the rest of the data, the samples themselves
  973.                
  974.                 DataWrittenGiB += (FileSizeMiB/1024.0); // convert to gibibytes, GiB
  975.             }
  976.            
  977.             // check if at the end - go to mode 2 if done
  978.             if ((ProcessingStage == 1) && (CurrentSpeed >= NormalSpeedsEnd))
  979.             {
  980.                 ProcessingStage = 2; // change to mode 2 for doing the best speeds
  981.                 CurrentSpeed = NormalSpeedsStart; // return to the start for one more cycle
  982.             }
  983.            
  984.             WithinRange = 0; // reset to update the speed
  985.         }
  986.        
  987.         DebugTest[0]++;
  988.     }
  989. }
  990.  
  991. void Settings()
  992. {
  993.     /*
  994.     This function is used to set the song's title, the true speed sample rate, and speed ranges.
  995.    
  996.     To do (in order of importance):
  997.     1.  Obtain the highest quality versions for as many songs as possible:  Felix, FF9, Sno, Sonic 3D Blast, and a few others;
  998.     */
  999.    
  1000.     // change the name of the song in the quotations here
  1001.     strcpy(SongName, "Final Fantasy 6 World");
  1002.    
  1003.     // if true speed in the original base file is 50,000 Hz, use 1 here.  If it is 100,000 Hz instead, use 2.
  1004.     Modifier = 1;
  1005.    
  1006.     // set the range for where the song sounds reasonably well
  1007.     NormalSpeedsStart = 50000; // The starting, slowest speed - below here is where the song is boring
  1008.     NormalSpeedsEnd = 150000; // The ending, fastest speed - above here is where the song is irritating
  1009.    
  1010.     // set the ranges of the best-sounding speeds for up to 3 "zones" - have something out of range if a zone is not used.
  1011.     BestSpeeds1Start = 70000; // The start, slowest, of first best zone
  1012.     BestSpeeds1End = 130000; // The end, fastest, of first best zone
  1013.     BestSpeeds2Start = 600000; // The start, slowest, of second best zone
  1014.     BestSpeeds2End = 700000; // The end, fastest, of second best zone
  1015.     BestSpeeds3Start = 800000; // The start, slowest, of third best zone
  1016.     BestSpeeds3End = 900000; // The end, fastest, of third best zone
  1017.    
  1018.     // set the number of loops used within each zone - use anything if the zone is not used; the array index number is one below the zone
  1019.     ZoneLapCount[0] = 2;
  1020.     ZoneLapCount[1] = 3;
  1021.     ZoneLapCount[2] = 3;
  1022.     ZoneLapCount[3] = 0;
  1023.     ZoneLapCount[4] = 0;
  1024.     ZoneLapCount[5] = 0;
  1025.     ZoneLapCount[6] = 0;
  1026.    
  1027.     // set the speeds at which the sample rate in the MP3's changes to the given new rate (12,000 Hz uses 19 Kbps and 6000 Hz max) - have something out of range if not used
  1028.     FrequencyChangeover16K = 46000; // The 16,000 Hz speeds start here (23 Kbps and 6000-8000 Hz range)
  1029.     FrequencyChangeover24K = 62000; // The 24,000 Hz speeds start here (31 Kbps and 8000-12,000 Hz range)
  1030.     FrequencyChangeover32K = 93000; // The 32,000 Hz speeds start here (40 Kbps and 12,000-16,000 Hz range)
  1031.     FrequencyChangeover48K = 124000; // The 48,000 Hz speeds start here (58 Kbps and 12,000-16,000 Hz range)
  1032.    
  1033.     /*
  1034.     The frequencies, speed ranges, sample rate changeovers, and loop counts are listed below for reference:
  1035.    
  1036.     What the columns mean:
  1037.     Notes - quick side notes related to the song, or things common with other songs.
  1038.     Song - the name of the song (obvious?) - the song's actual name is used, but the speed indication is left out (50 characters max)
  1039.     16K - the speed (as a percentage) at which the sample rate changes from 12,000 Hz to 16,000 Hz // Used for 6000 to 8000 Hz range (used as the basis for the other frequencies)
  1040.     24K - the speed (as a percentage) at which the sample rate changes from 16,000 Hz to 24,000 Hz // used for 8000 to 12,000 Hz range (multiply 16K's by 4/3 to find)
  1041.     32K - the speed (as a percentage) at which the sample rate changes from 24,000 Hz to 32,000 Hz // used for 12,000 to 16,000 Hz range (multiply 24K's by 3/2 to find)
  1042.     48K - the speed (as a percentage) at which the sample rate changes from 32,000 Hz to 48,000 Hz // used for 16,000+ Hz range (multiply 32K's by 4/3 to find)
  1043.     Best zones - the speed "zones" at which the song sounds the best (these use more speeds and more loops) - samplers use the normal range, but all best zone speeds
  1044.     Normal - the overall speed range that song uses - the point at which the song doesn't sound any more decent - samplers use the normal range, but all best zone speeds
  1045.     Loop order - the number of loops in each zone that is involved - samplers, special versions (actually 20), and non-looping versions use 1.
  1046.    
  1047.     +-----------+--------------------------------------------------+---+---+---+---+-------------------------+-------+--------------------------+
  1048.     |Notes      |Song                                              |16K|24K|32K|48K|Best zones               |Normal |loop order                |
  1049.     +-----------+--------------------------------------------------+---+---+---+---+-------------------------+-------+--------------------------+
  1050.     |01         |Aero the Acrobat Track 13                         |   |   |   |   |                         |       |
  1051.     |01         |Aero the Acrobat Track 14                         |   |   |   |   |                         |       |
  1052.     |01         |Aero the Acrobat Track 20                         |   |   |   |   |                         |       |
  1053.     |01         |Aero the Acrobat Track 20 20-lap                  |   |   |   |   |                         |       |immune:  special version
  1054.     |19         |Angelisland                                       |37 |50 |75 |100|55-85, 85-130            |40-150 |2, 4, X, 6, 5             |
  1055.     |01         |Arctic Zone                                       |   |   |   |   |                         |       |
  1056.     |01         |Bahamas Zone                                      |   |   |   |   |                         |       |immune:  non-looping
  1057.     |01         |Battle Zone                                       |90 |X  |X  |X  |55-115                   |40-140 |2, 6, 4                   |
  1058.     |01         |Battle Zone sampler                               |70 |90 |140|X  |immune:  sampler         |25-230 |immune:  sampler          |
  1059.     |           |Between Planets                                   |43 |58 |87 |116|80-130                   |70-140 |immune:  non-looping      |
  1060.     |01         |Blaster Master Area 2                             |   |   |   |   |                         |       |
  1061.     |01         |Blaster Master Area 4                             |   |   |   |   |                         |       |
  1062.     |01?        |Cactus Point                                      |   |   |   |   |                         |       |immune:  non-looping
  1063.     |           |Carnival Night                                    |43 |58 |87 |X  |65-95                    |40-125 |immune:  non-looping      |
  1064.     |01         |Delfino Plaza                                     |   |   |   |   |                         |       |
  1065.     |           |Desert Zone                                       |46 |62 |93 |X  |70-110                   |40-140 |3, 10, 7                  |
  1066.     |           |Desert Zone 20-lap                                |46 |62 |93 |X  |70-110                   |70-110 |immune:  special version  |
  1067.     |           |Du-di-da                                          |43 |58 |87 |116|70-130                   |50-160 |4, 10, 10                 |
  1068.     |02         |Felix World 1                                     |   |   |   |   |                         |       |
  1069.     |           |Final Fantasy 1 Battle                            |39 |52 |78 |104|75-110                   |60-140 |4, 7, 7                   |
  1070.     |1A         |Final Fantasy 1 Cave                              |39 |52 |78 |104|70-105, 105-160          |60-200 |2, 5, X, 7, 6             |
  1071.     |12         |Final Fantasy 1 World                             |39 |52 |78 |104|60-90, 90-135            |40-180 |2, 4, X, 6, 5             |
  1072.     |           |Final Fantasy 1 World sampler                     |39 |52 |78 |104|immune:  sampler         |30-270 |immune:  sampler          |
  1073.     |01         |Final Fantasy 5 Castle                            |   |   |   |   |                         |       |
  1074.     |01         |Final Fantasy 6 Battle                            |   |   |   |   |                         |       |
  1075.     |           |Final Fantasy 6 World                             |46 |62 |93 |124|70-130                   |50-150 |2, 3, 3                   |
  1076.     |           |Final Fantasy 6 World sampler                     |46 |62 |93 |124|immune:  sampler         |35-260 |immune:  sampler          |
  1077.     |06         |Final Fantasy 7 Chocobo Farm                      |   |   |   |   |                         |       |
  1078.     |        03 |Final Fantasy 7 Chocobo Racing                    |43 |58 |87 |116|65-125                   |50-150 |2, 4, 4                   |
  1079.     |           |Final Fantasy Tactics Shops                       |49 |66 |99 |132|60-130                   |40-160 |4, 11, 11                 |
  1080.     |01         |Gnasty's Loot                                     |   |   |   |   |                         |       |immune:  non-looping
  1081.     |02         |Haunted Castle                                    |   |   |   |   |                         |       |
  1082.     |01         |Jaws (game) Ending Theme                          |   |   |   |   |                         |       |immune:  non-looping
  1083.     |01         |Looney Tunes Back In Action Map                   |   |   |   |   |                         |       |immune:  non-looping
  1084.     |01         |Marble Madness Practice Race                      |   |   |   |   |                         |       |
  1085.     |06         |Marble Madness Ultimate Race                      |   |   |   |   |                         |       |
  1086.     |02         |Marvin's House                                    |   |   |   |   |                         |       |
  1087.     |           |Metropolis                                        |37 |50 |75 |100|55-115                   |40-135 |3, 7, 7                   |
  1088.     |01         |Misty Bog                                         |   |   |   |   |                         |       |immune:  non-looping
  1089.     |02         |Mountains So Beautiful                            |   |   |   |   |                         |       |
  1090.     |02         |Mosphoran Highwaste                               |   |   |   |   |                         |       |
  1091.     |           |Mountains So Far Away                             |37 |50 |75 |100|50-75, 75-110            |35-150 |2, 4, X, 6, 6             |
  1092.     |01         |Nature in the Rough                               |   |   |   |   |                         |       |immune:  non-looping
  1093.     |01         |Noki Bay                                          |   |   |   |   |                         |       |
  1094.     |01         |Oh What a World                                   |   |   |   |   |                         |       |
  1095.     |01  11     |Oh What a World 2                                 |110|150|X  |X  |65-100, 100-160, 160-250 |35-300 |2, 4, X, 6, X, 8, 7       |
  1096.     |07         |Oh What a World X                                 |   |   |   |   |                         |       |
  1097.     |           |On Parade                                         |43 |58 |87 |116|65-125                   |50-140 |3, 7, 6                   |
  1098.     |           |Out Where the Lake Is                             |46 |62 |93 |X  |60-100                   |30-125 |2, 5, 5                   |
  1099.     |02         |Ozmone Plain                                      |   |   |   |   |                         |       |
  1100.     |01         |Playland                                          |   |   |   |   |                         |       |immune:  non-looping
  1101.     |02         |Retro Zone                                        |   |   |   |   |                         |       |immune:  non-looping
  1102.     |16         |Sky Chase                                         |37 |50 |75 |100|60-90, 90-140            |50-150 |4, 7, X, 11, 10           |
  1103.     |05         |Sluminda                                          |   |   |   |   |                         |       |
  1104.     |01         |Sno                                               |   |   |   |   |                         |       |immune:  non-looping
  1105.     |17         |Sonic 3 Extra Life                                |37 |50 |75 |100|30-55, 55-95             |20-125 |immune:  non-looping      |
  1106.     |           |Sonic 3 Invincibility                             |37 |50 |75 |100|40-85                    |30-125 |8, 21, 24                 |
  1107.     |13  14     |Sonic 3 and Knuckles Extra Life                   |37 |50 |75 |100|30-50, 50-85, 85-150     |20-225 |immune:  non-looping      |
  1108.     |15         |Sonic 3 and Knuckles Invincibility                |37 |50 |75 |100|45-90, 90-180            |30-250 |8, 20, X, 40, 44          |
  1109.     |           |Super Monkey Ball 2 Boat                          |41 |55 |82 |X  |70-90                    |50-125 |2, 3, 2                   |
  1110.     |           |Super Monkey Ball 2 Title                         |41 |55 |82 |X  |60-80                    |50-125 |10, 24, 18                |
  1111.     |           |Super Monkey Ball 2 World 5                       |41 |55 |82 |X  |70-95                    |50-125 |2, 5, 4                   |
  1112.     |           |Super Monkey Ball 2 World 6                       |41 |55 |82 |110|65-120                   |50-140 |2, 4, 4                   |
  1113.     |           |Super Monkey Ball 2 World 7                       |41 |55 |82 |X  |70-115                   |50-140 |2, 7, 5                   |
  1114.     |09         |Super Monkey Ball 2 World 7 sampler               |41 |55 |82 |110|immune:  sampler         |35-230 |immune:  sampler          |
  1115.     |           |Super Monkey Ball 2 World 7 20-lap                |41 |55 |82 |X  |70-115                   |70-115 |immune:  special version  |
  1116.     |10  08     |Target Zone                                       |41 |55 |82 |110|110-180, 180-290, 290-480|60-500 |3, 7, X, 13, X, 23, 18    |
  1117.     |01         |Tiny Toon theme                                   |   |   |   |   |                         |       |
  1118.     |           |Tree Climb                                        |43 |58 |87 |116|60-120                   |40-140 |2, 3, 3                   |
  1119.     |           |Ultima Exodus Towns                               |43 |58 |87 |116|75-115                   |60-170 |3, 7, 7                   |
  1120.     |01         |Vegas Zone                                        |   |   |   |   |                         |       |
  1121.     |           |Village Zone                                      |43 |58 |87 |X  |70-100                   |50-125 |2, 4, 3                   |
  1122.     |           |Winter Land                                       |37 |50 |75 |100|80-125                   |50-180 |2, 5, 5                   |
  1123.     |01         |Winter Zone Version 1 Remix                       |   |   |   |   |                         |       |
  1124.     |18         |Winter Zone Version 1                             |37 |50 |75 |100|55-85, 85-130            |30-180 |2, 3, X, 4, 4             |
  1125.     |01         |Winter Zone Version 2 Remix                       |   |   |   |   |                         |       |
  1126.     |18         |Winter Zone Version 2                             |37 |50 |75 |100|55-85, 85-130            |30-180 |2, 3, X, 4, 4             |
  1127.     |05         |Zeliard Title                                     |   |   |   |   |                         |       |immune:  non-looping
  1128.     |03? 2B? 56?|Test case:  this is a song's longest allowed title|120|160|240|   |100-120, 180-250, 300-400|100-300|10, 25, 15, 30, 20, 40, 30|
  1129.     +-----------+--------------------------------------------------+---+---+---+---+-------------------------+-------+--------------------------+
  1130.    
  1131.     Notes:
  1132.     01  This song uses a very old version and really needs to be updated
  1133.     02  This song has a quality upgrade compared to 01, but used the old method for obtaining - a new one is in order
  1134.     03  This song needs to be reprocessed due to the frequency change-over points changing.
  1135.     04  This song needs to be reprocessed to extend the range of the best zone.  Double the 16K's changeover is the basis to use for readjusting.
  1136.     05  This song was recorded from a tape recorder and is of terrible quality, worse than 01.
  1137.     06  This song has yet to be obtained.
  1138.     07  This song has other variants that need to be obtained, but I'm unsure of just how many there are.
  1139.     08  This song may need a 48 KHz version as there are still audible distortions even at 32 KHz.
  1140.     09  This song's base file is incorrect and it needs to be redone.
  1141.     0A  This song's speed ranges have changed and it needs to be reprocessed, including any base files.
  1142.     0B-0F - reserved for common things.
  1143.    
  1144.     10  Target Zone has potential for the normal being beyond even 800% true speed (!!!).  It's huge 110-480 best zone speed range means that it
  1145.         must be segmented.  This is for best optimization of the MP3 player's capacity and loops.  Segmenting is done when the speed range for
  1146.         the best zone is at least 2.2 and involves a square root or cubic root to keep within this 2.2 max span.  For this song, it's based on
  1147.         the cubic root of "fast/slow", "480/110", or a bit over 1.6 (mental estimate).  This gives 110-180, 180-290, 290-480 as the segments.
  1148.     11  Because the best zone is so vast (65-250), it needs to be segmented into different subzones for best optimization.
  1149.         The segmenting involves the speeds 65-100, 100-160, and 160-250.
  1150.     12  This song's best zone, 60-135, is rather wide and has thus been segmented into 60-90 and 90-135.
  1151.     13  This song's normal zone can drop as low as 15% true speed, highly unusual.
  1152.     14  This song's best zone, 30-150, is truly gigantic and is segmented into 30-50, 50-85, and 85-150 segments because of it.
  1153.     15  This song's best zone, 45-180, is vast and has been segmented into 45-90 and 90-180.
  1154.     16  This song's best zone is also large, 60-140 and is split into 60-90 and 90-140.
  1155.     17  Yet another song with its best zone being large - 30-95 is segmented into 30-55 and 55-95.
  1156.     18  These two songs are nearly identical to each other in many ways.  The length (56 measures vs 48), affecting loop count, and intrument
  1157.         timing are a bit different.  The wide best zone span, 55-130, is segmented into 55-85 and 85-130 for both as this aspect is the same.
  1158.     19  Like many songs with Sonic, for some reason, this song, too, has a large 55-130 best range with 55-85 and 85-130 as it's two "zones".
  1159.     1A  This song's best zone, 70-160, is a bit too large and is thus segmented into 70-105 and 105-160.
  1160.     1B  
  1161.    
  1162.     When processing a song, do the following 11 stages:
  1163.     1.  Determine what the normal speed range is.
  1164.     2.  Determine where the best-sounding speeds lie.
  1165.     3.  Determine what lowpass frequency has the intensity less than 0.05 max.
  1166.     4.  Use this frequency to determine the frequency changeover points.
  1167.     5.  With the best and normal speeds obtained, determine how many loops are needed:
  1168.     5a.  If the song is non-looping, a sampler, or is a special version (like a 20-lap) it's immune to this and must be counted as 1.
  1169.     5b.  For the speeds in any range, the base speed for determining the loop count is the exponential mid-point (40 for a 20-80 range).
  1170.     5c.  The basis for the normal speeds is 4 minutes.
  1171.     5d.  If the song has no intro or the intro is well-liked, the basis for 6 minutes.
  1172.     5e.  If the intro is not liked, the basis is 8 minutes.
  1173.     6.  Save each unique version as a WAV file and have the number after "base" be that of the number of loops used, with 3 digits for leading zeros.
  1174.     7.  Adjust the settings above based on the information from stages 1 through 5.
  1175.     8.  Delete any leftover files from the previous run, if any, then run this program.
  1176.     9.  Use the BAT files to convert to MP3.
  1177.     10.  Copy the output files into a folder dedicated to the game then the song itself.
  1178.     11.  Copy this folder to the MP3 player to finish.
  1179.    
  1180.     */
  1181. }
  1182.  
  1183. int main()
  1184. {
  1185.     // main function, required with C, but used to call the related functions
  1186.     Settings(); // gets some settings set
  1187.     CreateOutputFiles(); // initiate the loop for creating the output files copying the data above changing the 8 bytes as needed
  1188.    
  1189.     return 0; // function must return something, usually 0
  1190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement