From 18 Jan, 2021 0:00 UTC: All services will be temporary unavailable for maintenance
  • R/O
  • HTTP
  • SSH
  • HTTPS

timidity41: Commit


Commit MetaInfo

Revisiond914323331c13b5b0c4a43482138bec2ae615f79 (tree)
Time2020-09-26 16:29:30
AuthorStarg <starg@user...>
CommiterStarg

Log Message

Merge branch 'dev41' into unicode

Change Summary

Incremental Difference

--- a/interface/w32g_i.c
+++ b/interface/w32g_i.c
@@ -5834,13 +5834,23 @@ void w32g_show_console(void)
58345834 //
58355835 // GDI アクセスを単一スレッドに限定するためのロック機構
58365836
5837+#ifdef TIMW32G_USE_USERMODE_LOCKS
5838+static SRWLOCK w32g_gdi_lock = SRWLOCK_INIT;
5839+#else
58375840 static HANDLE volatile hMutexGDI = NULL;
5841+#endif
58385842 // static int volatile lock_num = 0;
58395843 int gdi_lock_ex ( DWORD timeout )
58405844 {
58415845 // lock_num++;
58425846 // ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
58435847 // "gdi_lock<%d %d>", GetCurrentThreadId(),lock_num );
5848+#ifdef TIMW32G_USE_USERMODE_LOCKS
5849+ if (timeout == INFINITE)
5850+ AcquireSRWLockExclusive(&w32g_gdi_lock);
5851+ else
5852+ return TryAcquireSRWLockExclusive(&w32g_gdi_lock) ? 0 : -1;
5853+#else
58445854 if(hMutexGDI==NULL){
58455855 hMutexGDI = CreateMutex(NULL,FALSE,NULL);
58465856 if(hMutexGDI==NULL)
@@ -5849,6 +5859,7 @@ int gdi_lock_ex ( DWORD timeout )
58495859 if(WaitForSingleObject(hMutexGDI,timeout)==WAIT_FAILED){
58505860 return -1;
58515861 }
5862+#endif
58525863 return 0;
58535864 }
58545865 int gdi_lock(void)
@@ -5861,8 +5872,12 @@ extern int gdi_unlock(void)
58615872 //lock_num--;
58625873 //ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
58635874 // "gdi_unlock<%d %d>", GetCurrentThreadId(),lock_num );
5875+#ifdef TIMW32G_USE_USERMODE_LOCKS
5876+ ReleaseSRWLockExclusive(&w32g_gdi_lock);
5877+#else
58645878 if(hMutexGDI!=NULL){
58655879 ReleaseMutex(hMutexGDI);
58665880 }
5881+#endif
58675882 return 0;
58685883 }
--- a/interface/w32g_subwin2.c
+++ b/interface/w32g_subwin2.c
@@ -170,9 +170,27 @@ static void wrd_text_update ( int x_from, int y_from, int x_to, int y_to, int lo
170170
171171 static int volatile wrd_graphic_pal_init_flag = 0;
172172
173+#define TIMW32G_USE_USERMODE_LOCKS
174+#ifdef TIMW32G_USE_USERMODE_LOCKS
175+static CRITICAL_SECTION *w32g_wrd_wnd_lock = NULL;
176+#else
173177 static HANDLE volatile hMutexWrd = NULL;
178+#endif
179+
174180 static BOOL wrd_wnd_lock_ex ( DWORD timeout )
175181 {
182+#ifdef TIMW32G_USE_USERMODE_LOCKS
183+ static CRITICAL_SECTION cs;
184+
185+ if (w32g_wrd_wnd_lock == NULL) {
186+ InitializeCriticalSection(&cs);
187+ w32g_wrd_wnd_lock = &cs;
188+ }
189+ if (timeout == INFINITE)
190+ EnterCriticalSection(w32g_wrd_wnd_lock);
191+ else
192+ return TryEnterCriticalSection(w32g_wrd_wnd_lock);
193+#else
176194 if ( hMutexWrd == NULL ) {
177195 hMutexWrd = CreateMutex ( NULL, FALSE, NULL );
178196 if ( hMutexWrd == NULL )
@@ -181,6 +199,7 @@ static BOOL wrd_wnd_lock_ex ( DWORD timeout )
181199 if ( WaitForSingleObject ( hMutexWrd, timeout )== WAIT_FAILED ) {
182200 return FALSE;
183201 }
202+#endif
184203 return TRUE;
185204 }
186205 static BOOL wrd_wnd_lock (void)
@@ -189,7 +208,11 @@ static BOOL wrd_wnd_lock (void)
189208 }
190209 static void wrd_wnd_unlock (void)
191210 {
211+#ifdef TIMW32G_USE_USERMODE_LOCKS
212+ LeaveCriticalSection(w32g_wrd_wnd_lock);
213+#else
192214 ReleaseMutex ( hMutexWrd );
215+#endif
193216 }
194217
195218
--- a/interface/w32g_subwin3.c
+++ b/interface/w32g_subwin3.c
@@ -251,9 +251,25 @@ static int tracer_lock_result;
251251 #define TRACER_UNLOCK() { tracer_wnd_unlock(); }
252252 #endif
253253
254+#define TIMW32G_USE_USERMODE_LOCKS
255+#ifdef TIMW32G_USE_USERMODE_LOCKS
256+static CRITICAL_SECTION *w32g_tracer_wnd_lock = NULL;
257+#else
254258 static HANDLE volatile hMutexWrd = NULL;
259+#endif
255260 static BOOL tracer_wnd_lock_ex(DWORD timeout)
256261 {
262+#ifdef TIMW32G_USE_USERMODE_LOCKS
263+ static CRITICAL_SECTION cs;
264+ if (!w32g_tracer_wnd_lock) {
265+ InitializeCriticalSection(&cs);
266+ w32g_tracer_wnd_lock = &cs;
267+ }
268+ if (timeout == INFINITE)
269+ EnterCriticalSection(w32g_tracer_wnd_lock);
270+ else
271+ return TryEnterCriticalSection(w32g_tracer_wnd_lock);
272+#else
257273 if (!hMutexWrd) {
258274 hMutexWrd = CreateMutex(NULL, FALSE, NULL);
259275 if (!hMutexWrd)
@@ -262,6 +278,7 @@ static BOOL tracer_wnd_lock_ex(DWORD timeout)
262278 if (WaitForSingleObject(hMutexWrd, timeout) == WAIT_FAILED) {
263279 return FALSE;
264280 }
281+#endif
265282 return TRUE;
266283 }
267284 static BOOL tracer_wnd_lock(void)
@@ -270,7 +287,11 @@ static BOOL tracer_wnd_lock(void)
270287 }
271288 static void tracer_wnd_unlock(void)
272289 {
290+#ifdef TIMW32G_USE_USERMODE_LOCKS
291+ LeaveCriticalSection(w32g_tracer_wnd_lock);
292+#else
273293 ReleaseMutex(hMutexWrd);
294+#endif
274295 }
275296
276297 // ****************************************************************************
--- a/timidity/decode.c
+++ b/timidity/decode.c
@@ -313,12 +313,47 @@ static FLAC__StreamDecoderWriteStatus flac_write_callback(const FLAC__StreamDeco
313313 for (int i = 0; i < sdr->channels; i++) {
314314 switch (sdr->data_type) {
315315 case SAMPLE_TYPE_INT32:
316- memcpy(((FLAC__int32 *)sdr->data[i]) + context->current_size_in_samples, buffer[i], frame->header.blocksize * sizeof(FLAC__int32));
316+ {
317+ // MSVC can't figure out this does not change during the loop.
318+ int s = 32 - frame->header.bits_per_sample;
319+ int32 *src = buffer[i];
320+ int32 *dest = (int32 *)sdr->data[i] + context->current_size_in_samples;
321+ int n = frame->header.blocksize;
322+
323+ // This loop should be auto-vectorized.
324+ for (int j = 0; j < n; j++) {
325+ dest[j] = src[j] << s;
326+ }
327+ }
317328 break;
318329
319330 case SAMPLE_TYPE_INT16:
320- for (unsigned int j = 0; j < frame->header.blocksize; j++) {
321- sdr->data[i][context->current_size_in_samples + j] = (FLAC__int16)buffer[i][j];
331+ {
332+ int s = 16 - frame->header.bits_per_sample;
333+ int32 *src = buffer[i];
334+ int16 *dest = (int16 *)sdr->data[i] + context->current_size_in_samples;
335+ int n = frame->header.blocksize;
336+
337+ int j = 0;
338+
339+#if USE_X86_EXT_INTRIN >= 3
340+ int n8 = n & ~7;
341+ __m128i vs = _mm_cvtsi32_si128(s);
342+
343+ while (j < n8) {
344+ __m128i v0 = _mm_loadu_si128((const __m128i *)(src + j));
345+ __m128i v1 = _mm_loadu_si128((const __m128i *)(src + j + 4));
346+ __m128i v01 = _mm_packs_epi32(v0, v1);
347+ v01 = _mm_sll_epi16(v01, vs);
348+ _mm_storeu_si128((__m128i *)(dest + j), v01);
349+ j += 8;
350+ }
351+#endif
352+
353+ while (j < n) {
354+ dest[j] = (int16)(src[j] << s);
355+ j++;
356+ }
322357 }
323358 break;
324359 }
--- a/timidity/instrum.c
+++ b/timidity/instrum.c
@@ -1194,8 +1194,13 @@ fail:
11941194 sp->modenv_rate[4] = to_rate(64);
11951195 sp->modenv_offset[5] = 0;
11961196 sp->modenv_rate[5] = to_rate(64);
1197-
1197+
11981198 sp->offset = 0;
1199+ sp->seq_length = 0;
1200+ sp->seq_position = 0;
1201+ sp->lorand = -1;
1202+ sp->hirand = -1;
1203+ sp->rt_decay = 0;
11991204 READ_LONG(sp->data_length);
12001205 READ_LONG(sp->loop_start);
12011206 READ_LONG(sp->loop_end);
--- a/timidity/int_synth.c
+++ b/timidity/int_synth.c
@@ -4273,7 +4273,12 @@ static void init_sample_param(Sample *sample)
42734273 sample->modenv_velf[2] = 0;
42744274 sample->modenv_velf[3] = 0;
42754275 sample->modenv_velf[4] = 0;
4276- sample->modenv_velf[5] = 0;
4276+ sample->modenv_velf[5] = 0;
4277+ sample->seq_length = 0;
4278+ sample->seq_position = 0;
4279+ sample->lorand = -1;
4280+ sample->hirand = -1;
4281+ sample->rt_decay = 0;
42774282 }
42784283
42794284
--- a/timidity/mod2midi.c
+++ b/timidity/mod2midi.c
@@ -738,7 +738,13 @@ void load_module_samples (SAMPLE * s, int numsamples, int ntsc)
738738 sp->sample_type = SF_SAMPLETYPE_MONO;
739739 sp->sf_sample_link = -1;
740740 sp->sf_sample_index = 0;
741-
741+ sp->offset = 0;
742+ sp->seq_length = 0;
743+ sp->seq_position = 0;
744+ sp->lorand = -1;
745+ sp->hirand = -1;
746+ sp->rt_decay = 0;
747+
742748 sp->data_length <<= FRACTION_BITS;
743749 sp->loop_start <<= FRACTION_BITS;
744750 sp->loop_end <<= FRACTION_BITS;
--- a/timidity/playmidi.c
+++ b/timidity/playmidi.c
@@ -1271,6 +1271,8 @@ static void initialize_controllers(int c)
12711271 /* Process the Reset All Controllers event CC#121 */
12721272 static void reset_controllers(int c)
12731273 {
1274+ int i;
1275+
12741276 channel[c].expression = 127; /* SCC-1 does this. */
12751277 channel[c].sustain = 0;
12761278 channel[c].sostenuto = 0;
@@ -1283,12 +1285,12 @@ static void reset_controllers(int c)
12831285 channel[c].lastlrpn = channel[c].lastmrpn = 0;
12841286 channel[c].nrpn = -1;
12851287 channel[c].rpn_7f7f_flag = 1;
1286-
1288+
12871289 memset(channel[c].key_pressed, 0, sizeof(channel[c].key_pressed));
12881290 memset(channel[c].key_history, 0, sizeof(channel[c].key_history));
12891291 channel[c].last_key_history_index = 0;
12901292
1291- for (int i = 0; i < MAX_ELEMENT; i++) {
1293+ for (i = 0; i < MAX_ELEMENT; i++) {
12921294 safe_free(channel[c].seq_counters[i]);
12931295 channel[c].seq_counters[i] = NULL;
12941296 channel[c].seq_num_counters[i] = 0;
--- a/timidity/sndfont.c
+++ b/timidity/sndfont.c
@@ -1624,6 +1624,8 @@ static void set_sample_info(SFInfo *sf, SampleList *vp, LayerTable *tbl)
16241624
16251625 vp->v.offset = 0;
16261626
1627+ vp->v.offset = 0;
1628+
16271629 /* set loop position */
16281630 vp->v.loop_start = sp->startloop;
16291631 vp->v.loop_end = sp->endloop;
@@ -1744,6 +1746,12 @@ static void set_sample_info(SFInfo *sf, SampleList *vp, LayerTable *tbl)
17441746 vp->v.pitch_envelope[6] = 0; // 125ms dcy3
17451747 vp->v.pitch_envelope[7] = 0; // 0cent rls
17461748 vp->v.pitch_envelope[8] = 0; // 125ms rls
1749+ vp->v.offset = 0;
1750+ vp->v.seq_length = 0;
1751+ vp->v.seq_position = 0;
1752+ vp->v.lorand = -1;
1753+ vp->v.hirand = -1;
1754+ vp->v.rt_decay = 0;
17471755 }
17481756
17491757 /*----------------------------------------------------------------*/
Show on old repository browser