From b0f94afaf2557b6b318c4db26c2900d361b83752 Mon Sep 17 00:00:00 2001 From: Tjienta Vara Date: Fri, 19 Jan 2018 22:57:36 +0100 Subject: [PATCH] libobs, UI: Add true peak measurements Add a new algorithm to calculate the true-peak. It implements the Whittaker- Shannon interpolation from four samples to create 4 intermediate samples (5 x oversampling) inbetween the middle two samples. With 4 samples and 4 intermediate samples the algorithm can be implemented as a 4x4 vector-matrix cross product, which is ideal for SSE. I've also replaced the sample-peak algorithm using SSE as well to improve performance. Closes obsproject/obs-studio#1189 --- UI/data/locale/en-US.ini | 3 + UI/forms/OBSBasicSettings.ui | 36 ++++- UI/volume-control.cpp | 38 +++++ UI/volume-control.hpp | 2 + UI/window-basic-main.cpp | 43 +++++ UI/window-basic-main.hpp | 1 + UI/window-basic-settings.cpp | 13 ++ libobs/obs-audio-controls.c | 297 ++++++++++++++++++++++++++++++----- libobs/obs-audio-controls.h | 29 ++++ 9 files changed, 417 insertions(+), 45 deletions(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 89bd0b1c..2f3c3193 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -707,6 +707,9 @@ Basic.Settings.Audio.MeterDecayRate="Audio Meter Decay Rate" Basic.Settings.Audio.MeterDecayRate.Fast="Fast" Basic.Settings.Audio.MeterDecayRate.Medium="Medium (Type I PPM)" Basic.Settings.Audio.MeterDecayRate.Slow="Slow (Type II PPM)" +Basic.Settings.Audio.PeakMeterType="Peak Meter Type" +Basic.Settings.Audio.PeakMeterType.SamplePeak="Sample Peak" +Basic.Settings.Audio.PeakMeterType.TruePeak="True Peak (Higher CPU usage)" Basic.Settings.Audio.MultiChannelWarning.Enabled="WARNING: Surround sound audio is enabled." Basic.Settings.Audio.MultichannelWarning="If streaming, check to see if your streaming service supports both surround sound ingest and surround sound playback. Twitch, Facebook 360 Live, Mixer RTMP, Smashcast are examples where surround sound is fully supported. Although Facebook Live and YouTube Live both accept surround ingest, Facebook Live downmixes to stereo, and YouTube Live plays only two channels.\n\nOBS audio filters are compatible with surround sound, though VST plugin support isn't guaranteed." Basic.Settings.Audio.MultichannelWarning.Title="Enable surround sound audio?" diff --git a/UI/forms/OBSBasicSettings.ui b/UI/forms/OBSBasicSettings.ui index c89cc1e6..adb8a1f5 100644 --- a/UI/forms/OBSBasicSettings.ui +++ b/UI/forms/OBSBasicSettings.ui @@ -3362,7 +3362,7 @@ - + true @@ -3379,7 +3379,7 @@ - + color: rgb(255, 0, 4); @@ -3392,7 +3392,7 @@ - + @@ -3440,6 +3440,30 @@ + + + + 0 + + + + Basic.Settings.Audio.PeakMeterType.SamplePeak + + + + + Basic.Settings.Audio.PeakMeterType.TruePeak + + + + + + + + Basic.Settings.Audio.PeakMeterType + + + @@ -3744,8 +3768,8 @@ 0 0 - 98 - 28 + 818 + 697 @@ -3791,7 +3815,7 @@ 0 0 - 593 + 803 761 diff --git a/UI/volume-control.cpp b/UI/volume-control.cpp index 32d8185f..88b812a8 100644 --- a/UI/volume-control.cpp +++ b/UI/volume-control.cpp @@ -114,6 +114,11 @@ void VolControl::SetMeterDecayRate(qreal q) volMeter->setPeakDecayRate(q); } +void VolControl::setPeakMeterType(enum obs_peak_meter_type peakMeterType) +{ + volMeter->setPeakMeterType(peakMeterType); +} + VolControl::VolControl(OBSSource source_, bool showConfig) : source (source_), levelTotal (0.0f), @@ -413,6 +418,39 @@ void VolumeMeter::setInputPeakHoldDuration(qreal v) inputPeakHoldDuration = v; } +void VolumeMeter::setPeakMeterType(enum obs_peak_meter_type peakMeterType) +{ + obs_volmeter_set_peak_meter_type(obs_volmeter, peakMeterType); + switch (peakMeterType) { + case TRUE_PEAK_METER: + // For true-peak meters EBU has defined the Permitted Maximum, + // taking into account the accuracy of the meter and further + // processing required by lossy audio compression. + // + // The alignment level was not specified, but I've adjusted + // it compared to a sample-peak meter. Incidently Youtube + // uses this new Alignment Level as the maximum integrated + // loudness of a video. + // + // * Permitted Maximum Level (PML) = -2.0 dBTP + // * Alignment Level (AL) = -13 dBTP + setErrorLevel(-2.0); + setWarningLevel(-13.0); + break; + + case SAMPLE_PEAK_METER: + default: + // For a sample Peak Meter EBU has the following level + // definitions, taking into account inaccuracies of this meter: + // + // * Permitted Maximum Level (PML) = -9.0 dBFS + // * Alignment Level (AL) = -20.0 dBFS + setErrorLevel(-9.0); + setWarningLevel(-20.0); + break; + } +} + VolumeMeter::VolumeMeter(QWidget *parent, obs_volmeter_t *obs_volmeter) : QWidget(parent), obs_volmeter(obs_volmeter) { diff --git a/UI/volume-control.hpp b/UI/volume-control.hpp index 4e1db9ea..256199d8 100644 --- a/UI/volume-control.hpp +++ b/UI/volume-control.hpp @@ -190,6 +190,7 @@ public: void setPeakHoldDuration(qreal v); qreal getInputPeakHoldDuration() const; void setInputPeakHoldDuration(qreal v); + void setPeakMeterType(enum obs_peak_meter_type peakMeterType); protected: void paintEvent(QPaintEvent *event); @@ -259,4 +260,5 @@ public: void SetName(const QString &newName); void SetMeterDecayRate(qreal q); + void setPeakMeterType(enum obs_peak_meter_type peakMeterType); }; diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 99cfc9b6..12dc384a 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -388,6 +388,29 @@ void OBSBasic::UpdateVolumeControlsDecayRate() } } +void OBSBasic::UpdateVolumeControlsPeakMeterType() +{ + uint32_t peakMeterTypeIdx = config_get_uint(basicConfig, "Audio", + "PeakMeterType"); + + enum obs_peak_meter_type peakMeterType; + switch (peakMeterTypeIdx) { + case 0: + peakMeterType = SAMPLE_PEAK_METER; + break; + case 1: + peakMeterType = TRUE_PEAK_METER; + break; + default: + peakMeterType = SAMPLE_PEAK_METER; + break; + } + + for (size_t i = 0; i < volumes.size(); i++) { + volumes[i]->setPeakMeterType(peakMeterType); + } +} + void OBSBasic::ClearVolumeControls() { VolControl *control; @@ -1153,6 +1176,7 @@ bool OBSBasic::InitBasicConfigDefaults() "Stereo"); config_set_default_double(basicConfig, "Audio", "MeterDecayRate", VOLUME_METER_DECAY_FAST); + config_set_default_uint (basicConfig, "Audio", "PeakMeterType", 0); return true; } @@ -2507,6 +2531,25 @@ void OBSBasic::ActivateAudioSource(OBSSource source) double meterDecayRate = config_get_double(basicConfig, "Audio", "MeterDecayRate"); vol->SetMeterDecayRate(meterDecayRate); + + uint32_t peakMeterTypeIdx = config_get_uint(basicConfig, "Audio", + "PeakMeterType"); + + enum obs_peak_meter_type peakMeterType; + switch (peakMeterTypeIdx) { + case 0: + peakMeterType = SAMPLE_PEAK_METER; + break; + case 1: + peakMeterType = TRUE_PEAK_METER; + break; + default: + peakMeterType = SAMPLE_PEAK_METER; + break; + } + + vol->setPeakMeterType(peakMeterType); + vol->setContextMenuPolicy(Qt::CustomContextMenu); connect(vol, &QWidget::customContextMenuRequested, diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 8b7a405f..9b43afc9 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -195,6 +195,7 @@ private: void CreateDefaultScene(bool firstStart); void UpdateVolumeControlsDecayRate(); + void UpdateVolumeControlsPeakMeterType(); void ClearVolumeControls(); void UploadLog(const char *subdir, const char *file); diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index d1d8f48d..7d06e70e 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -401,6 +401,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) HookWidget(ui->channelSetup, COMBO_CHANGED, AUDIO_RESTART); HookWidget(ui->sampleRate, COMBO_CHANGED, AUDIO_RESTART); HookWidget(ui->meterDecayRate, COMBO_CHANGED, AUDIO_CHANGED); + HookWidget(ui->peakMeterType, COMBO_CHANGED, AUDIO_CHANGED); HookWidget(ui->desktopAudioDevice1, COMBO_CHANGED, AUDIO_CHANGED); HookWidget(ui->desktopAudioDevice2, COMBO_CHANGED, AUDIO_CHANGED); HookWidget(ui->auxAudioDevice1, COMBO_CHANGED, AUDIO_CHANGED); @@ -2124,6 +2125,8 @@ void OBSBasicSettings::LoadAudioSettings() "ChannelSetup"); double meterDecayRate = config_get_double(main->Config(), "Audio", "MeterDecayRate"); + uint32_t peakMeterTypeIdx = config_get_uint(main->Config(), "Audio", + "PeakMeterType"); loading = true; @@ -2159,6 +2162,8 @@ void OBSBasicSettings::LoadAudioSettings() else ui->meterDecayRate->setCurrentIndex(0); + ui->peakMeterType->setCurrentIndex(peakMeterTypeIdx); + LoadAudioDevices(); LoadAudioSources(); @@ -3113,6 +3118,14 @@ void OBSBasicSettings::SaveAudioSettings() main->UpdateVolumeControlsDecayRate(); } + if (WidgetChanged(ui->peakMeterType)) { + uint32_t peakMeterTypeIdx = ui->peakMeterType->currentIndex(); + config_set_uint(main->Config(), "Audio", "PeakMeterType", + peakMeterTypeIdx); + + main->UpdateVolumeControlsPeakMeterType(); + } + for (auto &audioSource : audioSources) { auto source = OBSGetStrongRef(get<0>(audioSource)); if (!source) diff --git a/libobs/obs-audio-controls.c b/libobs/obs-audio-controls.c index 4b0c79b4..85383007 100644 --- a/libobs/obs-audio-controls.c +++ b/libobs/obs-audio-controls.c @@ -16,6 +16,7 @@ along with this program. If not, see . */ #include +#include #include "util/threading.h" #include "util/bmem.h" @@ -62,18 +63,20 @@ struct meter_cb { }; struct obs_volmeter { - pthread_mutex_t mutex; - obs_source_t *source; - enum obs_fader_type type; - float cur_db; + pthread_mutex_t mutex; + obs_source_t *source; + enum obs_fader_type type; + float cur_db; - pthread_mutex_t callback_mutex; - DARRAY(struct meter_cb)callbacks; + pthread_mutex_t callback_mutex; + DARRAY(struct meter_cb) callbacks; - unsigned int update_ms; + enum obs_peak_meter_type peak_meter_type; + unsigned int update_ms; + float prev_samples[MAX_AUDIO_CHANNELS][4]; - float vol_magnitude[MAX_AUDIO_CHANNELS]; - float vol_peak[MAX_AUDIO_CHANNELS]; + float magnitude[MAX_AUDIO_CHANNELS]; + float peak[MAX_AUDIO_CHANNELS]; }; static float cubic_def_to_db(const float def) @@ -256,48 +259,256 @@ static void volmeter_source_destroyed(void *vptr, calldata_t *calldata) obs_volmeter_detach_source(volmeter); } -static void volmeter_process_audio_data(obs_volmeter_t *volmeter, - const struct audio_data *data) +static int get_nr_channels_from_audio_data(const struct audio_data *data) +{ + int nr_channels = 0; + for (int i = 0; i < MAX_AV_PLANES; i++) { + if (data->data[i]) + nr_channels++; + } + return CLAMP(nr_channels, 0, MAX_AUDIO_CHANNELS); +} + +/* msb(h, g, f, e) lsb(d, c, b, a) --> msb(h, h, g, f) lsb(e, d, c, b) + */ +#define SHIFT_RIGHT_2PS(msb, lsb) {\ + __m128 tmp = _mm_shuffle_ps(lsb, msb, _MM_SHUFFLE(0, 0, 3, 3));\ + lsb = _mm_shuffle_ps(lsb, tmp, _MM_SHUFFLE(2, 1, 2, 1));\ + msb = _mm_shuffle_ps(msb, msb, _MM_SHUFFLE(3, 3, 2, 1));\ +} + +/* x(d, c, b, a) --> (|d|, |c|, |b|, |a|) + */ +static inline __m128 abs_ps(__m128 v) +{ + return _mm_andnot_ps(_mm_set1_ps(-0.f), v); +} + +/* Take cross product of a vector with a matrix resulting in vector. + */ +#define VECTOR_MATRIX_CROSS_PS(out, v, m0, m1, m2, m3) \ +{\ + out = _mm_mul_ps(v, m0);\ + __m128 mul1 = _mm_mul_ps(v, m1);\ + __m128 mul2 = _mm_mul_ps(v, m2);\ + __m128 mul3 = _mm_mul_ps(v, m3);\ +\ + _MM_TRANSPOSE4_PS(out, mul1, mul2, mul3);\ +\ + out = _mm_add_ps(out, mul1);\ + out = _mm_add_ps(out, mul2);\ + out = _mm_add_ps(out, mul3);\ +} + +/* x4(d, c, b, a) --> max(a, b, c, d) + */ +inline float hmax_ps(__m128 x4) +{ + float x4_mem[4]; + _mm_store_ps(x4_mem, x4); + + float r = x4_mem[0]; + r = fmaxf(r, x4_mem[1]); + r = fmaxf(r, x4_mem[2]); + r = fmaxf(r, x4_mem[3]); + return r; +} + +/* Calculate the true peak over a set of samples. + * The algorithm implements 5x oversampling by using Whittaker–Shannon + * interpolation over four samples. + * + * The four samples have location t=-1.5, -0.5, +0.5, +1.5 + * The oversamples are taken at locations t=-0.3, -0.1, +0.1, +0.3 + * + * @param previous_samples Last 4 samples from the previous iteration. + * @param samples The samples to find the peak in. + * @param nr_samples Number of sets of 4 samples. + * @returns 5 times oversampled true-peak from the set of samples. + */ +static float get_true_peak(__m128 previous_samples, const float *samples, + size_t nr_samples) +{ + /* These are normalized-sinc parameters for interpolating over sample + * points which are located at x-coords: -1.5, -0.5, +0.5, +1.5. + * And oversample points at x-coords: -0.3, -0.1, 0.1, 0.3. */ + const __m128 m3 = _mm_set_ps(-0.155915f, 0.935489f, 0.233872f, -0.103943f); + const __m128 m1 = _mm_set_ps(-0.216236f, 0.756827f, 0.504551f, -0.189207f); + const __m128 p1 = _mm_set_ps(-0.189207f, 0.504551f, 0.756827f, -0.216236f); + const __m128 p3 = _mm_set_ps(-0.103943f, 0.233872f, 0.935489f, -0.155915f); + + __m128 work = previous_samples; + __m128 peak = previous_samples; + for (size_t i = 0; (i + 3) < nr_samples; i += 4) { + __m128 new_work = _mm_load_ps(&samples[i]); + __m128 intrp_samples; + + /* Include the actual sample values in the peak. */ + __m128 abs_new_work = abs_ps(new_work); + peak = _mm_max_ps(peak, abs_new_work); + + /* Shift in the next point. */ + SHIFT_RIGHT_2PS(new_work, work); + VECTOR_MATRIX_CROSS_PS(intrp_samples, work, m3, m1, p1, p3); + peak = _mm_max_ps(peak, abs_ps(intrp_samples)); + + SHIFT_RIGHT_2PS(new_work, work); + VECTOR_MATRIX_CROSS_PS(intrp_samples, work, m3, m1, p1, p3); + peak = _mm_max_ps(peak, abs_ps(intrp_samples)); + + SHIFT_RIGHT_2PS(new_work, work); + VECTOR_MATRIX_CROSS_PS(intrp_samples, work, m3, m1, p1, p3); + peak = _mm_max_ps(peak, abs_ps(intrp_samples)); + + SHIFT_RIGHT_2PS(new_work, work); + VECTOR_MATRIX_CROSS_PS(intrp_samples, work, m3, m1, p1, p3); + peak = _mm_max_ps(peak, abs_ps(intrp_samples)); + } + + return hmax_ps(peak); +} + +/* points contain the first four samples to calculate the sinc interpolation + * over. They will have come from a previous iteration. + */ +static float get_sample_peak(__m128 previous_samples, const float *samples, + size_t nr_samples) +{ + __m128 peak = previous_samples; + for (size_t i = 0; (i + 3) < nr_samples; i += 4) { + __m128 new_work = _mm_load_ps(&samples[i]); + peak = _mm_max_ps(peak, abs_ps(new_work)); + } + return hmax_ps(peak); +} + +static void volmeter_process_peak_last_samples(obs_volmeter_t *volmeter, + int channel_nr, float *samples, size_t nr_samples) +{ + /* Take the last 4 samples that need to be used for the next peak + * calculation. If there are less than 4 samples in total the new + * samples shift out the old samples. */ + + switch (nr_samples) { + case 0: + break; + case 1: + volmeter->prev_samples[channel_nr][0] = + volmeter->prev_samples[channel_nr][1]; + volmeter->prev_samples[channel_nr][1] = + volmeter->prev_samples[channel_nr][2]; + volmeter->prev_samples[channel_nr][2] = + volmeter->prev_samples[channel_nr][3]; + volmeter->prev_samples[channel_nr][3] = samples[nr_samples-1]; + break; + case 2: + volmeter->prev_samples[channel_nr][0] = + volmeter->prev_samples[channel_nr][2]; + volmeter->prev_samples[channel_nr][1] = + volmeter->prev_samples[channel_nr][3]; + volmeter->prev_samples[channel_nr][2] = samples[nr_samples-2]; + volmeter->prev_samples[channel_nr][3] = samples[nr_samples-1]; + break; + case 3: + volmeter->prev_samples[channel_nr][0] = + volmeter->prev_samples[channel_nr][3]; + volmeter->prev_samples[channel_nr][1] = samples[nr_samples-3]; + volmeter->prev_samples[channel_nr][2] = samples[nr_samples-2]; + volmeter->prev_samples[channel_nr][3] = samples[nr_samples-1]; + break; + default: + volmeter->prev_samples[channel_nr][0] = samples[nr_samples-4]; + volmeter->prev_samples[channel_nr][1] = samples[nr_samples-3]; + volmeter->prev_samples[channel_nr][2] = samples[nr_samples-2]; + volmeter->prev_samples[channel_nr][3] = samples[nr_samples-1]; + } +} + +static void volmeter_process_peak(obs_volmeter_t *volmeter, + const struct audio_data *data, int nr_channels) { int nr_samples = data->frames; int channel_nr = 0; - - for (size_t plane_nr = 0; plane_nr < MAX_AV_PLANES; plane_nr++) { + for (int plane_nr = 0; channel_nr < nr_channels; plane_nr++) { float *samples = (float *)data->data[plane_nr]; if (!samples) { - // This plane does not contain data. continue; } + if (((uintptr_t)samples & 0xf) > 0) { + printf("Audio plane %i is not aligned %p skipping " + "peak volume measurement.\n", + plane_nr, samples); + volmeter->peak[channel_nr] = 1.0; + channel_nr++; + continue; + } + + /* volmeter->prev_samples may not be aligned to 16 bytes; + * use unaligned load. */ + __m128 previous_samples = _mm_loadu_ps( + volmeter->prev_samples[channel_nr]); + + float peak; + switch (volmeter->peak_meter_type) { + case TRUE_PEAK_METER: + peak = get_true_peak(previous_samples, samples, + nr_samples); + break; + + case SAMPLE_PEAK_METER: + default: + peak = get_sample_peak(previous_samples, samples, + nr_samples); + break; - // For each plane calculate: - // * peak = the maximum-absolute of the sample values. - // * magnitude = root-mean-square of the sample values. - // A VU meter needs to integrate over 300ms, but this will - // be handled by the ballistics of the meter itself, - // reality. Which makes this calculation independent of - // sample rate or update rate. - float peak = 0.0; - float sum_of_squares = 0.0; - for (int sample_nr = 0; sample_nr < nr_samples; sample_nr++) { - float sample = samples[sample_nr]; - - peak = fmaxf(peak, fabsf(sample)); - sum_of_squares += (sample * sample); } - volmeter->vol_magnitude[channel_nr] = sqrtf(sum_of_squares / + volmeter_process_peak_last_samples(volmeter, channel_nr, samples, nr_samples); - volmeter->vol_peak[channel_nr] = peak; + + volmeter->peak[channel_nr] = peak; + channel_nr++; } - // Clear audio channels that are not in use. + /* Clear the peak of the channels that have not been handled. */ for (; channel_nr < MAX_AUDIO_CHANNELS; channel_nr++) { - volmeter->vol_magnitude[channel_nr] = 0.0; - volmeter->vol_peak[channel_nr] = 0.0; + volmeter->peak[channel_nr] = 0.0; } } +static void volmeter_process_magnitude(obs_volmeter_t *volmeter, + const struct audio_data *data, int nr_channels) +{ + size_t nr_samples = data->frames; + + int channel_nr = 0; + for (int plane_nr = 0; channel_nr < nr_channels; plane_nr++) { + float *samples = (float *)data->data[plane_nr]; + if (!samples) { + continue; + } + + float sum = 0.0; + for (size_t i = 0; i < nr_samples; i++) { + float sample = samples[i]; + sum += sample * sample; + } + volmeter->magnitude[channel_nr] = sqrtf(sum / nr_samples); + + channel_nr++; + } +} + +static void volmeter_process_audio_data(obs_volmeter_t *volmeter, + const struct audio_data *data) +{ + int nr_channels = get_nr_channels_from_audio_data(data); + + volmeter_process_peak(volmeter, data, nr_channels); + volmeter_process_magnitude(volmeter, data, nr_channels); +} + static void volmeter_source_data_received(void *vptr, obs_source_t *source, const struct audio_data *data, bool muted) { @@ -317,16 +528,16 @@ static void volmeter_source_data_received(void *vptr, obs_source_t *source, for (int channel_nr = 0; channel_nr < MAX_AUDIO_CHANNELS; channel_nr++) { magnitude[channel_nr] = mul_to_db( - volmeter->vol_magnitude[channel_nr] * mul); + volmeter->magnitude[channel_nr] * mul); peak[channel_nr] = mul_to_db( - volmeter->vol_peak[channel_nr] * mul); + volmeter->peak[channel_nr] * mul); + + /* The input-peak is NOT adjusted with volume, so that the user + * can check the input-gain. */ input_peak[channel_nr] = mul_to_db( - volmeter->vol_peak[channel_nr]); + volmeter->peak[channel_nr]); } - // The input-peak is NOT adjusted with volume, so that the user - // can check the input-gain. - pthread_mutex_unlock(&volmeter->mutex); signal_levels_updated(volmeter, magnitude, peak, input_peak); @@ -641,6 +852,14 @@ void obs_volmeter_detach_source(obs_volmeter_t *volmeter) volmeter_source_data_received, volmeter); } +void obs_volmeter_set_peak_meter_type(obs_volmeter_t *volmeter, + enum obs_peak_meter_type peak_meter_type) +{ + pthread_mutex_lock(&volmeter->mutex); + volmeter->peak_meter_type = peak_meter_type; + pthread_mutex_unlock(&volmeter->mutex); +} + void obs_volmeter_set_update_interval(obs_volmeter_t *volmeter, const unsigned int ms) { diff --git a/libobs/obs-audio-controls.h b/libobs/obs-audio-controls.h index 158af7bf..384d6187 100644 --- a/libobs/obs-audio-controls.h +++ b/libobs/obs-audio-controls.h @@ -68,6 +68,27 @@ enum obs_fader_type { OBS_FADER_LOG }; +/** + * @brief Peak meter types + */ +enum obs_peak_meter_type { + /** + * @brief A simple peak meter measuring the maximum of all samples. + * + * This was a very common type of peak meter used for audio, but + * is not very accurate with regards to further audio processing. + */ + SAMPLE_PEAK_METER, + + /** + * @brief An accurate peak meter measure the maximum of inter-samples. + * + * This meter is more computational intensive due to 4x oversampling + * to determine the true peak to an accuracy of +/- 0.5 dB. + */ + TRUE_PEAK_METER +}; + /** * @brief Create a fader * @param type the type of the fader @@ -200,6 +221,14 @@ EXPORT bool obs_volmeter_attach_source(obs_volmeter_t *volmeter, */ EXPORT void obs_volmeter_detach_source(obs_volmeter_t *volmeter); +/** + * @brief Set the peak meter type for the volume meter + * @param volmeter pointer to the volume meter object + * @param peak_meter_type set if true-peak needs to be measured. + */ +EXPORT void obs_volmeter_set_peak_meter_type(obs_volmeter_t *volmeter, + enum obs_peak_meter_type peak_meter_type); + /** * @brief Set the update interval for the volume meter * @param volmeter pointer to the volume meter object -- GitLab