Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv6647

Modified Files:
        Makefile muted.c 
Log Message:
Update muted for operation on OSX.  :)


Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/Makefile,v
retrieving revision 1.181
retrieving revision 1.182
diff -u -d -r1.181 -r1.182
--- Makefile    15 Jul 2005 22:21:31 -0000      1.181
+++ Makefile    18 Jul 2005 04:22:08 -0000      1.182
@@ -247,6 +247,7 @@
 ifeq (${OSARCH},Darwin)
 LIBS+=-lresolv
 CFLAGS+=-D__Darwin__
+AUDIO_LIBS=-framework CoreAudio
 endif
 ifeq (${OSARCH},FreeBSD)
 LIBS+=-lcrypto
@@ -447,7 +448,7 @@
        $(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) ast_expr.a $(LIBEDIT) 
db1-ast/libdb1.a stdtime/libtime.a $(LIBS)
 
 muted: muted.o
-       $(CC) -o muted muted.o
+       $(CC) $(AUDIO_LIBS) -o muted muted.o
 
 subdirs: 
        for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done

Index: muted.c
===================================================================
RCS file: /usr/cvsroot/asterisk/muted.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- muted.c     22 Apr 2005 13:11:34 -0000      1.7
+++ muted.c     18 Jul 2005 04:22:08 -0000      1.8
@@ -6,12 +6,19 @@
  * Copyright (C)  2004 - 2005, Digium Inc.
  *
  * Mark Spencer <[EMAIL PROTECTED]>
+ * 
+ * Updated for Mac OSX CoreAudio 
+ * by Josh Roberson <[EMAIL PROTECTED]>
  *
  * Distributed under the terms of the GNU General Public License version 2.0 
  *
  */
 
+#ifndef __Darwin__
 #include <linux/soundcard.h>
+#else
+#include <CoreAudio/AudioHardware.h> 
+#endif
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -35,7 +42,9 @@
 static int needfork = 1;
 static int debug = 0;
 static int stepsize = 3;
+#ifndef __Darwin__
 static int mixchan = SOUND_MIXER_VOLUME;
+#endif
 
 struct subchannel {
        char *name;
@@ -148,7 +157,7 @@
 }
 
 static FILE *astf;
-
+#ifndef __Darwin__
 static int mixfd;
 
 static int open_mixer(void)
@@ -160,6 +169,7 @@
        }
        return 0;
 }
+#endif /* !__Darwin */
 
 static int connect_asterisk(void)
 {
@@ -290,27 +300,84 @@
        return chan;
 }
 
+#ifndef __Darwin__
 static int getvol(void)
 {
        int vol;
+
        if (ioctl(mixfd, MIXER_READ(mixchan), &vol)) {
+#else
+static float getvol(void)
+{
+       float volumeL, volumeR, vol;
+       OSStatus err;
+       AudioDeviceID device;
+       UInt32 size;
+       UInt32 channels[2];
+
+       size = sizeof(device);
+       err = 
AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, 
&device);
+       size = sizeof(channels);
+       if (!err) 
+               err = AudioDeviceGetProperty(device, 0, false, 
kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
+       size = sizeof(vol);
+       if (!err)
+               err = AudioDeviceGetProperty(device, channels[0], false, 
kAudioDevicePropertyVolumeScalar, &size, &volumeL);
+       if (!err)
+               err = AudioDeviceGetProperty(device, channels[1], false, 
kAudioDevicePropertyVolumeScalar, &size, &volumeR);
+       printf("volumeL = %f - volumeR = %f\n", volumeL, volumeR);
+       if (!err)
+               vol = (volumeL < volumeR) ? volumeR : volumeL;
+       else {
+#endif
                fprintf(stderr, "Unable to read mixer volume: %s\n", 
strerror(errno));
                return -1;
        }
        return vol;
 }
 
+#ifndef __Darwin__
 static int setvol(int vol)
+#else
+static int setvol(float vol)
+#endif
 {
+#ifndef __Darwin__
        if (ioctl(mixfd, MIXER_WRITE(mixchan), &vol)) {
+#else  
+       float volumeL = vol;
+       float volumeR = vol;
+       OSStatus err;
+       AudioDeviceID device;
+       UInt32 size;
+       UInt32 channels[2];
+
+       size = sizeof(device);
+       err = 
AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, 
&device);
+       size = sizeof(channels);
+       err = AudioDeviceGetProperty(device, 0, false, 
kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
+       size = sizeof(vol);
+       if (!err)
+               err = AudioDeviceSetProperty(device, 0, channels[0], false, 
kAudioDevicePropertyVolumeScalar, size, &volumeL);
+       if (!err)
+               err = AudioDeviceSetProperty(device, 0, channels[1], false, 
kAudioDevicePropertyVolumeScalar, size, &volumeR); 
+       if (err) {
+#endif
+
                fprintf(stderr, "Unable to write mixer volume: %s\n", 
strerror(errno));
                return -1;
+
        }
        return 0;
 }
 
+#ifndef __Darwin__
 static int oldvol = 0;
 static int mutevol = 0;
+#else
+static float oldvol = 0;
+static float mutevol = 0;
+#endif
 
 static int mutedlevel(int orig, int mutelevel)
 {
@@ -323,7 +390,11 @@
 
 static void mute(void)
 {
+#ifndef __Darwin__
        int vol;
+#else
+       float vol;
+#endif
        int start;
        int x;
        vol = getvol();
@@ -341,19 +412,31 @@
        mutevol = mutedlevel(vol, mutelevel);
        setvol(mutevol);
        if (debug)
+#ifdef __Darwin__
+               printf("Mute from '%f' to '%f'!\n", oldvol, mutevol);
+#else
                printf("Mute from '%04x' to '%04x'!\n", oldvol, mutevol);
+#endif
        muted = 1;
 }
 
 static void unmute(void)
 {
+#ifdef __Darwin__
+       float vol;
+#else
        int vol;
+#endif
        int start;
        int x;
        vol = getvol();
        if (debug)
+#ifdef __Darwin__
+               printf("Unmute from '%f' (should be '%f') to '%f'!\n", vol, 
mutevol, oldvol);
+#else
                printf("Unmute from '%04x' (should be '%04x') to '%04x'!\n", 
vol, mutevol, oldvol);
-       if (vol == mutevol) {
+#endif
+       if ((int)vol == mutevol) {
                if (smoothfade)
                        start = mutelevel;
                else
@@ -522,14 +605,20 @@
        }
        if (load_config())
                exit(1);
+#ifndef __Darwin__
        if (open_mixer())
                exit(1);
+#endif
        if (connect_asterisk()) {
+#ifndef __Darwin__
                close(mixfd);
+#endif
                exit(1);
        }
        if (login_asterisk()) {
+#ifndef __Darwin__             
                close(mixfd);
+#endif
                fclose(astf);
                exit(1);
        }

_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs

Reply via email to