jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

751 lines
23KB

  1. //-----------------------------------------------------
  2. // name: "freeverb"
  3. // version: "1.0"
  4. // author: "Grame"
  5. // license: "BSD"
  6. // copyright: "(c)GRAME 2006"
  7. //
  8. // Code generated with Faust 0.9.9.5b2 (http://faust.grame.fr)
  9. //-----------------------------------------------------
  10. /* link with */
  11. /* link with */
  12. #include <math.h>
  13. /* link with */
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <limits.h>
  18. #include <math.h>
  19. #include <errno.h>
  20. #include <time.h>
  21. #include <sys/ioctl.h>
  22. #include <unistd.h>
  23. #include <fcntl.h>
  24. #include <pwd.h>
  25. #include <sys/types.h>
  26. #include <assert.h>
  27. #include <pthread.h>
  28. #include <sys/wait.h>
  29. #include <libgen.h>
  30. #include <jack/net.h>
  31. #include <list>
  32. #include <vector>
  33. #include <iostream>
  34. #include <fstream>
  35. #include <stack>
  36. #include <list>
  37. #include <map>
  38. #include "JackAudioQueueAdapter.h"
  39. using namespace std;
  40. // On Intel set FZ (Flush to Zero) and DAZ (Denormals Are Zero)
  41. // flags to avoid costly denormals
  42. #ifdef __SSE__
  43. #include <xmmintrin.h>
  44. #ifdef __SSE2__
  45. #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8040)
  46. #else
  47. #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000)
  48. #endif
  49. #else
  50. #define AVOIDDENORMALS
  51. #endif
  52. //#define BENCHMARKMODE
  53. struct Meta : map<const char*, const char*>
  54. {
  55. void declare (const char* key, const char* value) { (*this)[key]=value; }
  56. };
  57. #define max(x,y) (((x)>(y)) ? (x) : (y))
  58. #define min(x,y) (((x)<(y)) ? (x) : (y))
  59. inline int lsr (int x, int n) { return int(((unsigned int)x) >> n); }
  60. inline int int2pow2 (int x) { int r = 0; while ((1<<r)<x) r++; return r; }
  61. /******************************************************************************
  62. *******************************************************************************
  63. VECTOR INTRINSICS
  64. *******************************************************************************
  65. *******************************************************************************/
  66. /******************************************************************************
  67. *******************************************************************************
  68. USER INTERFACE
  69. *******************************************************************************
  70. *******************************************************************************/
  71. class UI
  72. {
  73. bool fStopped;
  74. public:
  75. UI() : fStopped(false) {}
  76. virtual ~UI() {}
  77. // -- active widgets
  78. virtual void addButton(const char* label, float* zone) = 0;
  79. virtual void addToggleButton(const char* label, float* zone) = 0;
  80. virtual void addCheckButton(const char* label, float* zone) = 0;
  81. virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
  82. virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
  83. virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0;
  84. // -- passive widgets
  85. virtual void addNumDisplay(const char* label, float* zone, int precision) = 0;
  86. virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0;
  87. virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0;
  88. virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0;
  89. // -- frames and labels
  90. virtual void openFrameBox(const char* label) = 0;
  91. virtual void openTabBox(const char* label) = 0;
  92. virtual void openHorizontalBox(const char* label) = 0;
  93. virtual void openVerticalBox(const char* label) = 0;
  94. virtual void closeBox() = 0;
  95. virtual void show() = 0;
  96. virtual void run() = 0;
  97. void stop() { fStopped = true; }
  98. bool stopped() { return fStopped; }
  99. virtual void declare(float* zone, const char* key, const char* value) {}
  100. };
  101. struct param {
  102. float* fZone; float fMin; float fMax;
  103. param(float* z, float a, float b) : fZone(z), fMin(a), fMax(b) {}
  104. };
  105. class CMDUI : public UI
  106. {
  107. int fArgc;
  108. char** fArgv;
  109. stack<string> fPrefix;
  110. map<string, param> fKeyParam;
  111. void addOption(const char* label, float* zone, float min, float max)
  112. {
  113. string fullname = fPrefix.top() + label;
  114. fKeyParam.insert(make_pair(fullname, param(zone, min, max)));
  115. }
  116. void openAnyBox(const char* label)
  117. {
  118. string prefix;
  119. if (label && label[0]) {
  120. prefix = fPrefix.top() + "-" + label;
  121. } else {
  122. prefix = fPrefix.top();
  123. }
  124. fPrefix.push(prefix);
  125. }
  126. public:
  127. CMDUI(int argc, char *argv[]) : UI(), fArgc(argc), fArgv(argv) { fPrefix.push("--"); }
  128. virtual ~CMDUI() {}
  129. virtual void addButton(const char* label, float* zone) {};
  130. virtual void addToggleButton(const char* label, float* zone) {};
  131. virtual void addCheckButton(const char* label, float* zone) {};
  132. virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step)
  133. {
  134. addOption(label,zone,min,max);
  135. }
  136. virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step)
  137. {
  138. addOption(label,zone,min,max);
  139. }
  140. virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step)
  141. {
  142. addOption(label,zone,min,max);
  143. }
  144. // -- passive widgets
  145. virtual void addNumDisplay(const char* label, float* zone, int precision) {}
  146. virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {}
  147. virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {}
  148. virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) {}
  149. virtual void openFrameBox(const char* label) { openAnyBox(label); }
  150. virtual void openTabBox(const char* label) { openAnyBox(label); }
  151. virtual void openHorizontalBox(const char* label) { openAnyBox(label); }
  152. virtual void openVerticalBox(const char* label) { openAnyBox(label); }
  153. virtual void closeBox() { fPrefix.pop(); }
  154. virtual void show() {}
  155. virtual void run()
  156. {
  157. char c;
  158. printf("Type 'q' to quit\n");
  159. while ((c = getchar()) != 'q') {
  160. sleep(1);
  161. }
  162. }
  163. void print()
  164. {
  165. map<string, param>::iterator i;
  166. cout << fArgc << "\n";
  167. cout << fArgv[0] << " option list : ";
  168. for (i = fKeyParam.begin(); i != fKeyParam.end(); i++) {
  169. cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax <<" ] ";
  170. }
  171. }
  172. void process_command()
  173. {
  174. map<string, param>::iterator p;
  175. for (int i = 1; i < fArgc; i++) {
  176. if (fArgv[i][0] == '-') {
  177. p = fKeyParam.find(fArgv[i]);
  178. if (p == fKeyParam.end()) {
  179. cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
  180. print();
  181. exit(1);
  182. }
  183. char* end;
  184. *(p->second.fZone) = float(strtod(fArgv[i+1], &end));
  185. i++;
  186. }
  187. }
  188. }
  189. void process_init()
  190. {
  191. map<string, param>::iterator p;
  192. for (int i = 1; i < fArgc; i++) {
  193. if (fArgv[i][0] == '-') {
  194. p = fKeyParam.find(fArgv[i]);
  195. if (p == fKeyParam.end()) {
  196. cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
  197. exit(1);
  198. }
  199. char* end;
  200. *(p->second.fZone) = float(strtod(fArgv[i+1], &end));
  201. i++;
  202. }
  203. }
  204. }
  205. };
  206. //----------------------------------------------------------------
  207. // Signal processor definition
  208. //----------------------------------------------------------------
  209. class dsp {
  210. protected:
  211. int fSamplingFreq;
  212. public:
  213. dsp() {}
  214. virtual ~dsp() {}
  215. virtual int getNumInputs() = 0;
  216. virtual int getNumOutputs() = 0;
  217. virtual void buildUserInterface(UI* interface) = 0;
  218. virtual void init(int samplingRate) = 0;
  219. virtual void compute(int len, float** inputs, float** outputs) = 0;
  220. virtual void conclude() {}
  221. };
  222. //----------------------------------------------------------------------------
  223. // FAUST generated code
  224. //----------------------------------------------------------------------------
  225. class mydsp : public dsp {
  226. private:
  227. float fslider0;
  228. float fRec9[2];
  229. float fslider1;
  230. int IOTA;
  231. float fVec0[2048];
  232. float fRec8[2];
  233. float fRec11[2];
  234. float fVec1[2048];
  235. float fRec10[2];
  236. float fRec13[2];
  237. float fVec2[2048];
  238. float fRec12[2];
  239. float fRec15[2];
  240. float fVec3[2048];
  241. float fRec14[2];
  242. float fRec17[2];
  243. float fVec4[2048];
  244. float fRec16[2];
  245. float fRec19[2];
  246. float fVec5[2048];
  247. float fRec18[2];
  248. float fRec21[2];
  249. float fVec6[2048];
  250. float fRec20[2];
  251. float fRec23[2];
  252. float fVec7[2048];
  253. float fRec22[2];
  254. float fVec8[1024];
  255. float fRec6[2];
  256. float fVec9[512];
  257. float fRec4[2];
  258. float fVec10[512];
  259. float fRec2[2];
  260. float fVec11[256];
  261. float fRec0[2];
  262. float fslider2;
  263. float fRec33[2];
  264. float fVec12[2048];
  265. float fRec32[2];
  266. float fRec35[2];
  267. float fVec13[2048];
  268. float fRec34[2];
  269. float fRec37[2];
  270. float fVec14[2048];
  271. float fRec36[2];
  272. float fRec39[2];
  273. float fVec15[2048];
  274. float fRec38[2];
  275. float fRec41[2];
  276. float fVec16[2048];
  277. float fRec40[2];
  278. float fRec43[2];
  279. float fVec17[2048];
  280. float fRec42[2];
  281. float fRec45[2];
  282. float fVec18[2048];
  283. float fRec44[2];
  284. float fRec47[2];
  285. float fVec19[2048];
  286. float fRec46[2];
  287. float fVec20[1024];
  288. float fRec30[2];
  289. float fVec21[512];
  290. float fRec28[2];
  291. float fVec22[512];
  292. float fRec26[2];
  293. float fVec23[256];
  294. float fRec24[2];
  295. public:
  296. static void metadata(Meta* m) {
  297. m->declare("name", "freeverb");
  298. m->declare("version", "1.0");
  299. m->declare("author", "Grame");
  300. m->declare("license", "BSD");
  301. m->declare("copyright", "(c)GRAME 2006");
  302. }
  303. virtual int getNumInputs() { return 2; }
  304. virtual int getNumOutputs() { return 2; }
  305. static void classInit(int samplingFreq) {
  306. }
  307. virtual void instanceInit(int samplingFreq) {
  308. fSamplingFreq = samplingFreq;
  309. fslider0 = 0.5f;
  310. for (int i=0; i<2; i++) fRec9[i] = 0;
  311. fslider1 = 0.8f;
  312. IOTA = 0;
  313. for (int i=0; i<2048; i++) fVec0[i] = 0;
  314. for (int i=0; i<2; i++) fRec8[i] = 0;
  315. for (int i=0; i<2; i++) fRec11[i] = 0;
  316. for (int i=0; i<2048; i++) fVec1[i] = 0;
  317. for (int i=0; i<2; i++) fRec10[i] = 0;
  318. for (int i=0; i<2; i++) fRec13[i] = 0;
  319. for (int i=0; i<2048; i++) fVec2[i] = 0;
  320. for (int i=0; i<2; i++) fRec12[i] = 0;
  321. for (int i=0; i<2; i++) fRec15[i] = 0;
  322. for (int i=0; i<2048; i++) fVec3[i] = 0;
  323. for (int i=0; i<2; i++) fRec14[i] = 0;
  324. for (int i=0; i<2; i++) fRec17[i] = 0;
  325. for (int i=0; i<2048; i++) fVec4[i] = 0;
  326. for (int i=0; i<2; i++) fRec16[i] = 0;
  327. for (int i=0; i<2; i++) fRec19[i] = 0;
  328. for (int i=0; i<2048; i++) fVec5[i] = 0;
  329. for (int i=0; i<2; i++) fRec18[i] = 0;
  330. for (int i=0; i<2; i++) fRec21[i] = 0;
  331. for (int i=0; i<2048; i++) fVec6[i] = 0;
  332. for (int i=0; i<2; i++) fRec20[i] = 0;
  333. for (int i=0; i<2; i++) fRec23[i] = 0;
  334. for (int i=0; i<2048; i++) fVec7[i] = 0;
  335. for (int i=0; i<2; i++) fRec22[i] = 0;
  336. for (int i=0; i<1024; i++) fVec8[i] = 0;
  337. for (int i=0; i<2; i++) fRec6[i] = 0;
  338. for (int i=0; i<512; i++) fVec9[i] = 0;
  339. for (int i=0; i<2; i++) fRec4[i] = 0;
  340. for (int i=0; i<512; i++) fVec10[i] = 0;
  341. for (int i=0; i<2; i++) fRec2[i] = 0;
  342. for (int i=0; i<256; i++) fVec11[i] = 0;
  343. for (int i=0; i<2; i++) fRec0[i] = 0;
  344. fslider2 = 0.8f;
  345. for (int i=0; i<2; i++) fRec33[i] = 0;
  346. for (int i=0; i<2048; i++) fVec12[i] = 0;
  347. for (int i=0; i<2; i++) fRec32[i] = 0;
  348. for (int i=0; i<2; i++) fRec35[i] = 0;
  349. for (int i=0; i<2048; i++) fVec13[i] = 0;
  350. for (int i=0; i<2; i++) fRec34[i] = 0;
  351. for (int i=0; i<2; i++) fRec37[i] = 0;
  352. for (int i=0; i<2048; i++) fVec14[i] = 0;
  353. for (int i=0; i<2; i++) fRec36[i] = 0;
  354. for (int i=0; i<2; i++) fRec39[i] = 0;
  355. for (int i=0; i<2048; i++) fVec15[i] = 0;
  356. for (int i=0; i<2; i++) fRec38[i] = 0;
  357. for (int i=0; i<2; i++) fRec41[i] = 0;
  358. for (int i=0; i<2048; i++) fVec16[i] = 0;
  359. for (int i=0; i<2; i++) fRec40[i] = 0;
  360. for (int i=0; i<2; i++) fRec43[i] = 0;
  361. for (int i=0; i<2048; i++) fVec17[i] = 0;
  362. for (int i=0; i<2; i++) fRec42[i] = 0;
  363. for (int i=0; i<2; i++) fRec45[i] = 0;
  364. for (int i=0; i<2048; i++) fVec18[i] = 0;
  365. for (int i=0; i<2; i++) fRec44[i] = 0;
  366. for (int i=0; i<2; i++) fRec47[i] = 0;
  367. for (int i=0; i<2048; i++) fVec19[i] = 0;
  368. for (int i=0; i<2; i++) fRec46[i] = 0;
  369. for (int i=0; i<1024; i++) fVec20[i] = 0;
  370. for (int i=0; i<2; i++) fRec30[i] = 0;
  371. for (int i=0; i<512; i++) fVec21[i] = 0;
  372. for (int i=0; i<2; i++) fRec28[i] = 0;
  373. for (int i=0; i<512; i++) fVec22[i] = 0;
  374. for (int i=0; i<2; i++) fRec26[i] = 0;
  375. for (int i=0; i<256; i++) fVec23[i] = 0;
  376. for (int i=0; i<2; i++) fRec24[i] = 0;
  377. }
  378. virtual void init(int samplingFreq) {
  379. classInit(samplingFreq);
  380. instanceInit(samplingFreq);
  381. }
  382. virtual void buildUserInterface(UI* interface) {
  383. interface->openVerticalBox("Freeverb");
  384. interface->addHorizontalSlider("Damp", &fslider0, 0.5f, 0.0f, 1.0f, 2.500000e-02f);
  385. interface->addHorizontalSlider("RoomSize", &fslider1, 0.8f, 0.0f, 1.0f, 2.500000e-02f);
  386. interface->addHorizontalSlider("Wet", &fslider2, 0.8f, 0.0f, 1.0f, 2.500000e-02f);
  387. interface->closeBox();
  388. }
  389. virtual void compute (int count, float** input, float** output) {
  390. float fSlow0 = (0.4f * fslider0);
  391. float fSlow1 = (1 - fSlow0);
  392. float fSlow2 = (0.7f + (0.28f * fslider1));
  393. float fSlow3 = fslider2;
  394. float fSlow4 = (1 - fSlow3);
  395. float* input0 = input[0];
  396. float* input1 = input[1];
  397. float* output0 = output[0];
  398. float* output1 = output[1];
  399. for (int i=0; i<count; i++) {
  400. fRec9[0] = ((fSlow1 * fRec8[1]) + (fSlow0 * fRec9[1]));
  401. float fTemp0 = input1[i];
  402. float fTemp1 = input0[i];
  403. float fTemp2 = (1.500000e-02f * (fTemp1 + fTemp0));
  404. fVec0[IOTA&2047] = (fTemp2 + (fSlow2 * fRec9[0]));
  405. fRec8[0] = fVec0[(IOTA-1617)&2047];
  406. fRec11[0] = ((fSlow1 * fRec10[1]) + (fSlow0 * fRec11[1]));
  407. fVec1[IOTA&2047] = (fTemp2 + (fSlow2 * fRec11[0]));
  408. fRec10[0] = fVec1[(IOTA-1557)&2047];
  409. fRec13[0] = ((fSlow1 * fRec12[1]) + (fSlow0 * fRec13[1]));
  410. fVec2[IOTA&2047] = (fTemp2 + (fSlow2 * fRec13[0]));
  411. fRec12[0] = fVec2[(IOTA-1491)&2047];
  412. fRec15[0] = ((fSlow1 * fRec14[1]) + (fSlow0 * fRec15[1]));
  413. fVec3[IOTA&2047] = (fTemp2 + (fSlow2 * fRec15[0]));
  414. fRec14[0] = fVec3[(IOTA-1422)&2047];
  415. fRec17[0] = ((fSlow1 * fRec16[1]) + (fSlow0 * fRec17[1]));
  416. fVec4[IOTA&2047] = (fTemp2 + (fSlow2 * fRec17[0]));
  417. fRec16[0] = fVec4[(IOTA-1356)&2047];
  418. fRec19[0] = ((fSlow1 * fRec18[1]) + (fSlow0 * fRec19[1]));
  419. fVec5[IOTA&2047] = (fTemp2 + (fSlow2 * fRec19[0]));
  420. fRec18[0] = fVec5[(IOTA-1277)&2047];
  421. fRec21[0] = ((fSlow1 * fRec20[1]) + (fSlow0 * fRec21[1]));
  422. fVec6[IOTA&2047] = (fTemp2 + (fSlow2 * fRec21[0]));
  423. fRec20[0] = fVec6[(IOTA-1188)&2047];
  424. fRec23[0] = ((fSlow1 * fRec22[1]) + (fSlow0 * fRec23[1]));
  425. fVec7[IOTA&2047] = (fTemp2 + (fSlow2 * fRec23[0]));
  426. fRec22[0] = fVec7[(IOTA-1116)&2047];
  427. float fTemp3 = (((((((fRec22[0] + fRec20[0]) + fRec18[0]) + fRec16[0]) + fRec14[0]) + fRec12[0]) + fRec10[0]) + fRec8[0]);
  428. fVec8[IOTA&1023] = (fTemp3 + (0.5f * fRec6[1]));
  429. fRec6[0] = fVec8[(IOTA-556)&1023];
  430. float fRec7 = (0 - (fTemp3 - fRec6[1]));
  431. fVec9[IOTA&511] = (fRec7 + (0.5f * fRec4[1]));
  432. fRec4[0] = fVec9[(IOTA-441)&511];
  433. float fRec5 = (fRec4[1] - fRec7);
  434. fVec10[IOTA&511] = (fRec5 + (0.5f * fRec2[1]));
  435. fRec2[0] = fVec10[(IOTA-341)&511];
  436. float fRec3 = (fRec2[1] - fRec5);
  437. fVec11[IOTA&255] = (fRec3 + (0.5f * fRec0[1]));
  438. fRec0[0] = fVec11[(IOTA-225)&255];
  439. float fRec1 = (fRec0[1] - fRec3);
  440. output0[i] = ((fSlow4 * fTemp1) + (fSlow3 * fRec1));
  441. fRec33[0] = ((fSlow1 * fRec32[1]) + (fSlow0 * fRec33[1]));
  442. fVec12[IOTA&2047] = (fTemp2 + (fSlow2 * fRec33[0]));
  443. fRec32[0] = fVec12[(IOTA-1640)&2047];
  444. fRec35[0] = ((fSlow1 * fRec34[1]) + (fSlow0 * fRec35[1]));
  445. fVec13[IOTA&2047] = (fTemp2 + (fSlow2 * fRec35[0]));
  446. fRec34[0] = fVec13[(IOTA-1580)&2047];
  447. fRec37[0] = ((fSlow1 * fRec36[1]) + (fSlow0 * fRec37[1]));
  448. fVec14[IOTA&2047] = (fTemp2 + (fSlow2 * fRec37[0]));
  449. fRec36[0] = fVec14[(IOTA-1514)&2047];
  450. fRec39[0] = ((fSlow1 * fRec38[1]) + (fSlow0 * fRec39[1]));
  451. fVec15[IOTA&2047] = (fTemp2 + (fSlow2 * fRec39[0]));
  452. fRec38[0] = fVec15[(IOTA-1445)&2047];
  453. fRec41[0] = ((fSlow1 * fRec40[1]) + (fSlow0 * fRec41[1]));
  454. fVec16[IOTA&2047] = (fTemp2 + (fSlow2 * fRec41[0]));
  455. fRec40[0] = fVec16[(IOTA-1379)&2047];
  456. fRec43[0] = ((fSlow1 * fRec42[1]) + (fSlow0 * fRec43[1]));
  457. fVec17[IOTA&2047] = (fTemp2 + (fSlow2 * fRec43[0]));
  458. fRec42[0] = fVec17[(IOTA-1300)&2047];
  459. fRec45[0] = ((fSlow1 * fRec44[1]) + (fSlow0 * fRec45[1]));
  460. fVec18[IOTA&2047] = (fTemp2 + (fSlow2 * fRec45[0]));
  461. fRec44[0] = fVec18[(IOTA-1211)&2047];
  462. fRec47[0] = ((fSlow1 * fRec46[1]) + (fSlow0 * fRec47[1]));
  463. fVec19[IOTA&2047] = (fTemp2 + (fSlow2 * fRec47[0]));
  464. fRec46[0] = fVec19[(IOTA-1139)&2047];
  465. float fTemp4 = (((((((fRec46[0] + fRec44[0]) + fRec42[0]) + fRec40[0]) + fRec38[0]) + fRec36[0]) + fRec34[0]) + fRec32[0]);
  466. fVec20[IOTA&1023] = (fTemp4 + (0.5f * fRec30[1]));
  467. fRec30[0] = fVec20[(IOTA-579)&1023];
  468. float fRec31 = (0 - (fTemp4 - fRec30[1]));
  469. fVec21[IOTA&511] = (fRec31 + (0.5f * fRec28[1]));
  470. fRec28[0] = fVec21[(IOTA-464)&511];
  471. float fRec29 = (fRec28[1] - fRec31);
  472. fVec22[IOTA&511] = (fRec29 + (0.5f * fRec26[1]));
  473. fRec26[0] = fVec22[(IOTA-364)&511];
  474. float fRec27 = (fRec26[1] - fRec29);
  475. fVec23[IOTA&255] = (fRec27 + (0.5f * fRec24[1]));
  476. fRec24[0] = fVec23[(IOTA-248)&255];
  477. float fRec25 = (fRec24[1] - fRec27);
  478. output1[i] = ((fSlow4 * fTemp0) + (fSlow3 * fRec25));
  479. // post processing
  480. fRec24[1] = fRec24[0];
  481. fRec26[1] = fRec26[0];
  482. fRec28[1] = fRec28[0];
  483. fRec30[1] = fRec30[0];
  484. fRec46[1] = fRec46[0];
  485. fRec47[1] = fRec47[0];
  486. fRec44[1] = fRec44[0];
  487. fRec45[1] = fRec45[0];
  488. fRec42[1] = fRec42[0];
  489. fRec43[1] = fRec43[0];
  490. fRec40[1] = fRec40[0];
  491. fRec41[1] = fRec41[0];
  492. fRec38[1] = fRec38[0];
  493. fRec39[1] = fRec39[0];
  494. fRec36[1] = fRec36[0];
  495. fRec37[1] = fRec37[0];
  496. fRec34[1] = fRec34[0];
  497. fRec35[1] = fRec35[0];
  498. fRec32[1] = fRec32[0];
  499. fRec33[1] = fRec33[0];
  500. fRec0[1] = fRec0[0];
  501. fRec2[1] = fRec2[0];
  502. fRec4[1] = fRec4[0];
  503. fRec6[1] = fRec6[0];
  504. fRec22[1] = fRec22[0];
  505. fRec23[1] = fRec23[0];
  506. fRec20[1] = fRec20[0];
  507. fRec21[1] = fRec21[0];
  508. fRec18[1] = fRec18[0];
  509. fRec19[1] = fRec19[0];
  510. fRec16[1] = fRec16[0];
  511. fRec17[1] = fRec17[0];
  512. fRec14[1] = fRec14[0];
  513. fRec15[1] = fRec15[0];
  514. fRec12[1] = fRec12[0];
  515. fRec13[1] = fRec13[0];
  516. fRec10[1] = fRec10[0];
  517. fRec11[1] = fRec11[0];
  518. fRec8[1] = fRec8[0];
  519. IOTA = IOTA+1;
  520. fRec9[1] = fRec9[0];
  521. }
  522. }
  523. };
  524. mydsp DSP;
  525. /******************************************************************************
  526. *******************************************************************************
  527. NETJACK AUDIO INTERFACE
  528. *******************************************************************************
  529. *******************************************************************************/
  530. //----------------------------------------------------------------------------
  531. // number of input and output channels
  532. //----------------------------------------------------------------------------
  533. int gNumInChans;
  534. int gNumOutChans;
  535. //----------------------------------------------------------------------------
  536. // Jack Callbacks
  537. //----------------------------------------------------------------------------
  538. static void net_shutdown(void *)
  539. {
  540. exit(1);
  541. }
  542. #ifdef BENCHMARKMODE
  543. // measuring jack performances
  544. static __inline__ unsigned long long int rdtsc(void)
  545. {
  546. unsigned long long int x;
  547. __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
  548. return x;
  549. }
  550. #define KSKIP 10
  551. #define KMESURE 1024
  552. int mesure = 0;
  553. unsigned long long int starts[KMESURE];
  554. unsigned long long int stops [KMESURE];
  555. #define STARTMESURE starts[mesure%KMESURE] = rdtsc();
  556. #define STOPMESURE stops[mesure%KMESURE] = rdtsc(); mesure = mesure+1;
  557. void printstats()
  558. {
  559. unsigned long long int low, hi, tot;
  560. low = hi = tot = (stops[KSKIP] - starts[KSKIP]);
  561. if (mesure < KMESURE) {
  562. for (int i = KSKIP+1; i<mesure; i++) {
  563. unsigned long long int m = stops[i] - starts[i];
  564. if (m<low) low = m;
  565. if (m>hi) hi = m;
  566. tot += m;
  567. }
  568. cout << low << ' ' << tot/(mesure-KSKIP) << ' ' << hi << endl;
  569. } else {
  570. for (int i = KSKIP+1; i<KMESURE; i++) {
  571. unsigned long long int m = stops[i] - starts[i];
  572. if (m<low) low = m;
  573. if (m>hi) hi = m;
  574. tot += m;
  575. }
  576. cout << low << ' ' << tot/(KMESURE-KSKIP) << ' ' << hi << endl;
  577. }
  578. }
  579. #else
  580. #define STARTMESURE
  581. #define STOPMESURE
  582. #endif
  583. static int net_process(jack_nframes_t buffer_size,
  584. int audio_input,
  585. float** audio_input_buffer,
  586. int midi_input,
  587. void** midi_input_buffer,
  588. int audio_output,
  589. float** audio_output_buffer,
  590. int midi_output,
  591. void** midi_output_buffer,
  592. void* data)
  593. {
  594. AVOIDDENORMALS;
  595. STARTMESURE
  596. DSP.compute(buffer_size, audio_input_buffer, audio_output_buffer);
  597. STOPMESURE
  598. return 0;
  599. }
  600. /******************************************************************************
  601. *******************************************************************************
  602. MAIN PLAY THREAD
  603. *******************************************************************************
  604. *******************************************************************************/
  605. //-------------------------------------------------------------------------
  606. // MAIN
  607. //-------------------------------------------------------------------------
  608. #define TEST_MASTER "194.5.49.5"
  609. int main(int argc, char *argv[]) {
  610. UI* interface = new CMDUI(argc, argv);
  611. jack_net_slave_t* net;
  612. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  613. //Jack::JackAudioQueueAdapter audio(2, 2, 1024, 44100, NULL);
  614. gNumInChans = DSP.getNumInputs();
  615. gNumOutChans = DSP.getNumOutputs();
  616. jack_slave_t request = { gNumInChans, gNumOutChans, 0, 0, DEFAULT_MTU, -1, 2 };
  617. jack_master_t result;
  618. printf("Network\n");
  619. //if (audio.Open() < 0) {
  620. // fprintf(stderr, "Cannot open audio\n");
  621. // return 1;
  622. //}
  623. //audio.Start();
  624. // Hang around forever...
  625. //while(1) CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.25, false);
  626. if ((net = jack_net_slave_open(TEST_MASTER, DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
  627. fprintf(stderr, "jack remote server not running ?\n");
  628. return 1;
  629. }
  630. jack_set_net_slave_process_callback(net, net_process, NULL);
  631. // We want to restart (that is "wait for available master" again)
  632. //jack_set_net_shutdown_callback(net, net_shutdown, 0);
  633. DSP.init(result.sample_rate);
  634. DSP.buildUserInterface(interface);
  635. if (jack_net_slave_activate(net) != 0) {
  636. fprintf(stderr, "cannot activate net");
  637. return 1;
  638. }
  639. int retVal = UIApplicationMain(argc, argv, nil, nil);
  640. [pool release];
  641. // Wait for application end
  642. jack_net_slave_deactivate(net);
  643. jack_net_slave_close(net);
  644. //if (audio.Close() < 0) {
  645. // fprintf(stderr, "Cannot close audio\n");
  646. //}
  647. return retVal;
  648. }