Split audioapi to core interface and driver interface parts
This commit is contained in:
parent
e2589db8b7
commit
212d554ad1
9 changed files with 98 additions and 192 deletions
82
include/core/audioapi-driver.hpp
Normal file
82
include/core/audioapi-driver.hpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#ifndef _audioapi_driver__hpp__included__
|
||||
#define _audioapi_driver__hpp__included__
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
//All the following need to be implemented by the sound driver itself
|
||||
struct _audioapi_driver
|
||||
{
|
||||
//These correspond to various audioapi_driver_* functions.
|
||||
void (*init)() throw();
|
||||
void (*quit)() throw();
|
||||
void (*enable)(bool enable);
|
||||
bool (*initialized)();
|
||||
void (*set_device)(const std::string& pdev, const std::string& rdev);
|
||||
std::string (*get_device)(bool rec);
|
||||
std::map<std::string, std::string> (*get_devices)(bool rec);
|
||||
const char* (*name)();
|
||||
};
|
||||
|
||||
struct audioapi_driver
|
||||
{
|
||||
audioapi_driver(struct _audioapi_driver driver);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the driver.
|
||||
*/
|
||||
void audioapi_driver_init() throw();
|
||||
|
||||
/**
|
||||
* Deinitialize the driver.
|
||||
*/
|
||||
void audioapi_driver_quit() throw();
|
||||
|
||||
/**
|
||||
* Enable or disable sound.
|
||||
*
|
||||
* parameter enable: Enable sounds if true, otherwise disable sounds.
|
||||
*/
|
||||
void audioapi_driver_enable(bool enable) throw();
|
||||
|
||||
/**
|
||||
* Has the sound system been successfully initialized?
|
||||
*
|
||||
* Returns: True if sound system has successfully initialized, false otherwise.
|
||||
*/
|
||||
bool audioapi_driver_initialized();
|
||||
|
||||
/**
|
||||
* Set sound device (playback).
|
||||
*
|
||||
* - If new sound device is invalid, the sound device is not changed.
|
||||
*
|
||||
* Parameter pdev: The new sound device (playback).
|
||||
* Parameter rdev: The new sound device (recording)
|
||||
*/
|
||||
void audioapi_driver_set_device(const std::string& pdev, const std::string& rdev) throw(std::bad_alloc,
|
||||
std::runtime_error);
|
||||
|
||||
/**
|
||||
* Get current sound device (playback).
|
||||
*
|
||||
* Returns: The current sound device.
|
||||
*/
|
||||
std::string audioapi_driver_get_device(bool rec) throw(std::bad_alloc);
|
||||
|
||||
/**
|
||||
* Get available sound devices (playback).
|
||||
*
|
||||
* Returns: The map of devices. Keyed by name of the device, values are human-readable names for devices.
|
||||
*/
|
||||
std::map<std::string, std::string> audioapi_driver_get_devices(bool rec) throw(std::bad_alloc);
|
||||
|
||||
/**
|
||||
* Identification for sound plugin.
|
||||
*/
|
||||
const char* audioapi_driver_name() throw();
|
||||
|
||||
#endif
|
|
@ -232,6 +232,10 @@ public:
|
|||
* Note: Setting rate to 0 enables dummy callbacks.
|
||||
*/
|
||||
void voice_rate(unsigned rate_r, unsigned rate_p);
|
||||
/**
|
||||
* Suppress all future VU updates.
|
||||
*/
|
||||
static void disable_vu_updates();
|
||||
//Vu values.
|
||||
vumeter vu_mleft;
|
||||
vumeter vu_mright;
|
||||
|
@ -275,87 +279,8 @@ private:
|
|||
volatile float _voicer_volume;
|
||||
resampler music_resampler;
|
||||
bool last_adjust; //Adjusting consequtively is too hard.
|
||||
static bool vu_disabled;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//All the following need to be implemented by the sound driver itself
|
||||
struct _audioapi_driver
|
||||
{
|
||||
//These correspond to various audioapi_driver_* functions.
|
||||
void (*init)() throw();
|
||||
void (*quit)() throw();
|
||||
void (*enable)(bool enable);
|
||||
bool (*initialized)();
|
||||
void (*set_device)(const std::string& pdev, const std::string& rdev);
|
||||
std::string (*get_device)(bool rec);
|
||||
std::map<std::string, std::string> (*get_devices)(bool rec);
|
||||
const char* (*name)();
|
||||
};
|
||||
|
||||
struct audioapi_driver
|
||||
{
|
||||
audioapi_driver(struct _audioapi_driver driver);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the driver.
|
||||
*/
|
||||
void audioapi_driver_init() throw();
|
||||
|
||||
/**
|
||||
* Deinitialize the driver.
|
||||
*/
|
||||
void audioapi_driver_quit() throw();
|
||||
|
||||
/**
|
||||
* Panic notification.
|
||||
*/
|
||||
void audioapi_panicing() throw();
|
||||
|
||||
/**
|
||||
* Enable or disable sound.
|
||||
*
|
||||
* parameter enable: Enable sounds if true, otherwise disable sounds.
|
||||
*/
|
||||
void audioapi_driver_enable(bool enable) throw();
|
||||
|
||||
/**
|
||||
* Has the sound system been successfully initialized?
|
||||
*
|
||||
* Returns: True if sound system has successfully initialized, false otherwise.
|
||||
*/
|
||||
bool audioapi_driver_initialized();
|
||||
|
||||
/**
|
||||
* Set sound device (playback).
|
||||
*
|
||||
* - If new sound device is invalid, the sound device is not changed.
|
||||
*
|
||||
* Parameter pdev: The new sound device (playback).
|
||||
* Parameter rdev: The new sound device (recording)
|
||||
*/
|
||||
void audioapi_driver_set_device(const std::string& pdev, const std::string& rdev) throw(std::bad_alloc,
|
||||
std::runtime_error);
|
||||
|
||||
/**
|
||||
* Get current sound device (playback).
|
||||
*
|
||||
* Returns: The current sound device.
|
||||
*/
|
||||
std::string audioapi_driver_get_device(bool rec) throw(std::bad_alloc);
|
||||
|
||||
/**
|
||||
* Get available sound devices (playback).
|
||||
*
|
||||
* Returns: The map of devices. Keyed by name of the device, values are human-readable names for devices.
|
||||
*/
|
||||
std::map<std::string, std::string> audioapi_driver_get_devices(bool rec) throw(std::bad_alloc);
|
||||
|
||||
/**
|
||||
* Identification for sound plugin.
|
||||
*/
|
||||
const char* audioapi_driver_name() throw();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#define MUSIC_BUFFERS 8
|
||||
#define MAX_VOICE_ADJUST 200
|
||||
|
||||
bool audioapi_instance::vu_disabled = false;
|
||||
|
||||
audioapi_instance::dummy_cb_proc::dummy_cb_proc(audioapi_instance& _parent)
|
||||
: parent(_parent)
|
||||
{
|
||||
|
@ -42,8 +44,6 @@ int audioapi_instance::dummy_cb_proc::operator()()
|
|||
|
||||
namespace
|
||||
{
|
||||
bool paniced = false;
|
||||
|
||||
// | -1 1 -1 1 | 1 0 0 0 |
|
||||
// | 0 0 0 1 | 0 1 0 0 |
|
||||
// | 1 1 1 1 | 0 0 1 0 |
|
||||
|
@ -499,7 +499,7 @@ void audioapi_instance::vumeter::operator()(float* asamples, size_t count, bool
|
|||
|
||||
void audioapi_instance::vumeter::update_vu()
|
||||
{
|
||||
if(paniced)
|
||||
if(vu_disabled)
|
||||
return;
|
||||
if(!samples) {
|
||||
vu = -999.0;
|
||||
|
@ -517,7 +517,7 @@ void audioapi_instance::vumeter::update_vu()
|
|||
CORE().dispatch->vu_change();
|
||||
}
|
||||
|
||||
void audioapi_panicing() throw()
|
||||
void audioapi_instance::disable_vu_updates()
|
||||
{
|
||||
paniced = true;
|
||||
vu_disabled = true;
|
||||
}
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
#include "core/audioapi.hpp"
|
||||
#include "core/instance.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
void dummy_init() throw()
|
||||
{
|
||||
lsnes_instance.audio->voice_rate(0, 0);
|
||||
}
|
||||
|
||||
void dummy_quit() throw()
|
||||
{
|
||||
}
|
||||
|
||||
void dummy_enable(bool enable) throw()
|
||||
{
|
||||
}
|
||||
|
||||
bool dummy_initialized()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void dummy_set_device(const std::string& pdev, const std::string& rdev) throw(std::bad_alloc,
|
||||
std::runtime_error)
|
||||
{
|
||||
if(pdev != "null")
|
||||
throw std::runtime_error("Bad sound device '" + pdev + "'");
|
||||
if(rdev != "null")
|
||||
throw std::runtime_error("Bad sound device '" + rdev + "'");
|
||||
}
|
||||
|
||||
std::string dummy_get_device(bool rec) throw(std::bad_alloc)
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> dummy_get_devices(bool rec) throw(std::bad_alloc)
|
||||
{
|
||||
std::map<std::string, std::string> ret;
|
||||
ret["null"] = "NULL sound output";
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* dummy_name() { return "Dummy sound plugin"; }
|
||||
|
||||
_audioapi_driver driver = {
|
||||
.init = dummy_init,
|
||||
.quit = dummy_quit,
|
||||
.enable = dummy_enable,
|
||||
.initialized = dummy_initialized,
|
||||
.set_device = dummy_set_device,
|
||||
.get_device = dummy_get_device,
|
||||
.get_devices = dummy_get_devices,
|
||||
.name = dummy_name
|
||||
};
|
||||
}
|
||||
|
||||
audioapi_driver::audioapi_driver(struct _audioapi_driver _driver)
|
||||
{
|
||||
driver = _driver;
|
||||
}
|
||||
|
||||
void audioapi_driver_init() throw()
|
||||
{
|
||||
driver.init();
|
||||
}
|
||||
|
||||
void audioapi_driver_quit() throw()
|
||||
{
|
||||
driver.quit();
|
||||
}
|
||||
|
||||
void audioapi_driver_enable(bool _enable) throw()
|
||||
{
|
||||
driver.enable(_enable);
|
||||
}
|
||||
|
||||
bool audioapi_driver_initialized()
|
||||
{
|
||||
return driver.initialized();
|
||||
}
|
||||
|
||||
void audioapi_driver_set_device(const std::string& pdev, const std::string& rdev) throw(std::bad_alloc,
|
||||
std::runtime_error)
|
||||
{
|
||||
driver.set_device(pdev, rdev);
|
||||
}
|
||||
|
||||
std::string audioapi_driver_get_device(bool rec) throw(std::bad_alloc)
|
||||
{
|
||||
return driver.get_device(rec);
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> audioapi_driver_get_devices(bool rec) throw(std::bad_alloc)
|
||||
{
|
||||
return driver.get_devices(rec);
|
||||
}
|
||||
|
||||
const char* audioapi_driver_name() throw()
|
||||
{
|
||||
return driver.name();
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#include "core/audioapi.hpp"
|
||||
#include "core/audioapi-driver.hpp"
|
||||
#include "core/command.hpp"
|
||||
#include "core/dispatch.hpp"
|
||||
#include "core/framerate.hpp"
|
||||
|
@ -338,7 +339,7 @@ void platform::fatal_error() throw()
|
|||
system_log << "-----------------------------------------------------------------------" << std::endl;
|
||||
system_log.close();
|
||||
graphics_driver_fatal_error();
|
||||
audioapi_panicing(); //Don't call update VU, as that crashes.
|
||||
audioapi_instance::disable_vu_updates(); //Don't call update VU, as that crashes.
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "lsnes.hpp"
|
||||
|
||||
#include "core/audioapi-driver.hpp"
|
||||
#include "core/command.hpp"
|
||||
#include "core/dispatch.hpp"
|
||||
#include "core/framerate.hpp"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "lsnes.hpp"
|
||||
|
||||
#include "core/audioapi-driver.hpp"
|
||||
#include "core/command.hpp"
|
||||
#include "core/dispatch.hpp"
|
||||
#include "core/framerate.hpp"
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "platform/wxwidgets/menu_projects.hpp"
|
||||
|
||||
#include "core/audioapi.hpp"
|
||||
#include "core/audioapi-driver.hpp"
|
||||
#include "core/command.hpp"
|
||||
#include "core/controller.hpp"
|
||||
#include "core/controllerframe.hpp"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "core/audioapi.hpp"
|
||||
#include "core/audioapi-driver.hpp"
|
||||
#include "core/dispatch.hpp"
|
||||
#include "core/instance.hpp"
|
||||
#include "core/window.hpp"
|
||||
|
|
Loading…
Add table
Reference in a new issue