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 */
32 namespace RubberBand {
35 system_is_multiprocessor()
37 static bool tested = false, mp = false;
39 if (tested) return mp;
45 GetSystemInfo(&sysinfo);
46 count = sysinfo.dwNumberOfProcessors;
51 size_t sz = sizeof(count);
52 if (sysctlbyname("hw.ncpu", &count, &sz, NULL, 0)) {
58 #else /* !__APPLE__, !_WIN32 */
62 FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
63 if (!cpuinfo) return false;
66 while (!feof(cpuinfo)) {
67 fgets(buf, 256, cpuinfo);
68 if (!strncmp(buf, "processor", 9)) {
76 #endif /* !__APPLE__, !_WIN32 */
86 int gettimeofday(struct timeval *tv, void *tz)
93 ::GetSystemTimeAsFileTime(&now.ft);
94 tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL);
95 tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL);
99 void usleep(unsigned long usec)
101 ::Sleep(usec == 0 ? 0 : usec < 1000 ? 1 : usec / 1000);
107 float *allocFloat(float *ptr, int count)
109 if (ptr) free((void *)ptr);
113 if (!posix_memalign(&allocated, 16, count * sizeof(float)))
116 allocated = malloc(count * sizeof(float));
117 for (int i = 0; i < count; ++i) ((float *)allocated)[i] = 0.f;
118 return (float *)allocated;
121 float *allocFloat(int count)
123 return allocFloat(0, count);
126 void freeFloat(float *ptr)
131 double *allocDouble(double *ptr, int count)
133 if (ptr) free((void *)ptr);
137 if (!posix_memalign(&allocated, 16, count * sizeof(double)))
140 allocated = malloc(count * sizeof(double));
141 for (int i = 0; i < count; ++i) ((double *)allocated)[i] = 0.f;
142 return (double *)allocated;
145 double *allocDouble(int count)
147 return allocDouble(0, count);
150 void freeDouble(double *ptr)