[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3898] contrib/py/scripts/addons/ io_import_sound_to_anim.py: -v 0.60Beta-

vlassius santos vlassius at vlassius.com.br
Sat Oct 27 13:34:36 CEST 2012


Revision: 3898
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3898
Author:   vlassius
Date:     2012-10-27 11:34:35 +0000 (Sat, 27 Oct 2012)
Log Message:
-----------
-v 0.60Beta- 
    Included: Option to use just the beat from the audio sound
    Included: Option to exclude the beat from the audio sound
    Included: More or less sensibility options when using the beat
    Included: Audio Channel Select option

Modified Paths:
--------------
    contrib/py/scripts/addons/io_import_sound_to_anim.py

Modified: contrib/py/scripts/addons/io_import_sound_to_anim.py
===================================================================
--- contrib/py/scripts/addons/io_import_sound_to_anim.py	2012-10-27 11:32:28 UTC (rev 3897)
+++ contrib/py/scripts/addons/io_import_sound_to_anim.py	2012-10-27 11:34:35 UTC (rev 3898)
@@ -21,7 +21,7 @@
 bl_info = {
     "name": "Import: Sound to Animation",
     "author": "Vlassius",
-    "version": (0, 50),
+    "version": (0, 60),
     "blender": (2, 57, 0),
     "api": 37023,
     "location": "Select a object -> go to the Object tab ->  Import Movement From Wav File",
@@ -39,6 +39,12 @@
 - Supported Audio: .wav (wave) 8 bits and 16 bits <br>
 - At least Blender 2.5.7 is necessary to run this program.
 
+-v 0.60Beta- 
+    Included: Option to use just the beat from the audio sound
+    Included: Option to exclude the beat from the audio sound
+    Included: More or less sensibility options when using the beat
+    Included: Audio Channel Select option
+
 -v 0.50Beta- 
     Included: Auto Adjust Audio Sensity option    
     Included: 8 bits .wav file support
@@ -137,12 +143,7 @@
 import wave
 
 #TODO
-#    Arrumar - não tem rotacao para objeto - so transformacao
-#    alterar OBJETO NOMEADO
-
-#    Colocar Escolha do Canal!!
 #
-#
 #   colocar CANCELAR com ESC
 #
 #
@@ -173,7 +174,7 @@
 
     iMaxValue= context.scene.imp_sound_to_anim.action_max_value
     iMinValue= context.scene.imp_sound_to_anim.action_min_value
-    
+                
     bEscala=bRotacao=bEixo=False   
     if context.scene.imp_sound_to_anim.import_type=='imp_t_Scale':
         bEscala=True;
@@ -529,7 +530,7 @@
 # Sound Converter
 #================================================================================================== 
 
-def SoundConv(File, DivSens, Sensibil, Resol, context, bAutoSense):
+def SoundConv(File, DivSens, Sensibil, Resol, context, bAutoSense, bRemoveBeat, bUseBeat, bMoreSensible, bLessSensible, AudioChannel):
 
     try:
         Wave_read= wave.open(File, 'rb')
@@ -538,8 +539,8 @@
         return False
 
     NumCh=      Wave_read.getnchannels()
-    SampW=      Wave_read.getsampwidth() // NumCh # 8, 16, 24 32 bits
-    FrameR=     Wave_read.getframerate() // NumCh
+    SampW=      Wave_read.getsampwidth() # 8, 16, 24 32 bits
+    FrameR=     Wave_read.getframerate() 
     NumFr=      Wave_read.getnframes()
     ChkCompr=   Wave_read.getcomptype()
     
@@ -555,6 +556,17 @@
 
     context.scene.imp_sound_to_anim.Info_Import=""
     
+    # controla numero do canal
+    if AudioChannel > NumCh:
+        print("Channel number " + str(AudioChannel) + " is selected but this audio file has just " + str(NumCh) + " channels, so selecting channel "  + str(NumCh) + "!")
+        AudioChannel = NumCh
+    
+    tmpAudioChannel= AudioChannel # apenas para por na tela
+        
+    AudioChannel -= 1  #used in index sum to find the channe, adjust to first byte sample index
+    
+    if SampW ==2:  AudioChannel*=2   # se dois canais, AudioChannel=4 porque são 4 bytes    
+    
     # usado para achar contorno da onda - achando picos 
     # numero de audio frames para cada video frame
     BytesResol= int(FrameR/Resol)
@@ -577,7 +589,7 @@
     print('Total Audio Frames: \t', NumFr)
     print('Frames/s: \t\t ' + str(FrameR))
     print('# Chanels in File: \t', NumCh)
-    print('Channel in use:\t\t 1')
+    print('Channel to use:\t\t', tmpAudioChannel)    
     print('Bit/Sample/Chanel: \t ' + str(SampW*8))
     print('# Frames/Act: \t\t', DivSens)
     
@@ -604,65 +616,76 @@
         # caso de 2 canais (esterio)
         # uso apenas 2 bytes em 16 bits, ie, apenas canal esquerdo
         # [0] e [1] para CH L
-        # [2] e [3] para CH R      
-        # uso 1 byte se em 8 bits
+        # [2] e [3] para CH R   and so on   
+        # mono:1 byte to 8 bits, 2 bytes to 16 bits
+        # sterio: 2 byte to 8 bits, 4 bytes to 16 bits
         ValorPico=0
         for i in range(BytesResol):    # leio o numero de frames de audio para cada frame de video, valor em torno de 1000
             frame = Wave_read.readframes(DivSens) #loop exterior copia DivSens frames a cada frame calculado
+
             if len(frame)==0: break
 
             if bAutoSense==0:    # AutoAudioSense Desligado
-
                 if SampW ==1:
-                    if frame[0]> ValorPico: 
-                        ValorPico= frame[0]               
+                    if Sensibil ==5:
+                        frame0= frame[AudioChannel] << 6 & 255
 
-                if SampW ==2:                # frame[0] baixa       frame[1] ALTA BIT 1 TEM SINAL
-                    if Sensibil ==0:
-                        if frame[1] <127:    # se bit1 =0, usa o valor - se bit1=1 quer dizer numero negativo
-                            if frame[1] > ValorPico: 
-                                ValorPico= frame[1]               
-                            
                     elif Sensibil ==4:
-                        if frame[1] < 127:     # se bit1 =0, usa o valor
-                            frame0= ((frame[0] & 0b11111100) >> 2) | ((frame[1] & 0b00000011) << 6)                        
-                            if frame0 > ValorPico: 
-                                    ValorPico= frame0               
-
+                        frame0= frame[AudioChannel] << 5 & 255
+                        
                     elif Sensibil ==3:
-                        if frame[1] < 127:    # se bit1 =0, usa o valor
-                            frame0= ((frame[0] & 0b11110000) >> 4) | ((frame[1] & 0b00001111) << 4)                        
-                            if frame0 > ValorPico: 
-                                    ValorPico= frame0               
-
+                        frame0= frame[AudioChannel] << 4 & 255
+                        
                     elif Sensibil ==2:
-                        if frame[1] < 127:    # se bit1 =0, usa o valor
-                            frame0= ((frame[0] & 0b11100000) >> 5) | ((frame[1] & 0b00011111) << 3)                        
-                            if frame0 > ValorPico: 
-                                    ValorPico= frame0               
-
+                        frame0= frame[AudioChannel] << 3 & 255
+                        
                     elif Sensibil ==1:
-                        if frame[1] < 127:    # se bit1 =0, usa o valor
-                            frame0= ((frame[0] & 0b11000000) >> 6) | ((frame[1] & 0b00111111) << 2)                        
-                            if frame0 > ValorPico: 
-                                    ValorPico= frame0               
+                        frame0= frame[AudioChannel] << 2 & 255
+                        
+                    elif Sensibil ==0:
+                        frame0= frame[AudioChannel]
 
-                    elif Sensibil ==5:
-                        if frame[0] > ValorPico: 
-                            ValorPico= frame[0]    
+                    if frame0> ValorPico: 
+                        ValorPico= frame0    
 
+                if SampW ==2:                # frame[0] baixa       frame[1] ALTA BIT 1 TEM SINAL!
+                    if Sensibil ==5:
+                        frame0=frame[AudioChannel]                    
+                    
+                    elif frame[1+AudioChannel] <127:    # se bit1 =0, usa o valor - se bit1=1 quer dizer numero negativo
+                        if Sensibil ==0:
+                            frame0= frame[1+AudioChannel]
+
+                        elif Sensibil ==4:
+                            frame0= ((frame[AudioChannel] & 0b11111100) >> 2) | ((frame[1+AudioChannel] & 0b00000011) << 6)                        
+
+                        elif Sensibil ==3:
+                            frame0= ((frame[AudioChannel] & 0b11110000) >> 4) | ((frame[1+AudioChannel] & 0b00001111) << 4)                        
+
+                        elif Sensibil ==2:
+                            frame0= ((frame[AudioChannel] & 0b11100000) >> 5) | ((frame[1+AudioChannel] & 0b00011111) << 3)                        
+
+                        elif Sensibil ==1:
+                            frame0= ((frame[AudioChannel] & 0b11000000) >> 6) | ((frame[1+AudioChannel] & 0b00111111) << 2)                        
+
+                    if frame0 > ValorPico: 
+                        ValorPico= frame0
+                    
+
             else:   # AutoAudioSense Ligado
                 if SampW ==1:
-                    if frame[0]> MaxAudio:                         
-                        MaxAudio = frame[0] 
+                    if frame[AudioChannel]> MaxAudio:                   
+                        MaxAudio = frame[AudioChannel] 
                         
-                    if frame[0]> ValorPico: 
-                        ValorPico=frame[0]
+                    if frame[AudioChannel]> ValorPico: 
+                        ValorPico=frame[AudioChannel]
                 
+                    #print("0-> " + str(frame[0]) + "  1-> " + str(frame[1]))
+                
                 if SampW ==2:   
-                    if frame[1] < 127:
-                        tmpValorPico= frame[1] << 8
-                        tmpValorPico+=  frame[0]
+                    if frame[1+AudioChannel] < 127:
+                        tmpValorPico= frame[1+AudioChannel] << 8
+                        tmpValorPico+=  frame[AudioChannel]
                         
                         if tmpValorPico > MaxAudio:
                             MaxAudio = tmpValorPico 
@@ -711,8 +734,31 @@
         print("================================================================")           
         print('Calculating Auto Audio Sentivity, pass 2 of 2.')
         print("================================================================")           
-        print(".")           
         
+        # caso usar batida, procurar por valores próximos do maximo e zerar restante.
+        # caso retirar batida, zerar valores próximos do maximo
+        
+        UseMinim=0
+        UseMax=0
+   
+        if bUseBeat==1:
+            print("Trying to use just the beat.")           
+            UseMinim= MaxAudio*0.8
+            if bMoreSensible:            
+                UseMinim= MaxAudio*0.7
+            elif bLessSensible:            
+                UseMinim= MaxAudio*0.9
+                    
+        if bRemoveBeat==1:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list