jack1 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.

866 lines
20KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2005 Jussi Laako
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <math.h>
  19. #include <config.h>
  20. #include <jack/jack.h>
  21. #include <jack/types.h>
  22. #include <jack/internal.h>
  23. #include <jack/engine.h>
  24. #include <jack/pool.h>
  25. #include <jack/port.h>
  26. #include <jack/midiport.h>
  27. #include <jack/jslist.h>
  28. #include <jack/intsimd.h>
  29. #include "local.h"
  30. static void jack_generic_buffer_init(void *port_buffer,
  31. size_t buffer_size,
  32. jack_nframes_t nframes);
  33. static void jack_audio_port_mixdown (jack_port_t *port,
  34. jack_nframes_t nframes);
  35. /* These function pointers are local to each address space. For
  36. * internal clients they reside within jackd; for external clients in
  37. * the application process. */
  38. jack_port_functions_t jack_builtin_audio_functions = {
  39. .buffer_init = jack_generic_buffer_init,
  40. .mixdown = jack_audio_port_mixdown,
  41. };
  42. extern jack_port_functions_t jack_builtin_midi_functions;
  43. jack_port_functions_t jack_builtin_NULL_functions = {
  44. .buffer_init = jack_generic_buffer_init,
  45. .mixdown = NULL,
  46. };
  47. /* Only the Audio and MIDI port types are currently built in. */
  48. jack_port_type_info_t jack_builtin_port_types[] = {
  49. { .type_name = JACK_DEFAULT_AUDIO_TYPE,
  50. .buffer_scale_factor = 1,
  51. },
  52. { .type_name = JACK_DEFAULT_MIDI_TYPE,
  53. .buffer_scale_factor = 1,
  54. },
  55. { .type_name = "", }
  56. };
  57. /* these functions have been taken from libDSP X86.c -jl */
  58. #ifdef USE_DYNSIMD
  59. static void (*opt_copy) (float *, const float *, int);
  60. static void (*opt_mix) (float *, const float *, int);
  61. static void
  62. gen_copyf (float *dest, const float *src, int length)
  63. {
  64. memcpy(dest, src, length * sizeof(float));
  65. }
  66. static void
  67. gen_mixf (float *dest, const float *src, int length)
  68. {
  69. int n;
  70. n = length;
  71. while (n--)
  72. *dest++ += *src++;
  73. /*for (iSample = 0; iSample < iDataLength; iSample++)
  74. fpDest[iSample] += fpSrc[iSample];*/
  75. }
  76. #ifdef ARCH_X86
  77. void jack_port_set_funcs ()
  78. {
  79. if (ARCH_X86_HAVE_SSE2(cpu_type)) {
  80. opt_copy = x86_sse_copyf;
  81. opt_mix = x86_sse_add2f;
  82. }
  83. else if (ARCH_X86_HAVE_3DNOW(cpu_type)) {
  84. opt_copy = x86_3dnow_copyf;
  85. opt_mix = x86_3dnow_add2f;
  86. }
  87. else {
  88. opt_copy = gen_copyf;
  89. opt_mix = gen_mixf;
  90. }
  91. }
  92. #else /* ARCH_X86 */
  93. void jack_port_set_funcs ()
  94. {
  95. opt_copy = gen_copyf;
  96. opt_mix = gen_mixf;
  97. }
  98. #endif /* ARCH_X86 */
  99. #endif /* USE_DYNSIMD */
  100. int
  101. jack_port_name_equals (jack_port_shared_t* port, const char* target)
  102. {
  103. char buf[JACK_PORT_NAME_SIZE+1];
  104. /* this nasty, nasty kludge is here because between 0.109.0 and 0.109.1,
  105. the ALSA audio backend had the name "ALSA", whereas as before and
  106. after it, it was called "alsa_pcm". this stops breakage for
  107. any setups that have saved "alsa_pcm" or "ALSA" in their connection
  108. state.
  109. */
  110. if (strncmp (target, "ALSA:capture", 12) == 0 || strncmp (target, "ALSA:playback", 13) == 0) {
  111. snprintf (buf, sizeof (buf), "alsa_pcm%s", target+4);
  112. target = buf;
  113. }
  114. return (strcmp (port->name, target) == 0 ||
  115. strcmp (port->alias1, target) == 0 ||
  116. strcmp (port->alias2, target) == 0);
  117. }
  118. jack_port_functions_t *
  119. jack_get_port_functions(jack_port_type_id_t ptid)
  120. {
  121. switch (ptid) {
  122. case JACK_AUDIO_PORT_TYPE:
  123. return &jack_builtin_audio_functions;
  124. case JACK_MIDI_PORT_TYPE:
  125. return &jack_builtin_midi_functions;
  126. /* no other builtin functions */
  127. default:
  128. return NULL;
  129. }
  130. }
  131. /*
  132. * Fills buffer with zeroes. For audio ports, engine->silent_buffer relies on it.
  133. */
  134. static void
  135. jack_generic_buffer_init(void *buffer, size_t size, jack_nframes_t nframes)
  136. {
  137. memset(buffer, 0, size);
  138. }
  139. jack_port_t *
  140. jack_port_new (const jack_client_t *client, jack_port_id_t port_id,
  141. jack_control_t *control)
  142. {
  143. jack_port_shared_t *shared = &control->ports[port_id];
  144. jack_port_type_id_t ptid = shared->ptype_id;
  145. jack_port_t *port;
  146. if ((port = (jack_port_t *) malloc (sizeof (jack_port_t))) == NULL) {
  147. return NULL;
  148. }
  149. port->mix_buffer = NULL;
  150. port->client_segment_base = NULL;
  151. port->shared = shared;
  152. port->type_info = &client->engine->port_types[ptid];
  153. pthread_mutex_init (&port->connection_lock, NULL);
  154. port->connections = 0;
  155. port->tied = NULL;
  156. if (client->control->id == port->shared->client_id) {
  157. /* It's our port, so initialize the pointers to port
  158. * functions within this address space. These builtin
  159. * definitions can be overridden by the client.
  160. */
  161. jack_port_functions_t *port_functions = jack_get_port_functions(ptid);
  162. if (port_functions == NULL)
  163. port_functions = &jack_builtin_NULL_functions;
  164. port->fptr = *port_functions;
  165. port->shared->has_mixdown = (port->fptr.mixdown ? TRUE : FALSE);
  166. }
  167. /* set up a base address so that port->offset can be used to
  168. compute the correct location. we don't store the location
  169. directly, because port->client_segment_base and/or
  170. port->offset can change if the buffer size or port counts
  171. are changed.
  172. */
  173. port->client_segment_base =
  174. (void **) &client->port_segment[ptid].attached_at;
  175. return port;
  176. }
  177. jack_port_t *
  178. jack_port_register (jack_client_t *client,
  179. const char *port_name,
  180. const char *port_type,
  181. unsigned long flags,
  182. unsigned long buffer_size)
  183. {
  184. jack_request_t req;
  185. jack_port_t *port = 0;
  186. int length ;
  187. VALGRIND_MEMSET (&req, 0, sizeof (req));
  188. req.type = RegisterPort;
  189. length = strlen ((const char *) client->control->name)
  190. + 1 + strlen (port_name);
  191. if ( length >= sizeof (req.x.port_info.name) ) {
  192. jack_error ("\"%s:%s\" is too long to be used as a JACK port name.\n"
  193. "Please use %lu characters or less.",
  194. client->control->name ,
  195. port_name,
  196. sizeof (req.x.port_info.name) - 1);
  197. return NULL ;
  198. }
  199. strcpy ((char *) req.x.port_info.name,
  200. (const char *) client->control->name);
  201. strcat ((char *) req.x.port_info.name, ":");
  202. strcat ((char *) req.x.port_info.name, port_name);
  203. snprintf (req.x.port_info.type, sizeof (req.x.port_info.type),
  204. "%s", port_type);
  205. req.x.port_info.flags = flags;
  206. req.x.port_info.buffer_size = buffer_size;
  207. req.x.port_info.client_id = client->control->id;
  208. if (jack_client_deliver_request (client, &req)) {
  209. jack_error ("cannot deliver port registration request");
  210. return NULL;
  211. }
  212. if ((port = jack_port_new (client, req.x.port_info.port_id,
  213. client->engine)) == NULL) {
  214. jack_error ("cannot allocate client side port structure");
  215. return NULL;
  216. }
  217. client->ports = jack_slist_prepend (client->ports, port);
  218. return port;
  219. }
  220. int
  221. jack_port_unregister (jack_client_t *client, jack_port_t *port)
  222. {
  223. jack_request_t req;
  224. VALGRIND_MEMSET (&req, 0, sizeof (req));
  225. req.type = UnRegisterPort;
  226. req.x.port_info.port_id = port->shared->id;
  227. req.x.port_info.client_id = client->control->id;
  228. return jack_client_deliver_request (client, &req);
  229. }
  230. /* LOCAL (in-client) connection querying only */
  231. int
  232. jack_port_connected (const jack_port_t *port)
  233. {
  234. return jack_slist_length (port->connections);
  235. }
  236. int
  237. jack_port_connected_to (const jack_port_t *port, const char *portname)
  238. {
  239. JSList *node;
  240. int ret = FALSE;
  241. /* XXX this really requires a cross-process lock
  242. so that ports/connections cannot go away
  243. while we are checking for them. that's hard,
  244. and has a non-trivial performance impact
  245. for jackd.
  246. */
  247. pthread_mutex_lock (&((jack_port_t *) port)->connection_lock);
  248. for (node = port->connections; node; node = jack_slist_next (node)) {
  249. jack_port_t *other_port = (jack_port_t *) node->data;
  250. if (jack_port_name_equals (other_port->shared, portname)) {
  251. ret = TRUE;
  252. break;
  253. }
  254. }
  255. pthread_mutex_unlock (&((jack_port_t *) port)->connection_lock);
  256. return ret;
  257. }
  258. const char **
  259. jack_port_get_connections (const jack_port_t *port)
  260. {
  261. const char **ret = NULL;
  262. JSList *node;
  263. unsigned int n;
  264. /* XXX this really requires a cross-process lock
  265. so that ports/connections cannot go away
  266. while we are checking for them. that's hard,
  267. and has a non-trivial performance impact
  268. for jackd.
  269. */
  270. pthread_mutex_lock (&((jack_port_t *) port)->connection_lock);
  271. if (port->connections != NULL) {
  272. ret = (const char **)
  273. malloc (sizeof (char *)
  274. * (jack_slist_length (port->connections) + 1));
  275. if (ret == NULL) {
  276. pthread_mutex_unlock (&((jack_port_t *)port)->connection_lock);
  277. return NULL;
  278. }
  279. for (n = 0, node = port->connections; node;
  280. node = jack_slist_next (node), ++n) {
  281. jack_port_t* other =(jack_port_t *) node->data;
  282. ret[n] = other->shared->name;
  283. }
  284. ret[n] = NULL;
  285. }
  286. pthread_mutex_unlock (&((jack_port_t *) port)->connection_lock);
  287. return ret;
  288. }
  289. /* SERVER-SIDE (all) connection querying */
  290. const char **
  291. jack_port_get_all_connections (const jack_client_t *client,
  292. const jack_port_t *port)
  293. {
  294. const char **ret;
  295. jack_request_t req;
  296. jack_port_t *tmp;
  297. unsigned int i;
  298. int need_free = FALSE;
  299. if (port == NULL) {
  300. return NULL;
  301. }
  302. VALGRIND_MEMSET (&req, 0, sizeof (req));
  303. req.type = GetPortConnections;
  304. req.x.port_info.name[0] = '\0';
  305. req.x.port_info.type[0] = '\0';
  306. req.x.port_info.flags = 0;
  307. req.x.port_info.buffer_size = 0;
  308. req.x.port_info.client_id = 0;
  309. req.x.port_info.port_id = port->shared->id;
  310. jack_client_deliver_request (client, &req);
  311. if (req.status != 0 || req.x.port_connections.nports == 0) {
  312. return NULL;
  313. }
  314. if (client->request_fd < 0) {
  315. /* internal client, .ports is in our own address space */
  316. return req.x.port_connections.ports;
  317. }
  318. if ((ret = (const char **) malloc (sizeof (char *) * (req.x.port_connections.nports + 1))) == NULL) {
  319. return NULL;
  320. }
  321. for (i = 0; i < req.x.port_connections.nports; ++i ) {
  322. jack_port_id_t port_id;
  323. if (read (client->request_fd, &port_id, sizeof (port_id))
  324. != sizeof (port_id)) {
  325. jack_error ("cannot read port id from server");
  326. return 0;
  327. }
  328. tmp = jack_port_by_id_int (client, port_id, &need_free);
  329. ret[i] = tmp->shared->name;
  330. if (need_free) {
  331. free (tmp);
  332. need_free = FALSE;
  333. }
  334. }
  335. ret[i] = NULL;
  336. return ret;
  337. }
  338. jack_port_t *
  339. jack_port_by_id_int (const jack_client_t *client, jack_port_id_t id, int* free)
  340. {
  341. JSList *node;
  342. for (node = client->ports; node; node = jack_slist_next (node)) {
  343. if (((jack_port_t *) node->data)->shared->id == id) {
  344. *free = FALSE;
  345. return (jack_port_t *) node->data;
  346. }
  347. }
  348. if (id >= client->engine->port_max)
  349. return NULL;
  350. if (client->engine->ports[id].in_use) {
  351. *free = TRUE;
  352. return jack_port_new (client, id, client->engine);
  353. }
  354. return NULL;
  355. }
  356. jack_port_t *
  357. jack_port_by_id (jack_client_t *client, jack_port_id_t id)
  358. {
  359. JSList *node;
  360. jack_port_t* port;
  361. int need_free = FALSE;
  362. for (node = client->ports_ext; node; node = jack_slist_next (node)) {
  363. port = node->data;
  364. if (port->shared->id == id) { // Found port, return the cached structure
  365. return port;
  366. }
  367. }
  368. // Otherwise possibly allocate a new port structure, keep it in the ports_ext list for later use
  369. port = jack_port_by_id_int (client,id,&need_free);
  370. if (port != NULL && need_free)
  371. client->ports_ext =
  372. jack_slist_prepend (client->ports_ext, port);
  373. return port;
  374. }
  375. jack_port_t *
  376. jack_port_by_name_int (jack_client_t *client, const char *port_name)
  377. {
  378. unsigned long i, limit;
  379. jack_port_shared_t *port;
  380. limit = client->engine->port_max;
  381. port = &client->engine->ports[0];
  382. for (i = 0; i < limit; i++) {
  383. if (port[i].in_use && jack_port_name_equals (&port[i], port_name)) {
  384. return jack_port_new (client, port[i].id,
  385. client->engine);
  386. }
  387. }
  388. return NULL;
  389. }
  390. jack_port_t *
  391. jack_port_by_name (jack_client_t *client, const char *port_name)
  392. {
  393. JSList *node;
  394. jack_port_t* port;
  395. for (node = client->ports_ext; node; node = jack_slist_next (node)) {
  396. port = node->data;
  397. if (jack_port_name_equals (port->shared, port_name)) {
  398. /* Found port, return the cached structure. */
  399. return port;
  400. }
  401. }
  402. /* Otherwise allocate a new port structure, keep it in the
  403. * ports_ext list for later use. */
  404. port = jack_port_by_name_int (client, port_name);
  405. if (port != NULL)
  406. client->ports_ext =
  407. jack_slist_prepend (client->ports_ext, port);
  408. return port;
  409. }
  410. jack_nframes_t
  411. jack_port_get_latency (jack_port_t *port)
  412. {
  413. return port->shared->latency;
  414. }
  415. jack_nframes_t
  416. jack_port_get_total_latency (jack_client_t *client, jack_port_t *port)
  417. {
  418. return port->shared->total_latency;
  419. }
  420. void
  421. jack_port_set_latency (jack_port_t *port, jack_nframes_t nframes)
  422. {
  423. port->shared->latency = nframes;
  424. }
  425. void *
  426. jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
  427. {
  428. JSList *node, *next;
  429. /* Output port. The buffer was assigned by the engine
  430. when the port was registered.
  431. */
  432. if (port->shared->flags & JackPortIsOutput) {
  433. if (port->tied) {
  434. return jack_port_get_buffer (port->tied, nframes);
  435. }
  436. return jack_output_port_buffer (port);
  437. }
  438. /* Input port. Since this can only be called from the
  439. process() callback, and since no connections can be
  440. made/broken during this phase (enforced by the jack
  441. server), there is no need to take the connection lock here
  442. */
  443. if ((node = port->connections) == NULL) {
  444. /* no connections; return a zero-filled buffer */
  445. return (void *) (*(port->client_segment_base) + port->type_info->zero_buffer_offset);
  446. }
  447. if ((next = jack_slist_next (node)) == NULL) {
  448. /* one connection: use zero-copy mode - just pass
  449. the buffer of the connected (output) port.
  450. */
  451. return jack_port_get_buffer (((jack_port_t *) node->data),
  452. nframes);
  453. }
  454. /* Multiple connections. Use a local buffer and mix the
  455. incoming data into that buffer. We have already
  456. established the existence of a mixdown function during the
  457. connection process.
  458. */
  459. if (port->mix_buffer == NULL) {
  460. jack_error( "internal jack error: mix_buffer not allocated" );
  461. return NULL;
  462. }
  463. port->fptr.mixdown (port, nframes);
  464. return (void *) port->mix_buffer;
  465. }
  466. size_t
  467. jack_port_type_buffer_size (jack_port_type_info_t* port_type_info, jack_nframes_t nframes)
  468. {
  469. if( port_type_info->buffer_scale_factor < 0 ) {
  470. return port_type_info->buffer_size;
  471. }
  472. return port_type_info->buffer_scale_factor
  473. * sizeof (jack_default_audio_sample_t)
  474. * nframes;
  475. }
  476. int
  477. jack_port_tie (jack_port_t *src, jack_port_t *dst)
  478. {
  479. if (dst->shared->client_id != src->shared->client_id) {
  480. jack_error ("cannot tie ports not owned by the same client");
  481. return -1;
  482. }
  483. if (dst->shared->flags & JackPortIsOutput) {
  484. jack_error ("cannot tie an input port");
  485. return -1;
  486. }
  487. dst->tied = src;
  488. return 0;
  489. }
  490. int
  491. jack_port_untie (jack_port_t *port)
  492. {
  493. if (port->tied == NULL) {
  494. jack_error ("port \"%s\" is not tied", port->shared->name);
  495. return -1;
  496. }
  497. port->tied = NULL;
  498. return 0;
  499. }
  500. int
  501. jack_port_request_monitor (jack_port_t *port, int onoff)
  502. {
  503. if (onoff) {
  504. port->shared->monitor_requests++;
  505. } else if (port->shared->monitor_requests) {
  506. port->shared->monitor_requests--;
  507. }
  508. if ((port->shared->flags & JackPortIsOutput) == 0) {
  509. JSList *node;
  510. /* this port is for input, so recurse over each of the
  511. connected ports.
  512. */
  513. pthread_mutex_lock (&port->connection_lock);
  514. for (node = port->connections; node;
  515. node = jack_slist_next (node)) {
  516. /* drop the lock because if there is a feedback loop,
  517. we will deadlock. XXX much worse things will
  518. happen if there is a feedback loop !!!
  519. */
  520. pthread_mutex_unlock (&port->connection_lock);
  521. jack_port_request_monitor ((jack_port_t *) node->data,
  522. onoff);
  523. pthread_mutex_lock (&port->connection_lock);
  524. }
  525. pthread_mutex_unlock (&port->connection_lock);
  526. }
  527. return 0;
  528. }
  529. int
  530. jack_port_request_monitor_by_name (jack_client_t *client,
  531. const char *port_name, int onoff)
  532. {
  533. jack_port_t *port;
  534. unsigned long i, limit;
  535. jack_port_shared_t *ports;
  536. limit = client->engine->port_max;
  537. ports = &client->engine->ports[0];
  538. for (i = 0; i < limit; i++) {
  539. if (ports[i].in_use &&
  540. strcmp (ports[i].name, port_name) == 0) {
  541. port = jack_port_new (client, ports[i].id,
  542. client->engine);
  543. return jack_port_request_monitor (port, onoff);
  544. free (port);
  545. return 0;
  546. }
  547. }
  548. return -1;
  549. }
  550. int
  551. jack_port_ensure_monitor (jack_port_t *port, int yn)
  552. {
  553. if (yn) {
  554. if (port->shared->monitor_requests == 0) {
  555. port->shared->monitor_requests++;
  556. }
  557. } else {
  558. if (port->shared->monitor_requests > 0) {
  559. port->shared->monitor_requests = 0;
  560. }
  561. }
  562. return 0;
  563. }
  564. int
  565. jack_port_monitoring_input (jack_port_t *port)
  566. {
  567. return port->shared->monitor_requests > 0;
  568. }
  569. const char *
  570. jack_port_name (const jack_port_t *port)
  571. {
  572. return port->shared->name;
  573. }
  574. int
  575. jack_port_get_aliases (const jack_port_t *port, char* const aliases[2])
  576. {
  577. int cnt = 0;
  578. if (port->shared->alias1[0] != '\0') {
  579. snprintf (aliases[0], JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE, "%s", port->shared->alias1);
  580. cnt++;
  581. }
  582. if (port->shared->alias2[0] != '\0') {
  583. snprintf (aliases[1], JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE, "%s", port->shared->alias2);
  584. cnt++;
  585. }
  586. return cnt;
  587. }
  588. const char *
  589. jack_port_short_name (const jack_port_t *port)
  590. {
  591. /* we know there is always a colon, because we put
  592. it there ...
  593. */
  594. return strchr (port->shared->name, ':') + 1;
  595. }
  596. int
  597. jack_port_is_mine (const jack_client_t *client, const jack_port_t *port)
  598. {
  599. return port->shared->client_id == client->control->id;
  600. }
  601. int
  602. jack_port_flags (const jack_port_t *port)
  603. {
  604. return port->shared->flags;
  605. }
  606. const char *
  607. jack_port_type (const jack_port_t *port)
  608. {
  609. return port->type_info->type_name;
  610. }
  611. int
  612. jack_port_set_name (jack_port_t *port, const char *new_name)
  613. {
  614. char *colon;
  615. int len;
  616. colon = strchr (port->shared->name, ':');
  617. len = sizeof (port->shared->name) -
  618. ((int) (colon - port->shared->name)) - 2;
  619. snprintf (colon+1, len, "%s", new_name);
  620. return 0;
  621. }
  622. int
  623. jack_port_set_alias (jack_port_t *port, const char *alias)
  624. {
  625. if (port->shared->alias1[0] == '\0') {
  626. snprintf (port->shared->alias1, sizeof (port->shared->alias1), "%s", alias);
  627. } else if (port->shared->alias2[0] == '\0') {
  628. snprintf (port->shared->alias2, sizeof (port->shared->alias2), "%s", alias);
  629. } else {
  630. return -1;
  631. }
  632. return 0;
  633. }
  634. int
  635. jack_port_unset_alias (jack_port_t *port, const char *alias)
  636. {
  637. if (strcmp (port->shared->alias1, alias) == 0) {
  638. port->shared->alias1[0] = '\0';
  639. } else if (strcmp (port->shared->alias2, alias) == 0) {
  640. port->shared->alias2[0] = '\0';
  641. } else {
  642. return -1;
  643. }
  644. return 0;
  645. }
  646. /* AUDIO PORT SUPPORT */
  647. static inline float f_max(float x, float a)
  648. {
  649. x -= a;
  650. x += fabs (x);
  651. x *= 0.5;
  652. x += a;
  653. return (x);
  654. }
  655. static void
  656. jack_audio_port_mixdown (jack_port_t *port, jack_nframes_t nframes)
  657. {
  658. JSList *node;
  659. jack_port_t *input;
  660. #ifndef ARCH_X86
  661. jack_nframes_t n;
  662. jack_default_audio_sample_t *dst, *src;
  663. #endif
  664. jack_default_audio_sample_t *buffer;
  665. /* by the time we've called this, we've already established
  666. the existence of more than one connection to this input
  667. port and allocated a mix_buffer.
  668. */
  669. /* no need to take connection lock, since this is called
  670. from the process() callback, and the jack server
  671. ensures that no changes to connections happen
  672. during this time.
  673. */
  674. node = port->connections;
  675. input = (jack_port_t *) node->data;
  676. buffer = port->mix_buffer;
  677. #ifndef USE_DYNSIMD
  678. memcpy (buffer, jack_output_port_buffer (input),
  679. sizeof (jack_default_audio_sample_t) * nframes);
  680. #else /* USE_DYNSIMD */
  681. opt_copy (buffer, jack_output_port_buffer (input), nframes);
  682. #endif /* USE_DYNSIMD */
  683. for (node = jack_slist_next (node); node;
  684. node = jack_slist_next (node)) {
  685. input = (jack_port_t *) node->data;
  686. #ifndef USE_DYNSIMD
  687. n = nframes;
  688. dst = buffer;
  689. src = jack_output_port_buffer (input);
  690. while (n--) {
  691. *dst++ += *src++;
  692. }
  693. #else /* USE_DYNSIMD */
  694. opt_mix (buffer, jack_output_port_buffer (input), nframes);
  695. #endif /* USE_DYNSIMD */
  696. }
  697. }