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.

102 lines
3.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 "JackError.h"
  17. #include "JackExports.h"
  18. #include <stdio.h>
  19. #include <assert.h>
  20. using namespace std;
  21. namespace Jack
  22. {
  23. int JackCallbackNetIOAdapter::Process(jack_nframes_t frames, void* arg)
  24. {
  25. JackCallbackNetIOAdapter* adapter = static_cast<JackCallbackNetIOAdapter*>(arg);
  26. float* buffer;
  27. int i;
  28. adapter->fLastCallbackTime = adapter->fCurCallbackTime;
  29. adapter->fCurCallbackTime = jack_get_time();
  30. if (!adapter->fIOAdapter->IsRunning())
  31. return 0;
  32. adapter->fIOAdapter->SetCallbackDeltaTime(adapter->fCurCallbackTime - adapter->fLastCallbackTime);
  33. for (i = 0; i < adapter->fCaptureChannels; i++) {
  34. buffer = static_cast<float*>(jack_port_get_buffer(adapter->fCapturePortList[i], frames));
  35. int len = 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. int len = 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. fCurCallbackTime = 0;
  56. fLastCallbackTime = 0;
  57. fCaptureRingBuffer = new JackResampler[fCaptureChannels];
  58. fPlaybackRingBuffer = new JackResampler[fPlaybackChannels];
  59. fIOAdapter->SetRingBuffers(fCaptureRingBuffer, fPlaybackRingBuffer);
  60. if (jack_set_process_callback(fJackClient, Process, this) < 0)
  61. goto fail;
  62. if (jack_set_buffer_size_callback(fJackClient, BufferSize, this) < 0)
  63. goto fail;
  64. if (jack_activate(fJackClient) < 0)
  65. goto fail;
  66. return;
  67. fail:
  68. FreePorts();
  69. }
  70. JackCallbackNetIOAdapter::~JackCallbackNetIOAdapter()
  71. {
  72. delete[] fCaptureRingBuffer;
  73. delete[] fPlaybackRingBuffer;
  74. }
  75. } //namespace