static unsigned int pack_pcm(unsigned char *data, unsigned int nsamples, mad_fixed_t const *left, mad_fixed_t const *right, int resolution, struct audio_stats *stats) { static struct audio_dither left_dither, right_dither; unsigned char const *start; register signed long sample0, sample1; int effective, bytes; start = data; effective = (resolution > 24) ? 24 : resolution; bytes = resolution / 8; if (right) { /* stereo */ while (nsamples--) { #ifdef LINEAR_DITHER sample0 = audio_linear_dither(effective, *left++, &left_dither, stats); sample1 = audio_linear_dither(effective, *right++, &right_dither, stats); #else sample0 = audio_linear_round(effective, *left++, stats); sample1 = audio_linear_round(effective, *right++, stats); #endif switch (resolution) { case 8: data[0] = sample0 + 0x80; data[1] = sample1 + 0x80; break; case 32: sample0 <<= 8; sample1 <<= 8; data[ 3] = sample0 >> 24; data[bytes + 3] = sample1 >> 24; case 24: data[ 2] = sample0 >> 16; data[bytes + 2] = sample1 >> 16; case 16: data[ 1] = sample0 >> 8; data[bytes + 1] = sample1 >> 8; data[ 0] = sample0 >> 0; data[bytes + 0] = sample1 >> 0; } data += bytes * 2; } } else { /* mono */ while (nsamples--) {
static int play(struct audio_play *play) { unsigned int len; mad_fixed_t const *left, *right; unsigned long mask; len = play->nsamples; left = play->samples[0]; right = play->samples[1]; mask = (1L << bitdepth) - 1; switch (play->mode) { case AUDIO_MODE_ROUND: while (len--) { fprintf(outfile, format_str, audio_linear_round(bitdepth, *left++, play->stats) & mask); if (right) { fprintf(outfile, format_str, audio_linear_round(bitdepth, *right++, play->stats) & mask); } } break; case AUDIO_MODE_DITHER: { static struct audio_dither left_dither, right_dither; while (len--) { fprintf(outfile, format_str, audio_linear_dither(bitdepth, *left++, &left_dither, play->stats) & mask); if (right) { fprintf(outfile, format_str, audio_linear_dither(bitdepth, *right++, &right_dither, play->stats) & mask); } } } break; } return 0; }
data[bytes + 2] = sample1 >> 16; case 16: data[ 1] = sample0 >> 8; data[bytes + 1] = sample1 >> 8; data[ 0] = sample0 >> 0; data[bytes + 0] = sample1 >> 0; } data += bytes * 2; } } else { /* mono */ while (nsamples--) { #ifdef LINEAR_DITHER sample0 = audio_linear_dither(effective, *left++, &left_dither, stats); #else sample0 = audio_linear_round(effective, *left++, stats); #endif switch (resolution) { case 8: data[0] = sample0 + 0x80; break; case 32: sample0 <<= 8; data[3] = sample0 >> 24; case 24: data[2] = sample0 >> 16; case 16: data[1] = sample0 >> 8; data[0] = sample0 >> 0; } data += bytes;