Ulillillia's WAV file sample rate generator program

download Ulillillia's WAV file sample rate generator program

of 19

  • date post

    10-Feb-2018
  • Category

    Documents

  • view

    216
  • download

    0

Embed Size (px)

Transcript of Ulillillia's WAV file sample rate generator program

  • 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) { Curren