audio

package
v0.0.0-...-c66ceb2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AudioCmd = &cobra.Command{
	Use:   "audio",
	Short: "A brief description of your command",
	Long:  ``,
}

AudioCmd represents the audio/audio command

View Source
var DeviceCmd = &cobra.Command{
	Use:   "devices",
	Short: "Prints info about all devices",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		devices, err := portaudio.Devices()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		fmt.Printf("Found %d devices. \n", len(devices))
		if len(devices) == 0 {
			return
		}

		fmt.Println("\n\nID Name Input Output SampleRate")

		for i, device := range devices {
			fmt.Printf("%v ", i)
			printDevice(device)
		}

		fmt.Println("\n\nDefault input device: ")
		defaultInputDevice, err := portaudio.DefaultInputDevice()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		printDevice(defaultInputDevice)

		fmt.Println("\n\nDefault output device: ")
		defaultOutputDevice, err := portaudio.DefaultOutputDevice()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		printDevice(defaultOutputDevice)
	},
}

DeviceCmd represents the Devices command

View Source
var DumpInputCmd = &cobra.Command{
	Use:   "dump-input",
	Short: "Dumps the audio input of a device to console",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		buf := make([]float32, averageSamples)
		s, err := portaudio.OpenDefaultStream(1, 0, sampleRate, len(buf), buf)
		if err != nil {
			panic(err)
		}
		defer func() {
			if err := s.Close(); err != nil {
				log.Fatal(err)
			}
		}()

		if err := s.Start(); err != nil {
			panic(err)
		}
		defer func() {
			if err := s.Stop(); err != nil {
				log.Fatal(err)
			}
		}()

		var frame int64
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, os.Interrupt)

		fmt.Println("Started listener, dumping input.")

		for {
			if err := s.Read(); err != nil {
				panic(err)
			}

			go calcAverage(frame, buf)
			frame++

			select {
			case <-c:
				fmt.Println("cancelled.")
				return
			default:
			}
		}
	},
}

DumpInputCmd represents the DumpInputs command

View Source
var SineCmd = &cobra.Command{
	Use:   "sine",
	Short: "Creates a sin curved audio",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		s := newStereoSine(float64(frequency), sampleRate)
		defer func() {
			if err := s.Close(); err != nil {
				log.Fatal(err)
			}
		}()

		if err := s.Start(); err != nil {
			panic(err)
		}
		defer func() {
			if err := s.Stop(); err != nil {
				log.Fatal(err)
			}
		}()

		time.Sleep(time.Duration(length) * time.Millisecond)
	},
}

SineCmd represents the Sines command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL