spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 766a36afc7208388bb0b44b2235329d3e9ab837d
parent 07c13da27d9c2acfc713c63c21d123cae4b5ce65
Author: sfan5 <sfan5@live.de>
Date:   Sat,  1 Jul 2017 15:13:49 +0200

Avoid AVX-related crashes in FFmpeg by aligning buffer

Diffstat:
Msrc/spek-fft.h | 22++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/spek-fft.h b/src/spek-fft.h @@ -3,6 +3,11 @@ #include <memory> #include <vector> +extern "C" { +#include <libavutil/mem.h> +} + + class FFTPlan; class FFT @@ -17,8 +22,17 @@ class FFTPlan public: FFTPlan(int nbits) : input_size(1 << nbits), output_size((1 << (nbits - 1)) + 1), - input(input_size), output(output_size) {} - virtual ~FFTPlan() {} + output(output_size) + { + // FFmpeg uses various assembly optimizations which expect + // input data to be aligned by up to 32 bytes (e.g. AVX) + this->input = (float*) av_malloc(sizeof(float) * input_size); + } + + virtual ~FFTPlan() + { + av_freep(this->input); + } int get_input_size() const { return this->input_size; } int get_output_size() const { return this->output_size; } @@ -30,11 +44,11 @@ public: virtual void execute() = 0; protected: - float *get_input() { return this->input.data(); } + float *get_input() { return this->input; } private: int input_size; int output_size; - std::vector<float> input; + float *input; std::vector<float> output; };