diff options
Diffstat (limited to 'Alc/backends/alsa.c')
-rw-r--r-- | Alc/backends/alsa.c | 77 |
1 files changed, 29 insertions, 48 deletions
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 0712a412..9a443c09 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -13,8 +13,8 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Or go to http://www.gnu.org/copyleft/lgpl.html */ @@ -230,7 +230,7 @@ typedef struct { al_string name; al_string device_name; } DevMap; -DECL_VECTOR(DevMap) +TYPEDEF_VECTOR(DevMap, vector_DevMap) static vector_DevMap PlaybackDevices; static vector_DevMap CaptureDevices; @@ -273,14 +273,14 @@ static void probe_devices(snd_pcm_stream_t stream, vector_DevMap *DeviceList) AL_STRING_INIT(entry.name); AL_STRING_INIT(entry.device_name); al_string_copy_cstr(&entry.name, alsaDevice); - al_string_copy_cstr(&entry.device_name, GetConfigValue("alsa", (stream==SND_PCM_STREAM_PLAYBACK) ? + al_string_copy_cstr(&entry.device_name, GetConfigValue(NULL, "alsa", (stream==SND_PCM_STREAM_PLAYBACK) ? "device" : "capture", "default")); VECTOR_PUSH_BACK(*DeviceList, entry); card = -1; if((err=snd_card_next(&card)) < 0) ERR("Failed to find a card: %s\n", snd_strerror(err)); - ConfigValueStr("alsa", prefix_name(stream), &main_prefix); + ConfigValueStr(NULL, "alsa", prefix_name(stream), &main_prefix); while(card >= 0) { const char *card_prefix = main_prefix; @@ -304,7 +304,7 @@ static void probe_devices(snd_pcm_stream_t stream, vector_DevMap *DeviceList) cardid = snd_ctl_card_info_get_id(info); snprintf(name, sizeof(name), "%s-%s", prefix_name(stream), cardid); - ConfigValueStr("alsa", name, &card_prefix); + ConfigValueStr(NULL, "alsa", name, &card_prefix); dev = -1; while(1) @@ -330,7 +330,7 @@ static void probe_devices(snd_pcm_stream_t stream, vector_DevMap *DeviceList) devname = snd_pcm_info_get_name(pcminfo); snprintf(name, sizeof(name), "%s-%s-%d", prefix_name(stream), cardid, dev); - ConfigValueStr("alsa", name, &device_prefix); + ConfigValueStr(NULL, "alsa", name, &device_prefix); snprintf(name, sizeof(name), "%s, %s (CARD=%s,DEV=%d)", cardname, devname, cardid, dev); @@ -625,28 +625,22 @@ static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name) if(name) { - const DevMap *iter, *end; + const DevMap *iter; if(VECTOR_SIZE(PlaybackDevices) == 0) probe_devices(SND_PCM_STREAM_PLAYBACK, &PlaybackDevices); - iter = VECTOR_ITER_BEGIN(PlaybackDevices); - end = VECTOR_ITER_END(PlaybackDevices); - for(;iter != end;iter++) - { - if(al_string_cmp_cstr(iter->name, name) == 0) - { - driver = al_string_get_cstr(iter->device_name); - break; - } - } - if(iter == end) +#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, name) == 0) + VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME); +#undef MATCH_NAME + if(iter == VECTOR_ITER_END(PlaybackDevices)) return ALC_INVALID_VALUE; + driver = al_string_get_cstr(iter->device_name); } else { name = alsaDevice; - driver = GetConfigValue("alsa", "device", "default"); + driver = GetConfigValue(NULL, "alsa", "device", "default"); } TRACE("Opening device \"%s\"\n", driver); @@ -710,7 +704,7 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self) break; } - allowmmap = GetConfigValueBool("alsa", "mmap", 1); + allowmmap = GetConfigValueBool(al_string_get_cstr(device->DeviceName), "alsa", "mmap", 1); periods = device->NumUpdates; periodLen = (ALuint64)device->UpdateSize * 1000000 / device->Frequency; bufferLen = periodLen * periods; @@ -776,8 +770,11 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self) } CHECK(snd_pcm_hw_params_set_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans))); /* set rate (implicitly constrains period/buffer parameters) */ - if(snd_pcm_hw_params_set_rate_resample(self->pcmHandle, hp, 0) < 0) - ERR("Failed to disable ALSA resampler\n"); + if(GetConfigValueBool(al_string_get_cstr(device->DeviceName), "alsa", "allow-resampler", 0)) + { + if(snd_pcm_hw_params_set_rate_resample(self->pcmHandle, hp, 0) < 0) + ERR("Failed to disable ALSA resampler\n"); + } CHECK(snd_pcm_hw_params_set_rate_near(self->pcmHandle, hp, &rate, NULL)); /* set buffer time (implicitly constrains period/buffer parameters) */ if((err=snd_pcm_hw_params_set_buffer_time_near(self->pcmHandle, hp, &bufferLen, NULL)) < 0) @@ -956,28 +953,22 @@ static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name) if(name) { - const DevMap *iter, *end; + const DevMap *iter; if(VECTOR_SIZE(CaptureDevices) == 0) probe_devices(SND_PCM_STREAM_CAPTURE, &CaptureDevices); - iter = VECTOR_ITER_BEGIN(CaptureDevices); - end = VECTOR_ITER_END(CaptureDevices); - for(;iter != end;iter++) - { - if(al_string_cmp_cstr(iter->name, name) == 0) - { - driver = al_string_get_cstr(iter->device_name); - break; - } - } - if(iter == end) +#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, name) == 0) + VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME); +#undef MATCH_NAME + if(iter == VECTOR_ITER_END(CaptureDevices)) return ALC_INVALID_VALUE; + driver = al_string_get_cstr(iter->device_name); } else { name = alsaDevice; - driver = GetConfigValue("alsa", "capture", "default"); + driver = GetConfigValue(NULL, "alsa", "capture", "default"); } TRACE("Opening device \"%s\"\n", driver); @@ -1364,25 +1355,15 @@ static ALCbackend* ALCalsaBackendFactory_createBackend(ALCalsaBackendFactory* UN if(type == ALCbackend_Playback) { ALCplaybackAlsa *backend; - - backend = ALCplaybackAlsa_New(sizeof(*backend)); + NEW_OBJ(backend, ALCplaybackAlsa)(device); if(!backend) return NULL; - memset(backend, 0, sizeof(*backend)); - - ALCplaybackAlsa_Construct(backend, device); - return STATIC_CAST(ALCbackend, backend); } if(type == ALCbackend_Capture) { ALCcaptureAlsa *backend; - - backend = ALCcaptureAlsa_New(sizeof(*backend)); + NEW_OBJ(backend, ALCcaptureAlsa)(device); if(!backend) return NULL; - memset(backend, 0, sizeof(*backend)); - - ALCcaptureAlsa_Construct(backend, device); - return STATIC_CAST(ALCbackend, backend); } |