Commits

Anonymous committed 320b34a

added antialiasing butterflys

  • Participants
  • Parent commits f08245f

Comments (0)

Files changed (2)

 
 class mp3_frame_decoded_data:
     def __init__(self):
-        self.dq_vals       = zeros( (2,2,32,18), dtype=float)
-        self.lr            = zeros( (2,2,32,18), dtype=float)
+        self.dq_vals          = zeros( (2,2,32,18), dtype=float)
+        self.lr_vals          = zeros( (2,2,32,18), dtype=float)
+        self.reordered_vals   = zeros( (2,2,32,18), dtype=float)
+        self.antialiased_vals = zeros( (2,2,32,18), dtype=float)
+
 
 class mp3_frame:
     def __init__(self):
     def process_stereo(self):
         has_intensity_stereo = (self.cur_frame.hdr.mode_extention & INTENSITY_STEREO_BIT)
         has_mid_side_stereo = (self.cur_frame.hdr.mode_extention & MID_SIDE_STEREO_BIT)
-        lr      = self.cur_frame.decoded_data.lr
+        lr      = self.cur_frame.decoded_data.lr_vals
         dq_vals = self.cur_frame.decoded_data.dq_vals
         
         for gr in xrange(2):                       
                     for ss in xrange(SSLIMIT): 
                         lr[gr][0][sb][ss] = dq_vals[gr][0][sb][ss]
 
-        print lr
 
     def process_intensity_stereo(self, gr, is_pos):
         ch = 0  
         return is_ratio
     
     def reorder_samples(self):
-        pass
+        smpl_rate = self.cur_frame.hdr.smpl_rate
+        lr   = self.cur_frame.decoded_data.lr_vals
+        ro   = self.cur_frame.decoded_data.reordered_vals
+        
+        for gr in xrange(2):
+            for ch in xrange(2):
+                if (self.cur_frame.side_info.window_switching_flag[ch][gr] and (self.cur_frame.side_info.block_type[ch][gr] == 2)):
+                    if (self.cur_frame.side_info.mixed_block_flag[ch][gr]):
+                        # NO REORDER FOR LOW 2 SUBBANDS 
+                        for sb in xrange(2):
+                            for ss in xrange(SSLIMIT):
+                                ro[gr][ch][sb][ss] = lr[gr][ch][sb][ss];
+                    
+                        # REORDERING FOR REST SWITCHED SHORT 
+                        sfb_start=sfBandIndex_s[smpl_rate][3]
+                        sfb_lines=sfBandIndex_s[smpl_rate][4] - sfb_start
+             
+                        for sfb in xrange(3,13):
+                            for window in xrange(3):                      
+                                for freq in xrange(sfb_lines):
+                                    src_line = sfb_start*3 + window*sfb_lines + freq 
+                                    des_line = (sfb_start*3) + window + (freq*3)
+                                    ro[gr][ch][des_line/SSLIMIT][des_line%SSLIMIT] = lr[gr][ch][src_line/SSLIMIT][src_line%SSLIMIT]
+
+                            sfb_start=sfBandIndex_s[smpl_rate][sfb]
+                            sfb_lines=sfBandIndex_s[smpl_rate][sfb+1] - sfb_start
+                               
+                       
+                    else: 
+                        #pure short                
+                        sfb_start=0
+                        sfb_lines=sfBandIndex_s[smpl_rate][1] 
+                        for sfb in xrange(13): 
+                            for window in xrange(3):
+                                for freq in xrange(sfb_lines):
+                                    src_line = sfb_start*3 + window*sfb_lines + freq 
+                                    des_line = (sfb_start*3) + window + (freq*3)
+                                    ro[gr][ch][des_line/SSLIMIT][des_line%SSLIMIT] = lr[gr][ch][src_line/SSLIMIT][src_line%SSLIMIT]
+
+                            sfb_start=sfBandIndex_s[smpl_rate][sfb]
+                            sfb_lines=sfBandIndex_s[smpl_rate][sfb+1] - sfb_start
+
+                else:
+                    #long blocks */
+                    for sb in xrange(SBLIMIT):
+                        for ss in xrange(SSLIMIT): 
+                            ro[gr][ch][sb][ss] = lr[gr][ch][sb][ss]
+               
 
     def antialias_samples(self):
-        pass
+        cs = [ 1.0/sqrt(1.0 + ci*ci) for ci in antialias_Ci]
+        ca = [  ci/sqrt(1.0 + ci*ci) for ci in antialias_Ci]
+
+        ro   = self.cur_frame.decoded_data.reordered_vals
+        aa   = self.cur_frame.decoded_data.antialiased_vals               
+
+        for gr in xrange(2):
+            for ch in xrange(2):          
+                for sb in xrange(SBLIMIT):
+                    for ss in xrange(SSLIMIT): 
+                        aa[gr][ch][sb][ss] = ro[gr][ch][sb][ss]
+
+                if  ((self.cur_frame.side_info.window_switching_flag[ch][gr] and (self.cur_frame.side_info.block_type[ch][gr] == 2)) and 
+                    (not self.cur_frame.side_info.mixed_block_flag[ch][gr])):
+                    return;
+
+                if ( self.cur_frame.side_info.window_switching_flag[ch][gr] and self.cur_frame.side_info.mixed_block_flag[ch][gr] and
+                 (self.cur_frame.side_info.block_type[ch][gr] == 2)):
+                    sblim = 1
+                else:
+                    sblim = SBLIMIT-1
+
+                # 31 alias-reduction operations between each pair of sub-bands 
+                # with 8 butterflies between each pair                         
+                for sb in xrange(sblim):   
+                    for ss in xrange(8):       
+                        bu = ro[gr][ch][sb][17-ss];
+                        bd = ro[gr][ch][sb+1][ss];
+                        aa[gr][ch][sb][17-ss] = (bu * cs[ss]) - (bd * ca[ss])
+                        aa[gr][ch][sb+1][ss]  = (bd * cs[ss]) + (bu * ca[ss])
+                       
 
     def hybrid_synthesis(self):
         pass
                     if(self.cur_frame.side_info.mixed_block_flag[ch][gr]):
                         #mixed blocks
                         print "mixed scale blocks not supported yet"
-                        pass
                     else:
                         #short blocks
                         for i in xrange(2):

File pyMP3_tables.py

 
 pretab = [0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0]
 
+antialias_Ci = [ -0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037]
+
 class huffman_table:
     def __init__(self, tbl_type, tbl_idx, treelen, xlen, ylen, linbits, values):
         self.tbl_type = tbl_type