-
Notifications
You must be signed in to change notification settings - Fork 5
/
equalizer.go
142 lines (118 loc) · 3.33 KB
/
equalizer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"fmt"
"log"
"time"
vlc "github.com/adrg/libvlc-go/v3"
)
func main() {
// Initialize libVLC. Additional command line arguments can be passed in
// to libVLC by specifying them in the Init function.
if err := vlc.Init("--no-video", "--quiet"); err != nil {
log.Fatal(err)
}
defer vlc.Release()
// Get equalizer preset names.
var (
eqPresetNames = vlc.EqualizerPresetNames()
presetIdx uint
)
fmt.Println("Equalizer presets: ")
for i, eqPresetName := range eqPresetNames {
if eqPresetName == "Full bass" {
presetIdx = uint(i)
}
fmt.Printf("#%d: %s\n", i, eqPresetName)
}
fmt.Println("")
// NOTE: in order to get a single equalizer preset, use
// vlc.EqualizerPresetName. Use EqualizerPresetCount to
// obtain the number of available equalizer presets.
// Get equalizer band frequencies.
bandFreqs := vlc.EqualizerBandFrequencies()
fmt.Println("Equalizer band frequencies: ")
for i, bandFreq := range bandFreqs {
fmt.Printf("#%d: %.2f\n", i, bandFreq)
}
fmt.Println("")
// NOTE: in order to get a single band frequency, use
// vlc.EqualizerBandFrequency. Use EqualizerBandCount
// to obtain the number of available equalizer bands.
// Create a new equalizer from a preset.
// If you want to start from scratch, use vlc.NewEqualizer.
equalizer, err := vlc.NewEqualizerFromPreset(presetIdx)
if err != nil {
log.Fatal(err)
}
defer equalizer.Release()
// Get and set preamplification value.
preAmp, err := equalizer.PreampValue()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Preamp value: %.2f\n", preAmp)
if err := equalizer.SetPreampValue(preAmp - 3); err != nil {
log.Fatal(err)
}
// Get and set individidual amplification values for the
// equalizer frequency bands.
bandCount := vlc.EqualizerBandCount()
for i := uint(0); i < bandCount; i++ {
bandFreq, err := equalizer.AmpValueAtIndex(i)
if err != nil {
log.Fatal(err)
}
fmt.Printf("#%d (%.2f): %.2f\n", i, bandFreqs[i], bandFreq)
if err := equalizer.SetAmpValueAtIndex(bandFreq+float64(i), i); err != nil {
log.Fatal(err)
}
}
fmt.Println("")
// Create a new player.
player, err := vlc.NewPlayer()
if err != nil {
log.Fatal(err)
}
defer func() {
player.Stop()
player.Release()
}()
// Add a media file from path or from URL.
// Set player media from path:
// media, err := player.LoadMediaFromPath("localpath/test.mp4")
// Set player media from URL:
media, err := player.LoadMediaFromURL("http://stream-uk1.radioparadise.com/mp3-32")
if err != nil {
log.Fatal(err)
}
defer media.Release()
if err := player.SetEqualizer(equalizer); err != nil {
log.Fatal(err)
}
// Retrieve player event manager.
manager, err := player.EventManager()
if err != nil {
log.Fatal(err)
}
// Register the media end reached event with the event manager.
quit := make(chan struct{})
eventCallback := func(event vlc.Event, userData interface{}) {
close(quit)
}
eventID, err := manager.Attach(vlc.MediaPlayerEndReached, eventCallback, nil)
if err != nil {
log.Fatal(err)
}
defer manager.Detach(eventID)
// Start playing the media.
if err = player.Play(); err != nil {
log.Fatal(err)
}
// Revert to the default equalizer.
time.Sleep(time.Duration(10) * time.Second)
if err := player.SetEqualizer(nil); err != nil {
log.Fatal(err)
}
fmt.Println("Reverted to the default equalizer settings")
<-quit
}