Kyocera KWS File Format
Written by Justin Heiner
jheiner@yahoo.com
http://merwin.bespin.org/r2m (Main Website - Contains RTTTL -> MIDI/KWS Converter)
http://ringtone.bespin.org (RTTTL Ringtone Website)

PHONES AFFECTED: Qualcomm/Kyocera 2235, 2255, 3035, and maybe more

HEADER: (Totals 6 Bytes)
1st - 4th bytes: Bit flipped length of file (32 bit)
                 Basically, you come up with the length of the file as a 32 bit number, convert
                   it into binary, and flip each bit (If it is a 1, make it a 0. If it is a 0
                   make it a 1). I have no clue why they did it this way. Or, if you want to get
                   the real length from the KWS file, read the 32 bit number, convert it into
                   binary, and flip each bit. It's that easy! :-)
5th and 6th bytes: Number of notes in the song (16 bit)
                 Count the number of notes in the song and put it here as a 16 bit number. DO NOT
                 flip the bits. The only place you need to do that is in the 1st - 4th bytes for
                 the file length.

NOTE: (Totals 4 Bytes)
1st byte: Note (1 is middle c)
2nd byte: 00 = pause, 04 = note
3rd byte: Duration (if equal to 0xFF or less, then the 4th byte is always 0x00.  If over 0xFF then 
          see below). You can pretty much skip down to the example in the next step if it is under 
          0xFF. The only difference is that you won't do the BitShifting. IE: If the duration in this 
          byte says 0xFA (The next byte will be 0x00), then your duration IS 0xFA, or 250 milliseconds.
4th byte: 2nd byte of duration. The duration is calculated using the follwing method:
             Take the 4th byte and BitShift it Left 1. I believe it is done with: myByte << 1
             This will take a number like 00000011 and make it 00000110.
             Then take this new number and XOR it with the 3rd byte.
             Then tack on the old 4th byte before new number that we just made.
             Example:
                Let's say that the 3rd and 4th bytes = 0xDE 0x07
                Take 0x07 (Binary 00000111) and BitShift it left.
                It now equals Binary 00001110. This is now our bitmask.
                The Binary of 0xDE is 11011110. We now do Bitmask XOR 0xDE.
                The equation of this looks like:
                   11011110 (0xDE)
                   00001110 (Bitmask)
                   --------
                   11010000 (New Partial Duration. Equivalent to 0xD0) 
                We then take our original 4th byte and append it to the beginning of our new 
                  partial duration.
                This comes out to equal 0x07D0, which in Decimal equals 20000.
                If the song is 120BPM (Beats Per Minute), each QuarterNote = 500 Milliseconds.
                That would mean that 2000 Milliseconds would equal a whole note.
                Basically, the RTTTL text for the note is:
                   (Let's just say that the note is 1 (Middle C, or c4)
                   MyNote:d=4,o=5,b=120:1c4
             The only hard part that I could see would be finding out the original BPM, 
               if it isn't 120BPM.d

FOOTER: (Totals 4 Bytes)
Same as 1st - 4th bytes of the Header
