Skip to content

adding xruns_get command #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/jack2"]
path = src/jack2
url = https://github.com/jackaudio/jack2
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif
LIBS = -ljack `pkg-config --libs lilv-0` -largtable2 -lreadline -lpthread

# additional include paths
INCS = -I/usr/include/lilv-0
INCS = -I/usr/include/lilv-0 -Isrc/jack2/common -Isrc/jack2/linux -Isrc/jack2/posix -Isrc/jack2/common/jack

# remove command
RM = rm -f
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ The commands supported by mod-host are:
e.g.: bypass 0 1
bypass_value = 1 bypass the effect and bypass_value = 0 process the effect

xruns_get
returns the number of xruns and the maximum delay reported since startup or
last xruns_get, response is of the format: resp 0 <number of xruns> <max delay>

load <filename>
e.g.: load my_preset

Expand All @@ -106,6 +110,7 @@ The commands supported by mod-host are:
quit
bye!


For each effect added, one client on JACK will be created. The names of clients
follow the standard: effect_\<instance_number\>

Expand Down
100 changes: 100 additions & 0 deletions src/atomic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of mod-host.
*
* mod-host 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 3 of the License, or
* (at your option) any later version.
*
* mod-host 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 mod-host. If not, see <http://www.gnu.org/licenses/>.
*
*/

/*
************************************************************************************************************************
*
************************************************************************************************************************
*/

#ifndef ATOMIC_H
#define ATOMIC_H


/*
************************************************************************************************************************
* INCLUDE FILES
************************************************************************************************************************
*/

#include "jack2/common/JackAtomic.h"

/*
************************************************************************************************************************
* DO NOT CHANGE THESE DEFINES
************************************************************************************************************************
*/


/*
************************************************************************************************************************
* CONFIGURATION DEFINES
************************************************************************************************************************
*/


/*
************************************************************************************************************************
* DATA TYPES
************************************************************************************************************************
*/


/*
************************************************************************************************************************
* GLOBAL VARIABLES
************************************************************************************************************************
*/


/*
************************************************************************************************************************
* MACRO'S
************************************************************************************************************************
*/


/*
************************************************************************************************************************
* FUNCTION PROTOTYPES
************************************************************************************************************************
*/

static inline long RESET_ATOMIC(volatile SInt32* val)
{
SInt32 actual;
do {
actual = *val;
} while (!CAS(actual, 0, val));
return actual;
}

/*
************************************************************************************************************************
* CONFIGURATION ERRORS
************************************************************************************************************************
*/


/*
************************************************************************************************************************
* END HEADER
************************************************************************************************************************
*/

#endif
31 changes: 31 additions & 0 deletions src/effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "lv2_evbuf.h"
#include "worker.h"
#include "symap.h"
#include "atomic.h"


/*
Expand Down Expand Up @@ -208,6 +209,7 @@ static effect_t Effects[MAX_INSTANCES];
static jack_client_t *Jack_Global_Client;
static jack_nframes_t Sample_Rate, BlockLength;
static size_t MidiBufferSize;
volatile int xruns;

/* LV2 and Lilv */
static LilvWorld *LV2_Data;
Expand Down Expand Up @@ -244,6 +246,7 @@ static void AllocatePortBuffers(effect_t* effect);
static int BufferSize(jack_nframes_t nframes, void* data);
static int ProcessAudio(jack_nframes_t nframes, void *arg);
static void GetFeatures(effect_t *effect);
static int XRun(void* data);


/*
Expand Down Expand Up @@ -309,6 +312,11 @@ static int BufferSize(jack_nframes_t nframes, void* data)
return SUCCESS;
}

static int XRun(void* data)
{
INC_ATOMIC(data);
return SUCCESS;
}

static int ProcessAudio(jack_nframes_t nframes, void *arg)
{
Expand Down Expand Up @@ -515,11 +523,16 @@ int effects_init(void)
/* This global client is for connections / disconnections */
Jack_Global_Client = jack_client_open("Global", JackNoStartServer, NULL);


if (Jack_Global_Client == NULL)
{
return ERR_JACK_CLIENT_CREATION;
}

/* Initialise XRun Info */
xruns = 0;
jack_reset_max_delayed_usecs(Jack_Global_Client);

/* Get sample rate */
Sample_Rate = jack_get_sample_rate(Jack_Global_Client);

Expand Down Expand Up @@ -607,6 +620,15 @@ int effects_init(void)
Effects[i].lilv_instance = NULL;
}

jack_set_xrun_callback(Jack_Global_Client, &XRun, &xruns);

/* Try activate the Jack client, this is needed for the xrun callback */
if (jack_activate(Jack_Global_Client) != 0)
{
fprintf(stderr, "can't activate Jack_Global_Client\n");
return ERR_JACK_CLIENT_ACTIVATION;
}

return SUCCESS;
}

Expand Down Expand Up @@ -1251,3 +1273,12 @@ int effects_get_controls_symbols(int effect_id, char** symbols)

return SUCCESS;
}

int effects_get_xruns(int *number_of_xruns, float *max_delay)
{
*number_of_xruns = xruns;
*max_delay = jack_get_max_delayed_usecs (Jack_Global_Client);
RESET_ATOMIC(&xruns);
jack_reset_max_delayed_usecs(Jack_Global_Client);
return SUCCESS;
}
1 change: 1 addition & 0 deletions src/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int effects_get_parameter(int effect_id, const char *control_symbol, float *valu
int effects_monitor_parameter(int effect_id, const char *control_symbol, const char *op, float value);
int effects_bypass(int effect_id, int value);
int effects_get_controls_symbols(int effect_id, char** symbols);
int effects_get_xruns(int *number_of_xruns, float *max_delay);


/*
Expand Down
1 change: 1 addition & 0 deletions src/jack2
Submodule jack2 added at ec8403
19 changes: 18 additions & 1 deletion src/mod-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ static void effects_get_param_cb(proto_t *proto)
protocol_response(buffer, proto);
}

static void effects_get_xruns_cb(proto_t *proto)
{
int resp;
int number_of_xruns;
float max_delay;
resp = effects_get_xruns(&number_of_xruns, &max_delay);

char buffer[128];
if (resp >= 0)
sprintf(buffer, "resp %i %i %.01f", resp, number_of_xruns, max_delay);
else
sprintf(buffer, "resp %i", resp);

protocol_response(buffer, proto);
}

static void effects_monitor_param_cb(proto_t *proto)
{
int resp;
Expand Down Expand Up @@ -430,11 +446,12 @@ int main(int argc, char **argv)
protocol_add_command(EFFECT_REMOVE, effects_remove_cb);
protocol_add_command(EFFECT_CONNECT, effects_connect_cb);
protocol_add_command(EFFECT_DISCONNECT, effects_disconnect_cb);
protocol_add_command(EFFECT_BYPASS, effects_bypass_cb);
protocol_add_command(EFFECT_PARAM_SET, effects_set_param_cb);
protocol_add_command(EFFECT_PARAM_GET, effects_get_param_cb);
protocol_add_command(EFFECT_PARAM_MON, effects_monitor_param_cb);
protocol_add_command(MONITOR_ADDR_SET, monitor_addr_set_cb);
protocol_add_command(EFFECT_BYPASS, effects_bypass_cb);
protocol_add_command(EFFECT_XRUNS_GET, effects_get_xruns_cb);
protocol_add_command(LOAD_COMMANDS, load_cb);
protocol_add_command(SAVE_COMMANDS, save_cb);
protocol_add_command(HELP, help_cb);
Expand Down
3 changes: 2 additions & 1 deletion src/mod-host.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@
#define EFFECT_REMOVE "remove %i"
#define EFFECT_CONNECT "connect %s %s"
#define EFFECT_DISCONNECT "disconnect %s %s"
#define EFFECT_BYPASS "bypass %i %i"
#define EFFECT_PARAM_SET "param_set %i %s %f"
#define EFFECT_PARAM_GET "param_get %i %s"
#define EFFECT_PARAM_MON "param_monitor %i %s %s %f"
#define MONITOR_ADDR_SET "monitor %s %i %i"
#define EFFECT_BYPASS "bypass %i %i"
#define EFFECT_XRUNS_GET "xruns_get"
#define LOAD_COMMANDS "load %s"
#define SAVE_COMMANDS "save %s"
#define HELP "help"
Expand Down