[From the beginning] the NO. 205 Section composite Wave data

Source: Internet
Author: User

Plot summary:
[Machine Xiao Wei] in the [engineer Ah Wei] accompanied by the practice of acoustic avatar.
This time we are going to look at [composite wave data].

Drama Start:

Star Calendar May 05, 2016 10:41:23, the Milky Way Galaxy Earles the Chinese Empire Jiangnan Line province.
[Engineer Ah Wei] is working with [machine Xiao Wei] to study [composite wave data].
























It's a little bit of a rule, but it's not a good description.

Find a similar type of control when you encounter actual data.




Def waveDataChoose2 (): Import Wavedata;    Import Wavename;    Array = Wavename.liter;    size = len (array);    N = 100;        Sampledata = [];        For I in Range (N): index = random.randint (0, size-1);        name = Array[index]; Tmpdata = eval (' Wavedata. ')                +name); if (len (tmpdata) > 0): if i%2 = = 0:for J in range (6): Sampledata + = TMPD                Ata            For j in Range (2): Sampledata + = Idlewave;                elif i%2 = = 1:for J in range (8): Sampledata + = Tmpdata;                     For j in range: Sampledata + = Idlewave;    #print (Len (sampledata));                return sampledata; #调用入口, generate WAV file def tmp (filename): #filename = [' combinewave_100_70_50 ', ' combinewave_100_80_50 ', ' combinewave_100_80_ ' Combinewave_110_70_50 ', ' combinewave_110_80_50 ', ' combinewave_110_80_60 ', ' combinewave_110_90_50 ', ' CombinewavE_110_90_60 ', ' combinewave_110_90_70 '];        size = len (filename);                For I in range (size): if i > 300:break; Writewav (i, filename); #生成声波数据def tmp2 (): Print (' Generate waveform starts.        >>> ');        fout= open (' Output.txt ', ' W ');                For I in range (1350, 1450, 50): A for J in range (550, 1050,):                Datastr = ' combinewave_ ' +str (i) + ' _ ' +str (j) + ' _ ' +str (k) + ' = [';                Fout.write (DATASTR);                data = Wavedatagen (I, J, K);                size = len (data);                    For n in range (size): Fout.write (str (data[n));                if (n < size-1): Fout.write (', ');                                    Fout.write (']; ');    Fout.write (' \ r \ n ');    Fout.close (); Print (' Generate waveform end, please go to output.txt to check.        '); #打印文件名 def tmp3 (): filename = [];      For I in range (550, 1050, 50): for J in range      for k in range (1350, 1450,): Datastr = ' combinewave_ ' +str (i) + ' _ ' +str (j) + ' _ ' +str (k);    Filename.append (DATASTR); Print (filename), #生成声波数据 def tmp2_2 (): Print (' Generate waveform starts.            >>> ');            fout= open (' Output.txt ', ' W ');             #终点不包括 #这里要和tmp3中的改动对应上 array = [[1000,1400,2400],[1100,1550,2600],[600,1000,2000],[900,1300,3000], [600,1400,2400],[700,1450,3200],[650,2050,2600],[550,2400,3000],[400,2300,3500], [350,2900,3500], [400, 700, 7              00], [350, 650, 650], [450,2200, 2750], [350, 2300, 2750],[500, 1500, 2600],[500,1500,3100],[450, 1700, 2400], [450, 1900, 2600],[600, 1500, 2000], [750, 1750, 3600], [2000, 6000, 6000], [7000, 7000, 7000], [1600, 6500, 6500], [2000,6500,6500], [5500, 5500, 7000], [5000, 5000,7000], [2100, 3000, 6000], [3800, 3800,             6800], [5400, 5400, 7000], [2000, 3000, 6800], [4500, 4500, 6500], [2000, 5000, 7000],[3000, 4500, 6500], [3000, 3000, 6500]];            For n in range (len (array)): I, j, k = Array[n][0], array[n][1], array[n][2];          Datastr = ' combinewave_ ' +str (i) + ' _ ' +str (j) + ' _ ' +str (k) + ' = [';            Fout.write (DATASTR);          data = Wavedatagen (I, J, K);            size = len (data);              For m in range (size): Fout.write (str (data[m));            if (n < size-1): Fout.write (', ');                        Fout.write (']; ');        Fout.write (' \ r \ n ');      Fout.close (); Print (' Generate waveform end, please go to output.txt to check.    ');      #打印文件名 def tmp3_2 (): filename = [];             #终点不包括 #这里要和tmp2中的改动对应上 array = [[1000,1400,2400],[1100,1550,2600],[600,1000,2000],[900,1300,3000], [600,1400,2400],[700,1450,3200],[650,2050,2600],[550,2400,3000],[400,2300,3500], [350,2900,3500], [400, 700, 7 00], [350, 650, 650], [450,2200, 2750], [350, 2300, 2750],[500, 1500, 2600],[500,1500,3100],[450, 1700, 2400], [450, 1900, 2600],[600, 1500, 2000], [750, 1750, 3600], [2000, 6000, 6000], [7000, 7000, 700 0], [1600, 6500, 6500], [2000,6500,6500], [5500, 5500, 7000], [5000, 5000,7000], [2100, 3000, 6000], [3800, 38 00, 6800], [5400, 5400, 7000], [2000, 3000, 6800], [4500, 4500, 6500], [2000, 5000, 7000], [3000,      4500, 6500], [3000, 3000, 6500]];          For n in range (len (array)): I, j, k = Array[n][0], array[n][1], array[n][2];          Datastr = ' combinewave_ ' +str (i) + ' _ ' +str (j) + ' _ ' +str (k);        Filename.append (DATASTR);   print (filename);


# # # # # # # # # # # # # @usage write a. wav file that can be written in binary for the acoustic data array. wav.        # @author mw# @date April 28, 2016 Thursday 14:31:34 # @param # @return # # # #def writewav (index = 0, filename = ' randwave '):    ByteArray = [];    DataArray = []; #filename = [' combinewave_100_70_50 ', ' combinewave_100_80_50 ', ' combinewave_100_80_60 ', ' combinewave_110_70_50 ', ' Combinewave_110_80_50 ', ' combinewave_110_80_60 ', ' combinewave_110_90_50 ', ' combinewave_110_90_60 ', ' combineWave_        110_90_70 '];    #样本数据阵列 Samplearray = WaveDataChoose2 ();    #样本数据点数 N = Len (Samplearray);    times = 3;        DataSize = N*times; FileSize = datasize+44;  #44为格式头部分所用字节数 #RIFF WAVE CHUNK riff_id = [0x52, 0x49, 0x46, 0x46]; # ' RIFF ' riff_size = Littleendian (fileSize-8, 4); #文件总字节数减去8 Riff_type = [0x57, 0x41,0x56, 0x45, 0x66, 0x6d, 0x74, 0x20]; # ' Wavefat ' #Format Chunk format_10_17 = [0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00]; #过滤4 + format 2 = 8 bytes Forma T_18_1B = [0x11, 0x2B, 0x00, 0x00]; #采样频率0x2B11 = 11025 format_1c_1f = [0x22, 0x56, 0x00, 0x00]; #比持率 = frequency * Channel * Sample bit = 22050 format_20_23 = [0x02, 0x00, 0x10, 0x00]; #块对齐 = number of channels * sample bits = 1*2 = 2 #Fact Chunk (optional) #Data Chunk data_24_27 = [0x64, 0x61, 0x74, 0x61]; # ' DATA ' tag data_size = Littleendian (fileSize-44, 4);        #下面的Data部分的字节数, total number of files bytes -44 #RIFF WAVE CHUNK "For I in Range (4): byte = Struct.pack (' B ', riff_id[i]);    Bytearray.append (byte);    "' RIFF = [b ' R ', b ' I ', B ' f ', B ' f '];    For I in range (4): Bytearray.append (Riff[i]);        For I in range (4): byte = Struct.pack (' B ', riff_size[i]);    Bytearray.append (byte);        ' For I in range (8): byte = Struct.pack (' B ', riff_type[i]);    Bytearray.append (byte);        #Format Chunk for I in range (8): byte = Struct.pack (' B ', format_10_17[i]);    Bytearray.append (byte);        For I in range (4): byte = Struct.pack (' B ', format_18_1b[i]);    Bytearray.append (byte); For I in range (4): byte = Struct.pack (' B ', format_1c_1f[i]);    Bytearray.append (byte);        For I in range (4): byte = Struct.pack (' B ', format_20_23[i]);        Bytearray.append (byte);        #Data Chunk for I in range (4): byte = Struct.pack (' B ', data_24_27[i]);    Bytearray.append (byte);                   "#Format_28_2B是数据块大小, Formathead is all part of the front of it formathead = [B ' W ', b ' A ', b ' V ', b ' E ', B ' f ', B ' m ', B ' t ', B ', B ' \x10 ', b ' \x00 ', b ' \x00 ', b ' \x00 ', b ' \x01 ', b ' \x00 ', b ' \x01 ', b ' \x00 ', b ' \x11 ', B ' + ', B ' \x00 ',                   B ' \x00 ', b ' "', B ' V ', b ' \x00 ', b ' \x00 ', b ' \x02 ', b ' \x00 ', b ' \x10 ', b ' \x00 ',    B ' d ', B ' a ', B ' t ', B ' a '];    For I in range (len (formathead)): Bytearray.append (Formathead[i]);        For I in range (4): byte = Struct.pack (' B ', data_size[i]);    Bytearray.append (byte); #写出到文件 print (' File write start.    >>> ');    fout= Open (filename+ ' _ ' +str (index) + '. wav ', ' WB ');        size = Len (ByteArray); For I in range (size): FouT.write (Bytearray[i]);    size = Len (Samplearray);            Sizeidle = Len (idlewave);    For j in range: For I in range (size): Fout.write (Samplearray[i]);    Fout.close (); Print (' The file is finished writing. ');

The end of this section, to know how to funeral, please see tell.

[From the beginning] the NO. 205 Section composite Wave data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.