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.

104 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. #define DEFAULT_RB_SIZE 16384
  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. adapter->fLastCallbackTime = adapter->fCurCallbackTime;
  30. adapter->fCurCallbackTime = jack_get_time();
  31. if (!adapter->fIOAdapter->IsRunning())
  32. return 0;
  33. adapter->fIOAdapter->SetCallbackDeltaTime(adapter->fCurCallbackTime - adapter->fLastCallbackTime);
  34. for (i = 0; i < adapter->fCaptureChannels; i++) {
  35. buffer = static_cast<float*>(jack_port_get_buffer(adapter->fCapturePortList[i], frames));
  36. int len = adapter->fCaptureRingBuffer[i].Read(buffer, frames);
  37. }
  38. for (i = 0; i < adapter->fPlaybackChannels; i++) {
  39. buffer = static_cast<float*>(jack_port_get_buffer(adapter->fPlaybackPortList[i], frames));
  40. int len = adapter->fPlaybackRingBuffer[i].Write(buffer, frames);
  41. }
  42. return 0;
  43. }
  44. int JackCallbackNetIOAdapter::BufferSize(jack_nframes_t nframes, void *arg)
  45. {
  46. JackCallbackNetIOAdapter* adapter = static_cast<JackCallbackNetIOAdapter*>(arg);
  47. adapter->fIOAdapter->SetBufferSize(nframes);
  48. return 0;
  49. }
  50. JackCallbackNetIOAdapter::JackCallbackNetIOAdapter(jack_client_t* jack_client,
  51. JackIOAdapterInterface* audio_io,
  52. int input,
  53. int output)
  54. : JackNetIOAdapter(jack_client, audio_io, input, output)
  55. {
  56. fCurCallbackTime = 0;
  57. fLastCallbackTime = 0;
  58. fCaptureRingBuffer = new JackResampler[fCaptureChannels];
  59. fPlaybackRingBuffer = new JackResampler[fPlaybackChannels];
  60. fIOAdapter->SetRingBuffers(fCaptureRingBuffer, fPlaybackRingBuffer);
  61. if (jack_set_process_callback(fJackClient, Process, this) < 0)
  62. goto fail;
  63. if (jack_set_buffer_size_callback(fJackClient, BufferSize, this) < 0)
  64. goto fail;
  65. if (jack_activate(fJackClient) < 0)
  66. goto fail;
  67. return;
  68. fail:
  69. FreePorts();
  70. }
  71. JackCallbackNetIOAdapter::~JackCallbackNetIOAdapter()
  72. {
  73. delete[] fCaptureRingBuffer;
  74. delete[] fPlaybackRingBuffer;
  75. }
  76. } //namespace