Added big-endian checking.

Added --zero option.
Added leadin for AC3 SPDIF.
This commit is contained in:
Jaroslav Kysela 2001-08-05 11:50:02 +00:00
parent 04255b61c5
commit c2aa076fb2
6 changed files with 70 additions and 15 deletions

View file

@ -105,21 +105,48 @@ init_spdif(void)
done_banner = 0;
}
int
output_spdif_zero(int frames)
{
int res;
buf[0] = 0x72; buf[1] = 0xf8; // spdif syncword
buf[2] = 0x1f; buf[3] = 0x4e; // ..............
buf[4] = 0x00; // null frame (no data)
buf[5] = 7 << 5; // stream = 7
buf[6] = 0x00; buf[7] = 0x00; // frame size
memset(&buf[8], 0, BLOCK_SIZE - 8);
while (frames-- > 0) {
res = output_play((short *)buf, BLOCK_SIZE / 2 / 2); /* 2 channels, 16-bit samples */
if (res < 0)
return res;
}
return 0;
}
int
output_spdif_leadin(void)
{
memset(buf, 0, 8);
return output_play((short *)buf, 8);
}
int
output_spdif(uint8_t *data_start, uint8_t *data_end, int quiet)
{
unsigned short *sbuf = (unsigned short *)buf;
int ret = 0, res;
while(buffer_syncframe(&syncinfo, &data_start, data_end))
{
sbuf[0] = 0xf872; //spdif syncword
sbuf[1] = 0x4e1f; // .............
sbuf[2] = 0x0001; // AC3 data
sbuf[3] = syncinfo.frame_size * 16;
sbuf[4] = 0x0b77; // AC3 syncwork
if (!done_banner) {
buf[0] = 0x72; buf[1] = 0xf8; // spdif syncword
buf[2] = 0x1f; buf[3] = 0x4e; // ..............
buf[4] = 0x01; // AC3 data
buf[5] = buf[10] >> 5; // bsmod, stream = 0
buf[6] = (syncinfo.frame_size * 16) & 0xff;
buf[7] = ((syncinfo.frame_size * 16) >> 8) & 0xff;
buf[8] = 0x77; buf[9] = 0x0b; // AC3 syncwork
if (!done_banner && !quiet) {
fprintf(stdout,"AC3 Stream ");
fprintf(stdout,"%2.1f KHz",syncinfo.sampling_rate * 1e-3);
fprintf(stdout,"%4d kbps",syncinfo.bit_rate);
@ -127,9 +154,11 @@ output_spdif(uint8_t *data_start, uint8_t *data_end, int quiet)
done_banner = 1;
}
#ifndef WORDS_BIGENDIAN
// extract_ac3 seems to write swabbed data
swab(&buf[10], &buf[10], syncinfo.frame_size * 2 - 2);
res = output_play(sbuf, BLOCK_SIZE / 2 / 2); /* 2 channels, 16-bit samples */
#endif
res = output_play((short *)buf, BLOCK_SIZE / 2 / 2); /* 2 channels, 16-bit samples */
ret = ret < 0 ? ret : res;
bzero(buf,BLOCK_SIZE);
}