RKPI2: an audio format that is easy to encode/decode
which is focused towards minimalism and simplicity.

0. Why was it created?
    It has no actual reason of why it was created. I just like
    making different formats. This is to store raw PCM data, just
    like WAVE format.

    WAVE is a format that is very complex by design and non-standard
    too, which makes it diffcult to create decoders for it.

Overview:
    +------------------+-------------+
    | Header Structure | PCM payload |  
    +------------------+-------------+
    Figure 1: structure of a RRPI2 file.

    "PCM payload" is just plain PCM data stored as the form
    of bytes, to parse it correctly "Header" is used to do that. 

1. Header Structure:
    +-------+------+-------------------------------+
    | Index | Size |             Remarks           |
    +-------+------+-------------------------------+
    |  0    |  6   | alawys number: 0x3d           |
    |  6    |  1   | is compressed with ZSTD [R0]? |
    |  7    |  3   | sampleformat index of PCM     | 
    |  10   |  3   | samplerate index of PCM       |
    |  13   |  3   | number of audio channels      | [N0]
    +-------+------+-------------------------------+

    [N0]: while packing into bitfield subtract by 1,
         while unpacking from bitfield add by 1.

    1.0 Sampleformat Index:
        +-------+---------------+
        | Index | Sampleformat  |
        +-------+---------------+
        | 0     | Signed 8-bit  |
        | 1     | Signed 16-bit |
        | 2     | Signed 32-bit |
        | 3     | Signed 64-bit |
        | 4     | Float  32-bit |
        | 5     | Float  64-bit |
        +-------+---------------+
    
    1.1 Samplerate Index:
        +-------+------------+
        | Index | Samplerate |
        +-------+------------+
        |  0    |   8000     |
        |  1    |   12000    |
        |  2    |   22050    |
        |  3    |   32000    |
        |  4    |   44100    |
        |  5    |   64000    |
        |  6    |   96000    |
        |  7    |   192000   |
        +-------+------------+

2. PCM Data:
    This portion of the file is the actual data, which will be used to reconstruct
    the sound. This has some static properties of this data:

    * Byteorder [R1] of multibyte samples is always big-endian [R2].
    * Audio channel layout is always interleaved [R3].

3. Notes:
    A RKPI2 file's first-byte must be one of: '0xf4', '0xf5', '0xf6', '0xf7'.
    Or, first byte right shifted by 2 must equal to: '0x3d'.

References:
    [R0] https://facebook.github.io/zstd/
    [R1] https://en.wikipedia.org/wiki/Endianness
    [R2] https://en.wikipedia.org/wiki/Endianness#Big-endian
    [R3] https://en.wikipedia.org/wiki/Interleaving_(data)