OSDN Git Service

Import UnkoTim212 unkotim212
authorStarg <starg@users.osdn.me>
Thu, 11 Jan 2018 01:02:00 +0000 (10:02 +0900)
committerStarg <starg@users.osdn.me>
Thu, 11 Jan 2018 01:02:00 +0000 (10:02 +0900)
61 files changed:
config.h
interface/npsyn_c.c
interface/portmidisyn_c.c
interface/rtsyn.h
interface/rtsyn_common.c
interface/w32g_ini.c
interface/w32g_pref.c
interface/w32g_res.h
interface/w32g_res.rc
interface/w32g_syn.c
interface/w32g_utl.c
interface/w32g_utl.h
interface/winsyn_c.c
kbtim/_timidity_.c
kbtim/kbtim.h
kbtim/kbtim_dll.cpp
kbtim/kbtim_dll.vcproj
kbtim/kbtim_kpi.vcproj
kbtimsetup/kbtimsetup.c
kbtimsetup/kbtimsetup.vcproj
libarc/libarc.vcxproj
tim_cui/tim_cui.vcproj
tim_cui/tim_cui.vcxproj
timdrvsetup/timdrvsetup.c
timdrvsetup/timdrvsetup.vcproj
timdrvsetup/timdrvsetup.vcxproj
timidity/aq.c
timidity/effect.c
timidity/effect.h
timidity/int_synth.c
timidity/int_synth.h
timidity/miditrace.c
timidity/output.c
timidity/output.h
timidity/playmidi.c
timidity/playmidi.h
timidity/portaudio_a.c
timidity/portaudio_a.h
timidity/thread.c
timidity/thread.h
timidity/timidity.c
timidity/timidity.vcproj
timidity/timidity.vcxproj
timidity/w32_a.c
timidity/w32_a.h
timidity/wasapi_a.c [new file with mode: 0644]
timidity/wasapi_a.h [new file with mode: 0644]
timidity/wdmks_a.c [new file with mode: 0644]
timidity/wdmks_a.h [new file with mode: 0644]
timidity_vs2008.sln
timw32g/timw32g.dsp
timw32g/timw32g.vcproj
timw32g/timw32g.vcxproj
twsyng/twsyng.vcproj
twsyng/twsyng.vcxproj
twsynsrv/twsynsrv.vcproj
twsynsrv/twsynsrv.vcxproj
windrv/timiditydrv.c
windrv/timiwp_timidity.c
windrv/windrv.vcproj
windrv/windrv.vcxproj

index 33aa81c..bca3f97 100644 (file)
--- a/config.h
+++ b/config.h
 #define TIMID_VERSION  "current"
 #define DEFAULT_PATH   ".\\"
 #define AU_W32 1
+#define AU_WASAPI 1
 #define AU_VORBIS 1
 #define AU_VORBIS_DLL 1
 #define VORBIS_DLL_INCLUDE_VORBISENC 1 /* ver 1.3.3 */
 #define DEFAULT_COMPUTE_BUFFER_BITS   6 /* ratio 1.45ms (44.1kHz) */
 #define TIMDRVINI 1 // use timdrv.ini or twsyng32.ini or timpp32g.ini ??
 #define IA_WINSYN
+//#undef AU_WASAPI
 #undef AU_VORBIS
 #undef AU_VORBIS_DLL
 #undef AU_GOGO
 #endif
 
 #ifdef CFG_FOR_SF
+#undef AU_WASAPI
 #undef AU_VORBIS
 #undef AU_VORBIS_DLL
 #undef AU_GOGO
 #define IA_WINSYN
 #define WINDRV 1
 #define AU_W32 1
+#define AU_WASAPI 1
 #undef AU_VORBIS
 #undef AU_VORBIS_DLL
 #undef AU_GOGO
 #undef HAVE_POPEN
 #undef REDUCE_VOICE_TIME_TUNING //playmidi.c \82Ì\90é\8c¾\95\94\82Ì #define \95\94\82ð\8dí\8f\9c\82µ\82È\82¢\82Æ\8b@\94\\82µ\82È\82¢
 #undef AU_W32
+#undef AU_WASAPI
 #undef AU_VORBIS
 #undef AU_VORBIS_DLL
 #undef AU_GOGO
@@ -708,7 +713,8 @@ typedef __int64 int64;
 #define HAVE_MKSTEMP
 #undef HAVE_POPEN
 #undef REDUCE_VOICE_TIME_TUNING //playmidi.c \82Ì\90é\8c¾\95\94\82Ì #define \95\94\82ð\8dí\8f\9c\82µ\82È\82¢\82Æ\8b@\94\\82µ\82È\82¢
-#define AU_W32 1
+#undef AU_W32
+#undef AU_WASAPI
 #undef AU_VORBIS
 #undef AU_VORBIS_DLL
 #undef AU_GOGO
@@ -766,7 +772,8 @@ typedef __int64 int64;
 #undef HAVE_POPEN
 #undef REDUCE_VOICE_TIME_TUNING //playmidi.c \82Ì\90é\8c¾\95\94\82Ì #define \95\94\82ð\8dí\8f\9c\82µ\82È\82¢\82Æ\8b@\94\\82µ\82È\82¢
 #undef AU_BUFFER 1
-#undef AU_W32 1
+#undef AU_W32
+#undef AU_WASAPI
 #undef AU_VORBIS
 #undef AU_VORBIS_DLL
 #undef AU_GOGO
index 54ba715..7c4dc8b 100755 (executable)
@@ -453,7 +453,7 @@ void winplaymidi(void) {
     DWORD ct = GetCurrentTime();
     if (winplaymidi_active_start_time == 0 || ct < winplaymidi_active_start_time) {
       winplaymidi_active_start_time = ct;
-    } else if (ct - winplaymidi_active_start_time > 2000) {
+    } else if (ct - winplaymidi_active_start_time > 60000) {
       winplaymidi_sleep_level = 2;
     }
   } else if (winplaymidi_sleep_level == 0) {
index 5223bb3..e9a4851 100755 (executable)
@@ -488,7 +488,7 @@ void winplaymidi(void){
                DWORD ct = GetCurrentTime ();
                if ( winplaymidi_active_start_time == 0 || ct < winplaymidi_active_start_time ) {
                        winplaymidi_active_start_time = ct;
-               } else if ( ct - winplaymidi_active_start_time > 2000 ) {
+               } else if ( ct - winplaymidi_active_start_time > 60000 ) {
                        winplaymidi_sleep_level = 2;
                }
        } else if ( winplaymidi_sleep_level == 0 ) {
index 08dca9f..a212951 100644 (file)
@@ -129,6 +129,7 @@ void rtsyn_normal_modeset(void);
 void rtsyn_init(void);
 void rtsyn_close(void);
 double rtsyn_set_latency(double latency);
+void rtsyn_set_skip_aq(int flg);
 void rtsyn_play_event(MidiEvent *ev);
 void rtsyn_play_event_time(MidiEvent *ev, double event_time);
 void rtsyn_tmr_reset(void);
index 7a2a224..6156a7a 100644 (file)
@@ -81,13 +81,14 @@ int rtsyn_system_mode = DEFAULT_SYSTEM_MODE;
 double rtsyn_latency = RTSYN_LATENCY;   //ratency (sec)
 int32 rtsyn_start_sample;
 int rtsyn_sample_time_mode = 0;
+int rtsyn_skip_aq = 0;
+double max_compute = RTSYN_LATENCY;    // play_event() \82Ì compute_data() \82Å\8cv\8eZ\82ð\8b\96\82·\8dÅ\91å\8e\9e\8aÔ
 
 static int rtsyn_played = 0;
 static double rtsyn_start_time;
 static double last_event_time;
 static double last_calc_time;
 static int set_time_first=2;
-extern int volatile stream_max_compute;        // play_event() \82Ì compute_data() \82Å\8cv\8eZ\82ð\8b\96\82·\8dÅ\91å\8e\9e\8aÔ
 
 //acitive sensing
 static int active_sensing_flag=0;
@@ -323,6 +324,11 @@ double rtsyn_set_latency(double latency){
        return latency;
 }
 
+void rtsyn_set_skip_aq(int flg)
+{
+       rtsyn_skip_aq = flg ? 1 : 0;
+}
+
 void rtsyn_init(void){
        int i,j;
        MidiEvent ev;
@@ -339,7 +345,12 @@ void rtsyn_init(void){
                          play_mode->extra_param[1]);
        }       
        if(ctl->id_character != 'N')
-         aq_set_soft_queue(rtsyn_latency*(double)1.01, 0.0);
+               if(rtsyn_skip_aq) // c212 add
+                 aq_set_soft_queue(0.0, 0.0); // skip audio queue
+               else
+                 aq_set_soft_queue(rtsyn_latency, 0.0);
+       max_compute = (double)stream_max_compute * DIV_1000; //rtsyn_latency * 1000.0;
+       max_compute = (rtsyn_latency > max_compute) ? rtsyn_latency : max_compute;
        i = current_keysig + ((current_keysig < 8) ? 7 : -9), j = 0;
        while (i != 7)
                i += (i < 7) ? 5 : -7, j++;
@@ -355,13 +366,16 @@ void rtsyn_init(void){
        
        if(play_mode && play_mode->open_output)
          play_mode->open_output();
+       
+       aq_setup();
+       
        if(play_mode && play_mode->acntl)
          play_mode->acntl(PM_REQ_PLAY_START, NULL);
        
-       aq_setup();
        rtsyn_reset();
        rtsyn_system_mode=DEFAULT_SYSTEM_MODE;
        change_system_mode(rtsyn_system_mode);
+
        reset_midi(0);
 }
 
@@ -384,43 +398,40 @@ void rtsyn_play_event_sample(MidiEvent *ev, int32 event_sample_time){
 void rtsyn_play_event_time(MidiEvent *ev, double event_time){
        int gch;
        double current_event_time, buf_time;
-       int32 max_compute;
        MidiEvent nev;
 
-               max_compute = rtsyn_latency * 1000.0;
-               max_compute = (stream_max_compute > max_compute) ? stream_max_compute : max_compute;
-               if ( (event_time - last_event_time) > (double)max_compute * DIV_1000){
-                               kill_all_voices();
-                               current_sample = (double)(play_mode->rate) * get_current_calender_time()+0.5;
-                               rtsyn_start_time=get_current_calender_time();
-                               rtsyn_start_sample=current_sample;
-                               last_event_time=rtsyn_start_time;
-               }else{
-                               nev.type = ME_NONE;
-                       if( (event_time - last_event_time) > 1.0/(double)TICKTIME_HZ ) {
-                               buf_time = last_event_time + 1.0/(double)TICKTIME_HZ;
+       if ( (event_time - last_event_time) > max_compute){
+                       kill_all_voices();
+                       current_sample = (double)(play_mode->rate) * get_current_calender_time()+0.5;
+                       rtsyn_start_time=get_current_calender_time();
+                       rtsyn_start_sample=current_sample;
+                       last_event_time=rtsyn_start_time;
+       }else{
+                       nev.type = ME_NONE;
+               if( (event_time - last_event_time) > 1.0/(double)TICKTIME_HZ ) {
+                       buf_time = last_event_time + 1.0/(double)TICKTIME_HZ;
+                       rtsyn_seq_set_time(&nev, buf_time);
+                       play_event(&nev);
+                       aq_fill_nonblocking();
+                               
+                       while( event_time > buf_time + 1.0/(double)TICKTIME_HZ){
+                               buf_time = buf_time + 1.0/(double)TICKTIME_HZ;
                                rtsyn_seq_set_time(&nev, buf_time);
                                play_event(&nev);
                                aq_fill_nonblocking();
-                               
-                               while( event_time > buf_time + 1.0/(double)TICKTIME_HZ){
-                                       buf_time = buf_time + 1.0/(double)TICKTIME_HZ;
-                                       rtsyn_seq_set_time(&nev, buf_time);
-                                       play_event(&nev);
-                                       aq_fill_nonblocking();
-                               }
                        }
-                               gch = GLOBAL_CHANNEL_EVENT_TYPE(ev->type);
-                               if(gch || !IS_SET_CHANNELMASK(quietchannels, ev->channel) ){
-                                       rtsyn_seq_set_time(ev,event_time);
-                                       play_event(ev);
-                                       aq_fill_nonblocking();
-                                       last_event_time = (event_time  > last_event_time) ? event_time : last_event_time ;
-                               }
+               }
+                       gch = GLOBAL_CHANNEL_EVENT_TYPE(ev->type);
+                       if(gch || !IS_SET_CHANNELMASK(quietchannels, ev->channel) ){
+                               rtsyn_seq_set_time(ev,event_time);
+                               play_event(ev);
+                               aq_fill_nonblocking();
+                               last_event_time = (event_time  > last_event_time) ? event_time : last_event_time ;
                        }
+               }
 //             }
 //             }
-               rtsyn_played = 1;
+       rtsyn_played = 1;
 
 
 }
index eb274e7..5907d51 100644 (file)
@@ -470,6 +470,16 @@ void LoadIniFile(SETTING_PLAYER *sp,  SETTING_TIMIDITY *st)
     IniGetKeyInt32(INI_SEC_TIMIDITY,"wmme_device_id",&st->wmme_device_id);
     IniGetKeyInt(INI_SEC_TIMIDITY,"wave_format_ext",&st->wave_format_ext);
 #endif
+#ifdef AU_WASAPI
+    IniGetKeyInt32(INI_SEC_TIMIDITY,"opt_wasapi_device_id",&st->wasapi_device_id);
+       IniGetKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_latency",&st->wasapi_latency);
+       IniGetKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_format_ext",&st->wasapi_format_ext);
+       IniGetKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_exclusive",&st->wasapi_exclusive);
+       IniGetKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_polling",&st->wasapi_polling);
+       IniGetKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_priority",&st->wasapi_priority);
+    IniGetKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_stream_category",&st->wasapi_stream_category);
+       IniGetKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_stream_option",&st->wasapi_stream_option);
+#endif
 #ifdef AU_PORTAUDIO
     IniGetKeyInt32(INI_SEC_TIMIDITY,"pa_wmme_device_id",&st->pa_wmme_device_id);
        IniGetKeyInt32(INI_SEC_TIMIDITY,"pa_ds_device_id",&st->pa_ds_device_id);
@@ -505,8 +515,9 @@ void LoadIniFile(SETTING_PLAYER *sp,  SETTING_TIMIDITY *st)
     IniGetKeyInt(INI_SEC_TIMIDITY,"SynShTime",&(st->SynShTime));
                if ( st->SynShTime < 0 ) st->SynShTime = 0;
     IniGetKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_latency",&(st->opt_rtsyn_latency));
-    if ( st->opt_rtsyn_latency < 20 ) st->opt_rtsyn_latency = 20;
+    if ( st->opt_rtsyn_latency < 1 ) st->opt_rtsyn_latency = 1;
     if ( st->opt_rtsyn_latency > 1000 ) st->opt_rtsyn_latency = 1000;  
+    IniGetKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_skip_aq",&(st->opt_rtsyn_skip_aq));       
 #elif defined(IA_W32G_SYN)
     IniGetKeyIntArray(INI_SEC_TIMIDITY,"SynIDPort",st->SynIDPort,MAX_PORT);
     IniGetKeyInt(INI_SEC_TIMIDITY,"syn_AutoStart",&(st->syn_AutoStart));
@@ -516,8 +527,9 @@ void LoadIniFile(SETTING_PLAYER *sp,  SETTING_TIMIDITY *st)
     IniGetKeyInt(INI_SEC_TIMIDITY,"SynShTime",&(st->SynShTime));
                if ( st->SynShTime < 0 ) st->SynShTime = 0;
     IniGetKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_latency",&(st->opt_rtsyn_latency));
-    if ( st->opt_rtsyn_latency < 20 ) st->opt_rtsyn_latency = 20;
+    if ( st->opt_rtsyn_latency < 1 ) st->opt_rtsyn_latency = 1;
     if ( st->opt_rtsyn_latency > 1000 ) st->opt_rtsyn_latency = 1000;
+    IniGetKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_skip_aq",&(st->opt_rtsyn_skip_aq));       
 #else
     IniGetKeyInt(INI_SEC_TIMIDITY,"processPriority",&(st->processPriority));
 #endif
@@ -696,6 +708,16 @@ SaveIniFile(SETTING_PLAYER *sp,  SETTING_TIMIDITY *st)
     IniPutKeyInt32(INI_SEC_TIMIDITY,"wmme_device_id",&st->wmme_device_id);
        IniPutKeyInt(INI_SEC_TIMIDITY,"wave_format_ext",&st->wave_format_ext);
 #endif
+#ifdef AU_WASAPI
+    IniPutKeyInt32(INI_SEC_TIMIDITY,"opt_wasapi_device_id",&st->wasapi_device_id);
+       IniPutKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_latency",&st->wasapi_latency);
+       IniPutKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_format_ext",&st->wasapi_format_ext);
+       IniPutKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_exclusive",&st->wasapi_exclusive);
+       IniPutKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_polling",&st->wasapi_polling);
+       IniPutKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_priority",&st->wasapi_priority);
+    IniPutKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_stream_category",&st->wasapi_stream_category);
+       IniPutKeyInt(INI_SEC_TIMIDITY,"opt_wasapi_stream_option",&st->wasapi_stream_option);
+#endif
 #ifdef AU_PORTAUDIO
     IniPutKeyInt32(INI_SEC_TIMIDITY,"pa_wmme_device_id",&st->pa_wmme_device_id);
     IniPutKeyInt32(INI_SEC_TIMIDITY,"pa_ds_device_id",&st->pa_ds_device_id);
@@ -733,6 +755,7 @@ SaveIniFile(SETTING_PLAYER *sp,  SETTING_TIMIDITY *st)
     IniPutKeyInt(INI_SEC_TIMIDITY,"syn_ThreadPriority",&(st->syn_ThreadPriority));     
     IniPutKeyInt(INI_SEC_TIMIDITY,"SynShTime",&(st->SynShTime));
     IniPutKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_latency",&(st->opt_rtsyn_latency));       
+    IniPutKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_skip_aq",&(st->opt_rtsyn_skip_aq));       
 #elif defined(IA_W32G_SYN)
     IniPutKeyIntArray(INI_SEC_TIMIDITY,"SynIDPort",st->SynIDPort,MAX_PORT);
     IniPutKeyInt(INI_SEC_TIMIDITY,"syn_AutoStart",&(st->syn_AutoStart));
@@ -741,6 +764,7 @@ SaveIniFile(SETTING_PLAYER *sp,  SETTING_TIMIDITY *st)
     IniPutKeyInt(INI_SEC_TIMIDITY,"SynPortNum",&(st->SynPortNum));
     IniPutKeyInt(INI_SEC_TIMIDITY,"SynShTime",&(st->SynShTime));
     IniPutKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_latency",&(st->opt_rtsyn_latency));       
+    IniPutKeyInt(INI_SEC_TIMIDITY,"opt_rtsyn_skip_aq",&(st->opt_rtsyn_skip_aq));       
 #else
     IniPutKeyInt(INI_SEC_TIMIDITY,"processPriority",&(st->processPriority));
 #endif
index 07d0b92..135c87f 100644 (file)
@@ -75,6 +75,9 @@
 #ifdef AU_W32
 #include "w32_a.h"
 #endif
+#ifdef AU_WASAPI
+#include "wasapi_a.h"
+#endif
 #ifdef AU_PORTAUDIO
 #include "portaudio_a.h"
 #ifdef AU_PORTAUDIO_DLL
@@ -179,6 +182,11 @@ double GetDlgItemFloat(HWND hwnd, UINT id);
 void wmmeConfigDialog(HWND hwnd);
 #endif
 
+#ifdef AU_WASAPI
+void wasapiConfigDialog(void);
+#endif
+
+
 #ifdef IA_W32G_SYN 
 static TCHAR **GetMidiINDrivers( void );
 #endif
@@ -385,7 +393,7 @@ extern int RestartTimidity;
 
 void PrefWndCreate(HWND hwnd, UINT cid)
 {
-    UINT page = PrefSearchPageFromCID(cid);
+    UINT page = cid ? PrefSearchPageFromCID(cid) : PrefInitialPage;
 
     VOLATILE_TOUCH(PrefWndDoing);
     if (PrefWndDoing)
@@ -434,6 +442,10 @@ LRESULT APIENTRY CALLBACK PrefWndDialogProc(HWND hwnd, UINT uMess, WPARAM wParam
        switch (uMess){
        case WM_INITDIALOG:
        {
+               int page = PrefInitialPage;
+               if (page < 0 || page > PREF_PAGE_MAX) {
+                       page = 0; // default
+               }
                hPrefWnd = hwnd;
                // main
 #if defined(IA_W32G_SYN) || defined(IA_W32GUI)
@@ -460,10 +472,10 @@ LRESULT APIENTRY CALLBACK PrefWndDialogProc(HWND hwnd, UINT uMess, WPARAM wParam
 #endif
                // table
                PrefWndCreateTabItems(hwnd);
-               PrefWndCreatePage(hwnd, 0);
+               PrefWndCreatePage(hwnd, page);
                SetForegroundWindow(hwnd);
-               SendDlgItemMessage ( hwnd, IDC_TAB_MAIN, TCM_SETCURSEL, (WPARAM)0, (LPARAM)0 );
-               ShowWindow ( pref_pages[0].hwnd, TRUE );
+               SendDlgItemMessage ( hwnd, IDC_TAB_MAIN, TCM_SETCURSEL, (WPARAM)(page), (LPARAM)0 );
+               ShowWindow ( pref_pages[page].hwnd, TRUE );     
                return TRUE;
        }
        case WM_COMMAND:
@@ -542,6 +554,7 @@ LRESULT APIENTRY CALLBACK PrefWndDialogProc(HWND hwnd, UINT uMess, WPARAM wParam
                }
                PrefWndCreatePage(hwnd, nIndex);
                ShowWindow(pref_pages[nIndex].hwnd, SW_SHOWNORMAL);
+               PrefInitialPage = nIndex;
                return TRUE;
            }
 
@@ -761,6 +774,9 @@ void reload_cfg(void)
     free_special_patch(-1);
     tmdy_free_config();
     free_soundfonts();
+#ifdef INT_SYNTH
+       free_int_synth();
+#endif // INT_SYNTH
     free_cache_data();
     timidity_start_initialize();
     if (!sp_temp->ConfigFile[0]) {
@@ -1518,6 +1534,7 @@ PrefSyn1DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
 #endif // defined(WINDRV_SETUP)
                SetDlgItemInt(hwnd,IDC_EDIT_SYN_SH_TIME,st_temp->SynShTime,FALSE);
                SetDlgItemInt(hwnd,IDC_EDIT_RTSYN_LATENCY,st_temp->opt_rtsyn_latency,FALSE);
+               DLG_FLAG_TO_CHECKBUTTON(hwnd, IDC_CHECK_RTSYN_SKIP_AQ, st_temp->opt_rtsyn_skip_aq);
 
                if(PlayerLanguage == LANGUAGE_JAPANESE) {
                        for (i = 0; i < CB_NUM(process_priority_num); i++)
@@ -1630,9 +1647,10 @@ PrefSyn1DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
 #endif // !defined(WINDRV_SETUP)
 
                st_temp->SynShTime = GetDlgItemInt(hwnd,IDC_EDIT_SYN_SH_TIME,NULL,FALSE);
-               RANGE(st_temp->SynShTime, 40, 1000);
+               RANGE(st_temp->SynShTime, 1, 1000);
                st_temp->opt_rtsyn_latency = GetDlgItemInt(hwnd,IDC_EDIT_RTSYN_LATENCY,NULL,FALSE);
                RANGE(st_temp->opt_rtsyn_latency, 1, 1000);
+               DLG_CHECKBUTTON_TO_FLAG(hwnd, IDC_CHECK_RTSYN_SKIP_AQ, st_temp->opt_rtsyn_skip_aq);
 
                // Set process priority
                tmp = SendDlgItemMessage ( hwnd, IDC_COMBO_PROCESS_PRIORITY, CB_GETCURSEL, 0, 0 );
@@ -3862,12 +3880,12 @@ static int cb_info_IDC_COMBO_FRAGMENTS_num[] = {
        128,
        160,
        256,
-       384,
-       512,
-       768,
-       1024,
-       2048,
-       4096,
+//     384,
+//     512,
+//     768,
+//     1024,
+//     2048,
+//     4096,
 };
 static const TCHAR *cb_info_IDC_COMBO_FRAGMENTS_en[] = {
        TEXT("2blocks"),
@@ -3884,12 +3902,12 @@ static const TCHAR *cb_info_IDC_COMBO_FRAGMENTS_en[] = {
        TEXT("128blocks"),
        TEXT("160blocks"),
        TEXT("256blocks"),
-       TEXT("384blocks"),
-       TEXT("512blocks"),
-       TEXT("768blocks"),
-       TEXT("1024blocks"),
-       TEXT("2048blocks"),
-       TEXT("4096blocks"),
+//     TEXT("384blocks"),
+//     TEXT("512blocks"),
+//     TEXT("768blocks"),
+//     TEXT("1024blocks"),
+//     TEXT("2048blocks"),
+//     TEXT("4096blocks"),
 };
 static const TCHAR *cb_info_IDC_COMBO_FRAGMENTS_jp[] = {
        TEXT("2\83u\83\8d\83b\83N"),
@@ -3906,12 +3924,12 @@ static const TCHAR *cb_info_IDC_COMBO_FRAGMENTS_jp[] = {
        TEXT("128\83u\83\8d\83b\83N"),
        TEXT("160\83u\83\8d\83b\83N"),
        TEXT("256\83u\83\8d\83b\83N"),
-       TEXT("384\83u\83\8d\83b\83N"),
-       TEXT("512\83u\83\8d\83b\83N"),
-       TEXT("768\83u\83\8d\83b\83N"),
-       TEXT("1024\83u\83\8d\83b\83N"),
-       TEXT("2048\83u\83\8d\83b\83N"),
-       TEXT("4096\83u\83\8d\83b\83N"),
+//     TEXT("384\83u\83\8d\83b\83N"),
+//     TEXT("512\83u\83\8d\83b\83N"),
+//     TEXT("768\83u\83\8d\83b\83N"),
+//     TEXT("1024\83u\83\8d\83b\83N"),
+//     TEXT("2048\83u\83\8d\83b\83N"),
+//     TEXT("4096\83u\83\8d\83b\83N"),
 };
 
 // IDC_COMBO_OUTPUT_MODE
@@ -4432,6 +4450,14 @@ PrefTiMidity3DialogProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
                                        break;
                                }
 #endif
+                               
+#ifdef AU_WASAPI
+                               if (st_temp->opt_playmode[0] == 'x' || st_temp->opt_playmode[0] == 'X') {
+                                       wasapiConfigDialog();
+                                       break;
+                               }
+#endif
+
 #ifdef AU_VORBIS
                                if (st_temp->opt_playmode[0] == 'v') {
                                        vorbisConfigDialog();
@@ -5858,6 +5884,9 @@ static void waveConfigDialogProcControlApply(HWND hwnd)
 #undef EDIT_GET
 #undef EDIT_GET_RANGE
 
+extern void wave_set_option_extensible(int);
+extern void wave_set_option_update_step(int);
+
 int waveConfigDialog(void)
 {
        int changed = 0;
@@ -7872,8 +7901,8 @@ PA_DEVICELIST cb_info_IDC_COMBO_PA_WMME_NAME[PA_DEVLIST_MAX];
 PA_DEVICELIST cb_info_IDC_COMBO_PA_WDMKS_NAME[PA_DEVLIST_MAX];
 PA_DEVICELIST cb_info_IDC_COMBO_PA_WASAPI_NAME[PA_DEVLIST_MAX];
 
-#define cb_num_IDC_COMBO_WASAPI_PRIORITY 8
-static const TCHAR *cb_info_IDC_COMBO_WASAPI_PRIORITY[] = {
+#define cb_num_IDC_COMBO_PA_WASAPI_PRIORITY 8
+static const TCHAR *cb_info_IDC_COMBO_PA_WASAPI_PRIORITY[] = {
     TEXT("None"),
     TEXT("Audio (Shared Mode)"),
     TEXT("Capture"),
@@ -7884,8 +7913,8 @@ static const TCHAR *cb_info_IDC_COMBO_WASAPI_PRIORITY[] = {
     TEXT("WindowManager"),
 };
 
-#define cb_num_IDC_COMBO_WASAPI_STREAM_CATEGORY 12
-static const TCHAR *cb_info_IDC_COMBO_WASAPI_STREAM_CATEGORY[] = {
+#define cb_num_IDC_COMBO_PA_WASAPI_STREAM_CATEGORY 12
+static const TCHAR *cb_info_IDC_COMBO_PA_WASAPI_STREAM_CATEGORY[] = {
     TEXT("Other"),
     TEXT("None"),
     TEXT("None"),
@@ -7900,8 +7929,8 @@ static const TCHAR *cb_info_IDC_COMBO_WASAPI_STREAM_CATEGORY[] = {
     TEXT("Media"),
 };
 
-#define cb_num_IDC_COMBO_WASAPI_STREAM_OPTION 3
-static const TCHAR *cb_info_IDC_COMBO_WASAPI_STREAM_OPTION[] = {
+#define cb_num_IDC_COMBO_PA_WASAPI_STREAM_OPTION 3
+static const TCHAR *cb_info_IDC_COMBO_PA_WASAPI_STREAM_OPTION[] = {
     TEXT("None"),
     TEXT("Raw"),
     TEXT("MatchFormat"),
@@ -7917,33 +7946,33 @@ LRESULT WINAPI portaudioConfigDialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM
                {
                        // WASAPI Options
                        if (st_temp->pa_wasapi_flag & paWinWasapiExclusive)
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_EXCLUSIVE, BM_SETCHECK, 1, 0);
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_EXCLUSIVE, BM_SETCHECK, 1, 0);
                        else
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_EXCLUSIVE, BM_SETCHECK, 0, 0);
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_EXCLUSIVE, BM_SETCHECK, 0, 0);
                        if (st_temp->pa_wasapi_flag & paWinWasapiRedirectHostProcessor)
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_REDIRECT, BM_SETCHECK, 1, 0);
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_REDIRECT, BM_SETCHECK, 1, 0);
                        else
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_REDIRECT, BM_SETCHECK, 0, 0);
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_REDIRECT, BM_SETCHECK, 0, 0);
                        if (st_temp->pa_wasapi_flag & paWinWasapiUseChannelMask)
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_CH_MASK, BM_SETCHECK, 1, 0);
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_CH_MASK, BM_SETCHECK, 1, 0);
                        else
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_CH_MASK, BM_SETCHECK, 0, 0);
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_CH_MASK, BM_SETCHECK, 0, 0);
                        if (st_temp->pa_wasapi_flag & paWinWasapiPolling)
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_POLLING, BM_SETCHECK, 1, 0);
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_POLLING, BM_SETCHECK, 1, 0);
                        else
-                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_WASAPI_POLLING, BM_SETCHECK, 0, 0);
-                       for (i = 0; i < cb_num_IDC_COMBO_WASAPI_PRIORITY; i++)
-                               CB_INSSTR(IDC_COMBO_WASAPI_PRIORITY, cb_info_IDC_COMBO_WASAPI_PRIORITY[i]);
-                       CB_SET(IDC_COMBO_WASAPI_PRIORITY, (st_temp->pa_wasapi_flag >> 4));
+                               SendDlgItemMessage(hwnd, IDC_CHECKBOX_PA_WASAPI_POLLING, BM_SETCHECK, 0, 0);
+                       for (i = 0; i < cb_num_IDC_COMBO_PA_WASAPI_PRIORITY; i++)
+                               CB_INSSTR(IDC_COMBO_PA_WASAPI_PRIORITY, cb_info_IDC_COMBO_PA_WASAPI_PRIORITY[i]);
+                       CB_SET(IDC_COMBO_PA_WASAPI_PRIORITY, (st_temp->pa_wasapi_flag >> 4));
 
-                       DI_DISABLE(IDC_CHECKBOX_WASAPI_CH_MASK); // \8dì\82Á\82Ä\82È\82¢\82Ì\82ÅOFF                   
+                       DI_DISABLE(IDC_CHECKBOX_PA_WASAPI_CH_MASK); // \8dì\82Á\82Ä\82È\82¢\82Ì\82ÅOFF                        
                        // WASAPI StreamCategory
-                       for (i = 0; i < cb_num_IDC_COMBO_WASAPI_STREAM_CATEGORY; i++)
-                               CB_INSSTR(IDC_COMBO_PA_WASAPI_STREAM_CATEGORY, cb_info_IDC_COMBO_WASAPI_STREAM_CATEGORY[i]);
+                       for (i = 0; i < cb_num_IDC_COMBO_PA_WASAPI_STREAM_CATEGORY; i++)
+                               CB_INSSTR(IDC_COMBO_PA_WASAPI_STREAM_CATEGORY, cb_info_IDC_COMBO_PA_WASAPI_STREAM_CATEGORY[i]);
                        CB_SET(IDC_COMBO_PA_WASAPI_STREAM_CATEGORY, (st_temp->pa_wasapi_stream_category));
                        // WASAPI StreamOption
-                       for (i = 0; i < cb_num_IDC_COMBO_WASAPI_STREAM_OPTION; i++)
-                               CB_INSSTR(IDC_COMBO_PA_WASAPI_STREAM_OPTION, cb_info_IDC_COMBO_WASAPI_STREAM_OPTION[i]);
+                       for (i = 0; i < cb_num_IDC_COMBO_PA_WASAPI_STREAM_OPTION; i++)
+                               CB_INSSTR(IDC_COMBO_PA_WASAPI_STREAM_OPTION, cb_info_IDC_COMBO_PA_WASAPI_STREAM_OPTION[i]);
                        CB_SET(IDC_COMBO_PA_WASAPI_STREAM_OPTION, (st_temp->pa_wasapi_stream_option));
 
 
@@ -8097,15 +8126,15 @@ LRESULT WINAPI portaudioConfigDialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM
                                }
                                // WASAPI Flag
                                flag = 0;
-                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_WASAPI_EXCLUSIVE,BM_GETCHECK,0,0))
+                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_PA_WASAPI_EXCLUSIVE,BM_GETCHECK,0,0))
                                        flag |= paWinWasapiExclusive;
-                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_WASAPI_REDIRECT,BM_GETCHECK,0,0))
+                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_PA_WASAPI_REDIRECT,BM_GETCHECK,0,0))
                                        flag |= paWinWasapiRedirectHostProcessor;
-                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_WASAPI_CH_MASK,BM_GETCHECK,0,0))
+                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_PA_WASAPI_CH_MASK,BM_GETCHECK,0,0))
                                        flag |= paWinWasapiUseChannelMask;
-                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_WASAPI_POLLING,BM_GETCHECK,0,0))
+                               if(SendDlgItemMessage(hwnd,IDC_CHECKBOX_PA_WASAPI_POLLING,BM_GETCHECK,0,0))
                                        flag |= paWinWasapiPolling;
-                               cb_sel = SendDlgItemMessage(hwnd, IDC_COMBO_WASAPI_PRIORITY, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
+                               cb_sel = SendDlgItemMessage(hwnd, IDC_COMBO_PA_WASAPI_PRIORITY, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
                                flag |= cb_sel << 4;
                                st_temp->pa_wasapi_flag = flag;
                                // WASAPI StreamCategory
@@ -8281,3 +8310,170 @@ void wmmeConfigDialog(HWND hwnd)
 #endif
 
 
+
+#ifdef AU_WASAPI
+///////////////////////////////////////////////////////////////////////
+//
+// WASAPI Config Dialog
+//
+///////////////////////////////////////////////////////////////////////
+
+WASAPI_DEVICELIST cb_info_IDC_COMBO_WASAPI_NAME[WASAPI_DEVLIST_MAX];
+
+#define cb_num_IDC_COMBO_WASAPI_PRIORITY 8
+static const TCHAR *cb_info_IDC_COMBO_WASAPI_PRIORITY[] = {
+    TEXT("Auto"),
+    TEXT("Audio (Shared Mode)"),
+    TEXT("Capture"),
+    TEXT("Distribution"),
+    TEXT("Games"),
+    TEXT("Playback"),
+    TEXT("ProAudio (Exclusive Mode)"),
+    TEXT("WindowManager"),
+};
+
+#define cb_num_IDC_COMBO_WASAPI_STREAM_CATEGORY 12
+static const TCHAR *cb_info_IDC_COMBO_WASAPI_STREAM_CATEGORY[] = {
+    TEXT("Other"),
+    TEXT("None"),
+    TEXT("None"),
+    TEXT("Communications"),
+    TEXT("Alerts"),
+    TEXT("SoundEffects"),
+    TEXT("GameEffects"),
+    TEXT("GameMedia"),
+    TEXT("GameChat"),
+    TEXT("Speech"),
+    TEXT("Movie"),
+    TEXT("Media"),
+};
+
+#define cb_num_IDC_COMBO_WASAPI_STREAM_OPTION 3
+static const TCHAR *cb_info_IDC_COMBO_WASAPI_STREAM_OPTION[] = {
+    TEXT("None"),
+    TEXT("Raw"),
+    TEXT("MatchFormat"),
+};
+
+
+LRESULT WINAPI wasapiConfigDialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+       int i = 0, cb_num = 0, cb_sel = 0, flag;
+
+       switch (msg) {
+               case WM_INITDIALOG:
+               {
+                       // WASAPI device
+                       cb_num = wasapi_device_list(cb_info_IDC_COMBO_WASAPI_NAME);
+                       if (cb_num == 0)
+                               DI_DISABLE(IDC_COMBO_WASAPI_DEV);
+                       else
+                               DI_ENABLE(IDC_COMBO_WASAPI_DEV);
+                       for (i = 0; i < cb_num && i < WASAPI_DEVLIST_MAX; i++) {
+                               CB_INSSTRA(IDC_COMBO_WASAPI_DEV, &cb_info_IDC_COMBO_WASAPI_NAME[i].name);
+                               if (st_temp->wasapi_device_id == cb_info_IDC_COMBO_WASAPI_NAME[i].deviceID)
+                                       cb_sel = i;
+                       }
+                       CB_SET(IDC_COMBO_WASAPI_DEV, (cb_sel));         
+                       // Latency
+                       SetDlgItemInt(hwnd, IDC_EDIT_WASAPI_LATENCY, st_temp->wasapi_latency, FALSE);
+                       SetDlgItemInt(hwnd, IDC_STATIC_WASAPI_LATENCY_MIN, cb_info_IDC_COMBO_WASAPI_NAME[cb_sel].LatencyMin, FALSE);
+                       SetDlgItemInt(hwnd, IDC_STATIC_WASAPI_LATENCY_MAX, cb_info_IDC_COMBO_WASAPI_NAME[cb_sel].LatencyMax, FALSE);
+                       // WASAPI WAVEFORMATEX
+                       if(st_temp->wasapi_format_ext == 0){
+                               CheckRadioButton(hwnd,IDC_RADIOBUTTON_WASAPI_FORMAT_EX,IDC_RADIOBUTTON_WASAPI_FORMAT_EXT,IDC_RADIOBUTTON_WASAPI_FORMAT_EX);
+                       }else{
+                               CheckRadioButton(hwnd,IDC_RADIOBUTTON_WASAPI_FORMAT_EX,IDC_RADIOBUTTON_WASAPI_FORMAT_EXT,IDC_RADIOBUTTON_WASAPI_FORMAT_EXT);
+                       }
+                       // WASAPI Share Mode
+               //      CH_SET(IDC_CHECKBOX_WASAPI_EXCLUSIVE, st_temp->wasapi_exclusive);
+                       if(st_temp->wasapi_exclusive == 0){
+                               CheckRadioButton(hwnd, IDC_RADIOBUTTON_WASAPI_SHARE, IDC_RADIOBUTTON_WASAPI_EXCLUSIVE, IDC_RADIOBUTTON_WASAPI_SHARE);
+                       }else{
+                               CheckRadioButton(hwnd, IDC_RADIOBUTTON_WASAPI_SHARE, IDC_RADIOBUTTON_WASAPI_EXCLUSIVE, IDC_RADIOBUTTON_WASAPI_EXCLUSIVE);
+                       }
+                       // WASAPI Flags
+                       if(st_temp->wasapi_polling == 0){
+                               CheckRadioButton(hwnd, IDC_RADIOBUTTON_WASAPI_EVENT, IDC_RADIOBUTTON_WASAPI_POLLING, IDC_RADIOBUTTON_WASAPI_EVENT);
+                       }else{
+                               CheckRadioButton(hwnd, IDC_RADIOBUTTON_WASAPI_EVENT, IDC_RADIOBUTTON_WASAPI_POLLING, IDC_RADIOBUTTON_WASAPI_POLLING);
+                       }
+                       // WASAPI Thread Priority
+                       for (i = 0; i < cb_num_IDC_COMBO_WASAPI_PRIORITY; i++)
+                               CB_INSSTR(IDC_COMBO_WASAPI_PRIORITY, cb_info_IDC_COMBO_WASAPI_PRIORITY[i]);
+                       CB_SET(IDC_COMBO_WASAPI_PRIORITY, (st_temp->wasapi_priority));          
+                       // WASAPI Stream Category
+                       for (i = 0; i < cb_num_IDC_COMBO_WASAPI_STREAM_CATEGORY; i++)
+                               CB_INSSTR(IDC_COMBO_WASAPI_STREAM_CATEGORY, cb_info_IDC_COMBO_WASAPI_STREAM_CATEGORY[i]);
+                       CB_SET(IDC_COMBO_WASAPI_STREAM_CATEGORY, (st_temp->wasapi_stream_category));
+                       // WASAPI Stream Option
+                       for (i = 0; i < cb_num_IDC_COMBO_WASAPI_STREAM_OPTION; i++)
+                               CB_INSSTR(IDC_COMBO_WASAPI_STREAM_OPTION, cb_info_IDC_COMBO_WASAPI_STREAM_OPTION[i]);
+                       CB_SET(IDC_COMBO_WASAPI_STREAM_OPTION, (st_temp->wasapi_stream_option));
+
+                       SetFocus(DI_GET(IDOK));
+                       return TRUE;
+               }
+               case WM_CLOSE:
+                       EndDialog(hwnd,FALSE);
+                       break;
+               case WM_COMMAND:
+                       switch (LOWORD(wp)) {
+                       case IDC_COMBO_WASAPI_DEV:                              
+                               if(IsWindowEnabled(GetDlgItem(hwnd, IDC_COMBO_WASAPI_DEV))) {
+                                       cb_sel = SendDlgItemMessage(hwnd, IDC_COMBO_WASAPI_DEV, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
+                                       SetDlgItemInt(hwnd, IDC_STATIC_WASAPI_LATENCY_MIN, cb_info_IDC_COMBO_WASAPI_NAME[cb_sel].LatencyMin, FALSE);
+                                       SetDlgItemInt(hwnd, IDC_STATIC_WASAPI_LATENCY_MAX, cb_info_IDC_COMBO_WASAPI_NAME[cb_sel].LatencyMax, FALSE);
+                               }       
+                               break;
+                       case IDCANCEL:
+                               PostMessage(hwnd,WM_CLOSE,(WPARAM)0,(LPARAM)0);
+                               break;
+                       case IDOK:
+                               // WASAPI device
+                               if(IsWindowEnabled(GetDlgItem(hwnd, IDC_COMBO_WASAPI_DEV))) {
+                                       cb_sel = SendDlgItemMessage(hwnd, IDC_COMBO_WASAPI_DEV, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
+                                       st_temp->wasapi_device_id = cb_info_IDC_COMBO_WASAPI_NAME[cb_sel].deviceID;
+                               }       
+                               // Latency
+                               st_temp->wasapi_latency = GetDlgItemInt(hwnd, IDC_EDIT_WASAPI_LATENCY, NULL, FALSE);
+                               // WASAPI WAVEFORMATEX
+                               if(SendDlgItemMessage(hwnd,IDC_RADIOBUTTON_WASAPI_FORMAT_EX,BM_GETCHECK,0,0))
+                                       st_temp->wasapi_format_ext = 0;
+                               else
+                                       st_temp->wasapi_format_ext = 1; 
+                               // WASAPI Share Mode
+                       //      st_temp->wasapi_exclusive = CH_GET(IDC_CHECKBOX_WASAPI_EXCLUSIVE);
+                       //      st_temp->wasapi_exclusive = CH_GET(IDC_RADIOBUTTON_WASAPI_SHARE) ? 0 : 1;
+                               if(SendDlgItemMessage(hwnd, IDC_RADIOBUTTON_WASAPI_SHARE, BM_GETCHECK, 0, 0))
+                                       st_temp->wasapi_exclusive = 0;
+                               else
+                                       st_temp->wasapi_exclusive = 1;
+                               // WASAPI Flags
+                               if(SendDlgItemMessage(hwnd, IDC_RADIOBUTTON_WASAPI_EVENT, BM_GETCHECK, 0, 0))
+                                       st_temp->wasapi_polling = 0;
+                               else
+                                       st_temp->wasapi_polling = 1;
+                               // WASAPI Thread Priority
+                               cb_sel = SendDlgItemMessage(hwnd, IDC_COMBO_WASAPI_PRIORITY, CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
+                               st_temp->wasapi_priority = cb_sel;
+                               // WASAPI Stream Category
+                               st_temp->wasapi_stream_category = CB_GET(IDC_COMBO_PA_WASAPI_STREAM_CATEGORY);
+                               // WASAPI Stream Option
+                               st_temp->wasapi_stream_option = CB_GET(IDC_COMBO_PA_WASAPI_STREAM_OPTION);
+
+                               EndDialog(hwnd,TRUE);
+                               break;
+                       }
+                       break;
+       }
+       return FALSE;
+}
+
+void wasapiConfigDialog(void)
+{
+       DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_WASAPI), hPrefWnd, (DLGPROC)wasapiConfigDialogProc);
+}
+
+#endif // AU_WASAPI
+
index c1dad96..4c372c2 100644 (file)
 #define IDD_DIALOG_RIFFWAVE_EN          163
 #define IDD_DIALOG_RIFFWAVE             164
 #define IDD_DIALOG_SEARCHBOX            165
-#define IDD_PREF_SFINI2                 166
-#define IDD_PREF_CUSTOM1_EN             167
-#define IDD_PREF_CUSTOM2_EN             168
-#define IDD_PREF_INT_SYNTH              169
-#define IDD_PREF_INT_SYNTH_EN           170
+#define        IDD_DIALOG_WASAPI               166
+#define IDD_PREF_SFINI2                 167
+#define IDD_PREF_CUSTOM1_EN             168
+#define IDD_PREF_CUSTOM2_EN             169
+#define IDD_PREF_INT_SYNTH              170
+#define IDD_PREF_INT_SYNTH_EN           171
 
 #define IDC_CONFIG_GUI                  300
 #define IDC_BUTTON_INI_FILE             350
 // compute_thread_num
 #define IDC_COMBO_COMPUTE_THREAD_NUM   3900
 
-
 //// synth
 // port
 #define IDC_COMBO_PORT_NUM             3950
 #define IDC_CHECK_SYN_AUTOSTART        3955
 #define IDC_EDIT_SYN_SH_TIME           3956
 #define IDC_EDIT_RTSYN_LATENCY         3957
+#define IDC_CHECK_RTSYN_SKIP_AQ        3958
 // priority
 #define IDC_COMBO_SYN_THREAD_PRIORITY  3970
 
 #define IDC_RADIOBUTTON_WAVE_FORMAT_EXT 8002
 #define IDC_EDIT_WMME_BUFFER_BIT        8003
 #define IDC_EDIT_WMME_BUFFER_NUM        8004
+// wasapi
+#define IDC_COMBO_WASAPI_DEV            8050
+#define IDC_RADIOBUTTON_WASAPI_FORMAT_EX  8051
+#define IDC_RADIOBUTTON_WASAPI_FORMAT_EXT 8052
+#define IDC_RADIOBUTTON_WASAPI_SHARE    8053
+#define IDC_RADIOBUTTON_WASAPI_EXCLUSIVE 8054
+#define IDC_RADIOBUTTON_WASAPI_EVENT    8055
+#define IDC_RADIOBUTTON_WASAPI_POLLING  8056
+#define IDC_COMBO_WASAPI_PRIORITY       8057
+#define IDC_COMBO_WASAPI_STREAM_CATEGORY  8058
+#define IDC_COMBO_WASAPI_STREAM_OPTION  8059
+#define IDC_EDIT_WASAPI_LATENCY         8060
+#define IDC_STATIC_WASAPI_LATENCY_MIN   8061
+#define IDC_STATIC_WASAPI_LATENCY_MAX   8062
 // portaudio
 #define IDC_COMBO_PA_ASIO_DEV           8100
 #define IDC_BUTTON_PA_ASIO_CONFIG       8101
 #define IDC_COMBO_PA_DS_DEV             8103
 #define IDC_COMBO_PA_WDMKS_DEV          8104
 #define IDC_COMBO_PA_WASAPI_DEV         8105
-#define IDC_CHECKBOX_WASAPI_EXCLUSIVE   8106
-#define IDC_CHECKBOX_WASAPI_REDIRECT    8107
-#define IDC_CHECKBOX_WASAPI_CH_MASK     8108
-#define IDC_CHECKBOX_WASAPI_POLLING     8109
-#define IDC_COMBO_WASAPI_PRIORITY       8110
+#define IDC_CHECKBOX_PA_WASAPI_EXCLUSIVE   8106
+#define IDC_CHECKBOX_PA_WASAPI_REDIRECT    8107
+#define IDC_CHECKBOX_PA_WASAPI_CH_MASK     8108
+#define IDC_CHECKBOX_PA_WASAPI_POLLING     8109
+#define IDC_COMBO_PA_WASAPI_PRIORITY       8110
 #define IDC_COMBO_PA_WASAPI_STREAM_CATEGORY  8115
 #define IDC_COMBO_PA_WASAPI_STREAM_OPTION  8120
 
index c5d4222..59fdab5 100644 (file)
@@ -528,12 +528,12 @@ FONT 9, "MS UI Gothic", 0, 0, 1
     LTEXT           "WASAPI", IDC_STATIC, 5, 88, 55, 8, SS_LEFT\r
     COMBOBOX        IDC_COMBO_PA_WASAPI_DEV, 60, 85, 125, 211, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
     GROUPBOX        "WASAPI Options", IDC_STATIC, 5, 105, 185, 100, WS_GROUP\r
-    AUTOCHECKBOX    "Exclusive mode", IDC_CHECKBOX_WASAPI_EXCLUSIVE, 10, 115, 62, 8\r
-    AUTOCHECKBOX    "UseChannelMask", IDC_CHECKBOX_WASAPI_CH_MASK, 10, 130, 66, 8\r
-    AUTOCHECKBOX    "Redirect host processor", IDC_CHECKBOX_WASAPI_REDIRECT, 85, 115, 86, 8\r
-    AUTOCHECKBOX    "Polling", IDC_CHECKBOX_WASAPI_POLLING, 85, 130, 35, 8\r
+    AUTOCHECKBOX    "Exclusive mode", IDC_CHECKBOX_PA_WASAPI_EXCLUSIVE, 10, 115, 62, 8\r
+    AUTOCHECKBOX    "UseChannelMask", IDC_CHECKBOX_PA_WASAPI_CH_MASK, 10, 130, 66, 8\r
+    AUTOCHECKBOX    "Redirect host processor", IDC_CHECKBOX_PA_WASAPI_REDIRECT, 85, 115, 86, 8\r
+    AUTOCHECKBOX    "Polling", IDC_CHECKBOX_PA_WASAPI_POLLING, 85, 130, 35, 8\r
     LTEXT           "Thread priority", IDC_STATIC, 10, 148, 60, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_WASAPI_PRIORITY, 70, 145, 115, 203, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    COMBOBOX        IDC_COMBO_PA_WASAPI_PRIORITY, 70, 145, 115, 203, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
     DEFPUSHBUTTON   "OK", IDOK, 225, 5, 40, 14, WS_GROUP\r
     PUSHBUTTON      "CANCEL", IDCANCEL, 225, 25, 40, 14\r
     LTEXT           "Stream Category", IDC_STATIC, 10, 168, 50, 8, SS_LEFT\r
@@ -738,6 +738,42 @@ FONT 8, "Tahoma"
 \r
 \r
 \r
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL\r
+IDD_DIALOG_WASAPI DIALOGEX 0, 0, 215, 200\r
+STYLE DS_MODALFRAME | DS_SETFONT | WS_CAPTION | WS_POPUP | WS_SYSMENU\r
+CAPTION "WASAPI Config"\r
+FONT 9, "MS UI Gothic", 0, 0, 1\r
+{\r
+    LTEXT           "WASAPI device", IDC_STATIC, 5, 5, 46, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_WASAPI_DEV, 5, 15, 160, 211, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    GROUPBOX        "Share Mode", IDC_STATIC, 5, 35, 50, 45, WS_GROUP\r
+    AUTORADIOBUTTON "Shared", IDC_RADIOBUTTON_WASAPI_SHARE, 10, 50, 36, 8, WS_GROUP | WS_TABSTOP\r
+    AUTORADIOBUTTON "Exclusive", IDC_RADIOBUTTON_WASAPI_EXCLUSIVE, 10, 65, 44, 8, WS_TABSTOP\r
+    LTEXT           "Thread priority", IDC_STATIC, 5, 140, 60, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_WASAPI_PRIORITY, 60, 138, 100, 120, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    DEFPUSHBUTTON   "OK", IDOK, 170, 5, 40, 14, WS_GROUP\r
+    PUSHBUTTON      "CANCEL", IDCANCEL, 170, 25, 40, 14\r
+    LTEXT           "Stream Category", IDC_STATIC, 5, 160, 50, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_WASAPI_STREAM_CATEGORY, 60, 158, 100, 120, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "Stream Option", IDC_STATIC, 5, 180, 43, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_WASAPI_STREAM_OPTION, 60, 178, 100, 54, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    GROUPBOX        "Format", IDC_STATIC, 60, 35, 105, 45, WS_GROUP\r
+    AUTORADIOBUTTON "WAVEFORMATEX", IDC_RADIOBUTTON_WASAPI_FORMAT_EX, 65, 50, 69, 8, WS_GROUP | WS_TABSTOP\r
+    AUTORADIOBUTTON "WAVEFORMATEXTENSIBLE", IDC_RADIOBUTTON_WASAPI_FORMAT_EXT, 65, 65, 95, 8, WS_TABSTOP\r
+    LTEXT           "Range (ms):", IDC_STATIC, 65, 115, 36, 8, SS_LEFT\r
+    GROUPBOX        "Latency", IDC_STATIC, 60, 85, 105, 45, WS_GROUP\r
+    EDITTEXT        IDC_EDIT_WASAPI_LATENCY, 115, 98, 35, 12, ES_AUTOHSCROLL\r
+    LTEXT           "Latency (ms):", IDC_STATIC, 65, 100, 40, 8, SS_LEFT\r
+    LTEXT           "9999", IDC_STATIC_WASAPI_LATENCY_MAX, 140, 115, 15, 8, SS_LEFT\r
+    LTEXT           "9999", IDC_STATIC_WASAPI_LATENCY_MIN, 115, 115, 15, 8, SS_LEFT\r
+    GROUPBOX        "Flags", IDC_STATIC, 5, 85, 50, 45, WS_GROUP\r
+    AUTORADIOBUTTON "Event", IDC_RADIOBUTTON_WASAPI_EVENT, 10, 100, 33, 8, WS_GROUP | WS_TABSTOP\r
+    AUTORADIOBUTTON "Polling", IDC_RADIOBUTTON_WASAPI_POLLING, 10, 115, 40, 8, WS_TABSTOP\r
+    LTEXT           "-", IDC_STATIC, 133, 115, 4, 8, SS_LEFT\r
+}\r
+\r
+\r
+\r
 LANGUAGE LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN\r
 IDD_DIALOG_WAVEFORM DIALOGEX 0, 0, 240, 120\r
 STYLE DS_MODALFRAME | DS_SETFONT | WS_CAPTION | WS_VISIBLE\r
@@ -3017,27 +3053,27 @@ IDD_PREF_SYN1 DIALOGEX 0, 0, 350, 290
 STYLE DS_CONTROL | DS_SETFONT | WS_CHILDWINDOW\r
 FONT 9, "MS UI Gothic", 0, 0, 1\r
 {\r
-    GROUPBOX        "MIDI IN \83f\83o\83C\83X", IDC_STATIC, 5, 50, 225, 100, WS_GROUP\r
-    LTEXT           "\83|\81[\83g\90\94", IDC_STATIC, 10, 65, 35, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_PORT_NUM, 45, 62, 45, 87, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "\83|\81[\83g 0", IDC_STATIC, 10, 85, 35, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT0, 45, 82, 180, 256, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "\83|\81[\83g 1", IDC_STATIC, 10, 100, 35, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT1, 45, 97, 180, 254, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "\83|\81[\83g 2", IDC_STATIC, 10, 115, 35, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT2, 45, 112, 180, 256, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "\83|\81[\83g 3", IDC_STATIC, 10, 130, 35, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT3, 45, 127, 180, 252, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    GROUPBOX        "\83\8a\83A\83\8b\83^\83C\83\80 \83V\83\93\83Z\83T\83C\83U\81[", IDC_STATIC, 5, 155, 225, 65, WS_GROUP\r
-    AUTOCHECKBOX    "\83V\83\93\83Z\82ð\8e©\93®\82Å\8aJ\8en\82·\82é", IDC_CHECK_SYN_AUTOSTART, 10, 170, 125, 10\r
+    GROUPBOX        "MIDI IN \83f\83o\83C\83X", IDC_STATIC, 5, 25, 225, 100, WS_GROUP\r
+    LTEXT           "\83|\81[\83g\90\94", IDC_STATIC, 10, 40, 35, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_PORT_NUM, 45, 37, 45, 87, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "\83|\81[\83g 0", IDC_STATIC, 10, 60, 35, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT0, 45, 57, 180, 256, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "\83|\81[\83g 1", IDC_STATIC, 10, 75, 35, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT1, 45, 72, 180, 254, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "\83|\81[\83g 2", IDC_STATIC, 10, 90, 35, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT2, 45, 87, 180, 256, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "\83|\81[\83g 3", IDC_STATIC, 10, 105, 35, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT3, 45, 102, 180, 252, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    GROUPBOX        "\83\8a\83A\83\8b\83^\83C\83\80 \83V\83\93\83Z\83T\83C\83U\81[", IDC_STATIC, 5, 130, 225, 80, WS_GROUP\r
+    AUTOCHECKBOX    "\83V\83\93\83Z\82ð\8e©\93®\82Å\8aJ\8en\82·\82é", IDC_CHECK_SYN_AUTOSTART, 10, 145, 110, 10\r
     LTEXT           "\83v\83\8d\83Z\83X\97D\90æ\93x", IDC_STATIC, 10, 240, 100, 8, SS_LEFT\r
     COMBOBOX        IDC_COMBO_PROCESS_PRIORITY, 115, 237, 110, 69, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
     LTEXT           "\83V\83\93\83Z\83X\83\8c\83b\83h\97D\90æ\93x", IDC_STATIC, 10, 255, 100, 8, SS_LEFT\r
     COMBOBOX        IDC_COMBO_SYN_THREAD_PRIORITY, 115, 252, 110, 69, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "\8cv\8eZ\82É\8a|\82¯\82é\8dÅ\91å\83~\83\8a\95b (\90\84\8f§\92l: 500ms)", IDC_STATIC, 10, 185, 170, 8, SS_LEFT\r
-    EDITTEXT        IDC_EDIT_SYN_SH_TIME, 185, 182, 40, 12, ES_NUMBER\r
-    LTEXT           "\83\8c\83C\83e\83\93\83V\81[ (\90\84\8f§\92l: 200ms)", IDC_STATIC, 10, 200, 170, 8, SS_LEFT\r
-    EDITTEXT        IDC_EDIT_RTSYN_LATENCY, 185, 196, 40, 12, ES_AUTOHSCROLL\r
+    LTEXT           "\8dÅ\91å\8cv\8eZ\8e\9e\8aÔ\83~\83\8a\95b (\90\84\8f§\92l: 500ms)", IDC_STATIC, 10, 160, 170, 8, SS_LEFT\r
+    EDITTEXT        IDC_EDIT_SYN_SH_TIME, 185, 157, 40, 12, ES_NUMBER\r
+    LTEXT           "\83\8c\83C\83e\83\93\83V\81[ (\90\84\8f§\92l: 200ms)", IDC_STATIC, 10, 175, 170, 8, SS_LEFT\r
+    EDITTEXT        IDC_EDIT_RTSYN_LATENCY, 185, 171, 40, 12, ES_AUTOHSCROLL\r
     PUSHBUTTON      "\90Ý\92è\83t\83@\83C\83\8b", IDC_BUTTON_CONFIG_FILE, 5, 5, 52, 14, BS_CENTER\r
     EDITTEXT        IDC_EDIT_CONFIG_FILE, 60, 5, 160, 14, ES_AUTOHSCROLL | ES_OEMCONVERT\r
     PUSHBUTTON      "\95Ò\8fW", IDC_BUTTON_CFG_EDIT, 225, 5, 25, 14, BS_CENTER\r
@@ -3046,15 +3082,16 @@ FONT 9, "MS UI Gothic", 0, 0, 1
     AUTORADIOBUTTON "\93ú\96{\8cê", IDC_RADIOBUTTON_JAPANESE, 240, 241, 45, 10, WS_TABSTOP\r
     AUTORADIOBUTTON "English", IDC_RADIOBUTTON_ENGLISH, 240, 257, 45, 10, WS_TABSTOP\r
     GROUPBOX        "\97D\90æ\93x", IDC_STATIC, 5, 225, 225, 50, WS_GROUP\r
-    GROUPBOX        "\83R\83\93\83s\83\85\81[\83g\83X\83\8c\83b\83h", IDC_STATIC, 235, 30, 110, 35, WS_GROUP\r
-    LTEXT           "\83X\83\8c\83b\83h\90\94", IDC_STATIC, 240, 46, 27, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_COMPUTE_THREAD_NUM, 300, 43, 40, 166, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    GROUPBOX        "\83X\83y\83N\83g\83\8d\83O\83\89\83\80", IDC_STATIC, 235, 70, 110, 40, WS_GROUP\r
-    LTEXT           "\95\\8e¦\8dX\90V\8aÔ\8au(sec)", IDC_STATIC, 240, 85, 57, 8, SS_LEFT\r
-    EDITTEXT        IDC_EDIT_SPECTROGRAM_UPDATE, 310, 83, 30, 12, ES_AUTOHSCROLL\r
-    LTEXT           "\83\8c\83x\83\8b", IDC_STATIC, 240, 130, 18, 8, SS_LEFT\r
-    GROUPBOX        "\83R\83\93\83\\81[\83\8b", IDC_STATIC, 235, 115, 110, 35, WS_GROUP\r
-    COMBOBOX        IDC_COMBO_CTL_VEBOSITY, 268, 128, 70, 146, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    GROUPBOX        "\83R\83\93\83s\83\85\81[\83g\83X\83\8c\83b\83h", IDC_STATIC, 235, 25, 110, 35, WS_GROUP\r
+    LTEXT           "\83X\83\8c\83b\83h\90\94", IDC_STATIC, 240, 41, 27, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_COMPUTE_THREAD_NUM, 300, 38, 40, 166, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    GROUPBOX        "\83X\83y\83N\83g\83\8d\83O\83\89\83\80", IDC_STATIC, 235, 65, 110, 40, WS_GROUP\r
+    LTEXT           "\95\\8e¦\8dX\90V\8aÔ\8au(sec)", IDC_STATIC, 240, 80, 57, 8, SS_LEFT\r
+    EDITTEXT        IDC_EDIT_SPECTROGRAM_UPDATE, 310, 78, 30, 12, ES_AUTOHSCROLL\r
+    LTEXT           "\83\8c\83x\83\8b", IDC_STATIC, 240, 125, 18, 8, SS_LEFT\r
+    GROUPBOX        "\83R\83\93\83\\81[\83\8b", IDC_STATIC, 235, 110, 110, 35, WS_GROUP\r
+    COMBOBOX        IDC_COMBO_CTL_VEBOSITY, 268, 123, 70, 146, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    AUTOCHECKBOX    "\83I\81[\83f\83B\83I\83L\83\85\81[\82ð\83X\83L\83b\83v", IDC_CHECK_RTSYN_SKIP_AQ, 10, 190, 83, 8\r
 }\r
 \r
 \r
@@ -3064,27 +3101,27 @@ IDD_PREF_SYN1_EN DIALOGEX 0, 0, 350, 290
 STYLE DS_CONTROL | DS_SETFONT | WS_CHILDWINDOW\r
 FONT 8, "Tahoma", 400, 0, 0\r
 {\r
-    GROUPBOX        "MIDI IN Device", IDC_STATIC, 5, 50, 225, 100, WS_GROUP\r
-    LTEXT           "Port max", IDC_STATIC, 10, 65, 39, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_PORT_NUM, 45, 64, 50, 87, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "Port 0", IDC_STATIC, 10, 85, 39, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT0, 45, 82, 180, 263, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "Port 1", IDC_STATIC, 10, 100, 39, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT1, 45, 97, 180, 262, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "Port 2", IDC_STATIC, 10, 115, 39, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT2, 45, 112, 180, 263, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "Port 3", IDC_STATIC, 10, 130, 39, 8, SS_LEFT\r
-    COMBOBOX        IDC_COMBO_IDPORT3, 45, 127, 180, 262, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    GROUPBOX        "Realtime synthesizer", IDC_STATIC, 5, 155, 225, 65, WS_GROUP\r
-    AUTOCHECKBOX    "Automatically start synthesize", IDC_CHECK_SYN_AUTOSTART, 10, 170, 145, 8\r
+    GROUPBOX        "MIDI IN Device", IDC_STATIC, 5, 25, 225, 100, WS_GROUP\r
+    LTEXT           "Port max", IDC_STATIC, 10, 40, 39, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_PORT_NUM, 45, 39, 50, 87, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "Port 0", IDC_STATIC, 10, 60, 39, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT0, 45, 57, 180, 263, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "Port 1", IDC_STATIC, 10, 75, 39, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT1, 45, 72, 180, 262, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "Port 2", IDC_STATIC, 10, 90, 39, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT2, 45, 87, 180, 263, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    LTEXT           "Port 3", IDC_STATIC, 10, 105, 39, 8, SS_LEFT\r
+    COMBOBOX        IDC_COMBO_IDPORT3, 45, 102, 180, 262, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    GROUPBOX        "Realtime synthesizer", IDC_STATIC, 5, 130, 225, 80, WS_GROUP\r
+    AUTOCHECKBOX    "Automatically start synthesize", IDC_CHECK_SYN_AUTOSTART, 10, 145, 113, 8\r
     LTEXT           "Process priority", IDC_STATIC, 10, 240, 104, 8, SS_LEFT\r
     COMBOBOX        IDC_COMBO_PROCESS_PRIORITY, 120, 237, 105, 69, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
     LTEXT           "Synth thread", IDC_STATIC, 10, 255, 104, 8, SS_LEFT\r
     COMBOBOX        IDC_COMBO_SYN_THREAD_PRIORITY, 120, 252, 105, 69, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
-    LTEXT           "Compute max time msec (recommend: 500)", IDC_STATIC, 10, 185, 169, 8, SS_LEFT\r
-    EDITTEXT        IDC_EDIT_SYN_SH_TIME, 185, 182, 40, 12, ES_NUMBER\r
-    LTEXT           "Latency msec (recommend: 200)", IDC_STATIC, 10, 200, 170, 8, SS_LEFT\r
-    EDITTEXT        IDC_EDIT_RTSYN_LATENCY, 185, 197, 40, 12, ES_NUMBER\r
+    LTEXT           "Compute max time msec (recommend: 500)", IDC_STATIC, 10, 160, 169, 8, SS_LEFT\r
+    EDITTEXT        IDC_EDIT_SYN_SH_TIME, 185, 157, 40, 12, ES_NUMBER\r
+    LTEXT           "Latency msec (recommend: 200)", IDC_STATIC, 10, 175, 170, 8, SS_LEFT\r
+    EDITTEXT        IDC_EDIT_RTSYN_LATENCY, 185, 172, 40, 12, ES_NUMBER\r
     PUSHBUTTON      "Config File", IDC_BUTTON_CONFIG_FILE, 5, 5, 52, 14, BS_CENTER\r
     EDITTEXT        IDC_EDIT_CONFIG_FILE, 60, 5, 160, 14, ES_AUTOHSCROLL | ES_OEMCONVERT\r
     PUSHBUTTON      "Edit", IDC_BUTTON_CFG_EDIT, 225, 5, 25, 14, BS_CENTER\r
@@ -3102,6 +3139,7 @@ FONT 8, "Tahoma", 400, 0, 0
     GROUPBOX        "Console", IDC_STATIC, 235, 110, 110, 35, WS_GROUP\r
     LTEXT           "Level", IDC_STATIC, 240, 125, 18, 8, SS_LEFT\r
     COMBOBOX        IDC_COMBO_CTL_VEBOSITY, 270, 123, 70, 146, WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT\r
+    AUTOCHECKBOX    "Skip Audio Queue", IDC_CHECK_RTSYN_SKIP_AQ, 10, 190, 72, 8\r
 }\r
 \r
 \r
index 066134b..3bcdc36 100755 (executable)
@@ -291,8 +291,8 @@ int msg_loopbuf_end = -1;
 extern int rtsyn_system_mode;
 HANDLE msg_loopbuf_hMutex = NULL; // \94r\91¼\8f\88\97\9d\97p
 int syn_AutoStart;                // \83V\83\93\83Z\8e©\93®\8bN\93®
-DWORD processPriority;            // \83v\83\8d\83Z\83X\82Ì\83v\83\89\83C\83I\83\8a\83e\83B
-DWORD syn_ThreadPriority;         // \83V\83\93\83Z\83X\83\8c\83b\83h\82Ì\83v\83\89\83C\83I\83\8a\83e\83B
+extern DWORD processPriority;            // \83v\83\8d\83Z\83X\82Ì\83v\83\89\83C\83I\83\8a\83e\83B
+extern DWORD syn_ThreadPriority;         // \83V\83\93\83Z\83X\83\8c\83b\83h\82Ì\83v\83\89\83C\83I\83\8a\83e\83B
 
 extern int volatile stream_max_compute;        // play_event() \82Ì compute_data() \82Å\8cv\8eZ\82ð\8b\96\82·\8dÅ\91å\8e\9e\8aÔ\81B
 
@@ -443,8 +443,8 @@ static int w32g_syn_main(void)
        w32g_syn.hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_TIMIDITY), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
        w32g_syn.hIconStart = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SERVER_START), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
        w32g_syn.hIconPause = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_SERVER_PAUSE), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
-       processPriority = NORMAL_PRIORITY_CLASS;
-       syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
+//     processPriority = NORMAL_PRIORITY_CLASS;
+//     syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
        for (i = 0; i <= MAX_PORT; i++) {
                w32g_syn_id_port[i] = i + 1;
        }
@@ -1229,8 +1229,8 @@ static int w32g_syn_main(void)
        SERVICE_TABLE_ENTRYA ServiceTable[2];
 
        w32g_syn.nid_uID = W32G_SYN_NID_UID;
-       processPriority = NORMAL_PRIORITY_CLASS;
-       syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
+//     processPriority = NORMAL_PRIORITY_CLASS;
+//     syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
        for (i = 0; i <= MAX_PORT; i++) {
                w32g_syn_id_port[i] = i + 1;
        }
index 837cedc..f343f5b 100644 (file)
@@ -63,6 +63,9 @@
 #ifdef AU_W32
 #include "w32_a.h"
 #endif
+#ifdef AU_WASAPI
+#include "wasapi_a.h"
+#endif
 #ifdef AU_PORTAUDIO
 #include "portaudio_a.h"
 #endif
@@ -71,7 +74,7 @@
 #include "thread.h"
 #include "miditrace.h"
 
-
+///r
 extern int opt_default_mid;
 extern int effect_lr_mode;
 extern int effect_lr_delay_msec;
@@ -82,21 +85,17 @@ extern char def_instr_name[];
 extern int opt_control_ratio;
 extern char *opt_aq_max_buff;
 extern char *opt_aq_fill_buff;
-///r
 extern char *opt_reduce_voice_threshold;
 extern char *opt_reduce_quality_threshold;
 extern char *opt_reduce_polyphony_threshold;
 extern DWORD processPriority;
-
 extern int opt_evil_mode;
 #ifdef SUPPORT_SOUNDSPEC
 extern double spectrogram_update_sec;
 #endif /* SUPPORT_SOUNDSPEC */
 extern int opt_buffer_fragments;
 extern int opt_audio_buffer_bits;
-///r
 extern int opt_compute_buffer_bits;
-
 extern int32 opt_output_rate;
 extern int PlayerLanguage;
 //extern int data_block_bits;
@@ -108,23 +107,20 @@ extern int IniFileAutoSave;
 extern int SecondMode;
 extern int AutoloadPlaylist;
 extern int AutosavePlaylist;
-///r
-//char DefaultPlaylistName[PLAYLIST_MAX][] = {"default.pls"};
-//char DefaultPlaylistPath[FILEPATH_MAX] = "";
-char DefaultPlaylistPath[PLAYLIST_MAX][FILEPATH_MAX];
-
-
-extern unsigned char opt_normal_chorus_plus;
-
 extern int PosSizeSave;
+extern unsigned char opt_normal_chorus_plus; 
 #ifdef AU_LAME
 extern void lame_ConfigDialogInfoLoadINI();
 extern void lame_ConfigDialogInfoSaveINI();
 #endif
 
 ///r
-extern DWORD processPriority;
+//char DefaultPlaylistName[PLAYLIST_MAX][] = {"default.pls"};
+//char DefaultPlaylistPath[FILEPATH_MAX] = "";
+char DefaultPlaylistPath[PLAYLIST_MAX][FILEPATH_MAX];
+
+
+
 
 
 
@@ -569,16 +565,12 @@ static int is_device_output_ID(int id)
 #if defined(WINDRV_SETUP)
 extern DWORD syn_ThreadPriority;
 extern int w32g_syn_port_num;
-extern int volatile stream_max_compute;
-uint32 opt_rtsyn_latency = 200; /* RTSYN_LATENCY=0.2 */
 #elif defined(IA_W32G_SYN)
 extern int w32g_syn_id_port[];
 extern int syn_AutoStart;
 //extern DWORD processPriority;
 extern DWORD syn_ThreadPriority;
 extern int w32g_syn_port_num;
-extern int volatile stream_max_compute;
-uint32 opt_rtsyn_latency = 200; /* RTSYN_LATENCY=0.2 */
 #endif
 
 void
@@ -724,6 +716,16 @@ ApplySettingTiMidity(SETTING_TIMIDITY *st)
        opt_wmme_device_id = st->wmme_device_id;
        opt_wave_format_ext = st->wave_format_ext;
 #endif
+#ifdef AU_WASAPI       
+       opt_wasapi_device_id = st->wasapi_device_id;
+       opt_wasapi_latency = st->wasapi_latency;
+       opt_wasapi_format_ext = st->wasapi_format_ext;
+       opt_wasapi_exclusive = st->wasapi_exclusive;
+       opt_wasapi_polling = st->wasapi_polling;
+       opt_wasapi_priority = st->wasapi_priority;
+       opt_wasapi_stream_category = st->wasapi_stream_category;
+       opt_wasapi_stream_option = st->wasapi_stream_option;
+#endif
 #ifdef AU_PORTAUDIO
        opt_pa_wmme_device_id = st->pa_wmme_device_id;
        opt_pa_ds_device_id = st->pa_ds_device_id;
@@ -774,23 +776,25 @@ ApplySettingTiMidity(SETTING_TIMIDITY *st)
     opt_use_midi_loop_repeat = SetFlag(st->opt_use_midi_loop_repeat);
     opt_midi_loop_repeat = SetValue(st->opt_midi_loop_repeat, 0, 99);
        
-#if defined(WINDRV_SETUP)
-//     processPriority = st->processPriority;
+#if defined(WINDRV_SETUP) || defined(WINDRV)
        syn_ThreadPriority = st->syn_ThreadPriority;
        stream_max_compute = st->SynShTime;
-       opt_rtsyn_latency = SetValue(st->opt_rtsyn_latency, 20, 1000);
+       opt_rtsyn_latency = SetValue(st->opt_rtsyn_latency, 1, 1000);
        rtsyn_set_latency((double)opt_rtsyn_latency * 0.001);
+       opt_rtsyn_skip_aq = st->opt_rtsyn_skip_aq;
+       rtsyn_set_skip_aq(opt_rtsyn_skip_aq);
 #elif defined(IA_W32G_SYN)
        for ( i = 0; i < MAX_PORT; i ++ ) {
                w32g_syn_id_port[i] = st->SynIDPort[i];
        }
        syn_AutoStart = st->syn_AutoStart;
-//     processPriority = st->processPriority;
        syn_ThreadPriority = st->syn_ThreadPriority;
        w32g_syn_port_num = st->SynPortNum;
        stream_max_compute = st->SynShTime;
-       opt_rtsyn_latency = SetValue(st->opt_rtsyn_latency, 20, 1000);
+       opt_rtsyn_latency = SetValue(st->opt_rtsyn_latency, 1, 1000);
        rtsyn_set_latency((double)opt_rtsyn_latency * 0.001);
+       opt_rtsyn_skip_aq = st->opt_rtsyn_skip_aq;
+       rtsyn_set_skip_aq(opt_rtsyn_skip_aq);
 #endif
 ///r
        processPriority = st->processPriority;
@@ -982,6 +986,16 @@ SaveSettingTiMidity(SETTING_TIMIDITY *st)
 #ifdef AU_W32
        st->wmme_device_id = opt_wmme_device_id;
        st->wave_format_ext = SetValue(opt_wave_format_ext, 0, 1);
+#endif 
+#ifdef AU_WASAPI       
+       st->wasapi_device_id = opt_wasapi_device_id;
+       st->wasapi_latency = opt_wasapi_latency;
+       st->wasapi_format_ext = opt_wasapi_format_ext;
+       st->wasapi_exclusive = opt_wasapi_exclusive;
+       st->wasapi_polling = opt_wasapi_polling;
+       st->wasapi_priority = opt_wasapi_priority;
+       st->wasapi_stream_category = opt_wasapi_stream_category;
+       st->wasapi_stream_option = opt_wasapi_stream_option;
 #endif
 #ifdef AU_PORTAUDIO
        st->pa_wmme_device_id = opt_pa_wmme_device_id;
@@ -1021,21 +1035,21 @@ SaveSettingTiMidity(SETTING_TIMIDITY *st)
        st->opt_modulation_update = opt_modulation_update;
        st->opt_cut_short_time = opt_cut_short_time;
        
-#if defined(WINDRV_SETUP)
-//     st->processPriority = processPriority;
+#if defined(WINDRV_SETUP) || defined(WINDRV)
        st->syn_ThreadPriority = syn_ThreadPriority;
        st->SynShTime = stream_max_compute;
        st->opt_rtsyn_latency = opt_rtsyn_latency;
+       st->opt_rtsyn_skip_aq = opt_rtsyn_skip_aq;
 #elif defined(IA_W32G_SYN)
        for ( i = 0; i < MAX_PORT; i ++ ) {
                st->SynIDPort[i] = w32g_syn_id_port[i];
        }
        st->syn_AutoStart = syn_AutoStart;
-//     st->processPriority = processPriority;
        st->syn_ThreadPriority = syn_ThreadPriority;
        st->SynPortNum = w32g_syn_port_num;
        st->SynShTime = stream_max_compute;
        st->opt_rtsyn_latency = opt_rtsyn_latency;
+       st->opt_rtsyn_skip_aq = opt_rtsyn_skip_aq;
 #endif
 ///r
        st->processPriority = processPriority;
index dd6fd3f..6d02387 100644 (file)
@@ -194,6 +194,14 @@ typedef struct SETTING_TIMIDITY_ {
 
        int32 wmme_device_id;
        int wave_format_ext; 
+       int32 wasapi_device_id;
+       int32 wasapi_latency;
+       int wasapi_format_ext;
+       int wasapi_exclusive;
+       int wasapi_polling;
+       int wasapi_priority;
+       int wasapi_stream_category;
+       int wasapi_stream_option;
        int32 pa_wmme_device_id;
        int32 pa_ds_device_id;
        int32 pa_asio_device_id;
@@ -232,6 +240,7 @@ typedef struct SETTING_TIMIDITY_ {
                DWORD syn_ThreadPriority;
                int SynShTime;
                uint32 opt_rtsyn_latency;       // --rtsyn-latency
+               int opt_rtsyn_skip_aq;  // --rtsyn-skip-aq
 #elif defined(IA_W32G_SYN)
                int SynIDPort[MAX_PORT];
                int syn_AutoStart;
@@ -240,6 +249,7 @@ typedef struct SETTING_TIMIDITY_ {
                int SynPortNum;
                int SynShTime;
                uint32 opt_rtsyn_latency;       // --rtsyn-latency
+               int opt_rtsyn_skip_aq;  // --rtsyn-skip-aq
 #endif
        int processPriority;            // --process-priority
        int compute_thread_num;
index 10d12b8..0dd06d4 100755 (executable)
@@ -554,7 +554,6 @@ static void doit(void)
 static int winplaymidi_sleep_level = 2;
 static DWORD winplaymidi_active_start_time = 0;
 
-
 void winplaymidi(void) {
 
   if (winplaymidi_sleep_level < 1) {
@@ -568,7 +567,7 @@ void winplaymidi(void) {
     DWORD ct = GetCurrentTime();
     if (winplaymidi_active_start_time == 0 || ct < winplaymidi_active_start_time) {
       winplaymidi_active_start_time = ct;
-    } else if (ct - winplaymidi_active_start_time > 2000) {
+    } else if (ct - winplaymidi_active_start_time > 60000) {
       winplaymidi_sleep_level = 2;
     }
   } else if (winplaymidi_sleep_level == 0) {
index f60896a..9ee1f2b 100644 (file)
@@ -185,7 +185,9 @@ void kbtim_uninitialize(void)
        tmdy_free_config();
        //free_reverb_buffer();
        free_effect_buffers();
+#ifdef INT_SYNTH
        free_int_synth();
+#endif // INT_SYNTH
        free_voices();//free_voice_by_Kobarin() \82Ì\91ã\82í\82è
     //initialize_resampler_coeffs \82Å\8am\95Û\82µ\82½\83\81\83\82\83\8a\82Ì\89ð\95ú
     uninitialize_resampler_coeffs();
index 214325b..7317b1c 100644 (file)
@@ -81,7 +81,7 @@ private:
     static void s_close_output(void){
         g_pDecoder->close_output();
     }
-    static int  s_output_data(const uint8 * Data, size_t Size){
+    static int32  s_output_data(const uint8 * Data, size_t Size){
         return g_pDecoder->output_data(Data, Size);
     }
     static int  s_acntl(int request, void * arg){
@@ -93,7 +93,7 @@ private:
 //PlayMode
     int  __fastcall open_output (void);
     void __fastcall close_output(void);
-    int  __fastcall output_data (const uint8 * Data, size_t Size);
+    int32  __fastcall output_data (const uint8 * Data, size_t Size);
     int  __fastcall acntl       (int request, void * arg);
     int  __fastcall detect(void){return 1;}
 ///r
index 2726e2a..5912b12 100644 (file)
@@ -218,7 +218,7 @@ void __fastcall KbTimDecoder::close_output(void)
 {
     m_pm.fd = -1;
 }
-int __fastcall KbTimDecoder::output_data(const uint8 *buf, size_t len)
+int32 __fastcall KbTimDecoder::output_data(const uint8 *buf, size_t len)
 {
     EnterCriticalSection(&m_cs);
     if(!m_nStart){
index 7ac63c8..38164ef 100644 (file)
@@ -17,8 +17,8 @@
        <Configurations>
                <Configuration
                        Name="Debug|Win32"
-                       OutputDirectory=".\kbtim_dll_Debug"
-                       IntermediateDirectory=".\kbtim_dll_Debug"
+                       OutputDirectory=".\Debug"
+                       IntermediateDirectory=".\Debug"
                        ConfigurationType="2"
                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
                        UseOfMFC="0"
@@ -55,9 +55,9 @@
                                BasicRuntimeChecks="3"
                                RuntimeLibrary="3"
                                PrecompiledHeaderFile=".\kbtim_dll_Debug/kbtim_dll.pch"
-                               AssemblerListingLocation=".\kbtim_dll_Debug/"
-                               ObjectFile=".\kbtim_dll_Debug/"
-                               ProgramDataBaseFileName=".\kbtim_dll_Debug/"
+                               AssemblerListingLocation=".\Debug"
+                               ObjectFile=".\Debug"
+                               ProgramDataBaseFileName=".\Debug"
                                BrowseInformation="1"
                                WarningLevel="3"
                                SuppressStartupBanner="true"
@@ -76,6 +76,7 @@
                        />
                        <Tool
                                Name="VCLinkerTool"
+                               AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
                                OutputFile="../../kbtim.dll"
                                LinkIncremental="2"
                                SuppressStartupBanner="true"
                </Configuration>
                <Configuration
                        Name="Release|Win32"
-                       OutputDirectory=".\kbtim_dll_Release"
-                       IntermediateDirectory=".\kbtim_dll_Release"
+                       OutputDirectory="..\Release\"
+                       IntermediateDirectory=".\Release\"
                        ConfigurationType="2"
                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
                        UseOfMFC="0"
                                EnableEnhancedInstructionSet="2"
                                FloatingPointModel="2"
                                PrecompiledHeaderFile=".\kbtim_dll_Release/kbtim_dll.pch"
-                               AssemblerListingLocation=".\kbtim_dll_Release/"
-                               ObjectFile=".\kbtim_dll_Release/"
-                               ProgramDataBaseFileName=".\kbtim_dll_Release/"
+                               AssemblerListingLocation=".\Release/"
+                               ObjectFile=".\Release/"
+                               ProgramDataBaseFileName=".\Release/"
                                BrowseInformation="1"
                                BrowseInformationFile="$(IntDir)\"
                                WarningLevel="0"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;"
+                               AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
                                OutputFile="../Release/kbtim.dll"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"
                                        </FileConfiguration>
                                </File>
                                <File
+                                       RelativePath="..\timidity\int_synth.c"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\timidity\loadtab.c"
                                        >
                                        <FileConfiguration
index 7b12ae0..1ae945a 100644 (file)
@@ -16,8 +16,8 @@
        <Configurations>
                <Configuration
                        Name="Release|Win32"
-                       OutputDirectory=".\kbtim_kpi_Release"
-                       IntermediateDirectory=".\kbtim_kpi_Release"
+                       OutputDirectory="..\Release\"
+                       IntermediateDirectory=".\Release\"
                        ConfigurationType="2"
                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
                        UseOfMFC="0"
@@ -59,9 +59,9 @@
                                EnableEnhancedInstructionSet="2"
                                FloatingPointModel="2"
                                PrecompiledHeaderFile=".\kbtim_kpi_Release/kbtim_kpi.pch"
-                               AssemblerListingLocation=".\kbtim_kpi_Release/"
-                               ObjectFile=".\kbtim_kpi_Release/"
-                               ProgramDataBaseFileName=".\kbtim_kpi_Release/"
+                               AssemblerListingLocation=".\Release/"
+                               ObjectFile=".\Release/"
+                               ProgramDataBaseFileName=".\Release/"
                                WarningLevel="3"
                                SuppressStartupBanner="true"
                        />
                                BasicRuntimeChecks="3"
                                RuntimeLibrary="1"
                                PrecompiledHeaderFile=".\kbtim_kpi_Debug/kbtim_kpi.pch"
-                               AssemblerListingLocation=".\kbtim_kpi_Debug/"
-                               ObjectFile=".\kbtim_kpi_Debug/"
-                               ProgramDataBaseFileName=".\kbtim_kpi_Debug/"
+                               AssemblerListingLocation=".\Debug"
+                               ObjectFile=".\Debug"
+                               ProgramDataBaseFileName=".\Debug"
                                WarningLevel="3"
                                SuppressStartupBanner="true"
                                DebugInformationFormat="4"
index 09311df..79e97bf 100644 (file)
@@ -292,7 +292,9 @@ void config_gui_main_close(void)
        tmdy_free_config();
        //free_reverb_buffer();
        free_effect_buffers();
+#ifdef INT_SYNTH
        free_int_synth();
+#endif // INT_SYNTH
        free_voices();
        uninitialize_resampler_coeffs();
        for (i = 0; i < MAX_CHANNELS; i++)
index c6111d4..88e077f 100644 (file)
@@ -40,8 +40,8 @@
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories="..\interface;..\libarc;..\libunimod;..\timidity;..\utils;..\portaudio\pa_common;..\pdcurses;..\pdcurses\win32;..\portmidi\pm_common;..\portmidi\porttime;..;..\..\include;%(AdditionalIncludeDirectories)"
-                               PreprocessorDefinitions="WINDRV_SETUP;_WINDOWS;_DEBUG;WIN32;HAVE_CONFIG_H;_MT;"
+                               AdditionalIncludeDirectories="..\interface;..\libarc;..\libunimod;..\timidity;..\utils;..\portaudio\pa_common;..\pdcurses;..\pdcurses\win32;..\portmidi\pm_common;..\portmidi\porttime;..;..\..\include;..\rcpcv;%(AdditionalIncludeDirectories)"
+                               PreprocessorDefinitions="KBTIM_SETUP;_WINDOWS;_DEBUG;WIN32;HAVE_CONFIG_H;_MT;"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="3"
                                RuntimeLibrary="3"
@@ -60,7 +60,7 @@
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="wsock32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;"
+                               AdditionalDependencies="wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
                                OutputFile="../Debug/$(ProjectName).exe"
                                GenerateDebugInformation="true"
                                LargeAddressAware="2"
                                FavorSizeOrSpeed="1"
                                OmitFramePointers="true"
                                WholeProgramOptimization="true"
-                               AdditionalIncludeDirectories="..\interface;..\libarc;..\libunimod;..\timidity;..\utils;..\portaudio\pa_common;..\pdcurses;..\pdcurses\win32;..\portmidi\pm_common;..\portmidi\porttime;..;..\..\include;%(AdditionalIncludeDirectories)"
-                               PreprocessorDefinitions="NDEBUG;_WINDOWS;WIN32;WINDRV_SETUP;HAVE_CONFIG_H;_MT;"
+                               AdditionalIncludeDirectories="..\interface;..\libarc;..\libunimod;..\timidity;..\utils;..\portaudio\pa_common;..\pdcurses;..\pdcurses\win32;..\portmidi\pm_common;..\portmidi\porttime;..;..\..\include;..\rcpcv;%(AdditionalIncludeDirectories)"
+                               PreprocessorDefinitions="NDEBUG;_WINDOWS;WIN32;KBTIM_SETUP;HAVE_CONFIG_H;_MT;"
                                RuntimeLibrary="2"
                                StructMemberAlignment="5"
                                BufferSecurityCheck="false"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="wsock32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;"
+                               AdditionalDependencies="wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
                                OutputFile="..\Release\$(ProjectName).exe"
-                               IgnoreDefaultLibraryNames="libc.lib;"
+                               IgnoreDefaultLibraryNames="libc.lib;LIBCMT.lib;"
                                GenerateDebugInformation="false"
                                SubSystem="2"
                                LargeAddressAware="2"
                </Configuration>
        </Configurations>
        <References>
+               <ProjectReference
+                       ReferencedProjectIdentifier="{11CDD90A-20E1-45AF-879E-F355742B38B7}"
+                       RelativePathToProject=".\libarc\libarc.vcproj"
+               />
+               <ProjectReference
+                       ReferencedProjectIdentifier="{8DC8ADE3-145A-4C63-80DD-0C93B6587B80}"
+                       RelativePathToProject=".\libunimod\libunimod.vcproj"
+               />
+               <ProjectReference
+                       ReferencedProjectIdentifier="{B05F8AA0-6140-4335-AD39-E276D17002CB}"
+                       RelativePathToProject=".\utils\utils.vcproj"
+               />
        </References>
        <Files>
                <Filter
                                >
                        </File>
                        <File
+                               RelativePath="..\timidity\w32_a.c"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\interface\w32g_ini.c"
                                >
                        </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\mfnode.c"
-                                       >
-                               </File>
-                               <File
                                        RelativePath="..\timidity\miditrace.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\modmid_a.c"
-                                       >
-                               </File>
-                               <File
                                        RelativePath="..\timidity\mt19937ar.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\portaudio_a.c"
+                                       RelativePath="..\timidity\quantity.c"
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\quantity.c"
+                                       RelativePath="..\timidity\rcp.c"
                                        >
                                </File>
                                <File
                                        >
                                </File>
                                <File
+                                       RelativePath="..\timidity\smfconv.c"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\timidity\smplfile.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\w32_a.c"
-                                       >
-                               </File>
-                               <File
-                                       RelativePath="..\timidity\w32_portaudio_dll.c"
-                                       >
-                               </File>
-                               <File
                                        RelativePath="..\timidity\wrd_read.c"
                                        >
                                </File>
index df9b1b1..7871d07 100644 (file)
@@ -40,6 +40,7 @@
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>Windows7.1SDK</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>StaticLibrary</ConfigurationType>
index a22d02d..502bd70 100644 (file)
                </Configuration>
                <Configuration
                        Name="Release|Win32"
-                       OutputDirectory=".\Release"
+                       OutputDirectory="..\Release\"
                        IntermediateDirectory=".\Release"
                        ConfigurationType="1"
                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
                                OptimizeReferences="2"
                                EnableCOMDATFolding="2"
                                RandomizedBaseAddress="1"
-                               DataExecutionPrevention="0"
+                               DataExecutionPrevention="2"
                        />
                        <Tool
                                Name="VCALinkTool"
                                        >
                                </File>
                                <File
+                                       RelativePath="..\timidity\wasapi_a.c"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\timidity\wave_a.c"
                                        >
                                </File>
index 894af0d..1f9e762 100644 (file)
@@ -41,6 +41,7 @@
     <ConfigurationType>Application</ConfigurationType>
     <UseOfMfc>false</UseOfMfc>
     <CharacterSet>MultiByte</CharacterSet>
+    <PlatformToolset>Windows7.1SDK</PlatformToolset>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
       <AdditionalDependencies>comctl32.lib;winmm.lib;wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <OutputFile>$(TargetPath)</OutputFile>
       <SuppressStartupBanner>true</SuppressStartupBanner>
-      <IgnoreSpecificDefaultLibraries>LIBCMT.lib;libc.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+      <IgnoreSpecificDefaultLibraries>LIBCMTD.lib;libc.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ProgramDatabaseFile>.\Debug/timidity.pdb</ProgramDatabaseFile>
       <SubSystem>Console</SubSystem>
     </ResourceCompile>
     <Link>
       <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
-      <AdditionalDependencies>comctl32.lib;odbc32.lib;odbccp32.lib;winmm.lib;wsock32.lib;;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>comctl32.lib;odbc32.lib;odbccp32.lib;winmm.lib;wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <OutputFile>$(TargetPath)</OutputFile>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <AdditionalLibraryDirectories>../release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <AdditionalIncludeDirectories>..\interface;..\libarc;..\libunimod;..\timidity;..\utils;..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ResourceCompile>
     <Link>
-      <AdditionalDependencies>comctl32.lib;odbc32.lib;odbccp32.lib;winmm.lib;wsock32.lib;;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>comctl32.lib;odbc32.lib;odbccp32.lib;winmm.lib;wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <OutputFile>$(TargetPath)</OutputFile>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <AdditionalLibraryDirectories>../release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
     <ClCompile Include="..\timidity\w32_libOggFLAC_dll.c" />
     <ClCompile Include="..\timidity\w32_portaudio_dll.c" />
     <ClCompile Include="..\timidity\w32_soundspec.c" />
+    <ClCompile Include="..\timidity\wasapi_a.c" />
     <ClCompile Include="..\timidity\wave_a.c" />
     <ClCompile Include="..\timidity\wrdt.c" />
     <ClCompile Include="..\timidity\wrd_read.c" />
index bb6c6e4..b766a53 100644 (file)
@@ -63,7 +63,10 @@ int playlist_max = 1;
 int playlist_max_ini = 1;
 int ConsoleClearFlag = 0;
 
-DWORD syn_ThreadPriority;         // \83V\83\93\83Z\83X\83\8c\83b\83h\82Ì\83v\83\89\83C\83I\83\8a\83e\83B
+extern char *opt_reduce_voice_threshold;
+extern char *opt_reduce_quality_threshold;
+extern char *opt_reduce_polyphony_threshold;
+
 
 
 // HWND
@@ -330,7 +333,9 @@ void config_gui_main_close(void)
        tmdy_free_config();
        //free_reverb_buffer();
        free_effect_buffers();
+#ifdef INT_SYNTH
        free_int_synth();
+#endif // INT_SYNTH
        free_voices();
        uninitialize_resampler_coeffs();
        for (i = 0; i < MAX_CHANNELS; i++)
index b5726a7..950774a 100644 (file)
@@ -17,8 +17,8 @@
        <Configurations>
                <Configuration
                        Name="Debug|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
+                       OutputDirectory="..\Debug"
+                       IntermediateDirectory=".\Debug"
                        ConfigurationType="1"
                        CharacterSet="2"
                        >
@@ -40,7 +40,7 @@
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories="..\interface;..\libarc;..\libunimod;..\timidity;..\utils;..\portaudio\pa_common;..\pdcurses;..\pdcurses\win32;..\portmidi\pm_common;..\portmidi\porttime;..;..\..\include;%(AdditionalIncludeDirectories)"
+                               AdditionalIncludeDirectories="..\interface,..\libarc,..\libunimod,..\timidity,..\utils,..\portaudio\pa_common,..\pdcurses,..\pdcurses\win32,..\portmidi\pm_common,..\portmidi\porttime,..,..\..\include"
                                PreprocessorDefinitions="WINDRV_SETUP;_WINDOWS;_DEBUG;WIN32;HAVE_CONFIG_H;_MT;"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="3"
@@ -60,8 +60,8 @@
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="wsock32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;"
-                               OutputFile="../Debug/$(ProjectName).exe"
+                               AdditionalDependencies="wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"
+                               OutputFile="..\Debug\timdrvsetup.exe"
                                IgnoreDefaultLibraryNames="libc.lib;"
                                GenerateDebugInformation="true"
                                SubSystem="2"
@@ -92,8 +92,8 @@
                </Configuration>
                <Configuration
                        Name="Release|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
+                       OutputDirectory="..\Release\"
+                       IntermediateDirectory="..\Release\timdrvsetup\"
                        ConfigurationType="1"
                        CharacterSet="2"
                        WholeProgramOptimization="1"
                                EnableIntrinsicFunctions="true"
                                FavorSizeOrSpeed="1"
                                OmitFramePointers="true"
-                               AdditionalIncludeDirectories="..\interface;..\libarc;..\libunimod;..\timidity;..\utils;..\portaudio\pa_common;..\pdcurses;..\pdcurses\win32;..\portmidi\pm_common;..\portmidi\porttime;..;..\..\include;%(AdditionalIncludeDirectories)"
+                               AdditionalIncludeDirectories="..\interface,..\libarc,..\libunimod,..\timidity,..\utils,..\portaudio\pa_common,..\pdcurses,..\pdcurses\win32,..\portmidi\pm_common,..\portmidi\porttime,..,..\..\include"
                                PreprocessorDefinitions="NDEBUG;_WINDOWS;WIN32;WINDRV_SETUP;HAVE_CONFIG_H;_MT;"
+                               ExceptionHandling="0"
                                RuntimeLibrary="2"
                                StructMemberAlignment="5"
                                BufferSecurityCheck="false"
                                EnableFunctionLevelLinking="true"
                                EnableEnhancedInstructionSet="2"
                                FloatingPointModel="2"
-                               WarningLevel="3"
-                               DebugInformationFormat="3"
+                               WarningLevel="1"
+                               DebugInformationFormat="0"
                                CompileAs="1"
                        />
                        <Tool
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="wsock32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;"
-                               OutputFile="..\Release\$(ProjectName).exe"
-                               EnableUAC="false"
-                               IgnoreDefaultLibraryNames="libc.lib;"
+                               AdditionalDependencies="odbc32.lib odbccp32.lib winmm.lib wsock32.lib comctl32.lib"
+                               ShowProgress="1"
+                               OutputFile="..\Release\timdrvsetup.exe"
+                               LinkIncremental="1"
+                               EnableUAC="true"
+                               IgnoreDefaultLibraryNames="libc.lib;LIBCMT.lib;"
                                GenerateDebugInformation="false"
                                SubSystem="2"
                                LargeAddressAware="2"
                </Configuration>
        </Configurations>
        <References>
+               <ProjectReference
+                       ReferencedProjectIdentifier="{11CDD90A-20E1-45AF-879E-F355742B38B7}"
+                       RelativePathToProject=".\libarc\libarc.vcproj"
+               />
+               <ProjectReference
+                       ReferencedProjectIdentifier="{8DC8ADE3-145A-4C63-80DD-0C93B6587B80}"
+                       RelativePathToProject=".\libunimod\libunimod.vcproj"
+               />
+               <ProjectReference
+                       ReferencedProjectIdentifier="{B05F8AA0-6140-4335-AD39-E276D17002CB}"
+                       RelativePathToProject=".\utils\utils.vcproj"
+               />
        </References>
        <Files>
                <Filter
                        <Filter
                                Name="timidity"
                                >
+                               <File
+                                       RelativePath="..\timidity\portaudio_a.h"
+                                       >
+                               </File>
                        </Filter>
                </Filter>
                <Filter
                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
                        >
                        <File
-                               RelativePath="..\interface\dumb_c.c"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\interface\rtsyn_common.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\timidity\w32_portaudio_dll.c"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\interface\w32g_ini.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\interface\w32g_syn.c"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\interface\w32g_utl.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\interface\winsyn_c.c"
+                               >
+                       </File>
                        <Filter
                                Name="timidity"
                                >
                                        >
                                </File>
                                <File
+                                       RelativePath="..\interface\dumb_c.c"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\timidity\effect.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\modmid_a.c"
-                                       >
-                               </File>
-                               <File
                                        RelativePath="..\timidity\mt19937ar.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
+                                       RelativePath="..\timidity\rcp.c"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\timidity\readmidi.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
+                                       RelativePath="..\timidity\smfconv.c"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\timidity\smplfile.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\w32_portaudio_dll.c"
+                                       RelativePath="..\timidity\wasapi_a.c"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\timidity\wave_a.c"
                                        >
                                </File>
                                <File
                        Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
                        UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
                        >
+                       <File
+                               RelativePath="..\interface\w32g_icon.ico"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\interface\w32g_res.rc"
+                               >
+                       </File>
                </Filter>
        </Files>
        <Globals>
index 2db721e..eb6441d 100644 (file)
     <ClCompile Include="..\timidity\loadtab.c" />
     <ClCompile Include="..\timidity\m2m.c" />
     <ClCompile Include="..\timidity\mfi.c" />
+    <ClCompile Include="..\timidity\mfnode.c" />
     <ClCompile Include="..\timidity\miditrace.c" />
     <ClCompile Include="..\timidity\mix.c" />
     <ClCompile Include="..\timidity\mod.c" />
     <ClCompile Include="..\timidity\voice_effect.c" />
     <ClCompile Include="..\timidity\w32_a.c" />
     <ClCompile Include="..\timidity\w32_portaudio_dll.c" />
+    <ClCompile Include="..\timidity\wasapi_a.c" />
     <ClCompile Include="..\timidity\wave_a.c" />
     <ClCompile Include="..\timidity\wrdt.c" />
     <ClCompile Include="..\timidity\wrd_read.c" />
index 447ced5..e3c2348 100644 (file)
@@ -54,7 +54,7 @@
 #define TEST_SPARE_RATE 0.9
 #define MAX_BUCKET_TIME 0.5
 ///r
-#define MAX_FILLED_TIME 3000.0 // def 2.0
+#define MAX_FILLED_TIME 2000.0 // def 2.0
 
 
 static int32 device_qsize;
@@ -106,6 +106,8 @@ int aq_calc_fragsize(void)
        bps = get_encoding_sample_size(play_mode->encoding);
     bs = audio_buffer_size * bps;
     dq = play_mode->rate * MAX_FILLED_TIME * bps;
+       if(dq > INT32_MAX) // 2GB // c212
+               dq = INT32_MAX;
     while(bs * 2 > dq)
        bs /= 2;
 
@@ -210,8 +212,12 @@ static int32 estimate_queue_size(void)
        general_output_convert((DATA_T*)nullsound, bucket_size / Bps);
     tb = play_mode->rate * Bps * TEST_SPARE_RATE;
     ntries = 1;
-    max_qbytes = play_mode->rate * MAX_FILLED_TIME * Bps;
-
+       { // c212
+               int64 tmp = play_mode->rate * MAX_FILLED_TIME * Bps;
+               if(tmp > INT32_MAX) // 2GB
+                       tmp = INT32_MAX;
+               max_qbytes = tmp;
+       }
   retry:
     chunktime = (double)bucket_size / Bps * div_playmode_rate;
     qbytes = 0;
@@ -251,7 +257,11 @@ static int32 estimate_queue_size(void)
                        ctl->cmsg(CMSG_ERROR, VERB_NOISY,
                                  "Can't estimate audio queue length");
                        set_bucket_size(audio_buffer_size * Bps);
+#ifdef ALIGN_SIZE
+                       aligned_free(nullsound);
+#else
                        free(nullsound);
+#endif
                        return 2 * audio_buffer_size * Bps;
                }
 
@@ -293,8 +303,6 @@ static int aq_output_data(uint8 *buff, int nbytes)
     return 0;
 }
 
-extern void do_effect2(uint8 *buf, int32 count); // effect.c
-
 int aq_add(DATA_T *samples, int32 count)
 {
     int32 nbytes, i;
@@ -313,10 +321,12 @@ int aq_add(DATA_T *samples, int32 count)
        aq_add_count += count;
     nbytes = general_output_convert(samples, count);
     buff = (uint8 *)samples;
-    do_effect2(buff, count);
-
-    if(device_qsize == 0 || nbuckets == 0)
-      return play_mode->output_data(buff, nbytes);
+///r c212
+    if(device_qsize == 0 || nbuckets == 0){ // thru audio_queue 
+               trace_loop();
+               play_counter += count;
+               return play_mode->output_data(buff, nbytes);
+       }
 
     aq_fill_buffer_flag = (aq_add_count <= aq_start_count);
 
index 20e2514..32f9ddb 100644 (file)
@@ -365,10 +365,9 @@ static inline void do_chorus_vst(DATA_T *buf, int32 count)
 
 ///// Master VST
 #ifdef VST_LOADER_ENABLE
-//#define MASTER_VST_EFFECT2 // \8fo\97Í\95Ï\8a·\8cã\82É Master VST
-#ifndef MASTER_VST_EFFECT2 // \8fo\97Í\95Ï\8a·\91O\82ÉVST
 /*
-\8fo\97Í\83r\83b\83g\82É\8aÖ\8cW\82È\82­double/float/int32\82ÅVST\82É\93n\82é
+\8fo\97Í\95Ï\8a·\91O\82ÉVST
+\8fo\97Í\83r\83b\83g\82É\8aÖ\8cW\82È\82­DATA_T\8c^ (double/float/int32)\82ÅVST\82É\93n\82é
 DATA_T_DOUBLE\82Ì\8fê\8d\87 VSTWRAP_EXT\82Ì\8fê\8d\87
        (double conv) (VST) (double conv) // GUARD_BITS\82Ì\83\8c\83x\83\8b\95Ï\8dX
 DATA_T_DOUBLE\82Ì\8fê\8d\87
@@ -450,53 +449,6 @@ static inline void do_master_vst(DATA_T *buf, int32 nsamples, int mono)
        /* TODO */
 #endif /* __W32__ */
 }
-
-#else // MASTER_VST_EFFECT2 // \8fo\97Í\95Ï\8a·\8cã\82ÉVST 
-/*
-\8fo\97Í\83r\83b\83g\82ÅVST\82É\93n\82é
-\8fo\97Í\89¹\97Ê\82Æ\82Ì\88Ê\92u\8aÖ\8cW\82ª\95Ï\82í\82é
-*/
-static inline void do_master_vst(uint8 *buf, int32 count, int mono)
-{
-       if (!hVSTHost || samples == NULL || nsamples <= 0)
-               return;
-       if (play_mode->encoding & PE_16BIT){
-               if (mono)
-                       ((mix_vst_effect16)GetProcAddress(hVSTHost, "effectProcessingInt16Mono"))((short *)buff, count, vst_samplerate);
-               else
-                       ((mix_vst_effect16)GetProcAddress(hVSTHost, "effectProcessingInt16"))((short *)buff, count*2, vst_samplerate);
-       }else if (play_mode->encoding & PE_24BIT){
-               if (mono)
-                       ((mix_vst_effect24)GetProcAddress(hVSTHost, "effectProcessingInt24Mono"))((char *)buff, count, vst_samplerate);
-               else
-                       ((mix_vst_effect24)GetProcAddress(hVSTHost, "effectProcessingInt24"))((char *)buff, count*2, vst_samplerate);
-       }else if (play_mode->encoding & PE_32BIT){
-               if (mono)
-                       ((mix_vst_effect32)GetProcAddress(hVSTHost, "effectProcessingInt32Mono"))((long *)buff, count, vst_samplerate);
-               else
-                       ((mix_vst_effect32)GetProcAddress(hVSTHost, "effectProcessingInt32"))((long *)buff, count*2, vst_samplerate);
-       }else if (play_mode->encoding & PE_F32BIT){
-               if (mono)
-                       ((mix_vst_effectF)GetProcAddress(hVSTHost, "effectProcessingFloatMono"))((float *)buff, count, vst_samplerate);
-               else
-                       ((mix_vst_effectF)GetProcAddress(hVSTHost, "effectProcessingFloat"))((float *)buff, count*2, vst_samplerate);
-       }
-#if defined(VSTWRAP_EXT) // if support effectProcessing int64/double
-       else if (play_mode->encoding & PE_64BIT){
-               if (mono)
-                       ((mix_vst_effect64)GetProcAddress(hVSTHost, "effectProcessingInt64Mono"))((int64 *)buff, count, vst_samplerate);
-               else
-                       ((mix_vst_effect64)GetProcAddress(hVSTHost, "effectProcessingInt64"))((int64 *)buff, count*2, vst_samplerate);
-       }
-       else if (play_mode->encoding & PE_F64BIT){
-               if (mono)
-                       ((mix_vst_effectD)GetProcAddress(hVSTHost, "effectProcessingDoubleMono"))((double *)buff, count, vst_samplerate);
-               else
-                       ((mix_vst_effectD)GetProcAddress(hVSTHost, "effectProcessingDouble"))((double *)buff, count*2, vst_samplerate);
-       }
-#endif
-}
-#endif /* MASTER_VST_EFFECT2 */
 #endif /* VST_LOADER_ENABLE */
 
 ///// Channel VST
@@ -638,11 +590,9 @@ static void init_vst_effect(void)
                          "%s could not be found in %s", funcname, libname);
                error++;
        }
-#ifndef MASTER_VST_EFFECT2 // \8fo\97Í\95Ï\8a·\91O\82ÉVST
 #if (!defined(VSTWRAP_EXT) && defined(DATA_T_DOUBLE)) || (!defined(DATA_T_DOUBLE) && !defined(DATA_T_FLOAT))
        memset(pre_vst_buffer, 0, sizeof(pre_vst_buffer));
 #endif
-#endif /* MASTER_VST_EFFECT2 */
 
        // Channel VST  
 #if defined(VSTWRAP_EXT) // support float/double
@@ -15697,6 +15647,7 @@ static void do_gate_reverb(DATA_T *buf, int32 count, InfoGateReverb *info)
        // gate
        gate_out = get_gate_level(&info->gate, cnt);
        switch(info->type){
+       default:
        case 0: // normal
                gateL = gate_out;
                gateR = gate_out;
@@ -24349,6 +24300,7 @@ static double ins_xg_revchar_to_rt(struct effect_xg_t *st)
 {
        double rt;
        switch(st->type_msb) {
+       default:
        case 0x01:
                switch(st->type_lsb) {
                default:
@@ -35733,23 +35685,12 @@ void do_effect(DATA_T *buf, int32 count)
                do_limiter(buf, count);
 ///r
 #ifdef VST_LOADER_ENABLE
-#ifndef MASTER_VST_EFFECT2
        do_master_vst(buf, nsamples, mono);
-#endif /* MASTER_VST_EFFECT2 */
 #endif /* VST_LOADER_ENABLE */
        
 }
 
 
-void do_effect2(uint8 *buf, int32 count)
-{
-#ifdef VST_LOADER_ENABLE
-#ifdef MASTER_VST_EFFECT2
-       do_master_vst(buf, count, play_mode->encoding & PE_MONO);
-#endif /* MASTER_VST_EFFECT2 */
-#endif /* VST_LOADER_ENABLE */
-}
-
 
 /************************************ inialize_effect ***************************************/
 
index aec0155..303002e 100644 (file)
@@ -2997,8 +2997,6 @@ extern void free_effect_list(EffectList *);
 extern void free_effect_buffers(void);
 extern void init_effect(void);
 extern void do_effect(DATA_T *buf, int32 count);
-extern void do_effect2(uint8 *buf, int32 count);
-
 
 /* effect util */
 extern void set_dry_signal_int32(int32 *, int32);
@@ -3006,7 +3004,6 @@ extern void set_dry_signal(DATA_T *, int32);
 extern void set_dry_signal_xg(DATA_T *, int32, int32);
 extern void mix_dry_signal(DATA_T *, int32);
 
-
 /* effect control */
 extern double voice_filter_reso;
 extern double voice_filter_gain;
index 48fb3d1..7b5d045 100644 (file)
@@ -2229,236 +2229,263 @@ static void conv_preset_envelope_param(int max, int32 *env, int16 *velf, int16 *
        keyf[0] = keyf[0]; // atk time
 }
 
-// type -1:scc/mms 0:scc 1:mms , preset -1:all 0~:num
-static void conv_preset_envelope(Preset_IS *is_set, int type, int preset)
+static void load_is_scc_data(INIDATA *ini, Preset_IS *set)
 {
-       int i, j;
-       
-       if(type < 0 || type == 0){
-               for(i = 0; i < SCC_SETTING_MAX; i++){
-                       Preset_SCC *set = NULL;
-                       if(preset >= 0 && i != preset)
-                               continue;
-                       if(!is_set->scc_setting[i])
-                               continue;
-                       set = is_set->scc_setting[i];
-                       conv_preset_envelope_param(SCC_ENV_PARAM, set->ampenv, NULL, NULL);
-                       conv_preset_envelope_param(SCC_ENV_PARAM, set->pitenv, NULL, NULL);
-               }
-       }
-       if(type < 0 || type == 1){
-               for(i = 0; i < MMS_SETTING_MAX; i++){
-                       Preset_MMS *set = NULL;
-                       if(preset >= 0 && i != preset)
-                               continue;
-                       if(!is_set->mms_setting[i])
-                               continue;
-                       set = is_set->mms_setting[i];
-                       for(j = 0; j < MMS_OP_MAX; j++){
-                               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set->op_ampenv[j], set->op_ampenv_velf[j], set->op_ampenv_keyf[j]);
-                               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set->op_modenv[j], set->op_modenv_velf[j], set->op_modenv_keyf[j]);
-                               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set->op_widenv[j], set->op_widenv_velf[j], set->op_widenv_keyf[j]);
-                               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set->op_pitenv[j], set->op_pitenv_velf[j], set->op_pitenv_keyf[j]);
-                       }
-               }
+       LPINISEC sec = NULL;
+       TCHAR tbf[258] = "";
+       char *p = NULL;
+       char name[30] = "";
+       char name2[30] = "";
+       int i;
+
+       sec = MyIni_GetSection(ini, "SCC_DATA", 0);
+       for(i = 0; i < SCC_DATA_MAX; i++){
+               snprintf(name, sizeof(name), "data_%03d", i); // \8c\85\90\94\8ew\92è
+               snprintf(name2, sizeof(name2), "name_%03d", i); // \8c\85\90\94\8ew\92è
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0");
+               config_parse_scc_data(p, set, i);       
+               p = MyIni_GetString(sec, name2, tbf, 256, "none");
+               if(set->scc_data_name[i] != NULL)
+                       safe_free(set->scc_data_name[i]);
+               set->scc_data_name[i] = safe_strdup(p);
        }
 }
 
-// type -1:ascc/mms 0:scc 1:mms , preset -1:all 0~:num
-void load_int_synth_preset(const char *inifile, Preset_IS *set, int type, int preset)
+static void load_is_scc_preset(INIDATA *ini, Preset_IS *set, int preset, int init)
+{
+       LPINISEC sec = NULL;
+       TCHAR tbf[258] = "";
+       char *p = NULL;
+       char name[30] = "";
+       char name2[30] = "";
+       void *mem = NULL;
+       int i = preset;
+       Preset_SCC *set2 = NULL;
+       
+       snprintf(name, sizeof(name), "SCC_%03d", i); // \8c\85\90\94\8ew\92è
+       sec = MyIni_GetSection(ini, name, 0);
+       if(sec == NULL && !init)
+               return;
+       mem = safe_malloc(sizeof(Preset_SCC));
+       if(!mem)
+               return;
+       memset(mem, 0, sizeof(Preset_SCC));
+       set->scc_setting[i] = (Preset_SCC *)mem;
+       set2 = set->scc_setting[i];
+       p = MyIni_GetString(sec, "name", tbf, 256, "SCC none");
+//     snprintf(name, sizeof(name), "[SCC] %s", p);
+       if(set->scc_setting[i]->inst_name != NULL)
+               safe_free(set->scc_setting[i]->inst_name);
+//     scc_setting[i].inst_name = safe_strdup(name);
+       set->scc_setting[i]->inst_name = safe_strdup(p);
+       p = MyIni_GetString(sec, "param", tbf, 256, "100:0");
+       config_parse_scc_param(p, set, i);
+       p = MyIni_GetString(sec, "osc", tbf, 256, "0:100:0:0");
+       config_parse_scc_osc(p, set, i);
+       p = MyIni_GetString(sec, "amp", tbf, 256, "0:0:0");
+       config_parse_scc_amp(p, set, i);
+       p = MyIni_GetString(sec, "pitch", tbf, 256, "0:0:0");
+       config_parse_scc_pitch(p, set, i);
+#define IS_SCC_ENV_DEFAULT "0:0:100:0:0:0:0:0:0:0:0:0:0:0"
+       p = MyIni_GetString(sec, "ampenv", tbf, 256, IS_SCC_ENV_DEFAULT);
+       config_parse_scc_ampenv(p, set, i);
+       p = MyIni_GetString(sec, "pitenv", tbf, 256, IS_SCC_ENV_DEFAULT);
+       config_parse_scc_pitenv(p, set, i);
+#define IS_SCC_LFO_DEFAULT "0:0:0:200"
+       p = MyIni_GetString(sec, "lfo1", tbf, 256, IS_SCC_LFO_DEFAULT);
+       config_parse_scc_lfo1(p, set, i);
+       p = MyIni_GetString(sec, "lfo2", tbf, 256, IS_SCC_LFO_DEFAULT);
+       config_parse_scc_lfo2(p, set, i);
+       // conv_preset_envelope
+       conv_preset_envelope_param(SCC_ENV_PARAM, set2->ampenv, NULL, NULL);
+       conv_preset_envelope_param(SCC_ENV_PARAM, set2->pitenv, NULL, NULL);
+}
+       
+static void load_is_mms_preset(INIDATA *ini, Preset_IS *set, int preset, int init)
 {
-       INIDATA ini={0};
        LPINISEC sec = NULL;
        TCHAR tbf[258] = "";
        char *p = NULL;
        char name[30] = "";
        char name2[30] = "";
-       int i, j, k, param;
+       void *mem = NULL;
+       int i = preset, j, k, param;
+       Preset_MMS *set2 = NULL;
+       
+       snprintf(name, sizeof(name), "MMS_%03d", i); // \8c\85\90\94\8ew\92è
+       sec = MyIni_GetSection(ini, name, 0);
+       if(sec == NULL && !init)
+               return;
+       mem = safe_malloc(sizeof(Preset_MMS));
+       if(!mem)
+               return;
+       memset(mem, 0, sizeof(Preset_MMS));
+       set->mms_setting[i] = (Preset_MMS *)mem;
+       set2 = set->mms_setting[i];
+       p = MyIni_GetString(sec, "name", tbf, 256, "MMS none");
+//     snprintf(name, sizeof(name), "[MMS] %s", p);
+       if(set->mms_setting[i]->inst_name != NULL)
+               safe_free(set->mms_setting[i]->inst_name);
+//     set->mms_setting[i].inst_name = safe_strdup(name);
+       set->mms_setting[i]->inst_name = safe_strdup(p);
+       set->mms_setting[i]->op_max = MyIni_GetInt32(sec, "op_max", 1);
+       for(j = 0; j < MMS_OP_MAX; j++){
+               snprintf(name, sizeof(name), "op_%d_param", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0");
+               config_parse_mms_op_param(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_range", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:127:0:127");
+               config_parse_mms_op_range(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_connect", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "-1");
+               config_parse_mms_op_connect(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_osc", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:100:0:0");
+               config_parse_mms_op_osc(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_wave", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:100:0:0:0");
+               config_parse_mms_op_wave(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_sub", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
+               config_parse_mms_op_sub(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_amp", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
+               config_parse_mms_op_amp(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_pitch", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
+               config_parse_mms_op_pitch(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_width", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
+               config_parse_mms_op_width(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_filter", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
+               config_parse_mms_op_filter(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_cutoff", j);
+               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
+               config_parse_mms_op_cutoff(p, set, i, j);
+#define IS_MMS_ENV_DEFAULT "0:0:100:0:0:0:0:0:0:0:0:0:0:0"
+               snprintf(name, sizeof(name), "op_%d_ampenv", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
+               config_parse_mms_op_ampenv(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_modenv", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
+               config_parse_mms_op_modenv(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_widenv", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
+               config_parse_mms_op_widenv(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_pitenv", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
+               config_parse_mms_op_pitenv(p, set, i, j);
+#define IS_MMS_ENVF_DEFAULT "0:0:0:0:0:0:0:0:0:0:0:0:0:0"
+               snprintf(name, sizeof(name), "op_%d_ampenv_keyf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_ampenv_keyf(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_modenv_keyf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_modenv_keyf(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_widenv_keyf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_widenv_keyf(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_pitenv_keyf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_pitenv_keyf(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_ampenv_velf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_ampenv_velf(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_modenv_velf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_modenv_velf(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_widenv_velf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_widenv_velf(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_pitenv_velf", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
+               config_parse_mms_op_pitenv_velf(p, set, i, j);
+#define IS_MMS_LFO_DEFAULT "0:0:0:200"
+               snprintf(name, sizeof(name), "op_%d_lfo1", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
+               config_parse_mms_op_lfo1(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_lfo2", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
+               config_parse_mms_op_lfo2(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_lfo3", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
+               config_parse_mms_op_lfo3(p, set, i, j);
+               snprintf(name, sizeof(name), "op_%d_lfo4", j);
+               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
+               config_parse_mms_op_lfo4(p, set, i, j);
+               // conv_preset_envelop
+               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set2->op_ampenv[j], set2->op_ampenv_velf[j], set2->op_ampenv_keyf[j]);
+               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set2->op_modenv[j], set2->op_modenv_velf[j], set2->op_modenv_keyf[j]);
+               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set2->op_widenv[j], set2->op_widenv_velf[j], set2->op_widenv_keyf[j]);
+               conv_preset_envelope_param(MMS_OP_ENV_PARAM, set2->op_pitenv[j], set2->op_pitenv_velf[j], set2->op_pitenv_keyf[j]);
+       }
+}
+
+// type -1:scc/mms 0:scc 1:mms , preset -1:all 0~:num
+static void load_int_synth_preset(const char *inifile, Preset_IS *set, int type, int32 preset, int init)
+{
+       INIDATA ini={0};
+       int i;
        
        MyIni_Load_timidity(&ini, inifile, 1, OF_VERBOSE);
        if(!set->scc_data_load){
                set->scc_data_load = 1;
-               sec = MyIni_GetSection(&ini, "SCC_DATA", 0);
-               for(i = 0; i < SCC_DATA_MAX; i++){
-                       if(i < 10){
-                               snprintf(name, sizeof(name), "data_00%d", i); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-                               snprintf(name2, sizeof(name2), "name_00%d", i); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-                       }else if(i < 100){
-                               snprintf(name, sizeof(name), "data_0%d", i);
-                               snprintf(name2, sizeof(name2), "name_0%d", i);
-                       }else{
-                               snprintf(name, sizeof(name), "data_%d", i);
-                               snprintf(name2, sizeof(name2), "name_%d", i);   
+               load_is_scc_data(&ini, set);
+       }
+       if(type == IS_INI_TYPE_ALL || type == IS_INI_TYPE_SCC){
+               if(preset == IS_INI_PRESET_ALL){
+                       for(i = 0; i < SCC_SETTING_MAX; i++){
+                               if(set->scc_setting[i])
+                                       continue;
+                               load_is_scc_preset(&ini, set, i, init);
                        }
-                       p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0");
-                       config_parse_scc_data(p, set, i);       
-                       p = MyIni_GetString(sec, name2, tbf, 256, "none");
-                       if(set->scc_data_name[i] != NULL)
-                               safe_free(set->scc_data_name[i]);
-                       set->scc_data_name[i] = safe_strdup(p);
+               }else if(preset < SCC_SETTING_MAX){                     
+                       if(!set->scc_setting[preset])
+                               load_is_scc_preset(&ini, set, preset, init);
                }
-       }
-       if(type < 0 || type == 0){
-               for(i = 0; i < SCC_SETTING_MAX; i++){
-                       void *mem = NULL;
-                       if(preset >= 0 && i != preset)
-                               continue;
-                       if(set->scc_setting[i])
-                               continue;
-                       mem = safe_malloc(sizeof(Preset_SCC));
-                       if(!mem)
-                               continue;
-                       memset(mem, 0, sizeof(Preset_SCC));
-                       set->scc_setting[i] = (Preset_SCC *)mem;
-                       if(i < 10)
-                               snprintf(name, sizeof(name), "SCC_00%d", i); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-                       else if(i < 100)
-                               snprintf(name, sizeof(name), "SCC_0%d", i);
-                       else
-                               snprintf(name, sizeof(name), "SCC_%d", i);
-                       sec = MyIni_GetSection(&ini, name, 0);
-                       p = MyIni_GetString(sec, "name", tbf, 256, "SCC none");
-               //      snprintf(name, sizeof(name), "[SCC] %s", p);
-                       if(set->scc_setting[i]->inst_name != NULL)
-                               safe_free(set->scc_setting[i]->inst_name);
-               //      scc_setting[i].inst_name = safe_strdup(name);
-                       set->scc_setting[i]->inst_name = safe_strdup(p);
-                       p = MyIni_GetString(sec, "param", tbf, 256, "100:0");
-                       config_parse_scc_param(p, set, i);
-                       p = MyIni_GetString(sec, "osc", tbf, 256, "0:100:0:0");
-                       config_parse_scc_osc(p, set, i);
-                       p = MyIni_GetString(sec, "amp", tbf, 256, "0:0:0");
-                       config_parse_scc_amp(p, set, i);
-                       p = MyIni_GetString(sec, "pitch", tbf, 256, "0:0:0");
-                       config_parse_scc_pitch(p, set, i);
-#define IS_SCC_ENV_DEFAULT "0:0:100:0:0:0:0:0:0:0:0:0:0:0"
-                       p = MyIni_GetString(sec, "ampenv", tbf, 256, IS_SCC_ENV_DEFAULT);
-                       config_parse_scc_ampenv(p, set, i);
-                       p = MyIni_GetString(sec, "pitenv", tbf, 256, IS_SCC_ENV_DEFAULT);
-                       config_parse_scc_pitenv(p, set, i);
-#define IS_SCC_LFO_DEFAULT "0:0:0:200"
-                       p = MyIni_GetString(sec, "lfo1", tbf, 256, IS_SCC_LFO_DEFAULT);
-                       config_parse_scc_lfo1(p, set, i);
-                       p = MyIni_GetString(sec, "lfo2", tbf, 256, IS_SCC_LFO_DEFAULT);
-                       config_parse_scc_lfo2(p, set, i);
+#ifdef IS_INI_LOAD_BLOCK
+               else if(preset > 0){     
+                       int32 block = (preset >> 10) - 1; // 10bit>SETTING_MAX
+                       int32 min = block * IS_INI_LOAD_BLOCK; // 1block=64or128preset
+                       int32 max = min + IS_INI_LOAD_BLOCK; // 1block=64or128preset
+                       if(max > SCC_SETTING_MAX) 
+                               max = SCC_SETTING_MAX;
+                       for(i = min; i < max; i++){
+                               if(set->scc_setting[i])
+                                       continue;
+                               load_is_scc_preset(&ini, set, i, init);
+                       }
                }
+#endif
        }
-       if(type < 0 || type == 1){
-               for(i = 0; i < MMS_SETTING_MAX; i++){
-                       void *mem = NULL;
-                       if(preset >= 0 && i != preset)
-                               continue;
-                       if(set->mms_setting[i])
-                               continue;
-                       mem = safe_malloc(sizeof(Preset_MMS));
-                       if(!mem)
-                               continue;
-                       memset(mem, 0, sizeof(Preset_MMS));
-                       set->mms_setting[i] = (Preset_MMS *)mem;
-                       if(i < 10)
-                               snprintf(name, sizeof(name), "MMS_00%d", i); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-                       else if(i < 100)
-                               snprintf(name, sizeof(name), "MMS_0%d", i);
-                       else
-                               snprintf(name, sizeof(name), "MMS_%d", i);
-                       sec = MyIni_GetSection(&ini, name, 0);
-                       p = MyIni_GetString(sec, "name", tbf, 256, "MMS none");
-               //      snprintf(name, sizeof(name), "[MMS] %s", p);
-                       if(set->mms_setting[i]->inst_name != NULL)
-                               safe_free(set->mms_setting[i]->inst_name);
-               //      set->mms_setting[i].inst_name = safe_strdup(name);
-                       set->mms_setting[i]->inst_name = safe_strdup(p);
-                       set->mms_setting[i]->op_max = MyIni_GetInt32(sec, "op_max", 1);
-                       for(j = 0; j < MMS_OP_MAX; j++){
-                               snprintf(name, sizeof(name), "op_%d_param", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0");
-                               config_parse_mms_op_param(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_range", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:127:0:127");
-                               config_parse_mms_op_range(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_connect", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "-1");
-                               config_parse_mms_op_connect(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_osc", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:100:0:0");
-                               config_parse_mms_op_osc(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_wave", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:0:100:0:0:0");
-                               config_parse_mms_op_wave(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_sub", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
-                               config_parse_mms_op_sub(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_amp", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
-                               config_parse_mms_op_amp(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_pitch", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
-                               config_parse_mms_op_pitch(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_width", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
-                               config_parse_mms_op_width(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_filter", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
-                               config_parse_mms_op_filter(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_cutoff", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, "0:0:0:0");
-                               config_parse_mms_op_cutoff(p, set, i, j);
-#define IS_MMS_ENV_DEFAULT "0:0:100:0:0:0:0:0:0:0:0:0:0:0"
-                               snprintf(name, sizeof(name), "op_%d_ampenv", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
-                               config_parse_mms_op_ampenv(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_modenv", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
-                               config_parse_mms_op_modenv(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_widenv", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
-                               config_parse_mms_op_widenv(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_pitenv", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENV_DEFAULT);
-                               config_parse_mms_op_pitenv(p, set, i, j);
-#define IS_MMS_ENVF_DEFAULT "0:0:0:0:0:0:0:0:0:0:0:0:0:0"
-                               snprintf(name, sizeof(name), "op_%d_ampenv_keyf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_ampenv_keyf(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_modenv_keyf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_modenv_keyf(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_widenv_keyf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_widenv_keyf(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_pitenv_keyf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_pitenv_keyf(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_ampenv_velf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_ampenv_velf(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_modenv_velf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_modenv_velf(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_widenv_velf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_widenv_velf(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_pitenv_velf", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_ENVF_DEFAULT);
-                               config_parse_mms_op_pitenv_velf(p, set, i, j);
-#define IS_MMS_LFO_DEFAULT "0:0:0:200"
-                               snprintf(name, sizeof(name), "op_%d_lfo1", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
-                               config_parse_mms_op_lfo1(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_lfo2", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
-                               config_parse_mms_op_lfo2(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_lfo3", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
-                               config_parse_mms_op_lfo3(p, set, i, j);
-                               snprintf(name, sizeof(name), "op_%d_lfo4", j);
-                               p = MyIni_GetString(sec, name, tbf, 256, IS_MMS_LFO_DEFAULT);
-                               config_parse_mms_op_lfo4(p, set, i, j);
+       if(type == IS_INI_TYPE_ALL || type == IS_INI_TYPE_MMS){
+               if(preset == IS_INI_PRESET_ALL){
+                       for(i = 0; i < MMS_SETTING_MAX; i++){
+                               if(set->mms_setting[i])
+                                       continue;
+                               load_is_mms_preset(&ini, set, i, init);
+                       }
+               }else if(preset < MMS_SETTING_MAX){     
+                       if(!set->mms_setting[preset])
+                               load_is_mms_preset(&ini, set, preset, init);
+               }
+#ifdef IS_INI_LOAD_BLOCK
+               else if(preset > 0){     
+                       int32 block = (preset >> 10) - 1; // 10bit>SETTING_MAX
+                       int32 min = block * IS_INI_LOAD_BLOCK; // 1block=64or128preset
+                       int32 max = min + IS_INI_LOAD_BLOCK; // 1block=64or128preset
+                       if(max > MMS_SETTING_MAX)
+                               max = MMS_SETTING_MAX;
+                       for(i = min; i < max; i++){
+                               if(set->mms_setting[i])
+                                       continue;
+                               load_is_mms_preset(&ini, set, i, init);
                        }
                }
+#endif
        }
        MyIni_SectionAllClear(&ini);
-       conv_preset_envelope(set, type, preset);
 }
        
 
@@ -2530,17 +2557,9 @@ static void scc_data_editor_save_ini(int num)
        char key2[30] = "";
        int i;
 
-       MyIni_Load(&ini, is_editor_inifile);    
-       if(num < 10){
-               snprintf(key1, sizeof(key1), "data_00%d", num); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-               snprintf(key2, sizeof(key2), "name_00%d", num); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-       }else if(num < 100){
-               snprintf(key1, sizeof(key1), "data_0%d", num);
-               snprintf(key2, sizeof(key2), "name_0%d", num);
-       }else{
-               snprintf(key1, sizeof(key1), "data_%d", num);
-               snprintf(key2, sizeof(key2), "name_%d", num);   
-       }
+       MyIni_Load(&ini, is_editor_inifile);
+       snprintf(key1, sizeof(key1), "data_%03d", num); // \8c\85\90\94\8ew\92è
+       snprintf(key2, sizeof(key2), "name_%03d", num); // \8c\85\90\94\8ew\92è     
        for(i = 0; i < SCC_DATA_LENGTH; i++){
                snprintf(data, sizeof(data), "%s%d:", data, is_editor_preset.scc_data_int[num][i]);
        }
@@ -2757,13 +2776,7 @@ static void scc_editor_delete_ini(int num)
        char sec[30] = "";
        
        MyIni_Load(&ini, is_editor_inifile);    
-       if(num < 10){
-               snprintf(sec, sizeof(sec), "SCC_00%d", num); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-       }else if(num < 100){
-               snprintf(sec, sizeof(sec), "SCC_0%d", num);
-       }else{
-               snprintf(sec, sizeof(sec), "SCC_%d", num);      
-       }
+       snprintf(sec, sizeof(sec), "SCC_%03d", num); // \8c\85\90\94\8ew\92è
        MyIni_DeleteSection(&ini, sec);
        MyIni_Save(&ini, is_editor_inifile);
        MyIni_SectionAllClear(&ini);
@@ -2782,13 +2795,7 @@ static void scc_editor_save_ini(int num)
                return;
        setting = is_editor_preset.scc_setting[num];
        MyIni_Load(&ini, is_editor_inifile);    
-       if(num < 10){
-               snprintf(sec, sizeof(sec), "SCC_00%d", num); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-       }else if(num < 100){
-               snprintf(sec, sizeof(sec), "SCC_0%d", num);
-       }else{
-               snprintf(sec, sizeof(sec), "SCC_%d", num);      
-       }       
+       snprintf(sec, sizeof(sec), "SCC_%03d", num); // \8c\85\90\94\8ew\92è
        inisec = MyIni_GetSection(&ini, sec, 1);
        MyIni_SetString(inisec, "name", setting->inst_name);
        // param
@@ -3444,13 +3451,7 @@ static void mms_editor_delete_ini(int num)
        char sec[30] = "";
        
        MyIni_Load(&ini, is_editor_inifile);    
-       if(num < 10){
-               snprintf(sec, sizeof(sec), "MMS_00%d", num); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-       }else if(num < 100){
-               snprintf(sec, sizeof(sec), "MMS_0%d", num);
-       }else{
-               snprintf(sec, sizeof(sec), "MMS_%d", num);      
-       }
+       snprintf(sec, sizeof(sec), "MMS_%03d", num); // \8c\85\90\94\8ew\92è
        MyIni_DeleteSection(&ini, sec);
        MyIni_Save(&ini, is_editor_inifile);
        MyIni_SectionAllClear(&ini);
@@ -3470,13 +3471,7 @@ static void mms_editor_save_ini(int num)
                return;
        setting = is_editor_preset.mms_setting[num];
        MyIni_Load(&ini, is_editor_inifile);    
-       if(num < 10){
-               snprintf(sec, sizeof(sec), "MMS_00%d", num); // \8c\85\90\94\8ew\92è\82í\82©\82ç\82ñ
-       }else if(num < 100){
-               snprintf(sec, sizeof(sec), "MMS_0%d", num);
-       }else{
-               snprintf(sec, sizeof(sec), "MMS_%d", num);      
-       }       
+       snprintf(sec, sizeof(sec), "MMS_%03d", num); // \8c\85\90\94\8ew\92è
        inisec = MyIni_GetSection(&ini, sec, 1);
        MyIni_SetString(inisec, "name", setting->inst_name);
        MyIni_SetInt32(inisec, "op_max", setting->op_max);
@@ -4012,7 +4007,7 @@ void is_editor_load_ini(void)
        scc_data_editor_override = 0; 
        scc_editor_override = 0; 
        mms_editor_override = 0;        
-       load_int_synth_preset(is_editor_inifile, &is_editor_preset, -1, -1); // all     
+       load_int_synth_preset(is_editor_inifile, &is_editor_preset, IS_INI_TYPE_ALL, IS_INI_PRESET_ALL, IS_INI_PRESET_INIT); // all, init
        scc_data_editor_load_preset(0);
        scc_data_editor_store_preset(-1);
        scc_editor_load_preset(0);
@@ -4235,10 +4230,41 @@ static Preset_IS *load_ini_file(char *ini_file, int type, int preset)
        Preset_IS *set = NULL;
        Preset_IS *newset = NULL;
 
+#if defined(IS_INI_LOAD_BLOCK)
+#if (IS_INI_LOAD_BLOCK == 32)
+       uint32 block = preset >> 5; // 1block=64preset 32block
+#elif (IS_INI_LOAD_BLOCK == 64)
+       uint32 block = preset >> 6; // 1block=64preset 16block
+#elif (IS_INI_LOAD_BLOCK == 128)
+       uint32 block = preset >> 7; // 1block=128preset 8block
+#endif
+       uint32 bit = 1L << block; // < 32bit
+       block = (block + 1) << 10; // 10bit > max(SCC_SETTING_MAX MMS_SETTING_MAX)
+#endif
+
     for (set = is_preset; set; set = set->next){
-               if (set->ini_file && !strcmp(set->ini_file, ini_file))
-                       load_int_synth_preset(ini_file, set, type, preset);
+               if (set->ini_file && !strcmp(set->ini_file, ini_file)){
+#if defined(IS_INI_LOAD_TYPE)
+                       if(type == IS_INI_TYPE_SCC && !set->scc_load)){
+                               load_int_synth_preset(ini_file, set, type, IS_INI_PRESET_ALL, IS_INI_PRESET_NONE);
+                               set->scc_load = 1;
+                       }else (type == IS_INI_TYPE_MMS && !set->mms_load){
+                               load_int_synth_preset(ini_file, set, type, IS_INI_PRESET_ALL, IS_INI_PRESET_NONE);
+                               set->mms_load = 1;
+                       }
+#elif defined(IS_INI_LOAD_BLOCK) // block\92P\88Ê\83\8d\81[\83h
+                       if(type == IS_INI_TYPE_SCC && !(set->scc_load & bit)){
+                               load_int_synth_preset(ini_file, set, type, block, IS_INI_PRESET_NONE);
+                               set->scc_load |= bit;
+                       }else if(type == IS_INI_TYPE_MMS && !(set->mms_load & bit)){
+                               load_int_synth_preset(ini_file, set, type, block, IS_INI_PRESET_NONE);
+                               set->mms_load |= bit;
+                       }
+#elif defined(IS_INI_LOAD_PRESET) // preset\92P\88Ê\83\8d\81[\83h
+                       load_int_synth_preset(ini_file, set, type, preset, IS_INI_PRESET_NONE);
+#endif
                        return set;
+               }
        }
        newset = (Preset_IS *)safe_malloc(sizeof(Preset_IS));
        memset(newset, 0, sizeof(Preset_IS));
@@ -4252,7 +4278,25 @@ static Preset_IS *load_ini_file(char *ini_file, int type, int preset)
                }
        }
        newset->ini_file = safe_strdup(ini_file);
-       load_int_synth_preset(ini_file, newset, type, preset);
+#if defined(IS_INI_LOAD_ALL) // \91S\95\94\83\8d\81[\83h
+       load_int_synth_preset(ini_file, newset, IS_INI_TYPE_ALL, IS_INI_PRESET_ALL, IS_INI_PRESET_NONE); // \91S\95\94\83\8d\81[\83h
+       newset->scc_load = 1;
+       newset->mms_load = 1;
+#elif defined(IS_INI_LOAD_TYPE)  // type\92P\88Ê\83\8d\81[\83h
+       load_int_synth_preset(ini_file, newset, type, IS_INI_PRESET_ALL, IS_INI_PRESET_NONE); // type\92P\88Ê\83\8d\81[\83h
+       if(type == IS_INI_TYPE_SCC)
+               newset->scc_load = 1;
+       else if(type == IS_INI_TYPE_MMS)
+               newset->mms_load = 1;
+#elif defined(IS_INI_LOAD_BLOCK) // block\92P\88Ê\83\8d\81[\83h
+       load_int_synth_preset(ini_file, newset, type, block, IS_INI_PRESET_NONE); // preset\92P\88Ê\83\8d\81[\83h
+       if(type == IS_INI_TYPE_SCC)
+               newset->scc_load |= bit;
+       else if(type == IS_INI_TYPE_MMS)
+               newset->mms_load |= bit;
+#elif defined(IS_INI_LOAD_PRESET) // preset\92P\88Ê\83\8d\81[\83h
+       load_int_synth_preset(ini_file, newset, type, preset, IS_INI_PRESET_NONE); // preset\92P\88Ê\83\8d\81[\83h
+#endif
        return newset;
 }
 
@@ -4262,11 +4306,14 @@ Instrument *extract_scc_file(char *ini_file, int preset)
        Sample *sample;
        Preset_IS *set = NULL;
 
-       set = load_ini_file(ini_file, 0, preset);
+       set = load_ini_file(ini_file, IS_INI_TYPE_SCC, preset);
        inst = (Instrument *)safe_malloc(sizeof(Instrument));
        memset(inst, 0, sizeof(Instrument));
        inst->instname = (char *)safe_malloc(256);
-       snprintf(inst->instname, 256, "[SCC] %d: %s", preset, (const char *)set->scc_setting[preset]->inst_name);
+       if(!set->scc_setting[preset])
+               snprintf(inst->instname, 256, "[SCC] %d: ----", preset);
+       else
+               snprintf(inst->instname, 256, "[SCC] %d: %s", preset, (const char *)set->scc_setting[preset]->inst_name);
        inst->type = INST_SCC;
        inst->samples = 1;
        inst->sample = (Sample *)safe_malloc(sizeof(Sample));
@@ -4286,11 +4333,14 @@ Instrument *extract_mms_file(char *ini_file, int preset)
        Preset_IS *set = NULL;
                
        load_la_rom();
-       set = load_ini_file(ini_file, 1, preset);
+       set = load_ini_file(ini_file, IS_INI_TYPE_MMS, preset);
        inst = (Instrument *)safe_malloc(sizeof(Instrument));
        memset(inst, 0, sizeof(Instrument));
        inst->instname = (char *)safe_malloc(256);
-       snprintf(inst->instname, 256, "[MMS] %d: %s", preset, (const char *)set->mms_setting[preset]->inst_name);
+       if(!set->mms_setting[preset])
+               snprintf(inst->instname, 256, "[MMS] %d: ----", preset);
+       else
+               snprintf(inst->instname, 256, "[MMS] %d: %s", preset, (const char *)set->mms_setting[preset]->inst_name);
        inst->type = INST_MMS;
        inst->samples = 1;
        inst->sample = (Sample *)safe_malloc(sizeof(Sample));
@@ -5360,6 +5410,12 @@ static inline void init_scc_preset(int v, InfoIS_SCC *info, Preset_IS *is_set, i
        int tmpi;
        FLOAT_T tmpf;
        
+       if(set == NULL){
+               info->init = 0;
+               return;
+       }
+       info->init = 1;
+
        // param
        tmpi = set->param[0]; // param0= output_level
        if(tmpi < 1)
@@ -5451,12 +5507,14 @@ static inline void init_scc_preset(int v, InfoIS_SCC *info, Preset_IS *is_set, i
 
 static void noteoff_scc(InfoIS_SCC *info)
 {
+       if(!info->init) return;
        reset_envelope0_release(&info->amp_env, ENV0_KEEP);
        reset_envelope0_release(&info->pit_env, ENV0_KEEP);
 }
 
 static void damper_scc(InfoIS_SCC *info, int8 damper)
 {
+       if(!info->init) return;
        reset_envelope0_damper(&info->amp_env, damper);
        reset_envelope0_damper(&info->pit_env, damper);
 }
@@ -5543,7 +5601,9 @@ static inline void compute_voice_scc_switch(int v, int32 count, DATA_T *is_buf,
        InfoIS_SCC *info = (InfoIS_SCC*)&vp->scc;
        int32 i;
        
-       if(!is_rs_mode){
+       if(!info->init){
+               memset(is_buf, 0, count * sizeof(DATA_T));              
+       }else if(!is_rs_mode){
                pre_compute_scc(info, v, count);
                for (i = 0; i < count; i++)
 #if defined(DATA_T_DOUBLE) || defined(DATA_T_FLOAT)
@@ -5678,6 +5738,12 @@ static inline void init_mms_preset(int v, InfoIS_MMS *info, Preset_IS *is_set, i
        FLOAT_T sub_note = note - 60, sub_velo = 127 - velo, div_velo = (FLOAT_T)velo * DIV_127;
        int i, j, tmpi;
 
+       if(set == NULL){
+               info->init = 0;
+               return;
+       }
+       info->init = 1;
+
        tmpi = set->op_max; // op max
        if(tmpi < 1 || tmpi > MMS_OP_MAX)
                tmpi = 0;
@@ -6070,6 +6136,7 @@ static void noteoff_mms(InfoIS_MMS *info)
 {
        int i;
        
+       if(!info->init) return;
        for(i = 0; i < info->op_max; i++){
                Info_OP *info2 = &info->op[i];
                
@@ -6090,6 +6157,7 @@ static void damper_mms(InfoIS_MMS *info, int8 damper)
 {
        int i;
        
+       if(!info->init) return;
        for(i = 0; i < info->op_max; i++){
                Info_OP *info2 = &info->op[i];
                
@@ -6223,7 +6291,9 @@ static inline void compute_voice_mms_switch(int v, int32 count, DATA_T *is_buf,
        InfoIS_MMS *info = (InfoIS_MMS*)&vp->mms;
        int32 i;
        
-       if(!is_rs_mode){
+       if(!info->init){
+               memset(is_buf, 0, count * sizeof(DATA_T));              
+       }else if(!is_rs_mode){
                pre_compute_mms(info, v, count);
                for (i = 0; i < count; i++)
 #if defined(DATA_T_DOUBLE) || defined(DATA_T_FLOAT)
@@ -6332,6 +6402,7 @@ void free_int_synth(void)
 {
        free_int_synth_preset();
        free_is_editor_preset();
+       la_pcm_data_load_flg = 0;
 }
 
 void init_int_synth(void)
index bbf3666..e564a02 100644 (file)
@@ -37,6 +37,18 @@ typedef float IS_RS_DATA_T;
 #define IS_RS_DATA_T_FLOAT
 #endif
 
+#define IS_INI_TYPE_ALL       (-1)
+#define IS_INI_TYPE_SCC       (0)
+#define IS_INI_TYPE_MMS       (1)
+#define IS_INI_PRESET_ALL     (-1)
+#define IS_INI_PRESET_NONE    (0)
+#define IS_INI_PRESET_INIT    (1)
+
+//#define IS_INI_LOAD_ALL 1 // \91S\95\94\83\8d\81[\83h , load_1_inst slowest , worst memory
+//#define IS_INI_LOAD_TYPE 1 // type\92P\88Ê\83\8d\81[\83h
+#define IS_INI_LOAD_BLOCK (32) // block\92P\88Ê\83\8d\81[\83h 1block=32/64/128preset
+//#define IS_INI_LOAD_PRESET 1 // preset\92P\88Ê\83\8d\81[\83h , load_all_inst very slow , load_1_inst fast , best memory
+
 
 // SCC
 #define SCC_DATA_MAX 128
@@ -45,7 +57,7 @@ typedef float IS_RS_DATA_T;
 #define MT32_DATA_MAX 128
 #define CM32L_DATA_MAX 256
 // SCC
-#define SCC_SETTING_MAX 1000
+#define SCC_SETTING_MAX 1000 // <=1000
 #define SCC_PARAM_MAX 1
 #define SCC_OSC_MAX 6
 #define SCC_AMP_MAX 4
@@ -53,7 +65,7 @@ typedef float IS_RS_DATA_T;
 #define SCC_ENV_PARAM 14
 #define SCC_LFO_PARAM 4
 // MMS (OP : operator/partial
-#define MMS_SETTING_MAX 1000
+#define MMS_SETTING_MAX 1000 // <=1000
 #define MMS_OP_MAX 16
 #define MMS_OP_PARAM_MAX 4
 #define MMS_OP_RANGE_MAX 4
@@ -193,6 +205,7 @@ typedef struct _Preset_MMS {
 typedef struct _Preset_IS {
        char *ini_file;
        int8 scc_data_load;
+       uint32 scc_load, mms_load;
        char *scc_data_name[SCC_DATA_MAX];
        int16 scc_data_int[SCC_DATA_MAX][SCC_DATA_LENGTH];
        FLOAT_T scc_data[SCC_DATA_MAX][SCC_DATA_LENGTH + 1];
@@ -202,6 +215,7 @@ typedef struct _Preset_IS {
 } Preset_IS;
 
 
+
 typedef FLOAT_T (*compute_osc_t)(FLOAT_T in, int32 var);
 typedef FLOAT_T (*compute_scc_t)(FLOAT_T in, FLOAT_T *data);
 
@@ -227,7 +241,7 @@ typedef struct {
 } Info_Resample;
 
 typedef struct {
-       int8 mode, scc_flag;
+       int8 init, mode, scc_flag;
        int32 thru_count;
        int32 cycle;
        FLOAT_T output_level;
@@ -262,7 +276,8 @@ typedef struct _Info_OP{
 typedef void (*compute_op_t)(Info_OP *info);
 
 typedef struct _InfoIS_MMS{
-       int8 op_max;
+
+       int8 init, op_max;
        int32 thru_count;
        Info_OP op[MMS_OP_MAX];
        compute_op_t op_ptr[MMS_OP_MAX];
index 65ffc74..c4d08b2 100644 (file)
@@ -380,7 +380,8 @@ int32 current_trace_samples(void)
     int32 sp;
     if((sp = aq_samples()) == -1)
        return -1;
-    return midi_trace.offset + aq_samples();
+    return midi_trace.offset + sp; // c212
+//    return midi_trace.offset + aq_samples();
 }
 
 void init_midi_trace(void)
index 6267d83..1a56ae0 100644 (file)
@@ -115,6 +115,10 @@ extern PlayMode arts_play_mode;
 extern PlayMode esd_play_mode;
 #endif /* AU_ESD */
 
+#ifdef AU_WASAPI
+extern PlayMode wasapi_play_mode;
+#endif /* AU_WASAPI */
+
 #ifdef AU_PORTAUDIO
 #ifndef AU_PORTAUDIO_DLL
 extern PlayMode portaudio_play_mode;
@@ -211,6 +215,10 @@ PlayMode *play_mode_list[] = {
 #ifdef AU_HPUX_ALIB
   &hpux_nplay_mode,
 #endif /* AU_HPUX_ALIB */
+  
+#if defined(AU_WASAPI)
+  &wasapi_play_mode,
+#endif /* AU_WASAPI */
 
 #if defined(AU_PORTAUDIO)
 #ifndef AU_PORTAUDIO_DLL
@@ -223,7 +231,7 @@ PlayMode *play_mode_list[] = {
   &portaudio_win_wmme_play_mode,
 #endif
 #endif /* AU_PORTAUDIO */
-
+  
 #ifdef AU_LAME
   &lame_play_mode,
 #endif
@@ -318,6 +326,23 @@ void change_output_volume(int32 vol)
     output_volumei = TIM_FSCALE(output_volume, 28);
 }
 
+static int use_temp_encoding = 0;
+static uint32 temp_encoding = 0;
+
+// called open_output()
+void set_temporary_encoding(uint32 enc)
+{      
+       temp_encoding = enc;
+       use_temp_encoding = 1;
+}
+
+// called close_output()
+void reset_temporary_encoding(void)
+{
+       use_temp_encoding = 0;
+       temp_encoding = 0;
+}
+
 
 
 /*****************************************************************/
@@ -444,40 +469,6 @@ static void CALLINGCONV f64tos8(DATA_T *lp, int32 c)
                _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned
        }
 }
-#elif (USE_X86_EXT_INTRIN >= 9) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tos8(DATA_T *lp, int32 c)
-{
-    int8 *cp=(int8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_8BIT_SIGNED);   
-       for(i = 0; i < c; i += 8){
-               __m256i vec_i32 = _mm256_cvttps_epi32(_mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul));
-               __m128i vec_i32_1 = _mm256_extracti128_si256(vec_i32, 0x0);
-               __m128i vec_i32_2 = _mm256_extracti128_si256(vec_i32, 0x1);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               __m128i vec_i8 = _mm_packs_epi16(vec_i16, _mm_setzero_si128());
-               _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tos8(DATA_T *lp, int32 c)
-{
-    int8 *cp=(int8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_8BIT_SIGNED);   
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               __m128i vec_i8 = _mm_packs_epi16(vec_i16, _mm_setzero_si128());
-               _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned
-       }
-}
 #elif (USE_X86_EXT_INTRIN >= 3) && defined(DATA_T_FLOAT)
 static void CALLINGCONV f64tos8(DATA_T *lp, int32 c)
 {
@@ -544,7 +535,7 @@ static void CALLINGCONV f64tou8(DATA_T *lp, int32 c)
                __m128i vec_i32_1 = _mm256_cvttpd_epi32(_mm256_mul_pd(D256_CLIP_INPUT(&lp[i], gain), vmul));
                __m128i vec_i32_2 = _mm256_cvttpd_epi32(_mm256_mul_pd(D256_CLIP_INPUT(&lp[i + 4], gain), vmul));
                __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               __m128i vec_i8 = _mm_packus_epi16(vec_i16, _mm_setzero_si128());
+               __m128i vec_i8 = _mm_packs_epi16(vec_i16, _mm_setzero_si128());
                vec_i8 = _mm_xor_si128(vex, vec_i8);
                _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned   
        }
@@ -567,45 +558,7 @@ static void CALLINGCONV f64tou8(DATA_T *lp, int32 c)
                __m128i vec_i32_1 = _mm_cvttps_epi32(_mm_mul_ps(F128_CLIP_MM(vec_f1, gain), vmul));
                __m128i vec_i32_2 = _mm_cvttps_epi32(_mm_mul_ps(F128_CLIP_MM(vec_f2, gain), vmul));
                __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               __m128i vec_i8 = _mm_packus_epi16(vec_i16, _mm_setzero_si128());
-               vec_i8 = _mm_xor_si128(vex, vec_i8);
-               _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 9) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tou8(DATA_T *lp, int32 c)
-{
-       uint8 *cp=(uint8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_8BIT_SIGNED);
-       __m128i vex = _mm_set1_epi8(0x80);      
-       for(i = 0; i < c; i += 8){
-               __m256i vec_i32 = _mm256_cvttps_epi32(_mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul));
-               __m128i vec_i32_1 = _mm256_extracti128_si256(vec_i32, 0x0);
-               __m128i vec_i32_2 = _mm256_extracti128_si256(vec_i32, 0x1);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               __m128i vec_i8 = _mm_packus_epi16(vec_i16, _mm_setzero_si128());
-               vec_i8 = _mm_xor_si128(vex, vec_i8);
-               _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tou8(DATA_T *lp, int32 c)
-{
-       uint8 *cp=(uint8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_8BIT_SIGNED);
-       __m128i vex = _mm_set1_epi8(0x80);      
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               __m128i vec_i8 = _mm_packus_epi16(vec_i16, _mm_setzero_si128());
+               __m128i vec_i8 = _mm_packs_epi16(vec_i16, _mm_setzero_si128());
                vec_i8 = _mm_xor_si128(vex, vec_i8);
                _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned
        }
@@ -624,7 +577,7 @@ static void CALLINGCONV f64tou8(DATA_T *lp, int32 c)
                __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
                __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
                __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               __m128i vec_i8 = _mm_packus_epi16(vec_i16, _mm_setzero_si128());
+               __m128i vec_i8 = _mm_packs_epi16(vec_i16, _mm_setzero_si128());
                vec_i8 = _mm_xor_si128(vex, vec_i8);
                _mm_storeu_si128((__m128i *)&cp[i], vec_i8); // L64bit=8bit*8 , H64bit next unaligned
        }
@@ -719,77 +672,6 @@ static void CALLINGCONV f64toulaw(DATA_T *lp, int32 c)
 #endif //  !(defined(_MSC_VER) || defined(MSC_VER))
        }       
 }
-#elif (USE_X86_EXT_INTRIN >= 9) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64toulaw(DATA_T *lp, int32 c)
-{
-       int8 *up=(int8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);  
-       for(i = 0; i < c; i += 8){
-               __m256i vec0 = _mm256_cvttps_epi32(_mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul));
-#if !(defined(_MSC_VER) || defined(MSC_VER))
-               {
-               int32 *out = (int32 *)vec0;
-               up[i] = AUDIO_S2U(out[0]);
-               up[i + 1] = AUDIO_S2U(out[1]);
-               up[i + 2] = AUDIO_S2U(out[2]);
-               up[i + 3] = AUDIO_S2U(out[3]);
-               up[i + 4] = AUDIO_S2U(out[4]);
-               up[i + 5] = AUDIO_S2U(out[5]);
-               up[i + 6] = AUDIO_S2U(out[6]);
-               up[i + 7] = AUDIO_S2U(out[7]);
-               }
-#else
-               up[i] = AUDIO_S2U(vec0.m256i_i32[0]);
-               up[i + 1] = AUDIO_S2U(vec0.m256i_i32[1]);
-               up[i + 2] = AUDIO_S2U(vec0.m256i_i32[2]);
-               up[i + 3] = AUDIO_S2U(vec0.m256i_i32[3]);
-               up[i + 4] = AUDIO_S2U(vec0.m256i_i32[4]);
-               up[i + 5] = AUDIO_S2U(vec0.m256i_i32[5]);
-               up[i + 6] = AUDIO_S2U(vec0.m256i_i32[6]);
-               up[i + 7] = AUDIO_S2U(vec0.m256i_i32[7]);
-#endif //  !(defined(_MSC_VER) || defined(MSC_VER))
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64toulaw(DATA_T *lp, int32 c)
-{
-       int8 *up=(int8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);  
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-#if !(defined(_MSC_VER) || defined(MSC_VER))
-               {
-               int32 *out1 = (int32 *)vec_i32_1;
-               int32 *out2 = (int32 *)vec_i32_2;
-               up[i] = AUDIO_S2U(out1[0]);
-               up[i + 1] = AUDIO_S2U(out1[1]);
-               up[i + 2] = AUDIO_S2U(out1[2]);
-               up[i + 3] = AUDIO_S2U(out1[3]);
-               up[i + 4] = AUDIO_S2U(out2[0]);
-               up[i + 5] = AUDIO_S2U(out2[1]);
-               up[i + 6] = AUDIO_S2U(out2[2]);
-               up[i + 7] = AUDIO_S2U(out2[3]);
-               }
-#else
-               up[i] = AUDIO_S2U(vec_i32_1.m128i_i32[0]);
-               up[i + 1] = AUDIO_S2U(vec_i32_1.m128i_i32[1]);
-               up[i + 2] = AUDIO_S2U(vec_i32_1.m128i_i32[2]);
-               up[i + 3] = AUDIO_S2U(vec_i32_1.m128i_i32[3]);
-               up[i + 4] = AUDIO_S2U(vec_i32_2.m128i_i32[0]);
-               up[i + 5] = AUDIO_S2U(vec_i32_2.m128i_i32[1]);
-               up[i + 6] = AUDIO_S2U(vec_i32_2.m128i_i32[2]);
-               up[i + 7] = AUDIO_S2U(vec_i32_2.m128i_i32[3]);
-#endif //  !(defined(_MSC_VER) || defined(MSC_VER))
-       }
-}
 #elif (USE_X86_EXT_INTRIN >= 3) && defined(DATA_T_FLOAT)
 static void CALLINGCONV f64toulaw(DATA_T *lp, int32 c)
 {
@@ -879,102 +761,6 @@ static void CALLINGCONV f64toalaw(DATA_T *lp, int32 c)
 #endif //  !(defined(_MSC_VER) || defined(MSC_VER))
        }
 }
-#elif (USE_X86_EXT_INTRIN >= 9) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64toalaw(DATA_T *lp, int32 c)
-{
-       int8 *up=(int8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);          
-       for(i = 0; i < c; i += 8){
-               __m256i vec0 = _mm256_cvttps_epi32(_mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul));
-#if !(defined(_MSC_VER) || defined(MSC_VER))
-               {
-               int32 *out = (int32 *)vec0;
-               up[i] = AUDIO_S2A(out[0]);
-               up[i + 1] = AUDIO_S2A(out[1]);
-               up[i + 2] = AUDIO_S2A(out[2]);
-               up[i + 3] = AUDIO_S2A(out[3]);
-               up[i + 4] = AUDIO_S2A(out[4]);
-               up[i + 5] = AUDIO_S2A(out[5]);
-               up[i + 6] = AUDIO_S2A(out[6]);
-               up[i + 7] = AUDIO_S2A(out[7]);
-               }
-#else
-               up[i] = AUDIO_S2A(vec0.m256i_i32[0]);
-               up[i + 1] = AUDIO_S2A(vec0.m256i_i32[1]);
-               up[i + 2] = AUDIO_S2A(vec0.m256i_i32[2]);
-               up[i + 3] = AUDIO_S2A(vec0.m256i_i32[3]);
-               up[i + 4] = AUDIO_S2A(vec0.m256i_i32[4]);
-               up[i + 5] = AUDIO_S2A(vec0.m256i_i32[5]);
-               up[i + 6] = AUDIO_S2A(vec0.m256i_i32[6]);
-               up[i + 7] = AUDIO_S2A(vec0.m256i_i32[7]);
-#endif //  !(defined(_MSC_VER) || defined(MSC_VER))
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64toalaw(DATA_T *lp, int32 c)
-{
-       int8 *up=(int8 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);  
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-#if !(defined(_MSC_VER) || defined(MSC_VER))
-               {
-               int32 *out1 = (int32 *)vec_i32_1;
-               int32 *out2 = (int32 *)vec_i32_2;
-               up[i] = AUDIO_S2A(out1[0]);
-               up[i + 1] = AUDIO_S2A(out1[1]);
-               up[i + 2] = AUDIO_S2A(out1[2]);
-               up[i + 3] = AUDIO_S2A(out1[3]);
-               up[i + 4] = AUDIO_S2A(out2[0]);
-               up[i + 5] = AUDIO_S2A(out2[1]);
-               up[i + 6] = AUDIO_S2A(out2[2]);
-               up[i + 7] = AUDIO_S2A(out2[3]);
-               }
-#else
-               up[i] = AUDIO_S2A(vec_i32_1.m128i_i32[0]);
-               up[i + 1] = AUDIO_S2A(vec_i32_1.m128i_i32[1]);
-               up[i + 2] = AUDIO_S2A(vec_i32_1.m128i_i32[2]);
-               up[i + 3] = AUDIO_S2A(vec_i32_1.m128i_i32[3]);
-               up[i + 4] = AUDIO_S2A(vec_i32_2.m128i_i32[0]);
-               up[i + 5] = AUDIO_S2A(vec_i32_2.m128i_i32[1]);
-               up[i + 6] = AUDIO_S2A(vec_i32_2.m128i_i32[2]);
-               up[i + 7] = AUDIO_S2A(vec_i32_2.m128i_i32[3]);
-#endif //  !(defined(_MSC_VER) || defined(MSC_VER))
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 3) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64toalaw(DATA_T *lp, int32 c)
-{
-       int8 *up=(int8 *)(lp);
-       int32 i;
-       __m128 gain = _mm_set1_ps((float)INPUT_GAIN);
-       __m128 vmul = _mm_set1_ps((float)MAX_16BIT_SIGNED);             
-       for(i = 0; i < c; i += 4){
-               __m128i vec0 = _mm_cvttps_epi32(_mm_mul_ps(F128_CLIP_INPUT(&lp[i], gain), vmul));
-#if !(defined(_MSC_VER) || defined(MSC_VER))
-               {
-               int32 *out = (int32 *)vec0;
-               up[i] = AUDIO_S2A(out[0]);
-               up[i + 1] = AUDIO_S2A(out[1]);
-               up[i + 2] = AUDIO_S2A(out[2]);
-               up[i + 3] = AUDIO_S2A(out[3]);
-               }
-#else
-               up[i] = AUDIO_S2A(vec0.m128i_i32[0]);
-               up[i + 1] = AUDIO_S2A(vec0.m128i_i32[1]);
-               up[i + 2] = AUDIO_S2A(vec0.m128i_i32[2]);
-               up[i + 3] = AUDIO_S2A(vec0.m128i_i32[3]);
-#endif //  !(defined(_MSC_VER) || defined(MSC_VER))
-       }
-}
 #else
 static void CALLINGCONV f64toalaw(DATA_T *lp, int32 c)
 {
@@ -1020,38 +806,6 @@ static void CALLINGCONV f64tos16(DATA_T *lp, int32 c)
                _mm_store_si128((__m128i *)&sp[i], vec_i16); // 128bit=16bit*8  
        }
 }
-#elif (USE_X86_EXT_INTRIN >= 9) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tos16(DATA_T *lp, int32 c)
-{
-       int16 *sp=(int16 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);  
-       for(i = 0; i < c; i += 8){
-               __m256i vec_i32 = _mm256_cvttps_epi32(_mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul));
-               __m128i vec_i32_1 = _mm256_extracti128_si256(vec_i32, 0x0);
-               __m128i vec_i32_2 = _mm256_extracti128_si256(vec_i32, 0x1);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               _mm_store_si128((__m128i *)&sp[i], vec_i16); // 128bit=16bit*8  
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tos16(DATA_T *lp, int32 c)
-{
-       int16 *sp=(int16 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);  
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               _mm_store_si128((__m128i *)&sp[i], vec_i16); // 128bit=16bit*8  
-       }
-}
 #elif (USE_X86_EXT_INTRIN >= 3) && defined(DATA_T_FLOAT)
 static void CALLINGCONV f64tos16(DATA_T *lp, int32 c)
 {
@@ -1143,42 +897,6 @@ static void CALLINGCONV f64tou16(DATA_T *lp, int32 c)
                _mm_store_si128((__m128i *)&sp[i], vec_i16); // 128bit=16bit*8  
        }
 }
-#elif (USE_X86_EXT_INTRIN >= 9) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tou16(DATA_T *lp, int32 c)
-{
-       uint16 *sp=(uint16 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);
-       __m128i vex = _mm_set1_epi16(0x8000);           
-       for(i = 0; i < c; i += 8){
-               __m256i vec_i32 = _mm256_cvttps_epi32(_mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul));
-               __m128i vec_i32_1 = _mm256_extracti128_si256(vec_i32, 0x0);
-               __m128i vec_i32_2 = _mm256_extracti128_si256(vec_i32, 0x1);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               vec_i16 = _mm_xor_si128(vex, vec_i16);
-               _mm_store_si128((__m128i *)&sp[i], vec_i16); // 128bit=16bit*8  
-       }
-}
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tou16(DATA_T *lp, int32 c)
-{
-       uint16 *sp=(uint16 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_16BIT_SIGNED);  
-       __m128i vex = _mm_set1_epi16(0x8000);   
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-               __m128i vec_i16 = _mm_packs_epi32(vec_i32_1, vec_i32_2);
-               vec_i16 = _mm_xor_si128(vex, vec_i16);
-               _mm_store_si128((__m128i *)&sp[i], vec_i16); // 128bit=16bit*8  
-       }
-}
 #elif (USE_X86_EXT_INTRIN >= 3) && defined(DATA_T_FLOAT)
 static void CALLINGCONV f64tou16(DATA_T *lp, int32 c)
 {
@@ -1238,16 +956,11 @@ static void CALLINGCONV f64tos24(DATA_T *lp, int32 c)
        const __m128 gain = _mm_set1_ps((float)INPUT_GAIN);
        const __m128 vmul = _mm_set1_ps((float)MAX_24BIT_SIGNED);
 #endif
-#if 0//(USE_X86_EXT_INTRIN >= 5)
-// *444*333*222*111 first data
-// ****444333222111 shuffled
-       const __m128i vs_96 = _mm_set_epi8(0xFF,0xFF,0xFF,0xFF,0x0E,0x0D,0x0C,0x0A, 0x09,0x08,0x06,0x05,0x04,0x02,0x01,0x00);
-#else
        const __m128i vm_24l = _mm_set_epi32(0x00000000,0x00FFFFFF,0x00000000,0x00FFFFFF);
        const __m128i vm_24h = _mm_set_epi32(0x00FFFFFF,0x00000000,0x00FFFFFF,0x00000000);
        const __m128i vm_48l = _mm_set_epi32(0x00000000,0x00000000,0x0000FFFF,0xFFFFFFFF);
        const __m128i vm_48h = _mm_set_epi32(0x0000FFFF,0xFFFFFFFF,0x00000000,0x00000000);
-#endif
+
        for(i = 0; i < c; i += 8){
 #if (USE_X86_EXT_INTRIN >= 8)
                __m128i vec_i32_1 = _mm256_cvttpd_epi32(_mm256_mul_pd(D256_CLIP_INPUT(&lp[i], gain), vmul));
@@ -1262,12 +975,6 @@ static void CALLINGCONV f64tos24(DATA_T *lp, int32 c)
                __m128i vec_i32_1 = _mm_cvttps_epi32(_mm_mul_ps(F128_CLIP_MM(vec_f1, gain), vmul)); // (24bit+8bit)*4
                __m128i vec_i32_2 = _mm_cvttps_epi32(_mm_mul_ps(F128_CLIP_MM(vec_f2, gain), vmul)); // (24bit+8bit)*4
 #endif
-#if 0//(USE_X86_EXT_INTRIN >= 5) // slow!?
-               __m128i vec_i96_1 = _mm_shuffle_epi8(vec_i32_1, vs_96);
-               __m128i vec_i96_2 = _mm_shuffle_epi8(vec_i32_1, vs_96);
-               __m128i vec_i128_1 = _mm_or_si128(vec_i96_1, _mm_slli_si128(vec_i96_2, 12)); // 24bit*4+(24bit+8bit) = 128bit
-               __m128i vec_i128_2 = _mm_srli_si128(vec_i96_2, 4); // 16bit+24bit*2 = 64bit
-#else
                __m128i vec_i24_1l = _mm_and_si128(vec_i32_1, vm_24l); 
                __m128i vec_i24_2l = _mm_and_si128(vec_i32_2, vm_24l); 
                __m128i vec_i24_1h = _mm_and_si128(vec_i32_1, vm_24h); 
@@ -1282,7 +989,6 @@ static void CALLINGCONV f64tos24(DATA_T *lp, int32 c)
                __m128i vec_i96_2 = _mm_or_si128(vec_i48_2l, _mm_srli_si128(vec_i48_2h, 2)); // 96bit+32bit
                __m128i vec_i128_1 = _mm_or_si128(vec_i96_1, _mm_slli_si128(vec_i96_2, 12)); // 24bit*4+(24bit+8bit) = 128bit
                __m128i vec_i128_2 = _mm_srli_si128(vec_i96_2, 4); // 16bit+24bit*2 = 64bit
-#endif
 #if (USE_X86_EXT_INTRIN >= 9)
                __m256i vec_i192 = MM256_SET2X_SI256(vec_i128_1, vec_i128_2); // 24bit*8 + emp64bit
                _mm256_storeu_si256((__m256i *)cp, vec_i192); // 192bit/256bit unalign \92´\82¦\82é\95ª\82Í\96³\8e\8b   
@@ -1300,44 +1006,18 @@ static void CALLINGCONV f64tos24(DATA_T *lp, int32 c)
 {
        uint8 *cp = (uint8 *)(lp);
        int32 i;
-#if (USE_X86_EXT_INTRIN >= 8)
-       const __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       const __m256 vmul = _mm256_set1_ps((float)MAX_24BIT_SIGNED);
-#else
        const __m128 gain = _mm_set1_ps((float)INPUT_GAIN);
        const __m128 vmul = _mm_set1_ps((float)MAX_24BIT_SIGNED);
-#endif
-#if 0//(USE_X86_EXT_INTRIN >= 5)
-// *444*333*222*111 first data
-// ****444333222111 shuffled
-       const __m128i vs_96 = _mm_set_epi8(0xFF,0xFF,0xFF,0xFF,0x0E,0x0D,0x0C,0x0A, 0x09,0x08,0x06,0x05,0x04,0x02,0x01,0x00);
-#else
        const __m128i vm_24l = _mm_set_epi32(0x00000000,0x00FFFFFF,0x00000000,0x00FFFFFF);
        const __m128i vm_24h = _mm_set_epi32(0x00FFFFFF,0x00000000,0x00FFFFFF,0x00000000);
        const __m128i vm_48l = _mm_set_epi32(0x00000000,0x00000000,0x0000FFFF,0xFFFFFFFF);
        const __m128i vm_48h = _mm_set_epi32(0x0000FFFF,0xFFFFFFFF,0x00000000,0x00000000);
-#endif
+
        for(i = 0; i < c; i += 8){
-#if (USE_X86_EXT_INTRIN >= 9)
-               __m256i vec_i32 = _mm256_cvttps_epi32(_mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul)); // (24bit+8bit) * 8  
-#elif (USE_X86_EXT_INTRIN >= 8)
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-#else
                __m128 vec_f1 = _mm_mul_ps(F128_CLIP_INPUT(&lp[i], gain), vmul);
                __m128 vec_f2 = _mm_mul_ps(F128_CLIP_INPUT(&lp[i + 4], gain), vmul);
                __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1); // (24bit+8bit)*4
                __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2); // (24bit+8bit)*4
-#endif
-#if 0//(USE_X86_EXT_INTRIN >= 5) // slow!?
-               __m128i vec_i96_1 = _mm_shuffle_epi8(vec_i32_1, vs_96);
-               __m128i vec_i96_2 = _mm_shuffle_epi8(vec_i32_1, vs_96);
-               __m128i vec_i128_1 = _mm_or_si128(vec_i96_1, _mm_slli_si128(vec_i96_2, 12)); // 24bit*4+(24bit+8bit) = 128bit
-               __m128i vec_i128_2 = _mm_srli_si128(vec_i96_2, 4); // 16bit+24bit*2 = 64bit
-#else
                __m128i vec_i24_1l = _mm_and_si128(vec_i32_1, vm_24l); 
                __m128i vec_i24_2l = _mm_and_si128(vec_i32_2, vm_24l); 
                __m128i vec_i24_1h = _mm_and_si128(vec_i32_1, vm_24h); 
@@ -1352,7 +1032,6 @@ static void CALLINGCONV f64tos24(DATA_T *lp, int32 c)
                __m128i vec_i96_2 = _mm_or_si128(vec_i48_2l, _mm_srli_si128(vec_i48_2h, 2)); // 96bit+32bit
                __m128i vec_i128_1 = _mm_or_si128(vec_i96_1, _mm_slli_si128(vec_i96_2, 12)); // 24bit*4+(24bit+8bit) = 128bit
                __m128i vec_i128_2 = _mm_srli_si128(vec_i96_2, 4); // 16bit+24bit*2 = 64bit
-#endif
 #if (USE_X86_EXT_INTRIN >= 9)
                __m256i vec_i192 = MM256_SET2X_SI256(vec_i128_1, vec_i128_2); // 24bit*8 + emp64bit
                _mm256_storeu_si256((__m256i *)cp, vec_i192); // 192bit/256bit unalign \92´\82¦\82é\95ª\82Í\96³\8e\8b   
@@ -1473,23 +1152,6 @@ static void CALLINGCONV f64tos32(DATA_T *lp, int32 c)
                _mm256_store_si256((__m256i *)&sp[i], vec_i32); // 256bit=32bit*16      
        }
 }
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tos32(DATA_T *lp, int32 c)
-{
-       int32 *sp=(int32 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_32BIT_SIGNED);  
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-               _mm_store_si128((__m128i *)&sp[i], vec_i32_1); // 128bit=32bit*4                
-               _mm_store_si128((__m128i *)&sp[i + 4], vec_i32_2); // 128bit=32bit*4    
-       }
-}
 #elif (USE_X86_EXT_INTRIN >= 3) && defined(DATA_T_FLOAT)
 static void CALLINGCONV f64tos32(DATA_T *lp, int32 c)
 {
@@ -1595,26 +1257,6 @@ static void CALLINGCONV f64tou32(DATA_T *lp, int32 c)
                _mm256_store_si256((__m256i *)&sp[i], vec_i32); // 256bit=32bit*16      
        }
 }
-#elif (USE_X86_EXT_INTRIN >= 8) && defined(DATA_T_FLOAT)
-static void CALLINGCONV f64tou32(DATA_T *lp, int32 c)
-{
-       uint32 *sp=(uint32 *)(lp);
-       int32 i;
-       __m256 gain = _mm256_set1_ps((float)INPUT_GAIN);
-       __m256 vmul = _mm256_set1_ps((float)MAX_32BIT_SIGNED);  
-       __m128i vex = _mm_set1_epi32(0x80000000);
-       for(i = 0; i < c; i += 8){
-               __m256 vec_f = _mm256_mul_ps(F256_CLIP_INPUT(&lp[i], gain), vmul);
-               __m128 vec_f1 = _mm256_extractf128_ps(vec_f, 0x0);
-               __m128 vec_f2 = _mm256_extractf128_ps(vec_f, 0x1);
-               __m128i vec_i32_1 = _mm_cvttps_epi32(vec_f1);
-               __m128i vec_i32_2 = _mm_cvttps_epi32(vec_f2);
-               vec_i32_1 = _mm_xor_si128(vex, vec_i32_1);
-               vec_i32_2 = _mm_xor_si128(vex, vec_i32_2);
-               _mm_store_si128((__m128i *)&sp[i], vec_i32_1); // 128bit=32bit*4                
-               _mm_store_si128((__m128i *)&sp[i + 4], vec_i32_2); // 128bit=32bit*4    
-       }
-}
 #elif (USE_X86_EXT_INTRIN >= 3) && defined(DATA_T_FLOAT)
 static void CALLINGCONV f64tou32(DATA_T *lp, int32 c)
 {
@@ -1939,79 +1581,80 @@ static void CALLINGCONV f64tof64(DATA_T *lp, int32 c)
 
 void general_output_convert_setup(void)
 {
+       uint32 penc = use_temp_encoding ? temp_encoding : play_mode->encoding; 
+       
     convert_count = 1; //def 8bit mono
-
-    if(!(play_mode->encoding & PE_MONO))
+    if(!(penc & PE_MONO))
                convert_count *= 2; /* Stereo samples */
 
        convert_bytes = convert_count;
-       if(play_mode->encoding & PE_16BIT)
+       if(penc & PE_16BIT)
     {
                convert_bytes *= 2;
-               if(play_mode->encoding & PE_BYTESWAP)
+               if(penc & PE_BYTESWAP)
                {
-                       if(play_mode->encoding & PE_SIGNED)
+                       if(penc & PE_SIGNED)
                                convert_fnc = f64tos16x;
                        else
                                convert_fnc = f64tou16x;
                }
-               else if(play_mode->encoding & PE_SIGNED)
+               else if(penc & PE_SIGNED)
                        convert_fnc = f64tos16;
                else
                        convert_fnc = f64tou16;
     }
-       else if(play_mode->encoding & PE_24BIT) {
+       else if(penc & PE_24BIT) {
                convert_bytes *= 3;
-               if(play_mode->encoding & PE_BYTESWAP)
+               if(penc & PE_BYTESWAP)
                {
-                       if(play_mode->encoding & PE_SIGNED)
+                       if(penc & PE_SIGNED)
                                convert_fnc = f64tos24x;
                        else
                                convert_fnc = f64tou24x;
-               } else if(play_mode->encoding & PE_SIGNED)
+               } else if(penc & PE_SIGNED)
                        convert_fnc = f64tos24;
                else
                        convert_fnc = f64tou24;
     }
-    else if(play_mode->encoding & PE_32BIT) {
+    else if(penc & PE_32BIT) {
                convert_bytes *= 4;
-               if(play_mode->encoding & PE_BYTESWAP)
+               if(penc & PE_BYTESWAP)
                {
-                       if(play_mode->encoding & PE_SIGNED)
+                       if(penc & PE_SIGNED)
                                convert_fnc = f64tos32x;
                        else
                                convert_fnc = f64tou32x;
-               } else if(play_mode->encoding & PE_SIGNED)
+               } else if(penc & PE_SIGNED)
                        convert_fnc = f64tos32;
                else
                        convert_fnc = f64tou32;
     }
-       else if(play_mode->encoding & PE_F32BIT) {
+       else if(penc & PE_F32BIT) {
                convert_bytes *= 4;
                convert_fnc = f64tof32;
     }
-    else if(play_mode->encoding & PE_64BIT) {
+    else if(penc & PE_64BIT) {
                convert_bytes *= 8;
-               if(play_mode->encoding & PE_BYTESWAP)
+               if(penc & PE_BYTESWAP)
                {
-                       if(play_mode->encoding & PE_SIGNED)
+                       if(penc & PE_SIGNED)
                                convert_fnc = f64tos64x;
                        else
                                convert_fnc = f64tou64x;
-               } else if(play_mode->encoding & PE_SIGNED)
+               } else if(penc & PE_SIGNED)
                        convert_fnc = f64tos64;
                else
                        convert_fnc = f64tou64;
     }
-       else if(play_mode->encoding & PE_F64BIT) {
+       else if(penc & PE_F64BIT) {
                convert_bytes *= 8;
                convert_fnc = f64tof64;
     }
-       else if(play_mode->encoding & PE_ULAW)
+       else if(penc & PE_ULAW)
                convert_fnc = f64toulaw;
-    else if(play_mode->encoding & PE_ALAW)
+    else if(penc & PE_ALAW)
                convert_fnc = f64toalaw;
-    else if(play_mode->encoding & PE_SIGNED)
+    else if(penc & PE_SIGNED)
                convert_fnc = f64tos8;
     else
                convert_fnc = f64tou8;
@@ -2921,79 +2564,80 @@ static void CALLINGCONV s32tof64(int32 *lp, int32 c)
 
 void general_output_convert_setup(void)
 {
-    convert_count = 1; //def 8bit mono
+       uint32 penc = use_temp_encoding ? temp_encoding : play_mode->encoding; 
 
-    if (!(play_mode->encoding & PE_MONO))
+    convert_count = 1; //def 8bit mono
+    if (!(penc & PE_MONO))
        convert_count *= 2; /* Stereo samples */
 
     convert_bytes = convert_count;
-    if (play_mode->encoding & PE_16BIT)
+    if (penc & PE_16BIT)
     {
        convert_bytes *= 2;
-       if (play_mode->encoding & PE_BYTESWAP)
+       if (penc & PE_BYTESWAP)
        {
-           if (play_mode->encoding & PE_SIGNED)
+           if (penc & PE_SIGNED)
                convert_fnc = s32tos16x;
            else
                convert_fnc = s32tou16x;
        }
-       else if (play_mode->encoding & PE_SIGNED)
+       else if (penc & PE_SIGNED)
            convert_fnc = s32tos16;
        else
            convert_fnc = s32tou16;
     }
-    else if (play_mode->encoding & PE_24BIT) {
+    else if (penc & PE_24BIT) {
        convert_bytes *= 3;
-       if (play_mode->encoding & PE_BYTESWAP)
+       if (penc & PE_BYTESWAP)
        {
-           if (play_mode->encoding & PE_SIGNED)
+           if (penc & PE_SIGNED)
                convert_fnc = s32tos24x;
            else
                convert_fnc = s32tou24x;
-       } else if (play_mode->encoding & PE_SIGNED)
+       } else if (penc & PE_SIGNED)
            convert_fnc = s32tos24;
        else
            convert_fnc = s32tou24;
     }
-    else if (play_mode->encoding & PE_32BIT) {
+    else if (penc & PE_32BIT) {
        convert_bytes *= 4;
-       if (play_mode->encoding & PE_BYTESWAP)
+       if (penc & PE_BYTESWAP)
        {
-           if (play_mode->encoding & PE_SIGNED)
+           if (penc & PE_SIGNED)
                convert_fnc = s32tos32x;
            else
                convert_fnc = s32tou32x;
-       } else if (play_mode->encoding & PE_SIGNED)
+       } else if (penc & PE_SIGNED)
            convert_fnc = s32tos32;
        else
            convert_fnc = s32tou32;
     }
-    else if (play_mode->encoding & PE_F32BIT) {
+    else if (penc & PE_F32BIT) {
        convert_bytes *= 4;
        convert_fnc = s32tof32;
     }
-    else if (play_mode->encoding & PE_64BIT) {
+    else if (penc & PE_64BIT) {
        convert_bytes *= 8;
-       if (play_mode->encoding & PE_BYTESWAP)
+       if (penc & PE_BYTESWAP)
        {
-           if (play_mode->encoding & PE_SIGNED)
+           if (penc & PE_SIGNED)
                convert_fnc = s32tos64x;
            else
                convert_fnc = s32tou64x;
-       } else if (play_mode->encoding & PE_SIGNED)
+       } else if (penc & PE_SIGNED)
            convert_fnc = s32tos64;
        else
            convert_fnc = s32tou64;
     }
-    else if (play_mode->encoding & PE_F64BIT) {
+    else if (penc & PE_F64BIT) {
        convert_bytes *= 8;
        convert_fnc = s32tof64;
     }
-    else if (play_mode->encoding & PE_ULAW)
+    else if (penc & PE_ULAW)
        convert_fnc = s32toulaw;
-    else if (play_mode->encoding & PE_ALAW)
+    else if (penc & PE_ALAW)
        convert_fnc = s32toalaw;
-    else if (play_mode->encoding & PE_SIGNED)
+    else if (penc & PE_SIGNED)
        convert_fnc = s32tos8;
     else
        convert_fnc = s32tou8;
@@ -3010,7 +2654,26 @@ int32 general_output_convert(DATA_T *buf, int32 count)
     return (count * convert_bytes);
 }
 
+///r
+int get_encoding_sample_size(int32 enc)
+{      
+       uint32 penc = use_temp_encoding ? temp_encoding : enc;
+       int size = (penc & PE_MONO) ? 1 : 2;
 
+       if(penc & PE_16BIT)
+               size *= 2;
+       else if (penc & PE_24BIT)
+               size *= 3;
+       else if (penc & PE_32BIT)
+               size *= 4;
+       else if (penc & PE_F32BIT)
+               size *= 4;
+       else if (penc & PE_64BIT)
+               size *= 8;
+       else if (penc & PE_F64BIT)
+               size *= 8;
+       return size;
+}
 
 ///r
 int validate_encoding(int enc, int include_enc, int exclude_enc)
@@ -3182,26 +2845,6 @@ const char *output_encoding_string(int enc)
            return "unsigned 8bit";
     /*NOTREACHED*/
 }
-///r
-int get_encoding_sample_size(int32 enc)
-{
-       int size = (enc & PE_MONO) ? 1 : 2;
-
-       if(enc & PE_16BIT)
-               size *= 2;
-       else if (enc & PE_24BIT)
-               size *= 3;
-       else if (enc & PE_32BIT)
-               size *= 4;
-       else if (enc & PE_F32BIT)
-               size *= 4;
-       else if (enc & PE_64BIT)
-               size *= 8;
-       else if (enc & PE_F64BIT)
-               size *= 8;
-
-       return size;
-}
 
 
 #if !defined(KBTIM) && !defined(WINVSTI)
index 4000ead..61e6a69 100644 (file)
@@ -26,6 +26,9 @@
 //#include "output.h"
 
 
+#define CNV_USE_TEMP_ENCODE
+// define : output.c general_output_convert() \82Å\83o\83b\83t\83@\95Ï\8a· \83V\83\93\83v\83\8b\82È\95Ï\8a·1\89ñ\82È\82Ì\82Å\91¬\82¢
+// undef : \8ae\8fo\97Í\82Å\83o\83b\83t\83@\95Ï\8a· \95Ï\8a·\82ð2\89ñ\82·\82é\95ª\92x\82¢
 
 
 /* Data format encoding bits */
@@ -214,7 +217,6 @@ extern int32 apply_encoding(int32 old_enc, int32 new_enc);
 extern const char *output_encoding_string(int enc);
 extern int get_encoding_sample_size(int32 enc);
 
-
 extern char *create_auto_output_name(const char *input_filename, const char *ext_str, char *output_dir, int mode);
 
 #if defined(__W32__)
@@ -225,6 +227,9 @@ extern char *create_auto_output_name(const char *input_filename, const char *ext
 #define FILE_OUTPUT_MODE       O_WRONLY|O_CREAT|O_TRUNC, 0644
 #endif
 
+extern void set_temporary_encoding(uint32 enc); // called open_output()
+extern void reset_temporary_encoding(void); // called close_output()
+
 extern double div_playmode_rate;
 extern double playmode_rate_div2;
 extern double playmode_rate_div3;
@@ -237,5 +242,9 @@ extern double playmode_rate_us;
 extern void init_output(void);
 extern void change_output_volume(int32);
 
+#ifdef __W32__
+extern CRITICAL_SECTION critSect;
+#endif
+
 #endif /* ___OUTPUT_H_ */
 
index 8f57804..acf208c 100644 (file)
@@ -118,7 +118,6 @@ static int old_rate = -1;
 #endif
 
 static int midi_streaming = 0;
-int volatile stream_max_compute = 500; /* compute time limit (in msec) when streaming */
 static int prescanning_flag;
 static int32 midi_restart_time = 0;
 Channel channel[MAX_CHANNELS];
@@ -131,6 +130,10 @@ int8 opt_init_keysig = 8;
 int8 opt_force_keysig = 8;
 int32 current_play_tempo = 500000;
 int opt_realtime_playing = 0;
+///r
+int volatile stream_max_compute = 500; /* compute time limit (in msec) when streaming */
+uint32 opt_rtsyn_latency = 200; 
+int opt_rtsyn_skip_aq = 0;
 int reduce_voice_threshold = -1;
 ///r
 int reduce_quality_threshold = -1;
@@ -3777,7 +3780,7 @@ static int init_channel_portamento(MidiEvent *e)
 {
 #if 1 // portamento and leagato
     int i, ch = e->channel, note = MIDI_EVENT_NOTE(e);
-       int32 times, fine = note * PORTAMENTO_CONTROL_RATIO;
+       int32 times = 0, fine = note * PORTAMENTO_CONTROL_RATIO;
 
        if(!(channel[ch].portamento_control != -1
                || channel[ch].portamento
@@ -12061,10 +12064,8 @@ static void do_compute_data_midi(int32 count)
        // elion add.
        // move effect.c do_effect()
        //mix_compressor(buffer_pointer, cnt);
-
-#ifndef MASTER_VST_EFFECT2     
     do_effect(buffer_pointer, count);
-#endif
+
        if(opt_realtime_playing)
                compute_data_midi_skip(0, cnt); // silent skip , buffer check
        current_sample += count;
index 0656097..e5e93b0 100644 (file)
@@ -794,6 +794,8 @@ extern ChannelBitMask drumchannel_mask;
 extern ChannelBitMask default_drumchannels;
 extern ChannelBitMask drumchannels;
 
+
+
 extern int adjust_panning_immediately;
 extern int max_voices;
 extern int voices, upper_voices;
@@ -825,6 +827,10 @@ extern int opt_modulation_envelope;
 extern int noise_sharp_type;
 extern int32 current_play_tempo;
 extern int opt_realtime_playing;
+extern int volatile stream_max_compute;
+extern uint32 opt_rtsyn_latency;
+extern int opt_rtsyn_skip_aq;
+
 extern int reduce_voice_threshold; /* msec */
 ///r
 extern int reduce_quality_threshold;
index 54e1606..0073ca3 100644 (file)
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
-///r
+
 #ifdef AU_PORTAUDIO
+
+
 #define PORTAUDIO_V19 1
 
 #ifdef __POCC__
@@ -124,10 +126,6 @@ static unsigned int bytesPerBuffer;
 static int pa_active=0;
 static int first=1;
 
-#if defined(__W32__)
-CRITICAL_SECTION critSect;
-#endif
-
 
 
 #if PORTAUDIO_V19
@@ -277,7 +275,8 @@ void processor_output(
        buflimit = (uint8*)pa_data.buf + bytesPerInBuffer;
        samplesToGo = pa_data.samplesToGo;
        bufpoint = (uint8*)pa_data.bufpoint;
-       
+
+#ifndef CNV_USE_TEMP_ENCODE            
        if(conv24_32){ // Int24
                samples1 = outputFrames * stereo;
                if(samplesToGo < datalength){
@@ -299,7 +298,6 @@ void processor_output(
                                *out++ = 0;
                        }
                }else{
-
                        for(i = 0; i < samples1; i++){
                                *out++ = 0;
                                *out++ = *(bufpoint)++;
@@ -341,7 +339,9 @@ void processor_output(
                        }
                        samplesToGo -= datalength;
                }
-       }else{
+       }else
+#endif
+       {
                if(samplesToGo < datalength ){
                        if(bufpoint+samplesToGo <= buflimit){
                                memcpy(out, bufpoint, samplesToGo);
@@ -380,7 +380,7 @@ void processor_output(
 }
 
 int paCallback(  const void *inputBuffer, void *outputBuffer,
-                     unsigned long framesPerBuffer,
+                     unsigned long outputFrames,
                      const PaStreamCallbackTimeInfo* timeInfo,
                      PaStreamCallbackFlags statusFlags,
                         void *userData )
@@ -408,13 +408,14 @@ int paCallback(  void *inputBuffer, void *outputBuffer,
        EnterCriticalSection(&critSect);
 #endif
     out = (uint8*)outputBuffer;
-       datalength = framesPerBuffer*data_nbyte*stereo;
+       datalength = outputFrames * data_nbyte * stereo;
 //     buflimit = pa_data.buf+bytesPerInBuffer*2;
 //     buflimit = pa_data.buf+DATA_BLOCK_SIZE*2;
        buflimit = (uint8*)pa_data.buf+bytesPerInBuffer;
        samplesToGo = pa_data.samplesToGo;
        bufpoint = (uint8*)pa_data.bufpoint;
        
+#ifndef CNV_USE_TEMP_ENCODE    
        if(conv16_32){
                if(samplesToGo < datalength  ){         
                        for(i=0;i<(samplesToGo>>1);i++){
@@ -446,7 +447,9 @@ int paCallback(  void *inputBuffer, void *outputBuffer,
                        }
                        samplesToGo -= datalength;
                }
-       }else{
+       }else
+#endif
+       {
                if(samplesToGo < datalength  ){
                        if(bufpoint+samplesToGo <= buflimit){
                                memcpy(out, bufpoint, samplesToGo);
@@ -700,11 +703,6 @@ static int open_output(void)
     }
 #endif
 
-       numBuffers = dpm.extra_param[0];
-       framesPerBuffer = audio_buffer_size;
-       framesPerInBuffer = numBuffers * framesPerBuffer;       
-       bytesPerBuffer = framesPerBuffer * data_nbyte * stereo; ///r
-       bytesPerInBuffer = framesPerInBuffer * data_nbyte * stereo;
 
        /* set StreamParameters */
        StreamParameters.device = DeviceIndex;
@@ -727,7 +725,6 @@ static int open_output(void)
                if( paFormatIsSupported != Pa_IsFormatSupported( NULL , &StreamParameters,(double) dpm.rate )){
                        StreamParameters.sampleFormat = paInt32;
                        conv16_32 = 1;
-                       bytesPerInBuffer *= 2;  // data_nbyte*2 ??
                } else {
                        StreamParameters.sampleFormat = paInt16;
                        conv16_32 = 0;
@@ -750,11 +747,38 @@ static int open_output(void)
                wasapiStreamInfo.streamOption = (PaWasapiStreamOption)opt_pa_wasapi_stream_option;
 #endif
                StreamParameters.hostApiSpecificStreamInfo = &wasapiStreamInfo;
-               conv24_32 = (SampleFormat == paInt24) ? 1 : 0; // only use RedirectHostProcessor
+               if(SampleFormat == paInt24 && (opt_pa_wasapi_flag & paWinWasapiRedirectHostProcessor) )
+                       conv24_32 = 1; // only use RedirectHostProcessor
+               else
+                       conv24_32 = 0;
        }else{
                StreamParameters.hostApiSpecificStreamInfo = NULL;
                conv24_32 = 0;
        }
+       
+#ifdef CNV_USE_TEMP_ENCODE
+       if(conv24_32){                  
+               int tmp_enc = dpm.encoding;
+               tmp_enc &= ~PE_24BIT;
+               tmp_enc |= PE_32BIT;
+               set_temporary_encoding(tmp_enc);
+               data_nbyte = data_nbyte * 4 / 3;
+       }else if(conv16_32 == 2){                       
+               int tmp_enc = dpm.encoding;
+               tmp_enc &= ~PE_16BIT;
+               tmp_enc |= PE_32BIT;
+               set_temporary_encoding(tmp_enc);
+               data_nbyte *= 2;
+       }else{
+               reset_temporary_encoding();
+       }
+#endif
+
+       numBuffers = dpm.extra_param[0];
+       framesPerBuffer = audio_buffer_size;
+       framesPerInBuffer = numBuffers * framesPerBuffer;       
+       bytesPerBuffer = framesPerBuffer * data_nbyte * stereo; ///r
+       bytesPerInBuffer = framesPerInBuffer * data_nbyte * stereo;
 
        paStreamFlags = paNoFlag;
 
@@ -842,7 +866,24 @@ static int open_output(void)
        pa_data.bufpoint = pa_data.buf;
        pa_data.bufepoint = pa_data.buf;
 //     firsttime = 1;
-///r
+///r   
+#ifdef CNV_USE_TEMP_ENCODE
+       if(conv24_32){                  
+               int tmp_enc = dpm.encoding;
+               tmp_enc &= ~PE_24BIT;
+               tmp_enc |= PE_32BIT;
+               set_temporary_encoding(tmp_enc);
+               data_nbyte = data_nbyte * 4 / 3;
+       }else if(conv16_32 == 2){                       
+               int tmp_enc = dpm.encoding;
+               tmp_enc &= ~PE_16BIT;
+               tmp_enc |= PE_32BIT;
+               set_temporary_encoding(tmp_enc);
+               data_nbyte *= 2;
+       }else{
+               reset_temporary_encoding();
+       }
+#endif
        numBuffers = Pa_GetMinNumBuffers( framesPerBuffer, dpm.rate );
        //framesPerInBuffer = numBuffers * framesPerBuffer;
        //if (framesPerInBuffer < 4096) framesPerInBuffer = 4096;
@@ -879,6 +920,9 @@ error2:
   free_portaudio_dll();
 #endif
 #endif
+#ifdef CNV_USE_TEMP_ENCODE
+       reset_temporary_encoding();
+#endif
 
        return -1;
 }
@@ -979,6 +1023,9 @@ static int output_data(const uint8 *buf, size_t nbytes)
 
 error:
        Pa_Terminate(); pa_active=0;
+#ifdef CNV_USE_TEMP_ENCODE
+       reset_temporary_encoding();
+#endif
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "PortAudio error: %s\n", Pa_GetErrorText( err ) );
        return -1;
 }
@@ -1026,8 +1073,10 @@ static void close_output(void)
        err = Pa_CloseStream( stream );
 //     if( err != paNoError ) goto error;
        Pa_Terminate(); 
-       pa_active=0;    
-
+       pa_active=0;            
+#ifdef CNV_USE_TEMP_ENCODE
+       reset_temporary_encoding();
+#endif
 #ifdef AU_PORTAUDIO_DLL
 #ifndef PORTAUDIO_V19
   free_portaudio_dll();
@@ -1038,6 +1087,9 @@ static void close_output(void)
 
 error:
        Pa_Terminate(); pa_active=0;
+#ifdef CNV_USE_TEMP_ENCODE
+       reset_temporary_encoding();
+#endif
 #ifdef AU_PORTAUDIO_DLL
 #ifndef PORTAUDIO_V19
   free_portaudio_dll();
@@ -1276,7 +1328,6 @@ error1:
 #else
        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "PortAudio error in acntl : %s\n", Pa_GetErrorText(err));
 #endif /* __W32__ */
-error2:
        Pa_Terminate();
        return err_unknown;
 }
index b0c88dd..9fb67f0 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "interface.h"
 #include "timidity.h"
+#include "output.h"
 
 #include <stdio.h>
 #ifdef HAVE_STDLIB_H
@@ -20,9 +21,6 @@
 ///r
 #define PA_DEVLIST_MAX 60
 #define PA_DEVLIST_LEN 64
-
-#define DEVLIST_MAX 20
-
 #define PA_DEVLIST_DEFAULT_NAME "(default)"
 #define PA_DEVLIST_ERROR_NAME "(null)"
 
index 1976331..dc04821 100644 (file)
@@ -84,6 +84,11 @@ static ALIGN uint8 thread_finish_all[MAX_THREADS]; // byte*16=64bit*2=128bit
 static ALIGN uint8 thread_finish[MAX_THREADS]; // byte*16=64bit*2=128bit
 CRITICAL_SECTION critThread;
 
+void set_compute_thread_priority(DWORD var)
+{
+       ComputeThreadPriority = var;
+}
+
 #if (USE_X86_EXT_INTRIN >= 3)
 #define THREAD_WAIT_MAIN _mm_pause(); // SSE2
 #define THREAD_WAIT_SUB Sleep(0);
index ae4343b..3b36056 100644 (file)
@@ -38,6 +38,9 @@ extern int compute_thread_num;
 extern int compute_thread_ready;
 
 #ifdef MULTI_THREAD_COMPUTE
+#if defined(__W32__)
+extern void set_compute_thread_priority(DWORD var);
+#endif // __W32__
 extern void begin_compute_thread(void);
 extern void terminate_compute_thread(void);
 extern void reset_compute_thread(void);
index 9eb8d96..04b6a15 100644 (file)
 #ifdef AU_W32
 #include "w32_a.h"
 #endif
+#ifdef AU_WASAPI
+#include "wasapi_a.h"
+#endif
+
 #ifdef AU_PORTAUDIO
 #include "portaudio_a.h"
 #endif
@@ -134,7 +138,9 @@ uint8 opt_normal_chorus_plus = 5; // chorusEX
 #if defined(__W32__)
 extern DWORD processPriority;
 DWORD processPriority = NORMAL_PRIORITY_CLASS; // \83v\83\8d\83Z\83X\82Ì\83v\83\89\83C\83I\83\8a\83e\83B
-#if !defined(IA_W32G_SYN)
+#if defined(IA_W32G_SYN) || defined(WINDRV)
+DWORD syn_ThreadPriority = THREAD_PRIORITY_NORMAL;
+#else
 int PlayerThreadPriority = THREAD_PRIORITY_NORMAL;
 int GUIThreadPriority = THREAD_PRIORITY_NORMAL;
 #endif
@@ -202,6 +208,7 @@ enum {
        TIM_OPT_RT_PRIO,
        TIM_OPT_SEQ_PORTS,
        TIM_OPT_RTSYN_LATENCY,
+       TIM_OPT_RTSYN_SKIP_AQ,
        TIM_OPT_REALTIME_LOAD,
        TIM_OPT_ADJUST_KEY,
        TIM_OPT_VOICE_QUEUE,
@@ -233,6 +240,14 @@ enum {
        TIM_OPT_OUTPUT_DEVICE_ID,
        TIM_OPT_WMME_DEVICE_ID,
        TIM_OPT_WAVE_FORMAT_EXT,
+       TIM_OPT_WASAPI_DEVICE_ID,
+       TIM_OPT_WASAPI_LATENCY,
+       TIM_OPT_WASAPI_FORMAT_EXT,
+       TIM_OPT_WASAPI_EXCLUSIVE,
+       TIM_OPT_WASAPI_POLLING,
+       TIM_OPT_WASAPI_PRIORITY,
+       TIM_OPT_WASAPI_STREAM_CATEGORY,
+       TIM_OPT_WASAPI_STREAM_OPTION,
        TIM_OPT_PA_WMME_DEVICE_ID,
        TIM_OPT_PA_DS_DEVICE_ID,
        TIM_OPT_PA_ASIO_DEVICE_ID,
@@ -410,7 +425,7 @@ static const struct option longopts[] = {
        { "emu-delay-time",                     required_argument, NULL, TIM_OPT_EMU_DELAY_TIME },
 #if defined(__W32__)
        { "process-priority",           required_argument, NULL, TIM_OPT_PROCESS_PRIORITY },
-#if !defined(IA_W32G_SYN)
+#if !(defined(IA_W32G_SYN) || defined(WINDRV))
        { "player-thread-priority",     required_argument, NULL, TIM_OPT_PLAYER_THREAD_PRIORITY },
 #endif
 #endif
@@ -445,13 +460,24 @@ static const struct option longopts[] = {
        { "output-swab",            optional_argument, NULL, TIM_OPT_OUTPUT_SWAB },
 #if defined(IA_WINSYN) || defined(IA_W32G_SYN) || defined(IA_W32GUI)
        { "rtsyn-latency",          required_argument, NULL, TIM_OPT_RTSYN_LATENCY },
+       { "rtsyn-skip-aq",          required_argument, NULL, TIM_OPT_RTSYN_SKIP_AQ },
 #endif
 ///r
        { "output-device-id",           required_argument, NULL, TIM_OPT_OUTPUT_DEVICE_ID },
 #ifdef AU_W32
        { "wmme-device-id",                     required_argument, NULL, TIM_OPT_WMME_DEVICE_ID },
-       { "wave_format_ext",            required_argument, NULL, TIM_OPT_WAVE_FORMAT_EXT },
        { "wave-format-ext",            required_argument, NULL, TIM_OPT_WAVE_FORMAT_EXT },
+       { "wmme-format-ext",            required_argument, NULL, TIM_OPT_WAVE_FORMAT_EXT },
+#endif
+#ifdef AU_WASAPI
+       { "wasapi-device-id",           required_argument, NULL, TIM_OPT_WASAPI_DEVICE_ID },
+       { "wasapi-latency",                     required_argument, NULL, TIM_OPT_WASAPI_LATENCY },
+       { "wasapi-format-ext",          required_argument, NULL, TIM_OPT_WASAPI_FORMAT_EXT },
+       { "wasapi-exclusive",           required_argument, NULL, TIM_OPT_WASAPI_EXCLUSIVE },
+       { "wasapi-polling",                     required_argument, NULL, TIM_OPT_WASAPI_POLLING },
+       { "wasapi-priority",            required_argument, NULL, TIM_OPT_WASAPI_PRIORITY },
+       { "wasapi-stream-category",             required_argument, NULL, TIM_OPT_WASAPI_STREAM_CATEGORY },
+       { "wasapi-stream-option",               required_argument, NULL, TIM_OPT_WASAPI_STREAM_OPTION },
 #endif
 #ifdef AU_PORTAUDIO    
        { "pa-wmme-device-id",          required_argument, NULL, TIM_OPT_PA_WMME_DEVICE_ID },
@@ -465,7 +491,6 @@ static const struct option longopts[] = {
        { "pa-wasapi-stream-option",required_argument, NULL, TIM_OPT_PA_WASAPI_STREAM_OPTION },
 #endif
 #endif
-
        { "wave-extensible",        no_argument,       NULL, TIM_OPT_WAVE_EXTENSIBLE },
        { "wave-update-step",       optional_argument, NULL, TIM_OPT_WAVE_UPDATE_STEP },
 #ifdef AU_FLAC
@@ -643,6 +668,7 @@ static inline int parse_opt_seq_ports(const char *);
 #endif
 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN) || defined(IA_NPSYN) || defined(IA_W32G_SYN) || defined(IA_W32GUI)
 static inline int parse_opt_rtsyn_latency(const char *);
+static inline int parse_opt_rtsyn_skip_aq(const char *);
 #endif
 static inline int parse_opt_j(const char *);
 static inline int parse_opt_K(const char *);
@@ -667,6 +693,16 @@ static inline int parse_opt_output_device_id(const char *);
 static inline int parse_opt_wmme_device_id(const char *);
 static inline int parse_opt_wave_format_ext(const char *arg);
 #endif
+#ifdef AU_WASAPI
+static inline int parse_opt_wasapi_device_id(const char *arg);
+static inline int parse_opt_wasapi_latency(const char *arg);
+static inline int parse_opt_wasapi_format_ext(const char *arg);
+static inline int parse_opt_wasapi_exclusive(const char *arg);
+static inline int parse_opt_wasapi_poling(const char *arg);
+static inline int parse_opt_wasapi_priority(const char *arg);
+static inline int parse_opt_wasapi_stream_category(const char *arg);
+static inline int parse_opt_wasapi_stream_option(const char *arg);
+#endif
 #ifdef AU_PORTAUDIO
 static inline int parse_opt_pa_wmme_device_id(const char *);
 static inline int parse_opt_pa_ds_device_id(const char *);
@@ -781,7 +817,7 @@ static inline int parse_opt_od_drive_xg(const char *arg);
 
 #if defined(__W32__)
 static inline int parse_opt_process_priority(const char *arg);
-#if !defined(IA_W32G_SYN)
+#if !(defined(IA_W32G_SYN) || defined(WINDRV))
 static inline int parse_opt_player_thread_priority(const char *arg);
 #endif
 static void w32_exit(void);
@@ -4029,6 +4065,8 @@ MAIN_INTERFACE int set_tim_opt_long(int c, const char *optarg, int index)
 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN) || defined(IA_NPSYN) || defined(IA_W32G_SYN) || defined(IA_W32GUI)
        case TIM_OPT_RTSYN_LATENCY:
                return parse_opt_rtsyn_latency(arg);
+       case TIM_OPT_RTSYN_SKIP_AQ:
+               return parse_opt_rtsyn_skip_aq(arg);
 #endif
        case TIM_OPT_REALTIME_LOAD:
                return parse_opt_j(arg);
@@ -4105,6 +4143,24 @@ MAIN_INTERFACE int set_tim_opt_long(int c, const char *optarg, int index)
        case TIM_OPT_WAVE_FORMAT_EXT:
                return parse_opt_wave_format_ext(arg);
 #endif
+#ifdef AU_WASAPI
+       case TIM_OPT_WASAPI_DEVICE_ID:
+               return parse_opt_wasapi_device_id(arg);
+       case TIM_OPT_WASAPI_LATENCY:
+               return parse_opt_wasapi_latency(arg);
+       case TIM_OPT_WASAPI_FORMAT_EXT:
+               return parse_opt_wasapi_format_ext(arg);
+       case TIM_OPT_WASAPI_EXCLUSIVE:
+               return parse_opt_wasapi_exclusive(arg);
+       case TIM_OPT_WASAPI_POLLING:
+               return parse_opt_wasapi_polling(arg);
+       case TIM_OPT_WASAPI_PRIORITY:
+               return parse_opt_wasapi_priority(arg);
+       case TIM_OPT_WASAPI_STREAM_CATEGORY:
+               return parse_opt_wasapi_stream_category(arg);
+       case TIM_OPT_WASAPI_STREAM_OPTION:
+               return parse_opt_wasapi_stream_option(arg);
+#endif
 #ifdef AU_PORTAUDIO
        case TIM_OPT_PA_WMME_DEVICE_ID:
                return parse_opt_pa_wmme_device_id(arg);
@@ -4264,7 +4320,7 @@ MAIN_INTERFACE int set_tim_opt_long(int c, const char *optarg, int index)
 #if defined(__W32__)
        case TIM_OPT_PROCESS_PRIORITY:
                return parse_opt_process_priority(arg);
-#if !defined(IA_W32G_SYN)
+#if !(defined(IA_W32G_SYN) || defined(WINDRV))
        case TIM_OPT_PLAYER_THREAD_PRIORITY:
                return parse_opt_player_thread_priority(arg);
 #endif
@@ -5765,7 +5821,31 @@ static int parse_opt_h(const char *arg)
 #ifdef AU_W32
 "             --wmme-device-id=n (for Windows only)",
 "               Number of WMME device ID (-1: Default device, 0..19: other)",
-"             --wave-format-ext=n",
+"             --wave-format-ext=n , --wmme-format-ext=n (for Windows only)",
+"               WMME Enable WAVE_FORMAT_EXTENSIBLE (default is 1)",
+#endif
+#ifdef AU_WASAPI
+"             --wasapi-device-id=n (for Windows only)",
+"               Number of WASAPI device ID (-1: Default device, 0..19: other)",
+"             --wasapi-latency=n (for Windows only)",
+"               WASAPI Latency ms n=1-9999 depend device (default is 30)",
+"             --wasapi-format-ext=n (for Windows only)",
+"               WASAPI Enable WAVE_FORMAT_EXTENSIBLE (default is 1)",
+"             --wasapi-exclusive=n (for Windows only)",
+"               WASAPI 0:Shared mode 1:Exclusive mode (default is 0)",
+"             --wasapi-polling=n (for Windows only)",
+"               WASAPI Flags 0:Event 1:Polling (default is 0)",
+"             --wasapi_priority=n (for Windows only)",
+"               WASAPI ThreadPriority (default is 0)",
+"               0:None 1:Audio , 2:Capture:2 , 3:Distribution , 4:Games , 5:playback , 6:ProAudio , 7:WindowManager",
+"             --wasapi-stream-category=n (for Windows only)",
+"               WASAPI StreamCategory (default is 0)",
+"               0:Other , 1:None , 2:None , 3:Communications , 4:Alerts , 5:SoundEffects ,",
+"               6:GameEffects , 7:GameMedia , 8:GameChat , 9:Speech , 10:Movie , 11:Media",
+"               values 1,2 are deprecated on Windows 10 and not included into enumeration",
+"             --wasapi-stream-option=n (for Windows only)",
+"               WASAPI StreamOption 0:None 1:Raw 2:MatchFormat (default is 0)",
+"               1:Raw bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1",
 #endif
 #ifdef AU_PORTAUDIO
 "             --pa-asio-device-id=n",
@@ -6383,13 +6463,6 @@ static inline int parse_opt_seq_ports(const char *arg)
 }
 #endif
 
-#if defined(IA_W32GUI)
-static inline int parse_opt_rtsyn_latency(const char *arg)
-{
-       /* --rtsyn-latency */
-       return 0;
-}
-#endif
 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN) ||defined(IA_NPSYN) || defined(IA_W32G_SYN)
 static inline int parse_opt_rtsyn_latency(const char *arg)
 {
@@ -6402,6 +6475,25 @@ static inline int parse_opt_rtsyn_latency(const char *arg)
        rtsyn_set_latency(latency);
        return 0;
 }
+
+static inline int parse_opt_rtsyn_skip_aq(const char *arg)
+{
+       /* --rtsyn-skip-aq */
+       if (!arg) return 0;
+       rtsyn_set_skip_aq(atoi(arg));
+       return 0;
+}
+#elif defined(IA_W32GUI)
+static inline int parse_opt_rtsyn_latency(const char *arg)
+{
+       /* --rtsyn-latency */
+       return 0;
+}
+static inline int parse_opt_rtsyn_skip_aq(const char *arg)
+{
+       /* --rtsyn-skip-aq */
+       return 0;
+}
 #endif
 
 static inline int parse_opt_j(const char *arg)
@@ -6716,6 +6808,64 @@ static inline int parse_opt_wmme_buffer_num(const char *arg)
        return 0;
 }
 #endif
+#ifdef AU_WASAPI
+static inline int parse_opt_wasapi_device_id(const char *arg)
+{
+       /* --wasapi-device-id */
+       if (!arg) return 0;
+       opt_wasapi_device_id = atoi(arg);
+       return 0;
+}
+static inline int parse_opt_wasapi_latency(const char *arg)
+{
+       /* --wasapi-latency */
+       if (!arg) return 0;
+       opt_wasapi_latency = atoi(arg);
+       return 0;
+}
+static inline int parse_opt_wasapi_format_ext(const char *arg)
+{
+       /* --wasapi-format_ext */
+       if (!arg) return 0;
+       opt_wasapi_format_ext = atoi(arg);
+       return 0;
+}
+static inline int parse_opt_wasapi_exclusive(const char *arg)
+{
+       /* --wasapi-exclusive */
+       if (!arg) return 0;
+       opt_wasapi_exclusive = atoi(arg);
+       return 0;
+}
+static inline int parse_opt_wasapi_polling(const char *arg)
+{
+       /* --wasapi-polling */
+       if (!arg) return 0;
+       opt_wasapi_polling = atoi(arg);
+       return 0;
+}
+static inline int parse_opt_wasapi_priority(const char *arg)
+{
+       /* --wasapi-priority */
+       if (!arg) return 0;
+       opt_wasapi_priority = atoi(arg);
+       return 0;
+}
+static inline int parse_opt_wasapi_stream_category(const char *arg)
+{
+       /* --wasapi-stream-category */
+       if (!arg) return 0;
+       opt_wasapi_stream_category = atoi(arg);
+       return 0;
+}
+static inline int parse_opt_wasapi_stream_option(const char *arg)
+{
+       /* --wasapi-stream-option */
+       if (!arg) return 0;
+       opt_wasapi_stream_option = atoi(arg);
+       return 0;
+}
+#endif
 ///r
 #ifdef AU_PORTAUDIO
 static inline int parse_opt_pa_wmme_device_id(const char *arg)
@@ -7209,7 +7359,7 @@ static inline int parse_opt_process_priority(const char *arg)
        return 0;
 }
 
-#ifndef IA_W32G_SYN
+#if !(defined(IA_W32G_SYN) || defined(WINDRV))
 static inline int parse_opt_player_thread_priority(const char *arg)
 {
        PlayerThreadPriority = (arg) ? (DWORD)atoi(arg) : THREAD_PRIORITY_NORMAL;
@@ -8233,7 +8383,7 @@ MAIN_INTERFACE int timidity_play_main(int nfiles, char **files)
                processPriority == REALTIME_PRIORITY_CLASS)
            if(!SetPriorityClass(GetCurrentProcess(), processPriority))
                        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Error changing process priority");
-#if !defined(IA_W32G_SYN)
+#if !(defined(IA_W32G_SYN) || defined(WINDRV))
        if( PlayerThreadPriority == THREAD_PRIORITY_LOWEST ||
                PlayerThreadPriority == THREAD_PRIORITY_BELOW_NORMAL ||
                PlayerThreadPriority == THREAD_PRIORITY_NORMAL ||
@@ -8612,7 +8762,10 @@ int main(int argc, char **argv)
 ///r
        load_all_instrument();
 
-#ifdef MULTI_THREAD_COMPUTE
+#ifdef MULTI_THREAD_COMPUTE    
+#if defined(__W32__) && ( defined(IA_W32G_SYN) )
+       set_compute_thread_priority(syn_ThreadPriority);
+#endif
        begin_compute_thread();
 #endif
        nfiles = argc - optind;
index 9bbface..7d3b790 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\wasapi_a.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\wave_a.c"
                                >
                        </File>
index b19a2ef..c92f661 100644 (file)
       <AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
       <ObjectFileName>.\Debug/</ObjectFileName>
       <ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
-      <WarningLevel>Level4</WarningLevel>
+      <WarningLevel>Level3</WarningLevel>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
       <CompileAs>CompileAsC</CompileAs>
     <ClCompile Include="vorbis_a.c" />
     <ClCompile Include="w32_a.c" />
     <ClCompile Include="w32_gogo.c" />
+    <ClCompile Include="wasapi_a.c" />
     <ClCompile Include="wave_a.c" />
     <ClCompile Include="wrd_read.c" />
     <ClCompile Include="wrdt.c" />
     <ClInclude Include="vstwrapper.h" />
     <ClInclude Include="w32_a.h" />
     <ClInclude Include="w32_gogo.h" />
+    <ClInclude Include="wasapi_a.h" />
     <ClInclude Include="wrd.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
index 12fca32..e86f266 100644 (file)
@@ -175,6 +175,7 @@ static int  open_output     (void); /* 0=success, 1=warning, -1=fatal error */
 static void close_output    (void);
 static int  output_data     (const uint8 * Data, size_t Size);
 static int  acntl           (int request, void * arg);
+static int  detect          (void);
 
 static void print_device_list(void);
 
@@ -232,7 +233,6 @@ static void                         WaitForBuffer   (int WaitForAllBuffers);
 
 /*****************************************************************************************************************************/
 
-static int detect(void);
 
 #define dpm w32_play_mode
 
@@ -261,14 +261,15 @@ static int open_output(void)
 ///r
     int             i;
 //     int             IsMono;
-    WAVEFORMATEX    wf;
+       WAVEFORMATEXTENSIBLE wfe = {0};
+       WAVEFORMATEX    *pwf = NULL;
     WAVEOUTCAPS     woc;
     MMRESULT        Result;
     UINT            DeviceID;
        int ret;
        int tmp;
-       WAVEFORMATEXTENSIBLE wfe;
-// guid_WAVE_FORMAT.Data1 = WAVE_FORMAT_X
+       int format_ext;
+
        GUID guid_WAVE_FORMAT = {WAVE_FORMAT_UNKNOWN,0x0000,0x0010,{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
        
 /*
@@ -295,64 +296,108 @@ static int open_output(void)
 /** They can't mean these. **/
 ///r
        dpm.encoding &= ~(PE_BYTESWAP);
-       if (dpm.encoding & (PE_16BIT | PE_24BIT | PE_32BIT | PE_F32BIT | PE_64BIT | PE_F64BIT))
+       if (dpm.encoding & (PE_16BIT | PE_24BIT | PE_32BIT | PE_F32BIT | PE_64BIT | PE_F64BIT)){
         dpm.encoding |= PE_SIGNED;
-    else // 8bit PE_ULAW PE_ALAW only unsigned
+       }else // 8bit PE_ULAW PE_ALAW only unsigned
         dpm.encoding &= ~PE_SIGNED;
-
-//    IsMono  = (dpm.encoding & PE_MONO);
-    memset(&wf, 0, sizeof(wf));
-       memset(&wfe, 0, sizeof(wfe));
-
-       if (dpm.encoding & PE_16BIT){
-               wf.wFormatTag = WAVE_FORMAT_PCM; // only WAVEFORMATEX
-               wf.wBitsPerSample = (int) 16;
-       }else if (dpm.encoding & PE_24BIT){
-               wf.wFormatTag = opt_wave_format_ext == 1 ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
-               guid_WAVE_FORMAT.Data1 = WAVE_FORMAT_PCM;
-               wf.wBitsPerSample = (int) 24;
+       format_ext = (dpm.encoding & (PE_ULAW | PE_ALAW)) ? 0 : opt_wave_format_ext;
+       if(format_ext){
+               pwf = &wfe.Format;
+               memcpy(&wfe.SubFormat, &guid_WAVE_FORMAT, sizeof(GUID));
+               pwf->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+               pwf->cbSize       = (WORD)22;
+       }else{
+               pwf = (WAVEFORMATEX *)&wfe;
+               pwf->cbSize       = (WORD)0;
+       }
+       if(dpm.encoding & PE_16BIT){
+               if(format_ext){                 
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 16;
+                       pwf->wBitsPerSample = (WORD) 16;
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 16;
+               }
+       }else if(dpm.encoding & PE_24BIT){
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 24;
+                       pwf->wBitsPerSample = (WORD) 24;
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 24;
+               }
        }else if(dpm.encoding & PE_32BIT){
-               wf.wFormatTag = opt_wave_format_ext == 1 ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
-               guid_WAVE_FORMAT.Data1 = WAVE_FORMAT_PCM;
-               wf.wBitsPerSample = (int) 32;
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 32;
+                       pwf->wBitsPerSample = (WORD) 32;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 32;
+               }
        }else if(dpm.encoding & PE_F32BIT){
-               wf.wFormatTag = opt_wave_format_ext == 1 ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_IEEE_FLOAT;
-               guid_WAVE_FORMAT.Data1 = WAVE_FORMAT_IEEE_FLOAT;
-               wf.wBitsPerSample = (int) 32;
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_IEEE_FLOAT;
+                       wfe.Samples.wValidBitsPerSample = 32;
+                       pwf->wBitsPerSample = (WORD) 32;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+                       pwf->wBitsPerSample = (WORD) 32;
+               }
        }else if(dpm.encoding & PE_64BIT){
-               wf.wFormatTag = opt_wave_format_ext == 1 ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_PCM;
-               guid_WAVE_FORMAT.Data1 = WAVE_FORMAT_PCM;
-               wf.wBitsPerSample = (int) 64;
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 64;
+                       pwf->wBitsPerSample = (WORD) 64;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 64;
+               }
        }else if(dpm.encoding & PE_F64BIT){
-               wf.wFormatTag = opt_wave_format_ext == 1 ? WAVE_FORMAT_EXTENSIBLE : WAVE_FORMAT_IEEE_FLOAT;
-               guid_WAVE_FORMAT.Data1 = WAVE_FORMAT_IEEE_FLOAT;
-               wf.wBitsPerSample = (int) 64;
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_IEEE_FLOAT;
+                       wfe.Samples.wValidBitsPerSample = 64;
+                       pwf->wBitsPerSample = (WORD) 64;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+                       pwf->wBitsPerSample = (WORD) 64;
+               }               
        }else if(dpm.encoding & PE_ALAW){
-               wf.wFormatTag = WAVE_FORMAT_ALAW; // only WAVEFORMATEX
-               wf.wBitsPerSample = (int) 8;
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_ALAW;
+                       wfe.Samples.wValidBitsPerSample = 8;
+                       pwf->wBitsPerSample = (WORD) 8;                 
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_ALAW;
+                       pwf->wBitsPerSample = (WORD) 8;
+               }
        }else if(dpm.encoding & PE_ULAW){
-               wf.wFormatTag = WAVE_FORMAT_MULAW; // only WAVEFORMATEX
-               wf.wBitsPerSample = (int) 8;
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_MULAW;
+                       wfe.Samples.wValidBitsPerSample = 8;
+                       pwf->wBitsPerSample = (WORD) 8;                 
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_MULAW;
+                       pwf->wBitsPerSample = (WORD) 8;
+               }
        }else{ // 8bit
-               wf.wFormatTag = WAVE_FORMAT_PCM; // only WAVEFORMATEX
-               wf.wBitsPerSample = (int) 8;
+               if(format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 8;
+                       pwf->wBitsPerSample = (WORD) 8;                 
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 8;
+               }
        }
+       pwf->nChannels       = (WORD)dpm.encoding & PE_MONO ? 1 : 2;
+       pwf->nSamplesPerSec  = (DWORD)dpm.rate;
+       pwf->nBlockAlign     = (WORD)(pwf->nChannels * pwf->wBitsPerSample / 8);
+       pwf->nAvgBytesPerSec = (DWORD)pwf->nSamplesPerSec * pwf->nBlockAlign;
+       wfe.dwChannelMask = pwf->nChannels==1 ? SPEAKER_MONO : SPEAKER_STEREO;
 
-       if(wf.wFormatTag == WAVE_FORMAT_EXTENSIBLE){
-               wfe.SubFormat = guid_WAVE_FORMAT;
-               wf.cbSize = (int)22;
-       }else
-               wf.cbSize = (int)0;
-
-       wf.nChannels            = (int)(dpm.encoding & PE_MONO ? 1 : 2);
-    wf.nSamplesPerSec  = (int)dpm.rate;
-       wf.nBlockAlign          = (int)(wf.nChannels * wf.wBitsPerSample / 8);
-    wf.nAvgBytesPerSec = (int)(wf.nSamplesPerSec * wf.nBlockAlign);
-       wfe.Format = wf;
-       wfe.Samples.wValidBitsPerSample = wf.wBitsPerSample; // union
-//     wfe.Samples.wSamplesPerBlock = 1;
-//     wfe.Samples.wReserved = 0;
-       wfe.dwChannelMask = wf.nChannels==1 ? SPEAKER_MONO : SPEAKER_STEREO;
 ///r
     if (dpm.extra_param[0] < 2)
     {
@@ -376,7 +421,7 @@ static int open_output(void)
 //     data_block_trunc_size = DATA_BLOCK_SIZE - (DATA_BLOCK_SIZE % wf.nBlockAlign); 
        data_block_num = dpm.extra_param[0];
        data_block_size = audio_buffer_size;
-       data_block_trunc_size = data_block_size * wf.nBlockAlign;
+       data_block_trunc_size = data_block_size * pwf->nBlockAlign;
 
 /** Open the device. **/
 
@@ -392,20 +437,13 @@ static int open_output(void)
        uDeviceID= (UINT)opt_wmme_device_id;
        }
 ///r
-       if(wf.wFormatTag == WAVE_FORMAT_EXTENSIBLE){
-               if (AllowSynchronousWaveforms)
-                       Result = waveOutOpen(&hDevice, uDeviceID, (LPCWAVEFORMATEX) &wfe, (DWORD_PTR) OnPlaybackEvent, 0, CALLBACK_FUNCTION | WAVE_ALLOWSYNC);
-               else
-                       Result = waveOutOpen(&hDevice, uDeviceID, (LPCWAVEFORMATEX) &wfe, (DWORD_PTR) OnPlaybackEvent, 0, CALLBACK_FUNCTION);
-       }else{
-               if (AllowSynchronousWaveforms)
-                       Result = waveOutOpen(&hDevice, uDeviceID, (LPWAVEFORMATEX) &wf, (DWORD_PTR) OnPlaybackEvent, 0, CALLBACK_FUNCTION | WAVE_ALLOWSYNC);
-               else
-                       Result = waveOutOpen(&hDevice, uDeviceID, (LPWAVEFORMATEX) &wf, (DWORD_PTR) OnPlaybackEvent, 0, CALLBACK_FUNCTION);
-       }
+       if (AllowSynchronousWaveforms)
+               Result = waveOutOpen(&hDevice, uDeviceID, (WAVEFORMATEX *) &wfe, (DWORD_PTR) OnPlaybackEvent, 0, CALLBACK_FUNCTION | WAVE_ALLOWSYNC);
+       else
+               Result = waveOutOpen(&hDevice, uDeviceID, (WAVEFORMATEX *) &wfe, (DWORD_PTR) OnPlaybackEvent, 0, CALLBACK_FUNCTION);
     if (Result)
     {
-        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Can't open audio device: encoding=<%s>, rate=<%d>, ch=<%d>: %s", output_encoding_string(dpm.encoding), dpm.rate, wf.nChannels, MMErrorMessage(Result));
+        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Can't open audio device: encoding=<%s>, rate=<%d>, ch=<%d>: %s", output_encoding_string(dpm.encoding), dpm.rate, pwf->nChannels, MMErrorMessage(Result));
         return -1;
     }
 #ifdef OUTPUT_DEBUG_STR
@@ -435,7 +473,7 @@ static int open_output(void)
 /** Calculate the buffer delay. **/
 ///r
     BufferDelay = data_block_size * data_block_num * 1000 / dpm.rate;
-       BufferBlockDelay = data_block_size * 1000 / dpm.rate + 1; // 1ms~
+       BufferBlockDelay = data_block_size * 1000 / dpm.rate / 4;
 
 /** Create the buffer pool. **/
 
@@ -543,7 +581,7 @@ static int output_data(const uint8 *Data, size_t Size)
     const uint8 *  d;
     int32   s;
     int32   c;
-    const int32  max_continue = 15;
+    const int32  max_continue = 1164;
        
     if (!hDevice)
                return -1;
index 1e5c06d..02fa51e 100644 (file)
 ///r
 #define DEVLIST_MAX 20
 
-typedef struct tag_DEVICELIST{
+typedef struct tag_DEVICELIST {
        int  deviceID;
        char name[MAXPNAMELEN];
 } DEVICELIST;
 
-
-extern CRITICAL_SECTION critSect;
-
-
 //extern int data_block_bits;
 //extern int data_block_num;
 ///r
diff --git a/timidity/wasapi_a.c b/timidity/wasapi_a.c
new file mode 100644 (file)
index 0000000..a398a7f
--- /dev/null
@@ -0,0 +1,1148 @@
+/*
+    TiMidity++ -- MIDI to WAVE converter and player
+    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
+    Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    wasapi_a.c
+       
+       Functions to play sound using WASAPI (Windows Vista).
+
+Based on <https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/multimedia/audio/RenderExclusiveEventDriven>,
+which is distributed under the MIT License:
+
+----
+The MIT License (MIT)
+
+Copyright (c) Microsoft Corporation
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+Portions of this repo are provided under the SIL Open Font License.
+See the LICENSE file in individual samples for additional details
+----
+
+Written by Starg.
+
+*/
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+
+#ifdef AU_WASAPI
+
+
+#ifdef __W32__
+#include "interface.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#ifndef NO_STRING_H
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#include <process.h>
+#include <tchar.h>
+
+#include "timidity.h"
+#include "common.h"
+#include "controls.h"
+#include "output.h"
+#include "wasapi_a.h"
+
+int opt_wasapi_device_id = -1; // default render
+int opt_wasapi_latency = 10; //  ms
+int opt_wasapi_format_ext = 1;
+int opt_wasapi_exclusive = 0; // shared
+int opt_wasapi_polling = 0; // 0:event 1:polling
+int opt_wasapi_priority = 0; // auto
+int opt_wasapi_stream_category = 0;
+int opt_wasapi_stream_option = 0;
+
+/*****************************************************************************************************************************/
+
+static int  open_output     (void); /* 0=success, 1=warning, -1=fatal error */
+static void close_output    (void);
+static int  output_data     (const uint8 *buf, size_t nbytes);
+static int  acntl           (int request, void *arg);
+static int  detect          (void);
+
+/*****************************************************************************************************************************/
+
+#define dpm wasapi_play_mode
+
+PlayMode dpm = {
+    DEFAULT_RATE,
+    PE_16BIT | PE_SIGNED,
+    PF_PCM_STREAM | PF_CAN_TRACE | PF_BUFF_FRAGM_OPT,
+    -1,
+    {32},
+    "WASAPI", 'x',
+    NULL,
+    &open_output,
+    &close_output,
+    &output_data,
+    &acntl,
+    &detect
+};
+
+/*****************************************************************************************************************************/
+
+#define CINTERFACE
+#define COBJMACROS
+#include <windows.h>
+#include <winbase.h>
+#include <objbase.h>
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+//#include <Avrt.h>
+#include <Audioclient.h>
+#include <audiopolicy.h>
+#define INITGUID
+#include <mmdeviceapi.h>
+#include <functiondiscoverykeys.h>
+#undef INITGUID
+#endif
+
+const CLSID tim_CLSID_MMDeviceEnumerator = {0xBCDE0395, 0xE52F, 0x467C, {0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E}};
+const IID tim_IID_IMMDeviceEnumerator    = {0xA95664D2, 0x9614, 0x4F35, {0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6}};
+const IID tim_IID_IAudioClient           = {0x1CB9AD4C, 0xDBFA, 0x4C32, {0xB1, 0x78, 0xC2, 0xF5, 0x68, 0xA7, 0x03, 0xB2}};
+const IID tim_IID_IAudioRenderClient     = {0xF294ACFC, 0x3146, 0x4483, {0xA7, 0xBF, 0xAD, 0xDC, 0xA7, 0xC2, 0x60, 0xE2}};
+
+#define SPEAKER_FRONT_LEFT        0x1
+#define SPEAKER_FRONT_RIGHT       0x2
+#define SPEAKER_FRONT_CENTER      0x4
+#define SPEAKER_MONO             (SPEAKER_FRONT_CENTER)
+#define SPEAKER_STEREO           (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)
+
+const char *ThreadPriorityName[] =
+{
+       NULL,
+       "Audio",
+       "Capture",
+       "Distribution",
+       "Games",
+       "Playback",
+       "Pro Audio",
+       "Window Manager"
+};
+
+/*****************************************************************************************************************************/
+
+typedef struct WABufferBlock_t {
+       struct WABufferBlock_t *pNext;
+       size_t CurrentSize;
+       size_t Capacity;
+       uint8 Data[1];
+} WABufferBlock;
+
+typedef struct WABuffer_t {
+       WABufferBlock *pHead;
+       WABufferBlock *pTail;
+       WABufferBlock *pFree;
+       uint32 FilledByte;
+} WABuffer;
+
+static WABuffer Buffers = {NULL, NULL, NULL, 0};
+
+static int get_filled_byte(void)
+{
+       return Buffers.FilledByte;
+}
+
+static int is_buffer_empty(void)
+{
+       return !Buffers.pHead;
+}
+
+static size_t calc_output_bytes(size_t max_bytes)
+{
+       size_t bytes = 0;
+       WABufferBlock *block = Buffers.pHead;
+
+       while(bytes < max_bytes && block){
+               bytes += block->CurrentSize;
+               block = block->pNext;
+       }
+       return bytes > max_bytes ? max_bytes : bytes;
+}
+
+static void clear_buffer(void)
+{
+       if(Buffers.pTail){
+               Buffers.pTail->pNext = Buffers.pFree;
+               Buffers.pFree = Buffers.pHead;
+               Buffers.pHead = NULL;
+               Buffers.pTail = NULL;
+       }
+}
+
+static void free_buffer(void)
+{
+       WABufferBlock *block = NULL;
+
+       clear_buffer();
+       block = Buffers.pFree;
+       while(block){
+               WABufferBlock* pNext = block->pNext;
+               free(block);
+               block = pNext;
+       }
+       Buffers.pFree = NULL;   
+       Buffers.FilledByte = 0;
+}
+
+/* if *pbuf == NULL, appends `size` count of zeros */
+static void input_buffer_partial(WABufferBlock *block, const uint8 **pbuf, size_t *bytes)
+{
+       size_t pushLength = block->Capacity - block->CurrentSize;
+
+       if(pushLength > *bytes)
+               pushLength = *bytes;
+       if(*pbuf){
+               memcpy(block->Data + block->CurrentSize, *pbuf, pushLength);
+               *pbuf += pushLength;
+       }else{
+               memset(block->Data + block->CurrentSize, 0, pushLength);
+       }
+       *bytes -= pushLength;
+       block->CurrentSize += pushLength;
+}
+
+/* if buf == NULL, appends `size` count of zeros */
+static int input_buffer(const uint8 *buf, size_t bytes)
+{
+       size_t pbytes = bytes;
+
+       while (bytes > 0){
+               if(Buffers.pTail && Buffers.pTail->CurrentSize < Buffers.pTail->Capacity){
+                       input_buffer_partial(Buffers.pTail, &buf, &bytes);
+               }else if(Buffers.pFree){
+                       WABufferBlock *block = Buffers.pFree;
+
+                       Buffers.pFree = Buffers.pFree->pNext;
+                       block->CurrentSize = 0;
+                       block->pNext = NULL;
+                       if(Buffers.pTail){
+                               Buffers.pTail->pNext = block;
+                               Buffers.pTail = block;
+                       }else{
+                               Buffers.pHead = block;
+                               Buffers.pTail = block;
+                       }
+                       input_buffer_partial(block, &buf, &bytes);
+               }else{
+                       size_t capacity = bytes * 4;
+                       WABufferBlock *new_block = (WABufferBlock *)safe_malloc(sizeof(WABufferBlock) + capacity);
+
+                       if(!new_block)
+                               return FALSE;
+                       if(Buffers.pTail)
+                               Buffers.pTail->pNext = new_block;
+                       else
+                               Buffers.pHead = new_block;
+                       Buffers.pTail = new_block;
+                       Buffers.pTail->pNext = NULL;
+                       Buffers.pTail->Capacity = capacity;
+                       Buffers.pTail->CurrentSize = 0;
+                       input_buffer_partial(Buffers.pTail, &buf, &bytes);
+               }
+       }
+       Buffers.FilledByte += pbytes;
+       return TRUE;
+}
+
+static void output_buffer(uint8 *buff, size_t bytes)
+{
+       size_t pbytes = bytes, tmp_bytes, out_bytes = 0;
+       WABufferBlock *block = Buffers.pHead;
+
+       while(bytes > 0 && block){
+               tmp_bytes = block->CurrentSize;
+               if(tmp_bytes > bytes)
+                       tmp_bytes = bytes;
+               memcpy(buff, block->Data, tmp_bytes);
+               buff += tmp_bytes;
+               bytes -= tmp_bytes;
+               out_bytes += tmp_bytes;
+               block = block->pNext;
+       }
+       while (out_bytes > 0 && Buffers.pHead){
+               tmp_bytes = Buffers.pHead->CurrentSize;
+               if(Buffers.pHead->CurrentSize > out_bytes){
+                       tmp_bytes = out_bytes;
+                       memmove(Buffers.pHead->Data, Buffers.pHead->Data + out_bytes, Buffers.pHead->CurrentSize - out_bytes);
+                       Buffers.pHead->CurrentSize -= out_bytes;
+               }else{
+                       WABufferBlock *pNext = Buffers.pHead->pNext;
+                       Buffers.pHead->pNext = Buffers.pFree;
+                       Buffers.pFree = Buffers.pHead;
+                       Buffers.pHead = pNext;
+                       if(!pNext)
+                               Buffers.pTail = NULL;
+               }
+               out_bytes -= tmp_bytes;
+       }
+       Buffers.FilledByte -= pbytes;
+}
+
+/*****************************************************************************************************************************/
+
+typedef HANDLE (WINAPI *fAvSetMmThreadCharacteristics)(LPCSTR,LPDWORD);
+typedef BOOL   (WINAPI *fAvRevertMmThreadCharacteristics)(HANDLE);
+
+static HINSTANCE hDll = NULL;
+static fAvSetMmThreadCharacteristics pAvSetMmThreadCharacteristics = NULL;
+static fAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics = NULL;
+
+static int load_avrt(void)
+{
+    hDll = LoadLibrary("avrt.dll");
+    if(hDll == NULL)
+        return FALSE;  
+#ifdef UNICODE
+       pAvSetMmThreadCharacteristics = (fAvSetMmThreadCharacteristics)GetProcAddress(hDll, "AvSetMmThreadCharacteristicsW");
+#else
+       pAvSetMmThreadCharacteristics = (fAvSetMmThreadCharacteristics)GetProcAddress(hDll, "AvSetMmThreadCharacteristicsA");
+#endif
+       pAvRevertMmThreadCharacteristics = (fAvRevertMmThreadCharacteristics)GetProcAddress(hDll, "AvRevertMmThreadCharacteristics");
+       return (int)pAvSetMmThreadCharacteristics && pAvRevertMmThreadCharacteristics;
+}
+
+static void free_avrt(void)
+{
+    if(hDll)
+        FreeLibrary(hDll);
+       hDll = NULL;    
+       pAvSetMmThreadCharacteristics = NULL;
+       pAvRevertMmThreadCharacteristics = NULL;
+}
+
+static int get_winver(void)
+{
+       DWORD winver, major, minor;
+       int ver = 0;
+
+       winver = GetVersion();          
+       major = (DWORD)(LOBYTE(LOWORD(winver)));
+       minor = (DWORD)(HIBYTE(LOWORD(winver)));
+       switch (major){
+       case 0:
+       case 1:
+       case 2:
+       case 3:
+       case 4:
+       case 5:
+               ver = 0;
+               break;
+       case 6:
+               switch (minor){
+               case 0: ver = 1; break; // vista
+               case 1: ver = 2; break; // 7
+               case 2: ver = 3; break; // 8
+               case 3: ver = 4; break; // 8.1
+               default: ver = 5; break; // 8.2?
+               }
+               break;
+       case 10:
+               switch (minor){
+               case 0: ver = 6; break; // 10
+               default: ver = 7; break; // 10.1?
+               }
+               break;
+       default:
+               ver = 8; // 11?
+               break;
+       }
+       return ver;
+}
+
+/*****************************************************************************************************************************/
+
+static HANDLE hEventTcv = NULL;
+static HANDLE hRenderThread = NULL;
+static IMMDevice* pMMDevice = NULL;
+static IAudioClient* pAudioClient = NULL;
+static IAudioRenderClient* pAudioRenderClient = NULL;
+static REFERENCE_TIME BufferDuration = 100000;
+static UINT32 FrameBytes = 0;
+static UINT32 BufferFrames = 0;
+static int ThreadPriorityNum = 0;
+static int IsExclusive = 0;
+static int IsPolling = 0;
+static int IsStarted = 0;
+static int IsOpened = 0;
+static int IsThreadStart = 0;
+static int IsThreadExit = 0;
+static int IsCoInit = 0;
+static int CoInitThreadId = 0;
+static int CvtMode = 0; // 0:no convert 1:convert 24bit(3byte->4byte)
+static uint32 QueueSize = sizeof(int16) * 2 * (1L << DEFAULT_AUDIO_BUFFER_BITS) * 2;
+static uint32 WaitTime = 1;
+static uint32 ThreadWaitTime = 1;
+
+static int write_buffer_event(void)
+{      
+       UINT32 padding = 0;
+       size_t out_bytes, out_frames;
+       BYTE *buf = NULL;
+
+       if(!IsExclusive)
+               if(FAILED(IAudioClient_GetCurrentPadding(pAudioClient, &padding)))
+                       return FALSE;
+       out_bytes = calc_output_bytes((BufferFrames - padding) * FrameBytes);
+       out_frames = out_bytes / FrameBytes;
+       if(IsExclusive && out_frames < BufferFrames){
+               if(!input_buffer(NULL, BufferFrames * FrameBytes - out_bytes))
+                       return FALSE;
+               out_bytes = BufferFrames * FrameBytes;
+               out_frames = out_bytes / FrameBytes;
+       }else if(out_frames == 0){
+               if(!input_buffer(NULL, FrameBytes - out_bytes))
+                       return FALSE;           
+               out_bytes = FrameBytes;
+               out_frames = 1;
+       }
+       if(FAILED(IAudioRenderClient_GetBuffer(pAudioRenderClient, out_frames, &buf)))
+               return FALSE;
+       output_buffer((uint8 *)buf, out_bytes);
+       IAudioRenderClient_ReleaseBuffer(pAudioRenderClient, out_frames, 0);
+       return TRUE;
+}
+
+static int write_buffer_polling(void)
+{      
+       UINT32 padding = 0;
+       size_t out_bytes, out_frames;
+       BYTE *buf = NULL;
+
+       if(FAILED(IAudioClient_GetCurrentPadding(pAudioClient, &padding)))
+               return FALSE;
+       out_bytes = calc_output_bytes((BufferFrames - padding) * FrameBytes);
+       out_frames = out_bytes / FrameBytes;
+       if(FAILED(IAudioRenderClient_GetBuffer(pAudioRenderClient, out_frames, &buf)))
+               return FALSE;
+       output_buffer((uint8 *)buf, out_bytes);
+       IAudioRenderClient_ReleaseBuffer(pAudioRenderClient, out_frames, 0);
+       return TRUE;
+}
+
+static unsigned int WINAPI render_thread(void *arglist)
+{
+       int ret = 1;
+       HANDLE hMmCss = NULL;
+       DWORD mmCssTaskIndex = 0;
+               
+       if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
+               return 1;
+       hMmCss = (pAvSetMmThreadCharacteristics)(ThreadPriorityName[ThreadPriorityNum], &mmCssTaskIndex);
+       if(!hMmCss)
+               goto thread_exit;
+       IsThreadStart = 1;
+       WaitForSingleObject(hEventTcv, INFINITE); // wait initialize open_output
+       ResetEvent(hEventTcv);
+       if(!IsPolling){
+               for(;;){ // event
+                       WaitForSingleObject(hEventTcv, INFINITE);
+                       ResetEvent(hEventTcv);
+                       if(IsThreadExit) break;         
+                       EnterCriticalSection(&critSect);
+                       write_buffer_event();
+                       LeaveCriticalSection(&critSect);
+               }
+       }else{
+               for(;;){ // polling
+                       WaitForSingleObject(hEventTcv, ThreadWaitTime);
+                       ResetEvent(hEventTcv);
+                       if(IsThreadExit) break;
+                       EnterCriticalSection(&critSect);
+                       write_buffer_polling();
+                       LeaveCriticalSection(&critSect);
+               }
+       }
+       ret = 0;
+thread_exit:
+       if(hMmCss)
+               (pAvRevertMmThreadCharacteristics)(hMmCss);
+       CoUninitialize();
+       IsThreadStart = 0;
+       return ret;
+}
+
+/*****************************************************************************************************************************/
+
+/* returns TRUE on success */
+static int get_default_device(IMMDevice** ppMMDevice)
+{
+       IMMDeviceEnumerator *pEnumerator = NULL;
+
+       if(FAILED(CoCreateInstance(&tim_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &tim_IID_IMMDeviceEnumerator, (void**)&pEnumerator)))
+               goto error;
+       if(FAILED(IMMDeviceEnumerator_GetDefaultAudioEndpoint(pEnumerator, eRender, eConsole, ppMMDevice)))
+               goto error;
+       if(pEnumerator)
+               IMMDeviceEnumerator_Release(pEnumerator);
+       return TRUE;
+error:
+       if(pEnumerator)
+               IMMDeviceEnumerator_Release(pEnumerator);
+       return FALSE;
+}
+
+static int get_device(IMMDevice **ppMMDevice, int devnum)
+{
+       int i;
+       UINT num;
+       HRESULT hr;
+       IMMDeviceEnumerator *pde = NULL;
+       IMMDeviceCollection *pdc = NULL;
+       IMMDevice *pdev = NULL;
+       WCHAR *pszDeviceId = NULL;
+
+       if(devnum > WASAPI_DEVLIST_MAX - 2)
+               devnum = -1;
+       if(devnum < 0)
+               return get_default_device(ppMMDevice);          
+       if(FAILED(CoCreateInstance(&tim_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &tim_IID_IMMDeviceEnumerator, (void **)&pde)))
+               goto error;
+       if(FAILED(IMMDeviceEnumerator_EnumAudioEndpoints(pde, eRender, DEVICE_STATE_ACTIVE, &pdc)))
+               goto error;     
+       if(FAILED(IMMDeviceCollection_GetCount(pdc, &num)))
+               goto error;
+       if(num <= 0)
+               goto error;
+       if(num > WASAPI_DEVLIST_MAX - 2)
+               num = WASAPI_DEVLIST_MAX - 2;
+       if(devnum > num)
+               goto error;
+       if(FAILED(IMMDeviceCollection_Item(pdc, devnum, &pdev)))
+               goto error;  
+       if(FAILED(IMMDevice_GetId(pdev, &pszDeviceId)))
+               goto error;
+       if(FAILED(IMMDeviceEnumerator_GetDevice(pde, pszDeviceId, ppMMDevice)))
+               goto error;             
+       if(pszDeviceId)
+               CoTaskMemFree(pszDeviceId);
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return TRUE;
+
+error: 
+       if(pszDeviceId)
+               CoTaskMemFree(pszDeviceId);
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return FALSE;
+}
+
+
+/*****************************************************************************************************************************/
+/* interface function */
+
+void close_output(void)
+{
+       if(IsStarted){
+               if(pAudioClient){
+                       IAudioClient_Stop(pAudioClient);
+               }
+               IsStarted = FALSE;
+       }
+       IsThreadExit = 1;
+       if(hRenderThread){
+               if(hEventTcv){
+                       SetEvent(hEventTcv);
+                       WaitForSingleObject(hRenderThread, INFINITE);
+               }
+               CloseHandle(hRenderThread);
+               hRenderThread = NULL;
+       }
+       IsThreadExit = 0;
+       free_buffer();
+       if(pAudioRenderClient){
+               IAudioRenderClient_Release(pAudioRenderClient);
+               pAudioRenderClient = NULL;
+       }
+       if(pAudioClient){
+               IAudioClient_Release(pAudioClient);
+               pAudioClient = NULL;
+       }
+       if(pMMDevice){
+               IMMDevice_Release(pMMDevice);
+               pMMDevice = NULL;
+       }
+       if(hEventTcv){
+               CloseHandle(hEventTcv);
+               hEventTcv = NULL;
+       }
+       if(IsCoInit && CoInitThreadId == GetCurrentThreadId()){
+               CoUninitialize();
+               IsCoInit = 0;
+       }
+       BufferFrames = 0;
+       free_avrt();
+#ifdef CNV_USE_TEMP_ENCODE
+       reset_temporary_encoding();
+#endif
+       IsOpened = 0;
+}
+
+/* 0=success, 1=warning, -1=fatal error */
+int open_output(void)
+{
+       HRESULT hr;
+       int include_enc, exclude_enc;
+       WAVEFORMATEXTENSIBLE wfe = {0};
+       WAVEFORMATEX *pwf = NULL;
+       AUDCLNT_SHAREMODE ShareMode;
+       uint32 StreamFlags;
+       REFERENCE_TIME Periodicity, LatencyMax, LatencyMin;     
+       GUID guid_WAVE_FORMAT = {WAVE_FORMAT_UNKNOWN,0x0000,0x0010,{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+       BYTE *buf;
+
+       close_output(); 
+       if(!get_winver()){
+               ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "ERROR! WASAPI require Windows Vista and later.");
+               return -1;
+       }
+       if(!load_avrt()){
+               ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "ERROR! AVRT.DLL function failed.");
+               goto error;
+       }       
+       IsExclusive = opt_wasapi_exclusive;
+       IsPolling = opt_wasapi_polling;
+       hEventTcv = CreateEvent(NULL,FALSE,FALSE,NULL); // reset manual
+       if(!hEventTcv)
+               goto error;     
+       hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+    if(FAILED(hr) && hr != RPC_E_CHANGED_MODE)
+               goto error;     
+    if(hr != RPC_E_CHANGED_MODE){
+               IsCoInit = 1;
+               CoInitThreadId = GetCurrentThreadId();
+    }
+       if(!get_device(&pMMDevice, opt_output_device_id == -3 ? opt_wasapi_device_id : opt_output_device_id))
+               goto error;
+       if(FAILED(IMMDevice_Activate(pMMDevice, &tim_IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&pAudioClient)))
+               goto error;     
+
+#if 0 // test format
+       {
+       IPropertyStore *pps = NULL;
+       PROPVARIANT value;
+       int cpsz;
+
+       if(FAILED(IMMDevice_OpenPropertyStore(pMMDevice, STGM_READ, &pps)))
+               goto error;
+    PropVariantInit(&value);
+    if(FAILED(IPropertyStore_GetValue(pps, &PKEY_AudioEngine_DeviceFormat, &value)))
+               goto error;
+       cpsz = min(sizeof(WAVEFORMATEXTENSIBLE), value.blob.cbSize);
+       memcpy(&wfe, value.blob.pBlobData, cpsz);
+    PropVariantClear(&value);
+       if(pps){
+               pps->lpVtbl->Release(pps); 
+               pps = NULL;
+       }
+       if(cpsz == sizeof(WAVEFORMATEX)){
+               pwf = (WAVEFORMATEX *)&wfe;
+               opt_wasapi_format_ext = 0;
+       }else{
+               pwf = &wfe.Format;
+               opt_wasapi_format_ext = 1;
+       }
+       }
+#endif
+
+       include_enc = PE_SIGNED;
+       exclude_enc = PE_BYTESWAP | PE_ULAW | PE_ALAW;  
+       if(!(dpm.encoding & (PE_F64BIT | PE_64BIT | PE_F32BIT | PE_32BIT | PE_24BIT | PE_16BIT))) // 8bit
+               include_enc |= PE_16BIT;
+       dpm.encoding = validate_encoding(dpm.encoding, include_enc, exclude_enc);
+       
+       if(opt_wasapi_format_ext){
+               pwf = &wfe.Format;
+               memcpy(&wfe.SubFormat, &guid_WAVE_FORMAT, sizeof(GUID));
+               pwf->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+               pwf->cbSize       = (WORD)22;
+       }else{
+               pwf = (WAVEFORMATEX *)&wfe;
+               pwf->cbSize       = (WORD)0;
+       }
+       CvtMode = 0;
+       if(dpm.encoding & PE_16BIT){
+               if(opt_wasapi_format_ext){                      
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 16;
+#if 1
+                       pwf->wBitsPerSample = (WORD) 16;
+#else
+                       if(opt_wasapi_exclusive){
+                               pwf->wBitsPerSample = (WORD) 32;
+                               CvtMode = 1;
+                       }else{
+                               pwf->wBitsPerSample = (WORD) 16;
+                       }               
+#endif
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 16;
+               }
+       }else if(dpm.encoding & PE_24BIT){
+               if(opt_wasapi_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 24;
+                       if(IsExclusive){
+                               pwf->wBitsPerSample = (WORD) 32;
+                               CvtMode = 2;
+                       }else{
+                               pwf->wBitsPerSample = (WORD) 24;
+                       }
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 24;
+               }
+       }else if(dpm.encoding & PE_32BIT){
+               if(opt_wasapi_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 32;
+                       pwf->wBitsPerSample = (WORD) 32;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 32;
+               }
+       }else if(dpm.encoding & PE_F32BIT){
+               if(opt_wasapi_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_IEEE_FLOAT;
+                       wfe.Samples.wValidBitsPerSample = 32;
+                       pwf->wBitsPerSample = (WORD) 32;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+                       pwf->wBitsPerSample = (WORD) 32;
+               }
+       }else if(dpm.encoding & PE_64BIT){
+               if(opt_wasapi_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 64;
+                       pwf->wBitsPerSample = (WORD) 64;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 64;
+               }
+       }else if(dpm.encoding & PE_F64BIT){
+               if(opt_wasapi_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_IEEE_FLOAT;
+                       wfe.Samples.wValidBitsPerSample = 64;
+                       pwf->wBitsPerSample = (WORD) 64;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+                       pwf->wBitsPerSample = (WORD) 64;
+               }
+       }else{ // 8bit // error
+               if(opt_wasapi_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 8;
+                       pwf->wBitsPerSample = (WORD) 8;                 
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 8;
+               }
+       }
+       pwf->nChannels       = (WORD)dpm.encoding & PE_MONO ? 1 : 2;
+       pwf->nSamplesPerSec  = (DWORD)dpm.rate;
+       pwf->nBlockAlign     = (WORD)(pwf->nChannels * pwf->wBitsPerSample / 8);
+       pwf->nAvgBytesPerSec = (DWORD)pwf->nSamplesPerSec * pwf->nBlockAlign;
+       wfe.dwChannelMask = pwf->nChannels==1 ? SPEAKER_MONO : SPEAKER_STEREO;
+
+#ifdef CNV_USE_TEMP_ENCODE
+       if(CvtMode == 2){                       
+               int tmp_enc = dpm.encoding;
+               tmp_enc &= ~PE_24BIT;
+               tmp_enc |= PE_32BIT;
+               set_temporary_encoding(tmp_enc);
+       }else if(CvtMode == 1){                 
+               int tmp_enc = dpm.encoding;
+               tmp_enc &= ~PE_16BIT;
+               tmp_enc |= PE_32BIT;
+               set_temporary_encoding(tmp_enc);
+       }else{
+               reset_temporary_encoding();
+       }
+#endif
+
+       FrameBytes = pwf->nBlockAlign;
+       
+#ifdef __IAudioClient2_INTERFACE_DEFINED__     
+       {
+               int ver = get_winver();
+
+               if(ver >= 3) // win8\88È\8fã
+               {
+                       AudioClientProperties acp = {0};
+                       acp.cbSize     = sizeof(AudioClientProperties);
+                       acp.bIsOffload = FALSE;
+                       acp.eCategory  = opt_wasapi_stream_category;
+               
+                       if(opt_wasapi_stream_option >= 2){
+                               if(ver >= 6) // win10\88È\8fã
+                                       acp.Options = AUDCLNT_STREAMOPTIONS_MATCH_FORMAT;
+                       }else if(opt_wasapi_stream_option == 1){
+                               if(ver >= 6) // win8.1\88È\8fã
+                                       acp.Options = AUDCLNT_STREAMOPTIONS_RAW;
+                       }
+                       hr = IAudioClient2_SetClientProperties((IAudioClient2 *)pAudioClient, (AudioClientProperties *)&acp);
+                               goto error;
+               }
+       }
+#endif
+       
+       if(opt_wasapi_priority <= 0 || opt_wasapi_priority > 7)
+               ThreadPriorityNum = IsExclusive ? 6 : 1;
+       else
+               ThreadPriorityNum = opt_wasapi_priority;
+       ShareMode = IsExclusive ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED;
+       StreamFlags = IsPolling ? 0x0 : AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
+       StreamFlags |= AUDCLNT_STREAMFLAGS_NOPERSIST;
+#if 1
+       LatencyMax = 100000;
+       LatencyMin = 30000;
+       if(FAILED(IAudioClient_GetDevicePeriod(pAudioClient, &LatencyMax, &LatencyMin))){
+               LatencyMax = 100000;
+               LatencyMin = 30000;
+       }
+       if(LatencyMax > 10000000) // 1000ms
+               LatencyMax = 10000000;
+       else if(LatencyMin < 10000)
+               LatencyMin = 10000; // 1ms
+       BufferDuration = opt_wasapi_latency * 10000; // ms to 100ns
+       if(BufferDuration > LatencyMax)
+               BufferDuration = LatencyMax;
+       if(BufferDuration < LatencyMin)
+               BufferDuration = LatencyMin;
+#else
+       BufferDuration = (IsExclusive ? 10 : 30) * 10000; // 10ms,30ms
+#endif
+       Periodicity = IsExclusive ? BufferDuration : 0;
+       
+       hr = IAudioClient_Initialize(pAudioClient, ShareMode, StreamFlags, BufferDuration, Periodicity, (WAVEFORMATEX *)&wfe, NULL);
+       if(hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED){
+               UINT32 bufferSize;
+
+               if(FAILED(IAudioClient_GetBufferSize(pAudioClient, &bufferSize)))
+                       goto error;
+               IAudioClient_Release(pAudioClient);
+               pAudioClient = NULL;
+               BufferDuration = (REFERENCE_TIME)(10000.0f * 1000 * bufferSize / pwf->nSamplesPerSec + 0.5);
+               if(FAILED(IMMDevice_Activate(pMMDevice, &tim_IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&pAudioClient)))
+                       goto error;
+               hr = IAudioClient_Initialize(pAudioClient, ShareMode, StreamFlags, BufferDuration, Periodicity, (WAVEFORMATEX *)&wfe, NULL);
+       }
+       if(FAILED(hr))
+               goto error;
+       if(FAILED(IAudioClient_GetBufferSize(pAudioClient, &BufferFrames)))
+               goto error;
+       if(!IsPolling)
+               if(FAILED(IAudioClient_SetEventHandle(pAudioClient, hEventTcv)))
+                       goto error;
+       if(FAILED(IAudioClient_GetService(pAudioClient, &tim_IID_IAudioRenderClient, (void**)&pAudioRenderClient)))
+               goto error;
+       
+       if(dpm.extra_param[0] < 2){
+               ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "Too small -B option: %d,X", dpm.extra_param[0]);
+               dpm.extra_param[0] = 2;
+       }       
+       if(audio_buffer_size < 5){
+               ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "Too small -B option: X,%d", audio_buffer_bits);
+               audio_buffer_bits = 5;
+       }
+       QueueSize = audio_buffer_size * FrameBytes * dpm.extra_param[0];
+       WaitTime = (double)audio_buffer_size * div_playmode_rate * 1000.0 * DIV_4; // blocktime/4
+       if(IsPolling){ // for polling
+               DWORD sleep_ms_in = (double)audio_buffer_size * div_playmode_rate * 1000.0 * DIV_2;
+               DWORD sleep_ms_out = (double)BufferDuration * DIV_10000 * DIV_2; // 100ns to ms
+               ThreadWaitTime = sleep_ms_in < sleep_ms_out ? sleep_ms_in : sleep_ms_out;
+       }
+       IsOpened = 1;
+       IsThreadStart = 0;
+       IsThreadExit = 0;
+       if(!hRenderThread){
+               hRenderThread = (HANDLE)_beginthreadex(NULL, 0, &render_thread, NULL, 0, NULL);
+               if(!hRenderThread)
+                       goto error;
+       }
+       if(!IsStarted){
+               int count = 20; // 200ms
+               if(FAILED(IAudioRenderClient_GetBuffer(pAudioRenderClient, BufferFrames, &buf)))
+                       goto error;
+               IAudioRenderClient_ReleaseBuffer(pAudioRenderClient, BufferFrames, AUDCLNT_BUFFERFLAGS_SILENT);
+               while(!IsThreadStart && count > 0){ // 
+                       Sleep(10);
+                       --count;
+               }
+               if(count <= 0) // time out
+                       goto error;
+               if(FAILED(IAudioClient_Start(pAudioClient)))
+                       goto error;     
+               SetEvent(hEventTcv); // start process
+               IsStarted = TRUE;
+       }
+       return 0;
+error:
+       close_output();
+       return -1;
+}
+
+int output_data(const uint8 *buf, size_t nbytes)
+{
+       int flg = TRUE, i;
+       int32 max_count = 64; // wait =  blocktime/4 * max_count
+#ifndef CNV_USE_TEMP_ENCODE
+       uint8 tbuff[2 * (1L << DEFAULT_AUDIO_BUFFER_BITS) * sizeof(int16) * 2] = {0};
+#endif
+
+       if(!IsOpened) 
+               return -1;      
+#ifndef CNV_USE_TEMP_ENCODE
+       if(CvtMode == 2){ // 24bit 3byte->4byte
+               int samples = nbytes / 3;
+               uint8 *in = (uint8 *)buf, *out = tbuff;
+               for(i = 0; i < samples; i++){
+                       *out++ = 0;
+                       *out++ = *(in)++;
+                       *out++ = *(in)++;
+                       *out++ = *(in)++;
+               }
+               buf = (const uint8 *)&tbuff;
+               nbytes = samples * 4;
+       }else if(CvtMode == 1){ // 16bit 2byte->4byte
+               int samples = nbytes / 2;
+               uint8 *in = (uint8 *)buf, *out = tbuff;
+               for(i = 0; i < samples; i++){
+                       *out++ = 0;
+                       *out++ = 0;
+                       *out++ = *(in)++;
+                       *out++ = *(in)++;
+               }
+               buf = (const uint8 *)&tbuff;
+               nbytes = samples * 4;
+       }
+#endif
+       for(;;){
+               if(!IsOpened)
+                       return -1; 
+               if(get_filled_byte() < QueueSize)
+                       break;
+               if(max_count <= 0){
+                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "WASAPI error: timeout output_data().");
+                       return -1; 
+               }
+               Sleep(WaitTime);
+               --max_count; 
+       }
+       EnterCriticalSection(&critSect);
+       flg = input_buffer(buf, nbytes);
+       LeaveCriticalSection(&critSect);
+       if(flg)
+               return 0;
+       close_output();
+       return -1;
+}
+
+int acntl(int request, void *arg)
+{
+       switch(request){
+       //case PM_REQ_GETFRAGSIZ:
+       //      return 0;
+       case PM_REQ_GETQSIZ:
+               *(int *)arg = QueueSize;
+               return 0;
+       case PM_REQ_GETFILLED:
+               *(int *)arg = get_filled_byte();
+               return 0;
+       case PM_REQ_FLUSH: // thru
+               while (!is_buffer_empty())
+                       WaitForSingleObject(hRenderThread, 10); 
+       case PM_REQ_DISCARD:
+               close_output();
+               open_output();
+               return 0;
+       case PM_REQ_PLAY_START:
+               return 0;
+       case PM_REQ_PLAY_END:
+               return 0;
+       default:
+               return -1;
+       }
+}
+
+int detect(void)
+{
+       IMMDevice *pMMDevice = NULL;
+       int result = get_default_device(&pMMDevice);
+       if(pMMDevice)
+               IMMDevice_Release(pMMDevice);
+       return result;
+}
+
+/*****************************************************************************************************************************/
+
+int wasapi_device_list(WASAPI_DEVICELIST *device)
+{
+       int i;
+       UINT num;
+       HRESULT hr;
+       IMMDeviceEnumerator *pde = NULL;
+       IMMDeviceCollection *pdc = NULL;
+       IPropertyStore *pps = NULL;
+       IAudioClient *tmpClient = NULL; 
+       REFERENCE_TIME LatencyMax, LatencyMin;
+       IMMDevice *defdev = NULL;
+       
+       device[0].deviceID = -1;
+       device[0].LatencyMax = 10;
+       device[0].LatencyMin = 3;
+       strcpy(device[0].name, "Default Render Device");
+       
+       if(!get_winver())
+               goto error0;
+       if(detect() == FALSE)
+               goto error0;    
+       if(!get_default_device(&defdev))
+               goto error0;    
+       if(FAILED(CoCreateInstance(&tim_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &tim_IID_IMMDeviceEnumerator, (void **)&pde)))
+               goto error1;
+       if(FAILED(IMMDeviceEnumerator_EnumAudioEndpoints(pde, eRender, DEVICE_STATE_ACTIVE, &pdc)))
+               goto error1;    
+       LatencyMax = 100000;
+       LatencyMin = 30000;
+       if(FAILED(IMMDevice_Activate(defdev, &tim_IID_IAudioClient, CLSCTX_ALL, NULL, (void **)&tmpClient))){
+               LatencyMin =LatencyMin;
+       }else if(FAILED(IAudioClient_GetDevicePeriod(tmpClient, &LatencyMax, &LatencyMin))){
+               LatencyMin =LatencyMin;
+       }       
+       LatencyMax /= 10000; // hns to ms
+       LatencyMin /= 10000; // hns to ms
+       if(LatencyMax > 1000)
+               LatencyMax = 1000;
+       if(LatencyMin < 0)
+               LatencyMin = 1;
+       device[0].LatencyMax = LatencyMax;
+       device[0].LatencyMin = LatencyMin;
+       if(tmpClient){
+               tmpClient->lpVtbl->Release(tmpClient);
+               tmpClient = NULL;
+       }       
+       if(defdev){
+               IMMDevice_Release(defdev);
+               defdev = NULL;
+       }
+       if(FAILED(IMMDeviceCollection_GetCount(pdc, &num)))
+               goto error1;
+       if(num <= 0)
+               goto error1;
+       if(num > WASAPI_DEVLIST_MAX - 2)
+               num = WASAPI_DEVLIST_MAX - 2;
+       for(i = 0; i < num; i++){ // -1, 0
+               IMMDevice *dev = NULL;
+               PROPVARIANT value;
+               IAudioClient *tmpClient = NULL;
+
+               if(FAILED(IMMDeviceCollection_Item(pdc, i, &dev)))
+                       goto error1;    
+               device[i+1].deviceID = i;
+               if(FAILED(IMMDevice_OpenPropertyStore(dev, STGM_READ, &pps)))
+                       goto error1;
+               PropVariantInit(&value);
+               if(FAILED(IPropertyStore_GetValue(pps, &PKEY_Device_FriendlyName, &value))){
+                       PropVariantClear(&value);
+               }else{
+                       if(value.pwszVal)
+#ifdef UNICODE
+                               WideCharToMultiByte(CP_UTF8, 0, value.pwszVal, (int)wcslen(value.pwszVal), device[i+1].name, WASAPI_DEVLIST_LEN - 1, 0, 0);
+#else
+                               WideCharToMultiByte(CP_ACP, 0, value.pwszVal, (int)wcslen(value.pwszVal), device[i+1].name, WASAPI_DEVLIST_LEN - 1, 0, 0);
+#endif
+                       else
+                               _snprintf(device[i+1].name, WASAPI_DEVLIST_LEN - 1, "Device Error %d", i);
+               }
+               PropVariantClear(&value);
+               LatencyMax = 100000;
+               LatencyMin = 30000;
+               if(FAILED(IMMDevice_Activate(dev, &tim_IID_IAudioClient, CLSCTX_ALL, NULL, (void **)&tmpClient))){
+               }else if(FAILED(IAudioClient_GetDevicePeriod(tmpClient, &LatencyMax, &LatencyMin))){
+               }
+               LatencyMax /= 10000; // hns to ms
+               LatencyMin /= 10000; // hns to ms
+               if(LatencyMax > 1000)
+                       LatencyMax = 1000;
+               if(LatencyMin < 0)
+                       LatencyMin = 1;
+               device[i+1].LatencyMax = LatencyMax;
+               device[i+1].LatencyMin = LatencyMin;
+               if(tmpClient){
+                       tmpClient->lpVtbl->Release(tmpClient);
+                       tmpClient = NULL;
+               }               
+               if(dev){
+                       IMMDevice_Release(dev);
+                       dev = NULL;
+               }
+               if(pps){
+                       pps->lpVtbl->Release(pps); 
+                       pps = NULL;
+               }
+       }
+       if(pdc)
+               pdc->lpVtbl->Release(pdc); 
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return num + 1; // +1 def dev
+
+error1:
+       if(tmpClient)
+               tmpClient->lpVtbl->Release(tmpClient);
+       if(pdc){
+               pdc->lpVtbl->Release(pdc);
+       }
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return 1;
+error0:
+       return 0;
+}
+
+
+#endif /* AU_WASAPI */
+
+
diff --git a/timidity/wasapi_a.h b/timidity/wasapi_a.h
new file mode 100644 (file)
index 0000000..8b12611
--- /dev/null
@@ -0,0 +1,41 @@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "interface.h"
+#include "timidity.h"
+#include "common.h"
+
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif /* HAVE_STDLIB_H */
+#ifndef NO_STRING_H
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#include <windows.h>
+
+
+#define WASAPI_DEVLIST_MAX 20
+#define WASAPI_DEVLIST_LEN 64
+#define WASAPI_MAX_STR_LEN 512
+
+typedef struct tag_WASAPI_DEVICELIST {
+       int  deviceID;
+       char name[WASAPI_DEVLIST_LEN];
+       int32 LatencyMax;
+       int32 LatencyMin;
+} WASAPI_DEVICELIST;
+
+extern int32 opt_wasapi_device_id;
+extern int32 opt_wasapi_latency;
+extern int opt_wasapi_format_ext;
+extern int opt_wasapi_exclusive;
+extern int opt_wasapi_polling;
+extern int opt_wasapi_priority;
+extern int opt_wasapi_stream_category;
+extern int opt_wasapi_stream_option;
+extern int wasapi_device_list(WASAPI_DEVICELIST *device);
diff --git a/timidity/wdmks_a.c b/timidity/wdmks_a.c
new file mode 100644 (file)
index 0000000..1e5170e
--- /dev/null
@@ -0,0 +1,915 @@
+/*
+    TiMidity++ -- MIDI to WAVE converter and player
+    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
+    Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    wdmks_a.c
+       
+       Functions to play sound using WDM Kernel Streeming (Windows 2000).
+*/
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+
+#ifdef AU_WDMKS
+
+#ifdef __W32__
+#include "interface.h"
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#ifndef NO_STRING_H
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#include <process.h>
+#include <tchar.h>
+
+#include "timidity.h"
+#include "common.h"
+#include "controls.h"
+#include "output.h"
+#include "wdmks_a.h"
+
+int opt_wdmks_device_id = -1;
+int opt_wdmks_format_ext = 1;
+int opt_wdmks_exclusive = 0;
+int opt_wdmks_priority = 0;
+
+/*****************************************************************************************************************************/
+
+static int  open_output     (void); /* 0=success, 1=warning, -1=fatal error */
+static void close_output    (void);
+static int  output_data     (const uint8 *buf, size_t nbytes);
+static int  acntl           (int request, void *arg);
+static int  detect          (void);
+
+/*****************************************************************************************************************************/
+
+#define dpm wdmks_play_mode
+
+PlayMode dpm = {
+    DEFAULT_RATE,
+    PE_16BIT | PE_SIGNED,
+    PF_PCM_STREAM | PF_CAN_TRACE | PF_BUFF_FRAGM_OPT,
+    -1,
+    {32},
+    "WDM Kernel Streeming", 'k',
+    NULL,
+    &open_output,
+    &close_output,
+    &output_data,
+    &acntl,
+    &detect
+};
+
+/*****************************************************************************************************************************/
+
+#define CINTERFACE
+#define COBJMACROS
+#include <windows.h>
+#include <winbase.h>
+#include <initguid.h>
+#include <objbase.h>
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+#include <Avrt.h>
+#include <Audioclient.h>
+#include <audiopolicy.h>
+#define INITGUID
+#include <mmdeviceapi.h>
+#include <functiondiscoverykeys.h>
+#undef INITGUID
+#endif
+
+#define SPEAKER_FRONT_LEFT        0x1
+#define SPEAKER_FRONT_RIGHT       0x2
+#define SPEAKER_FRONT_CENTER      0x4
+#define SPEAKER_MONO             (SPEAKER_FRONT_CENTER)
+#define SPEAKER_STEREO           (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)
+
+/*****************************************************************************************************************************/
+/* RenderBuffer */
+
+typedef struct RenderBufferNode
+{
+       struct RenderBufferNode *pNext;
+       size_t CurrentSize;
+       size_t Capacity;
+       char Data[1];
+} RenderBufferNode;
+
+typedef struct RenderBuffer
+{
+       RenderBufferNode *pHead;
+       RenderBufferNode *pTail;
+       RenderBufferNode *pFree;
+} RenderBuffer;
+
+static int IsRenderBufferEmpty(RenderBuffer *pRenderBuffer)
+{
+       return !pRenderBuffer->pHead;
+}
+
+static void ClearRenderBuffer(RenderBuffer *pRenderBuffer)
+{
+       if(pRenderBuffer->pTail){
+               /* prepend [pHead, ...,  pTail] to [pFree, ...] */
+               pRenderBuffer->pTail->pNext = pRenderBuffer->pFree;
+               pRenderBuffer->pFree = pRenderBuffer->pHead;
+               pRenderBuffer->pHead = NULL;
+               pRenderBuffer->pTail = NULL;
+       }
+}
+
+static void DeleteRenderBuffer(RenderBuffer *pRenderBuffer)
+{
+       RenderBufferNode *pNode = NULL;
+
+       ClearRenderBuffer(pRenderBuffer);
+       pNode = pRenderBuffer->pFree;
+       while(pNode){
+               RenderBufferNode* pNext = pNode->pNext;
+               free(pNode);
+               pNode = pNext;
+       }
+       pRenderBuffer->pFree = NULL;
+}
+
+/* if *ppData == NULL, appends `size` count of zeros */
+static void PushToRenderBufferPartial(RenderBufferNode *pNode, const uint8 **ppData, size_t *pSize)
+{
+       size_t pushLength = pNode->Capacity - pNode->CurrentSize;
+
+       if(pushLength > *pSize)
+               pushLength = *pSize;
+       if(*ppData){
+               memcpy(pNode->Data + pNode->CurrentSize, *ppData, pushLength);
+               *ppData += pushLength;
+       }else{
+               memset(pNode->Data + pNode->CurrentSize, 0, pushLength);
+       }
+       *pSize -= pushLength;
+       pNode->CurrentSize += pushLength;
+}
+
+/* if pData == NULL, appends `size` count of zeros */
+static int PushToRenderBuffer(RenderBuffer *pRenderBuffer, const uint8 *pData, size_t size)
+{
+       while (size > 0){
+               if(pRenderBuffer->pTail && pRenderBuffer->pTail->CurrentSize < pRenderBuffer->pTail->Capacity){
+                       PushToRenderBufferPartial(pRenderBuffer->pTail, &pData, &size);
+               }else if(pRenderBuffer->pFree){
+                       RenderBufferNode *pNode = pRenderBuffer->pFree;
+
+                       pRenderBuffer->pFree = pRenderBuffer->pFree->pNext;
+                       pNode->CurrentSize = 0;
+                       pNode->pNext = NULL;
+                       if(pRenderBuffer->pTail){
+                               pRenderBuffer->pTail->pNext = pNode;
+                               pRenderBuffer->pTail = pNode;
+                       }else{
+                               pRenderBuffer->pHead = pNode;
+                               pRenderBuffer->pTail = pNode;
+                       }
+                       PushToRenderBufferPartial(pNode, &pData, &size);
+               }else{
+                       size_t capacity = size * 4;
+                       RenderBufferNode *pNewNode = (RenderBufferNode *)safe_malloc(sizeof(RenderBufferNode) + capacity);
+
+                       if(!pNewNode)
+                               return FALSE;
+                       if(pRenderBuffer->pTail)
+                               pRenderBuffer->pTail->pNext = pNewNode;
+                       else
+                               pRenderBuffer->pHead = pNewNode;
+                       pRenderBuffer->pTail = pNewNode;
+                       pRenderBuffer->pTail->pNext = NULL;
+                       pRenderBuffer->pTail->Capacity = capacity;
+                       pRenderBuffer->pTail->CurrentSize = 0;
+                       PushToRenderBufferPartial(pRenderBuffer->pTail, &pData, &size);
+               }
+       }
+       return TRUE;
+}
+
+static int PushZeroToRenderBuffer(RenderBuffer *pRenderBuffer, size_t size)
+{
+       return PushToRenderBuffer(pRenderBuffer, NULL, size);
+}
+
+static size_t CalculateRenderBufferSize(RenderBuffer *pRenderBuffer, size_t maxSize)
+{
+       size_t size = 0;
+       RenderBufferNode *pNode = pRenderBuffer->pHead;
+
+       while(size < maxSize && pNode){
+               size += pNode->CurrentSize;
+               pNode = pNode->pNext;
+       }
+       if(size > maxSize)
+               size = maxSize;
+       return size;
+}
+
+static size_t ReadRenderBuffer(RenderBuffer *pRenderBuffer, char *pBuffer, size_t size)
+{
+       size_t copySize, copiedLength = 0;
+       RenderBufferNode *pNode = pRenderBuffer->pHead;
+
+       while(size > 0 && pNode){
+               copySize = pNode->CurrentSize;
+               if(copySize > size)
+                       copySize = size;
+               memcpy(pBuffer, pNode->Data, copySize);
+               pBuffer += copySize;
+               size -= copySize;
+               copiedLength += copySize;
+               pNode = pNode->pNext;
+       }
+       return copiedLength;
+}
+
+static size_t PopRenderBuffer(RenderBuffer *pRenderBuffer, size_t size)
+{
+       size_t popSize, actualLength = 0;
+
+       while (size > 0 && pRenderBuffer->pHead){
+               popSize = pRenderBuffer->pHead->CurrentSize;
+               if(pRenderBuffer->pHead->CurrentSize > size){
+                       popSize = size;
+                       memmove(pRenderBuffer->pHead->Data, pRenderBuffer->pHead->Data + size, pRenderBuffer->pHead->CurrentSize - size);
+                       pRenderBuffer->pHead->CurrentSize -= size;
+               }else{
+                       /* prepend pHead to [pFree, ...] */
+                       RenderBufferNode *pNext = pRenderBuffer->pHead->pNext;
+                       pRenderBuffer->pHead->pNext = pRenderBuffer->pFree;
+                       pRenderBuffer->pFree = pRenderBuffer->pHead;
+                       pRenderBuffer->pHead = pNext;
+                       if(!pNext)
+                               pRenderBuffer->pTail = NULL;
+               }
+               size -= popSize;
+               actualLength += popSize;
+       }
+       return actualLength;
+}
+
+/*****************************************************************************************************************************/
+
+static HANDLE hEventTcv = NULL;
+static HANDLE hRenderThread = NULL;
+static IMMDevice* pMMDevice = NULL;
+static IAudioClient* pAudioClient = NULL;
+static IAudioRenderClient* pAudioRenderClient = NULL;
+static RenderBuffer Buffers = {0, 0, 0};
+static UINT32 FrameBytes = 0;
+static UINT32 BufferFrames = 0;
+static int IsExclusive = 0;
+static int IsStarted = 0;
+static int IsOpened = 0;
+static int IsThreadExit = 0;
+
+static int WriteBuffer(void)
+{
+       UINT32 padding = 0;
+       size_t numberOfBytesToCopy, numberOfFramesToCopy;
+       BYTE *pData = NULL;
+
+       if(!IsExclusive)
+               if(FAILED(IAudioClient_GetCurrentPadding(pAudioClient, &padding)))
+                       return FALSE;
+       numberOfBytesToCopy = CalculateRenderBufferSize(&Buffers, (BufferFrames - padding) * FrameBytes);
+       numberOfFramesToCopy = numberOfBytesToCopy / FrameBytes;
+       if(IsExclusive && numberOfFramesToCopy < BufferFrames){
+               if(!PushZeroToRenderBuffer(&Buffers, BufferFrames * FrameBytes - numberOfBytesToCopy))
+                       return FALSE;
+               numberOfBytesToCopy = BufferFrames * FrameBytes;
+               numberOfFramesToCopy = numberOfBytesToCopy / FrameBytes;
+       }else if(numberOfFramesToCopy == 0){
+               if(!PushZeroToRenderBuffer(&Buffers, FrameBytes - numberOfBytesToCopy))
+                       return FALSE;
+               numberOfBytesToCopy = FrameBytes;
+               numberOfFramesToCopy = 1;
+       }
+       if(FAILED(IAudioRenderClient_GetBuffer(pAudioRenderClient, numberOfFramesToCopy, &pData)))
+               return FALSE;
+       PopRenderBuffer(&Buffers, ReadRenderBuffer(&Buffers, (char*)pData, numberOfFramesToCopy * FrameBytes));
+       IAudioRenderClient_ReleaseBuffer(pAudioRenderClient, numberOfFramesToCopy, 0);
+       return TRUE;
+}
+
+static unsigned int WINAPI RenderThread(void *arglist)
+{
+       int ret = 1;
+       HANDLE waitArray[2] = {hEventTcv, hEventTcv};
+       HANDLE hMmCss = NULL;
+       DWORD mmCssTaskIndex = 0;
+       
+       if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
+               return 1;
+       hMmCss = AvSetMmThreadCharacteristics(_T("Audio"), &mmCssTaskIndex);
+       if(!hMmCss)
+               goto thread_exit;       
+       for(;;){                
+               WaitForSingleObject(hEventTcv, INFINITE);
+               ResetEvent(hEventTcv);
+               if(IsThreadExit) break;         
+               EnterCriticalSection(&critSect);
+               WriteBuffer();
+               LeaveCriticalSection(&critSect);
+       }       
+       ret = 0;
+thread_exit:
+       if(hMmCss)
+               AvRevertMmThreadCharacteristics(hMmCss);
+       CoUninitialize();
+       return ret;
+}
+
+static void stop(void)
+{
+       if(!IsOpened)
+               return;
+       if(IsStarted){
+               if(pAudioClient){
+                       IAudioClient_Stop(pAudioClient);
+               }
+               IsStarted = FALSE;
+       }
+       IsThreadExit = 1;
+       if(hRenderThread){
+               if(hEventTcv){
+                       SetEvent(hEventTcv);
+                       WaitForSingleObject(hRenderThread, INFINITE);
+               }
+               CloseHandle(hRenderThread);
+               hRenderThread = NULL;
+       }
+       IsThreadExit = 0;
+       DeleteRenderBuffer(&Buffers);
+}
+
+static void reset(void)
+{
+       stop();
+       BufferFrames = 0;
+       FrameBytes = 0;
+       if(pAudioRenderClient){
+               IAudioRenderClient_Release(pAudioRenderClient);
+               pAudioRenderClient = NULL;
+       }
+       if(pAudioClient){
+               IAudioClient_Release(pAudioClient);
+               pAudioClient = NULL;
+       }
+       if(pMMDevice){
+               IMMDevice_Release(pMMDevice);
+               pMMDevice = NULL;
+       }
+       if(hEventTcv){
+               CloseHandle(hEventTcv);
+               hEventTcv = NULL;
+       }
+}
+
+static int start(void)
+{
+       BYTE *pData;
+
+       IsThreadExit = 0;
+       if(!hRenderThread){
+               hRenderThread = (HANDLE)_beginthreadex(NULL, 0, &RenderThread, NULL, 0, NULL);
+               if(!hRenderThread)
+                       goto error;
+       }
+       if(!IsStarted){
+               if(IsRenderBufferEmpty(&Buffers)){
+                       if(FAILED(IAudioRenderClient_GetBuffer(pAudioRenderClient, BufferFrames, &pData)))
+                               goto error;
+                       IAudioRenderClient_ReleaseBuffer(pAudioRenderClient, BufferFrames, AUDCLNT_BUFFERFLAGS_SILENT);
+               }else{
+                       if(!WriteBuffer())
+                               goto error;
+               }
+               if(FAILED(IAudioClient_Start(pAudioClient)))
+                       goto error;
+               IsStarted = TRUE;
+       }
+       return 0;
+error:
+       reset();
+       return -1;
+}
+
+/*****************************************************************************************************************************/
+
+/* returns TRUE on success */
+static int get_default_device(IMMDevice** ppMMDevice)
+{
+       IMMDeviceEnumerator *pEnumerator = NULL;
+
+       if(FAILED(CoCreateInstance(&tim_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &tim_IID_IMMDeviceEnumerator, (void**)&pEnumerator)))
+               goto error;
+       if(FAILED(IMMDeviceEnumerator_GetDefaultAudioEndpoint(pEnumerator, eRender, eConsole, ppMMDevice)))
+               goto error;
+       return TRUE;
+error:
+       if(pEnumerator)
+               IMMDeviceEnumerator_Release(pEnumerator);
+       return FALSE;
+}
+
+static int get_device(IMMDevice **ppMMDevice, int devnum)
+{
+       int i;
+       UINT num;
+       HRESULT hr;
+       IMMDeviceEnumerator *pde = NULL;
+       IMMDeviceCollection *pdc = NULL;
+       IMMDevice *pdev = NULL;
+       WCHAR *pszDeviceId = NULL;
+
+       if(devnum > WDMKS_DEVLIST_MAX - 2)
+               devnum = -1;
+       if(devnum < 0)
+               return get_default_device(ppMMDevice);          
+       if(FAILED(CoCreateInstance(&tim_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &tim_IID_IMMDeviceEnumerator, (void **)&pde)))
+               goto error;
+       if(FAILED(IMMDeviceEnumerator_EnumAudioEndpoints(pde, eRender, DEVICE_STATE_ACTIVE, &pdc)))
+               goto error;     
+       if(FAILED(IMMDeviceCollection_GetCount(pdc, &num)))
+               goto error;
+       if(num <= 0)
+               goto error;
+       if(num > WDMKS_DEVLIST_MAX - 2)
+               num = WDMKS_DEVLIST_MAX - 2;
+       if(devnum > num)
+               goto error;
+       if(FAILED(IMMDeviceCollection_Item(pdc, devnum, &pdev)))
+               goto error;  
+       if(FAILED(IMMDevice_GetId(pdev, &pszDeviceId)))
+               goto error;
+       if(FAILED(IMMDeviceEnumerator_GetDevice(pde, pszDeviceId, ppMMDevice)))
+               goto error;             
+       if(pszDeviceId)
+               CoTaskMemFree(pszDeviceId);
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return TRUE;
+
+error: 
+       if(pszDeviceId)
+               CoTaskMemFree(pszDeviceId);
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return FALSE;
+}
+
+static int get_winver()
+{
+       DWORD winver, major, minor;
+       int ver = 0;
+
+       winver = GetVersion();          
+       major = (DWORD)(LOBYTE(LOWORD(winver)));
+       minor = (DWORD)(HIBYTE(LOWORD(winver)));
+       switch (major){
+       case 0:
+       case 1:
+       case 2:
+       case 3:
+       case 4:
+       case 5:
+               ver = 0;
+               break;
+       case 6:
+               switch (minor){
+               case 0: ver = 1; break; // vista
+               case 1: ver = 2; break; // 7
+               case 2: ver = 3; break; // 8
+               case 3: ver = 4; break; // 8.1
+               default: ver = 5; break; // 8.2?
+               }
+               break;
+       case 10:
+               switch (minor){
+               case 0: ver = 6; break; // 10
+               default: ver = 7; break; // 10.1?
+               }
+               break;
+       default:
+               ver = 8; // 11?
+               break;
+       }
+       return ver;
+}
+
+/*****************************************************************************************************************************/
+/* interface function */
+
+/* 0=success, 1=warning, -1=fatal error */
+int open_output(void)
+{
+       HRESULT hr;
+       int include_enc, exclude_enc;
+       WAVEFORMATEXTENSIBLE wfe = {0};
+       WAVEFORMATEX *pwf = NULL;
+       AUDCLNT_SHAREMODE ShareMode;
+       uint32 StreamFlags;
+       REFERENCE_TIME BufferDuration, Periodicity;     
+       GUID guid_WAVE_FORMAT = {WAVE_FORMAT_UNKNOWN,0x0000,0x0010,{0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
+
+       
+    DWORD defaultInDevPathSize = 0;
+    DWORD defaultOutDevPathSize = 0;
+    wchar_t* defaultInDevPath = 0;
+    wchar_t* defaultOutDevPath = 0;
+
+
+       reset();
+
+       
+    if( waveOutMessage(0, DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&defaultOutDevPathSize, 0 ) == MMSYSERR_NOERROR )
+    {
+        defaultOutDevPath = (wchar_t *)PaUtil_AllocateMemory((defaultOutDevPathSize + 1) * sizeof(wchar_t));
+        waveOutMessage(0, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)defaultOutDevPath, defaultOutDevPathSize);
+    }
+
+       //hEventTcv = CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE);
+       hEventTcv = CreateEvent(NULL,FALSE,FALSE,NULL); // reset manual
+       if(!hEventTcv)
+               goto error;
+       if(!get_device(&pMMDevice, opt_output_device_id == -3 ? opt_wdmks_device_id : opt_output_device_id))
+               goto error;
+       if(FAILED(IMMDevice_Activate(pMMDevice, &tim_IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&pAudioClient)))
+               goto error;     
+
+#if 0 // test format
+       {
+       IPropertyStore *pps = NULL;
+       PROPVARIANT value;
+       int cpsz;
+
+       if(FAILED(IMMDevice_OpenPropertyStore(pMMDevice, STGM_READ, &pps)))
+               goto error;
+    PropVariantInit(&value);
+    if(FAILED(IPropertyStore_GetValue(pps, &PKEY_AudioEngine_DeviceFormat, &value)))
+               goto error;
+       cpsz = min(sizeof(WAVEFORMATEXTENSIBLE), value.blob.cbSize);
+       memcpy(&wfe, value.blob.pBlobData, cpsz);
+    PropVariantClear(&value);
+       if(pps){
+               pps->lpVtbl->Release(pps); 
+               pps = NULL;
+       }
+       if(cpsz == sizeof(WAVEFORMATEX)){
+               pwf = (WAVEFORMATEX *)&wfe;
+               opt_wdmks_format_ext = 0;
+       }else{
+               pwf = &wfe.Format;
+               opt_wdmks_format_ext = 1;
+       }
+       }
+#endif
+
+       include_enc = PE_SIGNED;
+       exclude_enc = PE_BYTESWAP | PE_ULAW | PE_ALAW;  
+       if(!(dpm.encoding & (PE_F64BIT | PE_64BIT | PE_F32BIT | PE_32BIT | PE_24BIT | PE_16BIT))) // 8bit
+               include_enc |= PE_16BIT;
+       if(opt_wdmks_format_ext && (dpm.encoding & PE_24BIT))
+               include_enc |= PE_4BYTE;
+       else
+               exclude_enc |= PE_4BYTE;
+       dpm.encoding = validate_encoding(dpm.encoding, include_enc, exclude_enc);
+       
+       if(opt_wdmks_format_ext){
+               pwf = &wfe.Format;
+               memcpy(&wfe.SubFormat, &guid_WAVE_FORMAT, sizeof(GUID));
+       }else{
+               pwf = (WAVEFORMATEX *)&wfe;
+               memset(pwf, 0, sizeof(WAVEFORMATEX));
+       }
+
+       if(dpm.encoding & PE_16BIT){
+               if(dpm.encoding & PE_4BYTE){
+                       if(opt_wdmks_format_ext){
+                               wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                               wfe.Samples.wValidBitsPerSample = 16;
+                               pwf->wBitsPerSample = (WORD) 32;                        
+                       }else{
+                               pwf->wFormatTag = WAVE_FORMAT_PCM;
+                               pwf->wBitsPerSample = (WORD) 16;
+                       }
+               }else{
+                       if(opt_wdmks_format_ext){
+                               wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                               wfe.Samples.wValidBitsPerSample = 16;
+                               pwf->wBitsPerSample = (WORD) 16;                        
+                       }else{
+                               pwf->wFormatTag = WAVE_FORMAT_PCM;
+                               pwf->wBitsPerSample = (WORD) 16;
+                       }
+               }
+       }else if(dpm.encoding & PE_24BIT){
+               if(dpm.encoding & PE_4BYTE){
+                       if(opt_wdmks_format_ext){
+                               wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                               wfe.Samples.wValidBitsPerSample = 24;
+                               pwf->wBitsPerSample = (WORD) 32;                        
+                       }else{
+                               pwf->wFormatTag = WAVE_FORMAT_PCM;
+                               pwf->wBitsPerSample = (WORD) 24;
+                       }
+               }else{
+                       if(opt_wdmks_format_ext){
+                               wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                               wfe.Samples.wValidBitsPerSample = 24;
+                               pwf->wBitsPerSample = (WORD) 24;                        
+                       }else{
+                               pwf->wFormatTag = WAVE_FORMAT_PCM;
+                               pwf->wBitsPerSample = (WORD) 24;
+                       }
+               }
+       }else if(dpm.encoding & PE_32BIT){
+               if(opt_wdmks_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 32;
+                       pwf->wBitsPerSample = (WORD) 32;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 32;
+               }
+       }else if(dpm.encoding & PE_F32BIT){
+               if(opt_wdmks_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_IEEE_FLOAT;
+                       wfe.Samples.wValidBitsPerSample = 32;
+                       pwf->wBitsPerSample = (WORD) 32;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+                       pwf->wBitsPerSample = (WORD) 32;
+               }
+       }else if(dpm.encoding & PE_64BIT){
+               if(opt_wdmks_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_PCM;
+                       wfe.Samples.wValidBitsPerSample = 64;
+                       pwf->wBitsPerSample = (WORD) 64;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_PCM;
+                       pwf->wBitsPerSample = (WORD) 64;
+               }
+       }else if(dpm.encoding & PE_F64BIT){
+               if(opt_wdmks_format_ext){
+                       wfe.SubFormat.Data1 = WAVE_FORMAT_IEEE_FLOAT;
+                       wfe.Samples.wValidBitsPerSample = 64;
+                       pwf->wBitsPerSample = (WORD) 64;                        
+               }else{
+                       pwf->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+                       pwf->wBitsPerSample = (WORD) 64;
+               }
+       }else{ // 8bit // error
+               pwf->wFormatTag = WAVE_FORMAT_PCM; // only WAVEFORMATEX
+               pwf->wBitsPerSample = (WORD) 8;
+       }
+       pwf->nChannels       = (WORD)dpm.encoding & PE_MONO ? 1 : 2;
+       pwf->nSamplesPerSec  = (DWORD)dpm.rate;
+       pwf->nBlockAlign     = (WORD)(pwf->nChannels * pwf->wBitsPerSample / 8);
+       pwf->nAvgBytesPerSec = (DWORD)pwf->nSamplesPerSec * pwf->nBlockAlign;
+       if(opt_wdmks_format_ext){
+               wfe.Samples.wValidBitsPerSample = pwf->wBitsPerSample; // union
+               wfe.Samples.wSamplesPerBlock = 1;
+               wfe.Samples.wReserved = wfe.Samples.wValidBitsPerSample;
+               wfe.dwChannelMask = pwf->nChannels==1 ? SPEAKER_MONO : SPEAKER_STEREO;
+               pwf->cbSize       = (WORD)22;
+       }else{
+               pwf->cbSize       = (WORD)0;
+       }
+
+       FrameBytes = pwf->nBlockAlign;
+
+       if(dpm.extra_param[0] < 2){
+               ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "Too small -B option: %d,X", dpm.extra_param[0]);
+               dpm.extra_param[0] = 2;
+       }
+       if(audio_buffer_bits < 5){
+               ctl->cmsg(CMSG_WARNING, VERB_NORMAL, "Too small -B option: X,%d", audio_buffer_bits);
+               audio_buffer_bits = 5;
+       }
+
+#ifdef __IAudioClient2_INTERFACE_DEFINED__     
+       {
+               int ver = get_winver();
+
+               if(ver >= 3) // win8\88È\8fã
+               {
+                       AudioClientProperties acp = {0};
+                       acp.cbSize     = sizeof(AudioClientProperties);
+                       acp.bIsOffload = FALSE;
+                       acp.eCategory  = opt_wdmks_stream_category;
+               
+                       if(opt_wdmks_stream_option >= 2){
+                               if(ver >= 6) // win10\88È\8fã
+                                       acp.Options = AUDCLNT_STREAMOPTIONS_MATCH_FORMAT;
+                       }else if(opt_wdmks_stream_option == 1){
+                               if(ver >= 6) // win8.1\88È\8fã
+                                       acp.Options = AUDCLNT_STREAMOPTIONS_RAW;
+                       }
+                       hr = IAudioClient2_SetClientProperties((IAudioClient2 *)pAudioClient, (AudioClientProperties *)&acp);
+                               goto error;
+               }
+       }
+#endif
+
+       IsExclusive = opt_wdmks_exclusive;
+       
+       ShareMode = IsExclusive ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED;
+       StreamFlags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK;// | AUDCLNT_STREAMFLAGS_NOPERSIST;
+       BufferDuration = (IsExclusive ? 10 : 30) * 10000; // 10ms,30ms
+       Periodicity = IsExclusive ? BufferDuration : 0;
+
+       hr = IAudioClient_Initialize(pAudioClient, ShareMode, StreamFlags, BufferDuration, Periodicity, (WAVEFORMATEX *)&wfe, NULL);
+       if(hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED){
+               UINT32 bufferSize;
+
+               if(FAILED(IAudioClient_GetBufferSize(pAudioClient, &bufferSize)))
+                       goto error;
+               IAudioClient_Release(pAudioClient);
+               pAudioClient = NULL;
+               BufferDuration = (REFERENCE_TIME)(10000.0f * 1000 * bufferSize / pwf->nSamplesPerSec + 0.5);
+               if(FAILED(IMMDevice_Activate(pMMDevice, &tim_IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&pAudioClient)))
+                       goto error;
+               hr = IAudioClient_Initialize(pAudioClient, ShareMode, StreamFlags, BufferDuration, Periodicity, (WAVEFORMATEX *)&wfe, NULL);
+       }
+       if(FAILED(hr))
+               goto error;
+       if(FAILED(IAudioClient_GetBufferSize(pAudioClient, &BufferFrames)))
+               goto error;
+       if(FAILED(IAudioClient_SetEventHandle(pAudioClient, hEventTcv)))
+               goto error;
+       if(FAILED(IAudioClient_GetService(pAudioClient, &tim_IID_IAudioRenderClient, (void**)&pAudioRenderClient)))
+               goto error;
+       IsOpened = 1;
+       return 0;
+error:
+       reset();
+       return -1;
+}
+
+void close_output(void)
+{
+       reset();
+       IsOpened = 0;
+}
+
+int output_data(const uint8 *buf, size_t nbytes)
+{
+       int flg = 0;
+
+       if(!IsOpened) return -1;
+       EnterCriticalSection(&critSect);
+       flg = PushToRenderBuffer(&Buffers, buf, nbytes);
+       LeaveCriticalSection(&critSect);
+       if(flg)
+               return 0;
+       reset();
+       return -1;
+}
+
+int acntl(int request, void *arg)
+{
+       switch(request){
+       //case PM_REQ_GETFRAGSIZ:
+       //      return 0;
+       //case PM_REQ_GETQSIZ:
+       //      if(BufferFrames <= 0)
+       //              return -1;
+       //      *(int *)arg = BufferFrames ;
+       //      return 0;
+//     case PM_REQ_GETFILLED:
+//             return 0;
+       case PM_REQ_DISCARD:
+               stop();
+               return 0;
+       case PM_REQ_FLUSH:
+               while (!IsRenderBufferEmpty(&Buffers))
+                       WaitForSingleObject(hRenderThread, 10);
+               return 0;
+       case PM_REQ_PLAY_START:
+               return start();
+       case PM_REQ_PLAY_END:
+               stop();
+               return 0;
+       default:
+               return -1;
+       }
+}
+
+int detect(void)
+{
+       IMMDevice *pMMDevice = NULL;
+       int result = get_default_device(&pMMDevice);
+
+       if(pMMDevice)
+               IMMDevice_Release(pMMDevice);
+       return result;
+}
+
+/*****************************************************************************************************************************/
+
+int wdmks_device_list(WDMKS_DEVICELIST *device)
+{
+       int i;
+       UINT num;
+       HRESULT hr;
+       IMMDeviceEnumerator *pde = NULL;
+       IMMDeviceCollection *pdc = NULL;
+       IPropertyStore *pps = NULL;
+       
+       device[0].deviceID = -1;
+//     device[0].LatencyMax = 100000;
+//     device[01].LatencyMin = 30000;
+       strcpy(device[0].name, "Default Render Device");
+
+       if(detect() == FALSE)
+               goto error0;
+       if(FAILED(CoCreateInstance(&tim_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &tim_IID_IMMDeviceEnumerator, (void **)&pde)))
+               goto error1;    
+       if(FAILED(IMMDeviceEnumerator_EnumAudioEndpoints(pde, eRender, DEVICE_STATE_ACTIVE, &pdc)))
+               goto error1;
+       if(FAILED(IMMDeviceCollection_GetCount(pdc, &num)))
+               goto error1;
+       if(num <= 0)
+               goto error1;
+       if(num > WDMKS_DEVLIST_MAX - 2)
+               num = WDMKS_DEVLIST_MAX - 2;
+       for(i = 0; i < num; i++){ // -1, 0
+               IMMDevice *dev = NULL;
+               PROPVARIANT value;
+       //      IAudioClient *tmpClient = NULL;
+
+               if(FAILED(IMMDeviceCollection_Item(pdc, i, &dev)))
+                       goto error1;    
+               device[i+1].deviceID = i;
+               if(FAILED(IMMDevice_OpenPropertyStore(dev, STGM_READ, &pps)))
+                       goto error1;
+               PropVariantInit(&value);
+               if(FAILED(IPropertyStore_GetValue(pps, &PKEY_Device_FriendlyName, &value))){
+                       PropVariantClear(&value);
+               }else{
+                       if(value.pwszVal)
+                               WideCharToMultiByte(CP_ACP, 0, value.pwszVal, (int)wcslen(value.pwszVal), device[i+1].name, WDMKS_DEVLIST_LEN - 1, 0, 0);
+                       else
+                               _snprintf(device[i+1].name, WDMKS_DEVLIST_LEN - 1, "Device Error %d", i);
+               }
+               PropVariantClear(&value);
+               //if(FAILED(IMMDevice_Activate(dev, &tim_IID__IAudioClient, CLSCTX_ALL, NULL, (void **)tmpClient))){
+               //      device[i+1].LatencyMax = 100000;
+               //      device[i+1].LatencyMin = 30000;
+               //}else if(FAILED(IAudioClient_GetDevicePeriod(tmpClient, &device[i+1].LatencyMax, &device[i+1].LatencyMin))){
+               //      device[i+1].LatencyMax = 100000;
+               //      device[i+1].LatencyMin = 30000;
+               //}
+               //if(tmpClient)
+               //      tmpClient->lpVtbl->Release(tmpClient);
+               if(pps){
+                       pps->lpVtbl->Release(pps); 
+                       pps = NULL;
+               }
+       }
+       if(pdc)
+               pdc->lpVtbl->Release(pdc); 
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return num + 1; // +1 def dev
+
+error1:
+       if(pdc)
+               pdc->lpVtbl->Release(pdc); 
+       if(pde)
+               IMMDeviceEnumerator_Release(pde);
+       return 1;
+error0:
+       return 0;
+}
+
+
+#endif /* AU_WDMKS */
+
+
diff --git a/timidity/wdmks_a.h b/timidity/wdmks_a.h
new file mode 100644 (file)
index 0000000..923acc5
--- /dev/null
@@ -0,0 +1,36 @@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "interface.h"
+#include "timidity.h"
+#include "common.h"
+
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif /* HAVE_STDLIB_H */
+#ifndef NO_STRING_H
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#include <windows.h>
+
+
+#define WDMKS_DEVLIST_MAX 20
+#define WDMKS_DEVLIST_LEN 64
+#define WDMKS_MAX_STR_LEN 512
+
+typedef struct tag_WDMKS_DEVICELIST {
+       int  deviceID;
+       char name[WDMKS_DEVLIST_LEN];
+} WDMKS_DEVICELIST;
+
+extern CRITICAL_SECTION critSect;
+
+extern int opt_wdmks_device_id;
+extern int opt_wdmks_format_ext;
+extern int opt_wdmks_priority;
+extern int wdmks_device_list(WDMKS_DEVICELIST *device);
index a6d5935..8a6cd62 100644 (file)
@@ -80,6 +80,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "timdrvsetup", "timdrvsetup\
        ProjectSection(ProjectDependencies) = postProject
                {11CDD90A-20E1-45AF-879E-F355742B38B7} = {11CDD90A-20E1-45AF-879E-F355742B38B7}
                {B05F8AA0-6140-4335-AD39-E276D17002CB} = {B05F8AA0-6140-4335-AD39-E276D17002CB}
+               {248B20A6-9609-4A5B-AFAE-09C7572FCE54} = {248B20A6-9609-4A5B-AFAE-09C7572FCE54}
                {8DC8ADE3-145A-4C63-80DD-0C93B6587B80} = {8DC8ADE3-145A-4C63-80DD-0C93B6587B80}
        EndProjectSection
 EndProject
index 09546c3..5b44acf 100644 (file)
@@ -70,7 +70,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MT /W3 /Gm /GX /ZI /Od /I "..\interface" /I "..\libarc" /I "..\libunimod" /I "..\timidity" /I "..\utils" /I ".." /I "..\..\include" /D "TW32G" /D "_WINDOWS" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /D "_MT" /YX /FD /GZ /c
+# ADD CPP /nologo /MT /W3 /Gm /GX /ZI /Od /I "..\interface" /I "..\libarc" /I "..\libunimod" /I "..\timidity" /I "..\utils" /I ".." /I "..\..\include" /D "TW32G" /D "_WINDOWS" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /D "_MT" /FR /YX /FD /GZ /c
 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x411 /d "_DEBUG"
index 14f8b2c..3741e80 100644 (file)
@@ -86,7 +86,7 @@
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/MACHINE:I386"
-                               AdditionalDependencies="comctl32.lib;libcmtd.lib;odbc32.lib;odbccp32.lib;winmm.lib;wsock32.lib;"
+                               AdditionalDependencies="comctl32.lib libcmtd.lib odbc32.lib odbccp32.lib winmm.lib wsock32.lib"
                                OutputFile="../Debug/timw32g.exe"
                                LinkIncremental="2"
                                SuppressStartupBanner="true"
                                ProgramDatabaseFile=".\Release/timw32g.pdb"
                                SubSystem="2"
                                LargeAddressAware="2"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
                                RandomizedBaseAddress="1"
-                               DataExecutionPrevention="0"
+                               DataExecutionPrevention="2"
                                TargetMachine="1"
                        />
                        <Tool
index b3573a2..85d57d5 100644 (file)
@@ -90,8 +90,8 @@
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(VCInstallDir)atlmfc\lib\amd64;$(VCInstallDir)lib\amd64;$(WindowsSdkDir)lib\x64;$(FrameworkSDKDir)\lib\x64;$(WindowsSdkDir)\lib\x64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;</LibraryPath>
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib;$(DXSDK_DIR)\ILib\x86;</LibraryPath>
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(VCInstallDir)atlmfc\lib\amd64;$(VCInstallDir)lib\amd64;$(WindowsSdkDir)lib\x64;$(FrameworkSDKDir)\lib\x64;$(WindowsSdkDir)\lib\x64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;</LibraryPath>
-    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">timw32g_c209</TargetName>
-    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">timw32g_x64_c209</TargetName>
+    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">timw32g_c212</TargetName>
+    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">timw32g_x64_c212</TargetName>
     <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectName)_x64</TargetName>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
       <AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
       <ObjectFileName>.\Debug/</ObjectFileName>
       <ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
-      <WarningLevel>Level1</WarningLevel>
+      <WarningLevel>Level3</WarningLevel>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
       <CompileAs>CompileAsC</CompileAs>
index 13cf13b..16381d1 100644 (file)
                                ProgramDatabaseFile=".\Release/twsyng.pdb"
                                SubSystem="2"
                                LargeAddressAware="2"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
                                RandomizedBaseAddress="1"
-                               DataExecutionPrevention="0"
+                               DataExecutionPrevention="2"
                        />
                        <Tool
                                Name="VCALinkTool"
                                >
                        </File>
                        <File
+                               RelativePath="..\timidity\wasapi_a.c"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\timidity\wave_a.c"
                                >
                        </File>
index ee9888e..5287ebb 100644 (file)
@@ -80,8 +80,8 @@
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\</IntDir>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
-    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">twsyng_c209</TargetName>
-    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">twsyng_x64_c209</TargetName>
+    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">twsyng_c212</TargetName>
+    <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">twsyng_x64_c212</TargetName>
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(VCInstallDir)lib\amd64;$(VCInstallDir)atlmfc\lib\amd64;$(WindowsSdkDir)lib\x64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;</LibraryPath>
     <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectName)_x64</TargetName>
   </PropertyGroup>
     <ClCompile Include="..\interface\w32g_utl.c" />
     <ClCompile Include="..\timidity\w32g_vorbis_dll.c" />
     <ClCompile Include="..\timidity\w32g_vorbisenc_dll.c" />
+    <ClCompile Include="..\timidity\wasapi_a.c" />
     <ClCompile Include="..\timidity\wave_a.c" />
     <ClCompile Include="..\interface\winsyn_c.c" />
     <ClCompile Include="..\timidity\wrd_read.c" />
index 190e26e..d4fe29b 100644 (file)
                                OptimizeReferences="2"
                                EnableCOMDATFolding="2"
                                RandomizedBaseAddress="1"
-                               DataExecutionPrevention="0"
+                               DataExecutionPrevention="2"
                        />
                        <Tool
                                Name="VCALinkTool"
                                >
                        </File>
                        <File
+                               RelativePath="..\timidity\wasapi_a.c"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\timidity\wave_a.c"
                                >
                        </File>
index f84c5b2..ef5f734 100644 (file)
     <ClCompile Include="..\interface\w32g_utl.c" />
     <ClCompile Include="..\timidity\w32g_vorbis_dll.c" />
     <ClCompile Include="..\timidity\w32g_vorbisenc_dll.c" />
+    <ClCompile Include="..\timidity\wasapi_a.c" />
     <ClCompile Include="..\timidity\wave_a.c" />
     <ClCompile Include="..\interface\winsyn_c.c" />
     <ClCompile Include="..\timidity\wrd_read.c" />
index 5d32e45..03d0081 100644 (file)
@@ -29,7 +29,9 @@
 #define _WIN32_WINNT 0x0400
 #endif
 
-#define RTSYN_MULTITHREAD 1
+#define RTSYN_THREAD 1 // exclude RTSYN_MULTITHREAD
+// #define RTSYN_MULTITHREAD 1 // exclude RTSYN_THREAD
+
 
 #ifdef __DMC__
 unsigned long _beginthreadex(void *security, unsigned stack_size,
@@ -129,9 +131,8 @@ static DWORD dwOpenFlags;
 static CRITICAL_SECTION mim_section;
 static volatile int stop_thread;
 static HANDLE hRtsynThread;
-static DWORD processPriority;
-#ifdef RTSYN_MULTITHREAD
-LONG driverCount;
+//static DWORD processPriority;
+#if defined(RTSYN_MULTITHREAD)
 static volatile int stop_rtthread;
 static HANDLE hCalcThread;
 #endif /* RTSYN_MULTITHREAD */
@@ -258,6 +259,9 @@ extern void CloseMidiVolume(void);
 extern int GetMidiVolume(void);
 extern void SetMidiVolume(int newvolume);
 extern void MidiMidiVolume(void);
+///r
+extern DWORD processPriority;
+extern DWORD syn_ThreadPriority;
 
 //unsigned __stdcall threadfunc2(LPVOID lpV);
 //STDAPI_(LONG) DefDriverProc(DWORD dwDriverId, HDRVR hdrvr, UINT msg, LONG lParam1, LONG lParam2);
@@ -276,7 +280,7 @@ STDAPI_(LRESULT) DriverProc(DWORD_PTR dwDriverId, HDRVR hdrvr, UINT msg, LPARAM
 
                        stop_thread = 1;    //why thread can't stop by this????
                        while (stop_thread != 0 && maxloop-- > 0) Sleep(10);
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD)
                        if (stop_thread == 0) {
                                stop_rtthread = 1;
                                while (stop_rtthread != 0 && maxloop-- > 0) Sleep(10);
@@ -297,7 +301,7 @@ STDAPI_(LRESULT) DriverProc(DWORD_PTR dwDriverId, HDRVR hdrvr, UINT msg, LPARAM
                return DRV_OK;
 
        case DRV_LOAD:
-               processPriority = GetPriorityClass(GetCurrentProcess());
+       //      processPriority = GetPriorityClass(GetCurrentProcess());
                InitializeCriticalSection(&mim_section);
                OpenMidiVolume();
                return DRV_OK;
@@ -448,10 +452,10 @@ static int initialize_timiwp_main(void)
 
                if (0 == timiwp_main_ini(argc, argv)) {
                        rtsyn_init();
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD)
                        hThread = (HANDLE)_beginthreadex(NULL, 0, threadfunc, 0, 0, &thrdaddr);
-                       SetPriorityClass(hThread, REALTIME_PRIORITY_CLASS);
-                       SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
+                       SetPriorityClass(hThread, processPriority);
+                       SetThreadPriority(hThread, syn_ThreadPriority);
 #endif /* RTSYN_MULTITHREAD */
                        opend = 1;
                }
@@ -463,7 +467,7 @@ static int initialize_timiwp_main(void)
                cont++;
        }
 
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD)
        hCalcThread = hThread;
 #endif /* RTSYN_MULTITHREAD */
 
@@ -471,7 +475,7 @@ static int initialize_timiwp_main(void)
 }
 
 
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD) || defined(RTSYN_THREAD)
 
 struct evbuf_t {
        UINT uMsg;
@@ -582,7 +586,9 @@ static int timsyn_play_some_data(void)
 
        return played;
 }
+#endif /* defined(RTSYN_MULTITHREAD) || defined(RTSYN_THREAD) */
 
+#if defined(RTSYN_MULTITHREAD)
 static unsigned __stdcall threadfunc(LPVOID lpV)
 {
 #ifdef DEBUG_OUTPUT_STATUS
@@ -627,7 +633,7 @@ static unsigned __stdcall threadfunc2(LPVOID lpV)
        }
 #endif /* DEBUG_OUTPUT_STATUS */
 
-       initialize_timiwp_main();
+//     initialize_timiwp_main();
 
        while (stop_rtthread == 0) {
                Sleep(10);
@@ -653,20 +659,26 @@ static unsigned __stdcall threadfunc(LPVOID lpV)
                fprintf(logfile, "[%.3f] %s :",
                        get_current_calender_time(), "into threadfunc()");
                fputs(" ", logfile);
-               fputs(path, logfile);
+               fputs("threadfunc()", logfile);
                fprintf(logfile, "\n");
                fclose(logfile);
        }
        }
 #endif /* DEBUG_OUTPUT_STATUS */
 
-       initialize_timiwp_main();
+//     initialize_timiwp_main(); // modMessage() case MODM_OPEN: \82Æ\8fd\95¡ c212
 
        while (stop_thread == 0) {
+#if defined(RTSYN_THREAD)
+               Sleep(1);
+               timsyn_play_some_data();
+               rtsyn_play_calculate();
+#else
                Sleep(1);
                EnterCriticalSection(&mim_section);
                rtsyn_play_calculate();
                LeaveCriticalSection(&mim_section);
+#endif
        }
 
        rtsyn_stop_playing();
@@ -750,7 +762,7 @@ STDAPI_(DWORD) modMessage(UINT uDeviceID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR
        MIDIHDR *IIMidiHdr;
        int exlen = 0;
        unsigned int thrdaddr;
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD) || defined(RTSYN_THREAD)
        UINT evbpoint;
        BYTE *sysexbuffer = NULL;
 #endif /* RTSYN_MULTITHREAD */
@@ -782,10 +794,10 @@ STDAPI_(DWORD) modMessage(UINT uDeviceID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR
                        }
                        dwOpenFlags = (DWORD)dwParam2;
 
-                       processPriority = GetPriorityClass(GetCurrentProcess());
-                       SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
+               //      processPriority = GetPriorityClass(GetCurrentProcess());
+                       SetPriorityClass(GetCurrentProcess(), processPriority);
 
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD)
                        hCalcThread = NULL;
                        hRtsynThread = (HANDLE)_beginthreadex(NULL, 0, threadfunc2, 0, 0, &thrdaddr);
                        if (!hRtsynThread) {
@@ -803,7 +815,7 @@ STDAPI_(DWORD) modMessage(UINT uDeviceID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR
                                OpenCount--;
                                return MMSYSERR_NOMEM;
                        }
-                       SetThreadPriority(hRtsynThread, THREAD_PRIORITY_TIME_CRITICAL);
+                       SetThreadPriority(hRtsynThread, syn_ThreadPriority);
 #endif /* RTSYN_MULTITHREAD */
                        modCallback(MM_MOM_OPEN, dwParam1, dwParam2);
                        modm_closed = 0;
@@ -887,7 +899,7 @@ STDAPI_(DWORD) modMessage(UINT uDeviceID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR
                exlen = (int)IIMidiHdr->dwBytesRecorded;
            }
 
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD) || defined(RTSYN_THREAD)
            IIMidiHdr->dwFlags &= ~MHDR_DONE;
            IIMidiHdr->dwFlags |= MHDR_INQUEUE;
 
@@ -937,7 +949,7 @@ STDAPI_(DWORD) modMessage(UINT uDeviceID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR
            EnterCriticalSection(&mim_section);
            {
                const double event_time = get_current_calender_time();
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD) || defined(RTSYN_THREAD)
                evbpoint = evbwpoint;
                if (++evbwpoint >= EVBUFF_SIZE)
                    evbwpoint -= EVBUFF_SIZE;
@@ -991,7 +1003,7 @@ STDAPI_(DWORD) modMessage(UINT uDeviceID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR
 
        case MODM_CLOSE:
                if (stop_thread != 0) return MIDIERR_STILLPLAYING;
-#ifdef RTSYN_MULTITHREAD
+#if defined(RTSYN_MULTITHREAD)
                if (stop_rtthread != 0) return MIDIERR_STILLPLAYING;
 #endif /* RTSYN_MULTITHREAD */
                --OpenCount;
index 2060da1..8fa4d87 100755 (executable)
@@ -53,6 +53,8 @@ extern char def_instr_name[];
 
 extern CRITICAL_SECTION critSect;
 extern int opt_evil_mode;
+extern DWORD syn_ThreadPriority;
+
 
 #include "timiwp_timidity.h"
 
@@ -223,6 +225,9 @@ int timiwp_main_ini(int argc, char **argv)
 ///r
        load_all_instrument();
 #ifdef MULTI_THREAD_COMPUTE
+#if defined(__W32__)
+       set_compute_thread_priority(syn_ThreadPriority);
+#endif
        begin_compute_thread();
 #endif
 
index 8412ee0..70f32f1 100644 (file)
                </Configuration>
                <Configuration
                        Name="Release|Win32"
-                       OutputDirectory="..\Release\windrv\"
+                       OutputDirectory="..\Release\"
                        IntermediateDirectory="..\Release\windrv\"
                        ConfigurationType="2"
                        InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC70.vsprops"
                                AssemblerListingLocation="..\Release\windrv\"
                                ObjectFile="..\Release\windrv\"
                                ProgramDataBaseFileName="..\Release\windrv\"
-                               WarningLevel="0"
+                               WarningLevel="1"
                                Detect64BitPortabilityProblems="false"
                                CompileAs="1"
                        />
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="winmm.lib;wsock32.lib;comctl32.lib;"
+                               AdditionalDependencies="winmm.lib wsock32.lib comctl32.lib"
                                ShowProgress="1"
                                OutputFile="..\Release\timiditydrv.dll"
                                LinkIncremental="1"
                                SetChecksum="true"
                                RandomizedBaseAddress="1"
                                FixedBaseAddress="1"
-                               DataExecutionPrevention="0"
+                               DataExecutionPrevention="2"
                        />
                        <Tool
                                Name="VCALinkTool"
                                        >
                                </File>
                                <File
+                                       RelativePath="..\timidity\wasapi_a.c"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\timidity\wave_a.c"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\vstwrapper.h"
+                                       RelativePath="..\timidity\vstwrapper.h"
                                        >
                                </File>
                                <File
-                                       RelativePath="..\timidity\vstwrapper.h"
+                                       RelativePath="..\vstwrapper.h"
                                        >
                                </File>
                                <File
index afc159d..46fe26b 100644 (file)
@@ -80,7 +80,7 @@
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
     <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">timiditydrv</TargetName>
-    <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">timiditydrv5</TargetName>
+    <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">timiditydrv</TargetName>
     <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">timiditydrv</TargetName>
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(VCInstallDir)lib\amd64;$(VCInstallDir)atlmfc\lib\amd64;$(WindowsSdkDir)lib\x64;C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64;</LibraryPath>
     <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">timiditydrv</TargetName>
     <ClCompile Include="..\timidity\thread.c" />
     <ClCompile Include="..\timidity\timidity.c" />
     <ClCompile Include="..\timidity\voice_effect.c" />
+    <ClCompile Include="..\timidity\wasapi_a.c" />
     <ClCompile Include="timiditydrv.c" />
     <ClCompile Include="timiwp_timidity.c" />
     <ClCompile Include="..\timidity\version.c" />