Ejemplo n.º 1
0
    def __init__(self):
        self.device = aud.device()
        self.music = aud.Factory(
            os.path.join(
                ROOT_PATH,
                'Data/Audio/Stellardrone - Light Years - 03 Eternity.mp3'))
        self.music = self.music.loop(-1)
        self.music_handle = self.device.play(self.music)

        self.sun = aud.Factory(os.path.join(ROOT_PATH, 'Data/Audio/sun.wav'))
        self.sun = self.sun.loop(-1)
        self.sun_handle = self.device.play(self.sun)
        self.sun_handle.pitch = 0.8
Ejemplo n.º 2
0
    def sound_effect(self,
                     sound_name,
                     game_object,
                     loop=0,
                     volume_scale=1.0,
                     attenuation=None):

        sound_path = bge.logic.expandPath("//sounds/")
        file_name = "{}{}.wav".format(sound_path, sound_name)

        if sound_name not in self.buffered:
            self.buffered[sound_name] = aud.Factory.buffer(
                aud.Factory(file_name))

        try:
            if isinstance(game_object, bge.types.KX_GameObject):
                handle = device.play(self.buffered[sound_name])
                handle.relative = False
                handle.loop_count = int(loop)

                if not game_object.invalid:
                    sound_effect = SoundEffect(self.manager, handle,
                                               game_object)
                    self.sound_effects.append(sound_effect)

                handle.volume = bge.logic.globalDict.get('volume',
                                                         0.2) * volume_scale
                if attenuation:
                    handle.attenuation = attenuation
                return handle

        except:
            print(game_object.name, sound_name)

        return None
Ejemplo n.º 3
0
	def start(self, args):
		"""Start Function"""
		scene = bge.logic.getCurrentScene()
		cam = scene.active_camera

		# Loading the device...
		self.device  = aud.device()
		self.device.distance_model = aud.AUD_DISTANCE_MODEL_LINEAR

		# Loading the sound...
		sName = bge.logic.expandPath("//")+args["Sound File"]
		self.factory = aud.Factory(sName)

		# Playing the sound...
		self.handle = self.device.play(self.factory)

		# 3D Sound configuration...
		self.__3dSound = args["3D Sound"]
		self.handle.relative = (self.__3dSound == False)
		self.handle.distance_maximum   = abs(args["Max Distance"])
		self.handle.distance_reference = abs(args["Min Distance"])
		self.handle.pitch = args["Pitch"]

		self.handle.volume = args["Volume"]

		if args["Loop Sound"]:
			self.handle.loop_count = -1
		else:
			self.handle.loop_count = 0

		self.__deleteObj = args["Delete Object After End"]
Ejemplo n.º 4
0
    def execute(self, context):
        addon_data = context.scene.freesound_data

        if (not addon_data.freesound_list_loaded):  
            return {"FINISHED"}

        try:
            addon_data.sound_is_playing = True
            client = Freesound_Validate.get_client(Freesound_Validate)

            sound_id = FREESOUNDList.get_sound_id(FREESOUNDList)
            sound_info = client.get_sound(sound_id)
            if (addon_data.high_quality):
                preview_file = str(sound_info.previews.preview_hq_mp3.split("/")[-1])
            else:
                preview_file = str(sound_info.previews.preview_lq_mp3.split("/")[-1])

            if (preview_file):
                if (os.path.isfile(os.path.dirname(os.path.realpath(__file__)) + '/' + preview_file)):
                    soundfile = os.path.dirname(os.path.realpath(__file__)) + '/' + preview_file
                else:
                    res = sound_info.retrieve_preview(os.path.dirname(os.path.realpath(__file__)), addon_data.high_quality)
                    soundfile = res[0]
                addon_data.soundfile = soundfile
                device = aud.device()
                factory = aud.Factory(soundfile)
                Freesound_Play.handle = device.play(factory)
                Freesound_Play.handle.loop_count = -1
        except:
            print ("File not found, search first")
        return {'FINISHED'}
Ejemplo n.º 5
0
    def __init__(self):
        factory = aud.Factory(common.BASE_PATH + '/legmotors.wav').loop(-1)

        self.handle = self.DEVICE.play(factory)
        self.handle.volume = 0.001
        self.prev_position = 0
        self.prev_speed = 0
Ejemplo n.º 6
0
    def play(self, sound, positional=True, loop=0, volume=1):
        """ Play a sound

			:param sound: The sound to be played. If it's a string, it will build a factory from the file at that relative path, otherwise, it should be a factory.
			:type sound: str or aud.Factory
			:param positional: Whether or not to use 3D positional audio. Defaults to True.
			:type positional: bool
			:param loop: Number of times to loop the sound. Negative == infinity.
			:type loop: int
			:param volume: The volume. 1.0 = 100%
			:type loop: float
			:returns: aud.Handle handle of the sound to be played
		"""
        if type(sound) == str:
            sound = logic.expandPath("//" + sound)
            sound = aud.Factory(sound)

        sound.loop(loop)
        sound.volume(volume)

        handle = self._device.play(sound)

        # if positional == False leave relative and keep position at [0,0,0]
        if positional == True:
            handle.relative = False
            self._collection.append(handle)

        return handle
Ejemplo n.º 7
0
    def reload(self, video):
        if video == self.path:
            return

        if USING_BGE_TEXTURE:
            vid = texture.VideoFFmpeg(video)
            vid.repeat = self.repeat
            vid.play()
            self.video = vid
            data = vid.image

            if self.play_audio:
                self.audio = aud.device().play(aud.Factory(video))
        else:
            data = None

        if data == None:
            print("Unable to load the video", video)
            return

        self.bind()
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vid.size[0], vid.size[1], 0,
                     GL_RGBA, GL_UNSIGNED_BYTE, data)

        self.image_size = vid.size[:]
        self.path = video
Ejemplo n.º 8
0
    def playSound(self,
                  sound,
                  buffer=False,
                  is3D=False,
                  refObj=None,
                  distMax=10):
        device = aud.device()

        if is3D and refObj is not None:
            device.distance_model = aud.AUD_DISTANCE_MODEL_LINEAR
            device.listener_location = refObj.scene.active_camera.worldPosition
            device.listener_orientation = refObj.scene.active_camera.worldOrientation.to_quaternion(
            )

        factory = None
        if not sound in self.soundBuffered.keys():
            factory = aud.Factory(self.soundFiles[sound]["Path"].as_posix())

            if buffer:
                factory = aud.Factory.buffer(factory)
                self.soundBuffered[sound] = factory

        else:
            factory = self.soundBuffered[sound]

        handle = device.play(factory)

        if is3D and refObj is not None:
            handle.relative = False
            handle.location = refObj.worldPosition
            handle.distance_maximum = distMax

        return handle
Ejemplo n.º 9
0
 def execute(self, noteName, frequency, volume, startoff, duration, squaV,
             samples, revB, process):
     self.use_custom_color = True
     self.useNetworkColor = False
     self.color = (1, 0.8, 0.5)
     if process:
         if noteName is not '':
             self.soundFile = ''
             self.message = ''
             indX = getIndex(noteName)
             if indX in range(0, 107):
                 freq = getFreq(indX)
             else:
                 self.message = 'Note Invalid'
                 return snd
             snd = aud.Factory.sine(freq, samples)
         elif frequency > 16.35160:
             self.soundFile = ''
             self.message = ''
             snd = aud.Factory.sine(frequency, samples)
         elif self.soundFile is not '':
             snd = aud.Factory(self.soundFile)
             if revB:
                 snd = snd.reverse()
             squaV = 0
         else:
             return None
         if squaV != 0:
             snd = snd.square(squaV)
         snd = snd.limit(startoff, duration)
     else:
         snd = None
     return snd
Ejemplo n.º 10
0
def sound_setup(*filepath):
    print('DOING SOUND SETUP')
    global sound_first_exec
    sound_first_exec = False

    import os

    # get the sound actuator
    sound_actuator = bge.logic.getCurrentController(
    ).owner.actuators['SoundAct']
    #print(sound_actuator, sound_actuator.__dir__())

    # prepare the sound factory
    if pps.sound_override is not None and os.path.isfile(pps.sound_override):
        soundpath = pps.sound_override
        print('USING MANUAL SOUND OVERRIDE:', soundpath)
    else:
        soundpath = bsh.soundpath
        print('USING STANDARD SOUND FILE', soundpath)

    if os.path.isfile(soundpath):

        factory = aud.Factory(soundpath)
        sound_actuator.sound = factory

    sound_actuator.startSound()
    sound_actuator.pauseSound()
Ejemplo n.º 11
0
    def __init__(self):
        factory = aud.Factory(common.BASE_PATH + '/booster.wav').loop(-1)

        # play the audio, this return a handle to control play/pause
        self.handle = self.DEVICE.play(factory)
        self.handle.volume = 0.001

        self.prev_speed = 0
Ejemplo n.º 12
0
def end_music(scene):
    handle = bpy.types.RenderSettings.music_handle
    addon_prefs = bpy.context.user_preferences.addons[__package__].preferences

    if addon_prefs.use_end:
        device = aud.device()
        factory = aud.Factory(addon_prefs.endfile)
        bpy.types.RenderSettings.music_handle = device.play(factory)
Ejemplo n.º 13
0
def end_music(scene):

    kill_music(scene)

    if scene.render_music.use_end:
        device = aud.device()
        factory = aud.Factory(scene.render_music.endfile)
        handle = device.play(factory)
Ejemplo n.º 14
0
    def __init__(self):
        factory = aud.Factory(common.BASE_PATH + '/wind.wav').loop(-1)

        self.oscillator = 0

        # play the audio, this return a handle to control play/pause
        self.handle = self.DEVICE.play(factory)
        self.handle.volume = 0.001
        self.prev_percent = 0
Ejemplo n.º 15
0
def play_music(scene):
    global handle

    if scene.render_music.use_play:
        if not hasattr(handle, "status") or (hasattr(handle, "status")
                                             and handle.status == False):
            print("Playing elevator music...")
            device = aud.device()
            factory = aud.Factory(scene.render_music.playfile)
            handle = device.play(factory)
            handle.loop_count = -1
Ejemplo n.º 16
0
    def play_music(self, sound_name, vol=1.0):
        if self.music:
            self.music.stop()

        sound_path = bge.logic.expandPath("//music/")
        file_name = "{}{}.wav".format(sound_path, sound_name)

        handle = device.play(aud.Factory(file_name))
        handle.volume = vol
        handle.loop_count = -1
        self.music = handle
Ejemplo n.º 17
0
	def __init__(self, gobj):
		super().__init__(gobj)
		
		
		self.device = aud.device()
		sound = logic.expandPath("//sounds/enemy_hurt.ogg")
		factory = aud.Factory(sound)
		self.factory = aud.Factory.buffer(factory)
		
		self.collision = self.gobj.collision
		
		self.state("damage_calc")
Ejemplo n.º 18
0
    def execute(self, context):
        sc = context.scene

        # 初回時のみサウンドデバイスを作成
        if AudioDevice.device is None:
            AudioDevice.device = aud.device()
        # サウンドファクトリを作成
        AudioDevice.factory = aud.Factory(self.filepath)
        # オーディオファイルを再生
        AudioDevice.handle = AudioDevice.device.play(AudioDevice.factory)
        AudioDevice.handle.volume = sc.paf_volume

        return {'FINISHED'}
Ejemplo n.º 19
0
    def __init__(self):
        self.field = "grass"
        self.lastFrame = 0
        self.lastFrameSwing = 0
        self.lastVoiceFrame = 0

        logic.playerAudioHandle = [None]

        logic.playerAudio = [
            aud.Factory(sfxPath + "hot.wav").loop(-1),
            aud.Factory(sfxPath + "link_push.wav"),
            aud.Factory(sfxPath + "steps_push_grass.wav"),
            aud.Factory(sfxPathOther + "fanfare_item.wav"),
            aud.Factory(sfxPath + "link_choke.wav"),
            aud.Factory(sfxPath + "bounceHit.wav"),
            aud.Factory(sfxPathOther + "game_over.mp3"),
            aud.Factory(sfxPath + "link_ledge_climb.wav"),
            aud.Factory(sfxPath + "link_ledge_fall.wav"),
        ]
Ejemplo n.º 20
0
def storeSound(soundName):
    # Make a factory for sound
    filepath = logic.expandPath('//audio/') + soundName + '.wav'
    factory = aud.Factory(filepath)

    # Buffer the factory
    bufferedFactory = aud.Factory.buffer(factory)

    # Get a handle for buffered factory
    bufferedHandle = device.play(bufferedFactory, keep=True)
    bufferedHandle.pause()

    # Store the handle
    storedSounds[soundName] = bufferedHandle
Ejemplo n.º 21
0
	def play(self, filepath=None, loop=False, volume = None, pitch = 1, callback = None, transition = (3, 2, 3)):
		""" Method to play an audio file.
		
		If an audio file is being played while calling this, it will be replaced by a new one. During the transation a *fadeOut->FadeIn* effect will occur.
		
		:param string filepath: Relative path (from the data folder) of the audio file to use.
		:param bool loop: If true the audio will be played in loop.
		:param float volume: The volume of the audio file relative to the master device. (Default = 1.0)
		:param float pitch: The pitch.
		:param function callback: Function to call once the playback ends.
		:param tuple transition: The times for the fade effect during transations. In order: Duration of the fadeout, time for the fadein to start, duration of the fadein. In sconds.
		"""
		
		if self.waiting == True: #Replace sound that will be played.
			self.filepath = filepath
			return
			
		if self.playing == True: #FadeOut this sound and fadeIn the new one.
			x, y, z = transition
			
			dummy = self.moveInstance()
			dummy.fadeOut(x, stop=True)

			if filepath: self.filepath = filepath
			self.waiting = True
			
			sequencer.Wait(y, lambda: self._transition_callback(z))
			self.callback = callback
			return
		
		self.callback = callback
		if not filepath: filepath = self.filepath
		else: self.filepath = filepath
		path = logic.expandPath("//../data/" + filepath)
		factory = aud.Factory(path)
		
		try:
			self.factory = factory
			self.handle = device.play(self.factory) #It sends a callback that will play the music on a new theread.
			self.handle.pitch = pitch
			if volume == None: self.volume = self._volume
			else: self.volume = volume
			if loop: self.handle.loop_count = -1
		except:
			if os.path.isfile(path) == False: utils.debug("Audio File, Not Found: " + path)
			else: raise RuntimeException("AudioFile Load Error: " + path)
		
		self.playing = True
		module.low_frequency_callbacks.append(self.update)
		return self
Ejemplo n.º 22
0
class VoiceSound:
    DEVICE = aud.device()
    raw = aud.Factory(common.BASE_PATH + '/voice.ogg')
    beep = aud.Factory(common.BASE_PATH + '/beep.wav')

    factory1 = raw.loop(-1)
    factory2 = raw.lowpass(440, 2).highpass(220, 1.5).loop(-1)

    def __init__(self):

        self.handle1 = self.DEVICE.play(self.factory1)
        self.handle2 = self.DEVICE.play(self.factory2)
        self.handle1.volume = 0.001
        self.handle2.volume = 0.001
        self.handle1.position = bge.logic.getRandomFloat() * 30
        self.handle2.position = self.handle1.position

        self.vol = 0.0
        self.muffled = False

    def set_volume(self, vol):
        self.vol = vol
        self.DEVICE.play(self.beep)
        self.update()

    def update(self):
        if not self.muffled:
            self.handle1.volume = self.vol * 0.5
            self.handle2.volume = 0.0
        else:
            self.handle2.volume = self.vol * 0.5
            self.handle1.volume = 0.0
        #if vol > 0.5:

    def set_muffle(self, val):
        self.muffled = val
        self.update()
Ejemplo n.º 23
0
    def __init__(self, own):

        self.indexItem = 0
        self.rows = 0
        self.columns = 0
        self.active = False
        self.session = -1
        self.subSession = -1
        self.audio = [
            None,
            aud.Factory(hud_sfx + "pm_cursor_select.wav"),
            aud.Factory(hud_sfx + "error.wav")
        ]

        # Arrays
        self.sessionSpace = [[9, 3], [3, 3]]

        self.arrayItem = [[[
            'bow', 'boomrang', 'bomb', 'bomb_arrow', 'hookshot', 'glass',
            'flipper', 'shovel', 'roc_plume'
        ]],
                          [['basic_sword', 'mystic_sword', 'hero_sword'],
                           ['wood_shield', 'hylian_shield', 'fairy_shield']]]

        items_list = logic.globalDict['Player']['Inventory']['Items'][
            'Objects']
        equip_list = logic.globalDict['Player']['Inventory']['Equipement']

        self.sessionData = [
            [self.initArrayEquipement(Inventory.ITEMS_SESSION, 0, items_list)],
            [
                self.initArrayEquipement(Inventory.EQUIP_SESSION, 0,
                                         equip_list['Swords']),
                self.initArrayEquipement(Inventory.EQUIP_SESSION, 1,
                                         equip_list['Shields'])
            ]
        ]
Ejemplo n.º 24
0
def init(cont):
    own = cont.owner

    #toggle menghilang
    own.visible = False

    var.w = wave.open(soundFile)
    w = var.w
    var.frameRate = w.getframerate()
    var.totalFrames = w.getnframes()
    var.totalTime = w.getnframes() / w.getframerate()

    cont.activate(cont.actuators['s1'])
    device = aud.device()
    factory = aud.Factory(soundFile)
    handle = device.play(factory)
Ejemplo n.º 25
0
	def __init__(self, gobj):
		super().__init__(gobj)
		
		#sound
		self.device = aud.device()
		sound = logic.expandPath("//sounds/aphtar_gun.ogg")
		factory = aud.Factory(sound)
		self.factory = aud.Factory.buffer(factory)
		
		
		bullet = "r__bullet"
		
		self.state("reflect")
		self.collision = self.gobj.sensors['Collision']
		
		self.hit = None
    def execute(self, context):
        # 初回時のみサウンドデバイスを作成
        if AudioDevice.device is None:
            AudioDevice.device = aud.device()

        # サウンドファクトリを作成
        AudioDevice.factory = aud.Factory(self.filepath)
        AudioDevice.filename = self.filename
        AudioDevice.pause = False

        # 再生中なら停止し、サウンドハンドラを破棄
        if AudioDevice.handle is not None:
            AudioDevice.handle.stop()
            AudioDevice.handle = None

        return {'FINISHED'}
Ejemplo n.º 27
0
 def __init__(self, audio_file_path, buffered=True):
     ''' audio_file_path = "//audio/comment/boum.ogg"
         buffered = Boolean '''
     self.device = aud.device()
     self.sound = gl.expandPath(audio_file_path)
     # Default buffered
     self.buffered = buffered
     # Load sound file
     try:
         self.factory = aud.Factory(self.sound)
     except:
         print("No sounf file:", self.sound)
     if self.buffered:
         try:
             self.factory_buffered = aud.Factory.buffer(self.factory)
         except:
             print("No sounf file:", self.sound)
Ejemplo n.º 28
0
 def execute(self, volume, duration, process, revB):
     self.use_custom_color = True
     self.useNetworkColor = False
     self.color = (1, 0.8, 1)
     dev = aud.device()
     if process and self.soundFile is not '':
         snd = aud.Factory(self.soundFile)
         if revB:
             snd = snd.reverse()
         if duration != 0:
             snd = snd.limit(0, duration)
         handle = dev.play(snd)
         handle.volume = volume
     if self.soundFile is '':
         self.message2 = 'Load Sound File'
     else:
         self.message2 = ''
Ejemplo n.º 29
0
    def set_audio_folder(self, sound_folder):

        if not sound_folder.endswith("/"):
            sound_folder += "/"  # Make sure there's a trailing slash for sound files to go

        sound_folder = logic.expandPath(sound_folder)

        self.sounds = {}

        for snd_info in os.walk(sound_folder):

            for f in snd_info[2]:

                filename = os.path.splitext(f)[0]  # Ignore the extension; we're just
                # interested in the audio file itself

                self.sounds[filename] = aud.Factory(sound_folder + f)
Ejemplo n.º 30
0
    def __init__(self):
        raw = aud.Factory(common.BASE_PATH +
                          "/Stellardrone - The Earth Is Blue.ogg")
        normal = raw.loop(-1)
        muffled = raw.lowpass(440, 2).highpass(220, 1.5).loop(-1)
        # play the audio, this return a handle to control play/pause
        self.handle1 = self.DEVICE.play(normal)
        self.handle2 = self.DEVICE.play(muffled)

        if "start_time" not in bge.logic.globalDict:
            bge.logic.globalDict["start_time"] = time.time()
            elapsed = 0
        else:
            elapsed = time.time() - bge.logic.globalDict["start_time"]
        self.handle1.position = elapsed
        self.handle2.position = elapsed
        self.handle1.volume = 0.5
        self.handle2.volume = 0.0