diff options
author | Chris Robinson <[email protected]> | 2007-11-30 00:28:34 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2007-11-30 00:28:34 -0800 |
commit | ab34e7c613aad78e193ba6f8a4d5631f1ba6a613 (patch) | |
tree | b50af3eed21b778be4599f5cd90b4c96ffb2616c | |
parent | aea161d98774d1281df02ae6231348890c5a0f3f (diff) |
Use an AL_PRINT macro for printing lib messages/errors to the console
-rw-r--r-- | Alc/ALc.c | 9 | ||||
-rw-r--r-- | Alc/alcConfig.c | 20 | ||||
-rw-r--r-- | Alc/alsa.c | 79 | ||||
-rw-r--r-- | Alc/oss.c | 10 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 13 | ||||
-rw-r--r-- | OpenAL32/alBuffer.c | 8 |
6 files changed, 72 insertions, 67 deletions
@@ -33,9 +33,7 @@ /////////////////////////////////////////////////////// // DEBUG INFORMATION -#ifdef _DEBUG - char szDebug[256]; -#endif +char szDebug[256]; /////////////////////////////////////////////////////// @@ -346,10 +344,7 @@ static ALCvoid ExitContext(ALCcontext *pContext) #ifdef _DEBUG if (pContext->SourceCount>0) - { - sprintf(szDebug,"OpenAL32 : alcDestroyContext() %d Source(s) NOT deleted\n", pContext->SourceCount); - OutputDebugString(szDebug); - } + AL_PRINT("alcDestroyContext() %d Source(s) NOT deleted\n", pContext->SourceCount); #endif // Free all the Sources still remaining diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c index f20b5e4f..c4b2fab0 100644 --- a/Alc/alcConfig.c +++ b/Alc/alcConfig.c @@ -23,6 +23,8 @@ #include <ctype.h> #include <string.h> +#include "alMain.h" + typedef struct ConfigEntry { char *key; char *value; @@ -65,7 +67,7 @@ static void LoadConfigFromFile(FILE *f) if(!buffer[i]) { - fprintf(stderr, "openal: config parse error: bad line \"%s\"\n", buffer); + AL_PRINT("config parse error: bad line \"%s\"\n", buffer); continue; } buffer[i] = 0; @@ -75,7 +77,7 @@ static void LoadConfigFromFile(FILE *f) if(buffer[i] && !isspace(buffer[i])) { if(buffer[i] != '#') - fprintf(stderr, "openal: config warning: extra data after block: \"%s\"\n", buffer+i); + AL_PRINT("config warning: extra data after block: \"%s\"\n", buffer+i); break; } } while(buffer[i]); @@ -86,7 +88,7 @@ static void LoadConfigFromFile(FILE *f) if(strcasecmp(cfgBlocks[i].name, buffer+1) == 0) { nextBlock = cfgBlocks+i; -// printf("found block '%s'\n", nextBlock->name); +// AL_PRINT("found block '%s'\n", nextBlock->name); break; } } @@ -96,7 +98,7 @@ static void LoadConfigFromFile(FILE *f) nextBlock = realloc(cfgBlocks, (cfgCount+1)*sizeof(ConfigBlock)); if(!nextBlock) { - fprintf(stderr, "openal: config parse error: error reallocating config blocks\n"); + AL_PRINT("config parse error: error reallocating config blocks\n"); continue; } cfgBlocks = nextBlock; @@ -107,7 +109,7 @@ static void LoadConfigFromFile(FILE *f) nextBlock->entries = NULL; nextBlock->entryCount = 0; -// printf("found new block '%s'\n", nextBlock->name); +// AL_PRINT("found new block '%s'\n", nextBlock->name); } curBlock = nextBlock; continue; @@ -121,7 +123,7 @@ static void LoadConfigFromFile(FILE *f) if(!buffer[i] || buffer[i] == '#' || i == 0) { - fprintf(stderr, "openal: config parse error: malformed option line: \"%s\"\n", buffer); + AL_PRINT("config parse error: malformed option line: \"%s\"\n", buffer); continue; } @@ -134,7 +136,7 @@ static void LoadConfigFromFile(FILE *f) i++; if(buffer[i] != '=') { - fprintf(stderr, "openal: config parse error: option without a value: \"%s\"\n", buffer); + AL_PRINT("config parse error: option without a value: \"%s\"\n", buffer); continue; } } @@ -158,7 +160,7 @@ static void LoadConfigFromFile(FILE *f) ent = realloc(curBlock->entries, (curBlock->entryCount+1)*sizeof(ConfigEntry)); if(!ent) { - fprintf(stderr, "openal: config parse error: error reallocating config entries\n"); + AL_PRINT("config parse error: error reallocating config entries\n"); continue; } curBlock->entries = ent; @@ -184,7 +186,7 @@ static void LoadConfigFromFile(FILE *f) free(ent->value); ent->value = strdup(buffer); -// printf("found '%s' = '%s'\n", ent->key, ent->value); +// AL_PRINT("found '%s' = '%s'\n", ent->key, ent->value); } } @@ -105,7 +105,7 @@ static int xrun_recovery(snd_pcm_t *handle, int err) if(err >= 0) err = psnd_pcm_start(handle); if (err < 0) - printf("Can't recover from underrun, prepare failed: %s\n", psnd_strerror(err)); + AL_PRINT("prepare failed: %s\n", psnd_strerror(err)); } else if (err == -ESTRPIPE) { @@ -117,7 +117,7 @@ static int xrun_recovery(snd_pcm_t *handle, int err) if(err >= 0) err = psnd_pcm_start(handle); if (err < 0) - printf("Can't recover from suspend, prepare failed: %s\n", psnd_strerror(err)); + AL_PRINT("prepare failed: %s\n", psnd_strerror(err)); } } return err; @@ -143,7 +143,7 @@ static ALuint ALSAProc(ALvoid *ptr) err = xrun_recovery(data->pcmHandle, -EPIPE); if (err < 0) { - fprintf(stderr, "XRUN recovery failed: %s\n", psnd_strerror(err)); + AL_PRINT("XRUN recovery failed: %s\n", psnd_strerror(err)); break; } } @@ -152,7 +152,7 @@ static ALuint ALSAProc(ALvoid *ptr) err = xrun_recovery(data->pcmHandle, -ESTRPIPE); if (err < 0) { - fprintf(stderr, "SUSPEND recovery failed: %s\n", psnd_strerror(err)); + AL_PRINT("SUSPEND recovery failed: %s\n", psnd_strerror(err)); break; } } @@ -163,7 +163,7 @@ static ALuint ALSAProc(ALvoid *ptr) err = xrun_recovery(data->pcmHandle, avail); if (err < 0) { - fprintf(stderr, "available update failed: %s\n", psnd_strerror(err)); + AL_PRINT("available update failed: %s\n", psnd_strerror(err)); break; } } @@ -185,7 +185,7 @@ static ALuint ALSAProc(ALvoid *ptr) { err = xrun_recovery(data->pcmHandle, err); if (err < 0) - fprintf(stderr, "mmap begin error: %s\n", psnd_strerror(err)); + AL_PRINT("mmap begin error: %s\n", psnd_strerror(err)); break; } @@ -206,8 +206,8 @@ static ALuint ALSAProc(ALvoid *ptr) commitres = psnd_pcm_mmap_commit(data->pcmHandle, offset, frames); if (commitres < 0 || (commitres-frames) != 0) { - fprintf(stderr, "mmap commit error: %s\n", - psnd_strerror(commitres >= 0 ? -EPIPE : commitres)); + AL_PRINT("mmap commit error: %s\n", + psnd_strerror(commitres >= 0 ? -EPIPE : commitres)); break; } @@ -231,7 +231,7 @@ static void fill_silence(snd_pcm_t *pcmHandle, snd_pcm_format_t alsaFormat, int err = xrun_recovery(pcmHandle, avail); if (err < 0) { - fprintf(stderr, "available update failed: %s\n", psnd_strerror(err)); + AL_PRINT("available update failed: %s\n", psnd_strerror(err)); return; } } @@ -247,7 +247,7 @@ static void fill_silence(snd_pcm_t *pcmHandle, snd_pcm_format_t alsaFormat, int err = xrun_recovery(pcmHandle, err); if (err < 0) { - fprintf(stderr, "mmap begin error: %s\n", psnd_strerror(err)); + AL_PRINT("mmap begin error: %s\n", psnd_strerror(err)); break; } continue; @@ -258,8 +258,8 @@ static void fill_silence(snd_pcm_t *pcmHandle, snd_pcm_format_t alsaFormat, int commitres = psnd_pcm_mmap_commit(pcmHandle, offset, frames); if (commitres < 0 || (commitres-frames) != 0) { - fprintf(stderr, "mmap commit error: %s\n", - psnd_strerror(commitres >= 0 ? -EPIPE : commitres)); + AL_PRINT("mmap commit error: %s\n", + psnd_strerror(commitres >= 0 ? -EPIPE : commitres)); break; } @@ -274,6 +274,7 @@ static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceNam unsigned int periods; alsa_data *data; char driver[64]; + char *err; int i; strncpy(driver, GetConfigValue("alsa", "default", "default"), sizeof(driver)-1); @@ -345,7 +346,7 @@ open_alsa: break; default: data->format = SND_PCM_FORMAT_UNKNOWN; - fprintf(stderr, "Unknown format?! %x\n", device->Format); + AL_PRINT("Unknown format?! %x\n", device->Format); } periods = GetConfigValueInt("alsa", "periods", 4); @@ -354,7 +355,7 @@ open_alsa: bufferSizeInFrames = device->UpdateFreq; psnd_pcm_hw_params_malloc(&p); -#define ok(func, str) (i=(func),((i<0)?fprintf(stderr,"%s failed: %s\n", str, psnd_strerror(i)),0:1)) +#define ok(func, str) (i=(func),((i<0)?(err=(str)),0:1)) /* start with the largest configuration space possible */ if(!(ok(psnd_pcm_hw_params_any(data->pcmHandle, p), "any") && /* set interleaved access */ @@ -372,6 +373,7 @@ open_alsa: /* install and prepare hardware configuration */ ok(psnd_pcm_hw_params(data->pcmHandle, p), "set params"))) { + AL_PRINT("%s failed: %s\n", err, psnd_strerror(i)); psnd_pcm_hw_params_free(p); psnd_pcm_close(data->pcmHandle); free(data); @@ -386,7 +388,7 @@ open_alsa: i = psnd_pcm_prepare(data->pcmHandle); if(i < 0) { - fprintf(stderr, "prepare error: %s\n", psnd_strerror(i)); + AL_PRINT("prepare error: %s\n", psnd_strerror(i)); psnd_pcm_close(data->pcmHandle); free(data); return ALC_FALSE; @@ -396,7 +398,7 @@ open_alsa: i = psnd_pcm_start(data->pcmHandle); if(i < 0) { - fprintf(stderr, "start error: %s\n", psnd_strerror(i)); + AL_PRINT("start error: %s\n", psnd_strerror(i)); psnd_pcm_close(data->pcmHandle); free(data); return ALC_FALSE; @@ -435,6 +437,7 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam snd_pcm_uframes_t bufferSizeInFrames = SampleSize; alsa_data *data; char driver[64]; + char *err; int i; strncpy(driver, GetConfigValue("alsa", "capture", "default"), sizeof(driver)-1); @@ -492,11 +495,11 @@ open_alsa: break; default: alsaFormat = SND_PCM_FORMAT_UNKNOWN; - fprintf(stderr, "Unknown format?! %x\n", format); + AL_PRINT("Unknown format?! %x\n", format); } psnd_pcm_hw_params_malloc(&p); -#define ok(func, str) (i=(func),((i<0)?fprintf(stderr,"%s failed\n", str),0:1)) +#define ok(func, str) (i=(func),((i<0)?(err=(str)),0:1)) /* start with the largest configuration space possible */ if(!(ok(psnd_pcm_hw_params_any(data->pcmHandle, p), "any") && /* set interleaved access */ @@ -514,6 +517,7 @@ open_alsa: /* install and prepare hardware configuration */ ok(psnd_pcm_hw_params(data->pcmHandle, p), "set params"))) { + AL_PRINT("%s failed: %s\n", err, psnd_strerror(i)); psnd_pcm_hw_params_free(p); psnd_pcm_close(data->pcmHandle); free(data); @@ -525,7 +529,7 @@ open_alsa: i = psnd_pcm_prepare(data->pcmHandle); if(i < 0) { - fprintf(stderr, "prepare error: %s\n", psnd_strerror(i)); + AL_PRINT("prepare error: %s\n", psnd_strerror(i)); psnd_pcm_close(data->pcmHandle); free(data); return ALC_FALSE; @@ -569,7 +573,7 @@ static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint l { err = xrun_recovery(data->pcmHandle, frames); if (err < 0) - fprintf(stderr, "available update failed: %s\n", psnd_strerror(err)); + AL_PRINT("available update failed: %s\n", psnd_strerror(err)); else frames = psnd_pcm_avail_update(data->pcmHandle); } @@ -592,7 +596,7 @@ static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint l err = xrun_recovery(data->pcmHandle, err); if (err < 0) { - fprintf(stderr, "mmap begin error: %s\n", psnd_strerror(err)); + AL_PRINT("mmap begin error: %s\n", psnd_strerror(err)); break; } continue; @@ -607,8 +611,8 @@ static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint l commitres = psnd_pcm_mmap_commit(data->pcmHandle, offset, size); if (commitres < 0 || (commitres-size) != 0) { - fprintf(stderr, "mmap commit error: %s\n", - psnd_strerror(commitres >= 0 ? -EPIPE : commitres)); + AL_PRINT("mmap commit error: %s\n", + psnd_strerror(commitres >= 0 ? -EPIPE : commitres)); break; } @@ -624,7 +628,7 @@ static ALCuint alsa_available_samples(ALCdevice *pDevice) { int err = xrun_recovery(data->pcmHandle, frames); if (err < 0) - fprintf(stderr, "available update failed: %s\n", psnd_strerror(err)); + AL_PRINT("available update failed: %s\n", psnd_strerror(err)); else frames = psnd_pcm_avail_update(data->pcmHandle); if(frames < 0) /* ew.. */ @@ -647,10 +651,6 @@ BackendFuncs alsa_funcs = { void alc_alsa_init(BackendFuncs *func_list) { -#define error(...) do { \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ -}while(0) snd_ctl_t *handle; int card, err, dev, idx = 1; snd_ctl_card_info_t *info; @@ -673,7 +673,7 @@ void alc_alsa_init(BackendFuncs *func_list) { \ dlclose(alsa_handle); \ alsa_handle = NULL; \ - error("Could not load %s from libasound.so.2: %s", #f, str); \ + AL_PRINT("Could not load %s from libasound.so.2: %s\n", #f, str); \ return; \ } \ } while(0) @@ -733,7 +733,7 @@ LOAD_FUNC(snd_card_next); card = -1; if(psnd_card_next(&card) < 0 || card < 0) - error("no playback cards found..."); + AL_PRINT("no playback cards found...\n"); else { alsaDeviceList[0] = AppendDeviceList("ALSA Software on default"); @@ -743,11 +743,11 @@ LOAD_FUNC(snd_card_next); while (card >= 0) { sprintf(name, "hw:%d", card); if ((err = psnd_ctl_open(&handle, name, 0)) < 0) { - error("control open (%i): %s", card, psnd_strerror(err)); + AL_PRINT("control open (%i): %s\n", card, psnd_strerror(err)); goto next_card; } if ((err = psnd_ctl_card_info(handle, info)) < 0) { - error("control hardware info (%i): %s", card, psnd_strerror(err)); + AL_PRINT("control hardware info (%i): %s\n", card, psnd_strerror(err)); psnd_ctl_close(handle); goto next_card; } @@ -760,7 +760,7 @@ LOAD_FUNC(snd_card_next); dev = -1; while (idx < MAX_ALL_DEVICES) { if (psnd_ctl_pcm_next_device(handle, &dev)<0) - error("snd_ctl_pcm_next_device"); + AL_PRINT("snd_ctl_pcm_next_device failed\n"); if (dev < 0) break; psnd_pcm_info_set_device(pcminfo, dev); @@ -768,7 +768,7 @@ LOAD_FUNC(snd_card_next); psnd_pcm_info_set_stream(pcminfo, stream); if ((err = psnd_ctl_pcm_info(handle, pcminfo)) < 0) { if (err != -ENOENT) - error("control digital audio info (%i): %s", card, psnd_strerror(err)); + AL_PRINT("control digital audio info (%i): %s\n", card, psnd_strerror(err)); continue; } snprintf(name, sizeof(name), "ALSA Software on %s [%s]", @@ -782,7 +782,7 @@ LOAD_FUNC(snd_card_next); psnd_ctl_close(handle); next_card: if(psnd_card_next(&card) < 0) { - error("snd_card_next"); + AL_PRINT("snd_card_next failed\n"); break; } } @@ -792,7 +792,7 @@ next_card: card = -1; if(psnd_card_next(&card) < 0 || card < 0) { - error("no capture cards found..."); + AL_PRINT("no capture cards found...\n"); psnd_pcm_info_free(pcminfo); psnd_ctl_card_info_free(info); return; @@ -804,10 +804,10 @@ next_card: sprintf(name, "hw:%d", card); handle = NULL; if ((err = psnd_ctl_open(&handle, name, 0)) < 0) { - error("control open (%i): %s", card, psnd_strerror(err)); + AL_PRINT("control open (%i): %s\n", card, psnd_strerror(err)); } if (err >= 0 && (err = psnd_ctl_card_info(handle, info)) < 0) { - error("control hardware info (%i): %s", card, psnd_strerror(err)); + AL_PRINT("control hardware info (%i): %s\n", card, psnd_strerror(err)); psnd_ctl_close(handle); } else if (err >= 0 && card < MAX_DEVICES-1) @@ -818,11 +818,10 @@ next_card: } if(handle) psnd_ctl_close(handle); if(psnd_card_next(&card) < 0) { - error("snd_card_next"); + AL_PRINT("snd_card_next failed\n"); break; } } psnd_pcm_info_free(pcminfo); psnd_ctl_card_info_free(info); -#undef error } @@ -92,7 +92,7 @@ static ALuint OSSProc(ALvoid *ptr) wrote = write(data->fd, data->mix_data+data->data_size-remaining, remaining); if(wrote < 0) { - fprintf(stderr, "write failed: %s\n", strerror(errno)); + AL_PRINT("write failed: %s\n", strerror(errno)); break; } if(wrote == 0) @@ -118,6 +118,7 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName oss_data *data; int ossFormat; int ossSpeed; + char *err; int i; strncpy(driver, GetConfigValue("oss", "device", "/dev/dsp"), sizeof(driver)-1); @@ -159,7 +160,7 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName break; default: ossFormat = -1; - fprintf(stderr, "Unknown format?! %x\n", device->Format); + AL_PRINT("Unknown format?! %x\n", device->Format); } periods = GetConfigValueInt("oss", "periods", 4); @@ -174,13 +175,14 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName log2FragmentSize = 4; numFragmentsLogSize = (periods << 16) | log2FragmentSize; -#define ok(func, str) (i=(func),((i<0)?fprintf(stderr,"%s failed\n", str),0:1)) +#define ok(func, str) (i=(func),((i<0)?(err=(str)),0:1)) if (!(ok(ioctl(data->fd, SNDCTL_DSP_SETFRAGMENT, &numFragmentsLogSize), "set fragment") && ok(ioctl(data->fd, SNDCTL_DSP_SETFMT, &ossFormat), "set format") && ok(ioctl(data->fd, SNDCTL_DSP_CHANNELS, &numChannels), "set channels") && ok(ioctl(data->fd, SNDCTL_DSP_SPEED, &ossSpeed), "set speed") && ok(ioctl(data->fd, SNDCTL_DSP_GETOSPACE, &info), "get space"))) { + AL_PRINT("%s failed: %s\n", err, strerror(i)); close(data->fd); free(data); return ALC_FALSE; @@ -229,7 +231,7 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName if(!device->Format) { - fprintf(stderr, "Unknown returned format/channel %#x/%d!\n", ossFormat, numChannels); + AL_PRINT("returned unknown format: %#x %d!\n", ossFormat, numChannels); close(data->fd); free(data); return ALC_FALSE; diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 3d34cf38..9957a741 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -62,6 +62,19 @@ extern "C" { #endif +extern char szDebug[256]; + +#define AL_PRINT(...) do { \ + int _al_print_i; \ + char *_al_print_fn = strrchr(__FILE__, '/'); \ + if(!_al_print_fn) _al_print_fn = __FILE__; \ + else _al_print_fn += 1; \ + _al_print_i = snprintf(szDebug, sizeof(szDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \ + snprintf(szDebug+_al_print_i, sizeof(szDebug)-_al_print_i, __VA_ARGS__); \ + fprintf(stderr, "%s", szDebug); \ +} while(0) + + #define AL_FORMAT_MONO_IMA4 0x1300 #define AL_FORMAT_STEREO_IMA4 0x1301 // These are from AL_EXT_MCFORMATS, which we don't support yet but the mixer diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 53ee128a..972c4ece 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -28,9 +28,6 @@ #include "alError.h" #include "alBuffer.h" -#ifdef _DEBUG - char szDebug[256]; -#endif /* * AL Buffer Functions @@ -966,10 +963,7 @@ ALvoid ReleaseALBuffers(ALvoid) #ifdef _DEBUG if(g_uiBufferCount > 0) - { - sprintf(szDebug, "OpenAL32 : DllMain() %d Buffer(s) NOT deleted\n", g_uiBufferCount); - OutputDebugString(szDebug); - } + AL_PRINT("exit() %d Buffer(s) NOT deleted\n", g_uiBufferCount); #endif ALBuffer = g_pBuffers; |