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.

122 lines
3.6KB

  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. #include "JackCallbackNetIOAdapter.h"
  16. #include "JackLibSampleRateResampler.h"
  17. #include "JackError.h"
  18. #include "JackExports.h"
  19. #include <stdio.h>
  20. #include <assert.h>
  21. using namespace std;
  22. namespace Jack
  23. {
  24. int JackCallbackNetIOAdapter::Process(jack_nframes_t frames, void* arg)
  25. {
  26. JackCallbackNetIOAdapter* adapter = static_cast<JackCallbackNetIOAdapter*>(arg);
  27. float* buffer;
  28. int i;
  29. if (!adapter->fIOAdapter->IsRunning())
  30. return 0;
  31. // DLL
  32. adapter->fIOAdapter->SetCallbackTime(jack_get_time());
  33. for (i = 0; i < adapter->fCaptureChannels; i++) {
  34. buffer = static_cast<float*>(jack_port_get_buffer(adapter->fCapturePortList[i], frames));
  35. adapter->fCaptureRingBuffer[i]->Read(buffer, frames);
  36. }
  37. for (i = 0; i < adapter->fPlaybackChannels; i++) {
  38. buffer = static_cast<float*>(jack_port_get_buffer(adapter->fPlaybackPortList[i], frames));
  39. adapter->fPlaybackRingBuffer[i]->Write(buffer, frames);
  40. }
  41. return 0;
  42. }
  43. int JackCallbackNetIOAdapter::BufferSize(jack_nframes_t nframes, void *arg)
  44. {
  45. JackCallbackNetIOAdapter* adapter = static_cast<JackCallbackNetIOAdapter*>(arg);
  46. adapter->fIOAdapter->SetBufferSize(nframes);
  47. return 0;
  48. }
  49. JackCallbackNetIOAdapter::JackCallbackNetIOAdapter(jack_client_t* jack_client,
  50. JackIOAdapterInterface* audio_io,
  51. int input,
  52. int output)
  53. : JackNetIOAdapter(jack_client, audio_io, input, output)
  54. {
  55. int i;
  56. fCurCallbackTime = 0;
  57. fLastCallbackTime = 0;
  58. fCaptureRingBuffer = new JackResampler*[fCaptureChannels];
  59. fPlaybackRingBuffer = new JackResampler*[fPlaybackChannels];
  60. for (i = 0; i < fCaptureChannels; i++) {
  61. fCaptureRingBuffer[i] = new JackLibSampleRateResampler();
  62. }
  63. for (i = 0; i < fPlaybackChannels; i++) {
  64. fPlaybackRingBuffer[i] = new JackLibSampleRateResampler();
  65. }
  66. fIOAdapter->SetRingBuffers(fCaptureRingBuffer, fPlaybackRingBuffer);
  67. jack_log("ReadSpace = %ld", fCaptureRingBuffer[0]->ReadSpace());
  68. jack_log("WriteSpace = %ld", fPlaybackRingBuffer[0]->WriteSpace());
  69. if (jack_set_process_callback(fJackClient, Process, this) < 0)
  70. goto fail;
  71. if (jack_set_buffer_size_callback(fJackClient, BufferSize, this) < 0)
  72. goto fail;
  73. if (jack_activate(fJackClient) < 0)
  74. goto fail;
  75. return;
  76. fail:
  77. FreePorts();
  78. }
  79. JackCallbackNetIOAdapter::~JackCallbackNetIOAdapter()
  80. {
  81. int i;
  82. for (i = 0; i < fCaptureChannels; i++) {
  83. delete(fCaptureRingBuffer[i]);
  84. }
  85. for (i = 0; i < fPlaybackChannels; i++) {
  86. delete(fPlaybackRingBuffer[i]);
  87. }
  88. delete[] fCaptureRingBuffer;
  89. delete[] fPlaybackRingBuffer;
  90. }
  91. } //namespace