2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2011-08-20 14:40:44 +00:00
|
|
|
#include <math.h>
|
2013-03-19 08:48:50 +00:00
|
|
|
#include <vector>
|
2011-08-14 10:34:11 +00:00
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
struct DSP;
|
|
|
|
|
|
|
|
struct Resampler {
|
2013-05-02 11:25:45 +00:00
|
|
|
Resampler(DSP& dsp) : dsp(dsp) {}
|
Update to v094r08 release.
byuu says:
Lots of changes this time around. FreeBSD stability and compilation is
still a work in progress.
FreeBSD 10 + Clang 3.3 = 108fps
FreeBSD 10 + GCC 4.7 = 130fps
Errata 1: I've been fighting that god-damned endian.h header for the
past nine WIPs now. The above WIP isn't building now because FreeBSD
isn't including headers before using certain types, and you end up with
a trillion error messages. So just delete all the endian.h includes from
nall/intrinsics.hpp to build.
Errata 2: I was trying to match g++ and g++47, so I used $(findstring
g++,$(compiler)), which ends up also matching clang++. Oops. Easy fix,
put Clang first and then else if g++ next. Not ideal, but oh well. All
it's doing for now is declaring -fwrapv twice, so you don't have to fix
it just yet. Probably just going to alias g++="g++47" and do exact
matching instead.
Errata 3: both OpenGL::term and VideoGLX::term are causing a core dump
on BSD. No idea why. The resources are initialized and valid, but
releasing them crashes the application.
Changelog:
- nall/Makefile is more flexible with overriding $(compiler), so you can
build with GCC or Clang on BSD (defaults to GCC now)
- PLATFORM_X was renamed to PLATFORM_XORG, and it's also declared with
PLATFORM_LINUX or PLATFORM_BSD
- PLATFORM_XORG probably isn't the best name ... still thinking about
what best to call LINUX|BSD|SOLARIS or ^(WINDOWS|MACOSX)
- fixed a few legitimate Clang warning messages in nall
- Compiler::VisualCPP is ugly as hell, renamed to Compiler::CL
- nall/platform includes nall/intrinsics first. Trying to move away from
testing for _WIN32, etc directly in all files. Work in progress.
- nall turns off Clang warnings that I won't "fix", because they aren't
broken. It's much less noisy to compile with warnings on now.
- phoenix gains the ability to set background and foreground colors on
various text container widgets (GTK only for now.)
- rewrote a lot of the MSU1 code to try and simplify it. Really hope
I didn't break anything ... I don't have any MSU1 test ROMs handy
- SNES coprocessor audio is now mixed as sclamp<16>(system_sample
+ coprocessor_sample) instead of sclamp<16>((sys + cop) / 2)
- allows for greater chance of aliasing (still low, SNES audio is
quiet), but doesn't cut base system volume in half anymore
- fixed Super Scope and Justifier cursor colors
- use input.xlib instead of input.x ... allows Xlib input driver to be
visible on Linux and BSD once again
- make install and make uninstall must be run as root again; no longer
using install but cp instead for BSD compatibility
- killed $(DESTDIR) ... use make prefix=$DESTDIR$prefix instead
- you can now set text/background colors for the loki console via (eg):
- settings.terminal.background-color 0x000000
- settings.terminal.foreground-color 0xffffff
2014-02-24 09:39:09 +00:00
|
|
|
virtual ~Resampler() {}
|
2015-11-21 07:36:48 +00:00
|
|
|
|
|
|
|
virtual auto setFrequency() -> void = 0;
|
|
|
|
virtual auto clear() -> void = 0;
|
|
|
|
virtual auto sample() -> void = 0;
|
|
|
|
|
|
|
|
DSP& dsp;
|
|
|
|
double frequency = 44100.0;
|
2011-09-23 11:13:57 +00:00
|
|
|
};
|
|
|
|
|
2011-08-20 14:40:44 +00:00
|
|
|
struct DSP {
|
2015-11-21 07:36:48 +00:00
|
|
|
enum class ResampleEngine : uint {
|
2011-09-23 11:13:57 +00:00
|
|
|
Nearest,
|
2011-08-20 14:40:44 +00:00
|
|
|
Linear,
|
|
|
|
Cosine,
|
|
|
|
Cubic,
|
|
|
|
Hermite,
|
|
|
|
Average,
|
2011-09-24 09:51:08 +00:00
|
|
|
Sinc,
|
2011-08-20 14:40:44 +00:00
|
|
|
};
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
inline DSP();
|
|
|
|
inline ~DSP();
|
2011-08-20 14:40:44 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
inline auto setChannels(uint channels) -> void;
|
|
|
|
inline auto setPrecision(uint precision) -> void;
|
|
|
|
inline auto setFrequency(double frequency) -> void; //inputFrequency
|
|
|
|
inline auto setVolume(double volume) -> void;
|
|
|
|
inline auto setBalance(double balance) -> void;
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
inline auto setResampler(ResampleEngine resamplingEngine) -> void;
|
|
|
|
inline auto setResamplerFrequency(double frequency) -> void; //outputFrequency
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
inline auto sample(int channel[]) -> void;
|
|
|
|
inline auto pending() const -> bool;
|
|
|
|
inline auto read(int channel[]) -> void;
|
|
|
|
|
|
|
|
inline auto clear() -> void;
|
2011-08-14 10:34:11 +00:00
|
|
|
|
|
|
|
protected:
|
2015-11-21 07:36:48 +00:00
|
|
|
inline auto write(double channel[]) -> void;
|
|
|
|
inline auto adjustVolume() -> void;
|
|
|
|
inline auto adjustBalance() -> void;
|
|
|
|
inline auto clamp(const uint bits, const int input) -> int;
|
2011-09-23 11:13:57 +00:00
|
|
|
|
2011-08-14 10:34:11 +00:00
|
|
|
struct Settings {
|
2015-11-21 07:36:48 +00:00
|
|
|
uint channels;
|
|
|
|
uint precision;
|
|
|
|
double frequency;
|
|
|
|
double volume;
|
|
|
|
double balance;
|
2011-08-14 10:34:11 +00:00
|
|
|
|
|
|
|
//internal
|
2015-11-21 07:36:48 +00:00
|
|
|
double intensity;
|
|
|
|
double intensityInverse;
|
2011-09-23 11:13:57 +00:00
|
|
|
} settings;
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
Resampler* resampler = nullptr;
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2011-08-20 14:40:44 +00:00
|
|
|
#include "buffer.hpp"
|
|
|
|
Buffer buffer;
|
|
|
|
Buffer output;
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
friend class ResampleNearest;
|
|
|
|
friend class ResampleLinear;
|
|
|
|
friend class ResampleCosine;
|
|
|
|
friend class ResampleCubic;
|
|
|
|
friend class ResampleAverage;
|
|
|
|
friend class ResampleHermite;
|
|
|
|
friend class ResampleSinc;
|
2011-08-20 14:40:44 +00:00
|
|
|
};
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2011-09-23 11:13:57 +00:00
|
|
|
#include "resample/nearest.hpp"
|
|
|
|
#include "resample/linear.hpp"
|
|
|
|
#include "resample/cosine.hpp"
|
|
|
|
#include "resample/cubic.hpp"
|
|
|
|
#include "resample/hermite.hpp"
|
|
|
|
#include "resample/average.hpp"
|
2011-09-24 09:51:08 +00:00
|
|
|
#include "resample/sinc.hpp"
|
2011-08-20 14:40:44 +00:00
|
|
|
#include "settings.hpp"
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
DSP::DSP() {
|
|
|
|
setResampler(ResampleEngine::Hermite);
|
|
|
|
setResamplerFrequency(44100.0);
|
|
|
|
|
|
|
|
setChannels(2);
|
|
|
|
setPrecision(16);
|
|
|
|
setFrequency(44100.0);
|
|
|
|
setVolume(1.0);
|
|
|
|
setBalance(0.0);
|
|
|
|
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSP::~DSP() {
|
|
|
|
if(resampler) delete resampler;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto DSP::sample(int channel[]) -> void {
|
|
|
|
for(auto c : range(settings.channels)) {
|
|
|
|
buffer.write(c) = (double)channel[c] * settings.intensityInverse;
|
2011-09-16 11:44:07 +00:00
|
|
|
}
|
2011-08-14 10:34:11 +00:00
|
|
|
buffer.wroffset++;
|
2011-09-23 11:13:57 +00:00
|
|
|
resampler->sample();
|
2011-08-14 10:34:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto DSP::pending() const -> bool {
|
2011-08-14 10:34:11 +00:00
|
|
|
return output.rdoffset != output.wroffset;
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto DSP::read(int channel[]) -> void {
|
2011-08-20 14:40:44 +00:00
|
|
|
adjustVolume();
|
|
|
|
adjustBalance();
|
2011-08-14 10:34:11 +00:00
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
for(auto c : range(settings.channels)) {
|
Update to v082r16 release.
byuu says:
Binary output is once again called bsnes. No versioning on the title
without a system cartridge loaded. Still saving config files to
.config/batch for now.
Finally fixed NES APU frame IRQ clearing on $4015 reads.
Added mouse button/axis binding through buttons on the input capture
window.
Added advanced settings window with driver selection and focus policy
settings. Will show your default driver properly if none are selected
now, unlike old bsnes.
That exposed a small bug where phoenix isn't removing widgets on
Layout::remove, worked around it for now by hiding the panels. Damn,
sick of working on phoenix.
Added all missing input controllers, which can all now be mapped, and
bound them to the main menu, and added NES support for selecting "no
connected controller."
Added mouse capture and the requisite tools menu option for it.
Added WindowManager class that keeps track of both position and size now
(eg full geometry), so now you can resize your windows and save the
settings, unlike old bsnes.
WindowManager has more stringent geometry checks. The *client area* (not
the window border) can't be below 0,0 or above the width/height of three
30" monitors. If you have 4+ 30" monitors, then fuck you :P
settings.cfg is now also saved, captures all currently available
settings. Right now, there's only one path for the file browser to
remember. I will probably make this per-system later.
FileBrowser has been made a bit more friendly. The bottom left tells you
what type of files the list is filtered by (so you see "*.sfc" for
SNES), and the bottom right has an open button that can enter folders or
load files.
Added video shader support.
Fixed nall/dsp variadic-channel support, was only outputting the left
channel.
2011-09-19 12:25:56 +00:00
|
|
|
channel[c] = clamp(settings.precision, output.read(c) * settings.intensity);
|
2011-09-16 11:44:07 +00:00
|
|
|
}
|
2011-08-14 10:34:11 +00:00
|
|
|
output.rdoffset++;
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto DSP::write(double channel[]) -> void {
|
|
|
|
for(auto c : range(settings.channels)) {
|
2011-09-16 11:44:07 +00:00
|
|
|
output.write(c) = channel[c];
|
|
|
|
}
|
2011-08-20 14:40:44 +00:00
|
|
|
output.wroffset++;
|
2011-08-14 10:34:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto DSP::adjustVolume() -> void {
|
|
|
|
for(auto c : range(settings.channels)) {
|
2011-09-16 11:44:07 +00:00
|
|
|
output.read(c) *= settings.volume;
|
|
|
|
}
|
2011-08-14 10:34:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto DSP::adjustBalance() -> void {
|
2011-09-16 11:44:07 +00:00
|
|
|
if(settings.channels != 2) return; //TODO: support > 2 channels
|
2011-08-20 14:40:44 +00:00
|
|
|
if(settings.balance < 0.0) output.read(1) *= 1.0 + settings.balance;
|
|
|
|
if(settings.balance > 0.0) output.read(0) *= 1.0 - settings.balance;
|
2011-08-14 10:34:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto DSP::clamp(const uint bits, const int x) -> int {
|
|
|
|
const int b = 1U << (bits - 1);
|
|
|
|
const int m = (1U << (bits - 1)) - 1;
|
2011-08-14 10:34:11 +00:00
|
|
|
return (x > m) ? m : (x < -b) ? -b : x;
|
|
|
|
}
|
|
|
|
|
2015-11-21 07:36:48 +00:00
|
|
|
auto DSP::clear() -> void {
|
2011-08-20 14:40:44 +00:00
|
|
|
buffer.clear();
|
|
|
|
output.clear();
|
2011-09-23 11:13:57 +00:00
|
|
|
resampler->clear();
|
2011-08-14 10:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|