Skip to content

Commit

Permalink
Better implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Nov 18, 2024
1 parent ed05512 commit 57a23c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/core/operators/amplify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ open Source
let parse_db s =
try Scanf.sscanf s " %f dB" Audio.lin_of_dB with _ -> float_of_string s

let conf_amplify =
Dtools.Conf.void ~p:(Configure.conf#plug "amplify") "Amplify configuration"

let conf_amplify_metadata =
Dtools.Conf.string
~p:(conf_amplify#plug "metadata")
~d:"liq_amplify" "Amplify metadata"

class amplify ~field ~override_field (source : source) coeff =
object (self)
inherit operator ~name:"track.audio.amplify" [source]
Expand Down Expand Up @@ -96,18 +88,13 @@ class amplify ~field ~override_field (source : source) coeff =
Frame.append buf (self#process new_track)
end

let default_override =
Lang.eval ~cache:false ~typecheck:false ~stdlib:`Disabled
"{settings.amplify.metadata()}"

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.getter_t (Lang.nullable_t Lang.string_t),
Some default_override,
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 \
Expand All @@ -116,6 +103,7 @@ let _ =
values can be passed in decibels with the suffix `dB` (e.g. `-8.2 \
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
Expand Down
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

0 comments on commit 57a23c8

Please sign in to comment.