audio: Change audio.SampleRate to be a const

This commit is contained in:
Hajime Hoshi 2016-02-08 00:48:43 +09:00
parent b63911e6f7
commit 60c4990555
4 changed files with 8 additions and 10 deletions

View File

@ -57,7 +57,7 @@ func square(out []int16, volume float64, freq float64, sequence float64) {
}
return
}
length := int(float64(audio.SampleRate()) / freq)
length := int(float64(audio.SampleRate) / freq)
if length == 0 {
panic("invalid freq")
}
@ -85,7 +85,7 @@ func toBytes(l, r []int16) []byte {
}
func addNote() {
size := audio.SampleRate() / 60
size := audio.SampleRate / 60
notes := []float64{freqC, freqD, freqE, freqF, freqG, freqA * 2, freqB * 2}
defer func() {

View File

@ -31,12 +31,12 @@ const (
screenHeight = 240
)
var pcm = make([]float64, 4*audio.SampleRate())
var pcm = make([]float64, 4*audio.SampleRate)
const baseFreq = 220
func init() {
s := float64(audio.SampleRate())
s := float64(audio.SampleRate)
amp := []float64{1.0, 0.8, 0.6, 0.4, 0.2}
x := []float64{4.0, 2.0, 1.0, 0.5, 0.25}
for i := 0; i < len(pcm); i++ {

View File

@ -19,12 +19,10 @@ import (
)
// SampleRate returns the sampling frequency (e.g. 44100).
func SampleRate() int {
return audio.SampleRate
}
const SampleRate = audio.SampleRate
// MaxChannel is a max number of channels.
var MaxChannel = audio.MaxChannel
const MaxChannel = audio.MaxChannel
// Queue queues the given data to the given channel.
// The given data is queued to the end of the buffer and not played immediately.
@ -32,7 +30,7 @@ var MaxChannel = audio.MaxChannel
// channel must be -1 or a channel index. If channel is -1, an empty channel is automatically selected.
// If the channel is not empty, this function does nothing and returns false. This returns true otherwise.
//
// data's format must be linear PCM (44100Hz, 16bits, 2 channel stereo, little endian).
// data's format must be linear PCM (44100Hz, 16bits, 2 channel stereo, little endian) without a header (e.g. RIFF header).
func Queue(channel int, data []byte) bool {
return audio.Queue(channel, data)
}

View File

@ -23,7 +23,7 @@ type channel struct {
nextInsertionPosition int
}
var MaxChannel = 32
const MaxChannel = 32
var channels = make([]*channel, MaxChannel)