Add automatic phase correction with cross-correlation detection and manual override
- Implement cross-correlation-based phase inversion detection - Add --force-invert-phase flag for manual override and testing - Add --no-phase-correction flag to disable automatic detection - Update README with comprehensive documentation - Improve phase detection sensitivity and add detailed logging - Ensure consistent IR polarity for easier mixing of multiple IRs
This commit is contained in:
28
main.go
28
main.go
@@ -83,6 +83,14 @@ func main() {
|
||||
Name: "plot-ir",
|
||||
Usage: "Plot the generated regular IR waveform to ir_plot.png",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "no-phase-correction",
|
||||
Usage: "Disable automatic phase correction (use if you know the phase is correct)",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "force-invert-phase",
|
||||
Usage: "Force inversion of the recorded sweep (for testing/manual override)",
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
// Read sweep WAV file
|
||||
@@ -118,8 +126,19 @@ func main() {
|
||||
recordedFiltered = convolve.CascadeHighcut(recordedFiltered, recSampleRate, highcutHz, cutSlope)
|
||||
}
|
||||
|
||||
// Force phase inversion if requested
|
||||
if c.Bool("force-invert-phase") {
|
||||
log.Printf("Forcing phase inversion of recorded sweep (manual override)")
|
||||
recordedFiltered = convolve.InvertPhase(recordedFiltered)
|
||||
}
|
||||
|
||||
log.Println("Performing deconvolution...")
|
||||
ir := convolve.Deconvolve(sweepData.PCMData, recordedFiltered)
|
||||
var ir []float64
|
||||
if c.Bool("no-phase-correction") {
|
||||
ir = convolve.Deconvolve(sweepData.PCMData, recordedFiltered)
|
||||
} else {
|
||||
ir = convolve.DeconvolveWithPhaseCorrection(sweepData.PCMData, recordedFiltered)
|
||||
}
|
||||
log.Printf("Deconvolution result: %d samples", len(ir))
|
||||
|
||||
log.Println("Trimming silence...")
|
||||
@@ -204,7 +223,12 @@ func main() {
|
||||
if c.Bool("mpt") {
|
||||
log.Println("Generating minimum phase transform...")
|
||||
// Use the original 96kHz IR for MPT generation
|
||||
originalIR := convolve.Deconvolve(sweepData.PCMData, recordedData.PCMData)
|
||||
var originalIR []float64
|
||||
if c.Bool("no-phase-correction") {
|
||||
originalIR = convolve.Deconvolve(sweepData.PCMData, recordedData.PCMData)
|
||||
} else {
|
||||
originalIR = convolve.DeconvolveWithPhaseCorrection(sweepData.PCMData, recordedData.PCMData)
|
||||
}
|
||||
originalIR = convolve.TrimSilence(originalIR, 1e-5)
|
||||
mptIR := convolve.MinimumPhaseTransform(originalIR)
|
||||
mptIR = convolve.Normalize(mptIR, c.Float64("normalize"))
|
||||
|
||||
Reference in New Issue
Block a user