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.

136 lines
4.1KB

  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. /*
  30. adapter->fLastCallbackTime = adapter->fCurCallbackTime;
  31. adapter->fCurCallbackTime = jack_get_time();
  32. */
  33. if (!adapter->fIOAdapter->IsRunning())
  34. return 0;
  35. // adapter->fIOAdapter->SetCallbackDeltaTime(adapter->fCurCallbackTime - adapter->fLastCallbackTime);
  36. // DLL
  37. adapter->fIOAdapter->SetCallbackTime(jack_get_time());
  38. //jack_info("ReadSpace = %ld", adapter->fCaptureRingBuffer[0].ReadSpace());
  39. //jack_info("WriteSpace = %ld", adapter->fPlaybackRingBuffer[0].WriteSpace());
  40. printf("ReadSpace = %ld\n", adapter->fCaptureRingBuffer[0]->ReadSpace());
  41. printf("WriteSpace = %ld\n", adapter->fPlaybackRingBuffer[0]->WriteSpace());
  42. for (i = 0; i < adapter->fCaptureChannels; i++) {
  43. buffer = static_cast<float*>(jack_port_get_buffer(adapter->fCapturePortList[i], frames));
  44. adapter->fCaptureRingBuffer[i]->Read(buffer, frames);
  45. }
  46. for (i = 0; i < adapter->fPlaybackChannels; i++) {
  47. buffer = static_cast<float*>(jack_port_get_buffer(adapter->fPlaybackPortList[i], frames));
  48. adapter->fPlaybackRingBuffer[i]->Write(buffer, frames);
  49. }
  50. return 0;
  51. }
  52. int JackCallbackNetIOAdapter::BufferSize(jack_nframes_t nframes, void *arg)
  53. {
  54. JackCallbackNetIOAdapter* adapter = static_cast<JackCallbackNetIOAdapter*>(arg);
  55. adapter->fIOAdapter->SetBufferSize(nframes);
  56. return 0;
  57. }
  58. JackCallbackNetIOAdapter::JackCallbackNetIOAdapter(jack_client_t* jack_client,
  59. JackIOAdapterInterface* audio_io,
  60. int input,
  61. int output)
  62. : JackNetIOAdapter(jack_client, audio_io, input, output)
  63. {
  64. int i;
  65. fCurCallbackTime = 0;
  66. fLastCallbackTime = 0;
  67. fCaptureRingBuffer = new JackResampler*[fCaptureChannels];
  68. fPlaybackRingBuffer = new JackResampler*[fPlaybackChannels];
  69. for (i = 0; i < fCaptureChannels; i++) {
  70. fCaptureRingBuffer[i] = new JackLibSampleRateResampler();
  71. }
  72. for (i = 0; i < fPlaybackChannels; i++) {
  73. fPlaybackRingBuffer[i] = new JackLibSampleRateResampler();
  74. }
  75. fIOAdapter->SetRingBuffers(fCaptureRingBuffer, fPlaybackRingBuffer);
  76. jack_log("ReadSpace = %ld", fCaptureRingBuffer[0]->ReadSpace());
  77. jack_log("WriteSpace = %ld", fPlaybackRingBuffer[0]->WriteSpace());
  78. if (jack_set_process_callback(fJackClient, Process, this) < 0)
  79. goto fail;
  80. if (jack_set_buffer_size_callback(fJackClient, BufferSize, this) < 0)
  81. goto fail;
  82. if (jack_activate(fJackClient) < 0)
  83. goto fail;
  84. return;
  85. fail:
  86. FreePorts();
  87. }
  88. JackCallbackNetIOAdapter::~JackCallbackNetIOAdapter()
  89. {
  90. int i;
  91. for (i = 0; i < fCaptureChannels; i++) {
  92. delete(fCaptureRingBuffer[i]);
  93. }
  94. for (i = 0; i < fPlaybackChannels; i++) {
  95. delete(fPlaybackRingBuffer[i]);
  96. }
  97. delete[] fCaptureRingBuffer;
  98. delete[] fPlaybackRingBuffer;
  99. }
  100. } //namespace