| 545 | } |
| 546 | |
| 547 | int encodepitch(float p) // pitch value quantisation: use double resolution for -30°..30° and half resolution for -90°..-30° and 30°..90° |
| 548 | { |
| 549 | const int thres = (1 << 24) / 3; |
| 550 | int r = (int)(p * (1 << 24)) / MAXPITCH; |
| 551 | if(r > thres) r = r / 4 + (1 << 22); |
| 552 | else if(r < -thres) r = r / 4 - (1 << 22); |
| 553 | r += (1 << 23) + (1 << (23 - PITCHBITS)); |
| 554 | if(r < 0) r = 0; |
| 555 | else if(r >= (1 << 24)) r = (1 << 24) - 1; |
| 556 | return r >> (24 - PITCHBITS); |
| 557 | } |
| 558 | |
| 559 | float decodepitch(int r) |
| 560 | { |