Commit c41c5f12 authored by sletz's avatar sletz
Browse files

Fix JackFrameTimer::Time2Frames and JackTimer::Frames2Time, jack_cpu compiled again.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2768 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 9221bc14
......@@ -22,6 +22,10 @@ Florian Faber
Jackdmp changes log
---------------------------
2008-08-03 Stephane Letz <letz@grame.fr>
* Fix JackFrameTimer::Time2Frames and JackTimer::Frames2Time, jack_cpu compiled again.
2008-08-01 Stephane Letz <letz@grame.fr>
* Fix desallocation of remaining clients when server quits.
......
......@@ -68,9 +68,9 @@ namespace Jack
#define ALL_CLIENTS -1 // for notification
#if defined(__ppc64__) || defined(__x86_64__)
#define JACK_PROTOCOL_VERSION 5
#define JACK_PROTOCOL_VERSION 6
#else
#define JACK_PROTOCOL_VERSION 4
#define JACK_PROTOCOL_VERSION 5
#endif
#define SOCKET_TIME_OUT 5 // in sec
......
......@@ -116,13 +116,13 @@ namespace Jack
jack_nframes_t Time2Frames(jack_time_t time)
{
long delta = (long) rint(((double) (long(time - fCurrentWakeup)) / ((jack_time_t)(fNextWakeUp - fCurrentWakeup))) * fBufferSize);
long delta = (long) rint(((double) ((long long)(time - fCurrentWakeup)) / ((long long)(fNextWakeUp - fCurrentWakeup))) * fBufferSize);
return (delta < 0) ? ((fFrames > 0) ? fFrames : 1) : (fFrames + delta);
}
jack_time_t Frames2Time(jack_nframes_t frames)
{
long delta = (long) rint(((double) (long(frames - fFrames)) * ((jack_time_t)(fNextWakeUp - fCurrentWakeup))) / fBufferSize);
long delta = (long) rint(((double) ((long long)(frames - fFrames)) * ((long long)(fNextWakeUp - fCurrentWakeup))) / fBufferSize);
return (delta < 0) ? ((fCurrentWakeup > 0) ? fCurrentWakeup : 1) : (fCurrentWakeup + delta);
}
......
......@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackFrameTimer.h"
#include "JackError.h"
#include <math.h>
#include <stdio.h>
namespace Jack
{
......@@ -53,7 +54,7 @@ JackTimer::JackTimer()
jack_nframes_t JackTimer::Time2Frames(jack_time_t time, jack_nframes_t buffer_size)
{
if (fInitialized) {
return fFrames + (long)rint(((double) ((time - fCurrentWakeup)) / ((jack_time_t)(fNextWakeUp - fCurrentWakeup))) * buffer_size);
return fFrames + (long)rint(((double) ((long long)(time - fCurrentWakeup)) / ((long long)(fNextWakeUp - fCurrentWakeup))) * buffer_size);
} else {
return 0;
}
......@@ -62,7 +63,7 @@ jack_nframes_t JackTimer::Time2Frames(jack_time_t time, jack_nframes_t buffer_si
jack_time_t JackTimer::Frames2Time(jack_nframes_t frames, jack_nframes_t buffer_size)
{
if (fInitialized) {
return fCurrentWakeup + (long)rint(((double) ((frames - fFrames)) * ((jack_time_t)(fNextWakeUp - fCurrentWakeup))) / buffer_size);
return fCurrentWakeup + (long)rint(((double) ((long long)(frames - fFrames)) * ((long long)(fNextWakeUp - fCurrentWakeup))) / buffer_size);
} else {
return 0;
}
......@@ -115,6 +116,8 @@ void JackFrameTimer::ReadFrameTime(JackTimer* timer)
cur_index = next_index;
memcpy(timer, ReadCurrentState(), sizeof(JackTimer));
next_index = GetCurrentIndex();
if (cur_index != next_index)
printf("JackFrameTimer::ReadFrameTime loop\n");
} while (cur_index != next_index); // Until a coherent state has been read
}
......
......@@ -130,7 +130,8 @@ struct JackClientCheckRequest : public JackRequest
JackClientCheckRequest()
{}
JackClientCheckRequest(const char* name, int protocol, int options): JackRequest(JackRequest::kClientCheck), fProtocol(protocol), fOptions(options)
JackClientCheckRequest(const char* name, int protocol, int options)
: JackRequest(JackRequest::kClientCheck), fProtocol(protocol), fOptions(options)
{
snprintf(fName, sizeof(fName), "%s", name);
}
......@@ -293,7 +294,8 @@ struct JackActivateRequest : public JackRequest
JackActivateRequest()
{}
JackActivateRequest(int refnum, int state): JackRequest(JackRequest::kActivateClient), fRefNum(refnum), fState(state)
JackActivateRequest(int refnum, int state)
: JackRequest(JackRequest::kActivateClient), fRefNum(refnum), fState(state)
{}
int Read(JackChannelTransaction* trans)
......@@ -419,7 +421,8 @@ struct JackPortUnRegisterRequest : public JackRequest
JackPortUnRegisterRequest()
{}
JackPortUnRegisterRequest(int refnum, int index): JackRequest(JackRequest::kUnRegisterPort), fRefNum(refnum), fPortIndex(index)
JackPortUnRegisterRequest(int refnum, int index)
: JackRequest(JackRequest::kUnRegisterPort), fRefNum(refnum), fPortIndex(index)
{}
int Read(JackChannelTransaction* trans)
......@@ -451,7 +454,8 @@ struct JackPortConnectNameRequest : public JackRequest
JackPortConnectNameRequest()
{}
JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name): JackRequest(JackRequest::kConnectNamePorts), fRefNum(refnum)
JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name)
: JackRequest(JackRequest::kConnectNamePorts), fRefNum(refnum)
{
strcpy(fSrc, src_name);
strcpy(fDst, dst_name);
......@@ -489,7 +493,8 @@ struct JackPortDisconnectNameRequest : public JackRequest
JackPortDisconnectNameRequest()
{}
JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name): JackRequest(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name)
: JackRequest(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
{
strcpy(fSrc, src_name);
strcpy(fDst, dst_name);
......@@ -526,7 +531,8 @@ struct JackPortConnectRequest : public JackRequest
JackPortConnectRequest()
{}
JackPortConnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst): JackRequest(JackRequest::kConnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
JackPortConnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst)
: JackRequest(JackRequest::kConnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
{}
int Read(JackChannelTransaction* trans)
......@@ -561,7 +567,8 @@ struct JackPortDisconnectRequest : public JackRequest
JackPortDisconnectRequest()
{}
JackPortDisconnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst): JackRequest(JackRequest::kDisconnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
JackPortDisconnectRequest(int refnum, jack_port_id_t src, jack_port_id_t dst)
: JackRequest(JackRequest::kDisconnectPorts), fRefNum(refnum), fSrc(src), fDst(dst)
{}
int Read(JackChannelTransaction* trans)
......@@ -594,7 +601,8 @@ struct JackSetBufferSizeRequest : public JackRequest
JackSetBufferSizeRequest()
{}
JackSetBufferSizeRequest(jack_nframes_t buffer_size): JackRequest(JackRequest::kSetBufferSize), fBufferSize(buffer_size)
JackSetBufferSizeRequest(jack_nframes_t buffer_size)
: JackRequest(JackRequest::kSetBufferSize), fBufferSize(buffer_size)
{}
int Read(JackChannelTransaction* trans)
......@@ -620,7 +628,8 @@ struct JackSetFreeWheelRequest : public JackRequest
JackSetFreeWheelRequest()
{}
JackSetFreeWheelRequest(int onoff): JackRequest(JackRequest::kSetFreeWheel), fOnOff(onoff)
JackSetFreeWheelRequest(int onoff)
: JackRequest(JackRequest::kSetFreeWheel), fOnOff(onoff)
{}
int Read(JackChannelTransaction* trans)
......@@ -646,7 +655,8 @@ struct JackReleaseTimebaseRequest : public JackRequest
JackReleaseTimebaseRequest()
{}
JackReleaseTimebaseRequest(int refnum): JackRequest(JackRequest::kReleaseTimebase), fRefNum(refnum)
JackReleaseTimebaseRequest(int refnum)
: JackRequest(JackRequest::kReleaseTimebase), fRefNum(refnum)
{}
int Read(JackChannelTransaction* trans)
......@@ -673,7 +683,8 @@ struct JackSetTimebaseCallbackRequest : public JackRequest
JackSetTimebaseCallbackRequest()
{}
JackSetTimebaseCallbackRequest(int refnum, int conditional): JackRequest(JackRequest::kSetTimebaseCallback), fRefNum(refnum), fConditionnal(conditional)
JackSetTimebaseCallbackRequest(int refnum, int conditional)
: JackRequest(JackRequest::kSetTimebaseCallback), fRefNum(refnum), fConditionnal(conditional)
{}
int Read(JackChannelTransaction* trans)
......
......@@ -36,14 +36,12 @@ jack_port_t *input_port;
jack_port_t *output_port;
jack_client_t *client;
unsigned long sr;
int idle_time = 0;
jack_nframes_t idle_time = 0;
int percent_cpu = 0;
int time_to_run = 0;
int time_before_run = 0;
int time_before_exit = 1;
jack_nframes_t cur_buffer_size;
jack_nframes_t start_frame;
jack_nframes_t cur_frame;
/* a simple state machine for this client */
volatile enum {
......@@ -63,12 +61,12 @@ void usage()
);
}
JackBufferSizeCallback update_buffer_size()
int update_buffer_size(jack_nframes_t nframes, void *arg)
{
cur_buffer_size = jack_get_buffer_size(client);
cur_buffer_size = nframes;
printf("Buffer size = %d \n", cur_buffer_size);
idle_time = (int) (cur_buffer_size * percent_cpu / 100);
printf("CPU load applies as %d sample delay.\n",idle_time);
idle_time = (jack_nframes_t) (cur_buffer_size * percent_cpu / 100);
printf("CPU load applies as %d sample delay.\n", idle_time);
return 0;
}
......@@ -76,30 +74,29 @@ JackBufferSizeCallback update_buffer_size()
* The process callback for this JACK application is called in a
* special realtime thread once for each audio cycle.
*
* This client follows a simple rule: when the JACK transport is
* running, copy the input port to the output. When it stops, exit.
*/
int process(jack_nframes_t nframes, void *arg)
{
jack_default_audio_sample_t *in, *out;
start_frame = jack_frame_time(client);
jack_nframes_t start_frame = jack_frame_time(client);
in = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port, nframes);
out = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port, nframes);
memset(out, 0, sizeof (jack_default_audio_sample_t) * nframes);
while ((client_state == Run) && (jack_frame_time(client) < (start_frame + idle_time))) {}
return 0;
return 0;
}
/**
* JACK calls this shutdown_callback if the server ever shuts down or
* decides to disconnect the client.
*/
void jack_shutdown(void *arg)
{
printf("Jack_cpu has been kicked out by jackd !");
printf("Jack_cpu has been kicked out by jackd !\n");
exit (1);
}
......@@ -108,6 +105,7 @@ int main(int argc, char *argv[])
const char **ports;
const char *client_name;
int got_time = 0;
jack_status_t status;
int option_index;
int opt;
......@@ -154,12 +152,18 @@ int main(int argc, char *argv[])
/* open a client connection to the JACK server */
client = jack_client_new(client_name);
client = jack_client_open (client_name, JackNoStartServer, &status);
if (client == NULL) {
fprintf(stderr, "jack_client_open() failed : is jack server running ?\n");
exit(1);
}
cur_buffer_size = jack_get_buffer_size(client);
printf("engine buffer size = %d \n", cur_buffer_size);
printf("engine sample rate: %d Hz\n", jack_get_sample_rate(client));
idle_time = (jack_nframes_t) (cur_buffer_size * percent_cpu / 100);
printf("CPU load applies as %d sample delay.\n", idle_time);
/* tell the JACK server to call `process()' whenever
there is work to be done.
......@@ -174,12 +178,6 @@ int main(int argc, char *argv[])
jack_on_shutdown(client, jack_shutdown, 0);
/* display the current sample rate.
*/
printf("engine sample rate: %d Hz\n", jack_get_sample_rate(client));
printf("computing time in samples : %d \n", idle_time);
/* create two ports */
input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
......@@ -191,13 +189,11 @@ int main(int argc, char *argv[])
exit(1);
}
if (jack_set_buffer_size_callback(client, update_buffer_size(), 0) != 0) {
if (jack_set_buffer_size_callback(client, update_buffer_size, 0) != 0) {
printf("Error when calling buffer_size_callback !");
return -1;
}
if (time_before_run == 0)
client_state = Run;
/* Tell the JACK server that we are ready to roll. Our
* process() callback will start running now. */
......
......@@ -2,11 +2,12 @@
# encoding: utf-8
test_programs = {
'synchroClient': ['testSynchroClient.cpp'],
'synchroServer': ['testSynchroServer.cpp'],
'synchroServerClient': ['testSynchroServerClient.cpp'],
#'synchroClient': ['testSynchroClient.cpp'],
#'synchroServer': ['testSynchroServer.cpp'],
#'synchroServerClient': ['testSynchroServerClient.cpp'],
'testSem': ['testSem.cpp'],
'jack_test': ['jack_test.cpp'],
'jack_cpu': ['jack_cpu.c'],
}
def build(bld):
......@@ -23,5 +24,5 @@ def build(bld):
prog.env.append_value("LINKFLAGS", "")
prog.uselib_local = 'clientlib'
prog.target = test_program
if test_program != 'jack_test':
prog.inst_var = 0
#if test_program != 'jack_test':
# prog.inst_var = 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment