Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Headers/SDLWrapper.h"
#include "Core/Headers/Console.h"
#include "Utility/Headers/Localization.h"

#include <stdexcept>

namespace Divide {

ErrorCode SDL_API::initAudioApi() {
    I32 flags = MIX_INIT_OGG | MIX_INIT_MP3;
    I32 ret = Mix_Init(flags);
    if((ret & flags) == flags) {
        _music = nullptr;
        _chunk = nullptr;
        // Try HiFi sound
        if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096) == -1) {
            ERROR_FN("%s", Mix_GetError());
            // Try lower quality
            if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048) == -1) {
                ERROR_FN("%s", Mix_GetError());
                return SDL_AUDIO_MIX_INIT_ERROR;
            }
        }
    
        return NO_ERR;
    } 
    ERROR_FN("%s", Mix_GetError());
    return SDL_AUDIO_INIT_ERROR;
}

void SDL_API::closeAudioApi() {
    if (_music != nullptr) {
        Mix_HaltMusic();
        Mix_FreeMusic(_music);
    }

    if (_chunk != nullptr) {
        Mix_FreeChunk(_chunk);
    }
    Mix_CloseAudio();
    Mix_Quit();
}

void SDL_API::playMusic(AudioDescriptor* musicFile){
    if (!musicFile) {
        return;
    }
    _music = Mix_LoadMUS(musicFile->getAudioFile().c_str());
    Mix_VolumeMusic(musicFile->getVolume());
    if (nullptr != _music) {
        if ( Mix_PlayMusic(_music, musicFile->isLooping() ? -1 : 0) == -1 ) {
            ERROR_FN("%s", Mix_GetError());
        }
    }
}

void SDL_API::playSound(AudioDescriptor* sound){
    if (sound == nullptr) {
        return;
    }
    if (_chunk != nullptr) {
        Mix_FreeChunk(_chunk);
    }
    _chunk  = Mix_LoadWAV(sound->getAudioFile().c_str());
    assert(_chunk);
    Mix_Volume(sound->getChannel(),sound->getVolume());

    if (_chunk == nullptr) {
        ERROR_FN(Locale::get("ERROR_SDL_LOAD_SOUND") ,sound->getName().c_str());
    }

    if (Mix_PlayChannel( sound->getChannel(), _chunk, sound->isLooping() ? -1 : 0 ) == -1) {
        ERROR_FN(Locale::get("ERROR_SDL_CANT_PLAY") ,sound->getName().c_str(),Mix_GetError());
    }
}

};

Commits for Divide-Framework/trunk/Source Code/Platform/Audio/sdl_mixer/SDLWrapper.cpp

Diff revisions: vs.
Revision Author Commited Message
337 Diff Diff IonutCava picture IonutCava Wed 17 Dec, 2014 17:25:16 +0000

[Ionut]
- Replaced all tabs with 4 spaces (some spacing may be off now. no way to check all the files.)
- Moved implementation details for ParamHandler, BoundingBox, BoundingSphere and ProfileTimer to proper .inl and .cpp files. (more to follow)
- Update all forward declared enums with the required storage type (as requested by the C++11 standard)

334 IonutCava picture IonutCava Wed 10 Dec, 2014 17:21:22 +0000

[Ionut]
- Reorganized the Hardware project and renamed to "Platform"
- Reorganized the Server project