Mercurial > pidgin
diff src/sound.c @ 1252:46c09828e929
[gaim-migrate @ 1262]
still need to do buddy.c, conversation.c, dialogs.c, prefs.c.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 13 Dec 2000 22:12:02 +0000 |
parents | a9cf2f61a7b1 |
children | 677e2c9e8baf |
line wrap: on
line diff
--- a/src/sound.c Wed Dec 13 20:23:06 2000 +0000 +++ b/src/sound.c Wed Dec 13 22:12:02 2000 +0000 @@ -53,12 +53,11 @@ { struct stat stat_buf; uid_t user = getuid(); - gid_t group = getgid(), - other_groups[32]; + gid_t group = getgid(), other_groups[32]; int i, numgroups; - if ((numgroups = getgroups (32, other_groups)) == -1) - return 0; + if ((numgroups = getgroups(32, other_groups)) == -1) + return 0; if (stat(dev, &stat_buf)) return 0; if (user == stat_buf.st_uid && stat_buf.st_mode & S_IWUSR) @@ -78,13 +77,13 @@ static void play_audio(char *data, int size) { - int fd; - - fd = open("/dev/audio", O_WRONLY | O_EXCL); - if (fd < 0) - return; - write(fd, data, size); - close(fd); + int fd; + + fd = open("/dev/audio", O_WRONLY | O_EXCL); + if (fd < 0) + return; + write(fd, data, size); + close(fd); } static void play_audio_file(char *file) @@ -138,19 +137,20 @@ ** Z-note -- this is from libaudiofile. Thanks guys! */ -int _af_ulaw2linear (unsigned char ulawbyte) +int _af_ulaw2linear(unsigned char ulawbyte) { - static int exp_lut[8] = {0,132,396,924,1980,4092,8316,16764}; - int sign, exponent, mantissa, sample; + static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 }; + int sign, exponent, mantissa, sample; - ulawbyte = ~ulawbyte; - sign = (ulawbyte & 0x80); - exponent = (ulawbyte >> 4) & 0x07; - mantissa = ulawbyte & 0x0F; - sample = exp_lut[exponent] + (mantissa << (exponent + 3)); - if (sign != 0) sample = -sample; + ulawbyte = ~ulawbyte; + sign = (ulawbyte & 0x80); + exponent = (ulawbyte >> 4) & 0x07; + mantissa = ulawbyte & 0x0F; + sample = exp_lut[exponent] + (mantissa << (exponent + 3)); + if (sign != 0) + sample = -sample; - return(sample); + return (sample); } @@ -158,20 +158,20 @@ static int play_esd(unsigned char *data, int size) { - int i; - guint16 *lineardata; - - lineardata = g_malloc(size * 2); + int i; + guint16 *lineardata; - for (i=0; i<size; i++) + lineardata = g_malloc(size * 2); + + for (i = 0; i < size; i++) lineardata[i] = _af_ulaw2linear(data[i]); - + write(esd_fd, lineardata, size * 2); close(esd_fd); g_free(lineardata); - return 1; + return 1; } @@ -189,10 +189,10 @@ { esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO; - esd_fd = esd_play_stream(format, 8012, NULL, "gaim"); + esd_fd = esd_play_stream(format, 8012, NULL, "gaim"); - if (esd_fd < 0) { - return 0; + if (esd_fd < 0) { + return 0; } return 1; @@ -205,74 +205,70 @@ char nas_server[] = "localhost"; AuServer *nas_serv = NULL; -static AuBool -NasEventHandler(AuServer *aud, AuEvent *ev, AuEventHandlerRec *handler) +static AuBool NasEventHandler(AuServer * aud, AuEvent * ev, AuEventHandlerRec * handler) { - AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev; + AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev; - if (ev->type == AuEventTypeElementNotify) { - switch (event->kind) { - case AuElementNotifyKindState: - switch (event->cur_state) { - case AuStateStop: - _exit(0); - } - break; - } - } - return AuTrue; + if (ev->type == AuEventTypeElementNotify) { + switch (event->kind) { + case AuElementNotifyKindState: + switch (event->cur_state) { + case AuStateStop: + _exit(0); + } + break; + } + } + return AuTrue; } static int play_nas(unsigned char *data, int size) { - AuDeviceID device = AuNone; - AuFlowID flow; - AuElement elements[3]; - int i, n, w; + AuDeviceID device = AuNone; + AuFlowID flow; + AuElement elements[3]; + int i, n, w; - /* look for an output device */ - for (i = 0; i < AuServerNumDevices(nas_serv); i++) { - if ((AuDeviceKind(AuServerDevice(nas_serv, i)) == - AuComponentKindPhysicalOutput) && - AuDeviceNumTracks(AuServerDevice(nas_serv, i)) == 1) { - device = AuDeviceIdentifier(AuServerDevice(nas_serv, i)); - break; - } - } + /* look for an output device */ + for (i = 0; i < AuServerNumDevices(nas_serv); i++) { + if ((AuDeviceKind(AuServerDevice(nas_serv, i)) == + AuComponentKindPhysicalOutput) && + AuDeviceNumTracks(AuServerDevice(nas_serv, i)) == 1) { + device = AuDeviceIdentifier(AuServerDevice(nas_serv, i)); + break; + } + } - if (device == AuNone) - return 0; + if (device == AuNone) + return 0; - if (!(flow = AuCreateFlow(nas_serv, NULL))) - return 0; + if (!(flow = AuCreateFlow(nas_serv, NULL))) + return 0; - AuMakeElementImportClient(&elements[0], 8012, AuFormatULAW8, - 1, AuTrue, size, size/2, 0, NULL); - AuMakeElementExportDevice(&elements[1], 0, device, 8012, - AuUnlimitedSamples, 0, NULL); - AuSetElements(nas_serv, flow, AuTrue, 2, elements, NULL); + AuMakeElementImportClient(&elements[0], 8012, AuFormatULAW8, 1, AuTrue, size, size / 2, 0, NULL); + AuMakeElementExportDevice(&elements[1], 0, device, 8012, AuUnlimitedSamples, 0, NULL); + AuSetElements(nas_serv, flow, AuTrue, 2, elements, NULL); - AuStartFlow(nas_serv, flow, NULL); + AuStartFlow(nas_serv, flow, NULL); + + AuWriteElement(nas_serv, flow, 0, size, data, AuTrue, NULL); - AuWriteElement(nas_serv, flow, 0, size, data, AuTrue, NULL); + AuRegisterEventHandler(nas_serv, AuEventHandlerIDMask, 0, flow, NasEventHandler, NULL); - AuRegisterEventHandler(nas_serv, AuEventHandlerIDMask, 0, flow, - NasEventHandler, NULL); - - while(1) { - AuHandleEvents(nas_serv); - } + while (1) { + AuHandleEvents(nas_serv); + } - return 1; + return 1; } static int can_play_nas() { - if ((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) - return 1; - return 0; + if ((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL))) + return 1; + return 0; } static int play_nas_file(char *file) @@ -302,7 +298,8 @@ #endif -void play_file(char *filename) { +void play_file(char *filename) +{ int pid; #ifdef _WIN32 @@ -331,7 +328,6 @@ execvp(args[0], args); _exit(0); } - #ifdef ESD_SOUND if (play_esd_file(filename)) _exit(0); @@ -355,50 +351,49 @@ void play(unsigned char *data, int size) { - int pid; + int pid; #ifdef _WIN32 - return; + return; #endif - + pid = fork(); - + if (pid < 0) return; - else if (pid == 0) { + else if (pid == 0) { if (sound_options & OPT_SOUND_BEEP) { printf("\a"); fflush(stdout); _exit(0); } - #ifdef ESD_SOUND - /* ESD is our player of choice. Are we OK to - * go there? */ - if (can_play_esd()) { - if (play_esd(data, size)) - _exit(0); - } + /* ESD is our player of choice. Are we OK to + * go there? */ + if (can_play_esd()) { + if (play_esd(data, size)) + _exit(0); + } #endif #ifdef NAS_SOUND - /* NAS is our second choice setup. */ - if (can_play_nas()) { - if (play_nas(data, size)) - _exit(0); - } + /* NAS is our second choice setup. */ + if (can_play_nas()) { + if (play_nas(data, size)) + _exit(0); + } #endif - /* Lastly, we can try just plain old /dev/audio */ - if (can_play_audio()) { - play_audio(data, size); - _exit(0); - } + /* Lastly, we can try just plain old /dev/audio */ + if (can_play_audio()) { + play_audio(data, size); + _exit(0); + } _exit(0); - } else { - gtk_timeout_add(100, (GtkFunction)clean_pid, NULL); - } + } else { + gtk_timeout_add(100, (GtkFunction)clean_pid, NULL); + } } extern int logins_not_muted; @@ -409,7 +404,7 @@ if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY)) return; - switch(sound) { + switch (sound) { case BUDDY_ARRIVE: if ((sound_options & OPT_SOUND_LOGIN) && logins_not_muted) { if (sound_file[BUDDY_ARRIVE]) { @@ -428,7 +423,7 @@ } } break; - case FIRST_RECEIVE: + case FIRST_RECEIVE: if (sound_options & OPT_SOUND_FIRST_RCV) { if (sound_file[FIRST_RECEIVE]) { play_file(sound_file[FIRST_RECEIVE]); @@ -437,7 +432,7 @@ } } break; - case RECEIVE: + case RECEIVE: if (sound_options & OPT_SOUND_RECV) { if (sound_file[RECEIVE]) { play_file(sound_file[RECEIVE]); @@ -455,7 +450,7 @@ } } break; - case CHAT_JOIN: + case CHAT_JOIN: if (sound_options & OPT_SOUND_CHAT_JOIN) { if (sound_file[CHAT_JOIN]) { play_file(sound_file[CHAT_JOIN]); @@ -464,7 +459,7 @@ } } break; - case CHAT_LEAVE: + case CHAT_LEAVE: if (sound_options & OPT_SOUND_CHAT_PART) { if (sound_file[CHAT_LEAVE]) { play_file(sound_file[CHAT_LEAVE]); @@ -473,7 +468,7 @@ } } break; - case CHAT_YOU_SAY: + case CHAT_YOU_SAY: if (sound_options & OPT_SOUND_CHAT_YOU_SAY) { if (sound_file[CHAT_YOU_SAY]) { play_file(sound_file[CHAT_YOU_SAY]); @@ -482,7 +477,7 @@ } } break; - case CHAT_SAY: + case CHAT_SAY: if (sound_options & OPT_SOUND_CHAT_SAY) { if (sound_file[CHAT_SAY]) { play_file(sound_file[CHAT_SAY]); @@ -491,6 +486,5 @@ } } break; - } + } } -