sound

package
v0.0.0-...-5d1b788 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INPUT  = 1
	OUTPUT = 2
)
View Source
const (
	MONO   = 1
	STEREO = 2
)
View Source
const (
	LEFT  = 1
	RIGHT = 2
)
View Source
const (
	EDEVICE    = 1
	ECHANNEL   = 2
	EFREQ      = 3
	EMONO      = 4
	ESTEREO    = 5
	EAMPLITUDE = 6
	EFUNCTION  = 7
	EINTERNAL  = 8
)

Errorcodes

Variables

View Source
var ChName = map[int]string{
	LEFT:  "LEFT",
	RIGHT: "RIGHT",
}
View Source
var ChValue = map[string]int{
	"LEFT":  LEFT,
	"RIGHT": RIGHT,
}
View Source
var ErrorDescription = map[int]string{
	EDEVICE:    "Unknown Device",
	ECHANNEL:   "Channel unknown, not defined or contains invalid data",
	EFREQ:      "Invalid Frequency",
	EMONO:      "A Mono Stream takes exactly one Channel",
	ESTEREO:    "A Stereo Stream takes exactly two Channels",
	EAMPLITUDE: "Invalid Amplitude",
	EFUNCTION:  "Test Function does not exist",
	EINTERNAL:  "Internal Error",
}

map containing the description of the Errorcode

View Source
var ErrorName = map[int]string{
	EDEVICE:    "EDEVICE",
	ECHANNEL:   "ECHANNEL",
	EFREQ:      "EFREQ",
	EMONO:      "EMONO",
	ESTEREO:    "ESTEREO",
	EAMPLITUDE: "EAMPLITUDE",
	EFUNCTION:  "EFUNCTION",
	EINTERNAL:  "EINTERNAL",
}

map containing the string representation of the Errorcode

Functions

func CalcGoertzel

func CalcGoertzel(freq float64, samplingRate float64, samples MonoSamples) float64

CalcGoertzel calculates the power for a given frequency in a MonoSample. The Goertzel Algorithm requires much less CPU cycles than calculating the sprectrum power density through an FFT. For more details on the Goertzel Filter check out: https://courses.cs.washington.edu/courses/cse466/12au/calendar/Goertzel-EETimes.pdf

func CalculateAverage

func CalculateAverage(slice []float64) (float64, error)

CalculateAverage calculates the mean value over a slice of float64 values

Types

type AudioStream

type AudioStream struct {
	DeviceName      string
	Direction       int
	Samplingrate    float64
	Channels        map[int]Channel
	FramesPerBuffer int

	Out PlayI
	In  RecordI
	// contains filtered or unexported fields
}

AudioStream contains all data necessary to play/record data from an audio device (sound card)

func (*AudioStream) Close

func (as *AudioStream) Close()

Close the Audiostream

func (*AudioStream) Initialize

func (as *AudioStream) Initialize() error

Initialize the Audiostream and open it

func (*AudioStream) Start

func (as *AudioStream) Start() error

Start the Audiostream

func (*AudioStream) Stop

func (as *AudioStream) Stop() error

Stop the Audiostream

type Channel

type Channel struct {
	AudioChId int
	Tones     Tones
}

type MonoSamples

type MonoSamples []Sample

type NoiseOut

type NoiseOut struct {
	Left  bool
	Right bool
}

func (*NoiseOut) Process

func (no *NoiseOut) Process(out interface{})

Process generates a random noise func (no *NoiseOut) Process(out StereoSamples) {

type PlayI

type PlayI interface {
	// Process(StereoSamples)
	Process(interface{})
}

PlayI is the interface that must be implemented to play audio on a local soundcard

type RecordI

type RecordI interface {
	Process(interface{})
	GetData() []StereoSamples
}

RecordI is the interface that must be implemented to record from a local soundcard

type Recorder

type Recorder struct {
	Samples []StereoSamples
}

Recorder holds the recorded StereoSamples

func (*Recorder) GetData

func (rec *Recorder) GetData() []StereoSamples

GetData returns the slice of recorded StereoSamples

func (*Recorder) Process

func (rec *Recorder) Process(in interface{})

Process writes the Audio samples into Memory

type Sample

type Sample float32

type SinusOut

type SinusOut struct {
	TonesL Tones
	TonesR Tones
	StepL  float64
	StepR  float64
	// contains filtered or unexported fields
}

func (*SinusOut) Process

func (so *SinusOut) Process(out interface{})

Process generates a sinewave func (so *SinusOut) Process(out StereoSamples) {

func (*SinusOut) Setup

func (so *SinusOut) Setup(samplingrate float64)

type SoundbenchError

type SoundbenchError struct {
	Errorcode      int
	Unit           string
	AdditionalInfo string
}

func (*SoundbenchError) Error

func (e *SoundbenchError) Error() string

type StereoSamples

type StereoSamples [][]Sample

type Tone

type Tone struct {
	Frequency float64
	Amplitude float64
}

type Tones

type Tones []Tone

Jump to

Keyboard shortcuts

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