Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #30 from erikd/ao-curses
Browse files Browse the repository at this point in the history
Add two new locks
  • Loading branch information
DavidGriffith authored Jun 11, 2016
2 parents 5434cde + 61eae87 commit 2cc9b5a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 12 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MAN_PREFIX = $(PREFIX)
CONFIG_DIR = /etc
#CONFIG_DIR = $(PREFIX)/etc

# Pick your sound support. The most featureful form of sound support is
# Pick your sound support. The most featureful form of sound support is
# through libao. Comment all of these out if you don't want sound.
#
#SOUND = none
Expand All @@ -30,8 +30,8 @@ SOUND = ao


##########################################################################
# The configuration options below are intended mainly for older flavors
# of Unix. For Linux, BSD, and Solaris released since 2003, you can
# The configuration options below are intended mainly for older flavors
# of Unix. For Linux, BSD, and Solaris released since 2003, you can
# ignore this section.
##########################################################################

Expand All @@ -44,7 +44,7 @@ COLOR = yes
CURSES = -lncurses
#CURSES = -lcurses

# Just in case your operating system keeps its user-added header files
# Just in case your operating system keeps its user-added header files
# somewhere unusual...
#
#INCL = -I/usr/local/include
Expand All @@ -67,8 +67,8 @@ CURSES = -lncurses
#NO_MEMMOVE = yes

# Default sample rate for sound effects.
# All modern sound interfaces can be expected to support 44100 Hz sample
# rates. Earlier ones, particularly ones in Sun 4c workstations support
# All modern sound interfaces can be expected to support 44100 Hz sample
# rates. Earlier ones, particularly ones in Sun 4c workstations support
# only up to 8000 Hz.
SAMPLERATE = 44100

Expand Down Expand Up @@ -123,7 +123,8 @@ CURSES_OBJECT = $(CURSES_DIR)/ux_init.o \
$(CURSES_DIR)/ux_blorb.o \
$(CURSES_DIR)/ux_audio.o \
$(CURSES_DIR)/ux_resource.o \
$(CURSES_DIR)/ux_audio_none.o
$(CURSES_DIR)/ux_audio_none.o \
$(CURSES_DIR)/ux_locks.o

DUMB_DIR = $(SRCDIR)/dumb
DUMB_TARGET = $(SRCDIR)/frotz_dumb.a
Expand Down
10 changes: 5 additions & 5 deletions src/curses/ux_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#endif

#include "ux_frotz.h"
#include "ux_locks.h"

#ifndef NO_SOUND

Expand Down Expand Up @@ -99,7 +100,6 @@ bool music_stop = FALSE;

float *musicbuffer;
int musicsamples;
int musicnum;


/*
Expand Down Expand Up @@ -259,8 +259,8 @@ void os_stop_sample (int number)
while(pthread_kill(playaiff_id, 0) == 0);
}

if (music_playing && (number == musicnum || number == 0)) {
music_playing = FALSE;
if (get_music_playing() && (number == get_musicnum () || number == 0)) {
set_music_playing(false);
while(pthread_kill(playmusic_id, 0) == 0);
}

Expand Down Expand Up @@ -456,7 +456,7 @@ static int mypower(int base, int exp) {
* handled here.
*
* This function should be able to play OGG chunks, but because of a bug
* or oversight in Libsndfile, that library is incapable of playing OGG
* or oversight in Libsndfile, that library is incapable of playing OGG
* data which are embedded in a larger file.
*
*/
Expand Down Expand Up @@ -631,7 +631,7 @@ static void *playmod(EFFECT *raw_effect)

EFFECT myeffect = *raw_effect;

musicnum = myeffect.number;
set_musicnum(myeffect.number);

filestart = ftell(myeffect.fp);
fseek(myeffect.fp, myeffect.result.data.startpos, SEEK_SET);
Expand Down
60 changes: 60 additions & 0 deletions src/curses/ux_locks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

#include <pthread.h>
#include <stdbool.h>

#include "ux_locks.h"

static bool music_playing = false;
static pthread_mutex_t music_playing_mutex = PTHREAD_MUTEX_INITIALIZER;

static int musicnum = 0;
static pthread_mutex_t musicnum_mutex = PTHREAD_MUTEX_INITIALIZER;

bool
get_music_playing (void)
{
bool value;

pthread_mutex_lock (&music_playing_mutex);
value = music_playing;
pthread_mutex_unlock (&music_playing_mutex);
return value;
}


bool
set_music_playing (bool new_value)
{
bool old_value;

pthread_mutex_lock (&music_playing_mutex);
old_value = music_playing;
music_playing = new_value;
pthread_mutex_unlock (&music_playing_mutex);
return old_value;
}


int
get_musicnum (void)
{
int value;

pthread_mutex_lock (&musicnum_mutex);
value = musicnum;
pthread_mutex_unlock (&musicnum_mutex);
return value;
}


int
set_musicnum (int new_value)
{
int old_value;

pthread_mutex_lock (&musicnum_mutex);
old_value = musicnum;
musicnum = new_value;
pthread_mutex_unlock (&musicnum_mutex);
return old_value;
}
5 changes: 5 additions & 0 deletions src/curses/ux_locks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bool get_music_playing (void);
bool set_music_playing (bool new_value);

int get_musicnum (void);
int set_musicnum (int new_value);

0 comments on commit 2cc9b5a

Please sign in to comment.