Add setting volume and showing the subchannel when in non-interactive mode.

This commit is contained in:
rocky
2005-03-16 02:19:20 +00:00
parent f34059d4a4
commit 20e610a017
2 changed files with 133 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
/* /*
$Id: audio.c,v 1.2 2005/03/15 12:22:37 rocky Exp $ $Id: audio.c,v 1.3 2005/03/16 02:19:20 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -21,6 +21,10 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/* A program to show use of audio controls. For a more expanded
CDDA player program using curses display see cdda-player in this
distribution.
*/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@@ -58,15 +62,7 @@
#include <cdio/util.h> #include <cdio/util.h>
#include <cdio/cd_types.h> #include <cdio/cd_types.h>
static void play_track(track_t t1, track_t t2); static bool play_track(track_t t1, track_t t2);
typedef enum {
PLAY_CD=1,
PLAY_TRACK=2,
STOP_PLAYING=3,
EJECT_CD=4,
CLOSE_CD=5,
} cd_operation_t;
CdIo_t *p_cdio; /* libcdio handle */ CdIo_t *p_cdio; /* libcdio handle */
driver_id_t driver_id = DRIVER_DEVICE; driver_id_t driver_id = DRIVER_DEVICE;
@@ -78,7 +74,6 @@ track_t i_first_audio_track;
track_t i_last_audio_track; track_t i_last_audio_track;
track_t i_tracks; track_t i_tracks;
msf_t toc[CDIO_CDROM_LEADOUT_TRACK+1]; msf_t toc[CDIO_CDROM_LEADOUT_TRACK+1];
cd_operation_t todo; /* operation to do in non-interactive mode */
cdio_subchannel_t sub; /* subchannel last time read */ cdio_subchannel_t sub; /* subchannel last time read */
int i_data; /* # of data tracks present ? */ int i_data; /* # of data tracks present ? */
int start_track = 0; int start_track = 0;
@@ -237,9 +232,11 @@ read_toc(CdIo_t *p_cdio)
} }
/*! Play an audio track. */ /*! Play an audio track. */
static void static bool
play_track(track_t i_start_track, track_t i_end_track) play_track(track_t i_start_track, track_t i_end_track)
{ {
bool b_ok = true;
if (!b_cd) { if (!b_cd) {
cd_close(psz_device); cd_close(psz_device);
read_toc(p_cdio); read_toc(p_cdio);
@@ -247,7 +244,7 @@ play_track(track_t i_start_track, track_t i_end_track)
read_subchannel(p_cdio); read_subchannel(p_cdio);
if (!b_cd || i_first_track == CDIO_CDROM_LEADOUT_TRACK) if (!b_cd || i_first_track == CDIO_CDROM_LEADOUT_TRACK)
return; return false;
if (debug) if (debug)
fprintf(stderr,"play tracks: %d-%d => ", i_start_track, i_end_track); fprintf(stderr,"play tracks: %d-%d => ", i_start_track, i_end_track);
@@ -259,9 +256,11 @@ play_track(track_t i_start_track, track_t i_end_track)
fprintf(stderr,"%d-%d\n",i_start_track, i_end_track); fprintf(stderr,"%d-%d\n",i_start_track, i_end_track);
cd_pause(p_cdio); cd_pause(p_cdio);
if ( DRIVER_OP_SUCCESS != cdio_audio_play_msf(p_cdio, &(toc[i_start_track]), b_ok = (DRIVER_OP_SUCCESS == cdio_audio_play_msf(p_cdio,
&(toc[i_end_track])) ) &(toc[i_start_track]),
xperror("play"); &(toc[i_end_track])) );
if (!b_ok) xperror("play");
return b_ok;
} }
static void static void
@@ -285,10 +284,12 @@ usage(char *prog)
" -p play the whole CD\n" " -p play the whole CD\n"
" -t n play track >n<\n" " -t n play track >n<\n"
" -t a-b play all tracks between a and b (inclusive)\n" " -t a-b play all tracks between a and b (inclusive)\n"
" -L set volume level\n"
" -s stop playing\n" " -s stop playing\n"
" -S list audio subchannel information\n"
" -e eject cdrom\n" " -e eject cdrom\n"
"\n" "\n"
"Thats all. Oh, maybe a few words more about the auto-mode. This\n" "That's all. Oh, maybe a few words more about the auto-mode. This\n"
"is the 'dont-touch-any-key' feature. You load a CD, player starts\n" "is the 'dont-touch-any-key' feature. You load a CD, player starts\n"
"to play it, and when it is done it ejects the CD. Start it that\n" "to play it, and when it is done it ejects the CD. Start it that\n"
"way on a spare console and forget about it...\n" "way on a spare console and forget about it...\n"
@@ -298,19 +299,31 @@ usage(char *prog)
, prog, prog); , prog, prog);
} }
typedef enum {
PLAY_CD=1,
PLAY_TRACK=2,
STOP_PLAYING=3,
EJECT_CD=4,
CLOSE_CD=5,
SET_VOLUME=6,
LIST_SUBCHANNEL=7,
} cd_operation_t;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c, nostop=0; int c, nostop=0;
char *h; char *h;
int i_rc = 0; int i_rc = 0;
int i_volume_level;
cd_operation_t todo; /* operation to do in non-interactive mode */
psz_program = strrchr(argv[0],'/'); psz_program = strrchr(argv[0],'/');
psz_program = psz_program ? psz_program+1 : argv[0]; psz_program = psz_program ? psz_program+1 : argv[0];
/* parse options */ /* parse options */
while ( 1 ) { while ( 1 ) {
if (-1 == (c = getopt(argc, argv, "xdhkvcCpset:la"))) if (-1 == (c = getopt(argc, argv, "aCdehkpL:sSt:vx")))
break; break;
switch (c) { switch (c) {
case 'v': case 'v':
@@ -322,6 +335,11 @@ main(int argc, char *argv[])
case 'a': case 'a':
auto_mode = 1; auto_mode = 1;
break; break;
case 'L':
if (NULL != (h = strchr(optarg,'-'))) {
i_volume_level = atoi(optarg);
todo = SET_VOLUME;
}
case 't': case 't':
if (NULL != (h = strchr(optarg,'-'))) { if (NULL != (h = strchr(optarg,'-'))) {
*h = 0; *h = 0;
@@ -346,6 +364,9 @@ main(int argc, char *argv[])
case 's': case 's':
todo = STOP_PLAYING; todo = STOP_PLAYING;
break; break;
case 'S':
todo = LIST_SUBCHANNEL;
break;
case 'e': case 'e':
todo = EJECT_CD; todo = EJECT_CD;
break; break;
@@ -428,6 +449,34 @@ main(int argc, char *argv[])
case CLOSE_CD: case CLOSE_CD:
i_rc = cdio_close_tray(psz_device, NULL) ? 0 : 1; i_rc = cdio_close_tray(psz_device, NULL) ? 0 : 1;
break; break;
case SET_VOLUME:
{
cdio_audio_volume_t volume;
volume.level[0] = i_volume_level;
i_rc = (DRIVER_OP_SUCCESS == cdio_audio_set_volume(p_cdio,
&volume))
? 0 : 1;
break;
}
case LIST_SUBCHANNEL:
if (read_subchannel(p_cdio)) {
if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PAUSED ||
sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) {
{
printf("track %2d - %02d:%02d (%02d:%02d abs) ",
sub.track,
sub.rel_addr.msf.m,
sub.rel_addr.msf.s,
sub.abs_addr.msf.m,
sub.abs_addr.msf.s);
}
}
printf("drive state: %s\n",
mmc_audio_state2str(sub.audio_status));
} else {
i_rc = 1;
}
break;
} }
else { else {
fprintf(stderr,"no CD in drive (%s)\n", psz_device); fprintf(stderr,"no CD in drive (%s)\n", psz_device);

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdda-player.c,v 1.14 2005/03/15 15:56:13 rocky Exp $ $Id: cdda-player.c,v 1.15 2005/03/16 02:19:20 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -67,24 +67,13 @@
#include "cddb.h" #include "cddb.h"
static void play_track(track_t t1, track_t t2); static bool play_track(track_t t1, track_t t2);
static void display_cdinfo(CdIo_t *p_cdio, track_t i_tracks, static void display_cdinfo(CdIo_t *p_cdio, track_t i_tracks,
track_t i_first_track); track_t i_first_track);
static void get_cddb_track_info(track_t i_track); static void get_cddb_track_info(track_t i_track);
static void get_cdtext_track_info(track_t i_track); static void get_cdtext_track_info(track_t i_track);
static void get_track_info(track_t i_track); static void get_track_info(track_t i_track);
typedef enum {
PLAY_CD=1,
PLAY_TRACK=2,
STOP_PLAYING=3,
EJECT_CD=4,
CLOSE_CD=5,
LIST_KEYS=6,
LIST_TRACKS=7,
PS_LIST_TRACKS=8
} cd_operation_t;
CdIo_t *p_cdio; /* libcdio handle */ CdIo_t *p_cdio; /* libcdio handle */
driver_id_t driver_id = DRIVER_DEVICE; driver_id_t driver_id = DRIVER_DEVICE;
int b_sig = false; /* set on some signals */ int b_sig = false; /* set on some signals */
@@ -97,7 +86,6 @@ track_t i_last_audio_track;
track_t i_last_display_track = CDIO_INVALID_TRACK; track_t i_last_display_track = CDIO_INVALID_TRACK;
track_t i_tracks; track_t i_tracks;
msf_t toc[CDIO_CDROM_LEADOUT_TRACK+1]; msf_t toc[CDIO_CDROM_LEADOUT_TRACK+1];
cd_operation_t todo; /* operation to do in non-interactive mode */
cdio_subchannel_t sub; /* subchannel last time read */ cdio_subchannel_t sub; /* subchannel last time read */
int i_data; /* # of data tracks present ? */ int i_data; /* # of data tracks present ? */
int start_track = 0; int start_track = 0;
@@ -537,12 +525,11 @@ play_track(track_t i_start_track, track_t i_end_track)
cd_pause(p_cdio); cd_pause(p_cdio);
sprintf(line,"play track %d...", i_start_track); sprintf(line,"play track %d...", i_start_track);
action(line); action(line);
b_okay = (DRIVER_OP_SUCCESS == cdio_audio_play_msf(p_cdio, b_ok = (DRIVER_OP_SUCCESS == cdio_audio_play_msf(p_cdio,
&(toc[i_start_track]), &(toc[i_start_track]),
&(toc[i_end_track])) ); &(toc[i_end_track])) );
if (!b_okay) if (!b_ok) xperror("play");
xperror("play"); return b_ok;
return b_okay;
} }
static void static void
@@ -796,7 +783,7 @@ usage(char *prog)
" -a start up in auto-mode\n" " -a start up in auto-mode\n"
" -v verbose\n" " -v verbose\n"
"\n" "\n"
"for non-interactive use (only one of them):\n" "for non-interactive use (only one) of these:\n"
" -l list tracks\n" " -l list tracks\n"
" -c print cover (PostScript to stdout)\n" " -c print cover (PostScript to stdout)\n"
" -C close CD-ROM tray. If you use this option,\n" " -C close CD-ROM tray. If you use this option,\n"
@@ -804,10 +791,12 @@ usage(char *prog)
" -p play the whole CD\n" " -p play the whole CD\n"
" -t n play track >n<\n" " -t n play track >n<\n"
" -t a-b play all tracks between a and b (inclusive)\n" " -t a-b play all tracks between a and b (inclusive)\n"
" -L set volume level\n"
" -s stop playing\n" " -s stop playing\n"
" -S list audio subchannel information\n"
" -e eject cdrom\n" " -e eject cdrom\n"
"\n" "\n"
"Thats all. Oh, maybe a few words more about the auto-mode. This\n" "That's all. Oh, maybe a few words more about the auto-mode. This\n"
"is the 'dont-touch-any-key' feature. You load a CD, player starts\n" "is the 'dont-touch-any-key' feature. You load a CD, player starts\n"
"to play it, and when it is done it ejects the CD. Start it that\n" "to play it, and when it is done it ejects the CD. Start it that\n"
"way on a spare console and forget about it...\n" "way on a spare console and forget about it...\n"
@@ -1202,12 +1191,27 @@ ps_list_tracks(void)
printf("showpage\n"); printf("showpage\n");
} }
typedef enum {
PLAY_CD=1,
PLAY_TRACK=2,
STOP_PLAYING=3,
EJECT_CD=4,
CLOSE_CD=5,
SET_VOLUME=6,
LIST_SUBCHANNEL=7,
LIST_KEYS=8,
LIST_TRACKS=9,
PS_LIST_TRACKS=10
} cd_operation_t;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c, nostop=0; int c, nostop=0;
char *h; char *h;
int i_rc = 0; int i_rc = 0;
int i_volume_level;
cd_operation_t todo; /* operation to do in non-interactive mode */
psz_program = strrchr(argv[0],'/'); psz_program = strrchr(argv[0],'/');
psz_program = psz_program ? psz_program+1 : argv[0]; psz_program = psz_program ? psz_program+1 : argv[0];
@@ -1217,7 +1221,7 @@ main(int argc, char *argv[])
cdio_loglevel_default = CDIO_LOG_WARN; cdio_loglevel_default = CDIO_LOG_WARN;
/* parse options */ /* parse options */
while ( 1 ) { while ( 1 ) {
if (-1 == (c = getopt(argc, argv, "xdhkvcCpset:la"))) if (-1 == (c = getopt(argc, argv, "acCdehkplL:sSt:vx")))
break; break;
switch (c) { switch (c) {
case 'v': case 'v':
@@ -1233,6 +1237,11 @@ main(int argc, char *argv[])
case 'a': case 'a':
auto_mode = 1; auto_mode = 1;
break; break;
case 'L':
if (NULL != (h = strchr(optarg,'-'))) {
i_volume_level = atoi(optarg);
todo = SET_VOLUME;
}
case 't': case 't':
if (NULL != (h = strchr(optarg,'-'))) { if (NULL != (h = strchr(optarg,'-'))) {
*h = 0; *h = 0;
@@ -1268,6 +1277,9 @@ main(int argc, char *argv[])
interactive = 0; interactive = 0;
todo = STOP_PLAYING; todo = STOP_PLAYING;
break; break;
case 'S':
todo = LIST_SUBCHANNEL;
break;
case 'e': case 'e':
interactive = 0; interactive = 0;
todo = EJECT_CD; todo = EJECT_CD;
@@ -1368,6 +1380,34 @@ main(int argc, char *argv[])
case CLOSE_CD: case CLOSE_CD:
i_rc = cdio_close_tray(psz_device, NULL) ? 0 : 1; i_rc = cdio_close_tray(psz_device, NULL) ? 0 : 1;
break; break;
case SET_VOLUME:
{
cdio_audio_volume_t volume;
volume.level[0] = i_volume_level;
i_rc = (DRIVER_OP_SUCCESS == cdio_audio_set_volume(p_cdio,
&volume))
? 0 : 1;
break;
}
case LIST_SUBCHANNEL:
if (read_subchannel(p_cdio)) {
if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PAUSED ||
sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) {
{
printf("track %2d - %02d:%02d (%02d:%02d abs) ",
sub.track,
sub.rel_addr.msf.m,
sub.rel_addr.msf.s,
sub.abs_addr.msf.m,
sub.abs_addr.msf.s);
}
}
printf("drive state: %s\n",
mmc_audio_state2str(sub.audio_status));
} else {
i_rc = 1;
}
break;
case LIST_KEYS: case LIST_KEYS:
case LIST_TRACKS: case LIST_TRACKS:
break; break;
@@ -1402,7 +1442,6 @@ main(int argc, char *argv[])
case 'e': case 'e':
cd_eject(); cd_eject();
break; break;
case 'S':
case 's': case 's':
cd_stop(p_cdio); cd_stop(p_cdio);
break; break;