1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
5 An audio time-stretching and pitch-shifting library.
6 Copyright 2007-2008 Chris Cannam.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
21 #include <sys/sysctl.h>
22 #else /* !__APPLE__, !_WIN32 */
25 #endif /* !__APPLE__, !_WIN32 */
31 namespace RubberBand {
34 system_is_multiprocessor()
36 static bool tested = false, mp = false;
38 if (tested) return mp;
44 GetSystemInfo(&sysinfo);
45 count = sysinfo.dwNumberOfProcessors;
50 size_t sz = sizeof(count);
51 if (sysctlbyname("hw.ncpu", &count, &sz, NULL, 0)) {
57 #else /* !__APPLE__, !_WIN32 */
61 FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
62 if (!cpuinfo) return false;
65 while (!feof(cpuinfo)) {
66 fgets(buf, 256, cpuinfo);
67 if (!strncmp(buf, "processor", 9)) {
75 #endif /* !__APPLE__, !_WIN32 */
85 int gettimeofday(struct timeval *tv, void *tz)
92 ::GetSystemTimeAsFileTime(&now.ft);
93 tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL);
94 tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL);
98 void usleep(unsigned long usec)
100 ::Sleep(usec == 0 ? 0 : usec < 1000 ? 1 : usec / 1000);
106 float *allocFloat(float *ptr, int count)
108 if (ptr) free((void *)ptr);
112 if (!posix_memalign(&allocated, 16, count * sizeof(float)))
115 allocated = malloc(count * sizeof(float));
116 for (int i = 0; i < count; ++i) ((float *)allocated)[i] = 0.f;
117 return (float *)allocated;
120 float *allocFloat(int count)
122 return allocFloat(0, count);
125 void freeFloat(float *ptr)
130 double *allocDouble(double *ptr, int count)
132 if (ptr) free((void *)ptr);
136 if (!posix_memalign(&allocated, 16, count * sizeof(double)))
139 allocated = malloc(count * sizeof(double));
140 for (int i = 0; i < count; ++i) ((double *)allocated)[i] = 0.f;
141 return (double *)allocated;
144 double *allocDouble(int count)
146 return allocDouble(0, count);
149 void freeDouble(double *ptr)