Skip to content

Commit eb95426

Browse files
committed
added comments
1 parent 1791a53 commit eb95426

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

pkg/pcm/config.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package pcm
33
import "github.com/Binozo/GoTinyAlsa/internal/tinypcm"
44

55
type Config struct {
6-
Channels int
7-
SampleRate int
8-
PeriodSize int
9-
PeriodCount int
6+
// The number of audio channels
7+
Channels int
8+
// Sample rate (the higher, the better)
9+
SampleRate int
10+
// Number of frames in a period
11+
PeriodSize int
12+
// Number of periods
13+
PeriodCount int
14+
// IO Format
1015
Format tinypcm.Format
1116
StartThreshold int
1217
StopThreshold int

pkg/pcm/info.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
package pcm
22

33
type Info struct {
4-
Access uint
5-
Format0 uint
6-
Format1 uint
7-
FormatNames []string
8-
Subformat uint
9-
RateMin uint
10-
RateMax uint
11-
ChannelsMin uint
12-
ChannelsMax uint
13-
SampleBitsMin uint
14-
SampleBitsMax uint
15-
PeriodSizeMin uint
16-
PeriodSizeMax uint
4+
// Mask that represents the type of read or write methods available
5+
Access uint
6+
// Mask that represents the PCM_FORMAT available (e.g. PCM_FORMAT_32_LE)
7+
Format0 uint
8+
// Mask that represents the PCM_FORMAT available (e.g. PCM_FORMAT_32_LE)
9+
Format1 uint
10+
// Pcm formats available
11+
FormatNames []string
12+
// Mask that represents the subformat available
13+
Subformat uint
14+
// Minimum available rate
15+
RateMin uint
16+
// Maximum available rate
17+
RateMax uint
18+
// Minimum available channels
19+
ChannelsMin uint
20+
// Maximum available channels
21+
ChannelsMax uint
22+
// Minimum available sample bits
23+
SampleBitsMin uint
24+
// Maximum available sample bits
25+
SampleBitsMax uint
26+
// Minimum available period size
27+
PeriodSizeMin uint
28+
// Maximum available period size
29+
PeriodSizeMax uint
30+
// Minimum available period count
1731
PeriodCountMin uint
32+
// Maximum available period count
1833
PeriodCountMax uint
1934
}

pkg/tinyalsa/audio.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const PCM_FORMAT_S32_LE = tinyapi.PCM_FORMAT_S32_LE
2121
const PCM_FORMAT_S32_BE = tinyapi.PCM_FORMAT_S32_BE
2222
const ErrorTolerance = 10 // defines how many error frames are allowed to be read without stopping reading the next ones
2323

24+
// GetAudioStream Listens to the input of the defined device
2425
func (d *AlsaDevice) GetAudioStream(config pcm.Config, audioData chan []byte) error {
2526
pcmDevice, err := tinyapi.PcmOpen(d.Card, d.Device, PCM_IN, config)
2627
if err != nil {
@@ -61,6 +62,7 @@ FrameReader:
6162
return nil
6263
}
6364

65+
// SendAudioStream plays the given audio data (usually wav) to the device
6466
func (d *AlsaDevice) SendAudioStream(audioData []byte) error {
6567
pcmDevice, err := tinyapi.PcmOpen(d.Card, d.Device, PCM_OUT, d.DeviceConfig)
6668
if err != nil {

pkg/tinyalsa/device.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type AlsaDevice struct {
1212
DeviceConfig pcm.Config
1313
}
1414

15+
// NewDevice defines a new device you want to interact with
1516
func NewDevice(cardNr int, deviceNr int, deviceConfig pcm.Config) AlsaDevice {
1617
return AlsaDevice{
1718
Card: cardNr,
@@ -20,6 +21,7 @@ func NewDevice(cardNr int, deviceNr int, deviceConfig pcm.Config) AlsaDevice {
2021
}
2122
}
2223

24+
// BestDeviceConfig return you the best device config to use
2325
func BestDeviceConfig(cardNr int, deviceNr int, format int) pcm.Config {
2426
device := AlsaDevice{
2527
Card: cardNr,
@@ -42,6 +44,7 @@ func BestDeviceConfig(cardNr int, deviceNr int, format int) pcm.Config {
4244
}
4345
}
4446

47+
// GetInfo returns information data about the given device's input & output
4548
func (d *AlsaDevice) GetInfo() DeviceInfo {
4649
inInfo, outInfo := tinyapi.GetParams(d.Card, d.Device)
4750
return DeviceInfo{

pkg/tinyalsa/deviceinfo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ package tinyalsa
33
import "github.com/Binozo/GoTinyAlsa/pkg/pcm"
44

55
type DeviceInfo struct {
6+
// Output info (e.g. speaker)
67
Out pcm.Info
7-
In pcm.Info
8+
// Input info (e.g. microphone)
9+
In pcm.Info
810
}
911

12+
// HasOutput returns true, if the given device has an output (e.g. speaker)
1013
func (i *DeviceInfo) HasOutput() bool {
1114
return i.Out.Access != 0 && i.Out.RateMin != 0
1215
}
1316

17+
// HasInput returns true, if the given device has an input (e.g. microphone)
1418
func (i *DeviceInfo) HasInput() bool {
1519
return i.In.Access != 0 && i.In.RateMin != 0
1620
}

0 commit comments

Comments
 (0)