~stanislav-fomin/seminar-assembler/trunk

« back to all changes in this revision

Viewing changes to src/seminar_assembler.py

  • Committer: stanislav-fomin at gmail
  • Date: 2013-05-11 09:14:25 UTC
  • Revision ID: stanislav-fomin@gmail.com-20130511091425-ia4059np72svhkyb
New WAV concatenation algorithm

Show diffs side-by-side

added added

removed removed

Lines of Context:
667
667
        time_prefix = ''
668
668
        if cur_ctime:
669
669
            time_prefix = cur_ctime.strftime('%Y-%m-%d-%H-%M-%S-')
 
670
 
 
671
        import wave
 
672
        
 
673
        data = []
 
674
        rawfile =  time_prefix + 'screen2log.raw'
 
675
        outfile =  time_prefix + 'screen2log.wav'
 
676
#        output = wave.open(rawfile, 'wb')
 
677
        output = open(rawfile, 'wb')
 
678
        normalnumframes = 0
 
679
        params =  None
 
680
        scmd = ''
 
681
        for num, infile in enumerate(wav_filenames):
 
682
            try:
 
683
                w = wave.open(infile, 'rb')
 
684
                if num == 0:
 
685
                    channels = w.getnchannels()  
 
686
                    bites = w.getsampwidth()*8
 
687
                    rate = w.getframerate()
 
688
                    toolsdir = self.toolsdir
 
689
                    scmd = (
 
690
                           r'%(toolsdir)s\sox\sox.exe -t raw '
 
691
                           ' -c %(channels)d -r %(rate)d -b %(bites)d '
 
692
                           ' -e signed-integer "%(rawfile)s" '
 
693
                           ' -t w64 "%(outfile)s"  '
 
694
                           ) % vars()
 
695
                    print scmd
 
696
                    pass
 
697
#                    output.setparams(w.getparams())
 
698
#                    normalnumframes = w.getnframes()               
 
699
                numframes = w.getnframes()
 
700
                #output.writeframesraw(w.readframes(numframes))
 
701
                output.write(w.readframes(numframes))
 
702
                print 'process ', infile 
 
703
                w.close()
 
704
            except:    
 
705
                print 'skip ', infile 
 
706
                pass
 
707
 
 
708
        output.close()
 
709
        print scmd
 
710
        os.system(scmd)    
 
711
        
 
712
 
 
713
    def build_screen2log_wav2(self, directory):
 
714
        """
 
715
        Write AVS-script for a bunch of small wav files
 
716
        """
 
717
        wav_filenames = []
 
718
        re_s2l = re.compile("\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d\[(?P<slot>\d\d\d)]\.wav$")
 
719
        for root, _dirnames, filenames in os.walk(directory):
 
720
            for filename in filenames:
 
721
                m = re_s2l.match(filename)
 
722
                if m:
 
723
                    wav_filenames.append(os.path.join(root, filename))
 
724
 
 
725
        wav_filenames.sort()
 
726
        if not wav_filenames:
 
727
            return
 
728
        
 
729
        wav_filenames = wav_filenames[:10000]
 
730
 
 
731
        cur_ctime = ut.guess_creation_time_by_name(wav_filenames[0])
 
732
        
 
733
        time_prefix = ''
 
734
        if cur_ctime:
 
735
            time_prefix = cur_ctime.strftime('%Y-%m-%d-%H-%M-%S-')
670
736
        
671
737
        sourcewavavslines = ['function screen2log_audio(){ ']
672
738
        for line, wav in enumerate(wav_filenames):