2006-09-03 10:39:10 +03:00
|
|
|
/*
|
2008-03-05 18:39:51 +02:00
|
|
|
Copyright (C) 2001 Paul Davis
|
2008-02-01 21:46:45 +02:00
|
|
|
Copyright (C) 2004-2008 Grame
|
2006-09-03 10:39:10 +03:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2007-01-24 14:19:21 +02:00
|
|
|
*/
|
|
|
|
|
2008-09-05 16:36:28 +03:00
|
|
|
#include "JackSystemDeps.h"
|
2006-09-03 10:39:10 +03:00
|
|
|
#include "JackLoopbackDriver.h"
|
2009-07-18 10:54:18 +03:00
|
|
|
#include "JackDriverLoader.h"
|
2006-09-03 10:39:10 +03:00
|
|
|
#include "JackEngineControl.h"
|
|
|
|
#include "JackGraphManager.h"
|
2008-05-26 12:49:27 +03:00
|
|
|
#include "JackError.h"
|
2006-09-03 10:39:10 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
namespace Jack
|
|
|
|
{
|
|
|
|
|
2011-12-15 12:08:10 +02:00
|
|
|
// When used in "slave" mode
|
2011-03-26 13:52:52 +02:00
|
|
|
|
|
|
|
int JackLoopbackDriver::ProcessReadSync()
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
2006-09-03 10:39:10 +03:00
|
|
|
// Loopback copy
|
|
|
|
for (int i = 0; i < fCaptureChannels; i++) {
|
2011-03-11 16:45:57 +02:00
|
|
|
memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
|
2008-03-05 18:39:51 +02:00
|
|
|
}
|
2006-09-03 10:39:10 +03:00
|
|
|
|
2012-01-07 18:38:03 +02:00
|
|
|
// Resume connected clients in the graph
|
2011-12-15 12:55:05 +02:00
|
|
|
if (ResumeRefNum() < 0) {
|
2011-03-26 13:52:52 +02:00
|
|
|
jack_error("JackLoopbackDriver::ProcessReadSync - ResumeRefNum error");
|
|
|
|
res = -1;
|
2006-09-03 10:39:10 +03:00
|
|
|
}
|
2011-03-26 13:52:52 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JackLoopbackDriver::ProcessWriteSync()
|
|
|
|
{
|
2012-01-07 18:38:03 +02:00
|
|
|
// Suspend on connected clients in the graph
|
2011-12-15 12:55:05 +02:00
|
|
|
if (SuspendRefNum() < 0) {
|
2013-02-11 10:23:04 +02:00
|
|
|
jack_error("JackLoopbackDriver::ProcessWriteSync - SuspendRefNum error");
|
2011-03-26 13:52:52 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JackLoopbackDriver::ProcessReadAsync()
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
// Loopback copy
|
|
|
|
for (int i = 0; i < fCaptureChannels; i++) {
|
|
|
|
memcpy(GetInputBuffer(i), GetOutputBuffer(i), sizeof(jack_default_audio_sample_t) * fEngineControl->fBufferSize);
|
|
|
|
}
|
|
|
|
|
2012-01-07 18:38:03 +02:00
|
|
|
// Resume connected clients in the graph
|
2011-12-15 12:55:05 +02:00
|
|
|
if (ResumeRefNum() < 0) {
|
2011-03-26 13:52:52 +02:00
|
|
|
jack_error("JackLoopbackDriver::ProcessReadAsync - ResumeRefNum error");
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JackLoopbackDriver::ProcessWriteAsync()
|
|
|
|
{
|
2006-09-03 10:39:10 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace
|
2009-07-18 10:54:18 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2011-03-11 16:45:57 +02:00
|
|
|
SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
|
2009-07-18 10:54:18 +03:00
|
|
|
{
|
|
|
|
jack_driver_desc_t * desc;
|
2011-04-22 22:14:31 +03:00
|
|
|
jack_driver_desc_filler_t filler;
|
|
|
|
jack_driver_param_value_t value;
|
|
|
|
|
2011-08-26 17:36:40 +03:00
|
|
|
desc = jack_driver_descriptor_construct("loopback", JackDriverSlave, "Loopback backend", &filler);
|
2011-04-22 22:14:31 +03:00
|
|
|
|
|
|
|
value.i = 0;
|
|
|
|
jack_driver_descriptor_add_parameter(desc, &filler, "channels", 'c', JackDriverParamInt, &value, NULL, "Maximum number of loopback ports", NULL);
|
2009-07-18 10:54:18 +03:00
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2011-03-11 16:45:57 +02:00
|
|
|
SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
|
2009-07-18 10:54:18 +03:00
|
|
|
{
|
|
|
|
const JSList * node;
|
|
|
|
const jack_driver_param_t * param;
|
|
|
|
int channels = 2;
|
2011-03-11 16:45:57 +02:00
|
|
|
|
2009-07-18 10:54:18 +03:00
|
|
|
for (node = params; node; node = jack_slist_next (node)) {
|
|
|
|
param = (const jack_driver_param_t *) node->data;
|
|
|
|
|
|
|
|
switch (param->character) {
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
channels = param->value.ui;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-11 16:45:57 +02:00
|
|
|
|
2009-07-18 10:54:18 +03:00
|
|
|
Jack::JackDriverClientInterface* driver = new Jack::JackLoopbackDriver(engine, table);
|
2013-10-16 14:30:33 +03:00
|
|
|
if (driver->Open(0, 0, 1, 1, channels, channels, false, "loopback", "loopback", 0, 0) == 0) {
|
2009-07-18 10:54:18 +03:00
|
|
|
return driver;
|
|
|
|
} else {
|
|
|
|
delete driver;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|