Skip to content

Commit 81d8131

Browse files
committed
Resync
1 parent ce2652b commit 81d8131

5 files changed

Lines changed: 86 additions & 10 deletions

File tree

audio/audio_mixer.c

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
#include <ibxm/ibxm.h>
6262
#endif
6363

64+
#ifdef HAVE_THREADS
65+
#include <rthreads/rthreads.h>
66+
#define AUDIO_MIXER_LOCK(voice) slock_lock(voice->lock)
67+
#define AUDIO_MIXER_UNLOCK(voice) slock_unlock(voice->lock)
68+
#else
69+
#define AUDIO_MIXER_LOCK(voice) do {} while(0)
70+
#define AUDIO_MIXER_UNLOCK(voice) do {} while(0)
71+
#endif
72+
6473
#define AUDIO_MIXER_MAX_VOICES 8
6574
#define AUDIO_MIXER_TEMP_BUFFER 8192
6675

@@ -183,6 +192,9 @@ struct audio_mixer_voice
183192
unsigned type;
184193
float volume;
185194
bool repeat;
195+
#ifdef HAVE_THREADS
196+
slock_t *lock;
197+
#endif
186198
};
187199

188200
/* TODO/FIXME - static globals */
@@ -312,15 +324,33 @@ void audio_mixer_init(unsigned rate)
312324
s_rate = rate;
313325

314326
for (i = 0; i < AUDIO_MIXER_MAX_VOICES; i++)
315-
s_voices[i].type = AUDIO_MIXER_TYPE_NONE;
327+
{
328+
audio_mixer_voice_t *voice = &s_voices[i];
329+
330+
voice->type = AUDIO_MIXER_TYPE_NONE;
331+
#ifdef HAVE_THREADS
332+
if (!voice->lock)
333+
voice->lock = slock_new();
334+
#endif
335+
}
316336
}
317337

318338
void audio_mixer_done(void)
319339
{
320340
unsigned i;
321341

322342
for (i = 0; i < AUDIO_MIXER_MAX_VOICES; i++)
323-
audio_mixer_release(&s_voices[i]);
343+
{
344+
audio_mixer_voice_t *voice = &s_voices[i];
345+
346+
AUDIO_MIXER_LOCK(voice);
347+
audio_mixer_release(voice);
348+
AUDIO_MIXER_UNLOCK(voice);
349+
#ifdef HAVE_THREADS
350+
slock_free(voice->lock);
351+
voice->lock = NULL;
352+
#endif
353+
}
324354
}
325355

326356
audio_mixer_sound_t* audio_mixer_load_wav(void *buffer, int32_t size,
@@ -837,6 +867,14 @@ audio_mixer_voice_t* audio_mixer_play(audio_mixer_sound_t* sound,
837867
if (voice->type != AUDIO_MIXER_TYPE_NONE)
838868
continue;
839869

870+
AUDIO_MIXER_LOCK(voice);
871+
872+
if (voice->type != AUDIO_MIXER_TYPE_NONE)
873+
{
874+
AUDIO_MIXER_UNLOCK(voice);
875+
continue;
876+
}
877+
840878
/* claim the voice, also helps with cleanup on error */
841879
voice->type = sound->type;
842880

@@ -881,16 +919,22 @@ audio_mixer_voice_t* audio_mixer_play(audio_mixer_sound_t* sound,
881919
voice->volume = volume;
882920
voice->sound = sound;
883921
voice->stop_cb = stop_cb;
922+
AUDIO_MIXER_UNLOCK(voice);
884923
}
885924
else
886925
{
887-
audio_mixer_release(voice);
926+
if(i < AUDIO_MIXER_MAX_VOICES)
927+
{
928+
audio_mixer_release(voice);
929+
AUDIO_MIXER_UNLOCK(voice);
930+
}
888931
voice = NULL;
889932
}
890933

891934
return voice;
892935
}
893936

937+
/* Need to hold lock for voice. */
894938
static void audio_mixer_release(audio_mixer_voice_t* voice)
895939
{
896940
if (!voice)
@@ -933,11 +977,14 @@ void audio_mixer_stop(audio_mixer_voice_t* voice)
933977

934978
if (voice)
935979
{
980+
AUDIO_MIXER_LOCK(voice);
936981
stop_cb = voice->stop_cb;
937982
sound = voice->sound;
938983

939984
audio_mixer_release(voice);
940985

986+
AUDIO_MIXER_UNLOCK(voice);
987+
941988
if (stop_cb)
942989
stop_cb(sound, AUDIO_MIXER_SOUND_STOPPED);
943990
}
@@ -1287,7 +1334,11 @@ void audio_mixer_mix(float* buffer, size_t num_frames,
12871334

12881335
for (i = 0; i < AUDIO_MIXER_MAX_VOICES; i++, voice++)
12891336
{
1290-
float volume = (override) ? volume_override : voice->volume;
1337+
float volume;
1338+
1339+
AUDIO_MIXER_LOCK(voice);
1340+
1341+
volume = (override) ? volume_override : voice->volume;
12911342

12921343
switch (voice->type)
12931344
{
@@ -1317,6 +1368,8 @@ void audio_mixer_mix(float* buffer, size_t num_frames,
13171368
case AUDIO_MIXER_TYPE_NONE:
13181369
break;
13191370
}
1371+
1372+
AUDIO_MIXER_UNLOCK(voice);
13201373
}
13211374

13221375
for (j = 0, sample = buffer; j < num_frames * 2; j++, sample++)
@@ -1341,5 +1394,7 @@ void audio_mixer_voice_set_volume(audio_mixer_voice_t *voice, float val)
13411394
if (!voice)
13421395
return;
13431396

1397+
AUDIO_MIXER_LOCK(voice);
13441398
voice->volume = val;
1399+
AUDIO_MIXER_UNLOCK(voice);
13451400
}

include/libretro.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ enum retro_language
287287
RETRO_LANGUAGE_SWEDISH = 25,
288288
RETRO_LANGUAGE_UKRAINIAN = 26,
289289
RETRO_LANGUAGE_CZECH = 27,
290-
RETRO_LANGUAGE_VALENCIAN = 28,
290+
RETRO_LANGUAGE_CATALAN_VALENCIA = 28,
291+
RETRO_LANGUAGE_CATALAN = 29,
291292
RETRO_LANGUAGE_LAST,
292293

293294
/* Ensure sizeof(enum) == sizeof(int) */

include/string/stdstring.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ int string_index_last_occurance(char str[], char t);
282282
/* Find the position of a substring in a string. */
283283
int string_find_index_substring_string(const char* str1, const char* str2);
284284

285+
/* Strips non-ASCII characters from a string. */
286+
void string_copy_only_ascii(char *str_stripped, const char* str);
287+
285288
RETRO_END_DECLS
286289

287290
#endif

libco/x86.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ static unsigned char co_swap_function[] = {
4141
0xff, 0xe0, /* jmp eax */
4242
};
4343

44-
#if defined(__DJGPP__)
45-
static void co_init(void)
46-
{
47-
}
48-
#elif defined(_WIN32)
44+
#ifdef _WIN32
4945
#include <windows.h>
5046

5147
static void co_init(void)

string/stdstring.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,24 @@ int string_find_index_substring_string(const char* str1, const char* str2)
630630

631631
return -1;
632632
}
633+
634+
/* Strips non-ASCII characters from a string. */
635+
void string_copy_only_ascii(char *str_stripped, const char* str)
636+
{
637+
if (!string_is_empty(str))
638+
{
639+
unsigned i = 0;
640+
unsigned j = 0;
641+
642+
for (i = 0; i < strlen(str); i++)
643+
{
644+
if (str[i] > 0x1F && str[i] < 0x80)
645+
{
646+
str_stripped[j] = str[i];
647+
j++;
648+
}
649+
}
650+
651+
str_stripped[j] = '\0';
652+
}
653+
}

0 commit comments

Comments
 (0)