Documentation ¶
Index ¶
- Constants
- func CalculateFrequency(note int) float32
- func CalculateFrequencyStr(note string) (float32, error)
- func DriverFunction(driver Driver, sampleRate int, quitWhenDone bool, exitChannel chan bool) func([][]float32)
- func NoteToInt(note string) (int, error)
- func NoteToString(note int) string
- func RunSynth(driver Driver, errChannel chan error, quitWhenDone bool, exitChannel chan bool)
- func StartSynth(noteChannel chan DelayedNoteData) error
- func StartSynthAsync(iNoteChannel chan DelayedNoteData, iQuitChannel chan bool, ...)
- func StartSynthAsyncWith(na *NoteArrangement, iNoteChannel chan DelayedNoteData, ...)
- func StartSynthWith(na *NoteArrangement, iNoteChannel chan DelayedNoteData, quitWhenDone bool) error
- type DelayedNoteData
- type Driver
- type NoteArrangement
- type NoteData
- type Overtone
- type PrimaryDriver
- func (pd *PrimaryDriver) AddDelayedNote(dnd DelayedNoteData)
- func (pd *PrimaryDriver) CalculateDuration() time.Duration
- func (pd *PrimaryDriver) CalculateOutput() []float32
- func (pd *PrimaryDriver) Finished() bool
- func (pd *PrimaryDriver) OutputChannels() int
- func (pd *PrimaryDriver) StepPhases(sampleRate int)
- type RawDelayedNoteData
- type SingleDriver
Constants ¶
const A4 float32 = 440
The base note to be used for the other calculations.
const A4I int = 57
Variables ¶
This section is empty.
Functions ¶
func CalculateFrequency ¶
Calculating the frequency of a given note.
func CalculateFrequencyStr ¶
Calculating the frequency of a given note from its string representation.
func DriverFunction ¶
func DriverFunction(driver Driver, sampleRate int, quitWhenDone bool, exitChannel chan bool) func([][]float32)
Returning a function to drive music synthesis given a driver and a sample rate.
func NoteToInt ¶
Converting the string-representation of a note to the int-representation of a note.
func NoteToString ¶
Converting the int-representation of a note to the string-representation of a note.
func StartSynth ¶
func StartSynth(noteChannel chan DelayedNoteData) error
Starting the synth with a channel for note data.
func StartSynthAsync ¶
func StartSynthAsync(iNoteChannel chan DelayedNoteData, iQuitChannel chan bool, oErrChannel chan error)
The function to start a synth with the intent of being asynchronous.
iNoteChannel - A channel to provide note data. iQuitChannel - A channel to query for an external exit signal. oErrChannel - A channel to send out error information to the calling
function.
func StartSynthAsyncWith ¶
func StartSynthAsyncWith(na *NoteArrangement, iNoteChannel chan DelayedNoteData, ioQuitChannel chan bool, oErrChannel chan error, quitWhenDone bool)
The function to start a synth with the intent of being asynchronous WITH a given slice of starting notes.
na - The slice of notes to play. iNoteChannel - A channel to provide note data. iQuitChannel - A channel to query for an external exit signal. oErrChannel - A channel to send out error information to the calling
function.
func StartSynthWith ¶
func StartSynthWith(na *NoteArrangement, iNoteChannel chan DelayedNoteData, quitWhenDone bool) error
Starting a synth with a beginning note arrangement.
Types ¶
type DelayedNoteData ¶
Type DelayedNoteData is a container that houses the delay and the note data for a given note.
func MakeNoteData ¶
func MakeNoteData(rdnd RawDelayedNoteData) (DelayedNoteData, error)
Constructing a single piece of DelayedNoteData from its corresponding RawDelayedNoteData.
type Driver ¶
type Driver interface { // Calculating the time in seconds that this driver should be running. CalculateDuration() time.Duration // Getting the number of output channels this driver is expecting. OutputChannels() int // Calculating the output on whatever set of channels for a given driver. CalculateOutput() []float32 // Finding out if a driver is finished playing. Finished() bool // Stepping the internal phases given a sample rate. StepPhases(int) }
Type Driver is an interface to define the required behavior for a data structure that can be used in driving PortAudio music synthesis.
type NoteArrangement ¶
type NoteArrangement []DelayedNoteData
Type NoteArrangement is a synonym for an array of structs, one being the delay from the last note, the other being the associaed NoteData for this note.
func EmptyNoteArrangement ¶
func EmptyNoteArrangement() *NoteArrangement
Creating an empty NoteArrangement.
func MakeNoteArrangement ¶
func MakeNoteArrangement(rdnds []RawDelayedNoteData) (*NoteArrangement, error)
Creating a NoteArrangement from a []RawDelayedNoteData
type NoteData ¶
type NoteData struct { Duration float32 Volume float32 Frequency float32 FadeFunc func(float32, float32) float32 Overtones []Overtone }
Type NoteData represents the information necessary to play a single note from a given instrument.
func GuitarNote ¶
Creating a NoteData from a guitar note.
type Overtone ¶
Type Overtone represents a relationship to a primary not that is some multiplier on the note's frequency with a given volume.
type PrimaryDriver ¶
type PrimaryDriver struct { QueuedNotes []DelayedNoteData // The list of NoteDatas to add. CurrentNotes []*SingleDriver // The list of current SingleDrivers. Time float32 // The current time of the PrimaryDriver. LastTime float32 // The time that the last SingleDriver was added. }
The primary driver that is used by the rest of the program by default to start whichever synth.
func NewPrimaryDriver ¶
func NewPrimaryDriver(queuedNotes []DelayedNoteData) *PrimaryDriver
Creating a PrimaryDriver from existent data.
func NewPrimaryDriverEmpty ¶
func NewPrimaryDriverEmpty() *PrimaryDriver
Creating a PrimaryDriver with no information inside yet.
func (*PrimaryDriver) AddDelayedNote ¶
func (pd *PrimaryDriver) AddDelayedNote(dnd DelayedNoteData)
Trying to add a new DelayedNoteData to the list of queued notes inside of a PrimaryDriver.
func (*PrimaryDriver) CalculateDuration ¶
func (pd *PrimaryDriver) CalculateDuration() time.Duration
Calculating the time in seconds that this driver should be running.
func (*PrimaryDriver) CalculateOutput ¶
func (pd *PrimaryDriver) CalculateOutput() []float32
Calculating the output on whatever set of channels for a given driver.
func (*PrimaryDriver) Finished ¶
func (pd *PrimaryDriver) Finished() bool
Finding out if a driver is finished playing.
func (*PrimaryDriver) OutputChannels ¶
func (pd *PrimaryDriver) OutputChannels() int
Getting the number of output channels this driver is expecting.
func (*PrimaryDriver) StepPhases ¶
func (pd *PrimaryDriver) StepPhases(sampleRate int)
Stepping the internal phases given a sample rate.
type RawDelayedNoteData ¶
type RawDelayedNoteData struct { Delay float32 `json:"delay"` Note string `json:"note"` Duration float32 `json:"duration"` Instrument string `json:"instrument"` }
Type RawDelayedNoteData is raw data from a message that can be converted into DelayedNoteData after decoding its JSON.
type SingleDriver ¶
type SingleDriver struct { Note NoteData // The data for this note. Phases []float32 // The current phase of the driver. Time float32 // The current time of the SingleDriver. StartTime float32 // The time this driver was started - if used without a PrimaryDriver it will always be 0. }
The driver to play a single note for a given duration.
func NewSingleDriver ¶
func NewSingleDriver(nd NoteData) *SingleDriver
Creating a new SingleDriver from a given NoteData.
func NewSingleDriverChild ¶
func NewSingleDriverChild(nd NoteData, startTime float32) *SingleDriver
Creating a new SingleDriver to be used as a player inside of a PrimaryDriver from a given NoteData.
func (*SingleDriver) CalculateDuration ¶
func (sd *SingleDriver) CalculateDuration() time.Duration
Calculating the time in seconds that this driver should be running.
func (*SingleDriver) CalculateOutput ¶
func (sd *SingleDriver) CalculateOutput() []float32
Calculating the output on whatever set of channels for a given driver.
func (*SingleDriver) Finished ¶
func (sd *SingleDriver) Finished() bool
Finding out if a driver is finished playing.
func (*SingleDriver) OutputChannels ¶
func (sd *SingleDriver) OutputChannels() int
Getting the number of output channels this driver is expecting.
func (*SingleDriver) StepPhases ¶
func (sd *SingleDriver) StepPhases(sampleRate int)
Stepping the internal phases given a sample rate.