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