@@ -20,7 +20,7 @@ uint32 IAudioAPI::s_audioDelay = 2;
20
20
std::array<bool , IAudioAPI::AudioAPIEnd> IAudioAPI::s_availableApis{};
21
21
22
22
IAudioAPI::IAudioAPI (uint32 samplerate, uint32 channels, uint32 samples_per_block, uint32 bits_per_sample)
23
- : m_samplerate(samplerate), m_channels(channels), m_samplesPerBlock(samples_per_block), m_bitsPerSample(bits_per_sample)
23
+ : m_samplerate(samplerate), m_channels(channels), m_samplesPerBlock(samples_per_block), m_bitsPerSample(bits_per_sample)
24
24
{
25
25
m_bytesPerBlock = samples_per_block * channels * (bits_per_sample / 8 );
26
26
InitWFX (m_samplerate, m_channels, m_bitsPerSample);
@@ -81,7 +81,7 @@ void IAudioAPI::InitializeStatic()
81
81
#if BOOST_OS_WINDOWS
82
82
s_availableApis[DirectSound] = true ;
83
83
s_availableApis[XAudio2] = XAudio2API::InitializeStatic ();
84
- if (!s_availableApis[XAudio2]) // don't try to initialize the older lib if the newer version is available
84
+ if (!s_availableApis[XAudio2]) // don't try to initialize the older lib if the newer version is available
85
85
s_availableApis[XAudio27] = XAudio27API::InitializeStatic ();
86
86
#endif
87
87
#if HAS_CUBEB
@@ -98,30 +98,29 @@ bool IAudioAPI::IsAudioAPIAvailable(AudioAPI api)
98
98
return false ;
99
99
}
100
100
101
- AudioAPIPtr IAudioAPI::CreateDeviceFromConfig (bool TV , sint32 rate, sint32 samples_per_block, sint32 bits_per_sample)
101
+ AudioAPIPtr IAudioAPI::CreateDeviceFromConfig (AudioType type , sint32 rate, sint32 samples_per_block, sint32 bits_per_sample)
102
102
{
103
- auto & config = GetConfig ();
104
- sint32 channels = CemuConfig::AudioChannelsToNChannels (TV ? config.tv_channels : config.pad_channels );
103
+ sint32 channels = CemuConfig::AudioChannelsToNChannels (AudioTypeToChannels (type));
105
104
return CreateDeviceFromConfig (TV, rate, channels, samples_per_block, bits_per_sample);
106
105
}
107
106
108
- AudioAPIPtr IAudioAPI::CreateDeviceFromConfig (bool TV , sint32 rate, sint32 channels, sint32 samples_per_block, sint32 bits_per_sample)
107
+ AudioAPIPtr IAudioAPI::CreateDeviceFromConfig (AudioType type , sint32 rate, sint32 channels, sint32 samples_per_block, sint32 bits_per_sample)
109
108
{
110
109
AudioAPIPtr audioAPIDev;
111
110
112
111
auto & config = GetConfig ();
113
112
114
113
const auto audio_api = (IAudioAPI::AudioAPI)config.audio_api ;
115
- auto & selectedDevice = TV ? config. tv_device : config. pad_device ;
114
+ auto selectedDevice = GetDeviceFromType (type) ;
116
115
117
- if (selectedDevice.empty ())
116
+ if (selectedDevice.empty ())
118
117
return {};
119
118
120
119
IAudioAPI::DeviceDescriptionPtr device_description;
121
120
if (IAudioAPI::IsAudioAPIAvailable (audio_api))
122
121
{
123
122
auto devices = IAudioAPI::GetDevices (audio_api);
124
- const auto it = std::find_if (devices.begin (), devices.end (), [&selectedDevice](const auto & d) {return d->GetIdentifier () == selectedDevice; });
123
+ const auto it = std::find_if (devices.begin (), devices.end (), [&selectedDevice](const auto & d) { return d->GetIdentifier () == selectedDevice; });
125
124
if (it != devices.end ())
126
125
device_description = *it;
127
126
}
@@ -138,7 +137,7 @@ AudioAPIPtr IAudioAPI::CreateDevice(AudioAPI api, const DeviceDescriptionPtr& de
138
137
if (!IsAudioAPIAvailable (api))
139
138
return {};
140
139
141
- switch (api)
140
+ switch (api)
142
141
{
143
142
#if BOOST_OS_WINDOWS
144
143
case DirectSound:
@@ -158,11 +157,11 @@ AudioAPIPtr IAudioAPI::CreateDevice(AudioAPI api, const DeviceDescriptionPtr& de
158
157
}
159
158
#endif
160
159
#if HAS_CUBEB
161
- case Cubeb:
162
- {
163
- const auto tmp = std::dynamic_pointer_cast<CubebAPI::CubebDeviceDescription>(device);
164
- return std::make_unique<CubebAPI>(tmp->GetDeviceId (), samplerate, channels, samples_per_block, bits_per_sample);
165
- }
160
+ case Cubeb:
161
+ {
162
+ const auto tmp = std::dynamic_pointer_cast<CubebAPI::CubebDeviceDescription>(device);
163
+ return std::make_unique<CubebAPI>(tmp->GetDeviceId (), samplerate, channels, samples_per_block, bits_per_sample);
164
+ }
166
165
#endif
167
166
default :
168
167
throw std::runtime_error (fmt::format (" invalid audio api: {}" , api));
@@ -173,8 +172,8 @@ std::vector<IAudioAPI::DeviceDescriptionPtr> IAudioAPI::GetDevices(AudioAPI api)
173
172
{
174
173
if (!IsAudioAPIAvailable (api))
175
174
return {};
176
-
177
- switch (api)
175
+
176
+ switch (api)
178
177
{
179
178
#if BOOST_OS_WINDOWS
180
179
case DirectSound:
@@ -210,3 +209,35 @@ uint32 IAudioAPI::GetAudioDelay() const
210
209
{
211
210
return m_audioDelayOverride > 0 ? m_audioDelayOverride : s_audioDelay;
212
211
}
212
+
213
+ AudioChannels IAudioAPI::AudioTypeToChannels (AudioType type)
214
+ {
215
+ auto & config = GetConfig ();
216
+ switch (type)
217
+ {
218
+ case TV:
219
+ return config.tv_channels ;
220
+ case Gamepad:
221
+ return config.pad_channels ;
222
+ case Portal:
223
+ return config.portal_channels ;
224
+ default :
225
+ return kMono ;
226
+ }
227
+ }
228
+
229
+ std::wstring IAudioAPI::GetDeviceFromType (AudioType type)
230
+ {
231
+ auto & config = GetConfig ();
232
+ switch (type)
233
+ {
234
+ case TV:
235
+ return config.tv_device ;
236
+ case Gamepad:
237
+ return config.pad_device ;
238
+ case Portal:
239
+ return config.portal_device ;
240
+ default :
241
+ return L" " ;
242
+ }
243
+ }
0 commit comments