Sfoglia il codice sorgente

libobs: Add IEC 60-268-18 compliant fader type

This adds a new fader type that implements a position/dB mapping
as specified in IEC 60-268-18.
fryshorts 11 anni fa
parent
commit
119d77e176
2 ha cambiato i file con 89 aggiunte e 1 eliminazioni
  1. 68 0
      libobs/obs-audio-controls.c
  2. 21 1
      libobs/obs-audio-controls.h

+ 68 - 0
libobs/obs-audio-controls.c

@@ -97,6 +97,64 @@ static float cubic_db_to_def(const float db)
 	return cbrtf(db_to_mul(db));
 }
 
+static float iec_def_to_db(const float def)
+{
+	if (def == 1.0f)
+		return 0.0f;
+	else if (def <= 0.0f)
+		return -INFINITY;
+
+	float db;
+
+	if (def >= 0.75f)
+		db = (def - 1.0f) / 0.25f * 9.0f;
+	else if (def >= 0.5f)
+		db = (def - 0.75f) / 0.25f * 11.0f - 9.0f;
+	else if (def >= 0.3f)
+		db = (def - 0.5f) / 0.2f * 10.0f - 20.0f;
+	else if (def >= 0.15f)
+		db = (def - 0.3f) / 0.15f * 10.0f - 30.0f;
+	else if (def >= 0.075f)
+		db = (def - 0.15f) / 0.075f * 10.0f - 40.0f;
+	else if (def >= 0.025f)
+		db = (def - 0.075f) / 0.05f * 10.0f - 50.0f;
+	else if (def >= 0.001f)
+		db = (def - 0.025f) / 0.025f * 90.0f - 60.0f;
+	else
+		db = -INFINITY;
+
+	return db;
+}
+
+static float iec_db_to_def(const float db)
+{
+	if (db == 0.0f)
+		return 1.0f;
+	else if (db == -INFINITY)
+		return 0.0f;
+
+	float def;
+
+	if (db >= -9.0f)
+		def = (db + 9.0f) / 9.0f * 0.25f + 0.75f;
+	else if (db >= -20.0f)
+		def = (db + 20.0f) / 11.0f * 0.25f + 0.5f;
+	else if (db >= -30.0f)
+		def = (db + 30.0f) / 10.0f * 0.2f + 0.3f;
+	else if (db >= -40.0f)
+		def = (db + 40.0f) / 10.0f * 0.15f + 0.15f;
+	else if (db >= -50.0f)
+		def = (db + 50.0f) / 10.0f * 0.075f + 0.075f;
+	else if (db >= -60.0f)
+		def = (db + 60.0f) / 10.0f * 0.05f + 0.025f;
+	else if (db >= -114.0f)
+		def = (db + 150.0f) / 90.0f * 0.025f;
+	else
+		def = 0.0f;
+
+	return def;
+}
+
 static void signal_volume_changed(signal_handler_t *sh,
 		struct obs_fader *fader, const float db)
 {
@@ -225,6 +283,12 @@ obs_fader_t *obs_fader_create(enum obs_fader_type type)
 		fader->max_db    = 0.0f;
 		fader->min_db    = -INFINITY;
 		break;
+	case OBS_FADER_IEC:
+		fader->def_to_db = iec_def_to_db;
+		fader->db_to_def = iec_db_to_def;
+		fader->max_db    = 0.0f;
+		fader->min_db    = -INFINITY;
+		break;
 	default:
 		goto fail;
 		break;
@@ -407,6 +471,10 @@ obs_volmeter_t *obs_volmeter_create(enum obs_fader_type type)
 		volmeter->pos_to_db = cubic_def_to_db;
 		volmeter->db_to_pos = cubic_db_to_def;
 		break;
+	case OBS_FADER_IEC:
+		volmeter->pos_to_db = iec_def_to_db;
+		volmeter->db_to_pos = iec_db_to_def;
+		break;
 	default:
 		goto fail;
 		break;

+ 21 - 1
libobs/obs-audio-controls.h

@@ -41,7 +41,27 @@ enum obs_fader_type {
 	 * results while being quite performant.
 	 * The input value is mapped to mul values with the simple formula x^3.
 	 */
-	OBS_FADER_CUBIC
+	OBS_FADER_CUBIC,
+	/**
+	 * @brief A fader compliant to IEC 60-268-18
+	 *
+	 * This type of fader has several segments with different slopes that
+	 * map deflection linearly to dB values. The segments are defined as
+	 * in the following table:
+	 *
+	@code
+	Deflection           | Volume
+	------------------------------------------
+	[ 100   %, 75   % ]  | [   0 dB,   -9 dB ]
+	[  75   %, 50   % ]  | [  -9 dB,  -20 dB ]
+	[  50   %, 30   % ]  | [ -20 dB,  -30 dB ]
+	[  30   %, 15   % ]  | [ -30 dB,  -40 dB ]
+	[  15   %,  7.5 % ]  | [ -40 dB,  -50 dB ]
+	[   7.5 %,  2.5 % ]  | [ -50 dB,  -60 dB ]
+	[   2.5 %,  0   % ]  | [ -60 dB, -inf dB ]
+	@endcode
+	 */
+	OBS_FADER_IEC
 };
 
 /**