github.com/noriah/catnip@v1.8.5/config.go (about) 1 package catnip 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/noriah/catnip/dsp" 8 "github.com/noriah/catnip/dsp/window" 9 "github.com/noriah/catnip/processor" 10 ) 11 12 type Config struct { 13 // The name of the backend from the input package 14 Backend string 15 // The name of the device to pull data from 16 Device string 17 // The rate that samples are read 18 SampleRate float64 19 // The number of samples per batch 20 SampleSize int 21 // The number of channels to read data from 22 ChannelCount int 23 // The number of times per second to process data 24 ProcessRate int 25 // Merge multiple channels into a single stream 26 Combine bool 27 28 // testing. leave false 29 // Use threaded processor 30 UseThreaded bool 31 32 // Function to call when setting up the pipeline 33 SetupFunc SetupFunc 34 // Function to call when starting the pipeline 35 StartFunc StartFunc 36 // Function to call when cleaning up the pipeline 37 CleanupFunc CleanupFunc 38 // Where to send the data from the audio analysis 39 Output processor.Output 40 // Method to run on data before running fft 41 Windower window.Function 42 // Analyzer to run analysis on data 43 Analyzer dsp.Analyzer 44 // Smoother to run smoothing on output from Analyzer 45 Smoother dsp.Smoother 46 } 47 48 func NewZeroConfig() Config { 49 return Config{ 50 SampleRate: 44100, 51 SampleSize: 1024, 52 ChannelCount: 1, 53 } 54 } 55 56 func (cfg *Config) Validate() error { 57 if cfg.SampleRate < float64(cfg.SampleSize) { 58 return errors.New("sample rate lower than sample size") 59 } 60 61 if cfg.SampleSize < 4 { 62 return errors.New("sample size too small (4+ required)") 63 } 64 65 switch { 66 case cfg.ChannelCount > MaxChannelCount: 67 return fmt.Errorf("too many channels (%d max)", MaxChannelCount) 68 69 case cfg.ChannelCount < 1: 70 return errors.New("too few channels (1 min)") 71 72 case cfg.SampleSize > MaxSampleSize: 73 return fmt.Errorf("sample size too large (%d max)", MaxSampleSize) 74 } 75 76 return nil 77 }