Exemplo n.º 1
0
 def randomize_parameters(self):
     ''' This method should be overrided to get some more interesting random generation of the parameters.
         Note : When overriding this one, you should also override _used_parameters.
         
         In general, returns the number of times it had to try again new parameters before giving something that makes sense.
         This is for audio units where generating can give a bad sound and we need to start again.
     '''
     
     for p in self.params:
         RF.randomize_parameter(p, self.au, RF.uniform)
     return 0
Exemplo n.º 2
0
    def randomize_parameters(self):
        ''' This method should be overrided to get some more interesting random generation of the parameters.
            Note : When overriding this one, you should also override _used_parameters.
            
            In general, returns the number of times it had to try again new parameters before giving something that makes sense.
            This is for audio units where generating can give a bad sound and we need to start again.
        '''

        for p in self.params:
            RF.randomize_parameter(p, self.au, RF.uniform)
        return 0
Exemplo n.º 3
0
 def randomize_parameters(self):
     self.reset_parameters()
     
     self.au.bypass = False if NR.uniform() < self.prob_on else True
     if self.au.bypass == True:
         return 0
         
     p = self.params
     p[0].value = 1.
     p[1].value = 1.
     while p[0].value > .4 and p[1].value > .9 - p[0].value: # hand-picked rule
         for i in [0,1]:
             # greater than .2 to ensure some chorus
             RF.randomize_parameter(p[i], self.au, RF.uniform_custom(.2, 1.))
     # greater than .2 again to ensure some chorus 
     RF.randomize_parameter(p[2], self.au, RF.uniform_custom(.2, 1.))
     
     return 0
Exemplo n.º 4
0
    def randomize_parameters(self):
        self.reset_parameters()

        self.au.bypass = False if NR.uniform() < self.prob_on else True
        if self.au.bypass == True:
            return 0

        p = self.params
        p[0].value = 1.
        p[1].value = 1.
        while p[0].value > .4 and p[
                1].value > .9 - p[0].value:  # hand-picked rule
            for i in [0, 1]:
                # greater than .2 to ensure some chorus
                RF.randomize_parameter(p[i], self.au,
                                       RF.uniform_custom(.2, 1.))
        # greater than .2 again to ensure some chorus
        RF.randomize_parameter(p[2], self.au, RF.uniform_custom(.2, 1.))

        return 0
Exemplo n.º 5
0
    def randomize_parameters(self, nb_trials=10):
        """
        Returns the number of trials if it succeded, -1 if not.
        But -1 should very unusual.
        
        nb_trials : nb of time it will try before it stops and returns -1
        """
        self.au.bypass = False if uniform() < self.prob_on else True
        if self.au.bypass == True:
            self.reset_parameters()        
            return 0
            
        for no_trial in range(nb_trials):
            self.reset_parameters()        

            # we do so Shelf is in [0, .4]u[.6, 1.], so there is at least some effect
            RF.randomize_parameter(self.params_dict['Shelf'], self.au, RF.uniform_custom(0., .4))
            self.params_dict['Shelf'].value += [0., .6][randint(2)]        
            RF.randomize_parameter(self.params_dict['Bass lift'], self.au, RF.uniform)
            RF.randomize_parameter(self.params_dict['Shelf q'], self.au, RF.uniform_custom(.5, 1.))

                
            normalize_volume(self.host, self.params_dict['Volume'], target_peak=self.volume, verbose=False)
            #self.params_dict['Volume'].value = .9
            vol = self.params_dict['Volume'].value
            
            #print 'TAL USE volume : ', vol.value
                
            if vol < 1. and vol > 0.:
                return no_trial
        return -1
Exemplo n.º 6
0
    def randomize_parameters(self, nb_trials=10):
        """
        Returns the number of trials if it succeded, -1 if not.
        But -1 should very unusual.
        
        nb_trials : nb of time it will try before it stops and returns -1
        """
        self.au.bypass = False if uniform() < self.prob_on else True
        if self.au.bypass == True:
            self.reset_parameters()
            return 0

        for no_trial in range(nb_trials):
            self.reset_parameters()

            # we do so Shelf is in [0, .4]u[.6, 1.], so there is at least some effect
            RF.randomize_parameter(self.params_dict['Shelf'], self.au,
                                   RF.uniform_custom(0., .4))
            self.params_dict['Shelf'].value += [0., .6][randint(2)]
            RF.randomize_parameter(self.params_dict['Bass lift'], self.au,
                                   RF.uniform)
            RF.randomize_parameter(self.params_dict['Shelf q'], self.au,
                                   RF.uniform_custom(.5, 1.))

            normalize_volume(self.host,
                             self.params_dict['Volume'],
                             target_peak=self.volume,
                             verbose=False)
            #self.params_dict['Volume'].value = .9
            vol = self.params_dict['Volume'].value

            #print 'TAL USE volume : ', vol.value

            if vol < 1. and vol > 0.:
                return no_trial
        return -1
Exemplo n.º 7
0
 def randomize_parameters(self, nb_trials=10):
     """
     Returns the number of trials if it succeded, -1 if not.
     But -1 should very unusual.
     
     nb_trials : nb of time it will try before it stops and returns -1
     """
     self.au.bypass = False if NR.uniform() < self.prob_on else True
     if self.au.bypass == True:
         self.reset_parameters()        
         return 0
         
     for no_trial in range(nb_trials):
         self.reset_parameters()        
         
         RF.randomize_parameter(self.params_dict['inputdrive'], self.au, RF.uniform_custom(.45, 1.))
         RF.randomize_parameter(self.params_dict['delaytime'], self.au, RF.uniform_custom(0.017, .04))
         RF.randomize_parameter(self.params_dict['feedback'], self.au, RF.uniform_custom(0., .3))
         
         f = lambda x : -.15*x**2 + .42*x + .18
         hp = self.params_dict['highcut']
         cp = self.params_dict['cutoff']
         hp.value = 0.; cp.value = 0.
         while cp.value < f(hp.value):
             RF.randomize_parameter(hp, self.au, RF.uniform)
             RF.randomize_parameter(cp, self.au, RF.uniform)
             
         param_vol = self.params_dict['dry']
         normalize_volume(self.host, param_vol, target_peak=self.volume, verbose=False)
         vol = param_vol.value
         RF.randomize_parameter(self.params_dict['wet'], self.au, RF.uniform_custom(vol/3., vol))
         if vol < param_vol.range[1] and vol > param_vol.range[0]:
             return no_trial
     return -1
Exemplo n.º 8
0
    def randomize_parameters(self, nb_trials=10):
        """
        Returns the number of trials if it succeded, -1 if not.
        But -1 should very unusual.
        
        nb_trials : nb of time it will try before it stops and returns -1
        """
        self.au.bypass = False if NR.uniform() < self.prob_on else True
        if self.au.bypass == True:
            self.reset_parameters()
            return 0

        for no_trial in range(nb_trials):
            self.reset_parameters()
            # dist
            # 0. 2/3 of the time, uniform between 0. 1. for the rest of the time
            RF.randomize_parameter(self.params_dict['DistTube'], self.au,
                                   RF.uniform_custom(-2., 1.))
            self.params_dict['DistMech'].value = max(
                self.params_dict['DistMech'].value, 0.)
            RF.randomize_parameter(self.params_dict['DistTube'], self.au,
                                   RF.uniform_custom(-2., 1.))
            self.params_dict['DistTube'].value = max(
                self.params_dict['DistTube'].value, 0.)

            # cut off
            RF.randomize_parameter(self.params_dict['MmFilterOn'], self.au,
                                   RF.weighted_list([0., 1.], [.33, .67]))
            if self.params_dict['MmFilterOn'].value == 1.:
                RF.randomize_parameter(self.params_dict['MmFilterCutoff'],
                                       self.au, RF.uniform)
                RF.randomize_parameter(self.params_dict['MmFilterRes'],
                                       self.au, RF.uniform)

            # Compress
            # off half the time
            temp = RF.weighted_list([False, True], [.33, .67])(None, None)
            if temp:
                RF.randomize_parameter(self.params_dict['CompressAmount'],
                                       self.au, RF.uniform)
            RF.randomize_parameter(self.params_dict['CompressMode'], self.au,
                                   RF.weighted_list([0., 1.], [.5, .5]))

            # Master
            RF.randomize_parameter(self.params_dict['MasterMix'], self.au,
                                   RF.uniform)
            normalize_volume(self.host,
                             self.params_dict['MasterVolume'],
                             target_peak=self.volume,
                             volumes=[.5, .7, .9],
                             verbose=False)

            #for p in self.params:
            #    if not p.name.startswith('Unused'):
            #        print p

            vol = self.params_dict['MasterVolume'].value
            #raw_input('test')
            if vol < 1. and vol > 0.:
                return no_trial
        return -1
Exemplo n.º 9
0
    def randomize_parameters(self, nb_trials=10):
        """
        Returns the number of trials if it succeded, -1 if not.
        But -1 should very unusual.
        
        nb_trials : nb of time it will try before it stops and returns -1
        """
        self.au.bypass = False if NR.uniform() < self.prob_on else True
        if self.au.bypass == True:
            self.reset_parameters()
            return 0

        for no_trial in range(nb_trials):
            self.reset_parameters()

            RF.randomize_parameter(self.params_dict['inputdrive'], self.au,
                                   RF.uniform_custom(.45, 1.))
            RF.randomize_parameter(self.params_dict['delaytime'], self.au,
                                   RF.uniform_custom(0.017, .04))
            RF.randomize_parameter(self.params_dict['feedback'], self.au,
                                   RF.uniform_custom(0., .3))

            f = lambda x: -.15 * x**2 + .42 * x + .18
            hp = self.params_dict['highcut']
            cp = self.params_dict['cutoff']
            hp.value = 0.
            cp.value = 0.
            while cp.value < f(hp.value):
                RF.randomize_parameter(hp, self.au, RF.uniform)
                RF.randomize_parameter(cp, self.au, RF.uniform)

            param_vol = self.params_dict['dry']
            normalize_volume(self.host,
                             param_vol,
                             target_peak=self.volume,
                             verbose=False)
            vol = param_vol.value
            RF.randomize_parameter(self.params_dict['wet'], self.au,
                                   RF.uniform_custom(vol / 3., vol))
            if vol < param_vol.range[1] and vol > param_vol.range[0]:
                return no_trial
        return -1
Exemplo n.º 10
0
    def randomize_parameters(self, nb_trials=10):
        """
        Returns the number of trials if it succeded, -1 if not.
        But -1 should very unusual.
        
        nb_trials : nb of time it will try before it stops and returns -1
        """
        self.au.bypass = False if NR.uniform() < self.prob_on else True
        if self.au.bypass == True:
            self.reset_parameters()        
            return 0
            
        for no_trial in range(nb_trials):
            self.reset_parameters()
            RF.randomize_parameter(self.params_dict['Pre Delay'], self.au, RF.uniform_custom(0., .35))
            RF.randomize_parameter(self.params_dict['Room Size'], self.au, RF.uniform)
            RF.randomize_parameter(self.params_dict['Damp'], self.au, RF.uniform)

            
            # high and low cut
            a,b,c = 2.833, -1.5167, 0.4
            f = lambda x : a*x**2 + b*x + c
            hc = self.params_dict['High Cut']
            lc = self.params_dict['Low Cut']
            hc.value = 0.; lc.value = 0.
            while hc.value < f(lc.value):
                RF.randomize_parameter(hc, self.au, RF.uniform_custom(.2, 1.))
                RF.randomize_parameter(lc, self.au, RF.uniform_custom(0., .8))
                
            #for x in self._used_parameters():
             #   print self.params_dict[x]
            
            param_vol = self.params_dict['Dry']
            normalize_volume(self.host, param_vol, target_peak=self.volume, volumes = [.5, .7, .9], verbose=False)
                    
            vol = param_vol.value
            if vol < 1. and vol > 0.:
                RF.randomize_parameter(self.params_dict['Wet'], self.au, RF.uniform_custom(vol*3./4., vol))
                return no_trial
        return -1
Exemplo n.º 11
0
            def set_some_osc_params(osc_no):
                ''' Setting up oscillator 'osc_no'.
                '''
                
                if verbose:
                    print '---------'
                    print '- OSC %i -' % osc_no
                    print '---------'

                # let's mute everything excep 'osc_no'
                for i in [1,2,3]:
                    params['MIX%i_Level' % i].value = (1. if i == osc_no else 0.)
                    
                # selecting which type of wave
                listes = [range(1,6), range(0,6), range(0,6)+[8]] # it can only be sin, tri, rect, saw, table / + off / + noise
                RF.randomize_parameter(params["OSC%i_Wave" % osc_no], au, RF.uniform_list(listes[osc_no-1]))
                
                if verbose:
                    print 'Wave type : %s' % params["OSC%i_Wave" % osc_no].get_str_from_value()

                if params["OSC%i_Wave" % osc_no].value == 0: # if it's OFF we won't do nothing
                    return
                    
                # selecting other things
                while True : 
                    RF.randomize_parameter(params['OSC%i_Width' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['OSC%i_Stack' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['OSC%i_StackOffset' % osc_no], au, RF.uniform_custom(0., .55))
                    RF.randomize_parameter(params['SHP%i_FilterType' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_CutOff' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_Resonance' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_ShapeType' % osc_no], au, RF.uniform_list(range(4)+[5]))
                    if verbose: 
                        print 'Shape type : %s (%i)' % (params['SHP%i_ShapeType' % osc_no].get_str_from_value(), params['SHP%i_ShapeType' % osc_no].value), 
                        
                    if params['SHP%i_ShapeType' % osc_no].value == 3:
                        RF.randomize_parameter(params['SHP%i_Bias' % osc_no], au, RF.uniform_custom(0., .25))
                    else:
                        RF.randomize_parameter(params['SHP%i_Bias' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_Drive' % osc_no], au, RF.uniform)
                    if verbose:
                        print 'and bias is %s' % params['SHP%i_Bias' % osc_no].get_str_from_value()
                        
                    
                    # some "not osc1" specific parameters
                    if osc_no != 1:
                        RF.randomize_parameter(params['OSC%i_Detune' % osc_no], au, RF.normal(.5, .05))
                        RF.randomize_parameter(params['OSC%i_SyncOffset' % osc_no], au, RF.uniform)
                        
                    if verbose:
                        print 'listening to OSC %i' % osc_no
                        #host.play()
                        
                    params["MIX%i_Level" % osc_no].value = .2
                    if check_volume(host, verbose=verbose) > .004:
                        break
                    if verbose:
                        print "Something doesn't sound good : let's do it again."
Exemplo n.º 12
0
    def randomize_parameters(self, nb_trials=10):
        """
        Generate random parameters in a clever way for audiounit 'au' (which must be automat1 by alphakanal)
        au must be in the graph of host.
        
        Returns the number of trials if it succeded, -1 if not.
        But -1 should very unusual.
        
        nb_trials : nb of time it will try before it stops and returns -1
        """
        #for trial_no in range(nb_trials):
        trial_no=0
        while True:
            self.reset_parameters()        
        
            
            verbose = False
            
            au = self.au
            host = self.host
            params = self.params_dict
            params["MIX1_Level"] = params["Mix1_Level"]
            

            self.reset_parameters()
                
            def set_some_osc_params(osc_no):
                ''' Setting up oscillator 'osc_no'.
                '''
                
                if verbose:
                    print '---------'
                    print '- OSC %i -' % osc_no
                    print '---------'

                # let's mute everything excep 'osc_no'
                for i in [1,2,3]:
                    params['MIX%i_Level' % i].value = (1. if i == osc_no else 0.)
                    
                # selecting which type of wave
                listes = [range(1,6), range(0,6), range(0,6)+[8]] # it can only be sin, tri, rect, saw, table / + off / + noise
                RF.randomize_parameter(params["OSC%i_Wave" % osc_no], au, RF.uniform_list(listes[osc_no-1]))
                
                if verbose:
                    print 'Wave type : %s' % params["OSC%i_Wave" % osc_no].get_str_from_value()

                if params["OSC%i_Wave" % osc_no].value == 0: # if it's OFF we won't do nothing
                    return
                    
                # selecting other things
                while True : 
                    RF.randomize_parameter(params['OSC%i_Width' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['OSC%i_Stack' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['OSC%i_StackOffset' % osc_no], au, RF.uniform_custom(0., .55))
                    RF.randomize_parameter(params['SHP%i_FilterType' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_CutOff' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_Resonance' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_ShapeType' % osc_no], au, RF.uniform_list(range(4)+[5]))
                    if verbose: 
                        print 'Shape type : %s (%i)' % (params['SHP%i_ShapeType' % osc_no].get_str_from_value(), params['SHP%i_ShapeType' % osc_no].value), 
                        
                    if params['SHP%i_ShapeType' % osc_no].value == 3:
                        RF.randomize_parameter(params['SHP%i_Bias' % osc_no], au, RF.uniform_custom(0., .25))
                    else:
                        RF.randomize_parameter(params['SHP%i_Bias' % osc_no], au, RF.uniform)
                    RF.randomize_parameter(params['SHP%i_Drive' % osc_no], au, RF.uniform)
                    if verbose:
                        print 'and bias is %s' % params['SHP%i_Bias' % osc_no].get_str_from_value()
                        
                    
                    # some "not osc1" specific parameters
                    if osc_no != 1:
                        RF.randomize_parameter(params['OSC%i_Detune' % osc_no], au, RF.normal(.5, .05))
                        RF.randomize_parameter(params['OSC%i_SyncOffset' % osc_no], au, RF.uniform)
                        
                    if verbose:
                        print 'listening to OSC %i' % osc_no
                        #host.play()
                        
                    params["MIX%i_Level" % osc_no].value = .2
                    if check_volume(host, verbose=verbose) > .004:
                        break
                    if verbose:
                        print "Something doesn't sound good : let's do it again."
                
            for i in [1,2,3]:
                set_some_osc_params(i)
                            

            # OSC volumes
            params['MIX1_Level'].value = 1.
            for i in [2,3]:
                if params['OSC%i_Wave' % i].value == 0:
                    params['MIX%i_Level' % i].value = params['MIX%i_Level' % i].default_value
                elif params['OSC%i_Wave' %i].value == 8: # if it's noise
                    RF.randomize_parameter(params['MIX%i_Level' % i], au, RF.uniform_custom(0., .25)) 
                else:
                    RF.randomize_parameter(params['MIX%i_Level' % i], au, RF.uniform) 
                
            
                         
            # envelop
            RF.randomize_parameter(params['AMP_Attack'], self.au, RF.normal(0., .25)) # if neg it becomes 0. alone
            for suffix in 'Hold Decay Sustain'.split():
                RF.randomize_parameter(params['AMP_%s' % suffix], self.au, RF.uniform)
            RF.randomize_parameter(params['AMP_Release'], self.au, RF.normal(.3, .5))

                         
            normalize_volume(host, params["OUT_Master"], target_peak=self.volume, verbose=verbose)
            vol = params['OUT_Master']
            
            if vol.value < vol.range[1] and vol.value > vol.range[0]:
                return trial_no
            trial_no+=1
        return -1
Exemplo n.º 13
0
    def randomize_parameters(self, nb_trials=10):
        """
        Returns the number of trials if it succeded, -1 if not.
        But -1 should very unusual.
        
        nb_trials : nb of time it will try before it stops and returns -1
        """
        self.au.bypass = False if NR.uniform() < self.prob_on else True
        if self.au.bypass == True:
            self.reset_parameters()
            return 0

        for no_trial in range(nb_trials):
            self.reset_parameters()
            # dist
            # 0. 2/3 of the time, uniform between 0. 1. for the rest of the time
            RF.randomize_parameter(self.params_dict["DistTube"], self.au, RF.uniform_custom(-2.0, 1.0))
            self.params_dict["DistMech"].value = max(self.params_dict["DistMech"].value, 0.0)
            RF.randomize_parameter(self.params_dict["DistTube"], self.au, RF.uniform_custom(-2.0, 1.0))
            self.params_dict["DistTube"].value = max(self.params_dict["DistTube"].value, 0.0)

            # cut off
            RF.randomize_parameter(self.params_dict["MmFilterOn"], self.au, RF.weighted_list([0.0, 1.0], [0.33, 0.67]))
            if self.params_dict["MmFilterOn"].value == 1.0:
                RF.randomize_parameter(self.params_dict["MmFilterCutoff"], self.au, RF.uniform)
                RF.randomize_parameter(self.params_dict["MmFilterRes"], self.au, RF.uniform)

            # Compress
            # off half the time
            temp = RF.weighted_list([False, True], [0.33, 0.67])(None, None)
            if temp:
                RF.randomize_parameter(self.params_dict["CompressAmount"], self.au, RF.uniform)
            RF.randomize_parameter(self.params_dict["CompressMode"], self.au, RF.weighted_list([0.0, 1.0], [0.5, 0.5]))

            # Master
            RF.randomize_parameter(self.params_dict["MasterMix"], self.au, RF.uniform)
            normalize_volume(
                self.host,
                self.params_dict["MasterVolume"],
                target_peak=self.volume,
                volumes=[0.5, 0.7, 0.9],
                verbose=False,
            )

            # for p in self.params:
            #    if not p.name.startswith('Unused'):
            #        print p

            vol = self.params_dict["MasterVolume"].value
            # raw_input('test')
            if vol < 1.0 and vol > 0.0:
                return no_trial
        return -1