Skip to content
Snippets Groups Projects
Commit 992e1faa authored by Edric Milaret's avatar Edric Milaret Committed by Gerrit Code Review
Browse files

windows: portaudio changes

- Switch to DirectSound API.
- Using system default device.
- Setting correct format input/output at init.
- Switch from AbortStream to StopStream as it seems logical to read last
  frame from buffer at call end.

Refs #68881

Change-Id: Ic1482d09ba23f60ca3fd0bdcc3b7d1c143584a7e
parent c3a19140
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ ifeq ($(call need_pkg,"portaudio >= 2.0"),)
PKGS_FOUND += portaudio
endif
PORTAUDIOCONF := --with-winapi=directx
$(TARBALLS)/portaudio-$(PORTAUDIO_VERSION).tgz:
$(call download,$(PORTAUDIO_URL))
......@@ -21,6 +22,6 @@ portaudio: portaudio-$(PORTAUDIO_VERSION).tgz .sum-portaudio
$(UNPACK)
.portaudio: portaudio
cd $< && $(HOSTVARS) ./configure $(HOSTCONF)
cd $< && $(HOSTVARS) ./configure $(HOSTCONF) $(PORTAUDIOCONF)
cd $< && $(MAKE) install
touch $@
......@@ -36,7 +36,7 @@
#include "audio/ringbuffer.h"
namespace ring {
//FIXME: We should use WASAPi or DirectSound
PortAudioLayer::PortAudioLayer(const AudioPreference &pref)
: AudioLayer(pref)
, indexIn_(pref.getAlsaCardin())
......@@ -133,9 +133,8 @@ PortAudioLayer::stopStream()
RING_DBG("Stop PortAudio Streams");
//FIX ME : Abort or Stop ??
for (int i = 0; i < Direction::End; i++) {
auto err = Pa_AbortStream(streams[i]);
auto err = Pa_StopStream(streams[i]);
if(err != paNoError)
this->handleError(err);
......@@ -349,11 +348,19 @@ PortAudioLayer::init()
this->handleError(err);
this->terminate();
}
//FIXME: Maybe find a better way
const PaDeviceInfo *outputDeviceInfo = Pa_GetDeviceInfo(indexOut_);
indexOut_ = indexRing_ = Pa_GetDefaultOutputDevice();
indexIn_ = Pa_GetDefaultInputDevice();
const auto outputDeviceInfo = Pa_GetDeviceInfo(indexOut_);
audioFormat_.nb_channels = outputDeviceInfo->maxOutputChannels;
audioFormat_.sample_rate = 48000;
audioFormat_.sample_rate = outputDeviceInfo->defaultSampleRate;
hardwareFormatAvailable(audioFormat_);
const auto inputDeviceInfo = Pa_GetDeviceInfo(indexIn_);
audioInputFormat_.nb_channels = inputDeviceInfo->maxInputChannels;
audioInputFormat_.sample_rate = inputDeviceInfo->defaultSampleRate;
hardwareInputFormatAvailable(audioInputFormat_);
}
void
......@@ -373,19 +380,15 @@ PortAudioLayer::initStream()
RING_DBG("Open PortAudio Output Stream");
PaStreamParameters outputParameters;
outputParameters.device = indexOut_;
RING_DBG("Index Device: %d", indexOut_);
if (outputParameters.device == paNoDevice) {
//TODO Should we fallback to default output device ?
RING_ERR("Error: No valid output device. There will be no sound.");
}
const auto outputDeviceInfo =
Pa_GetDeviceInfo(outputParameters.device);
RING_DBG("Default Sample Rate : %d", outputDeviceInfo->defaultSampleRate);
outputParameters.channelCount =
audioFormat_.nb_channels = outputDeviceInfo->maxOutputChannels;
//FIX ME : Default is 0....
audioFormat_.sample_rate = 48000;
outputParameters.sampleFormat = paInt16;
outputParameters.suggestedLatency = outputDeviceInfo->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
......@@ -394,7 +397,7 @@ PortAudioLayer::initStream()
&streams[Direction::Output],
NULL,
&outputParameters,
audioFormat_.sample_rate,
outputDeviceInfo->defaultSampleRate,
paFramesPerBufferUnspecified,
paNoFlag,
&PortAudioLayer::paOutputCallback,
......@@ -406,14 +409,11 @@ PortAudioLayer::initStream()
PaStreamParameters inputParameters;
inputParameters.device = indexIn_;
if (inputParameters.device == paNoDevice) {
//TODO Should we fallback to default output device ?
RING_ERR("Error: No valid input device. There will be no mic.");
}
const auto inputDeviceInfo =
Pa_GetDeviceInfo(inputParameters.device);
//FIX ME : Default is 0....
audioInputFormat_.sample_rate = 48000;
inputParameters.channelCount =
audioInputFormat_.nb_channels = inputDeviceInfo->maxInputChannels;
inputParameters.sampleFormat = paInt16;
......@@ -424,7 +424,7 @@ PortAudioLayer::initStream()
&streams[Direction::Input],
&inputParameters,
NULL,
audioInputFormat_.sample_rate,
inputDeviceInfo->defaultSampleRate,
paFramesPerBufferUnspecified,
paNoFlag,
&PortAudioLayer::paInputCallback,
......@@ -437,9 +437,6 @@ PortAudioLayer::initStream()
this->handleError(err);
}
hardwareFormatAvailable(audioFormat_);
hardwareInputFormatAvailable(audioInputFormat_);
flushUrgent();
flushMain();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment