Added OpenMP support on audio spectrum generation, and updated portuguese translation a little bit.

Originally committed to SVN as r1734.
This commit is contained in:
Rodrigo Braz Monteiro 2008-01-15 22:18:54 +00:00
parent a3c8e61f16
commit e271b979b2
4 changed files with 2416 additions and 2038 deletions

View file

@ -39,6 +39,9 @@
#include <list> #include <list>
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#ifdef _OPENMP
#include <omp.h>
#endif
#include "audio_spectrum.h" #include "audio_spectrum.h"
#include "fft.h" #include "fft.h"
#include "colorspace.h" #include "colorspace.h"
@ -155,11 +158,11 @@ public:
unsigned int overlap_offset = line_length / overlaps * 2; // FIXME: the result seems weird/wrong without this factor 2, but why? unsigned int overlap_offset = line_length / overlaps * 2; // FIXME: the result seems weird/wrong without this factor 2, but why?
// Raw sample data // Raw sample data
short *raw_sample_data = new short[line_length*2]; short *raw_sample_data = NULL;
float *sample_data = new float[line_length*2]; float *sample_data = NULL;
// Real and imaginary components of the output // Real and imaginary components of the output
float *out_r = new float[line_length*2]; float *out_r = NULL;
float *out_i = new float[line_length*2]; float *out_i = NULL;
FFT fft; // Use FFTW instead? A wavelet? FFT fft; // Use FFTW instead? A wavelet?
@ -170,28 +173,45 @@ public:
// a frequenmcy/power spectrum. // a frequenmcy/power spectrum.
int64_t sample = start * line_length*2 + overlap*overlap_offset; int64_t sample = start * line_length*2 + overlap*overlap_offset;
for (unsigned long i = 0; i < length; ++i) { long len = length;
provider->GetAudio(raw_sample_data, sample, line_length*2); #ifdef _OPENMP
for (size_t j = 0; j < line_length; ++j) { #pragma omp parallel shared(overlap,len,line_length)
sample_data[j*2] = (float)raw_sample_data[j*2]; #endif
sample_data[j*2+1] = (float)raw_sample_data[j*2+1]; {
short *raw_sample_data = new short[line_length*2];
float *sample_data = new float[line_length*2];
float *out_r = new float[line_length*2];
float *out_i = new float[line_length*2];
#ifdef _OPENMP
#pragma omp for
#endif
for (long i = 0; i < len; ++i) {
// Initialize
sample = start * line_length*2 + overlap*overlap_offset + i*line_length*2;
provider->GetAudio(raw_sample_data, sample, line_length*2);
for (size_t j = 0; j < line_length; ++j) {
sample_data[j*2] = (float)raw_sample_data[j*2];
sample_data[j*2+1] = (float)raw_sample_data[j*2+1];
}
fft.Transform(line_length*2, sample_data, out_r, out_i);
CacheLine &line = data[i + length*overlap];
for (size_t j = 0; j < line_length; ++j) {
line[j] = sqrt(out_r[j]*out_r[j] + out_i[j]*out_i[j]);
}
//sample += line_length*2;
} }
fft.Transform(line_length*2, sample_data, out_r, out_i); delete[] raw_sample_data;
delete[] sample_data;
CacheLine &line = data[i + length*overlap]; delete[] out_r;
for (size_t j = 0; j < line_length; ++j) { delete[] out_i;
line[j] = sqrt(out_r[j]*out_r[j] + out_i[j]*out_i[j]);
}
sample += line_length*2;
} }
} }
delete[] raw_sample_data;
delete[] sample_data;
delete[] out_r;
delete[] out_i;
} }
virtual ~FinalSpectrumCache() virtual ~FinalSpectrumCache()

View file

@ -46,6 +46,7 @@
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
OpenMP="true"
UsePrecompiledHeader="2" UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdwx.h" PrecompiledHeaderThrough="stdwx.h"
WarningLevel="3" WarningLevel="3"
@ -127,6 +128,7 @@
AdditionalIncludeDirectories="../../aegisub/win32;../../hunspell/src" AdditionalIncludeDirectories="../../aegisub/win32;../../hunspell/src"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2" RuntimeLibrary="2"
OpenMP="true"
UsePrecompiledHeader="2" UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdwx.h" PrecompiledHeaderThrough="stdwx.h"
WarningLevel="3" WarningLevel="3"

Binary file not shown.

File diff suppressed because it is too large Load diff