From 60c49905556ce49447ddac85de57489ef5e73294 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 8 Feb 2016 00:48:43 +0900 Subject: [PATCH] audio: Change audio.SampleRate to be a const --- example/audio/main.go | 4 ++-- example/piano/main.go | 4 ++-- exp/audio/audio.go | 8 +++----- internal/audio/audio.go | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/example/audio/main.go b/example/audio/main.go index 679f858f6..f5c14b0e5 100644 --- a/example/audio/main.go +++ b/example/audio/main.go @@ -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() { diff --git a/example/piano/main.go b/example/piano/main.go index d62ca4c38..6e2ac1c9c 100644 --- a/example/piano/main.go +++ b/example/piano/main.go @@ -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++ { diff --git a/exp/audio/audio.go b/exp/audio/audio.go index 797b8715d..9ea44dcdb 100644 --- a/exp/audio/audio.go +++ b/exp/audio/audio.go @@ -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) } diff --git a/internal/audio/audio.go b/internal/audio/audio.go index d8d95d7ea..7d46c5cda 100644 --- a/internal/audio/audio.go +++ b/internal/audio/audio.go @@ -23,7 +23,7 @@ type channel struct { nextInsertionPosition int } -var MaxChannel = 32 +const MaxChannel = 32 var channels = make([]*channel, MaxChannel)