From b5054e7596ae4abe99e2fc5a4a5510103a14d5e0 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 30 Oct 2010 12:20:00 +0000 Subject: added sound block for raw mic input --- diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index b23f5d4..a09181a 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -136,7 +136,7 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right', 'myfunc1arg', 'userdefined', 'addturtle', 'comment', 'print', 'cartesian', 'width', 'height', 'polar', 'sandwichtop_no_label', 'sandwichbottom', 'reskin'], - ['kbinput', 'readpixel', 'see', 'volume'], # 'pitch' + ['kbinput', 'readpixel', 'see', 'sound', 'volume', 'pitch'], ['journal', 'audio', 'description', 'hideblocks', 'showblocks', 'fullscreen', 'savepix', 'savesvg', 'picturelist', 'picture1x1a', 'picture1x1', 'picture2x2', 'picture2x1', @@ -221,7 +221,7 @@ BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pensize', 'color', 'shade', 'toppos', 'rightpos', 'bottompos', 'width', 'height', 'pop', 'keyboard', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'white', 'black', 'titlex', 'titley', 'leftx', 'topy', 'rightx', 'bottomy', - 'volume', 'pitch', 'voltage', 'resistance', 'gray', 'see'] + 'sound', 'volume', 'pitch', 'voltage', 'resistance', 'gray', 'see'] BOX_STYLE_MEDIA = ['description', 'audio', 'journal'] NUMBER_STYLE = ['plus2', 'product2', 'myfunc'] NUMBER_STYLE_VAR_ARG = ['myfunc1arg', 'myfunc2arg', 'myfunc3arg'] @@ -419,6 +419,7 @@ BLOCK_NAMES = { 'showblocks': [_('show blocks')], 'showaligned': [_('show aligned')], 'skin': [_('turtle shell')], + 'sound': [_('sound')], 'sqrt': ['√'], 'stack': [_('action')], 'stack1': [_('action 1')], @@ -565,6 +566,7 @@ PRIMITIVES = { 'showblocks': 'showblocks', 'showaligned': 'showaligned', 'skin': 'skin', + 'sound': 'sound', 'sqrt': 'sqrt', 'stack': 'stack', 'stack1': 'stack1', @@ -883,6 +885,7 @@ HELP_STRINGS = { 'show': _("draws text or show media from the Journal"), 'showblocks': _("restores hidden blocks"), 'skin': _("put a custom 'shell' on the turtle"), + 'sound': _("raw microphone input signal"), 'sqrt': _("calculates square root"), 'stack1': _("invokes Action 1 stack"), 'stack2': _("invokes Action 2 stack"), diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index a6b78d0..5dde533 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -301,6 +301,7 @@ class LogoCode: '(': [1, lambda self, x: self._prim_opar(x)], 'and': [2, lambda self, x, y: _and(x, y)], 'arc': [2, lambda self, x, y: self._prim_arc(self.tw.canvas.arc, x, y)], + 'audio': [1, lambda self, x: self._play_sound(x)], 'back': [1, lambda self, x: self._prim_move(self.tw.canvas.forward, -x)], 'black': [0, lambda self: BLACK], @@ -403,7 +404,7 @@ class LogoCode: 'showaligned': [1,lambda self, x: self._show(x, False)], 'showblocks': [0, lambda self: self.tw.showblocks()], 'skin': [1, lambda self, x: self._reskin(x)], - 'sound': [1, lambda self, x: self._play_sound(x)], + 'sound': [0, lambda self: self._get_sound()], 'sqrt': [1, lambda self, x: _sqrt(x)], 'stack1': [0, self._prim_stack1, True], 'stack': [1, self._prim_stack, True], @@ -1084,9 +1085,9 @@ class LogoCode: def find_sensor_blocks(self): """ Find any sensor blocks and set the appropriate sensor type """ - for name in ['volume', 'pitch', 'resistance', 'voltage']: + for name in ['sound', 'volume', 'pitch', 'resistance', 'voltage']: if len(self.tw.block_list.get_similar_blocks('block', name)): - if name in ['volume', 'pitch']: + if name in ['sound', 'volume', 'pitch']: self.tw.audiograb.set_sensor_type() return elif name == 'resistance': @@ -1388,6 +1389,14 @@ class LogoCode: else: return 0 + def _get_sound(self): + """ return raw mic in value """ + buf = self.ringbuffer.read(None, self.input_step) + if len(buf) > 0: + return float(buf[0]) + else: + return 0 + def _get_pitch(self): """ return index of max value in fft of mic in values """ buf = self.ringbuffer.read(None, self.input_step) -- cgit v0.9.1