I started developing a simple guitar looper using C++ in windows 10 by using the jackaudio's api. I am no really sure if starting and closing the server should be implemented by using the API functions, but since I found it convenient to both start the server and set the parameters with a single command, I made a script for it.
ECHO HELLO JACK!
cd C:\Program Files\JACK2
jackd.exe -S -X winmme -v -r -t10000 -dportaudio -d"ASIO::ASIO4ALL v2" -r44100 -p512
:: /jackd.exe -S -X winmme -v -t10000 -dportaudio -d"ASIO::Komplete Audio 6" -r44100 -p512 this is for when audio interface is selected. Not used in this script.
PAUSE
While developing, the way of testing my code was to compile it, and before start running it, I had to start the server first, which in most cases I preferred to do it using the qjackctl. However this way proved to be error prone since lots of issues has occurred, especially when "the appropriate way of shutting down the server" comes in. For instance, stopping the server via qjackctl forces my running program to exit normaly, but closing my running program without having stoped the server corrupts jack-audio behavior, ie. qjackctl sometimes hangs, crashes, and even if I restart my computer, or ever reinstall jack doesn't resolve the issue.
The log window messages are the following…
12:19:37.459 JACK was started with PID=8044.
jackdmp 1.9.17
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2016 Grame.
Copyright 2016-2021 Filipe Coelho.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
Drivers/internals found in : C:\Program Files\JACK2
Drivers/internals found in : C:\Program Files\JACK2
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
…then it stays there, and sometimes after 20~30 seconds (some others don’t – if freezes there forever.) it prints:
BDB1546 unable to join the environment
cannot open DB environment: Resource temporarily unavailable
Jack: JackWinThread::StartImp : create non RT thread
Jack: JackWinThread::ThreadHandler : start
Jack: Initializing PortAudio...
BDB1546 unable to join the environment
cannot open DB environment: Resource temporarily unavailable
Cannot connect to named pipe after wait = \\.\pipe\server_jack_default_0 err = 2
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
jack_deactivate called with a NULL client
jack_deactivate called with a NULL client
jack_client_close called with a NULL client
Jack: JackPortAudioDriver::Open nframes = 512 in = 0 out = 0 capture name = ASIO::ASIO4ALL v2 playback name = ASIO::ASIO4ALL v2 samplerate = 44100
Jack: JackDriver::Open capture_driver_name = ASIO::ASIO4ALL v2
Jack: JackDriver::Open playback_driver_name = ASIO::ASIO4ALL v2
Jack: Check protocol client = 8 server = 8
Jack: JackEngine::ClientInternalOpen: name = system
Jack: JackEngine::AllocateRefNum ref = 0
Jack: JackWinSemaphore::Allocate name = jack_pipe.default_system val = 0
Jack: JackEngine::NotifyAddClient: name = system
Jack: JackGraphManager::SetBufferSize size = 512
Jack: JackConnectionManager::DirectConnect first: ref1 = 0 ref2 = 0
Jack: JackGraphManager::ConnectRefNum cur_index = 0 ref1 = 0 ref2 = 0
Jack: JackDriver::SetupDriverSync driver sem in normal mode
Jack: JackPortAudioDriver::Open fInputDevice = 8, fOutputDevice 8
Jack: JackPortAudioDriver::Open setup max in channels = 2
Jack: JackPortAudioDriver::Open setup max out channels = 2
Jack: JackPortAudioDriver::OpenStream buffer_size = 512
Jack: JackWinNamedPipeServerChannel::Open
Jack: JackWinNamedPipeServer::BindAux : fName \\.\pipe\server_jack_default_0
Jack: JackEngine::Open
Jack: JackWinNamedPipeClient::ConnectAux : fName \\.\pipe\server_jack_default_0
Jack: JackEngine::ClientInternalOpen: name = freewheel
Jack: JackEngine::AllocateRefNum ref = 1
Jack: JackWinSemaphore::Allocate name = jack_pipe.default_freewheel val = 0
Jack: JackEngine::NotifyAddClient: name = freewheel
Jack: JackDriver::ClientNotify ref = 1 driver = system name = freewheel notify = 0
Jack: JackDriver::ClientNotify ref = 0 driver = freewheel name = system notify = 0
Jack: JackConnectionManager::DirectConnect first: ref1 = 1 ref2 = 1
Jack: JackGraphManager::ConnectRefNum cur_index = 0 ref1 = 1 ref2 = 1
Jack: JackDriver::SetupDriverSync driver sem in normal mode
Jack: JackAudioDriver::Attach fBufferSize = 512 fSampleRate = 44100
Jack: JackEngine::PortRegister ref = 0 name = system:capture_1 type = 32 bit float mono audio flags = 22 buffer_size = 512
Jack: JackGraphManager::AllocatePortAux port_index = 1 name = system:capture_1 type = 32 bit float mono audio
Jack: JackConnectionManager::AddOutputPort ref = 0 port = 1
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackAudioDriver::Attach fCapturePortList[i] port_index = 1
Jack: JackEngine::PortRegister ref = 0 name = system:capture_2 type = 32 bit float mono audio flags = 22 buffer_size = 512
Jack: JackGraphManager::AllocatePortAux port_index = 2 name = system:capture_2 type = 32 bit float mono audio
Jack: JackConnectionManager::AddOutputPort ref = 0 port = 2
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackAudioDriver::Attach fCapturePortList[i] port_index = 2
Jack: JackEngine::PortRegister ref = 0 name = system:playback_1 type = 32 bit float mono audio flags = 21 buffer_size = 512
Jack: JackGraphManager::AllocatePortAux port_index = 3 name = system:playback_1 type = 32 bit float mono audio
Jack: JackConnectionManager::AddInputPort ref = 0 port = 3
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackAudioDriver::Attach fPlaybackPortList[i] port_index = 3
Jack: JackEngine::PortRegister ref = 0 name = system:playback_2 type = 32 bit float mono audio flags = 21 buffer_size = 512
Jack: JackGraphManager::AllocatePortAux port_index = 4 name = system:playback_2 type = 32 bit float mono audio
Jack: JackConnectionManager::AddInputPort ref = 0 port = 4
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackEngine::ClientNotify: no callback for notification = 9
Jack: JackAudioDriver::Attach fPlaybackPortList[i] port_index = 4
Jack: InitTime : multimedia timer resolution set to 1 milliseconds
Jack: JackServer::IsRunning
Jack: JackWinMMEDriver::Open - num_potential_inputs 0
Jack: JackWinMMEDriver::Open - num_potential_outputs 1
Jack: JackWinMMEDriver::Open - multimedia timer resolution set to 1 milliseconds.
JackWinMMEDriver::Open - while creating output port: Undefined external error. | winmme, system_midi, out
Jack: JackWinMMEDriver::Open - input_count 0
Jack: JackWinMMEDriver::Open - output_count 0
Jack: JackDriver::Open capture_driver_name = in
Jack: JackDriver::Open playback_driver_name = out
Jack: Check protocol client = 8 server = 8
Jack: JackEngine::ClientInternalOpen: name = system_midi
Jack: JackEngine::AllocateRefNum ref = 2
Jack: JackWinSemaphore::Allocate name = jack_pipe.default_system_midi val = 0
Jack: JackEngine::NotifyAddClient: name = system_midi
Jack: JackDriver::ClientNotify ref = 2 driver = system name = system_midi notify = 0
Jack: JackDriver::ClientNotify ref = 0 driver = system_midi name = system notify = 0
Jack: JackDriver::ClientNotify ref = 2 driver = freewheel name = system_midi notify = 0
Jack: JackDriver::ClientNotify ref = 1 driver = system_midi name = freewheel notify = 0
Jack: JackGraphManager::SetBufferSize size = 512
Jack: JackConnectionManager::DirectConnect first: ref1 = 2 ref2 = 2
Jack: JackGraphManager::ConnectRefNum cur_index = 0 ref1 = 2 ref2 = 2
Jack: JackDriver::SetupDriverSync driver sem in normal mode
Jack: JackWinMMEDriver::Attach - fCaptureChannels 0
Jack: JackWinMMEDriver::Attach - fPlaybackChannels 0
Jack: JackServer::Start
Jack: JackPortAudioDriver::Start
Jack: JackWinMMEDriver::Start - Starting driver.
Jack: JackWinMMEDriver::Start - Enabling input ports.
Jack: JackWinMMEDriver::Start - Enabling output ports.
Jack: JackWinMMEDriver::Start - Driver started.
Jack: JackWinThread::StartImp : create non RT thread
Jack: JackWinThread::ThreadHandler : start
Jack: JackWinNamedPipeServerChannel::Init
Jack: JackWinNamedPipeServerChannel::ClientAdd size 0
Jack: JackWinThread::StartImp : create non RT thread
Jack: JackWinNamedPipeServer::BindAux : fName \\.\pipe\server_jack_default_0
Jack: JackWinThread::ThreadHandler : start
Jack: JackClientPipeThread::Execute 2c272f0
Jack: JackRequest::Notification
Jack: JackDriver::ClientNotify ref = 1 driver = freewheel name = freewheel notify = 18
Jack: JackDriver::ClientNotify ref = 1 driver = freewheel name = freewheel notify = 18
Jack: JackDriver::ClientNotify ref = 1 driver = freewheel name = freewheel notify = 18
Jack: JackDriver::ClientNotify ref = 1 driver = freewheel name = freewheel notify = 18
Jack: JackEngine::ClientNotify: no callback for notification = 4
Jack: JackEngine::ClientNotify: no callback for notification = 4
Jack: JackEngine::ClientNotify: no callback for notification = 4
Jack: JackClientPipeThread::Execute 2c272f0
And despite the fact that it seems to have started, a qjackctl notification window appears with the message:
Could not connect to Jack server as client.
-Overall operation failed.
-Unable to connect to server.
Please check the messages window for more info.
Without pressing “Cancel”, once in twice I am able to have my program running, just like as if the server functioned normally, and pressing “Cancel” makes the server stop. But only once between two recurrent attempts. As for code, I also tested ready-to-use examples from jack audio docs, to check if any difference will be noticed but nothing.
I am really clueless of how to debug this, since most solutions found in the internet are concerning Linux environment and apart from that, I find my implementation practice anorthodox , and I am pretty sure that I probably have to get my hands dirty with the API commands instead of searching for a ready to use- scripting solutions. However, debugging the server comes first for now.
so If anyone has an idea of how should I make jack server running appropriately again it would be great!
EDIT 10 minutes after posting the question, I managed to debug this, however I leave the post open, so as to help others that face a similar issue. The solution that worked for me is by running the following C++ code modified by the server_control example:
#include <iostream>
#include <jack/jack.h>
#include <jack/types.h>
#include <jack/control.h>
static jackctl_driver_t * jackctl_server_get_driver(jackctl_server_t *server, const char *driver_name)
{
const JSList * node_ptr = jackctl_server_get_drivers_list(server);
while (node_ptr) {
if (strcmp(jackctl_driver_get_name((jackctl_driver_t *)node_ptr->data), driver_name) == 0) {
return (jackctl_driver_t *)node_ptr->data;
}
node_ptr = jack_slist_next(node_ptr);
}
return NULL;
}
int main(int argc, char *argv[])
{
jackctl_server_t * server;
const char* driver_name = "portaudio";//You could probably change the driver name accordingly
server = jackctl_server_create2(NULL, NULL, NULL);
jackctl_server_open(server, jackctl_server_get_driver(server, driver_name));
jackctl_server_start(server);
jackctl_server_stop(server);
jackctl_server_close(server);
jackctl_server_destroy(server);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire