Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global meta setting to amplify. #4213

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/core/operators/amplify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open Source
let parse_db s =
try Scanf.sscanf s " %f dB" Audio.lin_of_dB with _ -> float_of_string s

class amplify ~field (source : source) override_field coeff =
class amplify ~field ~override_field (source : source) coeff =
object (self)
inherit operator ~name:"track.audio.amplify" [source]
val mutable override = None
Expand Down Expand Up @@ -63,7 +63,7 @@ class amplify ~field (source : source) override_field coeff =
else buf

method private set_override buf =
match override_field with
match Option.map (fun f -> f ()) override_field with
| Some f ->
if override <> None then
self#log#info "End of the current overriding.";
Expand Down Expand Up @@ -92,24 +92,26 @@ let _ =
let frame_t = Lang.pcm_audio_t () in
Lang.add_track_operator ~base:Modules.track_audio "amplify"
[
("", Lang.getter_t Lang.float_t, None, Some "Multiplicative factor.");
( "override",
Lang.nullable_t Lang.string_t,
Lang.getter_t (Lang.nullable_t Lang.string_t),
Some (Lang.string "liq_amplify"),
Some
"Specify the name of a metadata field that, when present and \
well-formed, overrides the amplification factor for the current \
track. Well-formed values are floats in decimal notation (e.g. \
`0.7`) which are taken as normal/linear multiplicative factors; \
values can be passed in decibels with the suffix `dB` (e.g. `-8.2 \
dB`, but the spaces do not matter)." );
dB`, but the spaces do not matter). Defaults to \
`settings.amplify.metadata`. Set to `null` to disable." );
("", Lang.getter_t Lang.float_t, None, Some "Multiplicative factor.");
("", frame_t, None, None);
]
~return_t:frame_t ~category:`Audio
~descr:"Multiply the amplitude of the signal."
(fun p ->
let c = Lang.to_float_getter (Lang.assoc "" 1 p) in
let field, s = Lang.to_track (Lang.assoc "" 2 p) in
let o = Lang.to_option (Lang.assoc "override" 1 p) in
let o = Option.map Lang.to_string o in
(field, new amplify ~field s o c))
let override_field =
Lang.to_valued_option Lang.to_string_getter (Lang.assoc "override" 1 p)
in
(field, new amplify ~field ~override_field s c))
22 changes: 22 additions & 0 deletions src/libs/tracks.liq
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,25 @@ def source.drop.metadata(~id=null(), s) =
let {metadata = _, ...tracks} = source.tracks(s)
source(id=id, tracks)
end

let settings.amplify =
settings.make.void(
"Settings for the amplify operator"
)

let settings.amplify.override =
settings.make(
description=
"Default metadata used to override amplification.",
"liq_amplify"
)

# @docof track.audio.amplify
def track.audio.amplify(
%argsof(track.audio.amplify[!override]),
~override=getter({(settings.amplify.override() : string?)}),
v,
t
) =
track.audio.amplify(%argsof(track.audio.amplify), v, t)
end
Loading