annotate src/sound.c @ 3110:13e5dc68efbc

[gaim-migrate @ 3124] SWEN committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 29 Mar 2002 04:13:57 +0000
parents a7e03c5d2205
children 16c2ad1a15ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
22 #ifdef HAVE_CONFIG_H
2090
b66aca8e8dce [gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2048
diff changeset
23 #include <config.h>
349
b402a23f35df [gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
24 #endif
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 #include <stdio.h>
1057
d50d3abb9eb7 [gaim-migrate @ 1067]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1006
diff changeset
26 #include <stdlib.h>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <string.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <sys/time.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 #include <unistd.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <fcntl.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #include <sys/wait.h>
63
12894b62d206 [gaim-migrate @ 73]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1
diff changeset
32 #include <unistd.h>
12894b62d206 [gaim-migrate @ 73]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1
diff changeset
33 #include <sys/types.h>
12894b62d206 [gaim-migrate @ 73]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1
diff changeset
34 #include <sys/stat.h>
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #ifdef ESD_SOUND
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 #include <esd.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 #endif
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
40 #ifdef ARTSC_SOUND
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
41 #include <artsc.h>
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
42 #endif
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
43
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 #ifdef NAS_SOUND
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 #include <audio/audiolib.h>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46 #endif
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 #include "gaim.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49 #include "sounds/BuddyArrive.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 #include "sounds/BuddyLeave.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 #include "sounds/Send.h"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 #include "sounds/Receive.h"
1694
bea407767ac1 [gaim-migrate @ 1704]
Rob Flynn <gaim@robflynn.com>
parents: 1517
diff changeset
53 #include "sounds/RedAlert.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
55 /* label and opt are null for the buddy pounce because it's configured *
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
56 * per pounce. NULL option means it doesn't get displayed in the sound *
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
57 * preferences box */
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
58 struct sound_struct sounds[NUM_SOUNDS] = {
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
59 N_("Buddy logs in"), OPT_SOUND_LOGIN, BuddyArrive, sizeof(BuddyArrive),
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
60 N_("Buddy logs out"), OPT_SOUND_LOGOUT, BuddyLeave, sizeof(BuddyLeave),
3072
359b4cd0e766 [gaim-migrate @ 3086]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
61 N_("Message recieved"), OPT_SOUND_RECV, Receive, sizeof(Receive),
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
62 N_("Message recieved begins conversation"), OPT_SOUND_FIRST_RCV, Receive, sizeof(Receive),
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
63 N_("Message sent"), OPT_SOUND_SEND, Send, sizeof(Send),
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
64 N_("Person enters chat"), OPT_SOUND_CHAT_JOIN, BuddyArrive, sizeof(BuddyArrive),
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
65 N_("Person leaves chat"), OPT_SOUND_CHAT_PART, BuddyLeave, sizeof(BuddyLeave),
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
66 N_("You talk in chat"), OPT_SOUND_CHAT_YOU_SAY, Send, sizeof(Send),
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
67 N_("Others talk in chat"), OPT_SOUND_CHAT_SAY, Receive, sizeof(Receive),
3072
359b4cd0e766 [gaim-migrate @ 3086]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
68 NULL, 0, RedAlert, sizeof(RedAlert)
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
69 };
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
70
655
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
71 static int check_dev(char *dev)
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
72 {
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
73 struct stat stat_buf;
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
74 uid_t user = getuid();
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
75 gid_t group = getgid(), other_groups[32];
899
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
76 int i, numgroups;
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
77
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
78 if ((numgroups = getgroups(32, other_groups)) == -1)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
79 return 0;
655
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
80 if (stat(dev, &stat_buf))
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
81 return 0;
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
82 if (user == stat_buf.st_uid && stat_buf.st_mode & S_IWUSR)
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
83 return 1;
899
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
84 if (stat_buf.st_mode & S_IWGRP) {
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
85 if (group == stat_buf.st_gid)
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
86 return 1;
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
87 for (i = 0; i < numgroups; i++)
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
88 if (other_groups[i] == stat_buf.st_gid)
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
89 return 1;
88d1edcd7cd6 [gaim-migrate @ 909]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 778
diff changeset
90 }
655
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
91 if (stat_buf.st_mode & S_IWOTH)
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
92 return 1;
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
93 return 0;
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
94 }
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
95
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96
2048
3366311426df [gaim-migrate @ 2058]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1805
diff changeset
97 static void play_audio(unsigned char *data, int size)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
99 int fd;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
100
2467
cd81f1f2c896 [gaim-migrate @ 2480]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2372
diff changeset
101 fd = open("/dev/audio", O_WRONLY | O_EXCL | O_NDELAY);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
102 if (fd < 0)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
103 return;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
104 write(fd, data, size);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
105 close(fd);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
108 static void play_audio_file(char *file)
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
109 {
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
110 /* here we can assume that we can write to /dev/audio */
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
111 char *buf;
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
112 struct stat info;
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
113 int fd = open(file, O_RDONLY);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
114 if (fd <= 0) {
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
115 return;
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
116 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
117 fstat(fd, &info);
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
118 if (info.st_size < 24)
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
119 return;
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
120 buf = malloc(info.st_size + 1);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
121 read(fd, buf, 24);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
122 read(fd, buf, info.st_size - 24);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
123 close(fd);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
124
2467
cd81f1f2c896 [gaim-migrate @ 2480]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2372
diff changeset
125 fd = open("/dev/audio", O_WRONLY | O_EXCL | O_NDELAY);
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
126 if (fd < 0) {
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
127 free(buf);
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
128 return;
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
129 }
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
130 write(fd, buf, info.st_size - 24);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
131 free(buf);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
132 close(fd);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
133 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
134
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
135 static int can_play_audio()
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
136 {
655
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
137 return check_dev("/dev/audio");
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
141 #if defined(ESD_SOUND) || defined(ARTSC_SOUND)
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
142
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
143 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
144 ** This routine converts from ulaw to 16 bit linear.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
145 **
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
146 ** Craig Reese: IDA/Supercomputing Research Center
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
147 ** 29 September 1989
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148 **
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149 ** References:
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
150 ** 1) CCITT Recommendation G.711 (very difficult to follow)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
151 ** 2) MIL-STD-188-113,"Interoperability and Performance Standards
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152 ** for Analog-to_Digital Conversion Techniques,"
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
153 ** 17 February 1987
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
154 **
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155 ** Input: 8 bit ulaw sample
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156 ** Output: signed 16 bit linear sample
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157 ** Z-note -- this is from libaudiofile. Thanks guys!
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
158 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159
2158
9b7cb09e2c06 [gaim-migrate @ 2168]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2090
diff changeset
160 static int _af_ulaw2linear(unsigned char ulawbyte)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
162 static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 };
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
163 int sign, exponent, mantissa, sample;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
165 ulawbyte = ~ulawbyte;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
166 sign = (ulawbyte & 0x80);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
167 exponent = (ulawbyte >> 4) & 0x07;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
168 mantissa = ulawbyte & 0x0F;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
169 sample = exp_lut[exponent] + (mantissa << (exponent + 3));
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
170 if (sign != 0)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
171 sample = -sample;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
173 return (sample);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
174 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
175
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
176 #endif
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
177
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
178 #ifdef ESD_SOUND
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179
354
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
180 int esd_fd;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
182 static int play_esd(unsigned char *data, int size)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
183 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
184 int i;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
185 guint16 *lineardata;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
186
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
187 lineardata = g_malloc(size * 2);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
188
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
189 for (i = 0; i < size; i++)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
190 lineardata[i] = _af_ulaw2linear(data[i]);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
191
354
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
192 write(esd_fd, lineardata, size * 2);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
193
354
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
194 close(esd_fd);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195 g_free(lineardata);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
196
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
197 return 1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
201 static int can_play_esd()
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202 {
354
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
203 esd_format_t format = ESD_BITS16 | ESD_STREAM | ESD_PLAY | ESD_MONO;
655
6ba20a0089d8 [gaim-migrate @ 665]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 606
diff changeset
204
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
205 esd_fd = esd_play_stream(format, 8012, NULL, "gaim");
354
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
206
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
207 if (esd_fd < 0) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
208 return 0;
354
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
209 }
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
210
2b91e42bff70 [gaim-migrate @ 364]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 349
diff changeset
211 return 1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
212 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
213
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
214 #endif
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
215
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
216 #ifdef ARTSC_SOUND
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
217
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
218 static int play_artsc(unsigned char *data, int size)
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
219 {
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
220 arts_stream_t stream;
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2370
diff changeset
221 guint16 *lineardata;
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
222 int result = 1;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
223 int error;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
224 int i;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
225
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
226 lineardata = g_malloc(size * 2);
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
227
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
228 for (i = 0; i < size; i++) {
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
229 lineardata[i] = _af_ulaw2linear(data[i]);
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
230 }
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
231
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
232 stream = arts_play_stream(8012, 16, 1, "gaim");
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
233
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
234 error = arts_write(stream, lineardata, size);
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
235 if (error < 0) {
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
236 result = 0;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
237 }
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
238
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
239 arts_close_stream(stream);
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
240
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
241 g_free(lineardata);
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
242
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
243 arts_free();
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
244
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
245 return result;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
246 }
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
247
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
248 static int can_play_artsc()
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
249 {
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
250 int error;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
251
2183
94ee8eacb6f8 [gaim-migrate @ 2193]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2179
diff changeset
252 error = arts_init();
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
253 if (error < 0)
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
254 return 0;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
255
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
256 return 1;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
257 }
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
258
2186
08781af8e3a9 [gaim-migrate @ 2196]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2183
diff changeset
259 static int artsc_play_file(char *file)
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
260 {
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
261 struct stat stat_buf;
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2370
diff changeset
262 unsigned char *buf = NULL;
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
263 int result = 0;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
264 int fd = -1;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
265
2680
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
266 if (!can_play_artsc())
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
267 return 0;
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
268
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
269 fd = open(file, O_RDONLY);
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
270 if (fd < 0)
2680
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
271 return 0;
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
272
2680
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
273 if (fstat(fd, &stat_buf)) {
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
274 close(fd);
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
275 return 0;
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
276 }
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
277
2680
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
278 if (!stat_buf.st_size) {
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
279 close(fd);
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
280 return 0;
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
281 }
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
282
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
283 buf = g_malloc(stat_buf.st_size);
2680
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
284 if (!buf) {
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
285 close(fd);
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
286 return 0;
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
287 }
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2370
diff changeset
288
2680
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
289 if (read(fd, buf, stat_buf.st_size) < 0) {
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
290 g_free(buf);
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
291 close(fd);
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
292 return 0;
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
293 }
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
294
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
295 result = play_artsc(buf, stat_buf.st_size);
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
296
2680
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
297 g_free(buf);
ab2ca2770d2e [gaim-migrate @ 2693]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2601
diff changeset
298 close(fd);
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
299 return result;
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
300 }
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
301
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
302 #endif /* ARTSC_SOUND */
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
303
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
304 #ifdef NAS_SOUND
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
305
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
306 char nas_server[] = "localhost";
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
307 AuServer *nas_serv = NULL;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
308
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
309 static AuBool NasEventHandler(AuServer * aud, AuEvent * ev, AuEventHandlerRec * handler)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
310 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
311 AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
312
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
313 if (ev->type == AuEventTypeElementNotify) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
314 switch (event->kind) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
315 case AuElementNotifyKindState:
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
316 switch (event->cur_state) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
317 case AuStateStop:
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
318 _exit(0);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
319 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
320 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
321 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
322 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
323 return AuTrue;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
325
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
326
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
327 static int play_nas(unsigned char *data, int size)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
328 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
329 AuDeviceID device = AuNone;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
330 AuFlowID flow;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
331 AuElement elements[3];
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
332 int i, n, w;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
333
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
334 /* look for an output device */
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
335 for (i = 0; i < AuServerNumDevices(nas_serv); i++) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
336 if ((AuDeviceKind(AuServerDevice(nas_serv, i)) ==
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
337 AuComponentKindPhysicalOutput) &&
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
338 AuDeviceNumTracks(AuServerDevice(nas_serv, i)) == 1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
339 device = AuDeviceIdentifier(AuServerDevice(nas_serv, i));
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
340 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
341 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
342 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
343
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
344 if (device == AuNone)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
345 return 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
346
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
347 if (!(flow = AuCreateFlow(nas_serv, NULL)))
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
348 return 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
349
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
350
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
351 AuMakeElementImportClient(&elements[0], 8012, AuFormatULAW8, 1, AuTrue, size, size / 2, 0, NULL);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
352 AuMakeElementExportDevice(&elements[1], 0, device, 8012, AuUnlimitedSamples, 0, NULL);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
353 AuSetElements(nas_serv, flow, AuTrue, 2, elements, NULL);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
354
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
355 AuStartFlow(nas_serv, flow, NULL);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
356
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
357 AuWriteElement(nas_serv, flow, 0, size, data, AuTrue, NULL);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
358
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
359 AuRegisterEventHandler(nas_serv, AuEventHandlerIDMask, 0, flow, NasEventHandler, NULL);
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
360
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
361 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
362 AuHandleEvents(nas_serv);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
363 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
364
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
365 return 1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
366 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
367
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
368 static int can_play_nas()
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
369 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
370 if ((nas_serv = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL)))
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
371 return 1;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
372 return 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
373 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
374
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
375 static int play_nas_file(char *file)
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
376 {
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
377 struct stat stat_buf;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
378 char *buf;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
379 int ret;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
380 int fd = open(file, O_RDONLY);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
381 if (fd <= 0)
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
382 return 0;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
383
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
384 if (!can_play_nas())
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
385 return 0;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
386
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
387 if (stat(file, &stat_buf))
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
388 return 0;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
389
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
390 if (!stat_buf.st_size)
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
391 return 0;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
392
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
393 buf = malloc(stat_buf.st_size);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
394 read(fd, buf, stat_buf.st_size);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
395 ret = play_nas(buf, stat_buf.st_size);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
396 free(buf);
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
397 return ret;
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
398 }
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
399
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
400 #endif
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
401
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
402 void play_file(char *filename)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
403 {
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
404 int pid;
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
405
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
406 #ifdef _WIN32
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
407 return;
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
408 #endif
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
409
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
410 if (sound_options & OPT_SOUND_BEEP) {
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
411 gdk_beep();
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
412 return;
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
413 }
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
414
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
415 else if (sound_options & OPT_SOUND_NORMAL) {
3072
359b4cd0e766 [gaim-migrate @ 3086]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
416 debug_printf("attempting to play audio file with internal method -- this is unlikely to work\n");
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
417 }
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
418
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
419 pid = fork();
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
420
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
421 if (pid < 0)
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
422 return;
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
423 else if (pid == 0) {
2601
61952dde7677 [gaim-migrate @ 2614]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2580
diff changeset
424 alarm(30);
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
425
3025
0486d3d00d0e [gaim-migrate @ 3038]
Sean Egan <seanegan@gmail.com>
parents: 3006
diff changeset
426 if ((sound_options & OPT_SOUND_CMD) && sound_cmd[0]) {
1214
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
427 char *args[4];
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
428 char command[4096];
2777
0899f8c99a15 [gaim-migrate @ 2790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2680
diff changeset
429
0899f8c99a15 [gaim-migrate @ 2790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2680
diff changeset
430 g_snprintf(command, sizeof(command), sound_cmd, filename);
0899f8c99a15 [gaim-migrate @ 2790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2680
diff changeset
431
1214
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
432 args[0] = "sh";
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
433 args[1] = "-c";
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
434 args[2] = command;
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
435 args[3] = NULL;
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
436 execvp(args[0], args);
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
437 _exit(0);
0baf39dc5437 [gaim-migrate @ 1224]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1109
diff changeset
438 }
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
439 #ifdef ESD_SOUND
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
440 else if (sound_options & OPT_SOUND_ESD) {
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
441 if (esd_play_file(NULL, filename, 1))
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
442 _exit(0);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
443 }
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
444 #endif
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
445
2186
08781af8e3a9 [gaim-migrate @ 2196]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2183
diff changeset
446 #ifdef ARTSC_SOUND
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
447 else if (sound_options & OPT_SOUND_ARTSC) {
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
448 if (artsc_play_file(filename))
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
449 _exit(0);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
450 }
2186
08781af8e3a9 [gaim-migrate @ 2196]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2183
diff changeset
451 #endif
08781af8e3a9 [gaim-migrate @ 2196]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2183
diff changeset
452
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
453 #ifdef NAS_SOUND
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
454 else if (sound_options & OPT_SOUND_NAS) {
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
455 if (play_nas_file(filename))
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
456 _exit(0);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
457 }
1109
c73736fa0b7c [gaim-migrate @ 1119]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1057
diff changeset
458 #endif
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
459 else if ((sound_options & OPT_SOUND_NORMAL) &&
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
460 can_play_audio()) {
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
461 play_audio_file(filename);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
462 _exit(0);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
463 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
464
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
465 _exit(0);
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
466 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
467 }
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
468
133
e277d5f0c1dd [gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 108
diff changeset
469 void play(unsigned char *data, int size)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
470 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
471 int pid;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
472
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
473 #ifdef _WIN32
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
474 return;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
475 #endif
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
476
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
477 if (sound_options & OPT_SOUND_BEEP) {
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
478 gdk_beep();
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
479 return;
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
480 }
3025
0486d3d00d0e [gaim-migrate @ 3038]
Sean Egan <seanegan@gmail.com>
parents: 3006
diff changeset
481
0486d3d00d0e [gaim-migrate @ 3038]
Sean Egan <seanegan@gmail.com>
parents: 3006
diff changeset
482 else if ((sound_options & OPT_SOUND_CMD) && sound_cmd[0]) {
0486d3d00d0e [gaim-migrate @ 3038]
Sean Egan <seanegan@gmail.com>
parents: 3006
diff changeset
483 debug_printf("can't play internal sound with external command -- skipping\n");
0486d3d00d0e [gaim-migrate @ 3038]
Sean Egan <seanegan@gmail.com>
parents: 3006
diff changeset
484 return;
0486d3d00d0e [gaim-migrate @ 3038]
Sean Egan <seanegan@gmail.com>
parents: 3006
diff changeset
485 }
0486d3d00d0e [gaim-migrate @ 3038]
Sean Egan <seanegan@gmail.com>
parents: 3006
diff changeset
486
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
487 pid = fork();
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
488
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
489 if (pid < 0)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
490 return;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
491 else if (pid == 0) {
2601
61952dde7677 [gaim-migrate @ 2614]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2580
diff changeset
492 alarm(30);
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
493
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
494 #ifdef ESD_SOUND
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
495 /* ESD is our player of choice. Are we OK to
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
496 * go there? */
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 2995
diff changeset
497 if (sound_options & OPT_SOUND_ESD) {
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
498 if (can_play_esd()) {
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
499 if (play_esd(data, size))
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
500 _exit(0);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
501 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
502 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
503 #endif
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
504
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
505 #ifdef ARTSC_SOUND
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
506 /* ArtsC is the new second choice. */
3006
234ce8eb132d [gaim-migrate @ 3019]
Sean Egan <seanegan@gmail.com>
parents: 3005
diff changeset
507 if (sound_options & OPT_SOUND_ARTSC) {
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
508 if (can_play_artsc()) {
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
509 if (play_artsc(data, size))
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
510 _exit(0);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
511 }
2179
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
512 }
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
513 #endif
64d8ef561763 [gaim-migrate @ 2189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2158
diff changeset
514
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
515 #ifdef NAS_SOUND
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
516 /* NAS is our second choice setup. */
3006
234ce8eb132d [gaim-migrate @ 3019]
Sean Egan <seanegan@gmail.com>
parents: 3005
diff changeset
517 if (sound_options & OPT_SOUND_NAS) {
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
518 if (can_play_nas()) {
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
519 if (play_nas(data, size))
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
520 _exit(0);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
521 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
522 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
523 #endif
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
524
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
525 /* Lastly, we can try just plain old /dev/audio */
3005
00ce285e3ed1 [gaim-migrate @ 3018]
Sean Egan <seanegan@gmail.com>
parents: 3004
diff changeset
526 if (sound_options & OPT_SOUND_NORMAL) {
2580
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
527 if (can_play_audio()) {
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
528 play_audio(data, size);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
529 _exit(0);
86eaeb064e82 [gaim-migrate @ 2593]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2478
diff changeset
530 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
531 }
668
c9b66c710283 [gaim-migrate @ 678]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 655
diff changeset
532
c9b66c710283 [gaim-migrate @ 678]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 655
diff changeset
533 _exit(0);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
534 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
535 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
536
133
e277d5f0c1dd [gaim-migrate @ 143]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 108
diff changeset
537 extern int logins_not_muted;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
538
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
539 void play_sound(int sound)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
540 {
1235
a9cf2f61a7b1 [gaim-migrate @ 1245]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1214
diff changeset
541 if (awaymessage && !(sound_options & OPT_SOUND_WHEN_AWAY))
a9cf2f61a7b1 [gaim-migrate @ 1245]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1214
diff changeset
542 return;
a9cf2f61a7b1 [gaim-migrate @ 1245]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1214
diff changeset
543
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
544 if ((sound == SND_BUDDY_ARRIVE) && !logins_not_muted)
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
545 return;
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
546
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
547 if (sound >= NUM_SOUNDS) {
3072
359b4cd0e766 [gaim-migrate @ 3086]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
548 debug_printf("sorry old fruit... can't say I know that sound: ", sound, "\n");
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
549 return;
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
550 }
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
551
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
552 /* check NULL for sounds that don't have an option, ie buddy pounce */
3072
359b4cd0e766 [gaim-migrate @ 3086]
Sean Egan <seanegan@gmail.com>
parents: 3060
diff changeset
553 if ((sound_options & sounds[sound].opt) || (sounds[sound].opt == 0)) {
3060
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
554 if (sound_file[sound]) {
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
555 play_file(sound_file[sound]);
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
556 } else {
4f2f12bf4408 [gaim-migrate @ 3074]
Sean Egan <seanegan@gmail.com>
parents: 3025
diff changeset
557 play(sounds[sound].snd, sounds[sound].snd_size);
1006
0a4d0ed65e17 [gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 899
diff changeset
558 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1235
diff changeset
559 }
64
b1d7336cba85 [gaim-migrate @ 74]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 63
diff changeset
560 }