diff --git a/revid/audio-input.go b/revid/audio-input.go index 4b498926..bf3980e7 100644 --- a/revid/audio-input.go +++ b/revid/audio-input.go @@ -197,16 +197,16 @@ func (a *AudioInput) open() error { log.Log(logger.Debug, "Sample rate set", "rate", defaultSampleRate) } - var fmt alsa.FormatType + var aFmt alsa.FormatType switch a.BitDepth { case 16: - fmt = alsa.S16_LE + aFmt = alsa.S16_LE case 32: - fmt = alsa.S32_LE + aFmt = alsa.S32_LE default: - return errors.New("Unsupported sample bits") + return fmt.Errorf("Unsupported sample bits %v\n", a.BitDepth) } - _, err = a.dev.NegotiateFormat(fmt) + _, err = a.dev.NegotiateFormat(aFmt) if err != nil { return err } @@ -274,7 +274,6 @@ func (a *AudioInput) input() { // Read reads a full PCM chunk from the ringbuffer, returning the number of bytes read upon success. // Any errors returned are unexpected and should be considered fatal. func (a *AudioInput) Read(p []byte) (n int, err error) { - fmt.Println("Performing AudioInput read...") chunk, err := a.rb.Next(rbNextTimeout) switch err { case nil: diff --git a/revid/audio-input_test.go b/revid/audio-input_test.go index a510428b..7c817c5f 100644 --- a/revid/audio-input_test.go +++ b/revid/audio-input_test.go @@ -2,28 +2,28 @@ package revid import ( "testing" + + "bitbucket.org/ausocean/iot/pi/netsender" ) -func TestAudioInput(t *testing.T) { +func TestAudioInputStart(t *testing.T) { + var logger testLogger + ns, err := netsender.New(&logger, nil, nil, nil) + if err != nil { + t.Errorf("netsender.New failed with error %v", err) + } - // var logger testLogger - // ns, err := netsender.New(&logger, nil, nil, nil) - // if err != nil { - // t.Errorf("netsender.New failed with error %v", err) - // } + var c Config + c.Logger = &logger + c.Input = Audio - // var c Config - // c.Logger = &logger - // c.Input = Audio - // c.Outputs = make([]uint8, 1) + rv, err := New(c, ns) + if err != nil { + t.Errorf("revid.New failed with error %v", err) + } - // rv, err := New(c, ns) - // if err != nil { - // t.Errorf("revid.New failed with error %v", err) - // } - - // err = rv.Start() - // if err != nil { - // t.Errorf("revid.Start failed with error %v", err) - // } + err = rv.Start() + if err != nil { + t.Errorf("revid.Start failed with error %v", err) + } } diff --git a/revid/config.go b/revid/config.go index 7bebf599..d914e221 100644 --- a/revid/config.go +++ b/revid/config.go @@ -164,10 +164,11 @@ const ( defaultExposure = "auto" defaultAutoWhiteBalance = "auto" - defaultSampleRate = 48000 - defaultBitDepth = 16 - defaultChannels = 1 - defaultRecPeriod = 1 + defaultAudioInputCodec = ADPCM + defaultSampleRate = 48000 + defaultBitDepth = 16 + defaultChannels = 1 + defaultRecPeriod = 1 ) // Validate checks for any errors in the config fields and defaults settings @@ -211,10 +212,16 @@ func (c *Config) Validate(r *Revid) error { } case PCM, ADPCM: case NothingDefined: - c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec) - c.InputCodec = defaultInputCodec - c.Logger.Log(logger.Info, pkg+"defaulting quantization", "quantization", defaultQuantization) - c.Quantization = defaultQuantization + switch c.Input { + case Audio: + c.Logger.Log(logger.Info, pkg+"input is audio but no codec defined, defaulting", "inputCodec", defaultAudioInputCodec) + c.InputCodec = defaultAudioInputCodec + default: + c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec) + c.InputCodec = defaultInputCodec + c.Logger.Log(logger.Info, pkg+"defaulting quantization", "quantization", defaultQuantization) + c.Quantization = defaultQuantization + } default: return errors.New("bad input codec defined in config") } @@ -285,6 +292,26 @@ func (c *Config) Validate(r *Revid) error { c.SampleRate = defaultSampleRate } + if c.Channels == 0 { + c.Logger.Log(logger.Info, pkg+"no number of channels defined, defaulting", "Channels", defaultChannels) + c.Channels = defaultChannels + } + + if c.BitDepth == 0 { + c.Logger.Log(logger.Info, pkg+"no bit depth defined, defaulting", "BitDepth", defaultBitDepth) + c.BitDepth = defaultBitDepth + } + + if c.RecPeriod == 0 { + c.Logger.Log(logger.Info, pkg+"no record period defined, defaulting", "recPeriod", defaultRecPeriod) + c.RecPeriod = defaultRecPeriod + } + + if c.WriteRate == 0 { + c.Logger.Log(logger.Info, pkg+"no write rate defined, defaulting", "writeRate", defaultWriteRate) + c.WriteRate = defaultWriteRate + } + if c.Bitrate == 0 { c.Logger.Log(logger.Info, pkg+"no bitrate defined, defaulting", "bitrate", defaultBitrate) c.Bitrate = defaultBitrate