JACK tools
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.

131 lines
3.6KB

  1. // ----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2012 Fons Adriaensen <fons@linuxaudio.org>
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. //
  18. // ----------------------------------------------------------------------------
  19. #ifndef __JACKCLIENT_H
  20. #define __JACKCLIENT_H
  21. #include <zita-resampler/vresampler.h>
  22. #include <jack/jack.h>
  23. #include "lfqueue.h"
  24. class Jackclient
  25. {
  26. public:
  27. Jackclient (jack_client_t*, const char *jserv, int mode, int nchan, void *arg);
  28. virtual ~Jackclient (void);
  29. enum { PLAY, CAPT };
  30. enum { INIT, TERM, WAIT, SYNC0, SYNC1, SYNC2, PROC1, PROC2 };
  31. void start (Lfq_audio *audioq,
  32. Lfq_int32 *commq,
  33. Lfq_adata *alsaq,
  34. Lfq_jdata *infoq,
  35. double ratio,
  36. int delay,
  37. int ltcor,
  38. int rqual);
  39. const char *jname (void) const { return _jname; }
  40. int fsamp (void) const { return _fsamp; }
  41. int bsize (void) const { return _bsize; }
  42. int rprio (void) const { return _rprio; }
  43. void register_ports (int nports);
  44. void *getarg(void) const { return _arg; }
  45. private:
  46. void init (const char *jserv);
  47. void fini (void);
  48. double modtime (double d)
  49. {
  50. if (d < -200) d += _quant;
  51. if (d > 200) d -= _quant;
  52. return d;
  53. }
  54. void initwait (int nwait);
  55. void initsync (void);
  56. void setloop (double bw);
  57. void silence (int nframes);
  58. void playback (int nframes);
  59. void capture (int nframes);
  60. void sendinfo (int state, double error, double ratio);
  61. virtual void thr_main (void) {}
  62. void jack_freewheel (int state);
  63. void jack_latency (jack_latency_callback_mode_t jlcm);
  64. int jack_process (int nframes);
  65. jack_client_t *_client;
  66. jack_port_t *_ports [256];
  67. void *_arg;
  68. const char *_jname;
  69. int _mode;
  70. int _nchan;
  71. int _state;
  72. int _count;
  73. int _fsamp;
  74. int _bsize;
  75. int _rprio;
  76. bool _freew;
  77. float *_buff;
  78. Lfq_audio *_audioq;
  79. Lfq_int32 *_commq;
  80. Lfq_adata *_alsaq;
  81. Lfq_jdata *_infoq;
  82. double _ratio;
  83. double _quant;
  84. int _ppsec;
  85. jack_nframes_t _ft;
  86. double _t_a0;
  87. double _t_a1;
  88. int _k_a0;
  89. int _k_a1;
  90. int _k_j0;
  91. double _delay;
  92. int _ltcor;
  93. double _w0;
  94. double _w1;
  95. double _w2;
  96. double _z1;
  97. double _z2;
  98. double _z3;
  99. double _rcorr;
  100. VResampler _resamp;
  101. static void jack_static_shutdown (void *arg);
  102. static int jack_static_buffsize (jack_nframes_t nframes, void *arg);
  103. static void jack_static_freewheel (int state, void *arg);
  104. static void jack_static_latency (jack_latency_callback_mode_t jlcm, void *arg);
  105. static int jack_static_process (jack_nframes_t nframes, void *arg);
  106. };
  107. #endif