core

package module
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

README

eridol-core-go

Module eridol-core-go provides a basic interface to build an eridol implementation. It provides oscillators and FFT suited for Eridol, so you don't have to worry about what "hearing" or "playing" a note means exactly.

Getting Started

You should read through the docs.

The following example program keeps ownership of octave 2 by playing the counter-claim tone.

	core.Run(func(heard core.Heard) (stop bool) {
			// check if someone is playing the claim tone
			isSomeoneClaiming := heard.Octaves[2].Claim

			// if someone is claiming play the counter claim tone
			core.Synth(2).SetNoteImmediately(core.CounterClaim, isSomeoneClaiming)

			// never stop running
			return false
		})

Documentation

Index

Constants

View Source
const OctaveCount = 6

Variables

This section is empty.

Functions

func DisableLogging added in v1.1.2

func DisableLogging()

Disables logging from miniaudio and eridol-core.

func DisableVisualization added in v1.1.2

func DisableVisualization()

Disables the visualization of FFT data.

func EnableLogging added in v1.1.2

func EnableLogging()

Enables logging from miniaudio and eridol-core.

func EnableVisualization added in v1.1.2

func EnableVisualization(octave int)

Shows the visualization of FFT data for an octave. Only one octave can be visable at a time.

func Run added in v1.1.0

func Run(callback UserCallback) error

Runs the callback every time new note data is avalable for at least one octave. Will not return until the callback returns true to stop. If you want raw sound data use RunWithRawSound(). If you want to set the threshold for note detection, use RunWithThreshold().

func RunWithRawSound added in v1.1.0

func RunWithRawSound(callback UserCallbackRaw) error

Runs the callback every time new sound data is avalable fo r at least one octave. Sound data is just raw numbers for the loudness of each note, as well as background noise. Will not return until the callback returns true to stop. If you want analyzed note data use Run().

func RunWithThreshold added in v1.1.7

func RunWithThreshold(callback UserCallback, signalThreshold float32) error

Runs the callback every time new note data is avalable for at least one octave. The sensativity to detecting notes can be set with signalThreshold. If the sensativity is too low it may detect false positives, if it's too high it won't be able to hear quite notes. Will not return until the callback returns true to stop. The default threshould used by Run() is 4, use that if you want a safe value.

Types

type Heard added in v1.1.0

type Heard struct {
	Octaves         [OctaveCount]Notes
	IsOctaveChanged [OctaveCount]bool
	TimeRunning     time.Duration
}

The results of eridol analyzing sound from the microphone. Contains boolean values for if each note is declared as playing or not playing

type HeardRaw added in v1.1.0

type HeardRaw struct {
	Octaves         [OctaveCount]RawSound
	IsOctaveChanged [OctaveCount]bool
	TimeRunning     time.Duration
}

The results of eridol analyzing sound from the microphone. Contains raw numbers for the loudness of each note, as well as background noise.

type Note

type Note int

An enum for each single note, including the claim and counter-claim tones.

const (
	B Note = iota
	Ds
	Fs
	A
	Claim
	CounterClaim
)

type Notes

type Notes struct {
	B            bool
	Ds           bool
	Fs           bool
	A            bool
	Claim        bool
	CounterClaim bool
}

A set of notes, including the claim and counter-claim tones. Each is set as on (true) or off (false).

func (Notes) Intersection added in v1.1.4

func (a Notes) Intersection(b Notes) Notes

Returns the intersection of both sets of notes. An output note will be playing if it is playing in both input sets.

func (Notes) IsEqual added in v1.1.9

func (a Notes) IsEqual(b Notes) bool

Returns true if note sets are exactly equal.

func (Notes) IsEqualWithoutTones added in v1.1.9

func (a Notes) IsEqualWithoutTones(b Notes) bool

Returns true if note sets are equal, ignoring the claim and counter-claim tones which may be different.

func (Notes) Set

func (notes Notes) Set(note Note, playing bool) Notes

Returns the set with one note set to the playing argument.

func (Notes) Union added in v1.1.0

func (a Notes) Union(b Notes) Notes

Returns the union of both sets of notes. An output note will be playing if it is playing in either input set.

func (Notes) With

func (notes Notes) With(note Note) Notes

Returns the set of notes with one note set to playing.

func (Notes) Without

func (notes Notes) Without(note Note) Notes

Returns the set of notes with one note set to not playing.

type RawSound added in v1.1.0

type RawSound struct {
	B                 float32
	Ds                float32
	Fs                float32
	A                 float32
	Claim             float32
	CounterClaim      float32
	BNoise            float32
	DsNoise           float32
	FsNoise           float32
	ANoise            float32
	ClaimNoise        float32
	CounterClaimNoise float32
	BackgroundNoise   float32
}

The raw sound data heard as float point loudnesses. Background noise around each note, and on average in the whole octave is also included.

func (RawSound) Add added in v1.1.0

func (a RawSound) Add(b RawSound) RawSound

Adds two raw noises element-wise and returns the sum.

func (RawSound) Scale added in v1.1.0

func (a RawSound) Scale(b float32) RawSound

Scales each element in a raw noise and returns it.

type SynthHandle added in v1.1.10

type SynthHandle struct {
	// contains filtered or unexported fields
}

A handle to planned Synth notes, allows them to be cancled later with CancelPlansFrom().

func (SynthHandle) CancelPlansFrom added in v1.1.10

func (handle SynthHandle) CancelPlansFrom()

Cancels any planned notes from the handle onwards. Notes started with synth.PlayNoteImmediately() will continue regardless until stopped with synthStopNoteImmediately().

func (SynthHandle) IsDone added in v1.1.10

func (handle SynthHandle) IsDone() bool

Returns true if all the handle's sound is done playing.

func (SynthHandle) OnDone added in v1.1.11

func (handle SynthHandle) OnDone(callback func()) bool

type Synthesizer added in v1.1.0

type Synthesizer struct {
	// contains filtered or unexported fields
}

Creates sound output for one octave by playing the necessary notes.

func Synth added in v1.1.0

func Synth(n int) *Synthesizer

Returns the synthesizer for the octave Nth octave. This synth is the same for the entire life of the program.

func (*Synthesizer) CancelAllPlans added in v1.1.0

func (synth *Synthesizer) CancelAllPlans()

Cancels all planned notes and delays. Notes started with PlayNoteImmediately() will continue regardless until stopped with StopNoteImmediately().

func (*Synthesizer) IsAllDone added in v1.1.9

func (synth *Synthesizer) IsAllDone() bool

Returns true if all planned sounds are done playing.

func (*Synthesizer) OnAllDone added in v1.1.12

func (synth *Synthesizer) OnAllDone(callback func())

func (*Synthesizer) PlanDelay added in v1.1.0

func (synth *Synthesizer) PlanDelay(duration time.Duration) (handle SynthHandle)

Plans a silent delay after any existing planned notes. This is the same as running PlanNotes() with an empty set of notes. Notes started with PlayNoteImmediately() will continue regardless until stopped with StopNoteImmediately(). Returns a handle to cancel this later.

func (*Synthesizer) PlanNotes added in v1.1.0

func (synth *Synthesizer) PlanNotes(notes Notes, duration time.Duration) (handle SynthHandle)

Plans to play notes for a set duration Will run after any already planned notes, or otherwise as soon as possible. Notes started with PlayNoteImmediately() will continue regardless until stopped with StopNoteImmediately(). Returns a handle to cancel this later.

func (*Synthesizer) PlanTimeRemaining added in v1.1.0

func (synth *Synthesizer) PlanTimeRemaining() time.Duration

Returns the amount of time remaining in the current series of planned notes. Includes any trailing silences that have been planned.

func (*Synthesizer) PlayNoteImmediately added in v1.1.0

func (synth *Synthesizer) PlayNoteImmediately(note Note)

Starts playing a single note as soon as possible. The note will continue to play regardless of planned notes until stopped.

func (*Synthesizer) SetNoteImmediately added in v1.1.0

func (synth *Synthesizer) SetNoteImmediately(note Note, playing bool)

Sets if an immediate note should be playing or note. If a note is set to playing it will continue to play regardless of planned notes until stopped.

func (*Synthesizer) SetNotesImmediately added in v1.1.0

func (synth *Synthesizer) SetNotesImmediately(notes Notes)

Sets if every note should immediately be playing or not For each note set to playing, it will continue to play regardless of planned notes until stopped.

func (*Synthesizer) Silence added in v1.1.0

func (synth *Synthesizer) Silence()

Silences everything, stopping immediate notes and canceling all planned notes.

func (*Synthesizer) StopNoteImmediately added in v1.1.0

func (synth *Synthesizer) StopNoteImmediately(note Note)

Stops a note already set to be playing immediately. Does not affect planned notes in any way.

type UserCallback added in v1.1.0

type UserCallback func(heard Heard) (stop bool)

The callback type implemented by the user if they want processed notes.

type UserCallbackRaw added in v1.1.0

type UserCallbackRaw func(heard HeardRaw) (stop bool)

The callback type implemented by the user if they want raw sound data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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