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.

86 lines
2.4KB

  1. <html>
  2. m4_include(`header.html')
  3. <h2>Issues to consider when porting programs to JACK</h2>
  4. <h4>Sample bit width assumptions</h4>
  5. A lot existing Linux audio software tends to assume that audio samples
  6. are 8 or 16 bits wide, and uses <code>short</code> to store them. This
  7. does not work with JACK, where all sample data, regardless of the
  8. original data format in which it was obtained (e.g. from disk), is
  9. stored as a floating point value normalized to the range -1.0 to +1.0.
  10. <h4>Channel interleaving assumptions</h4>
  11. Almost all existing Linux audio software assumes that when delivering
  12. a sample stream with more than one channel, the samples should be
  13. interleaved. This does not work with JACK, where all sample streams
  14. are mono.
  15. <h4>Block-on-write or block-on-read assumptions</h4>
  16. Quite a lot of existing Linux audio software tends to be structured
  17. around the blocking behaviour of a call to write(2) or read(2) when
  18. the file descriptor concerned refers to the audio interface. They
  19. often have this structure:
  20. <verbatim>
  21. // Playback
  22. while (1) {
  23. get_sample_date_from_somewhere (buf);
  24. write (audiofd, buf, bufsize);
  25. }
  26. // Capture
  27. while (1) {
  28. read (audiofd, buf, bufsize);
  29. put_sample_data_somewhere (buf);
  30. }
  31. </verbatim>
  32. These structures don't work with JACK, which is entirely callback
  33. driven and moves audio data by copying it to and from memory
  34. locations, not files. Instead, its necessary to define a
  35. <code>process()</code> callback which does this:
  36. <verbatim>
  37. // playback
  38. int
  39. process (nframes_t nframes)
  40. {
  41. get_nframes_of_data_from_somewhere_without_blocking (buf);
  42. sample_t *addr = jack_port_get_buffer (playback_port);
  43. memcpy (addr, buf, nframes * sizeof (sample_t));
  44. }
  45. // capture
  46. int
  47. process (nframes_t nframes)
  48. {
  49. sample_t *addr = jack_port_get_buffer (capture_port);
  50. memcpy (buf, addr, nframes * sizeof (sample_t));
  51. put_nframes_of_data_somewhere_without_blocking (buf);
  52. }
  53. </verbatim>
  54. The code in the <code>process()</code> function should not under
  55. (almost) any circumstances block: that is, it may not read/write data
  56. from/to a file, it may not call malloc(), it may not use
  57. pthread_mutex_lock(), and it should generally avoid system calls. the
  58. <code>process()</code> callback will be executed when the JACK server
  59. decides it should be, and it cannot be used to time other parts of the
  60. program.
  61. m4_include(`trailer.html')