LCOV - code coverage report
Current view: top level - libavfilter - generate_wave_table.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 45 40.0 %
Date: 2017-12-16 01:21:47 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Lesser General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2.1 of the License, or (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Lesser General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public
      15             :  * License along with FFmpeg; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  */
      18             : 
      19             : #include <stdint.h>
      20             : #include "libavutil/avassert.h"
      21             : #include "avfilter.h"
      22             : #include "generate_wave_table.h"
      23             : 
      24           1 : void ff_generate_wave_table(enum WaveType wave_type,
      25             :                             enum AVSampleFormat sample_fmt,
      26             :                             void *table, int table_size,
      27             :                             double min, double max, double phase)
      28             : {
      29           1 :     uint32_t i, phase_offset = phase / M_PI / 2 * table_size + 0.5;
      30             : 
      31      881895 :     for (i = 0; i < table_size; i++) {
      32      881894 :         uint32_t point = (i + phase_offset) % table_size;
      33             :         double d;
      34             : 
      35      881894 :         switch (wave_type) {
      36      881894 :         case WAVE_SIN:
      37      881894 :             d = (sin((double)point / table_size * 2 * M_PI) + 1) / 2;
      38      881894 :             break;
      39           0 :         case WAVE_TRI:
      40           0 :             d = (double)point * 2 / table_size;
      41           0 :             switch (4 * point / table_size) {
      42           0 :             case 0: d = d + 0.5; break;
      43           0 :             case 1:
      44           0 :             case 2: d = 1.5 - d; break;
      45           0 :             case 3: d = d - 1.5; break;
      46             :             }
      47           0 :             break;
      48           0 :         default:
      49           0 :             av_assert0(0);
      50             :         }
      51             : 
      52      881894 :         d  = d * (max - min) + min;
      53      881894 :         switch (sample_fmt) {
      54           0 :         case AV_SAMPLE_FMT_FLT: {
      55           0 :             float *fp = (float *)table;
      56           0 :             *fp++ = (float)d;
      57           0 :             table = fp;
      58           0 :             continue; }
      59           0 :         case AV_SAMPLE_FMT_DBL: {
      60           0 :             double *dp = (double *)table;
      61           0 :             *dp++ = d;
      62           0 :             table = dp;
      63           0 :             continue; }
      64             :         }
      65             : 
      66      881894 :         d += d < 0 ? -0.5 : 0.5;
      67      881894 :         switch (sample_fmt) {
      68           0 :         case AV_SAMPLE_FMT_S16: {
      69           0 :             int16_t *sp = table;
      70           0 :             *sp++ = (int16_t)d;
      71           0 :             table = sp;
      72           0 :             continue; }
      73      881894 :         case AV_SAMPLE_FMT_S32: {
      74      881894 :             int32_t *ip = table;
      75      881894 :             *ip++ = (int32_t)d;
      76      881894 :             table = ip;
      77      881894 :             continue; }
      78           0 :         default:
      79           0 :             av_assert0(0);
      80             :         }
      81             :     }
      82           1 : }

Generated by: LCOV version 1.13