1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 24 марта 2016 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #include <core/fade.h> 23 24 namespace lsp 25 { fade_in(float * dst,const float * src,size_t fade_len,size_t buf_len)26 void fade_in(float *dst, const float *src, size_t fade_len, size_t buf_len) 27 { 28 if ((fade_len <= 0) || (buf_len <= 0)) 29 return; 30 31 float k = 1.0f / fade_len; 32 if (fade_len > buf_len) 33 fade_len = buf_len; 34 35 for (size_t i=0; i < fade_len; ++i) 36 dst[i] = src[i] * i * k; 37 } 38 fade_out(float * dst,const float * src,size_t fade_len,size_t buf_len)39 void fade_out(float *dst, const float *src, size_t fade_len, size_t buf_len) 40 { 41 if ((fade_len <= 0) || (buf_len <= 0)) 42 return; 43 44 float k = 1.0f / fade_len; 45 if (fade_len > buf_len) 46 fade_len = buf_len; 47 else 48 { 49 src = &src[buf_len - fade_len]; 50 dst = &dst[buf_len - fade_len]; 51 } 52 53 for (size_t i=fade_len; i > 0; ) 54 *(dst++) = *(src++) * ((--i) * k); 55 } 56 } 57 58