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.

905 lines
28KB

  1. /*
  2. Copyright (C) 2008 Grame
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. /* link with */
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <limits.h>
  20. #include <math.h>
  21. #include <errno.h>
  22. #include <time.h>
  23. #include <vector>
  24. #include <stack>
  25. #include <string>
  26. #include <map>
  27. #include <iostream>
  28. #include <jack/jack.h>
  29. #include <windows.h>
  30. // g++ -O3 -lm -lsndfile myfx.cpp
  31. using namespace std;
  32. #define max(x,y) (((x)>(y)) ? (x) : (y))
  33. #define min(x,y) (((x)<(y)) ? (x) : (y))
  34. // abs is now predefined
  35. //template<typename T> T abs (T a) { return (a<T(0)) ? -a : a; }
  36. inline int lsr (int x, int n)
  37. {
  38. return int(((unsigned int)x) >> n);
  39. }
  40. /******************************************************************************
  41. *******************************************************************************
  42. VECTOR INTRINSICS
  43. *******************************************************************************
  44. *******************************************************************************/
  45. inline void *aligned_calloc(size_t nmemb, size_t size)
  46. {
  47. return (void*)((unsigned)(calloc((nmemb*size) + 15, sizeof(char))) + 15 & 0xfffffff0);
  48. }
  49. /******************************************************************************
  50. *******************************************************************************
  51. USER INTERFACE
  52. *******************************************************************************
  53. *******************************************************************************/
  54. class UI
  55. {
  56. bool fStopped;
  57. public:
  58. UI() : fStopped(false)
  59. {}
  60. virtual ~UI()
  61. {}
  62. // -- active widgets
  63. virtual void addButton(char* label, float* zone) = 0;
  64. virtual void addToggleButton(char* label, float* zone) = 0;
  65. virtual void addCheckButton(char* label, float* zone) = 0;
  66. virtual void addVerticalSlider(char* label, float* zone, float init, float min, float max, float step) = 0;
  67. virtual void addHorizontalSlider(char* label, float* zone, float init, float min, float max, float step) = 0;
  68. virtual void addNumEntry(char* label, float* zone, float init, float min, float max, float step) = 0;
  69. // -- passive widgets
  70. virtual void addNumDisplay(char* label, float* zone, int precision) = 0;
  71. virtual void addTextDisplay(char* label, float* zone, char* names[], float min, float max) = 0;
  72. virtual void addHorizontalBargraph(char* label, float* zone, float min, float max) = 0;
  73. virtual void addVerticalBargraph(char* label, float* zone, float min, float max) = 0;
  74. // -- frames and labels
  75. virtual void openFrameBox(char* label) = 0;
  76. virtual void openTabBox(char* label) = 0;
  77. virtual void openHorizontalBox(char* label) = 0;
  78. virtual void openVerticalBox(char* label) = 0;
  79. virtual void closeBox() = 0;
  80. virtual void show() = 0;
  81. virtual void run() = 0;
  82. void stop()
  83. {
  84. fStopped = true;
  85. }
  86. bool stopped()
  87. {
  88. return fStopped;
  89. }
  90. };
  91. struct param
  92. {
  93. float* fZone;
  94. float fMin;
  95. float fMax;
  96. param(float* z, float a, float b) : fZone(z), fMin(a), fMax(b)
  97. {}
  98. };
  99. class CMDUI : public UI
  100. {
  101. int fArgc;
  102. char** fArgv;
  103. stack<string> fPrefix;
  104. map<string, param> fKeyParam;
  105. void addOption(char* label, float* zone, float min, float max)
  106. {
  107. string fullname = fPrefix.top() + label;
  108. fKeyParam.insert(make_pair(fullname, param(zone, min, max)));
  109. }
  110. void openAnyBox(char* label)
  111. {
  112. string prefix;
  113. if (label && label[0]) {
  114. prefix = fPrefix.top() + "-" + label;
  115. } else {
  116. prefix = fPrefix.top();
  117. }
  118. fPrefix.push(prefix);
  119. }
  120. public:
  121. CMDUI(int argc, char *argv[]) : UI(), fArgc(argc), fArgv(argv)
  122. {
  123. fPrefix.push("--");
  124. }
  125. virtual ~CMDUI()
  126. {}
  127. virtual void addButton(char* label, float* zone)
  128. {}
  129. ;
  130. virtual void addToggleButton(char* label, float* zone)
  131. {}
  132. ;
  133. virtual void addCheckButton(char* label, float* zone)
  134. {}
  135. ;
  136. virtual void addVerticalSlider(char* label, float* zone, float init, float min, float max, float step)
  137. {
  138. addOption(label, zone, min, max);
  139. }
  140. virtual void addHorizontalSlider(char* label, float* zone, float init, float min, float max, float step)
  141. {
  142. addOption(label, zone, min, max);
  143. }
  144. virtual void addNumEntry(char* label, float* zone, float init, float min, float max, float step)
  145. {
  146. addOption(label, zone, min, max);
  147. }
  148. // -- passive widgets
  149. virtual void addNumDisplay(char* label, float* zone, int precision)
  150. {}
  151. virtual void addTextDisplay(char* label, float* zone, char* names[], float min, float max)
  152. {}
  153. virtual void addHorizontalBargraph(char* label, float* zone, float min, float max)
  154. {}
  155. virtual void addVerticalBargraph(char* label, float* zone, float min, float max)
  156. {}
  157. virtual void openFrameBox(char* label)
  158. {
  159. openAnyBox(label);
  160. }
  161. virtual void openTabBox(char* label)
  162. {
  163. openAnyBox(label);
  164. }
  165. virtual void openHorizontalBox(char* label)
  166. {
  167. openAnyBox(label);
  168. }
  169. virtual void openVerticalBox(char* label)
  170. {
  171. openAnyBox(label);
  172. }
  173. virtual void closeBox()
  174. {
  175. fPrefix.pop();
  176. }
  177. virtual void show()
  178. {}
  179. virtual void run()
  180. {
  181. char c;
  182. printf("Type 'q' to quit\n");
  183. while ((c = getchar()) != 'q') {
  184. //sleep(1);
  185. Sleep(1000);
  186. }
  187. }
  188. void print()
  189. {
  190. map<string, param>::iterator i;
  191. cout << fArgc << "\n";
  192. cout << fArgv[0] << " option list : ";
  193. for (i = fKeyParam.begin(); i != fKeyParam.end(); i++) {
  194. cout << "[ " << i->first << " " << i->second.fMin << ".." << i->second.fMax << " ] ";
  195. }
  196. //cout << " infile outfile\n";
  197. }
  198. void process_command()
  199. {
  200. map<string, param>::iterator p;
  201. for (int i = 1; i < fArgc; i++) {
  202. if (fArgv[i][0] == '-') {
  203. p = fKeyParam.find(fArgv[i]);
  204. if (p == fKeyParam.end()) {
  205. cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
  206. print();
  207. exit(1);
  208. }
  209. char* end;
  210. *(p->second.fZone) = float(strtod(fArgv[i + 1], &end));
  211. i++;
  212. }
  213. }
  214. }
  215. void process_init()
  216. {
  217. map<string, param>::iterator p;
  218. for (int i = 1; i < fArgc; i++) {
  219. if (fArgv[i][0] == '-') {
  220. p = fKeyParam.find(fArgv[i]);
  221. if (p == fKeyParam.end()) {
  222. cout << fArgv[0] << " : unrecognized option " << fArgv[i] << "\n";
  223. exit(1);
  224. }
  225. char* end;
  226. *(p->second.fZone) = float(strtod(fArgv[i + 1], &end));
  227. i++;
  228. }
  229. }
  230. }
  231. };
  232. //----------------------------------------------------------------
  233. // d�inition du processeur de signal
  234. //----------------------------------------------------------------
  235. class dsp
  236. {
  237. protected:
  238. int fSamplingFreq;
  239. public:
  240. dsp()
  241. {}
  242. virtual ~dsp()
  243. {}
  244. virtual int getNumInputs() = 0;
  245. virtual int getNumOutputs() = 0;
  246. virtual void buildUserInterface(UI* interface) = 0;
  247. virtual void init(int samplingRate) = 0;
  248. virtual void compute(int len, float** inputs, float** outputs) = 0;
  249. virtual void conclude()
  250. {}
  251. };
  252. //----------------------------------------------------------------------------
  253. // FAUST generated code
  254. //----------------------------------------------------------------------------
  255. class mydsp : public dsp
  256. {
  257. private:
  258. float fslider0;
  259. float R0_0;
  260. int iota0;
  261. float dline0[225];
  262. float R1_0;
  263. int iota1;
  264. float dline1[341];
  265. float R2_0;
  266. int iota2;
  267. float dline2[441];
  268. float R3_0;
  269. int iota3;
  270. float dline3[556];
  271. float R4_0;
  272. int iota4;
  273. float dline4[1617];
  274. float fslider1;
  275. float R5_0;
  276. float fslider2;
  277. float R6_0;
  278. int iota5;
  279. float dline5[1557];
  280. float R7_0;
  281. float R8_0;
  282. int iota6;
  283. float dline6[1491];
  284. float R9_0;
  285. float R10_0;
  286. int iota7;
  287. float dline7[1422];
  288. float R11_0;
  289. float R12_0;
  290. int iota8;
  291. float dline8[1277];
  292. float R13_0;
  293. float R14_0;
  294. int iota9;
  295. float dline9[1116];
  296. float R15_0;
  297. float R16_0;
  298. int iota10;
  299. float dline10[1188];
  300. float R17_0;
  301. float R18_0;
  302. int iota11;
  303. float dline11[1356];
  304. float R19_0;
  305. float R3_1;
  306. float R2_1;
  307. float R1_1;
  308. float R0_1;
  309. float R20_0;
  310. int iota12;
  311. float dline12[248];
  312. float R21_0;
  313. int iota13;
  314. float dline13[364];
  315. float R22_0;
  316. int iota14;
  317. float dline14[464];
  318. float R23_0;
  319. int iota15;
  320. float dline15[579];
  321. float R24_0;
  322. int iota16;
  323. float dline16[1640];
  324. float R25_0;
  325. float R26_0;
  326. int iota17;
  327. float dline17[1580];
  328. float R27_0;
  329. float R28_0;
  330. int iota18;
  331. float dline18[1514];
  332. float R29_0;
  333. float R30_0;
  334. int iota19;
  335. float dline19[1445];
  336. float R31_0;
  337. float R32_0;
  338. int iota20;
  339. float dline20[1300];
  340. float R33_0;
  341. float R34_0;
  342. int iota21;
  343. float dline21[1139];
  344. float R35_0;
  345. float R36_0;
  346. int iota22;
  347. float dline22[1211];
  348. float R37_0;
  349. float R38_0;
  350. int iota23;
  351. float dline23[1379];
  352. float R39_0;
  353. float R23_1;
  354. float R22_1;
  355. float R21_1;
  356. float R20_1;
  357. public:
  358. virtual int getNumInputs()
  359. {
  360. return 2;
  361. }
  362. virtual int getNumOutputs()
  363. {
  364. return 2;
  365. }
  366. virtual void init(int samplingFreq)
  367. {
  368. int i;
  369. fSamplingFreq = samplingFreq;
  370. fslider0 = 0.333300f;
  371. R0_0 = 0.0;
  372. iota0 = 0;
  373. for (i = 0; i < 225; i++)
  374. dline0[i] = 0.0;
  375. R1_0 = 0.0;
  376. iota1 = 0;
  377. for (i = 0; i < 341; i++)
  378. dline1[i] = 0.0;
  379. R2_0 = 0.0;
  380. iota2 = 0;
  381. for (i = 0; i < 441; i++)
  382. dline2[i] = 0.0;
  383. R3_0 = 0.0;
  384. iota3 = 0;
  385. for (i = 0; i < 556; i++)
  386. dline3[i] = 0.0;
  387. R4_0 = 0.0;
  388. iota4 = 0;
  389. for (i = 0; i < 1617; i++)
  390. dline4[i] = 0.0;
  391. fslider1 = 0.9500000f;
  392. R5_0 = 0.0;
  393. fslider2 = 0.9500000f;
  394. R6_0 = 0.0;
  395. iota5 = 0;
  396. for (i = 0; i < 1557; i++)
  397. dline5[i] = 0.0;
  398. R7_0 = 0.0;
  399. R8_0 = 0.0;
  400. iota6 = 0;
  401. for (i = 0; i < 1491; i++)
  402. dline6[i] = 0.0;
  403. R9_0 = 0.0;
  404. R10_0 = 0.0;
  405. iota7 = 0;
  406. for (i = 0; i < 1422; i++)
  407. dline7[i] = 0.0;
  408. R11_0 = 0.0;
  409. R12_0 = 0.0;
  410. iota8 = 0;
  411. for (i = 0; i < 1277; i++)
  412. dline8[i] = 0.0;
  413. R13_0 = 0.0;
  414. R14_0 = 0.0;
  415. iota9 = 0;
  416. for (i = 0; i < 1116; i++)
  417. dline9[i] = 0.0;
  418. R15_0 = 0.0;
  419. R16_0 = 0.0;
  420. iota10 = 0;
  421. for (i = 0; i < 1188; i++)
  422. dline10[i] = 0.0;
  423. R17_0 = 0.0;
  424. R18_0 = 0.0;
  425. iota11 = 0;
  426. for (i = 0; i < 1356; i++)
  427. dline11[i] = 0.0;
  428. R19_0 = 0.0;
  429. R3_1 = 0.0;
  430. R2_1 = 0.0;
  431. R1_1 = 0.0;
  432. R0_1 = 0.0;
  433. R20_0 = 0.0;
  434. iota12 = 0;
  435. for (i = 0; i < 248; i++)
  436. dline12[i] = 0.0;
  437. R21_0 = 0.0;
  438. iota13 = 0;
  439. for (i = 0; i < 364; i++)
  440. dline13[i] = 0.0;
  441. R22_0 = 0.0;
  442. iota14 = 0;
  443. for (i = 0; i < 464; i++)
  444. dline14[i] = 0.0;
  445. R23_0 = 0.0;
  446. iota15 = 0;
  447. for (i = 0; i < 579; i++)
  448. dline15[i] = 0.0;
  449. R24_0 = 0.0;
  450. iota16 = 0;
  451. for (i = 0; i < 1640; i++)
  452. dline16[i] = 0.0;
  453. R25_0 = 0.0;
  454. R26_0 = 0.0;
  455. iota17 = 0;
  456. for (i = 0; i < 1580; i++)
  457. dline17[i] = 0.0;
  458. R27_0 = 0.0;
  459. R28_0 = 0.0;
  460. iota18 = 0;
  461. for (i = 0; i < 1514; i++)
  462. dline18[i] = 0.0;
  463. R29_0 = 0.0;
  464. R30_0 = 0.0;
  465. iota19 = 0;
  466. for (i = 0; i < 1445; i++)
  467. dline19[i] = 0.0;
  468. R31_0 = 0.0;
  469. R32_0 = 0.0;
  470. iota20 = 0;
  471. for (i = 0; i < 1300; i++)
  472. dline20[i] = 0.0;
  473. R33_0 = 0.0;
  474. R34_0 = 0.0;
  475. iota21 = 0;
  476. for (i = 0; i < 1139; i++)
  477. dline21[i] = 0.0;
  478. R35_0 = 0.0;
  479. R36_0 = 0.0;
  480. iota22 = 0;
  481. for (i = 0; i < 1211; i++)
  482. dline22[i] = 0.0;
  483. R37_0 = 0.0;
  484. R38_0 = 0.0;
  485. iota23 = 0;
  486. for (i = 0; i < 1379; i++)
  487. dline23[i] = 0.0;
  488. R39_0 = 0.0;
  489. R23_1 = 0.0;
  490. R22_1 = 0.0;
  491. R21_1 = 0.0;
  492. R20_1 = 0.0;
  493. }
  494. virtual void buildUserInterface(UI* inter)
  495. {
  496. inter->openVerticalBox("Freeverb");
  497. inter->addHorizontalSlider("Damp", &fslider2, 0.500000f, 0.000000f, 1.000000f, 2.500000e-02f);
  498. inter->addHorizontalSlider("RoomSize", &fslider1, 0.500000f, 0.000000f, 1.000000f, 2.500000e-02f);
  499. inter->addHorizontalSlider("Wet", &fslider0, 0.333300f, 0.000000f, 1.000000f, 2.500000e-02f);
  500. inter->closeBox();
  501. }
  502. virtual void compute (int count, float** input, float** output)
  503. {
  504. float* input0;
  505. input0 = input[0];
  506. float* input1;
  507. input1 = input[1];
  508. float* output0;
  509. output0 = output[0];
  510. float* output1;
  511. output1 = output[1];
  512. float ftemp0 = fslider0;
  513. float ftemp1 = (1 - ftemp0);
  514. float ftemp5 = (0.700000f + (0.280000f * fslider1));
  515. float ftemp6 = (0.400000f * fslider2);
  516. float ftemp7 = (1 - ftemp6);
  517. for (int i = 0; i < count; i++) {
  518. float ftemp2 = input0[i];
  519. if (++iota0 == 225)
  520. iota0 = 0;
  521. float T0 = dline0[iota0];
  522. if (++iota1 == 341)
  523. iota1 = 0;
  524. float T1 = dline1[iota1];
  525. if (++iota2 == 441)
  526. iota2 = 0;
  527. float T2 = dline2[iota2];
  528. if (++iota3 == 556)
  529. iota3 = 0;
  530. float T3 = dline3[iota3];
  531. if (++iota4 == 1617)
  532. iota4 = 0;
  533. float T4 = dline4[iota4];
  534. float ftemp3 = input1[i];
  535. float ftemp4 = (1.500000e-02f * (ftemp2 + ftemp3));
  536. R5_0 = ((ftemp7 * R4_0) + (ftemp6 * R5_0));
  537. dline4[iota4] = (ftemp4 + (ftemp5 * R5_0));
  538. R4_0 = T4;
  539. if (++iota5 == 1557)
  540. iota5 = 0;
  541. float T5 = dline5[iota5];
  542. R7_0 = ((ftemp7 * R6_0) + (ftemp6 * R7_0));
  543. dline5[iota5] = (ftemp4 + (ftemp5 * R7_0));
  544. R6_0 = T5;
  545. if (++iota6 == 1491)
  546. iota6 = 0;
  547. float T6 = dline6[iota6];
  548. R9_0 = ((ftemp7 * R8_0) + (ftemp6 * R9_0));
  549. dline6[iota6] = (ftemp4 + (ftemp5 * R9_0));
  550. R8_0 = T6;
  551. if (++iota7 == 1422)
  552. iota7 = 0;
  553. float T7 = dline7[iota7];
  554. R11_0 = ((ftemp7 * R10_0) + (ftemp6 * R11_0));
  555. dline7[iota7] = (ftemp4 + (ftemp5 * R11_0));
  556. R10_0 = T7;
  557. if (++iota8 == 1277)
  558. iota8 = 0;
  559. float T8 = dline8[iota8];
  560. R13_0 = ((ftemp7 * R12_0) + (ftemp6 * R13_0));
  561. dline8[iota8] = (ftemp4 + (ftemp5 * R13_0));
  562. R12_0 = T8;
  563. if (++iota9 == 1116)
  564. iota9 = 0;
  565. float T9 = dline9[iota9];
  566. R15_0 = ((ftemp7 * R14_0) + (ftemp6 * R15_0));
  567. dline9[iota9] = (ftemp4 + (ftemp5 * R15_0));
  568. R14_0 = T9;
  569. if (++iota10 == 1188)
  570. iota10 = 0;
  571. float T10 = dline10[iota10];
  572. R17_0 = ((ftemp7 * R16_0) + (ftemp6 * R17_0));
  573. dline10[iota10] = (ftemp4 + (ftemp5 * R17_0));
  574. R16_0 = T10;
  575. if (++iota11 == 1356)
  576. iota11 = 0;
  577. float T11 = dline11[iota11];
  578. R19_0 = ((ftemp7 * R18_0) + (ftemp6 * R19_0));
  579. dline11[iota11] = (ftemp4 + (ftemp5 * R19_0));
  580. R18_0 = T11;
  581. float ftemp8 = (R16_0 + R18_0);
  582. dline3[iota3] = ((((0.500000f * R3_0) + R4_0) + (R6_0 + R8_0)) + ((R10_0 + R12_0) + (R14_0 + ftemp8)));
  583. float R3temp0 = T3;
  584. float R3temp1 = (R3_0 - (((R4_0 + R6_0) + (R8_0 + R10_0)) + ((R12_0 + R14_0) + ftemp8)));
  585. R3_0 = R3temp0;
  586. R3_1 = R3temp1;
  587. dline2[iota2] = ((0.500000f * R2_0) + R3_1);
  588. float R2temp0 = T2;
  589. float R2temp1 = (R2_0 - R3_1);
  590. R2_0 = R2temp0;
  591. R2_1 = R2temp1;
  592. dline1[iota1] = ((0.500000f * R1_0) + R2_1);
  593. float R1temp0 = T1;
  594. float R1temp1 = (R1_0 - R2_1);
  595. R1_0 = R1temp0;
  596. R1_1 = R1temp1;
  597. dline0[iota0] = ((0.500000f * R0_0) + R1_1);
  598. float R0temp0 = T0;
  599. float R0temp1 = (R0_0 - R1_1);
  600. R0_0 = R0temp0;
  601. R0_1 = R0temp1;
  602. output0[i] = ((ftemp1 * ftemp2) + (ftemp0 * R0_1));
  603. if (++iota12 == 248)
  604. iota12 = 0;
  605. float T12 = dline12[iota12];
  606. if (++iota13 == 364)
  607. iota13 = 0;
  608. float T13 = dline13[iota13];
  609. if (++iota14 == 464)
  610. iota14 = 0;
  611. float T14 = dline14[iota14];
  612. if (++iota15 == 579)
  613. iota15 = 0;
  614. float T15 = dline15[iota15];
  615. if (++iota16 == 1640)
  616. iota16 = 0;
  617. float T16 = dline16[iota16];
  618. R25_0 = ((ftemp7 * R24_0) + (ftemp6 * R25_0));
  619. dline16[iota16] = (ftemp4 + (ftemp5 * R25_0));
  620. R24_0 = T16;
  621. if (++iota17 == 1580)
  622. iota17 = 0;
  623. float T17 = dline17[iota17];
  624. R27_0 = ((ftemp7 * R26_0) + (ftemp6 * R27_0));
  625. dline17[iota17] = (ftemp4 + (ftemp5 * R27_0));
  626. R26_0 = T17;
  627. if (++iota18 == 1514)
  628. iota18 = 0;
  629. float T18 = dline18[iota18];
  630. R29_0 = ((ftemp7 * R28_0) + (ftemp6 * R29_0));
  631. dline18[iota18] = (ftemp4 + (ftemp5 * R29_0));
  632. R28_0 = T18;
  633. if (++iota19 == 1445)
  634. iota19 = 0;
  635. float T19 = dline19[iota19];
  636. R31_0 = ((ftemp7 * R30_0) + (ftemp6 * R31_0));
  637. dline19[iota19] = (ftemp4 + (ftemp5 * R31_0));
  638. R30_0 = T19;
  639. if (++iota20 == 1300)
  640. iota20 = 0;
  641. float T20 = dline20[iota20];
  642. R33_0 = ((ftemp7 * R32_0) + (ftemp6 * R33_0));
  643. dline20[iota20] = (ftemp4 + (ftemp5 * R33_0));
  644. R32_0 = T20;
  645. if (++iota21 == 1139)
  646. iota21 = 0;
  647. float T21 = dline21[iota21];
  648. R35_0 = ((ftemp7 * R34_0) + (ftemp6 * R35_0));
  649. dline21[iota21] = (ftemp4 + (ftemp5 * R35_0));
  650. R34_0 = T21;
  651. if (++iota22 == 1211)
  652. iota22 = 0;
  653. float T22 = dline22[iota22];
  654. R37_0 = ((ftemp7 * R36_0) + (ftemp6 * R37_0));
  655. dline22[iota22] = (ftemp4 + (ftemp5 * R37_0));
  656. R36_0 = T22;
  657. if (++iota23 == 1379)
  658. iota23 = 0;
  659. float T23 = dline23[iota23];
  660. R39_0 = ((ftemp7 * R38_0) + (ftemp6 * R39_0));
  661. dline23[iota23] = (ftemp4 + (ftemp5 * R39_0));
  662. R38_0 = T23;
  663. float ftemp9 = (R36_0 + R38_0);
  664. dline15[iota15] = ((((0.500000f * R23_0) + R24_0) + (R26_0 + R28_0)) + ((R30_0 + R32_0) + (R34_0 + ftemp9)));
  665. float R23temp0 = T15;
  666. float R23temp1 = (R23_0 - (((R24_0 + R26_0) + (R28_0 + R30_0)) + ((R32_0 + R34_0) + ftemp9)));
  667. R23_0 = R23temp0;
  668. R23_1 = R23temp1;
  669. dline14[iota14] = ((0.500000f * R22_0) + R23_1);
  670. float R22temp0 = T14;
  671. float R22temp1 = (R22_0 - R23_1);
  672. R22_0 = R22temp0;
  673. R22_1 = R22temp1;
  674. dline13[iota13] = ((0.500000f * R21_0) + R22_1);
  675. float R21temp0 = T13;
  676. float R21temp1 = (R21_0 - R22_1);
  677. R21_0 = R21temp0;
  678. R21_1 = R21temp1;
  679. dline12[iota12] = ((0.500000f * R20_0) + R21_1);
  680. float R20temp0 = T12;
  681. float R20temp1 = (R20_0 - R21_1);
  682. R20_0 = R20temp0;
  683. R20_1 = R20temp1;
  684. output1[i] = ((ftemp1 * ftemp3) + (ftemp0 * R20_1));
  685. }
  686. }
  687. };
  688. mydsp DSP;
  689. /******************************************************************************
  690. *******************************************************************************
  691. JACK AUDIO INTERFACE
  692. *******************************************************************************
  693. *******************************************************************************/
  694. //----------------------------------------------------------------------------
  695. // number of input and output channels
  696. //----------------------------------------------------------------------------
  697. int gNumInChans;
  698. int gNumOutChans;
  699. //----------------------------------------------------------------------------
  700. // Jack ports
  701. //----------------------------------------------------------------------------
  702. jack_port_t *input_ports[256];
  703. jack_port_t *output_ports[256];
  704. //----------------------------------------------------------------------------
  705. // tables of noninterleaved input and output channels for FAUST
  706. //----------------------------------------------------------------------------
  707. float* gInChannel[256];
  708. float* gOutChannel[256];
  709. //----------------------------------------------------------------------------
  710. // Jack Callbacks
  711. //----------------------------------------------------------------------------
  712. int srate(jack_nframes_t nframes, void *arg)
  713. {
  714. printf("the sample rate is now %u/sec\n", nframes);
  715. return 0;
  716. }
  717. void jack_shutdown(void *arg)
  718. {
  719. exit(1);
  720. }
  721. int process (jack_nframes_t nframes, void *arg)
  722. {
  723. int i;
  724. for (i = 0; i < gNumInChans; i++) {
  725. gInChannel[i] = (float *)jack_port_get_buffer(input_ports[i], nframes);
  726. }
  727. for (i = 0; i < gNumOutChans; i++) {
  728. gOutChannel[i] = (float *)jack_port_get_buffer(output_ports[i], nframes);
  729. }
  730. DSP.compute(nframes, gInChannel, gOutChannel);
  731. return 0;
  732. }
  733. //-------------------------------------------------------------------------
  734. // MAIN
  735. //-------------------------------------------------------------------------
  736. int main(int argc, char *argv[] )
  737. {
  738. char jackname[256];
  739. char** physicalInPorts;
  740. char** physicalOutPorts;
  741. jack_client_t* client;
  742. int i;
  743. CMDUI* inter = new CMDUI(argc, argv);
  744. DSP.buildUserInterface(inter);
  745. //_snprintf(jackname, 255, "%s", basename(argv[0]));
  746. _snprintf(jackname, 255, "%s", "freeverb");
  747. if ((client = jack_client_new(jackname)) == 0) {
  748. fprintf(stderr, "jack server not running?\n");
  749. return 1;
  750. }
  751. jack_set_process_callback(client, process, 0);
  752. jack_set_sample_rate_callback(client, srate, 0);
  753. jack_on_shutdown(client, jack_shutdown, 0);
  754. gNumInChans = DSP.getNumInputs();
  755. gNumOutChans = DSP.getNumOutputs();
  756. for (i = 0; i < gNumInChans; i++) {
  757. char buf[256];
  758. _snprintf(buf, 256, "in_%d", i);
  759. input_ports[i] = jack_port_register(client, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  760. }
  761. for (i = 0; i < gNumOutChans; i++) {
  762. char buf[256];
  763. _snprintf(buf, 256, "out_%d", i);
  764. output_ports[i] = jack_port_register(client, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  765. }
  766. DSP.init(jack_get_sample_rate(client));
  767. DSP.buildUserInterface(inter);
  768. inter->process_command();
  769. physicalInPorts = (char **)jack_get_ports(client, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  770. physicalOutPorts = (char **)jack_get_ports(client, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  771. if (jack_activate(client)) {
  772. fprintf(stderr, "cannot activate client");
  773. return 1;
  774. }
  775. /*
  776. if (physicalOutPorts != NULL) {
  777. for (int i = 0; i < gNumInChans && physicalOutPorts[i]; i++) {
  778. jack_connect(client, physicalOutPorts[i], jack_port_name(input_ports[i]));
  779. }
  780. }
  781. */
  782. if (physicalInPorts != NULL) {
  783. for (int i = 0; i < gNumOutChans && physicalInPorts[i]; i++) {
  784. jack_connect(client, jack_port_name(output_ports[i]), physicalInPorts[i]);
  785. }
  786. }
  787. /*
  788. jack_connect(client, "AudioPlayer:out1", jack_port_name(input_ports[0]));
  789. jack_connect(client, "AudioPlayer:out1", jack_port_name(input_ports[1]));
  790. jack_connect(client, "AudioPlayer:out2", jack_port_name(input_ports[0]));
  791. jack_connect(client, "AudioPlayer:out2", jack_port_name(input_ports[1]));
  792. */
  793. jack_connect(client, "JackRouter:out1", jack_port_name(input_ports[0]));
  794. jack_connect(client, "JackRouter:out2", jack_port_name(input_ports[1]));
  795. inter->run();
  796. jack_deactivate(client);
  797. for (i = 0; i < gNumInChans; i++) {
  798. jack_port_unregister(client, input_ports[i]);
  799. }
  800. for (i = 0; i < gNumOutChans; i++) {
  801. jack_port_unregister(client, output_ports[i]);
  802. }
  803. jack_client_close(client);
  804. return 0;
  805. }