Re: coreaudio-api digest, Vol 1 #146 - 10 msgs
Re: coreaudio-api digest, Vol 1 #146 - 10 msgs
- Subject: Re: coreaudio-api digest, Vol 1 #146 - 10 msgs
- From: "David A. Gatwood" <email@hidden>
- Date: Tue, 4 Dec 2001 15:47:02 -0800 (PST)
On Mon, 3 Dec 2001, David A. Gatwood wrote:
>
Finally, these were diffs against a slightly patched version of both
>
mpg123 and esound that I use in my own pet project, SongCue (which runs on
>
OS X -- check out http://www.songcue.com). You may get some easily
>
corrected glitches when patching against an unmodified tree. Apologies in
>
advance.
Okay, I'm not sure what happened there. mpg123 compiled and it worked,
but for whatever reason, just looking at the patch, I can see that such a
thing isn't possible, because there are parse errors all over the place,
and I tried building it today and it didn't work, as expected. Must have
been in the wrong directory or something. I don't even want to think
about it. Chalk it up to Monday. Here's a corrected patch that works
against stock sources. (See note at bottom about one additional change
for some versions of esound.)
-- begin patch
diff -u mpg123-0.59r/Makefile mpg123-0.59r-patched/Makefile
--- mpg123-0.59r/Makefile Tue Jun 15 13:39:06 1999
+++ mpg123-0.59r-patched/Makefile Tue Dec 4 15:26:20 2001
@@ -222,9 +222,9 @@
linux-ppc-esd:
$(MAKE) CC=gcc LDFLAGS= \
- AUDIO_LIB='-lesd -laudiofile' \
+ AUDIO_LIB='-L/sw/lib -lesd -laudiofile' \
OBJECTS='decode.o dct64.o audio_esd.o' \
- CFLAGS='-DREAL_IS_FLOAT -DLINUX -Wall -O2 -mcpu=ppc \
+ CFLAGS='-DREAL_IS_FLOAT -DLINUX -Wall -O2 \
-DOSS \
-fomit-frame-pointer -funroll-all-loops \
-finline-functions -ffast-math' \
diff -u mpg123-0.59r/mpg123.c mpg123-0.59r-patched/mpg123.c
--- mpg123-0.59r/mpg123.c Tue Jun 15 13:21:36 1999
+++ mpg123-0.59r-patched/mpg123.c Tue Dec 4 15:29:03 2001
@@ -18,13 +18,22 @@
#include <string.h>
#include <fcntl.h>
-#if 0
+#if 1
#define SET_RT
#endif
#ifdef SET_RT
#include <sched.h>
+#if (defined(__ppc__) && defined(__APPLE__))
+#include <mach/mach_init.h>
+#include <mach/task_policy.h>
+#include <mach/thread_act.h>
+#include <mach/thread_policy.h>
+#include <sys/sysctl.h>
+#else
+#error HI!
+#endif
#endif
#include "mpg123.h"
@@ -100,6 +109,12 @@
void set_synth_functions(struct frame *fr);
+#ifdef SET_RT
+#if (defined(__ppc__) && defined(__APPLE__))
+int get_bus_speed();
+#endif
+#endif
+
char *handle_remote(void)
{
switch(frontend_type) {
@@ -874,12 +889,35 @@
#ifdef SET_RT
if (param.realtime) { /* Get real-time priority */
+#if (defined(__ppc__) && defined(__APPLE__))
+ struct thread_time_constraint_policy ttcpolicy;
+ fprintf(stderr,"Getting real-time priority\n");
+
+ /* This is in AbsoluteTime units, which are equal to
+ 1/4 the bus speed on most machines. */
+
+ // hard-coded numbers are approximations for 100 MHz bus speed.
+ // assume that app deals in frame-sized chunks, e.g. 30 per second.
+ // ttcpolicy.period=833333;
+ ttcpolicy.period=(get_bus_speed() / 120);
+ // ttcpolicy.computation=60000;
+ ttcpolicy.computation=(get_bus_speed() / 1440);
+ // ttcpolicy.constraint=120000;
+ ttcpolicy.constraint=(get_bus_speed() / 720);
+ ttcpolicy.preemptible=1;
+
+ if (thread_policy_set(mach_thread_self(),
+ THREAD_TIME_CONSTRAINT_POLICY, (int *)&ttcpolicy,
+ THREAD_TIME_CONSTRAINT_POLICY_COUNT) != KERN_SUCCESS)
+ fprintf(stderr, "Can't do thread_policy_set\n");
+#else /* POSIX_RT */
struct sched_param sp;
fprintf(stderr,"Getting real-time priority\n");
memset(&sp, 0, sizeof(struct sched_param));
sp.sched_priority = sched_get_priority_min(SCHED_FIFO);
if (sched_setscheduler(0, SCHED_RR, &sp) == -1)
fprintf(stderr,"Can't get real-time priority\n");
+#endif
}
#endif
@@ -1198,5 +1236,30 @@
fprintf(o,"\nSee the manpage %s(1) for more information.\n", prgName);
exit(0);
}
+
+#ifdef SET_RT
+#if (defined(__ppc__) && defined(__APPLE__))
+int get_bus_speed()
+{
+int mib[2];
+unsigned int miblen;
+int busspeed;
+int retval;
+size_t len;
+
+mib[0]=CTL_HW;
+mib[1]=HW_BUS_FREQ;
+miblen=2;
+len=4;
+retval = sysctl(mib, miblen, &busspeed, &len, NULL, 0);
+
+/* Note: you should really check retval here, see man sysctl for info */
+
+// printf("%d\n", busspeed);
+return busspeed;
+}
+
+#endif
+#endif
-- end patch
Note that I've found another issue with esound support, or at least with
the version I have. Since it prevents compiling, I figured it was worth
at least mentioning. If you run into a compile error with an undefined
symbol "esdserver", then in audio_esd.c: in line 78, change:
ai->fn = esd_play_stream_fallback(format, ai->rate, esdserver, "mpg123");
to
if ((ai->fn = esd_play_stream(format, ai->rate, NULL, "mpg123")) == NULL)
ai->fn = esd_play_stream_fallback(format, ai->rate, NULL, "mpg123");
Again, completely unrelated to the issue at hand, but I figured it was
worth mentioning in case someone ran into it.
Later,
David
---------------------------------------------------------------------
Check out my weekly web comic:
http://www.techmagazine.org