/
phodevi_audio.php
113 lines (97 loc) · 2.81 KB
/
phodevi_audio.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2010 - 2021, Phoronix Media
Copyright (C) 2010 - 2021, Michael Larabel
phodevi_audio.php: The PTS Device Interface object for audio / sound cards
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class phodevi_audio extends phodevi_device_interface
{
public static function properties()
{
return array(
'identifier' => new phodevi_device_property('audio_processor_string', phodevi::smart_caching)
);
}
public static function audio_processor_string()
{
$audio = null;
if(phodevi::is_macos())
{
// TODO: implement
}
else if(phodevi::is_bsd())
{
foreach(array('dev.hdac.0.%desc') as $dev)
{
$dev = phodevi_bsd_parser::read_sysctl($dev);
if(!empty($dev))
{
$audio = $dev;
}
}
}
else if(phodevi::is_windows())
{
$win_sound = array();
$win32_sounddevice = shell_exec('powershell "(Get-WMIObject -Class win32_sounddevice | Select Name)"');
if(($x = strpos($win32_sounddevice, '----')) !== false)
{
$win32_sounddevice = trim(substr($win32_sounddevice, $x + 4));
foreach(explode("\n", $win32_sounddevice) as $sd)
{
if(!empty($sd))
{
$win_sound[] = $sd;
}
}
}
$win_sound = array_unique($win_sound);
$audio = implode(' + ', $win_sound);
}
else if(phodevi::is_linux())
{
foreach(pts_file_io::glob('/sys/class/sound/card*/hwC0D*/vendor_name') as $vendor_name)
{
$card_dir = dirname($vendor_name) . '/';
if(!is_readable($card_dir . 'chip_name'))
{
continue;
}
$vendor_name = pts_file_io::file_get_contents($vendor_name);
$chip_name = pts_file_io::file_get_contents($card_dir . 'chip_name');
$audio = $vendor_name . ' '. $chip_name;
if(strpos($chip_name, 'HDMI') !== false || strpos($chip_name, 'DP') !== false)
{
// If HDMI is in the audio string, likely the GPU-provided audio, so try to find the mainboard otherwise
$audio = null;
}
else
{
break;
}
}
if($audio == null)
{
$audio = phodevi_linux_parser::read_pci('Multimedia audio controller');
}
if($audio == null)
{
$audio = phodevi_linux_parser::read_pci('Audio device');
}
}
return $audio;
}
}
?>