Move audio implementation into interface.cpp

Move all libao operation into interface.cpp
This should have the result of removing all AV and GUI code from apple2e.cpp
OS code remaining in apple2e.cpp should basically be only file I/O, console I/O, and chrono.
This commit is contained in:
Brad Grantham 2016-12-26 22:28:45 -08:00
parent bf7961855f
commit cb60985ef0
3 changed files with 42 additions and 49 deletions

View File

@ -11,7 +11,6 @@
#include <map>
#include <thread>
#include <signal.h>
#include <ao/ao.h>
#include "fake6502.h"
@ -2604,31 +2603,6 @@ enum APPLE2Einterface::EventType process_events(MAINboard *board, bus_frontend&
return APPLE2Einterface::NONE;
}
ao_device *open_ao()
{
ao_device *device;
ao_sample_format format;
int default_driver;
ao_initialize();
default_driver = ao_default_driver_id();
memset(&format, 0, sizeof(format));
format.bits = 8;
format.channels = 1;
format.rate = 44100;
format.byte_format = AO_FMT_LITTLE;
/* -- Open driver -- */
device = ao_open_live(default_driver, &format, NULL /* no options */);
if (device == NULL) {
fprintf(stderr, "Error opening libao audio device.\n");
return nullptr;
}
return device;
}
int main(int argc, char **argv)
{
@ -2637,8 +2611,6 @@ int main(int argc, char **argv)
argv += 1;
char *diskII_rom_name = NULL, *floppy1_name = NULL, *floppy2_name = NULL;
bool have_audio = true;
while((argc > 0) && (argv[0][0] == '-')) {
if(strcmp(argv[0], "-debugger") == 0) {
debugging = true;
@ -2654,10 +2626,6 @@ int main(int argc, char **argv)
floppy2_name = argv[3];
argv += 4;
argc -= 4;
} else if(strcmp(argv[0], "-noaudio") == 0) {
have_audio = false;
argv += 1;
argc -= 1;
} else if(strcmp(argv[0], "-fast") == 0) {
run_fast = true;
argv += 1;
@ -2703,27 +2671,14 @@ int main(int argc, char **argv)
system_clock clk;
ao_device *aodev = open_ao();
if(aodev == NULL)
exit(EXIT_FAILURE);
MAINboard* mainboard;
MAINboard::display_write_func display = [](int addr, bool aux, unsigned char data)->bool{return APPLE2Einterface::write(addr, aux, data);};
MAINboard::audio_flush_func audio;
MAINboard::get_paddle_func paddle = [](int num)->tuple<float, bool>{return APPLE2Einterface::get_paddle(num);};
if(have_audio)
audio = [aodev](char *buf, size_t sz){
// static char prev_sample;
// for(int i = 0; i < sz; i++)
// if(buf[i] != prev_sample) {
if(!run_fast) ao_play(aodev, buf, sz);
// break;
// }
// prev_sample = buf[sz - 1];
};
else
audio = [](char *buf, size_t sz){};
MAINboard::audio_flush_func audio = [](char *buf, size_t sz){ if(!run_fast) APPLE2Einterface::enqueue_audio_samples(buf, sz); };
mainboard = new MAINboard(clk, b, display, audio, paddle);
bus.board = mainboard;
bus.reset();

View File

@ -7,6 +7,7 @@
#include <chrono>
#include <iostream>
#include <map>
#include <ao/ao.h>
// implicit centering in widget? Or special centering widget?
// lines (for around toggle and momentary)
@ -27,6 +28,7 @@ namespace APPLE2Einterface
chrono::time_point<chrono::system_clock> start_time;
static GLFWwindow* my_window;
ao_device *aodev;
DisplayMode display_mode = TEXT;
int display_page = 0; // Apple //e page minus 1 (so 0,1 not 1,2)
@ -1742,8 +1744,42 @@ void drop_callback(GLFWwindow* window, int count, const char** paths)
ui->drop(elapsed.count(), wx, wy, count, paths);
}
void enqueue_audio_samples(char *buf, size_t sz)
{
ao_play(aodev, buf, sz);
}
ao_device *open_ao()
{
ao_device *device;
ao_sample_format format;
int default_driver;
ao_initialize();
default_driver = ao_default_driver_id();
memset(&format, 0, sizeof(format));
format.bits = 8;
format.channels = 1;
format.rate = 44100;
format.byte_format = AO_FMT_LITTLE;
/* -- Open driver -- */
device = ao_open_live(default_driver, &format, NULL /* no options */);
if (device == NULL) {
fprintf(stderr, "Error opening libao audio device.\n");
return nullptr;
}
return device;
}
void start(bool run_fast, bool add_floppies, bool floppy0_inserted, bool floppy1_inserted)
{
aodev = open_ao();
if(aodev == NULL)
exit(EXIT_FAILURE);
load_joystick_setup();
glfwSetErrorCallback(error_callback);

View File

@ -54,4 +54,6 @@ std::tuple<float,bool> get_paddle(int num);
void show_floppy_activity(int number, bool activity);
void enqueue_audio_samples(char *buf, size_t sz);
};