effects_internal.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 14 Dec 2001 13:02:16 +0000
changeset 140 efa15d2a5403
parent 139 7e0c8c4388dc
child 201 e55fb6b45559
permissions -rw-r--r--
*** empty log message ***
     1 /*
     2     SDL_mixer:  An audio mixer library based on the SDL library
     3     Copyright (C) 1997, 1998, 1999, 2000, 2001  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@linuxgames.com)
    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 = 0; sample < 256; sample ++) {
    71                     *rc = (Uint8)(((float) sample) * ((float) volume / 255.0));
    72                     rc++;
    73                 }
    74             }
    75         }
    76     }
    77 
    78     return(_Eff_volume_table);
    79 }
    80 
    81 
    82 /* Build the volume table for Sint8-format samples.
    83  *
    84  * Each column of the table is a possible sample, while each row of the
    85  *  table is a volume. Volume is a Uint8, where 0 is silence and 255 is full
    86  *  volume. So _Eff_volume_table[128][mysample] would be the value of
    87  *  mysample, at half volume.
    88  */
    89 void *_Eff_build_volume_table_s8(void)
    90 {
    91     int volume;
    92     int sample;
    93     Sint8 *rc;
    94 
    95     if (!_Eff_volume_table) {
    96         rc = malloc(256 * 256);
    97         if (rc) {
    98             _Eff_volume_table = (void *) rc;
    99             for (volume = 0; volume < 256; volume++) {
   100                 for (sample = 0; sample < 256; sample ++) {
   101                     *rc = (Sint8)(((float) sample) * ((float) volume / 255.0));
   102                     rc++;
   103                 }
   104             }
   105         }
   106     }
   107 
   108     return(_Eff_volume_table);
   109 }
   110 
   111 
   112 /* end of effects.c ... */
   113