Skip to content

Commit 71b4d29

Browse files
Maximilian BruneMaximilian Brune
authored andcommitted
Added Buffering and Removed some useless stuff
1 parent dd90e30 commit 71b4d29

File tree

8 files changed

+280
-176
lines changed

8 files changed

+280
-176
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ mumble library written in go. Intended for writing client side music bots.
1010
## Features
1111
- you can play youtube videos (without any additional dependency)
1212
- it automatically uses UDP for sending audio data
13+
- Buffering, so no disruptions in hearing "should" occur
1314

1415
## TODO
15-
- implement buffering in the audiohandler.go (currently no "real" buffering exists which sometimes lead to short "disruptions" while hearing the music
1616
- implement more than just youtube videos as source for music
1717

1818
## Notes

gomble/audioformats/opus.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,24 @@ import "unsafe"
1919
import "errors"
2020
import "strconv"
2121

22+
// Possible constants to use
2223
const (
2324
// Best for most VoIP/videoconference applications where listening quality and intelligibility matter most
24-
OpusApplicationVoip = 2048
25+
OPUS_APPICATION_VOIP = 2048
2526

2627
// Best for broadcast/high-fidelity application where the decoded audio sho uld be as close as possible to the input
27-
OpusApplicationAudio = 2049
28+
OPUS_APPLICATION_VOICE = 2049
2829

2930
// Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used.
30-
OpusApplicationRestrictedLowdelay = 2051
31-
)
31+
OPUS_APPLICATION_RESTRICTEDLOWDELAY = 2051
3232

33-
const (
3433
// Signal being encoded is voice
35-
OpusSignalVoice = 3001
34+
OPUS_SIGNAL_VOICE = 3001
3635
// Signal being encoded is music
37-
OpusSignalMusic = 3002
36+
OPUS_SIGNAL_MUSIC = 3002
3837
)
3938

40-
// Constants for encoding to opus
39+
// Settings for encoding to opus
4140
const (
4241
// samplerate of 48kHz is opus default setting
4342
OPUS_SAMPLE_RATE = 48000
@@ -59,7 +58,7 @@ const (
5958
//OPUS_MAX_PACKET_SIZE = 1275
6059

6160
// The Application to use for opus. libopus will automatically
62-
OPUS_APPLICATION = OpusApplicationAudio
61+
OPUS_APPLICATION = OPUS_APPLICATION_VOICE
6362

6463
// Variable Bit Rate, if set to one libopus will automatically change the bitrate as it sees fit.
6564
OPUS_VBR = 0

gomble/audiohandler.go

Lines changed: 0 additions & 111 deletions
This file was deleted.

gomble/container/mediaContainer.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

gomble/event.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package gomble
22

3-
import "github.com/CodingVoid/gomble/gomble/audiosources"
4-
5-
// I need a base type.
63
type event interface {
74
}
85

@@ -17,23 +14,25 @@ type ChannelMessageReceivedEvent struct {
1714
Message string
1815
}
1916

20-
// Track related
17+
// Track got interrupted/stopped by user
18+
type TrackStoppedEvent struct {
19+
Track *Track
20+
}
2121

22-
// Reasons why track ended playing
23-
type TrackEndedReason int
22+
// Track got paused
23+
type TrackPausedEvent struct {
24+
Track *Track
25+
}
2426

25-
const (
26-
// Track got interrupted by user
27-
TRACK_INTERRUPTED = iota
28-
// Track ended playing because Track was over
29-
TRACK_ENDED
30-
// Some other failure occurred. The Logs should be checked for further Information
31-
TRACK_OTHER
32-
)
27+
// Track Finished playing
28+
type TrackFinishedEvent struct {
29+
Track *Track
30+
}
3331

34-
type TrackEndedEvent struct {
35-
Track audiosources.Audiosource
36-
Reason TrackEndedReason
32+
// Some other failure occurred. The Logs should be checked for further Information
33+
type TrackExceptionEvent struct {
34+
Track *Track
35+
err error
3736
}
3837

3938
/* Audiosource/Track related stuff

gomble/eventhandler.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ var Listener listener
1818
type listener struct {
1919
OnPrivateMessageReceived func(e PrivateMessageReceivedEvent)
2020
OnChannelMessageReceived func(e ChannelMessageReceivedEvent)
21-
OnTrackEnded func(e TrackEndedEvent)
21+
OnTrackPaused func(e TrackPausedEvent)
22+
OnTrackStopped func(e TrackStoppedEvent)
23+
OnTrackException func(e TrackExceptionEvent)
24+
OnTrackFinished func(e TrackFinishedEvent)
2225
}
2326

2427
// conn is our tcp connection to the server. It is used by packagereader.go to read packages from mumble-server and by packagewriter to write packages to the mumble-server.
@@ -103,19 +106,34 @@ func eventRoutine() {
103106
for e := range eventpuffer {
104107
switch e.(type) {
105108
case PrivateMessageReceivedEvent:
106-
logger.Debugf("Received Private Message Received event\n")
109+
logger.Debugf("Received PrivateMessageReceivedEvent\n")
107110
if Listener.OnPrivateMessageReceived != nil {
108111
Listener.OnPrivateMessageReceived(e.(PrivateMessageReceivedEvent))
109112
}
110113
case ChannelMessageReceivedEvent:
111-
logger.Debugf("Received Channel Message Received event\n")
114+
logger.Debugf("Received ChannelMessageReceivedEvent\n")
112115
if Listener.OnChannelMessageReceived != nil {
113116
Listener.OnChannelMessageReceived(e.(ChannelMessageReceivedEvent))
114117
}
115-
case TrackEndedEvent:
116-
logger.Debugf("Received TrackEndedEvent\n")
117-
if Listener.OnTrackEnded != nil {
118-
Listener.OnTrackEnded(e.(TrackEndedEvent))
118+
case TrackFinishedEvent:
119+
logger.Debugf("Received TrackFinishedEvent\n")
120+
if Listener.OnTrackFinished != nil {
121+
Listener.OnTrackFinished(e.(TrackFinishedEvent))
122+
}
123+
case TrackPausedEvent:
124+
logger.Debugf("Received TrackPausedEvent\n")
125+
if Listener.OnTrackPaused != nil {
126+
Listener.OnTrackPaused(e.(TrackPausedEvent))
127+
}
128+
case TrackStoppedEvent:
129+
logger.Debugf("Received TrackStoppedEvent\n")
130+
if Listener.OnTrackStopped != nil {
131+
Listener.OnTrackStopped(e.(TrackStoppedEvent))
132+
}
133+
case TrackExceptionEvent:
134+
logger.Debugf("Received TrackExceptionEvent\n")
135+
if Listener.OnTrackException != nil {
136+
Listener.OnTrackException(e.(TrackExceptionEvent))
119137
}
120138
default:
121139
logger.Errorf("Received unknown Event\n")

0 commit comments

Comments
 (0)