Audio: add a few settings to the option menu.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
0778812560
commit
5166731e5a
6 changed files with 113 additions and 4 deletions
|
@ -35,6 +35,9 @@ AudioGenerator & AudioGenerator::instance()
|
|||
AudioGenerator::AudioGenerator()
|
||||
{
|
||||
myDevice = nullptr;
|
||||
myInitialSilence = 200;
|
||||
mySilenceDelay = 10000;
|
||||
myPhysicalReference = 0x0fff;
|
||||
|
||||
QAudioFormat audioFormat;
|
||||
audioFormat.setSampleRate(44100);
|
||||
|
@ -53,6 +56,20 @@ QAudioOutput * AudioGenerator::getAudioOutput()
|
|||
return myAudioOutput.get();
|
||||
}
|
||||
|
||||
void AudioGenerator::getOptions(qint32 & initialSilence, qint32 & silenceDelay, qint32 & physical) const
|
||||
{
|
||||
initialSilence = myInitialSilence;
|
||||
silenceDelay = mySilenceDelay;
|
||||
physical = myPhysicalReference;
|
||||
}
|
||||
|
||||
void AudioGenerator::setOptions(const qint32 initialSilence, const qint32 silenceDelay, const qint32 physical)
|
||||
{
|
||||
myInitialSilence = std::max(0, initialSilence);
|
||||
mySilenceDelay = std::max(0, silenceDelay);
|
||||
myPhysicalReference = std::max(0, physical);
|
||||
}
|
||||
|
||||
void AudioGenerator::stateChanged(QAudio::State state)
|
||||
{
|
||||
qDebug(appleAudio) << "Changed state: state =" << state << ", error =" << myAudioOutput->error() << ", free =" << myAudioOutput->bytesFree() << "bytes";
|
||||
|
@ -111,10 +128,10 @@ void AudioGenerator::start()
|
|||
mySilence = 0;
|
||||
myMaximum = 0;
|
||||
myValue = 0;
|
||||
myPhysical = 0x0fff;
|
||||
myPhysical = myPhysicalReference;
|
||||
myTicks = std::queue<qint64>();
|
||||
|
||||
writeEnoughSilence(200); // ms
|
||||
writeEnoughSilence(myInitialSilence); // ms
|
||||
}
|
||||
|
||||
void AudioGenerator::writeEnoughSilence(const qint64 ms)
|
||||
|
@ -206,7 +223,7 @@ void AudioGenerator::generateSilence(audio_t * begin, audio_t * end)
|
|||
for (audio_t * ptr = begin; ptr != end; ++ptr)
|
||||
{
|
||||
++mySilence;
|
||||
if (myValue != 0 && mySilence > 10000)
|
||||
if (myValue != 0 && mySilence > mySilenceDelay)
|
||||
{
|
||||
myValue += delta;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ public:
|
|||
void writeAudio();
|
||||
void stateChanged(QAudio::State state);
|
||||
|
||||
void getOptions(qint32 & initialSilence, qint32 & silenceDelay, qint32 & physical) const;
|
||||
void setOptions(const qint32 initialSilence, const qint32 silenceDelay, const qint32 physical);
|
||||
|
||||
private:
|
||||
typedef short int audio_t;
|
||||
|
||||
|
@ -31,6 +34,11 @@ private:
|
|||
QIODevice * myDevice;
|
||||
std::vector<audio_t> myBuffer;
|
||||
|
||||
// options
|
||||
qint32 myInitialSilence;
|
||||
qint32 mySilenceDelay;
|
||||
qint16 myPhysicalReference;
|
||||
|
||||
qint64 myStartCPUCycles;
|
||||
qint64 myPreviousFrameTime;
|
||||
qint32 myMaximum;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "Registry.h"
|
||||
#include "SaveState.h"
|
||||
#include "CPU.h"
|
||||
#include "audio.h"
|
||||
|
||||
#include "linux/paddle.h"
|
||||
|
||||
|
@ -175,6 +176,8 @@ Preferences::Data getCurrentOptions(const std::shared_ptr<QGamepad> & gamepad)
|
|||
|
||||
currentOptions.screenshotTemplate = getScreenshotTemplate();
|
||||
|
||||
AudioGenerator::instance().getOptions(currentOptions.audioLatency, currentOptions.silenceDelay, currentOptions.physical);
|
||||
|
||||
return currentOptions;
|
||||
}
|
||||
|
||||
|
@ -261,4 +264,9 @@ void setNewOptions(const Preferences::Data & currentOptions, const Preferences::
|
|||
setScreenshotTemplate(newOptions.screenshotTemplate);
|
||||
}
|
||||
|
||||
if (currentOptions.audioLatency != newOptions.audioLatency)
|
||||
{
|
||||
AudioGenerator::instance().setOptions(newOptions.audioLatency, newOptions.silenceDelay, newOptions.physical);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -188,6 +188,10 @@ void Preferences::setData(const Data & data)
|
|||
|
||||
save_state->setText(data.saveState);
|
||||
screenshot->setText(data.screenshotTemplate);
|
||||
|
||||
audio_latency->setValue(data.audioLatency);
|
||||
silence_delay->setValue(data.silenceDelay);
|
||||
physical->setValue(data.physical);
|
||||
}
|
||||
|
||||
Preferences::Data Preferences::getData() const
|
||||
|
@ -220,6 +224,10 @@ Preferences::Data Preferences::getData() const
|
|||
data.saveState = save_state->text();
|
||||
data.screenshotTemplate = screenshot->text();
|
||||
|
||||
data.audioLatency = audio_latency->value();
|
||||
data.silenceDelay = silence_delay->value();
|
||||
data.physical = physical->value();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,10 @@ public:
|
|||
|
||||
bool enhancedSpeed;
|
||||
|
||||
int audioLatency;
|
||||
int silenceDelay;
|
||||
int physical;
|
||||
|
||||
std::vector<QString> disks;
|
||||
std::vector<QString> hds;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>648</width>
|
||||
<height>315</height>
|
||||
<height>316</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -385,6 +385,70 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="audio">
|
||||
<attribute name="title">
|
||||
<string>Audio</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_7">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="text">
|
||||
<string>Audio latency (ms)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="audio_latency">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Silence delay (frames)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="silence_delay">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>50000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_16">
|
||||
<property name="text">
|
||||
<string>Physical</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="physical">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="prefix">
|
||||
<string>0x</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>32767</number>
|
||||
</property>
|
||||
<property name="displayIntegerBase">
|
||||
<number>16</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="registry">
|
||||
<attribute name="title">
|
||||
<string>Registry</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue