doc: Update

This commit is contained in:
Hajime Hoshi 2017-07-01 17:10:55 +09:00
parent e596271002
commit 6f4f4ed06f
6 changed files with 30 additions and 32 deletions

View File

@ -18,7 +18,7 @@ Note: Gamepad is not available on Safari/Android/iOS. Keyboard is not available
## Features
* 2D Graphics (Geometry/Color matrix transformation, Various composition modes, Offscreen rendering)
* 2D Graphics (Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen)
* Input (Mouse, Keyboard, Gamepads, Touches)
* Audio (MP3, Ogg/Vorbis, WAV, PCM)

View File

@ -47,7 +47,7 @@
<h2 id="features">Features</h2>
<dl class="dl-horizontal">
<dt>2D Graphics</dt>
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering</dd>
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen</dd>
<dt>Input</dt>
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
<dt>Audio</dt>

Binary file not shown.

View File

@ -1,5 +1,14 @@
# License
## classic.mp3
```
https://musopen.org/music/466/johann-sebastian-bach/air-on-the-g-string-from-orchestral-suite-no-3-bwv-1068/
Air on the G String (from Orchestral Suite no. 3, BWV 1068)
Public Domain
```
## jab.wav
```
@ -17,13 +26,6 @@ http://mart.kitunebi.com/music_act.html
Harpie's Feather (ハルピュイアの羽) by Napi
```
## game2.mp3
```
http://mart.kitunebi.com/music_act.html
ノアの羽舟 by Napi
```
## ragtime.ogg

View File

@ -38,7 +38,7 @@ import (
&#34;github.com/hajimehoshi/ebiten&#34;
&#34;github.com/hajimehoshi/ebiten/audio&#34;
&#34;github.com/hajimehoshi/ebiten/audio/vorbis&#34;
&#34;github.com/hajimehoshi/ebiten/audio/mp3&#34;
&#34;github.com/hajimehoshi/ebiten/audio/wav&#34;
&#34;github.com/hajimehoshi/ebiten/ebitenutil&#34;
)
@ -47,7 +47,7 @@ const (
screenWidth = 320
screenHeight = 240
// This sample rate doesn&#39;t match with wav/ogg&#39;s sample rate,
// This sample rate doesn&#39;t match with wav/mp3&#39;s sample rate,
// but decoders adjust them.
sampleRate = 48000
)
@ -101,8 +101,8 @@ type Player struct {
input *Input
audioContext *audio.Context
audioPlayer *audio.Player
current time.Duration
total time.Duration
seekedCh chan error
seBytes []uint8
seCh chan []uint8
volume128 int
@ -126,11 +126,11 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) {
if err != nil {
return nil, err
}
oggF, err := ebitenutil.OpenFile(&#34;_resources/audio/ragtime.ogg&#34;)
mp3F, err := ebitenutil.OpenFile(&#34;_resources/audio/classic.mp3&#34;)
if err != nil {
return nil, err
}
s, err := vorbis.Decode(audioContext, oggF)
s, err := mp3.Decode(audioContext, mp3F)
if err != nil {
return nil, err
}
@ -149,6 +149,9 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) {
volume128: 128,
seCh: make(chan []uint8),
}
if player.total == 0 {
player.total = 1
}
player.audioPlayer.Play()
go func() {
s, err := wav.Decode(audioContext, wavF)
@ -172,14 +175,11 @@ func (p *Player) update() error {
case p.seBytes = &lt;-p.seCh:
close(p.seCh)
p.seCh = nil
case err := &lt;-p.seekedCh:
if err != nil {
return err
}
close(p.seekedCh)
p.seekedCh = nil
default:
}
if p.audioPlayer.IsPlaying() {
p.current = p.audioPlayer.Current()
}
p.updateBar()
p.updatePlayPause()
p.updateSE()
@ -229,9 +229,6 @@ func (p *Player) updatePlayPause() {
}
func (p *Player) updateBar() {
if p.seekedCh != nil {
return
}
if !p.input.isMouseButtonTriggered(ebiten.MouseButtonLeft) {
return
}
@ -246,10 +243,8 @@ func (p *Player) updateBar() {
return
}
pos := time.Duration(x-bx) * p.total / time.Duration(bw)
p.seekedCh = make(chan error, 1)
go func() {
p.seekedCh &lt;- p.audioPlayer.Seek(pos)
}()
p.current = pos
p.audioPlayer.Seek(pos)
}
func (p *Player) close() error {
@ -262,11 +257,9 @@ func (p *Player) draw(screen *ebiten.Image) {
op.GeoM.Translate(float64(x), float64(y))
screen.DrawImage(playerBarImage, op)
currentTimeStr := &#34;00:00&#34;
c := p.audioPlayer.Current()
prev := p.previousPos
p.previousPos = c
// Current Time
c := p.current
m := (c / time.Minute) % 100
s := (c / time.Second) % 60
currentTimeStr = fmt.Sprintf(&#34;%02d:%02d&#34;, m, s)
@ -284,7 +277,10 @@ Press S to toggle Play/Pause
Press P to play SE
Press Z or X to change volume of the music
%s`, ebiten.CurrentFPS(), currentTimeStr)
if p.audioPlayer.IsPlaying() &amp;&amp; prev == c {
current := p.audioPlayer.Current()
prev := p.previousPos
p.previousPos = p.audioPlayer.Current()
if p.audioPlayer.IsPlaying() &amp;&amp; prev == current {
msg &#43;= &#34;\nLoading...&#34;
}
ebitenutil.DebugPrint(screen, msg)

View File

@ -47,7 +47,7 @@
<h2 id="features">Features</h2>
<dl class="dl-horizontal">
<dt>2D Graphics</dt>
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering</dd>
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen</dd>
<dt>Input</dt>
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
<dt>Audio</dt>