diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-07-13 19:40:31 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-07-13 19:40:31 (GMT) |
commit | 3c67fe07b6103d1bd0ddafbfa7da0544cf7ed83e (patch) | |
tree | 6f7a60f03ff6a3a40729e58b3ade74a620ab8232 /rhimport/normalizer.go | |
parent | 6162042d3c40a7b9e49531e85f288014d56332b0 (diff) |
added normalizer step
always send last/first progress message of a step
Diffstat (limited to 'rhimport/normalizer.go')
-rw-r--r-- | rhimport/normalizer.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/rhimport/normalizer.go b/rhimport/normalizer.go new file mode 100644 index 0000000..3730929 --- /dev/null +++ b/rhimport/normalizer.go @@ -0,0 +1,73 @@ +// +// rhimportd +// +// The Radio Helsinki Rivendell Import Daemon +// +// +// Copyright (C) 2015-2016 Christian Pointner <equinox@helsinki.at> +// +// This file is part of rhimportd. +// +// rhimportd is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// rhimportd is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with rhimportd. If not, see <http://www.gnu.org/licenses/>. +// + +package rhimport + +import ( + "os" +) + +func NormalizeFile(ctx *Context) (err error) { + if ctx.LoudnessCorr == 0.0 { + rhdl.Println("NormalizeFile: skipping normalization since the gain = 0.0dB") + if ctx.ProgressCallBack != nil { + if keep := ctx.ProgressCallBack(2, "normalizing", 1.0, 1.0, ctx.ProgressCallBackData); !keep { + ctx.ProgressCallBack = nil + } + } + return + } + + rhl.Printf("NormalizeFile: using gain = %.2fdB", ctx.LoudnessCorr) + ctx.NormalizationLevel = 0 // don't do double normalization + + var src *os.File + if src, err = os.Open(ctx.SourceFile); err != nil { + return + } + defer src.Close() + + size := int64(0) + if info, err := src.Stat(); err != nil { + return err + } else { + size = info.Size() + } + + if ctx.ProgressCallBack != nil { + if keep := ctx.ProgressCallBack(2, "normalizing", 0.0, float64(size), ctx.ProgressCallBackData); !keep { + ctx.ProgressCallBack = nil + } + } + + // TODO: call ffmpeg + + if ctx.ProgressCallBack != nil { + if keep := ctx.ProgressCallBack(2, "normalizing", float64(size), float64(size), ctx.ProgressCallBackData); !keep { + ctx.ProgressCallBack = nil + } + } + + return +} |