YUIQQPXYFEVTS4XG4N6JTKBHWC4OFWWSCGJ6MLNA6AWTKSYCSIEQC }}func BenchmarkFullPipelineWavOnly(b *testing.B) {samples, sr, _ := utils.ReadWAVSamples(benchWAV)b.ResetTimer()b.ReportAllocs()for i := 0; i < b.N; i++ {segSamples := utils.ExtractSegmentSamples(samples, sr, 872, 895)outputSR := srif sr > 16000 {segSamples = utils.ResampleRate(segSamples, sr, 16000)outputSR = 16000}f, _ := os.CreateTemp("", "bench_*.wav")utils.WriteWAVFile(f.Name(), segSamples, outputSR)f.Close()os.Remove(f.Name())
File string `json:"file"`Folder string `json:"folder"`Output string `json:"output"`Prefix string `json:"prefix"`Filter string `json:"filter"`Species string `json:"species"`Certainty int `json:"certainty"`Size int `json:"size"`Color bool `json:"color"`WavOnly bool `json:"wav_only"`Night bool `json:"night"`Day bool `json:"day"`Lat float64 `json:"lat"`Lng float64 `json:"lng"`Timezone string `json:"timezone"`
File string `json:"file"`Folder string `json:"folder"`Output string `json:"output"`Prefix string `json:"prefix"`Filter string `json:"filter"`Species string `json:"species"`Certainty int `json:"certainty"`Size int `json:"size"`Color bool `json:"color"`Night bool `json:"night"`Day bool `json:"day"`Lat float64 `json:"lat"`Lng float64 `json:"lng"`Timezone string `json:"timezone"`
clips, skipped, errs := processFile(dataPath, input.Output, input.Prefix, input.Filter, speciesName, callType, input.Certainty, imgSize, input.Color, input.WavOnly, input.Night, input.Day, input.Lat, input.Lng, input.Timezone)
clips, skipped, errs := processFile(dataPath, input.Output, input.Prefix, input.Filter, speciesName, callType, input.Certainty, imgSize, input.Color, input.Night, input.Day, input.Lat, input.Lng, input.Timezone)
clips, skipped, errs := processFile(dataPath, input.Output, input.Prefix, input.Filter, speciesName, callType, input.Certainty, imgSize, input.Color, input.WavOnly, input.Night, input.Day, input.Lat, input.Lng, input.Timezone)
clips, skipped, errs := processFile(dataPath, input.Output, input.Prefix, input.Filter, speciesName, callType, input.Certainty, imgSize, input.Color, input.Night, input.Day, input.Lat, input.Lng, input.Timezone)
func processFile(dataPath, outputDir, prefix, filter, speciesName, callType string, certainty, imgSize int, color, wavOnly, night, day bool, lat, lng float64, timezone string) ([]string, int, []string) {
func processFile(dataPath, outputDir, prefix, filter, speciesName, callType string, certainty, imgSize int, color, night, day bool, lat, lng float64, timezone string) ([]string, int, []string) {
clips, errors = processSegments(matchingSegments, dataPath, samples, sampleRate, outputDir, prefix, basename, imgSize, color, wavOnly)
clips, errors = processSegments(matchingSegments, dataPath, samples, sampleRate, outputDir, prefix, basename, imgSize, color)
func processSegments(segments []*utils.Segment, dataPath string, samples []float64, sampleRate int, outputDir, prefix, basename string, imgSize int, color, wavOnly bool) ([]string, []string) {
func processSegments(segments []*utils.Segment, dataPath string, samples []float64, sampleRate int, outputDir, prefix, basename string, imgSize int, color bool) ([]string, []string) {
clipFiles, err := generateClip(samples, sampleRate, outputDir, prefix, basename, seg.StartTime, seg.EndTime, imgSize, color, wavOnly)
clipFiles, err := generateClip(samples, sampleRate, outputDir, prefix, basename, seg.StartTime, seg.EndTime, imgSize, color)
clips, errors = processSegmentsParallel(segments, dataPath, samples, sampleRate, outputDir, prefix, basename, imgSize, color, wavOnly)
clips, errors = processSegmentsParallel(segments, dataPath, samples, sampleRate, outputDir, prefix, basename, imgSize, color)
func processSegmentsParallel(segments []*utils.Segment, dataPath string, samples []float64, sampleRate int, outputDir, prefix, basename string, imgSize int, color, wavOnly bool) ([]string, []string) {
func processSegmentsParallel(segments []*utils.Segment, dataPath string, samples []float64, sampleRate int, outputDir, prefix, basename string, imgSize int, color bool) ([]string, []string) {
clipFiles, err := generateClip(samples, sampleRate, outputDir, prefix, basename, seg.StartTime, seg.EndTime, imgSize, color, wavOnly)
clipFiles, err := generateClip(samples, sampleRate, outputDir, prefix, basename, seg.StartTime, seg.EndTime, imgSize, color)
func generateClip(samples []float64, sampleRate int, outputDir, prefix, basename string, startTime, endTime float64, imgSize int, color, wavOnly bool) ([]string, error) {
func generateClip(samples []float64, sampleRate int, outputDir, prefix, basename string, startTime, endTime float64, imgSize int, color bool) ([]string, error) {
spectSampleRate := outputSampleRateconfig := utils.DefaultSpectrogramConfig(spectSampleRate)spectrogram := utils.GenerateSpectrogram(segSamples, config)if spectrogram == nil {return nil, fmt.Errorf("failed to generate spectrogram")}
spectSampleRate := outputSampleRateconfig := utils.DefaultSpectrogramConfig(spectSampleRate)spectrogram := utils.GenerateSpectrogram(segSamples, config)if spectrogram == nil {return nil, fmt.Errorf("failed to generate spectrogram")}
// Create image (grayscale or color)var img image.Imageif color {colorData := utils.ApplyL4Colormap(spectrogram)img = utils.CreateRGBImage(colorData)} else {img = utils.CreateGrayscaleImage(spectrogram)}if img == nil {return nil, fmt.Errorf("failed to create image")}
// Create image (grayscale or color)var img image.Imageif color {colorData := utils.ApplyL4Colormap(spectrogram)img = utils.CreateRGBImage(colorData)} else {img = utils.CreateGrayscaleImage(spectrogram)}if img == nil {return nil, fmt.Errorf("failed to create image")}
// Write PNG (O_EXCL fails atomically if file exists)pngFile, err := os.OpenFile(pngPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644)if err != nil {if os.IsExist(err) {return nil, fmt.Errorf("file already exists: %s", pngPath)}return nil, fmt.Errorf("failed to create PNG: %w", err)
// Write PNG (O_EXCL fails atomically if file exists)pngFile, err := os.OpenFile(pngPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644)if err != nil {if os.IsExist(err) {return nil, fmt.Errorf("file already exists: %s", pngPath)
if err := utils.WritePNG(resized, pngFile); err != nil {_ = pngFile.Close()return nil, fmt.Errorf("failed to write PNG: %w", err)}if err := pngFile.Close(); err != nil {return nil, fmt.Errorf("failed to close PNG: %w", err)}files = append(files, pngPath)
return nil, fmt.Errorf("failed to create PNG: %w", err)}if err := utils.WritePNG(resized, pngFile); err != nil {_ = pngFile.Close()return nil, fmt.Errorf("failed to write PNG: %w", err)}if err := pngFile.Close(); err != nil {return nil, fmt.Errorf("failed to close PNG: %w", err)