Chatter filtering function
The game uses a filtering function to compress the microphone input (8 bits per sample) it receives into a smaller format (4 bits per sample). Each compressed sample is stored in bytes with each byte containing two samples, least significant nibble first.
Specifically, the game receives 1000 bytes of microphone input and stores it in memory address 0x21C3DE0. It then filters it into 500 bytes which it places in address 0x22736F0 (placing a flag in 0x22736EC).
Here are the results of the filtering for each byte (the game doesn't actually use this table but calculates the results for each byte as it receives it).
| Input | Output |
|---|---|
| -128 | 0 |
| -127 to -112 | 1 |
| -111 to -96 | 2 |
| -95 to -80 | 3 |
| -79 to -64 | 4 |
| -63 to -48 | 5 |
| -47 to -32 | 6 |
| -31 to -16 | 7 |
| -15 to 15 | 8 |
| 16 to 31 | 9 |
| 32 to 47 | 10 |
| 48 to 63 | 11 |
| 64 to 79 | 12 |
| 80 to 95 | 13 |
| 96 to 111 | 14 |
| 112 to 127 | 15 |
The function used to generate the table above is as follows:
unsigned long FilterCode(signed char x){
unsigned long r4,r5;
r4=(signed char)x;
r5=r4>>3;
r5=((unsigned long)r5)>>0x1C; //15 if negative, 0 if positive
r5+=r4;
r4=r5<<0x14;
r4=r4>>0x18; // using signed 00000XX0
r4+=8;
return r4;
}
It is important to note that the game also interprets the filtered input as a series of signed bytes. Example:
- The microphone input byte 0xA0 (-96) is received.
- The byte is reinterpreted as 2 (0x02).
- The microphone input byte 0x40 (64) is received.
- The byte is reinterpreted as 12 (0x0C).
- The reinterpreted bytes are packed into a single byte, in this case 0xC2, or the signed integer -62.
Relationship to Chatter's Effect
The game compares the 15th byte (counting from 0) of this filtered input (which I will call X), and thus, very near the beginning of the sound. This is the result of filtering bytes 30 and 31 (also counting from 0) of the original input.
If the user is a Chatot, Chatter may confuse the opponent depending on the value of X, which is based on the filtered output:
- If X is greater than or equal to -30 and is less than 30, or if Chatot's cry is the default one, the confusion chance is (0+1)%.
- If X is less than -30, the confusion chance is (10+1)%.
- If X is greater than or equal to 30, the confusion chance is (30+1)%.
Memory locations of Chatot's cry during battle:
- 0x2298180 (Player's Pokemon)
- 0x229858C (Enemy Pokemon)
The confusion effect is considered an additional effect for the purposes of Shield Dust, but not for Serene Grace. In addition, Chatter can't cause confusion if Transform is in effect for the user.
