mirror of
https://github.com/alsa-project/alsa-tools.git
synced 2025-10-31 22:25:34 -04:00
Added big-endian checking.
Added --zero option. Added leadin for AC3 SPDIF.
This commit is contained in:
parent
04255b61c5
commit
c2aa076fb2
6 changed files with 70 additions and 15 deletions
|
|
@ -35,10 +35,10 @@
|
||||||
#include "libac3/ac3.h"
|
#include "libac3/ac3.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
|
|
||||||
void
|
void init_spdif(void);
|
||||||
init_spdif(void);
|
int output_spdif_zero(int frames);
|
||||||
int
|
int output_spdif_leadin(void);
|
||||||
output_spdif(uint_8 *data_start, uint_8 *data_end, int quiet);
|
int output_spdif(uint_8 *data_start, uint_8 *data_end, int quiet);
|
||||||
|
|
||||||
static int end_flag = 0;
|
static int end_flag = 0;
|
||||||
static int quiet = 0;
|
static int quiet = 0;
|
||||||
|
|
@ -56,6 +56,7 @@ static void help(void)
|
||||||
printf(" -C,--iec958c raw IEC958 (S/PDIF) consumer mode\n");
|
printf(" -C,--iec958c raw IEC958 (S/PDIF) consumer mode\n");
|
||||||
printf(" -P,--iec958p raw IEC958 (S/PDIF) professional mode\n");
|
printf(" -P,--iec958p raw IEC958 (S/PDIF) professional mode\n");
|
||||||
printf(" -R,--iec958r raw IEC958 (S/PDIF) PCM\n");
|
printf(" -R,--iec958r raw IEC958 (S/PDIF) PCM\n");
|
||||||
|
printf(" -Z,--zero=# add # zero-AC3-frames before stream\n");
|
||||||
printf(" -q,--quit quit mode\n");
|
printf(" -q,--quit quit mode\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,12 +106,14 @@ int main(int argc,char *argv[])
|
||||||
{"spdif", 0, NULL, 'C'},
|
{"spdif", 0, NULL, 'C'},
|
||||||
{"iec958p", 0, NULL, 'P'},
|
{"iec958p", 0, NULL, 'P'},
|
||||||
{"iec958r", 0, NULL, 'R'},
|
{"iec958r", 0, NULL, 'R'},
|
||||||
|
{"zero", 1, NULL, 'Z'},
|
||||||
{"quit", 0, NULL, 'q'},
|
{"quit", 0, NULL, 'q'},
|
||||||
{NULL, 0, NULL, 0},
|
{NULL, 0, NULL, 0},
|
||||||
};
|
};
|
||||||
ac3_config_t ac3_config;
|
ac3_config_t ac3_config;
|
||||||
output_t out_config;
|
output_t out_config;
|
||||||
int morehelp, loop = 0;
|
int morehelp, loop = 0;
|
||||||
|
int zero = 0;
|
||||||
|
|
||||||
bzero(&ac3_config, sizeof(ac3_config));
|
bzero(&ac3_config, sizeof(ac3_config));
|
||||||
ac3_config.fill_buffer_callback = fill_buffer;
|
ac3_config.fill_buffer_callback = fill_buffer;
|
||||||
|
|
@ -128,7 +131,7 @@ int main(int argc,char *argv[])
|
||||||
while (1) {
|
while (1) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if ((c = getopt_long(argc, argv, "hvcD:46CPRq", long_option, NULL)) < 0)
|
if ((c = getopt_long(argc, argv, "hvcD:46CPRZq", long_option, NULL)) < 0)
|
||||||
break;
|
break;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
@ -163,6 +166,9 @@ int main(int argc,char *argv[])
|
||||||
ac3_config.num_output_ch = 2;
|
ac3_config.num_output_ch = 2;
|
||||||
out_config.spdif = SPDIF_PCM;
|
out_config.spdif = SPDIF_PCM;
|
||||||
break;
|
break;
|
||||||
|
case 'Z':
|
||||||
|
zero = atoi(optarg);
|
||||||
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
ac3_config.flags |= AC3_QUIET;
|
ac3_config.flags |= AC3_QUIET;
|
||||||
out_config.quiet = 1;
|
out_config.quiet = 1;
|
||||||
|
|
@ -218,6 +224,10 @@ int main(int argc,char *argv[])
|
||||||
signal(SIGINT, ac3dec_signal_handler);
|
signal(SIGINT, ac3dec_signal_handler);
|
||||||
signal(SIGTERM, ac3dec_signal_handler);
|
signal(SIGTERM, ac3dec_signal_handler);
|
||||||
signal(SIGABRT, ac3dec_signal_handler);
|
signal(SIGABRT, ac3dec_signal_handler);
|
||||||
|
if (zero > 0)
|
||||||
|
output_spdif_zero(zero);
|
||||||
|
else
|
||||||
|
output_spdif_leadin();
|
||||||
while (fill_buffer(&start, &end) > 0)
|
while (fill_buffer(&start, &end) > 0)
|
||||||
if (output_spdif(start, end, quiet) < 0)
|
if (output_spdif(start, end, quiet) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -105,21 +105,48 @@ init_spdif(void)
|
||||||
done_banner = 0;
|
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
|
int
|
||||||
output_spdif(uint8_t *data_start, uint8_t *data_end, int quiet)
|
output_spdif(uint8_t *data_start, uint8_t *data_end, int quiet)
|
||||||
{
|
{
|
||||||
unsigned short *sbuf = (unsigned short *)buf;
|
|
||||||
int ret = 0, res;
|
int ret = 0, res;
|
||||||
|
|
||||||
while(buffer_syncframe(&syncinfo, &data_start, data_end))
|
while(buffer_syncframe(&syncinfo, &data_start, data_end))
|
||||||
{
|
{
|
||||||
sbuf[0] = 0xf872; //spdif syncword
|
buf[0] = 0x72; buf[1] = 0xf8; // spdif syncword
|
||||||
sbuf[1] = 0x4e1f; // .............
|
buf[2] = 0x1f; buf[3] = 0x4e; // ..............
|
||||||
sbuf[2] = 0x0001; // AC3 data
|
buf[4] = 0x01; // AC3 data
|
||||||
sbuf[3] = syncinfo.frame_size * 16;
|
buf[5] = buf[10] >> 5; // bsmod, stream = 0
|
||||||
sbuf[4] = 0x0b77; // AC3 syncwork
|
buf[6] = (syncinfo.frame_size * 16) & 0xff;
|
||||||
|
buf[7] = ((syncinfo.frame_size * 16) >> 8) & 0xff;
|
||||||
if (!done_banner) {
|
buf[8] = 0x77; buf[9] = 0x0b; // AC3 syncwork
|
||||||
|
|
||||||
|
if (!done_banner && !quiet) {
|
||||||
fprintf(stdout,"AC3 Stream ");
|
fprintf(stdout,"AC3 Stream ");
|
||||||
fprintf(stdout,"%2.1f KHz",syncinfo.sampling_rate * 1e-3);
|
fprintf(stdout,"%2.1f KHz",syncinfo.sampling_rate * 1e-3);
|
||||||
fprintf(stdout,"%4d kbps",syncinfo.bit_rate);
|
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;
|
done_banner = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WORDS_BIGENDIAN
|
||||||
// extract_ac3 seems to write swabbed data
|
// extract_ac3 seems to write swabbed data
|
||||||
swab(&buf[10], &buf[10], syncinfo.frame_size * 2 - 2);
|
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;
|
ret = ret < 0 ? ret : res;
|
||||||
bzero(buf,BLOCK_SIZE);
|
bzero(buf,BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
@BOTTOM@
|
@BOTTOM@
|
||||||
|
|
||||||
/* Architecture defines */
|
/* Architecture defines */
|
||||||
#undef __i386__
|
#undef __i386__
|
||||||
#undef __alpha__
|
#undef __alpha__
|
||||||
#undef __ppc__
|
#undef __ppc__
|
||||||
#undef __sparc__
|
#undef __sparc__
|
||||||
|
|
||||||
|
/* Big-Endian */
|
||||||
|
#undef WORDS_BIGENDIAN
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,24 @@
|
||||||
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
||||||
|
|
||||||
|
/* Define if your processor stores words with the most significant
|
||||||
|
byte first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||||
|
#undef WORDS_BIGENDIAN
|
||||||
|
|
||||||
|
/* Define if you have the asound library (-lasound). */
|
||||||
|
#undef HAVE_LIBASOUND
|
||||||
|
|
||||||
/* Name of package */
|
/* Name of package */
|
||||||
#undef PACKAGE
|
#undef PACKAGE
|
||||||
|
|
||||||
/* Version number of package */
|
/* Version number of package */
|
||||||
#undef VERSION
|
#undef VERSION
|
||||||
|
|
||||||
|
|
||||||
/* Architecture defines */
|
/* Architecture defines */
|
||||||
#undef __i386__
|
#undef __i386__
|
||||||
#undef __alpha__
|
#undef __alpha__
|
||||||
#undef __ppc__
|
#undef __ppc__
|
||||||
#undef __sparc__
|
#undef __sparc__
|
||||||
|
|
||||||
|
/* Big-Endian */
|
||||||
|
#undef WORDS_BIGENDIAN
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ AC_PROG_CC
|
||||||
AC_PROG_GCC_TRADITIONAL
|
AC_PROG_GCC_TRADITIONAL
|
||||||
AC_PROG_RANLIB
|
AC_PROG_RANLIB
|
||||||
|
|
||||||
AC_CHECK_LIB(ossaudio, _oss_ioctl, LIBS="$LIBS -lossaudio")
|
AC_C_BIGENDIAN
|
||||||
|
|
||||||
AM_PATH_ALSA(0.9.0)
|
AM_PATH_ALSA(0.9.0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
aclocal $ACLOCAL_FLAGS
|
aclocal $ACLOCAL_FLAGS
|
||||||
|
autoheader
|
||||||
automake --add-missing
|
automake --add-missing
|
||||||
autoconf
|
autoconf
|
||||||
./configure $*
|
./configure $*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue