effects_internal.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 15 Jan 2007 16:14:04 +0000
changeset 339 30996c5fd448
parent 241 503416fca921
child 359 83eaf245b7e7
permissions -rw-r--r--
Updated my email address everywhere I spewed it.
     1 /*
     2     SDL_mixer:  An audio mixer library based on the SDL library
     3     Copyright (C) 1997-2004 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     This file by Ryan C. Gordon (icculus@icculus.org)
    20 
    21     These are some helper functions for the internal mixer special effects.
    22 */
    23 
    24 /* $Id$ */
    25 
    26 
    27      /* ------ These are used internally only. Don't touch. ------ */
    28 
    29 
    30 
    31 #include <stdio.h>
    32 #include <stdlib.h>
    33 #include "SDL_mixer.h"
    34 
    35 /* Should we favor speed over memory usage and/or quality of output? */
    36 int _Mix_effects_max_speed = 0;
    37 
    38 
    39 void _Mix_InitEffects(void)
    40 {
    41     _Mix_effects_max_speed = (getenv(MIX_EFFECTSMAXSPEED) != NULL);
    42 }
    43 
    44 
    45 void *_Eff_volume_table = NULL;
    46 
    47 
    48 /* Build the volume table for Uint8-format samples.
    49  *
    50  * Each column of the table is a possible sample, while each row of the
    51  *  table is a volume. Volume is a Uint8, where 0 is silence and 255 is full
    52  *  volume. So _Eff_volume_table[128][mysample] would be the value of
    53  *  mysample, at half volume.
    54  */
    55 void *_Eff_build_volume_table_u8(void)
    56 {
    57     int volume;
    58     int sample;
    59     Uint8 *rc;
    60 
    61     if (!_Mix_effects_max_speed) {
    62         return(NULL);
    63     }
    64 
    65     if (!_Eff_volume_table) {
    66         rc = malloc(256 * 256);
    67         if (rc) {
    68             _Eff_volume_table = (void *) rc;
    69             for (volume = 0; volume < 256; volume++) {
    70                 for (sample = -128; sample < 128; sample ++) {
    71                     *rc = (Uint8)(((float) sample) * ((float) volume / 255.0)) 
    72                         + 128;
    73                     rc++;
    74                 }
    75             }
    76         }
    77     }
    78 
    79     return(_Eff_volume_table);
    80 }
    81 
    82 
    83 /* Build the volume table for Sint8-format samples.
    84  *
    85  * Each column of the table is a possible sample, while each row of the
    86  *  table is a volume. Volume is a Uint8, where 0 is silence and 255 is full
    87  *  volume. So _Eff_volume_table[128][mysample+128] would be the value of
    88  *  mysample, at half volume.
    89  */
    90 void *_Eff_build_volume_table_s8(void)
    91 {
    92     int volume;
    93     int sample;
    94     Sint8 *rc;
    95 
    96     if (!_Eff_volume_table) {
    97         rc = malloc(256 * 256);
    98         if (rc) {
    99             _Eff_volume_table = (void *) rc;
   100             for (volume = 0; volume < 256; volume++) {
   101                 for (sample = -128; sample < 128; sample ++) {
   102                     *rc = (Sint8)(((float) sample) * ((float) volume / 255.0));
   103                     rc++;
   104                 }
   105             }
   106         }
   107     }
   108 
   109     return(_Eff_volume_table);
   110 }
   111 
   112 
   113 /* end of effects.c ... */
   114