mirror of
https://github.com/alsa-project/alsa-tools.git
synced 2025-10-31 22:25:34 -04:00
More enhancements:
- added getopt_long to parse the command line options - added -D (--device) option - added -q (--quiet) option - added -I (--iec958) option - added AC3 to IEC958 encapsulation code (not tested) - addec xrun detection and restart
This commit is contained in:
parent
3f541f6ba8
commit
97a55787e6
13 changed files with 425 additions and 120 deletions
|
|
@ -39,13 +39,14 @@ typedef signed char sint_8;
|
|||
#define AC3_3DNOW_ENABLE 0x2
|
||||
#define AC3_MMX_ENABLE 0x4
|
||||
#define AC3_ALTIVEC_ENABLE 0x8
|
||||
#define AC3_QUIET 0x10
|
||||
|
||||
typedef struct ac3_config_s
|
||||
{
|
||||
//Bit flags that enable various things
|
||||
uint_32 flags;
|
||||
//Callback that points the decoder to new stream data
|
||||
void (*fill_buffer_callback)(uint_8 **, uint_8 **);
|
||||
ssize_t (*fill_buffer_callback)(uint_8 **, uint_8 **);
|
||||
//Number of discrete channels in final output (for downmixing)
|
||||
uint_16 num_output_ch;
|
||||
//Which channel of a dual mono stream to select
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ typedef struct syncinfo_s
|
|||
{
|
||||
uint_32 magic;
|
||||
/* Sync word == 0x0B77 */
|
||||
/* uint_16 syncword; */
|
||||
uint_16 syncword;
|
||||
/* crc for the first 5/8 of the sync block */
|
||||
/* uint_16 crc1; */
|
||||
/* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ static uint_8 *chunk_start, *chunk_end;
|
|||
uint_32 bits_left;
|
||||
uint_32 current_word;
|
||||
|
||||
void (*bitstream_fill_buffer)(uint_8**,uint_8**);
|
||||
ssize_t (*bitstream_fill_buffer)(uint_8**,uint_8**);
|
||||
|
||||
uint_8 bitstream_get_byte(void)
|
||||
{
|
||||
|
|
@ -122,7 +122,7 @@ bitstream_get_bh(uint_32 num_bits)
|
|||
}
|
||||
|
||||
void
|
||||
bitstream_init(void(*fill_function)(uint_8**,uint_8**))
|
||||
bitstream_init(ssize_t(*fill_function)(uint_8**,uint_8**))
|
||||
{
|
||||
// Setup the buffer fill callback
|
||||
bitstream_fill_buffer = fill_function;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
extern uint_32 bits_left;
|
||||
extern uint_32 current_word;
|
||||
|
||||
void bitstream_init(void(*fill_function)(uint_8**,uint_8**));
|
||||
void bitstream_init(ssize_t(*fill_function)(uint_8**,uint_8**));
|
||||
|
||||
uint_8 bitstream_get_byte(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ ac3_decode_frame(void)
|
|||
|
||||
parse_bsi(&bsi);
|
||||
|
||||
if(!done_banner)
|
||||
if(!done_banner && !(ac3_config.flags & AC3_QUIET))
|
||||
{
|
||||
stats_print_banner(&syncinfo,&bsi);
|
||||
done_banner = 1;
|
||||
|
|
|
|||
|
|
@ -85,13 +85,42 @@ static const struct frmsize_s frmsizecod_tbl[64] =
|
|||
{ 640 ,{1280 ,1394 ,1920 } }
|
||||
};
|
||||
|
||||
void
|
||||
parse_syncinfo_data(syncinfo_t *syncinfo, uint_8 *data)
|
||||
{
|
||||
// Get the sampling rate
|
||||
syncinfo->fscod = (data[2] >> 6) & 0x3;
|
||||
|
||||
if(syncinfo->fscod == 3)
|
||||
{
|
||||
//invalid sampling rate code
|
||||
error_flag = 1;
|
||||
return;
|
||||
}
|
||||
else if(syncinfo->fscod == 2)
|
||||
syncinfo->sampling_rate = 32000;
|
||||
else if(syncinfo->fscod == 1)
|
||||
syncinfo->sampling_rate = 44100;
|
||||
else
|
||||
syncinfo->sampling_rate = 48000;
|
||||
|
||||
// Get the frame size code
|
||||
syncinfo->frmsizecod = data[2] & 0x3f;
|
||||
|
||||
// Calculate the frame size and bitrate
|
||||
syncinfo->frame_size =
|
||||
frmsizecod_tbl[syncinfo->frmsizecod].frm_size[syncinfo->fscod];
|
||||
syncinfo->bit_rate = frmsizecod_tbl[syncinfo->frmsizecod].bit_rate;
|
||||
}
|
||||
|
||||
/* Parse a syncinfo structure, minus the sync word */
|
||||
void
|
||||
parse_syncinfo(syncinfo_t *syncinfo)
|
||||
{
|
||||
uint_32 tmp = 0;
|
||||
uint_8 data[3];
|
||||
uint_16 sync_word = 0;
|
||||
uint_32 time_out = 1<<16;
|
||||
|
||||
|
||||
//
|
||||
// Find a ac3 sync frame. Time out if we read 64k without finding
|
||||
|
|
@ -109,34 +138,11 @@ parse_syncinfo(syncinfo_t *syncinfo)
|
|||
// We need to read in the entire syncinfo struct (0x0b77 + 24 bits)
|
||||
// in order to determine how big the frame is
|
||||
//
|
||||
tmp = (tmp << 8) + bitstream_get_byte();
|
||||
tmp = (tmp << 8) + bitstream_get_byte();
|
||||
tmp = (tmp << 8) + bitstream_get_byte();
|
||||
|
||||
// Get the sampling rate
|
||||
syncinfo->fscod = (tmp >> 6) & 0x3;
|
||||
|
||||
if(syncinfo->fscod == 3)
|
||||
{
|
||||
//invalid sampling rate code
|
||||
error_flag = 1;
|
||||
return;
|
||||
}
|
||||
else if(syncinfo->fscod == 2)
|
||||
syncinfo->sampling_rate = 32000;
|
||||
else if(syncinfo->fscod == 1)
|
||||
syncinfo->sampling_rate = 44100;
|
||||
else
|
||||
syncinfo->sampling_rate = 48000;
|
||||
|
||||
// Get the frame size code
|
||||
syncinfo->frmsizecod = tmp & 0x3f;
|
||||
|
||||
// Calculate the frame size and bitrate
|
||||
syncinfo->frame_size =
|
||||
frmsizecod_tbl[syncinfo->frmsizecod].frm_size[syncinfo->fscod];
|
||||
syncinfo->bit_rate = frmsizecod_tbl[syncinfo->frmsizecod].bit_rate;
|
||||
data[0] = bitstream_get_byte();
|
||||
data[1] = bitstream_get_byte();
|
||||
data[2] = bitstream_get_byte();
|
||||
|
||||
parse_syncinfo_data(syncinfo, data);
|
||||
|
||||
// Buffer the entire syncframe
|
||||
bitstream_buffer_frame(syncinfo->frame_size * 2 - 5);
|
||||
|
|
@ -144,9 +150,9 @@ parse_syncinfo(syncinfo_t *syncinfo)
|
|||
// Check the crc over the entire frame
|
||||
crc_init();
|
||||
|
||||
crc_process_byte(tmp>>16);
|
||||
crc_process_byte((tmp>>8) & 0xff);
|
||||
crc_process_byte(tmp & 0xff);
|
||||
crc_process_byte(data[0]);
|
||||
crc_process_byte(data[1]);
|
||||
crc_process_byte(data[2]);
|
||||
crc_process_frame(bitstream_get_buffer_start(),syncinfo->frame_size * 2 - 5);
|
||||
|
||||
if(!crc_validate())
|
||||
|
|
@ -156,7 +162,8 @@ parse_syncinfo(syncinfo_t *syncinfo)
|
|||
return;
|
||||
}
|
||||
|
||||
stats_print_syncinfo(syncinfo);
|
||||
if (!(ac3_config.flags & AC3_QUIET))
|
||||
stats_print_syncinfo(syncinfo);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -290,7 +297,8 @@ parse_bsi(bsi_t *bsi)
|
|||
bsi->addbsi[i] = bitstream_get(8);
|
||||
}
|
||||
|
||||
stats_print_bsi(bsi);
|
||||
if (!(ac3_config.flags & AC3_QUIET))
|
||||
stats_print_bsi(bsi);
|
||||
}
|
||||
|
||||
/* More pain inducing parsing */
|
||||
|
|
@ -598,7 +606,8 @@ parse_audblk(bsi_t *bsi,audblk_t *audblk)
|
|||
}
|
||||
}
|
||||
|
||||
stats_print_audblk(bsi,audblk);
|
||||
if (!(ac3_config.flags & AC3_QUIET))
|
||||
stats_print_audblk(bsi,audblk);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
void parse_syncinfo_data(syncinfo_t *syncinfo, uint_8 *data);
|
||||
void parse_syncinfo(syncinfo_t *syncinfo);
|
||||
void parse_audblk(bsi_t *bsi,audblk_t *audblk);
|
||||
void parse_bsi(bsi_t *bsi);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ static const char *language[128] =
|
|||
|
||||
void stats_print_banner(syncinfo_t *syncinfo,bsi_t *bsi)
|
||||
{
|
||||
fprintf(stdout,PACKAGE"-"VERSION" (C) 2000 Aaron Holtzman (aholtzma@ess.engr.uvic.ca)\n");
|
||||
// fprintf(stdout,PACKAGE"-"VERSION" (C) 2000 Aaron Holtzman (aholtzma@ess.engr.uvic.ca)\n");
|
||||
|
||||
fprintf(stdout,"%d.%d Mode ",bsi->nfchans,bsi->lfeon);
|
||||
fprintf(stdout,"%2.1f KHz",syncinfo->sampling_rate * 1e-3);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue