[xiph-cvs] cvs commit: vorbis-tools/ogg123 ogg123.c ogg123.h
Michael Smith
msmith at xiph.org
Thu Jan 25 03:31:15 PST 2001
msmith 01/01/25 03:31:14
Modified: ogg123 ogg123.c ogg123.h
Log:
Make ogg123 behave sanely with non-44.1k/stereo files. Now opens output devices once, then reopens ONLY if the params change.
Revision Changes Path
1.22 +50 -31 vorbis-tools/ogg123/ogg123.c
Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ogg123.c 2001/01/25 06:39:31 1.21
+++ ogg123.c 2001/01/25 11:31:14 1.22
@@ -14,7 +14,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.c,v 1.21 2001/01/25 06:39:31 giles Exp $
+ last mod: $Id: ogg123.c,v 1.22 2001/01/25 11:31:14 msmith Exp $
********************************************************************/
@@ -99,9 +99,8 @@
int option_index = 1;
ao_option_t *temp_options = NULL;
int temp_driver_id = -1;
- devices_t *current;
- int bits, rate, channels;
buf_t *buffer = NULL;
+ devices_t *current;
opt.read_file = NULL;
opt.shuffle = 0;
@@ -185,37 +184,9 @@
/* Open all of the devices */
- /* FIXME: OggVorbis files aren't all 16 bit 44.1k stereo. */
- /* Heck, they might not even be Vorbis :) PCM-Ogg? */
- bits = 16;
- rate = 44100;
- channels = 2;
- current = opt.outdevices;
-
if (opt.verbose > 0)
fprintf(stderr, "Opening devices...\n");
- while (current != NULL) {
- ao_info_t *info = ao_get_driver_info(current->driver_id);
-
- if (opt.verbose > 0) {
- fprintf(stderr, "Device: %s\n", info->name);
- fprintf(stderr, "Author: %s\n", info->author);
- fprintf(stderr, "Comments: %s\n", info->comment);
- }
-
- current->device = ao_open(current->driver_id, bits, rate, channels,
- current->options);
- if (current->device == NULL) {
- fprintf(stderr, "Error opening device.\n");
- exit(1);
- }
- if (opt.quiet < 1)
- fprintf(stderr, "\n"); // Gotta keep 'em separated ...
-
- current = current->next_device;
- }
-
if (opt.buffer_size)
buffer = fork_writer (opt.buffer_size, opt.outdevices);
@@ -373,6 +344,9 @@
vorbis_comment *vc = ov_comment(&vf, -1);
vorbis_info *vi = ov_info(&vf, -1);
+ if(open_audio_devices(&opt, vi->rate, vi->channels) < 0)
+ exit(1);
+
if (opt.quiet < 1) {
for (i = 0; i < vc->comments; i++) {
char *cc = vc->user_comments[i]; /* current comment */
@@ -489,4 +463,49 @@
return NULL;
}
return fdopen(sockfd, "r+b");
+}
+
+int open_audio_devices(ogg123_options_t *opt, int rate, int channels)
+{
+ static int prevrate=0, prevchan=0;
+ devices_t *current;
+
+ if(prevrate == rate && prevchan == channels)
+ return 0;
+
+ if(prevrate !=0 && prevchan!=0)
+ {
+ current = opt->outdevices;
+ while (current != NULL) {
+ ao_close(current->device);
+ current = current->next_device;
+ }
+ }
+
+ prevrate = rate;
+ prevchan = channels;
+
+ current = opt->outdevices;
+ while (current != NULL) {
+ ao_info_t *info = ao_get_driver_info(current->driver_id);
+
+ if (opt->verbose > 0) {
+ fprintf(stderr, "Device: %s\n", info->name);
+ fprintf(stderr, "Author: %s\n", info->author);
+ fprintf(stderr, "Comments: %s\n", info->comment);
+ }
+
+ current->device = ao_open(current->driver_id, 16, rate, channels,
+ current->options);
+ if (current->device == NULL) {
+ fprintf(stderr, "Error opening device.\n");
+ return -1;
+ }
+ if (opt->quiet < 1)
+ fprintf(stderr, "\n"); // Gotta keep 'em separated ...
+
+ current = current->next_device;
+ }
+
+ return 0;
}
1.4 +2 -0 vorbis-tools/ogg123/ogg123.h
Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ogg123.h 2000/12/30 05:44:31 1.3
+++ ogg123.h 2001/01/25 11:31:14 1.4
@@ -26,6 +26,7 @@
FILE *instream; /* Stream to read from. */
devices_t *outdevices; /* Streams to write to. */
int buffer_size; /* Size of the buffer in chunks. */
+ int rate, channels; /* playback params for opening audio devices */
} ogg123_options_t; /* Changed in 0.6 to be non-static */
/* This goes here because it relies on some of the above. */
@@ -40,5 +41,6 @@
void play_file(ogg123_options_t opt, buf_t *buffer);
int get_tcp_socket(void); /* Will be going soon. */
FILE *http_open(char *server, int port, char *path); /* ditto */
+int open_audio_devices(ogg123_options_t *opt, int rate, int channels);
#endif /* !defined(__OGG123_H) */
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list