def draw(self, context): layout = self.layout layout.prop(context.scene.arduino, "type_add", expand=False) #rylan layout.operator("object.arduino_step_reset", text="Update Micro Controler Selection ", ) #icon="TRIA_DOWN" layout.label("Set the mode of each pin:") row = layout.row() row.template_list("arduino_UL_steplist", "", context.scene.arduino, "steps", context.scene.arduino, "index", rows=4, maxrows=10,) #row.prop(pin_setup_button, text=" ", expand=True) row = layout.row() row.operator("object.arduino_create_ino", text=" Create C:\\auto_script.ino ", ) # icon="ZOOMIN" row = layout.row() row.operator("object.open_serial_port_button", text=" Open Serial Port ", ) row = layout.row() row.operator("object.close_serial_port_button", text="Close Serial Port ", ) #print('panle draw function was called') if sound: aud.device().play(hover_sound) msg = link_gui() if msg != None: print(msg)
def __init__(self, ob): self.obj = ob self.last_update = self.start_time = time.time() self.end_time = None print("Attaching player controller to", ob) self.engine_sound = aud.device().play(aud.Factory(logic.expandPath("//../sounds/engine.ogg")).loop(-1)) self.bg_music = aud.device().play(aud.Factory(logic.expandPath("//../sounds/Circus Waltz FX.ogg")).loop(-1))
def action1(self): if self.activate_date+0.5 > time.time() : return if self.cycle : # play sound path = bge.logic.expandPath('//lib/light-baton/cycle-stop.wav') sound = aud.Factory.file(path) dev = aud.device() cam = bge.logic.getCurrentScene().active_camera vec = self.getOwnerObject().worldPosition - cam.worldPosition dev.listener_location = vec dev.volume = 0.8 dev.play(sound) self.cycle['class'].remove() self.cycle = None else : # play sound path = bge.logic.expandPath('//lib/light-baton/cycle-start.wav') sound = aud.Factory.file(path) dev = aud.device() cam = bge.logic.getCurrentScene().active_camera vec = self.getOwnerObject().worldPosition - cam.worldPosition dev.listener_location = vec dev.volume = 0.7 dev.play(sound) # spawn the cycle skin = self.getOwner().skin armature = skin.armature anim = skin.animations["set cycle"] armature.playAction(anim[0], anim[1], anim[4], layer=1) def t(): while armature.getActionFrame(1) <= anim[3] : time.sleep(0.05) scene = bge.logic.getCurrentScene() self.cycle = scene.addObject("light-cycle", self.getOwnerObject()) self.cycle['class'] = LightCycle(self.cycle, "light cycle") #self.cycle['class'].init() self.cycle['class'].enter(self.getOwnerObject(), self.cycle['class'].driversplace) self.cycle['class'].init() color = self.object['color'] if color in self.cyclecolors : self.cycle['class'].armature.replaceMesh(self.cyclecolors[color]) for child in self.cycle['class'].armature.children: if 'body' in child: #print(child.meshes) child.replaceMesh(self.cyclecolors[color]) #child.update() #print(child.meshes) self.cycle['class'].armature.update() thread = threading.Thread() thread.run = t thread.start() self.activate_date = time.time()
def render_handler(dummy): print("Render Complete") try: locale = bpy.context.user_preferences.addons[ __name__].preferences.playsong sound = aud.Factory.file(locale) aud.device().play(sound) except: print("Reverting to default song. Please confirm file exists") locale = bpy.context.user_preferences.addons[ __name__].preferences.defsong sound = aud.Factory.file(locale) aud.device().play(sound)
def play_bgm(self, music): if self.bgm_handle: # Fade out the previous music p = self.bgm_handle.position self.bgm_handle.stop() f = aud.Factory(self.bgm_file).fadeout(p, 1) aud.device().play(f).position = p # Now fadein the new music af = os.path.join(self.audio_folder, music)+".ogg" self.bgm_handle = aud.device().play(aud.Factory(af).fadein(0, 2)) self.bgm_handle.loop_count = -1 self.bgm_file = af
class BoosterSound: DEVICE = aud.device() 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_percent = 0 self.oscillator = 0 self.underwater = False def set_thrust(self, percent): diff = percent - self.prev_percent self.prev_percent = percent self.handle.volume = (percent**2) self.handle.pitch = max(0, (diff * 4 + 1.0)**2.0 * 0.8 + self.oscillator - 0.3 * self.underwater) self.oscillator = (bge.logic.getRandomFloat() - 0.5) * 2 * 0.1 + self.oscillator * 0.9 self.oscillator = self.oscillator * 0.99
def __init__(self, sys, data): super().__init__(sys, data) # Use a frame to store all of our widgets self.frame = bgui.Frame(self, border=0) self.frame.colors = [(0, 0, 0, 0) for i in range(4)] # A themed frame self.win = bgui.Frame(self, size=[0.6, 0.8], pos=[0.01, 0.01], options=bgui.BGUI_DEFAULT) # Create an image to display self.button_play = bgui.Image(self.win, 'images/button_play.png', name="play", size=[.45, .15], pos=[.0, .3], options = bgui.BGUI_DEFAULT|bgui.BGUI_CACHE) self.button_options = bgui.Image(self.win, 'images/button_options.png', name='options', size=[.45, .15], pos=[.0, .15], options = bgui.BGUI_DEFAULT|bgui.BGUI_CACHE) self.button_exit = bgui.Image(self.win, 'images/button_exit.png', name='exit', size=[.45, .15], pos=[.0, .02], options = bgui.BGUI_DEFAULT|bgui.BGUI_CACHE) self.imgpth = 'images' self.imglist = {'play': ['button_play.png', 'button_play_hover.png'], 'options': ['button_options.png', 'button_options_hover.png'], 'exit': ['button_exit.png', 'button_exit_hover.png']} #Beep click menu self.soundclick = aud.Factory.file(MENUCLICK) self.device = aud.device() buttons = [self.button_play, self.button_options, self.button_exit] for i in buttons: i.on_hover = self.on_img_hover i.on_mouse_exit = self.on_img_leave i.on_click = self.on_img_click # Add a label self.lbl = bgui.Label(self, text="SHIKA", font="themes/default/dylan.ttf", pt_size=150, color=(0.5, 0.3, 1.0, 0.7), pos=[0, 0.75], options = bgui.BGUI_DEFAULT | bgui.BGUI_CENTERX)
def __init__(self): self.sounds = [] # AUD self.device = aud.device() # MUSIC self.current_song = {"sound":None,"handle":None, "time":0.0} self.last_song = {"sound":None,"handle":None, "time":0.0} self.music = [] # SOUNDS self.factories = {} self.animation_sounds = {} # SETTINGS self.wait = 300.0 ### for sound in os.listdir(PATH_SOUNDS): if sound.endswith('.wav') or sound.endswith('.ogg'): self.factories[sound] = aud.Factory.file(PATH_SOUNDS+sound).buffer() for sound in os.listdir(PATH_MUSIC): if sound.endswith('.wav') or sound.endswith('.ogg'): self.music.append([aud.Factory.file(PATH_MUSIC+sound),sound])
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
def playspeaker(name, volume=1.0, limit=[], highpass=None, lowpass=None): speaker_obj = bpy.data.objects.get(name) if not speaker_obj: dprint("No speaker object named %s" % name) return 0.0 speaker = speaker_obj.data on = speaker.filter_sound if on: device = aud.device() #load the factory dprint("-" * 80) dprint("playing %s" % speaker.sound.filepath) dprint("-" * 80) dprint("limit %s" % str(limit)) dprint("lowpass %s" % str(lowpass)) dprint("highpass %s" % str(highpass)) f = speaker.sound.factory #f = aud.Factory(speaker.sound.filepath) if len(limit): f = f.limit(limit[0], limit[1]) if lowpass is not None: f = f.highpass(highpass) if highpass is not None: f = f.highpass(highpass) #apply the device.play(f) else: dprint('speaker.on = False')
def __init__(self, sys, data): super().__init__(sys, data) posx = 0.03 posy = 0.700 checkx = 1 button = None strbut = '' lblist = [] #Beep click menu self.soundclick = aud.Factory.file(MENU_CLICK) self.device = aud.device() for item in bge.logic.globalDict['users']: strbut = item lblist.append(strbut) button = bgui.FrameButton(self, text=strbut, size=[.16, .09], pos=[posx, posy], options = bgui.BGUI_DEFAULT) button.on_click = self.onBut posx += 0.20 checkx += 1 if checkx == 4: posy -= 0.100 posx = 0.03 checkx = 1 #self.lb = bgui.ListBox(self, "lb", items=lblist, padding=0.05, size=[0.9, 0.9], pos=[0.05, 0.05]) self.buttonAddProfil = bgui.FrameButton(self, text="Nouveau", size=[.18, .09], pos=[0.22, 0.05], options = bgui.BGUI_DEFAULT) self.buttonAddProfil.on_click = self.onAdd self.buttonexit = bgui.FrameButton(self, text="Quitter", size=[.18, .09], pos=[.03, 0.05], options = bgui.BGUI_DEFAULT) self.buttonexit.on_click = self.onExit
def __init__(self): self.oP = OutPipe("SoundEngine", 0) self.eI = EngineInterface() self.sD = SubtitleDrawer(self) self.subtitles = 1 self.language = "en" self.device = aud.device() self.sounds = {} self.dialogs = {} self.music = None self.musicHandle = None self.playbacks = [] self.dialogPlaybacks = [] self.videoAudio = None self.masterVolume = 1.0 self.dialogVolume = 1.0 self.musicVolume = 1.0 self.soundVolume = 1.0 self.setMasterVolume(1.0) self.oP("Initialized.")
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"]
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
def set_source(self, _file): self.__file = _file if self.state != 'STOP': self.state = 'STOP' self._texture.source = texture.VideoFFmpeg(_file) if not self._texture.source: self.__file = None self.__audio = None return # --- play audio stream if self.__audio: try: if self.__hassound is True: self.__handle.stop() self.__sound = aud.Factory(_file) print("self.__sound ", self.__sound) device = aud.device() print("device ", device) self.__handle = device.play(self.__sound) print("self.__handle ", self.__handle) self.__handle.loop_count = -1 self.__hassound = True except aud.error as err: print('Error: MoviePlayer.load - no sound available\n', err) self.__hassound = None self.__sound = None # -- scale the video self._texture.source.scale = True # -- play the video self.state = 'PLAY'
class Soundtrack: DEVICE = aud.device() 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 def muffle(self, val): if val: self.handle2.volume = 0.5 self.handle1.volume = 0.0 else: self.handle2.volume = 0.0 self.handle1.volume = 0.5
def span_pokemon(self): print('SPAAAWN') pokeball = scene.objects['pokeball'] pokeball.suspendDynamics() files = '//sound//pokeball_sound_effects_mp3cut_1.wv' files_path = logic.expandPath(files) sound = aud.Factory.file(files_path) device = aud.device() device.volume = 0.01 device.play(sound) pokebalOpenSpawn = scene.addObject('pokeball_spawner', pokeball, 800) pokebalOpenSpawn.playAction('pokeball_spawner_action', 0, 60, 0, speed=2) spawedPok = [ x for x in scene.objects if x.name == 'Charizard_sskeleton' ] if len(spawedPok) == 0: pokemon = scene.addObject('Charizard_skeleton', pokebalOpenSpawn, 12500) pokemon.localOrientation = self.avatar.localOrientation pokemon.worldPosition[2] += 3 pokemon.playAction('pokemon_grow', 0, 60, 0) pokemon['jump'] = False pokemon['name'] = 'charizard' self.avatar = pokemon
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'}
def execute(self, noteName, squaV, duration, volume, samples, process): self.use_custom_color = True self.useNetworkColor = False self.color = (1, 0.8, 1) frameC = bpy.context.scene.frame_current fps = bpy.context.scene.render.fps dev = aud.device() if frameC == 1: self.store.clear() stopF = 1 dev.stopAll() self.color = (0.9, 0.7, 0.8) return self.store if '.' in self.name: name = 'Handle_' + self.name.split('.')[1] else: name = 'Handle_000' if name in self.store: stopF = self.store[name + '_stop'] else: stopF = bpy.context.scene.frame_start # Only process if last note finished self.message = '' freq = 0 if process and frameC > stopF: indX = getIndex(noteName) if indX in range(0, 107): freq = getFreq(indX) else: self.message = 'Note Invalid' return self.store snd = aud.Factory.sine(freq, samples) if self.chordB: idxList = getChord(noteName) if len(idxList) == 3: # Make 3 Notes and Joi them snd1 = aud.Factory.sine(idxList[0], samples) snd2 = aud.Factory.sine(idxList[1], samples) snd3 = aud.Factory.sine(idxList[2], samples) snd = snd1.mix(snd2) snd = snd.mix(snd3) else: self.message = 'Invalid Input Note Name' return self.store if squaV != 0: snd = snd.square(squaV) snd = snd.limit(0, duration) handle = dev.play(snd) self.store[name] = handle self.store[name + '_start'] = int(frameC) self.store[name + '_stop'] = int(frameC + (duration * fps)) return self.store
def execute(self,snd): self.use_custom_color = True self.useNetworkColor = False self.color = (1,0.8,0.5) if snd is not None: dev = aud.device() handle = dev.play(snd) return snd
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)
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)
class Beep: DEVICE = aud.device() def __init__(self): self.factory = aud.Factory(common.BASE_PATH + '/page.wav') def play(self): handle = self.DEVICE.play(self.factory) handle.volume = 0.2
def play_buffer(buffer): dprint("Play BUff") device = aud.device() if not buffer: return None handle = device.play(buffer) handle.keep = True bpy.app.driver_namespace["ST_handle"] = handle return handle
class FoundSound: DEVICE = aud.device() def __init__(self): self.factory = aud.Factory(common.BASE_PATH + '/find.wav') def play(self): handle = self.DEVICE.play(self.factory) handle.volume = 0.5
def end_music(scene): handle = bpy.types.RenderSettings.music_handle addon_prefs = bpy.context.user_preferences.addons[__package__].preferences kill_music(scene) if addon_prefs.use_end: device = aud.device() factory = aud.Factory(addon_prefs.endfile) bpy.types.RenderSettings.music_handle = device.play(factory)
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
def mix_buffer(context): dprint("mix BUff") #make a buffer from the channel mix # set up a buffer with the same dictionary structure as the device = aud.device() scene = context.scene fps = scene.render.fps / scene.render.fps_base if not context: return None if scene.use_preview_range: frame_start = scene.frame_preview_start frame_end = scene.frame_preview_end else: frame_start = scene.frame_start frame_end = scene.frame_end # get g = None for name, value in scene.sound_channels.items(): mix = sound_buffer.get(name) if mix is None: continue speaker_name, action_name = name.split("__@__") speaker = bpy.data.speakers.get(speaker_name) if not speaker: continue action = getAction(speaker) if not speaker.filter_sound \ or action_name != action.name: # using the mute as a flag continue channel_name = action["channel_name"] fs = int(max(frame_start, action.frame_range.x)) fe = min(frame_end, action.frame_range.y) if True: for i in range(action["start"], action["end"]): ch = "channel%02d" % i if value.get(ch): # channel selected for mix f = mix.get(ch) if g: #f = f.join(g) # join f = f.mix(g) g = f if g: #factory_buffered = #aud.Factory.buffer(g.limit((fs-1) / fps, (fe-1) / fps)) bpy.app.driver_namespace["ST_buffer"] = g factory_buffered = aud.Factory.buffer(g) dprint("buffered") return factory_buffered return None
def play_music(scene): handle = bpy.types.RenderSettings.music_handle addon_prefs = bpy.context.user_preferences.addons[__package__].preferences if addon_prefs.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(addon_prefs.playfile) bpy.types.RenderSettings.music_handle = device.play(factory) handle.loop_count = -1
def set_range(self, seq): inp = seq[0] outp = seq[1] if inp > 0 and inp < outp: if self._texture.source: self._texture.source.range = (inp, outp) if self.__audio and self.__hassound: self.__handle.stop() self.__sound = self.__sound.limit(inp, outp) device = aud.device() self.__handle = device.play(self.__sound)
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")
def register(): for c in classes: bpy.utils.register_class(c) bpy.types.WindowManager.mp_index=bpy.props.IntProperty() bpy.types.WindowManager.mp_cycled = bpy.props.BoolProperty( \ description='start first if last is played',default=False) bpy.types.WindowManager.mp_pause = bpy.props.BoolProperty(False) bpy.types.WindowManager.mp_playing = bpy.props.BoolProperty(False) bpy.types.Scene.mp_volume = bpy.props.FloatProperty(name="Volume",default=1.0, min=0.0, max=1.0, update=volume_up) bpy.types.WindowManager.mp_d = aud.device() bpy.types.WindowManager.mp_MusHandle = bpy.props.FloatProperty(name="MusHandle",default=0.0, min=0.0, max=600) bpy.types.Scene.mp_playlist = bpy.props.CollectionProperty(type=MP_Playlist) bpy.types.Scene.mp_playlist_names = bpy.props.CollectionProperty(type=MP_Playlist)
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'}
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
def __init__(self, parent, name, vid, play_audio=False, repeat=0, size=[1, 1], pos=[0, 0], offset=[0,0], sub_theme='', options=BGUI_NONE): """ :param parent: the widget's parent :param name: the name of the widget :param vid: the video to use for the widget :param play_audio: play the audio track of the video :param repeat: how many times to repeat the video (-1 = infinite) :param size: a tuple containing the width and height :param pos: a tuple containing the x and y position :param sub_theme: name of a sub_theme defined in the theme file (similar to CSS classes) :param options: various other options """ Widget.__init__(self, parent, name, size, pos, offset, sub_theme, options) # Generate a texture id_buf = Buffer(GL_INT, 1) glGenTextures(1, id_buf) self.tex_id = id_buf.to_list()[0] if hasattr(id_buf, "to_list") else id_buf.list[0] # Bind and load the texture data glBindTexture(GL_TEXTURE_2D, self.tex_id) video = bge.texture.ImageRender(bge.logic.getCurrentScene(), bge.logic.getCurrentScene().objects["cam2"]) video.capsize = [256,128] im_buf = video.image if im_buf: # Setup some parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) # Upload the texture data glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256,128, 0, GL_RGBA, GL_UNSIGNED_BYTE, im_buf) else: logging.error("Unable to load the video:" + str(vid)) if play_audio: f = aud.Factory(vid) self.aud_handle = aud.device().play(f) else: self.aud_handle = None # Store the video for later self.video = video
def ST__FT_playback_status(scene): dprint("Play STATUS") context = bpy.context screen = context.screen device = aud.device() buffer = bpy.app.driver_namespace.get("ST_buffer") handle = bpy.app.driver_namespace.get("ST_handle") if handle and handle.status: if not screen.is_animation_playing: handle.pause() else: handle.resume() #device.stopAll() return None
def __init__(self, sound_folder='//assets/snd/'): self.device = aud.device() self.sounds = {} self.set_audio_folder(sound_folder) self.bgm_list = [] self.sound_volume = 1.0 self.bgm_volume = 1.0 self.fade_time = 1.0 # Fade time between BGM plays
def _aud_lock(*args, **kwargs): global _aud_locked if _aud_locked: return f(*args, **kwargs) else: dev = aud.device() dev.lock() try: _aud_locked = True return f(*args, **kwargs) finally: dev.unlock() _aud_locked = False
def use_linear_clamped_falloff(dist_min=10, dist_max=50, attenuation=1.0): global DIST_MAX global DIST_MIN global ATTENUATION log.info("Setting sound falloff to linear. Max dist: %d", dist_max) try: aud.device().distance_model = aud.AUD_DISTANCE_MODEL_LINEAR_CLAMPED except aud.error as e: log.warn("Can't set 3D audio model: %s", e) return DIST_MIN = dist_min DIST_MAX = dist_max ATTENUATION = attenuation
def use_inverse_clamped_falloff(dist_min=10, dist_max=10000, attenuation=1.0): global DIST_MAX global DIST_MIN global ATTENUATION log.info("Setting sound falloff to inverse linear") try: aud.device().distance_model = aud.AUD_DISTANCE_MODEL_INVERSE_CLAMPED except aud.error as e: log.warn("Can't set 3D audio model: %s", e) return DIST_MIN = dist_min DIST_MAX = dist_max ATTENUATION = attenuation
def playSound(): sound = aud.Factory.file(bge.logic.expandPath('//sounds/checkpoint.wav')) scene = bge.logic.getCurrentScene() sound_device = aud.device() sound_device.distance_model = aud.AUD_DISTANCE_MODEL_LINEAR sound_device.listener_location = owner.worldPosition sound_device.listener_velocity = [0, 0, 0] sound_handle = sound_device.play(sound) sound_handle.relative = False sound_handle.location = owner.worldPosition sound_handle.velocity = owner.getLinearVelocity() sound_handle.distance_maximum = 100 sound_handle.distance_reference = 1
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'}
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)
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 ST__FT_filter_playback(scene): dprint("filter playbakc") context = bpy.context screen = context.screen device = aud.device() buffer = bpy.app.driver_namespace.get("ST_buffer") handle = bpy.app.driver_namespace.get("ST_handle") if handle and handle.status == 0: handle = None bpy.app.driver_namespace["ST_handle"] = None if not screen.is_animation_playing: if handle: dprint("PAUSE PAUSE PAUSE") handle.pause() #device.stopAll() return None cf = scene.frame_current if scene.use_preview_range: frame_start = scene.frame_preview_start frame_end = scene.frame_preview_end else: frame_start = scene.frame_start frame_end = scene.frame_end fps = scene.render.fps / scene.render.fps_base ''' if cf == frame_start: if not handle and buffer: handle = device.play(buffer) handle.keep = True bpy.app.driver_namespace["ST_handle"] = handle ''' if handle: if cf == frame_start: device.lock() handle.pause() handle.position = max(cf / fps, 0.0) # don't like negs if cf >= 0.0: handle.resume() device.unlock() elif cf == frame_end: handle.pause() fr = int(handle.position * fps) '''
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)