OSDN Git Service

2007-3-10 Keishi Suenaga <skeishi@yahoo.co.jp>
authorKeishi Suenaga <s_keishi@mutt.freemail.ne.jp>
Fri, 9 Mar 2007 20:37:58 +0000 (20:37 +0000)
committerKeishi Suenaga <s_keishi@mutt.freemail.ne.jp>
Fri, 9 Mar 2007 20:37:58 +0000 (20:37 +0000)
* interface/npsyn_c.c
  interface/rtsyn.h
  interface/rtsyn_common.c
  interface/rtsyn_npipe.c
  timidity/npipe_a.c
  timidity/playmidi.c
  timidity/portaudio_a.c
  timidity/timidity.c
  utils/timer.c:          Windows Named Pipe interface.

ChangeLog
interface/npsyn_c.c
interface/rtsyn.h
interface/rtsyn_common.c
interface/rtsyn_npipe.c
timidity/npipe_a.c
timidity/playmidi.c
timidity/portaudio_a.c
timidity/timidity.c
utils/timer.c

index ea4fd7f..b573169 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-3-10  Keishi Suenaga <skeishi@yahoo.co.jp>
+
+       * interface/npsyn_c.c
+         interface/rtsyn.h
+         interface/rtsyn_common.c
+         interface/rtsyn_npipe.c
+         timidity/npipe_a.c
+         timidity/playmidi.c
+         timidity/portaudio_a.c
+         timidity/timidity.c
+         utils/timer.c:          Windows Named Pipe interface.
+         
 2007-02-09  Keishi Suenaga <skeishi@yahoo.co.jp>
 
        * interface.h.in:       Windows Named Pipe
        * windrv/timiwp_timidity.c: fix for WindowsMediaPlayer.
 
 \r2007-01-28  Keishi Suenaga <skeishi@yahoo.co.jp>
-\r
-       * interface/rtsyn_common.c: fix sysex check \r
-       * timidity/portaudio_a.c    small fix for compiling\r
+
+       * interface/rtsyn_common.c: fix sysex check 
+       * timidity/portaudio_a.c    small fix for compiling
        * timidity/timidity.c       w32 cfg file sequence changed
                                    option > exe dir > win dir
-\r                                  w32 set stdin&out binarymode\r
-       * timidity/w32_a.c          small fix for compiling\r
-       * windrv/Makefile.am        re-add add timidity.idl\r
-       * windrv/timiditydrv.c      re-add MIDIOUTCAPS2A(W)\r
+\r                                  w32 set stdin&out binarymode
+       * timidity/w32_a.c          small fix for compiling
+       * windrv/Makefile.am        re-add add timidity.idl
+       * windrv/timiditydrv.c      re-add MIDIOUTCAPS2A(W)
        * windrv/timiditydrv.idl    re-add
 
 2007-01-14  Keishi Suenaga <skeishi@yahoo.co.jp>
index 8f260a8..2d591e8 100755 (executable)
@@ -83,7 +83,6 @@ static int peek_character = -1;
 extern int volatile stream_max_compute;        // play_event() \82Ì compute_data() \82Å\8cv\8eZ\82ð\8b\96\82·\8dÅ\91å\8e\9e\8aÔ
 static int seq_quit=~0;
 
-
 static int ctl_open(int using_stdin, int using_stdout);
 static void ctl_close(void);
 static int ctl_read(int32 *valp);
@@ -227,18 +226,23 @@ static int ctl_pass_playing_list(int n, char *args[])
 int ctl_pass_playing_list2(int n, char *args[])
 #endif
 { 
-       if(n != 1){
-               ctl.cmsg(CMSG_WARNING, VERB_NORMAL, "Usage: timidity -iN [Named Pipe Name]\n");
+       if( (n < 1) || (n > 2) ){
+               ctl.cmsg(CMSG_WARNING, VERB_NORMAL, "Usage: timidity -iN [Named Pipe Name] SampeTimeMode(1 or 0) \n");
                return 1;
        }
        
        rtsyn_np_set_pipe_name(args[0]);
+       if( n==1 ){
+               rtsyn_sample_time_mode = 0;
+       }else{
+               rtsyn_sample_time_mode = atoi(args[1]);
+       }
 
 #if !defined(IA_W32G_SYN) && !defined(USE_GTK_GUI)
        ctl.cmsg(CMSG_WARNING, VERB_NORMAL, 
                "TiMidity starting in Windows Named Pipe Synthesizer mode\n");
        ctl.cmsg(CMSG_WARNING, VERB_NORMAL, 
-               "Usage: timidity -iN [Named Pipe Name]\n");
+               "Usage: timidity -iN [Named Pipe Name] SampeTimeMode(1 or 0) \n");
        ctl.cmsg(CMSG_WARNING, VERB_NORMAL, "\n");
        ctl.cmsg(CMSG_WARNING, VERB_NORMAL, 
                "N (Normal mode) M(GM mode) S(GS mode) X(XG mode) \n");
@@ -379,7 +383,8 @@ static void doit(void)
                        }
                }
                rtsyn_np_play_some_data();
-               rtsyn_play_calculate();
+               if(rtsyn_sample_time_mode == 0)
+                       rtsyn_play_calculate();
                if(intr) seq_quit=~0;
                sleep(1);
        }
index d959153..cb1f32d 100644 (file)
@@ -100,6 +100,9 @@ extern VOLATILE int intr;
 extern double rtsyn_latency;   /* = RTYSN_LATENCY */
 extern int rtsyn_system_mode;
 
+extern int32 rtsyn_start_sample;
+extern int rtsyn_sample_time_mode; //bool 1 ture 0 false
+
 /* reset synth    */
 void rtsyn_gm_reset(void);
 void rtsyn_gs_reset(void);
@@ -118,6 +121,7 @@ void rtsyn_close(void);
 double rtsyn_set_latency(double latency);
 void rtsyn_play_event(MidiEvent *ev);
 void rtsyn_play_event_time(MidiEvent *ev, double event_time);
+void rtsyn_tmr_reset(void);
 void rtsyn_server_reset(void);
 void rtsyn_reset(void);
 void rtsyn_stop_playing(void);
@@ -155,6 +159,7 @@ int rtsyn_buf_check(void);
 #ifdef IA_NPSYN
 #define RTSYN_NP_DATA 1
 #define RTSYN_NP_LONGDATA 2
+
 typedef struct rtsyn_np_evbuf_t{
        uint32 wMsg;
        union {
index e8398ec..125c022 100644 (file)
@@ -79,10 +79,11 @@ extern void reset_midi(int playing);
 
 int rtsyn_system_mode = DEFAULT_SYSTEM_MODE;
 double rtsyn_latency = RTSYN_LATENCY;   //ratency (sec)
+int32 rtsyn_start_sample;
+int rtsyn_sample_time_mode = 0;
 
 static int rtsyn_played = 0;
 static double rtsyn_start_time;
-static int32 rtsyn_start_sample;
 static double last_event_time;
 static double last_calc_time;
 static int set_time_first=2;
@@ -229,7 +230,8 @@ void rtsyn_init(void){
        auto_reduce_polyphony = 0;
        opt_sf_close_each_file = 0;
        
-       aq_set_soft_queue(rtsyn_latency*(double)1.01, 0.0);
+       if(ctl->id_character != 'N')
+         aq_set_soft_queue(rtsyn_latency*(double)1.01, 0.0);
        i = current_keysig + ((current_keysig < 8) ? 7 : -9), j = 0;
        while (i != 7)
                i += (i < 7) ? 5 : -7, j++;
@@ -249,6 +251,13 @@ void rtsyn_close(void){
        free_global_mblock();
 }
 
+rtsyn_play_event_sample(MidiEvent *ev, int32 event_sample_time){
+       ev->time=event_sample_time;
+       play_event(ev);
+       if(rtsyn_sample_time_mode != 1)
+         aq_fill_nonblocking();
+}
+
 void rtsyn_play_event_time(MidiEvent *ev, double event_time){
        int gch;
        double current_event_time, buf_time;
@@ -296,12 +305,7 @@ void rtsyn_play_event(MidiEvent *ev){
        rtsyn_play_event_time(ev, get_current_calender_time());
 }
 
-
-void rtsyn_reset(void){
-               rtsyn_server_reset();
-}
-
-void rtsyn_server_reset(void){
+void rtsyn_wot_reset(void){
        int i;
        kill_all_voices();
        if (free_instruments_afterwards){
@@ -318,11 +322,27 @@ void rtsyn_server_reset(void){
        reset_midi(1);
        reduce_voice_threshold = 0; // * Disable auto reduction voice *
        auto_reduce_polyphony = 0;
-       
-       rtsyn_start_time=get_current_calender_time();
-       rtsyn_start_sample=current_sample;
-       last_event_time=rtsyn_start_time + rtsyn_latency;
-       last_calc_time  = rtsyn_start_time;
+}
+
+void rtsyn_tmr_reset(void){
+       if(ctl->id_character == 'N')
+               current_sample = 0;     
+               rtsyn_start_time=get_current_calender_time();
+               rtsyn_start_sample=current_sample;
+               last_event_time=rtsyn_start_time + rtsyn_latency;
+               last_calc_time  = rtsyn_start_time;
+}
+
+void rtsyn_reset(void){
+       rtsyn_wot_reset();
+       rtsyn_tmr_reset();
+}
+
+void rtsyn_server_reset(void){
+       rtsyn_wot_reset();
+       if(rtsyn_sample_time_mode !=1){
+               rtsyn_tmr_reset();
+       }
 }
 
 void rtsyn_stop_playing(void)
@@ -379,8 +399,10 @@ void rtsyn_play_calculate(){
        
 int rtsyn_play_one_data (int port, int32 dwParam1, double event_time){
        MidiEvent ev;
-
-       event_time = event_time + rtsyn_latency;
+       
+       if(rtsyn_sample_time_mode != 1){
+               event_time += rtsyn_latency;
+       }
        ev.type = ME_NONE;
        ev.channel = dwParam1 & 0x0000000f;
        ev.channel = ev.channel+port*16;
@@ -432,9 +454,19 @@ int rtsyn_play_one_data (int port, int32 dwParam1, double event_time){
                        printf("MIDI Time Code Qtr\n");
                if ((dwParam1 & 0x000000ff) == 0xf3)
                        //Song Select(Song #) (not need)
-               if ((dwParam1 & 0x000000ff) == 0xf6)
-                       //Tune request (not need)
-                       printf("Tune request\n");
+#endif
+               if ((dwParam1 & 0x000000ff) == 0xf6){
+                       //Tune request  but use to make TiMidity++  to calculate.
+                       if(rtsyn_sample_time_mode == 1){
+                               ev.type = ME_NONE;
+                               rtsyn_play_event_sample(&ev, event_time);
+                               aq_fill_nonblocking();
+                               //aq_soft_flush();
+                       }else{
+                               //printf("Tune request\n");
+                       }
+               }
+#if 0
                if ((dwParam1 & 0x000000ff) == 0xf8)
                        //Timing Clock (not need)
                        printf("Timing Clock\n");
@@ -454,8 +486,12 @@ int rtsyn_play_one_data (int port, int32 dwParam1, double event_time){
                        active_sensing_time = get_current_calender_time();
                }
                if ((dwParam1 & 0x000000ff) == 0xff) {
-                       //System Reset
-                       printf("System Reset\n");
+                       //System Reset  use for TiMidity++  timer  reset
+                       if(rtsyn_sample_time_mode == 1){
+                               rtsyn_tmr_reset();
+                       }else{
+                               //printf("System Reset\n");
+                       }
                }
                break;
        default:
@@ -463,7 +499,11 @@ int rtsyn_play_one_data (int port, int32 dwParam1, double event_time){
                break;
        }
        if (ev.type != ME_NONE) {
-               rtsyn_play_event_time(&ev, event_time);
+               if(rtsyn_sample_time_mode != 1){
+                               rtsyn_play_event_time(&ev, event_time);
+               }else{
+                               rtsyn_play_event_sample(&ev, event_time);
+               }
        }
        return 0;
 }
@@ -474,7 +514,9 @@ void rtsyn_play_one_sysex (char *sysexbuffer, int exlen, double event_time ){
        MidiEvent ev;
        MidiEvent evm[260];
        
-       event_time = event_time + rtsyn_latency;
+       if(rtsyn_sample_time_mode != 1){
+               event_time += rtsyn_latency;
+       }
 
        if( (sysexbuffer[0] != '\xf0') && (sysexbuffer[0] != '\xf7') ) return ;
 
@@ -508,14 +550,26 @@ void rtsyn_play_one_sysex (char *sysexbuffer, int exlen, double event_time ){
                if(ev.type==ME_RESET && rtsyn_system_mode!=DEFAULT_SYSTEM_MODE){
                        ev.a=rtsyn_system_mode;
                        change_system_mode(rtsyn_system_mode);
-                       rtsyn_play_event_time(&ev, event_time);
+                       if(rtsyn_sample_time_mode != 1){
+                               rtsyn_play_event_time(&ev, event_time);
+                       }else{
+                               rtsyn_play_event_sample(&ev, event_time);
+                       }
                }else{
-                       rtsyn_play_event_time(&ev, event_time);
+                       if(rtsyn_sample_time_mode != 1){
+                               rtsyn_play_event_time(&ev, event_time);
+                       }else{
+                               rtsyn_play_event_sample(&ev, event_time);
+                       }
                }
        }
        if(ne=parse_sysex_event_multi(sysexbuffer+1,exlen-1, evm)){
                for (i = 0; i < ne; i++){
-                       rtsyn_play_event_time(&evm[i], event_time);
+                       if(rtsyn_sample_time_mode != 1){
+                               rtsyn_play_event_time(&(evm[i]), event_time);
+                       }else{
+                               rtsyn_play_event_sample(&(evm[i]), event_time);
+                       }
                }
        }
        
index 98e436b..d415792 100755 (executable)
@@ -221,23 +221,35 @@ int rtsyn_np_play_some_data(void)
                        exlen = evbuf[evbpoint].exlen;
                        sysexbuffer = evbuf[evbpoint].exbuffer;                 
                        LeaveCriticalSection(&mim_np_section);
-                       if((first_ev == 1)  || ( pre_time > dwParam2)){
-                               pre_time=dwParam2;
-                               timeoffset=dwParam2;
-                               mim_start_time = get_current_calender_time();
-                               first_ev=0;
-                       }
-                       if(dwParam2 !=0){
-                            event_time= mim_start_time+((double)(dwParam2-timeoffset))*(double)1.0/(double)1000.0;
-                       }else{
-                               event_time = get_current_calender_time();
+                       
+                       if(rtsyn_sample_time_mode !=1){
+                               if((first_ev == 1)  || ( pre_time > dwParam2)){
+                                       pre_time=dwParam2;
+                                       timeoffset=dwParam2;
+                                       mim_start_time = get_current_calender_time();
+                                       first_ev=0;
+                               }
+                               if(dwParam2 !=0){
+                                event_time= mim_start_time+((double)(dwParam2-timeoffset))*(double)1.0/(double)1000.0;
+                               }else{
+                                       event_time = get_current_calender_time();
+                               }
                        }
+                       
                        switch (wMsg) {
                        case RTSYN_NP_DATA:
-                               rtsyn_play_one_data (port, dwParam1, event_time);
+                               if(rtsyn_sample_time_mode !=1){
+                                       rtsyn_play_one_data(port, dwParam1, event_time);
+                               }else{
+                                       rtsyn_play_one_data(port, dwParam1, dwParam2);
+                               }
                                break;
                        case RTSYN_NP_LONGDATA:
-                               rtsyn_play_one_sysex (sysexbuffer,exlen, event_time);
+                               if(rtsyn_sample_time_mode !=1){
+                                       rtsyn_play_one_sysex(sysexbuffer,exlen, event_time);
+                               }else{
+                                       rtsyn_play_one_sysex(sysexbuffer,exlen, dwParam2);
+                               }
                                free(sysexbuffer);
                                break;
                        }
@@ -298,6 +310,7 @@ static void parse_ev(char* buffer, int *len){
                        exlen=npevbuf->exlen;
                        bp = sp+sizeof(RtsynNpEvBuf);
                        
+                       dwParam2=npevbuf->dwParam2;
                    if (*len >= sizeof(RtsynNpEvBuf)+exlen){
                                exbuffer= (char *)malloc( sizeof(char) * exlen);
                                memmove(exbuffer,sp+sizeof(RtsynNpEvBuf), exlen);
@@ -340,7 +353,7 @@ static int read_pipe_data()
        
        if( hPipe == NULL ) return -1;
        
-//     if ( ( 0 == PeekNamedPipe(hPipe,NULL,0,NULL,&length,NULL)) &&\r
+//     if ( ( 0 == PeekNamedPipe(hPipe,NULL,0,NULL,&length,NULL)) &&
 //              (GetLastError()==ERROR_BAD_PIPE) )  return -1;
        if ( 0 == PeekNamedPipe(hPipe,NULL,0,NULL,&length,NULL))  return -1;
        if(length == 0) return -1;
@@ -351,11 +364,13 @@ static int read_pipe_data()
        npipe_len=0;   // not good fix
        memset(npipe_buffer+npipe_len, 0, PIPE_BUFFER_SIZE-npipe_len);
        if(length <=  PIPE_BUFFER_SIZE - npipe_len){
-               ReadFile(hPipe, npipe_buffer+npipe_len,length, &n, &overlapped);
-               last_error = GetLastError();
-               if(last_error == ERROR_IO_PENDING){
-                       GetOverlappedResult(hPipe, &overlapped,&n,TRUE) ;
+               if( length > 0 ){
+                       ReadFile(hPipe, npipe_buffer+npipe_len,length, &n, &overlapped);
                        last_error = GetLastError();
+                       if(last_error == ERROR_IO_PENDING){
+                               GetOverlappedResult(hPipe, &overlapped,&n,TRUE) ;
+                               last_error = GetLastError();
+                       }
                }
        }else{
                ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Named Pipe buffer overlow");
index 77f389d..156f335 100755 (executable)
@@ -67,6 +67,8 @@
 //#define PIPE_BUFFER_SIZE (AUDIO_BUFFER_SIZE * 8)
 #define PIPE_BUFFER_SIZE (88200)
 static HANDLE hPipe=NULL;
+  OVERLAPPED pipe_ovlpd;
+  HANDLE hPipeEvent;
 static volatile int pipe_close=-1;
 static volatile int clear_pipe=-1;
 
@@ -81,7 +83,7 @@ static int acntl(int request, void *arg);
 
 PlayMode dpm = {
     DEFAULT_RATE,
-       PE_16BIT|PE_SIGNED, PF_PCM_STREAM,
+       PE_16BIT|PE_SIGNED, PF_PCM_STREAM|PF_CAN_TRACE,
     -1,
     {0,0,0,0,0},
     "Windows Named Pipe", 'N',
@@ -96,9 +98,7 @@ PlayMode dpm = {
 
 static int npipe_output_open(const char *pipe_name)
 {
-  char PipeName[256];
-  OVERLAPPED pipe_ovlpd;
-  HANDLE hPipeEvent;  
+  char PipeName[256];  
   DWORD ret;
   DWORD n;
   int i;
@@ -124,11 +124,11 @@ static int npipe_output_open(const char *pipe_name)
     ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "CnnectNamePipe(%ld) error %s",
        GetLastError(), pipe_name);
         CloseHandle(hPipe);
-           hPipe=NULL;\r
-        return -1;\r
+           hPipe=NULL;
+        return -1;
    }
 //     WaitForSingleObject(pipe_ovlpd.hPipeEvent, 1000);
-       CloseHandle(hPipeEvent);
+
        return 0;
 }
 
@@ -145,6 +145,7 @@ static int open_output(void)
                        return -1;
   }
   dpm.fd = 1;
+//  clear_pipe = 0;
   return 0;
 }
 
@@ -155,9 +156,10 @@ static int output_data(char *buf, int32 bytes)
        int32 retnum;
        retnum = bytes;
        DWORD length;
-       
+       char *clear_data;
+               
        if (hPipe == NULL) return -1;
-       if ( ( 0 == PeekNamedPipe(hPipe,NULL,0,NULL,&length,NULL)) &&\r
+       if ( ( 0 == PeekNamedPipe(hPipe,NULL,0,NULL,&length,NULL)) &&
                 (GetLastError()==ERROR_BAD_PIPE) )  return -1;
        if(dpm.fd == -1) return -1;
        if (pipe_close = 0){
@@ -167,29 +169,49 @@ static int output_data(char *buf, int32 bytes)
        }
        
        if (0 != PeekNamedPipe(hPipe,NULL,0,NULL,&length,NULL)){
-               if( (bytes <= PIPE_BUFFER_SIZE-length) && (clear_pipe == -1) ){
-                       ret=WriteFile(hPipe,buf,bytes,&n,NULL);
-                       if( (GetLastError() != ERROR_SUCCESS) &&
-                               (GetLastError() != ERROR_BAD_PIPE) ){      //why BAD_PIPE occurs here?
-                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "npipe_a_error %s: %ld",
+               if(clear_pipe == -1){
+                       if(bytes <= PIPE_BUFFER_SIZE-length){
+                               ret=WriteFile(hPipe,buf,bytes,&n,&pipe_ovlpd);
+                               if( (GetLastError() != ERROR_SUCCESS) &&
+                                       (GetLastError() != ERROR_IO_PENDING) &&
+                                       (GetLastError() != ERROR_BAD_PIPE) ){      //why BAD_PIPE occurs here?
+                               ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "npipe_a_error %s: %ld",
                                dpm.name, GetLastError());
-                               if(hPipe != NULL) CloseHandle(hPipe);
-                               hPipe=NULL;
-                               dpm.fd = -1;
-                                       
-                               return -1;
-               }
+                                       if(hPipe != NULL) CloseHandle(hPipe);
+                                       hPipe=NULL;
+                                       dpm.fd = -1;                                    
+                                       return -1;
+                               }
+                       }else{
+                               ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "npipe_a_errror overflow");
+                       }
                }else{
-                       clear_pipe= -1 ;
+                       if(length < audio_buffer_size){
+                               clear_data = (char*)safe_malloc(audio_buffer_size-length);
+                               memset(clear_data, 0, audio_buffer_size-length);
+                               WriteFile(hPipe,clear_data,audio_buffer_size-length,&n,&pipe_ovlpd);
+                               free(clear_data);
+                               if( (GetLastError() != ERROR_SUCCESS) &&
+                                       (GetLastError() != ERROR_IO_PENDING) &&
+                                       (GetLastError() != ERROR_BAD_PIPE) ){      //why BAD_PIPE occurs here?
+                               ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "npipe_a_error %s: %ld",
+                               dpm.name, GetLastError());
+                                       if(hPipe != NULL) CloseHandle(hPipe);
+                                       hPipe=NULL;
+                                       dpm.fd = -1;
+                                       return -1;
+                               }
+                               clear_pipe =-1;
+                       }
                }
        }
-
        return retnum;
 }
 
 static void close_output(void)
 {
        if(dpm.fd != -1){
+               CloseHandle(hPipeEvent);
                CloseHandle(hPipe);
                hPipe=NULL;
        dpm.fd = -1;
@@ -205,7 +227,7 @@ static int acntl(int request, void *arg)
     return 0;
   case PM_REQ_DISCARD:
   case PM_REQ_FLUSH:
-               clear_pipe=0;
+//             clear_pipe=0;
        return 0;
 
   }
index 96f9fbd..884f7d6 100644 (file)
@@ -8854,7 +8854,8 @@ void playmidi_tmr_reset(void)
     int i;
 
     aq_flush(0);
-    current_sample = 0;
+    if(ctl->id_character != 'N')
+        current_sample = 0;
     buffered_count = 0;
     buffer_pointer = common_buffer;
     for(i = 0; i < MAX_CHANNELS; i++)
index be2bc17..4dfc9b4 100644 (file)
@@ -196,22 +196,28 @@ int paCallback(  void *inputBuffer, void *outputBuffer,
 
 /* Cast data passed through stream to our structure type. */
 //    pa_data_t pa_data = (pa_data_t*)userData;
+       
+       int32 samplesToGo;
+       char *bufpoint;
     char *out = (char*)outputBuffer;
        unsigned long datalength = framesPerBuffer*data_nbyte*stereo;
        char * buflimit = pa_data.buf+bytesPerInBuffer*2;
        
+       samplesToGo=pa_data.samplesToGo;
+       bufpoint=pa_data.bufpoint;
+       
        if(conv16_32){
-               if(pa_data.samplesToGo < datalength  ){         
-                       for(i=0;i<pa_data.samplesToGo/2;i++){
+               if(samplesToGo < datalength  ){         
+                       for(i=0;i<samplesToGo/2;i++){
                                *out++ = 0;
                                *out++ = 0;
-                               *out++ = *(pa_data.bufpoint)++;
-                               *out++ = *(pa_data.bufpoint)++;
-                               if( buflimit <= pa_data.bufpoint ){
-                                       pa_data.bufpoint=pa_data.buf;
+                               *out++ = *(bufpoint)++;
+                               *out++ = *(bufpoint)++;
+                               if( buflimit <= bufpoint ){
+                                       bufpoint=pa_data.buf;
                                }
                        }
-                       pa_data.samplesToGo=0;
+                       samplesToGo=0;
                        for(;i<datalength/2;i++){
                                *out++ = 0;
                                *out++ = 0;
@@ -223,47 +229,49 @@ int paCallback(  void *inputBuffer, void *outputBuffer,
                        for(i=0;i<datalength/2;i++){
                                *out++ = 0;
                                *out++ = 0;
-                               *out++=*(pa_data.bufpoint)++;
-                               *out++=*(pa_data.bufpoint)++;
-                               if( buflimit <= pa_data.bufpoint ){
-                                       pa_data.bufpoint=pa_data.buf;
+                               *out++=*(bufpoint)++;
+                               *out++=*(bufpoint)++;
+                               if( buflimit <= bufpoint ){
+                                       bufpoint=pa_data.buf;
                                }
                        }
-                       pa_data.samplesToGo -= datalength;
+                       samplesToGo -= datalength;
                }
        }else{
-               if(pa_data.samplesToGo < datalength  ){
-                       if(pa_data.bufpoint+pa_data.samplesToGo <= buflimit){
-                               memcpy(out, pa_data.bufpoint, pa_data.samplesToGo);
-                               pa_data.bufpoint += pa_data.samplesToGo;
+               if(samplesToGo < datalength  ){
+                       if(bufpoint+samplesToGo <= buflimit){
+                               memcpy(out, bufpoint, samplesToGo);
+                               bufpoint += samplesToGo;
                        }else{
                                int32 send;
-                               send = buflimit-pa_data.bufpoint;
-                               if (send !=0) memcpy(out, pa_data.bufpoint, send);
+                               send = buflimit-bufpoint;
+                               if (send !=0) memcpy(out, bufpoint, send);
                                out +=send;
-                               memcpy(out, pa_data.buf, pa_data.samplesToGo -send);
-                               pa_data.bufpoint = pa_data.buf+pa_data.samplesToGo -send;
-                               out += pa_data.samplesToGo -send;
+                               memcpy(out, pa_data.buf, samplesToGo -send);
+                               bufpoint = pa_data.buf+samplesToGo -send;
+                               out += samplesToGo -send;
                        }
-                       memset(out, 0x0, datalength-pa_data.samplesToGo);
-                       pa_data.samplesToGo=0;
+                       memset(out, 0x0, datalength-samplesToGo);
+                       samplesToGo=0;
                        finished = 0;
                }else{
-                       if(pa_data.bufpoint + datalength <= buflimit){
-                               memcpy(out, pa_data.bufpoint, datalength);
-                               pa_data.bufpoint += datalength;
+                       if(bufpoint + datalength <= buflimit){
+                               memcpy(out, bufpoint, datalength);
+                               bufpoint += datalength;
                        }else{
                                int32 send;
-                               send = buflimit-pa_data.bufpoint;
-                               if (send !=0) memcpy(out, pa_data.bufpoint, send);
+                               send = buflimit-bufpoint;
+                               if (send !=0) memcpy(out, bufpoint, send);
                                out += send;
                                memcpy(out, pa_data.buf, datalength -send);
-                               pa_data.bufpoint = pa_data.buf+datalength -send;
+                               bufpoint = pa_data.buf+datalength -send;
                        }
-                       pa_data.samplesToGo -= datalength;
+                       samplesToGo -= datalength;
                }
        }
-    return finished ;
+       pa_data.samplesToGo=samplesToGo;
+       pa_data.bufpoint=bufpoint;
+       return finished ;
 
 }
 
@@ -517,6 +525,8 @@ error2:
 static int output_data(char *buf, int32 nbytes)
 {
        unsigned int i;
+       int32 samplesToGo;
+       char *bufepoint;
 
     if(pa_active == 0) return -1; 
        
@@ -525,19 +535,25 @@ static int output_data(char *buf, int32 nbytes)
 //     if(pa_data.samplesToGo > DATA_BLOCK_SIZE){ 
 //             Sleep(  (pa_data.samplesToGo - DATA_BLOCK_SIZE)/dpm.rate/4  );
 //     }
-       if (pa_data.buf+bytesPerInBuffer*2 >= pa_data.bufepoint + nbytes){
-               memcpy(pa_data.bufepoint, buf, nbytes);
-               pa_data.bufepoint += nbytes;
+       samplesToGo=pa_data.samplesToGo;
+       bufepoint=pa_data.bufepoint;
+
+       if (pa_data.buf+bytesPerInBuffer*2 >= bufepoint + nbytes){
+               memcpy(bufepoint, buf, nbytes);
+               bufepoint += nbytes;
                //buf += nbytes;
        }else{
-               int32 send = pa_data.buf+bytesPerInBuffer*2 - pa_data.bufepoint;
-               if (send != 0) memcpy(pa_data.bufepoint, buf, send);
+               int32 send = pa_data.buf+bytesPerInBuffer*2 - bufepoint;
+               if (send != 0) memcpy(bufepoint, buf, send);
                buf += send;
                memcpy(pa_data.buf, buf, nbytes - send);
-               pa_data.bufepoint = pa_data.buf + nbytes - send;
+               bufepoint = pa_data.buf + nbytes - send;
                //buf += nbytes-send;
        }
-       pa_data.samplesToGo += nbytes;
+       samplesToGo += nbytes;
+
+       pa_data.samplesToGo=samplesToGo;
+       pa_data.bufepoint=bufepoint;
 
 /*
        if(firsttime==1){
@@ -630,6 +646,8 @@ static int acntl(int request, void *arg)
        pa_data.bufpoint=pa_data.bufepoint;
        err = Pa_AbortStream( stream );
        if( (err!=paStreamIsStopped) && (err!=paNoError) ) goto error;
+       err = Pa_StartStream( stream );
+       if(err!=paNoError) goto error;
                return 0;
 
                //break;
index 5128e20..ee167e7 100644 (file)
@@ -609,12 +609,12 @@ static BOOL WINAPI handler(DWORD dw)
 #endif
 
 
-#if defined(IA_NPSYN)
-       if( ctl->id_character == 'N')
-       {
-               return FALSE;  //why FALSE need?  It must close by intr++;
-       }
-#endif
+//#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;
@@ -5886,7 +5886,13 @@ int main(int argc, char **argv)
        w32g_uninitialize();
        w32g_free_doc();
 #else
+#ifdef IA_NPSYN
+       timeBeginPeriod( 1 );
+#endif 
        main_ret = timidity_play_main(nfiles, files);
+#ifdef IA_NPSYN
+       timeEndPeriod( 1 );
+#endif 
 #ifdef IA_W32G_SYN
        if (CoInitializeOK)
                CoUninitialize();
index 4ab512e..28cbafd 100644 (file)
@@ -67,6 +67,9 @@ double get_current_calender_time(void)
 #include <windows.h>
 #include "timidity.h"
 #include "timer.h"
+#ifdef IA_NPSYN
+#define GetTickCount() timeGetTime()
+#endif 
 double get_current_calender_time(void)
 {
     static DWORD tick_start;