Commit e98a0034 authored by Mert Burkay Çöteli's avatar Mert Burkay Çöteli
Browse files

memory allocation problems are solved and ReadMe updates for the current AIMs

parent c9783dab
...@@ -36,17 +36,14 @@ This README would normally document whatever steps are necessary to get your app ...@@ -36,17 +36,14 @@ This README would normally document whatever steps are necessary to get your app
// The output will be Interleaved Nofchannelsx10x1024 real and imaginary parts. // The output will be Interleaved Nofchannelsx10x1024 real and imaginary parts.
// Input and output data formats can be followed from MPAI-CAE v1.3 // Input and output data formats can be followed from MPAI-CAE v1.3
analysistransform* m_fft = new analysistransform(); analysistransform* m_fft = new analysistransform(2048, 20480,1024,2);
int NofChannels = 32;
float* signal; // Data acquired from each microphone channel float* signal; // Data acquired from each microphone channel
float* realpart; // Real part to be malloc float* realpart; // Real part to be malloc
float* imagpart; // Imaginary part to be malloc float* imagpart; // Imaginary part to be malloc
for (int channel = 0; channel < NofChannels; channel++) m_fft->FFT(signal, realpart, imagpart);
{
m_fft->STFT(signal, realpart+channel, imagpart+channel)
}
### Who do I talk to? ### ### Who do I talk to? ###
* Repo owner or admin * Repo owner or admin
......
...@@ -9,6 +9,11 @@ analysistransform::analysistransform() ...@@ -9,6 +9,11 @@ analysistransform::analysistransform()
this->windowsize = 2048; this->windowsize = 2048;
this->overlap = 1024; this->overlap = 1024;
this->nofmics = 32; this->nofmics = 32;
// Create a hamming window of appropriate length
window = (double*)malloc(sizeof(double) * this->windowsize);
hamming(this->windowsize, window);
} }
// Create a constructor for analysis transform // Create a constructor for analysis transform
...@@ -18,6 +23,11 @@ analysistransform::analysistransform(int windowsize, int signallength, int hopsi ...@@ -18,6 +23,11 @@ analysistransform::analysistransform(int windowsize, int signallength, int hopsi
this->windowsize = windowsize; this->windowsize = windowsize;
this->overlap = hopsize; this->overlap = hopsize;
this->nofmics = nofmics; this->nofmics = nofmics;
// Create a hamming window of appropriate length
window = (double*)malloc(sizeof(double) * this->windowsize);
hamming(this->windowsize, window);
} }
// Create a hamming window of windowLength samples in buffer // Create a hamming window of windowLength samples in buffer
...@@ -25,7 +35,7 @@ void analysistransform::hamming(int windowLength, double* buffer) { ...@@ -25,7 +35,7 @@ void analysistransform::hamming(int windowLength, double* buffer) {
for (int i = 0; i < windowLength; i++) { for (int i = 0; i < windowLength; i++) {
buffer[i] = 0.54 - (0.46 * cos(2 * PI * (i / ((windowLength - 1) * 1.0)))); buffer[i] = 0.54 - (0.46 * cos(2 * PI * (i / (((double)windowLength - 1.0) * 1.0))));
} }
} }
...@@ -49,13 +59,6 @@ void* analysistransform::FFT(double* signal, double* realpart, double* imagpart) ...@@ -49,13 +59,6 @@ void* analysistransform::FFT(double* signal, double* realpart, double* imagpart)
plan_forward = fftw_plan_dft_r2c_1d(this->windowsize, data, fft_result, FFTW_ESTIMATE); plan_forward = fftw_plan_dft_r2c_1d(this->windowsize, data, fft_result, FFTW_ESTIMATE);
// Create a hamming window of appropriate length
double* window = (double*)malloc(sizeof(double) * this->windowsize);
hamming(this->windowsize, window);
int readIndex; int readIndex;
// Should we stop reading in chunks? // Should we stop reading in chunks?
...@@ -124,7 +127,6 @@ void* analysistransform::FFT(double* signal, double* realpart, double* imagpart) ...@@ -124,7 +127,6 @@ void* analysistransform::FFT(double* signal, double* realpart, double* imagpart)
fftw_free(data); fftw_free(data);
fftw_free(fft_result); fftw_free(fft_result);
free(window);
return 0; return 0;
......
...@@ -21,6 +21,7 @@ private: ...@@ -21,6 +21,7 @@ private:
int windowsize; int windowsize;
int overlap; int overlap;
int nofmics; int nofmics;
double* window;
}; };
......
...@@ -5,14 +5,14 @@ This README would normally document whatever steps are necessary to get your app ...@@ -5,14 +5,14 @@ This README would normally document whatever steps are necessary to get your app
### What is this repository for? ### ### What is this repository for? ###
* Quick summary * Quick summary
This repository comprises 4 AIM source codes (Analysis Transform, Sound Field Description, Synthesis Transform, and Packager) and 2 AIM executable (Speech Detection and Separation, Noise Cancellation) files This repository comprises 4 EAE AIM source codes (Analysis Transform, Sound Field Description, Synthesis Transform, and Packager) and 2 AIM executable (Speech Detection and Separation, Noise Cancellation) files
* Version * Version
v0.1 v0.1
### How do I get set up? ### ### How do I get set up? ###
* Summary of set up * Summary of set up
Each AIM's installation is defined in their ReadMe files Each AIM's installation is described in their ReadMe files
* Configuration * Configuration
* Dependencies * Dependencies
* Database configuration * Database configuration
......
...@@ -56,6 +56,8 @@ void* soundfielddescription::calcsphericalharmonics(double* pressure_real_in, do ...@@ -56,6 +56,8 @@ void* soundfielddescription::calcsphericalharmonics(double* pressure_real_in, do
} }
} }
} }
// Free the allocated space for spherical harmonics
free(sph_harmonics);
} }
return 0; return 0;
} }
\ No newline at end of file
# README #
This README would normally document whatever steps are necessary to get your application up and running.
### What is this repository for? ###
* Quick summary
Synthesis tranform is an AIM used for transferring the time-frequency domain multichannel signals into the time domain. This file introduces the setup for standalone application.
* Version
01.01.220708
* [Technical specifications MPAI-CAE v1.3](https://mpai.community/standards/resources/)
### How do I get set up? ###
* Summary of set up
The development language is C++. C++11 or its newer versions support compiling the code. See the list of C++ compilers. (https://en.wikipedia.org/wiki/List_of_compilers#C++_compilers)
This software uses a third-party fftw-3.3.9 that can be also downloaded from the link. (https://fftw.org/)
* Configuration
Usage of a new class
* Dependencies
include : \include
libs :
#if DEBUG
\libs\Windows_x64\Debug;\libs\Windows_x86\Debug;\libs\Linux\Debug
#else
\libs\Windows_x64\Release;\libs\Windows_x86\Release;\libs\Linux\Release
#endif
* Database configuration
This software doesnot use a database.
* How to run tests
[Conformance Testing Document MPAI-CAE](https://mpai.community/standards/resources/)
* Deployment instructions
***********Standalone usage of this AIM (code script)
// Input and output data formats can be followed from MPAI-CAE v1.3
synthesistransform* m_ifft = new synthesistransform();
float* signal; // Interleaved data output
float* realpart; // Real part to be malloc
float* imagpart; // Imaginary part to be malloc
m_ifft.IFFT(signal, realpart, imagpart);
### Who do I talk to? ###
* Repo owner or admin
Mert Burkay Çöteli , mbcoteli@aselsan.com.tr, Aselsan
* Other community or team contact
MPAI secreteriat , secretariat@mpai.community , MPAI
\ No newline at end of file
...@@ -3,22 +3,30 @@ ...@@ -3,22 +3,30 @@
// Create a constructor for synthesis transform // Create a constructor for analysis transform
synthesistransform::synthesistransform() synthesistransform::synthesistransform()
{ {
this->signallength = 20480; this->signallength = 20480;
this->windowsize = 2048; this->windowsize = 2048;
this->overlap = 1024; this->overlap = 1024;
this->nofmics = 32; this->nofmics = 32;
window = (double*)malloc(sizeof(double) * this->windowsize);
hamming(this->windowsize, window);
} }
// Create a constructor for synthesis transform // Create a constructor for analysis transform
synthesistransform::synthesistransform(int windowsize, int signallength, int hopsize, int nofmics) synthesistransform::synthesistransform(int windowsize, int signallength, int hopsize, int nofmics)
{ {
this->signallength = signallength; this->signallength = signallength;
this->windowsize = windowsize; this->windowsize = windowsize;
this->overlap = hopsize; this->overlap = hopsize;
this->nofmics = nofmics; this->nofmics = nofmics;
window = (double*)malloc(sizeof(double) * this->windowsize);
hamming(this->windowsize, window);
} }
// Create a hamming window of windowLength samples in buffer // Create a hamming window of windowLength samples in buffer
...@@ -26,11 +34,11 @@ void synthesistransform::hamming(int windowLength, double* buffer) { ...@@ -26,11 +34,11 @@ void synthesistransform::hamming(int windowLength, double* buffer) {
for (int i = 0; i < windowLength; i++) { for (int i = 0; i < windowLength; i++) {
buffer[i] = 0.54 - (0.46 * cos(2 * PI * (i / ((windowLength - 1) * 1.0)))); buffer[i] = 0.54 - (0.46 * cos(2 * PI * (i / (((double)windowLength - 1.0) * 1.0))));
} }
} }
// Function for the inverse fast fourier transform
void* synthesistransform::IFFT(double* istft_out, double* realpart, double* imagpart) { void* synthesistransform::IFFT(double* istft_out, double* realpart, double* imagpart) {
...@@ -38,17 +46,11 @@ void* synthesistransform::IFFT(double* istft_out, double* realpart, double* imag ...@@ -38,17 +46,11 @@ void* synthesistransform::IFFT(double* istft_out, double* realpart, double* imag
fftw_plan plan_backward; fftw_plan plan_backward;
int i; int i;
data = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * this->windowsize); data = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * this->windowsize);
ifft_output = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * this->windowsize); ifft_output = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * this->windowsize);
int outputcounter = 0; int outputcounter = 0;
double* window = (double*)malloc(sizeof(double) * this->windowsize);
hamming(this->windowsize, window);
plan_backward = fftw_plan_dft_1d(this->windowsize, data, ifft_output, FFTW_BACKWARD, FFTW_ESTIMATE); plan_backward = fftw_plan_dft_1d(this->windowsize, data, ifft_output, FFTW_BACKWARD, FFTW_ESTIMATE);
int readIndex; int readIndex;
...@@ -88,7 +90,10 @@ void* synthesistransform::IFFT(double* istft_out, double* realpart, double* imag ...@@ -88,7 +90,10 @@ void* synthesistransform::IFFT(double* istft_out, double* realpart, double* imag
// Copy the first (windowSize/2 + 1) data points into your spectrogram. // Copy the first (windowSize/2 + 1) data points into your spectrogram.
// We do this because the FFT output is mirrored about the nyquist // We do this because the FFT output is mirrored about the nyquist
// frequency, so the second half of the data is redundant. // frequency, so the second half of the data is redundant. This is how
// Matlab's spectrogram routine works.
//outputcounter = chunkPosition * this->nofmics + channelindex;
for (i = 0; i < this->windowsize/2; i++) for (i = 0; i < this->windowsize/2; i++)
{ {
......
...@@ -21,6 +21,7 @@ private: ...@@ -21,6 +21,7 @@ private:
int windowsize; int windowsize;
int overlap; int overlap;
int nofmics; int nofmics;
double* window;
}; };
#include "analysistransform.h" #include "analysistransform.h"
#include "synthesistransform.h" #include "synthesistransform.h"
#include "soundfielddescription.h" #include "soundfielddescription.h"
#include "packager.h"
int main() int main()
{ {
...@@ -40,25 +40,81 @@ int main() ...@@ -40,25 +40,81 @@ int main()
printf("{%f}", average_error / bloksize); printf("{%f}", average_error / bloksize);
soundfielddescription sfd = soundfielddescription();
char audioscenegeometry[] = R"( char audioscenegeometry[] = R"(
{ {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"title" : "Audio Scene Geometry", "title" : "Audio Scene Geometry",
"BlockIndex": , "BlockIndex": 1,
"BlockStart" : , "BlockStart" : 1659533438878,
"BlockEnd" : , "BlockEnd" : 1659533438898,
"SpeechCount" : 1, "SpeechCount" : 1,
"SourceDetectionMask" : [], "SourceDetectionMask" : [1,1,1],
"SpeechList": [ "SpeechList": [
{"SpeechID" : 0.93358, "ChannelID" : 0.0, "AzimuthDirection" : 0.35836, "ElevationDirection" : 0.0, "DistanceFlag" : 0.93358, "Distance" : 0.0}, {"SpeechID" : "09859d16-3c73-4bb0-9c74-91b451e34925", "ChannelID" : 0.0, "AzimuthDirection" : 0.35836, "ElevationDirection" : 0.0, "DistanceFlag" : 0.93358, "Distance" : 0.0}
]
], }
}
)"; )";
char microphonearraygeometry[] = R"(
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Microphone Array Geometry",
"MicrophoneArrayType": 0,
"MicrophoneArrayScat": 0,
"MicrophoneArrayFilterURI": "filter.file",
"SamplingRate": 4,
"SampleType": 2,
"BlockSize": 5,
"NumberofMicrophones": 32,
"MicrophoneList" : [
{"xCoord" : 0.93358,"yCoord" : 0.0,"zCoord" : 0.35836,"directivity" : 0.0,"micxLookCoord" : 0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : 0.35836},
{"xCoord" : 0.84804,"yCoord" : 0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.84804,"micyLookCoord" : 0.52991,"miczLookCoord" : 0.0},
{"xCoord" : 0.93358,"yCoord" : 0.0,"zCoord" : -0.35836,"directivity" : 0.0,"micxLookCoord" : 0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : -0.35836},
{"xCoord" : 0.84804,"yCoord" : -0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.84804,"micyLookCoord" : -0.52991,"miczLookCoord" : 0.0},
{"xCoord" : 0.52991,"yCoord" : 0.0,"zCoord" : 0.84804,"directivity" : 0.0,"micxLookCoord" : 0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : 0.84804},
{"xCoord" : 0.57922,"yCoord" : 0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : 0.35836,"yCoord" : 0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.35836,"micyLookCoord" : 0.93358,"miczLookCoord" : 0.0},
{"xCoord" : 0.57922,"yCoord" : 0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : 0.52991,"yCoord" : 0.0,"zCoord" : -0.84804,"directivity" : 0.0,"micxLookCoord" : 0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : -0.84804},
{"xCoord" : 0.57922,"yCoord" : -0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : 0.35836,"yCoord" : -0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : 0.35836,"micyLookCoord" : -0.93358,"miczLookCoord" : 0.0},
{"xCoord" : 0.57922,"yCoord" : -0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : 0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : -0.00625,"yCoord" : 0.35831,"zCoord" : 0.93358,"directivity" : 0.0,"micxLookCoord" : -0.00625,"micyLookCoord" : 0.35831,"miczLookCoord" : 0.93358},
{"xCoord" : 0.0,"yCoord" : 0.84804,"zCoord" : 0.52991,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : 0.84804,"miczLookCoord" : 0.52991},
{"xCoord" : 0.0,"yCoord" : 0.85716,"zCoord" : -0.51503,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : 0.85716,"miczLookCoord" : -0.51503},
{"xCoord" : 0.006254,"yCoord" : 0.35831,"zCoord" : -0.93358,"directivity" : 0.0,"micxLookCoord" : 0.006254,"micyLookCoord" : 0.35831,"miczLookCoord" : -0.93358},
{"xCoord" : -0.93358,"yCoord" : 0.0,"zCoord" : 0.35836,"directivity" : 0.0,"micxLookCoord" : -0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : 0.35836},
{"xCoord" : -0.84804,"yCoord" : -0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.84804,"micyLookCoord" : -0.52991,"miczLookCoord" : 0.0},
{"xCoord" : -0.93358,"yCoord" : 0.0,"zCoord" : -0.35836,"directivity" : 0.0,"micxLookCoord" : -0.93358,"micyLookCoord" : 0.0,"miczLookCoord" : -0.35836},
{"xCoord" : -0.84804,"yCoord" : 0.52991,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.84804,"micyLookCoord" : 0.52991,"miczLookCoord" : 0.0},
{"xCoord" : -0.52991,"yCoord" : 0.0,"zCoord" : 0.84804,"directivity" : 0.0,"micxLookCoord" : -0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : 0.84804},
{"xCoord" : -0.57922,"yCoord" : -0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : -0.35836,"yCoord" : -0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.35836,"micyLookCoord" : -0.93358,"miczLookCoord" : 0.0},
{"xCoord" : -0.57922,"yCoord" : -0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : -0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : -0.52991,"yCoord" : 0.0,"zCoord" : -0.84804,"directivity" : 0.0,"micxLookCoord" : -0.52991,"micyLookCoord" : 0.0,"miczLookCoord" : -0.84804},
{"xCoord" : -0.57922,"yCoord" : 0.57922,"zCoord" : -0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : -0.57357},
{"xCoord" : -0.35836,"yCoord" : 0.93358,"zCoord" : 0.0,"directivity" : 0.0,"micxLookCoord" : -0.35836,"micyLookCoord" : 0.93358,"miczLookCoord" : 0.0},
{"xCoord" : -0.57922,"yCoord" : 0.57922,"zCoord" : 0.57357,"directivity" : 0.0,"micxLookCoord" : -0.57922,"micyLookCoord" : 0.57922,"miczLookCoord" : 0.57357},
{"xCoord" : -0.00625,"yCoord" : -0.35831,"zCoord" : 0.93358,"directivity" : 0.0,"micxLookCoord" : -0.00625,"micyLookCoord" : -0.35831,"miczLookCoord" : 0.93358},
{"xCoord" : 0.0,"yCoord" : -0.84804,"zCoord" : 0.52991,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : -0.84804,"miczLookCoord" : 0.52991},
{"xCoord" : 0.0,"yCoord" : -0.84804,"zCoord" : -0.52991,"directivity" : 0.0,"micxLookCoord" : 0.0,"micyLookCoord" : -0.84804,"miczLookCoord" : -0.52991},
{"xCoord" : 0.00625,"yCoord" : -0.35831,"zCoord" : -0.93358,"directivity" : 0.0,"micxLookCoord" : 0.00625,"micyLookCoord" : -0.35831,"miczLookCoord" : -0.93358}
],
"MicrophoneArrayLookCoord" : {"xLookCoord" : 0.0, "yLookCoord" : 0.0, "zLookCoord" : 0.0}
}
)";
soundfielddescription sfd = soundfielddescription(microphonearraygeometry);
int msgsize = 0;
packager m_packager;
unsigned char* result = m_packager.createdata(audioscenegeometry, microphonearraygeometry, signal_out, &msgsize);
return 0; return 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