audio: Move to exa/audio

This commit is contained in:
Hajime Hoshi 2015-01-23 23:04:56 +09:00
parent 88ac129dd6
commit d020824b3a
2 changed files with 11 additions and 10 deletions

View File

@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/exp/audio"
"log" "log"
) )
@ -54,7 +55,7 @@ func square(out []float32, volume float64, freq float64, sequence float64) {
} }
return return
} }
length := int(float64(ebiten.AudioSampleRate()) / freq) length := int(float64(audio.SampleRate()) / freq)
if length == 0 { if length == 0 {
panic("invalid freq") panic("invalid freq")
} }
@ -68,7 +69,7 @@ func square(out []float32, volume float64, freq float64, sequence float64) {
} }
func addNote() { func addNote() {
size := ebiten.AudioSampleRate() / 60 size := audio.SampleRate() / 60
notes := []float64{freqC, freqD, freqE, freqF, freqG, freqA * 2, freqB * 2} notes := []float64{freqC, freqD, freqE, freqF, freqG, freqA * 2, freqB * 2}
defer func() { defer func() {
@ -92,10 +93,10 @@ func addNote() {
default: default:
freq = notes[note-'C'] freq = notes[note-'C']
} }
vol := 1.0 / 32.0 vol := 1.0 / 16.0
square(l, vol, freq, 0.5) square(l, vol, freq, 0.25)
square(r, vol, freq, 0.5) square(r, vol, freq, 0.25)
ebiten.AppendToAudioBuffer(0, l, r) audio.AppendToBuffer(0, l, r)
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {

View File

@ -12,21 +12,21 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package ebiten package audio
import ( import (
"github.com/hajimehoshi/ebiten/internal/audio" "github.com/hajimehoshi/ebiten/internal/audio"
) )
func AudioSampleRate() int { func SampleRate() int {
return audio.SampleRate return audio.SampleRate
} }
func AppendToAudioBuffer(channel int, l []float32, r []float32) bool { func AppendToBuffer(channel int, l []float32, r []float32) bool {
return audio.Append(channel, l, r) return audio.Append(channel, l, r)
} }
// TODO: better name // TODO: better name
func CurrentAudioTime() int { func CurrentTime() int {
return audio.CurrentBytes() return audio.CurrentBytes()
} }