mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 19:58:54 +01:00
audio: Refactoring
This commit is contained in:
parent
04739a7249
commit
637ed0d965
@ -587,9 +587,9 @@ func (p *Player) Pause() error {
|
|||||||
func (p *Player) Current() time.Duration {
|
func (p *Player) Current() time.Duration {
|
||||||
p.m.RLock()
|
p.m.RLock()
|
||||||
sample := p.pos / bytesPerSample / channelNum
|
sample := p.pos / bytesPerSample / channelNum
|
||||||
t := time.Duration(sample) * time.Second / time.Duration(p.sampleRate)
|
|
||||||
p.m.RUnlock()
|
p.m.RUnlock()
|
||||||
return t
|
|
||||||
|
return time.Duration(sample) * time.Second / time.Duration(p.sampleRate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volume returns the current volume of this player [0-1].
|
// Volume returns the current volume of this player [0-1].
|
||||||
@ -603,11 +603,12 @@ func (p *Player) Volume() float64 {
|
|||||||
// SetVolume sets the volume of this player.
|
// SetVolume sets the volume of this player.
|
||||||
// volume must be in between 0 and 1. This function panics otherwise.
|
// volume must be in between 0 and 1. This function panics otherwise.
|
||||||
func (p *Player) SetVolume(volume float64) {
|
func (p *Player) SetVolume(volume float64) {
|
||||||
p.m.Lock()
|
|
||||||
// The condition must be true when volume is NaN.
|
// The condition must be true when volume is NaN.
|
||||||
if !(0 <= volume && volume <= 1) {
|
if !(0 <= volume && volume <= 1) {
|
||||||
panic("audio: volume must be in between 0 and 1")
|
panic("audio: volume must be in between 0 and 1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.m.Lock()
|
||||||
p.volume = volume
|
p.volume = volume
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user