Audio codepaths now always enabled

- Supported platforms:
        - Mac/iOS (OpenAL)
        - Desktop Linux/POSIX (OpenAL)
        - Android (OpenSLES)
    - TODO : for POSIX builds we should provide our own "null" audio backend if OpenAL/OpenSL not found by build script
This commit is contained in:
Aaron Culliney 2016-07-23 11:44:49 -07:00
parent 06f8015959
commit cc9a164bec
7 changed files with 18 additions and 90 deletions

View File

@ -40,7 +40,7 @@ APPLE2_MAIN_SRC = \
jnihooks.c androidkeys.c
APPLE2_OPTIM_CFLAGS := -Os
APPLE2_BASE_CFLAGS := -DAPPLE2IX=1 -DINTERFACE_TOUCH=1 -DMOBILE_DEVICE=1 -DVIDEO_OPENGL=1 -DDEBUGGER=1 -DAUDIO_ENABLED=1 -std=gnu11 -fPIC $(APPLE2_OPTIM_CFLAGS) -I$(APPLE2_SRC_PATH)
APPLE2_BASE_CFLAGS := -DAPPLE2IX=1 -DINTERFACE_TOUCH=1 -DMOBILE_DEVICE=1 -DVIDEO_OPENGL=1 -DDEBUGGER=1 -std=gnu11 -fPIC $(APPLE2_OPTIM_CFLAGS) -I$(APPLE2_SRC_PATH)
APPLE2_BASE_LDLIBS := -Wl,-z,text -Wl,-z,noexecstack -llog -landroid -lGLESv2 -lz -lOpenSLES -latomic
LOCAL_WHOLE_STATIC_LIBRARIES += cpufeatures

View File

@ -2777,7 +2777,6 @@
"TESTING=1",
"TEST_CPU=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestCPU-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@ -2815,7 +2814,6 @@
"TESTING=1",
"TEST_CPU=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestCPU-Info.plist";
@ -2856,7 +2854,6 @@
"TESTING=1",
"TEST_VM=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestVM-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@ -2894,7 +2891,6 @@
"TESTING=1",
"TEST_VM=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestVM-Info.plist";
@ -2938,7 +2934,6 @@
"DISK_TRACING=1",
"VM_TRACING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestDisk-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@ -2979,7 +2974,6 @@
"DISK_TRACING=1",
"VM_TRACING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestDisk-Info.plist";
@ -3020,7 +3014,6 @@
"TESTING=1",
"TEST_DISPLAY=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestDisplay-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@ -3058,7 +3051,6 @@
"TESTING=1",
"TEST_DISPLAY=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2MacTests/Apple2iOSTestDisplay-Info.plist";
@ -3096,7 +3088,6 @@
"DISK_TRACING=1",
"VM_TRACING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
@ -3129,7 +3120,6 @@
"DISK_TRACING=1",
"VM_TRACING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
HEADER_SEARCH_PATHS = (
@ -3160,7 +3150,6 @@
"TEST_VM=1",
"TESTING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
@ -3190,7 +3179,6 @@
"TEST_VM=1",
"TESTING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
HEADER_SEARCH_PATHS = (
@ -3330,7 +3318,6 @@
"APPLE2IX=1",
"DEBUGGER=1",
"KEYPAD_JOYSTICK=1",
"AUDIO_ENABLED=1",
"VIDEO_OPENGL=1",
);
HEADER_SEARCH_PATHS = (
@ -3360,7 +3347,6 @@
"APPLE2IX=1",
"DEBUGGER=1",
"KEYPAD_JOYSTICK=1",
"AUDIO_ENABLED=1",
"VIDEO_OPENGL=1",
"NDEBUG=1",
);
@ -3394,7 +3380,6 @@
"TEST_CPU=1",
"TESTING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
@ -3424,7 +3409,6 @@
"TEST_CPU=1",
"TESTING=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
HEADER_SEARCH_PATHS = (
@ -3455,7 +3439,6 @@
"TESTING=1",
"TEST_DISPLAY=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
@ -3485,7 +3468,6 @@
"TESTING=1",
"TEST_DISPLAY=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
HEADER_SEARCH_PATHS = (
@ -3520,7 +3502,6 @@
"MOBILE_DEVICE=1",
"DEBUGGER=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2iOS/Apple2iOS-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
@ -3556,7 +3537,6 @@
"MOBILE_DEVICE=1",
"DEBUGGER=1",
"VIDEO_OPENGL=1",
"AUDIO_ENABLED=1",
"NDEBUG=1",
);
INFOPLIST_FILE = "$(SRCROOT)/Apple2iOS/Apple2iOS-Info.plist";

View File

@ -256,7 +256,6 @@ AC_ARG_ENABLE([audio], AS_HELP_STRING([--disable-audio], [Disable emulator audio
AC_SEARCH_LIBS(alcOpenDevice, openal, [
dnl found OpenAL ...
openal_supported='yes'
AC_DEFINE(AUDIO_ENABLED, 1, [Enable sound module])
AUDIO_GLUE_C="src/audio/speaker.c src/audio/mockingboard.c src/audio/playqueue.c"
AUDIO_O="src/audio/soundcore.o src/audio/soundcore-openal.o src/audio/speaker.o src/audio/playqueue.o src/audio/alhelpers.o src/audio/mockingboard.o src/audio/AY8910.o"
dnl HACK there's gotta be a better way ... without this verbosity, CFLAGS are not correct (lacking -DTESTING=1 , etc) if we don't specify specific obj files for test binaries
@ -267,19 +266,19 @@ AC_ARG_ENABLE([audio], AS_HELP_STRING([--disable-audio], [Disable emulator audio
testtrace_AUDIO_O="src/audio/testtrace-soundcore.o src/audio/testtrace-soundcore-openal.o src/audio/testtrace-speaker.o src/audio/testtrace-playqueue.o src/audio/testtrace-alhelpers.o src/audio/testtrace-mockingboard.o src/audio/testtrace-AY8910.o"
testvm_AUDIO_O="src/audio/testvm-soundcore.o src/audio/testvm-soundcore-openal.o src/audio/testvm-speaker.o src/audio/testvm-playqueue.o src/audio/testvm-alhelpers.o src/audio/testvm-mockingboard.o src/audio/testvm-AY8910.o"
], [
AC_MSG_WARN([Could not find OpenAL libraries, sound will be disabled])
AC_MSG_ERROR([Could not find OpenAL libraries ... todo fixme ... implement a null sound backend])
], [])
], [
AC_MSG_WARN([Could not find OpenAL headers, sound will be disabled])
AC_MSG_ERROR([Could not find OpenAL headers ... todo fixme ... implement a null sound backend])
], [
#include <AL/al.h>
#include <AL/alc.h>
])
], [
AC_MSG_WARN([Could not find OpenAL headers, sound will be disabled])
AC_MSG_ERROR([Could not find OpenAL headers ... todo fixme ... implement a null sound backend])
])
], [
AC_MSG_WARN([Could not find OpenAL headers, sound will be disabled])
AC_MSG_ERROR([Could not find OpenAL headers ... todo fixme ... implement a null sound backend])
])
])
AC_SUBST(AUDIO_GLUE_C)

View File

@ -104,15 +104,11 @@ static inline GLenum safeGLGetError(void) {
#define glGetError() 0
#endif
#ifdef DEBUGGER
#include "meta/debug.h"
#endif
#ifdef AUDIO_ENABLED
#include "audio/soundcore.h"
#include "audio/speaker.h"
#include "audio/mockingboard.h"
#endif
#ifdef ANDROID
# include "../Android/jni/android_globals.h"

View File

@ -71,11 +71,9 @@ bool alt_speed_enabled = false;
// misc
volatile uint8_t emul_reinitialize = 1;
#ifdef AUDIO_ENABLED
static bool emul_reinitialize_audio = false;
static bool emul_pause_audio = false;
static bool emul_resume_audio = false;
#endif
static bool cpu_shutting_down = false;
pthread_t cpu_thread_id = 0;
pthread_mutex_t interface_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -136,10 +134,8 @@ static void _timing_initialize(double scale) {
if (!is_fullspeed) {
cycles_persec_target = CLK_6502 * scale;
}
#ifdef AUDIO_ENABLED
speaker_reset();
//TIMING_LOG("ClockRate:%0.2lf ClockCyclesPerSpeakerSample:%0.2lf", cycles_persec_target, speaker_cyclesPerSample());
#endif
}
#if !TESTING
@ -162,9 +158,7 @@ void reinitialize(void) {
timing_initialize();
#ifdef AUDIO_ENABLED
MB_Reset();
#endif
}
void timing_initialize(void) {
@ -184,8 +178,7 @@ void timing_toggleCPUSpeed(void) {
timing_initialize();
}
#ifdef AUDIO_ENABLED
void timing_reinitializeAudio(void) {
static void timing_reinitializeAudio(void) {
SPINLOCK_ACQUIRE(&_pause_spinLock);
assert(pthread_self() != cpu_thread_id);
#if !TESTING
@ -196,7 +189,6 @@ void timing_reinitializeAudio(void) {
emul_resume_audio = false;
SPINLOCK_RELINQUISH(&_pause_spinLock);
}
#endif
void cpu_pause(void) {
assert(pthread_self() != cpu_thread_id);
@ -209,11 +201,9 @@ void cpu_pause(void) {
// CPU thread will be paused when it next tries to acquire interface_mutex
LOG("PAUSING CPU...");
#ifdef AUDIO_ENABLED
if (!emul_reinitialize_audio) {
emul_pause_audio = true;
}
#endif
pthread_mutex_lock(&interface_mutex);
is_paused = true;
} while (0);
@ -230,11 +220,9 @@ void cpu_resume(void) {
}
// CPU thread will be unblocked to acquire interface_mutex
#ifdef AUDIO_ENABLED
if (!emul_reinitialize_audio) {
emul_resume_audio = true;
}
#endif
LOG("RESUMING CPU...");
pthread_mutex_unlock(&interface_mutex);
is_paused = false;
@ -279,15 +267,12 @@ static void *cpu_thread(void *dummyptr) {
unsigned long dbg_cycles_executed = 0;
#endif
#ifdef AUDIO_ENABLED
audio_init();
speaker_init();
MB_Initialize();
#endif
do
{
#ifdef AUDIO_ENABLED
LOG("CPUTHREAD %lu LOCKING FOR MAYBE INITIALIZING AUDIO ...", cpu_thread_id);
pthread_mutex_lock(&interface_mutex);
if (emul_reinitialize_audio) {
@ -305,7 +290,6 @@ static void *cpu_thread(void *dummyptr) {
}
pthread_mutex_unlock(&interface_mutex);
LOG("UNLOCKING FOR MAYBE INITIALIZING AUDIO ...");
#endif
if (emul_reinitialize) {
reinitialize();
@ -323,19 +307,15 @@ static void *cpu_thread(void *dummyptr) {
do {
SCOPE_TRACE_CPU("CPU mainloop");
// -LOCK----------------------------------------------------------------------------------------- SAMPLE ti
#ifdef AUDIO_ENABLED
if (UNLIKELY(emul_pause_audio)) {
emul_pause_audio = false;
audio_pause();
}
#endif
pthread_mutex_lock(&interface_mutex);
#ifdef AUDIO_ENABLED
if (UNLIKELY(emul_resume_audio)) {
emul_resume_audio = false;
audio_resume();
}
#endif
clock_gettime(CLOCK_MONOTONIC, &ti);
deltat = timespec_diff(t0, ti, &negative);
@ -360,9 +340,7 @@ static void *cpu_thread(void *dummyptr) {
cpu65_cycles_to_execute = 0;
}
#ifdef AUDIO_ENABLED
MB_StartOfCpuExecute();
#endif
if (is_debugging) {
debugging_cycles0 = cpu65_cycles_to_execute;
debugging_cycles = cpu65_cycles_to_execute;
@ -402,21 +380,15 @@ static void *cpu_thread(void *dummyptr) {
#endif
g_dwCyclesThisFrame += cpu65_cycle_count;
#ifdef AUDIO_ENABLED
MB_UpdateCycles(); // update 6522s (NOTE: do this before updating cycles_count_total)
#endif
timing_checkpoint_cycles();
#ifdef AUDIO_ENABLED
speaker_flush(); // play audio
#endif
if (g_dwCyclesThisFrame >= dwClksPerFrame) {
g_dwCyclesThisFrame -= dwClksPerFrame;
#ifdef AUDIO_ENABLED
MB_EndOfVideoFrame();
#endif
}
clock_gettime(CLOCK_MONOTONIC, &tj);
@ -428,9 +400,7 @@ static void *cpu_thread(void *dummyptr) {
disk_motor_time = timespec_diff(disk6.motor_time, tj, &negative);
assert(!negative);
if (!is_fullspeed &&
#ifdef AUDIO_ENABLED
!speaker_isActive() &&
#endif
!video_isDirty(A2_DIRTY_FLAG) && (!disk6.motor_off && (disk_motor_time.tv_sec || disk_motor_time.tv_nsec > DISK_MOTOR_QUIET_NSECS)) )
{
TIMING_LOG("auto switching to full speed");
@ -503,9 +473,7 @@ static void *cpu_thread(void *dummyptr) {
#if !MOBILE_DEVICE
if (timing_shouldAutoAdjustSpeed()) {
if (is_fullspeed && (
#ifdef AUDIO_ENABLED
speaker_isActive() ||
#endif
video_isDirty(A2_DIRTY_FLAG) || (disk6.motor_off && (disk_motor_time.tv_sec || disk_motor_time.tv_nsec > DISK_MOTOR_QUIET_NSECS))) )
{
double speed = alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor;
@ -521,11 +489,9 @@ static void *cpu_thread(void *dummyptr) {
break;
}
#ifdef AUDIO_ENABLED
if (UNLIKELY(emul_reinitialize_audio)) {
break;
}
#endif
if (UNLIKELY(cpu_shutting_down)) {
break;
@ -537,11 +503,9 @@ static void *cpu_thread(void *dummyptr) {
}
} while (1);
#ifdef AUDIO_ENABLED
speaker_destroy();
MB_Destroy();
audio_shutdown();
#endif
return NULL;
}
@ -613,7 +577,6 @@ static void vm_prefsChanged(const char *domain) {
if (cpu_altscale_factor > CPU_SCALE_FASTEST_PIVOT) {
cpu_altscale_factor = CPU_SCALE_FASTEST;
}
#ifdef AUDIO_ENABLED
static float audioLatency = 0.f;
float latency = prefs_parseFloatValue(PREF_DOMAIN_AUDIO, PREF_AUDIO_LATENCY, &fVal) ? fVal : 0.25f;
@ -632,7 +595,6 @@ static void vm_prefsChanged(const char *domain) {
MB_SetEnabled(enabled);
timing_reinitializeAudio();
}
#endif
}
static __attribute__((constructor)) void _init_vm(void) {

View File

@ -95,13 +95,6 @@ bool timing_shouldAutoAdjustSpeed(void);
*/
void timing_initialize(void);
#ifdef AUDIO_ENABLED
/*
* force audio reinitialization
*/
void timing_reinitializeAudio(void);
#endif
/*
* Pause timing/CPU thread.
*

View File

@ -872,14 +872,15 @@ GLUE_C_READ(iie_cxrom_peripheral)
{
softswitches &= ~SS_CXROM;
base_cxrom = apple_ii_64k[0];
#ifdef AUDIO_ENABLED
// FIXME TODO : implement pluggable peripheral API
//if (mockingboard_inserted) {
extern VMFunc MB_Read;
base_c4rom = (void*)MB_Read;
base_c5rom = (void*)MB_Read;
#else
//} else {
base_c4rom = (void*)ram_nop;
base_c5rom = (void*)ram_nop;
#endif
//}
if (!(softswitches & SS_C3ROM)) {
base_c3rom = apple_ii_64k[0];
}
@ -1194,9 +1195,10 @@ static void _initialize_tables(void) {
// HACK TODO FIXME : this needs to be tied to the UI/configuration system (once we have more/conflicting options)
#ifdef AUDIO_ENABLED
// FIXME TODO : implement pluggable peripheral API
//if (mockingboard_inserted) {
mb_io_initialize(4, 5); /* Mockingboard(s) and/or Phasor in slots 4 & 5 */
#endif
//}
}
// ----------------------------------------------------------------------------
@ -1213,12 +1215,7 @@ void vm_initialize(void) {
void vm_reinitializeAudio(void) {
for (unsigned int i = 0xC030; i < 0xC040; i++) {
cpu65_vmem_r[i] = cpu65_vmem_w[i] =
#ifdef AUDIO_ENABLED
speaker_toggle;
#else
ram_nop;
#endif
cpu65_vmem_r[i] = cpu65_vmem_w[i] = speaker_toggle;
}
#warning TODO FIXME ... should unset MB/Phasor hooks if volume is zero ...
}
@ -1492,14 +1489,15 @@ bool vm_loadState(StateHelper_s *helper) {
LOG("LOAD base_cxrom = %d", state);
if (state == 0) {
base_cxrom = apple_ii_64k[0];
#ifdef AUDIO_ENABLED
// FIXME TODO : implement pluggable peripheral API
//if (mockingboard_inserted) {
extern VMFunc MB_Read;
base_c4rom = (void *)MB_Read;
base_c5rom = (void *)MB_Read;
#else
//} else {
base_c4rom = (void *)ram_nop;
base_c5rom = (void *)ram_nop;
#endif
//}
} else {
base_cxrom = apple_ii_64k[1];
base_c4rom = apple_ii_64k[1];