55 "errors"
66 "fmt"
77 "math"
8- "path/filepath"
98 "sort"
109 "strconv"
1110 "time"
@@ -24,7 +23,6 @@ type SilenceRegion struct {
2423
2524// NoiseProfile contains information about an extracted noise sample
2625type NoiseProfile struct {
27- FilePath string `json:"file_path"` // Path to extracted noise sample WAV file
2826 Start time.Duration `json:"start"` // Start time of silence region used
2927 Duration time.Duration `json:"duration"` // Duration of extracted sample
3028 MeasuredNoiseFloor float64 `json:"measured_noise_floor"` // dBFS, RMS level of silence (average noise)
@@ -1891,8 +1889,7 @@ func AnalyzeAudio(filename string, config *FilterChainConfig, progressCallback f
18911889 measurements .SilenceCandidates = silenceResult .Candidates
18921890
18931891 if silenceResult .BestRegion != nil {
1894- tempDir := filepath .Dir (filename ) // Use same directory as input file
1895- if profile , err := extractNoiseProfile (filename , silenceResult .BestRegion , tempDir ); err == nil && profile != nil {
1892+ if profile , err := extractNoiseProfile (filename , silenceResult .BestRegion ); err == nil && profile != nil {
18961893 measurements .NoiseProfile = profile
18971894 // If we got a noise profile measurement, use it as the primary noise floor
18981895 // This is more accurate than the overall RMS_trough because it's from pure silence
@@ -2500,21 +2497,15 @@ func measureSilenceCandidateSpectral(filename string, region SilenceRegion) *Sil
25002497 return metrics
25012498}
25022499
2503- // extractNoiseProfile extracts a noise sample from the silence region and measures its characteristics.
2504- // The extracted sample is written as a WAV file for use with afftdn's noise profiling.
2500+ // extractNoiseProfile measures noise characteristics from a silence region.
25052501// Uses atrim + astats filter chain to measure RMS level, peak level, and entropy.
2502+ // DNS-1500 uses inline noise learning via asendcmd with timestamps, so no WAV extraction needed.
25062503// Returns nil, nil if no suitable silence region exists or extraction fails non-fatally.
2507- func extractNoiseProfile (filename string , region * SilenceRegion , tempDir string ) (* NoiseProfile , error ) {
2504+ func extractNoiseProfile (filename string , region * SilenceRegion ) (* NoiseProfile , error ) {
25082505 if region == nil {
25092506 return nil , nil
25102507 }
25112508
2512- // Generate output filename for the noise profile WAV
2513- baseName := filepath .Base (filename )
2514- ext := filepath .Ext (baseName )
2515- nameWithoutExt := baseName [:len (baseName )- len (ext )]
2516- outputPath := filepath .Join (tempDir , nameWithoutExt + "_noise_profile.wav" )
2517-
25182509 // Open the audio file
25192510 reader , _ , err := audio .OpenAudioFile (filename )
25202511 if err != nil {
@@ -2543,14 +2534,7 @@ func extractNoiseProfile(filename string, region *SilenceRegion, tempDir string)
25432534 }
25442535 defer ffmpeg .AVFilterGraphFree (& filterGraph )
25452536
2546- // Create WAV encoder for writing the noise profile
2547- wavEncoder , err := createWAVEncoder (outputPath , bufferSinkCtx )
2548- if err != nil {
2549- return nil , nil // Non-fatal - extraction skipped
2550- }
2551- defer wavEncoder .Close ()
2552-
2553- // Process frames through filter to measure noise and write to WAV
2537+ // Process frames through filter to measure noise
25542538 filteredFrame := ffmpeg .AVFrameAlloc ()
25552539 defer ffmpeg .AVFrameFree (& filteredFrame )
25562540
@@ -2560,7 +2544,6 @@ func extractNoiseProfile(filename string, region *SilenceRegion, tempDir string)
25602544 var entropy float64
25612545 var noiseFloorFound bool
25622546 var framesProcessed int64
2563- var wavWriteError error
25642547
25652548 for {
25662549 frame , err := reader .ReadFrame ()
@@ -2585,13 +2568,6 @@ func extractNoiseProfile(filename string, region *SilenceRegion, tempDir string)
25852568 continue
25862569 }
25872570
2588- // Write frame to WAV file (if encoder available)
2589- if wavEncoder != nil && wavWriteError == nil {
2590- if err := wavEncoder .WriteFrame (filteredFrame ); err != nil {
2591- wavWriteError = err // Stop trying to write after first error
2592- }
2593- }
2594-
25952571 // Extract noise measurements from metadata
25962572 if metadata := filteredFrame .Metadata (); metadata != nil {
25972573 // RMS_level: average noise floor
@@ -2621,13 +2597,6 @@ func extractNoiseProfile(filename string, region *SilenceRegion, tempDir string)
26212597 break
26222598 }
26232599
2624- // Write remaining frames to WAV
2625- if wavEncoder != nil && wavWriteError == nil {
2626- if err := wavEncoder .WriteFrame (filteredFrame ); err != nil {
2627- wavWriteError = err
2628- }
2629- }
2630-
26312600 if metadata := filteredFrame .Metadata (); metadata != nil {
26322601 if value , ok := getFloatMetadata (metadata , metaKeyRMSLevel ); ok {
26332602 measuredNoiseFloor = value
@@ -2646,13 +2615,6 @@ func extractNoiseProfile(filename string, region *SilenceRegion, tempDir string)
26462615 }
26472616 }
26482617
2649- // Flush encoder
2650- if wavEncoder != nil && wavWriteError == nil {
2651- if err := wavEncoder .Flush (); err != nil {
2652- wavWriteError = err
2653- }
2654- }
2655-
26562618 if framesProcessed == 0 {
26572619 return nil , nil // No frames in silence region
26582620 }
@@ -2666,7 +2628,6 @@ func extractNoiseProfile(filename string, region *SilenceRegion, tempDir string)
26662628 }
26672629
26682630 // Build noise profile result
2669- // FilePath is set only if WAV was successfully written
26702631 profile := & NoiseProfile {
26712632 Start : region .Start ,
26722633 Duration : region .Duration ,
@@ -2675,11 +2636,6 @@ func extractNoiseProfile(filename string, region *SilenceRegion, tempDir string)
26752636 Entropy : entropy , // 1.0 = broadband noise, lower = tonal noise
26762637 }
26772638
2678- // Set FilePath only if WAV was successfully written
2679- if wavEncoder != nil && wavWriteError == nil {
2680- profile .FilePath = outputPath
2681- }
2682-
26832639 // Record warning if using silence region outside ideal range (8-18s)
26842640 if region .Duration < idealDurationMin {
26852641 profile .ExtractionWarning = fmt .Sprintf ("using short silence region (%.1fs) - ideally need >=%ds" , region .Duration .Seconds (), int (idealDurationMin .Seconds ()))
0 commit comments