A kind of implementation method that changes vibrating effect with music
Technical field
The present invention relates to a kind of vibration realizing method, particularly relate to a kind of implementation method that changes vibrating effect with music.
Background technology:
The electronic product that has music playing function at present, as mobile phone, MP3, MP4 etc., the vibrating function of this electronic product is used more and more widely, some vibration utilizes audio amplifier to realize, some vibration utilizes motor to realize, and along with the development of technology, increasing manufacturer selects to adopt motor to replace audio amplifier to carry out the design of hardware circuit.
But now the electronic product that drives vibration with motor is realizing aspect the vibration being the vibration of simple repetition rhythm, can not drive electronic product according to the vibration rhythm in the audio file and carry out rhythmical vibration, can not satisfy the requirement of people for the different vibration of different music rhythm.
Summary of the invention:
The objective of the invention is to overcome the deficiencies in the prior art, a kind of implementation method that changes vibrating effect with music is provided, be used for the electronic product that all have music playing function, after audio file decoding and do not carry out before the digital-to-analog conversion interruption being analyzed, adopt the method for analyzing pulse-code modulation PCM (abbreviation of English Pulse Code Modulation) data, size according to volume, and the power that changes brings the different of sense learning through practice for people's ear with each frequency, calculate the power CD-ROM drive motor vibration then of motor, make electronic product change rhythmical vibration, bring the experience of people's happiness according to music rhythm.
In order to achieve the above object, the technical solution used in the present invention is, a kind of implementation method with music variation vibrating effect has two kinds of schemes to realize: scheme one begins to analyze the information state of one-period for judging PCM_Level_L greater than zero count less than having no progeny in zero; Scheme two begins to analyze the information state of one-period for judging PCM_Level_L less than zero count greater than having no progeny in zero.
The step of scheme one is as follows:
This method relates to following data, cycle is T, the PCM data that read from the PCM buffer are represented with PCM_Level_L, the quantity of sampled point is SubCount in the one-period, the maximum of SubCount is MaxSubCount, amplitude maximum MaxV_tmp in the interruption, the amplitude reference value is set to constant VLowLimit, the sampled point reference value is set to constant FLowLimit, the maximum of interior all point of interruption amplitudes of sampling period is MaxV, effective period, number was that frequency is ICount, and the amplitude minimum reference value of establishing is MinV_T, and the time in sampling period is set according to product performance by realizing.
Step 1, to after the audio file decoding not before the PCM data conversion becomes final speech simulation waveform, the data of intercepting PCM are read each PCM_Level_L from the PCM buffer;
Step 2, judge that PCM_Level_L is whether greater than zero;
Step 3, PCM_Level_L>0, then execution in step 3.1, PCM_Level_L≤0, then execution in step 3.2;
Step 3.1, PCM_Level_L>0 then begin counting, obtain the quantity SubCount of sampled point in the subcycle, and write down the amplitude maximum MaxV_tmp of this moment, skip to step 5;
Step 3.2, PCM_Level_L≤0 then begin to analyze SubCount and the MaxV_tmp that positive amplitude in the PCM buffer is read in an interruption, and execution in step 4;
Step 4, satisfy SubCount<FLowLimit simultaneously, MaxV_tmp<VLowLimit's, then be judged as high-frequency noise and filter out, do not add up, be periods of inactivity, count the maximum of SubCount, MaxV_tmp;
Step 5, count the maximum MaxV of a sampling period MaxV_tmp, the maximum MaxSubCount among the SubCount, and count MaxV, MaxSubCount in the sampling period, and count the quantity of ICount effective period;
The maximum MaxV that step 6, sampling period interior front and back double sampling of comparison obtain, establishing difference is MaxV_L;
Step 7, judge that MaxV_L is whether less than-MinV_T;
Step 8, MaxV_L<-MinV_T, then execution in step 8.1, MaxV_L 〉=-MinV_T, then execution in step 8.2;
Step 8.1, MaxV_L<-MinV_T, then directly establish MaxV_L=0, motor stops vibration;
Step 8.2, MaxV_L 〉=-MinV_T, then execution in step 9;
Step 9, EP (end of program) are proceeded next round and are judged.
Audio file in the above-mentioned steps 1 refers to the audio file of existing form, as mp3 file, wav file, wma file, midi file, winamp etc.
The step of scheme two is as follows:
This method relates to following data, cycle is T, the PCM data that read from the PCM buffer are represented with PCM_Level_L, whenever a sampled point is a sampling subcycle by just changeing negative, the quantity of sampled point is SubCount in the subcycle, the maximum of SubCount is MaxSubCount, amplitude maximum MaxV_tmp in the interruption, the amplitude reference value is set to constant VLowLimit, the sampled point reference value is set to constant FLowLimit, the maximum of all point of interruption amplitudes is MaxV in the one-period, and be that frequency is ICount effective period, and the amplitude minimum reference value of establishing is MinV_T
Step 1, to after the audio file decoding not before the PCM data conversion becomes final speech simulation waveform, the data of intercepting PCM are read each PCM_Level_L from the PCM buffer;
Step 2, judge that PCM_Level_L is whether less than zero;
Step 3, PCM_Level_L<0, then execution in step 3.1, PCM_Level_L 〉=0, then execution in step 3.2;
Step 3.1, PCM_Level_L<0 then begin counting, obtain the quantity SubCount of sampled point in the one-period, and write down the amplitude maximum MaxV_tmp of this moment, skip to step 5;
Step 3.2, PCM_Level_L 〉=0 then begin to analyze SubCount and the MaxV_tmp that negative amplitude in the PCM buffer is read in an interruption, and execution in step 4;
Step 4, satisfy SubCount<FLowLimit simultaneously, MaxV_tmp<VLowLimit's, then be judged as high-frequency noise and filter out, do not add up, be periods of inactivity, count the maximum of SubCount, MaxV_tmp;
Step 5, count the maximum MaxV of MaxV_tmp in a sampling period, the maximum MaxSubCount among the SubCount, and count MaxV, MaxSubCount in the one-period, and count the quantity of ICount effective period;
The maximum MaxV that step 6, sampling period interior front and back double sampling of comparison obtain, establishing difference is MaxV_L;
Step 7, judge that MaxV_L is whether less than-MinV_T;
Step 8, MaxV_L<-MinV_T, then execution in step 8.1, MaxV_L 〉=-MinV_T, then execution in step 8.2;
Step 8.1, MaxV_L<-MinV_T, then directly establish MaxV_L=0, motor stops vibration;
Step 8.2, MaxV_L 〉=-MinV_T, then execution in step 9;
Step 9, EP (end of program) are carried out next round and are judged.
Audio file in the above-mentioned steps 1 refers to the audio file of existing form, as mp3 file, wav file, wma file, midi file, winamp etc.
Above method is used for all electronic products that have music playing function, can analyze left and right acoustic channels simultaneously, also can analyze left and right acoustic channels, stereo separately.
Compared with prior art, the invention has the beneficial effects as follows: the method that adopts the PCM data, size according to volume, and the power that changes brings the different of sense learning through practice for people's ear with each frequency, calculate the power CD-ROM drive motor vibration then of motor, make electronic product change rhythmical vibration, bring the experience of people's happiness according to music rhythm, the present invention just analyzes at the PCM data in addition, is not subjected to the restriction of the platform in the electronic product.
Description of drawings:
Fig. 1 is the program flow diagram of embodiments of the invention 1;
Fig. 2 is the program flow diagram of embodiments of the invention 2.
Embodiment:
Central idea of the present invention is to overcome the deficiencies in the prior art, a kind of implementation method that changes vibrating effect with music is provided, adopt the method for analyzing pulse-code modulation PCM data, size according to volume, and the power that changes brings the different of sense learning through practice for people's ear with each frequency, calculate the power CD-ROM drive motor vibration then of motor, make electronic product change rhythmical vibration according to music rhythm.Be elaborated with reference to accompanying drawing below in conjunction with embodiment, so that technical characterictic of the present invention and advantage are carried out more deep annotation.
A kind of implementation method with music variation vibrating effect has two kinds of schemes to realize: scheme one begins to analyze the information state of one-period for judging PCM_Level_L greater than zero count less than having no progeny in zero; Scheme two begins to analyze the information state of one-period for judging PCM_Level_L less than zero count greater than having no progeny in zero.
Embodiment 1
Program flow diagram of the present invention a kind ofly changes the implementation method of vibrating effect with music as shown in Figure 1, and its step is as follows:
This method relates to following data, cycle is T, the PCM data that read from the PCM buffer are represented with PCM_Level_L, the quantity of sampled point is SubCount in the one-period, the maximum of SubCount is MaxSubCount, amplitude maximum MaxV_tmp in the interruption, the amplitude reference value is set to constant VLowLimit, the sampled point reference value is set to constant FLowLimit, the maximum of interior all point of interruption amplitudes of sampling period is MaxV, effective period, number was that frequency is ICount, and the amplitude minimum reference value of establishing is MinV_T, and the time in sampling period is set according to product performance by realizing.
Step 1, to after the audio file decoding not before the PCM data conversion becomes final speech simulation waveform, the data of intercepting PCM are read each PCM_Level_L from the PCM buffer;
Step 2, judge that PCM_Level_L is whether greater than zero;
Step 3, PCM_Level_L>0, then execution in step 3.1, PCM_Level_L≤0, then execution in step 3.2;
Step 3.1, PCM_Level_L>0 then begin counting, obtain the quantity SubCount of sampled point in the subcycle, and write down the amplitude maximum MaxV_tmp of this moment, skip to step 5;
Step 3.2, PCM_Level_L≤0 then begin to analyze SubCount and the MaxV_tmp that positive amplitude in the PCM buffer is read in an interruption, and execution in step 4;
Step 4, satisfy SubCount<FLowLimit simultaneously, MaxV_tmp<VLowLimit's, then be judged as high-frequency noise and filter out, do not add up, be periods of inactivity, count the maximum of SubCount, MaxV_tmp;
Step 5, count the maximum MaxV of a sampling period MaxV_tmp, the maximum MaxSubCount among the SubCount, and count MaxV, MaxSubCount in the sampling period, and count the quantity of ICount effective period;
The maximum MaxV that step 6, sampling period interior front and back double sampling of comparison obtain, establishing difference is MaxV_L;
Step 7, judge that MaxV_L is whether less than-MinV_T;
Step 8, MaxV_L<-MinV_T, then execution in step 8.1, MaxV_L 〉=-MinV_T, then execution in step 8.2;
Step 8.1, MaxV_L<-MinV_T, then directly establish MaxV_L=0, motor stops vibration;
Step 8.2, MaxV_L 〉=-MinV_T, then execution in step 9;
Step 9, EP (end of program) are proceeded next round and are judged.
Audio file in the above-mentioned steps 1 refers to the audio file of existing form, as mp3 file, wav file, wma file, midi file, winamp etc.
Embodiment 2
This method also is applicable to judges the counting of PCM_Level_L less than zero time, the information of PCM_Level_L interrupt analysis one-period greater than zero time, its software flow pattern as shown in Figure 2, step is as follows:
This method relates to following data, cycle is T, the PCM data that read from the PCM buffer are represented with PCM_Level_L, the quantity of sampled point is SubCount in the one-period, the maximum of SubCount is MaxSubCount, amplitude maximum MaxV_tmp in the interruption, the amplitude reference value is set to constant VLowLimit, the sampled point reference value is set to constant FLowLimit, the maximum of interior all point of interruption amplitudes of sampling period is MaxV, effective period, number was that frequency is ICount, and the amplitude minimum reference value of establishing is MinV_T, and the time in sampling period is set according to product performance by realizing.
Step 1, to after the audio file decoding not before the PCM data conversion becomes final speech simulation waveform, the data of intercepting PCM are read each PCM_Level_L from the PCM buffer;
Step 2, judge that PCM_Level_L is whether less than zero;
Step 3, PCM_Level_L<0, then execution in step 3.1, PCM_Level_L 〉=0, then execution in step 3.2;
Step 3.1, PCM_Level_L<0 then begin counting, obtain the quantity SubCount of sampled point in the one-period, and write down the amplitude maximum MaxV_tmp of this moment, skip to step 5;
Step 3.2, PCM_Level_L 〉=0 then begin to analyze SubCount and the MaxV_tmp that negative amplitude in the PCM buffer is read in an interruption, and execution in step 4;
Step 4, satisfy SubCount<FLowLimit simultaneously, MaxV_tmp<VLowLimit's, then be judged as high-frequency noise and filter out, do not add up, be periods of inactivity, count the maximum of SubCount, MaxV_tmp;
Step 5, count the maximum MaxV of MaxV_tmp in a sampling period, the maximum MaxSubCount among the SubCount, and count MaxV, MaxSubCount in the one-period, and count the quantity of ICount effective period;
The maximum MaxV that step 6, sampling period interior front and back double sampling of comparison obtain, establishing difference is MaxV_L;
Step 7, judge that MaxV_L is whether less than-MinV_T;
Step 8, MaxV_L<-MinV_T, then execution in step 8.1, MaxV_L 〉=-MinV_T, then execution in step 8.2;
Step 8.1, MaxV_L<-MinV_T, then directly establish MaxV_L=0, motor stops vibration;
Step 8.2, MaxV_L 〉=-MinV_T, then execution in step 9;
Step 9, EP (end of program) are carried out next round and are judged.
Audio file in the above-mentioned steps 1 refers to the audio file of existing form, as mp3 file, wav file, wma file, midi file, winamp etc.
When concrete work, adopt the method for analyzing pulse-code modulation PCM data, according to the size of volume, and the power that changes and each frequency bring the different of sense learning through practice for people's ear, and the power of calculating motor CD-ROM drive motor is then vibrated.Because source of sound that sound variation is played a major role is identical, so most of sound all are same frequencies in the one-period, therefore with the number of getting back to former rail in the one-period, and each waveform strides across the used time of former rail, calculates current source of sound frequency; The amplitude that filters out is not high, the clutter that frequency is very high; The last variation rule that draws music again according to fine setting, final amplitude enhancing or decay are carried out in the influence of people's ear, motor characteristics is carried out the details debugging, strengthen, decay or suddenly change according to certain interval interior amplitude, the output voltage CD-ROM drive motor, make the electronic product that has music playback function change rhythmical vibration, bring the experience of people's happiness according to music rhythm.
Although the present invention has made clear and complete description by specific embodiment to the implementation method that changes vibrating effect with music, but the present invention is not limited only to described embodiment, and the purpose that reaches with music variation vibrating effect by simple data or process variations is contingent and all is included in the present invention.