diff options
-rw-r--r-- | Alc/ALc.c | 260 | ||||
-rw-r--r-- | Alc/ALu.c | 63 | ||||
-rw-r--r-- | Alc/alsa.c | 86 | ||||
-rw-r--r-- | Alc/dsound.c | 98 | ||||
-rw-r--r-- | Alc/null.c | 3 | ||||
-rw-r--r-- | Alc/oss.c | 74 | ||||
-rw-r--r-- | Alc/panning.c | 29 | ||||
-rw-r--r-- | Alc/portaudio.c | 40 | ||||
-rw-r--r-- | Alc/pulseaudio.c | 55 | ||||
-rw-r--r-- | Alc/solaris.c | 41 | ||||
-rw-r--r-- | Alc/wave.c | 39 | ||||
-rw-r--r-- | Alc/winmm.c | 46 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 28 |
13 files changed, 475 insertions, 387 deletions
@@ -778,6 +778,112 @@ ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key) } +ALuint BytesFromDevFmt(enum DevFmtType type) +{ + switch(type) + { + case DevFmtByte: return sizeof(ALbyte); + case DevFmtUByte: return sizeof(ALubyte); + case DevFmtShort: return sizeof(ALshort); + case DevFmtUShort: return sizeof(ALushort); + case DevFmtFloat: return sizeof(ALfloat); + } + return 0; +} +ALuint ChannelsFromDevFmt(enum DevFmtChannels chans) +{ + switch(chans) + { + case DevFmtMono: return 1; + case DevFmtStereo: return 2; + case DevFmtQuad: return 4; + case DevFmtX51: return 6; + case DevFmtX61: return 7; + case DevFmtX71: return 8; + } + return 0; +} +ALboolean DecomposeDevFormat(ALenum format, enum DevFmtChannels *chans, + enum DevFmtType *type) +{ + switch(format) + { + case AL_FORMAT_MONO8: + *chans = DevFmtMono; + *type = DevFmtUByte; + return AL_TRUE; + case AL_FORMAT_MONO16: + *chans = DevFmtMono; + *type = DevFmtShort; + return AL_TRUE; + case AL_FORMAT_MONO_FLOAT32: + *chans = DevFmtMono; + *type = DevFmtFloat; + return AL_TRUE; + case AL_FORMAT_STEREO8: + *chans = DevFmtStereo; + *type = DevFmtUByte; + return AL_TRUE; + case AL_FORMAT_STEREO16: + *chans = DevFmtStereo; + *type = DevFmtShort; + return AL_TRUE; + case AL_FORMAT_STEREO_FLOAT32: + *chans = DevFmtStereo; + *type = DevFmtFloat; + return AL_TRUE; + case AL_FORMAT_QUAD8: + *chans = DevFmtQuad; + *type = DevFmtUByte; + return AL_TRUE; + case AL_FORMAT_QUAD16: + *chans = DevFmtQuad; + *type = DevFmtShort; + return AL_TRUE; + case AL_FORMAT_QUAD32: + *chans = DevFmtQuad; + *type = DevFmtFloat; + return AL_TRUE; + case AL_FORMAT_51CHN8: + *chans = DevFmtX51; + *type = DevFmtUByte; + return AL_TRUE; + case AL_FORMAT_51CHN16: + *chans = DevFmtX51; + *type = DevFmtShort; + return AL_TRUE; + case AL_FORMAT_51CHN32: + *chans = DevFmtX51; + *type = DevFmtFloat; + return AL_TRUE; + case AL_FORMAT_61CHN8: + *chans = DevFmtX61; + *type = DevFmtUByte; + return AL_TRUE; + case AL_FORMAT_61CHN16: + *chans = DevFmtX61; + *type = DevFmtShort; + return AL_TRUE; + case AL_FORMAT_61CHN32: + *chans = DevFmtX61; + *type = DevFmtFloat; + return AL_TRUE; + case AL_FORMAT_71CHN8: + *chans = DevFmtX71; + *type = DevFmtUByte; + return AL_TRUE; + case AL_FORMAT_71CHN16: + *chans = DevFmtX71; + *type = DevFmtShort; + return AL_TRUE; + case AL_FORMAT_71CHN32: + *chans = DevFmtX71; + *type = DevFmtFloat; + return AL_TRUE; + } + return AL_FALSE; +} + /* IsDevice @@ -972,7 +1078,7 @@ static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->Bs2b = NULL; } - if(aluChannelsFromFormat(device->Format) <= 2) + if(ChannelsFromDevFmt(device->FmtChans) <= 2) { device->HeadDampen = GetConfigValueFloat(NULL, "head_dampen", DEFAULT_HEAD_DAMPEN); device->HeadDampen = __min(device->HeadDampen, 1.0f); @@ -1127,7 +1233,13 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, device->szDeviceName = NULL; device->Frequency = frequency; - device->Format = format; + if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE) + { + free(device); + alcSetError(NULL, ALC_INVALID_ENUM); + return NULL; + } + device->UpdateSize = SampleSize; device->NumUpdates = 1; @@ -1882,81 +1994,81 @@ ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context) // Sets the default channel order used by most non-WaveFormatEx-based APIs void SetDefaultChannelOrder(ALCdevice *device) { - switch(aluChannelsFromFormat(device->Format)) + switch(device->FmtChans) { - case 1: device->DevChannels[FRONT_CENTER] = 0; break; - - case 2: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; break; - - case 4: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[BACK_LEFT] = 2; - device->DevChannels[BACK_RIGHT] = 3; break; - - case 6: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[BACK_LEFT] = 2; - device->DevChannels[BACK_RIGHT] = 3; - device->DevChannels[FRONT_CENTER] = 4; - device->DevChannels[LFE] = 5; break; - - case 7: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[FRONT_CENTER] = 2; - device->DevChannels[LFE] = 3; - device->DevChannels[BACK_CENTER] = 4; - device->DevChannels[SIDE_LEFT] = 5; - device->DevChannels[SIDE_RIGHT] = 6; break; - - case 8: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[BACK_LEFT] = 2; - device->DevChannels[BACK_RIGHT] = 3; - device->DevChannels[FRONT_CENTER] = 4; - device->DevChannels[LFE] = 5; - device->DevChannels[SIDE_LEFT] = 6; - device->DevChannels[SIDE_RIGHT] = 7; break; + case DevFmtMono: device->DevChannels[FRONT_CENTER] = 0; break; + + case DevFmtStereo: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; break; + + case DevFmtQuad: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[BACK_LEFT] = 2; + device->DevChannels[BACK_RIGHT] = 3; break; + + case DevFmtX51: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[BACK_LEFT] = 2; + device->DevChannels[BACK_RIGHT] = 3; + device->DevChannels[FRONT_CENTER] = 4; + device->DevChannels[LFE] = 5; break; + + case DevFmtX61: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[FRONT_CENTER] = 2; + device->DevChannels[LFE] = 3; + device->DevChannels[BACK_CENTER] = 4; + device->DevChannels[SIDE_LEFT] = 5; + device->DevChannels[SIDE_RIGHT] = 6; break; + + case DevFmtX71: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[BACK_LEFT] = 2; + device->DevChannels[BACK_RIGHT] = 3; + device->DevChannels[FRONT_CENTER] = 4; + device->DevChannels[LFE] = 5; + device->DevChannels[SIDE_LEFT] = 6; + device->DevChannels[SIDE_RIGHT] = 7; break; } } // Sets the default order used by WaveFormatEx void SetDefaultWFXChannelOrder(ALCdevice *device) { - switch(aluChannelsFromFormat(device->Format)) + switch(device->FmtChans) { - case 1: device->DevChannels[FRONT_CENTER] = 0; break; - - case 2: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; break; - - case 4: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[BACK_LEFT] = 2; - device->DevChannels[BACK_RIGHT] = 3; break; - - case 6: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[FRONT_CENTER] = 2; - device->DevChannels[LFE] = 3; - device->DevChannels[BACK_LEFT] = 4; - device->DevChannels[BACK_RIGHT] = 5; break; - - case 7: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[FRONT_CENTER] = 2; - device->DevChannels[LFE] = 3; - device->DevChannels[BACK_CENTER] = 4; - device->DevChannels[SIDE_LEFT] = 5; - device->DevChannels[SIDE_RIGHT] = 6; break; - - case 8: device->DevChannels[FRONT_LEFT] = 0; - device->DevChannels[FRONT_RIGHT] = 1; - device->DevChannels[FRONT_CENTER] = 2; - device->DevChannels[LFE] = 3; - device->DevChannels[BACK_LEFT] = 4; - device->DevChannels[BACK_RIGHT] = 5; - device->DevChannels[SIDE_LEFT] = 6; - device->DevChannels[SIDE_RIGHT] = 7; break; + case DevFmtMono: device->DevChannels[FRONT_CENTER] = 0; break; + + case DevFmtStereo: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; break; + + case DevFmtQuad: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[BACK_LEFT] = 2; + device->DevChannels[BACK_RIGHT] = 3; break; + + case DevFmtX51: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[FRONT_CENTER] = 2; + device->DevChannels[LFE] = 3; + device->DevChannels[BACK_LEFT] = 4; + device->DevChannels[BACK_RIGHT] = 5; break; + + case DevFmtX61: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[FRONT_CENTER] = 2; + device->DevChannels[LFE] = 3; + device->DevChannels[BACK_CENTER] = 4; + device->DevChannels[SIDE_LEFT] = 5; + device->DevChannels[SIDE_RIGHT] = 6; break; + + case DevFmtX71: device->DevChannels[FRONT_LEFT] = 0; + device->DevChannels[FRONT_RIGHT] = 1; + device->DevChannels[FRONT_CENTER] = 2; + device->DevChannels[LFE] = 3; + device->DevChannels[BACK_LEFT] = 4; + device->DevChannels[BACK_RIGHT] = 5; + device->DevChannels[SIDE_LEFT] = 6; + device->DevChannels[SIDE_RIGHT] = 7; break; } } @@ -2031,7 +2143,13 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->Frequency = 8000; fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16"); - device->Format = GetFormatFromString(fmt); + if(DecomposeDevFormat(GetFormatFromString(fmt), + &device->FmtChans, &device->FmtType) == AL_FALSE) + { + /* Should never happen... */ + device->FmtChans = DevFmtStereo; + device->FmtType = DevFmtShort; + } device->NumUpdates = GetConfigValueInt(NULL, "periods", 4); if(device->NumUpdates < 2) @@ -186,6 +186,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) { ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume; ALbufferlistitem *BufferListItem; + enum DevFmtChannels DevChans; enum FmtChannels Channels; ALfloat DryGain, DryGainHF; ALfloat WetGain[MAX_SENDS]; @@ -193,12 +194,11 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALint NumSends, Frequency; ALboolean DupStereo; ALfloat Pitch; - ALenum Format; ALfloat cw; ALint i; /* Get device properties */ - Format = ALContext->Device->Format; + DevChans = ALContext->Device->FmtChans; DupStereo = ALContext->Device->DuplicateStereo; NumSends = ALContext->Device->NumAuxSends; Frequency = ALContext->Device->Frequency; @@ -268,24 +268,16 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) } else { - switch(Format) + switch(DevChans) { - case AL_FORMAT_MONO8: - case AL_FORMAT_MONO16: - case AL_FORMAT_MONO_FLOAT32: - case AL_FORMAT_STEREO8: - case AL_FORMAT_STEREO16: - case AL_FORMAT_STEREO_FLOAT32: + case DevFmtMono: + case DevFmtStereo: ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; break; - case AL_FORMAT_QUAD8: - case AL_FORMAT_QUAD16: - case AL_FORMAT_QUAD32: - case AL_FORMAT_51CHN8: - case AL_FORMAT_51CHN16: - case AL_FORMAT_51CHN32: + case DevFmtQuad: + case DevFmtX51: DryGain *= aluSqrt(2.0f/4.0f); ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; @@ -293,9 +285,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALSource->Params.DryGains[BACK_RIGHT] = DryGain * ListenerGain; break; - case AL_FORMAT_61CHN8: - case AL_FORMAT_61CHN16: - case AL_FORMAT_61CHN32: + case DevFmtX61: DryGain *= aluSqrt(2.0f/4.0f); ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; @@ -303,9 +293,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain; break; - case AL_FORMAT_71CHN8: - case AL_FORMAT_71CHN16: - case AL_FORMAT_71CHN32: + case DevFmtX71: DryGain *= aluSqrt(2.0f/6.0f); ALSource->Params.DryGains[FRONT_LEFT] = DryGain * ListenerGain; ALSource->Params.DryGains[FRONT_RIGHT] = DryGain * ListenerGain; @@ -314,9 +302,6 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALSource->Params.DryGains[SIDE_LEFT] = DryGain * ListenerGain; ALSource->Params.DryGains[SIDE_RIGHT] = DryGain * ListenerGain; break; - - default: - break; } } } @@ -915,24 +900,24 @@ DECL_TEMPLATE(ALbyte, StereoChans,2, aluF2B) #define DECL_TEMPLATE(T, func) \ static void Write_##T(ALCdevice *device, T *buffer, ALuint SamplesToDo) \ { \ - switch(aluChannelsFromFormat(device->Format)) \ + switch(device->FmtChans) \ { \ - case 1: \ + case DevFmtMono: \ Write_##T##_MonoChans(device, buffer, SamplesToDo); \ break; \ - case 2: \ + case DevFmtStereo: \ Write_##T##_StereoChans(device, buffer, SamplesToDo); \ break; \ - case 4: \ + case DevFmtQuad: \ Write_##T##_QuadChans(device, buffer, SamplesToDo); \ break; \ - case 6: \ + case DevFmtX51: \ Write_##T##_X51Chans(device, buffer, SamplesToDo); \ break; \ - case 7: \ + case DevFmtX61: \ Write_##T##_X61Chans(device, buffer, SamplesToDo); \ break; \ - case 8: \ + case DevFmtX71: \ Write_##T##_X71Chans(device, buffer, SamplesToDo); \ break; \ } \ @@ -1045,17 +1030,21 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) device->PendingClicks[i] = 0.0f; } - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - (void)Write_ALbyte; - case 1: + case DevFmtByte: + Write_ALbyte(device, buffer, SamplesToDo); + break; + case DevFmtUByte: Write_ALubyte(device, buffer, SamplesToDo); break; - case 2: + case DevFmtShort: Write_ALshort(device, buffer, SamplesToDo); break; - (void)Write_ALushort; - case 4: + case DevFmtUShort: + Write_ALushort(device, buffer, SamplesToDo); + break; + case DevFmtFloat: Write_ALfloat(device, buffer, SamplesToDo); break; } @@ -543,20 +543,24 @@ static ALCboolean alsa_reset_playback(ALCdevice *device) int i; - switch(aluBytesFromFormat(device->Format)) + format = -1; + switch(device->FmtType) { - case 1: + case DevFmtByte: + format = SND_PCM_FORMAT_S8; + break; + case DevFmtUByte: format = SND_PCM_FORMAT_U8; break; - case 2: + case DevFmtShort: format = SND_PCM_FORMAT_S16; break; - case 4: + case DevFmtUShort: + format = SND_PCM_FORMAT_U16; + break; + case DevFmtFloat: format = SND_PCM_FORMAT_FLOAT; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); - return ALC_FALSE; } allowmmap = GetConfigValueBool("alsa", "mmap", 1); @@ -584,39 +588,15 @@ static ALCboolean alsa_reset_playback(ALCdevice *device) /* set format (implicitly sets sample bits) */ if(i >= 0 && (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, format)) < 0) { - switch(aluChannelsFromFormat(device->Format)) - { - case 1: device->Format = AL_FORMAT_MONO_FLOAT32; break; - case 2: device->Format = AL_FORMAT_STEREO_FLOAT32; break; - case 4: device->Format = AL_FORMAT_QUAD32; break; - case 6: device->Format = AL_FORMAT_51CHN32; break; - case 7: device->Format = AL_FORMAT_61CHN32; break; - case 8: device->Format = AL_FORMAT_71CHN32; break; - } + device->FmtType = DevFmtFloat; if(format == SND_PCM_FORMAT_FLOAT || (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, SND_PCM_FORMAT_FLOAT)) < 0) { - switch(aluChannelsFromFormat(device->Format)) - { - case 1: device->Format = AL_FORMAT_MONO16; break; - case 2: device->Format = AL_FORMAT_STEREO16; break; - case 4: device->Format = AL_FORMAT_QUAD16; break; - case 6: device->Format = AL_FORMAT_51CHN16; break; - case 7: device->Format = AL_FORMAT_61CHN16; break; - case 8: device->Format = AL_FORMAT_71CHN16; break; - } + device->FmtType = DevFmtShort; if(format == SND_PCM_FORMAT_S16 || (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, SND_PCM_FORMAT_S16)) < 0) { - switch(aluChannelsFromFormat(device->Format)) - { - case 1: device->Format = AL_FORMAT_MONO8; break; - case 2: device->Format = AL_FORMAT_STEREO8; break; - case 4: device->Format = AL_FORMAT_QUAD8; break; - case 6: device->Format = AL_FORMAT_51CHN8; break; - case 7: device->Format = AL_FORMAT_61CHN8; break; - case 8: device->Format = AL_FORMAT_71CHN8; break; - } + device->FmtType = DevFmtUByte; if(format == SND_PCM_FORMAT_U8 || (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, SND_PCM_FORMAT_U8)) < 0) err = "set format"; @@ -624,22 +604,12 @@ static ALCboolean alsa_reset_playback(ALCdevice *device) } } /* set channels (implicitly sets frame bits) */ - if(i >= 0 && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(device->Format))) < 0) + if(i >= 0 && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, ChannelsFromDevFmt(device->FmtChans))) < 0) { - switch(aluBytesFromFormat(device->Format)) - { - case 1: device->Format = AL_FORMAT_STEREO8; break; - case 2: device->Format = AL_FORMAT_STEREO16; break; - case 4: device->Format = AL_FORMAT_STEREO_FLOAT32; break; - } + device->FmtChans = DevFmtStereo; if((i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, 2)) < 0) { - switch(aluBytesFromFormat(device->Format)) - { - case 1: device->Format = AL_FORMAT_MONO8; break; - case 2: device->Format = AL_FORMAT_MONO16; break; - case 4: device->Format = AL_FORMAT_MONO_FLOAT32; break; - } + device->FmtChans = DevFmtMono; if((i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, 1)) < 0) err = "set channels"; } @@ -803,20 +773,24 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam return ALC_FALSE; } - switch(aluBytesFromFormat(pDevice->Format)) + format = -1; + switch(pDevice->FmtType) { - case 1: + case DevFmtByte: + format = SND_PCM_FORMAT_S8; + break; + case DevFmtUByte: format = SND_PCM_FORMAT_U8; break; - case 2: + case DevFmtShort: format = SND_PCM_FORMAT_S16; break; - case 4: + case DevFmtUShort: + format = SND_PCM_FORMAT_U16; + break; + case DevFmtFloat: format = SND_PCM_FORMAT_FLOAT; break; - default: - AL_PRINT("Unknown format: 0x%x\n", pDevice->Format); - goto error; } err = NULL; @@ -832,7 +806,7 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam if(i >= 0 && (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, format)) < 0) err = "set format"; /* set channels (implicitly sets frame bits) */ - if(i >= 0 && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(pDevice->Format))) < 0) + if(i >= 0 && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, ChannelsFromDevFmt(pDevice->FmtChans))) < 0) err = "set channels"; /* set rate (implicitly constrains period/buffer parameters) */ if(i >= 0 && (i=psnd_pcm_hw_params_set_rate(data->pcmHandle, p, pDevice->Frequency, 0)) < 0) @@ -859,7 +833,7 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam psnd_pcm_hw_params_free(p); - frameSize = aluFrameSizeFromFormat(pDevice->Format); + frameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); data->ring = CreateRingBuffer(frameSize, pDevice->UpdateSize*pDevice->NumUpdates); if(!data->ring) diff --git a/Alc/dsound.c b/Alc/dsound.c index ce7dd80d..39f3e97f 100644 --- a/Alc/dsound.c +++ b/Alc/dsound.c @@ -188,7 +188,7 @@ static ALuint DSoundProc(ALvoid *ptr) return 1; } - FrameSize = aluFrameSizeFromFormat(pDevice->Format); + FrameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); FragSize = pDevice->UpdateSize * FrameSize; IDirectSoundBuffer_GetCurrentPosition(pData->DSsbuffer, &LastCursor, NULL); @@ -332,30 +332,48 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) DSoundData *pData = (DSoundData*)device->ExtraData; DSBUFFERDESC DSBDescription; WAVEFORMATEXTENSIBLE OutputType; - DWORD frameSize = 0; - ALenum format = 0; DWORD speakers; HRESULT hr; memset(&OutputType, 0, sizeof(OutputType)); + switch(device->FmtType) + { + case DevFmtByte: + device->FmtType = DevFmtUByte; + break; + case DevFmtUShort: + device->FmtType = DevFmtShort; + break; + case DevFmtUByte: + case DevFmtShort: + case DevFmtFloat: + break; + } + hr = IDirectSound_GetSpeakerConfig(pData->lpDS, &speakers); if(SUCCEEDED(hr) && ConfigValueExists(NULL, "format")) { - if(aluChannelsFromFormat(device->Format) == 1) - speakers = DSSPEAKER_COMBINED(DSSPEAKER_MONO, 0); - else if(aluChannelsFromFormat(device->Format) == 2) - speakers = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, 0); - else if(aluChannelsFromFormat(device->Format) == 4) - speakers = DSSPEAKER_COMBINED(DSSPEAKER_QUAD, 0); - else if(aluChannelsFromFormat(device->Format) == 6) - speakers = DSSPEAKER_COMBINED(DSSPEAKER_5POINT1, 0); - else if(aluChannelsFromFormat(device->Format) == 8) - speakers = DSSPEAKER_COMBINED(DSSPEAKER_7POINT1, 0); - else + switch(device->FmtChans) { - AL_PRINT("Unknown format: 0x%x\n", device->Format); - return ALC_FALSE; + case DevFmtMono: + speakers = DSSPEAKER_COMBINED(DSSPEAKER_MONO, 0); + break; + case DevFmtStereo: + speakers = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, 0); + break; + case DevFmtQuad: + speakers = DSSPEAKER_COMBINED(DSSPEAKER_QUAD, 0); + break; + case DevFmtX51: + speakers = DSSPEAKER_COMBINED(DSSPEAKER_5POINT1, 0); + break; + case DevFmtX61: + /* ??? */; + break; + case DevFmtX71: + speakers = DSSPEAKER_COMBINED(DSSPEAKER_7POINT1, 0); + break; } } if(SUCCEEDED(hr)) @@ -363,33 +381,18 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) speakers = DSSPEAKER_CONFIG(speakers); if(speakers == DSSPEAKER_MONO) { - if(aluBytesFromFormat(device->Format) == 1) - format = AL_FORMAT_MONO8; - else if(aluBytesFromFormat(device->Format) == 2) - format = AL_FORMAT_MONO16; - else if(aluBytesFromFormat(device->Format) == 4) - format = AL_FORMAT_MONO_FLOAT32; + device->FmtChans = DevFmtMono; OutputType.dwChannelMask = SPEAKER_FRONT_CENTER; } - else if(speakers == DSSPEAKER_STEREO) + else if(speakers == DSSPEAKER_STEREO || speakers == DSSPEAKER_HEADPHONE) { - if(aluBytesFromFormat(device->Format) == 1) - format = AL_FORMAT_STEREO8; - else if(aluBytesFromFormat(device->Format) == 2) - format = AL_FORMAT_STEREO16; - else if(aluBytesFromFormat(device->Format) == 4) - format = AL_FORMAT_STEREO_FLOAT32; + device->FmtChans = DevFmtStereo; OutputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; } else if(speakers == DSSPEAKER_QUAD) { - if(aluBytesFromFormat(device->Format) == 1) - format = AL_FORMAT_QUAD8; - else if(aluBytesFromFormat(device->Format) == 2) - format = AL_FORMAT_QUAD16; - else if(aluBytesFromFormat(device->Format) == 4) - format = AL_FORMAT_QUAD32; + device->FmtChans = DevFmtQuad; OutputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | @@ -397,12 +400,7 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) } else if(speakers == DSSPEAKER_5POINT1) { - if(aluBytesFromFormat(device->Format) == 1) - format = AL_FORMAT_51CHN8; - else if(aluBytesFromFormat(device->Format) == 2) - format = AL_FORMAT_51CHN16; - else if(aluBytesFromFormat(device->Format) == 4) - format = AL_FORMAT_51CHN32; + device->FmtChans = DevFmtX51; OutputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | @@ -412,12 +410,7 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) } else if(speakers == DSSPEAKER_7POINT1) { - if(aluBytesFromFormat(device->Format) == 1) - format = AL_FORMAT_71CHN8; - else if(aluBytesFromFormat(device->Format) == 2) - format = AL_FORMAT_71CHN16; - else if(aluBytesFromFormat(device->Format) == 4) - format = AL_FORMAT_71CHN32; + device->FmtChans = DevFmtX71; OutputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | @@ -427,13 +420,10 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT; } - else - format = device->Format; - frameSize = aluFrameSizeFromFormat(format); OutputType.Format.wFormatTag = WAVE_FORMAT_PCM; - OutputType.Format.nChannels = aluChannelsFromFormat(format); - OutputType.Format.wBitsPerSample = aluBytesFromFormat(format) * 8; + OutputType.Format.nChannels = ChannelsFromDevFmt(device->FmtChans); + OutputType.Format.wBitsPerSample = BytesFromDevFmt(device->FmtType) * 8; OutputType.Format.nBlockAlign = OutputType.Format.nChannels*OutputType.Format.wBitsPerSample/8; OutputType.Format.nSamplesPerSec = device->Frequency; OutputType.Format.nAvgBytesPerSec = OutputType.Format.nSamplesPerSec*OutputType.Format.nBlockAlign; @@ -468,14 +458,14 @@ static ALCboolean DSoundResetPlayback(ALCdevice *device) memset(&DSBDescription,0,sizeof(DSBUFFERDESC)); DSBDescription.dwSize=sizeof(DSBUFFERDESC); DSBDescription.dwFlags=DSBCAPS_GLOBALFOCUS|DSBCAPS_GETCURRENTPOSITION2; - DSBDescription.dwBufferBytes=device->UpdateSize * device->NumUpdates * frameSize; + DSBDescription.dwBufferBytes=device->UpdateSize * device->NumUpdates * + OutputType.Format.nBlockAlign; DSBDescription.lpwfxFormat=&OutputType.Format; hr = IDirectSound_CreateSoundBuffer(pData->lpDS, &DSBDescription, &pData->DSsbuffer, NULL); } if(SUCCEEDED(hr)) { - device->Format = format; SetDefaultWFXChannelOrder(device); pData->thread = StartThread(DSoundProc, device); if(!pData->thread) @@ -104,7 +104,8 @@ static ALCboolean null_reset_playback(ALCdevice *device) { null_data *data = (null_data*)device->ExtraData; - data->size = device->UpdateSize * aluFrameSizeFromFormat(device->Format); + data->size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, + device->FmtType); data->buffer = malloc(data->size); if(!data->buffer) { @@ -83,7 +83,7 @@ static ALuint OSSProc(ALvoid *ptr) SetRTPriority(); - frameSize = aluFrameSizeFromFormat(pDevice->Format); + frameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); while(!data->killNow && pDevice->Connected) { @@ -124,7 +124,7 @@ static ALuint OSSCaptureProc(ALvoid *ptr) SetRTPriority(); - frameSize = aluFrameSizeFromFormat(pDevice->Format); + frameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); while(!data->killNow) { @@ -198,33 +198,26 @@ static ALCboolean oss_reset_playback(ALCdevice *device) char *err; int i; - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - case 1: + case DevFmtByte: + ossFormat = AFMT_S8; + break; + case DevFmtUByte: ossFormat = AFMT_U8; break; - case 4: - switch(aluChannelsFromFormat(device->Format)) - { - case 1: device->Format = AL_FORMAT_MONO16; break; - case 2: device->Format = AL_FORMAT_STEREO16; break; - case 4: device->Format = AL_FORMAT_QUAD16; break; - case 6: device->Format = AL_FORMAT_51CHN16; break; - case 7: device->Format = AL_FORMAT_61CHN16; break; - case 8: device->Format = AL_FORMAT_71CHN16; break; - } + case DevFmtUShort: + case DevFmtFloat: + device->FmtType = DevFmtShort; /* fall-through */ - case 2: + case DevFmtShort: ossFormat = AFMT_S16_NE; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); - return ALC_FALSE; } periods = device->NumUpdates; - numChannels = aluChannelsFromFormat(device->Format); - frameSize = numChannels * aluBytesFromFormat(device->Format); + numChannels = ChannelsFromDevFmt(device->FmtChans); + frameSize = numChannels * BytesFromDevFmt(device->FmtType); ossSpeed = device->Frequency; log2FragmentSize = log2i(device->UpdateSize * frameSize); @@ -251,16 +244,17 @@ static ALCboolean oss_reset_playback(ALCdevice *device) } #undef ok - if((int)aluChannelsFromFormat(device->Format) != numChannels) + if((int)ChannelsFromDevFmt(device->FmtChans) != numChannels) { - AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device->Format), numChannels); + AL_PRINT("Could not set %d channels, got %d instead\n", ChannelsFromDevFmt(device->FmtChans), numChannels); return ALC_FALSE; } - if(!((ossFormat == AFMT_U8 && aluBytesFromFormat(device->Format) == 1) || - (ossFormat == AFMT_S16_NE && aluBytesFromFormat(device->Format) == 2))) + if(!((ossFormat == AFMT_S8 && device->FmtType == DevFmtByte) || + (ossFormat == AFMT_U8 && device->FmtType == DevFmtUByte) || + (ossFormat == AFMT_S16_NE && device->FmtType == DevFmtShort))) { - AL_PRINT("Could not set %d-bit output, got format %#x\n", aluBytesFromFormat(device->Format)*8, ossFormat); + AL_PRINT("Could not set %#x format type, got OSS format %#x\n", device->FmtType, ossFormat); return ALC_FALSE; } @@ -337,24 +331,27 @@ static ALCboolean oss_open_capture(ALCdevice *device, const ALCchar *deviceName) return ALC_FALSE; } - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - case 1: + case DevFmtByte: + ossFormat = AFMT_S8; + break; + case DevFmtUByte: ossFormat = AFMT_U8; break; - case 2: + case DevFmtShort: ossFormat = AFMT_S16_NE; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); - close(data->fd); + case DevFmtUShort: + case DevFmtFloat: free(data); + AL_PRINT("Format type %#x capture not supported on OSS\n", device->FmtType); return ALC_FALSE; } periods = 4; - numChannels = aluChannelsFromFormat(device->Format); - frameSize = numChannels * aluBytesFromFormat(device->Format); + numChannels = ChannelsFromDevFmt(device->FmtChans); + frameSize = numChannels * BytesFromDevFmt(device->FmtType); ossSpeed = device->Frequency; log2FragmentSize = log2i(device->UpdateSize * device->NumUpdates * frameSize / periods); @@ -378,18 +375,19 @@ static ALCboolean oss_open_capture(ALCdevice *device, const ALCchar *deviceName) } #undef ok - if((int)aluChannelsFromFormat(device->Format) != numChannels) + if((int)ChannelsFromDevFmt(device->FmtChans) != numChannels) { - AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device->Format), numChannels); + AL_PRINT("Could not set %d channels, got %d instead\n", ChannelsFromDevFmt(device->FmtChans), numChannels); close(data->fd); free(data); return ALC_FALSE; } - if(!((ossFormat == AFMT_U8 && aluBytesFromFormat(device->Format) == 1) || - (ossFormat == AFMT_S16_NE && aluBytesFromFormat(device->Format) == 2))) + if(!((ossFormat == AFMT_S8 && device->FmtType == DevFmtByte) || + (ossFormat == AFMT_U8 && device->FmtType == DevFmtUByte) || + (ossFormat == AFMT_S16_NE && device->FmtType == DevFmtShort))) { - AL_PRINT("Could not set %d-bit input, got format %#x\n", aluBytesFromFormat(device->Format)*8, ossFormat); + AL_PRINT("Could not set %#x format type, got OSS format %#x\n", device->FmtType, ossFormat); close(data->fd); free(data); return ALC_FALSE; diff --git a/Alc/panning.c b/Alc/panning.c index 89d359f5..4c055264 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -178,11 +178,9 @@ ALvoid aluInitPanning(ALCdevice *Device) Speaker2Chan = Device->Speaker2Chan; Matrix = Device->ChannelMatrix; - switch(Device->Format) + switch(Device->FmtChans) { - case AL_FORMAT_MONO8: - case AL_FORMAT_MONO16: - case AL_FORMAT_MONO_FLOAT32: + case DevFmtMono: Matrix[FRONT_LEFT][FRONT_CENTER] = aluSqrt(0.5); Matrix[FRONT_RIGHT][FRONT_CENTER] = aluSqrt(0.5); Matrix[SIDE_LEFT][FRONT_CENTER] = aluSqrt(0.5); @@ -195,9 +193,7 @@ ALvoid aluInitPanning(ALCdevice *Device) SpeakerAngle[0] = 0.0f * M_PI/180.0f; break; - case AL_FORMAT_STEREO8: - case AL_FORMAT_STEREO16: - case AL_FORMAT_STEREO_FLOAT32: + case DevFmtStereo: Matrix[FRONT_CENTER][FRONT_LEFT] = aluSqrt(0.5); Matrix[FRONT_CENTER][FRONT_RIGHT] = aluSqrt(0.5); Matrix[SIDE_LEFT][FRONT_LEFT] = 1.0f; @@ -214,9 +210,7 @@ ALvoid aluInitPanning(ALCdevice *Device) SetSpeakerArrangement("layout", SpeakerAngle, Speaker2Chan, Device->NumChan); break; - case AL_FORMAT_QUAD8: - case AL_FORMAT_QUAD16: - case AL_FORMAT_QUAD32: + case DevFmtQuad: Matrix[FRONT_CENTER][FRONT_LEFT] = aluSqrt(0.5); Matrix[FRONT_CENTER][FRONT_RIGHT] = aluSqrt(0.5); Matrix[SIDE_LEFT][FRONT_LEFT] = aluSqrt(0.5); @@ -237,9 +231,7 @@ ALvoid aluInitPanning(ALCdevice *Device) SetSpeakerArrangement("layout", SpeakerAngle, Speaker2Chan, Device->NumChan); break; - case AL_FORMAT_51CHN8: - case AL_FORMAT_51CHN16: - case AL_FORMAT_51CHN32: + case DevFmtX51: Matrix[SIDE_LEFT][FRONT_LEFT] = aluSqrt(0.5); Matrix[SIDE_LEFT][BACK_LEFT] = aluSqrt(0.5); Matrix[SIDE_RIGHT][FRONT_RIGHT] = aluSqrt(0.5); @@ -260,9 +252,7 @@ ALvoid aluInitPanning(ALCdevice *Device) SetSpeakerArrangement("layout", SpeakerAngle, Speaker2Chan, Device->NumChan); break; - case AL_FORMAT_61CHN8: - case AL_FORMAT_61CHN16: - case AL_FORMAT_61CHN32: + case DevFmtX61: Matrix[BACK_LEFT][BACK_CENTER] = aluSqrt(0.5); Matrix[BACK_LEFT][SIDE_LEFT] = aluSqrt(0.5); Matrix[BACK_RIGHT][BACK_CENTER] = aluSqrt(0.5); @@ -283,9 +273,7 @@ ALvoid aluInitPanning(ALCdevice *Device) SetSpeakerArrangement("layout", SpeakerAngle, Speaker2Chan, Device->NumChan); break; - case AL_FORMAT_71CHN8: - case AL_FORMAT_71CHN16: - case AL_FORMAT_71CHN32: + case DevFmtX71: Matrix[BACK_CENTER][BACK_LEFT] = aluSqrt(0.5); Matrix[BACK_CENTER][BACK_RIGHT] = aluSqrt(0.5); Device->NumChan = 7; @@ -305,9 +293,6 @@ ALvoid aluInitPanning(ALCdevice *Device) SpeakerAngle[6] = 150.0f * M_PI/180.0f; SetSpeakerArrangement("layout", SpeakerAngle, Speaker2Chan, Device->NumChan); break; - - default: - assert(0); } if(GetConfigValueBool(NULL, "scalemix", 0)) diff --git a/Alc/portaudio.c b/Alc/portaudio.c index 2b8e0fa4..77c7236f 100644 --- a/Alc/portaudio.c +++ b/Alc/portaudio.c @@ -190,24 +190,25 @@ static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName) (float)device->Frequency; outParams.hostApiSpecificStreamInfo = NULL; - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - case 1: + case DevFmtByte: + outParams.sampleFormat = paInt8; + break; + case DevFmtUByte: outParams.sampleFormat = paUInt8; break; - case 2: + case DevFmtUShort: + device->FmtType = DevFmtShort; + /* fall-through */ + case DevFmtShort: outParams.sampleFormat = paInt16; break; - case 4: + case DevFmtFloat: outParams.sampleFormat = paFloat32; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); - device->ExtraData = NULL; - free(data); - return ALC_FALSE; } - outParams.channelCount = aluChannelsFromFormat(device->Format); + outParams.channelCount = ChannelsFromDevFmt(device->FmtChans); SetDefaultChannelOrder(device); @@ -294,7 +295,7 @@ static ALCboolean pa_open_capture(ALCdevice *device, const ALCchar *deviceName) return ALC_FALSE; } - frame_size = aluFrameSizeFromFormat(device->Format); + frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->ring = CreateRingBuffer(frame_size, device->UpdateSize*device->NumUpdates); if(data->ring == NULL) { @@ -308,22 +309,25 @@ static ALCboolean pa_open_capture(ALCdevice *device, const ALCchar *deviceName) inParams.suggestedLatency = 0.0f; inParams.hostApiSpecificStreamInfo = NULL; - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - case 1: + case DevFmtByte: + inParams.sampleFormat = paInt8; + break; + case DevFmtUByte: inParams.sampleFormat = paUInt8; break; - case 2: + case DevFmtShort: inParams.sampleFormat = paInt16; break; - case 4: + case DevFmtFloat: inParams.sampleFormat = paFloat32; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); + case DevFmtUShort: + AL_PRINT("Unsigned short not supported\n"); goto error; } - inParams.channelCount = aluChannelsFromFormat(device->Format); + inParams.channelCount = ChannelsFromDevFmt(device->FmtChans); err = pPa_OpenStream(&data->stream, &inParams, NULL, device->Frequency, paFramesPerBufferUnspecified, paNoFlag, pa_capture_cb, device); diff --git a/Alc/pulseaudio.c b/Alc/pulseaudio.c index 46ac446a..b47e2101 100644 --- a/Alc/pulseaudio.c +++ b/Alc/pulseaudio.c @@ -385,17 +385,17 @@ static void sink_info_callback(pa_context *context, const pa_sink_info *info, in char chanmap_str[256] = ""; const struct { const char *str; - ALenum format; + enum DevFmtChannels chans; } chanmaps[] = { { "front-left,front-right,front-center,lfe,rear-left,rear-right,side-left,side-right", - AL_FORMAT_71CHN32 }, + DevFmtX71 }, { "front-left,front-right,front-center,lfe,rear-center,side-left,side-right", - AL_FORMAT_61CHN32 }, + DevFmtX61 }, { "front-left,front-right,front-center,lfe,rear-left,rear-right", - AL_FORMAT_51CHN32 }, - { "front-left,front-right,rear-left,rear-right", AL_FORMAT_QUAD32 }, - { "front-left,front-right", AL_FORMAT_STEREO_FLOAT32 }, - { "mono", AL_FORMAT_MONO_FLOAT32 }, + DevFmtX51 }, + { "front-left,front-right,rear-left,rear-right", DevFmtQuad }, + { "front-left,front-right", DevFmtStereo }, + { "mono", DevFmtMono }, { NULL, 0 } }; int i; @@ -420,7 +420,7 @@ static void sink_info_callback(pa_context *context, const pa_sink_info *info, in #endif ) { - device->Format = chanmaps[i].format; + device->FmtChans = chanmaps[i].chans; return; } } @@ -878,7 +878,7 @@ static ALCboolean pulse_reset_playback(ALCdevice *device) //{{{ if(!ConfigValueExists(NULL, "frequency")) flags |= PA_STREAM_FIX_RATE; - data->frame_size = aluFrameSizeFromFormat(device->Format); + data->frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType); data->attr.prebuf = -1; data->attr.fragsize = -1; data->attr.minreq = device->UpdateSize * data->frame_size; @@ -889,24 +889,26 @@ static ALCboolean pulse_reset_playback(ALCdevice *device) //{{{ flags |= PA_STREAM_EARLY_REQUESTS; flags |= PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE; - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - case 1: + case DevFmtByte: + device->FmtType = DevFmtUByte; + /* fall-through */ + case DevFmtUByte: data->spec.format = PA_SAMPLE_U8; break; - case 2: + case DevFmtUShort: + device->FmtType = DevFmtShort; + /* fall-through */ + case DevFmtShort: data->spec.format = PA_SAMPLE_S16NE; break; - case 4: + case DevFmtFloat: data->spec.format = PA_SAMPLE_FLOAT32NE; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); - ppa_threaded_mainloop_unlock(data->loop); - return ALC_FALSE; } data->spec.rate = device->Frequency; - data->spec.channels = aluChannelsFromFormat(device->Format); + data->spec.channels = ChannelsFromDevFmt(device->FmtChans); if(ppa_sample_spec_valid(&data->spec) == 0) { @@ -1056,7 +1058,7 @@ static ALCboolean pulse_open_capture(ALCdevice *device, const ALCchar *device_na ppa_threaded_mainloop_lock(data->loop); data->samples = device->UpdateSize * device->NumUpdates; - data->frame_size = aluFrameSizeFromFormat(device->Format); + data->frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType); if(data->samples < 100 * device->Frequency / 1000) data->samples = 100 * device->Frequency / 1000; @@ -1074,21 +1076,22 @@ static ALCboolean pulse_open_capture(ALCdevice *device, const ALCchar *device_na data->frame_size; data->spec.rate = device->Frequency; - data->spec.channels = aluChannelsFromFormat(device->Format); + data->spec.channels = ChannelsFromDevFmt(device->FmtChans); - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - case 1: + case DevFmtUByte: data->spec.format = PA_SAMPLE_U8; break; - case 2: + case DevFmtShort: data->spec.format = PA_SAMPLE_S16NE; break; - case 4: + case DevFmtFloat: data->spec.format = PA_SAMPLE_FLOAT32NE; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); + case DevFmtByte: + case DevFmtUShort: + AL_PRINT("Capture format type %#x capture not supported on PulseAudio\n", device->FmtType); ppa_threaded_mainloop_unlock(data->loop); goto fail; } diff --git a/Alc/solaris.c b/Alc/solaris.c index d07bac0b..a617554f 100644 --- a/Alc/solaris.c +++ b/Alc/solaris.c @@ -59,7 +59,7 @@ static ALuint SolarisProc(ALvoid *ptr) SetRTPriority(); - frameSize = aluFrameSizeFromFormat(pDevice->Format); + frameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); while(!data->killNow && pDevice->Connected) { @@ -139,37 +139,30 @@ static ALCboolean solaris_reset_playback(ALCdevice *device) AUDIO_INITINFO(&info); - switch(aluBytesFromFormat(device->Format)) + switch(device->FmtType) { - case 1: + case DevFmtByte: + device->FmtType = DevFmtUByte; + /* fall-through */ + case DevFmtUByte: info.play.precision = 8; info.play.encoding = AUDIO_ENCODING_LINEAR8; break; - case 4: - switch(numChannels) - { - case 1: device->Format = AL_FORMAT_MONO16; break; - case 2: device->Format = AL_FORMAT_STEREO16; break; - case 4: device->Format = AL_FORMAT_QUAD16; break; - case 6: device->Format = AL_FORMAT_51CHN16; break; - case 7: device->Format = AL_FORMAT_61CHN16; break; - case 8: device->Format = AL_FORMAT_71CHN16; break; - } + case DevFmtUShort: + case DevFmtFloat: + device->FmtType = DevFmtShort; /* fall-through */ - case 2: + case DevFmtShort: info.play.precision = 16; info.play.encoding = AUDIO_ENCODING_LINEAR; break; - default: - AL_PRINT("Unknown format: 0x%x\n", device->Format); - return ALC_FALSE; } - numChannels = aluChannelsFromFormat(device->Format); + numChannels = ChannelsFromDevFmt(device->FmtChans); info.play.sample_rate = device->Frequency; info.play.channels = numChannels; - frameSize = numChannels * aluBytesFromFormat(device->Format); + frameSize = numChannels * BytesFromDevFmt(device->FmtType); info.play.buffer_size = device->UpdateSize*device->NumUpdates * frameSize; if(ioctl(data->fd, AUDIO_SETINFO, &info) < 0) @@ -178,16 +171,16 @@ static ALCboolean solaris_reset_playback(ALCdevice *device) return ALC_FALSE; } - if(aluChannelsFromFormat(device->Format) != info.play.channels) + if(ChannelsFromDevFmt(device->FmtChans) != info.play.channels) { - AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device->Format), info.play.channels); + AL_PRINT("Could not set %d channels, got %d instead\n", ChannelsFromDevFmt(device->FmtChans), info.play.channels); return ALC_FALSE; } - if(!((info.play.precision == 8 && aluBytesFromFormat(device->Format) == 1) || - (info.play.precision == 16 && aluBytesFromFormat(device->Format) == 2))) + if(!((info.play.precision == 8 && device->FmtType == DevFmtUByte) || + (info.play.precision == 16 && device->FmtType == DevFmtShort))) { - AL_PRINT("Could not set %d-bit output, got %d\n", aluBytesFromFormat(device->Format)*8, info.play.precision); + AL_PRINT("Could not set %#x sample type, got %d\n", device->FmtType, info.play.precision); return ALC_FALSE; } @@ -95,7 +95,7 @@ static ALuint WaveProc(ALvoid *ptr) pDevice->Frequency / 2; uSB.s = 1; - frameSize = aluFrameSizeFromFormat(pDevice->Format); + frameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); done = 0; start = timeGetTime(); @@ -124,20 +124,21 @@ static ALuint WaveProc(ALvoid *ptr) if(uSB.b[0] != 1) { + ALuint bytesize = BytesFromDevFmt(pDevice->FmtType); ALubyte *bytes = data->buffer; ALuint i; - if(aluBytesFromFormat(pDevice->Format) == 1) + if(bytesize == 1) { for(i = 0;i < data->size;i++) fputc(bytes[i], data->f); } - else if(aluBytesFromFormat(pDevice->Format) == 2) + else if(bytesize == 2) { for(i = 0;i < data->size;i++) fputc(bytes[i^1], data->f); } - else if(aluBytesFromFormat(pDevice->Format) == 4) + else if(bytesize == 4) { for(i = 0;i < data->size;i++) fputc(bytes[i^3], data->f); @@ -199,29 +200,27 @@ static void wave_close_playback(ALCdevice *device) static ALCboolean wave_reset_playback(ALCdevice *device) { wave_data *data = (wave_data*)device->ExtraData; - ALuint channels, bits; + ALuint channels=0, bits=0; size_t val; fseek(data->f, 0, SEEK_SET); clearerr(data->f); - bits = aluBytesFromFormat(device->Format) * 8; - channels = aluChannelsFromFormat(device->Format); - - /* 7.1 max */ - if(channels > 8) + switch(device->FmtType) { - if(bits == 8) - device->Format = AL_FORMAT_71CHN8; - else if(bits == 16) - device->Format = AL_FORMAT_71CHN16; - else - { - device->Format = AL_FORMAT_71CHN32; - bits = 32; - } - channels = 8; + case DevFmtByte: + device->FmtType = DevFmtUByte; + break; + case DevFmtUShort: + device->FmtType = DevFmtShort; + break; + case DevFmtUByte: + case DevFmtShort: + case DevFmtFloat: + break; } + bits = BytesFromDevFmt(device->FmtType) * 8; + channels = ChannelsFromDevFmt(device->FmtChans); fprintf(data->f, "RIFF"); fwrite32le(0xFFFFFFFF, data->f); // 'RIFF' header len; filled in at close diff --git a/Alc/winmm.c b/Alc/winmm.c index 8688b7b0..ee21e71e 100644 --- a/Alc/winmm.c +++ b/Alc/winmm.c @@ -194,7 +194,7 @@ static DWORD WINAPI PlaybackThreadProc(LPVOID lpParameter) ALuint FrameSize; MSG msg; - FrameSize = aluFrameSizeFromFormat(pDevice->Format); + FrameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); while(GetMessage(&msg, NULL, 0, 0)) { @@ -272,7 +272,7 @@ static DWORD WINAPI CaptureThreadProc(LPVOID lpParameter) ALuint FrameSize; MSG msg; - FrameSize = aluFrameSizeFromFormat(pDevice->Format); + FrameSize = FrameSizeFromDevFmt(pDevice->FmtChans, pDevice->FmtType); while(GetMessage(&msg, NULL, 0, 0)) { @@ -336,25 +336,26 @@ static ALCboolean WinMMOpenPlayback(ALCdevice *pDevice, const ALCchar *deviceNam } pDevice->ExtraData = pData; - if(aluChannelsFromFormat(pDevice->Format) >= 2) + if(pDevice->FmtChans != DevFmtMono) + pDevice->FmtChans = DevFmtStereo; + switch(pDevice->FmtType) { - if(aluBytesFromFormat(pDevice->Format) >= 2) - pDevice->Format = AL_FORMAT_STEREO16; - else - pDevice->Format = AL_FORMAT_STEREO8; - } - else - { - if(aluBytesFromFormat(pDevice->Format) >= 2) - pDevice->Format = AL_FORMAT_MONO16; - else - pDevice->Format = AL_FORMAT_MONO8; + case DevFmtByte: + pDevice->FmtType = DevFmtUByte; + break; + case DevFmtUShort: + case DevFmtFloat: + pDevice->FmtType = DevFmtShort; + break; + case DevFmtUByte: + case DevFmtShort: + break; } memset(&wfexFormat, 0, sizeof(WAVEFORMATEX)); wfexFormat.wFormatTag = WAVE_FORMAT_PCM; - wfexFormat.nChannels = aluChannelsFromFormat(pDevice->Format); - wfexFormat.wBitsPerSample = aluBytesFromFormat(pDevice->Format) * 8; + wfexFormat.nChannels = ChannelsFromDevFmt(pDevice->FmtChans); + wfexFormat.wBitsPerSample = BytesFromDevFmt(pDevice->FmtType) * 8; wfexFormat.nBlockAlign = wfexFormat.wBitsPerSample * wfexFormat.nChannels / 8; wfexFormat.nSamplesPerSec = pDevice->Frequency; @@ -433,7 +434,7 @@ static ALCboolean WinMMResetPlayback(ALCdevice *device) // Create 4 Buffers lBufferSize = device->UpdateSize*device->NumUpdates / 4; - lBufferSize *= aluFrameSizeFromFormat(device->Format); + lBufferSize *= FrameSizeFromDevFmt(device->FmtChans, device->FmtType); BufferData = calloc(4, lBufferSize); for(i = 0;i < 4;i++) @@ -533,10 +534,17 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName } pDevice->ExtraData = pData; + if((pDevice->FmtChans != DevFmtMono && pDevice->FmtChans != DevFmtStereo) || + (pDevice->FmtType != DevFmtUByte && pDevice->FmtType != DevFmtShort)) + { + alcSetError(pDevice, ALC_INVALID_ENUM); + goto failure; + } + memset(&wfexCaptureFormat, 0, sizeof(WAVEFORMATEX)); wfexCaptureFormat.wFormatTag = WAVE_FORMAT_PCM; - wfexCaptureFormat.nChannels = aluChannelsFromFormat(pDevice->Format); - wfexCaptureFormat.wBitsPerSample = aluBytesFromFormat(pDevice->Format) * 8; + wfexCaptureFormat.nChannels = ChannelsFromDevFmt(pDevice->FmtChans); + wfexCaptureFormat.wBitsPerSample = BytesFromDevFmt(pDevice->FmtType) * 8; wfexCaptureFormat.nBlockAlign = wfexCaptureFormat.wBitsPerSample * wfexCaptureFormat.nChannels / 8; wfexCaptureFormat.nSamplesPerSec = pDevice->Frequency; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 9a7b01ba..4e0d03da 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -316,6 +316,31 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value); void RemoveUIntMapKey(UIntMap *map, ALuint key); ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key); +/* Device formats */ +enum DevFmtType { + DevFmtByte, /* AL_BYTE */ + DevFmtUByte, /* AL_UNSIGNED_BYTE */ + DevFmtShort, /* AL_SHORT */ + DevFmtUShort, /* AL_UNSIGNED_SHORT */ + DevFmtFloat, /* AL_FLOAT */ +}; +enum DevFmtChannels { + DevFmtMono, /* AL_MONO */ + DevFmtStereo, /* AL_STEREO */ + DevFmtQuad, /* AL_QUAD */ + DevFmtX51, /* AL_5POINT1 */ + DevFmtX61, /* AL_6POINT1 */ + DevFmtX71, /* AL_7POINT1 */ +}; + +ALuint BytesFromDevFmt(enum DevFmtType type); +ALuint ChannelsFromDevFmt(enum DevFmtChannels chans); +static __inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans, + enum DevFmtType type) +{ + return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type); +} + struct ALCdevice_struct { @@ -325,7 +350,8 @@ struct ALCdevice_struct ALuint Frequency; ALuint UpdateSize; ALuint NumUpdates; - ALenum Format; + enum DevFmtChannels FmtChans; + enum DevFmtType FmtType; ALCchar *szDeviceName; |