| 1467 | |
| 1468 | |
| 1469 | static void write_subframes(FlacEncodeContext *s) |
| 1470 | { |
| 1471 | int ch; |
| 1472 | |
| 1473 | for (ch = 0; ch < s->channels; ch++) { |
| 1474 | FlacSubframe *sub = &s->frame.subframes[ch]; |
| 1475 | int p, porder, psize; |
| 1476 | int32_t *part_end; |
| 1477 | int32_t *res = sub->residual; |
| 1478 | int32_t *frame_end = &sub->residual[s->frame.blocksize]; |
| 1479 | |
| 1480 | /* subframe header */ |
| 1481 | put_bits(&s->pb, 1, 0); |
| 1482 | put_bits(&s->pb, 6, sub->type_code); |
| 1483 | put_bits(&s->pb, 1, !!sub->wasted); |
| 1484 | if (sub->wasted) |
| 1485 | put_bits(&s->pb, sub->wasted, 1); |
| 1486 | |
| 1487 | /* subframe */ |
| 1488 | if (sub->type == FLAC_SUBFRAME_CONSTANT) { |
| 1489 | if(sub->obits == 33) |
| 1490 | put_sbits63(&s->pb, 33, s->frame.samples_33bps[0]); |
| 1491 | else if(sub->obits == 32) |
| 1492 | put_bits32(&s->pb, res[0]); |
| 1493 | else |
| 1494 | put_sbits(&s->pb, sub->obits, res[0]); |
| 1495 | } else if (sub->type == FLAC_SUBFRAME_VERBATIM) { |
| 1496 | if (sub->obits == 33) { |
| 1497 | int64_t *res64 = s->frame.samples_33bps; |
| 1498 | int64_t *frame_end64 = &s->frame.samples_33bps[s->frame.blocksize]; |
| 1499 | while (res64 < frame_end64) |
| 1500 | put_sbits63(&s->pb, 33, (*res64++)); |
| 1501 | } else if (sub->obits == 32) { |
| 1502 | while (res < frame_end) |
| 1503 | put_bits32(&s->pb, *res++); |
| 1504 | } else { |
| 1505 | while (res < frame_end) |
| 1506 | put_sbits(&s->pb, sub->obits, *res++); |
| 1507 | } |
| 1508 | } else { |
| 1509 | /* warm-up samples */ |
| 1510 | if (sub->obits == 33) { |
| 1511 | for (int i = 0; i < sub->order; i++) |
| 1512 | put_sbits63(&s->pb, 33, s->frame.samples_33bps[i]); |
| 1513 | res += sub->order; |
| 1514 | } else if (sub->obits == 32) { |
| 1515 | for (int i = 0; i < sub->order; i++) |
| 1516 | put_bits32(&s->pb, *res++); |
| 1517 | } else { |
| 1518 | for (int i = 0; i < sub->order; i++) |
| 1519 | put_sbits(&s->pb, sub->obits, *res++); |
| 1520 | } |
| 1521 | |
| 1522 | /* LPC coefficients */ |
| 1523 | if (sub->type == FLAC_SUBFRAME_LPC) { |
| 1524 | int cbits = s->options.lpc_coeff_precision; |
| 1525 | put_bits( &s->pb, 4, cbits-1); |
| 1526 | put_sbits(&s->pb, 5, sub->shift); |
no test coverage detected