OSDN Git Service

* timidity/ao_a.c
authorKeishi Suenaga <s_keishi@mutt.freemail.ne.jp>
Tue, 8 Apr 2008 00:35:58 +0000 (00:35 +0000)
committerKeishi Suenaga <s_keishi@mutt.freemail.ne.jp>
Tue, 8 Apr 2008 00:35:58 +0000 (00:35 +0000)
timidity/portaudio_a.c
timidity/timidity.c
timidity/w32_a.c    select audio device only in -o option

ChangeLog
timidity/ao_a.c
timidity/portaudio_a.c
timidity/timidity.c
timidity/w32_a.c

index 44c6f65..8c26c77 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-08  Keishi Suenaga <skeishi@yahoo.co.jp>
+
+       * timidity/ao_a.c
+         timidity/portaudio_a.c
+         timidity/timidity.c
+      timidity/w32_a.c    select audio device only in -o option
+
 2008-04-06  TAMUKI Shoichi <tamuki@linet.gr.jp>
 
        * timidity/timidity.c: Revert short -Od(n) option for output
index 2f5b25c..8959b36 100644 (file)
@@ -38,6 +38,8 @@
 #include "playmidi.h"
 #include "miditrace.h"
 
+static int opt_ao_device_id = -2;
+
 static int open_output(void); /* 0=success, 1=warning, -1=fatal error */
 static void close_output(void);
 static int output_data(char *buf, int32 nbytes);
@@ -62,7 +64,7 @@ PlayMode dpm = {
 static ao_device *ao_device_ctx;
 static ao_sample_format ao_sample_format_ctx;
 
-void show_ao_device_info(FILE *fp)
+static void show_ao_device_info(FILE *fp)
 {
   int driver_count;
   ao_info **devices;
@@ -70,20 +72,15 @@ void show_ao_device_info(FILE *fp)
 
   ao_initialize();
 
-  fputs("Output device name (ao only):" NLS
-"  -o device    ", fp);
-
   devices  = ao_driver_info_list(&driver_count);
   if (driver_count < 1) {
          fputs("*no device found*" NLS, fp);
   }
   else {
-         fputs("[ ", fp);
          for(i = 0; i < driver_count; i++) {
                  if (devices[i]->type == AO_TYPE_LIVE)
-                         fprintf(fp, "%s ", devices[i]->short_name);
+                         fprintf(fp, "%d %s \n", ao_driver_id(devices[i]->short_name), devices[i]->short_name);
          }
-         fputs("]", fp);
   }
   ao_shutdown();
 }
@@ -91,17 +88,48 @@ void show_ao_device_info(FILE *fp)
 
 static int open_output(void)
 {
-  int driver_id;
+  int driver_id, ret;
+
+  int driver_count;
+  ao_info **devices;
+  int i;
+  char buf[256];
 
   ao_initialize();
 
-  if (dpm.name == NULL) {
+  opt_ao_device_id = -2;
+  devices  = ao_driver_info_list(&driver_count);
+  if (driver_count > 0) {
+    for(i = 0; i < driver_count; i++) {
+      if(  (devices[i]->type == AO_TYPE_LIVE) 
+      && (dpm.name != NULL) && (strcmp(dpm.name, devices[i]->short_name) == 0)  ){
+        opt_ao_device_id = ao_driver_id(dpm.name);
+      }
+      
+    }
+  }
+
+  if (opt_ao_device_id == -2){
+    if(dpm.name != NULL)
+      ret = sscanf(dpm.name, "%d", &opt_ao_device_id);
+    if ( dpm.name == NULL || ret == 0 || ret == EOF)
+      opt_ao_device_id = -2;
+    }
+    if (opt_ao_device_id == -1){
+      ao_shutdown();
+      show_ao_device_info(stdout);
+      return -1;
+    }
+
+
+
+  if (opt_ao_device_id==-2) {
     driver_id = ao_default_driver_id();
   }
   else {
     ao_info *device;
 
-    driver_id = ao_driver_id(dpm.name);
+    driver_id = opt_ao_device_id;
     if ((device = ao_driver_info(driver_id)) == NULL) {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: driver is not supported.",
                dpm.name);
index 4dfc9b4..3fb6c05 100644 (file)
@@ -64,7 +64,7 @@
 #include "playmidi.h"
 #include "miditrace.h"
 
-int opt_pa_device_id = -1;
+static int opt_pa_device_id = -2;
 
 #define DATA_BLOCK_SIZE     (27648*4) /* WinNT Latency is 600 msec read pa_dsound.c */
 #define SAMPLE_RATE         (44100)
@@ -296,9 +296,14 @@ static int open_output_win_wmme(void)
 static int open_output(void)
 {
        double rate;
-       int n, nrates, include_enc, exclude_enc;
+       int n, nrates, include_enc, exclude_enc, ret;
        PaSampleFormat SampleFormat, nativeSampleFormats;
        
+       if( dpm.name != NULL)
+               ret = sscanf(dpm.name, "%d", &opt_pa_device_id);
+       if (dpm.name == NULL || ret == 0 || ret == EOF)
+               opt_pa_device_id = -2;
+       
 #ifdef AU_PORTAUDIO_DLL
 #if PORTAUDIO_V19
   {
@@ -339,7 +344,7 @@ static int open_output(void)
                pa_active = 1;
        }
 
-       if (opt_pa_device_id == -2){
+       if (opt_pa_device_id == -1){
                print_device_list();
                goto error2;
        }
@@ -366,7 +371,7 @@ static int open_output(void)
        DeviceInfo = Pa_GetDeviceInfo( DeviceIndex);
        if(DeviceInfo==NULL) goto error;
 
-       if(opt_pa_device_id != -1){
+       if(opt_pa_device_id != -2){
                const PaDeviceInfo *id_DeviceInfo;
        id_DeviceInfo=Pa_GetDeviceInfo((PaDeviceIndex)opt_pa_device_id);
                if(id_DeviceInfo==NULL) goto error;
@@ -440,7 +445,7 @@ static int open_output(void)
        return 0;
        
 #else
-       if(opt_pa_device_id != -1){
+       if(opt_pa_device_id == -2){
                DeviceID = Pa_GetDefaultOutputDeviceID();
            if(DeviceID==paNoDevice) goto error2;
        }else{
index 36fb683..7495103 100644 (file)
@@ -1,6 +1,6 @@
 /*
     TiMidity++ -- MIDI to WAVE converter and player
-    Copyright (C) 1999-2008 Masanao Izumo <iz@onicos.co.jp>
+    Copyright (C) 1999-2007 Masanao Izumo <iz@onicos.co.jp>
     Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
 
     This program is free software; you can redistribute it and/or modify
@@ -178,7 +178,6 @@ enum {
        TIM_OPT_OUTPUT_BITWIDTH,
        TIM_OPT_OUTPUT_FORMAT,
        TIM_OPT_OUTPUT_SWAB,
-       TIM_OPT_OUTPUT_DEVICE,
        TIM_OPT_FLAC_VERIFY,
        TIM_OPT_FLAC_PADDING,
        TIM_OPT_FLAC_COMPLEVEL,
@@ -196,7 +195,6 @@ enum {
        TIM_OPT_POLY_REDUCE,
        TIM_OPT_MUTE,
        TIM_OPT_TEMPER_MUTE,
-       TIM_OPT_PRESERVE_SILENCE,
        TIM_OPT_AUDIO_BUFFER,
        TIM_OPT_CACHE_SIZE,
        TIM_OPT_SAMPLE_FREQ,
@@ -211,6 +209,7 @@ enum {
        TIM_OPT_FREQ_TABLE,
        TIM_OPT_PURE_INT,
        TIM_OPT_MODULE,
+       TIM_OPT_PRESERVE_SILENCE,
        /* last entry */
        TIM_OPT_LAST = TIM_OPT_PURE_INT
 };
@@ -322,9 +321,6 @@ static const struct option longopts[] = {
        { "output-alaw",            no_argument,       NULL, TIM_OPT_OUTPUT_FORMAT },
        { "no-output-swab",         no_argument,       NULL, TIM_OPT_OUTPUT_SWAB },
        { "output-swab",            optional_argument, NULL, TIM_OPT_OUTPUT_SWAB },
-#if defined(AU_PORTAUDIO) || defined(AU_WIN32)
-       { "output-device",          required_argument, NULL, TIM_OPT_OUTPUT_DEVICE },
-#endif
 #ifdef AU_FLAC
        { "flac-verify",            no_argument,       NULL, TIM_OPT_FLAC_VERIFY },
        { "flac-padding",           required_argument, NULL, TIM_OPT_FLAC_PADDING },
@@ -349,7 +345,6 @@ static const struct option longopts[] = {
        { "polyphony-reduction",    optional_argument, NULL, TIM_OPT_POLY_REDUCE },
        { "mute",                   required_argument, NULL, TIM_OPT_MUTE },
        { "temper-mute",            required_argument, NULL, TIM_OPT_TEMPER_MUTE },
-       { "preserve-silence",       no_argument,       NULL, TIM_OPT_PRESERVE_SILENCE },
        { "audio-buffer",           required_argument, NULL, TIM_OPT_AUDIO_BUFFER },
        { "cache-size",             required_argument, NULL, TIM_OPT_CACHE_SIZE },
        { "sampling-freq",          required_argument, NULL, TIM_OPT_SAMPLE_FREQ },
@@ -367,6 +362,7 @@ static const struct option longopts[] = {
        { "freq-table",             required_argument, NULL, TIM_OPT_FREQ_TABLE },
        { "pure-intonation",        optional_argument, NULL, TIM_OPT_PURE_INT },
        { "module",                 required_argument, NULL, TIM_OPT_MODULE },
+       { "preserve-silence",       no_argument,       NULL, TIM_OPT_PRESERVE_SILENCE },
        { NULL,                     no_argument,       NULL, '\0'     }
 };
 #define INTERACTIVE_INTERFACE_IDS "kmqagrwAWNP"
@@ -498,7 +494,6 @@ static inline int parse_opt_p(const char *);
 static inline int parse_opt_p1(const char *);
 static inline int parse_opt_Q(const char *);
 static inline int parse_opt_Q1(const char *);
-static inline int parse_opt_preserve_silence(const char *);
 static inline int parse_opt_q(const char *);
 static inline int parse_opt_R(const char *);
 static inline int parse_opt_S(const char *);
@@ -517,6 +512,7 @@ static inline int parse_opt_x(char *);
 static inline void expand_escape_string(char *);
 static inline int parse_opt_Z(char *);
 static inline int parse_opt_Z1(const char *);
+static inline int parse_opt_preserve_silence(const char *);
 static inline int parse_opt_default_module(const char *);
 __attribute__((noreturn))
 static inline int parse_opt_fail(const char *);
@@ -604,22 +600,27 @@ CRITICAL_SECTION critSect;
 static BOOL WINAPI handler(DWORD dw)
 {
 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN)
-       if (ctl->id_character == 'W' || ctl->id_character == 'P')
-               rtsyn_midiports_close();
-#endif
-#if 0
-#if defined(IA_NPSYN)
-       if (ctl->id_character == 'N')
-               return FALSE;   /* why FALSE need?  It must close by intr++; */
-#endif
+       if( ctl->id_character == 'W' 
+               || ctl->id_character == 'P' )
+       {
+       rtsyn_midiports_close();
+       }
 #endif
-       printf ("***BREAK" NLS);
-       fflush(stdout);
-       intr++;
-       return TRUE;
+
+
+//#if defined(IA_NPSYN)
+//     if( ctl->id_character == 'N')
+//     {
+//             return FALSE;  //why FALSE need?  It must close by intr++;
+//     }
+//#endif
+       printf ("***BREAK" NLS); fflush(stdout);
+    intr++;
+    return TRUE;
 }
 #endif
 
+
 int effect_lr_mode = -1;
 /* 0: left delay
  * 1: right delay
@@ -2663,7 +2664,6 @@ MAIN_INTERFACE int set_tim_opt_short(int c, char *optarg)
        }
        return 0;
 }
-
 MAIN_INTERFACE int set_tim_opt_short_cfg(int c, char *optarg)
 {
        int err = 0;
@@ -2834,10 +2834,6 @@ MAIN_INTERFACE int set_tim_opt_long(int c, char *optarg, int index)
                return parse_opt_output_format(arg);
        case TIM_OPT_OUTPUT_SWAB:
                return parse_opt_output_swab(arg);
-#if defined(AU_PORTAUDIO) || defined(AU_WIN32)
-       case TIM_OPT_OUTPUT_DEVICE:
-               return parse_opt_output_device(arg);
-#endif
 #ifdef AU_FLAC
        case TIM_OPT_FLAC_VERIFY:
                return parse_opt_flac_verify(arg);
@@ -2878,8 +2874,6 @@ MAIN_INTERFACE int set_tim_opt_long(int c, char *optarg, int index)
                return parse_opt_Q(arg);
        case TIM_OPT_TEMPER_MUTE:
                return parse_opt_Q1(arg);
-       case TIM_OPT_PRESERVE_SILENCE:
-               return parse_opt_preserve_silence(arg);
        case TIM_OPT_AUDIO_BUFFER:
                return parse_opt_q(arg);
        case TIM_OPT_CACHE_SIZE:
@@ -2910,13 +2904,14 @@ MAIN_INTERFACE int set_tim_opt_long(int c, char *optarg, int index)
                return parse_opt_Z1(arg);
        case TIM_OPT_MODULE:
                return parse_opt_default_module(arg);
+       case TIM_OPT_PRESERVE_SILENCE:
+               return parse_opt_preserve_silence(arg);
        default:
                ctl->cmsg(CMSG_FATAL, VERB_NORMAL,
                                "[BUG] Inconceivable case branch %d", c);
                abort();
        }
 }
-
 MAIN_INTERFACE int set_tim_opt_long_cfg(int c, char *optarg, int index)
 {
        const struct option *the_option = &(longopts[index]);
@@ -2995,8 +2990,7 @@ static inline int parse_opt_C(const char *arg)
 static inline int parse_opt_c(char *arg)
 {
 #ifdef __W32__
-       if (got_a_configuration == 1)
-               return 0;
+       if(got_a_configuration == 1) return 0;
 #endif
        if (read_config_file(arg, 0))
                return 1;
@@ -3725,10 +3719,6 @@ static int parse_opt_h(const char *arg)
 "                   n+1 point Gauss-like interpolation, n=1-34 (default 25)",
 "  -O mode    --output-mode=mode",
 "               Select output mode and format (see below for list)",
-#if defined(AU_PORTAUDIO) || defined(AU_WIN32)
-"     d n     --output-device=n (for portaudio only)",
-"               Set the output device ID (n=-1 shows available device list)",
-#endif
 #ifdef AU_FLAC
 "             --flac-verify (for Ogg FLAC only)",
 "               Verify a correct encoding",
@@ -3758,19 +3748,20 @@ static int parse_opt_h(const char *arg)
 "               Number of frames per Ogg packet n:[0-10]",
 #endif
 "  -o file    --output-file=file",
-"               Output to another file (or device/server) (Use \"-\" for stdout)",
+"               Output to another file (or device No./server) (Use \"-\" for stdout)",
+"               \"-o -1\" shows available device No. list."
 "  -P file    --patch-file=file",
 "               Use patch file for all programs",
 "  -p n       --polyphony=n",
 "               Allow n-voice polyphony.  Optional auto polyphony reduction",
 "     (a)     --[no-]polyphony-reduction",
 "               Toggle automatic polyphony reduction.  Enabled by default",
+"             --preserve-silence",
+"               Do not drop initial silence. Default: drop initial silence",
 "  -Q n[,...] --mute=n[,...]",
 "               Ignore channel n (0: ignore all, -n: resume channel n)",
 "     (t)     --temper-mute=n[,...]",
 "               Quiet temperament type n (0..3: preset, 4..7: user-defined)",
-"             --preserve-silence",
-"               Do not drop initial silence.  Default: drop initial silence",
 "  -q sec/n   --audio-buffer=sec/n",
 "               Specify audio buffer in seconds",
 "                 sec: Maxmum buffer, n: Filled to start (default is 5.0/100%%)",
@@ -3988,9 +3979,6 @@ static int parse_opt_h(const char *arg)
        for (pmpp = play_mode_list; (pmp = *pmpp) != NULL; pmpp++)
                fprintf(fp, "  -O%c          %s" NLS,
                                pmp->id_character, pmp->id_name);
-#ifdef AU_AO
-       show_ao_device_info(fp);
-#endif /* AU_AO */
        fputs(NLS, fp);
        fputs("Output format options (append to -O? option):" NLS
 "  `S'          stereo" NLS
@@ -4005,6 +3993,11 @@ static int parse_opt_h(const char *arg)
 "  `A'          A-Law encoding" NLS
 "  `x'          byte-swapped output" NLS, fp);
        fputs(NLS, fp);
+#if defined(AU_PORTAUDIO) || defined(AU_WIN32)
+       fputs("Output device options (append to -O? option):" NLS
+"  `d(n)'       Output device ID (blank shows available device list)" NLS, fp);
+       fputs(NLS, fp);
+#endif
        fputs("Alternative output format long options:" NLS
 "  --output-stereo" NLS
 "  --output-mono" NLS
@@ -4339,9 +4332,6 @@ static inline int parse_opt_O(const char *arg)
        /* output mode */
        PlayMode *pmp, **pmpp;
        int found = 0;
-#if defined(AU_PORTAUDIO) || defined(AU_W32)
-       int ret;
-#endif
        
        for (pmpp = play_mode_list; (pmp = *pmpp) != NULL; pmpp++)
                if (pmp->id_character == *arg) {
@@ -4398,38 +4388,6 @@ static inline int parse_opt_O(const char *arg)
                        pmp->encoding ^= PE_BYTESWAP;   /* toggle */
                        pmp->encoding &= ~(PE_ULAW | PE_ALAW);
                        break;
-#ifdef AU_PORTAUDIO
-               case 'd':
-                       if (play_mode->id_character == 'p'
-                                       || play_mode->id_character == 'P'
-                                       || play_mode->id_character == 'o') {
-                               ret = sscanf(arg + 1, "%d", &opt_pa_device_id);
-                               if (ret != 0 && ret != EOF)
-                                       while (*(arg + 1) >= '0' && *(arg + 1) <= '9')
-                                               arg++;
-                               else {
-                                       opt_pa_device_id = -2;
-                                       play_mode->open_output();
-                                       return 1;
-                               }
-                       }
-                       break;
-#endif
-#ifdef AU_W32
-               case 'd':
-                       if (play_mode->id_character == 'd') {
-                               ret = sscanf(arg + 1, "%d", &opt_wmme_device_id);
-                               if (ret != 0 && ret != EOF)
-                                       while (*(arg + 1) >= '0' && *(arg + 1) <= '9')
-                                               arg++;
-                               else {
-                                       opt_wmme_device_id = -2;
-                                       play_mode->open_output();
-                                       return 1;
-                               }
-                       }
-                       break;
-#endif
                default:
                        ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
                                        "Unknown format modifier `%c'", *arg);
@@ -4515,48 +4473,6 @@ static inline int parse_opt_output_swab(const char *arg)
        return 0;
 }
 
-#if defined(AU_PORTAUDIO)
-static inline int parse_opt_output_device(const char *arg)
-{
-       int ret;
-       
-       if (arg == NULL)
-               return 1;
-       if (play_mode->id_character == 'p'
-                       || play_mode->id_character == 'P'
-                       || play_mode->id_character == 'o') {
-               ret = sscanf(arg, "%d", &opt_pa_device_id);
-               if (ret == 0 || ret == EOF)
-                       return 1;
-               if (opt_pa_device_id == -1) {
-                       opt_pa_device_id = -2;
-                       play_mode->open_output();
-                       return 1;
-               }
-       }
-       return 0;
-}
-#endif
-#if defined(AU_W32)
-static inline int parse_opt_output_device(const char *arg)
-{
-       int ret;
-       
-       if (arg == NULL)
-               return 1;
-       if (play_mode->id_character == 'd') {
-               ret = sscanf(arg, "%d", &opt_wmme_device_id);
-               if (ret == 0 || ret == EOF)
-                       return 1;
-               if (opt_wmme_device_id == -1) {
-                       opt_wmme_device_id = -2;
-                       play_mode->open_output();
-                       return 1;
-               }
-       }
-       return 0;
-}
-#endif
 
 #ifdef AU_FLAC
 extern void flac_set_option_verify(int);
@@ -4708,12 +4624,6 @@ static inline int parse_opt_Q1(const char *arg)
        return 0;
 }
 
-static inline int parse_opt_preserve_silence(const char *arg)
-{
-       opt_preserve_silence = 1;
-       return 0;
-}
-
 static inline int parse_opt_q(const char *arg)
 {
        char *max_buff = safe_strdup(arg);
@@ -4994,6 +4904,12 @@ static inline int parse_opt_default_module(const char *arg)
        return 0;
 }
 
+static inline int parse_opt_preserve_silence(const char *arg)
+{
+        opt_preserve_silence = 1;
+       return 0;
+}
+
 __attribute__((noreturn))
 static inline int parse_opt_fail(const char *arg)
 {
@@ -5133,6 +5049,7 @@ static RETSIGTYPE sigterm_exit(int sig)
      * function.  It is possible coredump if the signal is called in printf's.
      */
 
+
     write(2, "Terminated sig=0x", 17);
     s[0] = "0123456789abcdef"[(sig >> 4) & 0xf];
     s[1] = "0123456789abcdef"[sig & 0xf];
@@ -5871,8 +5788,7 @@ int main(int argc, char **argv)
        files  = argv + optind;
        if (nfiles > 0
                        && ctl->id_character != 'r' && ctl->id_character != 'A'
-                       && ctl->id_character != 'W' && ctl->id_character != 'N'
-                       && ctl->id_character != 'P')
+                       && ctl->id_character != 'W' && ctl->id_character != 'N' && ctl->id_character != 'P')
                files = expand_file_archives(files, &nfiles);
        if (nfiles > 0)
                files_nbuf = files[0];
@@ -5895,11 +5811,11 @@ int main(int argc, char **argv)
        w32g_free_doc();
 #else
 #ifdef IA_NPSYN
-       timeBeginPeriod(1);
+       timeBeginPeriod( 1 );
 #endif 
        main_ret = timidity_play_main(nfiles, files);
 #ifdef IA_NPSYN
-       timeEndPeriod(1);
+       timeEndPeriod( 1 );
 #endif 
 #ifdef IA_W32G_SYN
        if (CoInitializeOK)
@@ -5935,8 +5851,7 @@ int main(int argc, char **argv)
                free(wrdt_open_opts);
        if (nfiles > 0
                        && ctl->id_character != 'r' && ctl->id_character != 'A'
-                       && ctl->id_character != 'W' && ctl->id_character != 'N'
-                       && ctl->id_character != 'P') {
+                       && ctl->id_character != 'W' && ctl->id_character != 'N'  && ctl->id_character != 'P') {
                free(files_nbuf);
                free(files);
        }
index 326fde9..edf3034 100644 (file)
@@ -43,7 +43,7 @@ extern void *safe_malloc(size_t count);
 
 extern CRITICAL_SECTION critSect;
 
-int opt_wmme_device_id = -1;
+static int opt_wmme_device_id = -2;
 
 UINT uDeviceID;
 
@@ -224,8 +224,14 @@ static int open_output(void)
     WAVEOUTCAPS     woc;
     MMRESULT        Result;
     UINT            DeviceID;
-
-       if (opt_wmme_device_id == -2){
+       int ret;
+       
+       if( dpm.name != NULL)
+               ret = sscanf(dpm.name, "%d", &opt_wmme_device_id);
+       if ( dpm.name == NULL || ret == 0 || ret == EOF)
+               opt_wmme_device_id = -2;
+       
+       if (opt_wmme_device_id == -1){
                print_device_list();
                return -1;
        }
@@ -295,7 +301,7 @@ static int open_output(void)
 
                hDevice = 0;
 
-       if (opt_wmme_device_id == -1){
+       if (opt_wmme_device_id == -2){
                uDeviceID = WAVE_MAPPER;
     }else{
        uDeviceID= (UINT)opt_wmme_device_id;