From 6acb09a85e5652af36acee3c48bffec7de27643d Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sun, 30 Nov 2014 12:29:30 +0100 Subject: [PATCH] moved complex number helpers to complex.rsh --- app/src/main/rs/complex.rsh | 30 ++++++++++++++++++++++++++++++ app/src/main/rs/decoder.rs | 17 ++--------------- 2 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 app/src/main/rs/complex.rsh diff --git a/app/src/main/rs/complex.rsh b/app/src/main/rs/complex.rsh new file mode 100644 index 0000000..1249e85 --- /dev/null +++ b/app/src/main/rs/complex.rsh @@ -0,0 +1,30 @@ +/* +Copyright 2014 Ahmet Inan + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +typedef float2 complex_t; +static inline complex_t complex(float a, float b) { return (complex_t){ a, b }; } +static inline float cabs(complex_t z) { return length(z); } +static inline float carg(complex_t z) { return atan2(z[1], z[0]); } +static inline complex_t cexp(complex_t z) +{ + return complex(exp(z[0]) * cos(z[1]), exp(z[0]) * sin(z[1])); +} +static inline complex_t cmul(complex_t a, complex_t b) +{ + return complex(a[0] * b[0] - a[1] * b[1], a[0] * b[1] + a[1] * b[0]); +} +static inline complex_t conj(complex_t z) { return complex(z[0], -z[1]); } +static inline complex_t cdiv(complex_t a, complex_t b) { return cmul(a, conj(b)) / dot(b, b); } diff --git a/app/src/main/rs/decoder.rs b/app/src/main/rs/decoder.rs index 260c434..2f24821 100644 --- a/app/src/main/rs/decoder.rs +++ b/app/src/main/rs/decoder.rs @@ -17,27 +17,14 @@ limitations under the License. #pragma version(1) #pragma rs java_package_name(xdsopl.robot36) +#include "complex.rsh" + short *audio_buffer; uchar *value_buffer; uchar4 *pixel_buffer; static inline uchar4 rgb(uchar r, uchar g, uchar b) { return (uchar4){ b, g, r, 255 }; } -typedef float2 complex_t; -static inline complex_t complex(float a, float b) { return (complex_t){ a, b }; } -static inline float cabs(complex_t z) { return length(z); } -static inline float carg(complex_t z) { return atan2(z[1], z[0]); } -static inline complex_t cexp(complex_t z) -{ - return complex(exp(z[0]) * cos(z[1]), exp(z[0]) * sin(z[1])); -} -static inline complex_t cmul(complex_t a, complex_t b) -{ - return complex(a[0] * b[0] - a[1] * b[1], a[0] * b[1] + a[1] * b[0]); -} -static inline complex_t conj(complex_t z) { return complex(z[0], -z[1]); } -static inline complex_t cdiv(complex_t a, complex_t b) { return cmul(a, conj(b)) / dot(b, b); } - static float ema_a(float cutoff, float rate, int order) { float fc = cutoff / sqrt(rootn(2.0f, order) - 1.0f);