Skip to content

Commit e83260e

Browse files
committed
remove bitdepth and endianess from format
as per golang/go#18497 (comment)
1 parent 36d3529 commit e83260e

File tree

2 files changed

+21
-184
lines changed

2 files changed

+21
-184
lines changed

audio.go

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package audio
22

3-
import (
4-
"encoding/binary"
5-
"errors"
6-
)
3+
import "errors"
74

85
var (
96
// ErrInvalidBuffer is a generic error returned when trying to read/write to an invalid buffer.
@@ -16,10 +13,6 @@ type Format struct {
1613
NumChannels int
1714
// SampleRate is the sampling rate in Hz
1815
SampleRate int
19-
// BitDepth is the number of bits of data for each sample
20-
BitDepth int
21-
// Endianess indicate how the byte order of underlying bytes
22-
Endianness binary.ByteOrder
2316
}
2417

2518
// Buffer is the representation of an audio buffer.
@@ -63,8 +56,6 @@ func (buf *FloatBuffer) AsFloat32Buffer() *Float32Buffer {
6356
newB.Format = &Format{
6457
NumChannels: buf.Format.NumChannels,
6558
SampleRate: buf.Format.SampleRate,
66-
BitDepth: buf.Format.BitDepth,
67-
Endianness: buf.Format.Endianness,
6859
}
6960
return newB
7061
}
@@ -79,8 +70,6 @@ func (buf *FloatBuffer) AsIntBuffer() *IntBuffer {
7970
newB.Format = &Format{
8071
NumChannels: buf.Format.NumChannels,
8172
SampleRate: buf.Format.SampleRate,
82-
BitDepth: buf.Format.BitDepth,
83-
Endianness: buf.Format.Endianness,
8473
}
8574
return newB
8675
}
@@ -97,8 +86,6 @@ func (buf *FloatBuffer) Clone() Buffer {
9786
newB.Format = &Format{
9887
NumChannels: buf.Format.NumChannels,
9988
SampleRate: buf.Format.SampleRate,
100-
BitDepth: buf.Format.BitDepth,
101-
Endianness: buf.Format.Endianness,
10289
}
10390
return newB
10491
}
@@ -137,8 +124,6 @@ func (buf *Float32Buffer) AsFloatBuffer() *FloatBuffer {
137124
newB.Format = &Format{
138125
NumChannels: buf.Format.NumChannels,
139126
SampleRate: buf.Format.SampleRate,
140-
BitDepth: buf.Format.BitDepth,
141-
Endianness: buf.Format.Endianness,
142127
}
143128
return newB
144129
}
@@ -156,8 +141,6 @@ func (buf *Float32Buffer) AsIntBuffer() *IntBuffer {
156141
newB.Format = &Format{
157142
NumChannels: buf.Format.NumChannels,
158143
SampleRate: buf.Format.SampleRate,
159-
BitDepth: buf.Format.BitDepth,
160-
Endianness: buf.Format.Endianness,
161144
}
162145
return newB
163146
}
@@ -174,8 +157,6 @@ func (buf *Float32Buffer) Clone() Buffer {
174157
newB.Format = &Format{
175158
NumChannels: buf.Format.NumChannels,
176159
SampleRate: buf.Format.SampleRate,
177-
BitDepth: buf.Format.BitDepth,
178-
Endianness: buf.Format.Endianness,
179160
}
180161
return newB
181162
}
@@ -214,8 +195,6 @@ func (buf *IntBuffer) AsFloatBuffer() *FloatBuffer {
214195
newB.Format = &Format{
215196
NumChannels: buf.Format.NumChannels,
216197
SampleRate: buf.Format.SampleRate,
217-
BitDepth: buf.Format.BitDepth,
218-
Endianness: buf.Format.Endianness,
219198
}
220199
return newB
221200
}
@@ -230,8 +209,6 @@ func (buf *IntBuffer) AsFloat32Buffer() *Float32Buffer {
230209
newB.Format = &Format{
231210
NumChannels: buf.Format.NumChannels,
232211
SampleRate: buf.Format.SampleRate,
233-
BitDepth: buf.Format.BitDepth,
234-
Endianness: buf.Format.Endianness,
235212
}
236213
return newB
237214
}
@@ -264,8 +241,6 @@ func (buf *IntBuffer) Clone() Buffer {
264241
newB.Format = &Format{
265242
NumChannels: buf.Format.NumChannels,
266243
SampleRate: buf.Format.SampleRate,
267-
BitDepth: buf.Format.BitDepth,
268-
Endianness: buf.Format.Endianness,
269244
}
270245
return newB
271246
}

formats.go

+20-158
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,49 @@
11
package audio
22

3-
import "encoding/binary"
4-
53
var (
6-
// AIFF
74
// MONO
85

9-
// FormatMono225008bBE mono 8bit 22.5kHz AIFF like format.
10-
FormatMono225008bBE = &Format{
11-
NumChannels: 1,
12-
SampleRate: 22500,
13-
BitDepth: 8,
14-
Endianness: binary.BigEndian,
15-
}
16-
// FormatMono2250016bBE mono 16bit 22.5kHz AIFF like format.
17-
FormatMono2250016bBE = &Format{
6+
// FormatMono22500 mono 22.5kHz format.
7+
FormatMono22500 = &Format{
188
NumChannels: 1,
199
SampleRate: 22500,
20-
BitDepth: 16,
21-
Endianness: binary.BigEndian,
22-
}
23-
// FormatMono441008bBE mono 8bit 44.1kHz AIFF like format.
24-
FormatMono441008bBE = &Format{
25-
NumChannels: 1,
26-
SampleRate: 44100,
27-
BitDepth: 8,
28-
Endianness: binary.BigEndian,
2910
}
30-
// FormatMono4410016bBE mono 16bit 44.1kHz AIFF like format.
31-
FormatMono4410016bBE = &Format{
11+
// FormatMono44100 mono 8bit 44.1kHz format.
12+
FormatMono44100 = &Format{
3213
NumChannels: 1,
3314
SampleRate: 44100,
34-
BitDepth: 16,
35-
Endianness: binary.BigEndian,
3615
}
37-
// FormatMono4410024bBE mono 24bit 44.1kHz AIFF like format.
38-
FormatMono4410024bBE = &Format{
16+
// FormatMono48000 mono 48kHz format.
17+
FormatMono48000 = &Format{
3918
NumChannels: 1,
40-
SampleRate: 44100,
41-
BitDepth: 24,
42-
Endianness: binary.BigEndian,
19+
SampleRate: 48000,
4320
}
44-
// FormatMono4410032bBE mono 32bit 44.1kHz AIFF like format.
45-
FormatMono4410032bBE = &Format{
21+
// FormatMono96000 mono 96kHz format.
22+
FormatMono96000 = &Format{
4623
NumChannels: 1,
47-
SampleRate: 44100,
48-
BitDepth: 32,
49-
Endianness: binary.BigEndian,
24+
SampleRate: 96000,
5025
}
5126

5227
// STEREO
5328

54-
// FormatStereo225008bBE Stereo 8bit 22.5kHz AIFF like format.
55-
FormatStereo225008bBE = &Format{
56-
NumChannels: 2,
57-
SampleRate: 22500,
58-
BitDepth: 8,
59-
Endianness: binary.BigEndian,
60-
}
61-
// FormatStereo2250016bBE Stereo 16bit 22.5kHz AIFF like format.
62-
FormatStereo2250016bBE = &Format{
63-
NumChannels: 2,
64-
SampleRate: 22500,
65-
BitDepth: 16,
66-
Endianness: binary.BigEndian,
67-
}
68-
// FormatStereo441008bBE Stereo 8bit 44.1kHz AIFF like format.
69-
FormatStereo441008bBE = &Format{
70-
NumChannels: 2,
71-
SampleRate: 44100,
72-
BitDepth: 8,
73-
Endianness: binary.BigEndian,
74-
}
75-
// FormatStereo4410016bBE Stereo 16bit 44.1kHz AIFF like format.
76-
FormatStereo4410016bBE = &Format{
77-
NumChannels: 2,
78-
SampleRate: 44100,
79-
BitDepth: 16,
80-
Endianness: binary.BigEndian,
81-
}
82-
// FormatStereo4410024bBE Stereo 24bit 44.1kHz AIFF like format.
83-
FormatStereo4410024bBE = &Format{
84-
NumChannels: 2,
85-
SampleRate: 44100,
86-
BitDepth: 24,
87-
Endianness: binary.BigEndian,
88-
}
89-
// FormatStereo4410032bBE Stereo 32bit 44.1kHz AIFF like format.
90-
FormatStereo4410032bBE = &Format{
91-
NumChannels: 2,
92-
SampleRate: 44100,
93-
BitDepth: 32,
94-
Endianness: binary.BigEndian,
95-
}
96-
97-
// WAV
98-
// MONO
99-
100-
// FormatMono225008bLE mono 8bit 22.5kHz WAV like format.
101-
FormatMono225008bLE = &Format{
29+
// FormatStereo22500 Stereo 22.5kHz format.
30+
FormatStereo22500 = &Format{
10231
NumChannels: 1,
10332
SampleRate: 22500,
104-
BitDepth: 8,
105-
Endianness: binary.LittleEndian,
10633
}
107-
// FormatMono2250016bLE mono 16bit 22.5kHz WAV like format.
108-
FormatMono2250016bLE = &Format{
109-
NumChannels: 1,
110-
SampleRate: 22500,
111-
BitDepth: 16,
112-
Endianness: binary.LittleEndian,
113-
}
114-
// FormatMono441008bLE mono 8bit 44.1kHz WAV like format.
115-
FormatMono441008bLE = &Format{
116-
NumChannels: 1,
117-
SampleRate: 44100,
118-
BitDepth: 8,
119-
Endianness: binary.LittleEndian,
120-
}
121-
// FormatMono4410016bLE mono 16bit 44.1kHz WAV like format.
122-
FormatMono4410016bLE = &Format{
34+
// FormatStereo44100 Stereo 8bit 44.1kHz format.
35+
FormatStereo44100 = &Format{
12336
NumChannels: 1,
12437
SampleRate: 44100,
125-
BitDepth: 16,
126-
Endianness: binary.LittleEndian,
12738
}
128-
// FormatMono4410024bLE mono 24bit 44.1kHz WAV like format.
129-
FormatMono4410024bLE = &Format{
39+
// FormatStereo48000 Stereo 48kHz format.
40+
FormatStereo48000 = &Format{
13041
NumChannels: 1,
131-
SampleRate: 44100,
132-
BitDepth: 24,
133-
Endianness: binary.LittleEndian,
42+
SampleRate: 48000,
13443
}
135-
// FormatMono4410032bLE mono 32bit 44.1kHz WAV like format.
136-
FormatMono4410032bLE = &Format{
44+
// FormatStereo96000 Stereo 96kHz format.
45+
FormatStereo96000 = &Format{
13746
NumChannels: 1,
138-
SampleRate: 44100,
139-
BitDepth: 32,
140-
Endianness: binary.LittleEndian,
141-
}
142-
143-
// STEREO
144-
145-
// FormatStereo225008bLE Stereo 8bit 22.5kHz WAV like format.
146-
FormatStereo225008bLE = &Format{
147-
NumChannels: 2,
148-
SampleRate: 22500,
149-
BitDepth: 8,
150-
Endianness: binary.LittleEndian,
151-
}
152-
// FormatStereo2250016bLE Stereo 16bit 22.5kHz WAV like format.
153-
FormatStereo2250016bLE = &Format{
154-
NumChannels: 2,
155-
SampleRate: 22500,
156-
BitDepth: 16,
157-
Endianness: binary.LittleEndian,
158-
}
159-
// FormatStereo441008bLE Stereo 8bit 44.1kHz WAV like format.
160-
FormatStereo441008bLE = &Format{
161-
NumChannels: 2,
162-
SampleRate: 44100,
163-
BitDepth: 8,
164-
Endianness: binary.LittleEndian,
165-
}
166-
// FormatStereo4410016bLE Stereo 16bit 44.1kHz WAV like format.
167-
FormatStereo4410016bLE = &Format{
168-
NumChannels: 2,
169-
SampleRate: 44100,
170-
BitDepth: 16,
171-
Endianness: binary.LittleEndian,
172-
}
173-
// FormatStereo4410024bLE Stereo 24bit 44.1kHz WAV like format.
174-
FormatStereo4410024bLE = &Format{
175-
NumChannels: 2,
176-
SampleRate: 44100,
177-
BitDepth: 24,
178-
Endianness: binary.LittleEndian,
179-
}
180-
// FormatStereo4410032bLE Stereo 32bit 44.1kHz WAV like format.
181-
FormatStereo4410032bLE = &Format{
182-
NumChannels: 2,
183-
SampleRate: 44100,
184-
BitDepth: 32,
185-
Endianness: binary.LittleEndian,
47+
SampleRate: 96000,
18648
}
18749
)

0 commit comments

Comments
 (0)