Documentation ¶
Overview ¶
Example (RestNote_tempo_0) ¶
buf := restNote('Q', false, 0) fmt.Println("Temp 0:", len(buf))
Output: Temp 0: 26132
Example (RestNote_tempo_6) ¶
buf := restNote('W', false, 6) fmt.Println("Temp 6:", len(buf))
Output: Temp 6: 82904
Index ¶
- Constants
- Variables
- func BatteryLevel() (int, error)
- func CloseSoundDevice()
- func DownloadVoiceFiles(music *Music, writer io.Writer, names []string)
- func FlushSoundBuffer()
- func HertzToFreq(hertz float64) float64
- func HomeDir() string
- func InitSoundDevice() error
- func OpenSoundDevice(device string) error
- func SendBell()
- func StartWebServer(music *Music, address string)
- func StopPlayBack()
- func VariableLengthValue(data []byte) (value int32, byteSize int)
- type Chord
- type Midi
- type MidiChunk
- type MidiEvent
- type Music
- type Note
- type Piano
- type Sheet
- type Sustain
- type Violin
- type Voice
- type WaveHeader
- type Web
Examples ¶
Constants ¶
const ( // MIDI events MidiEventTrack = 0x00 MidiEventMeta = 0xFF MidiEventSystemExclusive1 = 0xF0 MidiEventSystemExclusive2 = 0xF7 // MIDI event types MidiEventTypeSeqNum = 0x00 MidiEventTypeText = 0x01 MidiEventTypeCopyright = 0x02 MidiEventTypeSeqOrTrackName = 0x03 MidiEventTypeInstName = 0x04 MidiEventTypeLyricText = 0x05 MidiEventTypeMarkerText = 0x06 MidiEventTypeCuePoint = 0x07 MidiEventTypeChanPrefix = 0x20 MidiEventTypeEndOfTrack = 0x2F MidiEventTypeTempo = 0x51 MidiEventTypeSMPTEOffset = 0x54 MidiEventTypeTimeSig = 0x58 MidiEventTypeKeySig = 0x59 MidiEventTypeSeqSpecEvent = 0x7F )
const ( // SampleAmp16bit - 16-bit sample amplitude SampleAmp16bit = 32767.0 // SampleRate - sample rate SampleRate = 44100 // SampleRate64 - float64 sample rate SampleRate64 = float64(SampleRate) )
const BeepNotation = `` /* 1846-byte string literal not displayed */
BeepNotation description
Variables ¶
var ( // DemoMusic notation DemoMusic = BuiltinMusic[0].Notation // PrintSheet enables printing beep notation while playing music PrintSheet bool // PrintNotes enables printing each notes while playing music PrintNotes bool )
var BuiltinMusic = []*Sheet{
{
ID: 1,
Name: "mozart-k33b-klavierstuck-in-f.txt",
Dir: "beep",
URL: "http://imslp.org/images/1/15/TN-Mozart%2C_Wofgang_Amadeus-NMA_09_27_Band_02_I_01_KV_33b.jpg",
Notation: `# Mozart K33b
VP SA8 SR9
A9HRDE cc DScszs|DEc DQzDE[|cc DScszs|DEc DQz DE[|vv DSvcsc|DEvs ]v|cc DScszs|VN
A3HLDE [n z, |cHRq HLz, |[n z, |cHRq HLz, |sl z, |]m pb|z, ]m |
A9HRDE cz [c|ss DSsz]z|DEs] ps|DSsz][ z][p|DEpDQ[ [|VN
A3HLDE [n ov|]m [n | pb ic| n, lHRq|HLnc DQ[|
A9HRDE cc DScszs|DEc DQzDE[|cc DScszs|DEc DQz DE[|vv DSvcsc|DEvs ]v|cc DScszs|VN
A3HLDE [n z, |cHRq HLz, |[n z, |cHRq HLz, |sl z, |]m pb|z, ]m |
A9HRDE cz [c|ss DSsz]z|DEs] ps|DSsz][ z][p|DEpDQ[ [|VN
A3HLDE [n ov|]m [n | pb ic| n, lHRq|HLnc DQ[|
A9HRDS DERE] DS][p[ |][p[ ][p[ |DE] DQp DEi|REc DScszs|cszs |cszs|DEcDQzDE[|REv DSvcsc|DEvs ]v|VN
A3HLDE DEcHRq HLvHRw|HLbHRe HLvw|cHRq HLic|[n ]m |z, |]m |zn z, |sl [, |z. DQp |
A9HRDE REc DScszs|DEcz [c|REs DSsz]z|DEs] ps|DSsz][ z][p|DE[DSitDQr|VN
A3HLDE z, ]m |[n ov|]m [n |pb ic|nz sc |DQn [|
A9HRDS DERE] DS][p[ |][p[ ][p[ |DE] DQp DEi|REc DScszs|cszs |cszs|DEcDQzDE[|REv DSvcsc|DEvs ]v|VN
A3HLDE DEcHRq HLvHRw|HLbHRe HLvw|cHRq HLic|[n ]m |z, |]m |zn z, |sl [, |z. DQp |
A9HRDE REc DScszs|DEcz [c|REs DSsz]z|DEs] ps|DSsz][ z][p|DE[DSitDQrRQ|VN
A3HLDE z, ]m |[n ov|]m [n |pb ic|nz sc |DQn [RQ|
`,
},
{
ID: 2,
Name: "passacaglia-handel-halvorsen.txt",
Dir: "beep",
URL: "https://azmusicfest.org/app/uploads/Passacaglia-Handel-Halvorsen-Pianistos-2.pdf",
Notation: `# Passacaglia - Handel Halvorsen
VP T5 SA9 SD9 SS9 SR9
# DQ - 130
A6HRDE RERERERE RERERERE|RERERERE RERERERE|icxc zc]c |[cpc ocic |VN
A4HLDE z,HReq yqeq |HLz,HReq yqeq |HLz,HReq yqeq|HLov,n HRwHLn,n|
# 5
A6HRDE uxzx ]x[x |pxox ixux |yz]z [zpz |oziz uzyz |DQz DEa= DQDDa DEz|VN
A4HLDE pmHRwHL. HRtHL.HRwHL.|icmb HRqHLbmb|[nmHRqHL, HRrHL,HRqHL,|ov,[ HRwHLn,n|pb .k HReHLk .k|
# 10
A6HRDW z |DEcioi pi[i|]izi xici |xuiu oupu |[u]u zuxu |VN
A4HLDE z,HReq yqeq|HLz,HReq yqeq|HLov,n HRwHLn,n|]mHRwHL. HRtHL.HRwHL.|icmb HRqHLbmb|
# 15
A6HRDE zyuy iyoy |py[y ]yzy |DQz DEa= DQDDa DEz|DWz |DEcH7qHR.H7q HR,H7qHRmH7q|VN
A4HLDE pbHRqHL, HRrHL,HRqHL,|ov,n HRwHLn,n|pb .k HReHLk .k|z,HReq yqeq|z,HReq yqeq |
# 20 8
A6HRDE nH7qHRbH7q HRvH7qHRcH7q|HRx.,. m.n. |b.v. c.x. |z,m, n,b, |v,c, x,z, |VN
A4HLDE ov,n HRwHLn,n |pmHRwHL. HRtHL.HRwHL.|icmb HRqHLbmb|[nmHRqHL, HRrHL,HRqHL,|ov,[ HRwHLn,n|
# 25 8
A6HRDQ , DEkj DQDDk DE,|DW, |DEH7qHRcvc bcnc|mc,c .cH7qHRc|.xcx vxbx |VN
A4HLDE pb.k HReHLk .k|z,HReq yqeq|HLz,HReq yqeq|HLov,n HRwHLn,n|]mHRwHL. HRtHL.HRwHL.|
# 30 8
A6HRDE nxmx ,x.x |.zxz czvz |bznz mz,z |DQ, DEkj DQDDk DE,|DW, |VN
A4HLDE icmb HRqHLbmb|pbHRqHL, HRrHL,HRqHL,|ov,n HRwHLn,n|pb .k HReHLk .k|z,HReq yqeq|
# 35
A6HRDE iici xizi|]i[i pioi |uuxu zu]u |[upu ouiu |yyzy ]y[y |VN
A4HLDE z,HReq yqeq|HLov,n HRwHLn,n|pbHRqHL, HRrHL,HRqHL,|icmb HRqHLbmb|pbHRqHL, HRrHL,HRqHL,|
# 40 # 8va---------------------------
A6HRDE pyoy iyuy |DQy DE65 DQDD6 DEy|DWy |DEcH7qHRx. z,]m|[npb ovic |VN
A4HLDE ov,n HRwHLn,n|pb.k HReHLk .k|z,HReq yqeq|HLz,HReq yqeq|HLov,n HRwHLn,n|
# 45 8
A6HRDE x.z, ]m[n|pbov icux |yzt] r[ep |woqi uHL.HRyHL,|HRDQy DE65 DQDD6 DEy|VN
A4HLDE z,HReq yqeq|HLov,n HRwHLn,n|]mHRwHL. HRtHL.HRwHL.|ob,n ,n,n |pb.k HReHLk .k|
# 50
A6HRDW y |DEicxc zc]c|[cpc ocic |uxzx ]x[x |pxox ixux |VN
A4HLDE z,HReq yqeq|HLz,HReq yqeq|HLov,n HRwHLn,n|pmHRwHL. HRtHL.HRwHL.|icmb HRqHLbmb|
# 55
A6HRDE yz]z [zpz |oziz uzyz |DQz DEa= DQDDa DEz|DWz |DEcioi pi[i|VN
A4HLDE [nmHRqHL, HRrHL,HRqHL,|ov,[ HRwHLn,n|pb .k HReHLk .k|z,HReq yqeq|HLz,HReq yqeq|
# 60
A6HRDE ]izi xici |xuiu oupu |[u]u zuxu |zyuy iyoy |py[y ]yzy |VN
A4HLDE ov,n HRwHLn,n|]mHRwHL. HRtHL.HRwHL.|icmb HRqHLbmb|pbHRqHL, HRrHL,HRqHL,|ov,n HRwHLn,n|
# 65
A6HRDQ z DEa= DQDDa DEz |DWz |DEicxc zc]c|[cpc ocic|uxzx ]x[x|VN
A4HLDE pb .k HReHLk .k|z,HReq yqeq|HLDWC2,z |C2vo |C2m] |
# 70
T3
A6HRDE pxox ixux|yz]z [zpz|oziz uzyz|DQz DEa= DQDDa DEz|DWz |VN
A4HLDW C2ci |C2n[ |C2vo |C2bp |C2,z|
`,
},
}
BuiltinMusic stores built-in music scores
Functions ¶
func BatteryLevel ¶ added in v1.0.2
BatteryLevel return battery charge level.
func DownloadVoiceFiles ¶
DownloadVoiceFiles downloads natural voice files
func HertzToFreq ¶
HertzToFreq converts Hertz to frequency unit
func OpenSoundDevice ¶
OpenSoundDevice opens hardware sound device
func StartWebServer ¶
StartWebServer starts beep web server
func VariableLengthValue ¶ added in v1.0.2
VariableLengthValue parses variable length value used in MIDI
Types ¶
type Midi ¶
type Midi struct { Chunks []*MidiChunk Tracks []*MidiChunk // voice tracks Format int Ntracks int // number of tracks TickDiv int // if 15th bit is 0 - (h.m.s.frames) resolution of a quarter note, 1 - metric (bar.beat) Playing bool OutputFile *os.File OutputBuf []int16 // contains filtered or unexported fields }
Midi - MIDI file
type MidiEvent ¶
type MidiEvent struct { Type int Delta int Start int Note *Note // beep note NoteNumber byte // MIDI note number }
MidiEvent - MIDI event
func (*MidiEvent) CalcDuration ¶
CalcDuration calculates duration for ticks
type Music ¶
type Music struct {
// contains filtered or unexported fields
}
Music player
type Note ¶
type Note struct {
// contains filtered or unexported fields
}
Note data
Example (Measure_tempo_3) ¶
note := &Note{ key: 3000 + 'q', volume: 100, amplitude: 9, duration: 'W', dotted: false, tempo: 3, samples: 0, } note.measure() fmt.Println("Temp 3:", note.samples) // samples in a whole note: 90112 // samples in tempo level 3: 90112 + 4% = 93716
Output: Temp 3: 93716
Example (Measure_tempo_9) ¶
note := &Note{ key: 3000 + 'q', volume: 100, amplitude: 9, duration: 'Q', dotted: false, tempo: 9, samples: 0, } note.measure() fmt.Println("Temp 9:", note.samples) // samples in quarter note: 22528 // samples in tempo level 9: 22528 - 20% = 18023
Output: Temp 9: 18023
type Piano ¶
type Piano struct {
// contains filtered or unexported fields
}
Piano voice
func (*Piano) ComputerVoice ¶
ComputerVoice enables or disables computer voice
func (*Piano) SustainNote ¶
SustainNote applies sustain settings to note
type Sheet ¶
type Sheet struct { ID int Name string Dir string Notation string URL string // contains filtered or unexported fields }
Sheet - music sheet
type Violin ¶
type Violin struct {
// contains filtered or unexported fields
}
Violin voice
func (*Violin) SustainNote ¶
SustainNote applies sustain settings to a note
type Voice ¶
type Voice interface { GetNote(note *Note, sustain *Sustain) bool SustainNote(note *Note, sustain *Sustain) Sustain() bool NaturalVoice() bool NaturalVoiceFound() bool ComputerVoice(enable bool) }
Voice interface GetNote: Gets a whole note for the key SustainNote: Used for sustaining computer generated voice Sustain: Indicates whether the instrument sustain note NaturalVoice: Indicates whether natural voice file is loaded ComputerVoice: Enable or disable computer voice
type WaveHeader ¶
type WaveHeader struct { ChunkID string ChunkSize int Format string Subchunk1ID string Subchunk1Size int AudioFormat int NumChannels int SampleRate int ByteRate int BlockAlign int BitsPerSample int Subchunk2ID string Subchunk2Size int // contains filtered or unexported fields }
WaveHeader - WAV file header
func NewWaveHeader ¶
func NewWaveHeader(channels, sampleRate, bitsPerSample, dataSize int) *WaveHeader
NewWaveHeader returns new WAV header
func (*WaveHeader) ReadHeader ¶
func (w *WaveHeader) ReadHeader(reader io.Reader) (int, error)
ReadHeader reads WAV header
func (*WaveHeader) String ¶
func (w *WaveHeader) String() string
func (*WaveHeader) WriteHeader ¶
func (w *WaveHeader) WriteHeader(writer io.Writer) (int, error)
WriteHeader writer WAV header