# Path: vulk/exception.py
# class SDL2Error(VulkError):
#     pass
# 
# class SoundError(VulkError):
#     pass


import logging
import sdl2
from sdl2 import sdlmixer as mixer
from sdl2.ext.compat import byteify
from vulk.exception import SDL2Error, SoundError

This module contains all audio related classes.
'''



logger = logging.getLogger()


class VulkAudio():
    '''This class is only used in baseapp.

    It initializes and close the audio system.
    '''
    def open(self, configuration):
        '''Open and configure audio system

        *Parameters:*

        - `configuration`: Configuration parameters from Application
        '''
        if sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_AUDIO) != 0:
            msg = "Cannot initialize audio system: %s" % sdl2.SDL_GetError()
            logger.critical(msg)
            raise SDL2Error(msg)

        if mixer.Mix_OpenAudio(mixer.MIX_DEFAULT_FREQUENCY,
                               mixer.MIX_DEFAULT_FORMAT, 2, 1024):
            msg = "Cannot open mixed audio: %s" % mixer.Mix_GetError()
            logger.critical(msg)

# Path: vulk/exception.py
# class SDL2Error(VulkError):
#     pass
# 
# class SoundError(VulkError):
#     pass


# Path: vulk/audio.py
import logging
import sdl2
from sdl2 import sdlmixer as mixer
from sdl2.ext.compat import byteify
from vulk.exception import SDL2Error, SoundError


This module contains all audio related classes.
'''



logger = logging.getLogger()


class VulkAudio():
    '''This class is only used in baseapp.

    It initializes and close the audio system.
    '''
    def open(self, configuration):
        '''Open and configure audio system

        *Parameters:*

        - `configuration`: Configuration parameters from Application
        '''
        if sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_AUDIO) != 0:
            msg = "Cannot initialize audio system: %s" % sdl2.SDL_GetError()
            logger.critical(msg)
            raise SDL2Error(msg)

        if mixer.Mix_OpenAudio(mixer.MIX_DEFAULT_FREQUENCY,
                               mixer.MIX_DEFAULT_FORMAT, 2, 1024):
            msg = "Cannot open mixed audio: %s" % mixer.Mix_GetError()
            logger.critical(msg)

            raise SDL2Error(msg)