Skip to content
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

Fix vtl tract sequence to ema and mesh #53

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/matlab_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set path to correct runtime lib so MATLAB does not use an outdated one
run: echo 'LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6' >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Add MSBuild to PATH
uses: microsoft/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.10"
# We need blender to run example 6
Expand Down
4 changes: 3 additions & 1 deletion include/VocalTractLabApi/VocalTractLabApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ C_EXPORT int vtlGesturalScoreToEma(const char *gestureFileName, const char *emaF
// Lower Cover (JAW) = 148)
// o filePath: path leading to the directory where EMA and mesh files shall be stored.
// o fileName: name of all exported datasets
// o frameSamplingRate: sampling rate of the frames, i. e. how many frames are in one second
//
// The return value is 0 if successful, and otherwise an error code >= 1.
// Error codes:
Expand All @@ -668,9 +669,10 @@ C_EXPORT int vtlGesturalScoreToEma(const char *gestureFileName, const char *emaF
// 8: EMA file already exists: prevents overwriting
// 9: EMA file could not be opened
// 10: API has not been initialized
// 11: frameSamplingRate <= 0.0
// ****************************************************************************

C_EXPORT int vtlTractSequenceToEmaAndMesh(double *tractParams, double *glottisParams, int numTractParams, int numGlottisParams, int numFrames, int numEmaPoints, int *surf, int *vert, const char *filePath, const char *fileName);
C_EXPORT int vtlTractSequenceToEmaAndMesh(double *tractParams, double *glottisParams, int numTractParams, int numGlottisParams, int numFrames, int numEmaPoints, int *surf, int *vert, const char *filePath, const char *fileName, double frameSamplingRate);


// ****************************************************************************
Expand Down
15 changes: 12 additions & 3 deletions src/VocalTractLabApi/VocalTractLabApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,7 @@ int vtlGesturalScoreToEma(const char *gestureFileName, const char *emaFileName)
// Lower Cover (JAW) = 148)
// o filePath: path leading to the directory where EMA and mesh files shall be stored.
// o fileName: name of all exported datasets
// o frameSamplingRate: sampling rate of the frames, i. e. how many frames are in one second
//
// The return value is 0 if successful, and otherwise an error code >= 1.
// Error codes:
Expand All @@ -1933,9 +1934,10 @@ int vtlGesturalScoreToEma(const char *gestureFileName, const char *emaFileName)
// 8: EMA file already exists: prevents overwriting
// 9: EMA file could not be opened
// 10: API has not been initialized
// 11: frameSamplingRate <= 0.0
// ****************************************************************************

int vtlTractSequenceToEmaAndMesh(double *tractParams, double *glottisParams, int numTractParams, int numGlottisParams, int numFrames, int numEmaPoints, int *surf, int *vert, const char *filePath, const char *fileName)
int vtlTractSequenceToEmaAndMesh(double *tractParams, double *glottisParams, int numTractParams, int numGlottisParams, int numFrames, int numEmaPoints, int *surf, int *vert, const char *filePath, const char *fileName, double frameSamplingRate)
{
// Return if no EMA point is selected
if (numEmaPoints <= 0)
Expand All @@ -1944,6 +1946,13 @@ int vtlTractSequenceToEmaAndMesh(double *tractParams, double *glottisParams, int
return 1;
}

if (frameSamplingRate <= 0.0)
{
printf("Error in vtlTractSequenceToEmaAndMesh(): frameSamplingRate <= 0");
return 11;
}


if (surf == NULL)
{
printf("Error in vtlTractSequenceToEmaAndMesh(): surf == NULL");
Expand Down Expand Up @@ -2100,7 +2109,7 @@ int vtlTractSequenceToEmaAndMesh(double *tractParams, double *glottisParams, int
for (int f = 0; f < numFrames; f++)
{
fs::path objFileName = objFilePath.string() + to_string(f) + ".obj" ; // name of current .obj file
emaFile << f*0.005 << " "; // Write current time (frame*0.005 currently) into file
emaFile << f * (1/frameSamplingRate) << " "; // time of the time step in seconds

// Set the properties of the target tube.
for (i = 0; i < numTractParams; i++)
Expand Down Expand Up @@ -2246,7 +2255,7 @@ int vtlGesturalScoreToEmaAndMesh(const char *gestureFileName, const char *filePa
int vertex[] = {115,225,335}; // Vertex Index of selected EMA point

// Call of vtlTractSequenceToEmaAndMesh could also be done from outside!
return vtlTractSequenceToEmaAndMesh(tractParams.data(), glottisParams.data(), numTractParams, numGlottisParams, numFrames, 3, surf, vertex, filePath, fileName);
return vtlTractSequenceToEmaAndMesh(tractParams.data(), glottisParams.data(), numTractParams, numGlottisParams, numFrames, 3, surf, vertex, filePath, fileName, EMA_SAMPLING_RATE_HZ);
}

// ****************************************************************************
2 changes: 1 addition & 1 deletion test/VtlApiTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ TEST(ApiTest, TractToEmaAndMesh)
ret = vtlTractSequenceToEmaAndMesh(tractSeq.data(), glottisSeq.data(),
numVocalTractParams, numGlottisParams, numFrames, numEmaPoints,
surf, vert,
exportedMeshPath, exportMeshBaseName);
exportedMeshPath, exportMeshBaseName, 200.0);

EXPECT_EQ(ret, 0);

Expand Down