Audio-Play-MPG123

 view release on metacpan or  search on metacpan

mpg123/mpg123.c  view on Meta::CPAN

{
    if(ai.output <= 0)
	ai.output = AUDIO_OUT_LINE_OUT;
    else
	ai.output |= AUDIO_OUT_LINE_OUT;
}
static void set_output (char *arg)
{
    switch (*arg) {
    case 'h': set_output_h(arg); break;
    case 's': set_output_s(arg); break;
    case 'l': set_output_l(arg); break;
    default:
	fprintf (stderr, "%s: Unknown argument \"%s\" to option \"%s\".\n",
		 prgName, arg, loptarg);
	exit (1);
    }
}
static void set_verbose (char *arg)
{
    param.verbose++;
}
static void set_wav(char *arg)
{
    param.outmode = DECODE_WAV;
    strncpy(param.filename,arg,255);
    param.filename[255] = 0;
}
static void set_cdr(char *arg)
{
    param.outmode = DECODE_CDR;
    strncpy(param.filename,arg,255);
    param.filename[255] = 0;
}
static void set_au(char *arg)
{
    param.outmode = DECODE_AU;
    strncpy(param.filename,arg,255);
    param.filename[255] = 0;
}
static void SetOutFile(char *Arg)
{
    param.outmode=DECODE_FILE;
    OutputDescriptor=open(Arg,O_CREAT|O_WRONLY,0777);
    if(OutputDescriptor==-1) {
	fprintf(stderr,"Can't open %s for writing (%s).\n",Arg,strerror(errno));
	exit(1);
    }
}
static void SetOutStdout(char *Arg)
{
    param.outmode=DECODE_FILE;
    OutputDescriptor=1;
}
static void SetOutStdout1(char *Arg)
{
    param.outmode=DECODE_AUDIOFILE;
    OutputDescriptor=1;
}

void not_compiled(char *arg)
{
    fprintf(stderr,"Option '-T / --realtime' not compiled into this binary\n");
}

/* Please note: GLO_NUM expects point to LONG! */
topt opts[] = {
    {'k', "skip",        GLO_ARG | GLO_LONG, 0, &param.startFrame, 0},
    {'a', "audiodevice", GLO_ARG | GLO_CHAR, 0, &ai.device,  0},
    {'2', "2to1",        0,                  0, &param.down_sample, 1},
    {'4', "4to1",        0,                  0, &param.down_sample, 2},
    {'t', "test",        0,                  0, &param.outmode, DECODE_TEST},
    {'s', "stdout",      0,       SetOutStdout, &param.outmode, DECODE_FILE},
    {'S', "STDOUT",      0,       SetOutStdout1, &param.outmode, DECODE_AUDIOFILE},
    {'O', "outfile",     GLO_ARG | GLO_CHAR, SetOutFile, NULL, 0},
    {'c', "check",       0,                  0, &param.checkrange, TRUE},
    {'v', "verbose",     0,        set_verbose, 0,           0},
    {'q', "quiet",       0,                  0, &param.quiet,      TRUE},
    {'y', "resync",      0,                  0, &param.tryresync,  FALSE},
    {'0', "single0",     0,                  0, &param.force_mono, 0},
    {0,   "left",        0,                  0, &param.force_mono, 0},
    {'1', "single1",     0,                  0, &param.force_mono, 1},
    {0,   "right",       0,                  0, &param.force_mono, 1},
    {'m', "singlemix",   0,                  0, &param.force_mono, 3},
    {0,   "mix",         0,                  0, &param.force_mono, 3},
    {0,   "mono",        0,                  0, &param.force_mono, 3},
    {0,   "stereo",      0,                  0, &param.force_stereo, 1},
    {0,   "reopen",      0,                  0, &param.force_reopen, 1},
    {'g', "gain",        GLO_ARG | GLO_LONG, 0, &ai.gain,    0},
    {'r', "rate",        GLO_ARG | GLO_LONG, 0, &param.force_rate,  0},
    {0  , "pitch",       GLO_ARG | GLO_FLOAT,0, &param.pitch     ,  0},
    {0,   "8bit",        0,                  0, &param.force_8bit, 1},
    {0,   "headphones",  0,                  set_output_h, 0,0},
    {0,   "speaker",     0,                  set_output_s, 0,0},
    {0,   "lineout",     0,                  set_output_l, 0,0},
    {'o', "output",      GLO_ARG | GLO_CHAR, set_output, 0,  0},
    {'f', "scale",       GLO_ARG | GLO_LONG, 0, &param.outscale,   0},
    {'n', "frames",      GLO_ARG | GLO_LONG, 0, &numframes,  0},
#ifdef TERM_CONTROL
    {'C', "control",	 0,		     0, &param.term_ctrl, TRUE},
#endif
    {'b', "buffer",      GLO_ARG | GLO_LONG, 0, &param.usebuffer,  0},
    {'R', "remote",      0,                  0, &param.remote,     FRONTEND_GENERIC},
    {'d', "doublespeed", GLO_ARG | GLO_LONG, 0, &param.doublespeed,0},
    {'h', "halfspeed",   GLO_ARG | GLO_LONG, 0, &param.halfspeed,  0},
    {'p', "proxy",       GLO_ARG | GLO_CHAR, 0, &proxyurl,   0},
    {'@', "list",        GLO_ARG | GLO_CHAR, 0, &listname,   0},
    /* 'z' comes from the the german word 'zufall' (eng: random) */
    {'z', "shuffle",     0,                  0, &param.shuffle,    1},
    {'Z', "random",      0,                  0, &param.shuffle,    2},
    {'E', "equalizer",	 GLO_ARG | GLO_CHAR, 0, &param.equalfile,1},
    {0,   "aggressive",	 0,   	             0, &param.aggressive,2},
#ifdef USE_3DNOW
    {0,   "force-3dnow", 0,                  0, &param.stat_3dnow,1},
    {0,   "no-3dnow",    0,                  0, &param.stat_3dnow,2},
    {0,   "test-3dnow",  0,                  0, &param.test_3dnow,TRUE},
#endif
#if !defined(WIN32) && !defined(GENERIC)
    {'u', "auth",        GLO_ARG | GLO_CHAR, 0, &httpauth,   0},
#endif
#if defined(SET_RT)
    {'T', "realtime",   0,                  0, &param.realtime, TRUE },
#else
    {'T', "realtime",   0,       not_compiled, 0,           0 },    
#endif
    {0  , "title",	0,		0, &param.xterm_title, TRUE },
    {'w', "wav",        GLO_ARG | GLO_CHAR, set_wav, 0 , 0 },
    {0  , "cdr",        GLO_ARG | GLO_CHAR, set_cdr, 0 , 0 },
    {0  , "au",         GLO_ARG | GLO_CHAR, set_au,  0 , 0 },
    {'?', "help",       0,              usage, 0,           0 },
    {0  , "longhelp",   0,        long_usage,  0,           0 },
    {0  , "version",    0,                     0, &param.print_version,1},
#ifdef USE_ESD
    {0 , "esd",     GLO_ARG | GLO_CHAR,    0,  &param.esdserver, 0 },
#endif
    {0, 0, 0, 0, 0, 0}
};

/*
 *   Change the playback sample rate.
 */
static void reset_audio(void)
{
#ifndef NOXFERMEM
    if (param.usebuffer) {
	/* wait until the buffer is empty,
	 * then tell the buffer process to
	 * change the sample rate.   [OF]
	 */
	while (xfermem_get_usedspace(buffermem)	> 0)
	    if (xfermem_block(XF_WRITER, buffermem) == XF_CMD_TERMINATE) {
		intflag = TRUE;
		break;
	    }
	buffermem->freeindex = -1;
	buffermem->readindex = 0; /* I know what I'm doing! ;-) */
	buffermem->freeindex = 0;
	if (intflag)
	    return;
	buffermem->buf[0] = ai.rate; 
	buffermem->buf[1] = ai.channels; 
	buffermem->buf[2] = ai.format;
	buffer_reset();
    }
    else 
#endif
	if (param.outmode == DECODE_AUDIO) {
	    /* audio_reset_parameters(&ai); */
	    /*   close and re-open in order to flush
	     *   the device's internal buffer before
	     *   changing the sample rate.   [OF]
	     */
	    audio_close (&ai);
	    if (audio_open(&ai) < 0) {
		perror("audio");
		exit(1);
	    }
	}
}

/*
 * play a frame read by read_frame();
 * (re)initialize audio if necessary.
 *



( run in 0.820 second using v1.01-cache-2.11-cpan-800906f7e73 )