(self, args)
SOUND: produce a sound or switch external speaker on/off.
SOUND: produce a sound or switch external speaker on/off.
SOUND : produce a sound or switch external speaker on / off .
def sound_(self, args):
        """SOUND: produce a sound or switch external speaker on/off."""
        arg0 = next(args)
        if self._multivoice and arg0 in (tk.ON, tk.OFF):
            command = arg0
        else:
            command = None
            freq = values.to_int(arg0)
            dur = values.to_single(next(args)).to_value()
            error.range_check(-65535, 65535, dur)
            volume = next(args)
            if volume is None:
                volume = 15
            else:
                volume = values.to_int(volume)
                error.range_check(-1, 15, volume)
                if volume == -1:
                    volume = 15
            voice = next(args)
            if voice is None:
                voice = 0
            else:
                voice = values.to_int(voice)
                error.range_check(0, 2, voice) # can't address noise channel here
        list(args)
        if command is not None:
            self._sound_on = (command == tk.ON)
            self.stop_all_sound()
            return
        if dur == 0:
            self.stop_all_sound()
            return
        # Tandy only allows frequencies below 37 (but plays them as 110 Hz)
        if freq != 0:
            # 32767 is pause
            error.range_check(-32768 if self._multivoice == 'tandy' else 37, 32767, freq)
        # calculate duration in seconds
        dur_sec = dur / TICK_LENGTH
        # loop if duration less than 1/44 == 0.02272727248
        if dur < LOOP_THRESHOLD:
            # play indefinitely in background
            self.emit_tone(freq, dur_sec, fill=1, loop=True, voice=voice, volume=volume)
            self._wait_background()
        else:
            self.emit_tone(freq, dur_sec, fill=1, loop=False, voice=voice, volume=volume)
            if self._foreground:
                # continue when last tone has started playing, both on tandy and gw
                # this is different from what PLAY does!
                self._wait(1)
            else:
                self._wait_background()
def sound_ ( self , args ) : arg0 = next ( args ) if self . _multivoice and arg0 in ( tk . ON , tk . OFF ) : command = arg0 else : command = None freq = values . to_int ( arg0 ) dur = values . to_single ( next ( args ) ) . to_value ( ) error . range_check ( - 65535 , 65535 , dur ) volume = next ( args ) if volume is None : volume = 15 else : volume = values . to_int ( volume ) error . range_check ( - 1 , 15 , volume ) if volume == - 1 : volume = 15 voice = next ( args ) if voice is None : voice = 0 else : voice = values . to_int ( voice ) error . range_check ( 0 , 2 , voice ) # can't address noise channel here list ( args ) if command is not None : self . _sound_on = ( command == tk . ON ) self . stop_all_sound ( ) return if dur == 0 : self . stop_all_sound ( ) return # Tandy only allows frequencies below 37 (but plays them as 110 Hz) if freq != 0 : # 32767 is pause error . range_check ( - 32768 if self . _multivoice == 'tandy' else 37 , 32767 , freq ) # calculate duration in seconds dur_sec = dur / TICK_LENGTH # loop if duration less than 1/44 == 0.02272727248 if dur < LOOP_THRESHOLD : # play indefinitely in background self . emit_tone ( freq , dur_sec , fill = 1 , loop = True , voice = voice , volume = volume ) self . _wait_background ( ) else : self . emit_tone ( freq , dur_sec , fill = 1 , loop = False , voice = voice , volume = volume ) if self . _foreground : # continue when last tone has started playing, both on tandy and gw # this is different from what PLAY does! self . _wait ( 1 ) else : self . _wait_background ( )