Clean up some exception messages and avoid duplicate log messages
This commit is contained in:
parent
360330b2ad
commit
7726a06d26
@ -616,11 +616,8 @@ void AlsaPlayback::open(const ALCchar *name)
|
||||
TRACE("Opening device \"%s\"\n", driver);
|
||||
int err{snd_pcm_open(&mPcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)};
|
||||
if(err < 0)
|
||||
{
|
||||
ERR("Could not open playback device '%s': %s\n", driver, snd_strerror(err));
|
||||
throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA playback \"%s\"",
|
||||
throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA device \"%s\"",
|
||||
driver};
|
||||
}
|
||||
|
||||
/* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */
|
||||
snd_config_update_free_global();
|
||||
@ -917,11 +914,8 @@ void AlsaCapture::open(const ALCchar *name)
|
||||
TRACE("Opening device \"%s\"\n", driver);
|
||||
int err{snd_pcm_open(&mPcmHandle, driver, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)};
|
||||
if(err < 0)
|
||||
{
|
||||
ERR("Could not open capture device '%s': %s\n", driver, snd_strerror(err));
|
||||
throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA capture \"%s\"",
|
||||
throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA device \"%s\"",
|
||||
driver};
|
||||
}
|
||||
|
||||
/* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */
|
||||
snd_config_update_free_global();
|
||||
@ -989,11 +983,7 @@ void AlsaCapture::open(const ALCchar *name)
|
||||
if(needring)
|
||||
{
|
||||
mRing = CreateRingBuffer(mDevice->BufferSize, mDevice->frameSizeFromFmt(), false);
|
||||
if(!mRing)
|
||||
{
|
||||
ERR("ring buffer create failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"};
|
||||
}
|
||||
if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
|
@ -108,26 +108,17 @@ void CoreAudioPlayback::open(const ALCchar *name)
|
||||
|
||||
AudioComponent comp{AudioComponentFindNext(NULL, &desc)};
|
||||
if(comp == nullptr)
|
||||
{
|
||||
ERR("AudioComponentFindNext failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not find audio component"};
|
||||
}
|
||||
|
||||
OSStatus err{AudioComponentInstanceNew(comp, &mAudioUnit)};
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioComponentInstanceNew failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u",
|
||||
err};
|
||||
}
|
||||
|
||||
/* init and start the default audio unit... */
|
||||
err = AudioUnitInitialize(mAudioUnit);
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitInitialize failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
@ -418,41 +409,29 @@ void CoreAudioCapture::open(const ALCchar *name)
|
||||
// Search for component with given description
|
||||
comp = AudioComponentFindNext(NULL, &desc);
|
||||
if(comp == NULL)
|
||||
{
|
||||
ERR("AudioComponentFindNext failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not finda udio component"};
|
||||
}
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not find audio component"};
|
||||
|
||||
// Open the component
|
||||
err = AudioComponentInstanceNew(comp, &mAudioUnit);
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioComponentInstanceNew failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u",
|
||||
err};
|
||||
}
|
||||
|
||||
// Turn off AudioUnit output
|
||||
enableIO = 0;
|
||||
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Output, 0, &enableIO, sizeof(ALuint));
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitSetProperty failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Could not disable audio unit output property: %u", err};
|
||||
}
|
||||
|
||||
// Turn on AudioUnit input
|
||||
enableIO = 1;
|
||||
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_EnableIO,
|
||||
kAudioUnitScope_Input, 1, &enableIO, sizeof(ALuint));
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitSetProperty failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Could not enable audio unit input property: %u", err};
|
||||
}
|
||||
|
||||
#if !TARGET_OS_IOS
|
||||
{
|
||||
@ -467,24 +446,15 @@ void CoreAudioCapture::open(const ALCchar *name)
|
||||
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, nullptr,
|
||||
&propertySize, &inputDevice);
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioObjectGetPropertyData failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input device: %u", err};
|
||||
}
|
||||
if(inputDevice == kAudioDeviceUnknown)
|
||||
{
|
||||
ERR("No input device found\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Unknown input device"};
|
||||
}
|
||||
|
||||
// Track the input device
|
||||
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_CurrentDevice,
|
||||
kAudioUnitScope_Global, 0, &inputDevice, sizeof(AudioDeviceID));
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitSetProperty failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input device: %u", err};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -495,28 +465,19 @@ void CoreAudioCapture::open(const ALCchar *name)
|
||||
err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_SetInputCallback,
|
||||
kAudioUnitScope_Global, 0, &input, sizeof(AURenderCallbackStruct));
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitSetProperty failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not set capture callback: %u", err};
|
||||
}
|
||||
|
||||
// Initialize the device
|
||||
err = AudioUnitInitialize(mAudioUnit);
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitInitialize failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err};
|
||||
}
|
||||
|
||||
// Get the hardware format
|
||||
propertySize = sizeof(AudioStreamBasicDescription);
|
||||
err = AudioUnitGetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
|
||||
1, &hardwareFormat, &propertySize);
|
||||
if(err != noErr || propertySize != sizeof(AudioStreamBasicDescription))
|
||||
{
|
||||
ERR("AudioUnitGetProperty failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input format: %u", err};
|
||||
}
|
||||
|
||||
// Set up the requested format description
|
||||
switch(mDevice->FmtType)
|
||||
@ -540,7 +501,6 @@ void CoreAudioCapture::open(const ALCchar *name)
|
||||
case DevFmtByte:
|
||||
case DevFmtUShort:
|
||||
case DevFmtUInt:
|
||||
ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s samples not suppoted",
|
||||
DevFmtTypeString(mDevice->FmtType)};
|
||||
}
|
||||
@ -560,7 +520,6 @@ void CoreAudioCapture::open(const ALCchar *name)
|
||||
case DevFmtX61:
|
||||
case DevFmtX71:
|
||||
case DevFmtAmbi3D:
|
||||
ERR("%s not supported\n", DevFmtChannelsString(mDevice->FmtChans));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s not supported",
|
||||
DevFmtChannelsString(mDevice->FmtChans)};
|
||||
}
|
||||
@ -586,10 +545,7 @@ void CoreAudioCapture::open(const ALCchar *name)
|
||||
err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output,
|
||||
1, &outputFormat, sizeof(outputFormat));
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitSetProperty failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input format: %u", err};
|
||||
}
|
||||
|
||||
// Set the AudioUnit output format frame count
|
||||
uint64_t FrameCount64{mDevice->UpdateSize};
|
||||
@ -597,21 +553,15 @@ void CoreAudioCapture::open(const ALCchar *name)
|
||||
mDevice->Frequency;
|
||||
FrameCount64 += MAX_RESAMPLER_PADDING;
|
||||
if(FrameCount64 > std::numeric_limits<uint32_t>::max()/2)
|
||||
{
|
||||
ERR("FrameCount too large\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Calculated frame count is too lareg: %" PRIu64, FrameCount64};
|
||||
}
|
||||
"Calculated frame count is too large: %" PRIu64, FrameCount64};
|
||||
|
||||
outputFrameCount = static_cast<uint32_t>(FrameCount64);
|
||||
err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_MaximumFramesPerSlice,
|
||||
kAudioUnitScope_Output, 0, &outputFrameCount, sizeof(outputFrameCount));
|
||||
if(err != noErr)
|
||||
{
|
||||
ERR("AudioUnitSetProperty failed: %d\n", err);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set capture frame count: %u",
|
||||
err};
|
||||
}
|
||||
|
||||
// Set up sample converter if needed
|
||||
if(outputFormat.mSampleRate != mDevice->Frequency)
|
||||
|
@ -341,10 +341,7 @@ void DSoundPlayback::open(const ALCchar *name)
|
||||
if(SUCCEEDED(hr))
|
||||
hr = mDS->SetCooperativeLevel(GetForegroundWindow(), DSSCL_PRIORITY);
|
||||
if(FAILED(hr))
|
||||
{
|
||||
ERR("Device init failed: 0x%08lx\n", hr);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
@ -753,8 +750,6 @@ void DSoundCapture::open(const ALCchar *name)
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
ERR("Device init failed: 0x%08lx\n", hr);
|
||||
|
||||
mRing = nullptr;
|
||||
if(mDSCbuffer)
|
||||
mDSCbuffer->Release();
|
||||
|
@ -336,11 +336,9 @@ void JackPlayback::open(const ALCchar *name)
|
||||
jack_status_t status;
|
||||
mClient = jack_client_open(client_name, ClientOptions, &status, nullptr);
|
||||
if(mClient == nullptr)
|
||||
{
|
||||
ERR("jack_client_open() failed, status = 0x%02x\n", status);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to connect to JACK server: 0x%02x",
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open client connection: 0x%02x",
|
||||
status};
|
||||
}
|
||||
|
||||
if((status&JackServerStarted))
|
||||
TRACE("JACK server started\n");
|
||||
if((status&JackNameNotUnique))
|
||||
|
@ -146,9 +146,9 @@ struct OpenSLPlayback final : public BackendBase {
|
||||
OpenSLPlayback(ALCdevice *device) noexcept : BackendBase{device} { }
|
||||
~OpenSLPlayback() override;
|
||||
|
||||
void process(SLAndroidSimpleBufferQueueItf bq);
|
||||
static void processC(SLAndroidSimpleBufferQueueItf bq, void *context)
|
||||
{ static_cast<OpenSLPlayback*>(context)->process(bq); }
|
||||
void process(SLAndroidSimpleBufferQueueItf bq);
|
||||
|
||||
int mixerProc();
|
||||
|
||||
@ -339,8 +339,8 @@ void OpenSLPlayback::open(const ALCchar *name)
|
||||
mEngineObj = nullptr;
|
||||
mEngine = nullptr;
|
||||
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to initialize OpenSL: 0x%08x",
|
||||
result};
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Failed to initialize OpenSL device: 0x%08x", result};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
@ -629,9 +629,9 @@ struct OpenSLCapture final : public BackendBase {
|
||||
OpenSLCapture(ALCdevice *device) noexcept : BackendBase{device} { }
|
||||
~OpenSLCapture() override;
|
||||
|
||||
void process(SLAndroidSimpleBufferQueueItf bq);
|
||||
static void processC(SLAndroidSimpleBufferQueueItf bq, void *context)
|
||||
{ static_cast<OpenSLCapture*>(context)->process(bq); }
|
||||
void process(SLAndroidSimpleBufferQueueItf bq);
|
||||
|
||||
void open(const ALCchar *name) override;
|
||||
bool start() override;
|
||||
@ -839,8 +839,8 @@ void OpenSLCapture::open(const ALCchar* name)
|
||||
mEngineObj = nullptr;
|
||||
mEngine = nullptr;
|
||||
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to initialize OpenSL: 0x%08x",
|
||||
result};
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Failed to initialize OpenSL device: 0x%08x", result};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
|
@ -350,11 +350,8 @@ void OSSPlayback::open(const ALCchar *name)
|
||||
|
||||
mFd = ::open(devname, O_WRONLY);
|
||||
if(mFd == -1)
|
||||
{
|
||||
ERR("Could not open %s: %s\n", devname, strerror(errno));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", devname,
|
||||
strerror(errno)};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
@ -560,11 +557,8 @@ void OSScapture::open(const ALCchar *name)
|
||||
|
||||
mFd = ::open(devname, O_RDONLY);
|
||||
if(mFd == -1)
|
||||
{
|
||||
ERR("Could not open %s: %s\n", devname, strerror(errno));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", devname,
|
||||
strerror(errno)};
|
||||
}
|
||||
|
||||
int ossFormat{};
|
||||
switch(mDevice->FmtType)
|
||||
@ -582,7 +576,6 @@ void OSScapture::open(const ALCchar *name)
|
||||
case DevFmtInt:
|
||||
case DevFmtUInt:
|
||||
case DevFmtFloat:
|
||||
ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported",
|
||||
DevFmtTypeString(mDevice->FmtType)};
|
||||
}
|
||||
@ -596,47 +589,30 @@ void OSScapture::open(const ALCchar *name)
|
||||
ALuint numFragmentsLogSize{(periods << 16) | log2FragmentSize};
|
||||
|
||||
audio_buf_info info{};
|
||||
const char *err;
|
||||
#define CHECKERR(func) if((func) < 0) { \
|
||||
err = #func; \
|
||||
goto err; \
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, #func " failed: %s", strerror(errno)}; \
|
||||
}
|
||||
CHECKERR(ioctl(mFd, SNDCTL_DSP_SETFRAGMENT, &numFragmentsLogSize));
|
||||
CHECKERR(ioctl(mFd, SNDCTL_DSP_SETFMT, &ossFormat));
|
||||
CHECKERR(ioctl(mFd, SNDCTL_DSP_CHANNELS, &numChannels));
|
||||
CHECKERR(ioctl(mFd, SNDCTL_DSP_SPEED, &ossSpeed));
|
||||
CHECKERR(ioctl(mFd, SNDCTL_DSP_GETISPACE, &info));
|
||||
if(0)
|
||||
{
|
||||
err:
|
||||
ERR("%s failed: %s\n", err, strerror(errno));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s failed: %s", err, strerror(errno)};
|
||||
}
|
||||
#undef CHECKERR
|
||||
|
||||
if(mDevice->channelsFromFmt() != numChannels)
|
||||
{
|
||||
ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(mDevice->FmtChans),
|
||||
numChannels);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set %s capture",
|
||||
DevFmtChannelsString(mDevice->FmtChans)};
|
||||
}
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Failed to set %s, got %d channels instead", DevFmtChannelsString(mDevice->FmtChans),
|
||||
numChannels};
|
||||
|
||||
if(!((ossFormat == AFMT_S8 && mDevice->FmtType == DevFmtByte) ||
|
||||
(ossFormat == AFMT_U8 && mDevice->FmtType == DevFmtUByte) ||
|
||||
(ossFormat == AFMT_S16_NE && mDevice->FmtType == DevFmtShort)))
|
||||
{
|
||||
ERR("Failed to set %s samples, got OSS format %#x\n", DevFmtTypeString(mDevice->FmtType), ossFormat);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set %s samples",
|
||||
DevFmtTypeString(mDevice->FmtType)};
|
||||
}
|
||||
if(!((ossFormat == AFMT_S8 && mDevice->FmtType == DevFmtByte)
|
||||
|| (ossFormat == AFMT_U8 && mDevice->FmtType == DevFmtUByte)
|
||||
|| (ossFormat == AFMT_S16_NE && mDevice->FmtType == DevFmtShort)))
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Failed to set %s samples, got OSS format %#x", DevFmtTypeString(mDevice->FmtType),
|
||||
ossFormat};
|
||||
|
||||
mRing = CreateRingBuffer(mDevice->BufferSize, frameSize, false);
|
||||
if(!mRing)
|
||||
{
|
||||
ERR("Ring buffer create failed\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"};
|
||||
}
|
||||
if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"};
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
|
@ -166,7 +166,6 @@ retry_open:
|
||||
mParams.sampleFormat = paInt16;
|
||||
goto retry_open;
|
||||
}
|
||||
ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open stream: %s",
|
||||
Pa_GetErrorText(err)};
|
||||
}
|
||||
@ -314,7 +313,6 @@ void PortCapture::open(const ALCchar *name)
|
||||
break;
|
||||
case DevFmtUInt:
|
||||
case DevFmtUShort:
|
||||
ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s samples not supported",
|
||||
DevFmtTypeString(mDevice->FmtType)};
|
||||
}
|
||||
@ -323,11 +321,8 @@ void PortCapture::open(const ALCchar *name)
|
||||
PaError err{Pa_OpenStream(&mStream, &mParams, nullptr, mDevice->Frequency,
|
||||
paFramesPerBufferUnspecified, paNoFlag, &PortCapture::readCallbackC, this)};
|
||||
if(err != paNoError)
|
||||
{
|
||||
ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open stream: %s",
|
||||
Pa_GetErrorText(err)};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
|
@ -1211,7 +1211,7 @@ void PulseCapture::open(const ALCchar *name)
|
||||
chanmap = X71ChanMap;
|
||||
break;
|
||||
case DevFmtAmbi3D:
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported",
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s capture not supported",
|
||||
DevFmtChannelsString(mDevice->FmtChans)};
|
||||
}
|
||||
SetChannelOrderFromMap(mDevice, chanmap);
|
||||
|
@ -52,8 +52,9 @@ struct Sdl2Backend final : public BackendBase {
|
||||
Sdl2Backend(ALCdevice *device) noexcept : BackendBase{device} { }
|
||||
~Sdl2Backend() override;
|
||||
|
||||
static void audioCallbackC(void *ptr, Uint8 *stream, int len);
|
||||
void audioCallback(Uint8 *stream, int len);
|
||||
static void audioCallbackC(void *ptr, Uint8 *stream, int len)
|
||||
{ static_cast<Sdl2Backend*>(ptr)->audioCallback(stream, len); }
|
||||
|
||||
void open(const ALCchar *name) override;
|
||||
bool reset() override;
|
||||
@ -80,9 +81,6 @@ Sdl2Backend::~Sdl2Backend()
|
||||
mDeviceID = 0;
|
||||
}
|
||||
|
||||
void Sdl2Backend::audioCallbackC(void *ptr, Uint8 *stream, int len)
|
||||
{ static_cast<Sdl2Backend*>(ptr)->audioCallback(stream, len); }
|
||||
|
||||
void Sdl2Backend::audioCallback(Uint8 *stream, int len)
|
||||
{
|
||||
const auto ulen = static_cast<unsigned int>(len);
|
||||
@ -130,16 +128,15 @@ void Sdl2Backend::open(const ALCchar *name)
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s", SDL_GetError()};
|
||||
|
||||
mDevice->Frequency = static_cast<ALuint>(have.freq);
|
||||
|
||||
if(have.channels == 1)
|
||||
mDevice->FmtChans = DevFmtMono;
|
||||
else if(have.channels == 2)
|
||||
mDevice->FmtChans = DevFmtStereo;
|
||||
else
|
||||
{
|
||||
ERR("Got unhandled SDL channel count: %d\n", int{have.channels});
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Unhandled SDL channel count: %d",
|
||||
int{have.channels}};
|
||||
}
|
||||
|
||||
switch(have.format)
|
||||
{
|
||||
case AUDIO_U8: mDevice->FmtType = DevFmtUByte; break;
|
||||
@ -149,7 +146,6 @@ void Sdl2Backend::open(const ALCchar *name)
|
||||
case AUDIO_S32SYS: mDevice->FmtType = DevFmtInt; break;
|
||||
case AUDIO_F32SYS: mDevice->FmtType = DevFmtFloat; break;
|
||||
default:
|
||||
ERR("Got unsupported SDL format: 0x%04x\n", have.format);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Unhandled SDL format: 0x%04x",
|
||||
have.format};
|
||||
}
|
||||
|
@ -117,10 +117,7 @@ void SndioPlayback::open(const ALCchar *name)
|
||||
|
||||
mSndHandle = sio_open(nullptr, SIO_PLAY, 0);
|
||||
if(mSndHandle == nullptr)
|
||||
{
|
||||
ERR("Could not open device\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open sound device"};
|
||||
}
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open backend device"};
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
@ -329,10 +326,7 @@ void SndioCapture::open(const ALCchar *name)
|
||||
|
||||
mSndHandle = sio_open(nullptr, SIO_REC, 0);
|
||||
if(mSndHandle == nullptr)
|
||||
{
|
||||
ERR("Could not open device\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open sound device"};
|
||||
}
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open backend device"};
|
||||
|
||||
sio_par par;
|
||||
sio_initpar(&par);
|
||||
@ -364,7 +358,6 @@ void SndioCapture::open(const ALCchar *name)
|
||||
par.sig = 0;
|
||||
break;
|
||||
case DevFmtFloat:
|
||||
ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported",
|
||||
DevFmtTypeString(mDevice->FmtType)};
|
||||
}
|
||||
@ -381,40 +374,26 @@ void SndioCapture::open(const ALCchar *name)
|
||||
mDevice->BufferSize = par.appbufsz;
|
||||
|
||||
if(!sio_setpar(mSndHandle, &par) || !sio_getpar(mSndHandle, &par))
|
||||
{
|
||||
ERR("Failed to set device parameters\n");
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set device praameters"};
|
||||
}
|
||||
|
||||
if(par.bits != par.bps*8)
|
||||
{
|
||||
ERR("Padded samples not supported (%u of %u bits)\n", par.bits, par.bps*8);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Padded samples not supported (got %u of %u bits)", par.bits, par.bps*8};
|
||||
}
|
||||
|
||||
if(!((mDevice->FmtType == DevFmtByte && par.bits == 8 && par.sig != 0) ||
|
||||
(mDevice->FmtType == DevFmtUByte && par.bits == 8 && par.sig == 0) ||
|
||||
(mDevice->FmtType == DevFmtShort && par.bits == 16 && par.sig != 0) ||
|
||||
(mDevice->FmtType == DevFmtUShort && par.bits == 16 && par.sig == 0) ||
|
||||
(mDevice->FmtType == DevFmtInt && par.bits == 32 && par.sig != 0) ||
|
||||
(mDevice->FmtType == DevFmtUInt && par.bits == 32 && par.sig == 0)) ||
|
||||
mDevice->channelsFromFmt() != par.rchan || mDevice->Frequency != par.rate)
|
||||
{
|
||||
ERR("Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead\n",
|
||||
if(!((mDevice->FmtType == DevFmtByte && par.bits == 8 && par.sig != 0)
|
||||
|| (mDevice->FmtType == DevFmtUByte && par.bits == 8 && par.sig == 0)
|
||||
|| (mDevice->FmtType == DevFmtShort && par.bits == 16 && par.sig != 0)
|
||||
|| (mDevice->FmtType == DevFmtUShort && par.bits == 16 && par.sig == 0)
|
||||
|| (mDevice->FmtType == DevFmtInt && par.bits == 32 && par.sig != 0)
|
||||
|| (mDevice->FmtType == DevFmtUInt && par.bits == 32 && par.sig == 0))
|
||||
|| mDevice->channelsFromFmt() != par.rchan || mDevice->Frequency != par.rate)
|
||||
throw al::backend_exception{ALC_INVALID_VALUE,
|
||||
"Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead",
|
||||
DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans),
|
||||
mDevice->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not set format %s %s %uhz",
|
||||
DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans),
|
||||
mDevice->Frequency};
|
||||
}
|
||||
mDevice->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate};
|
||||
|
||||
mRing = CreateRingBuffer(mDevice->BufferSize, par.bps*par.rchan, false);
|
||||
if(!mRing)
|
||||
{
|
||||
ERR("Failed to allocate %u-byte ringbuffer\n", mDevice->BufferSize*par.bps*par.rchan);
|
||||
throw al::backend_exception{ALC_OUT_OF_MEMORY, "Failed to allocate ring buffer"};
|
||||
}
|
||||
if(!mRing) throw al::backend_exception{ALC_OUT_OF_MEMORY, "Failed to allocate ring buffer"};
|
||||
|
||||
SetDefaultChannelOrder(mDevice);
|
||||
|
||||
|
@ -151,11 +151,8 @@ void SolarisBackend::open(const ALCchar *name)
|
||||
|
||||
mFd = ::open(solaris_driver.c_str(), O_WRONLY);
|
||||
if(mFd == -1)
|
||||
{
|
||||
ERR("Could not open %s: %s\n", solaris_driver.c_str(), strerror(errno));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s",
|
||||
solaris_driver.c_str(), strerror(errno)};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
|
@ -762,7 +762,6 @@ void WasapiPlayback::open(const ALCchar *name)
|
||||
|
||||
mDevId.clear();
|
||||
|
||||
ERR("Device init failed: 0x%08lx\n", hr);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr};
|
||||
}
|
||||
}
|
||||
@ -1336,7 +1335,6 @@ void WasapiCapture::open(const ALCchar *name)
|
||||
|
||||
mDevId.clear();
|
||||
|
||||
ERR("Device init failed: 0x%08lx\n", hr);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr};
|
||||
}
|
||||
|
||||
|
@ -223,11 +223,8 @@ void WaveBackend::open(const ALCchar *name)
|
||||
mFile = fopen(fname, "wb");
|
||||
#endif
|
||||
if(!mFile)
|
||||
{
|
||||
ERR("Could not open file '%s': %s\n", fname, strerror(errno));
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "Could not open file '%s': %s", fname,
|
||||
strerror(errno)};
|
||||
}
|
||||
|
||||
mDevice->DeviceName = name;
|
||||
}
|
||||
|
@ -127,8 +127,9 @@ struct WinMMPlayback final : public BackendBase {
|
||||
WinMMPlayback(ALCdevice *device) noexcept : BackendBase{device} { }
|
||||
~WinMMPlayback() override;
|
||||
|
||||
static void CALLBACK waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2);
|
||||
void CALLBACK waveOutProc(HWAVEOUT device, UINT msg, DWORD_PTR param1, DWORD_PTR param2);
|
||||
static void CALLBACK waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2)
|
||||
{ reinterpret_cast<WinMMPlayback*>(instance)->waveOutProc(device, msg, param1, param2); }
|
||||
|
||||
int mixerProc();
|
||||
|
||||
@ -162,10 +163,6 @@ WinMMPlayback::~WinMMPlayback()
|
||||
std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{});
|
||||
}
|
||||
|
||||
|
||||
void CALLBACK WinMMPlayback::waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2)
|
||||
{ reinterpret_cast<WinMMPlayback*>(instance)->waveOutProc(device, msg, param1, param2); }
|
||||
|
||||
/* WinMMPlayback::waveOutProc
|
||||
*
|
||||
* Posts a message to 'WinMMPlayback::mixerProc' everytime a WaveOut Buffer is
|
||||
@ -256,7 +253,6 @@ retry_open:
|
||||
mDevice->FmtType = DevFmtShort;
|
||||
goto retry_open;
|
||||
}
|
||||
ERR("waveOutOpen failed: %u\n", res);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "waveOutOpen failed: %u", res};
|
||||
}
|
||||
|
||||
@ -368,8 +364,9 @@ struct WinMMCapture final : public BackendBase {
|
||||
WinMMCapture(ALCdevice *device) noexcept : BackendBase{device} { }
|
||||
~WinMMCapture() override;
|
||||
|
||||
static void CALLBACK waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2);
|
||||
void CALLBACK waveInProc(HWAVEIN device, UINT msg, DWORD_PTR param1, DWORD_PTR param2);
|
||||
static void CALLBACK waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2)
|
||||
{ reinterpret_cast<WinMMCapture*>(instance)->waveInProc(device, msg, param1, param2); }
|
||||
|
||||
int captureProc();
|
||||
|
||||
@ -407,9 +404,6 @@ WinMMCapture::~WinMMCapture()
|
||||
std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{});
|
||||
}
|
||||
|
||||
void CALLBACK WinMMCapture::waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2)
|
||||
{ reinterpret_cast<WinMMCapture*>(instance)->waveInProc(device, msg, param1, param2); }
|
||||
|
||||
/* WinMMCapture::waveInProc
|
||||
*
|
||||
* Posts a message to 'WinMMCapture::captureProc' everytime a WaveIn Buffer is
|
||||
@ -513,10 +507,7 @@ void WinMMCapture::open(const ALCchar *name)
|
||||
reinterpret_cast<DWORD_PTR>(&WinMMCapture::waveInProcC),
|
||||
reinterpret_cast<DWORD_PTR>(this), CALLBACK_FUNCTION)};
|
||||
if(res != MMSYSERR_NOERROR)
|
||||
{
|
||||
ERR("waveInOpen failed: %u\n", res);
|
||||
throw al::backend_exception{ALC_INVALID_VALUE, "waveInOpen failed: %u", res};
|
||||
}
|
||||
|
||||
// Ensure each buffer is 50ms each
|
||||
DWORD BufferSize{mFormat.nAvgBytesPerSec / 20u};
|
||||
|
Loading…
x
Reference in New Issue
Block a user