src/effects_internal.c
author Ozkan Sezer
Wed, 18 Dec 2019 18:55:56 +0300
changeset 1098 3be892f72aa7
parent 1047 ee23898a09a2
child 1129 888c7be704ce
permissions -rw-r--r--
fix build.
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 
    21   This file by Ryan C. Gordon (icculus@icculus.org)
    22 
    23   These are some helper functions for the internal mixer special effects.
    24 */
    25 
    26 
    27 /* ------ These are used internally only. Don't touch. ------ */
    28 
    29 #include <stdio.h>
    30 #include <stdlib.h>
    31 #include "SDL_mixer.h"
    32 
    33 #define MIX_INTERNAL_EFFECT__
    34 #include "effects_internal.h"
    35 
    36 /* Should we favor speed over memory usage and/or quality of output? */
    37 int _Mix_effects_max_speed = 0;
    38 
    39 
    40 void _Mix_InitEffects(void)
    41 {
    42     _Mix_effects_max_speed = (SDL_getenv(MIX_EFFECTSMAXSPEED) != NULL);
    43 }
    44 
    45 void _Mix_DeinitEffects(void)
    46 {
    47     _Eff_PositionDeinit();
    48 }
    49 
    50 
    51 void *_Eff_volume_table = NULL;
    52 
    53 
    54 /* Build the volume table for Uint8-format samples.
    55  *
    56  * Each column of the table is a possible sample, while each row of the
    57  *  table is a volume. Volume is a Uint8, where 0 is silence and 255 is full
    58  *  volume. So _Eff_volume_table[128][mysample] would be the value of
    59  *  mysample, at half volume.
    60  */
    61 void *_Eff_build_volume_table_u8(void)
    62 {
    63     int volume;
    64     int sample;
    65     Uint8 *rc;
    66 
    67     if (!_Mix_effects_max_speed) {
    68         return(NULL);
    69     }
    70 
    71     if (!_Eff_volume_table) {
    72         rc = SDL_malloc(256 * 256);
    73         if (rc) {
    74             _Eff_volume_table = (void *) rc;
    75             for (volume = 0; volume < 256; volume++) {
    76                 for (sample = -128; sample < 128; sample ++) {
    77                     *rc = (Uint8)(((float) sample) * ((float) volume / 255.0f))
    78                         + 128;
    79                     rc++;
    80                 }
    81             }
    82         }
    83     }
    84 
    85     return(_Eff_volume_table);
    86 }
    87 
    88 
    89 /* Build the volume table for Sint8-format samples.
    90  *
    91  * Each column of the table is a possible sample, while each row of the
    92  *  table is a volume. Volume is a Uint8, where 0 is silence and 255 is full
    93  *  volume. So _Eff_volume_table[128][mysample+128] would be the value of
    94  *  mysample, at half volume.
    95  */
    96 void *_Eff_build_volume_table_s8(void)
    97 {
    98     int volume;
    99     int sample;
   100     Sint8 *rc;
   101 
   102     if (!_Eff_volume_table) {
   103         rc = SDL_malloc(256 * 256);
   104         if (rc) {
   105             _Eff_volume_table = (void *) rc;
   106             for (volume = 0; volume < 256; volume++) {
   107                 for (sample = -128; sample < 128; sample ++) {
   108                     *rc = (Sint8)(((float) sample) * ((float) volume / 255.0f));
   109                     rc++;
   110                 }
   111             }
   112         }
   113     }
   114 
   115     return(_Eff_volume_table);
   116 }
   117 
   118 
   119 /* end of effects.c ... */
   120 
   121 /* vi: set ts=4 sw=4 expandtab: */