fmhfuncs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Copyright (c) 1983-2013 Richard Dobson and Composers Desktop Project Ltd
  3. * http://people.bath.ac.uk/masrwd
  4. * http://www.composersdesktop.com
  5. * This file is part of the CDP System.
  6. * The CDP System is free software; you can redistribute it
  7. * and/or modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * The CDP System is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU Lesser General Public License for more details.
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with the CDP System; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. /* fmhfuncs.c */
  21. #include "fmdcode.h"
  22. /* TODO: expand to handle numframes frames? */
  23. void fmhcopy_3(ABFSAMPLE* abf,const float*buf)
  24. {
  25. abf->W = *buf++;
  26. abf->X = *buf++;
  27. abf->Y = *buf;
  28. }
  29. void fmhcopy_4(ABFSAMPLE* abf,const float*buf)
  30. {
  31. abf->W = *buf++;
  32. abf->X = *buf++;
  33. abf->Y = *buf++;
  34. abf->Z = *buf;
  35. }
  36. void fmhcopy_5(ABFSAMPLE* abf,const float*buf)
  37. {
  38. abf->W = *buf++;
  39. abf->X = *buf++;
  40. abf->Y = *buf++;
  41. abf->U = *buf++;
  42. abf->V = *buf;
  43. }
  44. void fmhcopy_6(ABFSAMPLE* abf,const float*buf)
  45. {
  46. abf->W = *buf++;
  47. abf->X = *buf++;
  48. abf->Y = *buf++;
  49. abf->Z = *buf++;
  50. abf->U = *buf++;
  51. abf->V = *buf;
  52. }
  53. // following discard 3rd order chans
  54. void fmhcopy_7(ABFSAMPLE* abf,const float*buf)
  55. {
  56. abf->W = *buf++;
  57. abf->X = *buf++;
  58. abf->Y = *buf++;
  59. abf->U = *buf++;
  60. abf->V = *buf;
  61. }
  62. void fmhcopy_8(ABFSAMPLE* abf,const float*buf)
  63. {
  64. abf->W = *buf++;
  65. abf->X = *buf++;
  66. abf->Y = *buf++;
  67. abf->Z = *buf++;
  68. abf->U = *buf++;
  69. abf->V = *buf;
  70. }
  71. // these identical for 2nd order horiz max, but may be expanded later!
  72. void fmhcopy_9(ABFSAMPLE* abf,const float*buf)
  73. {
  74. abf->W = *buf++;
  75. abf->X = *buf++;
  76. abf->Y = *buf++;
  77. abf->Z = *buf++;
  78. abf->R = *buf++;
  79. abf->S = *buf++;
  80. abf->T = *buf++;
  81. abf->U = *buf++;
  82. abf->V = *buf;
  83. }
  84. void fmhcopy_11(ABFSAMPLE* abf,const float*buf)
  85. {
  86. abf->W = *buf++;
  87. abf->X = *buf++;
  88. abf->Y = *buf++;
  89. abf->Z = *buf++;
  90. abf->R = *buf++;
  91. abf->S = *buf++;
  92. abf->T = *buf++;
  93. abf->U = *buf++;
  94. abf->V = *buf;
  95. }
  96. void fmhcopy_16(ABFSAMPLE* abf,const float*buf)
  97. {
  98. abf->W = *buf++;
  99. abf->X = *buf++;
  100. abf->Y = *buf++;
  101. abf->Z = *buf++;
  102. abf->R = *buf++;
  103. abf->S = *buf++;
  104. abf->T = *buf++;
  105. abf->U = *buf++;
  106. abf->V = *buf;
  107. }
  108. /********** DECODE FUNCS *************/
  109. /* TODO: complete support for numframes > 1 */
  110. void fm_i1_mono(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  111. {
  112. int i;
  113. float *p_out = outbuf;
  114. double aw;
  115. for(i=0;i < numframes; i++){
  116. aw = (double) inbuf->W * 0.7071;
  117. *p_out++ = (float) aw;
  118. }
  119. }
  120. void fm_i1_stereo(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  121. {
  122. int i;
  123. float *p_out = outbuf;
  124. double aw,ay;
  125. for(i=0;i < numframes; i++){
  126. aw = (double) inbuf->W * 0.7071;
  127. ay = (double) inbuf->Y * 0.5;
  128. *p_out++ = (float) (aw + ay);
  129. *p_out++ = (float) (aw - ay);
  130. }
  131. }
  132. void fm_i1_square(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  133. {
  134. int i;
  135. float *p_out = outbuf;
  136. double aw,ax,ay;
  137. for(i=0;i < numframes; i++){
  138. aw = (double) inbuf->W * 0.35355;
  139. ax = (double) inbuf->X * 0.17677;
  140. ay = (double) inbuf->Y * 0.17677;
  141. *p_out++ = (float) (aw + ax + ay); //FL
  142. *p_out++ = (float) (aw - ax + ay); //RL
  143. *p_out++ = (float) (aw - ax - ay); //RR
  144. *p_out++ = (float) (aw + ax - ay); //FR
  145. }
  146. }
  147. void fm_i2_square(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  148. {
  149. int i;
  150. float *p_out = outbuf;
  151. double aw,ax,ay,av;
  152. for(i=0;i < numframes; i++){
  153. aw = (double) inbuf->W * 0.3536;
  154. ax = (double) inbuf->X * 0.2434;
  155. ay = (double) inbuf->Y * 0.2434;
  156. av = (double) inbuf->V * 0.0964;
  157. *p_out++ = (float) (aw + ax + ay + av); //FL
  158. *p_out++ = (float) (aw - ax + ay - av ); //RL
  159. *p_out++ = (float) (aw - ax - ay + av); //RR
  160. *p_out++ = (float) (aw + ax - ay - av); //FR
  161. }
  162. }
  163. /* ditto, RLRL layout for WAVEX */
  164. void fm_i1_quad(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  165. {
  166. int i;
  167. float *p_out = outbuf;
  168. double aw,ax,ay;
  169. for(i=0;i < numframes; i++){
  170. aw = (double) inbuf->W * 0.35355;
  171. ax = (double) inbuf->X * 0.17677;
  172. ay = (double) inbuf->Y * 0.17677;
  173. *p_out++ = (float) (aw + ax + ay); //FL
  174. *p_out++ = (float) (aw + ax - ay); //FR
  175. *p_out++ = (float) (aw - ax + ay); //RL
  176. *p_out++ = (float) (aw - ax - ay); //RR
  177. }
  178. }
  179. void fm_i2_quad(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  180. {
  181. int i;
  182. float *p_out = outbuf;
  183. double aw,ax,ay,av;
  184. for(i=0;i < numframes; i++){
  185. aw = (double) inbuf->W * 0.3536;
  186. ax = (double) inbuf->X * 0.2434;
  187. ay = (double) inbuf->Y * 0.2434;
  188. av = (double) inbuf->V * 0.0964;
  189. *p_out++ = (float) (aw + ax + ay + av); //FL
  190. *p_out++ = (float) (aw + ax - ay - av); //FR
  191. *p_out++ = (float) (aw - ax + ay - av ); //RL
  192. *p_out++ = (float) (aw - ax - ay + av); //RR
  193. }
  194. }
  195. //front pair angle 72deg
  196. void fm_i1_pent(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  197. {
  198. int i;
  199. float *p_out = outbuf;
  200. double aw,ax,ay;
  201. for(i=0;i < numframes; i++){
  202. aw = (double) inbuf->W * 0.2828;
  203. ax = (double) inbuf->X;
  204. ay = (double) inbuf->Y;
  205. *p_out++ = (float) (aw + (ax*0.1618) + (ay*0.1176)); //FL
  206. *p_out++ = (float) (aw - (ax*0.0618) + (ay*0.1902));
  207. *p_out++ = (float) (aw - (ax*0.2));
  208. *p_out++ = (float) (aw - (ax*0.0618) - (ay*0.1902));
  209. *p_out++ = (float) (aw + (ax*0.1618) - (ay*0.1176)); //FR
  210. }
  211. }
  212. void fm_i2_pent(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  213. {
  214. int i;
  215. float *p_out = outbuf;
  216. double aw,ax,ay,au,av;
  217. for(i=0;i < numframes; i++){
  218. aw = (double) inbuf->W * 0.2828;
  219. ax = (double) inbuf->X;
  220. ay = (double) inbuf->Y;
  221. au = (double) inbuf->U;
  222. av = (double) inbuf->V;
  223. *p_out++ = (float) (aw + (ax*0.2227) + (ay*0.1618) + (au*0.0238) + (av * 0.0733));
  224. *p_out++ = (float) (aw - (ax*0.0851) + (ay*0.2619) - (au*0.0624) - (av * 0.0453));
  225. *p_out++ = (float) (aw - (ax*0.2753) + (au * 0.0771) );
  226. *p_out++ = (float) (aw - (ax*0.0851) - (ay*0.2619) - (au*0.0624) + (av * 0.0453));
  227. *p_out++ = (float) (aw + (ax*0.2227) - (ay*0.1618) + (au*0.0238) - (av * 0.0733));
  228. }
  229. }
  230. /* FMH only defines 1st order decode */
  231. void fm_i1_surr(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  232. {
  233. int i;
  234. float *p_out = outbuf;
  235. double aw,ax,ay;
  236. for(i=0;i < numframes; i++){
  237. aw = (double) inbuf->W;
  238. ax = (double) inbuf->X;
  239. ay = (double) inbuf->Y;
  240. /* TODO: fix this order! */
  241. *p_out++ = (float) ((aw * 0.169) + (ax*0.0797) + (ay * 0.0891)); //L
  242. *p_out++ = (float) ((aw * 0.1635) + (ax*0.0923)); //C ///???
  243. *p_out++ = (float) ((aw * 0.169) - (ax*0.0797) - (ay * 0.0891)); //R ///????
  244. *p_out++ = (float) ((aw * 0.4563) - (ax*0.1259) + (ay * 0.1543)); //LS
  245. *p_out++ = (float) ((aw * 0.4563) - (ax*0.1259) - (ay * 0.1543)); //RS
  246. }
  247. }
  248. /* from Bruce Wiggins via Csound */
  249. void fm_i2_surr(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  250. {
  251. int i;
  252. float *p_out = outbuf;
  253. double aw,ax,ay,au,av;
  254. for(i=0;i < numframes; i++){
  255. aw = (double) inbuf->W;
  256. ax = (double) inbuf->X;
  257. ay = (double) inbuf->Y;
  258. au = (double) inbuf->U;
  259. av = (double) inbuf->V;
  260. *p_out++ = (float) ((aw * 0.405) + (ax*0.32) + (ay * 0.31) + (au * 0.085) + (av * 0.125)); //L
  261. *p_out++ = (float) ((aw * 0.405) + (ax*0.32) - (ay * 0.31) + (au * 0.085) - (av * 0.125)); //R
  262. *p_out++ = (float) ((aw * 0.085) + (ax*0.04) + (au * 0.045) ); //C
  263. *p_out++ = (float) ((aw * 0.635) - (ax*0.335) + (ay * 0.28) - (au * 0.08) + (av * 0.08)); //LS
  264. *p_out++ = (float) ((aw * 0.635) - (ax*0.335) - (ay * 0.28) - (au * 0.08) - (av * 0.08)); //RS
  265. }
  266. }
  267. /* 5.1 versions - silent LFE */
  268. /* FMH only defines 1st order decode */
  269. void fm_i1_surr6(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  270. {
  271. int i;
  272. float *p_out = outbuf;
  273. double aw,ax,ay;
  274. for(i=0;i < numframes; i++){
  275. aw = (double) inbuf->W;
  276. ax = (double) inbuf->X;
  277. ay = (double) inbuf->Y;
  278. *p_out++ = (float) ((aw * 0.169) + (ax*0.0797) + (ay * 0.0891)); //L
  279. *p_out++ = (float) ((aw * 0.1635) + (ax*0.0923)); //C
  280. *p_out++ = (float) ((aw * 0.169) - (ax*0.0797) - (ay * 0.0891)); //R
  281. *p_out++ = 0.0f; //LFE
  282. *p_out++ = (float) ((aw * 0.4563) - (ax*0.1259) + (ay * 0.1543)); //LS
  283. *p_out++ = (float) ((aw * 0.4563) - (ax*0.1259) - (ay * 0.1543)); //RS
  284. }
  285. }
  286. /* from Bruce Wiggins via Csound */
  287. void fm_i2_surr6(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  288. {
  289. int i;
  290. float *p_out = outbuf;
  291. double aw,ax,ay,au,av;
  292. for(i=0;i < numframes; i++){
  293. aw = (double) inbuf->W;
  294. ax = (double) inbuf->X;
  295. ay = (double) inbuf->Y;
  296. au = (double) inbuf->U;
  297. av = (double) inbuf->V;
  298. *p_out++ = (float) ((aw * 0.405) + (ax*0.32) + (ay * 0.31) + (au * 0.085) + (av * 0.125)); //L
  299. *p_out++ = (float) ((aw * 0.405) + (ax*0.32) - (ay * 0.31) + (au * 0.085) - (av * 0.125)); //R
  300. *p_out++ = (float) ((aw * 0.085) + (ax*0.04) + (au * 0.045) ); //C
  301. *p_out++ = 0.0f; //LFE
  302. *p_out++ = (float) ((aw * 0.635) - (ax*0.335) + (ay * 0.28) - (au * 0.08) + (av * 0.08)); //LS
  303. *p_out++ = (float) ((aw * 0.635) - (ax*0.335) - (ay * 0.28) - (au * 0.08) - (av * 0.08)); //RS
  304. }
  305. }
  306. // 1st order 5.0
  307. void dm_i1_surr(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  308. {
  309. int i;
  310. float *p_out = outbuf;
  311. double aw,ax,ay;
  312. for(i=0;i < numframes; i++){
  313. aw = (double) inbuf->W;
  314. ax = (double) inbuf->X;
  315. ay = (double) inbuf->Y;
  316. *p_out++ = (float) ((aw * 0.4597) + (ax*0.4536) + (ay * 0.3591)); //L
  317. *p_out++ = (float) ((aw * 0.4597) + (ax*0.4536) - (ay * 0.3591)); //R
  318. *p_out++ = 0.0f; //C
  319. *p_out++ = (float) ((aw * 0.5662) - (ax*0.3681) + (ay * 0.4606)); //LS
  320. *p_out++ = (float) ((aw * 0.5662) - (ax*0.3681) - (ay * 0.4606)); //RS
  321. }
  322. }
  323. //1st order 5.1
  324. void dm_i1_surr6(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  325. {
  326. int i;
  327. float *p_out = outbuf;
  328. double aw,ax,ay;
  329. for(i=0;i < numframes; i++){
  330. aw = (double) inbuf->W;
  331. ax = (double) inbuf->X;
  332. ay = (double) inbuf->Y;
  333. *p_out++ = (float) ((aw * 0.4597) + (ax*0.4536) + (ay * 0.3591)); //L
  334. *p_out++ = (float) ((aw * 0.4597) + (ax*0.4536) - (ay * 0.3591)); //R
  335. *p_out++ = 0.0f; //C
  336. *p_out++ = 0.0f; //LFE
  337. *p_out++ = (float) ((aw * 0.5662) - (ax*0.3681) + (ay * 0.4606)); //LS
  338. *p_out++ = (float) ((aw * 0.5662) - (ax*0.3681) - (ay * 0.4606)); //RS
  339. }
  340. }
  341. // 2nd order 5.0
  342. void dm_i2_surr(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  343. {
  344. int i;
  345. float *p_out = outbuf;
  346. double aw,ax,ay,au,av;
  347. for(i=0;i < numframes; i++){
  348. aw = (double) inbuf->W;
  349. ax = (double) inbuf->X;
  350. ay = (double) inbuf->Y;
  351. au = (double) inbuf->U;
  352. av = (double) inbuf->V;
  353. *p_out++ = (float) ((aw * 0.3314) + (ax*0.4097) + (ay * 0.3487) + (au * 0.0828) + (av*0.1489)); //L
  354. *p_out++ = (float) ((aw * 0.3314) + (ax*0.4097) - (ay * 0.3487) + (au * 0.0828) - (av*0.1489)); //R
  355. *p_out++ = (float) ((aw * 0.0804) + (ax * 0.1327)); //C
  356. *p_out++ = (float) ((aw * 0.6025) - (ax*0.3627) + (ay * 0.4089) - (au * 0.0567)); //LS
  357. *p_out++ = (float) ((aw * 0.6025) - (ax*0.3627) - (ay * 0.4089) - (au * 0.0567)); //RS
  358. }
  359. }
  360. // 2nd order 5.1
  361. void dm_i2_surr6(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  362. {
  363. int i;
  364. float *p_out = outbuf;
  365. double aw,ax,ay,au,av;
  366. for(i=0;i < numframes; i++){
  367. aw = (double) inbuf->W;
  368. ax = (double) inbuf->X;
  369. ay = (double) inbuf->Y;
  370. au = (double) inbuf->U;
  371. av = (double) inbuf->V;
  372. *p_out++ = (float) ((aw * 0.3314) + (ax*0.4097) + (ay * 0.3487) + (au * 0.0828) + (av*0.1489)); //L
  373. *p_out++ = (float) ((aw * 0.3314) + (ax*0.4097) - (ay * 0.3487) + (au * 0.0828) - (av*0.1489)); //R
  374. *p_out++ = (float) ((aw * 0.0804) + (ax * 0.1327)); //C
  375. *p_out++ = 0.0f; //LFE
  376. *p_out++ = (float) ((aw * 0.6025) - (ax*0.3627) + (ay * 0.4089) - (au * 0.0567)); //LS
  377. *p_out++ = (float) ((aw * 0.6025) - (ax*0.3627) - (ay * 0.4089) - (au * 0.0567)); //RS
  378. }
  379. }
  380. void fm_i1_hex(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  381. {
  382. int i;
  383. float *p_out = outbuf;
  384. double aw,ax,ay;
  385. for(i=0;i < numframes; i++){
  386. aw = (double) inbuf->W * 0.2357;
  387. ax = (double) inbuf->X * 0.1443;
  388. ay = (double) inbuf->Y;
  389. *p_out++ = (float) (aw + ax + (ay * 0.0833)); //FL
  390. *p_out++ = (float) (aw + (ay * 0.1667)); //SL
  391. *p_out++ = (float) (aw - ax + (ay * 0.0833)); //RL
  392. *p_out++ = (float) (aw - ax - (ay * 0.0833)); //RR
  393. *p_out++ = (float) (aw - (ay * 0.1667)); //SR
  394. *p_out++ = (float) (aw + ax - (ay * 0.0833)); //FR
  395. }
  396. }
  397. void fm_i2_hex(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  398. {
  399. int i;
  400. float *p_out = outbuf;
  401. double aw,ax,ay,au,av;
  402. for(i=0;i < numframes; i++){
  403. aw = (double) inbuf->W * 0.2357;
  404. ax = (double) inbuf->X * 0.1987;
  405. ay = (double) inbuf->Y;
  406. au = (double) inbuf->U;
  407. av = (double) inbuf->V * 0.0556;
  408. *p_out++ = (float) (aw + ax + (ay * 0.1147) + (au * 0.0321) + av); //FL
  409. *p_out++ = (float) (aw + (ay * 0.2294) - (au * 0.0643) ); //SL
  410. *p_out++ = (float) (aw - ax + (ay * 0.1147) + (au * 0.0321) - av); //RL
  411. *p_out++ = (float) (aw - ax - (ay * 0.1147) + (au * 0.0321) + av); //RR
  412. *p_out++ = (float) (aw - (ay * 0.2294) - (au * 0.0643) ); //SR
  413. *p_out++ = (float) (aw + ax - (ay * 0.1147) + (au * 0.0321) - av); //FR
  414. }
  415. }
  416. void fm_i1_oct1(const ABFSAMPLE *inbuf,float*outbuf,unsigned int numframes)
  417. {
  418. int i;
  419. float *p_out = outbuf;
  420. double aw,ax,ay;
  421. for(i=0;i < numframes; i++){
  422. aw = (double) inbuf->W * 0.1768;
  423. ax = (double) inbuf->X;
  424. ay = (double) inbuf->Y;
  425. *p_out++ = (float) (aw + (ax * 0.1155) + (ay * 0.0478));
  426. *p_out++ = (float) (aw + (ax * 0.0478) + (ay * 0.1155));
  427. *p_out++ = (float) (aw - (ax * 0.0478) + (ay * 0.1155));
  428. *p_out++ = (float) (aw - (ax * 0.1155) + (ay * 0.0478));
  429. *p_out++ = (float) (aw - (ax * 0.231) - (ay * 0.0957));
  430. *p_out++ = (float) (aw - (ax * 0.0478) - (ay * 0.1155));
  431. *p_out++ = (float) (aw + (ax * 0.0478) - (ay * 0.1155));
  432. *p_out++ = (float) (aw + (ax * 0.1155) - (ay * 0.0478));
  433. }
  434. }
  435. void fm_i2_oct1(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  436. {
  437. int i;
  438. float *p_out = outbuf;
  439. double aw,ax,ay,au,av;
  440. for(i=0;i < numframes; i++){
  441. aw = (double) inbuf->W * 0.17677;
  442. ax = (double) inbuf->X;
  443. ay = (double) inbuf->Y;
  444. au = (double) inbuf->U * 0.03417;
  445. av = (double) inbuf->V * 0.03417;
  446. *p_out++ = (float) (aw + (ax * 0.15906) + (ay * 0.06588) + au + av);
  447. *p_out++ = (float) (aw + (ax * 0.06588) + (ay * 0.15906) - au + av);
  448. *p_out++ = (float) (aw - (ax * 0.06588) + (ay * 0.15906) - au - av);
  449. *p_out++ = (float) (aw - (ax * 0.15906) + (ay * 0.06588) + au - av);
  450. *p_out++ = (float) (aw - (ax * 0.15906) - (ay * 0.06588) + au + av);
  451. *p_out++ = (float) (aw - (ax * 0.06588) - (ay * 0.15906) - au + av);
  452. *p_out++ = (float) (aw + (ax * 0.06588) - (ay * 0.15906) - au - av);
  453. *p_out++ = (float) (aw + (ax * 0.15906) - (ay * 0.06588) + au - av);
  454. }
  455. }
  456. void fm_i1_oct2(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  457. {
  458. int i;
  459. float *p_out = outbuf;
  460. double aw,ax,ay;
  461. for(i=0;i < numframes; i++){
  462. aw = (double) inbuf->W * 0.1768;
  463. ax = (double) inbuf->X;
  464. ay = (double) inbuf->Y;
  465. *p_out++ = (float) (aw + (ax * 0.125) );
  466. *p_out++ = (float) (aw + (ax * 0.0884) + (ay * 0.0884));
  467. *p_out++ = (float) (aw + (ay * 0.125) );
  468. *p_out++ = (float) (aw - (ax * 0.0884) + (ay * 0.0884));
  469. *p_out++ = (float) (aw - (ax * 0.125) );
  470. *p_out++ = (float) (aw - (ax * 0.0884) - (ay * 0.0884));
  471. *p_out++ = (float) (aw - (ay * 0.125) );
  472. *p_out++ = (float) (aw + (ax * 0.0884) - (ay * 0.0884));
  473. }
  474. }
  475. void fm_i2_oct2(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  476. {
  477. int i;
  478. float *p_out = outbuf;
  479. double aw,ax,ay,au,av;
  480. for(i=0;i < numframes; i++){
  481. aw = (double) inbuf->W * 0.1768;
  482. ax = (double) inbuf->X;
  483. ay = (double) inbuf->Y;
  484. au = (double) inbuf->U * 0.0482;
  485. av = (double) inbuf->V * 0.0482;
  486. *p_out++ = (float) (aw + (ax * 0.1721) + au );
  487. *p_out++ = (float) (aw + (ax * 0.1217) + (ay * 0.1217) + av);
  488. *p_out++ = (float) (aw + (ay * 0.1721) - au );
  489. *p_out++ = (float) (aw - (ax * 0.1217) + (ay * 0.1217) - av);
  490. *p_out++ = (float) (aw - (ax * 0.1721) + au );
  491. *p_out++ = (float) (aw - (ax * 0.1217) - (ay * 0.1217) + av);
  492. *p_out++ = (float) (aw - (ay * 0.1721) - au );
  493. *p_out++ = (float) (aw + (ax * 0.1217) - (ay * 0.1217) - av);
  494. }
  495. }
  496. /* csound order; low/high anti-clockwise.
  497. FMH page order, 4 low folowed by 4 high , clockwise! */
  498. void fm_i1_cube(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  499. {
  500. int i;
  501. float *p_out = outbuf;
  502. double aw,ax,ay,az;
  503. for(i=0;i < numframes; i++){
  504. aw = (double) inbuf->W * 0.17677;
  505. ax = (double) inbuf->X * 0.07216;
  506. ay = (double) inbuf->Y * 0.07216;
  507. az = (double) inbuf->Z * 0.07216;
  508. *p_out++ = (float) (aw + ax + ay - az); // FL low
  509. *p_out++ = (float) (aw + ax + ay + az); // FL hi
  510. *p_out++ = (float) (aw - ax + ay - az); // RL low
  511. *p_out++ = (float) (aw - ax + ay + az); // hi
  512. *p_out++ = (float) (aw - ax - ay - az); // RR low
  513. *p_out++ = (float) (aw - ax - ay + az); // hi
  514. *p_out++ = (float) (aw + ax - ay - az); // FR low
  515. *p_out++ = (float) (aw + ax - ay + az); // hi
  516. }
  517. }
  518. void fm_i2_cube(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  519. {
  520. int i;
  521. float *p_out = outbuf;
  522. double aw,ax,ay,az,as,at,av;
  523. for(i=0;i < numframes; i++){
  524. aw = (double) inbuf->W * 0.1768;
  525. ax = (double) inbuf->X * 0.114;
  526. ay = (double) inbuf->Y * 0.114;
  527. az = (double) inbuf->Z * 0.114;
  528. as = (double) inbuf->S * 0.0369;
  529. at = (double) inbuf->T * 0.0369;
  530. av = (double) inbuf->V * 0.0369;
  531. *p_out++ = (float) (aw + ax + ay - az - as - at + av); //FL low
  532. *p_out++ = (float) (aw + ax + ay + az + as + at + av); // hi
  533. *p_out++ = (float) (aw - ax + ay - az + as - at - av); //RL low
  534. *p_out++ = (float) (aw - ax + ay + az - as + at - av);
  535. *p_out++ = (float) (aw - ax - ay - az + as + at + av); // RR low
  536. *p_out++ = (float) (aw - ax - ay + az - as - at + av);
  537. *p_out++ = (float) (aw + ax - ay - az - as + at - av); // FR low
  538. *p_out++ = (float) (aw + ax - ay + az + as - at - av);
  539. }
  540. }
  541. /* ditto, wavex order */
  542. /* Front L, front R, Back L, Back R; top Front L, Top Fr R, Top Back L, Top back R */
  543. void fm_i1_cubex(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  544. {
  545. int i;
  546. float *p_out = outbuf;
  547. double aw,ax,ay,az;
  548. for(i=0;i < numframes; i++){
  549. aw = (double) inbuf->W * 0.17677;
  550. ax = (double) inbuf->X * 0.07216;
  551. ay = (double) inbuf->Y * 0.07216;
  552. az = (double) inbuf->Z * 0.07216;
  553. *p_out++ = (float) (aw + ax + ay - az); // FL low
  554. *p_out++ = (float) (aw + ax - ay - az); // FR low
  555. *p_out++ = (float) (aw - ax + ay - az); // RL low
  556. *p_out++ = (float) (aw - ax - ay - az); // RR low
  557. *p_out++ = (float) (aw + ax + ay + az); // FL hi
  558. *p_out++ = (float) (aw + ax - ay + az); // FR hi
  559. *p_out++ = (float) (aw - ax + ay + az); // RL hi
  560. *p_out++ = (float) (aw - ax - ay + az); // RR hi
  561. }
  562. }
  563. void fm_i2_cubex(const ABFSAMPLE *inbuf,float *outbuf,unsigned int numframes)
  564. {
  565. int i;
  566. float *p_out = outbuf;
  567. double aw,ax,ay,az,as,at,av;
  568. for(i=0;i < numframes; i++){
  569. aw = (double) inbuf->W * 0.1768;
  570. ax = (double) inbuf->X * 0.114;
  571. ay = (double) inbuf->Y * 0.114;
  572. az = (double) inbuf->Z * 0.114;
  573. as = (double) inbuf->S * 0.0369;
  574. at = (double) inbuf->T * 0.0369;
  575. av = (double) inbuf->V * 0.0369;
  576. *p_out++ = (float) (aw + ax + ay - az - as - at + av); // FL low
  577. *p_out++ = (float) (aw + ax - ay - az - as + at - av); // FR low
  578. *p_out++ = (float) (aw - ax + ay - az + as - at - av); // RL low
  579. *p_out++ = (float) (aw - ax - ay - az + as + at + av); // RR low
  580. *p_out++ = (float) (aw + ax + ay + az + as + at + av); // FL hi
  581. *p_out++ = (float) (aw + ax - ay + az + as - at - av); // FR hi
  582. *p_out++ = (float) (aw - ax + ay + az - as + at - av); // RL hi
  583. *p_out++ = (float) (aw - ax - ay + az - as - at + av); // RR hi
  584. }
  585. }
  586. #ifdef NOTDEF
  587. void bfdcode4(float *inbuf,long numframes)
  588. {
  589. int i;
  590. float *p_buf = inbuf;
  591. double aw,ax,ay;
  592. for(i=0;i < numframes; i++){
  593. aw = (double)(p_buf[0]) ;
  594. ax = (double)(p_buf[1]) * 0.707;
  595. ay = (double)(p_buf[2]) * 0.707;
  596. //decode frame
  597. *p_buf++ = (float)(0.3333 * (aw + ax + ay)); //FL
  598. *p_buf++ = (float)(0.3333 * (aw + ax - ay)); //FR
  599. *p_buf++ = (float)(0.3333 * (aw - ax + ay)); //RL
  600. *p_buf++ = (float)(0.3333 * (aw - ax - ay)); //RR
  601. }
  602. }
  603. /* handle 3ch in to 4ch out! */
  604. void bfdcode324(float *inbuf,float*outbuf,long numframes)
  605. {
  606. int i;
  607. float *p_buf = inbuf;
  608. float * p_outbuf = outbuf;
  609. double aw,ax,ay;
  610. for(i=0;i < numframes; i++){
  611. int j;
  612. aw = (double)(*p_buf++) ;
  613. ax = (double)(*p_buf++) * 0.707;
  614. ay = (double)(*p_buf++) * 0.707;
  615. //decode frame
  616. *p_outbuf++ = (float)(0.3333 * (aw + ax + ay));
  617. *p_outbuf++ = (float)(0.3333 * (aw + ax - ay));
  618. *p_outbuf++ = (float)(0.3333 * (aw - ax + ay));
  619. *p_outbuf++ = (float)(0.3333 * (aw - ax - ay));
  620. }
  621. }
  622. #endif