forked from zikichombo/sound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.go
65 lines (53 loc) · 1.68 KB
/
form.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.
package sound
import "fmt"
import "zikichombo.org/sound/freq"
type _form struct {
c int
f freq.T
}
// Channels returns the number of channels of data
// in form v.
func (v *_form) Channels() int {
return v.c
}
// SampleRate returns the sample rate of data passing through v.
func (v *_form) SampleRate() freq.T {
return v.f
}
func (v *_form) String() string {
return fmt.Sprintf("[%d channels @ %s]", v.c, v.f)
}
// NewForm creates a new Form for sampling frequency f
// with c channels of data.
func NewForm(f freq.T, c int) Form {
return &_form{c: c, f: f}
}
// Interface Form specifies the logical content of pcm audio data,
// namely the number of channels and the sample rate. Form does not specify
// the in-memory layout of pcm audio data such as sample codec or whether or
// not the data is channel-interleaved.
//
// Applications which normalize memory layout of pcm data can use Form
// implementations to determine all necessary values of pcm data.
type Form interface {
Channels() int
SampleRate() freq.T
}
// MonoCd returns a single channel form at CD sampling rate.
func MonoCd() Form {
return &_form{c: 1, f: 44100 * freq.Hertz}
}
// MonoDvd gives a single channel form at Dvd sample rate (48kHz).
func MonoDvd() Form {
return &_form{c: 1, f: 48000 * freq.Hertz}
}
// StereoCd returns a 2-channel form at CD sampling rate.
func StereoCd() Form {
return &_form{c: 2, f: 44100 * freq.Hertz}
}
// StereoDvd gives a 2-channel form at Dvd sample rate (48kHz).
func StereoDvd() Form {
return &_form{c: 2, f: 48000 * freq.Hertz}
}