Skip to content

Commit ec12df3

Browse files
committed
Extended python code to support embedding proxy
1 parent f0ec379 commit ec12df3

12 files changed

Lines changed: 289 additions & 9 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ sources/jvxLibraries/third_party/git/orc/orc
121121
/sources/jvxLibraries/third_party/git/tracy
122122
/bin/tools/sed
123123

124+
platform-packages/sc594/jvx-component-templates-min/Debug
125+
platform-packages/sc594/jvx-component-templates-min/Release
124126

125-
127+
platform-packages/sc594/jvx-system-min/Debug
128+
platform-packages/sc594/jvx-system-min/Release
126129

python/ayf/audioio/ayfaudioinwav.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ def prepare_single_frame(self, inBufHdl, frameIdx):
137137
def start(self, inBufHdl):
138138
return math.ceil( self.duration_samples/inBufHdl.params.bs)
139139

140-
def stop(self):
141-
# Do nothing
142-
print("Input processing complete")
140+
def stop(self) -> int: ...
141+
# Do nothing
143142

144143
def progress(self, inBufHdl: ayfbuf.ayfaudio_buf):
145144
return (self.fIdx* inBufHdl.params.bs)/ self.duration_samples

sources/jvxLibraries/ayf-embedding-proxy/src/ayf-embedding-proxy.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,13 @@ extern "C"
347347
if (consoleAttached)
348348
{
349349
#ifdef JVX_OS_WINDOWS
350+
/* The following may be dangerous on some systems: all following prints may crash. Therefore it is
351+
* good to control this via ini file!! */
350352
BOOL freeResult = FreeConsole();
351353
if (!freeResult)
352354
{
353355
DWORD lErr = GetLastError();
354-
}
356+
}
355357
#endif
356358
}
357359
consoleAttached = false;

sources/sub-projects/ayfstarter/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ if(NOT AYFSTARTER_USE_RUST_LIBS)
3434
)
3535
endif()
3636

37-
set(AYF_STARTER_STATIC_LIBS ${AYF_STARTER_STATIC_LIBS} ${CMAKE_CURRENT_SOURCE_DIR}/sources/Libraries/connect/ayf_connect-starter)
37+
set(AYF_STARTER_STATIC_LIBS ${AYF_STARTER_STATIC_LIBS}
38+
${CMAKE_CURRENT_SOURCE_DIR}/sources/Libraries/connect/ayf_connect-starter
39+
${CMAKE_CURRENT_SOURCE_DIR}/sources/Libraries/emb/ayf-starter-emb-host
40+
)
3841

3942
jvx_addSubdirs("Configuring static library for ayfstarter core functionality" "${AYF_STARTER_STATIC_LIBS}" "${JVX_FOLDER_HIERARCHIE_BASE}/Library")
4043

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
jvx_exclude_platform("Emscripten")
2+
3+
set(PROJECT_NAME ayf-starter-emb-host)
4+
include(${JVX_CMAKE_DIR}/common_local_lib_head.cmake)
5+
6+
set(AYFBINRENDER_HEADTRACKER_RS232 TRUE)
7+
set(AYFBINRENDER_HEADTRACKER_ART TRUE)
8+
9+
include_directories(
10+
${CMAKE_CURRENT_SOURCE_DIR}/include
11+
${CMAKE_CURRENT_SOURCE_DIR}/include/os-${JVX_OS}
12+
${CMAKE_CURRENT_BINARY_DIR}
13+
14+
${JVX_BASE_LIBS_INCLUDE_PATH}/jvx-host-json/include
15+
${JVX_BASE_BINARY_DIR}/sources/jvxMinHosts/jvxMHAppMinHostCon/
16+
17+
${JVX_BASE_BINARY_DIR}/sources/jvxTools/jvxTconfigProcessor
18+
19+
${JVX_BASE_LIBS_INCLUDE_PATH}/jvxLConsoleHost/include
20+
21+
${JVX_BASE_BINARY_DIR}/sources/jvxComponents/jvxAutomationComponents/ayfATTypical
22+
)
23+
24+
set(LOCAL_SOURCES
25+
${CMAKE_CURRENT_SOURCE_DIR}/target/ayf-setup-hooks.cpp
26+
${JVX_BASE_LIBS_INCLUDE_PATH}/ayf-shared-connection-emb-host/src/exports/${JVX_OS}/exports-connect-host.def
27+
${CMAKE_CURRENT_SOURCE_DIR}/install/ayf-proxy.ini.in
28+
29+
)
30+
31+
set(BUILD_SHARED TRUE)
32+
33+
# this changes the name of the output to be followed by "_import"
34+
# It does NOT produce an import lib in the SDK for all projects which
35+
# are compiled to form a runtime
36+
# set(JVX_FORCE_RUNTIME_IMPORTLIB TRUE)
37+
38+
# This allows to copy import lib (.lib file) to sdk also
39+
# set(JVX_SDK_FORCE_DEPLOY_IMPORT_STATIC_LIB TRUE)
40+
41+
set(LOCAL_LIBS
42+
43+
# We can either hookup the version with static or shared objects
44+
# jvxLConsoleHost-shared_static
45+
jvxLConsoleHost-static_static
46+
47+
ayf-shared-connection-emb-host_static
48+
ayfATTypical_static
49+
)
50+
51+
52+
# Note: this dll is installed in the runtime folder. This could also go to the AWE folder,
53+
# however, anyway, the proxy dll must be loaded first and is NOT located in the AWE folder
54+
# As a consequence, you need to add the runtime folder to the PATH environment
55+
## set(JVX_SHARED_LIB_TARGET_FOLDER "${AYF_AWE_SHARED_LIBRARY_TARGET_FOLDER}")
56+
57+
set(JVX_COMPONENT_DLLS_PATH "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_RELEASE_RUNTIME}/jvxComponents")
58+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/install/ayf-proxy.ini.in ${CMAKE_CURRENT_BINARY_DIR}/ayf-proxy.ini)
59+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ayf-proxy.ini" DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../../../Python/python/runtime)
60+
61+
include(${JVX_CMAKE_DIR}/common_local_lib_foot.cmake)
62+
63+
# message(FATAL_ERROR "Import lib")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Select host to be loaded
2+
# EMBEDDED_HOST=MIN
3+
EMBEDDED_HOST=EMB
4+
# EMBEDDED_HOST=NONE
5+
6+
# Define the name of the min host to be loaded
7+
DLL_MIN_HOST=ayf-shared-connection-min-host.dll
8+
DLL_EMB_HOST=ayf-starter-emb-host.dll
9+
10+
DLL_EMB_ARG=--config,jvxConfig.jvx,--jvxdir,@JVX_COMPONENT_DLLS_PATH@,--textlog,--verbose_dll,--textloglev,10,--no-quit,--startExe,ayf_awe\ayf_awe.exe,--startArgs,--httpAutoConnect
11+
12+
# Attach a new console window to review runtime output
13+
OPEN_CONSOLE=no
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include "interfaces/all-hosts/configHostFeatures_common.h"
2+
#include "ayfATTypical.h"
3+
4+
const jvxModuleOnStart componentsOnLoad_automation[] =
5+
{
6+
{"ayfATTypical",[](IjvxObject* obj) {
7+
IjvxProperties* props = reqInterfaceObj<IjvxProperties>(obj);
8+
if (props)
9+
{
10+
jvxCallManagerProperties callGate;
11+
jvxCBool flag = 1;
12+
jvxErrorType res = props->set_property(callGate, jPRFCBOOL(flag), jPAD("/audio/primary_audio_tech_lowlevel"));
13+
retInterfaceObj<IjvxProperties>(obj, props);
14+
}}},
15+
nullptr
16+
};
17+
18+
extern "C"
19+
{
20+
jvxErrorType jvx_configure_host_features(configureHost_features* features)
21+
{
22+
configureHost_features* theFeaturesCH = nullptr;
23+
features->request_specialization(reinterpret_cast<jvxHandle**>(&theFeaturesCH), JVX_HOST_IMPLEMENTATION_HOST);
24+
if (theFeaturesCH)
25+
{
26+
theFeaturesCH->numSlotsComponents[JVX_COMPONENT_SYSTEM_AUTOMATION] = 1;
27+
theFeaturesCH->flag_blockModuleEdit[JVX_COMPONENT_SYSTEM_AUTOMATION] = true;
28+
theFeaturesCH->lst_ModulesOnStart[JVX_COMPONENT_SYSTEM_AUTOMATION] = componentsOnLoad_automation;
29+
30+
}
31+
return(JVX_NO_ERROR);
32+
}
33+
34+
jvxErrorType jvx_invalidate_host_features(configureHost_features* features)
35+
{
36+
return(JVX_NO_ERROR);
37+
}
38+
39+
jvxErrorType jvx_access_link_objects(
40+
jvxInitObject_tp* funcInit,
41+
jvxTerminateObject_tp* funcTerm, jvxApiString* adescr,
42+
jvxComponentType tp, jvxSize id)
43+
{
44+
jvxSize cnt = 0;
45+
// std::cout << __FUNCTION__ << ", " << __FILE__ << "," << __LINE__ << ": Implementation in project." << std::endl;
46+
//
47+
switch (tp)
48+
{
49+
50+
case JVX_COMPONENT_SYSTEM_AUTOMATION:
51+
if (id == cnt)
52+
{
53+
adescr->assign("Typical Automation");
54+
*funcInit = ayfATTypical_init;
55+
*funcTerm = ayfATTypical_terminate;
56+
return(JVX_NO_ERROR);
57+
}
58+
cnt++;
59+
break;
60+
}
61+
// Default implementation does just nothing
62+
return(JVX_ERROR_ELEMENT_NOT_FOUND);
63+
}
64+
}
65+
66+
// ==========================================================================================================
67+
// ==========================================================================================================
68+
69+
#define JVX_NUMBER_DEFAULT_STEPS_SEQUENCER_2AUDIO_RUN 6
70+
static jvxOneSequencerStepDefinition defaultSteps_2audio_run[JVX_NUMBER_DEFAULT_STEPS_SEQUENCER_2AUDIO_RUN] =
71+
{
72+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_COMMAND_PROCESS_PREPARE, JVX_COMPONENT_UNKNOWN, JVX_SIZE_DONTCARE, JVX_SIZE_DONTCARE, "Prepare all connections", "PrepConnections", 0, 1000, "*", "no label" },
73+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_CALLBACK, JVX_COMPONENT_UNKNOWN, 0, 0, "Callback after all prepared", "AfterAllPrep", 0, 1000, "no label", "no label" },
74+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_COMMAND_PROCESS_START, JVX_COMPONENT_UNKNOWN, JVX_SIZE_DONTCARE, JVX_SIZE_DONTCARE, "Start all connections", "StartConnections", 0, 1000, "*", "no label" },
75+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_CALLBACK, JVX_COMPONENT_UNKNOWN, 0, 0, "Callback after all started", "AfterAllStarted", 1, 1000, "no label", "no label" },
76+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_REQUEST_UPDATE_VIEWER, JVX_COMPONENT_UNKNOWN, 0, 0, "Update Viewer", "UpdateViewer", 0, 1000, "no label", "no label" },
77+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_WAIT_AND_RUN_TASKS, JVX_COMPONENT_UNKNOWN, 0, 0, "Wait and run tasks", "WaitRun", 0, -1, "no label", "no label" }
78+
};
79+
80+
#define JVX_NUMBER_DEFAULT_STEPS_SEQUENCER_2AUDIO_LEAVE 5
81+
static jvxOneSequencerStepDefinition defaultSteps_2audio_leave[JVX_NUMBER_DEFAULT_STEPS_SEQUENCER_2AUDIO_LEAVE] =
82+
{
83+
{ JVX_SEQUENCER_QUEUE_TYPE_LEAVE, JVX_SEQUENCER_TYPE_CALLBACK, JVX_COMPONENT_UNKNOWN, 0, 0, "Callback before all stop", "BeforeAllStop", 16, 1000, "no label", "no label" },
84+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_COMMAND_PROCESS_STOP, JVX_COMPONENT_UNKNOWN, JVX_SIZE_DONTCARE, JVX_SIZE_DONTCARE, "Stop all connections", "StopConnections", 0, 1000, "*", "no label" },
85+
{ JVX_SEQUENCER_QUEUE_TYPE_LEAVE, JVX_SEQUENCER_TYPE_CALLBACK, JVX_COMPONENT_UNKNOWN, 0, 0, "Callback before all postprocess", "BeforeAllPost", 17, 1000, "no label", "no label" },
86+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_COMMAND_PROCESS_POSTPROCESS, JVX_COMPONENT_UNKNOWN, JVX_SIZE_DONTCARE, JVX_SIZE_DONTCARE, "Postprocess all connections", "PostProcessConnections", 0, 1000, "*", "no label" },
87+
{ JVX_SEQUENCER_QUEUE_TYPE_RUN, JVX_SEQUENCER_TYPE_REQUEST_UPDATE_VIEWER, JVX_COMPONENT_UNKNOWN, 0, 0, "Update Viewer", "UpdateViewer", 0, 1000, "no label", "no label" },
88+
};
89+
extern "C"
90+
{
91+
jvxErrorType jvx_default_sequence_add(IjvxSequencer* theSeq)
92+
{
93+
// std::cout << __FUNCTION__ << ": Custom sequencer hook function, located in " << __FILE__ << std::endl;
94+
95+
jvxErrorType res = JVX_NO_ERROR;
96+
// featuresA->useDefaultStepsOnlyIfNoneConfig = false;
97+
// featuresA->nm_default_seq = "jvxInspireSequencerSet";
98+
99+
res = jvx_add_default_sequence_sequencer(theSeq,
100+
false,
101+
defaultSteps_2audio_run, JVX_NUMBER_DEFAULT_STEPS_SEQUENCER_2AUDIO_RUN,
102+
defaultSteps_2audio_leave, JVX_NUMBER_DEFAULT_STEPS_SEQUENCER_2AUDIO_LEAVE,
103+
"default sequencer spec 2 audio");
104+
105+
return res;
106+
};
107+
}

sources/sub-projects/ayfstarter/sources/Python/python/runtime/test-ayf-starter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self):
2929
self.hdl = None
3030

3131
def prepare(self, numIn = 1, numOut = 1, bSize = 128, sRate = 48000):
32-
self.hdl = ayf_starter_python.init_ayf_starter(numIn, numOut, bSize, sRate, int(-2), int(-2))
32+
self.hdl = ayf_starter_python.init_ayf_starter(numIn, numOut, bSize, sRate, int(-2), int(-2), "ayf-proxy.ini")
3333
return 0
3434

3535
# @abstractmethod
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import sys
2+
import os
3+
import numpy as np
4+
5+
# Better use the pylab plot as it shows also in debugger!
6+
import pylab as plt
7+
# from matplotlib import pyplot as plt
8+
9+
# Import the local references. This is a different version in the release
10+
# compared to the "released" version
11+
import local
12+
13+
sys.path.append('@AYF_PYTHON_PACKAGES@/ayf/audioio')
14+
15+
import ayf_starter_python
16+
import ayfaudioio as ayfio
17+
import ayfaudioproc as ayfproc
18+
import ayfaudiobuf as ayfbuf
19+
20+
## ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
21+
## This file with the .in extension is the basis for code generation. Therefore the
22+
## same file without .in extension should not be edited. Otherwise the changes may
23+
## be lost in case the C-part is rebuilt!
24+
## ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
25+
26+
class myProcessor(ayfproc.ayfaudio_processor):
27+
28+
def __init__(self):
29+
self.hdl = None
30+
31+
def prepare(self, numIn = 1, numOut = 1, bSize = 128, sRate = 48000):
32+
self.hdl = ayf_starter_python.init_ayf_starter(numIn, numOut, bSize, sRate, int(-2), int(-2), "ayf-proxy.ini")
33+
return 0
34+
35+
# @abstractmethod
36+
def process(self, inBuf: ayfbuf.ayfaudio_buf, outBuf: ayfbuf.ayfaudio_buf):
37+
38+
# Run core function
39+
res = ayf_starter_python.run_frame_ayf_starter(self.hdl, inBuf.params.chans, outBuf.params.chans, inBuf.params.bs, inBuf.fld, outBuf.fld)
40+
return res
41+
42+
# @abstractmethod
43+
def postprocess(self) :
44+
res = ayf_starter_python.term_ayf_starter(self.hdl)
45+
return res
46+
47+
# =================================================================================
48+
# =================================================================================
49+
50+
if __name__ == "__main__":
51+
52+
# Declare some processing parameters
53+
fsize = int(1024)
54+
nChansIn = int(1)
55+
nChansOut = int(1)
56+
srate = int(48000)
57+
58+
# Output the current process id to identify process in VS
59+
print("PID:", os.getpid())
60+
61+
# Print out the help text
62+
# help(ayf_starter_python)
63+
64+
### Convert into interleaved
65+
# ininter = np.ascontiguousarray(oneBuf).ravel(order="C")
66+
67+
### From interleaved to no-interleaved
68+
# oneBuf = np.ascontiguousarray(outinter.reshape(fsize, nChansOut).T)
69+
fwk = ayfio.ayfaudio(numIn = nChansIn, numOut = nChansOut, bSize = fsize, sRate = srate, operStr = 'INTERLEAVED', format = 'double')
70+
pp = myProcessor()
71+
72+
# Prepare source and sink
73+
fwk.prepare(source = 'test.wav', sink = 'out.wav')
74+
75+
# Framing loop
76+
fwk.run(pp)
77+
78+
# Processing done
79+
fwk.postprocess()
80+
81+
# Take out the data
82+
dat = fwk.output_data()
83+
84+
# Output result
85+
plt.plot(dat)
86+
plt.show()
87+
88+
print("Done!")

sources/sub-projects/ayfstarter/sources/Python/src/ayf_starter_python.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ extern "C"
1212
{
1313
}
1414

15-
void* init_ayf_starter(int nChannelsIn, int nChannelsOut, int fsize, int samplerate, int ayfIdentSlot_node, int ayfIdentSlot_dev)
15+
void* init_ayf_starter(int nChannelsIn, int nChannelsOut, int fsize, int samplerate, int ayfIdentSlot_node, int ayfIdentSlot_dev, const char* nmIniFile)
1616
{
1717
jvxErrorType res = JVX_NO_ERROR;
1818

1919
struct ayfInitConnectStruct initStr;
2020
ayfInitConnectStruct_init(&initStr, ayfIdentSlot_node, ayfIdentSlot_dev);
2121
initStr.fptr = cb_ayf_started;
2222
initStr.priv = nullptr;
23+
initStr.fNameIniPtr = nmIniFile;
2324

2425
struct ayfInitParamStruct paramStr;
2526
ayfInitParamStruct_init(&paramStr, nChannelsIn,

0 commit comments

Comments
 (0)