wasm: fix stereo
This commit is contained in:
@@ -43,13 +43,16 @@ std::vector<MiniAudioSource::DeviceInfo> MiniAudioSource::listInputDevices() {
|
||||
fullInfo = captureDevices[i];
|
||||
}
|
||||
|
||||
int maxCh = static_cast<int>(fullInfo.nativeDataFormatCount > 0
|
||||
? fullInfo.nativeDataFormats[0].channels : 2);
|
||||
// Find max channels across native formats.
|
||||
for (ma_uint32 f = 1; f < fullInfo.nativeDataFormatCount; ++f) {
|
||||
int ch = static_cast<int>(fullInfo.nativeDataFormats[f].channels);
|
||||
if (ch > maxCh) maxCh = ch;
|
||||
int maxCh = 0;
|
||||
if (fullInfo.nativeDataFormatCount > 0) {
|
||||
for (ma_uint32 f = 0; f < fullInfo.nativeDataFormatCount; ++f) {
|
||||
int ch = static_cast<int>(fullInfo.nativeDataFormats[f].channels);
|
||||
if (ch > maxCh) maxCh = ch;
|
||||
}
|
||||
}
|
||||
// channels == 0 means "any" in miniaudio (e.g. Web Audio backend).
|
||||
// Default to 2 (stereo) so the UI can offer multi-channel mode.
|
||||
if (maxCh <= 0) maxCh = 2;
|
||||
|
||||
double defaultSR = 48000.0;
|
||||
if (fullInfo.nativeDataFormatCount > 0 && fullInfo.nativeDataFormats[0].sampleRate > 0)
|
||||
@@ -131,6 +134,15 @@ bool MiniAudioSource::open() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read back actual device parameters (the backend may give us fewer
|
||||
// channels than requested, e.g. Web Audio defaults to mono).
|
||||
channels_ = static_cast<int>(device_->capture.channels);
|
||||
sampleRate_ = static_cast<double>(device_->sampleRate);
|
||||
|
||||
// Rebuild ring buffer to match actual channel count.
|
||||
size_t ringSize = static_cast<size_t>(sampleRate_ * channels_ * 2);
|
||||
ringBuf_ = std::make_unique<RingBuffer<float>>(ringSize);
|
||||
|
||||
if (ma_device_start(device_.get()) != MA_SUCCESS) {
|
||||
std::fprintf(stderr, "miniaudio: failed to start device\n");
|
||||
ma_device_uninit(device_.get());
|
||||
|
||||
@@ -41906,7 +41906,8 @@ static void ma_audio_worklet_processor_created__webaudio(EMSCRIPTEN_WEBAUDIO_T a
|
||||
var audioWorklet = emscriptenGetAudioObject($0);
|
||||
var audioContext = emscriptenGetAudioObject($1);
|
||||
|
||||
navigator.mediaDevices.getUserMedia({audio:true, video:false})
|
||||
var reqCh = $2;
|
||||
navigator.mediaDevices.getUserMedia({audio:{channelCount:{ideal:reqCh}}, video:false})
|
||||
.then(function(stream) {
|
||||
audioContext.streamNode = audioContext.createMediaStreamSource(stream);
|
||||
audioContext.streamNode.connect(audioWorklet);
|
||||
@@ -41919,7 +41920,7 @@ static void ma_audio_worklet_processor_created__webaudio(EMSCRIPTEN_WEBAUDIO_T a
|
||||
});
|
||||
|
||||
return getUserMediaResult;
|
||||
}, pParameters->pDevice->webaudio.audioWorklet, audioContext);
|
||||
}, pParameters->pDevice->webaudio.audioWorklet, audioContext, (int)pParameters->pConfig->capture.channels);
|
||||
|
||||
if (attachmentResult != MA_SUCCESS) {
|
||||
ma_log_postf(ma_device_get_log(pParameters->pDevice), MA_LOG_LEVEL_ERROR, "Web Audio: Failed to connect capture node.");
|
||||
@@ -42209,7 +42210,7 @@ static ma_result ma_device_init__webaudio(ma_device* pDevice, const ma_device_co
|
||||
|
||||
/* Now we need to connect our node to the graph. */
|
||||
if (deviceType == window.miniaudio.device_type.capture || deviceType == window.miniaudio.device_type.duplex) {
|
||||
navigator.mediaDevices.getUserMedia({audio:true, video:false})
|
||||
navigator.mediaDevices.getUserMedia({audio:{channelCount:{ideal:channels}}, video:false})
|
||||
.then(function(stream) {
|
||||
device.streamNode = device.webaudio.createMediaStreamSource(stream);
|
||||
device.streamNode.connect(device.scriptNode);
|
||||
|
||||
@@ -1128,7 +1128,7 @@ void Application::openPortAudio() {
|
||||
auto src = std::make_unique<MiniAudioSource>(sr, reqCh, deviceIdx);
|
||||
if (src->open()) {
|
||||
audioSource_ = std::move(src);
|
||||
settings_.sampleRate = sr;
|
||||
settings_.sampleRate = audioSource_->sampleRate();
|
||||
settings_.isIQ = false;
|
||||
settings_.numChannels = audioSource_->channels();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user