dynamic_modplug.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Jan 2016 22:12:31 -0800
changeset 712 7e59d684b070
parent 711 f40c5ac95b12
child 725 bdf7b8d20566
permissions -rw-r--r--
Updated to version 2.0.1
slouken@639
     1
/*
slouken@639
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@711
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
slouken@639
     4
slouken@639
     5
  This software is provided 'as-is', without any express or implied
slouken@639
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@639
     7
  arising from the use of this software.
slouken@639
     8
slouken@639
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@639
    10
  including commercial applications, and to alter it and redistribute it
slouken@639
    11
  freely, subject to the following restrictions:
slouken@639
    12
slouken@639
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@639
    14
     claim that you wrote the original software. If you use this software
slouken@639
    15
     in a product, an acknowledgment in the product documentation would be
slouken@639
    16
     appreciated but is not required.
slouken@639
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@639
    18
     misrepresented as being the original software.
slouken@639
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@639
    20
*/
slouken@639
    21
slouken@639
    22
#ifdef MODPLUG_MUSIC
slouken@639
    23
slouken@639
    24
#include "SDL_loadso.h"
slouken@639
    25
#include "SDL_mixer.h"
slouken@639
    26
#include "dynamic_modplug.h"
slouken@639
    27
slouken@639
    28
modplug_loader modplug = {
slouken@639
    29
    0, NULL
slouken@639
    30
};
slouken@639
    31
slouken@639
    32
#ifdef MODPLUG_DYNAMIC
slouken@639
    33
int Mix_InitModPlug()
slouken@639
    34
{
slouken@639
    35
    if ( modplug.loaded == 0 ) {
slouken@639
    36
        modplug.handle = SDL_LoadObject(MODPLUG_DYNAMIC);
slouken@639
    37
        if ( modplug.handle == NULL ) {
slouken@639
    38
            return -1;
slouken@639
    39
        }
slouken@639
    40
slouken@639
    41
        modplug.ModPlug_Load =
slouken@639
    42
            (ModPlugFile* (*)(const void* data, int size))
slouken@639
    43
            SDL_LoadFunction(modplug.handle, "ModPlug_Load");
slouken@639
    44
slouken@639
    45
        modplug.ModPlug_Unload =
slouken@639
    46
            (void (*)(ModPlugFile* file))
slouken@639
    47
            SDL_LoadFunction(modplug.handle, "ModPlug_Unload");
slouken@639
    48
slouken@639
    49
        modplug.ModPlug_Read =
slouken@639
    50
            (int  (*)(ModPlugFile* file, void* buffer, int size))
slouken@639
    51
            SDL_LoadFunction(modplug.handle, "ModPlug_Read");
slouken@639
    52
slouken@639
    53
        modplug.ModPlug_Seek =
slouken@639
    54
            (void (*)(ModPlugFile* file, int millisecond))
slouken@639
    55
            SDL_LoadFunction(modplug.handle, "ModPlug_Seek");
slouken@639
    56
slouken@639
    57
        modplug.ModPlug_GetSettings =
slouken@639
    58
            (void (*)(ModPlug_Settings* settings))
slouken@639
    59
            SDL_LoadFunction(modplug.handle, "ModPlug_GetSettings");
slouken@639
    60
slouken@639
    61
        modplug.ModPlug_SetSettings =
slouken@639
    62
            (void (*)(const ModPlug_Settings* settings))
slouken@639
    63
            SDL_LoadFunction(modplug.handle, "ModPlug_SetSettings");
slouken@639
    64
slouken@639
    65
        modplug.ModPlug_SetMasterVolume =
slouken@639
    66
            (void (*)(ModPlugFile* file,unsigned int cvol))
slouken@639
    67
            SDL_LoadFunction(modplug.handle, "ModPlug_SetMasterVolume");
slouken@639
    68
    }
slouken@639
    69
    ++modplug.loaded;
slouken@639
    70
slouken@639
    71
    return 0;
slouken@639
    72
}
aschiffler@642
    73
slouken@639
    74
void Mix_QuitModPlug()
slouken@639
    75
{
slouken@639
    76
    if ( modplug.loaded == 0 ) {
slouken@639
    77
        return;
slouken@639
    78
    }
slouken@639
    79
    if ( modplug.loaded == 1 ) {
slouken@639
    80
        SDL_UnloadObject(modplug.handle);
slouken@639
    81
    }
slouken@639
    82
    --modplug.loaded;
slouken@639
    83
}
slouken@639
    84
#else
slouken@639
    85
int Mix_InitModPlug()
slouken@639
    86
{
slouken@639
    87
    if ( modplug.loaded == 0 ) {
slouken@639
    88
#ifdef __MACOSX__
slouken@639
    89
        extern ModPlugFile* ModPlug_Load(const void* data, int size) __attribute__((weak_import));
slouken@639
    90
        if ( ModPlug_Load == NULL )
slouken@639
    91
        {
slouken@639
    92
            /* Missing weakly linked framework */
slouken@639
    93
            Mix_SetError("Missing modplug.framework");
slouken@639
    94
            return -1;
slouken@639
    95
        }
slouken@639
    96
#endif // __MACOSX__
slouken@639
    97
slouken@639
    98
        modplug.ModPlug_Load = ModPlug_Load;
slouken@639
    99
        modplug.ModPlug_Unload = ModPlug_Unload;
slouken@639
   100
        modplug.ModPlug_Read = ModPlug_Read;
slouken@639
   101
        modplug.ModPlug_Seek = ModPlug_Seek;
slouken@639
   102
        modplug.ModPlug_GetSettings = ModPlug_GetSettings;
slouken@639
   103
        modplug.ModPlug_SetSettings = ModPlug_SetSettings;
slouken@639
   104
        modplug.ModPlug_SetMasterVolume = ModPlug_SetMasterVolume;
slouken@639
   105
    }
slouken@639
   106
    ++modplug.loaded;
slouken@639
   107
slouken@639
   108
    return 0;
slouken@639
   109
}
slouken@639
   110
void Mix_QuitModPlug()
slouken@639
   111
{
slouken@639
   112
    if ( modplug.loaded == 0 ) {
slouken@639
   113
        return;
slouken@639
   114
    }
slouken@639
   115
    if ( modplug.loaded == 1 ) {
slouken@639
   116
    }
slouken@639
   117
    --modplug.loaded;
slouken@639
   118
}
slouken@639
   119
#endif /* MODPLUG_DYNAMIC */
slouken@639
   120
slouken@639
   121
#endif /* MODPLUG_MUSIC */