File: channelmap.go

package info (click to toggle)
golang-github-mesilliac-pulse-simple 0.0~git20170506.75ac54e-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: makefile: 2
file content (93 lines) | stat: -rw-r--r-- 2,457 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main

import (
	".." // pulse-simple
	"fmt"
)

func main() {
	fmt.Printf("Channel Map Test\n")
	fmt.Printf("================\n")
	fmt.Printf("CHANNELS_MAX: %v\n", pulse.CHANNELS_MAX)

	fmt.Printf("\nMono\n")
	fmt.Printf("----\n")
	mono := &pulse.ChannelMap{}
	mono.InitMono()
	print_info(mono)

	fmt.Printf("\nStereo\n")
	fmt.Printf("------\n")
	stereo := &pulse.ChannelMap{}
	stereo.InitStereo()
	print_info(stereo)

	spec := &pulse.SampleSpec{pulse.SAMPLE_S16LE, 44100, 2}
	fmt.Printf("\nspec := &SampleSpec{SAMPLE_S16LE, 44100, 2}\n")
	fmt.Printf("mono.Compatible(spec): %v\n", mono.Compatible(spec))
	fmt.Printf("stereo.Compatible(spec): %v\n", stereo.Compatible(spec))

	fmt.Printf("\n9 Channel AIFF (should fail)\n")
	fmt.Printf("----------------------------\n")
	cmap := &pulse.ChannelMap{}
	err := cmap.InitAuto(9, pulse.CHANNEL_MAP_AIFF)
	if err != nil {
		fmt.Printf("Error: %s\n", err)
	} else {
		print_info(cmap)
	}

	fmt.Printf("\n9 Channel AIFF (should succeed)\n")
	fmt.Printf("-------------------------------\n")
	cmap.InitExtend(9, pulse.CHANNEL_MAP_AIFF)
	print_info(cmap)

	fmt.Printf("\naiff9.Superset(stereo): %v\n", cmap.Superset(stereo))
	fmt.Printf("aiff9.Superset(mono): %v\n", cmap.Superset(mono))

	name, err := stereo.Name()
	if err != nil {
		fmt.Printf("\nstereo.Name(): %v\n", err)
	} else {
		fmt.Printf("\nstereo.Name(): %v\n", name)
	}
	name, err = stereo.PrettyName()
	if err != nil {
		fmt.Printf("stereo.PrettyName(): %v\n", err)
	} else {
		fmt.Printf("stereo.PrettyName(): %v\n", name)
	}

	fmt.Printf("\n7.1 Surround\n")
	fmt.Printf("------------\n")
	err = cmap.InitAuto(8, pulse.CHANNEL_MAP_ALSA)
	if err != nil {
		fmt.Printf("Error: %s\n", err)
	} else {
		print_info(cmap)
		name, err = cmap.PrettyName()
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("PrettyName: %v\n", name)
		}
	}

	fmt.Printf("\nsurround has subwoofer: %v\n",
		cmap.HasPosition(pulse.CHANNEL_POSITION_SUBWOOFER))
	fmt.Printf("stereo has subwoofer: %v\n",
		stereo.HasPosition(pulse.CHANNEL_POSITION_SUBWOOFER))
	fmt.Printf("subwoofer channel mask: 0x%x\n",
		pulse.CHANNEL_POSITION_SUBWOOFER.Mask())

	fmt.Printf("\nsurround.String(): %v\n", cmap.String())

}

func print_info(cmap *pulse.ChannelMap) {
	fmt.Printf("Channels: %v\n", cmap.Channels)
	for i := 0; i < int(cmap.Channels); i++ {
		fmt.Printf("Map[%d]: %d (%v)\n", i, cmap.Map[i], cmap.Map[i])
	}
	fmt.Printf("ChannelPositionMask: %b\n", cmap.Mask())
}